1
2
3
4
5
6
7 #ifndef MC__VFS_VFS_H
8 #define MC__VFS_VFS_H
9
10 #include <sys/types.h>
11 #include <sys/stat.h>
12 #include <dirent.h>
13 #ifdef HAVE_UTIMENSAT
14 #include <sys/time.h>
15 #elif defined (HAVE_UTIME_H)
16 #include <utime.h>
17 #endif
18 #include <stdio.h>
19 #include <unistd.h>
20 #include <stddef.h>
21
22 #include "lib/global.h"
23
24 #include "path.h"
25
26
27
28 #define VFS_CLASS(a) ((struct vfs_class *) (a))
29
30 #if defined (ENABLE_VFS_FTP) || defined (ENABLE_VFS_FISH)
31 #define ENABLE_VFS_NET 1
32 #endif
33
34
35
36
37
38
39
40
41 #define VFS_ENCODING_PREFIX "#enc:"
42
43 #define O_ALL (O_CREAT | O_EXCL | O_NOCTTY | O_NDELAY | O_SYNC | O_WRONLY | O_RDWR | O_RDONLY)
44
45
46
47 #if (O_ALL & O_APPEND)
48 #warning "Unexpected problem with flags, O_LINEAR disabled, contact pavel@ucw.cz"
49 #define O_LINEAR 0
50 #define IS_LINEAR(a) 0
51 #define NO_LINEAR(a) a
52 #else
53 #define O_LINEAR O_APPEND
54 #define IS_LINEAR(a) ((a) == (O_RDONLY | O_LINEAR))
55 #define NO_LINEAR(a) (((a) == (O_RDONLY | O_LINEAR)) ? O_RDONLY : (a))
56 #endif
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75 #ifdef ENOMSG
76 #define E_UNKNOWN ENOMSG
77 #else
78 #define E_UNKNOWN EIO
79 #endif
80
81 #ifdef EREMOTEIO
82 #define E_REMOTE EREMOTEIO
83 #else
84 #define E_REMOTE ENETUNREACH
85 #endif
86
87 #ifdef EPROTO
88 #define E_PROTO EPROTO
89 #else
90 #define E_PROTO EIO
91 #endif
92
93 typedef void (*fill_names_f) (const char *);
94
95 typedef void *vfsid;
96
97 #ifdef HAVE_UTIMENSAT
98 typedef struct timespec mc_timesbuf_t[2];
99 #else
100 typedef struct utimbuf mc_timesbuf_t;
101 #endif
102
103
104
105 typedef enum
106 {
107 VFSF_UNKNOWN = 0,
108 VFSF_LOCAL = 1 << 0,
109 VFSF_NOLINKS = 1 << 1,
110
111 VFSF_REMOTE = 1 << 2,
112 VFSF_READONLY = 1 << 3,
113 VFSF_USETMP = 1 << 4
114 } vfs_flags_t;
115
116
117 enum
118 {
119 VFS_CTL_IS_NOTREADY
120 };
121
122
123 enum
124 {
125 VFS_SETCTL_FORGET,
126 VFS_SETCTL_RUN,
127 VFS_SETCTL_LOGFILE,
128 VFS_SETCTL_FLUSH,
129
130
131
132 VFS_SETCTL_STALE_DATA
133 };
134
135
136
137 typedef struct vfs_class
138 {
139 const char *name;
140 vfs_flags_t flags;
141 const char *prefix;
142 int verrno;
143 gboolean flush;
144 FILE *logfile;
145
146
147 int (*init) (struct vfs_class * me);
148 void (*done) (struct vfs_class * me);
149
150
151
152
153
154 void (*fill_names) (struct vfs_class * me, fill_names_f);
155
156
157
158
159
160 int (*which) (struct vfs_class * me, const char *path);
161
162 void *(*open) (const vfs_path_t * vpath, int flags, mode_t mode);
163 int (*close) (void *vfs_info);
164 ssize_t (*read) (void *vfs_info, char *buffer, size_t count);
165 ssize_t (*write) (void *vfs_info, const char *buf, size_t count);
166
167 void *(*opendir) (const vfs_path_t * vpath);
168 struct vfs_dirent *(*readdir) (void *vfs_info);
169 int (*closedir) (void *vfs_info);
170
171 int (*stat) (const vfs_path_t * vpath, struct stat * buf);
172 int (*lstat) (const vfs_path_t * vpath, struct stat * buf);
173 int (*fstat) (void *vfs_info, struct stat * buf);
174
175 int (*chmod) (const vfs_path_t * vpath, mode_t mode);
176 int (*chown) (const vfs_path_t * vpath, uid_t owner, gid_t group);
177 int (*utime) (const vfs_path_t * vpath, mc_timesbuf_t * times);
178
179 int (*readlink) (const vfs_path_t * vpath, char *buf, size_t size);
180 int (*symlink) (const vfs_path_t * vpath1, const vfs_path_t * vpath2);
181 int (*link) (const vfs_path_t * vpath1, const vfs_path_t * vpath2);
182 int (*unlink) (const vfs_path_t * vpath);
183 int (*rename) (const vfs_path_t * vpath1, const vfs_path_t * vpath2);
184 int (*chdir) (const vfs_path_t * vpath);
185 int (*ferrno) (struct vfs_class * me);
186 off_t (*lseek) (void *vfs_info, off_t offset, int whence);
187 int (*mknod) (const vfs_path_t * vpath, mode_t mode, dev_t dev);
188
189 vfsid (*getid) (const vfs_path_t * vpath);
190
191 gboolean (*nothingisopen) (vfsid id);
192 void (*free) (vfsid id);
193
194 vfs_path_t *(*getlocalcopy) (const vfs_path_t * vpath);
195 int (*ungetlocalcopy) (const vfs_path_t * vpath, const vfs_path_t * local_vpath,
196 gboolean has_changed);
197
198 int (*mkdir) (const vfs_path_t * vpath, mode_t mode);
199 int (*rmdir) (const vfs_path_t * vpath);
200
201 int (*ctl) (void *vfs_info, int ctlop, void *arg);
202 int (*setctl) (const vfs_path_t * vpath, int ctlop, void *arg);
203
204 } vfs_class;
205
206
207
208
209
210 struct vfs_dirent
211 {
212
213 GString *d_name_str;
214
215
216 ino_t d_ino;
217 char *d_name;
218 };
219
220
221
222 extern int vfs_timeout;
223
224 #ifdef ENABLE_VFS_NET
225 extern int use_netrc;
226 #endif
227
228
229
230
231 void vfs_init_class (struct vfs_class *vclass, const char *name, vfs_flags_t flags,
232 const char *prefix);
233
234 void *vfs_s_open (const vfs_path_t * vpath, int flags, mode_t mode);
235 int vfs_s_stat (const vfs_path_t * vpath, struct stat *buf);
236 int vfs_s_lstat (const vfs_path_t * vpath, struct stat *buf);
237 int vfs_s_fstat (void *fh, struct stat *buf);
238
239 void vfs_adjust_stat (struct stat *s);
240
241 vfsid vfs_getid (const vfs_path_t * vpath);
242
243 void vfs_init (void);
244 void vfs_shut (void);
245
246 gboolean vfs_register_class (struct vfs_class *vfs);
247 void vfs_unregister_class (struct vfs_class *vfs);
248
249 void vfs_setup_work_dir (void);
250
251 void vfs_timeout_handler (void);
252 int vfs_timeouts (void);
253 void vfs_expire (gboolean now);
254
255 const char *vfs_get_current_dir (void);
256 char *vfs_get_current_dir_n (void);
257 const vfs_path_t *vfs_get_raw_current_dir (void);
258 void vfs_set_raw_current_dir (const vfs_path_t * vpath);
259
260 gboolean vfs_current_is_local (void);
261 gboolean vfs_file_is_local (const vfs_path_t * vpath);
262
263 char *vfs_strip_suffix_from_filename (const char *filename);
264
265 vfs_flags_t vfs_file_class_flags (const vfs_path_t * vpath);
266
267
268
269
270 const char *vfs_translate_path (const char *path);
271
272 char *vfs_translate_path_n (const char *path);
273
274 void vfs_stamp_path (const vfs_path_t * path);
275
276 void vfs_release_path (const vfs_path_t * vpath);
277
278 struct vfs_dirent *vfs_dirent_init (struct vfs_dirent *d, const char *fname, ino_t ino);
279 void vfs_dirent_assign (struct vfs_dirent *d, const char *fname, ino_t ino);
280 void vfs_dirent_free (struct vfs_dirent *d);
281
282 void vfs_fill_names (fill_names_f);
283
284
285 void vfs_print_message (const char *msg, ...) G_GNUC_PRINTF (1, 2);
286
287
288 int vfs_ferrno (struct vfs_class *vfs);
289
290 int vfs_new_handle (struct vfs_class *vclass, void *fsinfo);
291
292 struct vfs_class *vfs_class_find_by_handle (int handle, void **fsinfo);
293
294 void vfs_free_handle (int handle);
295
296 void vfs_setup_cwd (void);
297 char *_vfs_get_cwd (void);
298
299 int vfs_preallocate (int dest_desc, off_t src_fsize, off_t dest_fsize);
300
301 int vfs_clone_file (int dest_vfs_fd, int src_vfs_fd);
302
303
304
305
306 ssize_t mc_read (int handle, void *buffer, size_t count);
307 ssize_t mc_write (int handle, const void *buffer, size_t count);
308 int mc_utime (const vfs_path_t * vpath, mc_timesbuf_t * times);
309 int mc_readlink (const vfs_path_t * vpath, char *buf, size_t bufsiz);
310 int mc_close (int handle);
311 off_t mc_lseek (int fd, off_t offset, int whence);
312 DIR *mc_opendir (const vfs_path_t * vpath);
313 struct vfs_dirent *mc_readdir (DIR * dirp);
314 int mc_closedir (DIR * dir);
315 int mc_stat (const vfs_path_t * vpath, struct stat *buf);
316 int mc_mknod (const vfs_path_t * vpath, mode_t mode, dev_t dev);
317 int mc_link (const vfs_path_t * vpath1, const vfs_path_t * vpath2);
318 int mc_mkdir (const vfs_path_t * vpath, mode_t mode);
319 int mc_rmdir (const vfs_path_t * vpath);
320 int mc_fstat (int fd, struct stat *buf);
321 int mc_lstat (const vfs_path_t * vpath, struct stat *buf);
322 int mc_symlink (const vfs_path_t * vpath1, const vfs_path_t * vpath2);
323 int mc_rename (const vfs_path_t * vpath1, const vfs_path_t * vpath2);
324 int mc_chmod (const vfs_path_t * vpath, mode_t mode);
325 int mc_chown (const vfs_path_t * vpath, uid_t owner, gid_t group);
326 int mc_chdir (const vfs_path_t * vpath);
327 int mc_unlink (const vfs_path_t * vpath);
328 int mc_ctl (int fd, int ctlop, void *arg);
329 int mc_setctl (const vfs_path_t * vpath, int ctlop, void *arg);
330 int mc_open (const vfs_path_t * vpath, int flags, ...);
331 vfs_path_t *mc_getlocalcopy (const vfs_path_t * pathname_vpath);
332 int mc_ungetlocalcopy (const vfs_path_t * pathname_vpath, const vfs_path_t * local_vpath,
333 gboolean has_changed);
334 int mc_mkstemps (vfs_path_t ** pname_vpath, const char *prefix, const char *suffix);
335
336
337 const char *mc_tmpdir (void);
338
339
340
341
342 #endif