Improve documentation by adding build notes to the a9m24x0 CPU cards
[barebox-mini2440.git] / include / fs.h
blob552c4e94bb999e9d78c0672a0e6bf4e17a69252e
1 #ifndef __FS_H
2 #define __FS_H
4 #include <driver.h>
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 */
12 struct partition;
13 struct node_d;
14 struct stat;
16 struct dirent {
17 char d_name[256];
20 typedef struct dir {
21 struct device_d *dev;
22 struct fs_driver_d *fsdrv;
23 struct node_d *node;
24 struct dirent d;
25 void *priv; /* private data for the fs driver */
26 } DIR;
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 */
37 int no;
38 char in_use;
39 } FILE;
41 #define FS_DRIVER_NO_DEV 1
43 struct fs_driver_d {
44 ulong type;
45 char *name;
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);
76 struct driver_d drv;
78 unsigned long flags;
80 struct list_head list;
83 struct mtab_entry {
84 char path[PATH_MAX];
85 struct mtab_entry *next;
86 struct device_d *dev;
87 struct device_d *parent_device;
90 struct fs_device_d {
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);
105 int close(int fd);
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);
111 #define SEEK_SET 1
112 #define SEEK_CUR 2
113 #define SEEK_END 3
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 void *memmap(int fd, int flags);
137 #define PROT_READ 1
138 #define PROT_WRITE 2
140 #define LS_RECURSIVE 1
141 #define LS_SHOWARG 2
142 #define LS_COLUMN 4
143 int ls(const char *path, ulong flags);
145 char *mkmodestr(unsigned long mode, char *str);
148 * Information about mounted devices.
149 * Note that we only support mounting on directories lying
150 * directly in / and of course the root directory itself
152 struct mtab_entry *get_mtab_entry_by_path(const char *path);
153 struct mtab_entry *mtab_next_entry(struct mtab_entry *entry);
154 const char *fsdev_get_mountpoint(struct fs_device_d *fsdev);
157 * Read a file into memory. Memory is allocated with malloc and must
158 * be freed with free() afterwards. This function allocates one
159 * byte more than actually needed and sets this to zero, so that
160 * it can be used for text files.
161 * If size is nonzero it s set to the file size.
163 void *read_file(const char *filename, size_t *size);
166 * This function turns 'path' into an absolute path and removes all occurrences
167 * of "..", "." and double slashes. The returned string must be freed wit free().
169 char *normalise_path(const char *path);
171 /* Register a new filesystem driver */
172 int register_fs_driver(struct fs_driver_d *fsdrv);
174 #endif /* __FS_H */