mirror of
https://gitlab.com/sortix/sortix.git
synced 2023-02-13 20:55:38 -05:00
Remember path when opening files.
This commit is contained in:
parent
db57bb6336
commit
32f87f461d
6 changed files with 47 additions and 12 deletions
|
@ -23,6 +23,7 @@
|
|||
*******************************************************************************/
|
||||
|
||||
#include <sortix/kernel/platform.h>
|
||||
#include <sortix/kernel/string.h>
|
||||
#include <assert.h>
|
||||
#include <string.h>
|
||||
#include "descriptors.h"
|
||||
|
@ -54,6 +55,7 @@ namespace Sortix
|
|||
if ( !dev || dev == RESERVED_DEVICE ) { continue; }
|
||||
|
||||
dev->Unref();
|
||||
delete[] devices[i].path;
|
||||
}
|
||||
|
||||
delete[] devices;
|
||||
|
@ -61,7 +63,7 @@ namespace Sortix
|
|||
numdevices = 0;
|
||||
}
|
||||
|
||||
int DescriptorTable::Allocate(Device* object)
|
||||
int DescriptorTable::Allocate(Device* object, char* pathcopy)
|
||||
{
|
||||
for ( int i = 0; i < numdevices; i++ )
|
||||
{
|
||||
|
@ -70,6 +72,7 @@ namespace Sortix
|
|||
object->Refer();
|
||||
devices[i].dev = object;
|
||||
devices[i].flags = 0;
|
||||
devices[i].path = pathcopy;
|
||||
return i;
|
||||
}
|
||||
}
|
||||
|
@ -86,14 +89,17 @@ namespace Sortix
|
|||
}
|
||||
|
||||
size_t numpadded = newlistlength-numdevices;
|
||||
memset(newlist + numdevices, 0, sizeof(*devices) * numpadded);
|
||||
for ( size_t i = numdevices; i < newlistlength; i++ )
|
||||
newlist[i].dev = NULL,
|
||||
newlist[i].path = NULL,
|
||||
newlist[i].flags = 0;
|
||||
|
||||
delete[] devices;
|
||||
|
||||
devices = newlist;
|
||||
numdevices = newlistlength;
|
||||
|
||||
return Allocate(object);
|
||||
return Allocate(object, pathcopy);
|
||||
}
|
||||
|
||||
void DescriptorTable::Free(int index)
|
||||
|
@ -104,26 +110,30 @@ namespace Sortix
|
|||
if ( devices[index].dev != RESERVED_DEVICE )
|
||||
{
|
||||
devices[index].dev->Unref();
|
||||
delete[] devices[index].path;
|
||||
}
|
||||
|
||||
devices[index].dev = NULL;
|
||||
devices[index].path = NULL;
|
||||
devices[index].flags = 0;
|
||||
}
|
||||
|
||||
int DescriptorTable::Reserve()
|
||||
{
|
||||
return Allocate(RESERVED_DEVICE);
|
||||
return Allocate(RESERVED_DEVICE, NULL);
|
||||
}
|
||||
|
||||
void DescriptorTable::UseReservation(int index, Device* object)
|
||||
void DescriptorTable::UseReservation(int index, Device* object, char* pathcopy)
|
||||
{
|
||||
assert(index < index);
|
||||
assert(devices[index].dev != NULL);
|
||||
assert(devices[index].dev == RESERVED_DEVICE);
|
||||
assert(devices[index].path == NULL);
|
||||
|
||||
object->Refer();
|
||||
devices[index].dev = object;
|
||||
devices[index].flags = 0;
|
||||
devices[index].path = pathcopy;
|
||||
}
|
||||
|
||||
bool DescriptorTable::Fork(DescriptorTable* forkinto)
|
||||
|
@ -135,11 +145,16 @@ namespace Sortix
|
|||
{
|
||||
Device* dev = devices[i].dev;
|
||||
int flags = devices[i].flags;
|
||||
char* path = devices[i].path;
|
||||
if ( !dev || dev == RESERVED_DEVICE )
|
||||
path = NULL;
|
||||
path = path ? String::Clone(path) : NULL;
|
||||
if ( flags & FD_CLOFORK ) { dev = NULL; flags = 0; }
|
||||
newlist[i].dev = dev;
|
||||
newlist[i].flags = flags;
|
||||
if ( !dev || dev == RESERVED_DEVICE ) { continue; }
|
||||
newlist[i].dev->Refer();
|
||||
newlist[i].path = path;
|
||||
}
|
||||
|
||||
assert(!forkinto->devices);
|
||||
|
@ -171,5 +186,12 @@ namespace Sortix
|
|||
assert(devices[index].dev);
|
||||
return devices[index].flags;
|
||||
}
|
||||
|
||||
const char* DescriptorTable::GetPath(int index)
|
||||
{
|
||||
assert(0 <= index && index < numdevices);
|
||||
assert(devices[index].dev);
|
||||
return devices[index].path;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -33,6 +33,7 @@ namespace Sortix
|
|||
{
|
||||
Device* dev;
|
||||
int flags;
|
||||
char* path;
|
||||
};
|
||||
|
||||
class DescriptorTable
|
||||
|
@ -46,15 +47,16 @@ namespace Sortix
|
|||
DescriptorEntry* devices;
|
||||
|
||||
public:
|
||||
int Allocate(Device* object);
|
||||
int Allocate(Device* object, char* pathcopy);
|
||||
int Reserve();
|
||||
void Free(int index);
|
||||
void UseReservation(int index, Device* object);
|
||||
void UseReservation(int index, Device* object, char* pathcopy);
|
||||
bool Fork(DescriptorTable* forkinto);
|
||||
void OnExecute();
|
||||
void Reset();
|
||||
void SetFlags(int index, int flags);
|
||||
int GetFlags(int index);
|
||||
const char* GetPath(int index);
|
||||
|
||||
public:
|
||||
inline Device* Get(int index)
|
||||
|
|
|
@ -23,6 +23,7 @@
|
|||
******************************************************************************/
|
||||
|
||||
#include <sortix/kernel/platform.h>
|
||||
#include <sortix/kernel/string.h>
|
||||
#include <errno.h>
|
||||
#include <string.h>
|
||||
#include "syscall.h"
|
||||
|
@ -70,10 +71,13 @@ namespace Sortix
|
|||
|
||||
int SysOpen(const char* path, int flags, mode_t mode)
|
||||
{
|
||||
char* pathcopy = String::Clone(path);
|
||||
if ( !pathcopy )
|
||||
return -1;
|
||||
Process* process = CurrentProcess();
|
||||
Device* dev = Open(path, flags, mode);
|
||||
if ( !dev ) { return -1; /* TODO: errno */ }
|
||||
int fd = process->descriptors.Allocate(dev);
|
||||
if ( !dev ) { delete[] pathcopy; return -1; }
|
||||
int fd = process->descriptors.Allocate(dev, pathcopy);
|
||||
if ( fd < 0 ) { dev->Unref(); }
|
||||
int fdflags = 0;
|
||||
if ( flags & O_CLOEXEC ) { fdflags |= FD_CLOEXEC; }
|
||||
|
|
|
@ -23,6 +23,7 @@
|
|||
*******************************************************************************/
|
||||
|
||||
#include <sortix/kernel/platform.h>
|
||||
#include <sortix/kernel/string.h>
|
||||
#include <sortix/kernel/kthread.h>
|
||||
#include <sortix/seek.h>
|
||||
#include <errno.h>
|
||||
|
@ -179,7 +180,9 @@ namespace Sortix
|
|||
Process* process = CurrentProcess();
|
||||
Device* dev = process->descriptors.Get(fd);
|
||||
if ( !dev ) { errno = EBADF; return -1; }
|
||||
return process->descriptors.Allocate(dev);
|
||||
const char* path = process->descriptors.GetPath(fd);
|
||||
char* pathcopy = path ? String::Clone(path) : NULL;
|
||||
return process->descriptors.Allocate(dev, pathcopy);
|
||||
}
|
||||
|
||||
void Init()
|
||||
|
|
|
@ -338,8 +338,8 @@ namespace Sortix
|
|||
if ( !writing ) { delete reading; return -1; /* TODO: ENOMEM */ }
|
||||
|
||||
Process* process = CurrentProcess();
|
||||
int readfd = process->descriptors.Allocate(reading);
|
||||
int writefd = process->descriptors.Allocate(writing);
|
||||
int readfd = process->descriptors.Allocate(reading, NULL);
|
||||
int writefd = process->descriptors.Allocate(writing, NULL);
|
||||
|
||||
if ( readfd < 0 || writefd < 0 )
|
||||
{
|
||||
|
|
|
@ -40,6 +40,10 @@ TextTerminal::TextTerminal(TextBufferHandle* textbufhandle)
|
|||
Reset();
|
||||
}
|
||||
|
||||
TextTerminal::~TextTerminal()
|
||||
{
|
||||
}
|
||||
|
||||
void TextTerminal::Reset()
|
||||
{
|
||||
vgacolor = DEFAULT_COLOR;
|
||||
|
|
Loading…
Reference in a new issue