forked from Bananymous/banan-os
				
			Kernel/LibC: Implement unlinkat
This commit is contained in:
		
							parent
							
								
									91756c057e
								
							
						
					
					
						commit
						b75970958e
					
				|  | @ -107,7 +107,7 @@ namespace Kernel | ||||||
| 		BAN::ErrorOr<long> sys_access(const char* path, int amode); | 		BAN::ErrorOr<long> sys_access(const char* path, int amode); | ||||||
| 		BAN::ErrorOr<long> sys_create_dir(const char*, mode_t); | 		BAN::ErrorOr<long> sys_create_dir(const char*, mode_t); | ||||||
| 		BAN::ErrorOr<long> sys_hardlinkat(int fd1, const char* path1, int fd2, const char* path2, int flag); | 		BAN::ErrorOr<long> sys_hardlinkat(int fd1, const char* path1, int fd2, const char* path2, int flag); | ||||||
| 		BAN::ErrorOr<long> sys_unlink(const char*); | 		BAN::ErrorOr<long> sys_unlinkat(int fd, const char* path, int flag); | ||||||
| 		BAN::ErrorOr<long> sys_readlinkat(int fd, const char* path, char* buffer, size_t bufsize); | 		BAN::ErrorOr<long> sys_readlinkat(int fd, const char* path, char* buffer, size_t bufsize); | ||||||
| 
 | 
 | ||||||
| 		BAN::ErrorOr<long> sys_symlinkat(const char* path1, int fd, const char* path2); | 		BAN::ErrorOr<long> sys_symlinkat(const char* path1, int fd, const char* path2); | ||||||
|  |  | ||||||
|  | @ -1158,12 +1158,19 @@ namespace Kernel | ||||||
| 		return 0; | 		return 0; | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	BAN::ErrorOr<long> Process::sys_unlink(const char* path) | 	BAN::ErrorOr<long> Process::sys_unlinkat(int fd, const char* path, int flag) | ||||||
| 	{ | 	{ | ||||||
|  | 		if (flag && flag != AT_REMOVEDIR) | ||||||
|  | 			return BAN::Error::from_errno(EINVAL); | ||||||
|  | 
 | ||||||
| 		LockGuard _(m_process_lock); | 		LockGuard _(m_process_lock); | ||||||
| 		TRY(validate_string_access(path)); | 		TRY(validate_string_access(path)); | ||||||
| 
 | 
 | ||||||
| 		auto [parent, file_name] = TRY(find_parent_file(AT_FDCWD, path, O_WRONLY)); | 		auto [parent, file_name] = TRY(find_parent_file(fd, path, O_WRONLY)); | ||||||
|  | 
 | ||||||
|  | 		if (TRY(parent.inode->find_inode(file_name))->mode().ifdir() != (flag == AT_REMOVEDIR)) | ||||||
|  | 			return BAN::Error::from_errno(flag ? EPERM : ENOTDIR); | ||||||
|  | 
 | ||||||
| 		TRY(parent.inode->unlink(file_name)); | 		TRY(parent.inode->unlink(file_name)); | ||||||
| 
 | 
 | ||||||
| 		return 0; | 		return 0; | ||||||
|  |  | ||||||
|  | @ -56,7 +56,7 @@ __BEGIN_DECLS | ||||||
| 	O(SYS_POWEROFF,			poweroff)		\ | 	O(SYS_POWEROFF,			poweroff)		\ | ||||||
| 	O(SYS_FCHMODAT,			fchmodat)		\ | 	O(SYS_FCHMODAT,			fchmodat)		\ | ||||||
| 	O(SYS_CREATE_DIR,		create_dir)		\ | 	O(SYS_CREATE_DIR,		create_dir)		\ | ||||||
| 	O(SYS_UNLINK,			unlink) 		\ | 	O(SYS_UNLINKAT,			unlinkat) 		\ | ||||||
| 	O(SYS_READLINKAT,		readlinkat)		\ | 	O(SYS_READLINKAT,		readlinkat)		\ | ||||||
| 	O(SYS_MSYNC,			msync)			\ | 	O(SYS_MSYNC,			msync)			\ | ||||||
| 	O(SYS_PREAD,			pread)			\ | 	O(SYS_PREAD,			pread)			\ | ||||||
|  |  | ||||||
|  | @ -518,12 +518,17 @@ int fdatasync(int fildes) | ||||||
| 
 | 
 | ||||||
| int unlink(const char* path) | int unlink(const char* path) | ||||||
| { | { | ||||||
| 	return syscall(SYS_UNLINK, path); | 	return unlinkat(AT_FDCWD, path, 0); | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | int unlinkat(int fd, const char* path, int flag) | ||||||
|  | { | ||||||
|  | 	return syscall(SYS_UNLINKAT, fd, path, flag); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| int rmdir(const char* path) | int rmdir(const char* path) | ||||||
| { | { | ||||||
| 	return syscall(SYS_UNLINK, path); | 	return unlinkat(AT_FDCWD, path, AT_REMOVEDIR); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| char* optarg = nullptr; | char* optarg = nullptr; | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue