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