dentry_rehash(dentry);
}
-dentry_t *dentry_cached_lookup(dentry_t *parent, qstr_t *s) {
+int dentry_cached_lookup(dentry_t *parent, qstr_t *s, dentry_t **dentry) {
dentry_hash_entry_t *dhe = dentry_hash(parent, s->hash);
- dentry_t *dentry = NULL;
+ *dentry = NULL;
mutex_lock(&dhe->mutex);
list_head_t *p;
list_for_each(p, &dhe->list) {
- dentry = list_entry(p, dentry_t, d_hash);
- assert(dentry != NULL);
+ *dentry = list_entry(p, dentry_t, d_hash);
+ assert(*dentry != NULL);
- if (dentry->d_name.hash != s->hash) {
+ if ((*dentry)->d_name.hash != s->hash) {
continue;
}
- if (dentry->d_name.len != s->len) {
+ if ((*dentry)->d_name.len != s->len) {
continue;
}
- if (dentry->d_parent != parent) {
+ if ((*dentry)->d_parent != parent) {
continue;
}
- if (memcmp(dentry->d_name.name, s->name, s->len) != 0) {
+ if (memcmp((*dentry)->d_name.name, s->name, s->len) != 0) {
continue;
}
- dentry_get_locked(dentry);
+ dentry_get_locked(*dentry);
mutex_unlock(&dhe->mutex);
- return dentry;
+ return 0;
}
mutex_unlock(&dhe->mutex);
- return NULL;
+ return 0;
}
+
int dentry_real_lookup(dentry_t *parent, qstr_t *s, dentry_t **dentry) {
*dentry = NULL;
int ret = 0;
// 在获得信号量后,需要再上cache中查找一遍
// 因为这个过程中当前进程可能会睡眠,当被唤醒后,其它进程已经在内存准备好了
- *dentry = dentry_cached_lookup(parent, s);
+ ret = dentry_cached_lookup(parent, s, dentry);
+ assert(0 == ret);
if (NULL != *dentry) {
up(&dir->i_sem);
}
}
- dentry_t *dentry;
- dentry = path_lookup_create(&ni);
- ret = PTR_ERR(dentry);
- if (!IS_ERR(dentry)) {
+ dentry_t *dentry = NULL;
+ ret = path_lookup_create(&ni, &dentry);
+ if (0 != ret) {
+ assert(dentry == NULL);
ret = vfs_mkdir(ni.path.dentry->d_inode, dentry, mode);
dentry_put(dentry);
+ } else {
+ assert(dentry != NULL);
}
up(&ni.path.dentry->d_inode->i_sem);
compute_qstr_hash(&this);
// 根据该名字,先上dentry cache里找
- dentry = dentry_cached_lookup(ni->path.dentry, &this);
+ ret = dentry_cached_lookup(ni->path.dentry, &this, &dentry);
+ assert(0 == ret);
// 如果找不到就上实际存储设备中去找
if (NULL == dentry) {
// printk("HASH %s %lu\n", this.name, this.hash);
// 根据该名字,先上dentry cache里找
- dentry = dentry_cached_lookup(ni->path.dentry, &this);
+ ret = dentry_cached_lookup(ni->path.dentry, &this, &dentry);
+ assert(0 == ret);
// 如果找不到就上实际存储设备中去找
if (NULL == dentry) {
return ret;
}
-dentry_t *path_lookup_hash(dentry_t *base, qstr_t *name) {
- dentry_t *dentry = NULL;
-
+int path_lookup_hash(dentry_t *base, qstr_t *name, dentry_t **dentry) {
+ int ret = 0;
inode_t *inode = base->d_inode;
- dentry = dentry_cached_lookup(base, name);
- if (dentry != NULL) {
- return dentry;
+ ret = dentry_cached_lookup(base, name, dentry);
+ assert(0 == ret);
+ if (*dentry != NULL) {
+ return 0;
}
dentry_t *dentry_new = dentry_alloc(base, name);
if (dentry_new == NULL) {
- dentry = ERR_PTR(-ENOMEM);
- return dentry;
+ return ENOMEM;
}
- dentry = inode->i_ops->lookup(inode, dentry_new);
+ *dentry = inode->i_ops->lookup(inode, dentry_new);
- if (dentry == NULL) { // 返回 lookup 没有再分配一个dentry
- dentry = dentry_new;
+ if (*dentry == NULL) { // 返回 lookup 没有再分配一个dentry
+ *dentry = dentry_new;
} else { // 否则就释放dentry_new使用lookup返回的dentry
dentry_put(dentry_new);
}
- return dentry;
+ return 0;
}
-dentry_t *path_lookup_create(namei_t *ni) {
- dentry_t *dentry = NULL;
+int path_lookup_create(namei_t *ni, dentry_t **dentry) {
+ int err = 0;
// 在调用完path_lookup_create后调用 up 操作
down(&ni->path.dentry->d_inode->i_sem);
- dentry = ERR_PTR(-EEXIST);
+ //
if (ni->last_type != LAST_NORMAL) {
- return dentry;
+ return EEXIST;
}
- dentry = path_lookup_hash(ni->path.dentry, &ni->last);
- if (IS_ERR(dentry)) {
- return dentry;
+ err = path_lookup_hash(ni->path.dentry, &ni->last, dentry);
+ if (err != 0) {
+ return err;
}
- return dentry;
+ return err;
}
int path_open_namei(const char *path, int flags, int mode, namei_t *ni) {
down(&dir->d_inode->i_sem);
- dentry = dentry_cached_lookup(dir, &ni->last);
- if (IS_ERR(dentry)) {
- ret = PTR_ERR(dentry);
+ ret = path_lookup_hash(dir, &ni->last, &dentry);
+ if (0 != ret) {
up(&dir->d_inode->i_sem);
goto end;
}
}
int read_super_for_nodev(fs_type_t *type, int flags, void *data, fill_super_cb_t fill_super, vfsmount_t *mnt) {
- int ret = 0;
+ int err = 0;
superblock_t *s = 0;
// 分配superblock
- s = sget(type, NULL, set_anonymous_super, NULL);
+ err = sget(type, NULL, set_anonymous_super, NULL, &s);
assert(s != NULL);
//
s->sb_flags = flags;
- ret = fill_super(s, data);
- if (0 != ret) {
- panic("ret: %d", ret);
+ err = fill_super(s, data);
+ if (0 != err) {
+ panic("err: %d", err);
}
mnt->mnt_sb = s;
mnt->mnt_root = dentry_get(s->sb_root);
- return ret;
+ return err;
}
-superblock_t *sget(fs_type_t *type, //
- int (*test)(superblock_t *, void *), //
- int (*set)(superblock_t *, void *), //
- void *data //
+int sget(fs_type_t *type, //
+ int (*test)(superblock_t *, void *), //
+ int (*set)(superblock_t *, void *), //
+ void *data, //
+ superblock_t **s //
) {
- int ret = 0;
- superblock_t *s = 0;
+ int err = 0;
+
+ *s = 0;
if (0 != test) {
panic("not implemented");
}
// TOOD REMOVE
- assert(0 == s);
+ assert(0 == *s);
- s = alloc_super(type);
- if (0 == s) {
- return ERR_PTR(-ENOMEM);
+ *s = alloc_super(type);
+ if (0 == *s) {
+ return ENOMEM;
}
assert(0 != set);
- ret = set(s, data);
- assert(0 == ret);
+ err = set(*s, data);
+ assert(0 == err);
uint32_t eflags;
irq_save(eflags);
- list_add_tail(&s->sb_list, &g_superblocks);
+ list_add_tail(&(*s)->sb_list, &g_superblocks);
irq_restore(eflags);
- return s;
+ return err;
}
void init_special_inode(inode_t *inode, umode_t mode, dev_t rdev);
////
-dentry_t *dentry_cached_lookup(dentry_t *parent, qstr_t *s);
-int dentry_real_lookup(dentry_t *parent, qstr_t *s, dentry_t **dentry);
+int dentry_cached_lookup(dentry_t *parent, //
+ qstr_t *s, //
+ dentry_t **dentry // OUT
+);
+
+int dentry_real_lookup(dentry_t *parent, //
+ qstr_t *s, //
+ dentry_t **dentry // OUT
+);
+
dentry_t *dentry_alloc_root(inode_t *root_inode);
dentry_t *dentry_alloc(dentry_t *parent, const qstr_t *s);
void dentry_add(dentry_t *dentry, inode_t *inode);
//
bool path_init(const char *path, unsigned int flags, namei_t *ni);
int path_walk(const char *path, namei_t *ni);
-dentry_t *path_lookup_create(namei_t *ni);
+int path_lookup_create(namei_t *ni, //
+ dentry_t **dentry // OUT
+);
typedef int (*fill_super_cb_t)(superblock_t *sb, void *data);
int read_super_for_nodev(fs_type_t *type, int flags, void *data, fill_super_cb_t fill_super, vfsmount_t *mnt);
-superblock_t *sget(fs_type_t *type, //
- int (*test)(superblock_t *, void *), //
- int (*set)(superblock_t *, void *), //
- void *data //
+int sget(fs_type_t *type, //
+ int (*test)(superblock_t *, void *), //
+ int (*set)(superblock_t *, void *), //
+ void *data, //
+ superblock_t **s // OUT
);
file_t *get_file(int fd);
#endif
-#define MAX_ERRNO 4095
-
-#ifndef ASM
-
-#define IS_ERR_VALUE(x) (((unsigned long)(x)) >= ((unsigned long)(-MAX_ERRNO)))
-
-static inline void *ERR_PTR(long err) { return ((void *)(err)); }
-
-static inline long PTR_ERR(void *p) { return ((long)(p)); }
-
-static inline bool IS_ERR(void *p) { return IS_ERR_VALUE(p); }
-
-#endif
-
#endif //_SYSTEM_H
regs.ss = SELECTOR_KRNL_DS;
regs.fs = SELECTOR_KRNL_DS;
regs.gs = SELECTOR_KRNL_DS;
-#if 0
+#if 1
get_eflags(regs.eflags);
#else
regs.eflags = 0x200;
}
#endif
- // sti();
+ sti();
kernel_task("init", init_task_entry, NULL);
- sti();
-
current->priority = 1;
while (1) {
asm("hlt;");