Move all stuff from lib to contrib
[midnight-commander.git] / vfs / vfs.h
blob6abb39cb715e64308ebd4959fc7b9311e5573349
2 /**
3 * \file
4 * \brief Header: Virtual File System switch code
5 */
7 #ifndef MC_VFS_VFS_H
8 #define MC_VFS_VFS_H
10 void vfs_init (void);
11 void vfs_shut (void);
13 char *vfs_strip_suffix_from_filename (const char *filename);
14 char *vfs_canon (const char *path);
15 char *mc_get_current_wd (char *buffer, int bufsize);
16 char *vfs_get_current_dir (void);
17 int vfs_current_is_local (void);
18 int vfs_file_is_local (const char *filename);
19 /* translate path back to terminal encoding, remove all #enc:
20 * every invalid character is replaced with question mark
21 * return static buffer */
22 char *vfs_translate_path (const char *path);
23 /* return new string */
24 char *vfs_translate_path_n (const char *path);
25 /* return encoding after last #enc: or NULL, if part does not contain #enc:
26 * return static buffer */
27 const char *vfs_get_encoding (const char *path);
28 /* canonize and translate path, return new string */
29 char *vfs_canon_and_translate (const char *path);
31 /* Only the routines outside of the VFS module need the emulation macros */
33 int mc_open (const char *filename, int flags, ...);
34 int mc_close (int handle);
35 ssize_t mc_read (int handle, void *buffer, int count);
36 ssize_t mc_write (int handle, const void *buffer, int count);
37 off_t mc_lseek (int fd, off_t offset, int whence);
38 int mc_chdir (const char *path);
40 DIR *mc_opendir (const char *dirname);
41 struct dirent *mc_readdir (DIR * dirp);
42 int mc_closedir (DIR * dir);
44 int mc_stat (const char *path, struct stat *buf);
45 int mc_lstat (const char *path, struct stat *buf);
46 int mc_fstat (int fd, struct stat *buf);
48 int mc_chmod (const char *path, mode_t mode);
49 int mc_chown (const char *path, uid_t owner, gid_t group);
50 int mc_utime (const char *path, struct utimbuf *times);
51 int mc_readlink (const char *path, char *buf, int bufsiz);
52 int mc_unlink (const char *path);
53 int mc_symlink (const char *name1, const char *name2);
54 int mc_link (const char *name1, const char *name2);
55 int mc_mknod (const char *, mode_t, dev_t);
56 int mc_rename (const char *original, const char *target);
57 int mc_rmdir (const char *path);
58 int mc_mkdir (const char *path, mode_t mode);
60 char *mc_getlocalcopy (const char *pathname);
61 int mc_ungetlocalcopy (const char *pathname, const char *local, int has_changed);
62 int mc_ctl (int fd, int ctlop, void *arg);
63 int mc_setctl (const char *path, int ctlop, void *arg);
65 /* Operations for mc_ctl - on open file */
66 enum {
67 VFS_CTL_IS_NOTREADY
70 /* Operations for mc_setctl - on path */
71 enum {
72 VFS_SETCTL_FORGET,
73 VFS_SETCTL_RUN,
74 VFS_SETCTL_LOGFILE,
75 VFS_SETCTL_FLUSH, /* invalidate directory cache */
77 /* Setting this makes vfs layer give out potentially incorrect data,
78 but it also makes some operations much faster. Use with caution. */
79 VFS_SETCTL_STALE_DATA
82 #define O_ALL (O_CREAT | O_EXCL | O_NOCTTY | O_NDELAY | O_SYNC | O_WRONLY | O_RDWR | O_RDONLY)
83 /* Midnight commander code should _not_ use other flags than those
84 listed above and O_APPEND */
86 #if (O_ALL & O_APPEND)
87 #warning "Unexpected problem with flags, O_LINEAR disabled, contact pavel@ucw.cz"
88 #define O_LINEAR 0
89 #define IS_LINEAR(a) 0
90 #define NO_LINEAR(a) a
91 #else
92 #define O_LINEAR O_APPEND
93 #define IS_LINEAR(a) ((a) == (O_RDONLY | O_LINEAR)) /* Return only 0 and 1 ! */
94 #define NO_LINEAR(a) (((a) == (O_RDONLY | O_LINEAR)) ? O_RDONLY : (a))
95 #endif
97 /* O_LINEAR is strange beast, be careful. If you open file asserting
98 * O_RDONLY | O_LINEAR, you promise:
100 * a) to read file linearly from beginning to the end
101 * b) not to open another file before you close this one
102 * (this will likely go away in future)
103 * as a special gift, you may
104 * c) lseek() immediately after open(), giving ftpfs chance to
105 * reget. Be warned that this lseek() can fail, and you _have_
106 * to handle that gratefully.
108 * O_LINEAR allows filesystems not to create temporary file in some
109 * cases (ftp transfer). -- pavel@ucw.cz
112 /* And now some defines for our errors. */
114 #ifdef ENOSYS
115 #define E_NOTSUPP ENOSYS /* for use in vfs when module does not provide function */
116 #else
117 #define E_NOTSUPP EFAULT /* Does this happen? */
118 #endif
120 #ifdef ENOMSG
121 #define E_UNKNOWN ENOMSG /* if we do not know what error happened */
122 #else
123 #define E_UNKNOWN EIO /* if we do not know what error happened */
124 #endif
126 #ifdef EREMOTEIO
127 #define E_REMOTE EREMOTEIO /* if other side of ftp/fish reports error */
128 #else
129 #define E_REMOTE ENETUNREACH /* :-( there's no EREMOTEIO on some systems */
130 #endif
132 #ifdef EPROTO
133 #define E_PROTO EPROTO /* if other side fails to follow protocol */
134 #else
135 #define E_PROTO EIO
136 #endif
138 #endif