From a5344ec6d2fde0299ffaf71310fd02d6f7164980 Mon Sep 17 00:00:00 2001 From: Bernd Schubert Date: Wed, 16 Jun 2010 03:21:44 +0200 Subject: Further debugging: print return codes --- src/cow.c | 46 ++++++------- src/cow_utils.c | 32 ++++----- src/debug.c | 4 +- src/debug.h | 7 ++ src/findbranch.c | 38 +++++----- src/general.c | 50 +++++++------- src/readdir.c | 18 ++--- src/string.c | 6 +- src/unionfs.c | 206 +++++++++++++++++++++++++++---------------------------- src/unlink.c | 16 ++--- 10 files changed, 215 insertions(+), 208 deletions(-) diff --git a/src/cow.c b/src/cow.c index 2d8af6d..cfc692f 100644 --- a/src/cow.c +++ b/src/cow.c @@ -37,7 +37,7 @@ static int do_create(const char *path, int nbranch_ro, int nbranch_rw) { struct stat buf; int res = stat(dirp, &buf); - if (res != -1) return 0; // already exists + if (res != -1) RETURN(0); // already exists if (nbranch_ro == nbranch_rw) { // special case nbranch_ro = nbranch_rw, this is if we a create @@ -48,22 +48,22 @@ static int do_create(const char *path, int nbranch_ro, int nbranch_rw) { char o_dirp[PATHLEN_MAX]; // the pathname we want to copy sprintf(o_dirp, "%s%s", uopt.branches[nbranch_ro].path, path); res = stat(o_dirp, &buf); - if (res == -1) return 1; // lower level branch removed in the mean time? + if (res == -1) RETURN(1); // lower level branch removed in the mean time? } res = mkdir(dirp, buf.st_mode); if (res == -1) { usyslog(LOG_DAEMON, "Creating %s failed: \n", dirp); - return 1; + RETURN(1); } - if (nbranch_ro == nbranch_rw) return 0; // the special case again + if (nbranch_ro == nbranch_rw) RETURN(0); // the special case again - if (setfile(dirp, &buf)) return 1; // directory already removed by another process? + if (setfile(dirp, &buf)) RETURN(1); // directory already removed by another process? // TODO: time, but its values are modified by the next dir/file creation steps? - return 0; + RETURN(0); } /** @@ -73,15 +73,15 @@ static int do_create(const char *path, int nbranch_ro, int nbranch_rw) { int path_create(const char *path, int nbranch_ro, int nbranch_rw) { DBG("%s\n", path); - if (!uopt.cow_enabled) return 0; + if (!uopt.cow_enabled) RETURN(0); char p[PATHLEN_MAX]; - if (BUILD_PATH(p, uopt.branches[nbranch_rw].path, path)) return -ENAMETOOLONG; + if (BUILD_PATH(p, uopt.branches[nbranch_rw].path, path)) RETURN(-ENAMETOOLONG); struct stat st; if (!stat(p, &st)) { // path does already exists, no need to create it - return 0; + RETURN(0); } char *walk = (char *)path; @@ -96,13 +96,13 @@ int path_create(const char *path, int nbranch_ro, int nbranch_rw) { // +1 due to \0, which gets added automatically snprintf(p, (walk - path) + 1, "%s", path); // walk - path = strlen(/dir1) int res = do_create(p, nbranch_ro, nbranch_rw); - if (res) return res; // creating the directory failed + if (res) RETURN(res); // creating the directory failed // as above the do loop, walk over the next slashes, walk = dir2/ while (*walk != '\0' && *walk == '/') walk++; } while (*walk != '\0'); - return 0; + RETURN(0); } /** @@ -114,11 +114,11 @@ int path_create_cutlast(const char *path, int nbranch_ro, int nbranch_rw) { char *dname = u_dirname(path); if (dname == NULL) - return -ENOMEM; + RETURN(-ENOMEM); int ret = path_create(dname, nbranch_ro, nbranch_rw); free(dname); - return ret; + RETURN(ret); } /** @@ -132,9 +132,9 @@ int cow_cp(const char *path, int branch_ro, int branch_rw) { char from[PATHLEN_MAX], to[PATHLEN_MAX]; if (BUILD_PATH(from, uopt.branches[branch_ro].path, path)) - return -ENAMETOOLONG; + RETURN(-ENAMETOOLONG); if (BUILD_PATH(to, uopt.branches[branch_rw].path, path)) - return -ENAMETOOLONG; + RETURN(-ENAMETOOLONG); setlocale(LC_ALL, ""); @@ -170,12 +170,12 @@ int cow_cp(const char *path, int branch_ro, int branch_rw) { break; case S_IFSOCK: usyslog(LOG_WARNING, "COW of sockets not supported: %s\n", cow.from_path); - return 1; + RETURN(1); default: res = copy_file(&cow); } - return res; + RETURN(res); } /** @@ -187,27 +187,27 @@ int copy_directory(const char *path, int branch_ro, int branch_rw) { /* create the directory on the destination branch */ int res = path_create(path, branch_ro, branch_rw); if (res != 0) { - return res; + RETURN(res); } /* determine path to source directory on read-only branch */ char from[PATHLEN_MAX]; - if (BUILD_PATH(from, uopt.branches[branch_ro].path, path)) return 1; + if (BUILD_PATH(from, uopt.branches[branch_ro].path, path)) RETURN(1); DIR *dp = opendir(from); - if (dp == NULL) return 1; + if (dp == NULL) RETURN(1); struct dirent *de; while ((de = readdir(dp)) != NULL) { if (strcmp(de->d_name, ".") == 0 || strcmp(de->d_name, "..") == 0) continue; char member[PATHLEN_MAX]; - if (BUILD_PATH(member, path, de->d_name)) return 1; + if (BUILD_PATH(member, path, de->d_name)) RETURN(1); res = cow_cp(member, branch_ro, branch_rw); - if (res != 0) return res; + if (res != 0) RETURN(res); } closedir(dp); - return 0; + RETURN(0); } diff --git a/src/cow_utils.c b/src/cow_utils.c index b798a61..a79945b 100644 --- a/src/cow_utils.c +++ b/src/cow_utils.c @@ -104,10 +104,10 @@ int setfile(const char *path, struct stat *fs) usyslog(LOG_WARNING, "chflags: %s", path); rval = 1; } - return (rval); + RETURN((rval)); } #endif - return 0; + RETURN(0); } /** @@ -120,10 +120,10 @@ static int setlink(const char *path, struct stat *fs) if (lchown(path, fs->st_uid, fs->st_gid)) { if (errno != EPERM) { usyslog(LOG_WARNING, "lchown: %s", path); - return (1); + RETURN((1)); } } - return (0); + RETURN((0)); } @@ -144,7 +144,7 @@ int copy_file(struct cow *cow) if ((from_fd = open(cow->from_path, O_RDONLY, 0)) == -1) { usyslog(LOG_WARNING, "%s", cow->from_path); - return (1); + RETURN((1)); } fs = cow->stat; @@ -155,7 +155,7 @@ int copy_file(struct cow *cow) if (to_fd == -1) { usyslog(LOG_WARNING, "%s", cow->to_path); (void)close(from_fd); - return (1); + RETURN((1)); } /* @@ -194,14 +194,14 @@ int copy_file(struct cow *cow) } if (rcount < 0) { usyslog(LOG_WARNING, "copy failed: %s", cow->from_path); - return 1; + RETURN(1); } } if (rval == 1) { (void)close(from_fd); (void)close(to_fd); - return (1); + RETURN((1)); } if (setfile(cow->to_path, cow->stat)) @@ -228,7 +228,7 @@ int copy_file(struct cow *cow) rval = 1; } - return (rval); + RETURN((rval)); } /** @@ -243,17 +243,17 @@ int copy_link(struct cow *cow) if ((len = readlink(cow->from_path, link, sizeof(link)-1)) == -1) { usyslog(LOG_WARNING, "readlink: %s", cow->from_path); - return (1); + RETURN((1)); } link[len] = '\0'; if (symlink(link, cow->to_path)) { usyslog(LOG_WARNING, "symlink: %s", link); - return (1); + RETURN((1)); } - return setlink(cow->to_path, cow->stat); + RETURN(setlink(cow->to_path, cow->stat)); } /** @@ -266,9 +266,9 @@ int copy_fifo(struct cow *cow) if (mkfifo(cow->to_path, cow->stat->st_mode)) { usyslog(LOG_WARNING, "mkfifo: %s", cow->to_path); - return (1); + RETURN((1)); } - return setfile(cow->to_path, cow->stat); + RETURN(setfile(cow->to_path, cow->stat)); } /** @@ -281,7 +281,7 @@ int copy_special(struct cow *cow) if (mknod(cow->to_path, cow->stat->st_mode, cow->stat->st_rdev)) { usyslog(LOG_WARNING, "mknod: %s", cow->to_path); - return (1); + RETURN((1)); } - return setfile(cow->to_path, cow->stat); + RETURN(setfile(cow->to_path, cow->stat)); } diff --git a/src/debug.c b/src/debug.c index afa28e0..632ff1f 100644 --- a/src/debug.c +++ b/src/debug.c @@ -25,7 +25,7 @@ int debug_init(void) { if (!dbgfile) { printf("Failed to open %s for writing: %s.\nAborting!\n", dbgpath, strerror(errno)); - return 2; + RETURN(2); } - return 0; + RETURN(0); } diff --git a/src/debug.h b/src/debug.h index c72fbee..103d47b 100644 --- a/src/debug.h +++ b/src/debug.h @@ -38,6 +38,13 @@ extern FILE* dbgfile; #define usyslog(priority, format, ...) DBG(format, ##__VA_ARGS__) +#define RETURN(returncode) \ + do { \ + if (uopt.debug) DBG("return %d\n", returncode); \ + return returncode; \ + } while (0) + + /* In order to prevent useless function calls and to make the compiler * to optimize those out, debug.c will only have definitions if DEBUG * is defined. So if DEBUG is NOT defined, we define empty functions here */ diff --git a/src/findbranch.c b/src/findbranch.c index 5111c71..7e9e0ff 100644 --- a/src/findbranch.c +++ b/src/findbranch.c @@ -59,7 +59,7 @@ static int find_branch(const char *path, searchflag_t flag) { int i = 0; for (i = 0; i < uopt.nbranches; i++) { char p[PATHLEN_MAX]; - if (BUILD_PATH(p, uopt.branches[i].path, path)) return -ENAMETOOLONG; + if (BUILD_PATH(p, uopt.branches[i].path, path)) RETURN(-ENAMETOOLONG); struct stat stbuf; int res = lstat(p, &stbuf); @@ -70,10 +70,10 @@ static int find_branch(const char *path, searchflag_t flag) { switch (flag) { case RWRO: // any path we found is fine - return i; + RETURN(i); case RWONLY: // we need a rw-branch - if (uopt.branches[i].rw) return i; + if (uopt.branches[i].rw) RETURN(i); break; default: usyslog(LOG_ERR, "%s: Unknown flag %d\n", __func__, flag); @@ -85,15 +85,15 @@ static int find_branch(const char *path, searchflag_t flag) { if (res > 0) { // So no path, but whiteout found. No need to search in further branches errno = ENOENT; - return -1; + RETURN(-1); } else if (res < 0) { errno = res; // error - return -1; + RETURN(-1); } } errno = ENOENT; - return -1; + RETURN(-1); } /** @@ -101,7 +101,7 @@ static int find_branch(const char *path, searchflag_t flag) { */ int find_rorw_branch(const char *path) { DBG("%s\n", path); - return find_branch(path, RWRO); + RETURN(find_branch(path, RWRO)); } /** @@ -114,7 +114,7 @@ int __find_rw_branch_cutlast(const char *path, int rw_hint) { int branch = find_rw_branch_cow(path); DBG("branch = %d\n", branch); - if (branch >= 0 || (branch < 0 && errno != ENOENT)) return branch; + if (branch >= 0 || (branch < 0 && errno != ENOENT)) RETURN(branch); DBG("Check for parent directory\n"); @@ -124,7 +124,7 @@ int __find_rw_branch_cutlast(const char *path, int rw_hint) { char *dname = u_dirname(path); if (dname == NULL) { errno = ENOMEM; - return -1; + RETURN(-1); } branch = find_rorw_branch(dname); @@ -165,7 +165,7 @@ int __find_rw_branch_cutlast(const char *path, int rw_hint) { out: free(dname); - return branch; + RETURN(branch); } /** @@ -173,7 +173,7 @@ out: */ int find_rw_branch_cutlast(const char *path) { int rw_hint = -1; // autodetect rw_branch - return __find_rw_branch_cutlast(path, rw_hint); + RETURN(__find_rw_branch_cutlast(path, rw_hint)); } /** @@ -190,30 +190,30 @@ int find_rw_branch_cow(const char *path) { int branch_rorw = find_rorw_branch(path); // not found anywhere - if (branch_rorw < 0) return -1; + if (branch_rorw < 0) RETURN(-1); // the found branch is writable, good! - if (uopt.branches[branch_rorw].rw) return branch_rorw; + if (uopt.branches[branch_rorw].rw) RETURN(branch_rorw); // cow is disabled and branch is not writable, so deny write permission if (!uopt.cow_enabled) { errno = EACCES; - return -1; + RETURN(-1); } int branch_rw = find_lowest_rw_branch(branch_rorw); if (branch_rw < 0) { // no writable branch found errno = EACCES; - return -1; + RETURN(-1); } - if (cow_cp(path, branch_rorw, branch_rw)) return -1; + if (cow_cp(path, branch_rorw, branch_rw)) RETURN(-1); // remove a file that might hide the copied file remove_hidden(path, branch_rw); - return branch_rw; + RETURN(branch_rw); } /** @@ -224,8 +224,8 @@ int find_lowest_rw_branch(int branch_ro) { int i = 0; for (i = 0; i < branch_ro; i++) { - if (uopt.branches[i].rw) return i; // found it it. + if (uopt.branches[i].rw) RETURN(i); // found it it. } - return -1; + RETURN(-1); } diff --git a/src/general.c b/src/general.c index 5a7ce89..e0bb374 100644 --- a/src/general.c +++ b/src/general.c @@ -37,18 +37,18 @@ */ static int filedir_hidden(const char *path) { // cow mode disabled, no need for hidden files - if (!uopt.cow_enabled) return false; + if (!uopt.cow_enabled) RETURN(false); char p[PATHLEN_MAX]; - if (strlen(path) + strlen(HIDETAG) > PATHLEN_MAX) return -ENAMETOOLONG; + if (strlen(path) + strlen(HIDETAG) > PATHLEN_MAX) RETURN(-ENAMETOOLONG); snprintf(p, PATHLEN_MAX, "%s%s", path, HIDETAG); DBG("%s\n", p); struct stat stbuf; int res = lstat(p, &stbuf); - if (res == 0) return true; + if (res == 0) RETURN(true); - return 0; + RETURN(0); } /** @@ -57,10 +57,10 @@ static int filedir_hidden(const char *path) { int path_hidden(const char *path, int branch) { DBG("%s\n", path); - if (!uopt.cow_enabled) return false; + if (!uopt.cow_enabled) RETURN(false); char whiteoutpath[PATHLEN_MAX]; - if (BUILD_PATH(whiteoutpath, uopt.branches[branch].path, METADIR, path)) return false; + if (BUILD_PATH(whiteoutpath, uopt.branches[branch].path, METADIR, path)) RETURN(false); // -1 as we MUST not end on the next path element char *walk = whiteoutpath + uopt.branches[branch].path_len + strlen(METADIR) - 1; @@ -77,13 +77,13 @@ int path_hidden(const char *path, int branch) { // walk - path = strlen(/dir1) snprintf(p, (walk - whiteoutpath) + 1, "%s", whiteoutpath); int res = filedir_hidden(p); - if (res) return res; // path is hidden or error + if (res) RETURN(res); // path is hidden or error // as above the do loop, walk over the next slashes, walk = dir2/ while (*walk != '\0' && *walk == '/') walk++; } while (*walk != '\0'); - return 0; + RETURN(0); } /** @@ -93,15 +93,15 @@ int path_hidden(const char *path, int branch) { int remove_hidden(const char *path, int maxbranch) { DBG("%s\n", path); - if (!uopt.cow_enabled) return 0; + if (!uopt.cow_enabled) RETURN(0); if (maxbranch == -1) maxbranch = uopt.nbranches; int i; for (i = 0; i <= maxbranch; i++) { char p[PATHLEN_MAX]; - if (BUILD_PATH(p, uopt.branches[i].path, METADIR, path)) return -ENAMETOOLONG; - if (strlen(p) + strlen(HIDETAG) > PATHLEN_MAX) return -ENAMETOOLONG; + if (BUILD_PATH(p, uopt.branches[i].path, METADIR, path)) RETURN(-ENAMETOOLONG); + if (strlen(p) + strlen(HIDETAG) > PATHLEN_MAX) RETURN(-ENAMETOOLONG); strcat(p, HIDETAG); // TODO check length switch (path_is_dir(p)) { @@ -111,7 +111,7 @@ int remove_hidden(const char *path, int maxbranch) { } } - return 0; + RETURN(0); } /** @@ -124,11 +124,11 @@ filetype_t path_is_dir(const char *path) { struct stat buf; - if (lstat(path, &buf) == -1) return NOT_EXISTING; + if (lstat(path, &buf) == -1) RETURN(NOT_EXISTING); - if (S_ISDIR(buf.st_mode)) return IS_DIR; + if (S_ISDIR(buf.st_mode)) RETURN(IS_DIR); - return IS_FILE; + RETURN(IS_FILE); } /** @@ -139,26 +139,26 @@ static int do_create_whiteout(const char *path, int branch_rw, enum whiteout mod char metapath[PATHLEN_MAX]; - if (BUILD_PATH(metapath, METADIR, path)) return -1; + if (BUILD_PATH(metapath, METADIR, path)) RETURN(-1); // p MUST be without path to branch prefix here! 2 x branch_rw is correct here! // this creates e.g. branch/.unionfs/some_directory path_create_cutlast(metapath, branch_rw, branch_rw); char p[PATHLEN_MAX]; - if (BUILD_PATH(p, uopt.branches[branch_rw].path, metapath)) return -1; + if (BUILD_PATH(p, uopt.branches[branch_rw].path, metapath)) RETURN(-1); strcat(p, HIDETAG); // TODO check length int res; if (mode == WHITEOUT_FILE) { res = open(p, O_WRONLY | O_CREAT, S_IRUSR | S_IWUSR); - if (res == -1) return -1; + if (res == -1) RETURN(-1); res = close(res); } else { res = mkdir(p, S_IRWXU); } - return res; + RETURN(res); } /** @@ -166,7 +166,7 @@ static int do_create_whiteout(const char *path, int branch_rw, enum whiteout mod */ int hide_file(const char *path, int branch_rw) { DBG("%s\n", path); - return do_create_whiteout(path, branch_rw, WHITEOUT_FILE); + RETURN(do_create_whiteout(path, branch_rw, WHITEOUT_FILE)); } /** @@ -174,7 +174,7 @@ int hide_file(const char *path, int branch_rw) { */ int hide_dir(const char *path, int branch_rw) { DBG("%s\n", path); - return do_create_whiteout(path, branch_rw, WHITEOUT_DIR); + RETURN(do_create_whiteout(path, branch_rw, WHITEOUT_DIR)); } /** @@ -186,10 +186,10 @@ int maybe_whiteout(const char *path, int branch_rw, enum whiteout mode) { // we are not interested in the branch itself, only if it exists at all if (find_rorw_branch(path) != -1) { - return do_create_whiteout(path, branch_rw, mode); + RETURN(do_create_whiteout(path, branch_rw, mode)); } - return 0; + RETURN(0); } /** @@ -203,8 +203,8 @@ int set_owner(const char *path) { usyslog(LOG_WARNING, ":%s: Setting the correct file owner failed: %s !\n", __func__, strerror(errno)); - return -errno; + RETURN(-errno); } } - return 0; + RETURN(0); } diff --git a/src/readdir.c b/src/readdir.c index c01ed5e..6961c67 100644 --- a/src/readdir.c +++ b/src/readdir.c @@ -39,7 +39,7 @@ static bool hide_meta_files(int branch, const char *path, struct dirent *de) { - if (uopt.hide_meta_files == 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); @@ -49,14 +49,14 @@ static bool hide_meta_files(int branch, const char *path, struct dirent *de) // HIDE out .unionfs directory if (strcmp(uopt.branches[branch].path, path) == 0 && strcmp(METANAME, de->d_name) == 0) { - return true; + RETURN(true); } // HIDE fuse META files if (strncmp(FUSE_META_FILE, de->d_name, FUSE_META_LENGTH) == 0) - return true; + RETURN(true); - return false; + RETURN(false); } /** @@ -80,10 +80,10 @@ static bool is_hiding(struct hashtable *hides, char *fname) { hashtable_insert(hides, strdup(fname), malloc(1)); } - return true; + RETURN(true); } - return false; + RETURN(false); } /** @@ -187,7 +187,7 @@ out: filler(buf, "stats", NULL, 0); } - return rc; + RETURN(rc); } /** @@ -263,9 +263,9 @@ int dir_not_empty(const char *path) { out: if (uopt.cow_enabled) hashtable_destroy(whiteouts, 1); - if (rc) return rc; + if (rc) RETURN(rc); - return not_empty; + RETURN(not_empty); } diff --git a/src/string.c b/src/string.c index b36058d..36d3e54 100644 --- a/src/string.c +++ b/src/string.c @@ -115,7 +115,7 @@ int build_path(char *path, int max_len, const char *callfunc, int line, ...) { if (len + 1 > max_len) { usyslog (LOG_WARNING, "%s():%d Path too long \n", callfunc, line); errno = ENAMETOOLONG; - return -errno; + RETURN(-errno); } strcat (path, str); @@ -124,11 +124,11 @@ int build_path(char *path, int max_len, const char *callfunc, int line, ...) { if (len == 0) { usyslog(LOG_ERR, "from: %s():%d : No argument given?\n", callfunc, line); errno = EIO; - return -errno; + RETURN(-errno); } DBG("from: %s():%d path: %s\n", callfunc, line, str_ptr); - return 0; + RETURN(0); } /** diff --git a/src/unionfs.c b/src/unionfs.c index e3ed9b8..fd4556c 100644 --- a/src/unionfs.c +++ b/src/unionfs.c @@ -75,30 +75,30 @@ static int unionfs_chmod(const char *path, mode_t mode) { DBG("%s\n", path); int i = find_rw_branch_cow(path); - if (i == -1) return -errno; + if (i == -1) RETURN(-errno); char p[PATHLEN_MAX]; - if (BUILD_PATH(p, uopt.branches[i].path, path)) return -ENAMETOOLONG; + if (BUILD_PATH(p, uopt.branches[i].path, path)) RETURN(-ENAMETOOLONG); int res = chmod(p, mode); - if (res == -1) return -errno; + if (res == -1) RETURN(-errno); - return 0; + RETURN(0); } static int unionfs_chown(const char *path, uid_t uid, gid_t gid) { DBG("%s\n", path); int i = find_rw_branch_cow(path); - if (i == -1) return -errno; + if (i == -1) RETURN(-errno); char p[PATHLEN_MAX]; - if (BUILD_PATH(p, uopt.branches[i].path, path)) return -ENAMETOOLONG; + if (BUILD_PATH(p, uopt.branches[i].path, path)) RETURN(-ENAMETOOLONG); int res = lchown(p, uid, gid); - if (res == -1) return -errno; + if (res == -1) RETURN(-errno); - return 0; + RETURN(0); } /** @@ -109,17 +109,17 @@ static int unionfs_create(const char *path, mode_t mode, struct fuse_file_info * DBG("%s\n", path); int i = find_rw_branch_cutlast(path); - if (i == -1) return -errno; + if (i == -1) RETURN(-errno); char p[PATHLEN_MAX]; - if (BUILD_PATH(p, uopt.branches[i].path, path)) return -ENAMETOOLONG; + if (BUILD_PATH(p, uopt.branches[i].path, path)) RETURN(-ENAMETOOLONG); // NOTE: We should do: // Create the file with mode=0 first, otherwise we might create // a file as root + x-bit + suid bit set, which might be used for // security racing! int res = open(p, fi->flags, 0); - if (res == -1) return -errno; + if (res == -1) RETURN(-errno); set_owner(p); // no error check, since creating the file succeeded @@ -130,7 +130,7 @@ static int unionfs_create(const char *path, mode_t mode, struct fuse_file_info * remove_hidden(path, i); DBG("fd = %" PRIx64 "\n", fi->fh); - return 0; + RETURN(0); } @@ -142,21 +142,21 @@ static int unionfs_create(const char *path, mode_t mode, struct fuse_file_info * static int unionfs_flush(const char *path, struct fuse_file_info *fi) { DBG("%"PRIx64"\n", fi->fh); - if (uopt.stats_enabled && strcmp(path, STATS_FILENAME) == 0) return 0; + if (uopt.stats_enabled && strcmp(path, STATS_FILENAME) == 0) RETURN(0); int fd = dup(fi->fh); if (fd == -1) { // What to do now? - if (fsync(fi->fh) == -1) return -EIO; + if (fsync(fi->fh) == -1) RETURN(-EIO); - return -errno; + RETURN(-errno); } int res = close(fd); - if (res == -1) return -errno; + if (res == -1) RETURN(-errno); - return 0; + RETURN(0); } /** @@ -165,7 +165,7 @@ static int unionfs_flush(const char *path, struct fuse_file_info *fi) { static int unionfs_fsync(const char *path, int isdatasync, struct fuse_file_info *fi) { DBG("%"PRIx64"\n", fi->fh); - if (uopt.stats_enabled && strcmp(path, STATS_FILENAME) == 0) return 0; + if (uopt.stats_enabled && strcmp(path, STATS_FILENAME) == 0) RETURN(0); int res; if (isdatasync) { @@ -178,9 +178,9 @@ static int unionfs_fsync(const char *path, int isdatasync, struct fuse_file_info res = fsync(fi->fh); } - if (res == -1) return -errno; + if (res == -1) RETURN(-errno); - return 0; + RETURN(0); } static int unionfs_getattr(const char *path, struct stat *stbuf) { @@ -191,17 +191,17 @@ static int unionfs_getattr(const char *path, struct stat *stbuf) { stbuf->st_mode = S_IFREG | 0444; stbuf->st_nlink = 1; stbuf->st_size = STATS_SIZE; - return 0; + RETURN(0); } int i = find_rorw_branch(path); - if (i == -1) return -errno; + if (i == -1) RETURN(-errno); char p[PATHLEN_MAX]; - if (BUILD_PATH(p, uopt.branches[i].path, path)) return -ENAMETOOLONG; + if (BUILD_PATH(p, uopt.branches[i].path, path)) RETURN(-ENAMETOOLONG); int res = lstat(p, stbuf); - if (res == -1) return -errno; + if (res == -1) RETURN(-errno); /* This is a workaround for broken gnu find implementations. Actually, * n_links is not defined at all for directories by posix. However, it @@ -212,7 +212,7 @@ static int unionfs_getattr(const char *path, struct stat *stbuf) { */ if (S_ISDIR(stbuf->st_mode)) stbuf->st_nlink = 1; - return 0; + RETURN(0); } /** @@ -241,24 +241,24 @@ static int unionfs_link(const char *from, const char *to) { // hardlinks do not work across different filesystems so we need a copy of from first int i = find_rw_branch_cow(from); - if (i == -1) return -errno; + if (i == -1) RETURN(-errno); int j = __find_rw_branch_cutlast(to, i); - if (j == -1) return -errno; + if (j == -1) RETURN(-errno); DBG("from branch: %d to branch: %d\n", i, j); char f[PATHLEN_MAX], t[PATHLEN_MAX]; - if (BUILD_PATH(f, uopt.branches[i].path, from)) return -ENAMETOOLONG; - if (BUILD_PATH(t, uopt.branches[j].path, to)) return -ENAMETOOLONG; + if (BUILD_PATH(f, uopt.branches[i].path, from)) RETURN(-ENAMETOOLONG); + if (BUILD_PATH(t, uopt.branches[j].path, to)) RETURN(-ENAMETOOLONG); int res = link(f, t); - if (res == -1) return -errno; + if (res == -1) RETURN(-errno); // no need for set_owner(), since owner and permissions are copied over by link() remove_hidden(to, i); // remove hide file (if any) - return 0; + RETURN(0); } /** @@ -271,29 +271,29 @@ static int unionfs_mkdir(const char *path, mode_t mode) { DBG("%s\n", path); int i = find_rw_branch_cutlast(path); - if (i == -1) return -errno; + if (i == -1) RETURN(-errno); char p[PATHLEN_MAX]; - if (BUILD_PATH(p, uopt.branches[i].path, path)) return -ENAMETOOLONG; + if (BUILD_PATH(p, uopt.branches[i].path, path)) RETURN(-ENAMETOOLONG); int res = mkdir(p, 0); - if (res == -1) return -errno; + if (res == -1) RETURN(-errno); set_owner(p); // no error check, since creating the file succeeded // NOW, that the file has the proper owner we may set the requested mode chmod(p, mode); - return 0; + RETURN(0); } static int unionfs_mknod(const char *path, mode_t mode, dev_t rdev) { DBG("%s\n", path); int i = find_rw_branch_cutlast(path); - if (i == -1) return -errno; + if (i == -1) RETURN(-errno); char p[PATHLEN_MAX]; - if (BUILD_PATH(p, uopt.branches[i].path, path)) return -ENAMETOOLONG; + if (BUILD_PATH(p, uopt.branches[i].path, path)) RETURN(-ENAMETOOLONG); int file_type = mode & S_IFMT; int file_perm = mode & (S_PROT_MASK); @@ -313,7 +313,7 @@ static int unionfs_mknod(const char *path, mode_t mode, dev_t rdev) { res = mknod(p, file_type, rdev); } - if (res == -1) return -errno; + if (res == -1) RETURN(-errno); set_owner(p); // no error check, since creating the file succeeded // NOW, that the file has the proper owner we may set the requested mode @@ -321,7 +321,7 @@ static int unionfs_mknod(const char *path, mode_t mode, dev_t rdev) { remove_hidden(path, i); - return 0; + RETURN(0); } static int unionfs_open(const char *path, struct fuse_file_info *fi) { @@ -331,9 +331,9 @@ static int unionfs_open(const char *path, struct fuse_file_info *fi) { if ((fi->flags & 3) == O_RDONLY) { // This makes exec() fail //fi->direct_io = 1; - return 0; + RETURN(0); } - return -EACCES; + RETURN(-EACCES); } int i; @@ -343,13 +343,13 @@ static int unionfs_open(const char *path, struct fuse_file_info *fi) { i = find_rorw_branch(path); } - if (i == -1) return -errno; + if (i == -1) RETURN(-errno); char p[PATHLEN_MAX]; - if (BUILD_PATH(p, uopt.branches[i].path, path)) return -ENAMETOOLONG; + if (BUILD_PATH(p, uopt.branches[i].path, path)) RETURN(-ENAMETOOLONG); int fd = open(p, fi->flags); - if (fd == -1) return -errno; + if (fd == -1) RETURN(-errno); if (fi->flags & (O_WRONLY | O_RDWR)) { // There might have been a hide file, but since we successfully @@ -362,7 +362,7 @@ static int unionfs_open(const char *path, struct fuse_file_info *fi) { fi->fh = (unsigned long)fd; DBG("fd = %"PRIx64"\n", fi->fh); - return 0; + RETURN(0); } static int unionfs_read(const char *path, char *buf, size_t size, off_t offset, struct fuse_file_info *fi) { @@ -385,40 +385,40 @@ static int unionfs_read(const char *path, char *buf, size_t size, off_t offset, int res = pread(fi->fh, buf, size, offset); - if (res == -1) return -errno; + if (res == -1) RETURN(-errno); if (uopt.stats_enabled) stats_add_read(&stats, size); - return res; + RETURN(res); } static int unionfs_readlink(const char *path, char *buf, size_t size) { DBG("%s\n", path); int i = find_rorw_branch(path); - if (i == -1) return -errno; + if (i == -1) RETURN(-errno); char p[PATHLEN_MAX]; - if (BUILD_PATH(p, uopt.branches[i].path, path)) return -ENAMETOOLONG; + if (BUILD_PATH(p, uopt.branches[i].path, path)) RETURN(-ENAMETOOLONG); int res = readlink(p, buf, size - 1); - if (res == -1) return -errno; + if (res == -1) RETURN(-errno); buf[res] = '\0'; - return 0; + RETURN(0); } static int unionfs_release(const char *path, struct fuse_file_info *fi) { DBG("%s\n", path); - if (uopt.stats_enabled && strcmp(path, STATS_FILENAME) == 0) return 0; + if (uopt.stats_enabled && strcmp(path, STATS_FILENAME) == 0) RETURN(0); int res = close(fi->fh); - if (res == -1) return -errno; + if (res == -1) RETURN(-errno); - return 0; + RETURN(0); } /** @@ -432,29 +432,29 @@ static int unionfs_rename(const char *from, const char *to) { bool is_dir = false; // is 'from' a file or directory int j = find_rw_branch_cutlast(to); - if (j == -1) return -errno; + if (j == -1) RETURN(-errno); int i = find_rorw_branch(from); - if (i == -1) return -errno; + if (i == -1) RETURN(-errno); if (!uopt.branches[i].rw) { i = find_rw_branch_cow(from); - if (i == -1) return -errno; + if (i == -1) RETURN(-errno); } if (i != j) { usyslog(LOG_ERR, "%s: from and to are on different writable branches %d vs %d, which" "is not supported yet.\n", __func__, i, j); - return -EXDEV; + RETURN(-EXDEV); } char f[PATHLEN_MAX], t[PATHLEN_MAX]; - if (BUILD_PATH(f, uopt.branches[i].path, from)) return -ENAMETOOLONG; - if (BUILD_PATH(t, uopt.branches[i].path, to)) return -ENAMETOOLONG; + if (BUILD_PATH(f, uopt.branches[i].path, from)) RETURN(-ENAMETOOLONG); + if (BUILD_PATH(t, uopt.branches[i].path, to)) RETURN(-ENAMETOOLONG); filetype_t ftype = path_is_dir(f); if (ftype == NOT_EXISTING) - return -ENOENT; + RETURN(-ENOENT); else if (ftype == IS_DIR) is_dir = true; @@ -466,7 +466,7 @@ static int unionfs_rename(const char *from, const char *to) { res = hide_dir(from, i); else res = hide_file(from, i); - if (res) return -errno; + if (res) RETURN(-errno); } res = rename(f, t); @@ -483,7 +483,7 @@ static int unionfs_rename(const char *from, const char *to) { usyslog(LOG_ERR, "%s: cow of %s succeeded, but rename() failed and now " "also removing the whiteout failed\n", __func__, from); } - return -err; + RETURN(-err); } if (uopt.branches[i].rw) { @@ -497,7 +497,7 @@ static int unionfs_rename(const char *from, const char *to) { } remove_hidden(to, i); // remove hide file (if any) - return 0; + RETURN(0); } /** @@ -516,7 +516,7 @@ static int statvfs_local(const char *path, struct statvfs *stbuf) { */ struct statfs stfs; int res = statfs(path, &stfs); - if (res == -1) return res; + if (res == -1) RETURN(res); memset(stbuf, 0, sizeof(*stbuf)); stbuf->f_bsize = stfs.f_bsize; @@ -540,9 +540,9 @@ static int statvfs_local(const char *path, struct statvfs *stbuf) { stbuf->f_flag = 0; stbuf->f_namemax = stfs.f_namelen; - return 0; + RETURN(0); #else - return statvfs(path, stbuf); + RETURN(statvfs(path, stbuf)); #endif } @@ -618,53 +618,53 @@ static int unionfs_statfs(const char *path, struct statvfs *stbuf) { } } - return 0; + RETURN(0); } static int unionfs_symlink(const char *from, const char *to) { DBG("from %s to %s\n", from, to); int i = find_rw_branch_cutlast(to); - if (i == -1) return -errno; + if (i == -1) RETURN(-errno); char t[PATHLEN_MAX]; - if (BUILD_PATH(t, uopt.branches[i].path, to)) return -ENAMETOOLONG; + if (BUILD_PATH(t, uopt.branches[i].path, to)) RETURN(-ENAMETOOLONG); int res = symlink(from, t); - if (res == -1) return -errno; + if (res == -1) RETURN(-errno); set_owner(t); // no error check, since creating the file succeeded remove_hidden(to, i); // remove hide file (if any) - return 0; + RETURN(0); } static int unionfs_truncate(const char *path, off_t size) { DBG("%s\n", path); int i = find_rw_branch_cow(path); - if (i == -1) return -errno; + if (i == -1) RETURN(-errno); char p[PATHLEN_MAX]; - if (BUILD_PATH(p, uopt.branches[i].path, path)) return -ENAMETOOLONG; + if (BUILD_PATH(p, uopt.branches[i].path, path)) RETURN(-ENAMETOOLONG); int res = truncate(p, size); - if (res == -1) return -errno; + if (res == -1) RETURN(-errno); - return 0; + RETURN(0); } static int unionfs_utimens(const char *path, const struct timespec ts[2]) { DBG("%s\n", path); - if (uopt.stats_enabled && strcmp(path, STATS_FILENAME) == 0) return 0; + if (uopt.stats_enabled && strcmp(path, STATS_FILENAME) == 0) RETURN(0); int i = find_rw_branch_cow(path); - if (i == -1) return -errno; + if (i == -1) RETURN(-errno); char p[PATHLEN_MAX]; - if (BUILD_PATH(p, uopt.branches[i].path, path)) return -ENAMETOOLONG; + if (BUILD_PATH(p, uopt.branches[i].path, path)) RETURN(-ENAMETOOLONG); struct timeval tv[2]; tv[0].tv_sec = ts[0].tv_sec; @@ -677,7 +677,7 @@ static int unionfs_utimens(const char *path, const struct timespec ts[2]) { // weird utimes() symlink bug? struct stat buf; res = lstat(p, &buf); - if (res || !S_ISLNK(buf.st_mode)) return - ENOENT; + if (res || !S_ISLNK(buf.st_mode)) RETURN(-ENOENT); // nothing we can do something about, seems to be a failure // of the underlying filesystem or the syscall itself is not // supported on symlinks. utime() also does not work. @@ -687,9 +687,9 @@ static int unionfs_utimens(const char *path, const struct timespec ts[2]) { res = 0; } - if (res == -1) return -errno; + if (res == -1) RETURN(-errno); - return 0; + RETURN(0); } static int unionfs_write(const char *path, const char *buf, size_t size, off_t offset, struct fuse_file_info *fi) { @@ -698,11 +698,11 @@ static int unionfs_write(const char *path, const char *buf, size_t size, off_t o DBG("%"PRIx64"\n", fi->fh); int res = pwrite(fi->fh, buf, size, offset); - if (res == -1) return -errno; + if (res == -1) RETURN(-errno); if (uopt.stats_enabled) stats_add_written(&stats, size); - return res; + RETURN(res); } #ifdef HAVE_SETXATTR @@ -710,64 +710,64 @@ static int unionfs_getxattr(const char *path, const char *name, char *value, siz DBG("%s\n", path); int i = find_rorw_branch(path); - if (i == -1) return -errno; + if (i == -1) RETURN(-errno); char p[PATHLEN_MAX]; - if (BUILD_PATH(p, uopt.branches[i].path, path)) return -ENAMETOOLONG; + if (BUILD_PATH(p, uopt.branches[i].path, path)) RETURN(-ENAMETOOLONG); int res = lgetxattr(p, name, value, size); - if (res == -1) return -errno; + if (res == -1) RETURN(-errno); - return res; + RETURN(res); } static int unionfs_listxattr(const char *path, char *list, size_t size) { DBG("%s\n", path); int i = find_rorw_branch(path); - if (i == -1) return -errno; + if (i == -1) RETURN(-errno); char p[PATHLEN_MAX]; - if (BUILD_PATH(p, uopt.branches[i].path, path)) return -ENAMETOOLONG; + if (BUILD_PATH(p, uopt.branches[i].path, path)) RETURN(-ENAMETOOLONG); int res = llistxattr(p, list, size); - if (res == -1) return -errno; + if (res == -1) RETURN(-errno); - return res; + RETURN(res); } static int unionfs_removexattr(const char *path, const char *name) { DBG("%s\n", path); int i = find_rw_branch_cow(path); - if (i == -1) return -errno; + if (i == -1) RETURN(-errno); char p[PATHLEN_MAX]; - if (BUILD_PATH(p, uopt.branches[i].path, path)) return -ENAMETOOLONG; + if (BUILD_PATH(p, uopt.branches[i].path, path)) RETURN(-ENAMETOOLONG); int res = lremovexattr(p, name); - if (res == -1) return -errno; + if (res == -1) RETURN(-errno); - return res; + RETURN(res); } static int unionfs_setxattr(const char *path, const char *name, const char *value, size_t size, int flags) { DBG("%s\n", path); int i = find_rw_branch_cow(path); - if (i == -1) return -errno; + if (i == -1) RETURN(-errno); char p[PATHLEN_MAX]; - if (BUILD_PATH(p, uopt.branches[i].path, path)) return -ENAMETOOLONG; + if (BUILD_PATH(p, uopt.branches[i].path, path)) RETURN(-ENAMETOOLONG); int res = lsetxattr(p, name, value, size, flags); - if (res == -1) return -errno; + if (res == -1) RETURN(-errno); - return res; + RETURN(res); } #endif // HAVE_SETXATTR @@ -808,14 +808,14 @@ int main(int argc, char *argv[]) { uopt_init(); - if (fuse_opt_parse(&args, NULL, unionfs_opts, unionfs_opt_proc) == -1) return 1; + if (fuse_opt_parse(&args, NULL, unionfs_opts, unionfs_opt_proc) == -1) RETURN(1); if (uopt.debug) debug_init(); if (!uopt.doexit) { if (uopt.nbranches == 0) { printf("You need to specify at least one branch!\n"); - return 1; + RETURN(1); } if (uopt.stats_enabled) stats_init(&stats); @@ -845,5 +845,5 @@ int main(int argc, char *argv[]) { umask(0); int res = fuse_main(args.argc, args.argv, &unionfs_oper, NULL); - return uopt.doexit ? uopt.retval : res; + RETURN(uopt.doexit ? uopt.retval : res); } diff --git a/src/unlink.c b/src/unlink.c index ce37016..8b4000d 100644 --- a/src/unlink.c +++ b/src/unlink.c @@ -42,15 +42,15 @@ static int unlink_ro(const char *path, int branch_ro) { // find a writable branch above branch_ro int branch_rw = find_lowest_rw_branch(branch_ro); - if (branch_rw < 0) return EACCES; + if (branch_rw < 0) RETURN(EACCES); if (hide_file(path, branch_rw) == -1) { // creating the file with the hide tag failed // TODO: open() error messages are not optimal on unlink() - return errno; + RETURN(errno); } - return 0; + RETURN(0); } /** @@ -61,12 +61,12 @@ static int unlink_rw(const char *path, int branch_rw) { DBG("%s\n", path); char p[PATHLEN_MAX]; - if (BUILD_PATH(p, uopt.branches[branch_rw].path, path)) return ENAMETOOLONG; + if (BUILD_PATH(p, uopt.branches[branch_rw].path, path)) RETURN(ENAMETOOLONG); int res = unlink(p); - if (res == -1) return errno; + if (res == -1) RETURN(errno); - return 0; + RETURN(0); } /** @@ -76,7 +76,7 @@ int unionfs_unlink(const char *path) { DBG("%s\n", path); int i = find_rorw_branch(path); - if (i == -1) return errno; + if (i == -1) RETURN(errno); int res; if (!uopt.branches[i].rw) { @@ -95,5 +95,5 @@ int unionfs_unlink(const char *path) { } } - return -res; + RETURN(-res); } -- cgit v1.2.1