Merge commit 'stark/master'
authorAndre Noll <maan@systemlinux.org>
Tue, 20 May 2008 09:24:54 +0000 (11:24 +0200)
committerAndre Noll <maan@systemlinux.org>
Tue, 20 May 2008 09:24:54 +0000 (11:24 +0200)
adu.c

diff --git a/adu.c b/adu.c
index 292501d10cf0ab172fbe57a01032337ae2d8ce95..b311a386690de22071921950cb7a35b29d3d3b2f 100644 (file)
--- a/adu.c
+++ b/adu.c
@@ -90,8 +90,8 @@ int string_compare(const struct osl_object *obj1, const struct osl_object *obj2)
 enum dir_table_columns {
        /** The name of the directory. */
        DT_NAME,
-       /** The hash value of the name. */
-       DT_HASH,
+       /** The dir count number. */
+       DT_NUM,
        /** The number of bytes of all regular files. */
        DT_BYTES,
        /** The number of all regular files. */
@@ -107,12 +107,12 @@ static struct osl_column_description dir_table_cols[] = {
                .name = "dir",
                .compare_function = string_compare,
        },
-       [DT_HASH] = {
+       [DT_NUM] = {
                .storage_type = OSL_MAPPED_STORAGE,
                .storage_flags = OSL_RBTREE | OSL_FIXED_SIZE | OSL_UNIQUE,
-               .name = "hash",
-               .compare_function = osl_hash_compare,
-               .data_size = HASH_SIZE
+               .name = "num",
+               .compare_function = uint32_compare,
+               .data_size = sizeof(uint32_t)
        },
        [DT_BYTES] = {
                .storage_type = OSL_MAPPED_STORAGE,
@@ -192,8 +192,8 @@ static struct osl_table_description id_table_desc = {
 
 /** The columns of the id table. */
 enum user_table_columns {
-       /** The hash of the directory. */
-       UT_DIR_HASH,
+       /** The numer of the directory. */
+       UT_DIR_NUM,
        /** The number of bytes of all regular files in this dir owned by this id. */
        UT_BYTES,
        /** The number of files in this dir owned by this id. */
@@ -203,12 +203,12 @@ enum user_table_columns {
 };
 
 static struct osl_column_description user_table_cols[] = {
-       [UT_DIR_HASH] = {
+       [UT_DIR_NUM] = {
                .storage_type = OSL_MAPPED_STORAGE,
                .storage_flags = OSL_RBTREE | OSL_FIXED_SIZE | OSL_UNIQUE,
-               .name = "dir_hash",
-               .compare_function = osl_hash_compare,
-               .data_size = HASH_SIZE
+               .name = "dir_num",
+               .compare_function = uint32_compare,
+               .data_size = sizeof(uint32_t)
        },
        [IDT_BYTES] = {
                .storage_type = OSL_MAPPED_STORAGE,
@@ -246,17 +246,16 @@ static int create_tables(void)
        return 1;
 }
 
-int add_directory(char *dirname, uint64_t *dir_size, uint64_t *dir_files)
+int add_directory(char *dirname, uint32_t dir_num, uint64_t *dir_size,
+               uint64_t *dir_files)
 {
        struct osl_object dir_objects[NUM_DT_COLUMNS];
-       HASH_TYPE hash[HASH_SIZE];
 
-       INFO_LOG("scanning %s\n", dirname);
+       INFO_LOG("adding #%u: %s\n", dir_num, dirname);
        dir_objects[DT_NAME].data = dirname;
        dir_objects[DT_NAME].size = strlen(dirname) + 1;
-       hash_function(dirname, strlen(dirname), hash);
-       dir_objects[DT_HASH].data = hash;
-       dir_objects[DT_HASH].size = HASH_SIZE;
+       dir_objects[DT_NUM].data = &dir_num;
+       dir_objects[DT_NUM].size = sizeof(dir_num);
        dir_objects[DT_BYTES].data = dir_size;
        dir_objects[DT_BYTES].size = sizeof(*dir_size);
        dir_objects[DT_FILES].data = dir_files;
@@ -336,13 +335,13 @@ static int add_id_bytes(struct osl_row *row, uint64_t *add)
        return osl_update_object(id_table, row, IDT_FILES, &obj2);
 }
 
-static int update_user_row(struct osl_table *t, HASH_TYPE *hash,
+static int update_user_row(struct osl_table *t, uint32_t dir_num,
                uint64_t *add)
 {
        struct osl_row *row;
-       struct osl_object obj = {.data = hash, .size = HASH_SIZE};
+       struct osl_object obj = {.data = &dir_num, .size = sizeof(dir_num)};
 
-       int ret = osl_get_row(t, UT_DIR_HASH, &obj, &row);
+       int ret = osl_get_row(t, UT_DIR_NUM, &obj, &row);
 
        if (ret < 0 && ret != -E_RB_KEY_NOT_FOUND)
                return ret;
@@ -350,8 +349,8 @@ static int update_user_row(struct osl_table *t, HASH_TYPE *hash,
                struct osl_object objects[NUM_UT_COLUMNS];
                uint64_t num_files = 1;
 
-               objects[UT_DIR_HASH].data = hash;
-               objects[UT_DIR_HASH].size = HASH_SIZE;
+               objects[UT_DIR_NUM].data = &dir_num;
+               objects[UT_DIR_NUM].size = sizeof(dir_num);
                objects[UT_BYTES].data = add;
                objects[UT_BYTES].size = sizeof(*add);
                objects[UT_FILES].data = &num_files;
@@ -379,6 +378,8 @@ static int update_user_row(struct osl_table *t, HASH_TYPE *hash,
        }
 }
 
+static uint32_t dir_num;
+
 int scan_dir(char *dirname)
 {
        DIR *dir;
@@ -386,7 +387,6 @@ int scan_dir(char *dirname)
        int ret, cwd_fd, ret2;
        uint64_t dir_size = 0, dir_files = 0;
        struct osl_object obj;
-       HASH_TYPE hash[HASH_SIZE];
 
        INFO_LOG("----------------- %s\n", dirname);
        ret = para_opendir(dirname, &dir, &cwd_fd);
@@ -396,7 +396,6 @@ int scan_dir(char *dirname)
                WARNING_LOG("permission denied for %s\n", dirname);
                return 1;
        }
-       hash_function(dirname, strlen(dirname), hash);
        while ((entry = readdir(dir))) {
                mode_t m;
                char *tmp;
@@ -450,12 +449,12 @@ int scan_dir(char *dirname)
                if (ret < 0)
                        goto out;
                INFO_LOG("user_table: %p\n", user_table);
-               ret = update_user_row(user_table, hash, &size);
+               ret = update_user_row(user_table, dir_num, &size);
                INFO_LOG("update_user  ret: %d\n", ret);
                if (ret < 0)
                        goto out;
        }
-       ret = add_directory(dirname, &dir_size, &dir_files);
+       ret = add_directory(dirname, dir_num++, &dir_size, &dir_files);
 out:
        closedir(dir);
        ret2 = para_fchdir(cwd_fd);
@@ -559,10 +558,10 @@ static int print_big_dir(struct osl_row *row, void *data)
        if (ret < 0)
                return ret;
        bytes = *(uint64_t *)obj.data;
-       ret = osl_get_object(info->user_table, row, UT_DIR_HASH, &obj);
+       ret = osl_get_object(info->user_table, row, UT_DIR_NUM, &obj);
        if (ret < 0)
                return ret;
-       ret = osl_get_row(dir_table, DT_HASH, &obj, &dir_row);
+       ret = osl_get_row(dir_table, DT_NUM, &obj, &dir_row);
        if (ret < 0)
                return ret;
        ret = osl_get_object(dir_table, dir_row, DT_NAME, &obj);