From de12104436779ec2d4b87dc9111affa6bc9010ba Mon Sep 17 00:00:00 2001 From: Pavel Roskin Date: Wed, 12 Nov 2003 23:00:16 +0000 Subject: [PATCH] * gc.c: Use NULL instead of -1 for empty vfsid. Adjust all dependencies. * undelfs.c (undelfs_get_path): Don't shadow static ext2_fname. (undelfs_getid): Likewise. Use fs for non-empty vfsid. --- vfs/ChangeLog | 7 +++++++ vfs/direntry.c | 4 ++-- vfs/extfs.c | 4 ++-- vfs/gc.c | 14 +++++++------- vfs/sfs.c | 26 +++++++++++++------------- vfs/undelfs.c | 25 +++++++++++++------------ 6 files changed, 44 insertions(+), 36 deletions(-) diff --git a/vfs/ChangeLog b/vfs/ChangeLog index 24e931367..ba06812be 100644 --- a/vfs/ChangeLog +++ b/vfs/ChangeLog @@ -1,3 +1,10 @@ +2003-11-12 Pavel Roskin + + * gc.c: Use NULL instead of -1 for empty vfsid. Adjust all + dependencies. + * undelfs.c (undelfs_get_path): Don't shadow static ext2_fname. + (undelfs_getid): Likewise. Use fs for non-empty vfsid. + 2003-11-12 Andrew V. Samoilov * cpio.c (cpio_create_entry): Fix possible buffer underflow diff --git a/vfs/direntry.c b/vfs/direntry.c index 407d0f75d..647cf4f2d 100644 --- a/vfs/direntry.c +++ b/vfs/direntry.c @@ -1068,11 +1068,11 @@ vfs_s_getid (struct vfs_class *me, const char *path, struct vfs_stamping **paren *parent = NULL; if (!(p = vfs_s_get_path (me, path, &archive, FL_NO_OPEN))) - return (vfsid) -1; + return NULL; g_free(p); v = vfs_get_class (archive->name); id = vfs_getid (v, archive->name, &par); - if (id != (vfsid)-1){ + if (id) { *parent = g_new (struct vfs_stamping, 1); (*parent)->v = v; (*parent)->id = id; diff --git a/vfs/extfs.c b/vfs/extfs.c index 5ecc58fca..959cd1e7d 100644 --- a/vfs/extfs.c +++ b/vfs/extfs.c @@ -1132,12 +1132,12 @@ static vfsid extfs_getid (struct vfs_class *me, const char *path, struct vfs_sta *parent = NULL; if (!(p = extfs_get_path (path, &archive, 1, 1))) - return (vfsid) -1; + return NULL; g_free(p); if (archive->name){ v = vfs_get_class (archive->name); id = vfs_getid (v, archive->name, &par); - if (id != (vfsid)-1) { + if (id) { *parent = g_new (struct vfs_stamping, 1); (*parent)->v = v; (*parent)->id = id; diff --git a/vfs/gc.c b/vfs/gc.c index 30f4ecc19..0afa743ed 100644 --- a/vfs/gc.c +++ b/vfs/gc.c @@ -1,4 +1,4 @@ -/* Virtual File System grabage collection code +/* Virtual File System garbage collection code Copyright (C) 1995-2003 The Free Software Foundation Written by: 1995 Miguel de Icaza @@ -47,7 +47,7 @@ static struct vfs_stamping *stamps; static void vfs_addstamp (struct vfs_class *v, vfsid id, struct vfs_stamping *parent) { - if (!(v->flags & VFSF_LOCAL) && id != (vfsid) - 1) { + if (!(v->flags & VFSF_LOCAL) && id != NULL) { struct vfs_stamping *stamp; struct vfs_stamping *last_stamp = NULL; @@ -149,7 +149,7 @@ vfsid vfs_getid (struct vfs_class *vclass, const char *path, struct vfs_stamping **parent) { - vfsid id = (vfsid) - 1; + vfsid id = NULL; *parent = NULL; if (vclass->getid) @@ -235,7 +235,7 @@ _vfs_add_noncurrent_stamps (struct vfs_class *oldvfs, vfsid oldvfsid, f = is_parent (oldvfs, oldvfsid, par); vfs_rm_parents (par); - if ((nvfs == oldvfs && nvfsid == oldvfsid) || oldvfsid == (vfsid) - 1 + if ((nvfs == oldvfs && nvfsid == oldvfsid) || oldvfsid == NULL || f) { return; } @@ -249,7 +249,7 @@ _vfs_add_noncurrent_stamps (struct vfs_class *oldvfs, vfsid oldvfsid, return; } else { n2vfs = NULL; - n2vfsid = (vfsid) - 1; + n2vfsid = NULL; } if (get_other_type () == view_listing) { @@ -261,7 +261,7 @@ _vfs_add_noncurrent_stamps (struct vfs_class *oldvfs, vfsid oldvfsid, return; } else { n3vfs = NULL; - n3vfsid = (vfsid) - 1; + n3vfsid = NULL; } if (!oldvfs->nothingisopen || !(*oldvfs->nothingisopen) (oldvfsid)) @@ -272,7 +272,7 @@ _vfs_add_noncurrent_stamps (struct vfs_class *oldvfs, vfsid oldvfsid, if ((stamp->v == nvfs && stamp->id == nvfsid) || (stamp->v == n2vfs && stamp->id == n2vfsid) || (stamp->v == n3vfs && stamp->id == n3vfsid) - || stamp->id == (vfsid) - 1 || !stamp->v->nothingisopen + || !stamp->id || !stamp->v->nothingisopen || !(*stamp->v->nothingisopen) (stamp->id)) break; vfs_addstamp (stamp->v, stamp->id, stamp->parent); diff --git a/vfs/sfs.c b/vfs/sfs.c index 7f4bfdf06..22f0a1239 100644 --- a/vfs/sfs.c +++ b/vfs/sfs.c @@ -215,12 +215,14 @@ static int sfs_readlink (struct vfs_class *me, char *path, char *buf, int size) } static vfsid -sfs_getid (struct vfs_class *me, const char *path, struct vfs_stamping **parent) -{ /* FIXME: what should I do? */ +sfs_getid (struct vfs_class *me, const char *path, + struct vfs_stamping **parent) +{ struct vfs_class *v; vfsid id; struct vfs_stamping *par; struct cachedfile *cur = head; + char *path2; while (cur) { if (!strcmp (path, cur->name)) @@ -231,22 +233,20 @@ sfs_getid (struct vfs_class *me, const char *path, struct vfs_stamping **parent) *parent = NULL; if (!cur) - return (vfsid) (-1); + return NULL; - { - char *path2 = g_strdup (path); + path2 = g_strdup (path); - /* Strip suffix which led to this being sfs */ - v = vfs_split (path2, NULL, NULL); + /* Strip suffix which led to this being sfs */ + v = vfs_split (path2, NULL, NULL); - /* ... and learn whoever was the parent system */ - v = vfs_split (path2, NULL, NULL); + /* ... and learn whoever was the parent system */ + v = vfs_split (path2, NULL, NULL); - id = vfs_getid (v, path2, &par); - g_free (path2); - } + id = vfs_getid (v, path2, &par); + g_free (path2); - if (id != (vfsid) - 1) { + if (id) { *parent = g_new (struct vfs_stamping, 1); (*parent)->v = v; (*parent)->id = id; diff --git a/vfs/undelfs.c b/vfs/undelfs.c index c8389131a..436b40186 100644 --- a/vfs/undelfs.c +++ b/vfs/undelfs.c @@ -99,7 +99,7 @@ undelfs_shutdown (void) } static void -undelfs_get_path (const char *dirname, char **ext2_fname, char **file) +undelfs_get_path (const char *dirname, char **fsname, char **file) { const char *p; @@ -108,7 +108,7 @@ undelfs_get_path (const char *dirname, char **ext2_fname, char **file) hda5, sdb8 etc, which is assumed to live under /dev. -- pavel@ucw.cz */ - *ext2_fname = NULL; + *fsname = NULL; if (strncmp (dirname, "/#undel:", 8)) return; @@ -134,14 +134,14 @@ undelfs_get_path (const char *dirname, char **ext2_fname, char **file) *file = g_strdup (p+1); tmp = g_strndup (dirname, p - dirname); - *ext2_fname = g_strconcat ("/dev/", tmp, NULL); + *fsname = g_strconcat ("/dev/", tmp, NULL); g_free (tmp); return; } p--; } *file = g_strdup (""); - *ext2_fname = g_strconcat ("/dev/", dirname, NULL); + *fsname = g_strconcat ("/dev/", dirname, NULL); return; } @@ -640,19 +640,20 @@ undelfs_lseek(void *vfs_info, off_t offset, int whence) } static vfsid -undelfs_getid(struct vfs_class *me, const char *path, struct vfs_stamping **parent) +undelfs_getid (struct vfs_class *me, const char *path, + struct vfs_stamping **parent) { - char *ext2_fname, *file; + char *fname, *fsname; /* We run only on the local fs */ *parent = NULL; - undelfs_get_path (path, &ext2_fname, &file); + undelfs_get_path (path, &fsname, &fname); - if (!ext2_fname) - return (vfsid) -1; - g_free (ext2_fname); - g_free (file); - return (vfsid)0; + if (!fsname) + return NULL; + g_free (fname); + g_free (fsname); + return (vfsid) fs; } static int