11 * The following line is needed, because as usual, AIX pollutes every single
12 * name space they can get their hands on
16 /* Our virtual file system layer */
23 * Notice: Andrej Borsenkow <borsenkow.msk@sni.de> reports system
24 * (RelianUNIX), where it is bad idea to define struct vfs. That system
25 * has include called <sys/vfs.h>, which contains things like vfs_t.
28 typedef struct _vfs vfs
;
32 char *name
; /* "FIles over SHell" */
34 #define F_EXEC 1 /* Filesystem needs to execute external programs */
35 #define F_NET 2 /* Filesystem needs to access network */
36 char *prefix
; /* "fish:" */
37 void *data
; /* this is for filesystem's own use */
38 int verrno
; /* can't use errno because glibc2 might define errno as function */
40 int (*init
) (vfs
*me
);
41 void (*done
) (vfs
*me
);
42 void (*fill_names
) (vfs
*me
, void (*)(char *));
44 int (*which
) (vfs
*me
, char *path
);
46 void *(*open
) (vfs
*me
, char *fname
, int flags
, int mode
);
47 int (*close
) (void *vfs_info
);
48 int (*read
) (void *vfs_info
, char *buffer
, int count
);
49 int (*write
) (void *vfs_info
, char *buf
, int count
);
51 void *(*opendir
) (vfs
*me
, char *dirname
);
52 void *(*readdir
) (void *vfs_info
);
53 int (*closedir
) (void *vfs_info
);
54 int (*telldir
) (void *vfs_info
);
55 void (*seekdir
) (void *vfs_info
, int offset
);
57 int (*stat
) (vfs
*me
, char *path
, struct stat
*buf
);
58 int (*lstat
) (vfs
*me
, char *path
, struct stat
*buf
);
59 int (*fstat
) (void *vfs_info
, struct stat
*buf
);
61 int (*chmod
) (vfs
*me
, char *path
, int mode
);
62 int (*chown
) (vfs
*me
, char *path
, int owner
, int group
);
63 int (*utime
) (vfs
*me
, char *path
, struct utimbuf
*times
);
65 int (*readlink
) (vfs
*me
, char *path
, char *buf
, int size
);
66 int (*symlink
) (vfs
*me
, char *n1
, char *n2
);
67 int (*link
) (vfs
*me
, char *p1
, char *p2
);
68 int (*unlink
) (vfs
*me
, char *path
);
69 int (*rename
) (vfs
*me
, char *p1
, char *p2
);
70 int (*chdir
) (vfs
*me
, char *path
);
71 int (*ferrno
) (vfs
*me
);
72 int (*lseek
) (void *vfs_info
, off_t offset
, int whence
);
73 int (*mknod
) (vfs
*me
, char *path
, int mode
, int dev
);
75 vfsid (*getid
) (vfs
*me
, char *path
, struct vfs_stamping
**
78 int (*nothingisopen
) (vfsid id
);
79 void (*free
) (vfsid id
);
81 char *(*getlocalcopy
) (vfs
*me
, char *filename
);
82 int (*ungetlocalcopy
) (vfs
*me
, char *filename
, char *local
,
85 int (*mkdir
) (vfs
*me
, char *path
, mode_t mode
);
86 int (*rmdir
) (vfs
*me
, char *path
);
88 int (*ctl
) (void *vfs_info
, int ctlop
, int arg
);
89 int (*setctl
) (vfs
*me
, char *path
, int ctlop
, char *arg
);
91 caddr_t (*mmap
) (vfs
*me
, caddr_t addr
, size_t len
, int prot
,
92 int flags
, void *vfs_info
, off_t offset
);
93 int (*munmap
) (vfs
*me
, caddr_t addr
, size_t len
,
99 * This union is used to ensure that there is enough space for the
100 * filename (d_name) when the dirent structure is created.
104 char _extra_buffer
[((int) &((struct dirent
*)0)->d_name
) +
108 /* Other file systems */
109 extern vfs vfs_local_ops
;
110 extern vfs vfs_nil_ops
;
111 extern vfs vfs_tarfs_ops
;
112 extern vfs vfs_cpiofs_ops
;
114 extern vfs vfs_ftpfs_ops
;
115 extern vfs vfs_smbfs_ops
;
116 extern vfs vfs_fish_ops
;
117 extern vfs vfs_mcfs_ops
;
119 extern vfs vfs_extfs_ops
;
120 extern vfs vfs_sfs_ops
;
122 extern vfs vfs_undelfs_ops
;
124 struct vfs_stamping
{
127 struct vfs_stamping
*parent
; /* At the moment applies to tarfs only */
128 struct vfs_stamping
*next
;
132 void vfs_init (void);
133 void vfs_shut (void);
135 extern int vfs_type_absolute
;
136 vfs
*vfs_type (char *path
);
137 vfs
*vfs_split (char *path
, char **inpath
, char **op
);
138 vfsid
vfs_ncs_getid (vfs
*nvfs
, char *dir
, struct vfs_stamping
**par
);
139 void vfs_rm_parents (struct vfs_stamping
*stamp
);
140 char *vfs_path (char *path
);
141 char *vfs_strip_suffix_from_filename (const char *filename
);
142 char *vfs_canon (const char *path
);
143 char *mc_get_current_wd (char *buffer
, int bufsize
);
144 int vfs_current_is_local (void);
146 int vfs_current_is_extfs (void);
147 int vfs_current_is_tarfs (void);
148 int vfs_current_is_cpiofs (void);
150 int vfs_file_is_local (const char *name
);
151 int vfs_file_is_ftp (char *filename
);
152 int vfs_file_is_smb (char *filename
);
153 char *vfs_get_current_dir (void);
155 extern int vfs_timeout
;
156 extern int tar_gzipped_memlimit
;
158 void vfs_stamp (vfs
*, vfsid
);
159 void vfs_rmstamp (vfs
*, vfsid
, int);
160 void vfs_addstamp (vfs
*, vfsid
, struct vfs_stamping
*);
161 void vfs_add_noncurrent_stamps (vfs
*, vfsid
, struct vfs_stamping
*);
162 void vfs_add_current_stamps (void);
163 void vfs_free_resources(char *path
);
164 void vfs_timeout_handler (void);
165 void vfs_expire (int);
166 int vfs_timeouts (void);
168 void vfs_fill_names (void (*)(char *));
169 char *vfs_translate_url (char *);
171 void ftpfs_set_debug (const char *file
);
173 void ftpfs_hint_reread(int reread
);
174 void ftpfs_flushdir(void);
175 extern int use_netrc
;
177 # define ftpfs_flushdir()
178 # define ftpfs_hint_reread(x)
181 /* Only the routines outside of the VFS module need the emulation macros */
183 int mc_open (const char *filename
, int flags
, ...);
184 int mc_close (int handle
);
185 int mc_read (int handle
, char *buffer
, int count
);
186 int mc_write (int handle
, char *buffer
, int count
);
187 off_t
mc_lseek (int fd
, off_t offset
, int whence
);
188 int mc_chdir (char *);
190 DIR *mc_opendir (char *dirname
);
191 struct dirent
*mc_readdir(DIR *dirp
);
192 int mc_closedir (DIR *dir
);
193 int mc_telldir (DIR *dir
);
194 void mc_seekdir (DIR *dir
, int offset
);
196 int mc_stat (char *path
, struct stat
*buf
);
197 int mc_lstat (char *path
, struct stat
*buf
);
198 int mc_fstat (int fd
, struct stat
*buf
);
200 int mc_chmod (char *path
, int mode
);
201 int mc_chown (char *path
, int owner
, int group
);
202 int mc_utime (char *path
, struct utimbuf
*times
);
203 int mc_readlink (char *path
, char *buf
, int bufsiz
);
204 int mc_unlink (char *path
);
205 int mc_symlink (char *name1
, char *name2
);
206 int mc_link (const char *name1
, const char *name2
);
207 int mc_mknod (char *, int, int);
208 int mc_rename (const char *original
, const char *target
);
209 int mc_write (int fd
, char *buf
, int nbyte
);
210 int mc_rmdir (char *path
);
211 int mc_mkdir (char *path
, mode_t mode
);
213 char *mc_getlocalcopy (const char *pathname
);
214 int mc_ungetlocalcopy (const char *pathname
, char *local
, int has_changed
);
215 char *mc_def_getlocalcopy (vfs
*vfs
, char *filename
);
216 int mc_def_ungetlocalcopy (vfs
*vfs
, char *filename
, char *local
, int has_changed
);
217 int mc_ctl (int fd
, int ctlop
, int arg
);
218 int mc_setctl (char *path
, int ctlop
, char *arg
);
220 caddr_t
mc_mmap (caddr_t
, size_t, int, int, int, off_t
);
221 int mc_unmap (caddr_t
, size_t);
222 int mc_munmap (caddr_t addr
, size_t len
);
223 #endif /* HAVE_MMAP */
233 # define vfs_fill_names(x) do { } while (0)
234 # define vfs_add_current_stamps() do { } while (0)
235 # define vfs_current_is_local() 1
236 # define vfs_file_is_local(x) 1
237 # define vfs_file_is_ftp(x) 0
238 # define vfs_file_is_smb(x) 0
239 # define vfs_current_is_tarfs() 0
240 # define vfs_current_is_cpiofs() 0
241 # define vfs_current_is_extfs() 0
242 # define vfs_path(x) x
243 # define vfs_strip_suffix_from_filename(x) g_strdup(x)
244 # define mc_close close
245 # define mc_read read
246 # define mc_write write
247 # define mc_lseek lseek
248 # define mc_opendir opendir
249 # define mc_readdir readdir
250 # define mc_closedir closedir
251 # define mc_telldir telldir
252 # define mc_seekdir seekdir
254 # define mc_get_current_wd(x,size) get_current_wd (x, size)
255 # define mc_fstat fstat
256 # define mc_lstat lstat
258 # define mc_readlink readlink
259 # define mc_symlink symlink
260 # define mc_rename rename
262 # define mc_open open
263 # define mc_utime utime
264 # define mc_chmod chmod
265 # define mc_chown chown
266 # define mc_chdir chdir
267 # define mc_unlink unlink
269 # define mc_mmap mmap
270 # define mc_munmap munmap
272 # define mc_ctl(a,b,c) 0
273 static inline int mc_setctl(a
,b
,c
) { return 0; }
274 # define vfs_translate_url(s) g_strdup(s)
276 # define mc_stat stat
277 # define mc_mknod mknod
278 # define mc_link link
279 # define mc_mkdir mkdir
280 # define mc_rmdir rmdir
281 # define is_special_prefix(x) 0
282 # define vfs_type(x) (vfs *)(NULL)
283 # define vfs_init() do { } while (0)
284 # define vfs_shut() do { } while (0)
285 # define vfs_canon(p) g_strdup (canonicalize_pathname(p))
286 # define vfs_free_resources() do { } while (0)
287 # define vfs_timeout_handler() do { } while (0)
288 # define vfs_timeouts() 0
289 # define vfs_force_expire() do { } while (0)
293 # define mc_getlocalcopy(x) NULL
294 # define mc_ungetlocalcopy(x,y,z) do { } while (0)
296 # define ftpfs_hint_reread(x) do { } while (0)
297 # define ftpfs_flushdir() do { } while (0)
306 # define mc_ctl(a,b,c) 0
309 # define mc_mkdir(a,b) mkdir(a)
315 #define mc_errno errno
317 /* These functions are meant for use by vfs modules */
319 extern int vfs_parse_ls_lga (const char *p
, struct stat
*s
, char **filename
, char **linkname
);
320 extern int vfs_split_text (char *p
);
321 extern int vfs_parse_filetype (char c
);
322 extern int vfs_parse_filemode (const char *p
);
323 extern int vfs_parse_filedate(int idx
, time_t *t
);
325 extern void vfs_die (char *msg
);
326 extern char *vfs_get_password (char *msg
);
328 /* Flags for vfs_split_url() */
329 #define URL_ALLOW_ANON 1
330 #define URL_NOSLASH 2
332 extern char *vfs_split_url (const char *path
, char **host
, char **user
,
333 int *port
, char **pass
, int default_port
, int flags
);
336 /* Interface for requesting SMB credentials. */
337 struct smb_authinfo
{
345 struct smb_authinfo
*
346 vfs_smb_get_authinfo (const char *host
, const char *share
, const char *domain
,
348 #endif /* WITH_SMBFS */
350 extern void vfs_print_stats (const char *fs_name
, const char *action
,
351 const char *file_name
, off_t have
, off_t need
);
353 /* Don't use values 0..4 for a while -- 10/98, pavel@ucw.cz */
354 #define MCCTL_REMOVELOCALCOPY 5
355 #define MCCTL_IS_NOTREADY 6
356 #define MCCTL_FORGET_ABOUT 7
357 #define MCCTL_EXTFS_RUN 8
358 /* These two make vfs layer give out potentially incorrect data, but
359 they also make some operation 100 times faster. Use with caution. */
360 #define MCCTL_WANT_STALE_DATA 9
361 #define MCCTL_NO_STALE_DATA 10
363 extern int vfs_flags
;
364 extern uid_t vfs_uid
;
365 extern gid_t vfs_gid
;
367 #define FL_ALWAYS_MAGIC 1
369 #define FL_NO_FTPFS 4
370 #define FL_NO_UNDELFS 8
371 #define FL_NO_TARFS 16
372 #define FL_NO_EXTFS 32
374 #define FL_NO_FISH 128
376 #define FL_NO_LOCALHASH 0x20000000 /* When you never ever want vfs to work with regular files with # in name */
377 #define FL_NO_CWDSETUP 0x40000000
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"
387 #define IS_LINEAR(a) 0
388 #define NO_LINEAR(a) a
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))
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
411 #define MMAPNULL , NULL, NULL
416 /* And now some defines for our errors. */
419 #define E_NOTSUPP ENOSYS /* for use in vfs when module does not provide function */
421 #define E_NOTSUPP EFAULT /* Does this happen? */
425 #define E_UNKNOWN ENOMSG /* if we do not know what error happened */
427 #define E_UNKNOWN EIO /* if we do not know what error happened */
431 #define E_REMOTE EREMOTEIO /* if other side of ftp/fish reports error */
433 #define E_REMOTE ENETUNREACH /* :-( there's no EREMOTEIO on some systems */
437 #define E_PROTO EPROTO /* if other side fails to follow protocol */