1 /* Directory cache support -- so that you do not have copy of this in
2 * each and every filesystem.
4 * Written at 1998 by Pavel Machek <pavel@ucw.cz>, distribute under LGPL.
6 * Very loosely based on tar.c from midnight and archives.[ch] from
7 * avfs by Miklos Szeredi (mszeredi@inf.bme.hu)
9 * Unfortunately, I was unable to keep all filesystems
10 * uniform. tar-like filesystems use tree structure where each
11 * directory has pointers to its subdirectories. We can do this
12 * because we have full information about our archive.
14 * At ftp-like filesystems, situation is a little bit different. When
15 * you cd /usr/src/linux/drivers/char, you do _not_ want /usr,
16 * /usr/src, /usr/src/linux and /usr/src/linux/drivers to be
17 * listed. That means that we do not have complete information, and if
18 * /usr is symlink to /4, we will not know. Also we have to time out
19 * entries and things would get messy with tree-like approach. So we
20 * do different trick: root directory is completely special and
21 * completely fake, it contains entries such as 'usr', 'usr/src', ...,
22 * and we'll try to use custom find_entry function.
24 * Paths here do _not_ begin with '/', so root directory of
25 * archive/site is simply "". Beware. */
27 static volatile int total_inodes
= 0, total_entries
= 0;
30 #include "xdirentry.h"
31 #include "../src/tty.h"
33 #define CALL(x) if (MEDATA->x) MEDATA->x
36 vfs_s_new_inode (vfs
*me
, vfs_s_super
*super
, struct stat
*initstat
)
40 ino
= g_new (vfs_s_inode
, 1);
45 ino
->linkname
= ino
->localname
= NULL
;
53 ino
->st
.st_ino
= MEDATA
->inode_counter
++;
54 ino
->st
.st_dev
= MEDATA
->rdev
;
59 CALL (init_inode
) (me
, ino
);
65 vfs_s_new_entry (vfs
*me
, char *name
, vfs_s_inode
*inode
)
69 entry
= g_new (struct vfs_s_entry
, 1);
73 entry
->name
= g_strdup (name
);
80 entry
->ino
->ent
= entry
;
81 CALL (init_entry
) (me
, entry
);
87 vfs_s_free_inode (vfs
*me
, vfs_s_inode
*ino
)
90 vfs_die ("Don't pass NULL to me");
92 /* ==0 can happen if freshly created entry is deleted */
93 if (ino
->st
.st_nlink
<= 1){
97 vfs_s_free_entry (me
, ent
);
100 CALL (free_inode
) (me
, ino
);
101 ifree (ino
->linkname
);
103 unlink (ino
->localname
);
104 g_free(ino
->localname
);
107 ino
->super
->ino_usage
--;
109 } else ino
->st
.st_nlink
--;
113 vfs_s_free_entry (vfs
*me
, vfs_s_entry
*ent
)
116 if (ent
->prevp
){ /* It is possible that we are deleting freshly created entry */
117 *ent
->prevp
= ent
->next
;
119 ent
->next
->prevp
= ent
->prevp
;
123 is_dot
= (!strcmp (ent
->name
, ".")) || (!strcmp (ent
->name
, ".."));
128 if (!is_dot
&& ent
->ino
){
129 ent
->ino
->ent
= NULL
;
130 vfs_s_free_inode (me
, ent
->ino
);
138 void vfs_s_insert_entry (vfs
*me
, vfs_s_inode
*dir
, vfs_s_entry
*ent
)
142 for (ep
= &dir
->subdir
; *ep
!= NULL
; ep
= &((*ep
)->next
))
149 ent
->ino
->st
.st_nlink
++;
152 struct stat
*vfs_s_default_stat (vfs
*me
, mode_t mode
)
154 static struct stat st
;
157 myumask
= umask (022);
165 st
.st_uid
= getuid ();
166 st
.st_gid
= getgid ();
168 st
.st_mtime
= st
.st_atime
= st
.st_ctime
= time (NULL
);
174 vfs_s_add_dots (vfs
*me
, vfs_s_inode
*dir
, vfs_s_inode
*parent
)
176 struct vfs_s_entry
*dot
, *dotdot
;
180 dot
= vfs_s_new_entry (me
, ".", dir
);
181 dotdot
= vfs_s_new_entry (me
, "..", parent
);
182 vfs_s_insert_entry (me
, dir
, dot
);
183 vfs_s_insert_entry (me
, dir
, dotdot
);
185 parent
->st
.st_nlink
--; /* We do not count "." and ".." into nlinks */
189 vfs_s_generate_entry (vfs
*me
, char *name
, struct vfs_s_inode
*parent
, mode_t mode
)
191 struct vfs_s_inode
*inode
;
192 struct vfs_s_entry
*entry
;
195 st
= vfs_s_default_stat (me
, mode
);
196 inode
= vfs_s_new_inode (me
, parent
->super
, st
);
198 vfs_s_add_dots (me
, inode
, parent
);
200 entry
= vfs_s_new_entry (me
, name
, inode
);
205 /* We were asked to create entries automagically */
207 vfs_s_automake (vfs
*me
, vfs_s_inode
*dir
, char *path
, int flags
)
209 struct vfs_s_entry
*res
;
210 char *sep
= strchr (path
, PATH_SEP
);
214 res
= vfs_s_generate_entry (me
, path
, dir
, flags
& FL_MKDIR
? (0777 | S_IFDIR
) : 0777);
215 vfs_s_insert_entry (me
, dir
, res
);
224 * Follow > 0: follow links, serves as loop protect,
225 * == -1: do not follow links
228 vfs_s_find_entry_tree (vfs
*me
, vfs_s_inode
*root
, char *path
, int follow
, int flags
)
231 vfs_s_entry
*ent
= NULL
;
233 char p
[MC_MAXPATHLEN
] = "";
238 for (pseg
= 0; path
[pseg
] == PATH_SEP
; pseg
++)
244 for (pseg
= 0; path
[pseg
] && path
[pseg
] != PATH_SEP
; pseg
++)
247 strcat (p
, PATH_SEP_STR
);
248 strncpy (p
+ (t
= strlen (p
)), path
, pseg
);
252 for (ent
= root
->subdir
; ent
!= NULL
; ent
= ent
->next
)
253 if (strlen (ent
->name
) == pseg
&& (!strncmp (ent
->name
, path
, pseg
)))
257 if (!ent
&& (flags
& (FL_MKFILE
| FL_MKDIR
)))
258 ent
= vfs_s_automake (me
, root
, path
, flags
);
259 if (!ent
) ERRNOR (ENOENT
, NULL
);
261 /* here we must follow leading directories always; only the actual file is optional */
262 if (!(ent
= vfs_s_resolve_symlink (me
, ent
, p
, strchr (path
, PATH_SEP
) ? LINK_FOLLOW
: follow
)))
269 split_dir_name (vfs
*me
, char *path
, char **dir
, char **name
, char **save
)
272 s
= strrchr (path
, PATH_SEP
);
281 if (!*s
) /* This can happen if someone does stat("/"); */
289 vfs_s_find_entry_linear (vfs
*me
, vfs_s_inode
*root
, char *path
, int follow
, int flags
)
291 vfs_s_entry
* ent
= NULL
;
293 if (!(flags
& FL_DIR
)){
294 char *dirname
, *name
, *save
;
297 split_dir_name (me
, path
, &dirname
, &name
, &save
);
298 ino
= vfs_s_find_inode (me
, root
, dirname
, follow
, flags
| FL_DIR
);
301 ent
= vfs_s_find_entry_tree (me
, ino
, name
, follow
, flags
);
305 for (ent
= root
->subdir
; ent
!= NULL
; ent
= ent
->next
)
306 if (!strcmp (ent
->name
, path
))
309 if (ent
&& (! (MEDATA
->dir_uptodate
) (me
, ent
->ino
))){
311 message_1s (1, "Dir cache expired for", path
);
313 vfs_s_free_entry (me
, ent
);
319 ino
= vfs_s_new_inode (me
, root
->super
, vfs_s_default_stat (me
, S_IFDIR
| 0755));
320 ent
= vfs_s_new_entry (me
, path
, ino
);
321 if ((MEDATA
->dir_load
) (me
, ino
, path
) == -1){
322 vfs_s_free_entry (me
, ent
);
325 vfs_s_insert_entry (me
, root
, ent
);
327 for (ent
= root
->subdir
; ent
!= NULL
; ent
= ent
->next
)
328 if (!strcmp (ent
->name
, path
))
332 vfs_die ("find_linear: success but directory is not there\n");
335 if (!vfs_s_resolve_symlink (me
, ent
, follow
)) return NULL
;
341 vfs_s_find_inode (vfs
*me
, vfs_s_inode
*root
, char *path
, int follow
, int flags
)
344 if ((MEDATA
->find_entry
== vfs_s_find_entry_tree
) && (!*path
))
346 ent
= (MEDATA
->find_entry
)(me
, root
, path
, follow
, flags
);
353 vfs_s_resolve_symlink (vfs
*me
, vfs_s_entry
*entry
, char *path
, int follow
)
355 if (follow
== LINK_NO_FOLLOW
)
358 ERRNOR (ELOOP
, NULL
);
360 ERRNOR (ENOENT
, NULL
);
361 if (!S_ISLNK (entry
->ino
->st
.st_mode
))
364 if (*entry
->ino
->linkname
!= PATH_SEP
)
365 return (MEDATA
->find_entry
) (me
, entry
->dir
, entry
->ino
->linkname
, follow
- 1, 0);
367 /* convert the linkname to relative linkname with some leading ../ */
368 char linkname
[MC_MAXPATHLEN
] = "", *p
, *q
;
369 for (p
= path
, q
= entry
->ino
->linkname
; *p
== *q
; p
++, q
++);
370 while (*(--q
) != PATH_SEP
);
373 p
= strchr (p
, PATH_SEP
);
375 strcat (linkname
, q
);
378 strcat (linkname
, "..");
379 strcat (linkname
, PATH_SEP_STR
);
381 return (MEDATA
->find_entry
) (me
, entry
->dir
, linkname
, follow
- 1, 0);
385 /* Ook, these were functions around direcory entries / inodes */
386 /* -------------------------------- superblock games -------------------------- */
389 vfs_s_new_super (vfs
*me
)
393 super
= g_new0 (struct vfs_s_super
, 1);
397 super
->ino_usage
= 0;
403 vfs_s_insert_super (vfs
*me
, vfs_s_super
*super
)
405 super
->next
= MEDATA
->supers
;
406 super
->prevp
= &MEDATA
->supers
;
408 if (MEDATA
->supers
!= NULL
)
409 MEDATA
->supers
->prevp
= &super
->next
;
410 MEDATA
->supers
= super
;
414 vfs_s_free_super (vfs
*me
, vfs_s_super
*super
)
417 vfs_s_free_inode (me
, super
->root
);
422 /* We currently leak small ammount of memory, sometimes. Fix it if you can. */
423 if (super
->ino_usage
)
424 message_1s1d (1, " Direntry warning ", "Super ino_usage is %d, memory leak", super
->ino_usage
);
426 if (super
->want_stale
)
427 message_1s (1, " Direntry warning ", "Super has want_stale set");
431 *super
->prevp
= super
->next
;
433 super
->next
->prevp
= super
->prevp
;
436 CALL (free_archive
) (me
, super
);
442 /* ------------------------------------------------------------------------= */
445 vfs_s_stamp_me (vfs
*me
, struct vfs_s_super
*psup
, char *fs_name
)
447 struct vfs_stamping
*parent
;
450 v
= vfs_type (fs_name
);
451 if (v
== &vfs_local_ops
){
454 parent
= g_new (struct vfs_stamping
, 1);
457 parent
->id
= (*v
->getid
) (v
, fs_name
, &(parent
->parent
));
459 vfs_add_noncurrent_stamps (&vfs_tarfs_ops
, (vfsid
) psup
, parent
);
460 vfs_rm_parents (parent
);
464 vfs_s_get_path_mangle (vfs
*me
, char *inname
, struct vfs_s_super
**archive
, int flags
)
466 char *local
, *op
, *archive_name
;
468 struct vfs_s_super
*super
;
471 archive_name
= inname
;
472 vfs_split (inname
, &local
, &op
);
476 if (MEDATA
->archive_check
)
477 if (! (cookie
= MEDATA
->archive_check (me
, archive_name
, op
)))
480 for (super
= MEDATA
->supers
; super
!= NULL
; super
= super
->next
){
481 int i
; /* 0 == other, 1 == same, return it, 2 == other but stop scanning */
482 if ((i
= MEDATA
->archive_same (me
, super
, archive_name
, op
, cookie
))){
483 if (i
==1) goto return_success
;
488 if (flags
& FL_NO_OPEN
)
491 super
= vfs_s_new_super (me
);
492 result
= MEDATA
->open_archive (me
, super
, archive_name
, op
);
494 vfs_s_free_super (me
, super
);
498 vfs_die ("You have to fill name\n");
500 vfs_die ("You have to fill root inode\n");
502 vfs_s_insert_super (me
, super
);
503 vfs_s_stamp_me (me
, super
, archive_name
);
511 vfs_s_get_path (vfs
*me
, char *inname
, struct vfs_s_super
**archive
, int flags
)
513 char *buf
= g_strdup( inname
);
514 char *res
= vfs_s_get_path_mangle (me
, buf
, archive
, flags
);
517 res2
= g_strdup(res
);
523 vfs_s_invalidate (vfs
*me
, vfs_s_super
*super
)
525 if (!super
->want_stale
){
526 vfs_s_free_inode (me
, super
->root
);
527 super
->root
= vfs_s_new_inode (me
, super
, vfs_s_default_stat (me
, S_IFDIR
| 0755));
532 vfs_s_fullpath (vfs
*me
, vfs_s_inode
*ino
)
534 /* For now, usable only on filesystems with _linear structure */
535 if (MEDATA
->find_entry
!= vfs_s_find_entry_linear
)
536 vfs_die ("Implement me!");
537 if ((!ino
->ent
) || (!ino
->ent
->dir
) || (!ino
->ent
->dir
->ent
))
538 ERRNOR (EAGAIN
, NULL
);
539 return g_strconcat (ino
->ent
->dir
->ent
->name
, PATH_SEP_STR
,
540 ino
->ent
->name
, NULL
);
543 /* Support of archives */
544 /* ------------------------ readdir & friends ----------------------------- */
546 vfs_s_super
*vfs_s_super_from_path (vfs
*me
, char *name
)
548 struct vfs_s_super
*super
;
550 if (!vfs_s_get_path_mangle (me
, name
, &super
, 0))
556 vfs_s_inode_from_path (vfs
*me
, char *name
, int flags
)
558 struct vfs_s_super
*super
;
559 struct vfs_s_inode
*ino
;
562 if (!(q
= vfs_s_get_path_mangle (me
, name
, &super
, 0)))
565 ino
= vfs_s_find_inode (me
, super
->root
, q
, flags
& FL_FOLLOW
? LINK_FOLLOW
: LINK_NO_FOLLOW
, flags
& ~FL_FOLLOW
);
578 vfs_s_opendir (vfs
*me
, char *dirname
)
580 struct vfs_s_inode
*dir
;
581 struct dirhandle
*info
;
583 dir
= vfs_s_inode_from_path (me
, dirname
, FL_DIR
| FL_FOLLOW
);
586 if (!S_ISDIR (dir
->st
.st_mode
))
587 ERRNOR (ENOTDIR
, NULL
);
591 if (!dir
->subdir
) /* This can actually happen if we allow empty directories */
592 ERRNOR (EAGAIN
, NULL
);
594 info
= g_new (struct dirhandle
, 1);
595 info
->cur
= dir
->subdir
;
602 vfs_s_readdir (void *data
)
606 #ifdef NEED_EXTRA_DIRENT_BUFFER
607 char extra_buffer
[MC_MAXPATHLEN
];
611 struct dirhandle
*info
= (struct dirhandle
*) data
;
617 strcpy (&(dir
.dir
.d_name
[0]), info
->cur
->name
);
619 vfs_die ("Null in structure-can not happen");
621 #ifndef DIRENT_LENGTH_COMPUTED
622 dir
.d_namlen
= strlen (dir
.dir
.d_name
);
624 info
->cur
= info
->cur
->next
;
630 vfs_s_telldir (void *data
)
632 struct dirhandle
*info
= (struct dirhandle
*) data
;
633 struct vfs_s_entry
*cur
;
636 cur
= info
->dir
->subdir
;
638 if (cur
== info
->cur
)
647 vfs_s_seekdir (void *data
, int offset
)
649 struct dirhandle
*info
= (struct dirhandle
*) data
;
651 info
->cur
= info
->dir
->subdir
;
652 for (i
=0; i
<offset
; i
++)
653 vfs_s_readdir (data
);
657 vfs_s_closedir (void *data
)
659 struct dirhandle
*info
= (struct dirhandle
*) data
;
660 struct vfs_s_inode
*dir
= info
->dir
;
662 vfs_s_free_inode (dir
->super
->me
, dir
);
668 vfs_s_chdir (vfs
*me
, char *path
)
671 if (!(data
= vfs_s_opendir (me
, path
)))
673 vfs_s_closedir (data
);
677 /* --------------------------- stat and friends ---------------------------- */
680 vfs_s_internal_stat (vfs
*me
, char *path
, struct stat
*buf
, int flag
)
682 struct vfs_s_inode
*ino
;
684 if (!(ino
= vfs_s_inode_from_path (me
, path
, flag
)))
691 vfs_s_stat (vfs
*me
, char *path
, struct stat
*buf
)
693 return vfs_s_internal_stat (me
, path
, buf
, FL_FOLLOW
);
697 vfs_s_lstat (vfs
*me
, char *path
, struct stat
*buf
)
699 return vfs_s_internal_stat (me
, path
, buf
, FL_NONE
);
703 vfs_s_fstat (void *fh
, struct stat
*buf
)
710 vfs_s_readlink (vfs
*me
, char *path
, char *buf
, int size
)
712 struct vfs_s_inode
*ino
;
714 ino
= vfs_s_inode_from_path (me
, path
, 0);
718 if (!S_ISLNK (ino
->st
.st_mode
))
720 strncpy (buf
, ino
->linkname
, size
);
726 vfs_s_open (vfs
*me
, char *file
, int flags
, int mode
)
732 struct vfs_s_inode
*ino
;
734 if ((q
= vfs_s_get_path_mangle (me
, file
, &super
, 0)) == NULL
)
736 ino
= vfs_s_find_inode (me
, super
->root
, q
, LINK_FOLLOW
, FL_NONE
);
737 if (ino
&& ((flags
& (O_CREAT
| O_EXCL
)) == (O_CREAT
| O_EXCL
)))
738 ERRNOR (EEXIST
, NULL
);
740 char *dirname
, *name
, *save
;
743 if (!(flags
& O_CREAT
))
746 split_dir_name (me
, q
, &dirname
, &name
, &save
);
747 /* FIXME: if vfs_s_find_inode returns NULL, this will do rather bad
749 dir
= vfs_s_find_inode (me
, super
->root
, dirname
, LINK_FOLLOW
, FL_DIR
);
752 ent
= vfs_s_generate_entry (me
, name
, dir
, 0755);
754 vfs_s_insert_entry (me
, dir
, ent
);
755 ino
->localname
= tempnam (NULL
, me
->name
);
759 if (S_ISDIR (ino
->st
.st_mode
))
760 ERRNOR (EISDIR
, NULL
);
762 fh
= g_new (struct vfs_s_fh
, 1);
766 fh
->changed
= was_changed
;
769 if (MEDATA
->fh_open (me
, fh
, flags
, mode
)){
774 if (fh
->ino
->localname
){
775 fh
->handle
= open (fh
->ino
->localname
, flags
, mode
);
776 if (fh
->handle
== -1){
778 ERRNOR (errno
, NULL
);
782 /* i.e. we had no open files and now we have one */
783 vfs_rmstamp (&vfs_tarfs_ops
, (vfsid
) super
, 1);
785 fh
->ino
->st
.st_nlink
++;
790 vfs_s_read (void *fh
, char *buffer
, int count
)
793 vfs
*me
= FH_SUPER
->me
;
795 if (FH
->linear
== LS_LINEAR_CLOSED
){
796 print_vfs_message ("Starting linear transfer...");
797 if (!MEDATA
->linear_start (me
, FH
, 0))
801 if (FH
->linear
== LS_LINEAR_CLOSED
)
802 vfs_die ("linear_start() did not set linear_state!");
804 if (FH
->linear
== LS_LINEAR_OPEN
)
805 return MEDATA
->linear_read (me
, FH
, buffer
, count
);
808 n
= read (FH
->handle
, buffer
, count
);
813 vfs_die ("vfs_s_read: This should not happen\n");
818 vfs_s_write (void *fh
, char *buffer
, int count
)
821 vfs
*me
= FH_SUPER
->me
;
824 vfs_die ("no writing to linear files, please");
828 n
= write (FH
->handle
, buffer
, count
);
833 vfs_die ("vfs_s_write: This should not happen\n");
838 vfs_s_lseek (void *fh
, off_t offset
, int whence
)
840 off_t size
= FH
->ino
->st
.st_size
;
842 if (FH
->handle
!= -1){ /* If we have local file opened, we want to work with it */
843 int retval
= lseek (FH
->handle
, offset
, whence
);
845 FH
->ino
->super
->me
->verrno
= errno
;
851 offset
+= FH
->pos
; break;
853 offset
+= size
; break;
857 else if (offset
< size
)
865 vfs_s_close (void *fh
)
868 vfs
*me
= FH_SUPER
->me
;
870 FH_SUPER
->fd_usage
--;
871 if (!FH_SUPER
->fd_usage
){
872 struct vfs_stamping
*parent
;
875 v
= vfs_type (FH_SUPER
->name
);
876 if (v
== &vfs_local_ops
){
879 parent
= g_new (struct vfs_stamping
, 1);
882 parent
->id
= (*v
->getid
) (v
, FH_SUPER
->name
, &(parent
->parent
));
884 vfs_add_noncurrent_stamps (&vfs_tarfs_ops
, (vfsid
) (FH_SUPER
), parent
);
885 vfs_rm_parents (parent
);
887 if (FH
->linear
== LS_LINEAR_OPEN
)
888 MEDATA
->linear_close (me
, fh
);
889 if (MEDATA
->fh_close
)
890 res
= MEDATA
->fh_close (me
, fh
);
891 if (FH
->changed
&& MEDATA
->file_store
){
892 char *s
= vfs_s_fullpath (me
, FH
->ino
);
896 res
= MEDATA
->file_store (me
, FH_SUPER
, s
, FH
->ino
->localname
);
897 vfs_s_invalidate (me
, FH_SUPER
);
902 vfs_s_free_inode (me
, FH
->ino
);
907 /* ------------------------------- mc support ---------------------------- */
910 vfs_s_fill_names (vfs
*me
, void (*func
)(char *))
912 struct vfs_s_super
*a
= MEDATA
->supers
;
916 name
= g_strconcat ( a
->name
, "#", me
->prefix
, "/", /* a->current_dir->name, */ NULL
);
924 vfs_s_ferrno (vfs
*me
)
930 vfs_s_dump (vfs
*me
, char *prefix
, vfs_s_inode
*ino
)
932 printf ("%s %s %d ", prefix
, S_ISDIR (ino
->st
.st_mode
) ? "DIR" : "FILE", ino
->st
.st_mode
);
938 struct vfs_s_entry
*ent
;
942 s
= g_strconcat (prefix
, "/", ent
->name
, NULL
);
943 if (ent
->name
[0] == '.')
944 printf ("%s IGNORED\n", s
);
946 vfs_s_dump (me
, s
, ent
->ino
);
954 vfs_s_getlocalcopy (vfs
*me
, char *path
)
956 struct vfs_s_inode
*ino
;
957 char buf
[MC_MAXPATHLEN
];
960 ino
= vfs_s_inode_from_path (me
, path
, FL_FOLLOW
| FL_NONE
);
963 ino
->localname
= mc_def_getlocalcopy (me
, buf
);
964 /* FIXME: fd_usage++ missing */
965 return g_strdup (ino
->localname
);
969 vfs_s_setctl (vfs
*me
, char *path
, int ctlop
, char *arg
)
971 vfs_s_inode
*ino
= vfs_s_inode_from_path (me
, path
, 0);
975 case MCCTL_WANT_STALE_DATA
:
976 ino
->super
->want_stale
= 1;
978 case MCCTL_NO_STALE_DATA
:
979 ino
->super
->want_stale
= 0;
980 vfs_s_invalidate(me
, ino
->super
);
982 #if 0 /* FIXME: We should implement these */
983 case MCCTL_REMOVELOCALCOPY
:
984 return remove_temp_file (path
);
985 case MCCTL_FORGET_ABOUT
:
994 /* ----------------------------- Stamping support -------------------------- */
997 vfs_s_getid (vfs
*me
, char *path
, struct vfs_stamping
**parent
)
999 vfs_s_super
*archive
;
1003 struct vfs_stamping
*par
;
1006 if (!(p
= vfs_s_get_path (me
, path
, &archive
, FL_NO_OPEN
)))
1009 v
= vfs_type (archive
->name
);
1010 id
= (*v
->getid
) (v
, archive
->name
, &par
);
1011 if (id
!= (vfsid
)-1){
1012 *parent
= g_new (struct vfs_stamping
, 1);
1015 (*parent
)->parent
= par
;
1016 (*parent
)->next
= NULL
;
1018 return (vfsid
) archive
;
1022 vfs_s_nothingisopen (vfsid id
)
1024 if (((vfs_s_super
*)id
)->fd_usage
<= 0)
1031 vfs_s_free (vfsid id
)
1033 vfs_s_free_super (((vfs_s_super
*)id
)->me
, (vfs_s_super
*)id
);
1036 /* ----------- Utility functions for networked filesystems -------------- */
1039 vfs_s_select_on_two (int fd1
, int fd2
)
1042 struct timeval timeout
;
1044 int maxfd
= (fd1
> fd2
? fd1
: fd2
) + 1;
1047 timeout
.tv_usec
= 0;
1051 v
= select (maxfd
, &set
, 0, 0, &timeout
);
1054 if (FD_ISSET (fd1
, &set
))
1056 if (FD_ISSET (fd2
, &set
))
1062 vfs_s_get_line (vfs
*me
, int sock
, char *buf
, int buf_len
, char term
)
1064 FILE *logfile
= MEDATA
->logfile
;
1068 for (i
= 0; i
< buf_len
; i
++, buf
++){
1069 if (read (sock
, buf
, sizeof(char)) <= 0)
1072 fwrite (buf
, 1, 1, logfile
);
1081 while ((status
= read (sock
, &c
, sizeof (c
))) > 0){
1083 fwrite (&c
, 1, 1, logfile
);
1093 vfs_s_get_line_interruptible (vfs
*me
, char *buffer
, int size
, int fd
)
1098 enable_interrupt_key ();
1099 for (i
= 0; i
< size
-1; i
++){
1100 n
= read (fd
, buffer
+i
, 1);
1101 disable_interrupt_key ();
1102 if (n
== -1 && errno
== EINTR
){
1110 if (buffer
[i
] == '\n'){
1115 buffer
[size
-1] = 0;