toaruos/kernel/include/fs.h

143 lines
4.7 KiB
C
Raw Normal View History

2011-12-11 03:45:04 +04:00
/* vim: tabstop=4 shiftwidth=4 noexpandtab
*/
2011-01-22 10:09:47 +03:00
#ifndef FS_H
#define FS_H
#define PATH_SEPARATOR '/'
#define PATH_SEPARATOR_STRING "/"
#define PATH_UP ".."
#define PATH_DOT "."
#define O_RDONLY 0x0000
#define O_WRONLY 0x0001
#define O_RDWR 0x0002
#define O_APPEND 0x0008
#define O_CREAT 0x0200
#define O_TRUNC 0x0400
#define O_EXCL 0x0800
2011-01-22 10:09:47 +03:00
#define FS_FILE 0x01
#define FS_DIRECTORY 0x02
2011-02-09 04:03:54 +03:00
#define FS_CHARDEVICE 0x04
#define FS_BLOCKDEVICE 0x08
#define FS_PIPE 0x10
#define FS_SYMLINK 0x20
#define FS_MOUNTPOINT 0x40
2011-01-22 10:09:47 +03:00
#define _IFMT 0170000 /* type of file */
#define _IFDIR 0040000 /* directory */
#define _IFCHR 0020000 /* character special */
#define _IFBLK 0060000 /* block special */
#define _IFREG 0100000 /* regular */
#define _IFLNK 0120000 /* symbolic link */
#define _IFSOCK 0140000 /* socket */
#define _IFIFO 0010000 /* fifo */
2012-01-27 13:12:29 +04:00
2011-01-22 10:38:25 +03:00
struct fs_node;
2012-01-26 05:25:59 +04:00
typedef uint32_t (*read_type_t) (struct fs_node *, uint32_t, uint32_t, uint8_t *);
typedef uint32_t (*write_type_t) (struct fs_node *, uint32_t, uint32_t, uint8_t *);
typedef void (*open_type_t) (struct fs_node *, unsigned int flags);
2011-01-31 02:00:38 +03:00
typedef void (*close_type_t) (struct fs_node *);
typedef struct dirent *(*readdir_type_t) (struct fs_node *, uint32_t);
typedef struct fs_node *(*finddir_type_t) (struct fs_node *, char *name);
2012-01-26 05:25:59 +04:00
typedef void (*create_type_t) (struct fs_node *, char *name, uint16_t permission);
typedef void (*unlink_type_t) (struct fs_node *, char *name);
2012-01-26 05:25:59 +04:00
typedef void (*mkdir_type_t) (struct fs_node *, char *name, uint16_t permission);
2013-03-19 10:57:40 +04:00
typedef int (*ioctl_type_t) (struct fs_node *, int request, void * argp);
2013-03-22 22:58:22 +04:00
typedef int (*get_size_type_t) (struct fs_node *);
typedef int (*chmod_type_t) (struct fs_node *, int mode);
2011-01-22 10:09:47 +03:00
typedef struct fs_node {
char name[256]; /* The filename. */
void * device; /* Device object (optional) */
uint32_t mask; /* The permissions mask. */
uint32_t uid; /* The owning user. */
uint32_t gid; /* The owning group. */
uint32_t flags; /* Flags (node type, etc). */
uint32_t inode; /* Inode number. */
uint32_t length; /* Size of the file, in byte. */
uint32_t impl; /* Used to keep track which fs it belongs to. */
uint32_t open_flags; /* Flags passed to open (read/write/append, etc.) */
2013-03-26 08:48:16 +04:00
/* times */
uint32_t atime; /* Accessed */
uint32_t mtime; /* Modified */
uint32_t ctime; /* Created */
2013-03-26 08:48:16 +04:00
/* File operations */
2011-01-31 02:00:38 +03:00
read_type_t read;
write_type_t write;
open_type_t open;
close_type_t close;
readdir_type_t readdir;
finddir_type_t finddir;
2012-01-26 05:25:59 +04:00
create_type_t create;
mkdir_type_t mkdir;
2013-03-19 10:57:40 +04:00
ioctl_type_t ioctl;
2013-03-22 22:58:22 +04:00
get_size_type_t get_size;
chmod_type_t chmod;
unlink_type_t unlink;
2013-03-26 08:48:16 +04:00
struct fs_node *ptr; /* Alias pointer, for symlinks. */
uint32_t offset; /* Offset for read operations XXX move this to new "file descriptor" entry */
int32_t shared_with; /* File descriptor sharing XXX */
2011-01-22 10:09:47 +03:00
} fs_node_t;
2011-01-22 10:38:25 +03:00
struct dirent {
uint32_t ino; /* Inode number. */
char name[256]; /* The filename. */
2011-01-22 10:38:25 +03:00
};
2012-01-27 13:12:29 +04:00
struct stat {
uint16_t st_dev;
uint16_t st_ino;
uint32_t st_mode;
uint16_t st_nlink;
2012-12-10 04:59:55 +04:00
uint16_t st_uid;
uint16_t st_gid;
2012-01-27 13:12:29 +04:00
uint16_t st_rdev;
uint32_t st_size;
2012-12-10 04:59:55 +04:00
uint32_t st_atime;
uint32_t __unused1;
uint32_t st_mtime;
uint32_t __unused2;
uint32_t st_ctime;
uint32_t __unused3;
2012-01-27 13:12:29 +04:00
};
extern fs_node_t *fs_root;
2013-06-06 10:10:36 +04:00
extern fs_node_t * null_device_create(void);
extern fs_node_t * zero_device_create(void);
extern fs_node_t * serial_device_create(int device);
2013-06-06 10:10:36 +04:00
extern fs_node_t * procfs_create(void);
extern fs_node_t * tmpfs_create(void);
extern void serial_mount_devices(void);
2013-03-18 03:34:23 +04:00
extern int openpty(int * master, int * slave, char * name, void * _ign0, void * size);
2013-03-15 11:20:55 +04:00
2013-06-06 10:10:36 +04:00
extern fs_node_t * hello_device_create(void);
extern fs_node_t * random_device_create(void);
2011-01-22 10:09:47 +03:00
2012-01-26 05:25:59 +04:00
uint32_t read_fs(fs_node_t *node, uint32_t offset, uint32_t size, uint8_t *buffer);
uint32_t write_fs(fs_node_t *node, uint32_t offset, uint32_t size, uint8_t *buffer);
void open_fs(fs_node_t *node, unsigned int flags);
2012-01-26 05:25:59 +04:00
void close_fs(fs_node_t *node);
struct dirent *readdir_fs(fs_node_t *node, uint32_t index);
fs_node_t *finddir_fs(fs_node_t *node, char *name);
2012-02-06 02:04:41 +04:00
int mkdir_fs(char *name, uint16_t permission);
int create_file_fs(char *name, uint16_t permission);
fs_node_t *kopen(char *filename, uint32_t flags);
2012-01-26 05:25:59 +04:00
char *canonicalize_path(char *cwd, char *input);
fs_node_t *clone_fs(fs_node_t * source);
2013-03-19 10:57:40 +04:00
int ioctl_fs(fs_node_t *node, int request, void * argp);
int chmod_fs(fs_node_t *node, int mode);
int unlink_fs(char * name);
2011-01-22 10:09:47 +03:00
2013-06-06 10:10:36 +04:00
void vfs_install(void);
2013-03-15 11:20:55 +04:00
int vfs_mount(char * path, fs_node_t * local_root);
/* Debug purposes only, please */
2013-06-06 10:10:36 +04:00
void debug_print_vfs_tree(void);
2013-03-15 11:20:55 +04:00
2011-01-22 10:09:47 +03:00
#endif