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