From: John Hodge Date: Thu, 16 May 2013 05:17:05 +0000 (+0800) Subject: Kernel - Added 'Flags' param to VFS Read/Write/FindDir X-Git-Tag: rel0.15~476 X-Git-Url: https://git.ucc.asn.au/?a=commitdiff_plain;h=015f48988e0ff398409d71dfc692005ab439490a;p=tpg%2Facess2.git Kernel - Added 'Flags' param to VFS Read/Write/FindDir - Used for non-blocking IO --- diff --git a/KernelLand/Kernel/arch/x86/time.c b/KernelLand/Kernel/arch/x86/time.c index c79d4593..54e59a5d 100644 --- a/KernelLand/Kernel/arch/x86/time.c +++ b/KernelLand/Kernel/arch/x86/time.c @@ -4,6 +4,7 @@ * arch/x86/time.c */ #include +#include // === MACROS === #define TIMER_QUANTUM 100 diff --git a/KernelLand/Kernel/debug.c b/KernelLand/Kernel/debug.c index 49600c20..f0d21fa7 100644 --- a/KernelLand/Kernel/debug.c +++ b/KernelLand/Kernel/debug.c @@ -11,8 +11,7 @@ // === IMPORTS === extern void Threads_Dump(void); -extern void Heap_Dump(void) - ; +extern void Heap_Dump(void); extern void KernelPanic_SetMode(void); extern void KernelPanic_PutChar(char Ch); extern void IPStack_SendDebugText(const char *Text); @@ -24,7 +23,6 @@ void Debug_DbgOnlyFmt(const char *format, va_list args); void Debug_FmtS(int bUseKTerm, const char *format, ...); void Debug_Fmt(int bUseKTerm, const char *format, va_list args); void Debug_SetKTerminal(const char *File); -void LogFV(const char *Fmt, va_list args); // === GLOBALS === int gDebug_Level = 0; diff --git a/KernelLand/Kernel/drv/dgram_pipe.c b/KernelLand/Kernel/drv/dgram_pipe.c index 0acae3ad..c13ca2a7 100644 --- a/KernelLand/Kernel/drv/dgram_pipe.c +++ b/KernelLand/Kernel/drv/dgram_pipe.c @@ -64,15 +64,15 @@ struct sIPCPipe_Server // - Root tVFS_Node *IPCPipe_Root_MkNod(tVFS_Node *Node, const char *Name, Uint Flags); int IPCPipe_Root_ReadDir(tVFS_Node *Node, int ID, char Name[FILENAME_MAX]); -tVFS_Node *IPCPipe_Root_FindDir(tVFS_Node *Node, const char *Name); +tVFS_Node *IPCPipe_Root_FindDir(tVFS_Node *Node, const char *Name, Uint Flags); // - Server int IPCPipe_Server_ReadDir(tVFS_Node *Node, int ID, char Name[FILENAME_MAX]); -tVFS_Node *IPCPipe_Server_FindDir(tVFS_Node *Node, const char *Name); +tVFS_Node *IPCPipe_Server_FindDir(tVFS_Node *Node, const char *Name, Uint Flags); void IPCPipe_Server_Close(tVFS_Node *Node); // - Socket tIPCPipe_Channel *IPCPipe_int_GetEPs(tVFS_Node *Node, tIPCPipe_Endpoint **lep, tIPCPipe_Endpoint **rep); -size_t IPCPipe_Client_Read(tVFS_Node *Node, off_t Offset, size_t Length, void *Dest); -size_t IPCPipe_Client_Write(tVFS_Node *Node, off_t Offset, size_t Length, const void *Src); +size_t IPCPipe_Client_Read(tVFS_Node *Node, off_t Offset, size_t Length, void *Dest, Uint Flags); +size_t IPCPipe_Client_Write(tVFS_Node *Node, off_t Offset, size_t Length, const void *Src, Uint Flags); void IPCPipe_Client_Close(tVFS_Node *Node); // === GLOBALS === @@ -179,7 +179,7 @@ int IPCPipe_Root_ReadDir(tVFS_Node *Node, int ID, char Name[FILENAME_MAX]) /** * \return New client pointer */ -tVFS_Node *IPCPipe_Root_FindDir(tVFS_Node *Node, const char *Name) +tVFS_Node *IPCPipe_Root_FindDir(tVFS_Node *Node, const char *Name, Uint Flags) { tIPCPipe_Server *srv; ENTER("pNode sName", Node, Name); @@ -198,9 +198,14 @@ tVFS_Node *IPCPipe_Root_FindDir(tVFS_Node *Node, const char *Name) return NULL; } + if( Flags & VFS_FDIRFLAG_STAT ) { + // LEAVE('p', srv->TplClientNode); + // return &srv->TplClientNode; + } + // Create new client - tIPCPipe_Channel *new_client; - + tIPCPipe_Channel *new_client; + new_client = calloc(1, sizeof(tIPCPipe_Channel)); new_client->Server = srv; new_client->ClientEP.Node.Type = &gIPCPipe_ChannelNodeType; @@ -230,7 +235,7 @@ int IPCPipe_Server_ReadDir(tVFS_Node *Node, int ID, char Name[FILENAME_MAX]) // 'next' is a valid entry, but readdir should never be called on this node return -1; } -tVFS_Node *IPCPipe_Server_FindDir(tVFS_Node *Node, const char *Name) +tVFS_Node *IPCPipe_Server_FindDir(tVFS_Node *Node, const char *Name, Uint Flags) { tIPCPipe_Server *srv = Node->ImplPtr; @@ -241,6 +246,7 @@ tVFS_Node *IPCPipe_Server_FindDir(tVFS_Node *Node, const char *Name) return NULL; } + // TODO: Need VFS_FDIRFLAG_NOBLOCK? VFS_SelectNode(Node, VFS_SELECT_READ, 0, "IPCPipe Server"); tIPCPipe_Channel *conn; @@ -303,7 +309,7 @@ tIPCPipe_Channel *IPCPipe_int_GetEPs(tVFS_Node *Node, tIPCPipe_Endpoint **lep, t } return ch; } -size_t IPCPipe_Client_Read(tVFS_Node *Node, off_t Offset, size_t Length, void *Dest) +size_t IPCPipe_Client_Read(tVFS_Node *Node, off_t Offset, size_t Length, void *Dest, Uint Flags) { tIPCPipe_Endpoint *lep, *rep; tIPCPipe_Channel *channel = IPCPipe_int_GetEPs(Node, &lep, &rep); @@ -317,8 +323,15 @@ size_t IPCPipe_Client_Read(tVFS_Node *Node, off_t Offset, size_t Length, void *D } // Wait for a packet to be ready - VFS_SelectNode(Node, VFS_SELECT_READ, 0, "IPCPipe Endpoint"); + tTime timeout_z = 0, *timeout = ((Flags & VFS_IOFLAG_NOBLOCK) ? &timeout_z : NULL); + int rv = VFS_SelectNode(Node, VFS_SELECT_READ, timeout, "IPCPipe Endpoint"); + if( !rv ) { + errno = (Flags & VFS_IOFLAG_NOBLOCK) ? EWOULDBLOCK : EINTR; + LEAVE('i', -1); + return -1; + } if( channel->Server == NULL ) { + //errno = EIO; LEAVE('i', -1); return -1; } @@ -328,6 +341,7 @@ size_t IPCPipe_Client_Read(tVFS_Node *Node, off_t Offset, size_t Length, void *D if( !rep->Node.ImplPtr ) { Mutex_Release(&rep->lList); + //errno = EIO; LEAVE('i', -1); return -1; } @@ -356,7 +370,7 @@ size_t IPCPipe_Client_Read(tVFS_Node *Node, off_t Offset, size_t Length, void *D return ret; } -size_t IPCPipe_Client_Write(tVFS_Node *Node, off_t Offset, size_t Length, const void *Src) +size_t IPCPipe_Client_Write(tVFS_Node *Node, off_t Offset, size_t Length, const void *Src, Uint Flags) { tIPCPipe_Endpoint *lep, *rep; tIPCPipe_Channel *channel = IPCPipe_int_GetEPs(Node, &lep, &rep); @@ -374,7 +388,9 @@ size_t IPCPipe_Client_Write(tVFS_Node *Node, off_t Offset, size_t Length, const return 0; } - // Create packet structure + // TODO: Ensure that no more than DEF_MAX_BYTE_LIMIT bytes are in flight at one time + + // Create packet structure tIPCPipe_Packet *pkt = malloc(sizeof(tIPCPipe_Packet)+Length); pkt->Next = NULL; pkt->Offset = 0; diff --git a/KernelLand/Kernel/drv/fifo.c b/KernelLand/Kernel/drv/fifo.c index 6c635780..de3192ab 100644 --- a/KernelLand/Kernel/drv/fifo.c +++ b/KernelLand/Kernel/drv/fifo.c @@ -31,13 +31,13 @@ typedef struct sPipe { int FIFO_Install(char **Arguments); int FIFO_IOCtl(tVFS_Node *Node, int Id, void *Data); int FIFO_ReadDir(tVFS_Node *Node, int Id, char Dest[FILENAME_MAX]); -tVFS_Node *FIFO_FindDir(tVFS_Node *Node, const char *Filename); +tVFS_Node *FIFO_FindDir(tVFS_Node *Node, const char *Filename, Uint Flags); tVFS_Node *FIFO_MkNod(tVFS_Node *Node, const char *Name, Uint Flags); void FIFO_Reference(tVFS_Node *Node); void FIFO_Close(tVFS_Node *Node); int FIFO_Unlink(tVFS_Node *Node, const char *OldName); -size_t FIFO_Read(tVFS_Node *Node, off_t Offset, size_t Length, void *Buffer); -size_t FIFO_Write(tVFS_Node *Node, off_t Offset, size_t Length, const void *Buffer); +size_t FIFO_Read(tVFS_Node *Node, off_t Offset, size_t Length, void *Buffer, Uint Flags); +size_t FIFO_Write(tVFS_Node *Node, off_t Offset, size_t Length, const void *Buffer, Uint Flags); tPipe *FIFO_Int_NewPipe(int Size, const char *Name); // === GLOBALS === @@ -121,7 +121,7 @@ int FIFO_ReadDir(tVFS_Node *Node, int Id, char Dest[FILENAME_MAX]) * \brief Find a file in the FIFO root * \note Creates an anon pipe if anon is requested */ -tVFS_Node *FIFO_FindDir(tVFS_Node *Node, const char *Filename) +tVFS_Node *FIFO_FindDir(tVFS_Node *Node, const char *Filename, Uint Flags) { tPipe *tmp; if(!Filename) return NULL; @@ -132,6 +132,9 @@ tVFS_Node *FIFO_FindDir(tVFS_Node *Node, const char *Filename) // Anon Pipe if( strcmp(Filename, "anon") == 0 ) { + if( Flags & VFS_FDIRFLAG_STAT ) { + //return &gFIFI_TemplateAnonNode; + } tmp = FIFO_Int_NewPipe(DEFAULT_RING_SIZE, "anon"); return &tmp->Node; } @@ -219,7 +222,7 @@ int FIFO_Unlink(tVFS_Node *Node, const char *OldName) /** * \brief Read from a fifo pipe */ -size_t FIFO_Read(tVFS_Node *Node, off_t Offset, size_t Length, void *Buffer) +size_t FIFO_Read(tVFS_Node *Node, off_t Offset, size_t Length, void *Buffer, Uint Flags) { tPipe *pipe = Node->ImplPtr; Uint len; @@ -232,7 +235,7 @@ size_t FIFO_Read(tVFS_Node *Node, off_t Offset, size_t Length, void *Buffer) while(remaining) { // Wait for buffer to fill - if(pipe->Flags & PF_BLOCKING) + if( (pipe->Flags & PF_BLOCKING) && !(Flags & VFS_IOFLAG_NOBLOCK) ) { if( pipe->ReadPos == pipe->WritePos ) VFS_SelectNode(Node, VFS_SELECT_READ, NULL, "FIFO_Read"); @@ -303,7 +306,7 @@ size_t FIFO_Read(tVFS_Node *Node, off_t Offset, size_t Length, void *Buffer) /** * \brief Write to a fifo pipe */ -size_t FIFO_Write(tVFS_Node *Node, off_t Offset, size_t Length, const void *Buffer) +size_t FIFO_Write(tVFS_Node *Node, off_t Offset, size_t Length, const void *Buffer, Uint Flags) { tPipe *pipe = Node->ImplPtr; Uint len; @@ -316,7 +319,7 @@ size_t FIFO_Write(tVFS_Node *Node, off_t Offset, size_t Length, const void *Buff while(remaining) { // Wait for buffer to empty - if(pipe->Flags & PF_BLOCKING) + if( (pipe->Flags & PF_BLOCKING) && !(Flags & VFS_IOFLAG_NOBLOCK) ) { if( pipe->ReadPos == (pipe->WritePos+1)%pipe->BufSize ) { LOG("Blocking write on FIFO"); @@ -385,7 +388,7 @@ size_t FIFO_Write(tVFS_Node *Node, off_t Offset, size_t Length, const void *Buff return Length; } -// --- HELPERS --- +// --- HeLPERS --- /** * \fn tPipe *FIFO_Int_NewPipe(int Size, const char *Name) * \brief Create a new pipe diff --git a/KernelLand/Kernel/drv/pci.c b/KernelLand/Kernel/drv/pci.c index 1df421ec..dec81b8b 100644 --- a/KernelLand/Kernel/drv/pci.c +++ b/KernelLand/Kernel/drv/pci.c @@ -39,9 +39,9 @@ typedef struct sPCIDevice int PCI_ScanBus(int ID, int bFill); int PCI_int_ReadDirRoot(tVFS_Node *node, int pos, char Dest[FILENAME_MAX]); -tVFS_Node *PCI_int_FindDirRoot(tVFS_Node *node, const char *filename); +tVFS_Node *PCI_int_FindDirRoot(tVFS_Node *node, const char *filename, Uint Flags); Uint32 PCI_int_GetBusAddr(Uint16 Bus, Uint16 Slot, Uint16 Fcn, Uint8 Offset); -size_t PCI_int_ReadDevice(tVFS_Node *node, off_t Offset, size_t Length, void *buffer); +size_t PCI_int_ReadDevice(tVFS_Node *node, off_t Offset, size_t Length, void *buffer, Uint Flags); int PCI_int_EnumDevice(Uint16 bus, Uint16 dev, Uint16 fcn, tPCIDevice *info); // === GLOBALS === @@ -261,12 +261,10 @@ int PCI_int_ReadDirRoot(tVFS_Node *Node, int Pos, char Dest[FILENAME_MAX]) } /** */ -tVFS_Node *PCI_int_FindDirRoot(tVFS_Node *node, const char *filename) +tVFS_Node *PCI_int_FindDirRoot(tVFS_Node *node, const char *filename, Uint Flags) { - int i; - // Find Match - for(i=0;i 0 ) // Sorted list @@ -282,7 +280,7 @@ tVFS_Node *PCI_int_FindDirRoot(tVFS_Node *node, const char *filename) /** * \brief Read the PCI configuration space of a device */ -size_t PCI_int_ReadDevice(tVFS_Node *node, off_t pos, size_t length, void *buffer) +size_t PCI_int_ReadDevice(tVFS_Node *node, off_t pos, size_t length, void *buffer, Uint Flags) { if( pos + length > 256 ) return 0; diff --git a/KernelLand/Kernel/drv/proc.c b/KernelLand/Kernel/drv/proc.c index 930616ae..44cb8183 100644 --- a/KernelLand/Kernel/drv/proc.c +++ b/KernelLand/Kernel/drv/proc.c @@ -32,8 +32,8 @@ typedef struct sSysFS_Ent #endif int SysFS_Comm_ReadDir(tVFS_Node *Node, int Id, char Dest[FILENAME_MAX]); -tVFS_Node *SysFS_Comm_FindDir(tVFS_Node *Node, const char *Filename); -size_t SysFS_Comm_ReadFile(tVFS_Node *Node, off_t Offset, size_t Length, void *Buffer); +tVFS_Node *SysFS_Comm_FindDir(tVFS_Node *Node, const char *Filename, Uint Flags); +size_t SysFS_Comm_ReadFile(tVFS_Node *Node, off_t Offset, size_t Length, void *Buffer, Uint Flags); void SysFS_Comm_CloseFile(tVFS_Node *Node); // === GLOBALS === @@ -361,7 +361,7 @@ int SysFS_Comm_ReadDir(tVFS_Node *Node, int Pos, char Dest[FILENAME_MAX]) * \fn tVFS_Node *SysFS_Comm_FindDir(tVFS_Node *Node, const char *Filename) * \brief Find a file in a SysFS directory */ -tVFS_Node *SysFS_Comm_FindDir(tVFS_Node *Node, const char *Filename) +tVFS_Node *SysFS_Comm_FindDir(tVFS_Node *Node, const char *Filename, Uint Flags) { tSysFS_Ent *child = (tSysFS_Ent*)Node->ImplPtr; @@ -377,7 +377,7 @@ tVFS_Node *SysFS_Comm_FindDir(tVFS_Node *Node, const char *Filename) /** * \brief Read from an exposed buffer */ -size_t SysFS_Comm_ReadFile(tVFS_Node *Node, off_t Offset, size_t Length, void *Buffer) +size_t SysFS_Comm_ReadFile(tVFS_Node *Node, off_t Offset, size_t Length, void *Buffer, Uint Flags) { if( Offset > Node->Size ) return -1; if( Length > Node->Size ) Length = Node->Size; diff --git a/KernelLand/Kernel/drv/vterm.c b/KernelLand/Kernel/drv/vterm.c index cf12ff96..01612dc7 100644 --- a/KernelLand/Kernel/drv/vterm.c +++ b/KernelLand/Kernel/drv/vterm.c @@ -35,10 +35,10 @@ extern void Debug_SetKTerminal(const char *File); // === PROTOTYPES === int VT_Install(char **Arguments); int VT_ReadDir(tVFS_Node *Node, int Pos, char Dest[FILENAME_MAX]); -tVFS_Node *VT_FindDir(tVFS_Node *Node, const char *Name); +tVFS_Node *VT_FindDir(tVFS_Node *Node, const char *Name, Uint Flags); int VT_Root_IOCtl(tVFS_Node *Node, int Id, void *Data); -size_t VT_Read(tVFS_Node *Node, off_t Offset, size_t Length, void *Buffer); -size_t VT_Write(tVFS_Node *Node, off_t Offset, size_t Length, const void *Buffer); +size_t VT_Read(tVFS_Node *Node, off_t Offset, size_t Length, void *Buffer, Uint Flags); +size_t VT_Write(tVFS_Node *Node, off_t Offset, size_t Length, const void *Buffer, Uint Flags); int VT_Terminal_IOCtl(tVFS_Node *Node, int Id, void *Data); void VT_Terminal_Reference(tVFS_Node *Node); void VT_Terminal_Close(tVFS_Node *Node); @@ -285,7 +285,7 @@ int VT_ReadDir(tVFS_Node *Node, int Pos, char Dest[FILENAME_MAX]) * \param Node Root node * \param Name Name (number) of the terminal */ -tVFS_Node *VT_FindDir(tVFS_Node *Node, const char *Name) +tVFS_Node *VT_FindDir(tVFS_Node *Node, const char *Name, Uint Flags) { int num; @@ -354,12 +354,13 @@ int VT_Root_IOCtl(tVFS_Node *Node, int Id, void *Data) /** * \brief Read from a virtual terminal */ -size_t VT_Read(tVFS_Node *Node, off_t Offset, size_t Length, void *Buffer) +size_t VT_Read(tVFS_Node *Node, off_t Offset, size_t Length, void *Buffer, Uint Flags) { - int pos, avail; + int pos, avail, rv; tVTerm *term = &gVT_Terminals[ Node->Inode ]; Uint32 *codepoint_buf = Buffer; Uint32 *codepoint_in; + tTime timeout_zero = 0; Mutex_Acquire( &term->ReadingLock ); @@ -370,7 +371,12 @@ size_t VT_Read(tVFS_Node *Node, off_t Offset, size_t Length, void *Buffer) case TERM_MODE_TEXT: VT_int_UpdateCursor(term, 1); - VFS_SelectNode(Node, VFS_SELECT_READ, NULL, "VT_Read (UTF-8)"); + rv = VFS_SelectNode(Node, VFS_SELECT_READ, + (Flags & VFS_IOFLAG_NOBLOCK ? &timeout_zero : NULL), "VT_Read (UTF-8)"); + if(!rv) { + errno = (Flags & VFS_IOFLAG_NOBLOCK) ? EWOULDBLOCK : EINTR; + return -1; + } avail = term->InputWrite - term->InputRead; if(avail < 0) @@ -392,7 +398,12 @@ size_t VT_Read(tVFS_Node *Node, off_t Offset, size_t Length, void *Buffer) //case TERM_MODE_FB: // Other - UCS-4 default: - VFS_SelectNode(Node, VFS_SELECT_READ, NULL, "VT_Read (UCS-4)"); + rv = VFS_SelectNode(Node, VFS_SELECT_READ, + (Flags & VFS_IOFLAG_NOBLOCK ? &timeout_zero : NULL), "VT_Read (UCS-4)"); + if(!rv) { + errno = (Flags & VFS_IOFLAG_NOBLOCK) ? EWOULDBLOCK : EINTR; + return -1; + } avail = term->InputWrite - term->InputRead; if(avail < 0) @@ -433,7 +444,7 @@ size_t VT_Read(tVFS_Node *Node, off_t Offset, size_t Length, void *Buffer) /** * \brief Write to a virtual terminal */ -size_t VT_Write(tVFS_Node *Node, off_t Offset, size_t Length, const void *Buffer) +size_t VT_Write(tVFS_Node *Node, off_t Offset, size_t Length, const void *Buffer, Uint Flags) { tVTerm *term = &gVT_Terminals[ Node->Inode ]; int size; diff --git a/KernelLand/Kernel/drv/zero-one.c b/KernelLand/Kernel/drv/zero-one.c index e7d3892f..fa2b502f 100644 --- a/KernelLand/Kernel/drv/zero-one.c +++ b/KernelLand/Kernel/drv/zero-one.c @@ -12,12 +12,12 @@ // === PROTOTYPES === int CoreDevs_Install(char **Arguments); -size_t CoreDevs_Write(tVFS_Node *Node, off_t Offset, size_t Length, const void *Buffer); -size_t CoreDevs_Read_Zero(tVFS_Node *Node, off_t Offset, size_t Length, void *Buffer); -size_t CoreDevs_Read_One (tVFS_Node *Node, off_t Offset, size_t Length, void *Buffer); -size_t CoreDevs_Read_Null(tVFS_Node *Node, off_t Offset, size_t Length, void *Buffer); -size_t CoreDevs_Read_FRandom(tVFS_Node *Node, off_t Offset, size_t Length, void *Buffer); -size_t CoreDevs_Read_GRandom(tVFS_Node *Node, off_t Offset, size_t Length, void *Buffer); +size_t CoreDevs_Write(tVFS_Node *Node, off_t Offset, size_t Length, const void *Buffer, Uint Flags); +size_t CoreDevs_Read_Zero(tVFS_Node *Node, off_t Offset, size_t Length, void *Buffer, Uint Flags); +size_t CoreDevs_Read_One (tVFS_Node *Node, off_t Offset, size_t Length, void *Buffer, Uint Flags); +size_t CoreDevs_Read_Null(tVFS_Node *Node, off_t Offset, size_t Length, void *Buffer, Uint Flags); +size_t CoreDevs_Read_FRandom(tVFS_Node *Node, off_t Offset, size_t Length, void *Buffer, Uint Flags); +size_t CoreDevs_Read_GRandom(tVFS_Node *Node, off_t Offset, size_t Length, void *Buffer, Uint Flags); // === GLOBALS === MODULE_DEFINE(0, 0x0100, CoreDevs, CoreDevs_Install, NULL, NULL); @@ -103,18 +103,18 @@ int CoreDevs_Install(char **Options) return MODULE_ERR_OK; } -size_t CoreDevs_Write(tVFS_Node *Node, off_t Offset, size_t Length, const void *Buffer) +size_t CoreDevs_Write(tVFS_Node *Node, off_t Offset, size_t Length, const void *Buffer, Uint Flags) { return Length; // Ignore } -size_t CoreDevs_Read_Zero(tVFS_Node *Node, off_t Offset, size_t Length, void *Buffer) +size_t CoreDevs_Read_Zero(tVFS_Node *Node, off_t Offset, size_t Length, void *Buffer, Uint Flags) { memset(Buffer, 0, Length); return Length; } -size_t CoreDevs_Read_One (tVFS_Node *Node, off_t Offset, size_t Length, void *Buffer) +size_t CoreDevs_Read_One (tVFS_Node *Node, off_t Offset, size_t Length, void *Buffer, Uint Flags) { Uint8 *ptr = Buffer; size_t rem; @@ -123,13 +123,13 @@ size_t CoreDevs_Read_One (tVFS_Node *Node, off_t Offset, size_t Length, void *Bu return Length; } -size_t CoreDevs_Read_Null(tVFS_Node *Node, off_t Offset, size_t Length, void *Buffer) +size_t CoreDevs_Read_Null(tVFS_Node *Node, off_t Offset, size_t Length, void *Buffer, Uint Flags) { return 0; } //! Fast random number generator -size_t CoreDevs_Read_FRandom(tVFS_Node *Node, off_t Offset, size_t Length, void *Buffer) +size_t CoreDevs_Read_FRandom(tVFS_Node *Node, off_t Offset, size_t Length, void *Buffer, Uint Flags) { Uint8 *cbuf = Buffer; for( int i = 0; i < Length; i ++ ) @@ -137,8 +137,9 @@ size_t CoreDevs_Read_FRandom(tVFS_Node *Node, off_t Offset, size_t Length, void return Length; } -size_t CoreDevs_Read_GRandom(tVFS_Node *Node, off_t Offset, size_t Length, void *Buffer) +size_t CoreDevs_Read_GRandom(tVFS_Node *Node, off_t Offset, size_t Length, void *Buffer, Uint Flags) { + // TODO: VFS_IOFLAG_NOBLOCK Log_Error("CoreDevs", "GRandom is unimplimented"); return -1; } diff --git a/KernelLand/Kernel/include/acess_string.h b/KernelLand/Kernel/include/acess_string.h index df909f1a..12e9ba47 100644 --- a/KernelLand/Kernel/include/acess_string.h +++ b/KernelLand/Kernel/include/acess_string.h @@ -31,6 +31,8 @@ extern char *strchr(const char *__s, int __c); extern char *strrchr(const char *__s, int __c); extern void itoa(char *buf, Uint64 num, int base, int minLength, char pad); extern int atoi(const char *string); +extern long atol(const char *string); +extern long long atoll(const char *string); extern unsigned long long strtoull(const char *str, char **end, int base); extern unsigned long strtoul(const char *str, char **end, int base); extern signed long long strtoll(const char *str, char **end, int base); diff --git a/KernelLand/Kernel/include/logdebug.h b/KernelLand/Kernel/include/logdebug.h index 80cb1c93..c2faf7d2 100644 --- a/KernelLand/Kernel/include/logdebug.h +++ b/KernelLand/Kernel/include/logdebug.h @@ -35,6 +35,7 @@ extern void Debug_KernelPanic(void); //!< Initiate a kernel panic extern void Panic(const char *Msg, ...); //!< Print a panic message (initiates a kernel panic) extern void Warning(const char *Msg, ...); //!< Print a warning message extern void LogF(const char *Fmt, ...); //!< Print a log message without a trailing newline +extern void LogFV(const char *Fmt, va_list Args); //!< va_list non-newline log message extern void Log(const char *Fmt, ...); //!< Print a log message extern void Debug(const char *Fmt, ...); //!< Print a debug message (doesn't go to KTerm) extern void LogV(const char *Fmt, va_list Args); //!< va_list Log message diff --git a/KernelLand/Kernel/include/timers.h b/KernelLand/Kernel/include/timers.h index c43c4016..24832986 100644 --- a/KernelLand/Kernel/include/timers.h +++ b/KernelLand/Kernel/include/timers.h @@ -58,5 +58,10 @@ extern void Time_RemoveTimer(tTimer *Timer); */ extern void Time_Delay(int Delay); +/** + * \brief Busy wait for a period of milliseconds + */ +extern void Time_MicroSleep(Uint16 Delay); + #endif diff --git a/KernelLand/Kernel/include/vfs.h b/KernelLand/Kernel/include/vfs.h index 42b42550..82e6b56f 100644 --- a/KernelLand/Kernel/include/vfs.h +++ b/KernelLand/Kernel/include/vfs.h @@ -194,6 +194,28 @@ typedef struct sVFS_Node */ } tVFS_Node; +/** + * \name tVFS_NodeType.FindDir Flags + * \brief + * \{ + */ +//\! Attempt non-blocking IO +#define VFS_IOFLAG_NOBLOCK 0x001 +/** + * \} + */ + +/** + * \name tVFS_NodeType.FindDir Flags + * \brief + * \{ + */ +//\! Call was triggered by VFS_Stat (as opposed to open) +#define VFS_FDIRFLAG_STAT 0x001 +/** + * \} + */ + /** * \brief Functions for a specific node type */ @@ -251,7 +273,7 @@ struct sVFS_NodeType * \param Buffer Destination for read data * \return Number of bytes read */ - size_t (*Read)(struct sVFS_Node *Node, off_t Offset, size_t Length, void *Buffer); + size_t (*Read)(struct sVFS_Node *Node, off_t Offset, size_t Length, void *Buffer, Uint Flags); /** * \brief Write to the file * \param Node Pointer to this node @@ -260,7 +282,7 @@ struct sVFS_NodeType * \param Buffer Source of written data * \return Number of bytes read */ - size_t (*Write)(struct sVFS_Node *Node, off_t Offset, size_t Length, const void *Buffer); + size_t (*Write)(struct sVFS_Node *Node, off_t Offset, size_t Length, const void *Buffer, Uint Flags); /** * \brief Map a region of a file into memory @@ -289,7 +311,7 @@ struct sVFS_NodeType * \note The node returned must be accessable until tVFS_NodeType::Close * is called and ReferenceCount reaches zero. */ - struct sVFS_Node *(*FindDir)(struct sVFS_Node *Node, const char *Name); + struct sVFS_Node *(*FindDir)(struct sVFS_Node *Node, const char *Name, Uint Flags); /** * \brief Read from a directory @@ -307,7 +329,7 @@ struct sVFS_NodeType * \param Flags Flags to apply to the new child (directory or symlink) * \return Created node or NULL on error */ - tVFS_Node *(*MkNod)(struct sVFS_Node *Node, const char *Name, Uint Flags); + tVFS_Node *(*MkNod)(struct sVFS_Node *Node, const char *Name, Uint Mode); /** * \brief Relink (Rename/Remove) a file/directory diff --git a/KernelLand/Kernel/include/vfs_ext.h b/KernelLand/Kernel/include/vfs_ext.h index 00eeebb5..a3a85642 100644 --- a/KernelLand/Kernel/include/vfs_ext.h +++ b/KernelLand/Kernel/include/vfs_ext.h @@ -22,15 +22,17 @@ typedef Uint32 tMount; * \{ */ //! Open for execution -#define VFS_OPENFLAG_EXEC 0x01 +#define VFS_OPENFLAG_EXEC 0x001 //! Open for reading -#define VFS_OPENFLAG_READ 0x02 +#define VFS_OPENFLAG_READ 0x002 //! Open for writing -#define VFS_OPENFLAG_WRITE 0x04 +#define VFS_OPENFLAG_WRITE 0x004 //! Do not resolve the final symbolic link -#define VFS_OPENFLAG_NOLINK 0x40 +#define VFS_OPENFLAG_NOLINK 0x040 //! Create the file if it doesn't exist -#define VFS_OPENFLAG_CREATE 0x80 +#define VFS_OPENFLAG_CREATE 0x080 +//! Open file as non-blocking +#define VFS_OPENFLAG_NONBLOCK 0x100 //! Treat as a directory #define VFS_OPENFLAG_DIRECTORY 0x1000 //! Open as a user diff --git a/KernelLand/Kernel/vfs/acls.c b/KernelLand/Kernel/vfs/acls.c index c8bcc79c..d5deb165 100644 --- a/KernelLand/Kernel/vfs/acls.c +++ b/KernelLand/Kernel/vfs/acls.c @@ -5,6 +5,9 @@ #include "vfs.h" #include "vfs_int.h" +// === PROTOTYPES === +Uint VFS_int_CheckACLs(tVFS_ACL *ACLs, int Num, int bDeny, Uint Perms, tUID UID, tGID GID); + // === GLOBALS === tVFS_ACL gVFS_ACL_EveryoneRWX = { {1,-1}, {0,VFS_PERM_ALL} }; tVFS_ACL gVFS_ACL_EveryoneRW = { {1,-1}, {0,VFS_PERM_ALL^VFS_PERM_EXECUTE} }; diff --git a/KernelLand/Kernel/vfs/fs/devfs.c b/KernelLand/Kernel/vfs/fs/devfs.c index 93898226..ec6c7e2f 100644 --- a/KernelLand/Kernel/vfs/fs/devfs.c +++ b/KernelLand/Kernel/vfs/fs/devfs.c @@ -16,7 +16,7 @@ void DevFS_DelDevice(tDevFS_Driver *Device); tVFS_Node *DevFS_InitDevice(const char *Device, const char **Options); void DevFS_Unmount(tVFS_Node *RootNode); int DevFS_ReadDir(tVFS_Node *Node, int Pos, char Dest[FILENAME_MAX]); -tVFS_Node *DevFS_FindDir(tVFS_Node *Node, const char *Name); +tVFS_Node *DevFS_FindDir(tVFS_Node *Node, const char *Name, Uint Flags); // === GLOBALS === tVFS_Driver gDevFS_Info = { @@ -152,7 +152,7 @@ int DevFS_ReadDir(tVFS_Node *Node, int Pos, char Dest[FILENAME_MAX]) * \fn tVFS_Node *DevFS_FindDir(tVFS_Node *Node, const char *Name) * \brief Get an entry from the devices directory */ -tVFS_Node *DevFS_FindDir(tVFS_Node *Node, const char *Name) +tVFS_Node *DevFS_FindDir(tVFS_Node *Node, const char *Name, Uint Flags) { tDevFS_Driver *dev; diff --git a/KernelLand/Kernel/vfs/fs/root.c b/KernelLand/Kernel/vfs/fs/root.c index 56858617..ee2e72cb 100644 --- a/KernelLand/Kernel/vfs/fs/root.c +++ b/KernelLand/Kernel/vfs/fs/root.c @@ -1,6 +1,11 @@ /* - * AcessMicro VFS + * Acess2 Kernel + * - By John Hodge (thePowersGang) + * + * vfs/fs/root.c * - Root Filesystem Driver + * + * TODO: Restrict to directories only */ #define DEBUG 0 #include @@ -14,10 +19,10 @@ // === PROTOTYPES === tVFS_Node *Root_InitDevice(const char *Device, const char **Options); tVFS_Node *Root_MkNod(tVFS_Node *Node, const char *Name, Uint Flags); -tVFS_Node *Root_FindDir(tVFS_Node *Node, const char *Name); +tVFS_Node *Root_FindDir(tVFS_Node *Node, const char *Name, Uint Flags); int Root_ReadDir(tVFS_Node *Node, int Pos, char Dest[FILENAME_MAX]); -size_t Root_Read(tVFS_Node *Node, off_t Offset, size_t Length, void *Buffer); -size_t Root_Write(tVFS_Node *Node, off_t Offset, size_t Length, const void *Buffer); +size_t Root_Read(tVFS_Node *Node, off_t Offset, size_t Length, void *Buffer, Uint Flags); +size_t Root_Write(tVFS_Node *Node, off_t Offset, size_t Length, const void *Buffer, Uint Flags); tRamFS_File *Root_int_AllocFile(void); // === GLOBALS === @@ -149,7 +154,7 @@ tVFS_Node *Root_MkNod(tVFS_Node *Node, const char *Name, Uint Flags) * \fn tVFS_Node *Root_FindDir(tVFS_Node *Node, const char *Name) * \brief Find an entry in the filesystem */ -tVFS_Node *Root_FindDir(tVFS_Node *Node, const char *Name) +tVFS_Node *Root_FindDir(tVFS_Node *Node, const char *Name, Uint Flags) { tRamFS_File *parent = Node->ImplPtr; tRamFS_File *child = parent->Data.FirstChild; @@ -192,7 +197,7 @@ int Root_ReadDir(tVFS_Node *Node, int Pos, char Dest[FILENAME_MAX]) /** * \brief Read from a file in the root directory */ -size_t Root_Read(tVFS_Node *Node, off_t Offset, size_t Length, void *Buffer) +size_t Root_Read(tVFS_Node *Node, off_t Offset, size_t Length, void *Buffer, Uint Flags) { tRamFS_File *file = Node->ImplPtr; @@ -211,7 +216,7 @@ size_t Root_Read(tVFS_Node *Node, off_t Offset, size_t Length, void *Buffer) /** * \brief Write to a file in the root directory */ -size_t Root_Write(tVFS_Node *Node, off_t Offset, size_t Length, const void *Buffer) +size_t Root_Write(tVFS_Node *Node, off_t Offset, size_t Length, const void *Buffer, Uint Flags) { tRamFS_File *file = Node->ImplPtr; diff --git a/KernelLand/Kernel/vfs/io.c b/KernelLand/Kernel/vfs/io.c index 24aa78ba..f5b16cc1 100644 --- a/KernelLand/Kernel/vfs/io.c +++ b/KernelLand/Kernel/vfs/io.c @@ -1,6 +1,11 @@ /* - * AcessMicro VFS - * - File IO Passthru's + * Acess2 Kernel + * - By John Hodge (thePowersGang) + * + * vfs/io.c + * - VFS IO Handling (Read/Write) + * + * TODO: VFS-level caching to support non-blocking IO? */ #define DEBUG 0 #include @@ -48,7 +53,9 @@ size_t VFS_Read(int FD, size_t Length, void *Buffer) } LOG("Position=%llx", h->Position); - ret = h->Node->Type->Read(h->Node, h->Position, Length, Buffer); + Uint flags = 0; + flags |= (h->Mode & VFS_OPENFLAG_NONBLOCK) ? VFS_IOFLAG_NOBLOCK : 0; + ret = h->Node->Type->Read(h->Node, h->Position, Length, Buffer, flags); if(ret == (size_t)-1) LEAVE_RET('i', -1); h->Position += ret; @@ -77,12 +84,15 @@ size_t VFS_ReadAt(int FD, Uint64 Offset, size_t Length, void *Buffer) } if( !MM_GetPhysAddr(h->Node->Type->Read) ) { - Log_Error("VFS", "Node type %p(%s) read method is junk %p", h->Node->Type, h->Node, h->Node->Type->TypeName, + Log_Error("VFS", "Node type %p(%s) read method is junk %p", + h->Node->Type, h->Node->Type->TypeName, h->Node->Type->Read); LEAVE_RET('i', -1); } - ret = h->Node->Type->Read(h->Node, Offset, Length, Buffer); + Uint flags = 0; + flags |= (h->Mode & VFS_OPENFLAG_NONBLOCK) ? VFS_IOFLAG_NOBLOCK : 0; + ret = h->Node->Type->Read(h->Node, Offset, Length, Buffer, flags); if(ret == (size_t)-1) return -1; return ret; } @@ -114,12 +124,15 @@ size_t VFS_Write(int FD, size_t Length, const void *Buffer) } if( !MM_GetPhysAddr(h->Node->Type->Write) ) { - Log_Error("VFS", "Node type %p(%s) write method is junk %p", h->Node->Type, h->Node, h->Node->Type->TypeName, + Log_Error("VFS", "Node type %p(%s) write method is junk %p", + h->Node->Type, h->Node->Type->TypeName, h->Node->Type->Write); return -1; } - ret = h->Node->Type->Write(h->Node, h->Position, Length, Buffer); + Uint flags = 0; + flags |= (h->Mode & VFS_OPENFLAG_NONBLOCK) ? VFS_IOFLAG_NOBLOCK : 0; + ret = h->Node->Type->Write(h->Node, h->Position, Length, Buffer, flags); if(ret == (size_t)-1) return -1; h->Position += ret; @@ -144,11 +157,14 @@ size_t VFS_WriteAt(int FD, Uint64 Offset, size_t Length, const void *Buffer) if(!h->Node->Type || !h->Node->Type->Write) return 0; if( !MM_GetPhysAddr(h->Node->Type->Write) ) { - Log_Error("VFS", "Node type %p(%s) write method is junk %p", h->Node->Type, h->Node, h->Node->Type->TypeName, + Log_Error("VFS", "Node type %p(%s) write method is junk %p", + h->Node->Type, h->Node->Type->TypeName, h->Node->Type->Write); return -1; } - ret = h->Node->Type->Write(h->Node, Offset, Length, Buffer); + Uint flags = 0; + flags |= (h->Mode & VFS_OPENFLAG_NONBLOCK) ? VFS_IOFLAG_NOBLOCK : 0; + ret = h->Node->Type->Write(h->Node, Offset, Length, Buffer, flags); if(ret == (size_t)-1) return -1; return ret; } diff --git a/KernelLand/Kernel/vfs/memfile.c b/KernelLand/Kernel/vfs/memfile.c index f019c3d3..e2253d70 100644 --- a/KernelLand/Kernel/vfs/memfile.c +++ b/KernelLand/Kernel/vfs/memfile.c @@ -9,8 +9,8 @@ // === PROTOTYPES === tVFS_Node *VFS_MemFile_Create(const char *Path); void VFS_MemFile_Close(tVFS_Node *Node); -size_t VFS_MemFile_Read(tVFS_Node *Node, off_t Offset, size_t Length, void *Buffer); -size_t VFS_MemFile_Write(tVFS_Node *Node, off_t Offset, size_t Length, const void *Buffer); +size_t VFS_MemFile_Read(tVFS_Node *Node, off_t Offset, size_t Length, void *Buffer, Uint Flags); +size_t VFS_MemFile_Write(tVFS_Node *Node, off_t Offset, size_t Length, const void *Buffer, Uint Flags); // === GLOBALS === tVFS_NodeType gVFS_MemFileType = { @@ -93,7 +93,7 @@ void VFS_MemFile_Close(tVFS_Node *Node) /** * \brief Read from a memory file */ -size_t VFS_MemFile_Read(tVFS_Node *Node, off_t Offset, size_t Length, void *Buffer) +size_t VFS_MemFile_Read(tVFS_Node *Node, off_t Offset, size_t Length, void *Buffer, Uint Flags) { // Check for use of free'd file if(Node->ImplPtr == NULL) return 0; @@ -116,7 +116,7 @@ size_t VFS_MemFile_Read(tVFS_Node *Node, off_t Offset, size_t Length, void *Buff /** * \brief Write to a memory file */ -size_t VFS_MemFile_Write(tVFS_Node *Node, off_t Offset, size_t Length, const void *Buffer) +size_t VFS_MemFile_Write(tVFS_Node *Node, off_t Offset, size_t Length, const void *Buffer, Uint Flags) { // Check for use of free'd file if(Node->ImplPtr == NULL) return 0; diff --git a/KernelLand/Kernel/vfs/mmap.c b/KernelLand/Kernel/vfs/mmap.c index 21b62653..cbfce43b 100644 --- a/KernelLand/Kernel/vfs/mmap.c +++ b/KernelLand/Kernel/vfs/mmap.c @@ -133,7 +133,8 @@ void *VFS_MMap(void *DestHint, size_t Length, int Protection, int Flags, int FD, return NULL; } // TODO: Clip read length - read_len = nt->Read(h->Node, pagenum*PAGE_SIZE, PAGE_SIZE, (void*)mapping_dest); + read_len = nt->Read(h->Node, pagenum*PAGE_SIZE, PAGE_SIZE, + (void*)mapping_dest, 0); // TODO: This was commented out, why? if( read_len != PAGE_SIZE ) { memset( (void*)(mapping_dest+read_len), 0, PAGE_SIZE-read_len ); diff --git a/KernelLand/Kernel/vfs/open.c b/KernelLand/Kernel/vfs/open.c index 067a73ac..2bfb2612 100644 --- a/KernelLand/Kernel/vfs/open.c +++ b/KernelLand/Kernel/vfs/open.c @@ -298,6 +298,7 @@ restart_parse: // Check permissions on root of filesystem if( !VFS_CheckACL(curNode, VFS_PERM_EXECUTE) ) { LOG("Permissions failure on '%s'", Path); + errno = EPERM; goto _error; } @@ -316,7 +317,7 @@ restart_parse: } LOG("FindDir{=%p}(%p, '%s')", curNode->Type->FindDir, curNode, pathEle); // Get Child Node - tmpNode = curNode->Type->FindDir(curNode, pathEle); + tmpNode = curNode->Type->FindDir(curNode, pathEle, 0); LOG("tmpNode = %p", tmpNode); _CloseNode( curNode ); curNode = tmpNode; @@ -324,6 +325,7 @@ restart_parse: // Error Check if(!curNode) { LOG("Node '%s' not found in dir '%s'", pathEle, Path); + errno = ENOENT; goto _error; } @@ -336,11 +338,13 @@ restart_parse: if(!curNode->Type || !curNode->Type->Read) { Log_Warning("VFS", "VFS_ParsePath - Read of symlink node %p'%s' is NULL", curNode, Path); + errno = EINTERNAL; goto _error; } if(iNestedLinks > MAX_NESTED_LINKS) { Log_Notice("VFS", "VFS_ParsePath - Nested link limit exceeded"); + errno = ENOENT; goto _error; } @@ -351,9 +355,10 @@ restart_parse: int remlen = strlen(Path) - (ofs + nextSlash); if( curNode->Size + remlen > MAX_PATH_LEN ) { Log_Warning("VFS", "VFS_ParsePath - Symlinked path too long"); + errno = ENOENT; goto _error; } - curNode->Type->Read( curNode, 0, curNode->Size, path_buffer ); + curNode->Type->Read( curNode, 0, curNode->Size, path_buffer, 0 ); path_buffer[ curNode->Size ] = '\0'; LOG("path_buffer = '%s'", path_buffer); strcat(path_buffer, Path + ofs+nextSlash); @@ -374,6 +379,7 @@ restart_parse: if( !(curNode->Flags & VFS_FFLAG_DIRECTORY) ) { Log_Warning("VFS", "VFS_ParsePath - Path segment is not a directory"); + errno = ENOTDIR; goto _error; } @@ -385,6 +391,7 @@ restart_parse: // Check if allocation succeeded if(!tmp) { Log_Warning("VFS", "VFS_ParsePath - Unable to reallocate true path buffer"); + errno = ENOMEM; goto _error; } *TruePath = tmp; @@ -401,16 +408,18 @@ restart_parse: // Check final finddir call if( !curNode->Type || !curNode->Type->FindDir ) { Log_Warning("VFS", "VFS_ParsePath - FindDir doesn't exist for element of '%s'", Path); + errno = ENOENT; goto _error; } // Get last node LOG("FindDir(%p, '%s')", curNode, &Path[ofs]); - tmpNode = curNode->Type->FindDir(curNode, &Path[ofs]); + tmpNode = curNode->Type->FindDir(curNode, &Path[ofs], 0); LOG("tmpNode = %p", tmpNode); // Check if file was found if(!tmpNode) { LOG("Node '%s' not found in dir '%.*s'", &Path[ofs], ofs, Path); + errno = ENOENT; goto _error; } _CloseNode( curNode ); @@ -422,6 +431,7 @@ restart_parse: // Check if allocation succeeded if(!tmp) { Log_Warning("VFS", "VFS_ParsePath - Unable to reallocate true path buffer"); + errno = ENOMEM; goto _error; } *TruePath = tmp; @@ -450,7 +460,6 @@ _error: } // Open failed, so decrement the open handle count _DereferenceMount(mnt, "ParsePath - error"); - LEAVE('n'); return NULL; } @@ -610,7 +619,7 @@ int VFS_OpenEx(const char *Path, Uint Flags, Uint Mode) goto _error; } // Read symlink's path - node->Type->Read( node, 0, node->Size, tmppath ); + node->Type->Read( node, 0, node->Size, tmppath, 0 ); tmppath[ node->Size ] = '\0'; _CloseNode( node ); _DereferenceMount(mnt, "Open - symlink"); @@ -668,7 +677,7 @@ int VFS_OpenChild(int FD, const char *Name, Uint Mode) } // Find Child - node = h->Node->Type->FindDir(h->Node, Name); + node = h->Node->Type->FindDir(h->Node, Name, 0); if(!node) { errno = ENOENT; LEAVE_RET('i', -1); diff --git a/KernelLand/Modules/Display/BochsGA/bochsvbe.c b/KernelLand/Modules/Display/BochsGA/bochsvbe.c index 50e76d33..4eb9c66d 100644 --- a/KernelLand/Modules/Display/BochsGA/bochsvbe.c +++ b/KernelLand/Modules/Display/BochsGA/bochsvbe.c @@ -61,8 +61,8 @@ void BGA_int_SetMode(Uint16 width, Uint16 height); int BGA_int_ModeInfo(tVideo_IOCtl_Mode *info); int BGA_int_MapFB(void *Dest); // Filesystem -size_t BGA_Read(tVFS_Node *Node, off_t off, size_t len, void *buffer); -size_t BGA_Write(tVFS_Node *Node, off_t off, size_t len, const void *buffer); +size_t BGA_Read(tVFS_Node *Node, off_t off, size_t len, void *buffer, Uint Flags); +size_t BGA_Write(tVFS_Node *Node, off_t off, size_t len, const void *buffer, Uint Flags); int BGA_IOCtl(tVFS_Node *Node, int ID, void *Data); // === GLOBALS === @@ -146,7 +146,7 @@ void BGA_Uninstall(void) /** * \brief Read from the framebuffer */ -size_t BGA_Read(tVFS_Node *node, off_t off, size_t len, void *buffer) +size_t BGA_Read(tVFS_Node *node, off_t off, size_t len, void *buffer, Uint Flags) { // Check Mode if(giBGA_CurrentMode == -1) return -1; @@ -163,7 +163,7 @@ size_t BGA_Read(tVFS_Node *node, off_t off, size_t len, void *buffer) /** * \brief Write to the framebuffer */ -size_t BGA_Write(tVFS_Node *Node, off_t Offset, size_t Length, const void *Buffer) +size_t BGA_Write(tVFS_Node *Node, off_t Offset, size_t Length, const void *Buffer, Uint Flags) { if( giBGA_CurrentMode == -1 ) BGA_int_UpdateMode(0); return DrvUtil_Video_WriteLFB(&gBGA_DrvUtil_BufInfo, Offset, Length, Buffer); diff --git a/KernelLand/Modules/Display/VESA/main.c b/KernelLand/Modules/Display/VESA/main.c index 13fe798a..d9cd2ecc 100644 --- a/KernelLand/Modules/Display/VESA/main.c +++ b/KernelLand/Modules/Display/VESA/main.c @@ -27,7 +27,7 @@ // === PROTOTYPES === int Vesa_Install(char **Arguments); int VBE_int_GetModeList(void); -size_t Vesa_Write(tVFS_Node *Node, off_t Offset, size_t Length, const void *Buffer); +size_t Vesa_Write(tVFS_Node *Node, off_t Offset, size_t Length, const void *Buffer, Uint Flags); int Vesa_IOCtl(tVFS_Node *Node, int ID, void *Data); int Vesa_Int_SetMode(int Mode); int Vesa_Int_FindMode(tVideo_IOCtl_Mode *data); @@ -265,7 +265,7 @@ void Vesa_int_FillModeList(void) /** * \brief Write to the framebuffer */ -size_t Vesa_Write(tVFS_Node *Node, off_t Offset, size_t Length, const void *Buffer) +size_t Vesa_Write(tVFS_Node *Node, off_t Offset, size_t Length, const void *Buffer, Uint Flags) { if( gVesa_Modes[giVesaCurrentMode].framebuffer == 0 ) { Log_Warning("VESA", "Vesa_Write - Non-LFB Modes not yet supported."); diff --git a/KernelLand/Modules/Filesystems/Ext2/dir.c b/KernelLand/Modules/Filesystems/Ext2/dir.c index 33df8472..2f2b72f6 100644 --- a/KernelLand/Modules/Filesystems/Ext2/dir.c +++ b/KernelLand/Modules/Filesystems/Ext2/dir.c @@ -14,7 +14,7 @@ // === PROTOTYPES === int Ext2_ReadDir(tVFS_Node *Node, int Pos, char Dest[FILENAME_MAX]); -tVFS_Node *Ext2_FindDir(tVFS_Node *Node, const char *FileName); +tVFS_Node *Ext2_FindDir(tVFS_Node *Node, const char *FileName, Uint Flags); tVFS_Node *Ext2_MkNod(tVFS_Node *Node, const char *Name, Uint Flags); int Ext2_Unlink(tVFS_Node *Node, const char *OldName); int Ext2_Link(tVFS_Node *Parent, const char *Name, tVFS_Node *Node); @@ -124,7 +124,7 @@ int Ext2_ReadDir(tVFS_Node *Node, int Pos, char Dest[FILENAME_MAX]) * \param Filename Name of wanted file * \return VFS Node of file */ -tVFS_Node *Ext2_FindDir(tVFS_Node *Node, const char *Filename) +tVFS_Node *Ext2_FindDir(tVFS_Node *Node, const char *Filename, Uint Flags) { tExt2_Disk *disk = Node->ImplPtr; tExt2_Inode inode; @@ -147,10 +147,8 @@ tVFS_Node *Ext2_FindDir(tVFS_Node *Node, const char *Filename) while(size > 0) { VFS_ReadAt( disk->FD, Base+ofs, sizeof(tExt2_DirEnt), &dirent); - // TODO: Possible overrun if name_len == 255? - dirent.name[ dirent.name_len ] = '\0'; // Cap off string // If it matches, create a node and return it - if(dirent.name_len == filenameLen && strcmp(dirent.name, Filename) == 0) + if(dirent.name_len == filenameLen && strncmp(dirent.name, Filename, filenameLen) == 0) return Ext2_int_CreateNode( disk, dirent.inode ); // Increment pointers ofs += dirent.rec_len; diff --git a/KernelLand/Modules/Filesystems/Ext2/ext2_common.h b/KernelLand/Modules/Filesystems/Ext2/ext2_common.h index 4c8c45e2..b4c9547a 100644 --- a/KernelLand/Modules/Filesystems/Ext2/ext2_common.h +++ b/KernelLand/Modules/Filesystems/Ext2/ext2_common.h @@ -38,15 +38,15 @@ extern int Ext2_int_ReadInode(tExt2_Disk *Disk, Uint32 InodeId, tExt2_Inode *Ino extern int Ext2_int_WriteInode(tExt2_Disk *Disk, Uint32 InodeId, tExt2_Inode *Inode); // --- Dir --- extern int Ext2_ReadDir(tVFS_Node *Node, int Pos, char Dest[FILENAME_MAX]); -extern tVFS_Node *Ext2_FindDir(tVFS_Node *Node, const char *FileName); -extern tVFS_Node *Ext2_MkNod(tVFS_Node *Node, const char *Name, Uint Flags); +extern tVFS_Node *Ext2_FindDir(tVFS_Node *Node, const char *FileName, Uint Flags); +extern tVFS_Node *Ext2_MkNod(tVFS_Node *Node, const char *Name, Uint Mode); extern int Ext2_Link(tVFS_Node *Parent, const char *Name, tVFS_Node *Node); extern tVFS_Node *Ext2_int_CreateNode(tExt2_Disk *Disk, Uint InodeId); extern int Ext2_int_WritebackNode(tExt2_Disk *Disk, tVFS_Node *Node); // --- Read --- -extern size_t Ext2_Read(tVFS_Node *node, off_t offset, size_t length, void *buffer); +extern size_t Ext2_Read(tVFS_Node *node, off_t offset, size_t length, void *buffer, Uint Flags); // --- Write --- -extern size_t Ext2_Write(tVFS_Node *node, off_t offset, size_t length, const void *buffer); +extern size_t Ext2_Write(tVFS_Node *node, off_t offset, size_t length, const void *buffer, Uint Flags); extern Uint32 Ext2_int_AllocateBlock(tExt2_Disk *Disk, Uint32 LastBlock); extern void Ext2_int_DeallocateBlock(tExt2_Disk *Disk, Uint32 Block); extern int Ext2_int_AppendBlock(tExt2_Disk *Disk, tExt2_Inode *Inode, Uint32 Block); diff --git a/KernelLand/Modules/Filesystems/Ext2/read.c b/KernelLand/Modules/Filesystems/Ext2/read.c index 6244d9dc..c77f06f3 100644 --- a/KernelLand/Modules/Filesystems/Ext2/read.c +++ b/KernelLand/Modules/Filesystems/Ext2/read.c @@ -15,7 +15,7 @@ /** * \brief Read from a file */ -size_t Ext2_Read(tVFS_Node *Node, off_t Offset, size_t Length, void *Buffer) +size_t Ext2_Read(tVFS_Node *Node, off_t Offset, size_t Length, void *Buffer, Uint Flags) { tExt2_Disk *disk = Node->ImplPtr; tExt2_Inode inode; @@ -54,6 +54,7 @@ size_t Ext2_Read(tVFS_Node *Node, off_t Offset, size_t Length, void *Buffer) } // Read first block + // TODO: If (Flags & VFS_IOFLAG_NOBLOCK) trigger read and return EWOULDBLOCK? remLen = Length; VFS_ReadAt( disk->FD, base + Offset, disk->BlockSize - Offset, Buffer); remLen -= disk->BlockSize - Offset; @@ -65,7 +66,7 @@ size_t Ext2_Read(tVFS_Node *Node, off_t Offset, size_t Length, void *Buffer) { base = Ext2_int_GetBlockAddr(disk, inode.i_block, block); if(base == 0) { - Warning("[EXT2 ] NULL Block Detected in INode 0x%llx", Node->Inode); + Log_Warning("EXT2", "NULL Block Detected in INode 0x%llx", Node->Inode); LEAVE('i', 0); return 0; } diff --git a/KernelLand/Modules/Filesystems/Ext2/write.c b/KernelLand/Modules/Filesystems/Ext2/write.c index 766a0e66..207bf87b 100644 --- a/KernelLand/Modules/Filesystems/Ext2/write.c +++ b/KernelLand/Modules/Filesystems/Ext2/write.c @@ -20,7 +20,7 @@ void Ext2_int_DeallocateBlock(tExt2_Disk *Disk, Uint32 Block); /** * \brief Write to a file */ -size_t Ext2_Write(tVFS_Node *Node, off_t Offset, size_t Length, const void *Buffer) +size_t Ext2_Write(tVFS_Node *Node, off_t Offset, size_t Length, const void *Buffer, Uint Flags) { tExt2_Disk *disk = Node->ImplPtr; tExt2_Inode inode; @@ -31,7 +31,9 @@ size_t Ext2_Write(tVFS_Node *Node, off_t Offset, size_t Length, const void *Buff int bNewBlocks = 0; Debug_HexDump("Ext2_Write", Buffer, Length); - + + // TODO: Handle (Flags & VFS_IOFLAG_NOBLOCK) + Ext2_int_ReadInode(disk, Node->Inode, &inode); // Get the ammount of space already allocated diff --git a/KernelLand/Modules/Filesystems/FAT/common.h b/KernelLand/Modules/Filesystems/FAT/common.h index 2e9a232a..09b94a65 100644 --- a/KernelLand/Modules/Filesystems/FAT/common.h +++ b/KernelLand/Modules/Filesystems/FAT/common.h @@ -109,7 +109,7 @@ extern void FAT_int_WriteCluster(tFAT_VolInfo *Disk, Uint32 Cluster, const void // --- Directory Access --- extern int FAT_ReadDir(tVFS_Node *Node, int ID, char Dest[FILENAME_MAX]); -extern tVFS_Node *FAT_FindDir(tVFS_Node *Node, const char *Name); +extern tVFS_Node *FAT_FindDir(tVFS_Node *Node, const char *Name, Uint Flags); extern tVFS_Node *FAT_GetNodeFromINode(tVFS_Node *Root, Uint64 Inode); extern int FAT_int_GetEntryByCluster(tVFS_Node *DirNode, Uint32 Cluster, fat_filetable *Entry); #if SUPPORT_WRITE diff --git a/KernelLand/Modules/Filesystems/FAT/dir.c b/KernelLand/Modules/Filesystems/FAT/dir.c index cb2c6f33..c371f1f9 100644 --- a/KernelLand/Modules/Filesystems/FAT/dir.c +++ b/KernelLand/Modules/Filesystems/FAT/dir.c @@ -27,7 +27,7 @@ Uint16 *FAT_int_GetLFN(tVFS_Node *Node, int ID); void FAT_int_DelLFN(tVFS_Node *Node, int ID); #endif int FAT_ReadDir(tVFS_Node *Node, int ID, char Dest[FILENAME_MAX]); -tVFS_Node *FAT_FindDir(tVFS_Node *Node, const char *Name); +tVFS_Node *FAT_FindDir(tVFS_Node *Node, const char *Name, Uint Flags); tVFS_Node *FAT_GetNodeFromINode(tVFS_Node *Root, Uint64 Inode); #if SUPPORT_WRITE tVFS_Node *FAT_Mknod(tVFS_Node *Node, const char *Name, Uint Flags); @@ -630,7 +630,7 @@ int FAT_ReadDir(tVFS_Node *Node, int ID, char Dest[FILENAME_MAX]) * \fn tVFS_Node *FAT_FindDir(tVFS_Node *node, char *name) * \brief Finds an entry in the current directory */ -tVFS_Node *FAT_FindDir(tVFS_Node *Node, const char *Name) +tVFS_Node *FAT_FindDir(tVFS_Node *Node, const char *Name, Uint Flags) { fat_filetable fileent; diff --git a/KernelLand/Modules/Filesystems/FAT/fat.c b/KernelLand/Modules/Filesystems/FAT/fat.c index fc7d21ef..1411902a 100644 --- a/KernelLand/Modules/Filesystems/FAT/fat.c +++ b/KernelLand/Modules/Filesystems/FAT/fat.c @@ -33,9 +33,9 @@ void FAT_Unmount(tVFS_Node *Node); // --- Helpers int FAT_int_GetAddress(tVFS_Node *Node, Uint64 Offset, Uint64 *Addr, Uint32 *Cluster); // --- File IO -size_t FAT_Read(tVFS_Node *Node, off_t Offset, size_t Length, void *Buffer); +size_t FAT_Read(tVFS_Node *Node, off_t Offset, size_t Length, void *Buffer, Uint Flags); #if SUPPORT_WRITE -size_t FAT_Write(tVFS_Node *Node, off_t Offset, size_t Length, const void *Buffer); +size_t FAT_Write(tVFS_Node *Node, off_t Offset, size_t Length, const void *Buffer, Uint Flags); #endif void FAT_CloseFile(tVFS_Node *node); @@ -393,7 +393,7 @@ int FAT_int_GetAddress(tVFS_Node *Node, Uint64 Offset, Uint64 *Addr, Uint32 *Clu /** * \brief Reads data from a specified file */ -size_t FAT_Read(tVFS_Node *Node, off_t Offset, size_t Length, void *Buffer) +size_t FAT_Read(tVFS_Node *Node, off_t Offset, size_t Length, void *Buffer, Uint Flags) { int preSkip, count; Uint64 final_bytes; @@ -435,6 +435,8 @@ size_t FAT_Read(tVFS_Node *Node, off_t Offset, size_t Length, void *Buffer) } } + // TODO: Handle (Flags & VFS_IOFLAG_NOBLOCK) + // Reading from within one cluster if((int)Offset + (int)Length <= bpc) { @@ -512,7 +514,7 @@ size_t FAT_Read(tVFS_Node *Node, off_t Offset, size_t Length, void *Buffer) * \param Length Size of data to write * \param Buffer Data source */ -size_t FAT_Write(tVFS_Node *Node, off_t Offset, size_t Length, const void *Buffer) +size_t FAT_Write(tVFS_Node *Node, off_t Offset, size_t Length, const void *Buffer, Uint Flags) { tFAT_VolInfo *disk = Node->ImplPtr; char tmpBuf[disk->BytesPerCluster]; @@ -522,6 +524,7 @@ size_t FAT_Write(tVFS_Node *Node, off_t Offset, size_t Length, const void *Buffe off_t original_offset = Offset; if(Offset > Node->Size) return 0; + // TODO: Handle (Flags & VFS_IOFLAG_NOBLOCK) ENTER("pNode Xoffset xlength pbuffer", Node, Offset, Length, Buffer); diff --git a/KernelLand/Modules/Filesystems/InitRD/main.c b/KernelLand/Modules/Filesystems/InitRD/main.c index 96f783e3..c86c512f 100644 --- a/KernelLand/Modules/Filesystems/InitRD/main.c +++ b/KernelLand/Modules/Filesystems/InitRD/main.c @@ -17,9 +17,9 @@ extern tVFS_Node * const gInitRD_FileList[]; tVFS_Node *InitRD_InitDevice(const char *Device, const char **Arguments); void InitRD_Unmount(tVFS_Node *Node); tVFS_Node *InitRD_GetNodeFromINode(tVFS_Node *Root, Uint64 Inode); -size_t InitRD_ReadFile(tVFS_Node *Node, off_t Offset, size_t Size, void *Buffer); +size_t InitRD_ReadFile(tVFS_Node *Node, off_t Offset, size_t Size, void *Buffer, Uint Flags); int InitRD_ReadDir(tVFS_Node *Node, int ID, char Dest[FILENAME_MAX]); -tVFS_Node *InitRD_FindDir(tVFS_Node *Node, const char *Name); +tVFS_Node *InitRD_FindDir(tVFS_Node *Node, const char *Name, Uint Flags); void InitRD_DumpDir(tVFS_Node *Node, int Indent); // === GLOBALS === @@ -77,7 +77,7 @@ tVFS_Node *InitRD_GetNodeFromINode(tVFS_Node *Root, Uint64 Inode) /** * \brief Read from a file */ -size_t InitRD_ReadFile(tVFS_Node *Node, off_t Offset, size_t Length, void *Buffer) +size_t InitRD_ReadFile(tVFS_Node *Node, off_t Offset, size_t Length, void *Buffer, Uint Flags) { if(Offset > Node->Size) return 0; @@ -106,7 +106,7 @@ int InitRD_ReadDir(tVFS_Node *Node, int ID, char Dest[FILENAME_MAX]) /** * \brief Find an element in a directory */ -tVFS_Node *InitRD_FindDir(tVFS_Node *Node, const char *Name) +tVFS_Node *InitRD_FindDir(tVFS_Node *Node, const char *Name, Uint Flags) { int i; tInitRD_File *dir = Node->ImplPtr; diff --git a/KernelLand/Modules/Filesystems/NTFS/common.h b/KernelLand/Modules/Filesystems/NTFS/common.h index 312bee74..d6b11e8a 100644 --- a/KernelLand/Modules/Filesystems/NTFS/common.h +++ b/KernelLand/Modules/Filesystems/NTFS/common.h @@ -150,7 +150,8 @@ typedef struct sNTFS_FILE_Attrib }; } PACKED tNTFS_FILE_Attrib; +// -- dir.c extern int NTFS_ReadDir(tVFS_Node *Node, int Pos, char Dest[FILENAME_MAX]); -extern tVFS_Node *NTFS_FindDir(tVFS_Node *Node, const char *Name); +extern tVFS_Node *NTFS_FindDir(tVFS_Node *Node, const char *Name, Uint Flags); #endif diff --git a/KernelLand/Modules/Filesystems/NTFS/dir.c b/KernelLand/Modules/Filesystems/NTFS/dir.c index 11cd2417..538445b3 100644 --- a/KernelLand/Modules/Filesystems/NTFS/dir.c +++ b/KernelLand/Modules/Filesystems/NTFS/dir.c @@ -11,7 +11,7 @@ // === PROTOTYPES === int NTFS_ReadDir(tVFS_Node *Node, int Pos, char Dest[FILENAME_MAX]); -tVFS_Node *NTFS_FindDir(tVFS_Node *Node, const char *Name); +tVFS_Node *NTFS_FindDir(tVFS_Node *Node, const char *Name, Uint Flags); Uint64 NTFS_int_IndexLookup(Uint64 Inode, const char *IndexName, const char *Str); // === CODE === @@ -26,7 +26,7 @@ int NTFS_ReadDir(tVFS_Node *Node, int Pos, char Dest[FILENAME_MAX]) /** * \brief Get an entry from a directory by name */ -tVFS_Node *NTFS_FindDir(tVFS_Node *Node, const char *Name) +tVFS_Node *NTFS_FindDir(tVFS_Node *Node, const char *Name, Uint Flags) { tNTFS_Disk *disk = Node->ImplPtr; Uint64 inode = NTFS_int_IndexLookup(Node->Inode, "$I30", Name); diff --git a/KernelLand/Modules/Filesystems/RAMDisk/ramdisk.c b/KernelLand/Modules/Filesystems/RAMDisk/ramdisk.c index eeef8f68..d196f5fa 100644 --- a/KernelLand/Modules/Filesystems/RAMDisk/ramdisk.c +++ b/KernelLand/Modules/Filesystems/RAMDisk/ramdisk.c @@ -22,13 +22,13 @@ tVFS_Node *RAMFS_InitDevice(const char *Device, const char **Options); void RAMFS_Unmount(tVFS_Node *Node); // --- Directories --- int RAMFS_ReadDir(tVFS_Node *Node, int Index, char Dest[256]); -tVFS_Node *RAMFS_FindDir(tVFS_Node *Node, const char *Name); +tVFS_Node *RAMFS_FindDir(tVFS_Node *Node, const char *Name, Uint Flags); tVFS_Node *RAMFS_MkNod(tVFS_Node *Node, const char *Name, Uint Flags); int RAMFS_Link(tVFS_Node *DirNode, const char *Name, tVFS_Node *Node); int RAMFS_Unlink(tVFS_Node *Node, const char *Name); // --- Files --- -size_t RAMFS_Read(tVFS_Node *Node, off_t Offset, size_t Size, void *Buffer); -size_t RAMFS_Write(tVFS_Node *Node, off_t Offset, size_t Size, const void *Buffer); +size_t RAMFS_Read(tVFS_Node *Node, off_t Offset, size_t Size, void *Buffer, Uint Flags); +size_t RAMFS_Write(tVFS_Node *Node, off_t Offset, size_t Size, const void *Buffer, Uint Flags); // --- Internals -- void RAMFS_int_RefFile(tRAMFS_Inode *Inode); void RAMFS_int_DerefFile(tRAMFS_Inode *Inode); @@ -151,7 +151,7 @@ int RAMFS_ReadDir(tVFS_Node *Node, int Index, char Dest[FILENAME_MAX]) return -ENOENT; } -tVFS_Node *RAMFS_FindDir(tVFS_Node *Node, const char *Name) +tVFS_Node *RAMFS_FindDir(tVFS_Node *Node, const char *Name, Uint Flags) { tRAMFS_Dir *dir = Node->ImplPtr; @@ -170,7 +170,7 @@ tVFS_Node *RAMFS_FindDir(tVFS_Node *Node, const char *Name) tVFS_Node *RAMFS_MkNod(tVFS_Node *Node, const char *Name, Uint Flags) { tRAMFS_Dir *dir = Node->ImplPtr; - if( RAMFS_FindDir(Node, Name) != NULL ) + if( RAMFS_FindDir(Node, Name, 0) != NULL ) return NULL; tRAMFS_DirEnt *de = malloc( sizeof(tRAMFS_DirEnt) + strlen(Name) + 1 ); @@ -327,14 +327,14 @@ size_t RAMFS_int_DoIO(tRAMFS_File *File, off_t Offset, size_t Size, void *Buffer return Size; } -size_t RAMFS_Read(tVFS_Node *Node, off_t Offset, size_t Size, void *Buffer) +size_t RAMFS_Read(tVFS_Node *Node, off_t Offset, size_t Size, void *Buffer, Uint Flags) { tRAMFS_File *file = Node->ImplPtr; return RAMFS_int_DoIO(file, Offset, Size, Buffer, 1); } -size_t RAMFS_Write(tVFS_Node *Node, off_t Offset, size_t Size, const void *Buffer) +size_t RAMFS_Write(tVFS_Node *Node, off_t Offset, size_t Size, const void *Buffer, Uint Flags) { tRAMFS_File *file = Node->ImplPtr; diff --git a/KernelLand/Modules/IPStack/adapters.c b/KernelLand/Modules/IPStack/adapters.c index deb05528..7bf10d56 100644 --- a/KernelLand/Modules/IPStack/adapters.c +++ b/KernelLand/Modules/IPStack/adapters.c @@ -21,7 +21,7 @@ void *IPStack_Adapter_Add(const tIPStack_AdapterType *Type, void *Ptr, const voi void IPStack_Adapter_Del(void *Handle); // --- VFS API --- int Adapter_ReadDir(tVFS_Node *Node, int Pos, char Name[FILENAME_MAX]); -tVFS_Node *Adapter_FindDir(tVFS_Node *Node, const char *Name); +tVFS_Node *Adapter_FindDir(tVFS_Node *Node, const char *Name, Uint Flags); int Adapter_DirIOCtl(tVFS_Node *Node, int Num, void *Data); int Adapter_IOCtl(tVFS_Node *Node, int Num, void *Data); // --- "Internal" (IPStack) API --- @@ -157,7 +157,7 @@ int Adapter_ReadDir(tVFS_Node *Node, int Pos, char Dest[FILENAME_MAX]) return -EINVAL; } -tVFS_Node *Adapter_FindDir(tVFS_Node *Node, const char *Name) +tVFS_Node *Adapter_FindDir(tVFS_Node *Node, const char *Name, Uint Flags) { tAdapter *a = Adapter_GetByName(Name); if(!a) diff --git a/KernelLand/Modules/IPStack/interface.c b/KernelLand/Modules/IPStack/interface.c index c6ec2b3d..69d54c3e 100644 --- a/KernelLand/Modules/IPStack/interface.c +++ b/KernelLand/Modules/IPStack/interface.c @@ -22,14 +22,14 @@ extern tVFS_Node gIP_AdaptersNode; // === PROTOTYPES === int IPStack_Root_ReadDir(tVFS_Node *Node, int Pos, char Dest[FILENAME_MAX]); -tVFS_Node *IPStack_Root_FindDir(tVFS_Node *Node, const char *Name); +tVFS_Node *IPStack_Root_FindDir(tVFS_Node *Node, const char *Name, Uint Flags); int IPStack_Root_IOCtl(tVFS_Node *Node, int ID, void *Data); int IPStack_AddFile(tSocketFile *File); tInterface *IPStack_AddInterface(const char *Device, int Type, const char *Name); int IPStack_Iface_ReadDir(tVFS_Node *Node, int Pos, char Dest[FILENAME_MAX]); -tVFS_Node *IPStack_Iface_FindDir(tVFS_Node *Node, const char *Name); +tVFS_Node *IPStack_Iface_FindDir(tVFS_Node *Node, const char *Name, Uint Flags); int IPStack_Iface_IOCtl(tVFS_Node *Node, int ID, void *Data); // === GLOBALS === @@ -110,11 +110,8 @@ int IPStack_Root_ReadDir(tVFS_Node *Node, int Pos, char Dest[FILENAME_MAX]) /** * \brief Get the node of an interface */ -tVFS_Node *IPStack_Root_FindDir(tVFS_Node *Node, const char *Name) +tVFS_Node *IPStack_Root_FindDir(tVFS_Node *Node, const char *Name, Uint Flags) { - #if 0 - int i, num; - #endif tInterface *iface; ENTER("pNode sName", Node, Name); @@ -333,7 +330,7 @@ int IPStack_Iface_ReadDir(tVFS_Node *Node, int Pos, char Dest[FILENAME_MAX]) /** * \brief Gets a named node from an interface directory */ -tVFS_Node *IPStack_Iface_FindDir(tVFS_Node *Node, const char *Name) +tVFS_Node *IPStack_Iface_FindDir(tVFS_Node *Node, const char *Name, Uint Flags) { tSocketFile *file = gIP_FileTemplates; diff --git a/KernelLand/Modules/IPStack/routing.c b/KernelLand/Modules/IPStack/routing.c index e86f333b..ed3814bb 100644 --- a/KernelLand/Modules/IPStack/routing.c +++ b/KernelLand/Modules/IPStack/routing.c @@ -18,7 +18,7 @@ extern tVFS_Node *IPStack_Root_FindDir(tVFS_Node *Node, const char *Filename); // === PROTOTYPES === // - Routes directory int IPStack_RouteDir_ReadDir(tVFS_Node *Node, int Pos, char Dest[FILENAME_MAX]); -tVFS_Node *IPStack_RouteDir_FindDir(tVFS_Node *Node, const char *Name); +tVFS_Node *IPStack_RouteDir_FindDir(tVFS_Node *Node, const char *Name, Uint Flags); tVFS_Node *IPStack_RouteDir_MkNod(tVFS_Node *Node, const char *Name, Uint Flags); int IPStack_RouteDir_Unlink(tVFS_Node *Node, const char *OldName); tRoute *_Route_FindExactRoute(int Type, void *Network, int Subnet, int Metric); @@ -78,7 +78,7 @@ int IPStack_RouteDir_ReadDir(tVFS_Node *Node, int Pos, char Dest[FILENAME_MAX]) /** * \brief FindDir for the /Devices/ip/routes/ directory */ -tVFS_Node *IPStack_RouteDir_FindDir(tVFS_Node *Node, const char *Name) +tVFS_Node *IPStack_RouteDir_FindDir(tVFS_Node *Node, const char *Name, Uint Flags) { // Interpret the name as :, returning the interface for // needed to access that address. diff --git a/KernelLand/Modules/IPStack/tcp.c b/KernelLand/Modules/IPStack/tcp.c index 28dc2c59..aa951689 100644 --- a/KernelLand/Modules/IPStack/tcp.c +++ b/KernelLand/Modules/IPStack/tcp.c @@ -37,13 +37,13 @@ Uint16 TCP_GetUnusedPort(); // --- Server tVFS_Node *TCP_Server_Init(tInterface *Interface); int TCP_Server_ReadDir(tVFS_Node *Node, int Pos, char Name[FILENAME_MAX]); -tVFS_Node *TCP_Server_FindDir(tVFS_Node *Node, const char *Name); +tVFS_Node *TCP_Server_FindDir(tVFS_Node *Node, const char *Name, Uint Flags); int TCP_Server_IOCtl(tVFS_Node *Node, int ID, void *Data); void TCP_Server_Close(tVFS_Node *Node); // --- Client tVFS_Node *TCP_Client_Init(tInterface *Interface); -size_t TCP_Client_Read(tVFS_Node *Node, off_t Offset, size_t Length, void *Buffer); -size_t TCP_Client_Write(tVFS_Node *Node, off_t Offset, size_t Length, const void *Buffer); +size_t TCP_Client_Read(tVFS_Node *Node, off_t Offset, size_t Length, void *Buffer, Uint Flags); +size_t TCP_Client_Write(tVFS_Node *Node, off_t Offset, size_t Length, const void *Buffer, Uint Flags); int TCP_Client_IOCtl(tVFS_Node *Node, int ID, void *Data); void TCP_Client_Close(tVFS_Node *Node); // --- Helpers @@ -950,7 +950,7 @@ int TCP_Server_ReadDir(tVFS_Node *Node, int Pos, char Dest[FILENAME_MAX]) * \param Node Server node * \param Name Hexadecimal ID of the node */ -tVFS_Node *TCP_Server_FindDir(tVFS_Node *Node, const char *Name) +tVFS_Node *TCP_Server_FindDir(tVFS_Node *Node, const char *Name, Uint Flags) { tTCPConnection *conn; tTCPListener *srv = Node->ImplPtr; @@ -1105,7 +1105,7 @@ tVFS_Node *TCP_Client_Init(tInterface *Interface) * \note If \a Length is smaller than the size of the packet, the rest * of the packet's data will be discarded. */ -size_t TCP_Client_Read(tVFS_Node *Node, off_t Offset, size_t Length, void *Buffer) +size_t TCP_Client_Read(tVFS_Node *Node, off_t Offset, size_t Length, void *Buffer, Uint Flags) { tTCPConnection *conn = Node->ImplPtr; size_t len; @@ -1123,6 +1123,7 @@ size_t TCP_Client_Read(tVFS_Node *Node, off_t Offset, size_t Length, void *Buffe if( len == 0 ) { VFS_MarkAvaliable(Node, 0); + errno = 0; LEAVE('i', -1); return -1; } @@ -1132,7 +1133,17 @@ size_t TCP_Client_Read(tVFS_Node *Node, off_t Offset, size_t Length, void *Buffe } // Wait - VFS_SelectNode(Node, VFS_SELECT_READ|VFS_SELECT_ERROR, NULL, "TCP_Client_Read"); + { + tTime *timeout = NULL; + tTime timeout_zero = 0; + if( Flags & VFS_IOFLAG_NOBLOCK ) + timeout = &timeout_zero; + if( !VFS_SelectNode(Node, VFS_SELECT_READ|VFS_SELECT_ERROR, timeout, "TCP_Client_Read") ) { + errno = EWOULDBLOCK; + LEAVE('i', -1); + return -1; + } + } // Lock list and read as much as possible (up to `Length`) Mutex_Acquire( &conn->lRecievedPackets ); @@ -1182,7 +1193,7 @@ void TCP_INT_SendDataPacket(tTCPConnection *Connection, size_t Length, const voi /** * \brief Send some bytes on a connection */ -size_t TCP_Client_Write(tVFS_Node *Node, off_t Offset, size_t Length, const void *Buffer) +size_t TCP_Client_Write(tVFS_Node *Node, off_t Offset, size_t Length, const void *Buffer, Uint Flags) { tTCPConnection *conn = Node->ImplPtr; size_t rem = Length; @@ -1197,12 +1208,23 @@ size_t TCP_Client_Write(tVFS_Node *Node, off_t Offset, size_t Length, const void // Don't allow a write to a closed connection if( conn->State > TCP_ST_OPEN ) { VFS_MarkError(Node, 1); + errno = 0; LEAVE('i', -1); return -1; } // Wait - VFS_SelectNode(Node, VFS_SELECT_WRITE|VFS_SELECT_ERROR, NULL, "TCP_Client_Write"); + { + tTime *timeout = NULL; + tTime timeout_zero = 0; + if( Flags & VFS_IOFLAG_NOBLOCK ) + timeout = &timeout_zero; + if( !VFS_SelectNode(Node, VFS_SELECT_WRITE|VFS_SELECT_ERROR, timeout, "TCP_Client_Write") ) { + errno = EWOULDBLOCK; + LEAVE('i', -1); + return -1; + } + } do { diff --git a/KernelLand/Modules/IPStack/udp.c b/KernelLand/Modules/IPStack/udp.c index eb8281b4..40e6474f 100644 --- a/KernelLand/Modules/IPStack/udp.c +++ b/KernelLand/Modules/IPStack/udp.c @@ -15,8 +15,8 @@ void UDP_Unreachable(tInterface *Interface, int Code, void *Address, int Length, void UDP_SendPacketTo(tUDPChannel *Channel, int AddrType, const void *Address, Uint16 Port, const void *Data, size_t Length); // --- Client Channels tVFS_Node *UDP_Channel_Init(tInterface *Interface); -size_t UDP_Channel_Read(tVFS_Node *Node, off_t Offset, size_t Length, void *Buffer); -size_t UDP_Channel_Write(tVFS_Node *Node, off_t Offset, size_t Length, const void *Buffer); +size_t UDP_Channel_Read(tVFS_Node *Node, off_t Offset, size_t Length, void *Buffer, Uint Flags); +size_t UDP_Channel_Write(tVFS_Node *Node, off_t Offset, size_t Length, const void *Buffer, Uint Flags); int UDP_Channel_IOCtl(tVFS_Node *Node, int ID, void *Data); void UDP_Channel_Close(tVFS_Node *Node); // --- Helpers @@ -187,7 +187,7 @@ tVFS_Node *UDP_Channel_Init(tInterface *Interface) /** * \brief Read from the channel file (wait for a packet) */ -size_t UDP_Channel_Read(tVFS_Node *Node, off_t Offset, size_t Length, void *Buffer) +size_t UDP_Channel_Read(tVFS_Node *Node, off_t Offset, size_t Length, void *Buffer, Uint Flags) { tUDPChannel *chan = Node->ImplPtr; tUDPPacket *pack; @@ -203,7 +203,11 @@ size_t UDP_Channel_Read(tVFS_Node *Node, off_t Offset, size_t Length, void *Buff for(;;) { - VFS_SelectNode(Node, VFS_SELECT_READ, NULL, "UDP_Channel_Read"); + tTime timeout_z = 0, *timeout = (Flags & VFS_IOFLAG_NOBLOCK) ? &timeout_z : NULL; + int rv = VFS_SelectNode(Node, VFS_SELECT_READ, timeout, "UDP_Channel_Read"); + if( rv ) { + errno = (Flags & VFS_IOFLAG_NOBLOCK) ? EWOULDBLOCK : EINTR; + } SHORTLOCK(&chan->lQueue); if(chan->Queue == NULL) { SHORTREL(&chan->lQueue); @@ -247,7 +251,7 @@ size_t UDP_Channel_Read(tVFS_Node *Node, off_t Offset, size_t Length, void *Buff /** * \brief Write to the channel file (send a packet) */ -size_t UDP_Channel_Write(tVFS_Node *Node, off_t Offset, size_t Length, const void *Buffer) +size_t UDP_Channel_Write(tVFS_Node *Node, off_t Offset, size_t Length, const void *Buffer, Uint Flags) { tUDPChannel *chan = Node->ImplPtr; const tUDPEndpoint *ep; diff --git a/KernelLand/Modules/Input/Mouse/main.c b/KernelLand/Modules/Input/Mouse/main.c index 25185a2d..8c27f132 100644 --- a/KernelLand/Modules/Input/Mouse/main.c +++ b/KernelLand/Modules/Input/Mouse/main.c @@ -18,9 +18,9 @@ int Mouse_Cleanup(void); // - "User" side int Mouse_Root_ReadDir(tVFS_Node *Node, int Pos, char Dest[FILENAME_MAX]); -tVFS_Node *Mouse_Root_FindDir(tVFS_Node *Node, const char *Name); +tVFS_Node *Mouse_Root_FindDir(tVFS_Node *Node, const char *Name, Uint Flags); int Mouse_Dev_IOCtl(tVFS_Node *Node, int ID, void *Data); -size_t Mouse_Dev_Read(tVFS_Node *Node, off_t Offset, size_t Length, void *Data); +size_t Mouse_Dev_Read(tVFS_Node *Node, off_t Offset, size_t Length, void *Data, Uint Flags); // - Device Side tMouse *Mouse_Register(const char *Name, int NumButtons, int NumAxies); void Mouse_RemoveInstance(tMouse *Handle); @@ -76,7 +76,7 @@ int Mouse_Root_ReadDir(tVFS_Node *Node, int Pos, char Dest[FILENAME_MAX]) return 0; } -tVFS_Node *Mouse_Root_FindDir(tVFS_Node *Node, const char *Name) +tVFS_Node *Mouse_Root_FindDir(tVFS_Node *Node, const char *Name, Uint Flags) { if( strcmp(Name, "system") != 0 ) return NULL; return &gMouse_Pointer.Node; @@ -119,7 +119,7 @@ int Mouse_Dev_IOCtl(tVFS_Node *Node, int ID, void *Data) /** * \brief Read from a device */ -size_t Mouse_Dev_Read(tVFS_Node *Node, off_t Offset, size_t Length, void *Data) +size_t Mouse_Dev_Read(tVFS_Node *Node, off_t Offset, size_t Length, void *Data, Uint Flags) { tPointer *ptr = Node->ImplPtr; int n_buttons = ptr->FileHeader->NButtons; diff --git a/KernelLand/Modules/Storage/FDDv2/main.c b/KernelLand/Modules/Storage/FDDv2/main.c index bb088da1..7bea4769 100644 --- a/KernelLand/Modules/Storage/FDDv2/main.c +++ b/KernelLand/Modules/Storage/FDDv2/main.c @@ -22,9 +22,9 @@ int FDD_RegisterFS(void); // --- VFS int FDD_ReadDir(tVFS_Node *Node, int pos, char dest[FILENAME_MAX]); -tVFS_Node *FDD_FindDir(tVFS_Node *dirNode, const char *Name); +tVFS_Node *FDD_FindDir(tVFS_Node *dirNode, const char *Name, Uint Flags); int FDD_IOCtl(tVFS_Node *Node, int ID, void *Data); -size_t FDD_ReadFS(tVFS_Node *node, off_t Offset, size_t Len, void *buffer); +size_t FDD_ReadFS(tVFS_Node *node, off_t Offset, size_t Len, void *buffer, Uint Flags); // --- Helpers int FDD_int_ReadWriteWithinTrack(int Disk, int Track, int bWrite, size_t Offset, size_t Length, void *Buffer); @@ -129,7 +129,7 @@ int FDD_ReadDir(tVFS_Node *Node, int Pos, char Dest[FILENAME_MAX]) * \param Name Drive name * \return Pointer to node structure */ -tVFS_Node *FDD_FindDir(tVFS_Node *Node, const char *Name) +tVFS_Node *FDD_FindDir(tVFS_Node *Node, const char *Name, Uint Flags) { int pos; if( '0' > Name[0] || Name[0] > '9' ) return NULL; @@ -169,7 +169,7 @@ int FDD_IOCtl(tVFS_Node *Node, int ID, void *Data) * \param Buffer Destination buffer * \return Number of bytes read */ -size_t FDD_ReadFS(tVFS_Node *Node, off_t Offset, size_t Length, void *Buffer) +size_t FDD_ReadFS(tVFS_Node *Node, off_t Offset, size_t Length, void *Buffer, Uint Flags) { int disk = Node->Inode; int track; @@ -187,7 +187,9 @@ size_t FDD_ReadFS(tVFS_Node *Node, off_t Offset, size_t Length, void *Buffer) rem_len = Length; track = Offset / BYTES_PER_TRACK; - Offset %= BYTES_PER_TRACK; + Offset %= BYTES_PER_TRACK; + + // TODO: Handle (Flags & VFS_IOFLAG_NOBLOCK) if( Offset ) { diff --git a/KernelLand/Modules/Storage/LVM/main.c b/KernelLand/Modules/Storage/LVM/main.c index a41f6a27..fb57341b 100644 --- a/KernelLand/Modules/Storage/LVM/main.c +++ b/KernelLand/Modules/Storage/LVM/main.c @@ -18,13 +18,13 @@ int LVM_Cleanup(void); // --- int LVM_Root_ReadDir(tVFS_Node *Node, int ID, char Dest[FILENAME_MAX]); -tVFS_Node *LVM_Root_FindDir(tVFS_Node *Node, const char *Name); +tVFS_Node *LVM_Root_FindDir(tVFS_Node *Node, const char *Name, Uint Flags); int LVM_Vol_ReadDir(tVFS_Node *Node, int ID, char Dest[FILENAME_MAX]); -tVFS_Node *LVM_Vol_FindDir(tVFS_Node *Node, const char *Name); -size_t LVM_Vol_Read(tVFS_Node *Node, off_t Offset, size_t Length, void *Buffer); -size_t LVM_Vol_Write(tVFS_Node *Node, off_t Offset, size_t Length, const void *Buffer); -size_t LVM_SubVol_Read(tVFS_Node *Node, off_t Offset, size_t Length, void *Buffer); -size_t LVM_SubVol_Write(tVFS_Node *Node, off_t Offset, size_t Length, const void *Buffer); +tVFS_Node *LVM_Vol_FindDir(tVFS_Node *Node, const char *Name, Uint Flags); +size_t LVM_Vol_Read(tVFS_Node *Node, off_t Offset, size_t Length, void *Buffer, Uint Flags); +size_t LVM_Vol_Write(tVFS_Node *Node, off_t Offset, size_t Length, const void *Buffer, Uint Flags); +size_t LVM_SubVol_Read(tVFS_Node *Node, off_t Offset, size_t Length, void *Buffer, Uint Flags); +size_t LVM_SubVol_Write(tVFS_Node *Node, off_t Offset, size_t Length, const void *Buffer, Uint Flags); void LVM_CloseNode(tVFS_Node *Node); Uint LVM_int_DrvUtil_ReadBlock(Uint64 Address, Uint Count, void *Buffer, void *Argument); @@ -141,7 +141,7 @@ int LVM_Root_ReadDir(tVFS_Node *Node, int ID, char Dest[FILENAME_MAX]) else return -ENOENT; } -tVFS_Node *LVM_Root_FindDir(tVFS_Node *Node, const char *Name) +tVFS_Node *LVM_Root_FindDir(tVFS_Node *Node, const char *Name, Uint Flags) { tLVM_Vol *vol; for( vol = gpLVM_FirstVolume; vol; vol = vol->Next ) @@ -172,7 +172,7 @@ int LVM_Vol_ReadDir(tVFS_Node *Node, int ID, char Dest[FILENAME_MAX]) strncpy(Dest, src, FILENAME_MAX); return 0; } -tVFS_Node *LVM_Vol_FindDir(tVFS_Node *Node, const char *Name) +tVFS_Node *LVM_Vol_FindDir(tVFS_Node *Node, const char *Name, Uint Flags) { tLVM_Vol *vol = Node->ImplPtr; @@ -191,7 +191,7 @@ tVFS_Node *LVM_Vol_FindDir(tVFS_Node *Node, const char *Name) return NULL; } -size_t LVM_Vol_Read(tVFS_Node *Node, off_t Offset, size_t Length, void *Buffer) +size_t LVM_Vol_Read(tVFS_Node *Node, off_t Offset, size_t Length, void *Buffer, Uint Flags) { tLVM_Vol *vol = Node->ImplPtr; Uint64 byte_size = vol->BlockCount * vol->BlockSize; @@ -209,12 +209,12 @@ size_t LVM_Vol_Read(tVFS_Node *Node, off_t Offset, size_t Length, void *Buffer) ); } -size_t LVM_Vol_Write(tVFS_Node *Node, off_t Offset, size_t Length, const void *Buffer) +size_t LVM_Vol_Write(tVFS_Node *Node, off_t Offset, size_t Length, const void *Buffer, Uint Flags) { return 0; } -size_t LVM_SubVol_Read(tVFS_Node *Node, off_t Offset, size_t Length, void *Buffer) +size_t LVM_SubVol_Read(tVFS_Node *Node, off_t Offset, size_t Length, void *Buffer, Uint Flags) { tLVM_SubVolume *sv = Node->ImplPtr; Uint64 byte_size = sv->BlockCount * sv->Vol->BlockSize; @@ -238,7 +238,7 @@ size_t LVM_SubVol_Read(tVFS_Node *Node, off_t Offset, size_t Length, void *Buffe LVM_int_DrvUtil_ReadBlock, sv->Vol->BlockSize, sv->Vol ); } -size_t LVM_SubVol_Write(tVFS_Node *Node, off_t Offset, size_t Length, const void *Buffer) +size_t LVM_SubVol_Write(tVFS_Node *Node, off_t Offset, size_t Length, const void *Buffer, Uint Flags) { tLVM_SubVolume *sv = Node->ImplPtr; Uint64 byte_size = sv->BlockCount * sv->Vol->BlockSize; diff --git a/KernelLand/Modules/USB/Core/main.c b/KernelLand/Modules/USB/Core/main.c index 04645507..4b4efa36 100644 --- a/KernelLand/Modules/USB/Core/main.c +++ b/KernelLand/Modules/USB/Core/main.c @@ -19,7 +19,7 @@ extern void USB_PortCtl_Init(void); int USB_Install(char **Arguments); void USB_Cleanup(void); int USB_ReadDir(tVFS_Node *Node, int Pos, char Dest[FILENAME_MAX]); -tVFS_Node *USB_FindDir(tVFS_Node *Node, const char *Name); +tVFS_Node *USB_FindDir(tVFS_Node *Node, const char *Name, Uint Flags); int USB_IOCtl(tVFS_Node *Node, int Id, void *Data); // === GLOBALS === @@ -71,7 +71,7 @@ int USB_ReadDir(tVFS_Node *Node, int Pos, char Dest[FILENAME_MAX]) * \fn tVFS_Node *USB_FindDir(tVFS_Node *Node, const char *Name) * \brief Locate an entry in the USB root */ -tVFS_Node *USB_FindDir(tVFS_Node *Node, const char *Name) +tVFS_Node *USB_FindDir(tVFS_Node *Node, const char *Name, Uint Flags) { return NULL; } diff --git a/KernelLand/Modules/x86/VGAText/vga.c b/KernelLand/Modules/x86/VGAText/vga.c index d7ab474a..d72caafb 100644 --- a/KernelLand/Modules/x86/VGAText/vga.c +++ b/KernelLand/Modules/x86/VGAText/vga.c @@ -13,7 +13,7 @@ // === PROTOTYPES === int VGA_Install(char **Arguments); -size_t VGA_Write(tVFS_Node *Node, off_t Offset, size_t Length, const void *Buffer); +size_t VGA_Write(tVFS_Node *Node, off_t Offset, size_t Length, const void *Buffer, Uint Flags); int VGA_IOCtl(tVFS_Node *Node, int Id, void *Data); Uint8 VGA_int_GetColourNibble(Uint16 col); Uint16 VGA_int_GetWord(const tVT_Char *Char); @@ -70,7 +70,7 @@ int VGA_Install(char **Arguments) /** * \brief Writes a string of bytes to the VGA controller */ -size_t VGA_Write(tVFS_Node *Node, off_t Offset, size_t Length, const void *Buffer) +size_t VGA_Write(tVFS_Node *Node, off_t Offset, size_t Length, const void *Buffer, Uint Flags) { if( giVGA_BufferFormat == VIDEO_BUFFMT_TEXT ) {