1 /* guestmount - mount guests using libguestfs and FUSE
2 * Copyright (C) 2009-2011 Red Hat Inc.
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 * Derived from the example program 'fusexmp.c':
19 * Copyright (C) 2001-2007 Miklos Szeredi <miklos@szeredi.hu>
21 * This program can be distributed under the terms of the GNU GPL.
22 * See the file COPYING.
25 #define FUSE_USE_VERSION 26
43 #include <sys/types.h>
52 #include "guestmount.h"
56 /* See <attr/xattr.h> */
58 #define ENOATTR ENODATA
66 int keys_from_stdin = 0;
68 const char *libvirt_uri;
69 int dir_cache_timeout = 60;
70 static int trace_calls = 0;
72 #define TRACE_CALL(fs,...) \
74 fprintf (stderr, "%s: %s (" fs ")\n", \
75 program_name, __func__, __VA_ARGS__); \
81 return -guestfs_last_errno (g);
84 static struct guestfs_xattr_list *
85 copy_xattr_list (const struct guestfs_xattr *first, size_t num)
87 struct guestfs_xattr_list *xattrs;
89 xattrs = malloc (sizeof *xattrs);
96 xattrs->val = malloc (num * sizeof (struct guestfs_xattr));
97 if (xattrs->val == NULL) {
104 for (i = 0; i < num; ++i) {
105 xattrs->val[i].attrname = strdup (first[i].attrname);
106 xattrs->val[i].attrval_len = first[i].attrval_len;
107 xattrs->val[i].attrval = malloc (first[i].attrval_len);
108 memcpy (xattrs->val[i].attrval, first[i].attrval, first[i].attrval_len);
115 fg_readdir (const char *path, void *buf, fuse_fill_dir_t filler,
116 off_t offset, struct fuse_file_info *fi)
118 TRACE_CALL ("%s, %p, %ld", path, buf, (long) offset);
123 dir_cache_remove_all_expired (now);
125 struct guestfs_dirent_list *ents;
127 ents = guestfs_readdir (g, path);
132 for (i = 0; i < ents->len; ++i) {
134 memset (&stat, 0, sizeof stat);
136 stat.st_ino = ents->val[i].ino;
137 switch (ents->val[i].ftyp) {
138 case 'b': stat.st_mode = S_IFBLK; break;
139 case 'c': stat.st_mode = S_IFCHR; break;
140 case 'd': stat.st_mode = S_IFDIR; break;
141 case 'f': stat.st_mode = S_IFIFO; break;
142 case 'l': stat.st_mode = S_IFLNK; break;
143 case 'r': stat.st_mode = S_IFREG; break;
144 case 's': stat.st_mode = S_IFSOCK; break;
147 default: stat.st_mode = 0;
150 /* Copied from the example, which also ignores 'offset'. I'm
151 * not quite sure how this is ever supposed to work on large
154 if (filler (buf, ents->val[i].name, &stat, 0))
158 /* Now prepopulate the directory caches. This step is just an
159 * optimization, don't worry if it fails.
161 char **names = malloc ((ents->len + 1) * sizeof (char *));
163 for (i = 0; i < ents->len; ++i)
164 names[i] = ents->val[i].name;
167 struct guestfs_stat_list *ss = guestfs_lstatlist (g, path, names);
169 for (i = 0; i < ss->len; ++i) {
170 if (ss->val[i].ino >= 0) {
173 statbuf.st_dev = ss->val[i].dev;
174 statbuf.st_ino = ss->val[i].ino;
175 statbuf.st_mode = ss->val[i].mode;
176 statbuf.st_nlink = ss->val[i].nlink;
177 statbuf.st_uid = ss->val[i].uid;
178 statbuf.st_gid = ss->val[i].gid;
179 statbuf.st_rdev = ss->val[i].rdev;
180 statbuf.st_size = ss->val[i].size;
181 statbuf.st_blksize = ss->val[i].blksize;
182 statbuf.st_blocks = ss->val[i].blocks;
183 statbuf.st_atime = ss->val[i].atime;
184 statbuf.st_mtime = ss->val[i].mtime;
185 statbuf.st_ctime = ss->val[i].ctime;
187 lsc_insert (path, names[i], now, &statbuf);
190 guestfs_free_stat_list (ss);
193 struct guestfs_xattr_list *xattrs = guestfs_lxattrlist (g, path, names);
196 struct guestfs_xattr *first;
197 struct guestfs_xattr_list *copy;
198 for (i = 0, ni = 0; i < xattrs->len; ++i, ++ni) {
199 assert (strlen (xattrs->val[i].attrname) == 0);
200 if (xattrs->val[i].attrval_len > 0) {
202 first = &xattrs->val[i];
204 for (; i < xattrs->len && strlen (xattrs->val[i].attrname) > 0; ++i)
207 copy = copy_xattr_list (first, num);
209 xac_insert (path, names[ni], now, copy);
214 guestfs_free_xattr_list (xattrs);
217 char **links = guestfs_readlinklist (g, path, names);
219 for (i = 0; names[i] != NULL; ++i) {
221 /* Note that rlc_insert owns the string links[i] after this, */
222 rlc_insert (path, names[i], now, links[i]);
224 /* which is why we have to free links[i] here. */
227 free (links); /* free the array, not the strings */
233 guestfs_free_dirent_list (ents);
239 fg_getattr (const char *path, struct stat *statbuf)
241 TRACE_CALL ("%s, %p", path, statbuf);
243 const struct stat *buf;
245 buf = lsc_lookup (path);
247 memcpy (statbuf, buf, sizeof *statbuf);
251 struct guestfs_stat *r;
253 r = guestfs_lstat (g, path);
257 statbuf->st_dev = r->dev;
258 statbuf->st_ino = r->ino;
259 statbuf->st_mode = r->mode;
260 statbuf->st_nlink = r->nlink;
261 statbuf->st_uid = r->uid;
262 statbuf->st_gid = r->gid;
263 statbuf->st_rdev = r->rdev;
264 statbuf->st_size = r->size;
265 statbuf->st_blksize = r->blksize;
266 statbuf->st_blocks = r->blocks;
267 statbuf->st_atime = r->atime;
268 statbuf->st_mtime = r->mtime;
269 statbuf->st_ctime = r->ctime;
271 guestfs_free_stat (r);
276 /* Nautilus loves to use access(2) to test everything about a file,
277 * such as whether it's executable. Therefore treat this a lot like
281 fg_access (const char *path, int mask)
283 TRACE_CALL ("%s, %d", path, mask);
288 if (read_only && (mask & W_OK))
291 r = fg_getattr (path, &statbuf);
292 if (r < 0 || mask == F_OK)
295 struct fuse_context *fuse = fuse_get_context ();
300 ( fuse->uid == statbuf.st_uid ? statbuf.st_mode & S_IRUSR
301 : fuse->gid == statbuf.st_gid ? statbuf.st_mode & S_IRGRP
302 : statbuf.st_mode & S_IROTH);
305 ( fuse->uid == statbuf.st_uid ? statbuf.st_mode & S_IWUSR
306 : fuse->gid == statbuf.st_gid ? statbuf.st_mode & S_IWGRP
307 : statbuf.st_mode & S_IWOTH);
310 ( fuse->uid == statbuf.st_uid ? statbuf.st_mode & S_IXUSR
311 : fuse->gid == statbuf.st_gid ? statbuf.st_mode & S_IXGRP
312 : statbuf.st_mode & S_IXOTH);
314 return ok ? 0 : -EACCES;
318 fg_readlink (const char *path, char *buf, size_t size)
320 TRACE_CALL ("%s, %p, %zu", path, buf, size);
325 r = rlc_lookup (path);
327 r = guestfs_readlink (g, path);
333 /* Note this is different from the real readlink(2) syscall. FUSE wants
334 * the string to be always nul-terminated, even if truncated.
336 size_t len = strlen (r);
340 memcpy (buf, r, len);
344 char *tmp = (char *) r;
352 fg_mknod (const char *path, mode_t mode, dev_t rdev)
354 TRACE_CALL ("%s, 0%o, 0x%lx", path, mode, (long) rdev);
358 if (read_only) return -EROFS;
360 dir_cache_invalidate (path);
362 r = guestfs_mknod (g, mode, major (rdev), minor (rdev), path);
370 fg_mkdir (const char *path, mode_t mode)
372 TRACE_CALL ("%s, 0%o", path, mode);
376 if (read_only) return -EROFS;
378 dir_cache_invalidate (path);
380 r = guestfs_mkdir_mode (g, path, mode);
388 fg_unlink (const char *path)
390 TRACE_CALL ("%s", path);
394 if (read_only) return -EROFS;
396 dir_cache_invalidate (path);
398 r = guestfs_rm (g, path);
406 fg_rmdir (const char *path)
408 TRACE_CALL ("%s", path);
412 if (read_only) return -EROFS;
414 dir_cache_invalidate (path);
416 r = guestfs_rmdir (g, path);
424 fg_symlink (const char *from, const char *to)
426 TRACE_CALL ("%s, %s", from, to);
430 if (read_only) return -EROFS;
432 dir_cache_invalidate (to);
434 r = guestfs_ln_s (g, from, to);
442 fg_rename (const char *from, const char *to)
444 TRACE_CALL ("%s, %s", from, to);
448 if (read_only) return -EROFS;
450 dir_cache_invalidate (from);
451 dir_cache_invalidate (to);
453 /* XXX It's not clear how close the 'mv' command is to the
454 * rename syscall. We might need to add the rename syscall
455 * to the guestfs(3) API.
457 r = guestfs_mv (g, from, to);
465 fg_link (const char *from, const char *to)
467 TRACE_CALL ("%s, %s", from, to);
471 if (read_only) return -EROFS;
473 dir_cache_invalidate (from);
474 dir_cache_invalidate (to);
476 r = guestfs_ln (g, from, to);
484 fg_chmod (const char *path, mode_t mode)
486 TRACE_CALL ("%s, 0%o", path, mode);
490 if (read_only) return -EROFS;
492 dir_cache_invalidate (path);
494 r = guestfs_chmod (g, mode, path);
502 fg_chown (const char *path, uid_t uid, gid_t gid)
504 TRACE_CALL ("%s, %ld, %ld", path, (long) uid, (long) gid);
508 if (read_only) return -EROFS;
510 dir_cache_invalidate (path);
512 r = guestfs_lchown (g, uid, gid, path);
520 fg_truncate (const char *path, off_t size)
522 TRACE_CALL ("%s, %ld", path, (long) size);
526 if (read_only) return -EROFS;
528 dir_cache_invalidate (path);
530 r = guestfs_truncate_size (g, path, size);
538 fg_utimens (const char *path, const struct timespec ts[2])
540 TRACE_CALL ("%s, [{ %ld, %ld }, { %ld, %ld }]",
541 path, ts[0].tv_sec, ts[0].tv_nsec, ts[1].tv_sec, ts[1].tv_nsec);
545 if (read_only) return -EROFS;
547 dir_cache_invalidate (path);
549 time_t atsecs = ts[0].tv_sec;
550 long atnsecs = ts[0].tv_nsec;
551 time_t mtsecs = ts[1].tv_sec;
552 long mtnsecs = ts[1].tv_nsec;
555 if (atnsecs == UTIME_NOW)
559 if (atnsecs == UTIME_OMIT)
563 if (mtnsecs == UTIME_NOW)
567 if (mtnsecs == UTIME_OMIT)
571 r = guestfs_utimens (g, path, atsecs, atnsecs, mtsecs, mtnsecs);
578 /* All this function needs to do is to check that the requested open
579 * flags are valid. See the notes in <fuse/fuse.h>.
582 fg_open (const char *path, struct fuse_file_info *fi)
584 TRACE_CALL ("%s, 0%o", path, fi->flags);
586 int flags = fi->flags & 3;
588 if (read_only && flags != O_RDONLY)
595 fg_read (const char *path, char *buf, size_t size, off_t offset,
596 struct fuse_file_info *fi)
598 TRACE_CALL ("%s, %p, %zu, %ld", path, buf, size, (long) offset);
604 fprintf (stderr, "fg_read: %s: size %zu offset %ju\n",
607 /* The guestfs protocol limits size to somewhere over 2MB. We just
608 * reduce the requested size here accordingly and push the problem
609 * up to every user. http://www.jwz.org/doc/worse-is-better.html
611 const size_t limit = 2 * 1024 * 1024;
615 r = guestfs_pread (g, path, size, offset, &rsize);
619 /* This should never happen, but at least it stops us overflowing
620 * the output buffer if it does happen.
625 memcpy (buf, r, rsize);
632 fg_write (const char *path, const char *buf, size_t size,
633 off_t offset, struct fuse_file_info *fi)
635 TRACE_CALL ("%s, %p, %zu, %ld", path, buf, size, (long) offset);
637 if (read_only) return -EROFS;
639 dir_cache_invalidate (path);
642 const size_t limit = 2 * 1024 * 1024;
647 r = guestfs_pwrite (g, path, buf, size, offset);
655 fg_statfs (const char *path, struct statvfs *stbuf)
657 TRACE_CALL ("%s, %p", path, stbuf);
659 struct guestfs_statvfs *r;
661 r = guestfs_statvfs (g, path);
665 stbuf->f_bsize = r->bsize;
666 stbuf->f_frsize = r->frsize;
667 stbuf->f_blocks = r->blocks;
668 stbuf->f_bfree = r->bfree;
669 stbuf->f_bavail = r->bavail;
670 stbuf->f_files = r->files;
671 stbuf->f_ffree = r->ffree;
672 stbuf->f_favail = r->favail;
673 stbuf->f_fsid = r->fsid;
674 stbuf->f_flag = r->flag;
675 stbuf->f_namemax = r->namemax;
677 guestfs_free_statvfs (r);
683 fg_release (const char *path, struct fuse_file_info *fi)
685 TRACE_CALL ("%s", path);
687 /* Just a stub. This method is optional and can safely be left
693 /* Emulate this by calling sync. */
694 static int fg_fsync(const char *path, int isdatasync,
695 struct fuse_file_info *fi)
697 TRACE_CALL ("%s, %d", path, isdatasync);
701 r = guestfs_sync (g);
709 fg_setxattr (const char *path, const char *name, const char *value,
710 size_t size, int flags)
712 TRACE_CALL ("%s, %s, %p, %zu", path, name, value, size);
716 if (read_only) return -EROFS;
718 dir_cache_invalidate (path);
720 /* XXX Underlying guestfs(3) API doesn't understand the flags. */
721 r = guestfs_lsetxattr (g, name, value, size, path);
728 /* The guestfs(3) API for getting xattrs is much easier to use
729 * than the real syscall. Unfortunately we now have to emulate
730 * the real syscall using that API :-(
733 fg_getxattr (const char *path, const char *name, char *value,
736 TRACE_CALL ("%s, %s, %p, %zu", path, name, value, size);
738 const struct guestfs_xattr_list *xattrs;
741 xattrs = xac_lookup (path);
742 if (xattrs == NULL) {
743 xattrs = guestfs_lgetxattrs (g, path);
749 /* Find the matching attribute (index in 'i'). */
752 for (i = 0; i < xattrs->len; ++i) {
753 if (STREQ (xattrs->val[i].attrname, name))
757 if (i == xattrs->len) { /* not found */
762 /* The getxattr man page is unclear, but if value == NULL then we
763 * return the space required (the caller then makes a second syscall
764 * after allocating the required amount of space). If value != NULL
765 * then it's not clear what we should do, but it appears we should
766 * copy as much as possible and return -ERANGE if there's not enough
767 * space in the buffer.
769 size_t sz = xattrs->val[i].attrval_len;
781 memcpy (value, xattrs->val[i].attrval, sz);
785 guestfs_free_xattr_list ((struct guestfs_xattr_list *) xattrs);
790 /* Ditto as above. */
792 fg_listxattr (const char *path, char *list, size_t size)
794 TRACE_CALL ("%s, %p, %zu", path, list, size);
796 const struct guestfs_xattr_list *xattrs;
799 xattrs = xac_lookup (path);
800 if (xattrs == NULL) {
801 xattrs = guestfs_lgetxattrs (g, path);
807 /* Calculate how much space is required to hold the result. */
811 for (i = 0; i < xattrs->len; ++i) {
812 len = strlen (xattrs->val[i].attrname) + 1;
816 /* The listxattr man page is unclear, but if list == NULL then we
817 * return the space required (the caller then makes a second syscall
818 * after allocating the required amount of space). If list != NULL
819 * then it's not clear what we should do, but it appears we should
820 * copy as much as possible and return -ERANGE if there's not enough
821 * space in the buffer.
830 for (i = 0; i < xattrs->len; ++i) {
831 len = strlen (xattrs->val[i].attrname) + 1;
833 memcpy (list, xattrs->val[i].attrname, len);
845 guestfs_free_xattr_list ((struct guestfs_xattr_list *) xattrs);
851 fg_removexattr(const char *path, const char *name)
853 TRACE_CALL ("%s, %s", path, name);
857 if (read_only) return -EROFS;
859 dir_cache_invalidate (path);
861 r = guestfs_lremovexattr (g, name, path);
868 static struct fuse_operations fg_operations = {
869 .getattr = fg_getattr,
871 .readlink = fg_readlink,
872 .readdir = fg_readdir,
875 .symlink = fg_symlink,
882 .truncate = fg_truncate,
883 .utimens = fg_utimens,
888 .release = fg_release,
890 .setxattr = fg_setxattr,
891 .getxattr = fg_getxattr,
892 .listxattr = fg_listxattr,
893 .removexattr = fg_removexattr,
896 static void __attribute__((noreturn))
899 const char *tmp_argv[] = { program_name, "--help", NULL };
900 fuse_main (2, (char **) tmp_argv, &fg_operations, NULL);
904 static void __attribute__((noreturn))
907 if (status != EXIT_SUCCESS)
908 fprintf (stderr, _("Try `%s --help' for more information.\n"),
912 _("%s: FUSE module for libguestfs\n"
913 "%s lets you mount a virtual machine filesystem\n"
914 "Copyright (C) 2009-2010 Red Hat Inc.\n"
916 " %s [--options] [-- [--FUSE-options]] mountpoint\n"
918 " -a|--add image Add image\n"
919 " -c|--connect uri Specify libvirt URI for -d option\n"
920 " --dir-cache-timeout Set readdir cache timeout (default 5 sec)\n"
921 " -d|--domain guest Add disks from libvirt guest\n"
922 " --echo-keys Don't turn off echo for passphrases\n"
923 " --format[=raw|..] Force disk format for -a option\n"
924 " --fuse-help Display extra FUSE options\n"
925 " -i|--inspector Automatically mount filesystems\n"
926 " --help Display help message and exit\n"
927 " --keys-from-stdin Read passphrases from stdin\n"
928 " --live Connect to a live virtual machine\n"
929 " -m|--mount dev[:mnt[:opts]] Mount dev on mnt (if omitted, /)\n"
930 " -n|--no-sync Don't autosync\n"
931 " -o|--option opt Pass extra option to FUSE\n"
932 " -r|--ro Mount read-only\n"
933 " --selinux Enable SELinux support\n"
934 " -v|--verbose Verbose messages\n"
935 " -V|--version Display version and exit\n"
936 " -w|--rw Mount read-write\n"
937 " -x|--trace Trace guestfs API calls\n"
939 program_name, program_name, program_name);
945 main (int argc, char *argv[])
947 setlocale (LC_ALL, "");
948 bindtextdomain (PACKAGE, LOCALEBASEDIR);
949 textdomain (PACKAGE);
953 enum { HELP_OPTION = CHAR_MAX + 1 };
955 /* The command line arguments are broadly compatible with (a subset
956 * of) guestfish. Thus we have to deal mainly with -a, -m and --ro.
958 static const char *options = "a:c:d:im:no:rv?Vwx";
959 static const struct option long_options[] = {
960 { "add", 1, 0, 'a' },
961 { "connect", 1, 0, 'c' },
962 { "dir-cache-timeout", 1, 0, 0 },
963 { "domain", 1, 0, 'd' },
964 { "echo-keys", 0, 0, 0 },
965 { "format", 2, 0, 0 },
966 { "fuse-help", 0, 0, 0 },
967 { "help", 0, 0, HELP_OPTION },
968 { "inspector", 0, 0, 'i' },
969 { "keys-from-stdin", 0, 0, 0 },
971 { "mount", 1, 0, 'm' },
972 { "no-sync", 0, 0, 'n' },
973 { "option", 1, 0, 'o' },
976 { "selinux", 0, 0, 0 },
977 { "trace", 0, 0, 'x' },
978 { "verbose", 0, 0, 'v' },
979 { "version", 0, 0, 'V' },
983 struct drv *drvs = NULL;
985 struct mp *mps = NULL;
988 const char *format = NULL;
994 const char **fuse_argv = NULL;
996 #define ADD_FUSE_ARG(str) \
999 fuse_argv = realloc (fuse_argv, (1+fuse_argc) * sizeof (char *)); \
1001 perror ("realloc"); \
1002 exit (EXIT_FAILURE); \
1004 fuse_argv[fuse_argc-1] = (str); \
1005 fuse_argv[fuse_argc] = NULL; \
1008 /* LC_ALL=C is required so we can parse error messages. */
1009 setenv ("LC_ALL", "C", 1);
1011 /* Set global program name that is not polluted with libtool artifacts. */
1012 set_program_name (argv[0]);
1014 memset (&sa, 0, sizeof sa);
1015 sa.sa_handler = SIG_IGN;
1016 sa.sa_flags = SA_RESTART;
1017 sigaction (SIGPIPE, &sa, NULL);
1019 /* Various initialization. */
1022 g = guestfs_create ();
1024 fprintf (stderr, _("guestfs_create: failed to create handle\n"));
1025 exit (EXIT_FAILURE);
1028 guestfs_set_recovery_proc (g, 0);
1030 ADD_FUSE_ARG (program_name);
1031 /* MUST be single-threaded. You cannot have two threads accessing the
1032 * same libguestfs handle, and opening more than one handle is likely
1033 * to be very expensive.
1035 ADD_FUSE_ARG ("-s");
1038 c = getopt_long (argc, argv, options, long_options, &option_index);
1042 case 0: /* options which are long only */
1043 if (STREQ (long_options[option_index].name, "dir-cache-timeout"))
1044 dir_cache_timeout = atoi (optarg);
1045 else if (STREQ (long_options[option_index].name, "fuse-help"))
1047 else if (STREQ (long_options[option_index].name, "selinux"))
1048 guestfs_set_selinux (g, 1);
1049 else if (STREQ (long_options[option_index].name, "format")) {
1050 if (!optarg || STREQ (optarg, ""))
1054 } else if (STREQ (long_options[option_index].name, "keys-from-stdin")) {
1055 keys_from_stdin = 1;
1056 } else if (STREQ (long_options[option_index].name, "echo-keys")) {
1058 } else if (STREQ (long_options[option_index].name, "live")) {
1061 fprintf (stderr, _("%s: unknown long option: %s (%d)\n"),
1062 program_name, long_options[option_index].name, option_index);
1063 exit (EXIT_FAILURE);
1092 ADD_FUSE_ARG ("-o");
1093 ADD_FUSE_ARG (optarg);
1114 ADD_FUSE_ARG ("-f");
1115 guestfs_set_recovery_proc (g, 1);
1120 usage (EXIT_SUCCESS);
1123 usage (EXIT_FAILURE);
1127 /* Check we have the right options. */
1129 if (!drvs || !(mps || inspector)) {
1131 _("%s: must have at least one -a/-d and at least one -m/-i option\n"),
1133 exit (EXIT_FAILURE);
1136 size_t count_d = 0, count_other = 0;
1141 _("%s: --live is not compatible with --ro option\n"),
1143 exit (EXIT_FAILURE);
1148 _("%s: --live is not compatible with -i option\n"),
1150 exit (EXIT_FAILURE);
1153 /* --live: make sure there was one -d option and no -a options */
1154 for (drv = drvs; drv; drv = drv->next) {
1155 if (drv->type == drv_d)
1163 _("%s: with --live, you must use exactly one -d option\n"),
1165 exit (EXIT_FAILURE);
1168 if (count_other != 0) {
1170 _("%s: --live is not compatible with -a option\n"),
1172 exit (EXIT_FAILURE);
1176 /* We'd better have a mountpoint. */
1177 if (optind+1 != argc) {
1179 _("%s: you must specify a mountpoint in the host filesystem\n"),
1181 exit (EXIT_FAILURE);
1184 /* Do the guest drives and mountpoints. */
1185 add_drives (drvs, 'a');
1186 if (guestfs_launch (g) == -1)
1187 exit (EXIT_FAILURE);
1195 /* FUSE example does this, not clear if it's necessary, but ... */
1196 if (guestfs_umask (g, 0) == -1)
1197 exit (EXIT_FAILURE);
1199 /* At the last minute, remove the libguestfs error handler. In code
1200 * above this point, the default error handler has been used which
1201 * sends all errors to stderr. Now before entering FUSE itself we
1202 * want to silence errors so we can convert them (see error()
1205 guestfs_set_error_handler (g, NULL, NULL);
1207 /* Finish off FUSE args. */
1208 ADD_FUSE_ARG (argv[optind]);
1211 It says about the line containing the for-statement:
1212 error: assuming signed overflow does not occur when simplifying conditional to constant [-Wstrict-overflow]
1215 fprintf (stderr, "guestmount: invoking FUSE with args [");
1216 for (i = 0; i < fuse_argc; ++i) {
1217 if (i > 0) fprintf (stderr, ", ");
1218 fprintf (stderr, "%s", fuse_argv[i]);
1220 fprintf (stderr, "]\n");
1224 r = fuse_main (fuse_argc, (char **) fuse_argv, &fg_operations, NULL);
1230 exit (r == 0 ? EXIT_SUCCESS : EXIT_FAILURE);