vfs.h 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279
  1. #ifndef __VFS_H
  2. #define __VFS_H
  3. #ifdef HAVE_MMAP
  4. #include <sys/mman.h>
  5. #endif
  6. typedef void *vfsid;
  7. struct vfs_stamping {
  8. struct vfs_class *v;
  9. vfsid id;
  10. struct vfs_stamping *parent; /* At the moment applies to tarfs only */
  11. struct vfs_stamping *next;
  12. struct timeval time;
  13. };
  14. /* Flags of VFS classes */
  15. #define VFSF_LOCAL 1 /* Class is local (not virtual) filesystem */
  16. #define VFSF_NOLINKS 2 /* Hard links not supported */
  17. struct vfs_class {
  18. struct vfs_class *next;
  19. char *name; /* "FIles over SHell" */
  20. int flags;
  21. char *prefix; /* "fish:" */
  22. void *data; /* this is for filesystem's own use */
  23. int verrno; /* can't use errno because glibc2 might define errno as function */
  24. int (*init) (struct vfs_class *me);
  25. void (*done) (struct vfs_class *me);
  26. void (*fill_names) (struct vfs_class *me, void (*)(char *));
  27. int (*which) (struct vfs_class *me, char *path);
  28. void *(*open) (struct vfs_class *me, const char *fname, int flags,
  29. int mode);
  30. int (*close) (void *vfs_info);
  31. int (*read) (void *vfs_info, char *buffer, int count);
  32. int (*write) (void *vfs_info, char *buf, int count);
  33. void *(*opendir) (struct vfs_class *me, char *dirname);
  34. void *(*readdir) (void *vfs_info);
  35. int (*closedir) (void *vfs_info);
  36. int (*stat) (struct vfs_class *me, char *path, struct stat * buf);
  37. int (*lstat) (struct vfs_class *me, char *path, struct stat * buf);
  38. int (*fstat) (void *vfs_info, struct stat * buf);
  39. int (*chmod) (struct vfs_class *me, char *path, int mode);
  40. int (*chown) (struct vfs_class *me, char *path, int owner, int group);
  41. int (*utime) (struct vfs_class *me, char *path,
  42. struct utimbuf * times);
  43. int (*readlink) (struct vfs_class *me, char *path, char *buf,
  44. int size);
  45. int (*symlink) (struct vfs_class *me, char *n1, char *n2);
  46. int (*link) (struct vfs_class *me, char *p1, char *p2);
  47. int (*unlink) (struct vfs_class *me, char *path);
  48. int (*rename) (struct vfs_class *me, char *p1, char *p2);
  49. int (*chdir) (struct vfs_class *me, char *path);
  50. int (*ferrno) (struct vfs_class *me);
  51. int (*lseek) (void *vfs_info, off_t offset, int whence);
  52. int (*mknod) (struct vfs_class *me, char *path, int mode, int dev);
  53. vfsid (*getid) (struct vfs_class *me, const char *path,
  54. struct vfs_stamping ** parent);
  55. int (*nothingisopen) (vfsid id);
  56. void (*free) (vfsid id);
  57. char *(*getlocalcopy) (struct vfs_class *me, const char *filename);
  58. int (*ungetlocalcopy) (struct vfs_class *me, const char *filename,
  59. const char *local, int has_changed);
  60. int (*mkdir) (struct vfs_class *me, char *path, mode_t mode);
  61. int (*rmdir) (struct vfs_class *me, char *path);
  62. int (*ctl) (void *vfs_info, int ctlop, void *arg);
  63. int (*setctl) (struct vfs_class *me, char *path, int ctlop,
  64. void *arg);
  65. #ifdef HAVE_MMAP
  66. caddr_t (*mmap) (struct vfs_class *me, caddr_t addr, size_t len,
  67. int prot, int flags, void *vfs_info, off_t offset);
  68. int (*munmap) (struct vfs_class *me, caddr_t addr, size_t len,
  69. void *vfs_info);
  70. #endif
  71. };
  72. /*
  73. * This union is used to ensure that there is enough space for the
  74. * filename (d_name) when the dirent structure is created.
  75. */
  76. union vfs_dirent {
  77. struct dirent dent;
  78. char _extra_buffer[((int) &((struct dirent *) 0)->d_name) +
  79. MC_MAXPATHLEN + 1];
  80. };
  81. /* Register a file system class */
  82. int vfs_register_class (struct vfs_class *vfs);
  83. void init_cpiofs (void);
  84. void init_extfs (void);
  85. void init_fish (void);
  86. void init_ftpfs (void);
  87. void init_localfs (void);
  88. void init_mcfs (void);
  89. void init_sfs (void);
  90. void init_smbfs (void);
  91. void init_tarfs (void);
  92. void init_undelfs (void);
  93. void vfs_init (void);
  94. void vfs_shut (void);
  95. struct vfs_class *vfs_get_class (const char *path);
  96. struct vfs_class *vfs_split (const char *path, char **inpath, char **op);
  97. char *vfs_path (const char *path);
  98. char *vfs_strip_suffix_from_filename (const char *filename);
  99. char *vfs_canon (const char *path);
  100. char *mc_get_current_wd (char *buffer, int bufsize);
  101. char *vfs_get_current_dir (void);
  102. int vfs_current_is_local (void);
  103. int vfs_file_class_flags (const char *filename);
  104. static inline int
  105. vfs_file_is_local (const char *filename)
  106. {
  107. return vfs_file_class_flags (filename) & VFSF_LOCAL;
  108. }
  109. extern int vfs_timeout;
  110. void vfs_stamp (struct vfs_class *, vfsid);
  111. void vfs_rmstamp (struct vfs_class *, vfsid, int);
  112. void vfs_add_noncurrent_stamps (struct vfs_class *, vfsid, struct vfs_stamping *);
  113. void vfs_add_current_stamps (void);
  114. void vfs_timeout_handler (void);
  115. void vfs_expire (int);
  116. int vfs_timeouts (void);
  117. void vfs_release_path (const char *dir);
  118. void vfs_fill_names (void (*)(char *));
  119. char *vfs_translate_url (const char *);
  120. #ifdef USE_NETCODE
  121. extern int use_netrc;
  122. #endif
  123. /* Only the routines outside of the VFS module need the emulation macros */
  124. int mc_open (const char *filename, int flags, ...);
  125. int mc_close (int handle);
  126. int mc_read (int handle, char *buffer, int count);
  127. int mc_write (int handle, char *buffer, int count);
  128. off_t mc_lseek (int fd, off_t offset, int whence);
  129. int mc_chdir (char *);
  130. DIR *mc_opendir (char *dirname);
  131. struct dirent *mc_readdir (DIR * dirp);
  132. int mc_closedir (DIR * dir);
  133. int mc_stat (const char *path, struct stat *buf);
  134. int mc_lstat (const char *path, struct stat *buf);
  135. int mc_fstat (int fd, struct stat *buf);
  136. int mc_chmod (char *path, int mode);
  137. int mc_chown (char *path, int owner, int group);
  138. int mc_utime (char *path, struct utimbuf *times);
  139. int mc_readlink (char *path, char *buf, int bufsiz);
  140. int mc_unlink (char *path);
  141. int mc_symlink (char *name1, char *name2);
  142. int mc_link (const char *name1, const char *name2);
  143. int mc_mknod (char *, int, int);
  144. int mc_rename (const char *original, const char *target);
  145. int mc_rmdir (char *path);
  146. int mc_mkdir (char *path, mode_t mode);
  147. char *mc_getlocalcopy (const char *pathname);
  148. int mc_ungetlocalcopy (const char *pathname, char *local, int has_changed);
  149. int mc_ctl (int fd, int ctlop, void *arg);
  150. int mc_setctl (char *path, int ctlop, void *arg);
  151. #ifdef HAVE_MMAP
  152. caddr_t mc_mmap (caddr_t, size_t, int, int, int, off_t);
  153. int mc_munmap (caddr_t addr, size_t len);
  154. #endif /* HAVE_MMAP */
  155. #ifdef WITH_SMBFS
  156. /* Interface for requesting SMB credentials. */
  157. struct smb_authinfo {
  158. char *host;
  159. char *share;
  160. char *domain;
  161. char *user;
  162. char *password;
  163. };
  164. struct smb_authinfo *vfs_smb_get_authinfo (const char *host,
  165. const char *share,
  166. const char *domain,
  167. const char *user);
  168. #endif /* WITH_SMBFS */
  169. /* Operations for mc_ctl - on open file */
  170. enum {
  171. VFS_CTL_IS_NOTREADY
  172. };
  173. /* Operations for mc_setctl - on path */
  174. enum {
  175. VFS_SETCTL_FORGET,
  176. VFS_SETCTL_RUN,
  177. VFS_SETCTL_LOGFILE,
  178. VFS_SETCTL_FLUSH, /* invalidate directory cache */
  179. /* Setting this makes vfs layer give out potentially incorrect data,
  180. but it also makes some operations much faster. Use with caution. */
  181. VFS_SETCTL_STALE_DATA
  182. };
  183. #define O_ALL (O_CREAT | O_EXCL | O_NOCTTY | O_NDELAY | O_SYNC | O_WRONLY | O_RDWR | O_RDONLY)
  184. /* Midnight commander code should _not_ use other flags than those
  185. listed above and O_APPEND */
  186. #if (O_ALL & O_APPEND)
  187. #warning "Unexpected problem with flags, O_LINEAR disabled, contact pavel@ucw.cz"
  188. #define O_LINEAR 0
  189. #define IS_LINEAR(a) 0
  190. #define NO_LINEAR(a) a
  191. #else
  192. #define O_LINEAR O_APPEND
  193. #define IS_LINEAR(a) ((a) == (O_RDONLY | O_LINEAR)) /* Return only 0 and 1 ! */
  194. #define NO_LINEAR(a) (((a) == (O_RDONLY | O_LINEAR)) ? O_RDONLY : (a))
  195. #endif
  196. /* O_LINEAR is strange beast, be careful. If you open file asserting
  197. * O_RDONLY | O_LINEAR, you promise:
  198. *
  199. * a) to read file linearly from beginning to the end
  200. * b) not to open another file before you close this one
  201. * (this will likely go away in future)
  202. * as a special gift, you may
  203. * c) lseek() immediately after open(), giving ftpfs chance to
  204. * reget. Be warned that this lseek() can fail, and you _have_
  205. * to handle that gratefully.
  206. *
  207. * O_LINEAR allows filesystems not to create temporary file in some
  208. * cases (ftp transfer). -- pavel@ucw.cz
  209. */
  210. /* And now some defines for our errors. */
  211. #ifdef ENOSYS
  212. #define E_NOTSUPP ENOSYS /* for use in vfs when module does not provide function */
  213. #else
  214. #define E_NOTSUPP EFAULT /* Does this happen? */
  215. #endif
  216. #ifdef ENOMSG
  217. #define E_UNKNOWN ENOMSG /* if we do not know what error happened */
  218. #else
  219. #define E_UNKNOWN EIO /* if we do not know what error happened */
  220. #endif
  221. #ifdef EREMOTEIO
  222. #define E_REMOTE EREMOTEIO /* if other side of ftp/fish reports error */
  223. #else
  224. #define E_REMOTE ENETUNREACH /* :-( there's no EREMOTEIO on some systems */
  225. #endif
  226. #ifdef EPROTO
  227. #define E_PROTO EPROTO /* if other side fails to follow protocol */
  228. #else
  229. #define E_PROTO EIO
  230. #endif
  231. #endif /* __VFS_H */