update
[midnight-commander.git] / vfs / vfs.h
blobe04c92564f04c4da00d197ead400348101a53ce8
1 #ifndef __VFS_H
2 #define __VFS_H
4 #include <config.h>
5 #include <sys/types.h>
6 #include <sys/stat.h>
7 #include <dirent.h>
9 #if !defined(SCO_FLAVOR) || !defined(_SYS_SELECT_H) || defined(IS_AIX)
10 # include <sys/time.h> /* alex: this redefines struct timeval */
11 # ifdef IS_AIX
12 # include <time.h>
13 # endif
14 #endif /* SCO_FLAVOR */
16 #ifdef HAVE_UTIME_H
17 # include <utime.h>
18 #else
19 struct utimbuf {
20 time_t actime;
21 time_t modtime;
23 #endif
25 #ifdef USE_VFS
26 #ifdef HAVE_MMAP
27 #include <sys/mman.h>
28 #endif
30 #ifdef VFS_STANDALONE
31 #undef USE_EXT2FSLIB
32 #else
33 #undef BROKEN_PATHS
35 * Define this to allow /any/path/#ftp/ to access ftp tree. Broken, yes.
36 */
37 #endif
39 /* Our virtual file system layer */
41 typedef void * vfsid;
43 struct vfs_stamping;
46 * Notice: Andrej Borsenkow <borsenkow.msk@sni.de> reports system
47 * (RelianUNIX), where it is bad idea to define struct vfs. That system
48 * has include called <sys/vfs.h>, which contains things like vfs_t.
51 typedef struct _vfs vfs;
53 struct _vfs {
54 vfs *next;
55 char *name; /* "FIles over SHell" */
56 int flags;
57 #define F_EXEC 1
58 #define F_NET 2
59 char *prefix; /* "fish:" */
60 void *data; /* this is for filesystem's own use */
61 int verrno; /* can't use errno because glibc2 might define errno as function */
63 int (*init) (vfs *me);
64 void (*done) (vfs *me);
65 void (*fill_names) (vfs *me, void (*)(char *));
67 int (*which) (vfs *me, char *path);
69 void *(*open) (vfs *me, char *fname, int flags, int mode);
70 int (*close) (void *vfs_info);
71 int (*read) (void *vfs_info, char *buffer, int count);
72 int (*write) (void *vfs_info, char *buf, int count);
74 void *(*opendir) (vfs *me, char *dirname);
75 void *(*readdir) (void *vfs_info);
76 int (*closedir) (void *vfs_info);
77 int (*telldir) (void *vfs_info);
78 void (*seekdir) (void *vfs_info, int offset);
80 int (*stat) (vfs *me, char *path, struct stat *buf);
81 int (*lstat) (vfs *me, char *path, struct stat *buf);
82 int (*fstat) (void *vfs_info, struct stat *buf);
84 int (*chmod) (vfs *me, char *path, int mode);
85 int (*chown) (vfs *me, char *path, int owner, int group);
86 int (*utime) (vfs *me, char *path, struct utimbuf *times);
88 int (*readlink) (vfs *me, char *path, char *buf, int size);
89 int (*symlink) (vfs *me, char *n1, char *n2);
90 int (*link) (vfs *me, char *p1, char *p2);
91 int (*unlink) (vfs *me, char *path);
92 int (*rename) (vfs *me, char *p1, char *p2);
93 int (*chdir) (vfs *me, char *path);
94 int (*ferrno) (vfs *me);
95 int (*lseek) (void *vfs_info, off_t offset, int whence);
96 int (*mknod) (vfs *me, char *path, int mode, int dev);
98 vfsid (*getid) (vfs *me, char *path, struct vfs_stamping **
99 parent);
101 int (*nothingisopen) (vfsid id);
102 void (*free) (vfsid id);
104 char *(*getlocalcopy) (vfs *me, char *filename);
105 void (*ungetlocalcopy) (vfs *me, char *filename, char *local,
106 int has_changed);
108 int (*mkdir) (vfs *me, char *path, mode_t mode);
109 int (*rmdir) (vfs *me, char *path);
111 int (*ctl) (void *vfs_info, int ctlop, int arg);
112 int (*setctl) (vfs *me, char *path, int ctlop, char *arg);
113 #ifdef HAVE_MMAP
114 caddr_t (*mmap) (vfs *me, caddr_t addr, size_t len, int prot,
115 int flags, void *vfs_info, off_t offset);
116 int (*munmap) (vfs *me, caddr_t addr, size_t len,
117 void *vfs_info);
118 #endif
121 /* Other file systems */
122 extern vfs vfs_local_ops;
123 extern vfs vfs_tarfs_ops;
125 extern vfs vfs_ftpfs_ops;
126 extern vfs vfs_fish_ops;
127 extern vfs vfs_mcfs_ops;
129 extern vfs vfs_extfs_ops;
130 extern vfs vfs_sfs_ops;
132 extern vfs vfs_undelfs_ops;
134 struct vfs_stamping {
135 vfs *v;
136 vfsid id;
137 struct vfs_stamping *parent; /* At the moment applies to tarfs only */
138 struct vfs_stamping *next;
139 struct timeval time;
142 void vfs_init (void);
143 void vfs_shut (void);
145 extern int vfs_type_absolute;
146 vfs *vfs_type (char *path);
147 vfs *vfs_split (char *path, char **inpath, char **op);
148 vfsid vfs_ncs_getid (vfs *nvfs, char *dir, struct vfs_stamping **par);
149 void vfs_rm_parents (struct vfs_stamping *stamp);
150 char *vfs_path (char *path);
151 char *vfs_strip_suffix_from_filename (char *filename);
152 char *vfs_canon (char *path);
153 char *mc_get_current_wd (char *buffer, int bufsize);
154 int vfs_current_is_local (void);
155 #if 0
156 int vfs_current_is_extfs (void);
157 int vfs_current_is_tarfs (void);
158 #endif
159 int vfs_file_is_local (char *name);
160 int vfs_file_is_ftp (char *filename);
161 char *vfs_get_current_dir (void);
163 void vfs_stamp (vfs *, vfsid);
164 void vfs_rmstamp (vfs *, vfsid, int);
165 void vfs_addstamp (vfs *, vfsid, struct vfs_stamping *);
166 void vfs_add_noncurrent_stamps (vfs *, vfsid, struct vfs_stamping *);
167 void vfs_add_current_stamps (void);
168 void vfs_free_resources(char *path);
169 void vfs_timeout_handler ();
170 int vfs_timeouts ();
172 void vfs_fill_names (void (*)(char *));
173 char *vfs_translate_url (char *);
175 void ftpfs_set_debug (char *file);
176 #ifdef USE_NETCODE
177 void ftpfs_hint_reread(int reread);
178 void ftpfs_flushdir(void);
179 #else
180 # define ftpfs_flushdir()
181 # define ftpfs_hint_reread(x)
182 #endif
184 /* Only the routines outside of the VFS module need the emulation macros */
186 int mc_open (char *file, int flags, ...);
187 int mc_close (int handle);
188 int mc_read (int handle, char *buffer, int count);
189 int mc_write (int hanlde, char *buffer, int count);
190 off_t mc_lseek (int fd, off_t offset, int whence);
191 int mc_chdir (char *);
193 DIR *mc_opendir (char *dirname);
194 struct dirent *mc_readdir(DIR *dirp);
195 int mc_closedir (DIR *dir);
196 int mc_telldir (DIR *dir);
197 void mc_seekdir (DIR *dir, int offset);
199 int mc_stat (char *path, struct stat *buf);
200 int mc_lstat (char *path, struct stat *buf);
201 int mc_fstat (int fd, struct stat *buf);
203 int mc_chmod (char *path, int mode);
204 int mc_chown (char *path, int owner, int group);
205 int mc_utime (char *path, struct utimbuf *times);
206 int mc_readlink (char *path, char *buf, int bufsiz);
207 int mc_unlink (char *path);
208 int mc_symlink (char *name1, char *name2);
209 int mc_link (char *name1, char *name2);
210 int mc_mknod (char *, int, int);
211 int mc_rename (char *original, char *target);
212 int mc_write (int fd, char *buf, int nbyte);
213 int mc_rmdir (char *path);
214 int mc_mkdir (char *path, mode_t mode);
216 char *mc_getlocalcopy (char *filename);
217 void mc_ungetlocalcopy (char *filename, char *local, int has_changed);
218 char *mc_def_getlocalcopy (vfs *vfs, char *filename);
219 void mc_def_ungetlocalcopy (vfs *vfs, char *filename, char *local, int has_changed);
220 int mc_ctl (int fd, int ctlop, int arg);
221 int mc_setctl (char *path, int ctlop, char *arg);
222 #ifdef HAVE_MMAP
223 caddr_t mc_mmap (caddr_t, size_t, int, int, int, off_t);
224 int mc_unmap (caddr_t, size_t);
225 int mc_munmap (caddr_t addr, size_t len);
226 #endif /* HAVE_MMAP */
228 #else
230 #ifdef USE_NETCODE
231 # undef USE_NETCODE
232 #endif
234 # undef USE_NETCODE
236 # define vfs_fill_names(x)
237 # define vfs_add_current_stamps()
238 # define vfs_current_is_local() 1
239 # define vfs_file_is_local(x) 1
240 # define vfs_file_is_ftp(x) 0
241 # define vfs_current_is_tarfs() 0
242 # define vfs_current_is_extfs() 0
243 # define vfs_path(x) x
244 # define vfs_strip_suffix_from_filename(x) g_strdup(x)
245 # define mc_close close
246 # define mc_read read
247 # define mc_write write
248 # define mc_lseek lseek
249 # define mc_opendir opendir
250 # define mc_readdir readdir
251 # define mc_closedir closedir
252 # define mc_telldir telldir
253 # define mc_seekdir seekdir
255 # define mc_get_current_wd(x,size) get_current_wd (x, size)
256 # define mc_fstat fstat
257 # define mc_lstat lstat
259 # define mc_readlink readlink
260 # define mc_symlink symlink
261 # define mc_rename rename
263 #ifndef __os2__
264 # define mc_open open
265 # define mc_utime utime
266 # define mc_chmod chmod
267 # define mc_chown chown
268 # define mc_chdir chdir
269 # define mc_unlink unlink
270 #endif
272 # define mc_mmap mmap
273 # define mc_munmap munmap
275 # define mc_ctl(a,b,c) 0
276 # define mc_setctl(a,b,c) 0
277 # define vfs_translate_url g_strdup(s)
279 # define mc_stat stat
280 # define mc_mknod mknod
281 # define mc_link link
282 # define mc_mkdir mkdir
283 # define mc_rmdir rmdir
284 # define is_special_prefix(x) 0
285 # define vfs_type(x) (vfs *)(NULL)
286 # define vfs_init()
287 # define vfs_shut()
288 # define vfs_canon(p) g_strdup (canonicalize_pathname(p))
289 # define vfs_free_resources()
290 # define vfs_timeout_handler()
291 # define vfs_timeouts() 0
292 # define vfs_force_expire()
294 typedef int vfs;
296 # define mc_getlocalcopy(x) NULL
297 # define mc_ungetlocalcopy(x,y,z)
299 # define ftpfs_hint_reread(x)
300 # define ftpfs_flushdir()
302 #ifdef _OS_NT
303 # undef mc_rmdir
304 #endif
306 #ifdef OS2_NT
307 # undef mc_ctl
308 # undef mc_unlink
309 # define mc_ctl(a,b,c) 0
310 # ifndef __EMX__
311 # undef mc_mkdir
312 # define mc_mkdir(a,b) mkdir(a)
313 # endif
314 #endif
316 #endif /* USE_VFS */
318 #define mc_errno errno
320 /* These functions are meant for use by vfs modules */
322 extern int vfs_parse_ls_lga (char *p, struct stat *s, char **filename, char **linkname);
323 extern int vfs_split_text (char *p);
324 extern int vfs_parse_filetype (char c);
325 extern int vfs_parse_filemode (char *p);
326 extern int vfs_parse_filedate(int idx, time_t *t);
328 extern void vfs_die (char *msg);
329 extern char *vfs_get_password (char *msg);
330 extern char *vfs_split_url (char *path, char **host, char **user, int *port, char **pass,
331 int default_port, int flags);
332 #define URL_DEFAULTANON 1
333 #define URL_NOSLASH 2
334 extern void vfs_print_stats (char *fs_name, char *action, char *file_name, int have, int need);
336 /* Dont use values 0..4 for a while -- 10/98, pavel@ucw.cz */
337 #define MCCTL_REMOVELOCALCOPY 5
338 #define MCCTL_IS_NOTREADY 6
339 #define MCCTL_FORGET_ABOUT 7
340 #define MCCTL_EXTFS_RUN 8
341 /* These two make vfs layer give out potentially incorrect data, but
342 they also make some operation 100 times faster. Use with caution. */
343 #define MCCTL_WANT_STALE_DATA 9
344 #define MCCTL_NO_STALE_DATA 10
346 extern int vfs_flags;
347 extern uid_t vfs_uid;
348 extern gid_t vfs_gid;
350 #define FL_ALWAYS_MAGIC 1
351 #define FL_NO_MCFS 2
352 #define FL_NO_FTPFS 4
353 #define FL_NO_UNDELFS 8
354 #define FL_NO_TARFS 16
355 #define FL_NO_EXTFS 32
356 #define FL_NO_SFS 64
357 #define FL_NO_FISH 128
359 #define FL_NO_CWDSETUP 0x40000000
361 #ifdef VFS_STANDALONE
362 extern void mc_vfs_init( void );
363 extern void mc_vfs_done( void );
364 #endif
366 #define O_ALL (O_CREAT | O_EXCL | O_NOCTTY | O_NDELAY | O_SYNC | O_WRONLY | O_RDWR | O_RDONLY)
367 /* Midnight commander code should _not_ use other flags than those
368 listed above and O_APPEND */
370 #if (O_ALL & O_APPEND)
371 #warning Unexpected problem with flags, O_LINEAR disabled, contact pavel@ucw.cz
372 #define O_LINEAR 0
373 #define IS_LINEAR(a) 0
374 #define NO_LINEAR(a) a
375 #else
376 #define O_LINEAR O_APPEND
377 #define IS_LINEAR(a) ((a) == (O_RDONLY | O_LINEAR)) /* Return only 0 and 1 ! */
378 #define NO_LINEAR(a) (((a) == (O_RDONLY | O_LINEAR)) ? O_RDONLY : (a))
379 #endif
381 /* O_LINEAR is strange beast, be carefull. If you open file asserting
382 * O_RDONLY | O_LINEAR, you promise:
384 * a) to read file linearily from beggining to the end
385 * b) not to open another file before you close this one
386 * (this will likely go away in future)
387 * as a special gift, you may
388 * c) lseek() immediately after open(), giving ftpfs chance to
389 * reget. Be warned that this lseek() can fail, and you _have_
390 * to handle that gratefully.
392 * O_LINEAR allows filesystems not to create temporary file in some
393 * cases (ftp transfer). -- pavel@ucw.cz
396 #ifdef HAVE_MMAP
397 #define MMAPNULL , NULL, NULL
398 #else
399 #define MMAPNULL
400 #endif
402 /* And now some defines for our errors. */
404 #ifdef ENOSYS
405 #define E_NOTSUPP ENOSYS /* for use in vfs when module does not provide function */
406 #else
407 #define E_NOTSUPP EFAULT /* Does this happen? */
408 #endif
410 #ifdef ENOMSG
411 #define E_UNKNOWN ENOMSG /* if we do not know what error happened */
412 #else
413 #define E_UNKNOWN EIO /* if we do not know what error happened */
414 #endif
416 #ifdef EREMOTEIO
417 #define E_REMOTE EREMOTEIO /* if other side of ftp/fish reports error */
418 #else
419 #define E_REMOTE ENETUNREACH /* :-( there's no EREMOTEIO on some systems */
420 #endif
422 #ifdef EPROTO
423 #define E_PROTO EPROTO /* if other side fails to follow protocol */
424 #else
425 #define E_PROTO EIO
426 #endif
428 #endif /* __VFS_H */