Adding upstream version 4.00~pre53+dfsg.
[syslinux-debian/hramrach.git] / core / include / fs.h
blobf1d35bbb640d1a7ff2b561d2fef20b23fbbc18aa
1 #ifndef FS_H
2 #define FS_H
4 #include <stddef.h>
5 #include <stdbool.h>
6 #include <string.h>
7 #include <com32.h>
8 #include <stdio.h>
9 #include <sys/dirent.h>
10 #include "core.h"
11 #include "disk.h"
14 * Maximum number of open files. This is *currently* constrained by the
15 * fact that PXE needs to be able to fit all its packet buffers into a
16 * 64K segment; this should be fixed by moving the packet buffers to high
17 * memory.
19 #define MAX_OPEN_LG2 5
20 #define MAX_OPEN (1 << MAX_OPEN_LG2)
22 #define FILENAME_MAX_LG2 8
23 #define FILENAME_MAX (1 << FILENAME_MAX_LG2)
25 #define CURRENTDIR_MAX FILENAME_MAX
27 #define BLOCK_SIZE(fs) ((fs)->block_size)
28 #define BLOCK_SHIFT(fs) ((fs)->block_shift)
29 #define SECTOR_SIZE(fs) ((fs)->sector_size)
30 #define SECTOR_SHIFT(fs) ((fs)->sector_shift)
32 struct fs_info {
33 const struct fs_ops *fs_ops;
34 struct device *fs_dev;
35 void *fs_info; /* The fs-specific information */
36 int sector_shift, sector_size;
37 int block_shift, block_size;
38 struct inode *root, *cwd; /* Root and current directories */
39 char cwd_name[CURRENTDIR_MAX]; /* Current directory by name */
42 extern struct fs_info *this_fs;
44 struct dirent; /* Directory entry structure */
45 struct file;
46 enum fs_flags {
47 FS_NODEV = 1 << 0,
48 FS_USEMEM = 1 << 1, /* If we need a malloc routine, set it */
49 FS_THISIND = 1 << 2, /* Set cwd based on config file location */
52 struct fs_ops {
53 /* in fact, we use fs_ops structure to find the right fs */
54 const char *fs_name;
55 enum fs_flags fs_flags;
57 int (*fs_init)(struct fs_info *);
58 void (*searchdir)(const char *, struct file *);
59 uint32_t (*getfssec)(struct file *, char *, int, bool *);
60 void (*close_file)(struct file *);
61 void (*mangle_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 *);
70 /* the _dir_ stuff */
71 int (*readdir)(struct file *, struct dirent *);
73 int (*next_extent)(struct inode *, uint32_t);
77 * Extent structure: contains the mapping of some chunk of a file
78 * that is contiguous on disk.
80 struct extent {
81 sector_t pstart; /* Physical start sector */
82 uint32_t lstart; /* Logical start sector */
83 uint32_t len; /* Number of contiguous sectors */
86 /* Special sector numbers used for struct extent.pstart */
87 #define EXTENT_ZERO ((sector_t)-1) /* All-zero extent */
88 #define EXTENT_VOID ((sector_t)-2) /* Invalid information */
90 #define EXTENT_SPECIAL(x) ((x) >= EXTENT_VOID)
92 /*
93 * The inode structure, including the detail file information
95 struct inode {
96 struct fs_info *fs; /* The filesystem this inode is associated with */
97 int refcnt;
98 int mode; /* FILE , DIR or SYMLINK */
99 uint32_t size;
100 uint32_t blocks; /* How many blocks the file take */
101 uint32_t ino; /* Inode number */
102 uint32_t atime; /* Access time */
103 uint32_t mtime; /* Modify time */
104 uint32_t ctime; /* Create time */
105 uint32_t dtime; /* Delete time */
106 uint32_t flags;
107 uint32_t file_acl;
108 struct extent this_extent, next_extent;
109 char pvt[0]; /* Private filesystem data */
112 struct file {
113 struct fs_info *fs;
114 uint32_t offset; /* for next read */
115 struct inode *inode; /* The file-specific information */
118 enum dev_type {CHS, EDD};
121 * Struct device contains:
122 * the pointer points to the disk structure,
123 * the cache stuff.
125 struct cache;
127 struct device {
128 struct disk *disk;
130 /* the cache stuff */
131 char *cache_data;
132 struct cache *cache_head;
133 uint16_t cache_block_size;
134 uint16_t cache_entries;
135 uint32_t cache_size;
139 * Our definition of "not whitespace"
141 static inline bool not_whitespace(char c)
143 return (unsigned char)c > ' ';
147 * Inode allocator/deallocator
149 struct inode *alloc_inode(struct fs_info *fs, uint32_t ino, size_t data);
150 static inline void free_inode(struct inode * inode)
152 free(inode);
155 static inline struct inode *get_inode(struct inode *inode)
157 inode->refcnt++;
158 return inode;
160 static inline void put_inode(struct inode *inode)
162 if (! --inode->refcnt)
163 free(inode);
166 static inline void malloc_error(char *obj)
168 printf("Out of memory: can't allocate memory for %s\n", obj);
169 kaboom();
173 * File handle conversion functions
175 extern struct file files[];
176 static inline uint16_t file_to_handle(struct file *file)
178 return file ? (file - files)+1 : 0;
180 static inline struct file *handle_to_file(uint16_t handle)
182 return handle ? &files[handle-1] : NULL;
185 /* fs.c */
186 void pm_mangle_name(com32sys_t *);
187 void pm_searchdir(com32sys_t *);
188 void mangle_name(char *, const char *);
189 int searchdir(const char *name);
190 void _close_file(struct file *);
191 size_t pmapi_read_file(uint16_t *handle, void *buf, size_t sectors);
192 int open_file(const char *name, struct com32_filedata *filedata);
193 void pm_open_file(com32sys_t *);
194 void close_file(uint16_t handle);
195 void pm_close_file(com32sys_t *);
197 /* chdir.c */
198 void pm_realpath(com32sys_t *regs);
199 size_t realpath(char *dst, const char *src, size_t bufsize);
200 int chdir(const char *src);
202 /* readdir.c */
203 DIR *opendir(const char *pathname);
204 struct dirent *readdir(DIR *dir);
205 int closedir(DIR *dir);
208 * Generic functions that filesystem drivers may choose to use
211 /* mangle.c */
212 void generic_mangle_name(char *, const char *);
214 /* loadconfig.c */
215 int generic_load_config(void);
217 /* close.c */
218 void generic_close_file(struct file *file);
220 /* getfssec.c */
221 uint32_t generic_getfssec(struct file *file, char *buf,
222 int sectors, bool *have_more);
224 /* nonextextent.c */
225 int no_next_extent(struct inode *, uint32_t);
227 #endif /* FS_H */