5f1ab0eca6143c339368aa1584addbc9a31cb90e
[libguestfs.git] / examples / hello.c
1 /* Create a "/hello" file on /dev/sda1. */
2
3 #include <stdio.h>
4 #include <stdlib.h>
5 #include <unistd.h>
6 #include <guestfs.h>
7
8 int
9 main (int argc, char *argv[])
10 {
11   guestfs_h *g;
12
13   if (argc != 2 || access (argv[1], F_OK) != 0) {
14     fprintf (stderr, "Usage: hello disk-image\n");
15     exit (1);
16   }
17
18   if (!(g = guestfs_create ())) exit (1);
19
20   guestfs_set_verbose (g, 1);
21   if (guestfs_add_drive (g, argv[1]) == -1) exit (1);
22
23   if (guestfs_launch (g) == -1) exit (1);
24   if (guestfs_wait_ready (g) == -1) exit (1);
25
26   if (guestfs_mount (g, "/dev/sda1", "/") == -1) exit (1);
27
28   if (guestfs_touch (g, "/hello") == -1) exit (1);
29
30   guestfs_sync (g);
31   guestfs_close (g);
32   return 0;
33 }