-static void print_global_summary(void)
-{
- char d[FORMATED_VALUE_SIZE], f[FORMATED_VALUE_SIZE],
- s[FORMATED_VALUE_SIZE];
- enum enum_count_unit ud, uf;
- enum enum_size_unit us;
-
- if (conf.no_global_summary_given)
- return;
- ud = format_count_value(select_conf.count_unit_arg, num_dirs, 0, d);
- uf = format_count_value(select_conf.count_unit_arg, num_files, 0, f);
- us = format_size_value(select_conf.size_unit_arg, num_bytes, 0, s);
-
- if (!conf.no_headers_given)
- printf("Global summary "
- "(dirs(%c)/files(%c)/size(%c))\n",
- count_unit_abbrevs[ud],
- count_unit_abbrevs[uf],
- size_unit_abbrevs[us]
- );
- printf("\t%s\t%s\t%s\n\n", d, f, s);
-}
-
-static int print_user_summary_line(struct user_info *ui, __a_unused void *data)
-{
- char formated_dir_count[FORMATED_VALUE_SIZE],
- formated_file_count[FORMATED_VALUE_SIZE],
- formated_bytes[FORMATED_VALUE_SIZE ];
-
- format_count_value(select_conf.count_unit_arg, ui->dirs,
- select_conf.count_unit_arg == count_unit_arg_h,
- formated_dir_count);
- format_count_value(select_conf.count_unit_arg, ui->files,
- select_conf.count_unit_arg == count_unit_arg_h,
- formated_file_count);
- format_size_value(select_conf.size_unit_arg, ui->bytes,
- select_conf.size_unit_arg == size_unit_arg_h,
- formated_bytes);
- printf("\t%s\t%u\t%s\t%s\t%s\n",
- ui->pw_name? ui->pw_name : "?",
- (unsigned)ui->uid,
- formated_dir_count,
- formated_file_count,
- formated_bytes
- );
+static int global_summary_loop_function(struct osl_row *row, void *data)
+{
+ struct global_summary_info *gsi = data;
+ int ret;
+ uint64_t num;
+
+ ret = get_num_files_of_row(row, &num);
+ if (ret < 0)
+ goto err;
+ gsi->num_files += num;
+
+ ret = get_num_bytes_of_row(row, &num);
+ if (ret < 0)
+ goto err;
+ gsi->num_bytes += num;
+ gsi->num_dirs++;
+ return 1;
+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};
+
+ union atom_value values[] = {
+ [gsa_dirs] = {.num_value = 0ULL},
+ [gsa_files] = {.num_value = 0ULL},
+ [gsa_size] = {.num_value = 0ULL}
+ };
+
+ ret = adu_loop_reverse(dir_table, DT_BYTES, &gsi,
+ global_summary_loop_function, &gsi.ret, &gsi.osl_errno);
+ 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;
+ if (!select_conf.no_headers_given) {
+ ret = output("Global summary\n");
+ 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;
+
+ 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++;