Following prototypes of functions was changed in VFS-module API:
[midnight-commander.git] / lib / vfs / vfs.h
blob5778feb8bfcb5663785a12d2725aa4c5a6ed88bd
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 <sys/stat.h>
12 #include <dirent.h>
13 #include <utime.h>
14 #include <stdio.h>
15 #include <fcntl.h>
16 #include <unistd.h>
17 #include <stddef.h>
19 #include "lib/global.h"
20 #include "lib/fs.h" /* MC_MAXPATHLEN */
22 #include "interface.h"
23 #include "path.h"
25 /*** typedefs(not structures) and defined constants **********************************************/
27 #if defined (ENABLE_VFS_FTP) || defined (ENABLE_VFS_FISH) || defined (ENABLE_VFS_SMB)
28 #define ENABLE_VFS_NET 1
29 #endif
31 /**
32 * This is the type of callback function passed to vfs_fill_names.
33 * It gets the name of the virtual file system as its first argument.
34 * See also:
35 * vfs_fill_names().
38 #define VFS_ENCODING_PREFIX "#enc:"
40 #define O_ALL (O_CREAT | O_EXCL | O_NOCTTY | O_NDELAY | O_SYNC | O_WRONLY | O_RDWR | O_RDONLY)
41 /* Midnight commander code should _not_ use other flags than those
42 listed above and O_APPEND */
44 #if (O_ALL & O_APPEND)
45 #warning "Unexpected problem with flags, O_LINEAR disabled, contact pavel@ucw.cz"
46 #define O_LINEAR 0
47 #define IS_LINEAR(a) 0
48 #define NO_LINEAR(a) a
49 #else
50 #define O_LINEAR O_APPEND
51 #define IS_LINEAR(a) ((a) == (O_RDONLY | O_LINEAR)) /* Return only 0 and 1 ! */
52 #define NO_LINEAR(a) (((a) == (O_RDONLY | O_LINEAR)) ? O_RDONLY : (a))
53 #endif
55 /* O_LINEAR is strange beast, be careful. If you open file asserting
56 * O_RDONLY | O_LINEAR, you promise:
58 * a) to read file linearly from beginning to the end
59 * b) not to open another file before you close this one
60 * (this will likely go away in future)
61 * as a special gift, you may
62 * c) lseek() immediately after open(), giving ftpfs chance to
63 * reget. Be warned that this lseek() can fail, and you _have_
64 * to handle that gratefully.
66 * O_LINEAR allows filesystems not to create temporary file in some
67 * cases (ftp transfer). -- pavel@ucw.cz
70 /* And now some defines for our errors. */
72 #ifdef ENOSYS
73 #define E_NOTSUPP ENOSYS /* for use in vfs when module does not provide function */
74 #else
75 #define E_NOTSUPP EFAULT /* Does this happen? */
76 #endif
78 #ifdef ENOMSG
79 #define E_UNKNOWN ENOMSG /* if we do not know what error happened */
80 #else
81 #define E_UNKNOWN EIO /* if we do not know what error happened */
82 #endif
84 #ifdef EREMOTEIO
85 #define E_REMOTE EREMOTEIO /* if other side of ftp/fish reports error */
86 #else
87 #define E_REMOTE ENETUNREACH /* :-( there's no EREMOTEIO on some systems */
88 #endif
90 #ifdef EPROTO
91 #define E_PROTO EPROTO /* if other side fails to follow protocol */
92 #else
93 #define E_PROTO EIO
94 #endif
96 typedef void (*fill_names_f) (const char *);
98 typedef void *vfsid;
100 /*** enums ***************************************************************************************/
102 /* Flags of VFS classes */
103 typedef enum
105 VFSF_UNKNOWN = 0,
106 VFSF_LOCAL = 1 << 0, /* Class is local (not virtual) filesystem */
107 VFSF_NOLINKS = 1 << 1 /* Hard links not supported */
108 } vfs_class_flags_t;
110 /* Operations for mc_ctl - on open file */
111 enum
113 VFS_CTL_IS_NOTREADY
116 /* Operations for mc_setctl - on path */
117 enum
119 VFS_SETCTL_FORGET,
120 VFS_SETCTL_RUN,
121 VFS_SETCTL_LOGFILE,
122 VFS_SETCTL_FLUSH, /* invalidate directory cache */
124 /* Setting this makes vfs layer give out potentially incorrect data,
125 but it also makes some operations much faster. Use with caution. */
126 VFS_SETCTL_STALE_DATA
129 /*** structures declarations (and typedefs of structures)*****************************************/
131 typedef struct vfs_class
133 const char *name; /* "FIles over SHell" */
134 vfs_class_flags_t flags;
135 const char *prefix; /* "fish:" */
136 void *data; /* this is for filesystem's own use */
137 int verrno; /* can't use errno because glibc2 might define errno as function */
139 int (*init) (struct vfs_class * me);
140 void (*done) (struct vfs_class * me);
143 * The fill_names method shall call the callback function for every
144 * filesystem name that this vfs module supports.
146 void (*fill_names) (struct vfs_class * me, fill_names_f);
149 * The which() method shall return the index of the vfs subsystem
150 * or -1 if this vfs cannot handle the given pathname.
152 int (*which) (struct vfs_class * me, const char *path);
154 void *(*open) (const vfs_path_t * vpath, int flags, mode_t mode);
155 int (*close) (void *vfs_info);
156 ssize_t (*read) (void *vfs_info, char *buffer, size_t count);
157 ssize_t (*write) (void *vfs_info, const char *buf, size_t count);
159 void *(*opendir) (const vfs_path_t * vpath);
160 void *(*readdir) (void *vfs_info);
161 int (*closedir) (void *vfs_info);
163 int (*stat) (const vfs_path_t * vpath, struct stat * buf);
164 int (*lstat) (const vfs_path_t * vpath, struct stat * buf);
165 int (*fstat) (void *vfs_info, struct stat * buf);
167 int (*chmod) (const vfs_path_t * vpath, int mode);
168 int (*chown) (const vfs_path_t * vpath, uid_t owner, gid_t group);
169 int (*utime) (const vfs_path_t * vpath, struct utimbuf * times);
171 int (*readlink) (const vfs_path_t * vpath, char *buf, size_t size);
172 int (*symlink) (const vfs_path_t * vpath1, const vfs_path_t * vpath2);
173 int (*link) (const vfs_path_t * vpath1, const vfs_path_t * vpath2);
174 int (*unlink) (const vfs_path_t * vpath);
175 int (*rename) (const vfs_path_t * vpath1, const vfs_path_t * vpath2);
176 int (*chdir) (const vfs_path_t * vpath);
177 int (*ferrno) (struct vfs_class * me);
178 off_t (*lseek) (void *vfs_info, off_t offset, int whence);
179 int (*mknod) (const vfs_path_t * vpath, mode_t mode, dev_t dev);
181 vfsid (*getid) (const vfs_path_t * vpath);
183 int (*nothingisopen) (vfsid id);
184 void (*free) (vfsid id);
186 char *(*getlocalcopy) (const vfs_path_t * vpath);
187 int (*ungetlocalcopy) (const vfs_path_t * vpath, const char *local, int has_changed);
189 int (*mkdir) (const vfs_path_t * vpath, mode_t mode);
190 int (*rmdir) (const vfs_path_t * vpath);
192 int (*ctl) (void *vfs_info, int ctlop, void *arg);
193 int (*setctl) (const vfs_path_t * vpath, int ctlop, void *arg);
194 } vfs_class;
197 * This union is used to ensure that there is enough space for the
198 * filename (d_name) when the dirent structure is created.
200 union vfs_dirent
202 struct dirent dent;
203 char _extra_buffer[offsetof (struct dirent, d_name) + MC_MAXPATHLEN + 1];
206 /*** global variables defined in .c file *********************************************************/
208 extern int vfs_timeout;
210 #ifdef ENABLE_VFS_NET
211 extern int use_netrc;
212 #endif
214 /*** declarations of public functions ************************************************************/
216 /* lib/vfs/direntry.c: */
217 void *vfs_s_open (const vfs_path_t * vpath, int flags, mode_t mode);
219 vfsid vfs_getid (const vfs_path_t * vpath);
221 void vfs_init (void);
222 void vfs_shut (void);
223 /* Register a file system class */
224 gboolean vfs_register_class (struct vfs_class *vfs);
226 void vfs_setup_work_dir (void);
228 void vfs_timeout_handler (void);
229 int vfs_timeouts (void);
230 void vfs_expire (int now);
232 char *vfs_get_current_dir (void);
233 gboolean vfs_current_is_local (void);
234 gboolean vfs_file_is_local (const char *filename);
236 char *vfs_canon (const char *path);
237 char *vfs_strip_suffix_from_filename (const char *filename);
238 char *vfs_translate_url (const char *url);
240 struct vfs_class *vfs_split (char *path, char **inpath, char **op);
241 char *vfs_path (const char *path);
243 struct vfs_class *vfs_get_class (const char *path);
244 vfs_class_flags_t vfs_file_class_flags (const char *filename);
246 /* return encoding after last #enc: or NULL, if part does not contain #enc:
247 * return static buffer */
248 const char *vfs_get_encoding (const char *path);
250 /* canonize and translate path, return new string */
251 char *vfs_canon_and_translate (const char *path);
252 /* translate path back to terminal encoding, remove all #enc:
253 * every invalid character is replaced with question mark
254 * return static buffer */
255 char *vfs_translate_path (const char *path);
256 /* return new string */
257 char *vfs_translate_path_n (const char *path);
259 void vfs_stamp_path (const char *path);
261 void vfs_release_path (const char *dir);
263 void vfs_fill_names (fill_names_f);
265 void vfs_print_message (const char *msg, ...) __attribute__ ((format (__printf__, 1, 2)));
267 int vfs_ferrno (struct vfs_class *vfs);
269 int vfs_new_handle (struct vfs_class *vclass, void *fsinfo);
271 struct vfs_class *vfs_class_find_by_handle (int handle);
273 void *vfs_class_data_find_by_handle (int handle);
275 void vfs_free_handle (int handle);
277 const char *_vfs_get_cwd (void);
279 /*** inline functions ****************************************************************************/
280 #endif /* MC_VFS_VFS_H */