xdirentry.h 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  1. #ifndef DIRENTRY_H
  2. #define DIRENTRY_H
  3. #include <config.h>
  4. #include <stdio.h>
  5. #include <ctype.h>
  6. #include <string.h>
  7. #include <stdlib.h>
  8. #include <sys/types.h>
  9. #include <sys/stat.h>
  10. #include <fcntl.h>
  11. #include <unistd.h>
  12. #include <signal.h>
  13. #include <errno.h>
  14. #include <pwd.h>
  15. #include <grp.h>
  16. #include "../src/fs.h"
  17. #include "../src/util.h"
  18. #include "../src/mem.h"
  19. #include "../src/mad.h"
  20. #include "vfs.h"
  21. #define FOLLOW 15
  22. #define NO_FOLLOW -1
  23. /* For vfs_s_find_entry */
  24. #define FL_NONE 0
  25. #define FL_MKDIR 1
  26. #define FL_MKFILE 2
  27. #define FL_DIR 4
  28. /* For open_super */
  29. #define FL_NO_OPEN 1
  30. /* For vfs_s_entry_from_path */
  31. #define FL_FOLLOW 1
  32. #define FL_DIR 4
  33. typedef struct vfs_s_entry {
  34. struct vfs_s_entry **prevp, *next;
  35. struct vfs_s_inode *dir; /* Directory we are in - needed for invalidating directory when file in it changes */
  36. char *name; /* Name of this entry */
  37. struct vfs_s_inode *ino; /* ... and its inode */
  38. int magic;
  39. #define ENTRY_MAGIC 0x014512563
  40. } vfs_s_entry;
  41. typedef struct vfs_s_inode {
  42. struct vfs_s_entry *subdir;
  43. struct vfs_s_super *super;
  44. struct stat st; /* Parameters of this inode */
  45. char *linkname; /* Symlink's contents */
  46. char *localname; /* Filename of local file, if we have one */
  47. int flags;
  48. vfs_s_entry *ent; /* ftp needs this backpointer; don't use if you can avoid it */
  49. union {
  50. struct {
  51. long data_offset;
  52. } tar;
  53. struct {
  54. struct timeval timestamp;
  55. struct stat local_stat;
  56. } fish;
  57. } u;
  58. int magic;
  59. #define INODE_MAGIC 0x93451656
  60. } vfs_s_inode;
  61. typedef struct vfs_s_super {
  62. struct vfs_s_super **prevp, *next;
  63. vfs *me;
  64. vfs_s_inode *root;
  65. char *name; /* My name, whatever it means */
  66. int fd_usage; /* Usage count of this superblock */
  67. int want_stale; /* If set, we do not flush cache properly */
  68. union {
  69. struct {
  70. int fd;
  71. struct stat tarstat;
  72. } tar;
  73. struct {
  74. int sockr, sockw;
  75. char *home, *cwdir;
  76. char *host, *user;
  77. char *password;
  78. int flags;
  79. } fish;
  80. struct {
  81. int sockr, sockw;
  82. char *home, *cwdir;
  83. int isbinary;
  84. } ftp;
  85. } u;
  86. int magic;
  87. #define SUPER_MAGIC 0x915ac312
  88. } vfs_s_super;
  89. typedef struct vfs_s_fh {
  90. struct vfs_s_inode *ino;
  91. long pos; /* This is for module's use */
  92. int handle; /* This is for module's use, but if != -1, will be mc_close()d */
  93. int changed; /* Did this file change? */
  94. int linear; /* Is that file open with O_LINEAR? */
  95. union {
  96. struct {
  97. int got, total;
  98. } fish;
  99. } u;
  100. int magic;
  101. #define FH_MAGIC 0x91324682
  102. } vfs_s_fh;
  103. struct vfs_s_data {
  104. struct vfs_s_super *supers;
  105. int inode_counter;
  106. dev_t rdev;
  107. FILE *logfile;
  108. int (*init_inode) (vfs *me, vfs_s_inode *ino); /* optional */
  109. void (*free_inode) (vfs *me, vfs_s_inode *ino); /* optional */
  110. int (*init_entry) (vfs *me, vfs_s_entry *entry); /* optional */
  111. void* (*archive_check) (vfs *me, char *name, char *op); /* optional */
  112. int (*archive_same) (vfs *me, vfs_s_super *psup, char *archive_name, char *op, void *cookie);
  113. int (*open_archive) (vfs *me, vfs_s_super *psup, char *archive_name, char *op);
  114. void (*free_archive) (vfs *me, vfs_s_super *psup);
  115. int (*fh_open) (vfs *me, vfs_s_fh *fh, int flags, int mode);
  116. int (*fh_close) (vfs *me, vfs_s_fh *fh);
  117. vfs_s_entry* (*find_entry) (vfs *me, vfs_s_inode *root, char *path, int follow, int flags);
  118. int (*dir_load) (vfs *me, vfs_s_inode *ino, char *path);
  119. int (*dir_uptodate) (vfs *me, vfs_s_inode *ino);
  120. int (*file_store) (vfs *me, vfs_s_super *super, char *path, char *localname);
  121. int (*linear_start) (vfs *me, vfs_s_fh *fh, int from);
  122. int (*linear_read) (vfs *me, vfs_s_fh *fh, void *buf, int len);
  123. void (*linear_close) (vfs *me, vfs_s_fh *fh);
  124. };
  125. /* entries and inodes */
  126. vfs_s_inode *vfs_s_new_inode (vfs *me, vfs_s_super *super, struct stat *initstat);
  127. vfs_s_entry *vfs_s_new_entry (vfs *me, char *name, vfs_s_inode *inode);
  128. void vfs_s_free_entry (vfs *me, vfs_s_entry *ent);
  129. void vfs_s_insert_entry (vfs *me, vfs_s_inode *dir, vfs_s_entry *ent);
  130. struct stat *vfs_s_default_stat (vfs *me, mode_t mode);
  131. void vfs_s_add_dots (vfs *me, vfs_s_inode *dir, vfs_s_inode *parent);
  132. struct vfs_s_entry *vfs_s_generate_entry (vfs *me, char *name, struct vfs_s_inode *parent, mode_t mode);
  133. vfs_s_entry *vfs_s_automake(vfs *me, vfs_s_inode *dir, char *path, int flags);
  134. vfs_s_entry *vfs_s_find_entry_tree(vfs *me, vfs_s_inode *root, char *path, int follow, int flags);
  135. vfs_s_entry *vfs_s_find_entry_linear(vfs *me, vfs_s_inode *root, char *path, int follow, int flags);
  136. vfs_s_inode *vfs_s_find_inode(vfs *me, vfs_s_inode *root, char *path, int follow, int flags);
  137. vfs_s_inode *vfs_s_find_root(vfs *me, vfs_s_entry *entry);
  138. struct vfs_s_entry *vfs_s_resolve_symlink (vfs *me, vfs_s_entry *entry, int follow);
  139. /* superblock games */
  140. vfs_s_super *vfs_s_new_super (vfs *me);
  141. void vfs_s_free_super (vfs *me, vfs_s_super *super);
  142. /* outside interface */
  143. char *vfs_s_get_path_mangle (vfs *me, char *inname, vfs_s_super **archive, int flags);
  144. char *vfs_s_get_path (vfs *me, char *inname, vfs_s_super **archive, int flags);
  145. void vfs_s_invalidate (vfs *me, vfs_s_super *super);
  146. /* readdir & friends */
  147. vfs_s_super *vfs_s_super_from_path (vfs *me, char *name);
  148. vfs_s_inode *vfs_s_inode_from_path (vfs *me, char *name, int flags);
  149. void * vfs_s_opendir (vfs *me, char *dirname);
  150. void * vfs_s_readdir (void *data);
  151. int vfs_s_telldir (void *data);
  152. void vfs_s_seekdir (void *data, int offset);
  153. int vfs_s_closedir (void *data);
  154. int vfs_s_chdir (vfs *me, char *path);
  155. /* stat & friends */
  156. int vfs_s_stat (vfs *me, char *path, struct stat *buf);
  157. int vfs_s_lstat (vfs *me, char *path, struct stat *buf);
  158. int vfs_s_fstat (void *fh, struct stat *buf);
  159. int vfs_s_readlink (vfs *me, char *path, char *buf, int size);
  160. void *vfs_s_open (vfs *me, char *file, int flags, int mode);
  161. int vfs_s_read (void *fh, char *buffer, int count);
  162. int vfs_s_write (void *fh, char *buffer, int count);
  163. int vfs_s_lseek (void *fh, off_t offset, int whence);
  164. int vfs_s_close (void *fh);
  165. /* mc support */
  166. void vfs_s_fill_names (vfs *me, void (*func)(char *));
  167. int vfs_s_ferrno(vfs *me);
  168. void vfs_s_dump(vfs *me, char *prefix, vfs_s_inode *ino);
  169. char *vfs_s_getlocalcopy (vfs *me, char *path);
  170. /* stamping support */
  171. vfsid vfs_s_getid (vfs *me, char *path, struct vfs_stamping **parent);
  172. int vfs_s_nothingisopen (vfsid id);
  173. void vfs_s_free (vfsid id);
  174. int vfs_s_setctl (vfs *me, char *path, int ctlop, char *arg);
  175. /* network filesystems support */
  176. int vfs_s_select_on_two (int fd1, int fd2);
  177. int vfs_s_get_line (vfs *me, int sock, char *buf, int buf_len, char term);
  178. int vfs_s_get_line_interruptible (vfs *me, char *buffer, int size, int fd);
  179. /* If non-null, FREE */
  180. #define ifree(ptr) do { if (ptr) free(ptr); } while (0)
  181. #define MEDATA ((struct vfs_s_data *) me->data)
  182. #define ERRNOR(a, b) do { me->verrno = a; return b; } while (0)
  183. #define FH ((struct vfs_s_fh *) fh)
  184. #define FH_SUPER FH->ino->super
  185. #define LS_NOT_LINEAR 0
  186. #define LS_LINEAR_CLOSED 1
  187. #define LS_LINEAR_OPEN 2
  188. #endif