2

I want a convenient API in c to get the list of sub-volumes in the given btrfs partition as listed out when we run the command below.

btrfs subvolume list btrfs/subvol/path

Pramod Aithal
  • 93
  • 1
  • 9

1 Answers1

1

If you can't find a convenient API, popen is what you want:

#include <stdio.h>

FILE *popen(const char *command, const char *mode);
int pclose(FILE *stream);

int main(void)
{
    FILE *cmd = popen("btrfs subvolume list btrfs/subvol/path", "r");
    char result[128];

    while (fgets(result, sizeof(result), cmd) != NULL)
           printf("%s", result);
    pclose(cmd);
    return 0;
}
David Ranieri
  • 39,972
  • 7
  • 52
  • 94