+/*\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
#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
/**@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
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
{"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
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
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
\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
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
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