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