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
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;
}