X-Git-Url: http://git.annexia.org/?p=libguestfs.git;a=blobdiff_plain;f=fuse%2Fguestmount.c;h=ba0d626ca66ce1276f95258907555bb1adf22d49;hp=ec3cc77395be8158a703785f4ce91851e44f8871;hb=5c2da21b2ae56adc16bbd5bf9740a04ca70f9f19;hpb=429de2254176e470035eef05e0f3e9910d46863c diff --git a/fuse/guestmount.c b/fuse/guestmount.c index ec3cc77..ba0d626 100644 --- a/fuse/guestmount.c +++ b/fuse/guestmount.c @@ -46,6 +46,7 @@ #include "progname.h" +#include "guestmount.h" #include "dircache.h" /* See */ @@ -53,21 +54,6 @@ #define ENOATTR ENODATA #endif -#ifdef HAVE_GETTEXT -#include "gettext.h" -#define _(str) dgettext(PACKAGE, (str)) -//#define N_(str) dgettext(PACKAGE, (str)) -#else -#define _(str) str -//#define N_(str) str -#endif - -static inline char * -bad_cast (char const *s) -{ - return (char *) s; -} - static guestfs_h *g = NULL; static int read_only = 0; int verbose = 0; @@ -360,8 +346,10 @@ fg_readlink (const char *path, char *buf, size_t size) memcpy (buf, r, len); buf[len] = '\0'; - if (free_it) - free ((char *) r); + if (free_it) { + char *tmp = (char *) r; + free (tmp); + } return 0; } @@ -439,7 +427,7 @@ fg_symlink (const char *from, const char *to) dir_cache_invalidate (to); - r = guestfs_ln_s (g, to, from); + r = guestfs_ln_s (g, from, to); if (r == -1) return error (); @@ -453,6 +441,7 @@ fg_rename (const char *from, const char *to) if (read_only) return -EROFS; + dir_cache_invalidate (from); dir_cache_invalidate (to); /* XXX It's not clear how close the 'mv' command is to the @@ -473,9 +462,10 @@ fg_link (const char *from, const char *to) if (read_only) return -EROFS; + dir_cache_invalidate (from); dir_cache_invalidate (to); - r = guestfs_ln (g, to, from); + r = guestfs_ln (g, from, to); if (r == -1) return error (); @@ -619,7 +609,7 @@ fg_read (const char *path, char *buf, size_t size, off_t offset, size_t rsize; if (verbose) - fprintf (stderr, "fg_read: %s: size %zu offset %zu\n", + fprintf (stderr, "fg_read: %s: size %zu offset %ju\n", path, size, offset); /* The guestfs protocol limits size to somewhere over 2MB. We just @@ -630,8 +620,14 @@ fg_read (const char *path, char *buf, size_t size, off_t offset, if (size > limit) size = limit; + /* Note the correct error handling here is tricky, because in the + * case where the call returns a zero-length buffer, it might return + * NULL. However it won't adjust rsize along the error path, so we + * can set rsize to something beforehand and use that as a flag. + */ + rsize = 1; r = guestfs_pread (g, path, size, offset, &rsize); - if (r == NULL) + if (rsize == 1 && r == NULL) return error (); /* This should never happen, but at least it stops us overflowing @@ -694,7 +690,7 @@ fg_release (const char *path, struct fuse_file_info *fi) /* Emulate this by calling sync. */ static int fg_fsync(const char *path, int isdatasync, - struct fuse_file_info *fi) + struct fuse_file_info *fi) { int r; @@ -745,7 +741,7 @@ fg_getxattr (const char *path, const char *name, char *value, size_t i; int r = -ENOATTR; for (i = 0; i < xattrs->len; ++i) { - if (strcmp (xattrs->val[i].attrname, name) == 0) { + if (STREQ (xattrs->val[i].attrname, name)) { size_t sz = xattrs->val[i].attrval_len; if (sz > size) sz = size; @@ -993,13 +989,13 @@ main (int argc, char *argv[]) switch (c) { case 0: /* options which are long only */ - if (strcmp (long_options[option_index].name, "dir-cache-timeout") == 0) + if (STREQ (long_options[option_index].name, "dir-cache-timeout")) dir_cache_timeout = atoi (optarg); - else if (strcmp (long_options[option_index].name, "fuse-help") == 0) + else if (STREQ (long_options[option_index].name, "fuse-help")) fuse_help (); - else if (strcmp (long_options[option_index].name, "selinux") == 0) + else if (STREQ (long_options[option_index].name, "selinux")) guestfs_set_selinux (g, 1); - else if (strcmp (long_options[option_index].name, "trace") == 0) { + else if (STREQ (long_options[option_index].name, "trace")) { ADD_FUSE_ARG ("-f"); guestfs_set_trace (g, 1); guestfs_set_recovery_proc (g, 1); @@ -1110,6 +1106,10 @@ main (int argc, char *argv[]) /* Finish off FUSE args. */ ADD_FUSE_ARG (argv[optind]); + /* + It says about the line containing the for-statement: + error: assuming signed overflow does not occur when simplifying conditional to constant [-Wstrict-overflow] + if (verbose) { fprintf (stderr, "guestmount: invoking FUSE with args ["); for (i = 0; i < fuse_argc; ++i) { @@ -1118,6 +1118,7 @@ main (int argc, char *argv[]) } fprintf (stderr, "]\n"); } + */ r = fuse_main (fuse_argc, (char **) fuse_argv, &fg_operations, NULL);