分类: LINUX
2010-12-06 22:02:19
asmlinkage long sys_mkdir(const char __user * pathname, int mode)
{
int error = 0;
char * tmp;
//把用户空间的值copy到内核空间
tmp = getname(pathname);
error = PTR_ERR(tmp);
if (!IS_ERR(tmp)) {
struct dentry *dentry;
struct nameidata nd;
//先查到它的父目录,看父目录是否存在
error = path_lookup(tmp, LOOKUP_PARENT, &nd);
if (error)
goto out;
//寻找子结点的dentry. 如果没有,则新建之
dentry = lookup_create(&nd, 1);
error = PTR_ERR(dentry);
if (!IS_ERR(dentry)) {
if (!IS_POSIXACL(nd.dentry->d_inode))
mode &= ~current->fs->umask;
//与具体的文件系统相关的部份
error = vfs_mkdir(nd.dentry->d_inode, dentry, mode);
//减少dentry的引用计数
dput(dentry);
}
up(&nd.dentry->d_inode->i_sem);
//释放临时内存
path_release(&nd);
out:
putname(tmp);
}
return error;
}