This source file includes following definitions.
- local_open
- local_opendir
- local_readdir
- local_closedir
- local_stat
- local_lstat
- local_chmod
- local_chown
- local_fgetflags
- local_fsetflags
- local_utime
- local_readlink
- local_unlink
- local_symlink
- local_write
- local_rename
- local_chdir
- local_mknod
- local_link
- local_mkdir
- local_rmdir
- local_getlocalcopy
- local_ungetlocalcopy
- local_which
- local_read
- local_close
- local_errno
- local_fstat
- local_lseek
- local_nothingisopen
- vfs_init_localfs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28 #include <config.h>
29
30 #include <errno.h>
31 #include <sys/types.h>
32 #include <unistd.h>
33 #include <stdio.h>
34 #include <string.h>
35 #ifdef ENABLE_EXT2FS_ATTR
36 #include <e2p/e2p.h>
37 #endif
38
39 #include "lib/global.h"
40
41 #include "lib/vfs/xdirentry.h"
42 #include "lib/vfs/utilvfs.h"
43
44 #include "local.h"
45
46
47
48
49
50
51
52
53
54
55
56 static struct vfs_s_subclass local_subclass;
57 static struct vfs_class *vfs_local_ops = VFS_CLASS (&local_subclass);
58
59
60
61
62
63 static void *
64 local_open (const vfs_path_t *vpath, int flags, mode_t mode)
65 {
66 int *local_info;
67 int fd;
68 const char *path;
69
70 path = vfs_path_get_last_path_str (vpath);
71 fd = open (path, NO_LINEAR (flags), mode);
72 if (fd == -1)
73 return NULL;
74
75 local_info = g_new (int, 1);
76 *local_info = fd;
77
78 return local_info;
79 }
80
81
82
83 static void *
84 local_opendir (const vfs_path_t *vpath)
85 {
86 DIR *dir = NULL;
87
88 const char *path = vfs_path_get_last_path_str (vpath);
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104 while (dir == NULL)
105 {
106 dir = opendir (path);
107 if (dir == NULL)
108 {
109
110 if (errno == EINTR)
111 continue;
112
113 return NULL;
114 }
115
116
117 errno = 0;
118
119 if (readdir (dir) == NULL && errno == EINTR)
120 {
121 closedir (dir);
122 dir = NULL;
123 }
124 else
125 rewinddir (dir);
126 }
127
128 DIR **local_info = (DIR **) g_new (DIR *, 1);
129 *local_info = dir;
130
131 return local_info;
132 }
133
134
135
136 static struct vfs_dirent *
137 local_readdir (void *data)
138 {
139 struct dirent *d;
140 unsigned char type;
141
142
143
144
145 do
146 {
147 errno = 0;
148 d = readdir (*(DIR **) data);
149 }
150 while (d == NULL && errno == EINTR);
151
152 if (d == NULL)
153 return NULL;
154
155 #ifdef HAVE_STRUCT_DIRENT_D_TYPE
156 type = d->d_type;
157 #else
158 type = DT_UNKNOWN;
159 #endif
160
161 return vfs_dirent_init (NULL, d->d_name, d->d_ino, type);
162 }
163
164
165
166 static int
167 local_closedir (void *data)
168 {
169 int i;
170
171 i = closedir (*(DIR **) data);
172 g_free (data);
173 return i;
174 }
175
176
177
178 static int
179 local_stat (const vfs_path_t *vpath, struct stat *buf)
180 {
181 const char *path;
182
183 path = vfs_path_get_last_path_str (vpath);
184 return stat (path, buf);
185 }
186
187
188
189 static int
190 local_lstat (const vfs_path_t *vpath, struct stat *buf)
191 {
192 const char *path;
193
194 path = vfs_path_get_last_path_str (vpath);
195 #ifndef HAVE_STATLSTAT
196 return lstat (path, buf);
197 #else
198 return statlstat (path, buf);
199 #endif
200 }
201
202
203
204 static int
205 local_chmod (const vfs_path_t *vpath, mode_t mode)
206 {
207 const char *path;
208
209 path = vfs_path_get_last_path_str (vpath);
210 return chmod (path, mode);
211 }
212
213
214
215 static int
216 local_chown (const vfs_path_t *vpath, uid_t owner, gid_t group)
217 {
218 const char *path;
219
220 path = vfs_path_get_last_path_str (vpath);
221 return chown (path, owner, group);
222 }
223
224
225
226 #ifdef ENABLE_EXT2FS_ATTR
227
228 static int
229 local_fgetflags (const vfs_path_t *vpath, unsigned long *flags)
230 {
231 const char *path;
232
233 path = vfs_path_get_last_path_str (vpath);
234 return fgetflags (path, flags);
235 }
236
237
238
239 static int
240 local_fsetflags (const vfs_path_t *vpath, unsigned long flags)
241 {
242 const char *path;
243
244 path = vfs_path_get_last_path_str (vpath);
245 return fsetflags (path, flags);
246 }
247
248 #endif
249
250
251
252 static int
253 local_utime (const vfs_path_t *vpath, mc_timesbuf_t *times)
254 {
255 return vfs_utime (vfs_path_get_last_path_str (vpath), times);
256 }
257
258
259
260 static int
261 local_readlink (const vfs_path_t *vpath, char *buf, size_t size)
262 {
263 const char *path;
264
265 path = vfs_path_get_last_path_str (vpath);
266 return readlink (path, buf, size);
267 }
268
269
270
271 static int
272 local_unlink (const vfs_path_t *vpath)
273 {
274 const char *path;
275
276 path = vfs_path_get_last_path_str (vpath);
277 return unlink (path);
278 }
279
280
281
282 static int
283 local_symlink (const vfs_path_t *vpath1, const vfs_path_t *vpath2)
284 {
285 const char *path1, *path2;
286
287 path1 = vfs_path_get_last_path_str (vpath1);
288 path2 = vfs_path_get_last_path_str (vpath2);
289 return symlink (path1, path2);
290 }
291
292
293
294 static ssize_t
295 local_write (void *data, const char *buf, size_t nbyte)
296 {
297 int fd;
298 int n;
299
300 if (data == NULL)
301 return (-1);
302
303 fd = *(int *) data;
304
305 while ((n = write (fd, buf, nbyte)) == -1)
306 {
307 #ifdef EAGAIN
308 if (errno == EAGAIN)
309 continue;
310 #endif
311 #ifdef EINTR
312 if (errno == EINTR)
313 continue;
314 #endif
315 break;
316 }
317
318 return n;
319 }
320
321
322
323 static int
324 local_rename (const vfs_path_t *vpath1, const vfs_path_t *vpath2)
325 {
326 const char *path1, *path2;
327
328 path1 = vfs_path_get_last_path_str (vpath1);
329 path2 = vfs_path_get_last_path_str (vpath2);
330 return rename (path1, path2);
331 }
332
333
334
335 static int
336 local_chdir (const vfs_path_t *vpath)
337 {
338 const char *path;
339
340 path = vfs_path_get_last_path_str (vpath);
341 return chdir (path);
342 }
343
344
345
346 static int
347 local_mknod (const vfs_path_t *vpath, mode_t mode, dev_t dev)
348 {
349 const char *path;
350
351 path = vfs_path_get_last_path_str (vpath);
352 return mknod (path, mode, dev);
353 }
354
355
356
357 static int
358 local_link (const vfs_path_t *vpath1, const vfs_path_t *vpath2)
359 {
360 const char *path1, *path2;
361
362 path1 = vfs_path_get_last_path_str (vpath1);
363 path2 = vfs_path_get_last_path_str (vpath2);
364 return link (path1, path2);
365 }
366
367
368
369 static int
370 local_mkdir (const vfs_path_t *vpath, mode_t mode)
371 {
372 const char *path;
373
374 path = vfs_path_get_last_path_str (vpath);
375 return mkdir (path, mode);
376 }
377
378
379
380 static int
381 local_rmdir (const vfs_path_t *vpath)
382 {
383 const char *path;
384
385 path = vfs_path_get_last_path_str (vpath);
386 return rmdir (path);
387 }
388
389
390
391 static vfs_path_t *
392 local_getlocalcopy (const vfs_path_t *vpath)
393 {
394 return vfs_path_clone (vpath);
395 }
396
397
398
399 static int
400 local_ungetlocalcopy (const vfs_path_t *vpath, const vfs_path_t *local, gboolean has_changed)
401 {
402 (void) vpath;
403 (void) local;
404 (void) has_changed;
405
406 return 0;
407 }
408
409
410
411 static int
412 local_which (struct vfs_class *me, const char *path)
413 {
414 (void) me;
415 (void) path;
416
417 return 0;
418 }
419
420
421
422
423
424 ssize_t
425 local_read (void *data, char *buffer, size_t count)
426 {
427 int n;
428 int fd;
429
430 if (data == NULL)
431 return (-1);
432
433 fd = *(int *) data;
434
435 while ((n = read (fd, buffer, count)) == -1)
436 {
437 #ifdef EAGAIN
438 if (errno == EAGAIN)
439 continue;
440 #endif
441 #ifdef EINTR
442 if (errno == EINTR)
443 continue;
444 #endif
445 return (-1);
446 }
447
448 return n;
449 }
450
451
452
453 int
454 local_close (void *data)
455 {
456 int fd;
457
458 if (data == NULL)
459 return (-1);
460
461 fd = *(int *) data;
462 g_free (data);
463 return close (fd);
464 }
465
466
467
468 int
469 local_errno (struct vfs_class *me)
470 {
471 (void) me;
472 return errno;
473 }
474
475
476
477 int
478 local_fstat (void *data, struct stat *buf)
479 {
480 int fd = *(int *) data;
481
482 return fstat (fd, buf);
483 }
484
485
486
487 off_t
488 local_lseek (void *data, off_t offset, int whence)
489 {
490 int fd = *(int *) data;
491
492 return lseek (fd, offset, whence);
493 }
494
495
496
497 static gboolean
498 local_nothingisopen (vfsid id)
499 {
500 (void) id;
501
502 return TRUE;
503 }
504
505
506
507 void
508 vfs_init_localfs (void)
509 {
510
511 memset (&local_subclass, 0, sizeof (local_subclass));
512
513 vfs_init_class (vfs_local_ops, "localfs", VFSF_LOCAL, NULL);
514 vfs_local_ops->which = local_which;
515 vfs_local_ops->open = local_open;
516 vfs_local_ops->close = local_close;
517 vfs_local_ops->read = local_read;
518 vfs_local_ops->write = local_write;
519 vfs_local_ops->opendir = local_opendir;
520 vfs_local_ops->readdir = local_readdir;
521 vfs_local_ops->closedir = local_closedir;
522 vfs_local_ops->stat = local_stat;
523 vfs_local_ops->lstat = local_lstat;
524 vfs_local_ops->fstat = local_fstat;
525 vfs_local_ops->chmod = local_chmod;
526 vfs_local_ops->chown = local_chown;
527 #ifdef ENABLE_EXT2FS_ATTR
528 vfs_local_ops->fgetflags = local_fgetflags;
529 vfs_local_ops->fsetflags = local_fsetflags;
530 #endif
531 vfs_local_ops->utime = local_utime;
532 vfs_local_ops->readlink = local_readlink;
533 vfs_local_ops->symlink = local_symlink;
534 vfs_local_ops->link = local_link;
535 vfs_local_ops->unlink = local_unlink;
536 vfs_local_ops->rename = local_rename;
537 vfs_local_ops->chdir = local_chdir;
538 vfs_local_ops->ferrno = local_errno;
539 vfs_local_ops->lseek = local_lseek;
540 vfs_local_ops->mknod = local_mknod;
541 vfs_local_ops->getlocalcopy = local_getlocalcopy;
542 vfs_local_ops->ungetlocalcopy = local_ungetlocalcopy;
543 vfs_local_ops->mkdir = local_mkdir;
544 vfs_local_ops->rmdir = local_rmdir;
545 vfs_local_ops->nothingisopen = local_nothingisopen;
546 vfs_register_class (vfs_local_ops);
547 }
548
549