diff options
author | Martin Pärtel <martin.partel@gmail.com> | 2015-11-17 10:34:53 +0000 |
---|---|---|
committer | Martin Pärtel <martin.partel@gmail.com> | 2015-11-17 10:34:53 +0000 |
commit | 85d6a8c10ec9469c80382fb0b9e9bb0d2ec7c520 (patch) | |
tree | e3fc2ef99a0beb79a650ea437bbfa4c30e8bcef5 | |
parent | 6b56b050c0e4240389e52f47502acd43d50874c0 (diff) | |
download | bindfs-85d6a8c10ec9469c80382fb0b9e9bb0d2ec7c520.tar.gz |
Show the source dir in the first field on /etc/mtab.
Fixes #15. Thanks @tyll!
-rw-r--r-- | src/bindfs.c | 7 | ||||
-rw-r--r-- | src/misc.c | 27 | ||||
-rw-r--r-- | src/misc.h | 3 | ||||
-rw-r--r-- | tests/internals/test_internals.c | 19 |
4 files changed, 55 insertions, 1 deletions
diff --git a/src/bindfs.c b/src/bindfs.c index 0aa0a51..a40d578 100644 --- a/src/bindfs.c +++ b/src/bindfs.c @@ -1993,6 +1993,13 @@ int main(int argc, char *argv[]) fuse_opt_add_arg(&args, "-ouse_ino"); fuse_opt_add_arg(&args, "-oreaddir_ino"); + /* Show the source dir in the first field on /etc/mtab. */ + { + char *tmp = sprintf_new("-ofsname=%s", settings.mntsrc); + fuse_opt_add_arg(&args, tmp); + free(tmp); + } + /* We need to disable the attribute cache whenever two users can see different attributes. For now, only mirroring can do that. */ if (is_mirroring_enabled()) { @@ -18,6 +18,8 @@ */ #include "misc.h" +#include <stdarg.h> +#include <stdio.h> #include <stdlib.h> #include <string.h> #include <assert.h> @@ -68,6 +70,31 @@ char *strdup_until(const char *s, const char *endchars) } } +char *sprintf_new(const char *format, ...) +{ + va_list ap; + size_t buffer_size = strlen(format) + 32; + char *buffer = malloc(buffer_size); + if (buffer == NULL) { + return NULL; + } + + while (1) { + va_start(ap, format); + size_t len = (size_t)vsnprintf(buffer, buffer_size, format, ap); + va_end(ap); + if (len < buffer_size) { + return buffer; + } + free(buffer); + buffer_size *= 2; + buffer = malloc(buffer_size); + if (buffer == NULL) { + return NULL; + } + } +} + const char *my_basename(const char *path) { const char *p; @@ -31,6 +31,9 @@ int count_substrs(const char *s, const char *sub); an end character is reached. */ char *strdup_until(const char *s, const char *endchars); +/* Like sprintf but writes to an automatically malloc'ed buffer. */ +char *sprintf_new(const char *format, ...); + /* Returns a pointer to the first character after the final slash of path, or path itself if it contains no slashes. If the path ends with a slash, then the result is an empty diff --git a/tests/internals/test_internals.c b/tests/internals/test_internals.c index aba4045..f5dbed5 100644 --- a/tests/internals/test_internals.c +++ b/tests/internals/test_internals.c @@ -52,4 +52,21 @@ void my_dirname_suite() test_my_dirname(buf, ".."); } -TEST_MAIN(my_dirname_suite); +void sprintf_new_suite() { + char *result; + + result = sprintf_new("Hello %d %s", 123, "World"); + TEST_ASSERT(strcmp(result, "Hello 123 World") == 0); + free(result); + + result = sprintf_new("A %s", "loooooooooooooooooooooooooong result"); + TEST_ASSERT(strcmp(result, "A loooooooooooooooooooooooooong result") == 0); + free(result); +} + +void test_internal_suite() { + my_dirname_suite(); + sprintf_new_suite(); +} + +TEST_MAIN(test_internal_suite); |