xdirentry.h 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268
  1. #ifndef DIRENTRY_H
  2. #define DIRENTRY_H
  3. #include <stdio.h>
  4. #include <ctype.h>
  5. #include <string.h>
  6. #include <stdlib.h>
  7. #include <sys/types.h>
  8. #include <sys/stat.h>
  9. #include <unistd.h>
  10. #include <signal.h>
  11. #include <errno.h>
  12. #include <pwd.h>
  13. #include <grp.h>
  14. #include "vfs.h"
  15. #define LINK_FOLLOW 15
  16. #define LINK_NO_FOLLOW -1
  17. /* For vfs_s_find_entry */
  18. #define FL_NONE 0
  19. #define FL_MKDIR 1
  20. #define FL_MKFILE 2
  21. #define FL_DIR 4
  22. /* For open_super */
  23. #define FL_NO_OPEN 1
  24. /* For vfs_s_entry_from_path */
  25. #define FL_FOLLOW 1
  26. #define FL_DIR 4
  27. typedef struct vfs_s_entry {
  28. struct vfs_s_entry **prevp, *next;
  29. struct vfs_s_inode *dir; /* Directory we are in - needed for invalidating directory when file in it changes */
  30. char *name; /* Name of this entry */
  31. struct vfs_s_inode *ino; /* ... and its inode */
  32. /* int magic; */
  33. #define ENTRY_MAGIC 0x014512563
  34. } vfs_s_entry;
  35. typedef struct vfs_s_inode {
  36. struct vfs_s_entry *subdir;
  37. struct vfs_s_super *super;
  38. struct stat st; /* Parameters of this inode */
  39. char *linkname; /* Symlink's contents */
  40. char *localname; /* Filename of local file, if we have one */
  41. int flags;
  42. vfs_s_entry *ent; /* ftp needs this backpointer; don't use if you can avoid it */
  43. union {
  44. struct {
  45. long data_offset;
  46. } tar;
  47. struct {
  48. long offset;
  49. } cpio;
  50. struct {
  51. struct timeval timestamp;
  52. struct stat local_stat;
  53. } fish;
  54. struct {
  55. struct timeval timestamp;
  56. } ftp;
  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; /* Number of open files */
  67. int ino_usage; /* Usage count of this superblock */
  68. int want_stale; /* If set, we do not flush cache properly */
  69. union {
  70. struct {
  71. int fd;
  72. struct stat tarstat;
  73. } tar;
  74. struct {
  75. int sockr, sockw;
  76. char *cwdir;
  77. char *host, *user;
  78. char *password;
  79. int flags;
  80. } fish;
  81. struct {
  82. int sock;
  83. char *cwdir;
  84. char *host, *user;
  85. char *password;
  86. int port;
  87. char *proxy; /* proxy server, NULL if no proxy */
  88. int failed_on_login; /* used to pass the failure reason to upper levels */
  89. int use_source_route;
  90. int use_passive_connection;
  91. int remote_is_amiga; /* No leading slash allowed for AmiTCP (Amiga) */
  92. int isbinary;
  93. int cwd_defered; /* current_directory was changed but CWD command hasn't
  94. been sent yet */
  95. int strict; /* ftp server doesn't understand
  96. "LIST -la <path>"; use "CWD <path>"/
  97. "LIST" instead */
  98. int control_connection_buzy;
  99. #define RFC_AUTODETECT 0
  100. #define RFC_DARING 1
  101. #define RFC_STRICT 2
  102. } ftp;
  103. struct {
  104. int fd;
  105. struct stat stat;
  106. int type; /* Type of the archive */
  107. /*int pos; In case reentrancy will be needed */
  108. struct defer_inode *defered; /* List of inodes for which another entries may appear */
  109. } cpio;
  110. } u;
  111. /* int magic; */
  112. #define SUPER_MAGIC 0x915ac312
  113. } vfs_s_super;
  114. typedef struct vfs_s_fh {
  115. struct vfs_s_inode *ino;
  116. long pos; /* This is for module's use */
  117. int handle; /* This is for module's use, but if != -1, will be mc_close()d */
  118. int changed; /* Did this file change? */
  119. int linear; /* Is that file open with O_LINEAR? */
  120. union {
  121. struct {
  122. int got, total, append;
  123. } fish;
  124. struct {
  125. int sock, append;
  126. } ftp;
  127. } u;
  128. /* int magic; */
  129. #define FH_MAGIC 0x91324682
  130. } vfs_s_fh;
  131. struct vfs_s_data {
  132. struct vfs_s_super *supers;
  133. int inode_counter;
  134. dev_t rdev;
  135. FILE *logfile;
  136. int (*init_inode) (vfs *me, vfs_s_inode *ino); /* optional */
  137. void (*free_inode) (vfs *me, vfs_s_inode *ino); /* optional */
  138. int (*init_entry) (vfs *me, vfs_s_entry *entry); /* optional */
  139. void* (*archive_check) (vfs *me, char *name, char *op); /* optional */
  140. int (*archive_same) (vfs *me, vfs_s_super *psup, char *archive_name, char *op, void *cookie);
  141. int (*open_archive) (vfs *me, vfs_s_super *psup, char *archive_name, char *op);
  142. void (*free_archive) (vfs *me, vfs_s_super *psup);
  143. int (*fh_open) (vfs *me, vfs_s_fh *fh, int flags, int mode);
  144. int (*fh_close) (vfs *me, vfs_s_fh *fh);
  145. vfs_s_entry* (*find_entry) (vfs *me, vfs_s_inode *root, char *path, int follow, int flags);
  146. int (*dir_load) (vfs *me, vfs_s_inode *ino, char *path);
  147. int (*dir_uptodate) (vfs *me, vfs_s_inode *ino);
  148. int (*file_store) (vfs *me, vfs_s_fh *fh, char *path, char *localname);
  149. int (*linear_start) (vfs *me, vfs_s_fh *fh, int from);
  150. int (*linear_read) (vfs *me, vfs_s_fh *fh, void *buf, int len);
  151. void (*linear_close) (vfs *me, vfs_s_fh *fh);
  152. };
  153. /* entries and inodes */
  154. vfs_s_inode *vfs_s_new_inode (vfs *me, vfs_s_super *super,
  155. struct stat *initstat);
  156. vfs_s_entry *vfs_s_new_entry (vfs *me, char *name, vfs_s_inode *inode);
  157. void vfs_s_free_entry (vfs *me, vfs_s_entry *ent);
  158. void vfs_s_insert_entry (vfs *me, vfs_s_inode *dir,
  159. vfs_s_entry *ent);
  160. struct stat *vfs_s_default_stat (vfs *me, mode_t mode);
  161. void vfs_s_add_dots (vfs *me, vfs_s_inode *dir,
  162. vfs_s_inode *parent);
  163. vfs_s_entry *vfs_s_generate_entry (vfs *me, char *name,
  164. struct vfs_s_inode *parent, mode_t mode);
  165. vfs_s_entry *vfs_s_automake (vfs *me, vfs_s_inode *dir, char *path,
  166. int flags);
  167. vfs_s_entry *vfs_s_find_entry_tree (vfs *me, vfs_s_inode *root, char *path,
  168. int follow, int flags);
  169. vfs_s_entry *vfs_s_find_entry_linear (vfs *me, vfs_s_inode *root, char *path,
  170. int follow, int flags);
  171. vfs_s_inode *vfs_s_find_inode (vfs *me, vfs_s_inode *root, char *path,
  172. int follow, int flags);
  173. vfs_s_inode *vfs_s_find_root (vfs *me, vfs_s_entry *entry);
  174. vfs_s_entry *vfs_s_resolve_symlink (vfs *me, vfs_s_entry *entry, char *path,
  175. int follow);
  176. /* superblock games */
  177. vfs_s_super *vfs_s_new_super (vfs *me);
  178. void vfs_s_free_super (vfs *me, vfs_s_super *super);
  179. /* outside interface */
  180. char *vfs_s_get_path_mangle (vfs *me, char *inname, vfs_s_super **archive,
  181. int flags);
  182. char *vfs_s_get_path (vfs *me, char *inname, vfs_s_super **archive,
  183. int flags);
  184. void vfs_s_invalidate (vfs *me, vfs_s_super *super);
  185. char *vfs_s_fullpath (vfs *me, vfs_s_inode *ino);
  186. /* readdir & friends */
  187. vfs_s_super *vfs_s_super_from_path (vfs *me, char *name);
  188. vfs_s_inode *vfs_s_inode_from_path (vfs *me, char *name, int flags);
  189. void *vfs_s_opendir (vfs *me, char *dirname);
  190. void *vfs_s_readdir (void *data);
  191. int vfs_s_telldir (void *data);
  192. void vfs_s_seekdir (void *data, int offset);
  193. int vfs_s_closedir (void *data);
  194. int vfs_s_chdir (vfs *me, char *path);
  195. /* stat & friends */
  196. int vfs_s_stat (vfs *me, char *path, struct stat *buf);
  197. int vfs_s_lstat (vfs *me, char *path, struct stat *buf);
  198. int vfs_s_fstat (void *fh, struct stat *buf);
  199. int vfs_s_readlink (vfs *me, char *path, char *buf, int size);
  200. void *vfs_s_open (vfs *me, char *file, int flags, int mode);
  201. int vfs_s_read (void *fh, char *buffer, int count);
  202. int vfs_s_write (void *fh, char *buffer, int count);
  203. int vfs_s_lseek (void *fh, off_t offset, int whence);
  204. int vfs_s_close (void *fh);
  205. /* mc support */
  206. void vfs_s_fill_names (vfs *me, void (*func)(char *));
  207. int vfs_s_ferrno(vfs *me);
  208. void vfs_s_dump(vfs *me, char *prefix, vfs_s_inode *ino);
  209. char *vfs_s_getlocalcopy (vfs *me, char *path);
  210. /* stamping support */
  211. vfsid vfs_s_getid (vfs *me, char *path, struct vfs_stamping **parent);
  212. int vfs_s_nothingisopen (vfsid id);
  213. void vfs_s_free (vfsid id);
  214. int vfs_s_setctl (vfs *me, char *path, int ctlop, char *arg);
  215. /* network filesystems support */
  216. int vfs_s_select_on_two (int fd1, int fd2);
  217. int vfs_s_get_line (vfs *me, int sock, char *buf, int buf_len, char term);
  218. int vfs_s_get_line_interruptible (vfs *me, char *buffer, int size, int fd);
  219. /* misc */
  220. int vfs_s_retrieve_file (vfs *me, struct vfs_s_inode *ino);
  221. #if 0
  222. #define ERRNOR(a, b) do { me->verrno = a; return b; } while (0)
  223. #else
  224. #define ERRNOR(a, b) { me->verrno = a; return b; }
  225. #endif
  226. #define MEDATA ((struct vfs_s_data *) me->data)
  227. #define FH ((struct vfs_s_fh *) fh)
  228. #define FH_SUPER FH->ino->super
  229. #define LS_NOT_LINEAR 0
  230. #define LS_LINEAR_CLOSED 1
  231. #define LS_LINEAR_OPEN 2
  232. #endif