mirror of
https://github.com/Mathewnd/Astral.git
synced 2026-10-27 12:48:22 +00:00
vfs: finish new locking scheme
This commit is contained in:
@@ -99,7 +99,10 @@ syscallret_t syscall_openat(context_t *context, int dirfd, char *path, int flags
|
||||
ret.ret = newfd;
|
||||
|
||||
cleanup:
|
||||
VOP_UNLOCK(vnode);
|
||||
|
||||
if (vnode)
|
||||
VOP_UNLOCK(vnode);
|
||||
|
||||
cleanup_nounlock:
|
||||
if (vnode && ret.errno) {
|
||||
vfs_close(vnode, fileflagstovnodeflags(flags));
|
||||
|
||||
@@ -18,8 +18,6 @@ syscallret_t syscall_renameat(context_t *context, int olddirfd, char *uoldpath,
|
||||
return ret;
|
||||
}
|
||||
|
||||
char *oldcomponent = NULL;
|
||||
char *newcomponent = NULL;
|
||||
char *oldpath = alloc(oldpathlen + 1);
|
||||
if (oldpath == NULL) {
|
||||
ret.errno = ENOMEM;
|
||||
@@ -42,54 +40,19 @@ syscallret_t syscall_renameat(context_t *context, int olddirfd, char *uoldpath,
|
||||
file_t *oldfile = NULL;
|
||||
vnode_t *newdirnode = NULL;
|
||||
file_t *newfile = NULL;
|
||||
vnode_t *targetdirnode = NULL;
|
||||
vnode_t *sourcedirnode = NULL;
|
||||
ret.errno = dirfd_enter(oldpath, olddirfd, &oldfile, &olddirnode);
|
||||
|
||||
if (ret.errno)
|
||||
goto cleanup;
|
||||
|
||||
ret.errno = dirfd_enter(newpath, newdirfd, &newfile, &newdirnode);
|
||||
|
||||
if (ret.errno)
|
||||
goto cleanup;
|
||||
|
||||
oldcomponent = alloc(strlen(oldpath) + 1);
|
||||
newcomponent = alloc(strlen(newpath) + 1);
|
||||
|
||||
if (oldcomponent == NULL && newcomponent == NULL)
|
||||
goto cleanup;
|
||||
|
||||
// TODO deadlocks.
|
||||
ret.errno = vfs_lookup(&sourcedirnode, olddirnode, oldpath, oldcomponent, VFS_LOOKUP_NOLINK | VFS_LOOKUP_PARENT);
|
||||
if (ret.errno)
|
||||
goto cleanup;
|
||||
|
||||
ret.errno = vfs_lookup(&targetdirnode, newdirnode, newpath, newcomponent, VFS_LOOKUP_NOLINK | VFS_LOOKUP_PARENT);
|
||||
if (ret.errno) {
|
||||
VOP_UNLOCK(sourcedirnode);
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
ret.errno = VOP_RENAME(sourcedirnode, oldcomponent, targetdirnode, newcomponent, flags);
|
||||
ret.errno = vfs_rename(olddirnode, oldpath, newdirnode, newpath, flags);
|
||||
ret.ret = ret.errno ? -1 : 0;
|
||||
VOP_UNLOCK(targetdirnode);
|
||||
VOP_UNLOCK(sourcedirnode);
|
||||
|
||||
cleanup:
|
||||
|
||||
if (targetdirnode)
|
||||
VOP_RELEASE(targetdirnode);
|
||||
|
||||
if (sourcedirnode)
|
||||
VOP_RELEASE(sourcedirnode);
|
||||
|
||||
if (oldcomponent)
|
||||
free(oldcomponent);
|
||||
|
||||
if (newcomponent)
|
||||
free(newcomponent);
|
||||
|
||||
if (olddirnode)
|
||||
dirfd_leave(olddirnode, oldfile);
|
||||
|
||||
|
||||
@@ -40,25 +40,10 @@ syscallret_t syscall_unlinkat(context_t *, int dirfd, char *upath, int flags) {
|
||||
if (ret.errno)
|
||||
goto cleanup;
|
||||
|
||||
// TODO rmdir flag
|
||||
|
||||
vnode_t *node = NULL;
|
||||
ret.errno = vfs_lookup(&node, dirnode, path, component, VFS_LOOKUP_NOLINK | VFS_LOOKUP_PARENT);
|
||||
if (ret.errno)
|
||||
goto cleanup;
|
||||
|
||||
ret.errno = VOP_UNLINK(node, component, &_cpu()->thread->proc->cred);
|
||||
ret.errno = vfs_unlink(dirnode, path);
|
||||
ret.ret = ret.errno ? -1 : 0;
|
||||
// locked by vfs_lookup
|
||||
VOP_UNLOCK(node);
|
||||
|
||||
cleanup:
|
||||
if (component)
|
||||
free(component);
|
||||
|
||||
if (node)
|
||||
VOP_RELEASE(node);
|
||||
|
||||
if (dirnode)
|
||||
dirfd_leave(dirnode, file);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user