vfs.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411
  1. #ifndef __VFS_H
  2. #define __VFS_H
  3. #include <config.h>
  4. #include <sys/stat.h>
  5. #include <dirent.h>
  6. #if 0
  7. #include "src/mad.h"
  8. #endif
  9. #if !defined(SCO_FLAVOR) || !defined(_SYS_SELECT_H)
  10. # include <sys/time.h> /* alex: this redefines struct timeval */
  11. #endif /* SCO_FLAVOR */
  12. #ifdef HAVE_UTIME_H
  13. # include <utime.h>
  14. #else
  15. struct utimbuf {
  16. time_t actime;
  17. time_t modtime;
  18. };
  19. #endif
  20. #ifdef USE_VFS
  21. #ifdef HAVE_MMAP
  22. #include <sys/mman.h>
  23. #endif
  24. #ifdef VFS_STANDALONE
  25. #undef USE_EXT2FSLIB
  26. #else
  27. #undef BROKEN_PATHS
  28. /*
  29. * Define this to allow /any/path/#ftp/ to access ftp tree. Broken, yes.
  30. */
  31. #endif
  32. /* Our virtual file system layer */
  33. typedef void * vfsid;
  34. struct vfs_stamping;
  35. /*
  36. * Notice: Andrej Borsenkow <borsenkow.msk@sni.de> reports system
  37. * (RelianUNIX), where it is bad idea to define struct vfs. That system
  38. * has include called <sys/vfs.h>, which contains things like vfs_t.
  39. */
  40. typedef struct _vfs vfs;
  41. struct _vfs {
  42. vfs *next;
  43. char *name; /* "FIles over SHell" */
  44. int flags;
  45. #define F_EXEC 1
  46. #define F_NET 2
  47. char *prefix; /* "fish:" */
  48. void *data; /* this is for filesystem's own use */
  49. int verrno; /* can't use errno because glibc2 might define errno as function */
  50. int (*init) (vfs *me);
  51. void (*done) (vfs *me);
  52. void (*fill_names) (vfs *me, void (*)(char *));
  53. int (*which) (vfs *me, char *path);
  54. void *(*open) (vfs *me, char *fname, int flags, int mode);
  55. int (*close) (void *vfs_info);
  56. int (*read) (void *vfs_info, char *buffer, int count);
  57. int (*write) (void *vfs_info, char *buf, int count);
  58. void *(*opendir) (vfs *me, char *dirname);
  59. void *(*readdir) (void *vfs_info);
  60. int (*closedir) (void *vfs_info);
  61. int (*telldir) (void *vfs_info);
  62. void (*seekdir) (void *vfs_info, int offset);
  63. int (*stat) (vfs *me, char *path, struct stat *buf);
  64. int (*lstat) (vfs *me, char *path, struct stat *buf);
  65. int (*fstat) (void *vfs_info, struct stat *buf);
  66. int (*chmod) (vfs *me, char *path, int mode);
  67. int (*chown) (vfs *me, char *path, int owner, int group);
  68. int (*utime) (vfs *me, char *path, struct utimbuf *times);
  69. int (*readlink) (vfs *me, char *path, char *buf, int size);
  70. int (*symlink) (vfs *me, char *n1, char *n2);
  71. int (*link) (vfs *me, char *p1, char *p2);
  72. int (*unlink) (vfs *me, char *path);
  73. int (*rename) (vfs *me, char *p1, char *p2);
  74. int (*chdir) (vfs *me, char *path);
  75. int (*ferrno) (vfs *me);
  76. int (*lseek) (void *vfs_info, off_t offset, int whence);
  77. int (*mknod) (vfs *me, char *path, int mode, int dev);
  78. vfsid (*getid) (vfs *me, char *path, struct vfs_stamping **
  79. parent);
  80. int (*nothingisopen) (vfsid id);
  81. void (*free) (vfsid id);
  82. char *(*getlocalcopy) (vfs *me, char *filename);
  83. void (*ungetlocalcopy) (vfs *me, char *filename, char *local,
  84. int has_changed);
  85. int (*mkdir) (vfs *me, char *path, mode_t mode);
  86. int (*rmdir) (vfs *me, char *path);
  87. int (*ctl) (void *vfs_info, int ctlop, int arg);
  88. int (*setctl) (vfs *me, char *path, int ctlop, char *arg);
  89. #ifdef HAVE_MMAP
  90. caddr_t (*mmap) (vfs *me, caddr_t addr, size_t len, int prot,
  91. int flags, void *vfs_info, off_t offset);
  92. int (*munmap) (vfs *me, caddr_t addr, size_t len,
  93. void *vfs_info);
  94. #endif
  95. };
  96. /* Other file systems */
  97. extern vfs vfs_local_ops;
  98. extern vfs vfs_tarfs_ops;
  99. extern vfs vfs_ftpfs_ops;
  100. extern vfs vfs_fish_ops;
  101. extern vfs vfs_mcfs_ops;
  102. extern vfs vfs_extfs_ops;
  103. extern vfs vfs_sfs_ops;
  104. extern vfs vfs_undelfs_ops;
  105. struct vfs_stamping {
  106. vfs *v;
  107. vfsid id;
  108. struct vfs_stamping *parent; /* At the moment applies to tarfs only */
  109. struct vfs_stamping *next;
  110. struct timeval time;
  111. };
  112. void vfs_init (void);
  113. void vfs_shut (void);
  114. extern int vfs_type_absolute;
  115. vfs *vfs_type (char *path);
  116. vfs *vfs_split (char *path, char **inpath, char **op);
  117. vfsid vfs_ncs_getid (vfs *nvfs, char *dir, struct vfs_stamping **par);
  118. void vfs_rm_parents (struct vfs_stamping *stamp);
  119. char *vfs_path (char *path);
  120. char *vfs_canon (char *path);
  121. char *mc_get_current_wd (char *buffer, int bufsize);
  122. int vfs_current_is_local (void);
  123. #if 0
  124. int vfs_current_is_extfs (void);
  125. int vfs_current_is_tarfs (void);
  126. #endif
  127. int vfs_file_is_local (char *name);
  128. int vfs_file_is_ftp (char *filename);
  129. char *vfs_get_current_dir (void);
  130. void vfs_stamp (vfs *, vfsid);
  131. void vfs_rmstamp (vfs *, vfsid, int);
  132. void vfs_addstamp (vfs *, vfsid, struct vfs_stamping *);
  133. void vfs_add_noncurrent_stamps (vfs *, vfsid, struct vfs_stamping *);
  134. void vfs_add_current_stamps (void);
  135. void vfs_free_resources(char *path);
  136. void vfs_timeout_handler ();
  137. int vfs_timeouts ();
  138. void vfs_fill_names (void (*)(char *));
  139. char *vfs_translate_url (char *);
  140. void ftpfs_set_debug (char *file);
  141. #ifdef USE_NETCODE
  142. void ftpfs_hint_reread(int reread);
  143. void ftpfs_flushdir(void);
  144. #else
  145. # define ftpfs_flushdir()
  146. # define ftpfs_hint_reread(x)
  147. #endif
  148. /* Only the routines outside of the VFS module need the emulation macros */
  149. int mc_open (char *file, int flags, ...);
  150. int mc_close (int handle);
  151. int mc_read (int handle, char *buffer, int count);
  152. int mc_write (int hanlde, char *buffer, int count);
  153. off_t mc_lseek (int fd, off_t offset, int whence);
  154. int mc_chdir (char *);
  155. DIR *mc_opendir (char *dirname);
  156. struct dirent *mc_readdir(DIR *dirp);
  157. int mc_closedir (DIR *dir);
  158. int mc_telldir (DIR *dir);
  159. void mc_seekdir (DIR *dir, int offset);
  160. int mc_stat (char *path, struct stat *buf);
  161. int mc_lstat (char *path, struct stat *buf);
  162. int mc_fstat (int fd, struct stat *buf);
  163. int mc_chmod (char *path, int mode);
  164. int mc_chown (char *path, int owner, int group);
  165. int mc_utime (char *path, struct utimbuf *times);
  166. int mc_readlink (char *path, char *buf, int bufsiz);
  167. int mc_unlink (char *path);
  168. int mc_symlink (char *name1, char *name2);
  169. int mc_link (char *name1, char *name2);
  170. int mc_mknod (char *, int, int);
  171. int mc_rename (char *original, char *target);
  172. int mc_write (int fd, char *buf, int nbyte);
  173. int mc_rmdir (char *path);
  174. int mc_mkdir (char *path, mode_t mode);
  175. char *mc_getlocalcopy (char *filename);
  176. void mc_ungetlocalcopy (char *filename, char *local, int has_changed);
  177. char *mc_def_getlocalcopy (vfs *vfs, char *filename);
  178. void mc_def_ungetlocalcopy (vfs *vfs, char *filename, char *local, int has_changed);
  179. int mc_ctl (int fd, int ctlop, int arg);
  180. int mc_setctl (char *path, int ctlop, char *arg);
  181. #ifdef HAVE_MMAP
  182. caddr_t mc_mmap (caddr_t, size_t, int, int, int, off_t);
  183. int mc_unmap (caddr_t, size_t);
  184. int mc_munmap (caddr_t addr, size_t len);
  185. #endif /* HAVE_MMAP */
  186. #else
  187. #ifdef USE_NETCODE
  188. # undef USE_NETCODE
  189. #endif
  190. # undef USE_NETCODE
  191. # define vfs_fill_names(x)
  192. # define vfs_add_current_stamps()
  193. # define vfs_current_is_local() 1
  194. # define vfs_file_is_local(x) 1
  195. # define vfs_file_is_ftp(x) 0
  196. # define vfs_current_is_tarfs() 0
  197. # define vfs_current_is_extfs() 0
  198. # define vfs_path(x) x
  199. # define mc_close close
  200. # define mc_read read
  201. # define mc_write write
  202. # define mc_lseek lseek
  203. # define mc_opendir opendir
  204. # define mc_readdir readdir
  205. # define mc_closedir closedir
  206. # define mc_telldir telldir
  207. # define mc_seekdir seekdir
  208. # define mc_get_current_wd(x,size) get_current_wd (x, size)
  209. # define mc_fstat fstat
  210. # define mc_lstat lstat
  211. # define mc_readlink readlink
  212. # define mc_symlink symlink
  213. # define mc_rename rename
  214. #ifndef __os2__
  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. #endif
  222. # define mc_mmap mmap
  223. # define mc_munmap munmap
  224. # define mc_ctl(a,b,c) 0
  225. # define mc_setctl(a,b,c)
  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()
  234. # define vfs_shut()
  235. # define vfs_canon(p) strdup (canonicalize_pathname(p))
  236. # define vfs_free_resources()
  237. # define vfs_timeout_handler()
  238. # define vfs_timeouts() 0
  239. # define vfs_force_expire()
  240. typedef int vfs;
  241. # define mc_getlocalcopy(x) NULL
  242. # define mc_ungetlocalcopy(x,y,z)
  243. # define ftpfs_hint_reread(x)
  244. # define ftpfs_flushdir()
  245. #ifdef _OS_NT
  246. # undef mc_rmdir
  247. #endif
  248. #ifdef OS2_NT
  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 (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 (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. extern char *vfs_split_url (char *path, char **host, char **user, int *port, char **pass,
  268. int default_port, int flags);
  269. #define URL_DEFAULTANON 1
  270. #define URL_NOSLASH 2
  271. extern void vfs_print_stats (char *fs_name, char *action, char *file_name, int have, int need);
  272. /* Dont use values 0..4 for a while -- 10/98, pavel@ucw.cz */
  273. #define MCCTL_REMOVELOCALCOPY 5
  274. #define MCCTL_IS_NOTREADY 6
  275. #define MCCTL_FORGET_ABOUT 7
  276. #define MCCTL_EXTFS_RUN 8
  277. /* These two make vfs layer give out potentially incorrect data, but
  278. they also make some operation 100 times faster. Use with caution. */
  279. #define MCCTL_WANT_STALE_DATA 9
  280. #define MCCTL_NO_STALE_DATA 10
  281. extern int vfs_flags;
  282. extern uid_t vfs_uid;
  283. extern gid_t vfs_gid;
  284. #define FL_ALWAYS_MAGIC 1
  285. #define FL_NO_MCFS 2
  286. #define FL_NO_FTPFS 4
  287. #define FL_NO_UNDELFS 8
  288. #define FL_NO_TARFS 16
  289. #define FL_NO_EXTFS 32
  290. #define FL_NO_SFS 64
  291. #define FL_NO_FISH 128
  292. #define FL_NO_CWDSETUP 0x40000000
  293. #ifdef VFS_STANDALONE
  294. extern void mc_vfs_init( void );
  295. extern void mc_vfs_done( void );
  296. #endif
  297. #define O_ALL (O_CREAT | O_EXCL | O_NOCTTY | O_NDELAY | O_SYNC | O_WRONLY | O_RDWR | O_RDONLY)
  298. /* Midnight commander code should _not_ use other flags than those
  299. listed above and O_APPEND */
  300. #if (O_ALL & O_APPEND)
  301. #warning Unexpected problem with flags, O_LINEAR disabled, contact pavel@ucw.cz
  302. #define O_LINEAR 0
  303. #define IS_LINEAR(a) 0
  304. #define NO_LINEAR(a) a
  305. #else
  306. #define O_LINEAR O_APPEND
  307. #define IS_LINEAR(a) ((a) == (O_RDONLY | O_LINEAR)) /* Return only 0 and 1 ! */
  308. #define NO_LINEAR(a) (((a) == (O_RDONLY | O_LINEAR)) ? O_RDONLY : (a))
  309. #endif
  310. /* O_LINEAR is strange beast, be carefull. If you open file asserting
  311. * O_RDONLY | O_LINEAR, you promise:
  312. *
  313. * a) to read file linearily from beggining to the end
  314. * b) not to open another file before you close this one
  315. * (this will likely go away in future)
  316. * as a special gift, you may
  317. * c) lseek() immediately after open(), giving ftpfs chance to
  318. * reget. Be warned that this lseek() can fail, and you _have_
  319. * to handle that gratefully.
  320. *
  321. * O_LINEAR allows filesystems not to create temporary file in some
  322. * cases (ftp transfer). -- pavel@ucw.cz
  323. */
  324. #define VFS_MIN(a,b) ((a)<(b) ? (a) : (b))
  325. #define VFS_MAX(a,b) ((a)<(b) ? (b) : (a))
  326. #ifdef HAVE_MMAP
  327. #define MMAPNULL , NULL, NULL
  328. #else
  329. #define MMAPNULL
  330. #endif
  331. #define DIR_SEP_CHAR '/'
  332. /* And now some defines for our errors. */
  333. #define E_NOTSUPP ENOSYS /* for use in vfs when module does not provide function */
  334. #define E_UNKNOWN ENOMSG /* if we do not know what error happened */
  335. #define E_REMOTE EREMOTEIO /* if other side of ftp/fish reports error */
  336. #define E_PROTO EPROTO /* if other side fails to follow protocol */
  337. #endif /* __VFS_H */