xdirentry.h 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  1. #ifndef MC_VFS_XDIRENTRY_H
  2. #define MC_VFS_XDIRENTRY_H
  3. #include <stdio.h>
  4. #include <sys/types.h>
  5. #define LINK_FOLLOW 15
  6. #define LINK_NO_FOLLOW -1
  7. /* For vfs_s_find_entry */
  8. #define FL_NONE 0
  9. #define FL_MKDIR 1
  10. #define FL_MKFILE 2
  11. #define FL_DIR 4
  12. /* For open_super */
  13. #define FL_NO_OPEN 1
  14. /* For vfs_s_entry_from_path */
  15. #define FL_FOLLOW 1
  16. #define FL_DIR 4
  17. /* For vfs_s_subclass->flags */
  18. #define VFS_S_REMOTE 1
  19. #define VFS_S_READONLY 2
  20. /* Single connection or archive */
  21. struct vfs_s_super {
  22. struct vfs_s_super **prevp, *next;
  23. struct vfs_class *me;
  24. struct vfs_s_inode *root;
  25. char *name; /* My name, whatever it means */
  26. int fd_usage; /* Number of open files */
  27. int ino_usage; /* Usage count of this superblock */
  28. int want_stale; /* If set, we do not flush cache properly */
  29. union {
  30. struct {
  31. int sockr, sockw;
  32. char *cwdir;
  33. char *host, *user;
  34. char *password;
  35. int flags;
  36. } fish;
  37. struct {
  38. int sock;
  39. char *cwdir;
  40. char *host, *user;
  41. char *password;
  42. int port;
  43. char *proxy; /* proxy server, NULL if no proxy */
  44. int failed_on_login; /* used to pass the failure reason to upper levels */
  45. int use_passive_connection;
  46. int remote_is_amiga; /* No leading slash allowed for AmiTCP (Amiga) */
  47. int isbinary;
  48. int cwd_deferred; /* current_directory was changed but CWD command hasn't
  49. been sent yet */
  50. int strict; /* ftp server doesn't understand
  51. "LIST -la <path>"; use "CWD <path>"/
  52. "LIST" instead */
  53. int ctl_connection_busy;
  54. } ftp;
  55. struct {
  56. int fd;
  57. struct stat st;
  58. int type; /* Type of the archive */
  59. struct defer_inode *deferred; /* List of inodes for which another entries may appear */
  60. } arch;
  61. } u;
  62. };
  63. /*
  64. * Single virtual file - directory entry. The same inode can have many
  65. * entries (i.e. hard links), but usually has only one.
  66. */
  67. struct vfs_s_entry {
  68. struct vfs_s_entry **prevp, *next; /* Pointers in the entry list */
  69. struct vfs_s_inode *dir; /* Directory we are in, i.e. our parent */
  70. char *name; /* Name of this entry */
  71. struct vfs_s_inode *ino; /* ... and its inode */
  72. };
  73. /* Single virtual file - inode */
  74. struct vfs_s_inode {
  75. struct vfs_s_super *super; /* Archive the file is on */
  76. struct vfs_s_entry *ent; /* Our entry in the parent directory -
  77. use only for directories because they
  78. cannot be hardlinked */
  79. struct vfs_s_entry *subdir; /* If this is a directory, its entry */
  80. struct stat st; /* Parameters of this inode */
  81. char *linkname; /* Symlink's contents */
  82. char *localname; /* Filename of local file, if we have one */
  83. struct timeval timestamp; /* Subclass specific */
  84. long data_offset; /* Subclass specific */
  85. };
  86. /* Data associated with an open file */
  87. struct vfs_s_fh {
  88. struct vfs_s_inode *ino;
  89. long pos; /* This is for module's use */
  90. int handle; /* This is for module's use, but if != -1, will be mc_close()d */
  91. int changed; /* Did this file change? */
  92. int linear; /* Is that file open with O_LINEAR? */
  93. union {
  94. struct {
  95. off_t got, total;
  96. int append;
  97. } fish;
  98. struct {
  99. int sock, append;
  100. } ftp;
  101. } u;
  102. };
  103. /*
  104. * One of our subclasses (tar, cpio, fish, ftpfs) with data and methods.
  105. * Extends vfs_class. Stored in the "data" field of vfs_class.
  106. */
  107. struct vfs_s_subclass {
  108. struct vfs_s_super *supers;
  109. int inode_counter;
  110. int flags; /* whether the subclass is remove, read-only etc */
  111. dev_t rdev;
  112. FILE *logfile;
  113. int flush; /* if set to 1, invalidate directory cache */
  114. int (*init_inode) (struct vfs_class *me, struct vfs_s_inode *ino); /* optional */
  115. void (*free_inode) (struct vfs_class *me, struct vfs_s_inode *ino); /* optional */
  116. int (*init_entry) (struct vfs_class *me, struct vfs_s_entry *entry); /* optional */
  117. void *(*archive_check) (struct vfs_class *me, const char *name, char *op); /* optional */
  118. int (*archive_same) (struct vfs_class *me, struct vfs_s_super *psup,
  119. const char *archive_name, char *op, void *cookie);
  120. int (*open_archive) (struct vfs_class *me, struct vfs_s_super *psup,
  121. const char *archive_name, char *op);
  122. void (*free_archive) (struct vfs_class *me,
  123. struct vfs_s_super *psup);
  124. int (*fh_open) (struct vfs_class *me, struct vfs_s_fh *fh, int flags,
  125. int mode);
  126. int (*fh_close) (struct vfs_class *me, struct vfs_s_fh *fh);
  127. struct vfs_s_entry *(*find_entry) (struct vfs_class *me,
  128. struct vfs_s_inode *root,
  129. const char *path, int follow, int flags);
  130. int (*dir_load) (struct vfs_class *me, struct vfs_s_inode *ino,
  131. char *path);
  132. int (*dir_uptodate) (struct vfs_class *me, struct vfs_s_inode *ino);
  133. int (*file_store) (struct vfs_class *me, struct vfs_s_fh *fh,
  134. char *path, char *localname);
  135. int (*linear_start) (struct vfs_class *me, struct vfs_s_fh *fh,
  136. off_t from);
  137. int (*linear_read) (struct vfs_class *me, struct vfs_s_fh *fh,
  138. void *buf, int len);
  139. void (*linear_close) (struct vfs_class *me, struct vfs_s_fh *fh);
  140. };
  141. /* entries and inodes */
  142. struct vfs_s_inode *vfs_s_new_inode (struct vfs_class *me,
  143. struct vfs_s_super *super,
  144. struct stat *initstat);
  145. struct vfs_s_entry *vfs_s_new_entry (struct vfs_class *me, const char *name,
  146. struct vfs_s_inode *inode);
  147. void vfs_s_free_entry (struct vfs_class *me, struct vfs_s_entry *ent);
  148. void vfs_s_insert_entry (struct vfs_class *me, struct vfs_s_inode *dir,
  149. struct vfs_s_entry *ent);
  150. struct stat *vfs_s_default_stat (struct vfs_class *me, mode_t mode);
  151. struct vfs_s_entry *vfs_s_generate_entry (struct vfs_class *me, const char *name,
  152. struct vfs_s_inode *parent,
  153. mode_t mode);
  154. struct vfs_s_inode *vfs_s_find_inode (struct vfs_class *me,
  155. const struct vfs_s_super *super,
  156. const char *path, int follow, int flags);
  157. struct vfs_s_inode *vfs_s_find_root (struct vfs_class *me,
  158. struct vfs_s_entry *entry);
  159. /* outside interface */
  160. void vfs_s_init_class (struct vfs_class *vclass,
  161. struct vfs_s_subclass *sub);
  162. const char *vfs_s_get_path_mangle (struct vfs_class *me, char *inname,
  163. struct vfs_s_super **archive, int flags);
  164. void vfs_s_invalidate (struct vfs_class *me, struct vfs_s_super *super);
  165. char *vfs_s_fullpath (struct vfs_class *me, struct vfs_s_inode *ino);
  166. /* network filesystems support */
  167. int vfs_s_select_on_two (int fd1, int fd2);
  168. int vfs_s_get_line (struct vfs_class *me, int sock, char *buf, int buf_len,
  169. char term);
  170. int vfs_s_get_line_interruptible (struct vfs_class *me, char *buffer,
  171. int size, int fd);
  172. /* misc */
  173. int vfs_s_retrieve_file (struct vfs_class *me, struct vfs_s_inode *ino);
  174. #define ERRNOR(a, b) do { me->verrno = a; return b; } while (0)
  175. #define MEDATA ((struct vfs_s_subclass *) me->data)
  176. #define FH ((struct vfs_s_fh *) fh)
  177. #define FH_SUPER FH->ino->super
  178. #define LS_NOT_LINEAR 0
  179. #define LS_LINEAR_CLOSED 1
  180. #define LS_LINEAR_OPEN 2
  181. #define LS_LINEAR_PREOPEN 3
  182. #endif