Support user-mountable devices in fstab
authorMikko Rasa <tdb@tdb.fi>
Sat, 19 Apr 2014 15:57:51 +0000 (18:57 +0300)
committerMikko Rasa <tdb@tdb.fi>
Sat, 19 Apr 2014 17:11:49 +0000 (20:11 +0300)
main.c

diff --git a/main.c b/main.c
index cd95cc943cc78cabd0142b2b881367847bda9567..2609341f6c870eef728bd6e08f966958fa460baa 100644 (file)
--- a/main.c
+++ b/main.c
@@ -211,6 +211,16 @@ char **get_mounted_devices(void)
        return get_mount_entries("/etc/mtab", NULL);
 }
 
+int is_user_mountable(struct mntent *me)
+{
+       return hasmntopt(me, "user")!=NULL;
+}
+
+char **get_fstab_devices(void)
+{
+       return get_mount_entries("/etc/fstab", &is_user_mountable);
+}
+
 int is_in_array(char **names, char *devname)
 {
        int i;
@@ -298,12 +308,17 @@ int check_buses(char *devpath, char **buses)
        return 0;
 }
 
-int can_mount(Property *props)
+int can_mount(Property *props, char **allowed)
 {
        static char *removable_buses[] = { "usb", "firewire", 0 };
+       char *devname;
        char *devpath;
        int i;
 
+       devname = get_property_value(props, "DEVNAME");
+       if(is_in_array(allowed, devname))
+               return 1;
+
        if(!match_property_value(props, "DEVTYPE", "partition"))
                return 0;
 
@@ -400,10 +415,12 @@ Device *get_devices(void)
        Device *devices = NULL;
        int n_devices = 0;
        char **mounted = NULL;
+       char **fstab = NULL;
        int i;
 
        nodes = get_device_nodes("/dev/disk/by-id");
        mounted = get_mounted_devices();
+       fstab = get_fstab_devices();
 
        for(i=0; nodes[i]; ++i)
        {
@@ -425,7 +442,7 @@ Device *get_devices(void)
                                printf("  %s = %s\n", props[j].name, props[j].value);
                }
 
-               if(can_mount(props))
+               if(can_mount(props, fstab))
                {
                        char *devname;
                        char *label;