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. */
.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,
/** 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. */
};
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,
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;
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;
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;
}
}
+static uint32_t dir_num;
+
int scan_dir(char *dirname)
{
DIR *dir;
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);
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;
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);
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);