+err:
+ gsi->ret = ret;
+ gsi->osl_errno = (ret == -E_OSL)? osl_errno : 0;
+ return ret;
+}
+
+static int print_global_summary(struct format_info *fi)
+{
+ int ret;
+ char *buf;
+ struct global_summary_info gsi = {.num_dirs = 0};
+ char *header = select_conf.header_given? select_conf.header_arg :
+ "Global summary\n";
+
+ union atom_value values[] = {
+ [gsa_dirs] = {.num_value = 0ULL},
+ [gsa_files] = {.num_value = 0ULL},
+ [gsa_size] = {.num_value = 0ULL}
+ };
+
+ ret = compile_regex(&gsi.preg, &gsi.inverse_matching);
+ if (ret < 0)
+ return ret;
+ ret = adu_loop_reverse(dir_table, DT_BYTES, &gsi,
+ global_summary_loop_function, &gsi.ret, &gsi.osl_errno);
+ free_regex(gsi.preg);
+ if (ret < 0)
+ return ret;
+ values[gsa_dirs].num_value = (long long unsigned)gsi.num_dirs;
+ values[gsa_files].num_value = (long long unsigned)gsi.num_files;
+ values[gsa_size].num_value = (long long unsigned)gsi.num_bytes;
+
+ ret = output("%s", header);
+ if (ret < 0)
+ return ret;
+ buf = format_items(fi, values);
+ ret = output("%s", buf);
+ free(buf);
+ return ret;
+}
+
+static int user_summary_loop_function(struct osl_row *row, void *data)
+{
+ struct user_summary_info *usi = data;
+ uint64_t num;
+ int ret;
+
+ if (usi->preg) {
+ char *dirname;
+ ret = get_dir_name_of_row(row, &dirname);
+ if (ret < 0)
+ goto err;
+ ret = dir_is_admissible(dirname, usi->preg, usi->inverse_matching);
+ free(dirname);
+ if (!ret)
+ return 1;
+ }
+ ret = get_num_user_files(row, usi->ui, &num);
+ if (ret < 0)
+ goto err;
+ usi->files += num;
+ ret = get_num_user_bytes(row, usi->ui, &num);
+ if (ret < 0)
+ goto err;
+ usi->bytes += num;
+ usi->dirs++;
+ return 1;
+err:
+ usi->ret = ret;
+ usi->osl_errno = (ret == -E_OSL)? osl_errno : 0;
+ return ret;
+}
+
+static int compute_user_summary(struct user_info *ui, void *data)
+{
+ struct user_summary_loop_data *usld = data;
+ struct user_summary_info *usi = usld->current++;
+ int ret = compile_regex(&usi->preg, &usi->inverse_matching);
+
+ if (ret < 0)
+ return ret;
+ usi->ui = ui;
+ ret = adu_loop_reverse(ui->table, UT_BYTES, usi, user_summary_loop_function,
+ &usi->ret, &usi->osl_errno);
+ free_regex(usi->preg);
+ return ret;
+}
+
+static int print_user_summary_line(struct user_summary_info *usi,
+ struct format_info *fi)
+{
+ struct user_info *ui = usi->ui;
+ union atom_value values[] = {
+ [usa_pw_name] = {.string_value = ui->pw_name?
+ ui->pw_name : "?"},
+ [usa_uid] = {.num_value = (long long unsigned)ui->uid},
+ [usa_dirs] = {.num_value = (long long unsigned)usi->dirs},
+ [usa_files] = {.num_value = (long long unsigned)usi->files},
+ [usa_size] = {.num_value = (long long unsigned)usi->bytes}
+ };
+ char *buf = format_items(fi, values);
+ int ret = output("%s", buf);
+
+ free(buf);
+ return ret;