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 0;
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 while (dir == NULL)
104 {
105 dir = opendir (path);
106 if (dir == NULL)
107 return NULL;
108
109 if (readdir (dir) == NULL && errno == EINTR)
110 {
111 closedir (dir);
112 dir = NULL;
113 }
114 else
115 rewinddir (dir);
116 }
117
118 DIR **local_info = (DIR **) g_new (DIR *, 1);
119 *local_info = dir;
120
121 return local_info;
122 }
123
124
125
126 static struct vfs_dirent *
127 local_readdir (void *data)
128 {
129 struct dirent *d;
130
131 d = readdir (*(DIR **) data);
132
133 return (d != NULL ? vfs_dirent_init (NULL, d->d_name, d->d_ino) : NULL);
134 }
135
136
137
138 static int
139 local_closedir (void *data)
140 {
141 int i;
142
143 i = closedir (*(DIR **) data);
144 g_free (data);
145 return i;
146 }
147
148
149
150 static int
151 local_stat (const vfs_path_t *vpath, struct stat *buf)
152 {
153 const char *path;
154
155 path = vfs_path_get_last_path_str (vpath);
156 return stat (path, buf);
157 }
158
159
160
161 static int
162 local_lstat (const vfs_path_t *vpath, struct stat *buf)
163 {
164 const char *path;
165
166 path = vfs_path_get_last_path_str (vpath);
167 #ifndef HAVE_STATLSTAT
168 return lstat (path, buf);
169 #else
170 return statlstat (path, buf);
171 #endif
172 }
173
174
175
176 static int
177 local_chmod (const vfs_path_t *vpath, mode_t mode)
178 {
179 const char *path;
180
181 path = vfs_path_get_last_path_str (vpath);
182 return chmod (path, mode);
183 }
184
185
186
187 static int
188 local_chown (const vfs_path_t *vpath, uid_t owner, gid_t group)
189 {
190 const char *path;
191
192 path = vfs_path_get_last_path_str (vpath);
193 return chown (path, owner, group);
194 }
195
196
197
198 #ifdef ENABLE_EXT2FS_ATTR
199
200 static int
201 local_fgetflags (const vfs_path_t *vpath, unsigned long *flags)
202 {
203 const char *path;
204
205 path = vfs_path_get_last_path_str (vpath);
206 return fgetflags (path, flags);
207 }
208
209
210
211 static int
212 local_fsetflags (const vfs_path_t *vpath, unsigned long flags)
213 {
214 const char *path;
215
216 path = vfs_path_get_last_path_str (vpath);
217 return fsetflags (path, flags);
218 }
219
220 #endif
221
222
223
224 static int
225 local_utime (const vfs_path_t *vpath, mc_timesbuf_t *times)
226 {
227 return vfs_utime (vfs_path_get_last_path_str (vpath), times);
228 }
229
230
231
232 static int
233 local_readlink (const vfs_path_t *vpath, char *buf, size_t size)
234 {
235 const char *path;
236
237 path = vfs_path_get_last_path_str (vpath);
238 return readlink (path, buf, size);
239 }
240
241
242
243 static int
244 local_unlink (const vfs_path_t *vpath)
245 {
246 const char *path;
247
248 path = vfs_path_get_last_path_str (vpath);
249 return unlink (path);
250 }
251
252
253
254 static int
255 local_symlink (const vfs_path_t *vpath1, const vfs_path_t *vpath2)
256 {
257 const char *path1, *path2;
258
259 path1 = vfs_path_get_last_path_str (vpath1);
260 path2 = vfs_path_get_last_path_str (vpath2);
261 return symlink (path1, path2);
262 }
263
264
265
266 static ssize_t
267 local_write (void *data, const char *buf, size_t nbyte)
268 {
269 int fd;
270 int n;
271
272 if (data == NULL)
273 return (-1);
274
275 fd = *(int *) data;
276
277 while ((n = write (fd, buf, nbyte)) == -1)
278 {
279 #ifdef EAGAIN
280 if (errno == EAGAIN)
281 continue;
282 #endif
283 #ifdef EINTR
284 if (errno == EINTR)
285 continue;
286 #endif
287 break;
288 }
289
290 return n;
291 }
292
293
294
295 static int
296 local_rename (const vfs_path_t *vpath1, const vfs_path_t *vpath2)
297 {
298 const char *path1, *path2;
299
300 path1 = vfs_path_get_last_path_str (vpath1);
301 path2 = vfs_path_get_last_path_str (vpath2);
302 return rename (path1, path2);
303 }
304
305
306
307 static int
308 local_chdir (const vfs_path_t *vpath)
309 {
310 const char *path;
311
312 path = vfs_path_get_last_path_str (vpath);
313 return chdir (path);
314 }
315
316
317
318 static int
319 local_mknod (const vfs_path_t *vpath, mode_t mode, dev_t dev)
320 {
321 const char *path;
322
323 path = vfs_path_get_last_path_str (vpath);
324 return mknod (path, mode, dev);
325 }
326
327
328
329 static int
330 local_link (const vfs_path_t *vpath1, const vfs_path_t *vpath2)
331 {
332 const char *path1, *path2;
333
334 path1 = vfs_path_get_last_path_str (vpath1);
335 path2 = vfs_path_get_last_path_str (vpath2);
336 return link (path1, path2);
337 }
338
339
340
341 static int
342 local_mkdir (const vfs_path_t *vpath, mode_t mode)
343 {
344 const char *path;
345
346 path = vfs_path_get_last_path_str (vpath);
347 return mkdir (path, mode);
348 }
349
350
351
352 static int
353 local_rmdir (const vfs_path_t *vpath)
354 {
355 const char *path;
356
357 path = vfs_path_get_last_path_str (vpath);
358 return rmdir (path);
359 }
360
361
362
363 static vfs_path_t *
364 local_getlocalcopy (const vfs_path_t *vpath)
365 {
366 return vfs_path_clone (vpath);
367 }
368
369
370
371 static int
372 local_ungetlocalcopy (const vfs_path_t *vpath, const vfs_path_t *local, gboolean has_changed)
373 {
374 (void) vpath;
375 (void) local;
376 (void) has_changed;
377
378 return 0;
379 }
380
381
382
383 static int
384 local_which (struct vfs_class *me, const char *path)
385 {
386 (void) me;
387 (void) path;
388
389 return 0;
390 }
391
392
393
394
395
396 ssize_t
397 local_read (void *data, char *buffer, size_t count)
398 {
399 int n;
400 int fd;
401
402 if (data == NULL)
403 return (-1);
404
405 fd = *(int *) data;
406
407 while ((n = read (fd, buffer, count)) == -1)
408 {
409 #ifdef EAGAIN
410 if (errno == EAGAIN)
411 continue;
412 #endif
413 #ifdef EINTR
414 if (errno == EINTR)
415 continue;
416 #endif
417 return (-1);
418 }
419
420 return n;
421 }
422
423
424
425 int
426 local_close (void *data)
427 {
428 int fd;
429
430 if (data == NULL)
431 return (-1);
432
433 fd = *(int *) data;
434 g_free (data);
435 return close (fd);
436 }
437
438
439
440 int
441 local_errno (struct vfs_class *me)
442 {
443 (void) me;
444 return errno;
445 }
446
447
448
449 int
450 local_fstat (void *data, struct stat *buf)
451 {
452 int fd = *(int *) data;
453
454 return fstat (fd, buf);
455 }
456
457
458
459 off_t
460 local_lseek (void *data, off_t offset, int whence)
461 {
462 int fd = *(int *) data;
463
464 return lseek (fd, offset, whence);
465 }
466
467
468
469 static gboolean
470 local_nothingisopen (vfsid id)
471 {
472 (void) id;
473
474 return TRUE;
475 }
476
477
478
479 void
480 vfs_init_localfs (void)
481 {
482
483 memset (&local_subclass, 0, sizeof (local_subclass));
484
485 vfs_init_class (vfs_local_ops, "localfs", VFSF_LOCAL, NULL);
486 vfs_local_ops->which = local_which;
487 vfs_local_ops->open = local_open;
488 vfs_local_ops->close = local_close;
489 vfs_local_ops->read = local_read;
490 vfs_local_ops->write = local_write;
491 vfs_local_ops->opendir = local_opendir;
492 vfs_local_ops->readdir = local_readdir;
493 vfs_local_ops->closedir = local_closedir;
494 vfs_local_ops->stat = local_stat;
495 vfs_local_ops->lstat = local_lstat;
496 vfs_local_ops->fstat = local_fstat;
497 vfs_local_ops->chmod = local_chmod;
498 vfs_local_ops->chown = local_chown;
499 #ifdef ENABLE_EXT2FS_ATTR
500 vfs_local_ops->fgetflags = local_fgetflags;
501 vfs_local_ops->fsetflags = local_fsetflags;
502 #endif
503 vfs_local_ops->utime = local_utime;
504 vfs_local_ops->readlink = local_readlink;
505 vfs_local_ops->symlink = local_symlink;
506 vfs_local_ops->link = local_link;
507 vfs_local_ops->unlink = local_unlink;
508 vfs_local_ops->rename = local_rename;
509 vfs_local_ops->chdir = local_chdir;
510 vfs_local_ops->ferrno = local_errno;
511 vfs_local_ops->lseek = local_lseek;
512 vfs_local_ops->mknod = local_mknod;
513 vfs_local_ops->getlocalcopy = local_getlocalcopy;
514 vfs_local_ops->ungetlocalcopy = local_ungetlocalcopy;
515 vfs_local_ops->mkdir = local_mkdir;
516 vfs_local_ops->rmdir = local_rmdir;
517 vfs_local_ops->nothingisopen = local_nothingisopen;
518 vfs_register_class (vfs_local_ops);
519 }
520
521