4 * \brief Header: Virtual File System switch code
10 #include <sys/types.h>
20 int vfs_current_is_local (void);
21 int vfs_file_is_local (const char *filename
);
22 ssize_t
mc_read (int handle
, void *buffer
, int count
);
23 ssize_t
mc_write (int handle
, const void *buffer
, int count
);
24 int mc_utime (const char *path
, struct utimbuf
*times
);
25 int mc_readlink (const char *path
, char *buf
, int bufsiz
);
26 int mc_ungetlocalcopy (const char *pathname
, const char *local
, int has_changed
);
28 /* return encoding after last #enc: or NULL, if part does not contain #enc:
29 * return static buffer */
30 const char *vfs_get_encoding (const char *path
);
32 /* return new string */
33 char *vfs_translate_path_n (const char *path
);
35 #else /* ENABLE_VFS */
37 #define vfs_init() do { } while (0)
38 #define vfs_shut() do { } while (0)
39 #define vfs_current_is_local() (1)
40 #define vfs_file_is_local(x) (1)
42 #define mc_write write
43 #define mc_utime utime
44 #define mc_readlink readlink
45 #define mc_ungetlocalcopy(x,y,z) do { } while (0)
47 static inline const char *vfs_get_encoding (const char *path
)
53 /* return new string */
54 static inline char *vfs_translate_path_n (const char *path
)
56 return ((path
== NULL
) ? g_strdup ("") : g_strdup (path
));
59 static inline char* vfs_canon_and_translate(const char* path
)
66 if (path
[0] == PATH_SEP
)
68 char *curr_dir
= g_get_current_dir();
69 ret_str
= g_strdup_printf("%s" PATH_SEP_STR
"%s", curr_dir
, path
);
73 ret_str
= g_strdup(path
);
75 canonicalize_pathname (ret_str
);
79 #endif /* ENABLE_VFS */
81 char *vfs_strip_suffix_from_filename (const char *filename
);
82 char *vfs_canon (const char *path
);
83 char *mc_get_current_wd (char *buffer
, int bufsize
);
84 char *vfs_get_current_dir (void);
85 /* translate path back to terminal encoding, remove all #enc:
86 * every invalid character is replaced with question mark
87 * return static buffer */
88 char *vfs_translate_path (const char *path
);
89 /* canonize and translate path, return new string */
90 char *vfs_canon_and_translate (const char *path
);
92 char *vfs_translate_url (const char *url
);
94 /* Only the routines outside of the VFS module need the emulation macros */
96 int mc_open (const char *filename
, int flags
, ...);
97 int mc_close (int handle
);
98 off_t
mc_lseek (int fd
, off_t offset
, int whence
);
99 int mc_chdir (const char *path
);
101 DIR *mc_opendir (const char *dirname
);
102 struct dirent
*mc_readdir (DIR * dirp
);
103 int mc_closedir (DIR * dir
);
105 int mc_stat (const char *path
, struct stat
*buf
);
106 int mc_lstat (const char *path
, struct stat
*buf
);
107 int mc_fstat (int fd
, struct stat
*buf
);
109 int mc_chmod (const char *path
, mode_t mode
);
110 int mc_chown (const char *path
, uid_t owner
, gid_t group
);
111 int mc_unlink (const char *path
);
112 int mc_symlink (const char *name1
, const char *name2
);
113 int mc_link (const char *name1
, const char *name2
);
114 int mc_mknod (const char *, mode_t
, dev_t
);
115 int mc_rename (const char *original
, const char *target
);
116 int mc_rmdir (const char *path
);
117 int mc_mkdir (const char *path
, mode_t mode
);
119 char *mc_getlocalcopy (const char *pathname
);
120 int mc_ctl (int fd
, int ctlop
, void *arg
);
121 int mc_setctl (const char *path
, int ctlop
, void *arg
);
123 /* Operations for mc_ctl - on open file */
128 /* Operations for mc_setctl - on path */
133 VFS_SETCTL_FLUSH
, /* invalidate directory cache */
135 /* Setting this makes vfs layer give out potentially incorrect data,
136 but it also makes some operations much faster. Use with caution. */
137 VFS_SETCTL_STALE_DATA
140 #define O_ALL (O_CREAT | O_EXCL | O_NOCTTY | O_NDELAY | O_SYNC | O_WRONLY | O_RDWR | O_RDONLY)
141 /* Midnight commander code should _not_ use other flags than those
142 listed above and O_APPEND */
144 #if (O_ALL & O_APPEND)
145 #warning "Unexpected problem with flags, O_LINEAR disabled, contact pavel@ucw.cz"
147 #define IS_LINEAR(a) 0
148 #define NO_LINEAR(a) a
150 #define O_LINEAR O_APPEND
151 #define IS_LINEAR(a) ((a) == (O_RDONLY | O_LINEAR)) /* Return only 0 and 1 ! */
152 #define NO_LINEAR(a) (((a) == (O_RDONLY | O_LINEAR)) ? O_RDONLY : (a))
155 /* O_LINEAR is strange beast, be careful. If you open file asserting
156 * O_RDONLY | O_LINEAR, you promise:
158 * a) to read file linearly from beginning to the end
159 * b) not to open another file before you close this one
160 * (this will likely go away in future)
161 * as a special gift, you may
162 * c) lseek() immediately after open(), giving ftpfs chance to
163 * reget. Be warned that this lseek() can fail, and you _have_
164 * to handle that gratefully.
166 * O_LINEAR allows filesystems not to create temporary file in some
167 * cases (ftp transfer). -- pavel@ucw.cz
170 /* And now some defines for our errors. */
173 #define E_NOTSUPP ENOSYS /* for use in vfs when module does not provide function */
175 #define E_NOTSUPP EFAULT /* Does this happen? */
179 #define E_UNKNOWN ENOMSG /* if we do not know what error happened */
181 #define E_UNKNOWN EIO /* if we do not know what error happened */
185 #define E_REMOTE EREMOTEIO /* if other side of ftp/fish reports error */
187 #define E_REMOTE ENETUNREACH /* :-( there's no EREMOTEIO on some systems */
191 #define E_PROTO EPROTO /* if other side fails to follow protocol */