From 483d9ae51c59d4a45ec2144f2d69ae85b3e31cab Mon Sep 17 00:00:00 2001 From: Bernd Schubert Date: Tue, 1 Jun 2010 20:24:43 +0200 Subject: Also hide fuse meta files. Note: -o hide_meta_dir is now deprecated in favour of -o hide_meta_files Thanks go to Wolf Geldmacher in Ubuntu bug 587917 for reporting this issue. --- man/unionfs-fuse.8 | 6 ++++-- src/opts.c | 10 +++++++--- src/opts.h | 3 ++- src/readdir.c | 19 +++++++++++++------ src/unionfs.c | 1 + src/unionfs.h | 4 ++++ 6 files changed, 31 insertions(+), 12 deletions(-) diff --git a/man/unionfs-fuse.8 b/man/unionfs-fuse.8 index 92d559b..91ae8fc 100644 --- a/man/unionfs-fuse.8 +++ b/man/unionfs-fuse.8 @@ -38,12 +38,14 @@ for an example. \fB\-o cow Enable copy\-on\-write .TP -\fB\-o hide_meta_dir +\fB\-o hide_meta_files In our unionfs root path we have a .unionfs directory that includes metadata, such as hidden (deleted) files. This options make this directory invisible from readdir(), so for example "ls -la /union_root/" will not show it. However, this directory is still there and "cd .unionfs" -or "ls -l .unionfs" still work. This option is especially usufull for +or "ls -l .unionfs" still work. Also, libfuse will create .fuse_hidden* +files, if a file is open, but will be deleted. Those fuse meta files also +will be invisble. This option is especially usufull for package builders. .TP \fB\-d diff --git a/src/opts.c b/src/opts.c index b17d147..cbde708 100644 --- a/src/opts.c +++ b/src/opts.c @@ -232,8 +232,9 @@ static void print_help(const char *progname) { " mountpoint\n" " -d Enable debug output\n" " -o debug_file file to write debug information into\n" - " -o hide_meta_dir \".unionfs\" is a secret directory not\n" - " print by readdir()\n" + " -o hide_meta_files \".unionfs\" is a secret directory not\n" + " visible by readdir(), and so are\n" + " .fuse_hidden* files\n" " -o max_files=number Increase the maximum number of open files\n" " -o relaxed_permissions Disable permissions checks, but only if\n" " running neither as UID=0 or GID=0\n" @@ -319,8 +320,11 @@ int unionfs_opt_proc(void *data, const char *arg, int key, struct fuse_args *out fuse_opt_add_arg(outargs, "-ho"); uopt.doexit = 1; return 0; + case KEY_HIDE_META_FILES: + uopt.hide_meta_files = true; + return 0; case KEY_HIDE_METADIR: - uopt.hide_meta_dir = true; + uopt.hide_meta_files = true; return 0; case KEY_MAX_FILES: set_max_open_files(arg); diff --git a/src/opts.h b/src/opts.h index 0875e48..10c85a0 100644 --- a/src/opts.h +++ b/src/opts.h @@ -28,7 +28,7 @@ typedef struct { char *chroot; // chroot we might go into bool debug; // enable debugging char *dbgpath; // debug file we write debug information into - bool hide_meta_dir; + bool hide_meta_files; bool relaxed_permissions; } uopt_t; @@ -39,6 +39,7 @@ enum { KEY_DEBUG, KEY_DEBUG_FILE, KEY_HELP, + KEY_HIDE_META_FILES, KEY_HIDE_METADIR, KEY_MAX_FILES, KEY_NOINITGROUPS, diff --git a/src/readdir.c b/src/readdir.c index d5c3d01..cc1c072 100644 --- a/src/readdir.c +++ b/src/readdir.c @@ -33,22 +33,29 @@ /** - * Hide our METADIR (.unionfs). As is causes a slight slowndown this is optional + * Hide metadata. As is causes a slight slowndown this is optional + * */ -static bool hide_meta_dir(int branch, const char *path, struct dirent *de) +static bool hide_meta_files(int branch, const char *path, struct dirent *de) { - if (uopt.hide_meta_dir == false) return false; + if (uopt.hide_meta_files == false) return false; fprintf(stderr, "uopt.branches[branch].path = %s path = %s\n", uopt.branches[branch].path, path); fprintf(stderr, "METANAME = %s, de->d_name = %s\n", METANAME, de->d_name); - // TODO Would it be faster to add hash comparison here? + // TODO Would it be faster to add hash comparison? + + // HIDE out .unionfs directory if (strcmp(uopt.branches[branch].path, path) == 0 && strcmp(METANAME, de->d_name) == 0) { return true; } + // HIDE fuse META files + if (strncmp(FUSE_META_FILE, de->d_name, FUSE_META_LENGTH) == 0) + return true; + return false; } @@ -154,7 +161,7 @@ int unionfs_readdir(const char *path, void *buf, fuse_fill_dir_t filler, off_t o if (hashtable_search(whiteouts, de->d_name) != NULL) continue; } - if (hide_meta_dir(i, p, de) == true) continue; + if (hide_meta_files(i, p, de) == true) continue; // fill with something dummy, we're interested in key existence only hashtable_insert(files, strdup(de->d_name), malloc(1)); @@ -241,7 +248,7 @@ int dir_not_empty(const char *path) { if (hashtable_search(whiteouts, de->d_name) != NULL) continue; } - if (hide_meta_dir(i, p, de) == true) continue; + if (hide_meta_files(i, p, de) == true) continue; // When we arrive here, a valid entry was found not_empty = 1; diff --git a/src/unionfs.c b/src/unionfs.c index 55eda85..cd58a83 100644 --- a/src/unionfs.c +++ b/src/unionfs.c @@ -58,6 +58,7 @@ static struct fuse_opt unionfs_opts[] = { FUSE_OPT_KEY("--help", KEY_HELP), FUSE_OPT_KEY("-h", KEY_HELP), FUSE_OPT_KEY("hide_meta_dir", KEY_HIDE_METADIR), + FUSE_OPT_KEY("hide_meta_files", KEY_HIDE_META_FILES), FUSE_OPT_KEY("max_files=%s", KEY_MAX_FILES), FUSE_OPT_KEY("noinitgroups", KEY_NOINITGROUPS), FUSE_OPT_KEY("relaxed_permissions", KEY_RELAXED_PERMISSIONS), diff --git a/src/unionfs.h b/src/unionfs.h index 592a725..74b824f 100644 --- a/src/unionfs.h +++ b/src/unionfs.h @@ -13,6 +13,10 @@ #define METANAME ".unionfs" #define METADIR (METANAME "/") // string concetanation! +// fuse meta files, we might want to hide those +#define FUSE_META_FILE ".fuse_hidden" +#define FUSE_META_LENGTH 12 + // file access protection mask #define S_PROT_MASK (S_ISUID| S_ISGID | S_ISVTX | S_IRWXU | S_IRWXG | S_IRWXO) -- cgit v1.2.1