13 * Maximum number of open files. This is *currently* constrained by the
14 * fact that PXE needs to be able to fit all its packet buffers into a
15 * 64K segment; this should be fixed by moving the packet buffers to high
18 #define MAX_OPEN_LG2 5
19 #define MAX_OPEN (1 << MAX_OPEN_LG2)
21 #define FILENAME_MAX_LG2 8
22 #define FILENAME_MAX (1 << FILENAME_MAX_LG2)
24 #define CURRENTDIR_MAX FILENAME_MAX
26 #define BLOCK_SIZE(fs) ((fs)->block_size)
27 #define BLOCK_SHIFT(fs) ((fs)->block_shift)
28 #define SECTOR_SIZE(fs) ((fs)->sector_size)
29 #define SECTOR_SHIFT(fs) ((fs)->sector_shift)
32 const struct fs_ops *fs_ops;
33 struct device *fs_dev;
34 void *fs_info; /* The fs-specific information */
35 int sector_shift, sector_size;
36 int block_shift, block_size;
37 struct inode *root, *cwd; /* Root and current directories */
38 char cwd_name[CURRENTDIR_MAX]; /* Current directory by name */
41 extern struct fs_info *this_fs;
43 struct dirent; /* Directory entry structure */
47 FS_USEMEM = 1 << 1, /* If we need a malloc routine, set it */
48 FS_THISIND = 1 << 2, /* Set cwd based on config file location */
52 /* in fact, we use fs_ops structure to find the right fs */
54 enum fs_flags fs_flags;
56 int (*fs_init)(struct fs_info *);
57 void (*searchdir)(const char *, struct file *);
58 uint32_t (*getfssec)(struct file *, char *, int, bool *);
59 void (*close_file)(struct file *);
60 void (*mangle_name)(char *, const char *);
61 char * (*unmangle_name)(char *, const char *);
62 size_t (*realpath)(struct fs_info *, char *, const char *, size_t);
63 int (*chdir)(struct fs_info *, const char *);
64 int (*load_config)(void);
66 struct inode * (*iget_root)(struct fs_info *);
67 struct inode * (*iget)(const char *, struct inode *);
68 int (*readlink)(struct inode *, char *);
71 struct dirent * (*readdir)(struct file *);
73 void (*next_extent)(struct inode *);
76 enum inode_mode {I_FILE, I_DIR, I_SYMLINK};
79 * Extent structure: contains the mapping of some chunk of a file
80 * that is contiguous on disk.
83 sector_t pstart; /* Physical start sector */
84 uint32_t lstart; /* Logical start sector */
85 uint32_t len; /* Number of contiguous sectors */
88 /* Special sector numbers used for struct extent.pstart */
89 #define EXTENT_ZERO ((sector_t)-1) /* All-zero extent */
90 #define EXTENT_VOID ((sector_t)-2) /* Invalid information */
92 #define EXTENT_SPECIAL(x) ((x) >= EXTENT_VOID)
95 * The inode structure, including the detail file information
98 struct fs_info *fs; /* The filesystem this inode is associated with */
100 int mode; /* FILE , DIR or SYMLINK */
102 uint32_t blocks; /* How many blocks the file take */
103 uint32_t ino; /* Inode number */
104 uint32_t atime; /* Access time */
105 uint32_t mtime; /* Modify time */
106 uint32_t ctime; /* Create time */
107 uint32_t dtime; /* Delete time */
110 struct extent this_extent, prev_extent, next_extent;
111 char pvt[0]; /* Private filesystem data */
120 /* For the new universal-path_lookup */
122 struct inode *inode; /* The file-specific information */
123 uint32_t offset; /* for next read */
126 /* For the old searchdir method */
128 struct open_file_t *open_file;/* The fs-specific open file struct */
134 enum dev_type {CHS, EDD};
137 * Struct device contains:
138 * the pointer points to the disk structure,
146 /* the cache stuff */
148 struct cache *cache_head;
149 uint16_t cache_block_size;
150 uint16_t cache_entries;
155 * Our definition of "not whitespace"
157 static inline bool not_whitespace(char c)
159 return (unsigned char)c > ' ';
163 * Inode allocator/deallocator
165 struct inode *alloc_inode(struct fs_info *fs, uint32_t ino, size_t data);
166 static inline void free_inode(struct inode * inode)
171 static inline struct inode *get_inode(struct inode *inode)
176 static inline void put_inode(struct inode *inode)
178 if (! --inode->refcnt)
182 static inline void malloc_error(char *obj)
184 printf("Out of memory: can't allocate memory for %s\n", obj);
189 * File handle conversion functions
191 extern struct file files[];
192 static inline uint16_t file_to_handle(struct file *file)
194 return file ? (file - files)+1 : 0;
196 static inline struct file *handle_to_file(uint16_t handle)
198 return handle ? &files[handle-1] : NULL;
202 void pm_mangle_name(com32sys_t *);
203 void pm_unmangle_name(com32sys_t *);
204 void pm_searchdir(com32sys_t *);
205 void mangle_name(char *, const char *);
206 char *unmangle_name(char *, const char *);
207 int searchdir(const char *name);
208 void _close_file(struct file *);
209 size_t pmapi_read_file(uint16_t *handle, void *buf, size_t sectors);
212 void pm_realpath(com32sys_t *regs);
213 size_t realpath(char *dst, const char *src, size_t bufsize);
214 int chdir(const char *src);
217 * Generic functions that filesystem drivers may choose to use
221 void generic_mangle_name(char *, const char *);
222 #define generic_unmangle_name stpcpy
225 int generic_load_config(void);
228 void generic_close_file(struct file *file);
231 uint32_t generic_getfssec(struct file *file, char *buf,
232 int sectors, bool *have_more);