Fixed mntctl() checking
authorewt <devnull@localhost>
Tue, 17 Jun 1997 14:49:07 +0000 (14:49 +0000)
committerewt <devnull@localhost>
Tue, 17 Jun 1997 14:49:07 +0000 (14:49 +0000)
CVS patchset: 1690
CVS date: 1997/06/17 14:49:07

CHANGES
config.h.in
configure.in
lib/fs.c
misc/miscfn.h

diff --git a/CHANGES b/CHANGES
index 8c2ddf5..c107468 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -13,6 +13,7 @@
        - added "day" query format which is like date, but doesn't print
          any time
        - added --changelog alias to query a packages changelog entry
+       - added mntctl() support for AIX (I think, I can't test this)
 
 2.4 -> 2.4.1:
        - take advantage of lchown() if it's available
index d80551b..a45c709 100644 (file)
@@ -87,4 +87,7 @@
    two defined */
 #define HAVE_GETMNTENT 0
 
+/* Define as one if you have mntctl() (only aix?) */
+#define HAVE_MNTCTL 0
+
 #endif
index ccf449c..585606b 100644 (file)
@@ -278,6 +278,7 @@ 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(strerror, [], MISCOBJS="$MISCOBJS strerror.o")
 AC_CHECK_FUNC(strtol, [], MISCOBJS="$MISCOBJS strtol.o")
 AC_CHECK_FUNC(strtoul, [], MISCOBJS="$MISCOBJS strtoul.o")
index d660917..e4a68b9 100644 (file)
--- a/lib/fs.c
+++ b/lib/fs.c
@@ -1,5 +1,9 @@
 #include "miscfn.h"
 
+#if HAVE_ALLOCA_H
+# include <alloca.h>
+#endif
+
 #include <errno.h>
 #include <stdio.h>
 #include <stdlib.h>
@@ -22,6 +26,65 @@ static int numFilesystems;
 
 static int getFilesystemList(void);
 
+#if HAVE_MNTCTL
+
+/* modeled after sample code from Till Bubeck */
+
+#include <sys/mntctl.h>
+#include <sys/vmount.h>
+
+static int getFilesystemList(void) {
+    int size;
+    void * buf;
+    struct vmount * vm;
+    int num;
+    int fsnameLength;
+    int i;
+
+    num = mntctl(MCTL_QUERY, sizeof(size), (char *) &size);
+    if (num < 0) {
+       rpmError(RPMERR_MTAB, _("mntctl() failed to return fugger size: %s"), 
+                strerror(errno));
+       return 1;
+    }
+
+    buf = alloca(size);
+    num = mntctl(MCTL_QUERY, size, buf);
+
+    numFilesystems = num;
+
+    filesystems = malloc(sizeof(*filesystems) * numFilesystems);
+    fsnames = malloc(sizeof(*filesystems) * numFilesystems);
+    
+    for (vm = buf, i = 0; i < num; i++) {
+       fsnameLength = vm->vmt_data[VMT_STUB].vmt_size;
+       fsnames[i] = malloc(fsnameLength + 1);
+       strncpy(fsnames[i],(char *)vm + vm->vmt_data[VMT_STUB].vmt_off, 
+               fsname_len);
+
+       filesystems[i].mntPoint = fsnames[i];
+
+       if (stat(fsnames[i], &sb)) {
+           rpmError(RPMERR_STAT, "failed to stat %s: %s", fsnames[i],
+                       strerror(errno));
+
+           for (i = 0; i < num; i++)
+               free(filesystems[i].mntPoint);
+           free(filesystems);
+           free(fsnameS);
+
+           filesystems = NULL;
+       }
+       
+       filesystems[num].dev = sb.st_dev;
+
+       /* goto the next vmount structure: */
+       vm = (struct vmount *)((char *)vm + vm->vmt_length);
+    }
+
+    return 0;
+}
+#else 
 static int getFilesystemList(void) {
     our_mntent item, * itemptr;
     FILE * mtab;
@@ -83,6 +146,7 @@ static int getFilesystemList(void) {
 
     return 0; 
 }
+#endif
 
 int rpmGetFilesystemList(char *** listptr) {
     if (!fsnames) 
index b943321..dc6cbcd 100644 (file)
@@ -84,8 +84,8 @@ extern void *myrealloc(void *, size_t);
 # define GETMNTENT_TWO 1
 # define our_mntent struct mnttab
 # define our_mntdir mnt_mountp
-#else
-# error Neither mntent.h nor mnttab.h exists. I cannot build on this system.
+#else if !HAVE_MNTCTL
+# error Neither mntent.h, mnttab.h, or mntctl() exists. I cannot build on this system.
 #endif
 
 #ifndef MOUNTED