1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 23:47:45 +00:00

Kernel: Support open() with O_CREAT.

It's now possible to create zero-length files! :^)
Also hook up the new functionality in /bin/touch.
This commit is contained in:
Andreas Kling 2019-01-22 00:58:13 +01:00
parent a47f33bed3
commit f70136a324
9 changed files with 108 additions and 39 deletions

View file

@ -124,7 +124,7 @@ void init_ksyms()
void load_ksyms()
{
int error;
auto descriptor = VFS::the().open("/kernel.map", error);
auto descriptor = VFS::the().open("/kernel.map", error, 0, 0);
if (!descriptor) {
kprintf("Failed to open /kernel.map\n");
} else {

View file

@ -289,7 +289,7 @@ int Process::do_exec(const String& path, Vector<String>&& arguments, Vector<Stri
return -ENOENT;
int error;
auto descriptor = VFS::the().open(path, error, 0, m_cwd ? m_cwd->identifier() : InodeIdentifier());
auto descriptor = VFS::the().open(path, error, 0, 0, m_cwd ? m_cwd->identifier() : InodeIdentifier());
if (!descriptor) {
ASSERT(error != 0);
return error;
@ -1117,7 +1117,7 @@ int Process::sys$utime(const char* pathname, const Unix::utimbuf* buf)
return -EFAULT;
String path(pathname);
int error;
auto descriptor = VFS::the().open(move(path), error, 0, cwd_inode()->identifier());
auto descriptor = VFS::the().open(move(path), error, 0, 0, cwd_inode()->identifier());
if (!descriptor)
return error;
auto& inode = *descriptor->inode();
@ -1206,7 +1206,7 @@ int Process::sys$lstat(const char* path, Unix::stat* statbuf)
if (!validate_write_typed(statbuf))
return -EFAULT;
int error;
auto descriptor = VFS::the().open(move(path), error, O_NOFOLLOW_NOERROR, cwd_inode()->identifier());
auto descriptor = VFS::the().open(move(path), error, O_NOFOLLOW_NOERROR, 0, cwd_inode()->identifier());
if (!descriptor)
return error;
descriptor->stat(statbuf);
@ -1218,7 +1218,7 @@ int Process::sys$stat(const char* path, Unix::stat* statbuf)
if (!validate_write_typed(statbuf))
return -EFAULT;
int error;
auto descriptor = VFS::the().open(move(path), error, 0, cwd_inode()->identifier());
auto descriptor = VFS::the().open(move(path), error, 0, 0, cwd_inode()->identifier());
if (!descriptor)
return error;
descriptor->stat(statbuf);
@ -1233,7 +1233,7 @@ int Process::sys$readlink(const char* path, char* buffer, size_t size)
return -EFAULT;
int error;
auto descriptor = VFS::the().open(path, error, O_RDONLY | O_NOFOLLOW_NOERROR, cwd_inode()->identifier());
auto descriptor = VFS::the().open(path, error, O_RDONLY | O_NOFOLLOW_NOERROR, 0, cwd_inode()->identifier());
if (!descriptor)
return error;
@ -1255,7 +1255,7 @@ int Process::sys$chdir(const char* path)
if (!validate_read_str(path))
return -EFAULT;
int error;
auto descriptor = VFS::the().open(path, error, 0, cwd_inode()->identifier());
auto descriptor = VFS::the().open(path, error, 0, 0, cwd_inode()->identifier());
if (!descriptor)
return error;
if (!descriptor->is_directory())
@ -1288,7 +1288,7 @@ size_t Process::number_of_open_file_descriptors() const
return count;
}
int Process::sys$open(const char* path, int options)
int Process::sys$open(const char* path, int options, mode_t mode)
{
#ifdef DEBUG_IO
dbgprintf("%s(%u) sys$open(\"%s\")\n", name().characters(), pid(), path);
@ -1299,7 +1299,7 @@ int Process::sys$open(const char* path, int options)
return -EMFILE;
int error = -EWHYTHO;
ASSERT(cwd_inode());
auto descriptor = VFS::the().open(path, error, options, cwd_inode()->identifier());
auto descriptor = VFS::the().open(path, error, options, mode, cwd_inode()->identifier());
if (!descriptor)
return error;
if (options & O_DIRECTORY && !descriptor->is_directory())

View file

@ -140,7 +140,7 @@ public:
pid_t sys$getpid();
pid_t sys$getppid();
mode_t sys$umask(mode_t);
int sys$open(const char* path, int options);
int sys$open(const char* path, int options, mode_t mode = 0);
int sys$close(int fd);
ssize_t sys$read(int fd, void* outbuf, size_t nread);
ssize_t sys$write(int fd, const void*, size_t);

View file

@ -73,7 +73,7 @@ static dword handle(RegisterDump& regs, dword function, dword arg1, dword arg2,
case Syscall::SC_getcwd:
return current->sys$getcwd((char*)arg1, (size_t)arg2);
case Syscall::SC_open:
return current->sys$open((const char*)arg1, (int)arg2);
return current->sys$open((const char*)arg1, (int)arg2, (mode_t)arg3);
case Syscall::SC_write:
return current->sys$write((int)arg1, (const void*)arg2, (size_t)arg3);
case Syscall::SC_close: