int rename_file(char *old_filename, char *new_filename)
{
char *from = old_filename;
char *to = new_filename;
int ret = 0;
struct nameidata old_nd, new_nd;
struct dentry *old_dentry, *new_dentry;
ret = path_lookup(from, LOOKUP_PARENT, &old_nd);
if (ret != 0)
{
return -ENOENT;
}
ret = path_lookup(to,LOOKUP_PARENT, &new_nd);
if (ret != 0)
{
return -ENOENT;
}
old_dentry = lookup_one_len(old_nd.last.name, old_nd.path.dentry, strlen(old_nd.last.name));
if (IS_ERR(old_dentry))
{
//path_release(&nd);
return -EACCES;
}
new_dentry = lookup_one_len(new_nd.last.name, new_nd.path.dentry, strlen(new_nd.last.name));
if (IS_ERR(new_dentry))
{
//path_release(&new_nd);
return -EACCES;
}
vfs_rename(old_nd.path.dentry->d_inode, old_dentry, new_nd.path.dentry->d_inode, new_dentry);
dput(old_dentry);
dput(new_dentry);
//path_release(&nd);
return 0;
}
先这么实现内核态下的文件移动吧
阅读(215) | 评论(0) | 转发(0) |