ext4: add methods to access file mode, owner, atime, mtime, ctime
[lwext4.git] / fs_test / lwext4_server.c
index 12eb4c572c5fa3c534c89f87210a09e155ed8622..486e121255ad99f79a4160c1ed615262aebe9f37 100644 (file)
 #include <sys/types.h>
 #endif
 
+#include <ext4.h>
 #include "../blockdev/linux/ext4_filedev.h"
 #include "../blockdev/windows/io_raw.h"
 
-#include <ext4.h>
-#include <errno.h>
 
 static int winsock_init(void);
 static void winsock_fini(void);
@@ -71,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];
@@ -300,12 +299,13 @@ 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'},
+           {"version", no_argument, 0, 'x'},
            {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:vcwx", long_options,
                                      &option_index))) {
 
                switch (c) {
@@ -316,13 +316,17 @@ 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;
+               case 'x':
+                       puts(VERSION);
+                       exit(0);
                        break;
                default:
                        printf("%s", usage);
@@ -412,7 +416,21 @@ int _mount(char *p)
                return -1;
        }
 
-       rc = ext4_mount(dev_name, mount_point);
+       if (verbose)
+               ext4_dmask_set(DEBUG_ALL);
+
+       rc = ext4_mount(dev_name, mount_point, false);
+       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;
@@ -421,6 +439,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");
@@ -430,7 +449,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)
@@ -1107,22 +1134,22 @@ int _stats_check(char *p)
 static char *entry_to_str(uint8_t type)
 {
        switch (type) {
-       case EXT4_DIRENTRY_UNKNOWN:
-               return "[UNK] ";
-       case EXT4_DIRENTRY_REG_FILE:
-               return "[FIL] ";
-       case EXT4_DIRENTRY_DIR:
-               return "[DIR] ";
-       case EXT4_DIRENTRY_CHRDEV:
-               return "[CHA] ";
-       case EXT4_DIRENTRY_BLKDEV:
-               return "[BLK] ";
-       case EXT4_DIRENTRY_FIFO:
-               return "[FIF] ";
-       case EXT4_DIRENTRY_SOCK:
-               return "[SOC] ";
-       case EXT4_DIRENTRY_SYMLINK:
-               return "[SYM] ";
+       case EXT4_DE_UNKNOWN:
+               return "[unk] ";
+       case EXT4_DE_REG_FILE:
+               return "[fil] ";
+       case EXT4_DE_DIR:
+               return "[dir] ";
+       case EXT4_DE_CHRDEV:
+               return "[cha] ";
+       case EXT4_DE_BLKDEV:
+               return "[blk] ";
+       case EXT4_DE_FIFO:
+               return "[fif] ";
+       case EXT4_DE_SOCK:
+               return "[soc] ";
+       case EXT4_DE_SYMLINK:
+               return "[sym] ";
        default:
                break;
        }