From 20f30a0e387ba7db82ce76264a5e81374eda271a Mon Sep 17 00:00:00 2001 From: Fufu Fang Date: Sun, 1 Sep 2019 08:52:18 +0100 Subject: [PATCH] Tidied up some of the comments and formatting --- Doxyfile | 2 +- README.md | 2 +- src/cache.c | 6 +++--- src/cache.h | 18 +++++++++--------- src/fuse_local.h | 5 +++++ src/link.h | 9 +++++++-- src/network.c | 16 +++++++++------- src/network.h | 7 ++++++- src/util.h | 38 ++++++++++++++++++++++---------------- 9 files changed, 63 insertions(+), 40 deletions(-) diff --git a/Doxyfile b/Doxyfile index 134ea1b..56a01a6 100644 --- a/Doxyfile +++ b/Doxyfile @@ -983,7 +983,7 @@ FILTER_SOURCE_PATTERNS = # (index.html). This can be useful if you have a project on for instance GitHub # and want to reuse the introduction page also for the doxygen output. -USE_MDFILE_AS_MAINPAGE = +USE_MDFILE_AS_MAINPAGE = README.md #--------------------------------------------------------------------------- # Configuration options related to source browsing diff --git a/README.md b/README.md index e9820fc..e87c8bc 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# HTTPDirFS - now with a permanent cache +# HTTPDirFS - HTTP Directory Filesystem, 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. diff --git a/src/cache.c b/src/cache.c index 61ff21a..0c86ae8 100644 --- a/src/cache.c +++ b/src/cache.c @@ -937,22 +937,22 @@ long Cache_read(Cache *cf, char *output_buf, off_t len, off_t offset) } else { #ifdef CACHE_LOCK_DEBUG - /* Wait for the background download thread to finish */ fprintf(stderr, "Cache_read(): thread %lu: locking and unlocking bgt_lock;\n", pthread_self()); #endif + /* Wait for the background download thread to finish */ PTHREAD_MUTEX_LOCK(&cf->bgt_lock); PTHREAD_MUTEX_UNLOCK(&cf->bgt_lock); #ifdef CACHE_LOCK_DEBUG - /* Wait for any other download thread to finish*/ fprintf(stderr, "Cache_read(): thread %lu: locking rw_lock;\n", pthread_self()); #endif + /* Wait for any other download thread to finish*/ PTHREAD_MUTEX_LOCK(&cf->rw_lock); if (Seg_exist(cf, offset)) { - /* The segment already exists - it was downloaded by other + /* The segment now exists - it was downloaded by another * download thread. Send it off and unlock the I/O */ send = Data_read(cf, (uint8_t *) output_buf, len, offset); #ifdef CACHE_LOCK_DEBUG diff --git a/src/cache.h b/src/cache.h index 38c894b..0e8f6a6 100644 --- a/src/cache.h +++ b/src/cache.h @@ -1,6 +1,14 @@ #ifndef CACHE_H #define CACHE_H +/** + * \file cache.h + * \brief cache related structures and functions + * \details + * - We store the metadata and the actual data separately in two + * separate folders. + */ + #include /** @@ -10,14 +18,6 @@ typedef struct Cache Cache; #include "link.h" -/** - * \file cache.h - * \brief cache related structures and functions - * \details - * - We store the metadata and the actual data separately in two - * separate folders. - */ - /** * \brief Type definition for a cache segment */ @@ -100,7 +100,7 @@ void Cache_close(Cache *cf); /** * \brief create a cache file set if it doesn't exist already * \return - * - 0, if the cache file already exists, or was created succesfully. + * - 0, if the cache file already exists, or was created successfully. * - -1, otherwise * \note Called by fs_open() */ diff --git a/src/fuse_local.h b/src/fuse_local.h index 26cb120..9f459c1 100644 --- a/src/fuse_local.h +++ b/src/fuse_local.h @@ -1,6 +1,11 @@ #ifndef FUSE_LOCAL_H #define FUSE_LOCAL_H +/** + * \file fuse_local.h + * \brief FUSE related functions + */ + /* Initialise fuse */ int fuse_local_init(int argc, char **argv); diff --git a/src/link.h b/src/link.h index f8849c0..3d1dc27 100644 --- a/src/link.h +++ b/src/link.h @@ -1,6 +1,11 @@ #ifndef LINK_H #define LINK_H +/** + * \file link.h + * \brief link related structures and functions + */ + #include "util.h" #include @@ -60,12 +65,12 @@ extern int ROOT_LINK_OFFSET; void link_system_init(); /** - * \brief + * \brief Add a link to the curl multi bundle for querying stats */ void Link_get_stat(Link *this_link); /** - * \brief set the stats for a file + * \brief Set the stats of a link, after curl multi handle finished querying */ void Link_set_stat(Link* this_link, CURL *curl); diff --git a/src/network.c b/src/network.c index 90b33da..98fb58b 100644 --- a/src/network.c +++ b/src/network.c @@ -33,8 +33,8 @@ static pthread_mutex_t curl_lock; #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wunused-function" /** - * \note - * Required for OpenSSL 1.02, but not OpenSSL 1.1 + * \brief OpenSSL 1.02 cryptography callback function + * \details Required for OpenSSL 1.02, but not OpenSSL 1.1 */ static void crypto_lock_callback(int mode, int type, char *file, int line) { @@ -48,8 +48,8 @@ static void crypto_lock_callback(int mode, int type, char *file, int line) } /** - * \note - * Required for OpenSSL 1.02, but not OpenSSL 1.1 + * \brief OpenSSL 1.02 thread ID function + * \details Required for OpenSSL 1.02, but not OpenSSL 1.1 */ static unsigned long thread_id(void) { @@ -75,7 +75,8 @@ static void crypto_lock_init(void) } /** - * \note Adapted from: + * \brief Curl share handle callback function + * \details Adapted from: * https://curl.haxx.se/libcurl/c/threaded-shared-conn.html */ static void curl_callback_lock(CURL *handle, curl_lock_data data, @@ -98,7 +99,8 @@ static void curl_callback_unlock(CURL *handle, curl_lock_data data, } /** - * \note Adapted from: + * \brief Process a curl message + * \details Adapted from: * https://curl.haxx.se/libcurl/c/10-at-a-time.html */ static void curl_process_msgs(CURLMsg *curl_msg, int n_running_curl, @@ -155,7 +157,7 @@ static void curl_process_msgs(CURLMsg *curl_msg, int n_running_curl, } /** - * \note effectively based on + * \details effectively based on * https://curl.haxx.se/libcurl/c/multi-double.html */ int curl_multi_perform_once() diff --git a/src/network.h b/src/network.h index 411fde9..8f6876c 100644 --- a/src/network.h +++ b/src/network.h @@ -1,6 +1,11 @@ #ifndef NETWORK_H #define NETWORK_H +/** + * \file network.h + * \brief network related functions + */ + #include "link.h" typedef enum { @@ -8,7 +13,7 @@ typedef enum { HTTP_PARTIAL_CONTENT = 206, HTTP_RANGE_NOT_SATISFIABLE = 416, HTTP_TOO_MANY_REQUESTS = 429 -}HTTPResponseCode; +} HTTPResponseCode; typedef enum { FILESTAT = 's', diff --git a/src/util.h b/src/util.h index 94a392e..89cdb57 100644 --- a/src/util.h +++ b/src/util.h @@ -8,17 +8,18 @@ #include #include -#define PTHREAD_MUTEX_UNLOCK(x)\ -({\ - int i;\ - i = pthread_mutex_unlock(x);\ - if (i) { \ - fprintf(stderr, "pthread_mutex_unlock failed, %d, %s\n", i, \ - strerror(i));\ - exit(EXIT_FAILURE);\ - }\ -}) +/** + * \brief the maximum length of a path and a URL. + * \details This corresponds the maximum path length under Ext4. + */ +#define MAX_PATH_LEN 4096 +/** \brief the maximum length of a filename. */ +#define MAX_FILENAME_LEN 255 + +/** + * \brief wrapper for pthread_mutex_lock() + */ #define PTHREAD_MUTEX_LOCK(x)\ ({\ int i;\ @@ -31,13 +32,18 @@ }) /** - * \brief the maximum length of a path and a URL. - * \details This corresponds the maximum path length under Ext4. + * \brief wrapper for pthread_mutex_unlock() */ -#define MAX_PATH_LEN 4096 - -/** \brief the maximum length of a filename. */ -#define MAX_FILENAME_LEN 255 +#define PTHREAD_MUTEX_UNLOCK(x)\ +({\ + int i;\ + i = pthread_mutex_unlock(x);\ + if (i) { \ + fprintf(stderr, "pthread_mutex_unlock failed, %d, %s\n", i, \ + strerror(i));\ + exit(EXIT_FAILURE);\ + }\ +}) /** * \brief append a path