From 85d6a8c10ec9469c80382fb0b9e9bb0d2ec7c520 Mon Sep 17 00:00:00 2001 From: Martin Pärtel Date: Tue, 17 Nov 2015 10:34:53 +0000 Subject: Show the source dir in the first field on /etc/mtab. Fixes #15. Thanks @tyll! --- src/bindfs.c | 7 +++++++ src/misc.c | 27 +++++++++++++++++++++++++++ src/misc.h | 3 +++ 3 files changed, 37 insertions(+) (limited to 'src') 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()) { diff --git a/src/misc.c b/src/misc.c index 612ec82..e0aba02 100644 --- a/src/misc.c +++ b/src/misc.c @@ -18,6 +18,8 @@ */ #include "misc.h" +#include +#include #include #include #include @@ -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; diff --git a/src/misc.h b/src/misc.h index dc654d6..b059596 100644 --- a/src/misc.h +++ b/src/misc.h @@ -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 -- cgit v1.2.3