- DIR *dir;
- struct dirent *entry;
- int ret, cwd_fd, ret2;
- uint64_t dir_size = 0, dir_files = 0;
- struct osl_object obj;
-
- INFO_LOG("----------------- %s\n", dirname);
- ret = para_opendir(dirname, &dir, &cwd_fd);
- if (ret < 0) {
- if (ret != -ERRNO_TO_ERROR(EACCES))
- return ret;
- WARNING_LOG("permission denied for %s\n", dirname);
- return 1;
- }
- while ((entry = readdir(dir))) {
- mode_t m;
- char *tmp;
- struct stat s;
- uint32_t uid;
- uint64_t size;
- struct osl_row *id_row;
- struct osl_table *user_table;
-
- if (!strcmp(entry->d_name, "."))
- continue;
- if (!strcmp(entry->d_name, ".."))
- continue;
- if (lstat(entry->d_name, &s) == -1)
- continue;
- m = s.st_mode;
- if (!S_ISREG(m) && !S_ISDIR(m))
- continue;
- if (S_ISDIR(m)) {
- tmp = make_message("%s/%s", dirname, entry->d_name);
- ret = scan_dir(tmp);
- free(tmp);
- if (ret < 0)
- goto out;
- continue;
- }
- /* regular file */
- size = s.st_size;
- dir_size += size;
- dir_files++;
- uid = s.st_uid;
- INFO_LOG("++++++++++++++++++++++++++ %s, uid: %u\n", entry->d_name, uid);
- obj.data = &uid;
- obj.size = sizeof(uid);
- ret = osl_get_row(id_table, IDT_UID, &obj, &id_row);
- if (ret < 0 && ret != -E_RB_KEY_NOT_FOUND)
- goto out;
- if (ret < 0) {
- ret = create_and_open_user_table(uid, &user_table);
- if (ret < 0)
- goto out;
- ret = insert_id_row(uid, user_table, &id_row);
- if (ret < 0)
- goto out;
- } else {
- ret = get_user_table(id_row, &user_table);
- if (ret < 0)
- goto out;
- }
- ret = add_id_bytes(id_row, &size);
- if (ret < 0)
- goto out;
- INFO_LOG("user_table: %p\n", user_table);
- 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_num++, &dir_size, &dir_files);
-out:
- closedir(dir);
- ret2 = para_fchdir(cwd_fd);
- if (ret2 < 0 && ret >= 0)
- ret = ret2;
- close(cwd_fd);
- return ret;