link_path_walk () 분석
3671 단어 link_path_walk
주요 데이터 구조:
struct qstr { /* , */
unsigned int hash;
unsigned int len;
const unsigned char *name;
};
struct nameidata
struct nameidata {
struct path path;
struct qstr last; /* */
struct path root; /* */
struct inode *inode; /* path.dentry.d_inode */
unsigned int flags; /* */
unsigned seq;
int last_type; /* */
unsigned depth; /* */
char *saved_names[MAX_NESTED_LINKS + 1]; /* */
/* Intent data */
union {
struct open_intent open;
} intent; /* , */
};
함수 분석:
static int link_path_walk(const char *name, struct nameidata *nd)
{
struct path next;
int err;
while (*name=='/') /* */
name++;
if (!*name) /* NULL, 0 */
return 0;
/* At this point we know we have a real path component. */
for(;;) { /* name "/" */
unsigned long hash;
struct qstr this; /* , */
unsigned int c;
int type;
err = may_lookup(nd); /* */
if (err)
break;
this.name = name;
c = *(const unsigned char *)name;
hash = init_name_hash();/* hash = 0 */
do { /* , "/" */
name++;
hash = partial_name_hash(c, hash);
c = *(const unsigned char *)name;
} while (c && (c != '/'));
this.len = name - (const char *) this.name;
this.hash = end_name_hash(hash);
type = LAST_NORM;
if (this.name[0] == '.') switch (this.len) {
case 2:
if (this.name[1] == '.') {
type = LAST_DOTDOT;
nd->flags |= LOOKUP_JUMPED;
}
break; /* , */
case 1:/* */
type = LAST_DOT;
}
if (likely(type == LAST_NORM)) {/* "." "..", */
struct dentry *parent = nd->path.dentry;
nd->flags &= ~LOOKUP_JUMPED;
if (unlikely(parent->d_flags & DCACHE_OP_HASH)) {
err = parent->d_op->d_hash(parent, nd->inode,
&this); /* d_hash , hash */
if (err < 0)
break;
}
}
/* remove trailing slashes? */
if (!c) /* NULL, */
goto last_component;
while (*++name == '/');
if (!*name) /* */
goto last_component;
/* */
err = walk_component(nd, &next, &this, type, LOOKUP_FOLLOW);/* */
if (err < 0)
return err;
if (err) { /* , follow_link */
err = nested_symlink(&next, nd);/* */
if (err)
return err;
}
if (can_lookup(nd->inode)) /* inode->i_opflags IOP_LOOKUP , inode->i_op->lookup */
continue;
err = -ENOTDIR;
break;
/* here ends the main loop */
last_component:
nd->last = this;
nd->last_type = type;
return 0;
}
terminate_walk(nd); /* nd */
return err;
}
linux 3.2