9
0
Fork 0
barebox/include/fs.h

117 lines
3.2 KiB
C
Raw Normal View History

#ifndef __FS_H
#define __FS_H
#include <driver.h>
#define FS_TYPE_CRAMFS 1
2007-07-05 16:01:37 +00:00
#define FS_TYPE_RAMFS 2
2007-07-05 16:01:40 +00:00
#define FS_TYPE_DEVFS 3
2007-07-05 16:01:37 +00:00
#define PATH_MAX 1024 /* include/linux/limits.h */
struct partition;
2007-07-05 16:01:37 +00:00
struct node_d;
2007-07-05 16:01:38 +00:00
struct stat;
2007-07-05 16:01:37 +00:00
struct dirent {
char name[256];
};
struct dir {
struct device_d *dev;
struct fs_driver_d *fsdrv;
struct node_d *node;
struct dirent d;
void *priv; /* private data for the fs driver */
};
2007-07-05 16:01:38 +00:00
typedef struct filep {
2007-07-05 16:01:38 +00:00
struct device_d *dev; /* The device this FILE belongs to */
ulong pos; /* current position in stream */
2007-07-05 16:01:38 +00:00
ulong size; /* The size of this inode */
2007-07-05 16:01:40 +00:00
ulong flags; /* the O_* flags from open */
2007-07-05 16:01:38 +00:00
void *inode; /* private to the filesystem driver */
/* private fields. Mapping between FILE and filedescriptor number */
2007-07-05 16:01:38 +00:00
int no;
2007-07-05 16:01:38 +00:00
char in_use;
2007-07-05 16:01:38 +00:00
} FILE;
2007-07-05 16:01:37 +00:00
#define FS_DRIVER_NO_DEV 1
struct fs_driver_d {
ulong type;
char *name;
int (*probe) (struct device_d *dev);
2007-07-05 16:01:37 +00:00
int (*mkdir)(struct device_d *dev, const char *pathname);
2007-07-05 16:01:44 +00:00
int (*rmdir)(struct device_d *dev, const char *pathname);
2007-07-05 16:01:38 +00:00
2007-07-05 16:01:38 +00:00
/* create a file. The file is guaranteed to not exist */
2007-07-05 16:01:38 +00:00
int (*create)(struct device_d *dev, const char *pathname, mode_t mode);
2007-07-05 16:01:44 +00:00
int (*unlink)(struct device_d *dev, const char *pathname);
2007-07-05 16:01:38 +00:00
/* Truncate a file to given size */
int (*truncate)(struct device_d *dev, FILE *f, ulong size);
int (*open)(struct device_d *dev, FILE *f, const char *pathname);
2007-07-05 16:01:38 +00:00
int (*close)(struct device_d *dev, FILE *f);
int (*read)(struct device_d *dev, FILE *f, void *buf, size_t size);
2007-07-05 16:01:38 +00:00
int (*write)(struct device_d *dev, FILE *f, const void *buf, size_t size);
2007-07-05 16:01:37 +00:00
struct dir* (*opendir)(struct device_d *dev, const char *pathname);
struct dirent* (*readdir)(struct device_d *dev, struct dir *dir);
int (*closedir)(struct device_d *dev, struct dir *dir);
2007-07-05 16:01:38 +00:00
int (*stat)(struct device_d *dev, const char *file, struct stat *stat);
2007-07-05 16:01:37 +00:00
struct driver_d drv;
2007-07-05 16:01:37 +00:00
unsigned long flags;
};
struct fs_device_d {
struct device_d *parent; /* the device we are associated with */
struct device_d dev; /* our own device */
struct fs_driver_d *driver;
};
2007-07-05 16:01:38 +00:00
int open(const char *pathname, int flags);
2007-07-05 16:01:38 +00:00
int creat(const char *pathname, mode_t mode);
2007-07-05 16:01:44 +00:00
int unlink(const char *pathname);
2007-07-05 16:01:38 +00:00
int close(int fd);
2007-07-05 16:01:38 +00:00
int stat(const char *filename, struct stat *s);
2007-07-05 16:01:38 +00:00
int read(int fd, void *buf, size_t count);
ssize_t write(int fd, const void *buf, size_t count);
2007-07-05 16:01:40 +00:00
#define SEEK_SET 1
#define SEEK_CUR 2
#define SEEK_END 3
off_t lseek(int fildes, off_t offset, int whence);
int ls(const char *path, ulong flags);
2007-07-05 16:01:38 +00:00
int mkdir (const char *pathname);
2007-07-05 16:01:44 +00:00
int rmdir (const char *pathname);
int mount (const char *device, const char *fsname, const char *path);
2007-07-05 16:01:38 +00:00
int umount(const char *pathname);
2007-07-05 16:01:38 +00:00
struct dir *opendir(const char *pathname);
struct dirent *readdir(struct dir *dir);
int closedir(struct dir *dir);
2007-07-05 16:01:37 +00:00
char *mkmodestr(unsigned long mode, char *str);
2007-07-05 16:01:38 +00:00
struct mtab_entry *get_mtab_entry_by_path(const char *path);
2007-07-05 16:01:44 +00:00
struct mtab_entry *mtab_next_entry(struct mtab_entry *entry);
2007-07-05 16:01:38 +00:00
struct mtab_entry {
char path[PATH_MAX];
struct mtab_entry *next;
struct device_d *dev;
2007-07-05 16:01:44 +00:00
struct device_d *parent_device;
2007-07-05 16:01:38 +00:00
};
void normalise_path(char *path);
#endif /* __FS_H */