18#define DBG_TAG "DFS.dentry"
19#define DBG_LVL DBG_WARNING
22#define DFS_DENTRY_HASH_NR 32
23struct dentry_hash_head
27static struct dentry_hash_head hash_head;
29static uint32_t _dentry_hash(
struct dfs_mnt *mnt,
const char *path)
37 val = ((val << 5) + val) + *path++;
55 char *dentry_path = path;
60 if (rt_strncmp(
mnt->
fullpath, dentry_path, mntpoint_len) == 0)
62 dentry_path += mntpoint_len;
66 dentry->
pathname = strlen(dentry_path) ? rt_strdup(dentry_path) : rt_strdup(path);
72 LOG_I(
"create a dentry:%p for %s", dentry, fullpath);
85 return _dentry_create(
mnt, rela_path,
RT_TRUE);;
123 DLOG(msg,
"dentry",
"dentry", DLOG_MSG,
"free dentry, ref_count=0");
136 DLOG(msg,
"dentry",
"mnt", DLOG_MSG,
"dfs_mnt_unref(dentry->mnt)");
144 LOG_I(
"free a dentry: %p", dentry);
205 if (rt_strncmp(
mnt->
fullpath, path, mntpoint_len) == 0)
207 path += mntpoint_len;
215 dentry = _dentry_hash_lookup(
mnt, path);
220 DLOG(activate,
"dentry");
222 DLOG(msg,
"dentry",
"dentry", DLOG_MSG,
"dfs_dentry_create_rela(mnt=%s, path=%s)",
mnt->
fullpath, path);
226 DLOG(msg,
"dentry",
mnt->
fs_ops->
name, DLOG_MSG,
"vnode=fs_ops->lookup(dentry)");
236 dentry->
vnode = vnode;
257 DLOG(msg,
"dentry",
"dentry", DLOG_MSG,
"dfs_dentry_unref(dentry)");
262 DLOG(deactivate,
"dentry");
267 DLOG(note,
"dentry",
"found dentry");
277 if (dentry && dentry->
mnt)
280 int path_len = strlen(dentry->
pathname);
282 path = (
char *)
rt_malloc(mnt_len + path_len + 3);
287 rt_snprintf(path, mnt_len + path_len + 2,
"%s%s", dentry->
mnt->
fullpath,
292 rt_snprintf(path, mnt_len + path_len + 2,
"%s/%s", dentry->
mnt->
fullpath,
306 index = strrchr(dentry->
pathname,
'/');
309 int length = index - dentry->
pathname;
310 int path_length = strlen(dentry->
mnt->
fullpath) + length + 3;
312 pathname = (
char*)
rt_malloc(path_length);
317 rt_snprintf(pathname, path_length - 1,
"%s%.*s", dentry->
mnt->
fullpath,
322 rt_snprintf(pathname, path_length - 1,
"%s/%.*s", dentry->
mnt->
fullpath,
337 uint32_t crc32 = 0xFFFFFFFF;
343 while(fullpath[i] !=
'\0')
345 for (uint8_t b = 1; b; b <<= 1)
347 crc32 ^= (fullpath[i] & b) ? 1 : 0;
348 crc32 = (crc32 & 1) ? crc32 >> 1 ^ 0xEDB88320 : crc32 >> 1;
struct dfs_dentry * dfs_dentry_create(struct dfs_mnt *mnt, char *fullpath)
struct dfs_dentry * dfs_dentry_lookup(struct dfs_mnt *mnt, const char *path, uint32_t flags)
int dfs_dentry_init(void)
#define DFS_DENTRY_HASH_NR
struct dfs_dentry * dfs_dentry_unref(struct dfs_dentry *dentry)
uint32_t dfs_dentry_full_path_crc32(struct dfs_dentry *dentry)
char * dfs_dentry_full_path(struct dfs_dentry *dentry)
void dfs_dentry_insert(struct dfs_dentry *dentry)
struct dfs_dentry * dfs_dentry_create_rela(struct dfs_mnt *mnt, char *rela_path)
char * dfs_dentry_pathname(struct dfs_dentry *dentry)
int dfs_dentry_dump(int argc, char **argv)
struct dfs_dentry * dfs_dentry_ref(struct dfs_dentry *dentry)
#define DENTRY_IS_ADDHASH
#define DENTRY_IS_ALLOCED
int dfs_is_mounted(struct dfs_mnt *mnt)
int dfs_mnt_unref(struct dfs_mnt *mnt)
struct dfs_mnt * dfs_mnt_ref(struct dfs_mnt *mnt)
void dfs_vnode_unref(struct dfs_vnode *vnode)
void dfs_file_unlock(void)
rt_err_t dfs_file_lock(void)
rt_inline void rt_list_remove(rt_list_t *n)
remove node from list.
rt_weak void * rt_calloc(rt_size_t count, rt_size_t size)
This function will contiguously allocate enough space for count objects that are size bytes of memory...
rt_inline void rt_list_init(rt_list_t *l)
initialize a list
rt_inline void rt_list_insert_after(rt_list_t *l, rt_list_t *n)
insert a node after a list
#define rt_list_for_each_entry(pos, head, member)
rt_weak void rt_free(void *ptr)
This function will release the previously allocated memory block by rt_malloc. The released memory bl...
rt_weak void * rt_malloc(rt_size_t size)
Allocate a block of memory with a minimum of 'size' bytes.
#define MSH_CMD_EXPORT_ALIAS(...)
#define rt_atomic_sub(ptr, v)
#define rt_atomic_add(ptr, v)
#define rt_atomic_store(ptr, v)
#define rt_atomic_load(ptr)
struct rt_list_node rt_list_t
struct dfs_vnode *(* lookup)(struct dfs_dentry *dentry)
const struct dfs_filesystem_ops * fs_ops