mc.sh & mc.csh creation fixed...
[midnight-commander.git] / vfs / vfs.h
blob65cd2e98404ef8461ab491ca2ddc50d5645ab146
1 #ifndef __VFS_H
2 #define __VFS_H
4 #ifdef USE_VFS
5 #ifdef HAVE_MMAP
6 #include <sys/mman.h>
7 #endif
11 * The following line is needed, because as usual, AIX pollutes every single
12 * name space they can get their hands on
14 #undef vfs_type
16 /* Our virtual file system layer */
18 typedef void * vfsid;
20 struct vfs_stamping;
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;
30 struct _vfs {
31 vfs *next;
32 char *name; /* "FIles over SHell" */
33 int flags;
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 **
76 parent);
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,
83 int has_changed);
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);
90 #ifdef HAVE_MMAP
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,
94 void *vfs_info);
95 #endif
99 * This union is used to ensure that there is enough space for the
100 * filename (d_name) when the dirent structure is created.
102 union vfs_dirent {
103 struct dirent dent;
104 char _extra_buffer [((int) &((struct dirent *)0)->d_name) +
105 MC_MAXPATHLEN + 1];
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 {
125 vfs *v;
126 vfsid id;
127 struct vfs_stamping *parent; /* At the moment applies to tarfs only */
128 struct vfs_stamping *next;
129 struct timeval time;
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 #if 0
146 int vfs_current_is_extfs (void);
147 int vfs_current_is_tarfs (void);
148 int vfs_current_is_cpiofs (void);
149 #endif
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);
169 #ifdef USE_NETCODE
170 void ftpfs_hint_reread(int reread);
171 void ftpfs_flushdir(void);
172 extern int use_netrc;
173 #else
174 # define ftpfs_flushdir()
175 # define ftpfs_hint_reread(x)
176 #endif
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);
216 #ifdef HAVE_MMAP
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 */
222 #else
224 #ifdef USE_NETCODE
225 # undef USE_NETCODE
226 #endif
228 # undef USE_NETCODE
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)
287 typedef int vfs;
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)
295 #ifdef NATIVE_WIN32
296 # undef mc_rmdir
297 #endif
299 #ifdef NATIVE_WIN32
300 # undef mc_ctl
301 # undef mc_unlink
302 # define mc_ctl(a,b,c) 0
303 # ifndef __EMX__
304 # undef mc_mkdir
305 # define mc_mkdir(a,b) mkdir(a)
306 # endif
307 #endif
309 #endif /* USE_VFS */
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);
331 #ifdef WITH_SMBFS
332 /* Interface for requesting SMB credentials. */
333 struct smb_authinfo {
334 char *host;
335 char *share;
336 char *domain;
337 char *user;
338 char *password;
341 struct smb_authinfo *
342 vfs_smb_get_authinfo (const char *host, const char *share, const char *domain,
343 const char *user);
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
359 #define vfs_uid 0
360 #define vfs_gid 0
362 #define FL_ALWAYS_MAGIC 1
363 #define FL_NO_MCFS 2
364 #define FL_NO_FTPFS 4
365 #define FL_NO_UNDELFS 8
366 #define FL_NO_TARFS 16
367 #define FL_NO_EXTFS 32
368 #define FL_NO_SFS 64
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"
381 #define O_LINEAR 0
382 #define IS_LINEAR(a) 0
383 #define NO_LINEAR(a) a
384 #else
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))
388 #endif
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
405 #ifdef HAVE_MMAP
406 #define MMAPNULL , NULL, NULL
407 #else
408 #define MMAPNULL
409 #endif
411 /* And now some defines for our errors. */
413 #ifdef ENOSYS
414 #define E_NOTSUPP ENOSYS /* for use in vfs when module does not provide function */
415 #else
416 #define E_NOTSUPP EFAULT /* Does this happen? */
417 #endif
419 #ifdef ENOMSG
420 #define E_UNKNOWN ENOMSG /* if we do not know what error happened */
421 #else
422 #define E_UNKNOWN EIO /* if we do not know what error happened */
423 #endif
425 #ifdef EREMOTEIO
426 #define E_REMOTE EREMOTEIO /* if other side of ftp/fish reports error */
427 #else
428 #define E_REMOTE ENETUNREACH /* :-( there's no EREMOTEIO on some systems */
429 #endif
431 #ifdef EPROTO
432 #define E_PROTO EPROTO /* if other side fails to follow protocol */
433 #else
434 #define E_PROTO EIO
435 #endif
437 #endif /* __VFS_H */