summaryrefslogtreecommitdiffstats
path: root/src/mkmntdirs.c
diff options
context:
space:
mode:
authorroot <root@nc.nor.wtbts.org>2008-11-26 08:11:29 +0000
committerroot <root@nc.nor.wtbts.org>2008-11-26 08:11:29 +0000
commitd502ce6638987f0693f19c44104cdb6cd8b1be58 (patch)
tree99e231be3807b1eb798f205564722d885fc5165b /src/mkmntdirs.c
parent9f48dfb93bf5fd031e9102e018a124122c0d1bc2 (diff)
downloadalpine-baselayout-d502ce6638987f0693f19c44104cdb6cd8b1be58.tar.bz2
alpine-baselayout-d502ce6638987f0693f19c44104cdb6cd8b1be58.tar.xz
added mkmntdirs application
this program creates all mount points in fstab
Diffstat (limited to 'src/mkmntdirs.c')
-rw-r--r--src/mkmntdirs.c67
1 files changed, 67 insertions, 0 deletions
diff --git a/src/mkmntdirs.c b/src/mkmntdirs.c
new file mode 100644
index 0000000..2f8f622
--- /dev/null
+++ b/src/mkmntdirs.c
@@ -0,0 +1,67 @@
+/*
+ * Create mount directories in fstab
+ *
+ * Copyright(c) 2008 Natanael Copa <natanael.copa@gmail.com>
+ * May be distributed under the terms of GPL-2
+ *
+ * usage: mkmntdirs [fstab]
+ *
+ */
+
+#include <sys/stat.h>
+#include <sys/types.h>
+
+#include <err.h>
+#include <error.h>
+#include <mntent.h>
+#include <stdio.h>
+
+
+#ifdef DEBUG
+#define mkdir_recursive(p) puts((p))
+#else
+static void mkdir_recursive(char *path)
+{
+ char *s = path;
+ while (1) {
+ int c = '\0';
+ while (*s) {
+ if (*s == '/') {
+ do {
+ ++s;
+ } while (*s == '/');
+ c = *s; /* Save the current char */
+ *s = '\0'; /* and replace it with nul. */
+ break;
+ }
+ ++s;
+ }
+ mkdir(path, 0755);
+ if (c == '\0')
+ return;
+ *s = c;
+ }
+}
+#endif
+
+int main(int argc, const char *argv[])
+{
+ const char *filename = "/etc/fstab";
+ FILE *f;
+ struct mntent *ent;
+ if (argc == 2)
+ filename = argv[1];
+
+ f = setmntent(filename, "r");
+ if (f == NULL)
+ err(1, filename);
+
+ while ((ent = getmntent(f)) != NULL) {
+ if (strcmp(ent->mnt_dir, "none") != 0)
+ mkdir_recursive(ent->mnt_dir);
+ }
+
+ endmntent(f);
+ return 0;
+}
+