vfs.h 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  1. /**
  2. * \file
  3. * \brief Header: Virtual File System switch code
  4. */
  5. #ifndef MC__VFS_VFS_H
  6. #define MC__VFS_VFS_H
  7. #include <sys/types.h>
  8. #include <dirent.h>
  9. #include <utime.h>
  10. #include <stdio.h>
  11. #include "lib/global.h"
  12. /*** typedefs(not structures) and defined constants **********************************************/
  13. #if defined (ENABLE_VFS_FTP) || defined (ENABLE_VFS_FISH) || defined (ENABLE_VFS_SMB)
  14. #define ENABLE_VFS_NET 1
  15. #endif
  16. /**
  17. * This is the type of callback function passed to vfs_fill_names.
  18. * It gets the name of the virtual file system as its first argument.
  19. * See also:
  20. * vfs_fill_names().
  21. */
  22. #define VFS_ENCODING_PREFIX "#enc:"
  23. #define O_ALL (O_CREAT | O_EXCL | O_NOCTTY | O_NDELAY | O_SYNC | O_WRONLY | O_RDWR | O_RDONLY)
  24. /* Midnight commander code should _not_ use other flags than those
  25. listed above and O_APPEND */
  26. #if (O_ALL & O_APPEND)
  27. #warning "Unexpected problem with flags, O_LINEAR disabled, contact pavel@ucw.cz"
  28. #define O_LINEAR 0
  29. #define IS_LINEAR(a) 0
  30. #define NO_LINEAR(a) a
  31. #else
  32. #define O_LINEAR O_APPEND
  33. #define IS_LINEAR(a) ((a) == (O_RDONLY | O_LINEAR)) /* Return only 0 and 1 ! */
  34. #define NO_LINEAR(a) (((a) == (O_RDONLY | O_LINEAR)) ? O_RDONLY : (a))
  35. #endif
  36. /* O_LINEAR is strange beast, be careful. If you open file asserting
  37. * O_RDONLY | O_LINEAR, you promise:
  38. *
  39. * a) to read file linearly from beginning to the end
  40. * b) not to open another file before you close this one
  41. * (this will likely go away in future)
  42. * as a special gift, you may
  43. * c) lseek() immediately after open(), giving ftpfs chance to
  44. * reget. Be warned that this lseek() can fail, and you _have_
  45. * to handle that gratefully.
  46. *
  47. * O_LINEAR allows filesystems not to create temporary file in some
  48. * cases (ftp transfer). -- pavel@ucw.cz
  49. */
  50. /* And now some defines for our errors. */
  51. #ifdef ENOSYS
  52. #define E_NOTSUPP ENOSYS /* for use in vfs when module does not provide function */
  53. #else
  54. #define E_NOTSUPP EFAULT /* Does this happen? */
  55. #endif
  56. #ifdef ENOMSG
  57. #define E_UNKNOWN ENOMSG /* if we do not know what error happened */
  58. #else
  59. #define E_UNKNOWN EIO /* if we do not know what error happened */
  60. #endif
  61. #ifdef EREMOTEIO
  62. #define E_REMOTE EREMOTEIO /* if other side of ftp/fish reports error */
  63. #else
  64. #define E_REMOTE ENETUNREACH /* :-( there's no EREMOTEIO on some systems */
  65. #endif
  66. #ifdef EPROTO
  67. #define E_PROTO EPROTO /* if other side fails to follow protocol */
  68. #else
  69. #define E_PROTO EIO
  70. #endif
  71. typedef void (*fill_names_f) (const char *);
  72. /*** enums ***************************************************************************************/
  73. /* Flags of VFS classes */
  74. typedef enum
  75. {
  76. VFSF_UNKNOWN = 0,
  77. VFSF_LOCAL = 1 << 0, /* Class is local (not virtual) filesystem */
  78. VFSF_NOLINKS = 1 << 1 /* Hard links not supported */
  79. } vfs_class_flags_t;
  80. /* Operations for mc_ctl - on open file */
  81. enum
  82. {
  83. VFS_CTL_IS_NOTREADY
  84. };
  85. /* Operations for mc_setctl - on path */
  86. enum
  87. {
  88. VFS_SETCTL_FORGET,
  89. VFS_SETCTL_RUN,
  90. VFS_SETCTL_LOGFILE,
  91. VFS_SETCTL_FLUSH, /* invalidate directory cache */
  92. /* Setting this makes vfs layer give out potentially incorrect data,
  93. but it also makes some operations much faster. Use with caution. */
  94. VFS_SETCTL_STALE_DATA
  95. };
  96. /*** structures declarations (and typedefs of structures)*****************************************/
  97. struct vfs_class;
  98. /*** global variables defined in .c file *********************************************************/
  99. extern int vfs_timeout;
  100. #ifdef ENABLE_VFS_NET
  101. extern int use_netrc;
  102. #endif
  103. /*** declarations of public functions ************************************************************/
  104. void vfs_init (void);
  105. void vfs_shut (void);
  106. void vfs_timeout_handler (void);
  107. int vfs_timeouts (void);
  108. void vfs_expire (int now);
  109. gboolean vfs_current_is_local (void);
  110. gboolean vfs_file_is_local (const char *filename);
  111. ssize_t mc_read (int handle, void *buffer, size_t count);
  112. ssize_t mc_write (int handle, const void *buffer, size_t count);
  113. int mc_utime (const char *path, struct utimbuf *times);
  114. int mc_readlink (const char *path, char *buf, size_t bufsiz);
  115. int mc_ungetlocalcopy (const char *pathname, const char *local, int has_changed);
  116. int mc_close (int handle);
  117. off_t mc_lseek (int fd, off_t offset, int whence);
  118. DIR *mc_opendir (const char *dirname);
  119. struct dirent *mc_readdir (DIR * dirp);
  120. int mc_closedir (DIR * dir);
  121. int mc_stat (const char *path, struct stat *buf);
  122. int mc_mknod (const char *path, mode_t mode, dev_t dev);
  123. int mc_link (const char *name1, const char *name2);
  124. int mc_mkdir (const char *path, mode_t mode);
  125. int mc_rmdir (const char *path);
  126. int mc_fstat (int fd, struct stat *buf);
  127. int mc_lstat (const char *path, struct stat *buf);
  128. int mc_symlink (const char *name1, const char *name2);
  129. int mc_rename (const char *original, const char *target);
  130. int mc_chmod (const char *path, mode_t mode);
  131. int mc_chown (const char *path, uid_t owner, gid_t group);
  132. int mc_chdir (const char *path);
  133. int mc_unlink (const char *path);
  134. int mc_ctl (int fd, int ctlop, void *arg);
  135. int mc_setctl (const char *path, int ctlop, void *arg);
  136. int mc_open (const char *filename, int flags, ...);
  137. char *mc_get_current_wd (char *buffer, size_t bufsize);
  138. char *vfs_canon (const char *path);
  139. char *mc_getlocalcopy (const char *pathname);
  140. char *vfs_strip_suffix_from_filename (const char *filename);
  141. char *vfs_translate_url (const char *url);
  142. struct vfs_class *vfs_get_class (const char *path);
  143. vfs_class_flags_t vfs_file_class_flags (const char *filename);
  144. /* return encoding after last #enc: or NULL, if part does not contain #enc:
  145. * return static buffer */
  146. const char *vfs_get_encoding (const char *path);
  147. /* return new string */
  148. char *vfs_translate_path_n (const char *path);
  149. /* canonize and translate path, return new string */
  150. char *vfs_canon_and_translate (const char *path);
  151. void vfs_stamp_path (const char *path);
  152. void vfs_release_path (const char *dir);
  153. void vfs_fill_names (fill_names_f);
  154. char *vfs_get_current_dir (void);
  155. /* translate path back to terminal encoding, remove all #enc:
  156. * every invalid character is replaced with question mark
  157. * return static buffer */
  158. char *vfs_translate_path (const char *path);
  159. /*** inline functions ****************************************************************************/
  160. #endif /* MC_VFS_VFS_H */