9 #include <sys/dirent.h>
15 * Maximum number of open files. This is *currently* constrained by the
16 * fact that PXE needs to be able to fit all its packet buffers into a
17 * 64K segment; this should be fixed by moving the packet buffers to high
20 #define MAX_OPEN_LG2 5
21 #define MAX_OPEN (1 << MAX_OPEN_LG2)
23 #define FILENAME_MAX_LG2 8
24 #define FILENAME_MAX (1 << FILENAME_MAX_LG2)
26 #define CURRENTDIR_MAX FILENAME_MAX
28 #define BLOCK_SIZE(fs) ((fs)->block_size)
29 #define BLOCK_SHIFT(fs) ((fs)->block_shift)
30 #define SECTOR_SIZE(fs) ((fs)->sector_size)
31 #define SECTOR_SHIFT(fs) ((fs)->sector_shift)
34 const struct fs_ops
*fs_ops
;
35 struct device
*fs_dev
;
36 void *fs_info
; /* The fs-specific information */
37 int sector_shift
, sector_size
;
38 int block_shift
, block_size
;
39 struct inode
*root
, *cwd
; /* Root and current directories */
40 char cwd_name
[CURRENTDIR_MAX
]; /* Current directory by name */
43 extern struct fs_info
*this_fs
;
45 struct dirent
; /* Directory entry structure */
49 FS_USEMEM
= 1 << 1, /* If we need a malloc routine, set it */
50 FS_THISIND
= 1 << 2, /* Set cwd based on config file location */
54 /* in fact, we use fs_ops structure to find the right fs */
56 enum fs_flags fs_flags
;
58 int (*fs_init
)(struct fs_info
*);
59 void (*searchdir
)(const char *, struct file
*);
60 uint32_t (*getfssec
)(struct file
*, char *, int, bool *);
61 void (*close_file
)(struct file
*);
62 void (*mangle_name
)(char *, const char *);
63 size_t (*realpath
)(struct fs_info
*, char *, const char *, size_t);
64 int (*chdir
)(struct fs_info
*, const char *);
65 int (*chdir_start
)(void);
66 int (*open_config
)(struct com32_filedata
*);
68 struct inode
* (*iget_root
)(struct fs_info
*);
69 struct inode
* (*iget
)(const char *, struct inode
*);
70 int (*readlink
)(struct inode
*, char *);
73 int (*readdir
)(struct file
*, struct dirent
*);
75 int (*next_extent
)(struct inode
*, uint32_t);
77 int (*copy_super
)(void *buf
);
81 * Extent structure: contains the mapping of some chunk of a file
82 * that is contiguous on disk.
85 sector_t pstart
; /* Physical start sector */
86 uint32_t lstart
; /* Logical start sector */
87 uint32_t len
; /* Number of contiguous sectors */
90 /* Special sector numbers used for struct extent.pstart */
91 #define EXTENT_ZERO ((sector_t)-1) /* All-zero extent */
92 #define EXTENT_VOID ((sector_t)-2) /* Invalid information */
94 #define EXTENT_SPECIAL(x) ((x) >= EXTENT_VOID)
97 * The inode structure, including the detail file information
100 struct fs_info
*fs
; /* The filesystem this inode is associated with */
101 struct inode
*parent
; /* Parent directory, if any */
102 const char *name
; /* Name, valid for generic path search only */
104 int mode
; /* FILE , DIR or SYMLINK */
106 uint64_t blocks
; /* How many blocks the file take */
107 uint64_t ino
; /* Inode number */
108 uint32_t atime
; /* Access time */
109 uint32_t mtime
; /* Modify time */
110 uint32_t ctime
; /* Create time */
111 uint32_t dtime
; /* Delete time */
114 struct extent this_extent
, next_extent
;
115 char pvt
[0]; /* Private filesystem data */
120 uint32_t offset
; /* for next read */
121 struct inode
*inode
; /* The file-specific information */
125 * Struct device contains:
126 * the pointer points to the disk structure,
134 /* the cache stuff */
136 struct cache
*cache_head
;
137 uint16_t cache_block_size
;
138 uint16_t cache_entries
;
143 * Our definition of "not whitespace"
145 static inline bool not_whitespace(char c
)
147 return (unsigned char)c
> ' ';
151 * Inode allocator/deallocator
153 struct inode
*alloc_inode(struct fs_info
*fs
, uint32_t ino
, size_t data
);
154 static inline void free_inode(struct inode
* inode
)
159 static inline struct inode
*get_inode(struct inode
*inode
)
162 dprintf("get_inode %p name %s refcnt %d\n",
163 inode
, inode
->name
, inode
->refcnt
);
167 void put_inode(struct inode
*inode
);
169 static inline void malloc_error(char *obj
)
171 printf("Out of memory: can't allocate memory for %s\n", obj
);
176 * File handle conversion functions
178 extern struct file files
[];
179 static inline uint16_t file_to_handle(struct file
*file
)
181 return file
? (file
- files
)+1 : 0;
183 static inline struct file
*handle_to_file(uint16_t handle
)
185 return handle
? &files
[handle
-1] : NULL
;
191 void pm_mangle_name(com32sys_t
*);
192 void pm_searchdir(com32sys_t
*);
193 void mangle_name(char *, const char *);
194 int searchdir(const char *name
);
195 void _close_file(struct file
*);
196 size_t pmapi_read_file(uint16_t *handle
, void *buf
, size_t sectors
);
197 int open_file(const char *name
, struct com32_filedata
*filedata
);
198 void pm_open_file(com32sys_t
*);
199 void close_file(uint16_t handle
);
200 void pm_close_file(com32sys_t
*);
201 int open_config(void);
204 void pm_realpath(com32sys_t
*regs
);
205 size_t realpath(char *dst
, const char *src
, size_t bufsize
);
206 int chdir(const char *src
);
209 DIR *opendir(const char *pathname
);
210 struct dirent
*readdir(DIR *dir
);
211 int closedir(DIR *dir
);
214 char *core_getcwd(char *buf
, size_t size
);
217 * Generic functions that filesystem drivers may choose to use
221 int generic_chdir_start(void);
224 void generic_mangle_name(char *, const char *);
227 int search_dirs(struct com32_filedata
*filedata
,
228 const char *search_directores
[], const char *filenames
[],
230 int generic_open_config(struct com32_filedata
*filedata
);
233 void generic_close_file(struct file
*file
);
236 uint32_t generic_getfssec(struct file
*file
, char *buf
,
237 int sectors
, bool *have_more
);
240 int no_next_extent(struct inode
*, uint32_t);