4 #include <linux/list.h>
10 #include <sys/dirent.h>
16 * Maximum number of open files.
18 #define MAX_OPEN_LG2 7
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 *, int, 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 size_t (*realpath
)(struct fs_info
*, char *, const char *, size_t);
62 int (*chdir
)(struct fs_info
*, const char *);
63 int (*chdir_start
)(void);
64 int (*open_config
)(struct com32_filedata
*);
66 struct inode
* (*iget_root
)(struct fs_info
*);
67 struct inode
* (*iget
)(const char *, struct inode
*);
68 int (*readlink
)(struct inode
*, char *);
71 int (*readdir
)(struct file
*, struct dirent
*);
73 int (*next_extent
)(struct inode
*, uint32_t);
75 int (*copy_super
)(void *buf
);
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 */
99 struct inode
*parent
; /* Parent directory, if any */
100 const char *name
; /* Name, valid for generic path search only */
102 int mode
; /* FILE , DIR or SYMLINK */
104 uint64_t blocks
; /* How many blocks the file take */
105 uint64_t ino
; /* Inode number */
106 uint32_t atime
; /* Access time */
107 uint32_t mtime
; /* Modify time */
108 uint32_t ctime
; /* Create time */
109 uint32_t dtime
; /* Delete time */
112 struct extent this_extent
, next_extent
;
113 char pvt
[0]; /* Private filesystem data */
118 uint32_t offset
; /* for next read */
119 struct inode
*inode
; /* The file-specific information */
123 * Struct device contains:
124 * the pointer points to the disk structure,
132 /* the cache stuff */
134 struct cache
*cache_head
;
135 uint16_t cache_block_size
;
136 uint16_t cache_entries
;
141 * Our definition of "not whitespace"
143 static inline bool not_whitespace(char c
)
145 return (unsigned char)c
> ' ';
149 * Inode allocator/deallocator
151 struct inode
*alloc_inode(struct fs_info
*fs
, uint32_t ino
, size_t data
);
152 static inline void free_inode(struct inode
* inode
)
157 static inline struct inode
*get_inode(struct inode
*inode
)
160 dprintf("get_inode %p name %s refcnt %d\n",
161 inode
, inode
->name
, inode
->refcnt
);
165 void put_inode(struct inode
*inode
);
167 static inline void malloc_error(char *obj
)
169 printf("Out of memory: can't allocate memory for %s\n", obj
);
174 * File handle conversion functions
176 extern struct file files
[];
177 static inline uint16_t file_to_handle(struct file
*file
)
179 return file
? (file
- files
)+1 : 0;
181 static inline struct file
*handle_to_file(uint16_t handle
)
183 return handle
? &files
[handle
-1] : NULL
;
187 struct list_head list
;
191 extern struct list_head PATH
;
193 extern struct path_entry
*path_add(const char *str
);
196 void fs_init(const struct fs_ops
**ops
, void *priv
);
197 void pm_mangle_name(com32sys_t
*);
198 void pm_searchdir(com32sys_t
*);
199 void mangle_name(char *, const char *);
200 int searchdir(const char *name
, int flags
);
201 void _close_file(struct file
*);
202 size_t pmapi_read_file(uint16_t *handle
, void *buf
, size_t sectors
);
203 int open_file(const char *name
, int flags
, struct com32_filedata
*filedata
);
204 void pm_open_file(com32sys_t
*);
205 void close_file(uint16_t handle
);
206 void pm_close_file(com32sys_t
*);
207 int open_config(void);
209 extern uint16_t SectorShift
;
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 DIR *opendir(const char *pathname
);
218 struct dirent
*readdir(DIR *dir
);
219 int closedir(DIR *dir
);
222 char *core_getcwd(char *buf
, size_t size
);
225 * Generic functions that filesystem drivers may choose to use
229 int generic_chdir_start(void);
232 void generic_mangle_name(char *, const char *);
235 int search_dirs(struct com32_filedata
*filedata
,
236 const char *search_directores
[], const char *filenames
[],
238 int generic_open_config(struct com32_filedata
*filedata
);
241 void generic_close_file(struct file
*file
);
244 uint32_t generic_getfssec(struct file
*file
, char *buf
,
245 int sectors
, bool *have_more
);
248 int no_next_extent(struct inode
*, uint32_t);