Traslated some chmod mgs related (for win32 support? not shure)
[midnight-commander.git] / vfs / vfs.h
blob124dacdb975b03441185d7223e686023e2ca3331
1 #ifndef __VFS_H
2 #define __VFS_H
4 #ifdef USE_VFS
5 #ifdef HAVE_MMAP
6 #include <sys/mman.h>
7 #endif
9 #ifdef VFS_STANDALONE
10 #undef USE_EXT2FSLIB
11 #else
12 #undef BROKEN_PATHS
14 * Define this to allow /any/path/#ftp/ to access ftp tree. Broken, yes.
15 */
16 #endif
19 * The following line is needed, because as usual, AIX pollutes every single
20 * name space they can get their hands on
22 #undef vfs_type
24 /* Our virtual file system layer */
26 typedef void * vfsid;
28 struct vfs_stamping;
31 * Notice: Andrej Borsenkow <borsenkow.msk@sni.de> reports system
32 * (RelianUNIX), where it is bad idea to define struct vfs. That system
33 * has include called <sys/vfs.h>, which contains things like vfs_t.
36 typedef struct _vfs vfs;
38 struct _vfs {
39 vfs *next;
40 char *name; /* "FIles over SHell" */
41 int flags;
42 #define F_EXEC 1 /* Filesystem needs to execute external programs */
43 #define F_NET 2 /* Filesystem needs to access network */
44 char *prefix; /* "fish:" */
45 void *data; /* this is for filesystem's own use */
46 int verrno; /* can't use errno because glibc2 might define errno as function */
48 int (*init) (vfs *me);
49 void (*done) (vfs *me);
50 void (*fill_names) (vfs *me, void (*)(char *));
52 int (*which) (vfs *me, char *path);
54 void *(*open) (vfs *me, char *fname, int flags, int mode);
55 int (*close) (void *vfs_info);
56 int (*read) (void *vfs_info, char *buffer, int count);
57 int (*write) (void *vfs_info, char *buf, int count);
59 void *(*opendir) (vfs *me, char *dirname);
60 void *(*readdir) (void *vfs_info);
61 int (*closedir) (void *vfs_info);
62 int (*telldir) (void *vfs_info);
63 void (*seekdir) (void *vfs_info, int offset);
65 int (*stat) (vfs *me, char *path, struct stat *buf);
66 int (*lstat) (vfs *me, char *path, struct stat *buf);
67 int (*fstat) (void *vfs_info, struct stat *buf);
69 int (*chmod) (vfs *me, char *path, int mode);
70 int (*chown) (vfs *me, char *path, int owner, int group);
71 int (*utime) (vfs *me, char *path, struct utimbuf *times);
73 int (*readlink) (vfs *me, char *path, char *buf, int size);
74 int (*symlink) (vfs *me, char *n1, char *n2);
75 int (*link) (vfs *me, char *p1, char *p2);
76 int (*unlink) (vfs *me, char *path);
77 int (*rename) (vfs *me, char *p1, char *p2);
78 int (*chdir) (vfs *me, char *path);
79 int (*ferrno) (vfs *me);
80 int (*lseek) (void *vfs_info, off_t offset, int whence);
81 int (*mknod) (vfs *me, char *path, int mode, int dev);
83 vfsid (*getid) (vfs *me, char *path, struct vfs_stamping **
84 parent);
86 int (*nothingisopen) (vfsid id);
87 void (*free) (vfsid id);
89 char *(*getlocalcopy) (vfs *me, char *filename);
90 int (*ungetlocalcopy) (vfs *me, char *filename, char *local,
91 int has_changed);
93 int (*mkdir) (vfs *me, char *path, mode_t mode);
94 int (*rmdir) (vfs *me, char *path);
96 int (*ctl) (void *vfs_info, int ctlop, int arg);
97 int (*setctl) (vfs *me, char *path, int ctlop, char *arg);
98 #ifdef HAVE_MMAP
99 caddr_t (*mmap) (vfs *me, caddr_t addr, size_t len, int prot,
100 int flags, void *vfs_info, off_t offset);
101 int (*munmap) (vfs *me, caddr_t addr, size_t len,
102 void *vfs_info);
103 #endif
106 /* Other file systems */
107 extern vfs vfs_local_ops;
108 extern vfs vfs_nil_ops;
109 extern vfs vfs_tarfs_ops;
110 extern vfs vfs_cpiofs_ops;
112 extern vfs vfs_ftpfs_ops;
113 extern vfs vfs_smbfs_ops;
114 extern vfs vfs_fish_ops;
115 extern vfs vfs_mcfs_ops;
117 extern vfs vfs_extfs_ops;
118 extern vfs vfs_sfs_ops;
120 extern vfs vfs_undelfs_ops;
122 struct vfs_stamping {
123 vfs *v;
124 vfsid id;
125 struct vfs_stamping *parent; /* At the moment applies to tarfs only */
126 struct vfs_stamping *next;
127 struct timeval time;
130 void vfs_init (void);
131 void vfs_shut (void);
133 extern int vfs_type_absolute;
134 vfs *vfs_type (char *path);
135 vfs *vfs_split (char *path, char **inpath, char **op);
136 vfsid vfs_ncs_getid (vfs *nvfs, char *dir, struct vfs_stamping **par);
137 void vfs_rm_parents (struct vfs_stamping *stamp);
138 char *vfs_path (char *path);
139 char *vfs_strip_suffix_from_filename (const char *filename);
140 char *vfs_canon (const char *path);
141 char *mc_get_current_wd (char *buffer, int bufsize);
142 int vfs_current_is_local (void);
143 #if 0
144 int vfs_current_is_extfs (void);
145 int vfs_current_is_tarfs (void);
146 int vfs_current_is_cpiofs (void);
147 #endif
148 int vfs_file_is_local (const char *name);
149 int vfs_file_is_ftp (char *filename);
150 int vfs_file_is_smb (char *filename);
151 char *vfs_get_current_dir (void);
153 void vfs_stamp (vfs *, vfsid);
154 void vfs_rmstamp (vfs *, vfsid, int);
155 void vfs_addstamp (vfs *, vfsid, struct vfs_stamping *);
156 void vfs_add_noncurrent_stamps (vfs *, vfsid, struct vfs_stamping *);
157 void vfs_add_current_stamps (void);
158 void vfs_free_resources(char *path);
159 void vfs_timeout_handler (void);
160 void vfs_expire (int);
161 int vfs_timeouts (void);
163 void vfs_fill_names (void (*)(char *));
164 char *vfs_translate_url (char *);
166 void ftpfs_set_debug (const char *file);
167 #ifdef USE_NETCODE
168 void ftpfs_hint_reread(int reread);
169 void ftpfs_flushdir(void);
170 #else
171 # define ftpfs_flushdir()
172 # define ftpfs_hint_reread(x)
173 #endif
175 /* Only the routines outside of the VFS module need the emulation macros */
177 int mc_open (const char *filename, int flags, ...);
178 int mc_close (int handle);
179 int mc_read (int handle, char *buffer, int count);
180 int mc_write (int handle, char *buffer, int count);
181 off_t mc_lseek (int fd, off_t offset, int whence);
182 int mc_chdir (char *);
184 DIR *mc_opendir (char *dirname);
185 struct dirent *mc_readdir(DIR *dirp);
186 int mc_closedir (DIR *dir);
187 int mc_telldir (DIR *dir);
188 void mc_seekdir (DIR *dir, int offset);
190 int mc_stat (char *path, struct stat *buf);
191 int mc_lstat (char *path, struct stat *buf);
192 int mc_fstat (int fd, struct stat *buf);
194 int mc_chmod (char *path, int mode);
195 int mc_chown (char *path, int owner, int group);
196 int mc_utime (char *path, struct utimbuf *times);
197 int mc_readlink (char *path, char *buf, int bufsiz);
198 int mc_unlink (char *path);
199 int mc_symlink (char *name1, char *name2);
200 int mc_link (char *name1, char *name2);
201 int mc_mknod (char *, int, int);
202 int mc_rename (char *original, char *target);
203 int mc_write (int fd, char *buf, int nbyte);
204 int mc_rmdir (char *path);
205 int mc_mkdir (char *path, mode_t mode);
207 char *mc_getlocalcopy (const char *pathname);
208 int mc_ungetlocalcopy (const char *pathname, char *local, int has_changed);
209 char *mc_def_getlocalcopy (vfs *vfs, char *filename);
210 int mc_def_ungetlocalcopy (vfs *vfs, char *filename, char *local, int has_changed);
211 int mc_ctl (int fd, int ctlop, int arg);
212 int mc_setctl (char *path, int ctlop, char *arg);
213 #ifdef HAVE_MMAP
214 caddr_t mc_mmap (caddr_t, size_t, int, int, int, off_t);
215 int mc_unmap (caddr_t, size_t);
216 int mc_munmap (caddr_t addr, size_t len);
217 #endif /* HAVE_MMAP */
219 #else
221 #ifdef USE_NETCODE
222 # undef USE_NETCODE
223 #endif
225 # undef USE_NETCODE
227 # define vfs_fill_names(x) do { } while (0)
228 # define vfs_add_current_stamps() do { } while (0)
229 # define vfs_current_is_local() 1
230 # define vfs_file_is_local(x) 1
231 # define vfs_file_is_ftp(x) 0
232 # define vfs_file_is_smb(x) 0
233 # define vfs_current_is_tarfs() 0
234 # define vfs_current_is_cpiofs() 0
235 # define vfs_current_is_extfs() 0
236 # define vfs_path(x) x
237 # define vfs_strip_suffix_from_filename(x) g_strdup(x)
238 # define mc_close close
239 # define mc_read read
240 # define mc_write write
241 # define mc_lseek lseek
242 # define mc_opendir opendir
243 # define mc_readdir readdir
244 # define mc_closedir closedir
245 # define mc_telldir telldir
246 # define mc_seekdir seekdir
248 # define mc_get_current_wd(x,size) get_current_wd (x, size)
249 # define mc_fstat fstat
250 # define mc_lstat lstat
252 # define mc_readlink readlink
253 # define mc_symlink symlink
254 # define mc_rename rename
256 # define mc_open open
257 # define mc_utime utime
258 # define mc_chmod chmod
259 # define mc_chown chown
260 # define mc_chdir chdir
261 # define mc_unlink unlink
263 # define mc_mmap mmap
264 # define mc_munmap munmap
266 # define mc_ctl(a,b,c) 0
267 # define mc_setctl(a,b,c) 0
268 # define vfs_translate_url(s) g_strdup(s)
270 # define mc_stat stat
271 # define mc_mknod mknod
272 # define mc_link link
273 # define mc_mkdir mkdir
274 # define mc_rmdir rmdir
275 # define is_special_prefix(x) 0
276 # define vfs_type(x) (vfs *)(NULL)
277 # define vfs_init() do { } while (0)
278 # define vfs_shut() do { } while (0)
279 # define vfs_canon(p) g_strdup (canonicalize_pathname(p))
280 # define vfs_free_resources() do { } while (0)
281 # define vfs_timeout_handler() do { } while (0)
282 # define vfs_timeouts() 0
283 # define vfs_force_expire() do { } while (0)
285 typedef int vfs;
287 # define mc_getlocalcopy(x) NULL
288 # define mc_ungetlocalcopy(x,y,z) do { } while (0)
290 # define ftpfs_hint_reread(x) do { } while (0)
291 # define ftpfs_flushdir() do { } while (0)
293 #ifdef _OS_NT
294 # undef mc_rmdir
295 #endif
297 #ifdef OS2_NT
298 # undef mc_ctl
299 # undef mc_unlink
300 # define mc_ctl(a,b,c) 0
301 # ifndef __EMX__
302 # undef mc_mkdir
303 # define mc_mkdir(a,b) mkdir(a)
304 # endif
305 #endif
307 #endif /* USE_VFS */
309 #define mc_errno errno
311 /* These functions are meant for use by vfs modules */
313 extern int vfs_parse_ls_lga (const char *p, struct stat *s, char **filename, char **linkname);
314 extern int vfs_split_text (char *p);
315 extern int vfs_parse_filetype (char c);
316 extern int vfs_parse_filemode (const char *p);
317 extern int vfs_parse_filedate(int idx, time_t *t);
319 extern void vfs_die (char *msg);
320 extern char *vfs_get_password (char *msg);
321 extern char *vfs_split_url (const char *path, char **host, char **user,
322 int *port, char **pass, int default_port, int flags);
324 #ifdef WITH_SMBFS
325 /* Interface for requesting SMB credentials. */
326 struct smb_authinfo {
327 char *host;
328 char *share;
329 char *domain;
330 char *user;
331 char *password;
334 struct smb_authinfo *
335 vfs_smb_get_authinfo (const char *host, const char *share, const char *domain,
336 const char *user);
337 #endif /* WITH_SMBFS */
339 #define URL_DEFAULTANON 1
340 #define URL_NOSLASH 2
341 extern void vfs_print_stats (char *fs_name, char *action, char *file_name, int have, int 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 extern int vfs_flags;
354 extern uid_t vfs_uid;
355 extern gid_t vfs_gid;
357 #define FL_ALWAYS_MAGIC 1
358 #define FL_NO_MCFS 2
359 #define FL_NO_FTPFS 4
360 #define FL_NO_UNDELFS 8
361 #define FL_NO_TARFS 16
362 #define FL_NO_EXTFS 32
363 #define FL_NO_SFS 64
364 #define FL_NO_FISH 128
366 #define FL_NO_LOCALHASH 0x20000000 /* When you never ever want vfs to work with regular files with # in name */
367 #define FL_NO_CWDSETUP 0x40000000
370 #ifdef VFS_STANDALONE
371 extern void mc_vfs_init( void );
372 extern void mc_vfs_done( void );
373 #endif
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 */