-static void print_user_stats(void)
-{
- struct user_info *ui;
-
- FOR_EACH_USER(ui) {
- struct user_stats_info usi = {
- .count = conf.limit_arg,
- .ui = ui
- };
- if (!ui_used(ui) || !ui_admissible(ui))
- continue;
- usi.flags = USF_PRINT_DIRNAME | USF_PRINT_BYTES | USF_COMPUTE_SUMMARY;
- printf("************************************************ uid %u\n",
- (unsigned) ui->uid);
- printf("----------------- Largest dirs -------------------\n");
- osl_rbtree_loop_reverse(ui->table, UT_BYTES, &usi,
- user_stats_loop_function);
- printf("---------- dirs containing most files ------------\n");
- usi.count = conf.limit_arg,
- usi.flags = USF_PRINT_DIRNAME | USF_PRINT_FILES;
- osl_rbtree_loop_reverse(ui->table, UT_FILES, &usi,
- user_stats_loop_function);
- }
-}
-
-static int print_statistics(void)
-{
- int ret;
- struct global_stats_info gsi = {
- .count = conf.limit_arg,
- .flags = GSF_PRINT_DIRNAME | GSF_PRINT_BYTES | GSF_COMPUTE_SUMMARY
- };
-
- printf("----------------- Largest dirs -------------------\n");
- ret = osl_rbtree_loop_reverse(dir_table, DT_BYTES, &gsi,
- global_stats_loop_function);
- if (ret < 0 && ret != -E_LOOP_COMPLETE)
- return ret;
- gsi.count = conf.limit_arg;
-
- gsi.flags = GSF_PRINT_DIRNAME | GSF_PRINT_FILES;
- printf("---------- dirs containing most files ------------\n");
- ret = osl_rbtree_loop_reverse(dir_table, DT_FILES, &gsi,
- global_stats_loop_function);
- if (ret < 0 && ret != -E_LOOP_COMPLETE)
- return ret;
-
- printf("------------------ Global summary (dirs/files/bytes)\n"
- "%llu\t%llu\t%llu\n",
- (long long unsigned)num_dirs, (long long unsigned)num_files,
- (long long unsigned)num_bytes);
- print_user_stats();
- print_id_stats();
- return 1;
-}
-
-static char *get_uid_list_name(void)
-{
- return make_message("%s/uid_list", conf.database_dir_arg);
-}
-
-static int write_uid_list(void)
-{
- char *buf, *filename;
- uint32_t count = 0;
- struct user_info *ui;
- size_t size = num_uids * sizeof(uint32_t);
- int ret;
-
- if (!num_uids)
- return 0;
- buf = para_malloc(size);
- FOR_EACH_USER(ui) {
- if (!ui_used(ui) || !ui_admissible(ui))
- continue;
- DEBUG_LOG("saving uid %u\n", (unsigned) ui->uid);
- write_u32(buf + count++ * sizeof(uint32_t), ui->uid);
- }
- filename = get_uid_list_name();
- ret = para_write_file(filename, buf, size);
- free(filename);
- free(buf);
- return ret;
-}
-
-static int open_dir_table(void)
-{
- if (!dir_table_desc.dir) /* we did not create the table */
- dir_table_desc.dir = para_strdup(conf.database_dir_arg);
- return osl_open_table(&dir_table_desc, &dir_table);
-}
-
-static void close_dir_table(void)
-{
- int ret;
-
- if (!dir_table)
- return;
- ret = osl_close_table(dir_table, OSL_MARK_CLEAN);
- if (ret < 0)
- ERROR_LOG("failed to close dir table: %s\n", error_txt(-ret));
- free((char *)dir_table_desc.dir);
- dir_table = NULL;
-}
-
-static void close_user_table(struct user_info *ui)
-{
- int ret;
-
- if (!ui || !ui_used(ui) || !ui_admissible(ui))
- return;
- ret = osl_close_table(ui->table, OSL_MARK_CLEAN);
- if (ret < 0)
- ERROR_LOG("failed to close user table %u: %s\n",
- (unsigned) ui->uid, error_txt(-ret));
- free((char *)ui->desc->name);
- ui->desc->name = NULL;
- free((char *)ui->desc->dir);
- ui->desc->dir = NULL;
- free(ui->desc);
- ui->desc = NULL;
- ui->table = NULL;
- ui->flags = 0;
-}
-
-static void close_user_tables(void)
-{
- struct user_info *ui;
-
- FOR_EACH_USER(ui)
- close_user_table(ui);
-}
-
-static void close_all_tables(void)
-{
- close_dir_table();
- close_user_tables();
- free_hash_table();
-}
-
-static int com_create()