diff options
author | dianshi <dianshi@main.lv> | 2020-06-27 11:47:52 +0100 |
---|---|---|
committer | dianshi <dianshi@main.lv> | 2020-06-27 11:47:52 +0100 |
commit | a9d8b8915e5d9f9d2bb30ac94a882795d2a2d517 (patch) | |
tree | b54f87bac53ee080a9e728ce03e1dcd820eff766 | |
parent | f2b53c4cb1316bfd11068b4df1c6f25aa1133e53 (diff) | |
download | nmount-a9d8b8915e5d9f9d2bb30ac94a882795d2a2d517.tar.gz nmount-a9d8b8915e5d9f9d2bb30ac94a882795d2a2d517.zip |
Add support for non source fs
-rw-r--r-- | Makefile | 5 | ||||
-rw-r--r-- | nmount.c | 57 |
2 files changed, 47 insertions, 15 deletions
@@ -1,3 +1,6 @@ make: gcc -Wall nmount.c -o nmount - gcc -static nmount.c -o nmount_static
\ No newline at end of file + gcc -static nmount.c -o nmount_static + +clean: + rm nmount nmount_static
\ No newline at end of file @@ -80,19 +80,20 @@ vfs_options vfs_options_proc[] = static const struct vfs { - char *name; - long flags; - char *mountpoint; - vfs_options *options; + char *name; //filesystem name + long flags; //dunno + char *mountpoint; //default mount point if mount dir is not set + int nosource; //does fs have source or not + vfs_options *options; //hellpers to show all possible options to config fs mount } vfstab[] = { - {"devtmpfs", 0, "/Device", NULL}, - {"mqueue", 0, "/MQueue/", NULL}, - {"proc", 0, "/Process", (struct vfs_options*)&vfs_options_proc}, - {"tmpfs", 0, "/Ram", NULL}, - {"sysfs", 0, "/System", NULL}, - {"ext4", 0, NULL, NULL}, - {"vfat", 0, NULL, NULL}, - {NULL, 0, NULL, NULL}, + {"devtmpfs", 0, "/Device", 0, NULL}, + {"mqueue", 0, "/MQueue/", 0, NULL}, + {"proc", 0, "/Process", 1, (struct vfs_options*)&vfs_options_proc}, + {"tmpfs", 0, "/Ram", 0, NULL}, + {"sysfs", 0, "/System", 0, NULL}, + {"ext4", 0, NULL, 0, NULL}, + {"vfat", 0, NULL, 0, NULL}, + {NULL, 0, NULL, 0, NULL}, }; static const struct mount_flags @@ -173,6 +174,19 @@ int check_filetype(char *fsname) return 0; } +int get_fs_idx(char *fsname) +{ + int i; + for (i=0;i<STRUCT_LEN(vfstab,struct vfs);i++) + { + if (strncmp(vfstab[i].name,fsname,max(strlen(vfstab[i].name),strlen(fsname))) == 0) + { + return i; + } + } + return -1; +} + unsigned long str2flag(char *opt) { int i; @@ -213,6 +227,7 @@ int main(int argc, char **argv) { int c; int i,j,k; + int fs_idx=-1; printf("One big real mount\n"); @@ -288,6 +303,7 @@ int main(int argc, char **argv) if (NULL != g_params.f_type) { + //dindt found fs name if (check_filetype(g_params.f_type) != 1) { printf("Unknow file type %s\n",g_params.f_type); @@ -298,7 +314,13 @@ int main(int argc, char **argv) } printf("\n"); return 1; + //found fs name + } else + { + //find index of fs in fs table + fs_idx = get_fs_idx(g_params.f_type); //should allways be possitive as its allready checked } + } if (NULL != g_params.f_flags) @@ -314,15 +336,22 @@ int main(int argc, char **argv) } } + //if target dir is defined use it if (NULL != g_params.f_target_dir) { mkdir(g_params.f_target_dir, 0000); + //if target dir is not define use default one + } else { + g_params.f_target_dir = vfstab[fs_idx].mountpoint; + mkdir(g_params.f_target_dir, 0000); } + //source dir is not need for some of the fs'es + if (((NULL != g_params.f_source_dir) && (vfstab[fs_idx].nosource == 0)) || + ((NULL == g_params.f_source_dir) && (vfstab[fs_idx].nosource == 1))) if ((NULL != g_params.f_target_dir) && (NULL != g_params.f_flags) && - (NULL != g_params.f_type) && - (NULL != g_params.f_source_dir)) + (NULL != g_params.f_type)) { printf("Flags: %d\n",g_params.mount_flags); int ret = smount( |