*** empty log message ***
[midnight-commander.git] / vfs / vfs.h
blobfb6c808fac675672e8cbca5d6ab9149ae757e059
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
107 * This union is used to ensure that there is enough space for the
108 * filename (d_name) when the dirent structure is created.
110 union vfs_dirent {
111 struct dirent dent;
112 char _extra_buffer [((int) &((struct dirent *)0)->d_name) +
113 MC_MAXPATHLEN + 1];
116 /* Other file systems */
117 extern vfs vfs_local_ops;
118 extern vfs vfs_nil_ops;
119 extern vfs vfs_tarfs_ops;
120 extern vfs vfs_cpiofs_ops;
122 extern vfs vfs_ftpfs_ops;
123 extern vfs vfs_smbfs_ops;
124 extern vfs vfs_fish_ops;
125 extern vfs vfs_mcfs_ops;
127 extern vfs vfs_extfs_ops;
128 extern vfs vfs_sfs_ops;
130 extern vfs vfs_undelfs_ops;
132 struct vfs_stamping {
133 vfs *v;
134 vfsid id;
135 struct vfs_stamping *parent; /* At the moment applies to tarfs only */
136 struct vfs_stamping *next;
137 struct timeval time;
140 void vfs_init (void);
141 void vfs_shut (void);
143 extern int vfs_type_absolute;
144 vfs *vfs_type (char *path);
145 vfs *vfs_split (char *path, char **inpath, char **op);
146 vfsid vfs_ncs_getid (vfs *nvfs, char *dir, struct vfs_stamping **par);
147 void vfs_rm_parents (struct vfs_stamping *stamp);
148 char *vfs_path (char *path);
149 char *vfs_strip_suffix_from_filename (const char *filename);
150 char *vfs_canon (const char *path);
151 char *mc_get_current_wd (char *buffer, int bufsize);
152 int vfs_current_is_local (void);
153 #if 0
154 int vfs_current_is_extfs (void);
155 int vfs_current_is_tarfs (void);
156 int vfs_current_is_cpiofs (void);
157 #endif
158 int vfs_file_is_local (const char *name);
159 int vfs_file_is_ftp (char *filename);
160 int vfs_file_is_smb (char *filename);
161 char *vfs_get_current_dir (void);
163 extern int vfs_timeout;
164 extern int tar_gzipped_memlimit;
166 void vfs_stamp (vfs *, vfsid);
167 void vfs_rmstamp (vfs *, vfsid, int);
168 void vfs_addstamp (vfs *, vfsid, struct vfs_stamping *);
169 void vfs_add_noncurrent_stamps (vfs *, vfsid, struct vfs_stamping *);
170 void vfs_add_current_stamps (void);
171 void vfs_free_resources(char *path);
172 void vfs_timeout_handler (void);
173 void vfs_expire (int);
174 int vfs_timeouts (void);
176 void vfs_fill_names (void (*)(char *));
177 char *vfs_translate_url (char *);
179 void ftpfs_set_debug (const char *file);
180 #ifdef USE_NETCODE
181 void ftpfs_hint_reread(int reread);
182 void ftpfs_flushdir(void);
183 extern int use_netrc;
184 #else
185 # define ftpfs_flushdir()
186 # define ftpfs_hint_reread(x)
187 #endif
189 /* Only the routines outside of the VFS module need the emulation macros */
191 int mc_open (const char *filename, int flags, ...);
192 int mc_close (int handle);
193 int mc_read (int handle, char *buffer, int count);
194 int mc_write (int handle, char *buffer, int count);
195 off_t mc_lseek (int fd, off_t offset, int whence);
196 int mc_chdir (char *);
198 DIR *mc_opendir (char *dirname);
199 struct dirent *mc_readdir(DIR *dirp);
200 int mc_closedir (DIR *dir);
201 int mc_telldir (DIR *dir);
202 void mc_seekdir (DIR *dir, int offset);
204 int mc_stat (char *path, struct stat *buf);
205 int mc_lstat (char *path, struct stat *buf);
206 int mc_fstat (int fd, struct stat *buf);
208 int mc_chmod (char *path, int mode);
209 int mc_chown (char *path, int owner, int group);
210 int mc_utime (char *path, struct utimbuf *times);
211 int mc_readlink (char *path, char *buf, int bufsiz);
212 int mc_unlink (char *path);
213 int mc_symlink (char *name1, char *name2);
214 int mc_link (const char *name1, const char *name2);
215 int mc_mknod (char *, int, int);
216 int mc_rename (const char *original, const char *target);
217 int mc_write (int fd, char *buf, int nbyte);
218 int mc_rmdir (char *path);
219 int mc_mkdir (char *path, mode_t mode);
221 char *mc_getlocalcopy (const char *pathname);
222 int mc_ungetlocalcopy (const char *pathname, char *local, int has_changed);
223 char *mc_def_getlocalcopy (vfs *vfs, char *filename);
224 int mc_def_ungetlocalcopy (vfs *vfs, char *filename, char *local, int has_changed);
225 int mc_ctl (int fd, int ctlop, int arg);
226 int mc_setctl (char *path, int ctlop, char *arg);
227 #ifdef HAVE_MMAP
228 caddr_t mc_mmap (caddr_t, size_t, int, int, int, off_t);
229 int mc_unmap (caddr_t, size_t);
230 int mc_munmap (caddr_t addr, size_t len);
231 #endif /* HAVE_MMAP */
233 #else
235 #ifdef USE_NETCODE
236 # undef USE_NETCODE
237 #endif
239 # undef USE_NETCODE
241 # define vfs_fill_names(x) do { } while (0)
242 # define vfs_add_current_stamps() do { } while (0)
243 # define vfs_current_is_local() 1
244 # define vfs_file_is_local(x) 1
245 # define vfs_file_is_ftp(x) 0
246 # define vfs_file_is_smb(x) 0
247 # define vfs_current_is_tarfs() 0
248 # define vfs_current_is_cpiofs() 0
249 # define vfs_current_is_extfs() 0
250 # define vfs_path(x) x
251 # define vfs_strip_suffix_from_filename(x) g_strdup(x)
252 # define mc_close close
253 # define mc_read read
254 # define mc_write write
255 # define mc_lseek lseek
256 # define mc_opendir opendir
257 # define mc_readdir readdir
258 # define mc_closedir closedir
259 # define mc_telldir telldir
260 # define mc_seekdir seekdir
262 # define mc_get_current_wd(x,size) get_current_wd (x, size)
263 # define mc_fstat fstat
264 # define mc_lstat lstat
266 # define mc_readlink readlink
267 # define mc_symlink symlink
268 # define mc_rename rename
270 # define mc_open open
271 # define mc_utime utime
272 # define mc_chmod chmod
273 # define mc_chown chown
274 # define mc_chdir chdir
275 # define mc_unlink unlink
277 # define mc_mmap mmap
278 # define mc_munmap munmap
280 # define mc_ctl(a,b,c) 0
281 static inline int mc_setctl(a,b,c) { return 0; }
282 # define vfs_translate_url(s) g_strdup(s)
284 # define mc_stat stat
285 # define mc_mknod mknod
286 # define mc_link link
287 # define mc_mkdir mkdir
288 # define mc_rmdir rmdir
289 # define is_special_prefix(x) 0
290 # define vfs_type(x) (vfs *)(NULL)
291 # define vfs_init() do { } while (0)
292 # define vfs_shut() do { } while (0)
293 # define vfs_canon(p) g_strdup (canonicalize_pathname(p))
294 # define vfs_free_resources() do { } while (0)
295 # define vfs_timeout_handler() do { } while (0)
296 # define vfs_timeouts() 0
297 # define vfs_force_expire() do { } while (0)
299 typedef int vfs;
301 # define mc_getlocalcopy(x) NULL
302 # define mc_ungetlocalcopy(x,y,z) do { } while (0)
304 # define ftpfs_hint_reread(x) do { } while (0)
305 # define ftpfs_flushdir() do { } while (0)
307 #ifdef _OS_NT
308 # undef mc_rmdir
309 #endif
311 #ifdef OS2_NT
312 # undef mc_ctl
313 # undef mc_unlink
314 # define mc_ctl(a,b,c) 0
315 # ifndef __EMX__
316 # undef mc_mkdir
317 # define mc_mkdir(a,b) mkdir(a)
318 # endif
319 #endif
321 #endif /* USE_VFS */
323 #define mc_errno errno
325 /* These functions are meant for use by vfs modules */
327 extern int vfs_parse_ls_lga (const char *p, struct stat *s, char **filename, char **linkname);
328 extern int vfs_split_text (char *p);
329 extern int vfs_parse_filetype (char c);
330 extern int vfs_parse_filemode (const char *p);
331 extern int vfs_parse_filedate(int idx, time_t *t);
333 extern void vfs_die (char *msg);
334 extern char *vfs_get_password (char *msg);
336 /* Flags for vfs_split_url() */
337 #define URL_ALLOW_ANON 1
338 #define URL_NOSLASH 2
340 extern char *vfs_split_url (const char *path, char **host, char **user,
341 int *port, char **pass, int default_port, int flags);
343 #ifdef WITH_SMBFS
344 /* Interface for requesting SMB credentials. */
345 struct smb_authinfo {
346 char *host;
347 char *share;
348 char *domain;
349 char *user;
350 char *password;
353 struct smb_authinfo *
354 vfs_smb_get_authinfo (const char *host, const char *share, const char *domain,
355 const char *user);
356 #endif /* WITH_SMBFS */
358 extern void vfs_print_stats (const char *fs_name, const char *action,
359 const char *file_name, off_t have, off_t need);
361 /* Don't use values 0..4 for a while -- 10/98, pavel@ucw.cz */
362 #define MCCTL_REMOVELOCALCOPY 5
363 #define MCCTL_IS_NOTREADY 6
364 #define MCCTL_FORGET_ABOUT 7
365 #define MCCTL_EXTFS_RUN 8
366 /* These two make vfs layer give out potentially incorrect data, but
367 they also make some operation 100 times faster. Use with caution. */
368 #define MCCTL_WANT_STALE_DATA 9
369 #define MCCTL_NO_STALE_DATA 10
371 extern int vfs_flags;
372 extern uid_t vfs_uid;
373 extern gid_t vfs_gid;
375 #define FL_ALWAYS_MAGIC 1
376 #define FL_NO_MCFS 2
377 #define FL_NO_FTPFS 4
378 #define FL_NO_UNDELFS 8
379 #define FL_NO_TARFS 16
380 #define FL_NO_EXTFS 32
381 #define FL_NO_SFS 64
382 #define FL_NO_FISH 128
384 #define FL_NO_LOCALHASH 0x20000000 /* When you never ever want vfs to work with regular files with # in name */
385 #define FL_NO_CWDSETUP 0x40000000
388 #ifdef VFS_STANDALONE
389 extern void mc_vfs_init( void );
390 extern void mc_vfs_done( void );
391 #endif
393 #define O_ALL (O_CREAT | O_EXCL | O_NOCTTY | O_NDELAY | O_SYNC | O_WRONLY | O_RDWR | O_RDONLY)
394 /* Midnight commander code should _not_ use other flags than those
395 listed above and O_APPEND */
397 #if (O_ALL & O_APPEND)
398 #warning "Unexpected problem with flags, O_LINEAR disabled, contact pavel@ucw.cz"
399 #define O_LINEAR 0
400 #define IS_LINEAR(a) 0
401 #define NO_LINEAR(a) a
402 #else
403 #define O_LINEAR O_APPEND
404 #define IS_LINEAR(a) ((a) == (O_RDONLY | O_LINEAR)) /* Return only 0 and 1 ! */
405 #define NO_LINEAR(a) (((a) == (O_RDONLY | O_LINEAR)) ? O_RDONLY : (a))
406 #endif
408 /* O_LINEAR is strange beast, be carefull. If you open file asserting
409 * O_RDONLY | O_LINEAR, you promise:
411 * a) to read file linearly from beginning to the end
412 * b) not to open another file before you close this one
413 * (this will likely go away in future)
414 * as a special gift, you may
415 * c) lseek() immediately after open(), giving ftpfs chance to
416 * reget. Be warned that this lseek() can fail, and you _have_
417 * to handle that gratefully.
419 * O_LINEAR allows filesystems not to create temporary file in some
420 * cases (ftp transfer). -- pavel@ucw.cz
423 #ifdef HAVE_MMAP
424 #define MMAPNULL , NULL, NULL
425 #else
426 #define MMAPNULL
427 #endif
429 /* And now some defines for our errors. */
431 #ifdef ENOSYS
432 #define E_NOTSUPP ENOSYS /* for use in vfs when module does not provide function */
433 #else
434 #define E_NOTSUPP EFAULT /* Does this happen? */
435 #endif
437 #ifdef ENOMSG
438 #define E_UNKNOWN ENOMSG /* if we do not know what error happened */
439 #else
440 #define E_UNKNOWN EIO /* if we do not know what error happened */
441 #endif
443 #ifdef EREMOTEIO
444 #define E_REMOTE EREMOTEIO /* if other side of ftp/fish reports error */
445 #else
446 #define E_REMOTE ENETUNREACH /* :-( there's no EREMOTEIO on some systems */
447 #endif
449 #ifdef EPROTO
450 #define E_PROTO EPROTO /* if other side fails to follow protocol */
451 #else
452 #define E_PROTO EIO
453 #endif
455 #endif /* __VFS_H */