show_super_backingdev(sb, force_csum);
}
-int list_cachesets(char *cset_dir)
+static void list_cacheset_devs(char *cset_dir, char *cset_name) {
+ int i = 0;
+ DIR *cachedir;
+ struct stat cache_stat;
+ char intbuf[4];
+ char entry[256];
+
+ strcpy(entry, cset_dir);
+ strcat(entry, "/");
+ strcat(entry, cset_name);
+ strcat(entry, "/cache0");
+ snprintf(intbuf, 4, "%d", i);
+
+ while(true) {
+ char buf[256];
+ int len;
+
+ if((cachedir = opendir(entry)) == NULL)
+ break;
+
+ if(stat(entry, &cache_stat))
+ break;
+
+ if((len = readlink(entry, buf, sizeof(buf) - 1)) != -1) {
+ buf[len] = '\0';
+ printf("\t%s\n", buf);
+ }
+
+ /* remove i from end and append i++ */
+ entry[strlen(entry)-strlen(intbuf)] = 0;
+ i++;
+ snprintf(intbuf, 4, "%d", i);
+ strcat(entry, intbuf);
+ }
+}
+
+int list_cachesets(char *cset_dir, bool list_devs)
{
struct dirent *ent;
DIR *dir = opendir(cset_dir);
while ((ent = readdir(dir)) != NULL) {
struct stat statbuf;
- char entry[100];
+ char entry[256];
+ struct dirent *cache_ent;
if (!strcmp(ent->d_name, ".") || !strcmp(ent->d_name, ".."))
continue;
strcpy(entry, cset_dir);
strcat(entry, "/");
strcat(entry, ent->d_name);
+
if(stat(entry, &statbuf) == -1) {
fprintf(stderr, "Failed to stat %s\n", entry);
return 1;
}
+
if (S_ISDIR(statbuf.st_mode)) {
printf("%s\n", ent->d_name);
+
+ if(list_devs) {
+ list_cacheset_devs(cset_dir, ent->d_name);
+ }
}
}
void show_super_cache(struct cache_sb *, bool);
struct cache_sb *query_dev(char *, bool);
-int list_cachesets(char *);
+int list_cachesets(char *, bool);
char *parse_array_to_list(char *const *);
int register_bcache();
int probe(char *, int);
/* list globals */
char *cset_dir = "/sys/fs/bcache";
+bool list_devs = false;
/* status globals */
bool status_all = false;
static NihOption list_cachesets_options[] = {
{'d', "dir", N_("directory"), NULL, NULL, &cset_dir, NULL},
+ {0, "list-devs", N_("list all devices in the cache sets as well"), NULL, NULL, &list_devs, NULL},
NIH_OPTION_LAST
};
int bcache_list_cachesets (NihCommand *command, char *const *args)
{
- return list_cachesets(cset_dir);
+ return list_cachesets(cset_dir, list_devs);
}
int bcache_query_devs (NihCommand *command, char *const *args)
for (i = 0; args[i] != NULL; i++) {
- printf("query-devs on :%s\n", args[i]);
+ printf("query-devs on: %s\n", args[i]);
struct cache_sb *sb = query_dev(args[i], false);
print_dev_info(sb, force_csum);
}