summaryrefslogtreecommitdiffstats
path: root/examples/hello.c
blob: b4d5d8c63f615dbd6a4260a2fb7082328848d00b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
/* Create a "/hello" file on chosen partition.
 * eg:
 *   hello guest.img /dev/sda1
 *   hello guest.img /dev/VolGroup00/LogVol00
 */

#if HAVE_CONFIG_H
# include <config.h>
#endif
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <guestfs.h>

int
main (int argc, char *argv[])
{
  guestfs_h *g;

  if (argc != 3 || access (argv[1], F_OK) != 0) {
    fprintf (stderr, "Usage: hello disk-image partition\n");
    exit (EXIT_FAILURE);
  }

  if (!(g = guestfs_create ())) exit (EXIT_FAILURE);

  if (guestfs_add_drive (g, argv[1]) == -1) exit (EXIT_FAILURE);

  if (guestfs_launch (g) == -1) exit (EXIT_FAILURE);

  if (guestfs_mount (g, argv[2], "/") == -1) exit (EXIT_FAILURE);

  if (guestfs_touch (g, "/hello") == -1) exit (EXIT_FAILURE);

  guestfs_sync (g);
  guestfs_close (g);
  return 0;
}