Relicense Sortix to the ISC license.
I hereby relicense all my work on Sortix under the ISC license as below.
All Sortix contributions by other people are already under this license,
are not substantial enough to be copyrightable, or have been removed.
All imported code from other projects is compatible with this license.
All GPL licensed code from other projects had previously been removed.
Copyright 2011-2016 Jonas 'Sortie' Termansen and contributors.
Permission to use, copy, modify, and distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
2016-03-02 17:38:16 -05:00
|
|
|
/*
|
2017-01-09 17:40:56 -05:00
|
|
|
* Copyright (c) 2011-2017 Jonas 'Sortie' Termansen.
|
Relicense Sortix to the ISC license.
I hereby relicense all my work on Sortix under the ISC license as below.
All Sortix contributions by other people are already under this license,
are not substantial enough to be copyrightable, or have been removed.
All imported code from other projects is compatible with this license.
All GPL licensed code from other projects had previously been removed.
Copyright 2011-2016 Jonas 'Sortie' Termansen and contributors.
Permission to use, copy, modify, and distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
2016-03-02 17:38:16 -05:00
|
|
|
*
|
|
|
|
* Permission to use, copy, modify, and distribute this software for any
|
|
|
|
* purpose with or without fee is hereby granted, provided that the above
|
|
|
|
* copyright notice and this permission notice appear in all copies.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
|
|
|
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
|
|
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
|
|
|
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
|
|
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
|
|
|
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
|
|
|
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
|
|
*
|
|
|
|
* io.cpp
|
|
|
|
* Provides system calls for input and output.
|
|
|
|
*/
|
2011-11-16 02:37:29 -05:00
|
|
|
|
2014-01-16 14:46:56 -05:00
|
|
|
#include <sys/socket.h>
|
2013-10-26 20:42:10 -04:00
|
|
|
#include <sys/types.h>
|
|
|
|
|
|
|
|
#include <assert.h>
|
|
|
|
#include <errno.h>
|
2014-05-07 08:14:38 -04:00
|
|
|
#include <fsmarshall-msg.h>
|
2013-10-26 20:42:10 -04:00
|
|
|
#include <stddef.h>
|
|
|
|
#include <stdint.h>
|
|
|
|
|
|
|
|
#include <sortix/dirent.h>
|
|
|
|
#include <sortix/fcntl.h>
|
2016-01-23 14:56:07 -05:00
|
|
|
#include <sortix/ioctl.h>
|
2013-10-26 20:42:10 -04:00
|
|
|
#include <sortix/seek.h>
|
|
|
|
#include <sortix/socket.h>
|
|
|
|
#include <sortix/stat.h>
|
2014-01-20 18:53:18 -05:00
|
|
|
#include <sortix/statvfs.h>
|
2013-10-26 20:42:10 -04:00
|
|
|
#include <sortix/uio.h>
|
2015-09-27 19:57:22 -04:00
|
|
|
#include <sortix/unistd.h>
|
2013-10-26 20:42:10 -04:00
|
|
|
|
2012-08-07 18:19:44 -04:00
|
|
|
#include <sortix/kernel/copy.h>
|
|
|
|
#include <sortix/kernel/descriptor.h>
|
|
|
|
#include <sortix/kernel/dtable.h>
|
2013-10-26 20:42:10 -04:00
|
|
|
#include <sortix/kernel/ioctx.h>
|
|
|
|
#include <sortix/kernel/kernel.h>
|
2012-08-01 14:22:31 -04:00
|
|
|
#include <sortix/kernel/kthread.h>
|
2013-05-12 18:41:30 -04:00
|
|
|
#include <sortix/kernel/process.h>
|
2013-10-26 20:42:10 -04:00
|
|
|
#include <sortix/kernel/refcount.h>
|
|
|
|
#include <sortix/kernel/string.h>
|
|
|
|
#include <sortix/kernel/syscall.h>
|
2013-05-12 18:41:30 -04:00
|
|
|
#include <sortix/kernel/thread.h>
|
2013-06-01 07:24:27 -04:00
|
|
|
#include <sortix/kernel/vnode.h>
|
2012-08-07 18:19:44 -04:00
|
|
|
|
2013-06-01 07:24:27 -04:00
|
|
|
#include "partition.h"
|
2011-11-16 02:37:29 -05:00
|
|
|
|
2012-08-07 18:19:44 -04:00
|
|
|
namespace Sortix {
|
|
|
|
|
2015-05-13 11:10:19 -04:00
|
|
|
static Ref<Descriptor> PrepareLookup(const char* path, int dirfd)
|
2012-08-07 18:19:44 -04:00
|
|
|
{
|
2015-05-13 11:10:19 -04:00
|
|
|
if ( path[0] == '/' )
|
2012-08-07 18:19:44 -04:00
|
|
|
return CurrentProcess()->GetRoot();
|
|
|
|
if ( dirfd == AT_FDCWD )
|
|
|
|
return CurrentProcess()->GetCWD();
|
|
|
|
return CurrentProcess()->GetDescriptor(dirfd);
|
|
|
|
}
|
|
|
|
|
2014-10-16 18:04:47 -04:00
|
|
|
ssize_t sys_write(int fd, const void* buffer, size_t count)
|
2012-08-07 18:19:44 -04:00
|
|
|
{
|
|
|
|
Ref<Descriptor> desc = CurrentProcess()->GetDescriptor(fd);
|
|
|
|
if ( !desc )
|
|
|
|
return -1;
|
|
|
|
ioctx_t ctx; SetupUserIOCtx(&ctx);
|
|
|
|
ssize_t ret = desc->write(&ctx, (const uint8_t*) buffer, count);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2014-10-16 18:04:47 -04:00
|
|
|
ssize_t sys_pwrite(int fd, const void* buffer, size_t count, off_t off)
|
2012-08-07 18:19:44 -04:00
|
|
|
{
|
|
|
|
Ref<Descriptor> desc = CurrentProcess()->GetDescriptor(fd);
|
|
|
|
if ( !desc )
|
|
|
|
return -1;
|
|
|
|
ioctx_t ctx; SetupUserIOCtx(&ctx);
|
|
|
|
ssize_t ret = desc->pwrite(&ctx, (const uint8_t*) buffer, count, off);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2014-10-16 18:04:47 -04:00
|
|
|
ssize_t sys_read(int fd, void* buffer, size_t count)
|
2012-08-07 18:19:44 -04:00
|
|
|
{
|
|
|
|
Ref<Descriptor> desc = CurrentProcess()->GetDescriptor(fd);
|
|
|
|
if ( !desc )
|
|
|
|
return -1;
|
|
|
|
ioctx_t ctx; SetupUserIOCtx(&ctx);
|
|
|
|
ssize_t ret = desc->read(&ctx, (uint8_t*) buffer, count);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2014-10-16 18:04:47 -04:00
|
|
|
ssize_t sys_pread(int fd, void* buffer, size_t count, off_t off)
|
2012-08-07 18:19:44 -04:00
|
|
|
{
|
|
|
|
Ref<Descriptor> desc = CurrentProcess()->GetDescriptor(fd);
|
|
|
|
if ( !desc )
|
|
|
|
return -1;
|
|
|
|
ioctx_t ctx; SetupUserIOCtx(&ctx);
|
|
|
|
ssize_t ret = desc->pread(&ctx, (uint8_t*) buffer, count, off);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2014-10-16 18:04:47 -04:00
|
|
|
off_t sys_lseek(int fd, off_t offset, int whence)
|
2012-08-07 18:19:44 -04:00
|
|
|
{
|
|
|
|
Ref<Descriptor> desc = CurrentProcess()->GetDescriptor(fd);
|
|
|
|
if ( !desc )
|
|
|
|
return -1;
|
|
|
|
ioctx_t ctx; SetupUserIOCtx(&ctx);
|
|
|
|
off_t ret = desc->lseek(&ctx, offset, whence);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2014-10-16 18:04:47 -04:00
|
|
|
int sys_close(int fd)
|
2012-08-07 18:19:44 -04:00
|
|
|
{
|
|
|
|
ioctx_t ctx; SetupUserIOCtx(&ctx);
|
|
|
|
Ref<DescriptorTable> dtable = CurrentProcess()->GetDTable();
|
|
|
|
Ref<Descriptor> desc = dtable->FreeKeep(fd);
|
|
|
|
dtable.Reset();
|
|
|
|
if ( !desc )
|
|
|
|
return -1;
|
2015-01-30 18:16:54 -05:00
|
|
|
// TODO: This can be a significant bottleneck. All we need to do is ask the
|
|
|
|
// filesystem for whether any errors occurred that should be reported
|
|
|
|
// at close time.
|
|
|
|
//return desc->sync(&ctx);
|
|
|
|
return 0;
|
2012-08-07 18:19:44 -04:00
|
|
|
}
|
|
|
|
|
2015-05-13 11:48:53 -04:00
|
|
|
int sys_closefrom(int fd)
|
|
|
|
{
|
|
|
|
ioctx_t ctx; SetupUserIOCtx(&ctx);
|
|
|
|
Ref<DescriptorTable> dtable = CurrentProcess()->GetDTable();
|
|
|
|
int ret = dtable->CloseFrom(fd);
|
|
|
|
dtable.Reset();
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2014-10-16 18:04:47 -04:00
|
|
|
int sys_dup(int fd)
|
2012-08-07 18:19:44 -04:00
|
|
|
{
|
|
|
|
Ref<DescriptorTable> dtable = CurrentProcess()->GetDTable();
|
|
|
|
Ref<Descriptor> desc = dtable->Get(fd);
|
|
|
|
return dtable->Allocate(desc, 0);
|
|
|
|
}
|
|
|
|
|
2014-10-16 18:04:47 -04:00
|
|
|
int sys_dup3(int oldfd, int newfd, int flags)
|
2013-06-27 14:47:24 -04:00
|
|
|
{
|
2013-09-23 14:41:31 -04:00
|
|
|
if ( flags & ~(O_CLOEXEC | O_CLOFORK) )
|
|
|
|
return errno = EINVAL, -1;
|
|
|
|
int fd_flags = 0;
|
2016-01-07 18:36:14 -05:00
|
|
|
fd_flags |= flags & O_CLOEXEC ? FD_CLOEXEC : 0;
|
|
|
|
fd_flags |= flags & O_CLOFORK ? FD_CLOFORK : 0;
|
2013-06-27 14:47:24 -04:00
|
|
|
Ref<DescriptorTable> dtable = CurrentProcess()->GetDTable();
|
2013-09-23 14:41:31 -04:00
|
|
|
return dtable->Copy(oldfd, newfd, fd_flags);
|
|
|
|
}
|
|
|
|
|
2014-10-16 18:04:47 -04:00
|
|
|
int sys_dup2(int oldfd, int newfd)
|
2013-09-23 14:41:31 -04:00
|
|
|
{
|
|
|
|
if ( oldfd < 0 || newfd < 0 )
|
|
|
|
return errno = EINVAL, -1;
|
|
|
|
int ret = sys_dup3(oldfd, newfd, 0);
|
|
|
|
if ( ret < 0 && errno == EINVAL )
|
|
|
|
return errno = 0, newfd;
|
|
|
|
return ret;
|
2013-06-27 14:47:24 -04:00
|
|
|
}
|
|
|
|
|
2012-08-07 18:19:44 -04:00
|
|
|
// TODO: If this function fails the file may still have been created. Does a
|
|
|
|
// standard prohibit this and is that the wrong thing?
|
2014-10-16 18:04:47 -04:00
|
|
|
int sys_openat(int dirfd, const char* path, int flags, mode_t mode)
|
2012-08-07 18:19:44 -04:00
|
|
|
{
|
|
|
|
char* pathcopy = GetStringFromUser(path);
|
|
|
|
if ( !pathcopy )
|
|
|
|
return -1;
|
|
|
|
ioctx_t ctx; SetupUserIOCtx(&ctx);
|
|
|
|
int fdflags = 0;
|
|
|
|
if ( flags & O_CLOEXEC ) fdflags |= FD_CLOEXEC;
|
|
|
|
if ( flags & O_CLOFORK ) fdflags |= FD_CLOFORK;
|
|
|
|
flags &= ~(O_CLOEXEC | O_CLOFORK);
|
2015-05-13 11:10:19 -04:00
|
|
|
Ref<Descriptor> from = PrepareLookup(pathcopy, dirfd);
|
2012-08-07 18:19:44 -04:00
|
|
|
if ( !from ) { delete[] pathcopy; return -1; }
|
2015-05-13 11:10:19 -04:00
|
|
|
Ref<Descriptor> desc = from->open(&ctx, pathcopy, flags, mode);
|
2012-08-07 18:19:44 -04:00
|
|
|
from.Reset();
|
|
|
|
delete[] pathcopy;
|
|
|
|
if ( !desc )
|
|
|
|
return -1;
|
|
|
|
Ref<DescriptorTable> dtable = CurrentProcess()->GetDTable();
|
2014-05-07 08:14:38 -04:00
|
|
|
int ret = dtable->Allocate(desc, fdflags);
|
|
|
|
if ( ret < 0 )
|
|
|
|
{
|
|
|
|
// TODO: We should use a fail-safe dtable reservation mechanism that
|
|
|
|
// causes this error earlier before we have side effects.
|
|
|
|
}
|
|
|
|
return ret;
|
2012-08-07 18:19:44 -04:00
|
|
|
}
|
|
|
|
|
2015-09-27 19:57:22 -04:00
|
|
|
int sys_faccessat(int dirfd, const char* path, int mode, int flags)
|
2012-08-07 18:19:44 -04:00
|
|
|
{
|
2014-11-05 15:36:39 -05:00
|
|
|
if ( flags & ~(AT_SYMLINK_NOFOLLOW | AT_EACCESS) )
|
2013-11-16 07:21:44 -05:00
|
|
|
return errno = EINVAL, -1;
|
2015-09-27 19:57:22 -04:00
|
|
|
if ( mode & ~(X_OK | W_OK | R_OK) )
|
|
|
|
return errno = EINVAL, -1;
|
2012-08-07 18:19:44 -04:00
|
|
|
char* pathcopy = GetStringFromUser(path);
|
|
|
|
if ( !pathcopy )
|
|
|
|
return -1;
|
|
|
|
ioctx_t ctx; SetupUserIOCtx(&ctx);
|
2015-05-13 11:10:19 -04:00
|
|
|
Ref<Descriptor> from = PrepareLookup(pathcopy, dirfd);
|
2012-10-23 17:55:33 -04:00
|
|
|
if ( !from ) { delete[] pathcopy; return -1; }
|
2016-10-22 17:47:28 -04:00
|
|
|
int open_flags = O_READ | O_IS_STAT |
|
|
|
|
(flags & AT_SYMLINK_NOFOLLOW ? O_SYMLINK_NOFOLLOW : 0);
|
2015-05-13 11:10:19 -04:00
|
|
|
Ref<Descriptor> desc = from->open(&ctx, pathcopy, open_flags);
|
2012-08-07 18:19:44 -04:00
|
|
|
delete[] pathcopy;
|
2015-09-27 19:57:22 -04:00
|
|
|
if ( !desc )
|
|
|
|
return -1;
|
|
|
|
ioctx_t kctx; SetupKernelIOCtx(&kctx);
|
|
|
|
struct stat st;
|
|
|
|
if ( desc->stat(&kctx, &st) < 0 )
|
|
|
|
return -1;
|
|
|
|
mode_t mask;
|
|
|
|
if ( kctx.uid == st.st_uid )
|
|
|
|
mask = 0700;
|
|
|
|
else if ( kctx.gid == st.st_gid )
|
|
|
|
mask = 0070;
|
|
|
|
else
|
|
|
|
mask = 0007;
|
|
|
|
if ( (mode & X_OK) && !(st.st_mode & 0111 & mask) )
|
|
|
|
return errno = EACCES, -1;
|
|
|
|
if ( (mode & W_OK) && !(st.st_mode & 0222 & mask) )
|
|
|
|
return errno = EACCES, -1;
|
|
|
|
if ( (mode & R_OK) && !(st.st_mode & 0444 & mask) )
|
|
|
|
return errno = EACCES, -1;
|
|
|
|
return 0;
|
2012-08-07 18:19:44 -04:00
|
|
|
}
|
|
|
|
|
2014-10-16 18:04:47 -04:00
|
|
|
int sys_unlinkat(int dirfd, const char* path, int flags)
|
2012-08-07 18:19:44 -04:00
|
|
|
{
|
|
|
|
char* pathcopy = GetStringFromUser(path);
|
|
|
|
if ( !pathcopy )
|
|
|
|
return -1;
|
|
|
|
ioctx_t ctx; SetupUserIOCtx(&ctx);
|
2015-05-13 11:10:19 -04:00
|
|
|
Ref<Descriptor> from = PrepareLookup(pathcopy, dirfd);
|
2012-10-23 07:50:33 -04:00
|
|
|
if ( !from ) { delete[] pathcopy; return -1; }
|
2015-05-13 11:10:19 -04:00
|
|
|
int ret = from->unlinkat(&ctx, pathcopy, flags);
|
2012-08-07 18:19:44 -04:00
|
|
|
delete[] pathcopy;
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2014-10-16 18:04:47 -04:00
|
|
|
int sys_mkdirat(int dirfd, const char* path, mode_t mode)
|
2012-08-07 18:19:44 -04:00
|
|
|
{
|
|
|
|
char* pathcopy = GetStringFromUser(path);
|
|
|
|
if ( !pathcopy )
|
|
|
|
return -1;
|
|
|
|
ioctx_t ctx; SetupUserIOCtx(&ctx);
|
2015-05-13 11:10:19 -04:00
|
|
|
Ref<Descriptor> from = PrepareLookup(pathcopy, dirfd);
|
2012-10-23 18:07:39 -04:00
|
|
|
if ( !from ) { delete[] pathcopy; return -1; }
|
2015-05-13 11:10:19 -04:00
|
|
|
int ret = from->mkdir(&ctx, pathcopy, mode);
|
2012-08-07 18:19:44 -04:00
|
|
|
delete[] pathcopy;
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2014-10-16 18:04:47 -04:00
|
|
|
int sys_truncateat(int dirfd, const char* path, off_t length)
|
2012-08-07 18:19:44 -04:00
|
|
|
{
|
|
|
|
char* pathcopy = GetStringFromUser(path);
|
|
|
|
if ( !pathcopy )
|
|
|
|
return -1;
|
|
|
|
ioctx_t ctx; SetupUserIOCtx(&ctx);
|
2015-05-13 11:10:19 -04:00
|
|
|
Ref<Descriptor> from = PrepareLookup(pathcopy, dirfd);
|
2012-10-24 08:49:19 -04:00
|
|
|
if ( !from ) { delete[] pathcopy; return -1; }
|
2015-05-13 11:10:19 -04:00
|
|
|
Ref<Descriptor> desc = from->open(&ctx, pathcopy, O_WRITE);
|
2012-08-07 18:19:44 -04:00
|
|
|
delete[] pathcopy;
|
|
|
|
if ( !desc )
|
|
|
|
return -1;
|
|
|
|
return desc->truncate(&ctx, length);
|
|
|
|
}
|
|
|
|
|
2014-10-16 18:04:47 -04:00
|
|
|
int sys_ftruncate(int fd, off_t length)
|
2012-08-07 18:19:44 -04:00
|
|
|
{
|
|
|
|
Ref<Descriptor> desc = CurrentProcess()->GetDescriptor(fd);
|
|
|
|
if ( !desc )
|
|
|
|
return -1;
|
|
|
|
ioctx_t ctx; SetupUserIOCtx(&ctx);
|
|
|
|
return desc->truncate(&ctx, length);
|
|
|
|
}
|
|
|
|
|
2014-10-16 18:04:47 -04:00
|
|
|
int sys_fstatat(int dirfd, const char* path, struct stat* st, int flags)
|
2011-11-16 02:37:29 -05:00
|
|
|
{
|
2013-11-16 07:21:44 -05:00
|
|
|
if ( flags & ~(AT_SYMLINK_NOFOLLOW) )
|
|
|
|
return errno = EINVAL;
|
2012-08-07 18:19:44 -04:00
|
|
|
char* pathcopy = GetStringFromUser(path);
|
|
|
|
if ( !pathcopy )
|
|
|
|
return -1;
|
|
|
|
ioctx_t ctx; SetupUserIOCtx(&ctx);
|
2015-05-13 11:10:19 -04:00
|
|
|
Ref<Descriptor> from = PrepareLookup(pathcopy, dirfd);
|
2012-08-07 18:19:44 -04:00
|
|
|
if ( !from ) { delete[] pathcopy; return -1; }
|
2016-10-22 17:47:28 -04:00
|
|
|
int open_flags = O_READ | O_IS_STAT |
|
|
|
|
(flags & AT_SYMLINK_NOFOLLOW ? O_SYMLINK_NOFOLLOW : 0);
|
2015-05-13 11:10:19 -04:00
|
|
|
Ref<Descriptor> desc = from->open(&ctx, pathcopy, open_flags);
|
2012-08-07 18:19:44 -04:00
|
|
|
delete[] pathcopy;
|
|
|
|
if ( !desc )
|
|
|
|
return -1;
|
|
|
|
return desc->stat(&ctx, st);
|
|
|
|
}
|
|
|
|
|
2014-10-16 18:04:47 -04:00
|
|
|
int sys_fstat(int fd, struct stat* st)
|
2012-08-07 18:19:44 -04:00
|
|
|
{
|
|
|
|
Ref<Descriptor> desc = CurrentProcess()->GetDescriptor(fd);
|
|
|
|
if ( !desc )
|
|
|
|
return -1;
|
|
|
|
ioctx_t ctx; SetupUserIOCtx(&ctx);
|
|
|
|
return desc->stat(&ctx, st);
|
|
|
|
}
|
|
|
|
|
2014-10-16 18:04:47 -04:00
|
|
|
int sys_fstatvfs(int fd, struct statvfs* stvfs)
|
2014-01-20 18:53:18 -05:00
|
|
|
{
|
|
|
|
Ref<Descriptor> desc = CurrentProcess()->GetDescriptor(fd);
|
|
|
|
if ( !desc )
|
|
|
|
return -1;
|
|
|
|
ioctx_t ctx; SetupUserIOCtx(&ctx);
|
|
|
|
return desc->statvfs(&ctx, stvfs);
|
|
|
|
}
|
|
|
|
|
2014-10-16 18:04:47 -04:00
|
|
|
int sys_fstatvfsat(int dirfd, const char* path, struct statvfs* stvfs, int flags)
|
2014-01-20 18:53:18 -05:00
|
|
|
{
|
|
|
|
if ( flags & ~(AT_SYMLINK_NOFOLLOW) )
|
|
|
|
return errno = EINVAL;
|
|
|
|
char* pathcopy = GetStringFromUser(path);
|
|
|
|
if ( !pathcopy )
|
|
|
|
return -1;
|
|
|
|
ioctx_t ctx; SetupUserIOCtx(&ctx);
|
2015-05-13 11:10:19 -04:00
|
|
|
Ref<Descriptor> from = PrepareLookup(pathcopy, dirfd);
|
2014-01-20 18:53:18 -05:00
|
|
|
if ( !from ) { delete[] pathcopy; return -1; }
|
2016-10-22 17:47:28 -04:00
|
|
|
int open_flags = O_READ | O_IS_STAT |
|
|
|
|
(flags & AT_SYMLINK_NOFOLLOW ? O_SYMLINK_NOFOLLOW : 0);
|
2015-05-13 11:10:19 -04:00
|
|
|
Ref<Descriptor> desc = from->open(&ctx, pathcopy, open_flags);
|
2014-01-20 18:53:18 -05:00
|
|
|
delete[] pathcopy;
|
|
|
|
if ( !desc )
|
|
|
|
return -1;
|
|
|
|
return desc->statvfs(&ctx, stvfs);
|
|
|
|
}
|
|
|
|
|
2014-10-16 18:04:47 -04:00
|
|
|
int sys_fcntl(int fd, int cmd, uintptr_t arg)
|
2012-08-07 18:19:44 -04:00
|
|
|
{
|
2013-09-24 06:39:48 -04:00
|
|
|
// Operations on the descriptor table.
|
2012-08-07 18:19:44 -04:00
|
|
|
Ref<DescriptorTable> dtable = CurrentProcess()->GetDTable();
|
2014-08-09 06:29:35 -04:00
|
|
|
if ( cmd == F_PREVFD )
|
|
|
|
return dtable->Previous(fd);
|
|
|
|
if ( cmd == F_NEXTFD )
|
|
|
|
return dtable->Next(fd);
|
2013-09-24 06:39:48 -04:00
|
|
|
|
|
|
|
// Operations on the file descriptior.
|
|
|
|
if ( cmd == F_SETFD )
|
2014-02-15 15:52:32 -05:00
|
|
|
return dtable->SetFlags(fd, (int) arg) ? 0 : -1;
|
2013-09-24 06:39:48 -04:00
|
|
|
if ( cmd == F_GETFD )
|
|
|
|
return dtable->GetFlags(fd);
|
|
|
|
|
|
|
|
// Operations on the file description.
|
2013-09-24 07:35:05 -04:00
|
|
|
if ( F_DECODE_CMD(F_DECODE_CMD_RAW(cmd)) == F_DUPFD_NUM )
|
|
|
|
{
|
|
|
|
int fd_flags = F_DECODE_FLAGS(F_DECODE_CMD_RAW(cmd));
|
|
|
|
return dtable->Allocate(fd, fd_flags, (int) arg);
|
|
|
|
}
|
2013-09-24 06:39:48 -04:00
|
|
|
Ref<Descriptor> desc = dtable->Get(fd);
|
|
|
|
if ( !desc )
|
|
|
|
return -1;
|
|
|
|
if ( cmd == F_SETFL )
|
2014-02-15 15:52:32 -05:00
|
|
|
return desc->SetFlags((int) arg) ? 0 : -1;
|
2013-09-24 06:39:48 -04:00
|
|
|
if ( cmd == F_GETFL )
|
|
|
|
return desc->GetFlags();
|
|
|
|
|
|
|
|
return errno = EINVAL, -1;
|
2012-08-07 18:19:44 -04:00
|
|
|
}
|
|
|
|
|
2016-01-23 14:56:07 -05:00
|
|
|
int sys_ioctl(int fd, int cmd, uintptr_t arg)
|
2013-03-21 16:35:51 -04:00
|
|
|
{
|
2016-11-15 15:08:41 -05:00
|
|
|
Ref<Descriptor> desc = CurrentProcess()->GetDescriptor(fd);
|
|
|
|
if ( !desc )
|
|
|
|
return -1;
|
|
|
|
ioctx_t ctx; SetupUserIOCtx(&ctx);
|
|
|
|
return desc->ioctl(&ctx, cmd, arg);
|
2013-03-21 16:35:51 -04:00
|
|
|
}
|
|
|
|
|
2015-11-19 20:57:09 -05:00
|
|
|
ssize_t sys_readdirents(int fd, struct dirent* dirent, size_t size)
|
2012-08-07 18:19:44 -04:00
|
|
|
{
|
|
|
|
if ( SSIZE_MAX < size )
|
|
|
|
size = SSIZE_MAX;
|
|
|
|
Ref<Descriptor> desc = CurrentProcess()->GetDescriptor(fd);
|
|
|
|
if ( !desc )
|
|
|
|
return -1;
|
|
|
|
ioctx_t ctx; SetupUserIOCtx(&ctx);
|
2015-11-19 20:57:09 -05:00
|
|
|
return desc->readdirents(&ctx, dirent, size);
|
2012-08-07 18:19:44 -04:00
|
|
|
}
|
|
|
|
|
2014-10-16 18:04:47 -04:00
|
|
|
int sys_fchdir(int fd)
|
2012-10-24 07:06:12 -04:00
|
|
|
{
|
|
|
|
Process* process = CurrentProcess();
|
|
|
|
Ref<Descriptor> desc = process->GetDescriptor(fd);
|
|
|
|
if ( !desc )
|
|
|
|
return -1;
|
|
|
|
if ( !S_ISDIR(desc->type) )
|
|
|
|
return errno = ENOTDIR, -1;
|
|
|
|
process->SetCWD(desc);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-10-16 18:04:47 -04:00
|
|
|
int sys_fchdirat(int dirfd, const char* path)
|
2012-08-07 18:19:44 -04:00
|
|
|
{
|
|
|
|
char* pathcopy = GetStringFromUser(path);
|
|
|
|
if ( !pathcopy )
|
|
|
|
return -1;
|
|
|
|
ioctx_t ctx; SetupUserIOCtx(&ctx);
|
2015-05-13 11:10:19 -04:00
|
|
|
Ref<Descriptor> from = PrepareLookup(pathcopy, dirfd);
|
|
|
|
Ref<Descriptor> desc = from->open(&ctx, pathcopy, O_READ | O_DIRECTORY);
|
2012-08-07 18:19:44 -04:00
|
|
|
from.Reset();
|
|
|
|
delete[] pathcopy;
|
|
|
|
if ( !desc )
|
|
|
|
return -1;
|
|
|
|
CurrentProcess()->SetCWD(desc);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-10-16 18:04:47 -04:00
|
|
|
int sys_fchroot(int fd)
|
2013-05-29 18:32:22 -04:00
|
|
|
{
|
|
|
|
Process* process = CurrentProcess();
|
|
|
|
Ref<Descriptor> desc = process->GetDescriptor(fd);
|
|
|
|
if ( !desc )
|
|
|
|
return -1;
|
|
|
|
if ( !S_ISDIR(desc->type) )
|
|
|
|
return errno = ENOTDIR, -1;
|
|
|
|
process->SetRoot(desc);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-10-16 18:04:47 -04:00
|
|
|
int sys_fchrootat(int dirfd, const char* path)
|
2013-05-29 18:32:22 -04:00
|
|
|
{
|
|
|
|
char* pathcopy = GetStringFromUser(path);
|
|
|
|
if ( !pathcopy )
|
|
|
|
return -1;
|
|
|
|
ioctx_t ctx; SetupUserIOCtx(&ctx);
|
2015-05-13 11:10:19 -04:00
|
|
|
Ref<Descriptor> from = PrepareLookup(pathcopy, dirfd);
|
|
|
|
Ref<Descriptor> desc = from->open(&ctx, pathcopy, O_READ | O_DIRECTORY);
|
2013-05-29 18:32:22 -04:00
|
|
|
from.Reset();
|
|
|
|
delete[] pathcopy;
|
|
|
|
if ( !desc )
|
|
|
|
return -1;
|
|
|
|
CurrentProcess()->SetRoot(desc);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-10-16 18:04:47 -04:00
|
|
|
int sys_fchown(int fd, uid_t owner, gid_t group)
|
2012-10-24 13:52:28 -04:00
|
|
|
{
|
|
|
|
Ref<Descriptor> desc = CurrentProcess()->GetDescriptor(fd);
|
|
|
|
if ( !desc )
|
|
|
|
return -1;
|
|
|
|
ioctx_t ctx; SetupUserIOCtx(&ctx);
|
|
|
|
return desc->chown(&ctx, owner, group);
|
|
|
|
}
|
2012-10-24 13:43:11 -04:00
|
|
|
|
2014-10-16 18:04:47 -04:00
|
|
|
int sys_fchownat(int dirfd, const char* path, uid_t owner, gid_t group, int flags)
|
2012-10-23 14:02:33 -04:00
|
|
|
{
|
2013-11-16 07:21:44 -05:00
|
|
|
if ( flags & ~(AT_SYMLINK_NOFOLLOW) )
|
|
|
|
return errno = EINVAL, -1;
|
2012-10-23 14:02:33 -04:00
|
|
|
char* pathcopy = GetStringFromUser(path);
|
|
|
|
if ( !pathcopy )
|
|
|
|
return -1;
|
|
|
|
ioctx_t ctx; SetupUserIOCtx(&ctx);
|
2015-05-13 11:10:19 -04:00
|
|
|
Ref<Descriptor> from = PrepareLookup(pathcopy, dirfd);
|
2012-10-24 13:43:11 -04:00
|
|
|
if ( !from ) { delete[] pathcopy; return -1; }
|
2018-09-01 10:37:17 -04:00
|
|
|
int open_flags = O_READ | (flags & AT_SYMLINK_NOFOLLOW ? O_SYMLINK_NOFOLLOW : 0);
|
2015-05-13 11:10:19 -04:00
|
|
|
Ref<Descriptor> desc = from->open(&ctx, pathcopy, open_flags);
|
2012-10-23 14:02:33 -04:00
|
|
|
from.Reset();
|
|
|
|
delete[] pathcopy;
|
|
|
|
if ( !desc )
|
|
|
|
return -1;
|
|
|
|
return desc->chown(&ctx, owner, group);
|
|
|
|
}
|
|
|
|
|
2016-03-26 07:36:07 -04:00
|
|
|
#if defined(__i386__)
|
|
|
|
struct fchownat_request /* duplicated in libc/unistd/fchownat.c */
|
|
|
|
{
|
|
|
|
int dirfd;
|
|
|
|
const char* path;
|
|
|
|
uid_t owner;
|
|
|
|
gid_t group;
|
|
|
|
int flags;
|
|
|
|
};
|
|
|
|
|
|
|
|
int sys_fchownat_wrapper(const struct fchownat_request* user_request)
|
|
|
|
{
|
|
|
|
struct fchownat_request request;
|
|
|
|
if ( !CopyFromUser(&request, user_request, sizeof(request)) )
|
|
|
|
return -1;
|
|
|
|
return sys_fchownat(request.dirfd, request.path, request.owner,
|
|
|
|
request.group, request.flags);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2014-10-16 18:04:47 -04:00
|
|
|
int sys_fchmod(int fd, mode_t mode)
|
2012-10-24 18:17:43 -04:00
|
|
|
{
|
|
|
|
Ref<Descriptor> desc = CurrentProcess()->GetDescriptor(fd);
|
|
|
|
if ( !desc )
|
|
|
|
return -1;
|
|
|
|
ioctx_t ctx; SetupUserIOCtx(&ctx);
|
|
|
|
return desc->chmod(&ctx, mode);
|
|
|
|
}
|
|
|
|
|
2014-10-16 18:04:47 -04:00
|
|
|
int sys_fchmodat(int dirfd, const char* path, mode_t mode, int flags)
|
2012-10-23 13:55:54 -04:00
|
|
|
{
|
2013-11-16 07:21:44 -05:00
|
|
|
if ( flags & ~(AT_SYMLINK_NOFOLLOW) )
|
|
|
|
return errno = EINVAL, -1;
|
2012-10-23 13:55:54 -04:00
|
|
|
char* pathcopy = GetStringFromUser(path);
|
|
|
|
if ( !pathcopy )
|
|
|
|
return -1;
|
|
|
|
ioctx_t ctx; SetupUserIOCtx(&ctx);
|
2015-05-13 11:10:19 -04:00
|
|
|
Ref<Descriptor> from = PrepareLookup(pathcopy, dirfd);
|
2012-10-24 18:29:48 -04:00
|
|
|
if ( !from ) { delete[] pathcopy; return -1; }
|
2018-09-01 10:37:17 -04:00
|
|
|
int open_flags = O_READ | (flags & AT_SYMLINK_NOFOLLOW ? O_SYMLINK_NOFOLLOW : 0);
|
2015-05-13 11:10:19 -04:00
|
|
|
Ref<Descriptor> desc = from->open(&ctx, pathcopy, open_flags);
|
2012-10-23 13:55:54 -04:00
|
|
|
from.Reset();
|
|
|
|
delete[] pathcopy;
|
|
|
|
if ( !desc )
|
|
|
|
return -1;
|
|
|
|
return desc->chmod(&ctx, mode);
|
|
|
|
}
|
|
|
|
|
2015-01-22 18:29:04 -05:00
|
|
|
int sys_futimens(int fd, const struct timespec* user_times)
|
2013-03-19 17:01:01 -04:00
|
|
|
{
|
|
|
|
Ref<Descriptor> desc = CurrentProcess()->GetDescriptor(fd);
|
|
|
|
if ( !desc )
|
|
|
|
return -1;
|
|
|
|
ioctx_t ctx; SetupUserIOCtx(&ctx);
|
2016-02-24 10:29:37 -05:00
|
|
|
return desc->utimens(&ctx, user_times);
|
2013-03-19 17:01:01 -04:00
|
|
|
}
|
|
|
|
|
2014-10-16 18:04:47 -04:00
|
|
|
int sys_utimensat(int dirfd, const char* path,
|
2015-01-22 18:29:04 -05:00
|
|
|
const struct timespec* user_times, int flags)
|
2013-03-19 17:01:01 -04:00
|
|
|
{
|
2013-11-16 07:21:44 -05:00
|
|
|
if ( flags & ~(AT_SYMLINK_NOFOLLOW) )
|
|
|
|
return errno = EINVAL, -1;
|
2013-03-19 17:01:01 -04:00
|
|
|
char* pathcopy = GetStringFromUser(path);
|
|
|
|
if ( !pathcopy )
|
|
|
|
return -1;
|
|
|
|
ioctx_t ctx; SetupUserIOCtx(&ctx);
|
2015-05-13 11:10:19 -04:00
|
|
|
Ref<Descriptor> from = PrepareLookup(pathcopy, dirfd);
|
2013-03-19 17:01:01 -04:00
|
|
|
if ( !from ) { delete[] pathcopy; return -1; }
|
2018-09-01 10:37:17 -04:00
|
|
|
int open_flags = O_READ | (flags & AT_SYMLINK_NOFOLLOW ? O_SYMLINK_NOFOLLOW : 0);
|
2015-05-13 11:10:19 -04:00
|
|
|
Ref<Descriptor> desc = from->open(&ctx, pathcopy, open_flags);
|
2013-03-19 17:01:01 -04:00
|
|
|
from.Reset();
|
|
|
|
delete[] pathcopy;
|
|
|
|
if ( !desc )
|
|
|
|
return -1;
|
2016-02-24 10:29:37 -05:00
|
|
|
return desc->utimens(&ctx, user_times);
|
2013-03-19 17:01:01 -04:00
|
|
|
}
|
|
|
|
|
2014-10-16 18:04:47 -04:00
|
|
|
int sys_linkat(int olddirfd, const char* oldpath,
|
|
|
|
int newdirfd, const char* newpath,
|
|
|
|
int flags)
|
2012-10-23 14:09:43 -04:00
|
|
|
{
|
2013-11-16 07:21:44 -05:00
|
|
|
if ( flags & ~(AT_SYMLINK_FOLLOW) )
|
|
|
|
return errno = EINVAL, -1;
|
2012-10-25 09:43:53 -04:00
|
|
|
|
2012-10-23 14:09:43 -04:00
|
|
|
ioctx_t ctx; SetupUserIOCtx(&ctx);
|
|
|
|
|
|
|
|
char* newpathcopy = GetStringFromUser(newpath);
|
|
|
|
if ( !newpathcopy )
|
|
|
|
return -1;
|
2015-05-13 11:10:19 -04:00
|
|
|
Ref<Descriptor> newfrom(PrepareLookup(newpathcopy, newdirfd));
|
2012-10-25 09:43:53 -04:00
|
|
|
if ( !newfrom ) { delete[] newpathcopy; return -1; }
|
2012-10-23 14:09:43 -04:00
|
|
|
|
|
|
|
char* final_elem;
|
|
|
|
Ref<Descriptor> dir = OpenDirContainingPath(&ctx, newfrom, newpathcopy,
|
|
|
|
&final_elem);
|
|
|
|
delete[] newpathcopy;
|
|
|
|
if ( !dir )
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
char* oldpathcopy = GetStringFromUser(oldpath);
|
|
|
|
if ( !oldpathcopy ) { delete[] final_elem; return -1; }
|
2015-05-13 11:10:19 -04:00
|
|
|
Ref<Descriptor> oldfrom = PrepareLookup(oldpathcopy, olddirfd);
|
2012-10-25 09:43:53 -04:00
|
|
|
if ( !oldfrom ) { delete[] oldpathcopy; delete[] final_elem; return -1; }
|
2012-10-23 14:09:43 -04:00
|
|
|
|
2013-11-16 07:21:44 -05:00
|
|
|
int open_flags = O_READ | (flags & AT_SYMLINK_FOLLOW ? 0 : O_SYMLINK_NOFOLLOW);
|
2015-05-13 11:10:19 -04:00
|
|
|
Ref<Descriptor> file = oldfrom->open(&ctx, oldpathcopy, open_flags);
|
2012-10-23 14:09:43 -04:00
|
|
|
delete[] oldpathcopy;
|
|
|
|
if ( !file ) { delete[] final_elem; return -1; }
|
|
|
|
|
|
|
|
int ret = dir->link(&ctx, final_elem, file);
|
|
|
|
delete[] final_elem;
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2014-10-16 18:04:47 -04:00
|
|
|
int sys_symlinkat(const char* oldpath, int newdirfd, const char* newpath)
|
2013-11-21 14:27:34 -05:00
|
|
|
{
|
|
|
|
ioctx_t ctx; SetupUserIOCtx(&ctx);
|
|
|
|
|
2014-09-22 11:35:54 -04:00
|
|
|
char* newpath_copy = GetStringFromUser(newpath);
|
|
|
|
if ( !newpath_copy )
|
2013-11-21 14:27:34 -05:00
|
|
|
return -1;
|
2014-09-22 11:35:54 -04:00
|
|
|
char* oldpath_copy = GetStringFromUser(oldpath);
|
|
|
|
if ( !oldpath_copy )
|
|
|
|
return delete[] newpath_copy, -1;
|
2013-11-21 14:27:34 -05:00
|
|
|
|
2015-05-13 11:10:19 -04:00
|
|
|
Ref<Descriptor> newfrom(PrepareLookup(newpath_copy, newdirfd));
|
2014-09-22 11:35:54 -04:00
|
|
|
if ( !newfrom )
|
|
|
|
return delete[] newpath_copy, -1;
|
2013-11-21 14:27:34 -05:00
|
|
|
|
2015-05-13 11:10:19 -04:00
|
|
|
int ret = newfrom->symlink(&ctx, oldpath, newpath_copy);
|
2013-11-21 14:27:34 -05:00
|
|
|
|
2014-09-22 11:35:54 -04:00
|
|
|
delete[] oldpath_copy;
|
|
|
|
delete[] newpath_copy;
|
2013-11-21 14:27:34 -05:00
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2014-10-16 18:04:47 -04:00
|
|
|
int sys_settermmode(int fd, unsigned mode)
|
2012-08-07 18:19:44 -04:00
|
|
|
{
|
|
|
|
Ref<Descriptor> desc = CurrentProcess()->GetDescriptor(fd);
|
|
|
|
if ( !desc )
|
|
|
|
return -1;
|
|
|
|
ioctx_t ctx; SetupUserIOCtx(&ctx);
|
|
|
|
return desc->settermmode(&ctx, mode);
|
|
|
|
}
|
|
|
|
|
2014-10-16 18:04:47 -04:00
|
|
|
int sys_gettermmode(int fd, unsigned* mode)
|
2012-08-07 18:19:44 -04:00
|
|
|
{
|
|
|
|
Ref<Descriptor> desc = CurrentProcess()->GetDescriptor(fd);
|
|
|
|
if ( !desc )
|
|
|
|
return -1;
|
|
|
|
ioctx_t ctx; SetupUserIOCtx(&ctx);
|
|
|
|
return desc->gettermmode(&ctx, mode);
|
2011-11-16 02:37:29 -05:00
|
|
|
}
|
2012-08-07 18:19:44 -04:00
|
|
|
|
2014-10-16 18:04:47 -04:00
|
|
|
int sys_isatty(int fd)
|
2012-08-07 18:19:44 -04:00
|
|
|
{
|
|
|
|
Ref<Descriptor> desc = CurrentProcess()->GetDescriptor(fd);
|
|
|
|
if ( !desc )
|
|
|
|
return 0;
|
|
|
|
ioctx_t ctx; SetupUserIOCtx(&ctx);
|
|
|
|
return desc->isatty(&ctx);
|
|
|
|
}
|
|
|
|
|
2014-10-16 18:04:47 -04:00
|
|
|
int sys_tcgetwincurpos(int fd, struct wincurpos* wcp)
|
2013-12-20 15:55:05 -05:00
|
|
|
{
|
|
|
|
Ref<Descriptor> desc = CurrentProcess()->GetDescriptor(fd);
|
|
|
|
if ( !desc )
|
|
|
|
return -1;
|
|
|
|
ioctx_t ctx; SetupUserIOCtx(&ctx);
|
|
|
|
return desc->tcgetwincurpos(&ctx, wcp);
|
|
|
|
}
|
|
|
|
|
2014-10-16 18:04:47 -04:00
|
|
|
int sys_tcgetwinsize(int fd, struct winsize* ws)
|
2012-08-07 18:19:44 -04:00
|
|
|
{
|
2016-11-15 15:08:41 -05:00
|
|
|
return sys_ioctl(fd, TIOCGWINSZ, (uintptr_t) ws);
|
2012-08-07 18:19:44 -04:00
|
|
|
}
|
|
|
|
|
2014-10-16 18:04:47 -04:00
|
|
|
int sys_tcsetpgrp(int fd, pid_t pgid)
|
2013-06-11 20:18:07 -04:00
|
|
|
{
|
|
|
|
Ref<Descriptor> desc = CurrentProcess()->GetDescriptor(fd);
|
|
|
|
if ( !desc )
|
|
|
|
return -1;
|
|
|
|
ioctx_t ctx; SetupUserIOCtx(&ctx);
|
|
|
|
return desc->tcsetpgrp(&ctx, pgid);
|
|
|
|
}
|
|
|
|
|
2014-10-16 18:04:47 -04:00
|
|
|
int sys_tcgetpgrp(int fd)
|
2013-06-11 20:18:07 -04:00
|
|
|
{
|
|
|
|
Ref<Descriptor> desc = CurrentProcess()->GetDescriptor(fd);
|
|
|
|
if ( !desc )
|
|
|
|
return -1;
|
|
|
|
ioctx_t ctx; SetupUserIOCtx(&ctx);
|
|
|
|
return desc->tcgetpgrp(&ctx);
|
|
|
|
}
|
|
|
|
|
2012-12-20 10:19:07 -05:00
|
|
|
static int sys_renameat_inner(int olddirfd, const char* oldpath,
|
|
|
|
int newdirfd, const char* newpath)
|
|
|
|
{
|
2015-05-13 11:10:19 -04:00
|
|
|
Ref<Descriptor> olddir(PrepareLookup(oldpath, olddirfd));
|
2012-12-20 10:19:07 -05:00
|
|
|
if ( !olddir )
|
|
|
|
return -1;
|
|
|
|
|
2015-05-13 11:10:19 -04:00
|
|
|
Ref<Descriptor> newdir(PrepareLookup(newpath, newdirfd));
|
2012-12-20 10:19:07 -05:00
|
|
|
if ( !newdir )
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
ioctx_t ctx; SetupUserIOCtx(&ctx);
|
2015-05-13 11:10:19 -04:00
|
|
|
return newdir->rename_here(&ctx, olddir, oldpath, newpath);
|
2012-12-20 10:19:07 -05:00
|
|
|
}
|
|
|
|
|
2014-10-16 18:04:47 -04:00
|
|
|
int sys_renameat(int olddirfd, const char* oldpath,
|
|
|
|
int newdirfd, const char* newpath)
|
2012-12-20 10:19:07 -05:00
|
|
|
{
|
|
|
|
char* oldpathcopy = GetStringFromUser(oldpath);
|
|
|
|
if ( !oldpathcopy ) return -1;
|
|
|
|
char* newpathcopy = GetStringFromUser(newpath);
|
|
|
|
if ( !newpathcopy ) { delete[] oldpathcopy; return -1; }
|
|
|
|
int ret = sys_renameat_inner(olddirfd, oldpathcopy, newdirfd, newpathcopy);
|
|
|
|
delete[] newpathcopy;
|
|
|
|
delete[] oldpathcopy;
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2013-03-19 15:18:15 -04:00
|
|
|
// TODO: This should probably be moved into user-space. It'd be nice if
|
|
|
|
// user-space could just open the symlink and read/write it like a regular file.
|
2014-10-16 18:04:47 -04:00
|
|
|
ssize_t sys_readlinkat(int dirfd, const char* path, char* buf, size_t size)
|
2013-03-19 15:18:15 -04:00
|
|
|
{
|
|
|
|
char* pathcopy = GetStringFromUser(path);
|
|
|
|
if ( !pathcopy )
|
|
|
|
return -1;
|
|
|
|
ioctx_t ctx; SetupUserIOCtx(&ctx);
|
2015-05-13 11:10:19 -04:00
|
|
|
Ref<Descriptor> from = PrepareLookup(pathcopy, dirfd);
|
2013-03-19 15:18:15 -04:00
|
|
|
if ( !from ) { delete[] pathcopy; return -1; }
|
2015-05-13 11:10:19 -04:00
|
|
|
Ref<Descriptor> desc = from->open(&ctx, pathcopy, O_READ | O_SYMLINK_NOFOLLOW);
|
2013-03-19 15:18:15 -04:00
|
|
|
delete[] pathcopy;
|
|
|
|
if ( !desc )
|
|
|
|
return -1;
|
2016-09-26 14:01:58 -04:00
|
|
|
return desc->readlink(&ctx, buf, size);
|
2013-03-19 15:18:15 -04:00
|
|
|
}
|
|
|
|
|
2014-10-16 18:04:47 -04:00
|
|
|
int sys_fsync(int fd)
|
2013-03-20 08:16:12 -04:00
|
|
|
{
|
|
|
|
Ref<Descriptor> desc = CurrentProcess()->GetDescriptor(fd);
|
|
|
|
if ( !desc )
|
|
|
|
return -1;
|
|
|
|
ioctx_t ctx; SetupUserIOCtx(&ctx);
|
|
|
|
return desc->sync(&ctx);
|
|
|
|
}
|
|
|
|
|
2014-10-16 18:04:47 -04:00
|
|
|
int sys_accept4(int fd, void* addr, size_t* addrlen, int flags)
|
2013-03-19 17:40:37 -04:00
|
|
|
{
|
|
|
|
Ref<Descriptor> desc = CurrentProcess()->GetDescriptor(fd);
|
|
|
|
if ( !desc )
|
|
|
|
return -1;
|
|
|
|
int fdflags = 0;
|
|
|
|
if ( flags & SOCK_CLOEXEC ) fdflags |= FD_CLOEXEC;
|
|
|
|
if ( flags & SOCK_CLOFORK ) fdflags |= FD_CLOFORK;
|
2018-04-29 07:32:29 -04:00
|
|
|
flags &= ~(SOCK_CLOEXEC | SOCK_CLOFORK);
|
2013-03-19 17:40:37 -04:00
|
|
|
ioctx_t ctx; SetupUserIOCtx(&ctx);
|
2017-02-25 11:00:24 -05:00
|
|
|
Ref<Descriptor> conn = desc->accept4(&ctx, (uint8_t*) addr, addrlen, flags);
|
2013-03-19 17:40:37 -04:00
|
|
|
if ( !conn )
|
|
|
|
return -1;
|
|
|
|
return CurrentProcess()->GetDTable()->Allocate(conn, fdflags);
|
|
|
|
}
|
|
|
|
|
2014-10-16 18:04:47 -04:00
|
|
|
int sys_bind(int fd, const void* addr, size_t addrlen)
|
2013-03-19 17:40:37 -04:00
|
|
|
{
|
|
|
|
Ref<Descriptor> desc = CurrentProcess()->GetDescriptor(fd);
|
|
|
|
if ( !desc )
|
|
|
|
return -1;
|
|
|
|
ioctx_t ctx; SetupUserIOCtx(&ctx);
|
|
|
|
return desc->bind(&ctx, (const uint8_t*) addr, addrlen);
|
|
|
|
}
|
|
|
|
|
2014-10-16 18:04:47 -04:00
|
|
|
int sys_connect(int fd, const void* addr, size_t addrlen)
|
2013-03-19 17:40:37 -04:00
|
|
|
{
|
|
|
|
Ref<Descriptor> desc = CurrentProcess()->GetDescriptor(fd);
|
|
|
|
if ( !desc )
|
|
|
|
return -1;
|
|
|
|
ioctx_t ctx; SetupUserIOCtx(&ctx);
|
|
|
|
return desc->connect(&ctx, (const uint8_t*) addr, addrlen);
|
|
|
|
}
|
|
|
|
|
2014-10-16 18:04:47 -04:00
|
|
|
int sys_listen(int fd, int backlog)
|
2013-03-19 17:40:37 -04:00
|
|
|
{
|
|
|
|
Ref<Descriptor> desc = CurrentProcess()->GetDescriptor(fd);
|
|
|
|
if ( !desc )
|
|
|
|
return -1;
|
|
|
|
ioctx_t ctx; SetupUserIOCtx(&ctx);
|
|
|
|
return desc->listen(&ctx, backlog);
|
|
|
|
}
|
|
|
|
|
2014-10-16 18:04:47 -04:00
|
|
|
ssize_t sys_recv(int fd, void* buffer, size_t count, int flags)
|
2013-03-19 17:40:37 -04:00
|
|
|
{
|
|
|
|
Ref<Descriptor> desc = CurrentProcess()->GetDescriptor(fd);
|
|
|
|
if ( !desc )
|
|
|
|
return -1;
|
|
|
|
ioctx_t ctx; SetupUserIOCtx(&ctx);
|
|
|
|
return desc->recv(&ctx, (uint8_t*) buffer, count, flags);
|
|
|
|
}
|
|
|
|
|
2014-10-16 18:04:47 -04:00
|
|
|
ssize_t sys_send(int fd, const void* buffer, size_t count, int flags)
|
2013-03-19 17:40:37 -04:00
|
|
|
{
|
|
|
|
Ref<Descriptor> desc = CurrentProcess()->GetDescriptor(fd);
|
|
|
|
if ( !desc )
|
|
|
|
return -1;
|
|
|
|
ioctx_t ctx; SetupUserIOCtx(&ctx);
|
|
|
|
return desc->send(&ctx, (const uint8_t*) buffer, count, flags);
|
|
|
|
}
|
|
|
|
|
2017-01-09 17:40:56 -05:00
|
|
|
ssize_t sys_readv(int fd, const struct iovec* iov, int iovcnt)
|
2013-05-03 15:43:01 -04:00
|
|
|
{
|
|
|
|
Ref<Descriptor> desc = CurrentProcess()->GetDescriptor(fd);
|
|
|
|
if ( !desc )
|
|
|
|
return -1;
|
|
|
|
ioctx_t ctx; SetupUserIOCtx(&ctx);
|
2017-01-09 17:40:56 -05:00
|
|
|
return desc->readv(&ctx, iov, iovcnt);
|
2013-05-03 15:43:01 -04:00
|
|
|
}
|
|
|
|
|
2017-01-09 17:40:56 -05:00
|
|
|
ssize_t sys_preadv(int fd, const struct iovec* iov, int iovcnt, off_t offset)
|
2013-05-03 15:43:01 -04:00
|
|
|
{
|
|
|
|
Ref<Descriptor> desc = CurrentProcess()->GetDescriptor(fd);
|
|
|
|
if ( !desc )
|
|
|
|
return -1;
|
|
|
|
ioctx_t ctx; SetupUserIOCtx(&ctx);
|
2017-01-09 17:40:56 -05:00
|
|
|
return desc->preadv(&ctx, iov, iovcnt, offset);
|
2013-05-03 15:43:01 -04:00
|
|
|
}
|
|
|
|
|
2017-01-09 17:40:56 -05:00
|
|
|
ssize_t sys_writev(int fd, const struct iovec* iov, int iovcnt)
|
2013-05-03 15:43:01 -04:00
|
|
|
{
|
|
|
|
Ref<Descriptor> desc = CurrentProcess()->GetDescriptor(fd);
|
|
|
|
if ( !desc )
|
|
|
|
return -1;
|
|
|
|
ioctx_t ctx; SetupUserIOCtx(&ctx);
|
2017-01-09 17:40:56 -05:00
|
|
|
return desc->writev(&ctx, iov, iovcnt);
|
2013-05-03 15:43:01 -04:00
|
|
|
}
|
|
|
|
|
2017-01-09 17:40:56 -05:00
|
|
|
ssize_t sys_pwritev(int fd, const struct iovec* iov, int iovcnt, off_t offset)
|
2013-05-03 15:43:01 -04:00
|
|
|
{
|
|
|
|
Ref<Descriptor> desc = CurrentProcess()->GetDescriptor(fd);
|
|
|
|
if ( !desc )
|
|
|
|
return -1;
|
|
|
|
ioctx_t ctx; SetupUserIOCtx(&ctx);
|
2017-01-09 17:40:56 -05:00
|
|
|
return desc->pwritev(&ctx, iov, iovcnt, offset);
|
2013-05-03 15:43:01 -04:00
|
|
|
}
|
|
|
|
|
2014-10-16 18:04:47 -04:00
|
|
|
int sys_mkpartition(int fd, off_t start, off_t length, int flags)
|
2013-06-01 07:24:27 -04:00
|
|
|
{
|
|
|
|
int fdflags = 0;
|
|
|
|
if ( flags & O_CLOEXEC ) fdflags |= FD_CLOEXEC;
|
|
|
|
if ( flags & O_CLOFORK ) fdflags |= FD_CLOFORK;
|
|
|
|
|
|
|
|
Ref<Descriptor> desc = CurrentProcess()->GetDescriptor(fd);
|
|
|
|
if ( !desc )
|
|
|
|
return -1;
|
|
|
|
|
2014-10-26 19:17:34 -04:00
|
|
|
int dflags = desc->GetFlags();
|
2013-06-01 07:24:27 -04:00
|
|
|
Ref<Inode> inner_inode = desc->vnode->inode;
|
|
|
|
desc.Reset();
|
|
|
|
|
2017-10-26 11:12:07 -04:00
|
|
|
if ( !S_ISBLK(inner_inode->type) && !S_ISREG(inner_inode->type) )
|
|
|
|
return errno = EPERM, -1;
|
|
|
|
if ( start < 0 || length < 0 )
|
|
|
|
return errno = EINVAL, -1;
|
|
|
|
off_t end;
|
|
|
|
if ( __builtin_add_overflow(start, length, &end) )
|
|
|
|
return errno = EOVERFLOW, -1;
|
|
|
|
|
2013-06-01 07:24:27 -04:00
|
|
|
Ref<Inode> partition(new Partition(inner_inode, start, length));
|
|
|
|
if ( !partition )
|
|
|
|
return -1;
|
|
|
|
inner_inode.Reset();
|
|
|
|
|
|
|
|
Ref<Vnode> partition_vnode(new Vnode(partition, Ref<Vnode>(NULL), 0, 0));
|
|
|
|
if ( !partition_vnode )
|
|
|
|
return -1;
|
|
|
|
partition.Reset();
|
|
|
|
|
|
|
|
Ref<Descriptor> partition_desc(new Descriptor(partition_vnode, dflags));
|
|
|
|
if ( !partition_desc )
|
|
|
|
return -1;
|
|
|
|
partition_vnode.Reset();
|
|
|
|
|
|
|
|
return CurrentProcess()->GetDTable()->Allocate(partition_desc, fdflags);
|
|
|
|
}
|
|
|
|
|
2017-01-09 17:40:56 -05:00
|
|
|
ssize_t sys_sendmsg(int fd, const struct msghdr* msg, int flags)
|
2014-01-16 14:46:56 -05:00
|
|
|
{
|
2017-01-09 17:40:56 -05:00
|
|
|
Ref<Descriptor> desc = CurrentProcess()->GetDescriptor(fd);
|
|
|
|
if ( !desc )
|
2014-01-16 14:46:56 -05:00
|
|
|
return -1;
|
2017-01-09 17:40:56 -05:00
|
|
|
ioctx_t ctx; SetupUserIOCtx(&ctx);
|
|
|
|
return desc->sendmsg(&ctx, msg, flags);
|
2014-01-16 14:46:56 -05:00
|
|
|
}
|
|
|
|
|
2017-01-09 17:40:56 -05:00
|
|
|
ssize_t sys_recvmsg(int fd, struct msghdr* msg, int flags)
|
2014-01-16 14:46:56 -05:00
|
|
|
{
|
|
|
|
Ref<Descriptor> desc = CurrentProcess()->GetDescriptor(fd);
|
|
|
|
if ( !desc )
|
|
|
|
return -1;
|
2017-01-09 17:40:56 -05:00
|
|
|
ioctx_t ctx; SetupUserIOCtx(&ctx);
|
|
|
|
return desc->recvmsg(&ctx, msg, flags);
|
2014-01-16 14:46:56 -05:00
|
|
|
}
|
|
|
|
|
2014-10-16 18:04:47 -04:00
|
|
|
int sys_getsockopt(int fd, int level, int option_name,
|
|
|
|
void* option_value, size_t* option_size_ptr)
|
2014-02-28 11:10:08 -05:00
|
|
|
{
|
|
|
|
Ref<Descriptor> desc = CurrentProcess()->GetDescriptor(fd);
|
|
|
|
if ( !desc )
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
ioctx_t ctx; SetupUserIOCtx(&ctx);
|
|
|
|
return desc->getsockopt(&ctx, level, option_name, option_value, option_size_ptr);
|
|
|
|
}
|
|
|
|
|
2014-10-16 18:04:47 -04:00
|
|
|
int sys_setsockopt(int fd, int level, int option_name,
|
|
|
|
const void* option_value, size_t option_size)
|
2014-02-28 11:10:08 -05:00
|
|
|
{
|
|
|
|
Ref<Descriptor> desc = CurrentProcess()->GetDescriptor(fd);
|
|
|
|
if ( !desc )
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
ioctx_t ctx; SetupUserIOCtx(&ctx);
|
|
|
|
return desc->setsockopt(&ctx, level, option_name, option_value, option_size);
|
|
|
|
}
|
|
|
|
|
2014-10-16 18:04:47 -04:00
|
|
|
ssize_t sys_tcgetblob(int fd, const char* name, void* buffer, size_t count)
|
2014-05-05 15:36:40 -04:00
|
|
|
{
|
|
|
|
Ref<Descriptor> desc = CurrentProcess()->GetDescriptor(fd);
|
|
|
|
if ( !desc )
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
char* name_copy = NULL;
|
|
|
|
if ( name && !(name_copy = GetStringFromUser(name)) )
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
ioctx_t ctx; SetupUserIOCtx(&ctx);
|
|
|
|
ssize_t result = desc->tcgetblob(&ctx, name_copy, buffer, count);
|
|
|
|
delete[] name_copy;
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2014-10-16 18:04:47 -04:00
|
|
|
ssize_t sys_tcsetblob(int fd, const char* name, const void* buffer, size_t count)
|
2014-05-05 15:36:40 -04:00
|
|
|
{
|
|
|
|
Ref<Descriptor> desc = CurrentProcess()->GetDescriptor(fd);
|
|
|
|
if ( !desc )
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
char* name_copy = NULL;
|
|
|
|
if ( name && !(name_copy = GetStringFromUser(name)) )
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
ioctx_t ctx; SetupUserIOCtx(&ctx);
|
|
|
|
ssize_t result = desc->tcsetblob(&ctx, name_copy, buffer, count);
|
|
|
|
delete[] name_copy;
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2017-02-23 14:12:26 -05:00
|
|
|
int sys_getpeername(int fd, void* addr, size_t* addrsize)
|
2014-06-27 17:26:59 -04:00
|
|
|
{
|
2017-02-23 14:12:26 -05:00
|
|
|
Ref<Descriptor> desc = CurrentProcess()->GetDescriptor(fd);
|
|
|
|
if ( !desc )
|
|
|
|
return -1;
|
|
|
|
ioctx_t ctx; SetupUserIOCtx(&ctx);
|
|
|
|
return desc->getpeername(&ctx, (uint8_t*) addr, addrsize);
|
2014-06-27 17:26:59 -04:00
|
|
|
}
|
|
|
|
|
2017-02-23 14:12:26 -05:00
|
|
|
int sys_getsockname(int fd, void* addr, size_t* addrsize)
|
2014-06-27 17:26:59 -04:00
|
|
|
{
|
2017-02-23 14:12:26 -05:00
|
|
|
Ref<Descriptor> desc = CurrentProcess()->GetDescriptor(fd);
|
|
|
|
if ( !desc )
|
|
|
|
return -1;
|
|
|
|
ioctx_t ctx; SetupUserIOCtx(&ctx);
|
|
|
|
return desc->getsockname(&ctx, (uint8_t*) addr, addrsize);
|
2014-06-27 17:26:59 -04:00
|
|
|
}
|
|
|
|
|
2014-10-16 18:04:47 -04:00
|
|
|
int sys_shutdown(int fd, int how)
|
2014-06-27 18:11:13 -04:00
|
|
|
{
|
2016-08-06 09:44:37 -04:00
|
|
|
Ref<Descriptor> desc = CurrentProcess()->GetDescriptor(fd);
|
|
|
|
if ( !desc )
|
|
|
|
return -1;
|
|
|
|
ioctx_t ctx; SetupUserIOCtx(&ctx);
|
|
|
|
return desc->shutdown(&ctx, how);
|
2014-06-27 18:11:13 -04:00
|
|
|
}
|
|
|
|
|
2014-05-07 08:14:38 -04:00
|
|
|
int sys_unmountat(int dirfd, const char* path, int flags)
|
|
|
|
{
|
|
|
|
char* pathcopy = GetStringFromUser(path);
|
|
|
|
if ( !pathcopy )
|
|
|
|
return -1;
|
|
|
|
ioctx_t ctx; SetupUserIOCtx(&ctx);
|
2015-05-13 11:10:19 -04:00
|
|
|
Ref<Descriptor> from = PrepareLookup(pathcopy, dirfd);
|
2014-05-07 08:14:38 -04:00
|
|
|
if ( !from )
|
|
|
|
return delete[] pathcopy, -1;
|
2015-05-13 11:10:19 -04:00
|
|
|
int ret = from->unmount(&ctx, pathcopy, flags);
|
2014-05-07 08:14:38 -04:00
|
|
|
delete[] pathcopy;
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
int sys_fsm_fsbind(int rootfd, int mpointfd, int flags)
|
|
|
|
{
|
|
|
|
if ( flags & ~(0) )
|
|
|
|
return errno = EINVAL, -1;
|
|
|
|
Ref<Descriptor> desc = CurrentProcess()->GetDescriptor(rootfd);
|
|
|
|
if ( !desc )
|
|
|
|
return -1;
|
|
|
|
Ref<Descriptor> mpoint = CurrentProcess()->GetDescriptor(mpointfd);
|
|
|
|
if ( !mpoint )
|
|
|
|
return -1;
|
|
|
|
ioctx_t ctx; SetupUserIOCtx(&ctx);
|
|
|
|
return mpoint->fsm_fsbind(&ctx, desc, flags);
|
|
|
|
}
|
|
|
|
|
|
|
|
int sys_fsm_mountat(int dirfd, const char* path, const struct stat* rootst, int flags)
|
|
|
|
{
|
|
|
|
if ( flags & ~(FSM_MOUNT_CLOEXEC | FSM_MOUNT_CLOFORK |
|
|
|
|
FSM_MOUNT_NOFOLLOW | FSM_MOUNT_NONBLOCK) )
|
|
|
|
return -1;
|
|
|
|
int fdflags = 0;
|
|
|
|
if ( flags & FSM_MOUNT_CLOEXEC ) fdflags |= FD_CLOEXEC;
|
|
|
|
if ( flags & FSM_MOUNT_CLOFORK ) fdflags |= FD_CLOFORK;
|
|
|
|
flags &= ~(FSM_MOUNT_CLOEXEC | FSM_MOUNT_CLOFORK);
|
|
|
|
char* pathcopy = GetStringFromUser(path);
|
|
|
|
if ( !pathcopy )
|
|
|
|
return -1;
|
|
|
|
ioctx_t ctx; SetupUserIOCtx(&ctx);
|
2015-05-13 11:10:19 -04:00
|
|
|
Ref<Descriptor> from = PrepareLookup(pathcopy, dirfd);
|
2014-05-07 08:14:38 -04:00
|
|
|
if ( !from )
|
|
|
|
return delete[] pathcopy, -1;
|
2015-05-13 11:10:19 -04:00
|
|
|
Ref<Descriptor> desc = from->fsm_mount(&ctx, pathcopy, rootst, flags);
|
2014-05-07 08:14:38 -04:00
|
|
|
delete[] pathcopy;
|
2016-01-27 15:24:20 -05:00
|
|
|
if ( !desc )
|
|
|
|
return -1;
|
2014-05-07 08:14:38 -04:00
|
|
|
Ref<DescriptorTable> dtable = CurrentProcess()->GetDTable();
|
|
|
|
int ret = dtable->Allocate(desc, fdflags);
|
|
|
|
if ( ret < 0 )
|
|
|
|
{
|
|
|
|
// TODO: We should use a fail-safe dtable reservation mechanism that
|
|
|
|
// causes this error earlier before we have side effects.
|
|
|
|
int errnum = errno;
|
2015-05-13 11:10:19 -04:00
|
|
|
from->unmount(&ctx, pathcopy, 0);
|
2014-05-07 08:14:38 -04:00
|
|
|
return errno = errnum, -1;
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2016-01-23 14:56:07 -05:00
|
|
|
int sys_tcdrain(int fd)
|
|
|
|
{
|
|
|
|
Ref<Descriptor> desc = CurrentProcess()->GetDescriptor(fd);
|
|
|
|
if ( !desc )
|
|
|
|
return -1;
|
|
|
|
ioctx_t ctx; SetupUserIOCtx(&ctx);
|
|
|
|
return desc->tcdrain(&ctx);
|
|
|
|
}
|
|
|
|
|
|
|
|
int sys_tcflow(int fd, int action)
|
|
|
|
{
|
|
|
|
Ref<Descriptor> desc = CurrentProcess()->GetDescriptor(fd);
|
|
|
|
if ( !desc )
|
|
|
|
return -1;
|
|
|
|
ioctx_t ctx; SetupUserIOCtx(&ctx);
|
|
|
|
return desc->tcflow(&ctx, action);
|
|
|
|
}
|
|
|
|
|
|
|
|
int sys_tcflush(int fd, int queue_selector)
|
|
|
|
{
|
|
|
|
Ref<Descriptor> desc = CurrentProcess()->GetDescriptor(fd);
|
|
|
|
if ( !desc )
|
|
|
|
return -1;
|
|
|
|
ioctx_t ctx; SetupUserIOCtx(&ctx);
|
|
|
|
return desc->tcflush(&ctx, queue_selector);
|
|
|
|
}
|
|
|
|
|
|
|
|
int sys_tcgetattr(int fd, struct termios* tio)
|
|
|
|
{
|
|
|
|
Ref<Descriptor> desc = CurrentProcess()->GetDescriptor(fd);
|
|
|
|
if ( !desc )
|
|
|
|
return -1;
|
|
|
|
ioctx_t ctx; SetupUserIOCtx(&ctx);
|
|
|
|
return desc->tcgetattr(&ctx, tio);
|
|
|
|
}
|
|
|
|
|
|
|
|
pid_t sys_tcgetsid(int fd)
|
|
|
|
{
|
|
|
|
Ref<Descriptor> desc = CurrentProcess()->GetDescriptor(fd);
|
|
|
|
if ( !desc )
|
|
|
|
return -1;
|
|
|
|
ioctx_t ctx; SetupUserIOCtx(&ctx);
|
|
|
|
return desc->tcgetsid(&ctx);
|
|
|
|
}
|
|
|
|
|
|
|
|
int sys_tcsendbreak(int fd, int duration)
|
|
|
|
{
|
|
|
|
Ref<Descriptor> desc = CurrentProcess()->GetDescriptor(fd);
|
|
|
|
if ( !desc )
|
|
|
|
return -1;
|
|
|
|
ioctx_t ctx; SetupUserIOCtx(&ctx);
|
|
|
|
return desc->tcsendbreak(&ctx, duration);
|
|
|
|
}
|
|
|
|
|
|
|
|
int sys_tcsetattr(int fd, int actions, const struct termios* tio)
|
|
|
|
{
|
|
|
|
Ref<Descriptor> desc = CurrentProcess()->GetDescriptor(fd);
|
|
|
|
if ( !desc )
|
|
|
|
return -1;
|
|
|
|
ioctx_t ctx; SetupUserIOCtx(&ctx);
|
|
|
|
return desc->tcsetattr(&ctx, actions, tio);
|
|
|
|
}
|
|
|
|
|
2012-08-07 18:19:44 -04:00
|
|
|
} // namespace Sortix
|