8 #ifdef HAVE_SYS_TIMEB_H
9 # include <sys/timeb.h>
11 #ifdef TIME_WITH_SYS_TIME
12 # include <sys/time.h>
15 # ifdef HAVE_SYS_TIME_H
16 # include <sys/time.h>
41 * Define this to allow /any/path/#ftp/ to access ftp tree. Broken, yes.
46 * The following line is needed, because as usual, AIX polutes every single
47 * name space they can get their hands on
51 /* Our virtual file system layer */
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
;
67 char *name
; /* "FIles over SHell" */
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
**
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
,
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
);
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
,
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
{
152 struct vfs_stamping
*parent
; /* At the moment applies to tarfs only */
153 struct vfs_stamping
*next
;
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);
171 int vfs_current_is_extfs (void);
172 int vfs_current_is_tarfs (void);
173 int vfs_current_is_cpiofs (void);
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
);
195 void ftpfs_hint_reread(int reread
);
196 void ftpfs_flushdir(void);
198 # define ftpfs_flushdir()
199 # define ftpfs_hint_reread(x)
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
);
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 */
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 # define mc_open open
284 # define mc_utime utime
285 # define mc_chmod chmod
286 # define mc_chown chown
287 # define mc_chdir chdir
288 # define mc_unlink unlink
290 # define mc_mmap mmap
291 # define mc_munmap munmap
293 # define mc_ctl(a,b,c) 0
294 # define mc_setctl(a,b,c) 0
295 # define vfs_translate_url(s) g_strdup(s)
297 # define mc_stat stat
298 # define mc_mknod mknod
299 # define mc_link link
300 # define mc_mkdir mkdir
301 # define mc_rmdir rmdir
302 # define is_special_prefix(x) 0
303 # define vfs_type(x) (vfs *)(NULL)
304 # define vfs_init() do { } while (0)
305 # define vfs_shut() do { } while (0)
306 # define vfs_canon(p) g_strdup (canonicalize_pathname(p))
307 # define vfs_free_resources() do { } while (0)
308 # define vfs_timeout_handler() do { } while (0)
309 # define vfs_timeouts() 0
310 # define vfs_force_expire() do { } while (0)
314 # define mc_getlocalcopy(x) NULL
315 # define mc_ungetlocalcopy(x,y,z) do { } while (0)
317 # define ftpfs_hint_reread(x) do { } while (0)
318 # define ftpfs_flushdir() do { } while (0)
327 # define mc_ctl(a,b,c) 0
330 # define mc_mkdir(a,b) mkdir(a)
336 #define mc_errno errno
338 /* These functions are meant for use by vfs modules */
340 extern int vfs_parse_ls_lga (const char *p
, struct stat
*s
, char **filename
, char **linkname
);
341 extern int vfs_split_text (char *p
);
342 extern int vfs_parse_filetype (char c
);
343 extern int vfs_parse_filemode (const char *p
);
344 extern int vfs_parse_filedate(int idx
, time_t *t
);
346 extern void vfs_die (char *msg
);
347 extern char *vfs_get_password (char *msg
);
348 extern char *vfs_split_url (const char *path
, char **host
, char **user
,
349 int *port
, char **pass
, int default_port
, int flags
);
352 /* Interface for requesting SMB credentials. */
353 struct smb_authinfo
{
361 struct smb_authinfo
*
362 vfs_smb_get_authinfo (const char *host
, const char *share
, const char *domain
,
364 #endif /* WITH_SMBFS */
366 #define URL_DEFAULTANON 1
367 #define URL_NOSLASH 2
368 extern void vfs_print_stats (char *fs_name
, char *action
, char *file_name
, int have
, int need
);
370 /* Dont use values 0..4 for a while -- 10/98, pavel@ucw.cz */
371 #define MCCTL_REMOVELOCALCOPY 5
372 #define MCCTL_IS_NOTREADY 6
373 #define MCCTL_FORGET_ABOUT 7
374 #define MCCTL_EXTFS_RUN 8
375 /* These two make vfs layer give out potentially incorrect data, but
376 they also make some operation 100 times faster. Use with caution. */
377 #define MCCTL_WANT_STALE_DATA 9
378 #define MCCTL_NO_STALE_DATA 10
380 extern int vfs_flags
;
381 extern uid_t vfs_uid
;
382 extern gid_t vfs_gid
;
384 #define FL_ALWAYS_MAGIC 1
386 #define FL_NO_FTPFS 4
387 #define FL_NO_UNDELFS 8
388 #define FL_NO_TARFS 16
389 #define FL_NO_EXTFS 32
391 #define FL_NO_FISH 128
393 #define FL_NO_LOCALHASH 0x20000000 /* When you never ever want vfs to work with regular files with # in name */
394 #define FL_NO_CWDSETUP 0x40000000
397 #ifdef VFS_STANDALONE
398 extern void mc_vfs_init( void );
399 extern void mc_vfs_done( void );
402 #define O_ALL (O_CREAT | O_EXCL | O_NOCTTY | O_NDELAY | O_SYNC | O_WRONLY | O_RDWR | O_RDONLY)
403 /* Midnight commander code should _not_ use other flags than those
404 listed above and O_APPEND */
406 #if (O_ALL & O_APPEND)
407 #warning "Unexpected problem with flags, O_LINEAR disabled, contact pavel@ucw.cz"
409 #define IS_LINEAR(a) 0
410 #define NO_LINEAR(a) a
412 #define O_LINEAR O_APPEND
413 #define IS_LINEAR(a) ((a) == (O_RDONLY | O_LINEAR)) /* Return only 0 and 1 ! */
414 #define NO_LINEAR(a) (((a) == (O_RDONLY | O_LINEAR)) ? O_RDONLY : (a))
417 /* O_LINEAR is strange beast, be carefull. If you open file asserting
418 * O_RDONLY | O_LINEAR, you promise:
420 * a) to read file linearily from beggining to the end
421 * b) not to open another file before you close this one
422 * (this will likely go away in future)
423 * as a special gift, you may
424 * c) lseek() immediately after open(), giving ftpfs chance to
425 * reget. Be warned that this lseek() can fail, and you _have_
426 * to handle that gratefully.
428 * O_LINEAR allows filesystems not to create temporary file in some
429 * cases (ftp transfer). -- pavel@ucw.cz
433 #define MMAPNULL , NULL, NULL
438 /* And now some defines for our errors. */
441 #define E_NOTSUPP ENOSYS /* for use in vfs when module does not provide function */
443 #define E_NOTSUPP EFAULT /* Does this happen? */
447 #define E_UNKNOWN ENOMSG /* if we do not know what error happened */
449 #define E_UNKNOWN EIO /* if we do not know what error happened */
453 #define E_REMOTE EREMOTEIO /* if other side of ftp/fish reports error */
455 #define E_REMOTE ENETUNREACH /* :-( there's no EREMOTEIO on some systems */
459 #define E_PROTO EPROTO /* if other side fails to follow protocol */