src/tools/bsnapshot.c
int subvolumes() {
      rblist      *lst;
      struct stat  sp;
      struct vols *elt1 = NULL;
      char   ed1[50];

      Mmsg(cmd, "%sbtrfs subvolume show \"%s\"", arg->sudo, arg->mountpoint);
      if (run_program_full_output(cmd, 300, errmsg)) {
         Dmsg(10, "Unable to get information %s\n", errmsg);
         strip_quotes(errmsg);
         printf("status=0 type=btrfs error=\"%s\"\n", errmsg);
         return 0;
      }

      /* TODO: Very week way to analyse FS */
      if (!strstr(errmsg, "is btrfs root")) {
         printf("status=0 type=btrfs error=\"Not btrfs root fs\"\n");
         return 0;
      }
      
      Mmsg(cmd, "%sbtrfs subvolume list -s \"%s\"", arg->sudo, arg->mountpoint);
      if (run_program_full_output(cmd, 300, errmsg)) {
         Dmsg(10, "Unable to list snapshot snapshot %s\n", errmsg);
         strip_quotes(errmsg);
         printf("status=0 type=btrfs error=\"%s\"\n", errmsg);
         return 0;
      }

      lst = New(rblist(elt1, &elt1->link));
      scan_subvolumes(errmsg, lst);

      Mmsg(cmd, "%sbtrfs subvolume list \"%s\"", arg->sudo, arg->mountpoint);
      if (run_program_full_output(cmd, 300, errmsg)) {
         Dmsg(10, "Unable to list subvolume %s\n", errmsg);
         strip_quotes(errmsg);
         printf("status=0 type=btrfs error=\"%s\"\n", errmsg);
         delete lst;
         return 0;
      }
      scan_subvolumes(errmsg, lst);

      foreach_rblist(elt1, lst) {
         if (elt1->count > 0) { /* Looks to be a snapshot, we saw two entries */
            continue;
         }

         path_concat(path, arg->mountpoint, elt1->path, NULL);

         if (stat(path, &sp) == 0) {
            printf("dev=%s mountpoint=\"%s\" fstype=btrfs\n", 
                   edit_uint64(sp.st_dev, ed1), path);

         } else {
            Dmsg(10, "Unable to stat %s (%s)\n", elt1->path, path);
         }
      }
      delete lst;
      return 1;
   }
/* List subvolumes, they may not be listed by mount */
List subvolumes, they may not be listed by mount
List subvolumes they may not be listed by mount
int subvolumes() {
      rblist      *lst;
      struct stat  sp;
      struct vols *elt1 = NULL;
      char   ed1[50];
      Mmsg(cmd, "%sbtrfs subvolume show \"%s\"", arg->sudo, arg->mountpoint);
      if (run_program_full_output(cmd, 300, errmsg)) {
         Dmsg(10, "Unable to get information %s\n", errmsg);
         strip_quotes(errmsg);
         printf("status=0 type=btrfs error=\"%s\"\n", errmsg);
         return 0;
      }
      if (!strstr(errmsg, "is btrfs root")) {
         printf("status=0 type=btrfs error=\"Not btrfs root fs\"\n");
         return 0;
      }
      Mmsg(cmd, "%sbtrfs subvolume list -s \"%s\"", arg->sudo, arg->mountpoint);
      if (run_program_full_output(cmd, 300, errmsg)) {
         Dmsg(10, "Unable to list snapshot snapshot %s\n", errmsg);
         strip_quotes(errmsg);
         printf("status=0 type=btrfs error=\"%s\"\n", errmsg);
         return 0;
      }
      lst = New(rblist(elt1, &elt1->link));
      scan_subvolumes(errmsg, lst);
      Mmsg(cmd, "%sbtrfs subvolume list \"%s\"", arg->sudo, arg->mountpoint);
      if (run_program_full_output(cmd, 300, errmsg)) {
         Dmsg(10, "Unable to list subvolume %s\n", errmsg);
         strip_quotes(errmsg);
         printf("status=0 type=btrfs error=\"%s\"\n", errmsg);
         delete lst;
         return 0;
      }
      scan_subvolumes(errmsg, lst);
      foreach_rblist(elt1, lst) {
         if (elt1->count > 0) { 
            continue;
         }
         path_concat(path, arg->mountpoint, elt1->path, NULL);
         if (stat(path, &sp) == 0) {
            printf("dev=%s mountpoint=\"%s\" fstype=btrfs\n", 
                   edit_uint64(sp.st_dev, ed1), path);
         } else {
            Dmsg(10, "Unable to stat %s (%s)\n", elt1->path, path);
         }
      }
      delete lst;
      return 1;
   }
int subvolumes ( ) { rblist * lst ; struct stat sp ; struct vols * elt1 = NULL ; char ed1 [ 50 ] ; Mmsg ( cmd , " \" \" " , arg -> sudo , arg -> mountpoint ) ; if ( run_program_full_output ( cmd , 300 , errmsg ) ) { Dmsg ( 10 , " \n " , errmsg ) ; strip_quotes ( errmsg ) ; printf ( " \" \" \n " , errmsg ) ; return 0 ; } if ( ! strstr ( errmsg , " " ) ) { printf ( " \" \" \n " ) ; return 0 ; } Mmsg ( cmd , " \" \" " , arg -> sudo , arg -> mountpoint ) ; if ( run_program_full_output ( cmd , 300 , errmsg ) ) { Dmsg ( 10 , " \n " , errmsg ) ; strip_quotes ( errmsg ) ; printf ( " \" \" \n " , errmsg ) ; return 0 ; } lst = New ( rblist ( elt1 , & elt1 -> link ) ) ; scan_subvolumes ( errmsg , lst ) ; Mmsg ( cmd , " \" \" " , arg -> sudo , arg -> mountpoint ) ; if ( run_program_full_output ( cmd , 300 , errmsg ) ) { Dmsg ( 10 , " \n " , errmsg ) ; strip_quotes ( errmsg ) ; printf ( " \" \" \n " , errmsg ) ; delete lst ; return 0 ; } scan_subvolumes ( errmsg , lst ) ; foreach_rblist ( elt1 , lst ) { if ( elt1 -> count > 0 ) { continue ; } path_concat ( path , arg -> mountpoint , elt1 -> path , NULL ) ; if ( stat ( path , & sp ) == 0 ) { printf ( " \" \" \n " , edit_uint64 ( sp . st_dev , ed1 ) , path ) ; } else { Dmsg ( 10 , " \n " , elt1 -> path , path ) ; } } delete lst ; return 1 ; }
List subvolumes, they may not be listed by mount
List subvolumes they may not be listed by mount
/* TODO: Very week way to analyse FS */ /* Looks to be a snapshot, we saw two entries */