3 * - By John Hodge (thePowersGang)
12 #include <acess/sys.h>
15 #define LVMBASE "/Devices/LVM"
16 #define AMOUNTROOT "/Mount/auto"
18 void TryMount(const char *Volume, const char *Part);
21 int main(int argc, char *argv[])
23 mkdir(AMOUNTROOT, 0755);
24 // TODO: Handle variants like 'by-label' and 'by-id'
26 // Iterate '/Devices/LVM/*/*'
27 DIR *dp = opendir(LVMBASE);
30 while( (ent = readdir(dp)) )
32 if( ent->d_name[0] == '.' )
34 if( strncmp(ent->d_name, "by-", 3) == 0 )
37 char path[sizeof(LVMBASE)+1+strlen(ent->d_name)+1];
38 sprintf(path, LVMBASE"/%s", ent->d_name);
39 DIR *ddp = opendir(path);
42 // Attempt to mount each sub-volume
45 while( (dent = readdir(ddp)) )
47 if(dent->d_name[0] == '.')
49 if(strcmp(dent->d_name, "ROOT") == 0)
52 TryMount(ent->d_name, dent->d_name);
58 // If only ROOT exists, attempt to mount that as '/Mount/auto/devname'
61 TryMount(ent->d_name, NULL);
70 void TryMount(const char *Volume, const char *Part)
73 size_t devpath_len = sizeof(LVMBASE)+1+strlen(Volume)+1 + (Part ? strlen(Part)+1 : 5);
74 char devpath[devpath_len];
75 sprintf(devpath, LVMBASE"/%s/%s", Volume, (Part ? Part : "ROOT"));
78 size_t mntpath_len = sizeof(AMOUNTROOT)+1+strlen(Volume)+1 + (Part ? strlen(Part)+1 : 0);
79 char mntpath[mntpath_len];
80 sprintf(mntpath, AMOUNTROOT"/%s", Volume);
83 strcat(mntpath, Part);
88 if( _SysMount(devpath, mntpath, NULL, "") ) {
89 fprintf(stderr, "Unable to mount '%s'\n", devpath);