Implement F_SETFL and F_GETFL support in fcntl.
This commit is contained in:
parent
ac1d64fd7e
commit
38b146472e
|
@ -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> Descriptor::Fork()
|
||||||
{
|
{
|
||||||
Ref<Descriptor> ret(new Descriptor(vnode, dflags));
|
Ref<Descriptor> ret(new Descriptor(vnode, dflags));
|
||||||
|
|
|
@ -53,6 +53,8 @@ public:
|
||||||
Descriptor(Ref<Vnode> vnode, int dflags);
|
Descriptor(Ref<Vnode> vnode, int dflags);
|
||||||
virtual ~Descriptor();
|
virtual ~Descriptor();
|
||||||
Ref<Descriptor> Fork();
|
Ref<Descriptor> Fork();
|
||||||
|
bool SetFlags(int new_dflags);
|
||||||
|
int GetFlags();
|
||||||
int sync(ioctx_t* ctx);
|
int sync(ioctx_t* ctx);
|
||||||
int stat(ioctx_t* ctx, struct stat* st);
|
int stat(ioctx_t* ctx, struct stat* st);
|
||||||
int chmod(ioctx_t* ctx, mode_t mode);
|
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)
|
static int sys_fcntl(int fd, int cmd, unsigned long arg)
|
||||||
{
|
{
|
||||||
Ref<DescriptorTable> dtable = CurrentProcess()->GetDTable();
|
Ref<DescriptorTable> dtable = CurrentProcess()->GetDTable();
|
||||||
|
Ref<Descriptor> desc;
|
||||||
int ret = -1;
|
int ret = -1;
|
||||||
switch ( cmd )
|
switch ( cmd )
|
||||||
{
|
{
|
||||||
|
@ -310,8 +311,12 @@ static int sys_fcntl(int fd, int cmd, unsigned long arg)
|
||||||
ret = dtable->GetFlags(fd);
|
ret = dtable->GetFlags(fd);
|
||||||
break;
|
break;
|
||||||
case F_SETFL:
|
case F_SETFL:
|
||||||
|
if ( (desc = dtable->Get(fd)) )
|
||||||
|
ret = desc->SetFlags((int) arg) ? 0 : -1;
|
||||||
|
break;
|
||||||
case F_GETFL:
|
case F_GETFL:
|
||||||
errno = ENOSYS;
|
if ( (desc = dtable->Get(fd)) )
|
||||||
|
ret = desc->GetFlags();
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
errno = EINVAL;
|
errno = EINVAL;
|
||||||
|
|
Loading…
Reference in New Issue