X-Git-Url: http://erislabs.net/gitweb/?a=blobdiff_plain;f=lib%2Fmountlist.c;h=6f7d07cbc1b9eb970801d2669e2ffcd29c499b15;hb=115741fa52092c59e33d75428b776513caa88f87;hp=c2c77b3f0a620a3935127a09f5c216dc3806e8c3;hpb=34bd051ef6e5edb9df5a8f274a7b7afbbdda3470;p=gnulib.git diff --git a/lib/mountlist.c b/lib/mountlist.c index c2c77b3f0..6f7d07cbc 100644 --- a/lib/mountlist.c +++ b/lib/mountlist.c @@ -1,5 +1,5 @@ /* mountlist.c -- return a list of mounted filesystems - Copyright (C) 1991, 1992, 1997, 1998, 1999 Free Software Foundation, Inc. + Copyright (C) 1991, 1992, 1997-2000 Free Software Foundation, Inc. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -40,7 +40,6 @@ char *strstr (); char *xmalloc (); char *xrealloc (); char *xstrdup (); -void error (); #include #ifndef errno @@ -85,6 +84,11 @@ extern int errno; # include #endif +#ifdef MOUNTED_FS_STAT_DEV /* BeOS. */ +# include +# include +#endif + #ifdef MOUNTED_FREAD /* SVR2. */ # include #endif @@ -151,46 +155,6 @@ xatoi (char *cp) } return val; } - -/* Convert, in place, each unambiguous `\040' sequence in the NUL-terminated - string, STR, to a single space. `unambiguous' means that it must not be - immediately preceded by an odd number of backslash characters. */ - -static void -translate_040_to_space (char *str) -{ - while (1) - { - char *p; - char *backslash = strstr (str, "\\040"); - unsigned int backslash_count = 0; - - if (backslash == NULL) - break; - - /* Count preceding backslashes, going no further than str. */ - for (p = backslash - 1; p >= str && *p == '\\'; p--) - ++backslash_count; - - if (backslash_count % 2 == 1) - { - /* The backslash is escaped; advance past the 040 and - continue searching. */ - str = backslash + 4; - continue; - } - - /* We found an unambiguous `\040'. Replace it with a space - and move everything following it back by 3 bytes. - The source and destination regions may overlap, so we have - to use memmove. */ - *backslash = ' '; - str = backslash + 1; - /* Be sure to copy the trailing NUL byte, too. */ - memmove (str, backslash + 4, strlen (backslash + 4) + 1); - } -} - #endif /* MOUNTED_GETMNTENT1. */ #if MOUNTED_GETMNTINFO @@ -296,7 +260,7 @@ static char * fsp_to_string (const struct statfs *fsp) { # if defined HAVE_F_FSTYPENAME_IN_STATFS - return fsp->f_fstypename; + return (char *) (fsp->f_fstypename); # else return fstype_to_string (fsp->f_type); # endif @@ -389,11 +353,6 @@ read_filesystem_list (int need_fs_type) else me->me_dev = (dev_t) -1; /* Magic; means not known yet. */ - /* FIXME: do the conversion only if we're using some version of - GNU libc -- which one? */ - /* Convert each `\040' string to a space. */ - translate_040_to_space (me->me_mountdir); - /* Add to the linked list. */ *mtail = me; mtail = &me->me_next; @@ -458,6 +417,111 @@ read_filesystem_list (int need_fs_type) } #endif /* MOUNTED_GETMNT. */ +#if defined (MOUNTED_FS_STAT_DEV) /* BeOS */ + { + /* The next_dev() and fs_stat_dev() system calls give the list of + all filesystems, including the information returned by statvfs() + (fs type, total blocks, free blocks etc.), but without the mount + point. But on BeOS all filesystems except / are mounted in the + rootfs, directly under /. + The directory name of the mount point is often, but not always, + identical to the volume name of the device. + We therefore get the list of subdirectories of /, and the list + of all filesystems, and match the two lists. */ + + DIR *dirp; + struct rootdir_entry + { + char *name; + dev_t dev; + ino_t ino; + struct rootdir_entry *next; + }; + struct rootdir_entry *rootdir_list; + struct rootdir_entry **rootdir_tail; + int32 pos; + dev_t dev; + fs_info fi; + + /* All volumes are mounted in the rootfs, directly under /. */ + rootdir_list = NULL; + rootdir_tail = &rootdir_list; + dirp = opendir ("/"); + if (dirp) + { + struct dirent *d; + + while ((d = readdir (dirp)) != NULL) + { + char *name; + struct stat statbuf; + + if (strcmp (d->d_name, "..") == 0) + continue; + + if (strcmp (d->d_name, ".") == 0) + name = xstrdup ("/"); + else + { + name = xmalloc (1 + strlen (d->d_name) + 1); + name[0] = '/'; + strcpy (name + 1, d->d_name); + } + + if (lstat (name, &statbuf) >= 0 && S_ISDIR (statbuf.st_mode)) + { + struct rootdir_entry *re; + + re = (struct rootdir_entry *) xmalloc (sizeof (struct rootdir_entry)); + re->name = name; + re->dev = statbuf.st_dev; + re->ino = statbuf.st_ino; + + /* Add to the linked list. */ + *rootdir_tail = re; + rootdir_tail = &re->next; + } + else + free (name); + } + closedir (dirp); + } + *rootdir_tail = NULL; + + for (pos = 0; (dev = next_dev (&pos)) >= 0; ) + if (fs_stat_dev (dev, &fi) >= 0) + { + /* Note: fi.dev == dev. */ + struct rootdir_entry *re; + + for (re = rootdir_list; re; re = re->next) + if (re->dev == fi.dev && re->ino == fi.root) + break; + + me = (struct mount_entry *) xmalloc (sizeof (struct mount_entry)); + me->me_devname = xstrdup (fi.device_name[0] != '\0' ? fi.device_name : fi.fsh_name); + me->me_mountdir = xstrdup (re != NULL ? re->name : fi.fsh_name); + me->me_type = xstrdup (fi.fsh_name); + me->me_dev = fi.dev; + me->me_dummy = 0; + me->me_remote = (fi.flags & B_FS_IS_SHARED) != 0; + + /* Add to the linked list. */ + *mtail = me; + mtail = &me->me_next; + } + *mtail = NULL; + + while (rootdir_list != NULL) + { + struct rootdir_entry *re = rootdir_list; + rootdir_list = re->next; + free (re->name); + free (re); + } + } +#endif /* MOUNTED_FS_STAT_DEV */ + #if defined (MOUNTED_GETFSSTAT) /* __alpha running OSF_1 */ { int numsys, counter, bufsize; @@ -660,6 +724,8 @@ read_filesystem_list (int need_fs_type) for (thisent = entries; thisent < entries + bufsize; thisent += vmp->vmt_length) { + char *options, *ignore; + vmp = (struct vmount *) thisent; me = (struct mount_entry *) xmalloc (sizeof (struct mount_entry)); if (vmp->vmt_flags & MNT_REMOTE) @@ -683,7 +749,12 @@ read_filesystem_list (int need_fs_type) } me->me_mountdir = xstrdup (thisent + vmp->vmt_data[VMT_STUB].vmt_off); me->me_type = xstrdup (fstype_to_string (vmp->vmt_gfstype)); - me->me_dummy = ME_DUMMY (me->me_devname, me->me_type); + options = thisent + vmp->vmt_data[VMT_ARGS].vmt_off; + ignore = strstr (options, "ignore"); + me->me_dummy = (ignore + && (ignore == options || ignore[-1] == ',') + && (ignore[sizeof "ignore" - 1] == ',' + || ignore[sizeof "ignore" - 1] == '\0')); me->me_dev = (dev_t) -1; /* vmt_fsid might be the info we want. */ /* Add to the linked list. */ @@ -717,18 +788,3 @@ read_filesystem_list (int need_fs_type) return NULL; } } - -#ifdef TEST -int -main (int argc, char **argv) -{ - int i; - for (i = 1; i < argc; i++) - { - char *p = xstrdup (argv[i]); - translate_040_to_space (p); - printf ("%s: %s\n", argv[i], p); - } - exit (0); -} -#endif