File: btrfs.helper.cpp

package info (click to toggle)
etbemon 1.4.2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,624 kB
  • sloc: perl: 18,038; cpp: 546; sh: 428; ansic: 407; makefile: 71
file content (69 lines) | stat: -rw-r--r-- 1,468 bytes parent folder | download | duplicates (4)
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#include <stdio.h>
#include <sys/types.h>
#include <unistd.h>
#include <sys/wait.h>

int main(int argc, char **argv)
{
  if(argc != 2)
  {
    fprintf(stderr, "ERROR: Must specify mountpoint of BTRFS filesystem\n");
    return 1;
  }
  pid_t pid = fork();
  if(-1 == pid)
  {
    fprintf(stderr, "ERROR: Fork failed\n");
    return 1;
  }
  else if(pid)
  {
    int wstatus = 0;
    if(wait(&wstatus) == -1)
    {
      fprintf(stderr, "ERROR: wait(2) error\n");
      return 1;
    }
    if(!WIFEXITED(wstatus) || WEXITSTATUS(wstatus))
    {
      fprintf(stderr, "ERROR: Error running btrfs device stats\n");
      return 1;
    }
  }
  else
  {
    char * const child_args[] = { "/bin/btrfs", "device", "stats", argv[1], NULL };
    execv(child_args[0], child_args);
    fprintf(stderr, "ERROR: Can't execute %s\n", child_args[0]);
    return 1;
  }

  pid = fork();
  if(-1 == pid)
  {
    fprintf(stderr, "ERROR: Fork failed\n");
    return 1;
  }
  else if(pid)
  {
    int wstatus = 0;
    if(wait(&wstatus) == -1)
    {
      fprintf(stderr, "ERROR: wait(2) error\n");
      return 1;
    }
    if(!WIFEXITED(wstatus) || WEXITSTATUS(wstatus))
    {
      fprintf(stderr, "ERROR: Error running btrfs subvol list\n");
      return 1;
    }
  }
  else
  {
    char * const child_args[] = { "/bin/btrfs", "subvol", "list", argv[1], NULL };
    execv(child_args[0], child_args);
    fprintf(stderr, "ERROR: Can't execute %s\n", child_args[0]);
    return 1;
  }
}