Licence header.
[lwext4.git] / fs_test / lwext4_server.c
index 30a7a0803efe1bbda94622279f847d58ebfbe923..53ee5e2fca0955d2ef3513799af03bcf092d6732 100644 (file)
@@ -1,3 +1,30 @@
+/*\r
+ * Copyright (c) 2014 Grzegorz Kostka (kostka.grzegorz@gmail.com)\r
+ * All rights reserved.\r
+ *\r
+ * Redistribution and use in source and binary forms, with or without\r
+ * modification, are permitted provided that the following conditions\r
+ * are met:\r
+ *\r
+ * - Redistributions of source code must retain the above copyright\r
+ *   notice, this list of conditions and the following disclaimer.\r
+ * - Redistributions in binary form must reproduce the above copyright\r
+ *   notice, this list of conditions and the following disclaimer in the\r
+ *   documentation and/or other materials provided with the distribution.\r
+ * - The name of the author may not be used to endorse or promote products\r
+ *   derived from this software without specific prior written permission.\r
+ *\r
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR\r
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES\r
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.\r
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,\r
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT\r
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,\r
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY\r
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT\r
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF\r
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\r
+ */\r
 \r
 #include <errno.h>\r
 #include <stdio.h>\r
@@ -10,8 +37,9 @@
 #include <time.h>\r
 \r
 #ifdef WIN32\r
-#include <windows.h>\r
 #include <winsock2.h>\r
+#include <ws2tcpip.h>\r
+#include <windows.h>\r
 #else\r
 #include <sys/socket.h>\r
 #include <netinet/in.h>\r
@@ -45,6 +73,14 @@ static char *ext4_fname = "ext2";
 /**@brief   Verbose mode*/\r
 static int verbose = 0;\r
 \r
+/**@brief   Winpart mode*/\r
+static int winpart = 0;\r
+\r
+/**@brief   Blockdev handle*/\r
+static struct ext4_blockdev *bd;\r
+\r
+static int cache_wb = 0;\r
+\r
 static char read_buffer[MAX_RW_BUFFER];\r
 static char write_buffer[MAX_RW_BUFFER];\r
 \r
@@ -53,9 +89,11 @@ static const char *usage = "                                    \n\
 Welcome in lwext4_server.                                       \n\\r
 Copyright (c) 2013 Grzegorz Kostka (kostka.grzegorz@gmail.com)  \n\\r
 Usage:                                                          \n\\r
-    --image    (-i) - ext2/3/4 image file                       \n\\r
-    --port     (-p) - server port                               \n\\r
-    --verbose  (-v) - verbose mode                              \n\\r
+    --image     (-i) - ext2/3/4 image file                      \n\\r
+    --port      (-p) - server port                              \n\\r
+    --verbose   (-v) - verbose mode                             \n\\r
+    --winpart   (-w) - windows_partition mode                   \n\\r
+    --cache_wb  (-c) - cache writeback_mode                     \n\\r
 \n";\r
 \r
 \r
@@ -266,10 +304,12 @@ static bool parse_opt(int argc, char **argv)
             {"image",   required_argument, 0, 'i'},\r
             {"port",    required_argument, 0, 'p'},\r
             {"verbose", required_argument, 0, 'v'},\r
+            {"winpart", required_argument, 0, 'w'},\r
+            {"cache_wb",required_argument, 0, 'c'},\r
             {0, 0, 0, 0}\r
     };\r
 \r
-    while(-1 != (c = getopt_long (argc, argv, "i:p:v:", long_options, &option_index))) {\r
+    while(-1 != (c = getopt_long (argc, argv, "c:i:p:v:w:", long_options, &option_index))) {\r
 \r
         switch(c){\r
         case 'i':\r
@@ -281,6 +321,12 @@ static bool parse_opt(int argc, char **argv)
         case 'v':\r
             verbose = atoi(optarg);\r
             break;\r
+        case 'c':\r
+            cache_wb = atoi(optarg);\r
+            break;\r
+        case 'w':\r
+            winpart = atoi(optarg);\r
+            break;\r
         default:\r
             printf("%s", usage);\r
             return false;\r
@@ -300,7 +346,6 @@ int main(int argc, char *argv[])
     if(!parse_opt(argc, argv))\r
         return -1;\r
 \r
-    ext4_filedev_filename(ext4_fname);\r
     listenfd = server_open();\r
 \r
     printf("lwext4_server: listening on port: %d\n", connection_port);\r
@@ -337,16 +382,28 @@ int main(int argc, char *argv[])
 \r
 int _device_register(char *p)\r
 {\r
-    int bd;\r
+    int dev;\r
     int cache_mode;\r
     char dev_name[32];\r
 \r
-    if(sscanf(p, "%d %d %s", &bd, &cache_mode, dev_name) != 3){\r
+    if(sscanf(p, "%d %d %s", &dev, &cache_mode, dev_name) != 3){\r
         printf("Param list error\n");\r
         return -1;\r
     }\r
 \r
-    return ext4_device_register(ext4_filedev_get(), 0, dev_name);\r
+#ifdef WIN32\r
+    if(winpart){\r
+        ext4_io_raw_filename(ext4_fname);\r
+        bd = ext4_io_raw_dev_get();\r
+\r
+    }\r
+    else\r
+#endif\r
+    {\r
+        ext4_filedev_filename(ext4_fname);\r
+        bd = ext4_filedev_get();\r
+    }\r
+    return ext4_device_register(bd, 0, dev_name);\r
 }\r
 \r
 int _mount(char *p)\r
@@ -360,7 +417,10 @@ int _mount(char *p)
         return -1;\r
     }\r
 \r
-    return ext4_mount(dev_name, mount_point);\r
+    rc = ext4_mount(dev_name, mount_point);\r
+    if(cache_wb)\r
+        ext4_cache_write_back(mount_point, 1);\r
+    return rc;\r
 }\r
 \r
 int _umount(char *p)\r
@@ -372,6 +432,9 @@ int _umount(char *p)
         return -1;\r
     }\r
 \r
+    if(cache_wb)\r
+        ext4_cache_write_back(mount_point, 0);\r
+\r
     return ext4_umount(mount_point);\r
 }\r
 \r