Last fuzzy trim
[midnight-commander.git] / vfs / vfs.h
blob63e6f0f28c946e279fcecfc8e242f8659fd63b46
1 #ifndef __VFS_H
2 #define __VFS_H
4 #ifdef USE_VFS
5 #ifdef HAVE_MMAP
6 #include <sys/mman.h>
7 #endif
9 #ifdef VFS_STANDALONE
10 #undef USE_EXT2FSLIB
11 #else
12 #undef BROKEN_PATHS
14 * Define this to allow /any/path/#ftp/ to access ftp tree. Broken, yes.
15 */
16 #endif
19 * The following line is needed, because as usual, AIX pollutes every single
20 * name space they can get their hands on
22 #undef vfs_type
24 /* Our virtual file system layer */
26 typedef void * vfsid;
28 struct vfs_stamping;
31 * Notice: Andrej Borsenkow <borsenkow.msk@sni.de> reports system
32 * (RelianUNIX), where it is bad idea to define struct vfs. That system
33 * has include called <sys/vfs.h>, which contains things like vfs_t.
36 typedef struct _vfs vfs;
38 struct _vfs {
39 vfs *next;
40 char *name; /* "FIles over SHell" */
41 int flags;
42 #define F_EXEC 1 /* Filesystem needs to execute external programs */
43 #define F_NET 2 /* Filesystem needs to access network */
44 char *prefix; /* "fish:" */
45 void *data; /* this is for filesystem's own use */
46 int verrno; /* can't use errno because glibc2 might define errno as function */
48 int (*init) (vfs *me);
49 void (*done) (vfs *me);
50 void (*fill_names) (vfs *me, void (*)(char *));
52 int (*which) (vfs *me, char *path);
54 void *(*open) (vfs *me, char *fname, int flags, int mode);
55 int (*close) (void *vfs_info);
56 int (*read) (void *vfs_info, char *buffer, int count);
57 int (*write) (void *vfs_info, char *buf, int count);
59 void *(*opendir) (vfs *me, char *dirname);
60 void *(*readdir) (void *vfs_info);
61 int (*closedir) (void *vfs_info);
62 int (*telldir) (void *vfs_info);
63 void (*seekdir) (void *vfs_info, int offset);
65 int (*stat) (vfs *me, char *path, struct stat *buf);
66 int (*lstat) (vfs *me, char *path, struct stat *buf);
67 int (*fstat) (void *vfs_info, struct stat *buf);
69 int (*chmod) (vfs *me, char *path, int mode);
70 int (*chown) (vfs *me, char *path, int owner, int group);
71 int (*utime) (vfs *me, char *path, struct utimbuf *times);
73 int (*readlink) (vfs *me, char *path, char *buf, int size);
74 int (*symlink) (vfs *me, char *n1, char *n2);
75 int (*link) (vfs *me, char *p1, char *p2);
76 int (*unlink) (vfs *me, char *path);
77 int (*rename) (vfs *me, char *p1, char *p2);
78 int (*chdir) (vfs *me, char *path);
79 int (*ferrno) (vfs *me);
80 int (*lseek) (void *vfs_info, off_t offset, int whence);
81 int (*mknod) (vfs *me, char *path, int mode, int dev);
83 vfsid (*getid) (vfs *me, char *path, struct vfs_stamping **
84 parent);
86 int (*nothingisopen) (vfsid id);
87 void (*free) (vfsid id);
89 char *(*getlocalcopy) (vfs *me, char *filename);
90 int (*ungetlocalcopy) (vfs *me, char *filename, char *local,
91 int has_changed);
93 int (*mkdir) (vfs *me, char *path, mode_t mode);
94 int (*rmdir) (vfs *me, char *path);
96 int (*ctl) (void *vfs_info, int ctlop, int arg);
97 int (*setctl) (vfs *me, char *path, int ctlop, char *arg);
98 #ifdef HAVE_MMAP
99 caddr_t (*mmap) (vfs *me, caddr_t addr, size_t len, int prot,
100 int flags, void *vfs_info, off_t offset);
101 int (*munmap) (vfs *me, caddr_t addr, size_t len,
102 void *vfs_info);
103 #endif
106 /* Other file systems */
107 extern vfs vfs_local_ops;
108 extern vfs vfs_nil_ops;
109 extern vfs vfs_tarfs_ops;
110 extern vfs vfs_cpiofs_ops;
112 extern vfs vfs_ftpfs_ops;
113 extern vfs vfs_smbfs_ops;
114 extern vfs vfs_fish_ops;
115 extern vfs vfs_mcfs_ops;
117 extern vfs vfs_extfs_ops;
118 extern vfs vfs_sfs_ops;
120 extern vfs vfs_undelfs_ops;
122 struct vfs_stamping {
123 vfs *v;
124 vfsid id;
125 struct vfs_stamping *parent; /* At the moment applies to tarfs only */
126 struct vfs_stamping *next;
127 struct timeval time;
130 void vfs_init (void);
131 void vfs_shut (void);
133 extern int vfs_type_absolute;
134 vfs *vfs_type (char *path);
135 vfs *vfs_split (char *path, char **inpath, char **op);
136 vfsid vfs_ncs_getid (vfs *nvfs, char *dir, struct vfs_stamping **par);
137 void vfs_rm_parents (struct vfs_stamping *stamp);
138 char *vfs_path (char *path);
139 char *vfs_strip_suffix_from_filename (const char *filename);
140 char *vfs_canon (const char *path);
141 char *mc_get_current_wd (char *buffer, int bufsize);
142 int vfs_current_is_local (void);
143 #if 0
144 int vfs_current_is_extfs (void);
145 int vfs_current_is_tarfs (void);
146 int vfs_current_is_cpiofs (void);
147 #endif
148 int vfs_file_is_local (const char *name);
149 int vfs_file_is_ftp (char *filename);
150 int vfs_file_is_smb (char *filename);
151 char *vfs_get_current_dir (void);
153 void vfs_stamp (vfs *, vfsid);
154 void vfs_rmstamp (vfs *, vfsid, int);
155 void vfs_addstamp (vfs *, vfsid, struct vfs_stamping *);
156 void vfs_add_noncurrent_stamps (vfs *, vfsid, struct vfs_stamping *);
157 void vfs_add_current_stamps (void);
158 void vfs_free_resources(char *path);
159 void vfs_timeout_handler (void);
160 void vfs_expire (int);
161 int vfs_timeouts (void);
163 void vfs_fill_names (void (*)(char *));
164 char *vfs_translate_url (char *);
166 void ftpfs_set_debug (const char *file);
167 #ifdef USE_NETCODE
168 void ftpfs_hint_reread(int reread);
169 void ftpfs_flushdir(void);
170 extern int use_netrc;
171 #else
172 # define ftpfs_flushdir()
173 # define ftpfs_hint_reread(x)
174 #endif
176 /* Only the routines outside of the VFS module need the emulation macros */
178 int mc_open (const char *filename, int flags, ...);
179 int mc_close (int handle);
180 int mc_read (int handle, char *buffer, int count);
181 int mc_write (int handle, char *buffer, int count);
182 off_t mc_lseek (int fd, off_t offset, int whence);
183 int mc_chdir (char *);
185 DIR *mc_opendir (char *dirname);
186 struct dirent *mc_readdir(DIR *dirp);
187 int mc_closedir (DIR *dir);
188 int mc_telldir (DIR *dir);
189 void mc_seekdir (DIR *dir, int offset);
191 int mc_stat (char *path, struct stat *buf);
192 int mc_lstat (char *path, struct stat *buf);
193 int mc_fstat (int fd, struct stat *buf);
195 int mc_chmod (char *path, int mode);
196 int mc_chown (char *path, int owner, int group);
197 int mc_utime (char *path, struct utimbuf *times);
198 int mc_readlink (char *path, char *buf, int bufsiz);
199 int mc_unlink (char *path);
200 int mc_symlink (char *name1, char *name2);
201 int mc_link (const char *name1, const char *name2);
202 int mc_mknod (char *, int, int);
203 int mc_rename (const char *original, const char *target);
204 int mc_write (int fd, char *buf, int nbyte);
205 int mc_rmdir (char *path);
206 int mc_mkdir (char *path, mode_t mode);
208 char *mc_getlocalcopy (const char *pathname);
209 int mc_ungetlocalcopy (const char *pathname, char *local, int has_changed);
210 char *mc_def_getlocalcopy (vfs *vfs, char *filename);
211 int mc_def_ungetlocalcopy (vfs *vfs, char *filename, char *local, int has_changed);
212 int mc_ctl (int fd, int ctlop, int arg);
213 int mc_setctl (char *path, int ctlop, char *arg);
214 #ifdef HAVE_MMAP
215 caddr_t mc_mmap (caddr_t, size_t, int, int, int, off_t);
216 int mc_unmap (caddr_t, size_t);
217 int mc_munmap (caddr_t addr, size_t len);
218 #endif /* HAVE_MMAP */
220 #else
222 #ifdef USE_NETCODE
223 # undef USE_NETCODE
224 #endif
226 # undef USE_NETCODE
228 # define vfs_fill_names(x) do { } while (0)
229 # define vfs_add_current_stamps() do { } while (0)
230 # define vfs_current_is_local() 1
231 # define vfs_file_is_local(x) 1
232 # define vfs_file_is_ftp(x) 0
233 # define vfs_file_is_smb(x) 0
234 # define vfs_current_is_tarfs() 0
235 # define vfs_current_is_cpiofs() 0
236 # define vfs_current_is_extfs() 0
237 # define vfs_path(x) x
238 # define vfs_strip_suffix_from_filename(x) g_strdup(x)
239 # define mc_close close
240 # define mc_read read
241 # define mc_write write
242 # define mc_lseek lseek
243 # define mc_opendir opendir
244 # define mc_readdir readdir
245 # define mc_closedir closedir
246 # define mc_telldir telldir
247 # define mc_seekdir seekdir
249 # define mc_get_current_wd(x,size) get_current_wd (x, size)
250 # define mc_fstat fstat
251 # define mc_lstat lstat
253 # define mc_readlink readlink
254 # define mc_symlink symlink
255 # define mc_rename rename
257 # define mc_open open
258 # define mc_utime utime
259 # define mc_chmod chmod
260 # define mc_chown chown
261 # define mc_chdir chdir
262 # define mc_unlink unlink
264 # define mc_mmap mmap
265 # define mc_munmap munmap
267 # define mc_ctl(a,b,c) 0
268 # define mc_setctl(a,b,c) 0
269 # define vfs_translate_url(s) g_strdup(s)
271 # define mc_stat stat
272 # define mc_mknod mknod
273 # define mc_link link
274 # define mc_mkdir mkdir
275 # define mc_rmdir rmdir
276 # define is_special_prefix(x) 0
277 # define vfs_type(x) (vfs *)(NULL)
278 # define vfs_init() do { } while (0)
279 # define vfs_shut() do { } while (0)
280 # define vfs_canon(p) g_strdup (canonicalize_pathname(p))
281 # define vfs_free_resources() do { } while (0)
282 # define vfs_timeout_handler() do { } while (0)
283 # define vfs_timeouts() 0
284 # define vfs_force_expire() do { } while (0)
286 typedef int vfs;
288 # define mc_getlocalcopy(x) NULL
289 # define mc_ungetlocalcopy(x,y,z) do { } while (0)
291 # define ftpfs_hint_reread(x) do { } while (0)
292 # define ftpfs_flushdir() do { } while (0)
294 #ifdef _OS_NT
295 # undef mc_rmdir
296 #endif
298 #ifdef OS2_NT
299 # undef mc_ctl
300 # undef mc_unlink
301 # define mc_ctl(a,b,c) 0
302 # ifndef __EMX__
303 # undef mc_mkdir
304 # define mc_mkdir(a,b) mkdir(a)
305 # endif
306 #endif
308 #endif /* USE_VFS */
310 #define mc_errno errno
312 /* These functions are meant for use by vfs modules */
314 extern int vfs_parse_ls_lga (const char *p, struct stat *s, char **filename, char **linkname);
315 extern int vfs_split_text (char *p);
316 extern int vfs_parse_filetype (char c);
317 extern int vfs_parse_filemode (const char *p);
318 extern int vfs_parse_filedate(int idx, time_t *t);
320 extern void vfs_die (char *msg);
321 extern char *vfs_get_password (char *msg);
323 /* Flags for vfs_split_url() */
324 #define URL_ALLOW_ANON 1
325 #define URL_NOSLASH 2
327 extern char *vfs_split_url (const char *path, char **host, char **user,
328 int *port, char **pass, int default_port, int flags);
330 #ifdef WITH_SMBFS
331 /* Interface for requesting SMB credentials. */
332 struct smb_authinfo {
333 char *host;
334 char *share;
335 char *domain;
336 char *user;
337 char *password;
340 struct smb_authinfo *
341 vfs_smb_get_authinfo (const char *host, const char *share, const char *domain,
342 const char *user);
343 #endif /* WITH_SMBFS */
345 extern void vfs_print_stats (const char *fs_name, const char *action,
346 const char *file_name, off_t have, off_t need);
348 /* Don't use values 0..4 for a while -- 10/98, pavel@ucw.cz */
349 #define MCCTL_REMOVELOCALCOPY 5
350 #define MCCTL_IS_NOTREADY 6
351 #define MCCTL_FORGET_ABOUT 7
352 #define MCCTL_EXTFS_RUN 8
353 /* These two make vfs layer give out potentially incorrect data, but
354 they also make some operation 100 times faster. Use with caution. */
355 #define MCCTL_WANT_STALE_DATA 9
356 #define MCCTL_NO_STALE_DATA 10
358 extern int vfs_flags;
359 extern uid_t vfs_uid;
360 extern gid_t vfs_gid;
362 #define FL_ALWAYS_MAGIC 1
363 #define FL_NO_MCFS 2
364 #define FL_NO_FTPFS 4
365 #define FL_NO_UNDELFS 8
366 #define FL_NO_TARFS 16
367 #define FL_NO_EXTFS 32
368 #define FL_NO_SFS 64
369 #define FL_NO_FISH 128
371 #define FL_NO_LOCALHASH 0x20000000 /* When you never ever want vfs to work with regular files with # in name */
372 #define FL_NO_CWDSETUP 0x40000000
375 #ifdef VFS_STANDALONE
376 extern void mc_vfs_init( void );
377 extern void mc_vfs_done( void );
378 #endif
380 #define O_ALL (O_CREAT | O_EXCL | O_NOCTTY | O_NDELAY | O_SYNC | O_WRONLY | O_RDWR | O_RDONLY)
381 /* Midnight commander code should _not_ use other flags than those
382 listed above and O_APPEND */
384 #if (O_ALL & O_APPEND)
385 #warning "Unexpected problem with flags, O_LINEAR disabled, contact pavel@ucw.cz"
386 #define O_LINEAR 0
387 #define IS_LINEAR(a) 0
388 #define NO_LINEAR(a) a
389 #else
390 #define O_LINEAR O_APPEND
391 #define IS_LINEAR(a) ((a) == (O_RDONLY | O_LINEAR)) /* Return only 0 and 1 ! */
392 #define NO_LINEAR(a) (((a) == (O_RDONLY | O_LINEAR)) ? O_RDONLY : (a))
393 #endif
395 /* O_LINEAR is strange beast, be carefull. If you open file asserting
396 * O_RDONLY | O_LINEAR, you promise:
398 * a) to read file linearly from beginning to the end
399 * b) not to open another file before you close this one
400 * (this will likely go away in future)
401 * as a special gift, you may
402 * c) lseek() immediately after open(), giving ftpfs chance to
403 * reget. Be warned that this lseek() can fail, and you _have_
404 * to handle that gratefully.
406 * O_LINEAR allows filesystems not to create temporary file in some
407 * cases (ftp transfer). -- pavel@ucw.cz
410 #ifdef HAVE_MMAP
411 #define MMAPNULL , NULL, NULL
412 #else
413 #define MMAPNULL
414 #endif
416 /* And now some defines for our errors. */
418 #ifdef ENOSYS
419 #define E_NOTSUPP ENOSYS /* for use in vfs when module does not provide function */
420 #else
421 #define E_NOTSUPP EFAULT /* Does this happen? */
422 #endif
424 #ifdef ENOMSG
425 #define E_UNKNOWN ENOMSG /* if we do not know what error happened */
426 #else
427 #define E_UNKNOWN EIO /* if we do not know what error happened */
428 #endif
430 #ifdef EREMOTEIO
431 #define E_REMOTE EREMOTEIO /* if other side of ftp/fish reports error */
432 #else
433 #define E_REMOTE ENETUNREACH /* :-( there's no EREMOTEIO on some systems */
434 #endif
436 #ifdef EPROTO
437 #define E_PROTO EPROTO /* if other side fails to follow protocol */
438 #else
439 #define E_PROTO EIO
440 #endif
442 #endif /* __VFS_H */