From dda52c18d6a434f6f4c947cd75770240a738f9d6 Mon Sep 17 00:00:00 2001 From: ewt Date: Thu, 19 Jun 1997 22:18:02 +0000 Subject: [PATCH] Changes for OSF/1 getmntinfo_r() CVS patchset: 1708 CVS date: 1997/06/19 22:18:02 --- config.h.in | 3 +++ configure.in | 6 ++++-- lib/fs.c | 47 ++++++++++++++++++++++++++++++++++------------- misc/getmntent.c | 2 +- misc/miscfn.h | 5 ++++- 5 files changed, 46 insertions(+), 17 deletions(-) diff --git a/config.h.in b/config.h.in index 2702668..07b32bf 100644 --- a/config.h.in +++ b/config.h.in @@ -93,4 +93,7 @@ /* Define as one if you have "struct mnttab" (only sco?) */ #define HAVE_STRUCT_MNTTAB 0 +/* Define as one if you have getmntinfo_r() (only osf?) */ +#define HAVE_GETMNTINFO_R 0 + #endif diff --git a/configure.in b/configure.in index 6393251..2a92e2e 100644 --- a/configure.in +++ b/configure.in @@ -277,8 +277,10 @@ fi dnl Checks for library functions. AC_CHECK_FUNC(inet_aton, AC_DEFINE(HAVE_INET_ATON), MISCOBJS="$MISCOBJS inet_aton.o") AC_CHECK_FUNC(realpath, AC_DEFINE(HAVE_REALPATH), MISCOBJS="$MISCOBJS realpath.o") -AC_CHECK_FUNC(getmntent, AC_DEFINE(HAVE_GETMNTENT), MISCOBJS="$MISCOBJS getmntent.o") -AC_CHECK_FUNC(mntctl, AC_DEFINE(HAVE_MNTCTL)) +AC_CHECK_FUNC(getmntent, AC_DEFINE(HAVE_GETMNTENT), [ + AC_CHECK_FUNC(mntctl, AC_DEFINE(HAVE_MNTCTL),[ + AC_CHECK_FUNC(getmntinfo_r, AC_DEFINE(HAVE_GETMNTINFO_R), + MISCOBJS="$MISCOBJS getmntent.o") ])]) AC_CHECK_FUNC(strerror, [], MISCOBJS="$MISCOBJS strerror.o") AC_CHECK_FUNC(strtol, [], MISCOBJS="$MISCOBJS strtol.o") AC_CHECK_FUNC(strtoul, [], MISCOBJS="$MISCOBJS strtoul.o") diff --git a/lib/fs.c b/lib/fs.c index 1d88e30..3b34800 100644 --- a/lib/fs.c +++ b/lib/fs.c @@ -108,19 +108,30 @@ static int getFilesystemList(void) { } #else static int getFilesystemList(void) { - our_mntent item, * itemptr; - FILE * mtab; int numAlloced = 10; int num = 0; struct stat sb; int i; - - mtab = fopen(MOUNTED, "r"); - if (!mtab) { - rpmError(RPMERR_MTAB, _("failed to open %s: %s"), MOUNTED, - strerror(errno)); - return 1; - } + char * mntdir; + #if GETMNTENT_ONE || GETMNTENT_TWO + our_mntent item, * itemptr; + FILE * mtab; + #elif HAVE_GETMNTINFO_R + struct statfs * mounts = NULL; + int mntCount = 0, bufSize = 0, flags = MNT_NOWAIT; + int nextMount = 0; + #endif + + #if GETMNTENT_ONE || GETMNTENT_TWO + mtab = fopen(MOUNTED, "r"); + if (!mtab) { + rpmError(RPMERR_MTAB, _("failed to open %s: %s"), MOUNTED, + strerror(errno)); + return 1; + } + #elif HAVE_GETMNTINFO_R + getmntinfo_r(&mounts, flags, &mntCount, &bufSize); + #endif filesystems = malloc(sizeof(*filesystems) * (numAlloced + 1)); @@ -130,13 +141,18 @@ static int getFilesystemList(void) { itemptr = getmntent(mtab); if (!itemptr) break; item = *itemptr; + mntdir = item.our_mntdir; #elif GETMNTENT_TWO /* Solaris, maybe others */ if (getmntent(mtab, &item)) break; + mntdir = item.our_mntdir; + #elif HAVE_GETMNTINFO_R + if (nextMount == mntCount) break; + mntdir = mounts[nextMount++].f_mntonname; #endif - if (stat(item.our_mntdir, &sb)) { - rpmError(RPMERR_STAT, "failed to stat %s: %s", item.our_mntdir, + if (stat(mntdir, &sb)) { + rpmError(RPMERR_STAT, "failed to stat %s: %s", mntdir, strerror(errno)); for (i = 0; i < num; i++) @@ -153,10 +169,15 @@ static int getFilesystemList(void) { } filesystems[num].dev = sb.st_dev; - filesystems[num++].mntPoint = strdup(item.our_mntdir); + filesystems[num++].mntPoint = strdup(mntdir); } - fclose(mtab); + #if GETMNTENT_ONE || GETMNTENT_TWO + fclose(mtab); + #elif HAVE_GETMNTINFO_R + free(mounts); + #endif + filesystems[num].mntPoint = NULL; fsnames = malloc(sizeof(*fsnames) * (num + 1)); diff --git a/misc/getmntent.c b/misc/getmntent.c index ebce8ab..d2455a2 100644 --- a/misc/getmntent.c +++ b/misc/getmntent.c @@ -11,7 +11,7 @@ #define COMMENTCHAR '#' #endif -#if HAVE_STRUCT_MNTTAB { +#if HAVE_STRUCT_MNTTAB our_mntent * getmntent(FILE *filep) { static struct mnttab entry; static our_mntent item = { entry.mt_filsys }; diff --git a/misc/miscfn.h b/misc/miscfn.h index 0ca0ef3..80a5194 100644 --- a/misc/miscfn.h +++ b/misc/miscfn.h @@ -62,7 +62,10 @@ extern void *myrealloc(void *, size_t); #define lchown chown #endif -#if HAVE_MNTENT_H || !(HAVE_GETMNTENT) || HAVE_STRUCT_MNTTAB +#if HAVE_GETMNTINFO_R || HAVE_MNTCTL +# define GETMNTENT_ONE 0 +# define GETMNTENT_TWO 0 +#elif HAVE_MNTENT_H || !(HAVE_GETMNTENT) || HAVE_STRUCT_MNTTAB # if HAVE_MNTENT_H || HAVE_STRUCT_MNTTAB # include # define our_mntent struct mntent -- 2.7.4