StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
sfs_index.h
1 #ifndef _SFS_INDEX_H_
2 #define _SFS_INDEX_H_
3 
4 #include <string.h>
5 #include "fs_index.h"
6 #include <sys/uio.h>
7 
8 typedef unsigned int UINT32;
9 typedef unsigned short UINT16;
10 typedef unsigned char UINT8;
11 
12 #include "sfs_base.h"
13 
14 // File Format
15 //
16 // ----------------
17 // | VolumeSpec
18 // | HEAD
19 // | FILE / (data)
20 // | FILE / (data)
21 // | FILE / (data)
22 // | ....
23 // | TAIL
24 // ----------------
25 //
26 // FILE Attributes:
27 //
28 // SFS_ATTR_INVALID : deleted file
29 //
30 //
31 // Filenames:
32 //
33 // /xxx absolute path
34 // xxx relative to directory part of previous entry
35 // 0 length used to reset "previous entry"
36 // xxx/ directory
37 // xxx file
38 // xxx/xxx/yyy xxx/xxx/ is "directory part"
39 
40 
41 
42 
43 class SFS_ittr {
44  public:
45  union {
46  SFS_File entry;
47  char entryBuff[256];
48  };
49  char stickypath[256];
50  char ppath[256];
51  char fullpath[256];
52 
53 #if defined(__USE_LARGEFILE64) || defined(_LARGEFILE64_SOURCE)
54  long long int fileoffset; // from start of file.
55 #else
56  int fileoffset ;
57 #endif
58 
59  int filepos; // 0 start of header, 1 end of header, 2 end of file record, -1 at end of file system
60  int skipped_bytes; // bytes skipped due to ignored info...
61 
62  int legacy;
63  SFS_ittr() {
64  fileoffset = 0;
65  skipped_bytes = 0;
66  };
67 
68 #if defined(__USE_LARGEFILE64) || defined(_LARGEFILE64_SOURCE)
69  SFS_ittr(long long int offset)
70 #else
71  SFS_ittr(int offset)
72 #endif
73  {
74  fileoffset = offset;
75  };
76 
77  int get(wrapfile *wrap);
78  //int legacy_get(wrapfile *wrap);
79  // int get(char *buff, int sz);
80 
81  int next();
82  //int legacy_next();
83 
84  // DAQ SPECIFIC
85  int nextLRHD();
86  int nextDatap();
87  int findEventNumber();
88  int findFullLength();
89  // END DAQ SPECIFIC
90 
91  wrapfile *wfile;
92  void swapEntry();
93 };
94 
95 
96 inline int seeksize(int filesize)
97 {
98  return (filesize + 3) & 0xfffffffc;
99 }
100 
101 inline int get_sfsFileSize(SFS_File *file)
102 {
103  return seeksize(strlen(file->name)+1) + sizeof(SFS_File) - 4;
104 }
105 
106 inline int get_sfsFileSize(char *file)
107 {
108  return seeksize(strlen(file)+1) + sizeof(SFS_File) - 4;
109 }
110 
111 // sfs_lib prototypes
112 void write_env(char *var, char *value);
113 char *read_env(char *var);
114 void getFullPath(char *out, char *in);
115 int seeksize(int filesize);
116 void striptofirst(char *str);
117 char *striptofile(char *str);
118 void stripfile(char *str);
119 char *striptodir(char *str);
120 
121 char *SFS_getpayload(char *buff); // takes a pointer to a FILE and gets the payload...
122 
123 
124 struct SfsDirsize {
125  long long int size;
126  long long int dataSize;
127 };
128 
129 class sfs_index : public fs_index {
130  public:
131 
132  int singleDirMount;
133  SFS_ittr *singleDirIttr;
134 
135  int getInodeSize(fs_inode *inode, SfsDirsize *sz);
136  int getDirSize(char *dir, SfsDirsize *sz);
137 
138 #if defined(__USE_LARGEFILE64) || defined(_LARGEFILE64_SOURCE)
139  int mountSingleDir(char *fn, long long int offset=0);
140  int getSingleDirSize(char *fn, long long int offset);
141  long long int singleDirOffset;
142  long long int nextSingleDirOffset;
143  int mountSingleDirMem(char *buff, int size, long long int offset=0);
144  int singleDirSize;
145 #else
146  int mountSingleDir(char *fn, int offset=0);
147  int getSingleDirSize(char *fn, int offset);
148  int singleDirOffset;
149  int singleDirSize;
150  int nextSingleDirOffset;
151  int mountSingleDirMem(char *buff, int size, int offset=0);
152 #endif
153 
154 
155  int mountSingleDir();
156  int mountNextDir();
157 
158 
159  sfs_index();
160  virtual ~sfs_index() {
161  umount();
162  if(singleDirIttr) delete singleDirIttr;
163  wfile.close();
164  }
165 
166  int _create();
167  void dump(int) { dump("/",root); };
168 
169  int getwritevsz(fs_iovec *fsiovec, int n);
170  int writev_call_retry(int fd, iovec *iovec, int vec);
171  int writev(fs_iovec *fsiovec, int n);
172  int writev_sticky(fs_iovec *iovec, int n, int *sticky);
173  int write(char *fn, char *buff, int sz);
174 
175  static int getfileheadersz(char *fn);
176  int putfileheader(char *ptr, char *fn, int filesz, int flags=SFS_ATTR_NOCD);
177 
178  private:
179 
180  void addnode(SFS_ittr *ittr);
181  int _mountNextDir();
182 #if defined(__USE_LARGEFILE64) || defined(_LARGEFILE64_SOURCE)
183  fs_inode *add_inode(fs_inode *parent, char *name, long long int offset, int sz, int overhead);
184  fs_inode *add_inode_from(fs_inode *neighbor, char *name, long long int offset, int sz, int overhead=0);
185 #else
186  fs_inode *add_inode(fs_inode *parent, char *name, int offset, int sz, int overhead);
187  fs_inode *add_inode_from(fs_inode *neighbor, char *name, int offset, int sz, int overhead=0);
188 #endif
189 
190  fs_inode *find_last_lesser_child(fs_inode *parent, char *name, int &first, int &eq);
191  fs_inode *find_last_lesser_neighbor(fs_inode *neighbor, char *name, int &eq);
192  void dump(const char *path, fs_inode *inode);
193 
194  int writeFsHeader();
195 };
196 
197 
198 #endif