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);
145 int vfs_file_is_local (const char *name
);
146 int vfs_file_is_ftp (char *filename
);
147 int vfs_file_is_smb (char *filename
);
148 char *vfs_get_current_dir (void);
150 extern int vfs_timeout
;
152 void vfs_stamp (vfs
*, vfsid
);
153 void vfs_rmstamp (vfs
*, vfsid
, int);
154 void vfs_add_noncurrent_stamps (vfs
*, vfsid
, struct vfs_stamping
*);
155 void vfs_add_current_stamps (void);
156 void vfs_timeout_handler (void);
157 void vfs_expire (int);
158 int vfs_timeouts (void);
160 void vfs_fill_names (void (*)(char *));
161 char *vfs_translate_url (char *);
163 void ftpfs_set_debug (const char *file
);
165 void ftpfs_hint_reread(int reread
);
166 void ftpfs_flushdir(void);
167 extern int use_netrc
;
169 # define ftpfs_flushdir()
170 # define ftpfs_hint_reread(x)
173 /* Only the routines outside of the VFS module need the emulation macros */
175 int mc_open (const char *filename
, int flags
, ...);
176 int mc_close (int handle
);
177 int mc_read (int handle
, char *buffer
, int count
);
178 int mc_write (int handle
, char *buffer
, int count
);
179 off_t
mc_lseek (int fd
, off_t offset
, int whence
);
180 int mc_chdir (char *);
182 DIR *mc_opendir (char *dirname
);
183 struct dirent
*mc_readdir(DIR *dirp
);
184 int mc_closedir (DIR *dir
);
185 int mc_telldir (DIR *dir
);
186 void mc_seekdir (DIR *dir
, int offset
);
188 int mc_stat (const char *path
, struct stat
*buf
);
189 int mc_lstat (const char *path
, struct stat
*buf
);
190 int mc_fstat (int fd
, struct stat
*buf
);
192 int mc_chmod (char *path
, int mode
);
193 int mc_chown (char *path
, int owner
, int group
);
194 int mc_utime (char *path
, struct utimbuf
*times
);
195 int mc_readlink (char *path
, char *buf
, int bufsiz
);
196 int mc_unlink (char *path
);
197 int mc_symlink (char *name1
, char *name2
);
198 int mc_link (const char *name1
, const char *name2
);
199 int mc_mknod (char *, int, int);
200 int mc_rename (const char *original
, const char *target
);
201 int mc_rmdir (char *path
);
202 int mc_mkdir (char *path
, mode_t mode
);
204 char *mc_getlocalcopy (const char *pathname
);
205 int mc_ungetlocalcopy (const char *pathname
, char *local
, int has_changed
);
206 char *mc_def_getlocalcopy (vfs
*vfs
, char *filename
);
207 int mc_def_ungetlocalcopy (vfs
*vfs
, char *filename
, char *local
, int has_changed
);
208 int mc_ctl (int fd
, int ctlop
, int arg
);
209 int mc_setctl (char *path
, int ctlop
, char *arg
);
211 caddr_t
mc_mmap (caddr_t
, size_t, int, int, int, off_t
);
212 int mc_unmap (caddr_t
, size_t);
213 int mc_munmap (caddr_t addr
, size_t len
);
214 #endif /* HAVE_MMAP */
224 # define vfs_fill_names(x) do { } while (0)
225 # define vfs_add_current_stamps() do { } while (0)
226 # define vfs_current_is_local() 1
227 # define vfs_file_is_local(x) 1
228 # define vfs_file_is_ftp(x) 0
229 # define vfs_file_is_smb(x) 0
230 # define vfs_current_is_tarfs() 0
231 # define vfs_current_is_cpiofs() 0
232 # define vfs_current_is_extfs() 0
233 # define vfs_path(x) x
234 # define vfs_strip_suffix_from_filename(x) g_strdup(x)
235 # define mc_close close
236 # define mc_read read
237 # define mc_write write
238 # define mc_lseek lseek
239 # define mc_opendir opendir
240 # define mc_readdir readdir
241 # define mc_closedir closedir
242 # define mc_telldir telldir
243 # define mc_seekdir seekdir
245 # define mc_get_current_wd(x,size) get_current_wd (x, size)
246 # define mc_fstat fstat
247 # define mc_lstat lstat
249 # define mc_readlink readlink
250 # define mc_symlink symlink
251 # define mc_rename rename
253 # define mc_open open
254 # define mc_utime utime
255 # define mc_chmod chmod
256 # define mc_chown chown
257 # define mc_chdir chdir
258 # define mc_unlink unlink
260 # define mc_mmap mmap
261 # define mc_munmap munmap
263 # define mc_ctl(a,b,c) 0
264 static inline int mc_setctl(char *path
, int ctlop
, char *arg
) { return 0; }
265 # define vfs_translate_url(s) g_strdup(s)
267 # define mc_stat stat
268 # define mc_mknod mknod
269 # define mc_link link
270 # define mc_mkdir mkdir
271 # define mc_rmdir rmdir
272 # define is_special_prefix(x) 0
273 # define vfs_type(x) (vfs *)(NULL)
274 # define vfs_init() do { } while (0)
275 # define vfs_shut() do { } while (0)
276 # define vfs_canon(p) g_strdup (canonicalize_pathname(p))
277 # define vfs_timeout_handler() do { } while (0)
278 # define vfs_timeouts() 0
279 # define vfs_force_expire() do { } while (0)
283 # define mc_getlocalcopy(x) NULL
284 # define mc_ungetlocalcopy(x,y,z) do { } while (0)
286 # define ftpfs_hint_reread(x) do { } while (0)
287 # define ftpfs_flushdir() do { } while (0)
296 # define mc_ctl(a,b,c) 0
299 # define mc_mkdir(a,b) mkdir(a)
305 #define mc_errno errno
307 /* These functions are meant for use by vfs modules */
309 extern int vfs_parse_ls_lga (const char *p
, struct stat
*s
, char **filename
, char **linkname
);
310 extern int vfs_split_text (char *p
);
311 extern int vfs_parse_filetype (char c
);
312 extern int vfs_parse_filemode (const char *p
);
313 extern int vfs_parse_filedate(int idx
, time_t *t
);
315 extern void vfs_die (const char *msg
);
316 extern char *vfs_get_password (char *msg
);
318 /* Flags for vfs_split_url() */
319 #define URL_ALLOW_ANON 1
320 #define URL_NOSLASH 2
322 extern char *vfs_split_url (const char *path
, char **host
, char **user
,
323 int *port
, char **pass
, int default_port
, int flags
);
326 /* Interface for requesting SMB credentials. */
327 struct smb_authinfo
{
335 struct smb_authinfo
*
336 vfs_smb_get_authinfo (const char *host
, const char *share
, const char *domain
,
338 #endif /* WITH_SMBFS */
340 extern void vfs_print_stats (const char *fs_name
, const char *action
,
341 const char *file_name
, off_t have
, off_t need
);
343 /* Don't use values 0..4 for a while -- 10/98, pavel@ucw.cz */
344 #define MCCTL_REMOVELOCALCOPY 5
345 #define MCCTL_IS_NOTREADY 6
346 #define MCCTL_FORGET_ABOUT 7
347 #define MCCTL_EXTFS_RUN 8
348 /* These two make vfs layer give out potentially incorrect data, but
349 they also make some operation 100 times faster. Use with caution. */
350 #define MCCTL_WANT_STALE_DATA 9
351 #define MCCTL_NO_STALE_DATA 10
353 #define FL_ALWAYS_MAGIC 1
355 #define FL_NO_FTPFS 4
356 #define FL_NO_UNDELFS 8
357 #define FL_NO_TARFS 16
358 #define FL_NO_EXTFS 32
360 #define FL_NO_FISH 128
362 #define FL_NO_LOCALHASH 0x20000000 /* When you never ever want vfs to work with regular files with # in name */
363 #define FL_NO_CWDSETUP 0x40000000
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"
373 #define IS_LINEAR(a) 0
374 #define NO_LINEAR(a) a
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))
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 linearly from beginning 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
397 #define MMAPNULL , NULL, NULL
402 /* And now some defines for our errors. */
405 #define E_NOTSUPP ENOSYS /* for use in vfs when module does not provide function */
407 #define E_NOTSUPP EFAULT /* Does this happen? */
411 #define E_UNKNOWN ENOMSG /* if we do not know what error happened */
413 #define E_UNKNOWN EIO /* if we do not know what error happened */
417 #define E_REMOTE EREMOTEIO /* if other side of ftp/fish reports error */
419 #define E_REMOTE ENETUNREACH /* :-( there's no EREMOTEIO on some systems */
423 #define E_PROTO EPROTO /* if other side fails to follow protocol */