Usermode/automounter - Added automounter
authorJohn Hodge <[email protected]>
Wed, 3 Jul 2013 11:33:08 +0000 (19:33 +0800)
committerJohn Hodge <[email protected]>
Wed, 3 Jul 2013 11:33:08 +0000 (19:33 +0800)
Makefile
Usermode/Applications/automounter_src/Makefile [new file with mode: 0644]
Usermode/Applications/automounter_src/main.c [new file with mode: 0644]

index f0f85df..4ff95bd 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -14,7 +14,7 @@ USRLIBS := crt0.o acess.ld ld-acess.so libc.so libposix.so
 USRLIBS += libreadline.so libnet.so liburi.so libpsocket.so
 USRLIBS += libimage_sif.so libunicode.so
 
-USRAPPS := init login CLIShell cat ls mount
+USRAPPS := init login CLIShell cat ls mount automounter
 USRAPPS += bomb lspci
 USRAPPS += ip dhcpclient ping telnet irc wget telnetd
 USRAPPS += axwin3 gui_ate gui_shell
diff --git a/Usermode/Applications/automounter_src/Makefile b/Usermode/Applications/automounter_src/Makefile
new file mode 100644 (file)
index 0000000..96f0b15
--- /dev/null
@@ -0,0 +1,12 @@
+# Project: Automounter\r
+\r
+-include ../Makefile.cfg\r
+\r
+CPPFLAGS += \r
+LDFLAGS  += \r
+\r
+DIR = SBin\r
+BIN = automount\r
+OBJ = main.o\r
+\r
+-include ../Makefile.tpl\r
diff --git a/Usermode/Applications/automounter_src/main.c b/Usermode/Applications/automounter_src/main.c
new file mode 100644 (file)
index 0000000..c30924a
--- /dev/null
@@ -0,0 +1,92 @@
+/*
+ * Acess2 Automounter
+ * - By John Hodge (thePowersGang)
+ *
+ * main.c
+ * - Program core
+ */
+#include <stdlib.h>
+#include <dirent.h>
+#include <stdio.h>
+#include <string.h>
+#include <acess/sys.h>
+#include <assert.h>
+
+#define        LVMBASE "/Devices/LVM"
+#define AMOUNTROOT     "/Mount/auto"
+
+void   TryMount(const char *Volume, const char *Part);
+
+// === CODE ===
+int main(int argc, char *argv[])
+{
+       mkdir(AMOUNTROOT, 0755);
+       // TODO: Handle variants like 'by-label' and 'by-id'
+       
+       // Iterate '/Devices/LVM/*/*'
+       DIR     *dp = opendir(LVMBASE);
+       assert(dp);
+       struct dirent   *ent;
+       while( (ent = readdir(dp)) )
+       {
+               if( ent->d_name[0] == '.' )
+                       continue ;
+               if( strncmp(ent->d_name, "by-", 3) == 0 )
+                       continue ;
+               
+               char    path[sizeof(LVMBASE)+1+strlen(ent->d_name)+1];
+               sprintf(path, LVMBASE"/%s", ent->d_name);
+               DIR     *ddp = opendir(path);
+               assert(ddp);
+
+               // Attempt to mount each sub-volume
+               struct dirent   *dent;
+                int    nParts = 0;
+               while( (dent = readdir(ddp)) )
+               {
+                       if(dent->d_name[0] == '.')
+                               continue ;
+                       if(strcmp(dent->d_name, "ROOT") == 0)
+                               continue ;
+
+                       TryMount(ent->d_name, dent->d_name);
+
+                       nParts ++;
+               }
+               closedir(ddp);
+               
+               // If only ROOT exists, attempt to mount that as '/Mount/auto/devname'
+               if( nParts == 0 )
+               {
+                       TryMount(ent->d_name, NULL);
+               }
+       }
+       
+       closedir(dp);
+       
+       return 0;
+}
+
+void TryMount(const char *Volume, const char *Part)
+{
+       // Create device path
+       size_t  devpath_len = sizeof(LVMBASE)+1+strlen(Volume)+1 + (Part ? strlen(Part)+1 : 5);
+       char devpath[devpath_len];
+       sprintf(devpath, LVMBASE"/%s/%s", Volume, (Part ? Part : "ROOT"));
+
+       // Create mount path
+       size_t  mntpath_len = sizeof(AMOUNTROOT)+1+strlen(Volume)+1 + (Part ? strlen(Part)+1 : 0);
+       char mntpath[mntpath_len];
+       sprintf(mntpath, AMOUNTROOT"/%s", Volume);
+       if( Part ) {
+               strcat(mntpath, "-");
+               strcat(mntpath, Part);
+       }
+       mkdir(mntpath, 0755);
+       
+       // Attempt mount
+       if( _SysMount(devpath, mntpath, NULL, "") ) {
+               fprintf(stderr, "Unable to mount '%s'\n", devpath);
+       }
+}
+

UCC git Repository :: git.ucc.asn.au