6 #define FS_TYPE_CRAMFS 1
7 #define FS_TYPE_RAMFS 2
8 #define FS_TYPE_DEVFS 3
10 #define PATH_MAX 1024 /* include/linux/limits.h */
22 struct fs_driver_d
*fsdrv
;
25 void *priv
; /* private data for the fs driver */
28 typedef struct filep
{
29 struct device_d
*dev
; /* The device this FILE belongs to */
30 ulong pos
; /* current position in stream */
31 ulong size
; /* The size of this inode */
32 ulong flags
; /* the O_* flags from open */
34 void *inode
; /* private to the filesystem driver */
36 /* private fields. Mapping between FILE and filedescriptor number */
41 #define FS_DRIVER_NO_DEV 1
46 int (*probe
) (struct device_d
*dev
);
47 int (*mkdir
)(struct device_d
*dev
, const char *pathname
);
48 int (*rmdir
)(struct device_d
*dev
, const char *pathname
);
50 /* create a file. The file is guaranteed to not exist */
51 int (*create
)(struct device_d
*dev
, const char *pathname
, mode_t mode
);
52 int (*unlink
)(struct device_d
*dev
, const char *pathname
);
54 /* Truncate a file to given size */
55 int (*truncate
)(struct device_d
*dev
, FILE *f
, ulong size
);
57 int (*open
)(struct device_d
*dev
, FILE *f
, const char *pathname
);
58 int (*close
)(struct device_d
*dev
, FILE *f
);
59 int (*read
)(struct device_d
*dev
, FILE *f
, void *buf
, size_t size
);
60 int (*write
)(struct device_d
*dev
, FILE *f
, const void *buf
, size_t size
);
61 off_t (*lseek
)(struct device_d
*dev
, FILE *f
, off_t pos
);
63 struct dir
* (*opendir
)(struct device_d
*dev
, const char *pathname
);
64 struct dirent
* (*readdir
)(struct device_d
*dev
, struct dir
*dir
);
65 int (*closedir
)(struct device_d
*dev
, DIR *dir
);
66 int (*stat
)(struct device_d
*dev
, const char *file
, struct stat
*stat
);
68 int (*ioctl
)(struct device_d
*dev
, FILE *f
, int request
, void *buf
);
69 int (*erase
)(struct device_d
*dev
, FILE *f
, size_t count
,
70 unsigned long offset
);
71 int (*protect
)(struct device_d
*dev
, FILE *f
, size_t count
,
72 unsigned long offset
, int prot
);
74 int (*memmap
)(struct device_d
*dev
, FILE *f
, void **map
, int flags
);
80 struct list_head list
;
85 struct mtab_entry
*next
;
87 struct device_d
*parent_device
;
91 char *backingstore
; /* the device we are associated with */
92 struct device_d dev
; /* our own device */
94 struct fs_driver_d
*driver
;
96 struct mtab_entry mtab
;
100 * standard posix file functions
102 int open(const char *pathname
, int flags
, ...);
103 int creat(const char *pathname
, mode_t mode
);
104 int unlink(const char *pathname
);
106 int stat(const char *filename
, struct stat
*s
);
107 int read(int fd
, void *buf
, size_t count
);
108 int ioctl(int fd
, int request
, void *buf
);
109 ssize_t
write(int fd
, const void *buf
, size_t count
);
115 off_t
lseek(int fildes
, off_t offset
, int whence
);
116 int mkdir (const char *pathname
, mode_t mode
);
118 /* Create a directory and its parents */
119 int make_directory(const char *pathname
);
120 int rmdir (const char *pathname
);
122 const char *getcwd(void);
123 int chdir(const char *pathname
);
125 DIR *opendir(const char *pathname
);
126 struct dirent
*readdir(DIR *dir
);
127 int closedir(DIR *dir
);
129 int mount (const char *device
, const char *fsname
, const char *path
);
130 int umount(const char *pathname
);
132 /* not-so-standard functions */
133 int erase(int fd
, size_t count
, unsigned long offset
);
134 int protect(int fd
, size_t count
, unsigned long offset
, int prot
);
135 int protect_file(const char *file
, int prot
);
136 void *memmap(int fd
, int flags
);
141 #define LS_RECURSIVE 1
144 int ls(const char *path
, ulong flags
);
146 char *mkmodestr(unsigned long mode
, char *str
);
149 * Information about mounted devices.
150 * Note that we only support mounting on directories lying
151 * directly in / and of course the root directory itself
153 struct mtab_entry
*get_mtab_entry_by_path(const char *path
);
154 struct mtab_entry
*mtab_next_entry(struct mtab_entry
*entry
);
155 const char *fsdev_get_mountpoint(struct fs_device_d
*fsdev
);
158 * Read a file into memory. Memory is allocated with malloc and must
159 * be freed with free() afterwards. This function allocates one
160 * byte more than actually needed and sets this to zero, so that
161 * it can be used for text files.
162 * If size is nonzero it s set to the file size.
164 void *read_file(const char *filename
, size_t *size
);
167 * This function turns 'path' into an absolute path and removes all occurrences
168 * of "..", "." and double slashes. The returned string must be freed wit free().
170 char *normalise_path(const char *path
);
172 /* Register a new filesystem driver */
173 int register_fs_driver(struct fs_driver_d
*fsdrv
);