mirror of
https://gitlab.com/sortix/sortix.git
synced 2023-02-13 20:55:38 -05:00
Implement F_SETFL and F_GETFL support in fcntl.
This commit is contained in:
parent
ac1d64fd7e
commit
38b146472e
3 changed files with 25 additions and 1 deletions
|
@ -110,6 +110,23 @@ Descriptor::~Descriptor()
|
|||
{
|
||||
}
|
||||
|
||||
bool Descriptor::SetFlags(int new_dflags)
|
||||
{
|
||||
// TODO: Hmm, there is race condition between changing the flags here and
|
||||
// the code that uses the flags below. We could add a lock, but that
|
||||
// would kinda prevent concurrency on the same file descriptor. Since
|
||||
// the chances of this becoming a problem is rather slim (but could
|
||||
// happen!), we'll do the unsafe thing for now. (See below also)
|
||||
dflags = (dflags & ~DESCRIPTOR_FLAGS) & (new_dflags & DESCRIPTOR_FLAGS);
|
||||
return true;
|
||||
}
|
||||
|
||||
int Descriptor::GetFlags()
|
||||
{
|
||||
// TODO: The race condition also applies here if the variable can change.
|
||||
return dflags;
|
||||
}
|
||||
|
||||
Ref<Descriptor> Descriptor::Fork()
|
||||
{
|
||||
Ref<Descriptor> ret(new Descriptor(vnode, dflags));
|
||||
|
|
|
@ -53,6 +53,8 @@ public:
|
|||
Descriptor(Ref<Vnode> vnode, int dflags);
|
||||
virtual ~Descriptor();
|
||||
Ref<Descriptor> Fork();
|
||||
bool SetFlags(int new_dflags);
|
||||
int GetFlags();
|
||||
int sync(ioctx_t* ctx);
|
||||
int stat(ioctx_t* ctx, struct stat* st);
|
||||
int chmod(ioctx_t* ctx, mode_t mode);
|
||||
|
|
|
@ -300,6 +300,7 @@ static int sys_fstat(int fd, struct stat* st)
|
|||
static int sys_fcntl(int fd, int cmd, unsigned long arg)
|
||||
{
|
||||
Ref<DescriptorTable> dtable = CurrentProcess()->GetDTable();
|
||||
Ref<Descriptor> desc;
|
||||
int ret = -1;
|
||||
switch ( cmd )
|
||||
{
|
||||
|
@ -310,8 +311,12 @@ static int sys_fcntl(int fd, int cmd, unsigned long arg)
|
|||
ret = dtable->GetFlags(fd);
|
||||
break;
|
||||
case F_SETFL:
|
||||
if ( (desc = dtable->Get(fd)) )
|
||||
ret = desc->SetFlags((int) arg) ? 0 : -1;
|
||||
break;
|
||||
case F_GETFL:
|
||||
errno = ENOSYS;
|
||||
if ( (desc = dtable->Get(fd)) )
|
||||
ret = desc->GetFlags();
|
||||
break;
|
||||
default:
|
||||
errno = EINVAL;
|
||||
|
|
Loading…
Reference in a new issue