vfs.h 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441
  1. #ifndef __VFS_H
  2. #define __VFS_H
  3. #ifdef USE_VFS
  4. #ifdef HAVE_MMAP
  5. #include <sys/mman.h>
  6. #endif
  7. /*
  8. * The following line is needed, because as usual, AIX pollutes every single
  9. * name space they can get their hands on
  10. */
  11. #undef vfs_type
  12. /* Our virtual file system layer */
  13. typedef void * vfsid;
  14. struct vfs_stamping;
  15. /*
  16. * Notice: Andrej Borsenkow <borsenkow.msk@sni.de> reports system
  17. * (RelianUNIX), where it is bad idea to define struct vfs. That system
  18. * has include called <sys/vfs.h>, which contains things like vfs_t.
  19. */
  20. typedef struct _vfs vfs;
  21. struct _vfs {
  22. vfs *next;
  23. char *name; /* "FIles over SHell" */
  24. int flags;
  25. #define F_EXEC 1 /* Filesystem needs to execute external programs */
  26. #define F_NET 2 /* Filesystem needs to access network */
  27. char *prefix; /* "fish:" */
  28. void *data; /* this is for filesystem's own use */
  29. int verrno; /* can't use errno because glibc2 might define errno as function */
  30. int (*init) (vfs *me);
  31. void (*done) (vfs *me);
  32. void (*fill_names) (vfs *me, void (*)(char *));
  33. int (*which) (vfs *me, char *path);
  34. void *(*open) (vfs *me, char *fname, int flags, int mode);
  35. int (*close) (void *vfs_info);
  36. int (*read) (void *vfs_info, char *buffer, int count);
  37. int (*write) (void *vfs_info, char *buf, int count);
  38. void *(*opendir) (vfs *me, char *dirname);
  39. void *(*readdir) (void *vfs_info);
  40. int (*closedir) (void *vfs_info);
  41. int (*telldir) (void *vfs_info);
  42. void (*seekdir) (void *vfs_info, int offset);
  43. int (*stat) (vfs *me, char *path, struct stat *buf);
  44. int (*lstat) (vfs *me, char *path, struct stat *buf);
  45. int (*fstat) (void *vfs_info, struct stat *buf);
  46. int (*chmod) (vfs *me, char *path, int mode);
  47. int (*chown) (vfs *me, char *path, int owner, int group);
  48. int (*utime) (vfs *me, char *path, struct utimbuf *times);
  49. int (*readlink) (vfs *me, char *path, char *buf, int size);
  50. int (*symlink) (vfs *me, char *n1, char *n2);
  51. int (*link) (vfs *me, char *p1, char *p2);
  52. int (*unlink) (vfs *me, char *path);
  53. int (*rename) (vfs *me, char *p1, char *p2);
  54. int (*chdir) (vfs *me, char *path);
  55. int (*ferrno) (vfs *me);
  56. int (*lseek) (void *vfs_info, off_t offset, int whence);
  57. int (*mknod) (vfs *me, char *path, int mode, int dev);
  58. vfsid (*getid) (vfs *me, char *path, struct vfs_stamping **
  59. parent);
  60. int (*nothingisopen) (vfsid id);
  61. void (*free) (vfsid id);
  62. char *(*getlocalcopy) (vfs *me, char *filename);
  63. int (*ungetlocalcopy) (vfs *me, char *filename, char *local,
  64. int has_changed);
  65. int (*mkdir) (vfs *me, char *path, mode_t mode);
  66. int (*rmdir) (vfs *me, char *path);
  67. int (*ctl) (void *vfs_info, int ctlop, int arg);
  68. int (*setctl) (vfs *me, char *path, int ctlop, char *arg);
  69. #ifdef HAVE_MMAP
  70. caddr_t (*mmap) (vfs *me, caddr_t addr, size_t len, int prot,
  71. int flags, void *vfs_info, off_t offset);
  72. int (*munmap) (vfs *me, caddr_t addr, size_t len,
  73. void *vfs_info);
  74. #endif
  75. };
  76. /*
  77. * This union is used to ensure that there is enough space for the
  78. * filename (d_name) when the dirent structure is created.
  79. */
  80. union vfs_dirent {
  81. struct dirent dent;
  82. char _extra_buffer [((int) &((struct dirent *)0)->d_name) +
  83. MC_MAXPATHLEN + 1];
  84. };
  85. /* Other file systems */
  86. extern vfs vfs_local_ops;
  87. extern vfs vfs_nil_ops;
  88. extern vfs vfs_tarfs_ops;
  89. extern vfs vfs_cpiofs_ops;
  90. extern vfs vfs_ftpfs_ops;
  91. extern vfs vfs_smbfs_ops;
  92. extern vfs vfs_fish_ops;
  93. extern vfs vfs_mcfs_ops;
  94. extern vfs vfs_extfs_ops;
  95. extern vfs vfs_sfs_ops;
  96. extern vfs vfs_undelfs_ops;
  97. struct vfs_stamping {
  98. vfs *v;
  99. vfsid id;
  100. struct vfs_stamping *parent; /* At the moment applies to tarfs only */
  101. struct vfs_stamping *next;
  102. struct timeval time;
  103. };
  104. void vfs_init (void);
  105. void vfs_shut (void);
  106. extern int vfs_type_absolute;
  107. vfs *vfs_type (char *path);
  108. vfs *vfs_split (char *path, char **inpath, char **op);
  109. vfsid vfs_ncs_getid (vfs *nvfs, char *dir, struct vfs_stamping **par);
  110. void vfs_rm_parents (struct vfs_stamping *stamp);
  111. char *vfs_path (char *path);
  112. char *vfs_strip_suffix_from_filename (const char *filename);
  113. char *vfs_canon (const char *path);
  114. char *mc_get_current_wd (char *buffer, int bufsize);
  115. int vfs_current_is_local (void);
  116. #if 0
  117. int vfs_current_is_extfs (void);
  118. int vfs_current_is_tarfs (void);
  119. int vfs_current_is_cpiofs (void);
  120. #endif
  121. int vfs_file_is_local (const char *name);
  122. int vfs_file_is_ftp (char *filename);
  123. int vfs_file_is_smb (char *filename);
  124. char *vfs_get_current_dir (void);
  125. extern int vfs_timeout;
  126. void vfs_stamp (vfs *, vfsid);
  127. void vfs_rmstamp (vfs *, vfsid, int);
  128. void vfs_addstamp (vfs *, vfsid, struct vfs_stamping *);
  129. void vfs_add_noncurrent_stamps (vfs *, vfsid, struct vfs_stamping *);
  130. void vfs_add_current_stamps (void);
  131. void vfs_free_resources(char *path);
  132. void vfs_timeout_handler (void);
  133. void vfs_expire (int);
  134. int vfs_timeouts (void);
  135. void vfs_fill_names (void (*)(char *));
  136. char *vfs_translate_url (char *);
  137. void ftpfs_set_debug (const char *file);
  138. #ifdef USE_NETCODE
  139. void ftpfs_hint_reread(int reread);
  140. void ftpfs_flushdir(void);
  141. extern int use_netrc;
  142. #else
  143. # define ftpfs_flushdir()
  144. # define ftpfs_hint_reread(x)
  145. #endif
  146. /* Only the routines outside of the VFS module need the emulation macros */
  147. int mc_open (const char *filename, int flags, ...);
  148. int mc_close (int handle);
  149. int mc_read (int handle, char *buffer, int count);
  150. int mc_write (int handle, char *buffer, int count);
  151. off_t mc_lseek (int fd, off_t offset, int whence);
  152. int mc_chdir (char *);
  153. DIR *mc_opendir (char *dirname);
  154. struct dirent *mc_readdir(DIR *dirp);
  155. int mc_closedir (DIR *dir);
  156. int mc_telldir (DIR *dir);
  157. void mc_seekdir (DIR *dir, int offset);
  158. int mc_stat (char *path, struct stat *buf);
  159. int mc_lstat (char *path, struct stat *buf);
  160. int mc_fstat (int fd, struct stat *buf);
  161. int mc_chmod (char *path, int mode);
  162. int mc_chown (char *path, int owner, int group);
  163. int mc_utime (char *path, struct utimbuf *times);
  164. int mc_readlink (char *path, char *buf, int bufsiz);
  165. int mc_unlink (char *path);
  166. int mc_symlink (char *name1, char *name2);
  167. int mc_link (const char *name1, const char *name2);
  168. int mc_mknod (char *, int, int);
  169. int mc_rename (const char *original, const char *target);
  170. int mc_write (int fd, char *buf, int nbyte);
  171. int mc_rmdir (char *path);
  172. int mc_mkdir (char *path, mode_t mode);
  173. char *mc_getlocalcopy (const char *pathname);
  174. int mc_ungetlocalcopy (const char *pathname, char *local, int has_changed);
  175. char *mc_def_getlocalcopy (vfs *vfs, char *filename);
  176. int mc_def_ungetlocalcopy (vfs *vfs, char *filename, char *local, int has_changed);
  177. int mc_ctl (int fd, int ctlop, int arg);
  178. int mc_setctl (char *path, int ctlop, char *arg);
  179. #ifdef HAVE_MMAP
  180. caddr_t mc_mmap (caddr_t, size_t, int, int, int, off_t);
  181. int mc_unmap (caddr_t, size_t);
  182. int mc_munmap (caddr_t addr, size_t len);
  183. #endif /* HAVE_MMAP */
  184. #else
  185. #ifdef USE_NETCODE
  186. # undef USE_NETCODE
  187. #endif
  188. # undef USE_NETCODE
  189. # define vfs_fill_names(x) do { } while (0)
  190. # define vfs_add_current_stamps() do { } while (0)
  191. # define vfs_current_is_local() 1
  192. # define vfs_file_is_local(x) 1
  193. # define vfs_file_is_ftp(x) 0
  194. # define vfs_file_is_smb(x) 0
  195. # define vfs_current_is_tarfs() 0
  196. # define vfs_current_is_cpiofs() 0
  197. # define vfs_current_is_extfs() 0
  198. # define vfs_path(x) x
  199. # define vfs_strip_suffix_from_filename(x) g_strdup(x)
  200. # define mc_close close
  201. # define mc_read read
  202. # define mc_write write
  203. # define mc_lseek lseek
  204. # define mc_opendir opendir
  205. # define mc_readdir readdir
  206. # define mc_closedir closedir
  207. # define mc_telldir telldir
  208. # define mc_seekdir seekdir
  209. # define mc_get_current_wd(x,size) get_current_wd (x, size)
  210. # define mc_fstat fstat
  211. # define mc_lstat lstat
  212. # define mc_readlink readlink
  213. # define mc_symlink symlink
  214. # define mc_rename rename
  215. # define mc_open open
  216. # define mc_utime utime
  217. # define mc_chmod chmod
  218. # define mc_chown chown
  219. # define mc_chdir chdir
  220. # define mc_unlink unlink
  221. # define mc_mmap mmap
  222. # define mc_munmap munmap
  223. # define mc_ctl(a,b,c) 0
  224. static inline int mc_setctl(a,b,c) { return 0; }
  225. # define vfs_translate_url(s) g_strdup(s)
  226. # define mc_stat stat
  227. # define mc_mknod mknod
  228. # define mc_link link
  229. # define mc_mkdir mkdir
  230. # define mc_rmdir rmdir
  231. # define is_special_prefix(x) 0
  232. # define vfs_type(x) (vfs *)(NULL)
  233. # define vfs_init() do { } while (0)
  234. # define vfs_shut() do { } while (0)
  235. # define vfs_canon(p) g_strdup (canonicalize_pathname(p))
  236. # define vfs_free_resources() do { } while (0)
  237. # define vfs_timeout_handler() do { } while (0)
  238. # define vfs_timeouts() 0
  239. # define vfs_force_expire() do { } while (0)
  240. typedef int vfs;
  241. # define mc_getlocalcopy(x) NULL
  242. # define mc_ungetlocalcopy(x,y,z) do { } while (0)
  243. # define ftpfs_hint_reread(x) do { } while (0)
  244. # define ftpfs_flushdir() do { } while (0)
  245. #ifdef NATIVE_WIN32
  246. # undef mc_rmdir
  247. #endif
  248. #ifdef NATIVE_WIN32
  249. # undef mc_ctl
  250. # undef mc_unlink
  251. # define mc_ctl(a,b,c) 0
  252. # ifndef __EMX__
  253. # undef mc_mkdir
  254. # define mc_mkdir(a,b) mkdir(a)
  255. # endif
  256. #endif
  257. #endif /* USE_VFS */
  258. #define mc_errno errno
  259. /* These functions are meant for use by vfs modules */
  260. extern int vfs_parse_ls_lga (const char *p, struct stat *s, char **filename, char **linkname);
  261. extern int vfs_split_text (char *p);
  262. extern int vfs_parse_filetype (char c);
  263. extern int vfs_parse_filemode (const char *p);
  264. extern int vfs_parse_filedate(int idx, time_t *t);
  265. extern void vfs_die (char *msg);
  266. extern char *vfs_get_password (char *msg);
  267. /* Flags for vfs_split_url() */
  268. #define URL_ALLOW_ANON 1
  269. #define URL_NOSLASH 2
  270. extern char *vfs_split_url (const char *path, char **host, char **user,
  271. int *port, char **pass, int default_port, int flags);
  272. #ifdef WITH_SMBFS
  273. /* Interface for requesting SMB credentials. */
  274. struct smb_authinfo {
  275. char *host;
  276. char *share;
  277. char *domain;
  278. char *user;
  279. char *password;
  280. };
  281. struct smb_authinfo *
  282. vfs_smb_get_authinfo (const char *host, const char *share, const char *domain,
  283. const char *user);
  284. #endif /* WITH_SMBFS */
  285. extern void vfs_print_stats (const char *fs_name, const char *action,
  286. const char *file_name, off_t have, off_t need);
  287. /* Don't use values 0..4 for a while -- 10/98, pavel@ucw.cz */
  288. #define MCCTL_REMOVELOCALCOPY 5
  289. #define MCCTL_IS_NOTREADY 6
  290. #define MCCTL_FORGET_ABOUT 7
  291. #define MCCTL_EXTFS_RUN 8
  292. /* These two make vfs layer give out potentially incorrect data, but
  293. they also make some operation 100 times faster. Use with caution. */
  294. #define MCCTL_WANT_STALE_DATA 9
  295. #define MCCTL_NO_STALE_DATA 10
  296. extern int vfs_flags;
  297. extern uid_t vfs_uid;
  298. extern gid_t vfs_gid;
  299. #define FL_ALWAYS_MAGIC 1
  300. #define FL_NO_MCFS 2
  301. #define FL_NO_FTPFS 4
  302. #define FL_NO_UNDELFS 8
  303. #define FL_NO_TARFS 16
  304. #define FL_NO_EXTFS 32
  305. #define FL_NO_SFS 64
  306. #define FL_NO_FISH 128
  307. #define FL_NO_LOCALHASH 0x20000000 /* When you never ever want vfs to work with regular files with # in name */
  308. #define FL_NO_CWDSETUP 0x40000000
  309. #define O_ALL (O_CREAT | O_EXCL | O_NOCTTY | O_NDELAY | O_SYNC | O_WRONLY | O_RDWR | O_RDONLY)
  310. /* Midnight commander code should _not_ use other flags than those
  311. listed above and O_APPEND */
  312. #if (O_ALL & O_APPEND)
  313. #warning "Unexpected problem with flags, O_LINEAR disabled, contact pavel@ucw.cz"
  314. #define O_LINEAR 0
  315. #define IS_LINEAR(a) 0
  316. #define NO_LINEAR(a) a
  317. #else
  318. #define O_LINEAR O_APPEND
  319. #define IS_LINEAR(a) ((a) == (O_RDONLY | O_LINEAR)) /* Return only 0 and 1 ! */
  320. #define NO_LINEAR(a) (((a) == (O_RDONLY | O_LINEAR)) ? O_RDONLY : (a))
  321. #endif
  322. /* O_LINEAR is strange beast, be carefull. If you open file asserting
  323. * O_RDONLY | O_LINEAR, you promise:
  324. *
  325. * a) to read file linearly from beginning to the end
  326. * b) not to open another file before you close this one
  327. * (this will likely go away in future)
  328. * as a special gift, you may
  329. * c) lseek() immediately after open(), giving ftpfs chance to
  330. * reget. Be warned that this lseek() can fail, and you _have_
  331. * to handle that gratefully.
  332. *
  333. * O_LINEAR allows filesystems not to create temporary file in some
  334. * cases (ftp transfer). -- pavel@ucw.cz
  335. */
  336. #ifdef HAVE_MMAP
  337. #define MMAPNULL , NULL, NULL
  338. #else
  339. #define MMAPNULL
  340. #endif
  341. /* And now some defines for our errors. */
  342. #ifdef ENOSYS
  343. #define E_NOTSUPP ENOSYS /* for use in vfs when module does not provide function */
  344. #else
  345. #define E_NOTSUPP EFAULT /* Does this happen? */
  346. #endif
  347. #ifdef ENOMSG
  348. #define E_UNKNOWN ENOMSG /* if we do not know what error happened */
  349. #else
  350. #define E_UNKNOWN EIO /* if we do not know what error happened */
  351. #endif
  352. #ifdef EREMOTEIO
  353. #define E_REMOTE EREMOTEIO /* if other side of ftp/fish reports error */
  354. #else
  355. #define E_REMOTE ENETUNREACH /* :-( there's no EREMOTEIO on some systems */
  356. #endif
  357. #ifdef EPROTO
  358. #define E_PROTO EPROTO /* if other side fails to follow protocol */
  359. #else
  360. #define E_PROTO EIO
  361. #endif
  362. #endif /* __VFS_H */