vfs.h 3.9 KB

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