From 825bd4d3fb70620364e401236135444e46290dd1 Mon Sep 17 00:00:00 2001 From: Fufu Fang Date: Thu, 25 Apr 2019 21:33:22 +0100 Subject: [PATCH] added the command line switch to control the download segment size --- README.md | 16 ++++++++-------- src/cache.c | 9 ++++++++- src/cache.h | 5 +++++ src/main.c | 6 ++++++ 4 files changed, 27 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index b2a00dc..865a3c9 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,3 @@ - - # HTTPDirFS - now with a permanent cache Have you ever wanted to mount those HTTP directory listings as if it was a partition? Look no further, this is your solution. HTTPDirFS stands for Hyper Text Transfer Protocol Directory Filesystem @@ -13,15 +11,17 @@ The permanent cache system caches all the files you have downloaded, so you don' An example URL would be [Debian CD Image Server](https://cdimage.debian.org/debian-cd/). The ``-f`` flag keeps the program in the foreground, which is useful for monitoring which URL the filesystem is visiting. -Other useful options: - +Useful options: + -f Run HTTPDirFS in foreground -u --username HTTP authentication username -p --password HTTP authentication password -P --proxy Proxy for libcurl, for more details refer to - https://curl.haxx.se/libcurl/c/CURLOPT_PROXY.html - --proxy-username Username for the proxy - --proxy-password Password for the proxy - --cache Set the cache folder + https://curl.haxx.se/libcurl/c/CURLOPT_PROXY.html + --proxy-username Username for the proxy + --proxy-password Password for the proxy + --cache Set the cache folder + --dl-seg-size Set the size of each download segment in MB, + default to 8MB ## Permanent cache system You can now cache all the files you have looked at permanently on your hard diff --git a/src/cache.c b/src/cache.c index 346d82f..afc4254 100644 --- a/src/cache.c +++ b/src/cache.c @@ -18,7 +18,7 @@ * \details We set it to 1024*1024*8 = 8MiB */ -#define DATA_BLK_SZ 8*1024*1024 +#define DEFAULT_DATA_BLK_SZ 8*1024*1024 /** * \brief Maximum segment block count @@ -44,7 +44,9 @@ typedef enum { EMEM = -4, /**< Memory allocation failure */ } MetaError; + int CACHE_SYSTEM_INIT = 0; +int DATA_BLK_SZ = 0; /** * \brief The metadata directory @@ -88,12 +90,17 @@ void CacheSystem_init(const char *path) fprintf(stderr, "CacheSystem_init(): mkdir(): %s\n", strerror(errno)); } + if (mkdir(DATA_DIR, S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH) && (errno != EEXIST)) { fprintf(stderr, "CacheSystem_init(): mkdir(): %s\n", strerror(errno)); } + if (!DATA_BLK_SZ) { + DATA_BLK_SZ = DEFAULT_DATA_BLK_SZ; + } + CACHE_SYSTEM_INIT = 1; } diff --git a/src/cache.h b/src/cache.h index 569a003..5beead0 100644 --- a/src/cache.h +++ b/src/cache.h @@ -49,6 +49,11 @@ typedef struct { */ extern int CACHE_SYSTEM_INIT; +/** + * \brief The size of each download segment + */ +extern int DATA_BLK_SZ; + /** * \brief initialise the cache system directories * \details This function basically sets up the following variables: diff --git a/src/main.c b/src/main.c index d2c7dc2..137804f 100644 --- a/src/main.c +++ b/src/main.c @@ -142,6 +142,7 @@ parse_arg_list(int argc, char **argv, char ***fuse_argv, int *fuse_argc) {"proxy-username", required_argument, NULL, 'L'}, /* 6 */ {"proxy-password", required_argument, NULL, 'L'}, /* 7 */ {"cache", required_argument, NULL, 'L'}, /* 8 */ + {"dl-seg-size", required_argument, NULL, 'L'}, /* 9 */ {0, 0, 0, 0} }; while ((c = @@ -193,6 +194,9 @@ parse_arg_list(int argc, char **argv, char ***fuse_argv, int *fuse_argc) case 8: CacheSystem_init(optarg); break; + case 9: + DATA_BLK_SZ = atoi(optarg) * 1024 * 1024; + break; default: fprintf(stderr, "Error: Invalid option\n"); add_arg(fuse_argv, fuse_argc, "--help"); @@ -246,6 +250,8 @@ static void print_http_options() --proxy-username Username for the proxy\n\ --proxy-password Password for the proxy\n\ --cache Set the cache folder\n\ + --dl-seg-size Set the size of each download segment in MB, \n\ + default to 8MB\n\ \n\ libfuse options:\n"); }