vfs.h 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  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. void vfs_init (void);
  11. void vfs_shut (void);
  12. char *vfs_strip_suffix_from_filename (const char *filename);
  13. char *vfs_canon (const char *path);
  14. char *mc_get_current_wd (char *buffer, int bufsize);
  15. char *vfs_get_current_dir (void);
  16. int vfs_current_is_local (void);
  17. int vfs_file_is_local (const char *filename);
  18. /* translate path back to terminal encoding, remove all #enc:
  19. * every invalid character is replaced with question mark
  20. * return static buffer */
  21. char *vfs_translate_path (const char *path);
  22. /* return new string */
  23. char *vfs_translate_path_n (const char *path);
  24. /* return encoding after last #enc: or NULL, if part does not contain #enc:
  25. * return static buffer */
  26. const char *vfs_get_encoding (const char *path);
  27. /* canonize and translate path, return new string */
  28. char *vfs_canon_and_translate (const char *path);
  29. char *vfs_translate_url (const char *url);
  30. /* Only the routines outside of the VFS module need the emulation macros */
  31. int mc_open (const char *filename, int flags, ...);
  32. int mc_close (int handle);
  33. ssize_t mc_read (int handle, void *buffer, int count);
  34. ssize_t mc_write (int handle, const void *buffer, int count);
  35. off_t mc_lseek (int fd, off_t offset, int whence);
  36. int mc_chdir (const char *path);
  37. DIR *mc_opendir (const char *dirname);
  38. struct dirent *mc_readdir (DIR * dirp);
  39. int mc_closedir (DIR * dir);
  40. int mc_stat (const char *path, struct stat *buf);
  41. int mc_lstat (const char *path, struct stat *buf);
  42. int mc_fstat (int fd, struct stat *buf);
  43. int mc_chmod (const char *path, mode_t mode);
  44. int mc_chown (const char *path, uid_t owner, gid_t group);
  45. int mc_utime (const char *path, struct utimbuf *times);
  46. int mc_readlink (const char *path, char *buf, int bufsiz);
  47. int mc_unlink (const char *path);
  48. int mc_symlink (const char *name1, const char *name2);
  49. int mc_link (const char *name1, const char *name2);
  50. int mc_mknod (const char *, mode_t, dev_t);
  51. int mc_rename (const char *original, const char *target);
  52. int mc_rmdir (const char *path);
  53. int mc_mkdir (const char *path, mode_t mode);
  54. char *mc_getlocalcopy (const char *pathname);
  55. int mc_ungetlocalcopy (const char *pathname, const char *local, int has_changed);
  56. int mc_ctl (int fd, int ctlop, void *arg);
  57. int mc_setctl (const char *path, int ctlop, void *arg);
  58. /* Operations for mc_ctl - on open file */
  59. enum {
  60. VFS_CTL_IS_NOTREADY
  61. };
  62. /* Operations for mc_setctl - on path */
  63. enum {
  64. VFS_SETCTL_FORGET,
  65. VFS_SETCTL_RUN,
  66. VFS_SETCTL_LOGFILE,
  67. VFS_SETCTL_FLUSH, /* invalidate directory cache */
  68. /* Setting this makes vfs layer give out potentially incorrect data,
  69. but it also makes some operations much faster. Use with caution. */
  70. VFS_SETCTL_STALE_DATA
  71. };
  72. #define O_ALL (O_CREAT | O_EXCL | O_NOCTTY | O_NDELAY | O_SYNC | O_WRONLY | O_RDWR | O_RDONLY)
  73. /* Midnight commander code should _not_ use other flags than those
  74. listed above and O_APPEND */
  75. #if (O_ALL & O_APPEND)
  76. #warning "Unexpected problem with flags, O_LINEAR disabled, contact pavel@ucw.cz"
  77. #define O_LINEAR 0
  78. #define IS_LINEAR(a) 0
  79. #define NO_LINEAR(a) a
  80. #else
  81. #define O_LINEAR O_APPEND
  82. #define IS_LINEAR(a) ((a) == (O_RDONLY | O_LINEAR)) /* Return only 0 and 1 ! */
  83. #define NO_LINEAR(a) (((a) == (O_RDONLY | O_LINEAR)) ? O_RDONLY : (a))
  84. #endif
  85. /* O_LINEAR is strange beast, be careful. If you open file asserting
  86. * O_RDONLY | O_LINEAR, you promise:
  87. *
  88. * a) to read file linearly from beginning to the end
  89. * b) not to open another file before you close this one
  90. * (this will likely go away in future)
  91. * as a special gift, you may
  92. * c) lseek() immediately after open(), giving ftpfs chance to
  93. * reget. Be warned that this lseek() can fail, and you _have_
  94. * to handle that gratefully.
  95. *
  96. * O_LINEAR allows filesystems not to create temporary file in some
  97. * cases (ftp transfer). -- pavel@ucw.cz
  98. */
  99. /* And now some defines for our errors. */
  100. #ifdef ENOSYS
  101. #define E_NOTSUPP ENOSYS /* for use in vfs when module does not provide function */
  102. #else
  103. #define E_NOTSUPP EFAULT /* Does this happen? */
  104. #endif
  105. #ifdef ENOMSG
  106. #define E_UNKNOWN ENOMSG /* if we do not know what error happened */
  107. #else
  108. #define E_UNKNOWN EIO /* if we do not know what error happened */
  109. #endif
  110. #ifdef EREMOTEIO
  111. #define E_REMOTE EREMOTEIO /* if other side of ftp/fish reports error */
  112. #else
  113. #define E_REMOTE ENETUNREACH /* :-( there's no EREMOTEIO on some systems */
  114. #endif
  115. #ifdef EPROTO
  116. #define E_PROTO EPROTO /* if other side fails to follow protocol */
  117. #else
  118. #define E_PROTO EIO
  119. #endif
  120. #endif