aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/bindfs.c7
-rw-r--r--src/misc.c27
-rw-r--r--src/misc.h3
-rw-r--r--tests/internals/test_internals.c19
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()) {
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 <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;
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
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);