2007-07-05 16:01:35 +00:00
|
|
|
#ifndef __FS_H
|
|
|
|
#define __FS_H
|
|
|
|
|
|
|
|
#include <driver.h>
|
2012-08-12 11:28:27 +00:00
|
|
|
#include <filetype.h>
|
2007-07-05 16:01:35 +00:00
|
|
|
|
2007-07-05 16:01:37 +00:00
|
|
|
#define PATH_MAX 1024 /* include/linux/limits.h */
|
|
|
|
|
2007-07-05 16:01:35 +00:00
|
|
|
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 {
|
2007-07-05 16:01:52 +00:00
|
|
|
char d_name[256];
|
2007-07-05 16:01:37 +00:00
|
|
|
};
|
|
|
|
|
2007-07-05 16:01:52 +00:00
|
|
|
typedef struct dir {
|
2007-07-05 16:01:37 +00:00
|
|
|
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:52 +00:00
|
|
|
} DIR;
|
2007-07-05 16:01:37 +00:00
|
|
|
|
2007-07-05 16:01:38 +00:00
|
|
|
typedef struct filep {
|
2014-10-08 11:48:12 +00:00
|
|
|
struct fs_device_d *fsdev; /* The device this FILE belongs to */
|
2014-10-08 12:01:37 +00:00
|
|
|
char *path;
|
2011-10-14 11:46:09 +00:00
|
|
|
loff_t pos; /* current position in stream */
|
2012-07-03 08:12:40 +00:00
|
|
|
#define FILE_SIZE_STREAM ((loff_t) -1)
|
2011-10-14 11:46:09 +00:00
|
|
|
loff_t 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
|
|
|
|
2014-12-02 16:29:05 +00:00
|
|
|
void *priv; /* private to the filesystem driver */
|
2007-07-05 16:01:38 +00:00
|
|
|
|
|
|
|
/* 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
|
2007-07-05 16:01:35 +00:00
|
|
|
|
|
|
|
struct fs_driver_d {
|
|
|
|
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);
|
|
|
|
|
2012-08-21 09:21:33 +00:00
|
|
|
int (*symlink)(struct device_d *dev, const char *pathname,
|
|
|
|
const char *newpath);
|
2012-08-16 16:48:35 +00:00
|
|
|
int (*readlink)(struct device_d *dev, const char *pathname, char *name,
|
|
|
|
size_t size);
|
|
|
|
|
2007-07-05 16:01:38 +00:00
|
|
|
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);
|
2011-03-25 10:04:53 +00:00
|
|
|
int (*flush)(struct device_d *dev, FILE *f);
|
2011-10-14 11:46:09 +00:00
|
|
|
loff_t (*lseek)(struct device_d *dev, FILE *f, loff_t pos);
|
2007-07-05 16:01:35 +00:00
|
|
|
|
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);
|
2007-07-05 16:01:52 +00:00
|
|
|
int (*closedir)(struct device_d *dev, 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
|
|
|
|
2008-06-06 07:25:13 +00:00
|
|
|
int (*ioctl)(struct device_d *dev, FILE *f, int request, void *buf);
|
2007-07-05 16:01:55 +00:00
|
|
|
int (*erase)(struct device_d *dev, FILE *f, size_t count,
|
2011-10-14 11:46:09 +00:00
|
|
|
loff_t offset);
|
2007-07-16 08:29:28 +00:00
|
|
|
int (*protect)(struct device_d *dev, FILE *f, size_t count,
|
2011-10-14 11:46:09 +00:00
|
|
|
loff_t offset, int prot);
|
2007-07-05 16:01:55 +00:00
|
|
|
|
2007-07-15 11:50:04 +00:00
|
|
|
int (*memmap)(struct device_d *dev, FILE *f, void **map, int flags);
|
|
|
|
|
2007-07-05 16:01:35 +00:00
|
|
|
struct driver_d drv;
|
2007-07-05 16:01:37 +00:00
|
|
|
|
2012-08-12 11:28:27 +00:00
|
|
|
enum filetype type;
|
|
|
|
|
2007-07-05 16:01:37 +00:00
|
|
|
unsigned long flags;
|
2007-07-05 16:01:35 +00:00
|
|
|
};
|
|
|
|
|
2012-02-19 15:43:39 +00:00
|
|
|
#define dev_to_fs_device(d) container_of(d, struct fs_device_d, dev)
|
2012-02-19 15:39:53 +00:00
|
|
|
|
2012-02-19 17:10:50 +00:00
|
|
|
extern struct list_head fs_device_list;
|
|
|
|
#define for_each_fs_device(f) list_for_each_entry(f, &fs_device_list, list)
|
2013-09-27 21:26:00 +00:00
|
|
|
extern struct bus_type fs_bus;
|
2012-02-11 13:29:19 +00:00
|
|
|
|
2007-07-05 16:01:35 +00:00
|
|
|
struct fs_device_d {
|
2009-06-11 13:33:49 +00:00
|
|
|
char *backingstore; /* the device we are associated with */
|
2007-07-05 16:01:35 +00:00
|
|
|
struct device_d dev; /* our own device */
|
|
|
|
|
|
|
|
struct fs_driver_d *driver;
|
2007-10-19 06:45:57 +00:00
|
|
|
|
2012-02-14 22:07:57 +00:00
|
|
|
struct cdev *cdev;
|
2012-02-19 17:10:50 +00:00
|
|
|
char *path;
|
|
|
|
struct device_d *parent_device;
|
|
|
|
struct list_head list;
|
2014-02-07 21:28:12 +00:00
|
|
|
char *options;
|
2015-06-17 10:57:42 +00:00
|
|
|
char *linux_rootarg;
|
2007-07-05 16:01:35 +00:00
|
|
|
};
|
|
|
|
|
2012-08-12 11:28:27 +00:00
|
|
|
#define drv_to_fs_driver(d) container_of(d, struct fs_driver_d, drv)
|
|
|
|
|
2007-07-05 16:02:12 +00:00
|
|
|
/*
|
|
|
|
* standard posix file functions
|
|
|
|
*/
|
2007-09-24 15:03:20 +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);
|
2011-03-25 10:04:53 +00:00
|
|
|
int flush(int fd);
|
2012-08-22 04:54:19 +00:00
|
|
|
int lstat(const char *filename, struct stat *s);
|
2007-07-05 16:01:38 +00:00
|
|
|
int stat(const char *filename, struct stat *s);
|
2014-10-08 12:02:23 +00:00
|
|
|
int fstat(int fd, struct stat *s);
|
2013-02-17 21:05:00 +00:00
|
|
|
ssize_t read(int fd, void *buf, size_t count);
|
2013-02-17 21:05:01 +00:00
|
|
|
ssize_t pread(int fd, void *buf, size_t count, loff_t offset);
|
2008-06-06 07:25:13 +00:00
|
|
|
int ioctl(int fd, int request, void *buf);
|
2007-07-05 16:01:38 +00:00
|
|
|
ssize_t write(int fd, const void *buf, size_t count);
|
2013-02-17 21:05:01 +00:00
|
|
|
ssize_t pwrite(int fd, const void *buf, size_t count, loff_t offset);
|
2007-07-05 16:01:40 +00:00
|
|
|
|
|
|
|
#define SEEK_SET 1
|
|
|
|
#define SEEK_CUR 2
|
|
|
|
#define SEEK_END 3
|
|
|
|
|
2011-10-14 11:46:09 +00:00
|
|
|
loff_t lseek(int fildes, loff_t offset, int whence);
|
2007-09-24 15:03:20 +00:00
|
|
|
int mkdir (const char *pathname, mode_t mode);
|
2007-09-27 09:59:18 +00:00
|
|
|
|
|
|
|
/* Create a directory and its parents */
|
|
|
|
int make_directory(const char *pathname);
|
2007-07-05 16:01:44 +00:00
|
|
|
int rmdir (const char *pathname);
|
2007-07-05 16:01:35 +00:00
|
|
|
|
2007-07-05 16:01:51 +00:00
|
|
|
const char *getcwd(void);
|
|
|
|
int chdir(const char *pathname);
|
|
|
|
|
2007-07-05 16:01:52 +00:00
|
|
|
DIR *opendir(const char *pathname);
|
|
|
|
struct dirent *readdir(DIR *dir);
|
|
|
|
int closedir(DIR *dir);
|
2007-07-05 16:01:35 +00:00
|
|
|
|
2012-08-21 09:21:33 +00:00
|
|
|
int symlink(const char *pathname, const char *newpath);
|
2012-08-16 16:48:35 +00:00
|
|
|
int readlink(const char *path, char *buf, size_t bufsiz);
|
|
|
|
|
2014-02-07 21:28:12 +00:00
|
|
|
int mount (const char *device, const char *fsname, const char *path,
|
|
|
|
const char *fsoptions);
|
2007-07-05 16:02:12 +00:00
|
|
|
int umount(const char *pathname);
|
|
|
|
|
2007-07-16 08:29:28 +00:00
|
|
|
/* not-so-standard functions */
|
2015-03-01 12:32:08 +00:00
|
|
|
int erase(int fd, size_t count, loff_t offset);
|
|
|
|
int protect(int fd, size_t count, loff_t offset, int prot);
|
2009-10-02 13:23:22 +00:00
|
|
|
int protect_file(const char *file, int prot);
|
2007-07-15 11:50:04 +00:00
|
|
|
void *memmap(int fd, int flags);
|
|
|
|
|
2012-03-18 16:59:46 +00:00
|
|
|
#define FILESIZE_MAX ((loff_t)-1)
|
|
|
|
|
2007-07-15 11:50:04 +00:00
|
|
|
#define PROT_READ 1
|
|
|
|
#define PROT_WRITE 2
|
2007-07-05 16:02:12 +00:00
|
|
|
|
|
|
|
#define LS_RECURSIVE 1
|
|
|
|
#define LS_SHOWARG 2
|
2008-03-11 20:41:56 +00:00
|
|
|
#define LS_COLUMN 4
|
2007-07-05 16:02:12 +00:00
|
|
|
int ls(const char *path, ulong flags);
|
|
|
|
|
2007-07-05 16:01:37 +00:00
|
|
|
char *mkmodestr(unsigned long mode, char *str);
|
|
|
|
|
2007-07-05 16:02:12 +00:00
|
|
|
/*
|
2008-03-01 20:06:14 +00:00
|
|
|
* This function turns 'path' into an absolute path and removes all occurrences
|
2007-07-05 16:02:12 +00:00
|
|
|
* of "..", "." and double slashes. The returned string must be freed wit free().
|
|
|
|
*/
|
2007-07-05 16:01:51 +00:00
|
|
|
char *normalise_path(const char *path);
|
2012-08-22 10:54:50 +00:00
|
|
|
char *normalise_link(const char *pathname, const char* symlink);
|
2007-07-05 16:01:38 +00:00
|
|
|
|
2012-08-17 07:28:15 +00:00
|
|
|
char *get_mounted_path(const char *path);
|
2007-07-05 16:01:38 +00:00
|
|
|
|
2013-11-01 08:33:17 +00:00
|
|
|
struct cdev *get_cdev_by_mountpath(const char *path);
|
|
|
|
|
2009-06-10 19:15:06 +00:00
|
|
|
/* Register a new filesystem driver */
|
|
|
|
int register_fs_driver(struct fs_driver_d *fsdrv);
|
|
|
|
|
2012-02-19 17:22:04 +00:00
|
|
|
void automount_remove(const char *_path);
|
|
|
|
int automount_add(const char *path, const char *cmd);
|
|
|
|
void automount_print(void);
|
|
|
|
|
2012-11-29 19:21:26 +00:00
|
|
|
int unlink_recursive(const char *path, char **failedpath);
|
|
|
|
|
2013-09-27 20:47:10 +00:00
|
|
|
int fsdev_open_cdev(struct fs_device_d *fsdev);
|
2013-09-27 22:02:39 +00:00
|
|
|
const char *cdev_get_mount_path(struct cdev *cdev);
|
2014-02-07 21:28:12 +00:00
|
|
|
const char *cdev_mount_default(struct cdev *cdev, const char *fsoptions);
|
2013-09-27 22:02:39 +00:00
|
|
|
void mount_all(void);
|
2013-09-27 20:47:10 +00:00
|
|
|
|
2015-06-17 10:57:42 +00:00
|
|
|
void fsdev_set_linux_rootarg(struct fs_device_d *fsdev, const char *str);
|
|
|
|
char *path_get_linux_rootarg(const char *path);
|
|
|
|
|
2007-07-05 16:01:35 +00:00
|
|
|
#endif /* __FS_H */
|