9 #if !defined(SCO_FLAVOR) || !defined(_SYS_SELECT_H) || defined(IS_AIX)
10 # include <sys/time.h> /* alex: this redefines struct timeval */
14 #endif /* SCO_FLAVOR */
35 * Define this to allow /any/path/#ftp/ to access ftp tree. Broken, yes.
40 * The following line is needed, because as usual, AIX polutes every single
41 * name space they can get their hands on
45 /* Our virtual file system layer */
52 * Notice: Andrej Borsenkow <borsenkow.msk@sni.de> reports system
53 * (RelianUNIX), where it is bad idea to define struct vfs. That system
54 * has include called <sys/vfs.h>, which contains things like vfs_t.
57 typedef struct _vfs vfs
;
61 char *name
; /* "FIles over SHell" */
65 char *prefix
; /* "fish:" */
66 void *data
; /* this is for filesystem's own use */
67 int verrno
; /* can't use errno because glibc2 might define errno as function */
69 int (*init
) (vfs
*me
);
70 void (*done
) (vfs
*me
);
71 void (*fill_names
) (vfs
*me
, void (*)(char *));
73 int (*which
) (vfs
*me
, char *path
);
75 void *(*open
) (vfs
*me
, char *fname
, int flags
, int mode
);
76 int (*close
) (void *vfs_info
);
77 int (*read
) (void *vfs_info
, char *buffer
, int count
);
78 int (*write
) (void *vfs_info
, char *buf
, int count
);
80 void *(*opendir
) (vfs
*me
, char *dirname
);
81 void *(*readdir
) (void *vfs_info
);
82 int (*closedir
) (void *vfs_info
);
83 int (*telldir
) (void *vfs_info
);
84 void (*seekdir
) (void *vfs_info
, int offset
);
86 int (*stat
) (vfs
*me
, char *path
, struct stat
*buf
);
87 int (*lstat
) (vfs
*me
, char *path
, struct stat
*buf
);
88 int (*fstat
) (void *vfs_info
, struct stat
*buf
);
90 int (*chmod
) (vfs
*me
, char *path
, int mode
);
91 int (*chown
) (vfs
*me
, char *path
, int owner
, int group
);
92 int (*utime
) (vfs
*me
, char *path
, struct utimbuf
*times
);
94 int (*readlink
) (vfs
*me
, char *path
, char *buf
, int size
);
95 int (*symlink
) (vfs
*me
, char *n1
, char *n2
);
96 int (*link
) (vfs
*me
, char *p1
, char *p2
);
97 int (*unlink
) (vfs
*me
, char *path
);
98 int (*rename
) (vfs
*me
, char *p1
, char *p2
);
99 int (*chdir
) (vfs
*me
, char *path
);
100 int (*ferrno
) (vfs
*me
);
101 int (*lseek
) (void *vfs_info
, off_t offset
, int whence
);
102 int (*mknod
) (vfs
*me
, char *path
, int mode
, int dev
);
104 vfsid (*getid
) (vfs
*me
, char *path
, struct vfs_stamping
**
107 int (*nothingisopen
) (vfsid id
);
108 void (*free
) (vfsid id
);
110 char *(*getlocalcopy
) (vfs
*me
, char *filename
);
111 void (*ungetlocalcopy
) (vfs
*me
, char *filename
, char *local
,
114 int (*mkdir
) (vfs
*me
, char *path
, mode_t mode
);
115 int (*rmdir
) (vfs
*me
, char *path
);
117 int (*ctl
) (void *vfs_info
, int ctlop
, int arg
);
118 int (*setctl
) (vfs
*me
, char *path
, int ctlop
, char *arg
);
120 caddr_t (*mmap
) (vfs
*me
, caddr_t addr
, size_t len
, int prot
,
121 int flags
, void *vfs_info
, off_t offset
);
122 int (*munmap
) (vfs
*me
, caddr_t addr
, size_t len
,
127 /* Other file systems */
128 extern vfs vfs_local_ops
;
129 extern vfs vfs_tarfs_ops
;
131 extern vfs vfs_ftpfs_ops
;
132 extern vfs vfs_smbfs_ops
;
133 extern vfs vfs_fish_ops
;
134 extern vfs vfs_mcfs_ops
;
136 extern vfs vfs_extfs_ops
;
137 extern vfs vfs_sfs_ops
;
139 extern vfs vfs_undelfs_ops
;
141 struct vfs_stamping
{
144 struct vfs_stamping
*parent
; /* At the moment applies to tarfs only */
145 struct vfs_stamping
*next
;
149 void vfs_init (void);
150 void vfs_shut (void);
152 extern int vfs_type_absolute
;
153 vfs
*vfs_type (char *path
);
154 vfs
*vfs_split (char *path
, char **inpath
, char **op
);
155 vfsid
vfs_ncs_getid (vfs
*nvfs
, char *dir
, struct vfs_stamping
**par
);
156 void vfs_rm_parents (struct vfs_stamping
*stamp
);
157 char *vfs_path (char *path
);
158 char *vfs_strip_suffix_from_filename (char *filename
);
159 char *vfs_canon (char *path
);
160 char *mc_get_current_wd (char *buffer
, int bufsize
);
161 int vfs_current_is_local (void);
163 int vfs_current_is_extfs (void);
164 int vfs_current_is_tarfs (void);
166 int vfs_file_is_local (char *name
);
167 int vfs_file_is_ftp (char *filename
);
168 int vfs_file_is_smb (char *filename
);
169 char *vfs_get_current_dir (void);
171 void vfs_stamp (vfs
*, vfsid
);
172 void vfs_rmstamp (vfs
*, vfsid
, int);
173 void vfs_addstamp (vfs
*, vfsid
, struct vfs_stamping
*);
174 void vfs_add_noncurrent_stamps (vfs
*, vfsid
, struct vfs_stamping
*);
175 void vfs_add_current_stamps (void);
176 void vfs_free_resources(char *path
);
177 void vfs_timeout_handler ();
180 void vfs_fill_names (void (*)(char *));
181 char *vfs_translate_url (char *);
183 void ftpfs_set_debug (const char *file
);
185 void ftpfs_hint_reread(int reread
);
186 void ftpfs_flushdir(void);
188 # define ftpfs_flushdir()
189 # define ftpfs_hint_reread(x)
192 /* Only the routines outside of the VFS module need the emulation macros */
194 int mc_open (char *file
, int flags
, ...);
195 int mc_close (int handle
);
196 int mc_read (int handle
, char *buffer
, int count
);
197 int mc_write (int hanlde
, char *buffer
, int count
);
198 off_t
mc_lseek (int fd
, off_t offset
, int whence
);
199 int mc_chdir (char *);
201 DIR *mc_opendir (char *dirname
);
202 struct dirent
*mc_readdir(DIR *dirp
);
203 int mc_closedir (DIR *dir
);
204 int mc_telldir (DIR *dir
);
205 void mc_seekdir (DIR *dir
, int offset
);
207 int mc_stat (char *path
, struct stat
*buf
);
208 int mc_lstat (char *path
, struct stat
*buf
);
209 int mc_fstat (int fd
, struct stat
*buf
);
211 int mc_chmod (char *path
, int mode
);
212 int mc_chown (char *path
, int owner
, int group
);
213 int mc_utime (char *path
, struct utimbuf
*times
);
214 int mc_readlink (char *path
, char *buf
, int bufsiz
);
215 int mc_unlink (char *path
);
216 int mc_symlink (char *name1
, char *name2
);
217 int mc_link (char *name1
, char *name2
);
218 int mc_mknod (char *, int, int);
219 int mc_rename (char *original
, char *target
);
220 int mc_write (int fd
, char *buf
, int nbyte
);
221 int mc_rmdir (char *path
);
222 int mc_mkdir (char *path
, mode_t mode
);
224 char *mc_getlocalcopy (char *filename
);
225 void mc_ungetlocalcopy (char *filename
, char *local
, int has_changed
);
226 char *mc_def_getlocalcopy (vfs
*vfs
, char *filename
);
227 void mc_def_ungetlocalcopy (vfs
*vfs
, char *filename
, char *local
, int has_changed
);
228 int mc_ctl (int fd
, int ctlop
, int arg
);
229 int mc_setctl (char *path
, int ctlop
, char *arg
);
231 caddr_t
mc_mmap (caddr_t
, size_t, int, int, int, off_t
);
232 int mc_unmap (caddr_t
, size_t);
233 int mc_munmap (caddr_t addr
, size_t len
);
234 #endif /* HAVE_MMAP */
244 # define vfs_fill_names(x)
245 # define vfs_add_current_stamps()
246 # define vfs_current_is_local() 1
247 # define vfs_file_is_local(x) 1
248 # define vfs_file_is_ftp(x) 0
249 # define vfs_file_is_smb(x) 0
250 # define vfs_current_is_tarfs() 0
251 # define vfs_current_is_extfs() 0
252 # define vfs_path(x) x
253 # define vfs_strip_suffix_from_filename(x) g_strdup(x)
254 # define mc_close close
255 # define mc_read read
256 # define mc_write write
257 # define mc_lseek lseek
258 # define mc_opendir opendir
259 # define mc_readdir readdir
260 # define mc_closedir closedir
261 # define mc_telldir telldir
262 # define mc_seekdir seekdir
264 # define mc_get_current_wd(x,size) get_current_wd (x, size)
265 # define mc_fstat fstat
266 # define mc_lstat lstat
268 # define mc_readlink readlink
269 # define mc_symlink symlink
270 # define mc_rename rename
273 # define mc_open open
274 # define mc_utime utime
275 # define mc_chmod chmod
276 # define mc_chown chown
277 # define mc_chdir chdir
278 # define mc_unlink unlink
281 # define mc_mmap mmap
282 # define mc_munmap munmap
284 # define mc_ctl(a,b,c) 0
285 # define mc_setctl(a,b,c) 0
286 # define vfs_translate_url(s) g_strdup(s)
288 # define mc_stat stat
289 # define mc_mknod mknod
290 # define mc_link link
291 # define mc_mkdir mkdir
292 # define mc_rmdir rmdir
293 # define is_special_prefix(x) 0
294 # define vfs_type(x) (vfs *)(NULL)
297 # define vfs_canon(p) g_strdup (canonicalize_pathname(p))
298 # define vfs_free_resources()
299 # define vfs_timeout_handler()
300 # define vfs_timeouts() 0
301 # define vfs_force_expire()
305 # define mc_getlocalcopy(x) NULL
306 # define mc_ungetlocalcopy(x,y,z)
308 # define ftpfs_hint_reread(x)
309 # define ftpfs_flushdir()
318 # define mc_ctl(a,b,c) 0
321 # define mc_mkdir(a,b) mkdir(a)
327 #define mc_errno errno
329 /* These functions are meant for use by vfs modules */
331 extern int vfs_parse_ls_lga (char *p
, struct stat
*s
, char **filename
, char **linkname
);
332 extern int vfs_split_text (char *p
);
333 extern int vfs_parse_filetype (char c
);
334 extern int vfs_parse_filemode (char *p
);
335 extern int vfs_parse_filedate(int idx
, time_t *t
);
337 extern void vfs_die (char *msg
);
338 extern char *vfs_get_password (char *msg
);
339 extern char *vfs_split_url (char *path
, char **host
, char **user
, int *port
, char **pass
,
340 int default_port
, int flags
);
341 #define URL_DEFAULTANON 1
342 #define URL_NOSLASH 2
343 extern void vfs_print_stats (char *fs_name
, char *action
, char *file_name
, int have
, int need
);
345 /* Dont use values 0..4 for a while -- 10/98, pavel@ucw.cz */
346 #define MCCTL_REMOVELOCALCOPY 5
347 #define MCCTL_IS_NOTREADY 6
348 #define MCCTL_FORGET_ABOUT 7
349 #define MCCTL_EXTFS_RUN 8
350 /* These two make vfs layer give out potentially incorrect data, but
351 they also make some operation 100 times faster. Use with caution. */
352 #define MCCTL_WANT_STALE_DATA 9
353 #define MCCTL_NO_STALE_DATA 10
355 extern int vfs_flags
;
356 extern uid_t vfs_uid
;
357 extern gid_t vfs_gid
;
359 #define FL_ALWAYS_MAGIC 1
361 #define FL_NO_FTPFS 4
362 #define FL_NO_UNDELFS 8
363 #define FL_NO_TARFS 16
364 #define FL_NO_EXTFS 32
366 #define FL_NO_FISH 128
368 #define FL_NO_CWDSETUP 0x40000000
370 #ifdef VFS_STANDALONE
371 extern void mc_vfs_init( void );
372 extern void mc_vfs_done( void );
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 linearily from beggining 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 */