]> Savannah Git Hosting - gnulib.git/commitdiff
mountlist: add me_mntroot field on Linux machines
authorDave Chiluk <chiluk@canonical.com>
Mon, 31 Aug 2015 21:07:58 +0000 (16:07 -0500)
committerPádraig Brady <P@draigBrady.com>
Tue, 8 Sep 2015 21:46:53 +0000 (22:46 +0100)
* lib/mountlist.c (read_file_system_list): Populate me_mntroot in
mount_entry so Linux machines based on /proc/self/mountinfo can
distinguish between bind mounts and original mounts.  In reality bind
mounts aren't treated differently than mountroot=/ mounts by the
kernel, but the user often wants these bind mounts distinguished.
* lib/mountlist.h (struct mount_entry): Add me_mntroot element.
More details at https://pad.lv/1432871

ChangeLog
lib/mountlist.c
lib/mountlist.h

index f8ea91ad6e544574c13919c937dc1b2894fd229f..04e8f1b08a559a1d4116a157b25d28b028c828f0 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,14 @@
+2015-09-08  Dave Chiluk  <chiluk@canonical.com>
+
+       mountlist: add me_mntroot field on Linux machines
+       * lib/mountlist.c (read_file_system_list): Populate me_mntroot in
+       mount_entry so Linux machines based on /proc/self/mountinfo can
+       distinguish between bind mounts and original mounts.  In reality bind
+       mounts aren't treated differently than mountroot=/ mounts by the
+       kernel, but the user often wants these bind mounts distinguished.
+       * lib/mountlist.h (struct mount_entry): Add me_mntroot element.
+       More details at https://pad.lv/1432871
+
 2015-09-08  Christian Egli  <christian.egli@sbs.ch>
 
        doc: Describe to use multiple instances of gnulib
index 6f04f5552d5bfcd36918943afef075243dc46586..08ade6f60baf6e4ad0d5b48b34c08c0839a0f9fb 100644 (file)
@@ -447,6 +447,7 @@ read_file_system_list (bool need_fs_type)
         me = xmalloc (sizeof *me);
         me->me_devname = xstrdup (mnt->mnt_fsname);
         me->me_mountdir = xstrdup (mnt->mnt_dir);
+        me->me_mntroot = NULL;
         me->me_type = xstrdup (mnt->mnt_type);
         me->me_type_malloced = 1;
         me->me_dummy = ME_DUMMY (me->me_devname, me->me_type);
