fs.h 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. /* vim: tabstop=4 shiftwidth=4 noexpandtab
  2. */
  3. #pragma once
  4. #define PATH_SEPARATOR '/'
  5. #define PATH_SEPARATOR_STRING "/"
  6. #define PATH_UP ".."
  7. #define PATH_DOT "."
  8. #define O_RDONLY 0x0000
  9. #define O_WRONLY 0x0001
  10. #define O_RDWR 0x0002
  11. #define O_APPEND 0x0008
  12. #define O_CREAT 0x0200
  13. #define O_TRUNC 0x0400
  14. #define O_EXCL 0x0800
  15. #define O_NOFOLLOW 0x1000
  16. #define O_PATH 0x2000
  17. #define FS_FILE 0x01
  18. #define FS_DIRECTORY 0x02
  19. #define FS_CHARDEVICE 0x04
  20. #define FS_BLOCKDEVICE 0x08
  21. #define FS_PIPE 0x10
  22. #define FS_SYMLINK 0x20
  23. #define FS_MOUNTPOINT 0x40
  24. #define _IFMT 0170000 /* type of file */
  25. #define _IFDIR 0040000 /* directory */
  26. #define _IFCHR 0020000 /* character special */
  27. #define _IFBLK 0060000 /* block special */
  28. #define _IFREG 0100000 /* regular */
  29. #define _IFLNK 0120000 /* symbolic link */
  30. #define _IFSOCK 0140000 /* socket */
  31. #define _IFIFO 0010000 /* fifo */
  32. struct fs_node;
  33. typedef uint32_t (*read_type_t) (struct fs_node *, uint32_t, uint32_t, uint8_t *);
  34. typedef uint32_t (*write_type_t) (struct fs_node *, uint32_t, uint32_t, uint8_t *);
  35. typedef void (*open_type_t) (struct fs_node *, unsigned int flags);
  36. typedef void (*close_type_t) (struct fs_node *);
  37. typedef struct dirent *(*readdir_type_t) (struct fs_node *, uint32_t);
  38. typedef struct fs_node *(*finddir_type_t) (struct fs_node *, char *name);
  39. typedef void (*create_type_t) (struct fs_node *, char *name, uint16_t permission);
  40. typedef void (*unlink_type_t) (struct fs_node *, char *name);
  41. typedef void (*mkdir_type_t) (struct fs_node *, char *name, uint16_t permission);
  42. typedef int (*ioctl_type_t) (struct fs_node *, int request, void * argp);
  43. typedef int (*get_size_type_t) (struct fs_node *);
  44. typedef int (*chmod_type_t) (struct fs_node *, int mode);
  45. typedef void (*symlink_type_t) (struct fs_node *, char * name, char * value);
  46. typedef int (*readlink_type_t) (struct fs_node *, char * buf, size_t size);
  47. typedef int (*selectcheck_type_t) (struct fs_node *);
  48. typedef int (*selectwait_type_t) (struct fs_node *, void * process);
  49. typedef int (*chown_type_t) (struct fs_node *, int, int);
  50. typedef struct fs_node {
  51. char name[256]; /* The filename. */
  52. void * device; /* Device object (optional) */
  53. uint32_t mask; /* The permissions mask. */
  54. uint32_t uid; /* The owning user. */
  55. uint32_t gid; /* The owning group. */
  56. uint32_t flags; /* Flags (node type, etc). */
  57. uint32_t inode; /* Inode number. */
  58. uint32_t length; /* Size of the file, in byte. */
  59. uint32_t impl; /* Used to keep track which fs it belongs to. */
  60. uint32_t open_flags; /* Flags passed to open (read/write/append, etc.) */
  61. /* times */
  62. uint32_t atime; /* Accessed */
  63. uint32_t mtime; /* Modified */
  64. uint32_t ctime; /* Created */
  65. /* File operations */
  66. read_type_t read;
  67. write_type_t write;
  68. open_type_t open;
  69. close_type_t close;
  70. readdir_type_t readdir;
  71. finddir_type_t finddir;
  72. create_type_t create;
  73. mkdir_type_t mkdir;
  74. ioctl_type_t ioctl;
  75. get_size_type_t get_size;
  76. chmod_type_t chmod;
  77. unlink_type_t unlink;
  78. symlink_type_t symlink;
  79. readlink_type_t readlink;
  80. struct fs_node *ptr; /* Alias pointer, for symlinks. */
  81. uint32_t offset; /* Offset for read operations XXX move this to new "file descriptor" entry */
  82. int32_t refcount;
  83. uint32_t nlink;
  84. selectcheck_type_t selectcheck;
  85. selectwait_type_t selectwait;
  86. chown_type_t chown;
  87. } fs_node_t;
  88. struct dirent {
  89. uint32_t ino; /* Inode number. */
  90. char name[256]; /* The filename. */
  91. };
  92. struct stat {
  93. uint16_t st_dev;
  94. uint16_t st_ino;
  95. uint32_t st_mode;
  96. uint16_t st_nlink;
  97. uint16_t st_uid;
  98. uint16_t st_gid;
  99. uint16_t st_rdev;
  100. uint32_t st_size;
  101. uint32_t st_atime;
  102. uint32_t __unused1;
  103. uint32_t st_mtime;
  104. uint32_t __unused2;
  105. uint32_t st_ctime;
  106. uint32_t __unused3;
  107. uint32_t st_blksize;
  108. uint32_t st_blocks;
  109. };
  110. struct vfs_entry {
  111. char * name;
  112. fs_node_t * file;
  113. char * device;
  114. char * fs_type;
  115. };
  116. extern fs_node_t *fs_root;
  117. extern int pty_create(void *size, fs_node_t ** fs_master, fs_node_t ** fs_slave);
  118. int has_permission(fs_node_t *node, int permission_bit);
  119. uint32_t read_fs(fs_node_t *node, uint32_t offset, uint32_t size, uint8_t *buffer);
  120. uint32_t write_fs(fs_node_t *node, uint32_t offset, uint32_t size, uint8_t *buffer);
  121. void open_fs(fs_node_t *node, unsigned int flags);
  122. void close_fs(fs_node_t *node);
  123. struct dirent *readdir_fs(fs_node_t *node, uint32_t index);
  124. fs_node_t *finddir_fs(fs_node_t *node, char *name);
  125. int mkdir_fs(char *name, uint16_t permission);
  126. int create_file_fs(char *name, uint16_t permission);
  127. fs_node_t *kopen(char *filename, uint32_t flags);
  128. char *canonicalize_path(char *cwd, char *input);
  129. fs_node_t *clone_fs(fs_node_t * source);
  130. int ioctl_fs(fs_node_t *node, int request, void * argp);
  131. int chmod_fs(fs_node_t *node, int mode);
  132. int chown_fs(fs_node_t *node, int uid, int gid);
  133. int unlink_fs(char * name);
  134. int symlink_fs(char * value, char * name);
  135. int readlink_fs(fs_node_t * node, char * buf, size_t size);
  136. int selectcheck_fs(fs_node_t * node);
  137. int selectwait_fs(fs_node_t * node, void * process);
  138. void vfs_install(void);
  139. void * vfs_mount(char * path, fs_node_t * local_root);
  140. typedef fs_node_t * (*vfs_mount_callback)(char * arg, char * mount_point);
  141. int vfs_register(char * name, vfs_mount_callback callback);
  142. int vfs_mount_type(char * type, char * arg, char * mountpoint);
  143. void vfs_lock(fs_node_t * node);
  144. /* Debug purposes only, please */
  145. void debug_print_vfs_tree(void);
  146. void map_vfs_directory(char *);
  147. int make_unix_pipe(fs_node_t ** pipes);