xdirentry.h 7.0 KB

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