xdirentry.h 9.4 KB

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