Add \brief command to file header to make doxygen happy.
[adu.git] / create.c
index 5c243d8..3a221ca 100644 (file)
--- a/create.c
+++ b/create.c
@@ -4,51 +4,21 @@
  * Licensed under the GPL v2. For licencing details see COPYING.
  */
 
-/** \file create.c The create mode of adu. */
+/** \file create.c \brief The create mode of adu. */
 
 #include <dirent.h> /* readdir() */
+#include "format.h"
 #include "adu.h"
 #include "gcc-compat.h"
 #include "cmdline.h"
 #include "fd.h"
 #include "string.h"
 #include "error.h"
-#include "portable_io.h"
+#include "user.h"
 
 /* Id of the device containing the base dir. */
 static dev_t device_id;
 
-static int write_uid(struct user_info *ui, void *data)
-{
-       char **p = data;
-
-       write_u32(*p, ui->uid);
-       *p += sizeof(uint32_t);
-       return 1;
-}
-
-static int write_uid_list(void)
-{
-       char *buf, *p, *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 = p = adu_malloc(size);
-       ret = for_each_admissible_user(write_uid, &p);
-       if (ret < 0)
-               goto out;
-       filename = get_uid_list_name();
-       ret = adu_write_file(filename, buf, size);
-       free(filename);
-out:
-       free(buf);
-       return ret;
-}
-
 static int add_directory(char *dirname, uint64_t *dir_num, uint64_t *parent_dir_num,
                uint64_t *dir_size, uint64_t *dir_files)
 {
@@ -88,9 +58,7 @@ static int update_user_row(struct osl_table *t, uint64_t dir_num,
                objects[UT_BYTES].size = sizeof(*add);
                objects[UT_FILES].data = &num_files;
                objects[UT_FILES].size = sizeof(num_files);
-               INFO_LOG("######################### ret: %d\n", ret);
                ret = osl(osl_add_row(t, objects));
-               INFO_LOG("######################### ret: %d\n", ret);
                return ret;
        } else { /* add size and increment file count */
                uint64_t num;
@@ -133,7 +101,7 @@ static int scan_dir(char *dirname, uint64_t *parent_dir_num)
        }
        while ((entry = readdir(dir))) {
                mode_t m;
-               struct stat s;
+               struct stat64 s;
                uint32_t uid;
                uint64_t size;
                struct user_info *ui;
@@ -142,8 +110,8 @@ static int scan_dir(char *dirname, uint64_t *parent_dir_num)
                        continue;
                if (!strcmp(entry->d_name, ".."))
                        continue;
-               if (lstat(entry->d_name, &s) == -1) {
-                       WARNING_LOG("lstat error for %s/%s (%s)\n",
+               if (lstat64(entry->d_name, &s) == -1) {
+                       WARNING_LOG("lstat64 error for %s/%s (%s)\n",
                                dirname, entry->d_name, strerror(errno));
                        continue;
                }
@@ -163,7 +131,7 @@ static int scan_dir(char *dirname, uint64_t *parent_dir_num)
                dir_size += size;
                dir_files++;
                uid = s.st_uid;
-               ret = search_uid(uid, CREATE_USER_TABLE | OPEN_USER_TABLE, &ui);
+               ret = create_user_table(uid, &ui);
                if (ret < 0)
                        goto out;
                ui->bytes += size;
@@ -183,7 +151,7 @@ out:
        return ret;
 }
 
-int com_create()
+int com_create(void)
 {
        uint64_t zero = 0ULL;
        int ret;
@@ -202,8 +170,7 @@ int com_create()
        ret = scan_dir(conf.base_dir_arg, &zero);
        if (ret < 0)
                goto out;
-       ret = write_uid_list();
+       ret = write_uid_file();
 out:
-       close_all_tables();
        return ret;
 }