From 1b5642c78995f2468e14380252826cdfccb92632 Mon Sep 17 00:00:00 2001 From: Andre Noll Date: Sun, 25 May 2008 18:35:41 +0200 Subject: [PATCH] Write the list of all uids to a file. The select command will need this. --- adu.c | 37 +++++++++++++++++++++++++++++++++++-- 1 file changed, 35 insertions(+), 2 deletions(-) diff --git a/adu.c b/adu.c index 20f0f61..5f674dc 100644 --- a/adu.c +++ b/adu.c @@ -196,6 +196,8 @@ int add_directory(char *dirname, uint32_t dir_num, uint64_t *dir_size, return osl_add_row(dir_table, dir_objects); } +static uint32_t num_uids; + int create_and_open_user_table(uint32_t uid, struct osl_table **t) { int ret; @@ -206,7 +208,9 @@ int create_and_open_user_table(uint32_t uid, struct osl_table **t) desc->column_descriptions = user_table_cols; desc->dir = para_strdup(DATABASE_DIR); desc->name = make_message("%u", uid); - INFO_LOG("................................. %u\n", uid); + num_uids++; + INFO_LOG(".............................uid #%u: %u\n", + (unsigned)num_uids, (unsigned)uid); // user_table_desc.name = make_message("%u", uid); ret = osl_create_table(desc); if (ret < 0) @@ -523,6 +527,35 @@ static int print_statistics(void) return 1; } +static int write_uid_list(void) +{ + char *buf, *filename = DATABASE_DIR "/" "uid_list"; + 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->table) + continue; + write_u32(buf + count++ * sizeof(uint32_t), ui->uid); + } + ret = para_write_file(filename, buf, size); + free(buf); + return ret; +} + +static int com_create(char *dirname) +{ + int ret = scan_dir(dirname); + + if (ret < 0) + return ret; + return write_uid_list(); +} int main(int argc, char **argv) { @@ -535,7 +568,7 @@ int main(int argc, char **argv) ret = -E_SYNTAX; if (argc != 2) goto out; - ret = scan_dir(argv[1]); + ret = com_create(argv[1]); if (ret < 0) goto out; print_statistics(); -- 2.39.5