int osl_errno;
};
+struct user_summary_info {
+ struct user_info *ui;
+ int ret;
+ int osl_errno;
+};
+
+
enum user_stats_flags {
USF_PRINT_DIRNAME = 1,
USF_PRINT_BYTES = 2,
return 1;
}
+static int get_num_user_files(struct osl_row *row, struct user_info *ui,
+ uint64_t *num_files)
+{
+ struct osl_object obj;
+ int ret = osl(osl_get_object(ui->table, row, UT_FILES, &obj));
+
+ if (ret < 0)
+ return ret;
+ *num_files = *(uint64_t *)obj.data;
+ return 1;
+}
+
static int get_num_bytes_of_row(struct osl_row *row, uint64_t *num_bytes)
{
struct osl_object obj;
return 1;
}
+static int get_num_user_bytes(struct osl_row *row, struct user_info *ui,
+ uint64_t *num_bytes)
+{
+ struct osl_object obj;
+ int ret = osl(osl_get_object(ui->table, row, UT_BYTES, &obj));
+
+ if (ret < 0)
+ return ret;
+ *num_bytes = *(uint64_t *)obj.data;
+ return 1;
+}
+
static int user_stats_loop_function(struct osl_row *row, void *data)
{
return ret;
}
-static int print_user_summary_line(struct user_info *ui, __a_unused void *data)
+static int user_summary_loop_function(struct osl_row *row, void *data)
+{
+ struct user_summary_info *usi = data;
+ uint64_t num;
+ int ret;
+
+ ret = get_num_user_files(row, usi->ui, &num);
+ if (ret < 0)
+ goto err;
+ usi->ui->files += num;
+ ret = get_num_user_bytes(row, usi->ui, &num);
+ if (ret < 0)
+ goto err;
+ usi->ui->bytes += num;
+ usi->ui->dirs++;
+ return 1;
+err:
+ usi->ret = ret;
+ usi->osl_errno = (ret == -E_OSL)? osl_errno : 0;
+ return -1;
+}
+
+static int compute_user_summary(struct user_info *ui, __a_unused void *data)
+{
+ struct user_summary_info usi = {.ui = ui};
+
+ return adu_loop_reverse(ui->table, UT_BYTES, &usi, user_summary_loop_function,
+ &usi.ret, &usi.osl_errno);
+}
+
+static int print_user_summary_line(struct user_info *ui, void *data)
{
struct format_info *fi = data;
union atom_value values[] = {
ui->pw_name : "?"},
[usa_uid] = {.num_value = (long long unsigned)ui->uid},
[usa_dirs] = {.num_value = (long long unsigned)ui->dirs},
- [usa_files] = {.num_value = (long long unsigned)ui->files},
+ [usa_files] = {.num_value = (long long unsigned)ui->files},
[usa_size] = {.num_value = (long long unsigned)ui->bytes}
};
- char *buf = format_items(fi, values);
- int ret = output("%s", buf);
+ char *buf;
+ int ret;
+ buf = format_items(fi, values);
+ ret = output("%s", buf);
free(buf);
return ret;
}
if (ret < 0)
return ret;
}
+ int ret = for_each_admissible_user(compute_user_summary, fi);
+ if (ret < 0)
+ return ret;
sort_hash_table(summary_comparators[select_conf.user_summary_sort_arg]);
return for_each_admissible_user(print_user_summary_line, fi);
}
if (ret < 0)
return ret;
}
- if (select_conf.sort_arg == sort_arg_files)
+ if (select_conf.list_sort_arg == list_sort_arg_file_count)
sort_column = DT_FILES;
return adu_loop_reverse(dir_table, sort_column, &gli,
global_list_loop_function, &gli.ret, &gli.osl_errno);