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;
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;
+ char *bus;
+
+ devname = get_property_value(props, "DEVNAME");
+ if(is_in_array(allowed, devname))
+ return 1;
+
+ if(match_property_value(props, "ID_TYPE", "cd") && match_property_value(props, "ID_CDROM_MEDIA", "1"))
+ return 1;
if(!match_property_value(props, "DEVTYPE", "partition"))
return 0;
if(is_removable(devpath))
return 1;
- for(i=0; removable_buses[i]; ++i)
- if(match_property_value(props, "ID_BUS", removable_buses[i]))
- return 1;
+ bus = get_property_value(props, "ID_BUS");
+ if(is_in_array(removable_buses, bus))
+ return 1;
return check_buses(devpath, removable_buses);
}
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)
{
printf(" %s = %s\n", props[j].name, props[j].value);
}
- if(can_mount(props))
+ if(can_mount(props, fstab))
{
char *devname;
char *label;
char buf[1024];
int pos = 0;
int status;
+ fd_set fds;
+ struct timeval timeout;
close(pipe_fd[1]);
+ FD_ZERO(&fds);
+ FD_SET(pipe_fd[0], &fds);
+ timeout.tv_sec = 0;
+ timeout.tv_usec = 200000;
while(1)
{
- int len;
+ if(select(pipe_fd[0]+1, &fds, NULL, NULL, &timeout))
+ {
+ int len;
- len = read(pipe_fd[0], buf+pos, sizeof(buf)-pos-1);
- if(len<=0)
+ len = read(pipe_fd[0], buf+pos, sizeof(buf)-pos-1);
+ if(len<=0)
+ break;
+ pos += len;
+ }
+ else if(waitpid(pid, &status, 0))
break;
- pos += len;
}
buf[pos] = 0;
- waitpid(pid, &status, 0);
if(!WIFEXITED(status) || WEXITSTATUS(status))
{
GtkWidget *dialog;