2 * Copyright (C) 2010 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 along
15 * with this program; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19 /* Test that we can get correct errnos all the way back from the
20 * appliance, translated to the local operating system.
35 main (int argc, char *argv[])
39 struct guestfs_stat *stat;
40 const char *filename = "test1.img";
42 g = guestfs_create ();
44 fprintf (stderr, "failed to create handle\n");
48 fd = open (filename, O_WRONLY|O_CREAT|O_NOCTTY|O_TRUNC, 0666);
53 if (ftruncate (fd, 524288000) == -1) {
59 if (close (fd) == -1) {
65 if (guestfs_add_drive_opts (g, filename,
66 GUESTFS_ADD_DRIVE_OPTS_FORMAT, "raw",
70 if (guestfs_launch (g) == -1)
73 if (guestfs_part_disk (g, "/dev/sda", "mbr") == -1)
76 if (guestfs_mkfs (g, "ext2", "/dev/sda1") == -1)
79 /* Mount read-only, and check that errno == EROFS is passed back when
82 if (guestfs_mount_ro (g, "/dev/sda1", "/") == -1)
85 r = guestfs_touch (g, "/test");
88 "guestfs_touch: expected error for read-only filesystem\n");
92 err = guestfs_last_errno (g);
95 "guestfs_touch: expected errno == EROFS, but got %d\n", err);
99 if (guestfs_umount (g, "/") == -1)
102 /* Mount it writable and test some other errors. */
103 if (guestfs_mount_options (g, "", "/dev/sda1", "/") == -1)
106 stat = guestfs_lstat (g, "/nosuchfile");
109 "guestfs_lstat: expected error for missing file\n");
113 err = guestfs_last_errno (g);
116 "guestfs_lstat: expected errno == ENOENT, but got %d\n", err);
120 if (guestfs_touch (g, "/test") == -1)
123 r = guestfs_mkdir (g, "/test");
126 "guestfs_mkdir: expected error for file which exists\n");
130 err = guestfs_last_errno (g);
133 "guestfs_mkdir: expected errno == EEXIST, but got %d\n", err);