+/*\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 <stdlib.h>\r
#include <unistd.h>\r
-#include <errno.h>\r
#include <string.h>\r
#include <stdint.h>\r
#include <stdbool.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
#include <sys/types.h>\r
#endif\r
\r
-#include <ext4.h>\r
+\r
#include <ext4_filedev.h>\r
#include <io_raw.h>\r
\r
+#include <ext4.h>\r
+\r
static int winsock_init(void);\r
static void winsock_fini(void);\r
static char* entry_to_str(uint8_t type);\r
\r
\r
/**@brief Default connection port*/\r
-static int connection_port = 8888;\r
+static int connection_port = 1234;\r
\r
/**@brief Default filesystem filename.*/\r
static char *ext4_fname = "ext2";\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
clock_t t = get_ms();\r
r = op_call[i].lwext4_call(opcode);\r
\r
- printf("rc: %d, time: %ums\n", r, get_ms() - t);\r
+ printf("rc: %d, time: %ums\n", r, (unsigned int)(get_ms() - t));\r
\r
break;\r
}\r
exit(-1);\r
}\r
\r
+ int yes = 1;\r
+ if (setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, (void *)&yes, sizeof(int))) {\r
+ printf("setsockopt() error: %s\n", strerror(errno));\r
+ exit(-1);\r
+ }\r
+\r
serv_addr.sin_family = AF_INET;\r
serv_addr.sin_addr.s_addr = htonl(INADDR_ANY);\r
serv_addr.sin_port = htons(connection_port);\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
close(connfd);\r
}\r
\r
- closesocket(listenfd);\r
winsock_fini();\r
return 0;\r
}\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
int i;\r
ext4_file fd;\r
\r
- if(sscanf(p, "%s %s %d", &path, prefix, &cnt) != 3){\r
+ if(sscanf(p, "%s %s %d", path, prefix, &cnt) != 3){\r
printf("Param list error\n");\r
return -1;\r
}\r
int i, d, wb;\r
ext4_file fd;\r
\r
- if(sscanf(p, "%s %s %d %d", &path, prefix, &cnt, &ll) != 4){\r
+ if(sscanf(p, "%s %s %d %d", path, prefix, &cnt, &ll) != 4){\r
printf("Param list error\n");\r
return -1;\r
}\r
int i, d, rb;\r
ext4_file fd;\r
\r
- if(sscanf(p, "%s %s %d %d", &path, prefix, &cnt, &ll) != 4){\r
+ if(sscanf(p, "%s %s %d %d", path, prefix, &cnt, &ll) != 4){\r
printf("Param list error\n");\r
return -1;\r
}\r
char prefix[32];\r
int cnt, i, rc;\r
\r
- if(sscanf(p, "%s %s %d", &path, prefix, &cnt) != 3){\r
+ if(sscanf(p, "%s %s %d", path, prefix, &cnt) != 3){\r
printf("Param list error\n");\r
return -1;\r
}\r
char prefix[32];\r
int cnt, i, rc;\r
\r
- if(sscanf(p, "%s %s %d", &path, prefix, &cnt) != 3){\r
+ if(sscanf(p, "%s %s %d", path, prefix, &cnt) != 3){\r
printf("Param list error\n");\r
return -1;\r
}\r
char prefix[32];\r
int cnt, i, rc;\r
\r
- if(sscanf(p, "%s %s %d", &path, prefix, &cnt) != 3){\r
+ if(sscanf(p, "%s %s %d", path, prefix, &cnt) != 3){\r
printf("Param list error\n");\r
return -1;\r
}\r
{\r
char path[256];\r
\r
- if(sscanf(p, "%s", &path) != 1){\r
+ if(sscanf(p, "%s", path) != 1){\r
printf("Param list error\n");\r
return -1;\r
}\r
\r
struct ext4_mount_stats actual_stats;\r
\r
- if(sscanf(p, "%s", &path) != 1){\r
+ if(sscanf(p, "%s", path) != 1){\r
printf("Param list error\n");\r
return -1;\r
}\r