X-Git-Url: http://erislabs.net/gitweb/?a=blobdiff_plain;f=lib%2Fmountlist.c;h=a2c1c2569ff3da887551106e4b7578de152bacb8;hb=24a2f092937bbbfdb21a9eedf909fca820154561;hp=49109e737c65bcf415a3220ca03bdf21df0e14ac;hpb=55b81b990f6f80f9f622f56aada6357e67286ed2;p=gnulib.git diff --git a/lib/mountlist.c b/lib/mountlist.c index 49109e737..a2c1c2569 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-2001 Free Software Foundation, Inc. + Copyright (C) 1991, 1992, 1997-2003 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 @@ -21,7 +21,7 @@ #include #include -#include "mountlist.h" + #ifdef STDC_HEADERS # include @@ -33,13 +33,11 @@ void free (); #else # include #endif +#include "xalloc.h" #ifndef strstr char *strstr (); #endif -char *xmalloc (); -char *xrealloc (); -char *xstrdup (); #include #ifndef errno @@ -58,9 +56,21 @@ extern int errno; # include #endif -#if defined MOUNTED_GETFSSTAT /* __alpha running OSF_1 */ -# include -# include +#if defined MOUNTED_GETFSSTAT /* OSF_1 and Darwin1.3.x */ +# if HAVE_SYS_UCRED_H +# include /* needed by powerpc-apple-darwin1.3.7 */ +# endif +# if HAVE_SYS_MOUNT_H +# include +# endif +# if HAVE_SYS_FS_TYPES_H +# include /* needed by powerpc-apple-darwin1.3.7 */ +# endif +# if HAVE_STRUCT_FSSTAT_F_FSTYPENAME +# define FS_TYPE(Ent) ((Ent).f_fstypename) +# else +# define FS_TYPE(Ent) mnt_names[(Ent).f_type] +# endif #endif /* MOUNTED_GETFSSTAT */ #ifdef MOUNTED_GETMNTENT1 /* 4.3BSD, SunOS, HP-UX, Dynix, Irix. */ @@ -126,12 +136,16 @@ extern int errno; # include #endif +#undef MNT_IGNORE #if defined MNTOPT_IGNORE && defined HAVE_HASMNTOPT # define MNT_IGNORE(M) hasmntopt ((M), MNTOPT_IGNORE) #else # define MNT_IGNORE(M) 0 #endif +#include "mountlist.h" +#include "unlocked-io.h" + #ifdef MOUNTED_GETMNTENT1 /* 4.3BSD, SunOS, HP-UX, Dynix, Irix. */ /* Return the value of the hexadecimal number represented by CP. No prefix (like '0x') or suffix (like 'h') is expected to be @@ -308,21 +322,21 @@ read_filesystem_list (int need_fs_type) remove. Specifically, automount create normal NFS mounts. */ - if(listmntent(&mntlist, KMTAB, NULL, NULL) < 0) + if (listmntent (&mntlist, KMTAB, NULL, NULL) < 0) return NULL; for (p = mntlist; p; p = p->next) { mnt = p->ment; - me = (struct mount_entry*) xmalloc(sizeof (struct mount_entry)); - me->me_devname = xstrdup(mnt->mnt_fsname); - me->me_mountdir = xstrdup(mnt->mnt_dir); - me->me_type = xstrdup(mnt->mnt_type); + me = xmalloc (sizeof (struct mount_entry)); + me->me_devname = xstrdup (mnt->mnt_fsname); + me->me_mountdir = xstrdup (mnt->mnt_dir); + me->me_type = xstrdup (mnt->mnt_type); me->me_dummy = ME_DUMMY (me->me_devname, me->me_type); me->me_remote = ME_REMOTE (me->me_devname, me->me_type); me->me_dev = -1; *mtail = me; mtail = &me->me_next; } - freemntlist(mntlist); + freemntlist (mntlist); } #endif @@ -339,7 +353,7 @@ read_filesystem_list (int need_fs_type) while ((mnt = getmntent (fp))) { - me = (struct mount_entry *) xmalloc (sizeof (struct mount_entry)); + me = xmalloc (sizeof (struct mount_entry)); me->me_devname = xstrdup (mnt->mnt_fsname); me->me_mountdir = xstrdup (mnt->mnt_dir); me->me_type = xstrdup (mnt->mnt_type); @@ -378,7 +392,7 @@ read_filesystem_list (int need_fs_type) { char *fs_type = fsp_to_string (fsp); - me = (struct mount_entry *) xmalloc (sizeof (struct mount_entry)); + me = xmalloc (sizeof (struct mount_entry)); me->me_devname = xstrdup (fsp->f_mntfromname); me->me_mountdir = xstrdup (fsp->f_mntonname); me->me_type = fs_type; @@ -403,7 +417,7 @@ read_filesystem_list (int need_fs_type) 0 < (val = getmnt (&offset, &fsd, sizeof (fsd), NOSTAT_MANY, (char *) 0))) { - me = (struct mount_entry *) xmalloc (sizeof (struct mount_entry)); + me = xmalloc (sizeof (struct mount_entry)); me->me_devname = xstrdup (fsd.fd_req.devname); me->me_mountdir = xstrdup (fsd.fd_req.path); me->me_type = gt_names[fsd.fd_req.fstype]; @@ -475,7 +489,7 @@ read_filesystem_list (int need_fs_type) { struct rootdir_entry *re; - re = (struct rootdir_entry *) xmalloc (sizeof (struct rootdir_entry)); + re = xmalloc (sizeof (struct rootdir_entry)); re->name = name; re->dev = statbuf.st_dev; re->ino = statbuf.st_ino; @@ -501,7 +515,7 @@ read_filesystem_list (int need_fs_type) if (re->dev == fi.dev && re->ino == fi.root) break; - me = (struct mount_entry *) xmalloc (sizeof (struct mount_entry)); + me = 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); @@ -530,13 +544,13 @@ read_filesystem_list (int need_fs_type) int numsys, counter, bufsize; struct statfs *stats; - numsys = getfsstat ((struct statfs *)0, 0L, MNT_WAIT); + numsys = getfsstat ((struct statfs *)0, 0L, MNT_NOWAIT); if (numsys < 0) return (NULL); bufsize = (1 + numsys) * sizeof (struct statfs); - stats = (struct statfs *)xmalloc (bufsize); - numsys = getfsstat (stats, bufsize, MNT_WAIT); + stats = xmalloc (bufsize); + numsys = getfsstat (stats, bufsize, MNT_NOWAIT); if (numsys < 0) { @@ -546,10 +560,10 @@ read_filesystem_list (int need_fs_type) for (counter = 0; counter < numsys; counter++) { - me = (struct mount_entry *) xmalloc (sizeof (struct mount_entry)); + me = xmalloc (sizeof (struct mount_entry)); me->me_devname = xstrdup (stats[counter].f_mntfromname); me->me_mountdir = xstrdup (stats[counter].f_mntonname); - me->me_type = mnt_names[stats[counter].f_type]; + me->me_type = xstrdup (FS_TYPE (stats[counter])); me->me_dummy = ME_DUMMY (me->me_devname, me->me_type); me->me_remote = ME_REMOTE (me->me_devname, me->me_type); me->me_dev = (dev_t) -1; /* Magic; means not known yet. */ @@ -575,7 +589,7 @@ read_filesystem_list (int need_fs_type) while (fread (&mnt, sizeof mnt, 1, fp) > 0) { - me = (struct mount_entry *) xmalloc (sizeof (struct mount_entry)); + me = xmalloc (sizeof (struct mount_entry)); # ifdef GETFSTYP /* SVR3. */ me->me_devname = xstrdup (mnt.mt_dev); # else @@ -620,12 +634,12 @@ read_filesystem_list (int need_fs_type) #ifdef MOUNTED_GETMNTTBL /* DolphinOS goes it's own way */ { - struct mntent **mnttbl=getmnttbl(),**ent; + struct mntent **mnttbl = getmnttbl (), **ent; for (ent=mnttbl;*ent;ent++) { - me = (struct mount_entry *) xmalloc (sizeof (struct mount_entry)); + me = xmalloc (sizeof (struct mount_entry)); me->me_devname = xstrdup ( (*ent)->mt_resource); - me->me_mountdir = xstrdup( (*ent)->mt_directory); + me->me_mountdir = xstrdup ( (*ent)->mt_directory); me->me_type = xstrdup ((*ent)->mt_fstype); me->me_dummy = ME_DUMMY (me->me_devname, me->me_type); me->me_remote = ME_REMOTE (me->me_devname, me->me_type); @@ -635,7 +649,7 @@ read_filesystem_list (int need_fs_type) *mtail = me; mtail = &me->me_next; } - endmnttbl(); + endmnttbl (); } #endif @@ -684,7 +698,7 @@ read_filesystem_list (int need_fs_type) { while ((ret = getmntent (fp, &mnt)) == 0) { - me = (struct mount_entry *) xmalloc (sizeof (struct mount_entry)); + me = xmalloc (sizeof (struct mount_entry)); me->me_devname = xstrdup (mnt.mnt_special); me->me_mountdir = xstrdup (mnt.mnt_mountp); me->me_type = xstrdup (mnt.mnt_fstype); @@ -716,21 +730,32 @@ read_filesystem_list (int need_fs_type) int bufsize; char *entries, *thisent; struct vmount *vmp; + int n_entries; + int i; /* Ask how many bytes to allocate for the mounted filesystem info. */ - mntctl (MCTL_QUERY, sizeof bufsize, (struct vmount *) &bufsize); + if (mntctl (MCTL_QUERY, sizeof bufsize, (struct vmount *) &bufsize) != 0) + return NULL; entries = xmalloc (bufsize); /* Get the list of mounted filesystems. */ - mntctl (MCTL_QUERY, bufsize, (struct vmount *) entries); + n_entries = mntctl (MCTL_QUERY, bufsize, (struct vmount *) entries); + if (n_entries < 0) + { + int saved_errno = errno; + free (entries); + errno = saved_errno; + return NULL; + } - for (thisent = entries; thisent < entries + bufsize; - thisent += vmp->vmt_length) + for (i = 0, thisent = entries; + i < n_entries; + i++, thisent += vmp->vmt_length) { char *options, *ignore; vmp = (struct vmount *) thisent; - me = (struct mount_entry *) xmalloc (sizeof (struct mount_entry)); + me = xmalloc (sizeof (struct mount_entry)); if (vmp->vmt_flags & MNT_REMOTE) { char *host, *path;