f6c2062bc6dc0bf1b82c8ecfc31ebb270f368423
[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   if (guestfs_add_drive (g, argv[1]) == -1) exit (1);
21
22   if (guestfs_launch (g) == -1) exit (1);
23   if (guestfs_wait_ready (g) == -1) exit (1);
24
25   if (guestfs_mount (g, "/dev/sda1", "/") == -1) exit (1);
26
27   if (guestfs_touch (g, "/hello") == -1) exit (1);
28
29   guestfs_sync (g);
30   guestfs_close (g);
31   return 0;
32 }