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