From 7a53690aeea9469ac9399a98e5cfe18ee40b82b2 Mon Sep 17 00:00:00 2001 From: Mike Blumenkrantz Date: Mon, 16 May 2011 10:33:57 +0000 Subject: [PATCH] add some rudimentary dir management for mounting (creation/deletion of /media/$uuid dirs) SVN revision: 59440 --- src/bin/e_sys_main.c | 61 +++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 58 insertions(+), 3 deletions(-) diff --git a/src/bin/e_sys_main.c b/src/bin/e_sys_main.c index 01670b1..d87ae64 100644 --- a/src/bin/e_sys_main.c +++ b/src/bin/e_sys_main.c @@ -5,6 +5,7 @@ #include #include #include +#include #include #include #include @@ -125,14 +126,68 @@ main(int argc, if (mnt) { Eina_Strbuf *buf; + int ret; + const char *mp; buf = eina_strbuf_new(); if (!buf) goto err; for (i = 1; i < argc; i++) - eina_strbuf_append_printf(buf, "%s ", argv[i]); - return system(eina_strbuf_string_get(buf)); + { + if (!strncmp(argv[i], "/media/", 7)) + { + mp = argv[i]; + if (!strcmp(action, "mount")) + { + struct stat s; + + if (stat("/media", &s)) + { + mode_t um; + + um = umask(0); + if (mkdir("/media", S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH)) + { + printf("ERROR: COULD NOT CREATE DIRECTORY /media\n"); + exit(40); + } + umask(um); + } + else if (!S_ISDIR(s.st_mode)) + { + printf("ERROR: NOT A DIRECTORY: /media\n"); + exit(40); + } + + if (stat(argv[i], &s)) + { + mode_t um; + + um = umask(0); + if (mkdir(argv[i], S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH)) + { + printf("ERROR: COULD NOT CREATE DIRECTORY %s\n", argv[i]); + exit(40); + } + umask(um); + } + else if (!S_ISDIR(s.st_mode)) + { + printf("ERROR: NOT A DIRECTORY: %s\n", argv[i]); + exit(40); + } + } + } + eina_strbuf_append_printf(buf, "%s ", argv[i]); + } + ret = system(eina_strbuf_string_get(buf)); + if ((!strcmp(action, "umount")) && (!ret)) + { + if (rmdir(mp)) + printf("ERROR: COULD NOT UNLINK MOUNT POINT %s\n", mp); + } + return ret; } - + eina_shutdown(); return 0; -- 2.7.4