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
;
157 void vfs_stamp (vfs
*, vfsid
);
158 void vfs_rmstamp (vfs
*, vfsid
, int);
159 void vfs_add_noncurrent_stamps (vfs
*, vfsid
, struct vfs_stamping
*);
160 void vfs_add_current_stamps (void);
161 void vfs_timeout_handler (void);
162 void vfs_expire (int);
163 int vfs_timeouts (void);
165 void vfs_fill_names (void (*)(char *));
166 char *vfs_translate_url (char *);
168 void ftpfs_set_debug (const char *file
);
170 void ftpfs_hint_reread(int reread
);
171 void ftpfs_flushdir(void);
172 extern int use_netrc
;
174 # define ftpfs_flushdir()
175 # define ftpfs_hint_reread(x)
178 /* Only the routines outside of the VFS module need the emulation macros */
180 int mc_open (const char *filename
, int flags
, ...);
181 int mc_close (int handle
);
182 int mc_read (int handle
, char *buffer
, int count
);
183 int mc_write (int handle
, char *buffer
, int count
);
184 off_t
mc_lseek (int fd
, off_t offset
, int whence
);
185 int mc_chdir (char *);
187 DIR *mc_opendir (char *dirname
);
188 struct dirent
*mc_readdir(DIR *dirp
);
189 int mc_closedir (DIR *dir
);
190 int mc_telldir (DIR *dir
);
191 void mc_seekdir (DIR *dir
, int offset
);
193 int mc_stat (char *path
, struct stat
*buf
);
194 int mc_lstat (char *path
, struct stat
*buf
);
195 int mc_fstat (int fd
, struct stat
*buf
);
197 int mc_chmod (char *path
, int mode
);
198 int mc_chown (char *path
, int owner
, int group
);
199 int mc_utime (char *path
, struct utimbuf
*times
);
200 int mc_readlink (char *path
, char *buf
, int bufsiz
);
201 int mc_unlink (char *path
);
202 int mc_symlink (char *name1
, char *name2
);
203 int mc_link (const char *name1
, const char *name2
);
204 int mc_mknod (char *, int, int);
205 int mc_rename (const char *original
, const char *target
);
206 int mc_write (int fd
, char *buf
, int nbyte
);
207 int mc_rmdir (char *path
);
208 int mc_mkdir (char *path
, mode_t mode
);
210 char *mc_getlocalcopy (const char *pathname
);
211 int mc_ungetlocalcopy (const char *pathname
, char *local
, int has_changed
);
212 char *mc_def_getlocalcopy (vfs
*vfs
, char *filename
);
213 int mc_def_ungetlocalcopy (vfs
*vfs
, char *filename
, char *local
, int has_changed
);
214 int mc_ctl (int fd
, int ctlop
, int arg
);
215 int mc_setctl (char *path
, int ctlop
, char *arg
);
217 caddr_t
mc_mmap (caddr_t
, size_t, int, int, int, off_t
);
218 int mc_unmap (caddr_t
, size_t);
219 int mc_munmap (caddr_t addr
, size_t len
);
220 #endif /* HAVE_MMAP */
230 # define vfs_fill_names(x) do { } while (0)
231 # define vfs_add_current_stamps() do { } while (0)
232 # define vfs_current_is_local() 1
233 # define vfs_file_is_local(x) 1
234 # define vfs_file_is_ftp(x) 0
235 # define vfs_file_is_smb(x) 0
236 # define vfs_current_is_tarfs() 0
237 # define vfs_current_is_cpiofs() 0
238 # define vfs_current_is_extfs() 0
239 # define vfs_path(x) x
240 # define vfs_strip_suffix_from_filename(x) g_strdup(x)
241 # define mc_close close
242 # define mc_read read
243 # define mc_write write
244 # define mc_lseek lseek
245 # define mc_opendir opendir
246 # define mc_readdir readdir
247 # define mc_closedir closedir
248 # define mc_telldir telldir
249 # define mc_seekdir seekdir
251 # define mc_get_current_wd(x,size) get_current_wd (x, size)
252 # define mc_fstat fstat
253 # define mc_lstat lstat
255 # define mc_readlink readlink
256 # define mc_symlink symlink
257 # define mc_rename rename
259 # define mc_open open
260 # define mc_utime utime
261 # define mc_chmod chmod
262 # define mc_chown chown
263 # define mc_chdir chdir
264 # define mc_unlink unlink
266 # define mc_mmap mmap
267 # define mc_munmap munmap
269 # define mc_ctl(a,b,c) 0
270 static inline int mc_setctl(a
,b
,c
) { return 0; }
271 # define vfs_translate_url(s) g_strdup(s)
273 # define mc_stat stat
274 # define mc_mknod mknod
275 # define mc_link link
276 # define mc_mkdir mkdir
277 # define mc_rmdir rmdir
278 # define is_special_prefix(x) 0
279 # define vfs_type(x) (vfs *)(NULL)
280 # define vfs_init() do { } while (0)
281 # define vfs_shut() do { } while (0)
282 # define vfs_canon(p) g_strdup (canonicalize_pathname(p))
283 # define vfs_timeout_handler() do { } while (0)
284 # define vfs_timeouts() 0
285 # define vfs_force_expire() do { } while (0)
289 # define mc_getlocalcopy(x) NULL
290 # define mc_ungetlocalcopy(x,y,z) do { } while (0)
292 # define ftpfs_hint_reread(x) do { } while (0)
293 # define ftpfs_flushdir() do { } while (0)
302 # define mc_ctl(a,b,c) 0
305 # define mc_mkdir(a,b) mkdir(a)
311 #define mc_errno errno
313 /* These functions are meant for use by vfs modules */
315 extern int vfs_parse_ls_lga (const char *p
, struct stat
*s
, char **filename
, char **linkname
);
316 extern int vfs_split_text (char *p
);
317 extern int vfs_parse_filetype (char c
);
318 extern int vfs_parse_filemode (const char *p
);
319 extern int vfs_parse_filedate(int idx
, time_t *t
);
321 extern void vfs_die (char *msg
);
322 extern char *vfs_get_password (char *msg
);
324 /* Flags for vfs_split_url() */
325 #define URL_ALLOW_ANON 1
326 #define URL_NOSLASH 2
328 extern char *vfs_split_url (const char *path
, char **host
, char **user
,
329 int *port
, char **pass
, int default_port
, int flags
);
332 /* Interface for requesting SMB credentials. */
333 struct smb_authinfo
{
341 struct smb_authinfo
*
342 vfs_smb_get_authinfo (const char *host
, const char *share
, const char *domain
,
344 #endif /* WITH_SMBFS */
346 extern void vfs_print_stats (const char *fs_name
, const char *action
,
347 const char *file_name
, off_t have
, off_t need
);
349 /* Don't use values 0..4 for a while -- 10/98, pavel@ucw.cz */
350 #define MCCTL_REMOVELOCALCOPY 5
351 #define MCCTL_IS_NOTREADY 6
352 #define MCCTL_FORGET_ABOUT 7
353 #define MCCTL_EXTFS_RUN 8
354 /* These two make vfs layer give out potentially incorrect data, but
355 they also make some operation 100 times faster. Use with caution. */
356 #define MCCTL_WANT_STALE_DATA 9
357 #define MCCTL_NO_STALE_DATA 10
362 #define FL_ALWAYS_MAGIC 1
364 #define FL_NO_FTPFS 4
365 #define FL_NO_UNDELFS 8
366 #define FL_NO_TARFS 16
367 #define FL_NO_EXTFS 32
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 #define O_ALL (O_CREAT | O_EXCL | O_NOCTTY | O_NDELAY | O_SYNC | O_WRONLY | O_RDWR | O_RDONLY)
376 /* Midnight commander code should _not_ use other flags than those
377 listed above and O_APPEND */
379 #if (O_ALL & O_APPEND)
380 #warning "Unexpected problem with flags, O_LINEAR disabled, contact pavel@ucw.cz"
382 #define IS_LINEAR(a) 0
383 #define NO_LINEAR(a) a
385 #define O_LINEAR O_APPEND
386 #define IS_LINEAR(a) ((a) == (O_RDONLY | O_LINEAR)) /* Return only 0 and 1 ! */
387 #define NO_LINEAR(a) (((a) == (O_RDONLY | O_LINEAR)) ? O_RDONLY : (a))
390 /* O_LINEAR is strange beast, be carefull. If you open file asserting
391 * O_RDONLY | O_LINEAR, you promise:
393 * a) to read file linearly from beginning to the end
394 * b) not to open another file before you close this one
395 * (this will likely go away in future)
396 * as a special gift, you may
397 * c) lseek() immediately after open(), giving ftpfs chance to
398 * reget. Be warned that this lseek() can fail, and you _have_
399 * to handle that gratefully.
401 * O_LINEAR allows filesystems not to create temporary file in some
402 * cases (ftp transfer). -- pavel@ucw.cz
406 #define MMAPNULL , NULL, NULL
411 /* And now some defines for our errors. */
414 #define E_NOTSUPP ENOSYS /* for use in vfs when module does not provide function */
416 #define E_NOTSUPP EFAULT /* Does this happen? */
420 #define E_UNKNOWN ENOMSG /* if we do not know what error happened */
422 #define E_UNKNOWN EIO /* if we do not know what error happened */
426 #define E_REMOTE EREMOTEIO /* if other side of ftp/fish reports error */
428 #define E_REMOTE ENETUNREACH /* :-( there's no EREMOTEIO on some systems */
432 #define E_PROTO EPROTO /* if other side fails to follow protocol */