@@ -478,7 +479,8 @@ read_file_system_list (bool need_fs_type)
         while (getline (&line, &buf_size, fp) != -1)
           {
             unsigned int devmaj, devmin;
-            int target_s, target_e, type_s, type_e, source_s, source_e;
+            int target_s, target_e, type_s, type_e;
+            int source_s, source_e, mntroot_s, mntroot_e;
             char test;
             char *dash;
             int rc;
@@ -486,13 +488,15 @@ read_file_system_list (bool need_fs_type)
             rc = sscanf(line, "%*u "        /* id - discarded  */
                               "%*u "        /* parent - discarded */
                               "%u:%u "      /* dev major:minor  */
-                              "%*s "        /* mountroot - discarded  */
+                              "%n%*s%n "    /* mountroot */
                               "%n%*s%n"     /* target, start and end  */
                               "%c",         /* more data...  */
                               &devmaj, &devmin,
+                              &mntroot_s, &mntroot_e,
                               &target_s, &target_e,
                               &test);
-            if (rc != 3 && rc != 5)  /* 5 if %n included in count.  */
+
+            if (rc != 3 && rc != 7)  /* 7 if %n included in count.  */
               continue;
 
             /* skip optional fields, terminated by " - "  */
@@ -511,16 +515,19 @@ read_file_system_list (bool need_fs_type)
               continue;
 
             /* manipulate the sub-strings in place.  */
+            line[mntroot_e] = '\0';
             line[target_e] = '\0';
             dash[type_e] = '\0';
             dash[source_e] = '\0';
             unescape_tab (dash + source_s);
             unescape_tab (line + target_s);
+            unescape_tab (line + mntroot_s);
 
             me = xmalloc (sizeof *me);
 
             me->me_devname = xstrdup (dash + source_s);
             me->me_mountdir = xstrdup (line + target_s);
+            me->me_mntroot = xstrdup (line + mntroot_s);
             me->me_type = xstrdup (dash + type_s);
             me->me_type_malloced = 1;
             me->me_dev = makedev (devmaj, devmin);
@@ -566,6 +573,7 @@ read_file_system_list (bool need_fs_type)
             me = xmalloc (sizeof *me);
             me->me_devname = xstrdup (mnt->mnt_fsname);
             me->me_mountdir = xstrdup (mnt->mnt_dir);
+            me->me_mntroot = NULL;
             me->me_type = xstrdup (mnt->mnt_type);
             me->me_type_malloced = 1;
             me->me_dummy = ME_DUMMY (me->me_devname, me->me_type, bind);
@@ -598,6 +606,7 @@ read_file_system_list (bool need_fs_type)
         me = xmalloc (sizeof *me);
         me->me_devname = xstrdup (fsp->f_mntfromname);
         me->me_mountdir = xstrdup (fsp->f_mntonname);
+        me->me_mntroot = NULL;
         me->me_type = fs_type;
         me->me_type_malloced = 0;
         me->me_dummy = ME_DUMMY (me->me_devname, me->me_type);
@@ -624,6 +633,7 @@ read_file_system_list (bool need_fs_type)
         me = xmalloc (sizeof *me);
         me->me_devname = xstrdup (fsp->f_mntfromname);
         me->me_mountdir = xstrdup (fsp->f_mntonname);
+        me->me_mntroot = NULL;
         me->me_type = xstrdup (fsp->f_fstypename);
         me->me_type_malloced = 1;
         me->me_dummy = ME_DUMMY (me->me_devname, me->me_type);
@@ -650,6 +660,7 @@ read_file_system_list (bool need_fs_type)
         me = xmalloc (sizeof *me);
         me->me_devname = xstrdup (fsd.fd_req.devname);
         me->me_mountdir = xstrdup (fsd.fd_req.path);
+        me->me_mntroot = NULL;
         me->me_type = gt_names[fsd.fd_req.fstype];
         me->me_type_malloced = 0;
         me->me_dummy = ME_DUMMY (me->me_devname, me->me_type);
@@ -748,6 +759,7 @@ read_file_system_list (bool need_fs_type)
           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_mntroot = NULL;
           me->me_type = xstrdup (fi.fsh_name);
           me->me_type_malloced = 1;
           me->me_dev = fi.dev;
@@ -797,6 +809,7 @@ read_file_system_list (bool need_fs_type)
         me = xmalloc (sizeof *me);
         me->me_devname = xstrdup (stats[counter].f_mntfromname);
         me->me_mountdir = xstrdup (stats[counter].f_mntonname);
+        me->me_mntroot = NULL;
         me->me_type = xstrdup (FS_TYPE (stats[counter]));
         me->me_type_malloced = 1;
         me->me_dummy = ME_DUMMY (me->me_devname, me->me_type);
@@ -833,6 +846,7 @@ read_file_system_list (bool need_fs_type)
         strcpy (me->me_devname + 5, mnt.mt_dev);
 # endif
         me->me_mountdir = xstrdup (mnt.mt_filsys);
+        me->me_mntroot = NULL;
         me->me_dev = (dev_t) -1;        /* Magic; means not known yet. */
         me->me_type = "";
         me->me_type_malloced = 0;
@@ -880,6 +894,7 @@ read_file_system_list (bool need_fs_type)
         me = xmalloc (sizeof *me);
         me->me_devname = xstrdup ((*ent)->mt_resource);
         me->me_mountdir = xstrdup ((*ent)->mt_directory);
+        me->me_mntroot = NULL;
         me->me_type = xstrdup ((*ent)->mt_fstype);
         me->me_type_malloced = 1;
         me->me_dummy = ME_DUMMY (me->me_devname, me->me_type);
@@ -942,6 +957,7 @@ read_file_system_list (bool need_fs_type)
             me = xmalloc (sizeof *me);
             me->me_devname = xstrdup (mnt.mnt_special);
             me->me_mountdir = xstrdup (mnt.mnt_mountp);
+            me->me_mntroot = NULL;
             me->me_type = xstrdup (mnt.mnt_fstype);
             me->me_type_malloced = 1;
             me->me_dummy = MNT_IGNORE (&mnt) != 0;
@@ -1020,6 +1036,7 @@ read_file_system_list (bool need_fs_type)
                                       vmp->vmt_data[VMT_OBJECT].vmt_off);
           }
         me->me_mountdir = xstrdup (thisent + vmp->vmt_data[VMT_STUB].vmt_off);
+        me->me_mntroot = NULL;
         me->me_type = xstrdup (fstype_to_string (vmp->vmt_gfstype));
         me->me_type_malloced = 1;
         options = thisent + vmp->vmt_data[VMT_ARGS].vmt_off;
@@ -1063,6 +1080,7 @@ read_file_system_list (bool need_fs_type)
             me = xmalloc (sizeof *me);
             me->me_devname = xstrdup (dev.f_mntfromname);
             me->me_mountdir = xstrdup (dev.f_mntonname);
+            me->me_mntroot = NULL;
             me->me_type = xstrdup (dev.f_fstypename);
             me->me_type_malloced = 1;
             me->me_dummy = ME_DUMMY (me->me_devname, me->me_type);
@@ -1105,6 +1123,7 @@ void free_mount_entry (struct mount_entry *me)
 {
   free (me->me_devname);
   free (me->me_mountdir);
+  free (me->me_mntroot);
   if (me->me_type_malloced)
     free (me->me_type);
   free (me);
index 735776b063945d370286e9c6c4195d69c27eca8e..9ce3137f86abcb463b33ed26b490db90087579d9 100644 (file)
@@ -27,6 +27,8 @@ struct mount_entry
 {
   char *me_devname;             /* Device node name, including "/dev/". */
   char *me_mountdir;            /* Mount point directory name. */
+  char *me_mntroot;             /* Directory on filesystem of device used */
+                                /* as root for the (bind) mount. */
   char *me_type;                /* "nfs", "4.2", etc. */
   dev_t me_dev;                 /* Device number of me_mountdir. */
   unsigned int me_dummy : 1;    /* Nonzero for dummy file systems. */