vfs.h 4.4 KB

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