lwext4_server: improve opt list
[lwext4.git] / fs_test / lwext4_server.c
index b1e720b6c81e921efff698c3134437d24f45998d..111b3a10cf044f40f00a14af2c72b70150ec07b8 100644 (file)
@@ -70,15 +70,15 @@ static int connection_port = 1234;
 static char *ext4_fname = "ext2";
 
 /**@brief   Verbose mode*/
-static int verbose = 0;
+static bool verbose = false;
 
 /**@brief   Winpart mode*/
-static int winpart = 0;
+static bool winpart = false;
 
 /**@brief   Blockdev handle*/
 static struct ext4_blockdev *bd;
 
-static int cache_wb = 0;
+static bool cache_wb = false;
 
 static char read_buffer[MAX_RW_BUFFER];
 static char write_buffer[MAX_RW_BUFFER];
@@ -299,12 +299,12 @@ static bool parse_opt(int argc, char **argv)
        static struct option long_options[] = {
            {"image", required_argument, 0, 'i'},
            {"port", required_argument, 0, 'p'},
-           {"verbose", required_argument, 0, 'v'},
-           {"winpart", required_argument, 0, 'w'},
-           {"cache_wb", required_argument, 0, 'c'},
+           {"verbose", no_argument, 0, 'v'},
+           {"winpart", no_argument, 0, 'w'},
+           {"cache_wb", no_argument, 0, 'c'},
            {0, 0, 0, 0}};
 
-       while (-1 != (c = getopt_long(argc, argv, "c:i:p:v:w:", long_options,
+       while (-1 != (c = getopt_long(argc, argv, "i:p:vcw", long_options,
                                      &option_index))) {
 
                switch (c) {
@@ -315,13 +315,13 @@ static bool parse_opt(int argc, char **argv)
                        connection_port = atoi(optarg);
                        break;
                case 'v':
-                       verbose = atoi(optarg);
+                       verbose = true;
                        break;
                case 'c':
-                       cache_wb = atoi(optarg);
+                       cache_wb = true;
                        break;
                case 'w':
-                       winpart = atoi(optarg);
+                       winpart = true;
                        break;
                default:
                        printf("%s", usage);
@@ -411,7 +411,21 @@ int _mount(char *p)
                return -1;
        }
 
+       if (verbose)
+               ext4_dmask_set(DEBUG_ALL);
+
        rc = ext4_mount(dev_name, mount_point);
+       if (rc != EOK)
+               return rc;
+
+       rc = ext4_recover(mount_point);
+       if (rc != EOK && rc != ENOTSUP)
+               return rc;
+
+       rc = ext4_journal_start(mount_point);
+       if (rc != EOK)
+               return rc;
+
        if (cache_wb)
                ext4_cache_write_back(mount_point, 1);
        return rc;
@@ -420,6 +434,7 @@ int _mount(char *p)
 int _umount(char *p)
 {
        char mount_point[32];
+       int rc;
 
        if (sscanf(p, "%s", mount_point) != 1) {
                printf("Param list error\n");
@@ -429,7 +444,15 @@ int _umount(char *p)
        if (cache_wb)
                ext4_cache_write_back(mount_point, 0);
 
-       return ext4_umount(mount_point);
+       rc = ext4_journal_stop(mount_point);
+       if (rc != EOK)
+               return rc;
+
+       rc = ext4_umount(mount_point);
+       if (rc != EOK)
+               return rc;
+
+       return rc;
 }
 
 int _mount_point_stats(char *p)