49 lines
1020 B
C
49 lines
1020 B
C
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <czmq.h>
|
|
#include <guestfs.h>
|
|
|
|
int main(int argc, char **argv) {
|
|
if (argc < 2) {
|
|
printf("Usage: %s <disk-path>\n", argv[0]);
|
|
return EXIT_FAILURE;
|
|
}
|
|
|
|
guestfs_h *g = guestfs_create();
|
|
|
|
for (int i = 1; i < argc; i++) {
|
|
printf("Loading drive %s...\n", argv[i]);
|
|
guestfs_add_drive(g, argv[i]);
|
|
}
|
|
|
|
guestfs_launch(g);
|
|
|
|
char **filesystems = guestfs_list_filesystems(g);
|
|
if (filesystems == NULL)
|
|
return EXIT_FAILURE;
|
|
|
|
for (int i = 0; filesystems[i] != NULL; i += 2) {
|
|
printf("%s:%s is a %s filesystem\n",
|
|
argv[2], filesystems[i], filesystems[i+1]);
|
|
free(filesystems[i]);
|
|
free(filesystems[i+1]);
|
|
}
|
|
free(filesystems);
|
|
|
|
guestfs_mount(g, "/dev/sda3", "/");
|
|
|
|
char *passwd = guestfs_cat(g, "/etc/passwd");
|
|
|
|
printf("passwd contents:\n\n%s", passwd);
|
|
|
|
free(passwd);
|
|
|
|
/* Unmount everything. */
|
|
if (guestfs_umount_all(g) == -1)
|
|
return EXIT_FAILURE;
|
|
|
|
guestfs_shutdown(g);
|
|
|
|
return EXIT_SUCCESS;
|
|
}
|