-static int global_stats_loop_function(struct osl_row *row, void *data)
-{
- struct global_stats_info *gsi = data;
- struct osl_object obj;
- char *dirname, formated_value[FORMATED_VALUE_SIZE];
- int ret, summary = gsi->flags & GSF_COMPUTE_SUMMARY;
-
- check_signals();
- if (!gsi->count && !summary) {
- ret = -E_LOOP_COMPLETE;
- goto err;
- }
- if (summary || (gsi->count && (gsi->flags & GSF_PRINT_FILES))) {
- uint64_t files;
- ret = osl(osl_get_object(dir_table, row, DT_FILES, &obj));
- if (ret < 0)
- goto err;
- files = *(uint64_t *)obj.data;
- if (gsi->count && (gsi->flags & GSF_PRINT_FILES)) {
- format_count_value(conf.count_unit_arg, files,
- conf.count_unit_arg == count_unit_arg_h,
- formated_value);
- printf("\t%s%s", formated_value,
- (gsi->flags & (GSF_PRINT_BYTES | GSF_PRINT_DIRNAME))?
- "\t" : "\n");
- }
- if (summary)
- num_files += files;
- }
- if (summary || (gsi->count && (gsi->flags & GSF_PRINT_BYTES))) {
- uint64_t bytes;
- ret = osl(osl_get_object(dir_table, row, DT_BYTES, &obj));
- if (ret < 0)
- goto err;
- bytes = *(uint64_t *)obj.data;
- if (gsi->count && (gsi->flags & GSF_PRINT_BYTES)) {
- format_size_value(conf.size_unit_arg, bytes,
- conf.size_unit_arg == size_unit_arg_h,
- formated_value);
- printf("%s%s%s",
- (gsi->flags & GSF_PRINT_FILES)? "" : "\t",
- formated_value,
- (gsi->flags & GSF_PRINT_DIRNAME)? "\t" : "\n"
- );
- }
- if (summary) {
- num_bytes += bytes;
- num_dirs++;
- }
- }
- if (gsi->count && (gsi->flags & GSF_PRINT_DIRNAME)) {
- ret = get_dir_name_of_row(row, &dirname);
- if (ret < 0)
- goto err;
- printf("%s%s\n",
- (gsi->flags & (GSF_PRINT_BYTES | GSF_PRINT_FILES))? "" : "\t",
- dirname);
- free(dirname);
- }
- if (gsi->count > 0)
- gsi->count--;
- return 1;
-err:
- gsi->ret = ret;
- gsi->osl_errno = (ret == -E_OSL)? osl_errno : 0;
- return -1;
-}
-