Kernel: Add SYS_OPENAT
This commit is contained in:
		
							parent
							
								
									91f812e17f
								
							
						
					
					
						commit
						5aed186827
					
				|  | @ -58,6 +58,7 @@ namespace Kernel | |||
| 		BAN::ErrorOr<void> setenvp(char** envp); | ||||
| 
 | ||||
| 		BAN::ErrorOr<int> open(BAN::StringView, int); | ||||
| 		BAN::ErrorOr<int> openat(int, BAN::StringView, int); | ||||
| 		BAN::ErrorOr<void> close(int fd); | ||||
| 		BAN::ErrorOr<size_t> read(int fd, void* buffer, size_t count); | ||||
| 		BAN::ErrorOr<size_t> write(int fd, const void* buffer, size_t count); | ||||
|  |  | |||
|  | @ -469,6 +469,22 @@ namespace Kernel | |||
| 		return fd; | ||||
| 	} | ||||
| 
 | ||||
| 	BAN::ErrorOr<int> Process::openat(int fd, BAN::StringView path, int flags) | ||||
| 	{ | ||||
| 		BAN::String absolute_path; | ||||
| 		 | ||||
| 		{ | ||||
| 			LockGuard _(m_lock); | ||||
| 			TRY(validate_fd(fd)); | ||||
| 			TRY(absolute_path.append(open_file_description(fd).path)); | ||||
| 		} | ||||
| 		 | ||||
| 		TRY(absolute_path.push_back('/')); | ||||
| 		TRY(absolute_path.append(path)); | ||||
| 
 | ||||
| 		return open(absolute_path, flags); | ||||
| 	} | ||||
| 
 | ||||
| 	BAN::ErrorOr<void> Process::close(int fd) | ||||
| 	{ | ||||
| 		LockGuard _(m_lock); | ||||
|  |  | |||
|  | @ -48,6 +48,14 @@ namespace Kernel | |||
| 			return -res.error().get_error_code(); | ||||
| 		return res.value(); | ||||
| 	} | ||||
| 	 | ||||
| 	int sys_openat(int fd, const char* path, int oflags) | ||||
| 	{ | ||||
| 		auto res = Process::current().openat(fd, path, oflags); | ||||
| 		if (res.is_error()) | ||||
| 			return -res.error().get_error_code(); | ||||
| 		return res.value(); | ||||
| 	} | ||||
| 
 | ||||
| 	long sys_alloc(size_t bytes) | ||||
| 	{ | ||||
|  | @ -187,6 +195,9 @@ namespace Kernel | |||
| 		case SYS_OPEN: | ||||
| 			ret = sys_open((const char*)arg1, (int)arg2); | ||||
| 			break; | ||||
| 		case SYS_OPENAT: | ||||
| 			ret = sys_openat((int)arg1, (const char*)arg2, (int)arg3); | ||||
| 			break; | ||||
| 		case SYS_ALLOC: | ||||
| 			ret = sys_alloc((size_t)arg1); | ||||
| 			break; | ||||
|  |  | |||
|  | @ -7,3 +7,8 @@ int open(const char* path, int oflag, ...) | |||
| { | ||||
| 	return syscall(SYS_OPEN, path, oflag); | ||||
| } | ||||
| 
 | ||||
| int openat(int fd, const char* path, int oflag, ...) | ||||
| { | ||||
| 	return syscall(SYS_OPENAT, fd, path, oflag); | ||||
| } | ||||
|  |  | |||
|  | @ -11,20 +11,21 @@ __BEGIN_DECLS | |||
| #define SYS_TERMID 4 | ||||
| #define SYS_CLOSE 5 | ||||
| #define SYS_OPEN 6 | ||||
| #define SYS_ALLOC 7 | ||||
| #define SYS_FREE 8 | ||||
| #define SYS_SEEK 9 | ||||
| #define SYS_TELL 10 | ||||
| #define SYS_GET_TERMIOS 11 | ||||
| #define SYS_SET_TERMIOS 12 | ||||
| #define SYS_FORK 13 | ||||
| #define SYS_SLEEP 14 | ||||
| #define SYS_EXEC 15 | ||||
| #define SYS_REALLOC 16 | ||||
| #define SYS_WAIT 17 | ||||
| #define SYS_FSTAT 18 | ||||
| #define SYS_SETENVP 19 | ||||
| #define SYS_READ_DIR_ENTRIES 20 | ||||
| #define SYS_OPENAT 7 | ||||
| #define SYS_ALLOC 8 | ||||
| #define SYS_REALLOC 9 | ||||
| #define SYS_FREE 10 | ||||
| #define SYS_SEEK 11 | ||||
| #define SYS_TELL 12 | ||||
| #define SYS_GET_TERMIOS 13 | ||||
| #define SYS_SET_TERMIOS 14 | ||||
| #define SYS_FORK 15 | ||||
| #define SYS_EXEC 16 | ||||
| #define SYS_SLEEP 17 | ||||
| #define SYS_WAIT 18 | ||||
| #define SYS_FSTAT 19 | ||||
| #define SYS_SETENVP 20 | ||||
| #define SYS_READ_DIR_ENTRIES 21 | ||||
| 
 | ||||
| __END_DECLS | ||||
| 
 | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue