From 5f2024e5977e0cca0993a20dad5ab794c94d5711 Mon Sep 17 00:00:00 2001 From: John Hodge Date: Sat, 21 Jan 2012 09:17:59 +0800 Subject: [PATCH] VFS - Rework to remove function pointers from tVFS_Node - Moved them to an indirect pointer (tVFS_NodeType) - Also fixed constness in VFS_Write --- Kernel/drv/fifo.c | 28 ++++-- Kernel/drv/pci.c | 14 ++- Kernel/drv/proc.c | 24 +++-- Kernel/drv/vterm.c | 42 ++++---- Kernel/drvutil.c | 40 ++++---- Kernel/include/api_drv_disk.h | 9 +- Kernel/include/api_drv_video.h | 4 +- Kernel/include/vfs.h | 24 ++++- Kernel/include/vfs_int.h | 9 ++ Kernel/vfs/dir.c | 43 ++------ Kernel/vfs/fs/devfs.c | 8 +- Kernel/vfs/fs/root.c | 30 +++--- Kernel/vfs/io.c | 24 ++--- Kernel/vfs/main.c | 2 +- Kernel/vfs/memfile.c | 23 ++--- Kernel/vfs/mmap.c | 11 ++- Kernel/vfs/nodecache.c | 4 +- Kernel/vfs/open.c | 131 ++++++++++--------------- Modules/Display/BochsGA/bochsvbe.c | 15 +-- Modules/Display/VESA/main.c | 15 +-- Modules/Filesystems/Ext2/dir.c | 27 +++-- Modules/Filesystems/Ext2/ext2.c | 9 +- Modules/Filesystems/Ext2/ext2_common.h | 2 +- Modules/Filesystems/Ext2/write.c | 3 +- Modules/Filesystems/FAT/fat.c | 45 +++++---- Modules/Filesystems/NTFS/main.c | 14 +-- Modules/IPStack/interface.c | 17 ++-- Modules/IPStack/main.c | 9 +- Modules/IPStack/routing.c | 16 ++- Modules/IPStack/tcp.c | 34 ++++--- Modules/IPStack/udp.c | 15 +-- Modules/Input/PS2KbMouse/kb.c | 9 +- Modules/Input/PS2KbMouse/ps2mouse.c | 6 +- Modules/Network/NE2000/ne2000.c | 26 +++-- Modules/Network/RTL8139/rtl8139.c | 22 +++-- Modules/Storage/ATA/main.c | 37 ++++--- Modules/Storage/FDDv2/main.c | 18 +++- Modules/x86/VGAText/vga.c | 20 ++-- 38 files changed, 450 insertions(+), 379 deletions(-) diff --git a/Kernel/drv/fifo.c b/Kernel/drv/fifo.c index b27c678d..4d3595b7 100644 --- a/Kernel/drv/fifo.c +++ b/Kernel/drv/fifo.c @@ -31,11 +31,25 @@ tVFS_Node *FIFO_FindDir(tVFS_Node *Node, const char *Filename); void FIFO_Close(tVFS_Node *Node); int FIFO_Relink(tVFS_Node *Node, const char *OldName, const char *NewName); Uint64 FIFO_Read(tVFS_Node *Node, Uint64 Offset, Uint64 Length, void *Buffer); -Uint64 FIFO_Write(tVFS_Node *Node, Uint64 Offset, Uint64 Length, void *Buffer); +Uint64 FIFO_Write(tVFS_Node *Node, Uint64 Offset, Uint64 Length, const void *Buffer); tPipe *FIFO_Int_NewPipe(int Size, const char *Name); // === GLOBALS === MODULE_DEFINE(0, 0x0032, FIFO, FIFO_Install, NULL, NULL); +tVFS_NodeType gFIFO_DirNodeType = { + .TypeName = "FIFO Dir Node", + .ReadDir = FIFO_ReadDir, + .FindDir = FIFO_FindDir, + .MkNod = FIFO_MkNod, + .Relink = FIFO_Relink, + .IOCtl = FIFO_IOCtl +}; +tVFS_NodeType gFIFO_PipeNodeType = { + .TypeName = "FIFO Pipe Node", + .Read = FIFO_Read, + .Write = FIFO_Write, + .Close = FIFO_Close +}; tDevFS_Driver gFIFO_DriverInfo = { NULL, "fifo", { @@ -43,11 +57,7 @@ tDevFS_Driver gFIFO_DriverInfo = { .NumACLs = 1, .ACLs = &gVFS_ACL_EveryoneRW, .Flags = VFS_FFLAG_DIRECTORY, - .ReadDir = FIFO_ReadDir, - .FindDir = FIFO_FindDir, - .MkNod = FIFO_MkNod, - .Relink = FIFO_Relink, - .IOCtl = FIFO_IOCtl + .Type = &gFIFO_DirNodeType } }; tVFS_Node gFIFO_AnonNode = { @@ -280,7 +290,7 @@ Uint64 FIFO_Read(tVFS_Node *Node, Uint64 Offset, Uint64 Length, void *Buffer) * \fn Uint64 FIFO_Write(tVFS_Node *Node, Uint64 Offset, Uint64 Length, void *Buffer) * \brief Write to a fifo pipe */ -Uint64 FIFO_Write(tVFS_Node *Node, Uint64 Offset, Uint64 Length, void *Buffer) +Uint64 FIFO_Write(tVFS_Node *Node, Uint64 Offset, Uint64 Length, const void *Buffer) { tPipe *pipe = Node->ImplPtr; Uint len; @@ -386,9 +396,7 @@ tPipe *FIFO_Int_NewPipe(int Size, const char *Name) ret->Node.CTime = ret->Node.MTime = ret->Node.ATime = now(); - ret->Node.Read = FIFO_Read; - ret->Node.Write = FIFO_Write; - ret->Node.Close = FIFO_Close; + ret->Node.Type = &gFIFO_PipeNodeType; return ret; } diff --git a/Kernel/drv/pci.c b/Kernel/drv/pci.c index 72342964..8745080b 100644 --- a/Kernel/drv/pci.c +++ b/Kernel/drv/pci.c @@ -44,6 +44,15 @@ MODULE_DEFINE(0, 0x0100, PCI, PCI_Install, NULL, NULL); int giPCI_InodeHandle = -1; int giPCI_DeviceCount = 0; tPCIDevice *gPCI_Devices = NULL; +tVFS_NodeType gPCI_RootNodeType = { + .TypeName = "PCI Root Node", + .ReadDir = PCI_int_ReadDirRoot, + .FindDir = PCI_int_FindDirRoot +}; +tVFS_NodeType gPCI_DevNodeType = { + .TypeName = "PCI Dev Node", + .Read = PCI_int_ReadDevice +}; tDevFS_Driver gPCI_DriverStruct = { NULL, "pci", { @@ -51,8 +60,7 @@ tDevFS_Driver gPCI_DriverStruct = { .Size = -1, .NumACLs = 1, .ACLs = &gVFS_ACL_EveryoneRX, - .ReadDir = PCI_int_ReadDirRoot, - .FindDir = PCI_int_FindDirRoot + .Type = &gPCI_RootNodeType } }; Uint32 *gaPCI_PortBitmap = NULL; @@ -473,7 +481,7 @@ int PCI_int_EnumDevice(Uint16 bus, Uint16 slot, Uint16 fcn, tPCIDevice *info) info->Node.NumACLs = 1; info->Node.ACLs = &gVFS_ACL_EveryoneRO; - info->Node.Read = PCI_int_ReadDevice; + info->Node.Type = &gPCI_RootNodeType; return 1; } diff --git a/Kernel/drv/proc.c b/Kernel/drv/proc.c index 3283c864..73f45354 100644 --- a/Kernel/drv/proc.c +++ b/Kernel/drv/proc.c @@ -40,6 +40,15 @@ void SysFS_Comm_CloseFile(tVFS_Node *Node); extern tSysFS_Ent gSysFS_Version; // Defined Later extern tSysFS_Ent gSysFS_Root; // Defined Later MODULE_DEFINE(0, VERSION, SysFS, SysFS_Install, NULL, NULL); +tVFS_NodeType gSysFS_FileNodeType = { + .TypeName = "SysFS File", + .Read = SysFS_Comm_ReadFile + }; +tVFS_NodeType gSysFS_DirNodeType = { + .TypeName = "SysFS Dir", + .ReadDir = SysFS_Comm_ReadDir, + .FindDir = SysFS_Comm_FindDir + }; tSysFS_Ent gSysFS_Version_Kernel = { NULL, NULL, // Nexts &gSysFS_Version, // Parent @@ -50,7 +59,7 @@ tSysFS_Ent gSysFS_Version_Kernel = { .Size = 0, .NumACLs = 1, .ACLs = &gVFS_ACL_EveryoneRO, - .Read = SysFS_Comm_ReadFile + .Type = &gSysFS_FileNodeType }, "Kernel" }; @@ -64,8 +73,7 @@ tSysFS_Ent gSysFS_Version = { .NumACLs = 1, .ACLs = &gVFS_ACL_EveryoneRX, .Flags = VFS_FFLAG_DIRECTORY, - .ReadDir = SysFS_Comm_ReadDir, - .FindDir = SysFS_Comm_FindDir + .Type = &gSysFS_DirNodeType }, "Version" }; @@ -88,9 +96,7 @@ tDevFS_Driver gSysFS_DriverInfo = { .Flags = VFS_FFLAG_DIRECTORY, .ImplPtr = &gSysFS_Version, .Size = sizeof(gSysFS_Root)/sizeof(tSysFS_Ent), - .ReadDir = SysFS_Comm_ReadDir, - .FindDir = SysFS_Comm_FindDir, - .IOCtl = NULL + .Type = &gSysFS_DirNodeType } }; int giSysFS_NextFileID = 2; @@ -158,8 +164,7 @@ int SysFS_RegisterFile(const char *Path, const char *Data, int Length) child->Node.NumACLs = 1; child->Node.ACLs = &gVFS_ACL_EveryoneRX; child->Node.Flags = VFS_FFLAG_DIRECTORY; - child->Node.ReadDir = SysFS_Comm_ReadDir; - child->Node.FindDir = SysFS_Comm_FindDir; + child->Node.Type = &gSysFS_DirNodeType; if( !prev ) { if(ent) ent->Node.ImplPtr = child; @@ -212,8 +217,7 @@ int SysFS_RegisterFile(const char *Path, const char *Data, int Length) child->Node.Size = Length; child->Node.NumACLs = 1; child->Node.ACLs = &gVFS_ACL_EveryoneRO; - child->Node.Read = SysFS_Comm_ReadFile; - child->Node.Close = SysFS_Comm_CloseFile; + child->Node.Type = &gSysFS_FileNodeType; // Add to parent's child list if(ent) { diff --git a/Kernel/drv/vterm.c b/Kernel/drv/vterm.c index b4df6e35..03e7c6c7 100644 --- a/Kernel/drv/vterm.c +++ b/Kernel/drv/vterm.c @@ -94,16 +94,16 @@ char *VT_ReadDir(tVFS_Node *Node, int Pos); tVFS_Node *VT_FindDir(tVFS_Node *Node, const char *Name); int VT_Root_IOCtl(tVFS_Node *Node, int Id, void *Data); Uint64 VT_Read(tVFS_Node *Node, Uint64 Offset, Uint64 Length, void *Buffer); -Uint64 VT_Write(tVFS_Node *Node, Uint64 Offset, Uint64 Length, void *Buffer); +Uint64 VT_Write(tVFS_Node *Node, Uint64 Offset, Uint64 Length, const void *Buffer); int VT_Terminal_IOCtl(tVFS_Node *Node, int Id, void *Data); void VT_SetResolution(int Width, int Height); void VT_SetMode(int Mode); void VT_SetTerminal(int ID); void VT_KBCallBack(Uint32 Codepoint); -void VT_int_PutString(tVTerm *Term, Uint8 *Buffer, Uint Count); +void VT_int_PutString(tVTerm *Term, const Uint8 *Buffer, Uint Count); void VT_int_ClearLine(tVTerm *Term, int Num); void VT_int_ParseEscape_StandardLarge(tVTerm *Term, char CmdChar, int argc, int *args); - int VT_int_ParseEscape(tVTerm *Term, char *Buffer); + int VT_int_ParseEscape(tVTerm *Term, const char *Buffer); void VT_int_PutChar(tVTerm *Term, Uint32 Ch); void VT_int_ScrollText(tVTerm *Term, int Count); void VT_int_ScrollFramebuffer( tVTerm *Term, int Count ); @@ -122,6 +122,18 @@ const Uint16 caVT100Colours[] = { // === GLOBALS === MODULE_DEFINE(0, VERSION, VTerm, VT_Install, NULL, DEFAULT_INPUT, NULL); +tVFS_NodeType gVT_RootNodeType = { + .TypeName = "VTerm Root", + .ReadDir = VT_ReadDir, + .FindDir = VT_FindDir, + .IOCtl = VT_Root_IOCtl + }; +tVFS_NodeType gVT_TermNodeType = { + .TypeName = "VTerm", + .Read = VT_Read, + .Write = VT_Write, + .IOCtl = VT_Terminal_IOCtl + }; tDevFS_Driver gVT_DrvInfo = { NULL, "VTerm", { @@ -129,9 +141,7 @@ tDevFS_Driver gVT_DrvInfo = { .Size = NUM_VTS, .Inode = -1, .NumACLs = 0, - .ReadDir = VT_ReadDir, - .FindDir = VT_FindDir, - .IOCtl = VT_Root_IOCtl + .Type = &gVT_RootNodeType } }; // --- Terminals --- @@ -254,10 +264,8 @@ int VT_Install(char **Arguments) gVT_Terminals[i].Node.Inode = i; gVT_Terminals[i].Node.ImplPtr = &gVT_Terminals[i]; gVT_Terminals[i].Node.NumACLs = 0; // Only root can open virtual terminals - - gVT_Terminals[i].Node.Read = VT_Read; - gVT_Terminals[i].Node.Write = VT_Write; - gVT_Terminals[i].Node.IOCtl = VT_Terminal_IOCtl; + + gVT_Terminals[i].Node.Type = &gVT_TermNodeType; // Semaphore_Init(&gVT_Terminals[i].InputSemaphore, 0, MAX_INPUT_CHARS8, "VTerm", gVT_Terminals[i].Name); } @@ -528,10 +536,10 @@ Uint64 VT_Read(tVFS_Node *Node, Uint64 Offset, Uint64 Length, void *Buffer) } /** - * \fn Uint64 VT_Write(tVFS_Node *Node, Uint64 Offset, Uint64 Length, void *Buffer) + * \fn Uint64 VT_Write(tVFS_Node *Node, Uint64 Offset, Uint64 Length, const void *Buffer) * \brief Write to a virtual terminal */ -Uint64 VT_Write(tVFS_Node *Node, Uint64 Offset, Uint64 Length, void *Buffer) +Uint64 VT_Write(tVFS_Node *Node, Uint64 Offset, Uint64 Length, const void *Buffer) { tVTerm *term = &gVT_Terminals[ Node->Inode ]; int size; @@ -1293,10 +1301,10 @@ void VT_int_ParseEscape_StandardLarge(tVTerm *Term, char CmdChar, int argc, int } /** - * \fn int VT_int_ParseEscape(tVTerm *Term, char *Buffer) + * \fn int VT_int_ParseEscape(tVTerm *Term, const char *Buffer) * \brief Parses a VT100 Escape code */ -int VT_int_ParseEscape(tVTerm *Term, char *Buffer) +int VT_int_ParseEscape(tVTerm *Term, const char *Buffer) { char c; int argc = 0, j = 1; @@ -1380,10 +1388,10 @@ int VT_int_ParseEscape(tVTerm *Term, char *Buffer) } /** - * \fn void VT_int_PutString(tVTerm *Term, Uint8 *Buffer, Uint Count) + * \fn void VT_int_PutString(tVTerm *Term, const Uint8 *Buffer, Uint Count) * \brief Print a string to the Virtual Terminal */ -void VT_int_PutString(tVTerm *Term, Uint8 *Buffer, Uint Count) +void VT_int_PutString(tVTerm *Term, const Uint8 *Buffer, Uint Count) { Uint32 val; int i; @@ -1395,7 +1403,7 @@ void VT_int_PutString(tVTerm *Term, Uint8 *Buffer, Uint Count) if( Buffer[i] == 0x1B ) { i ++; - i += VT_int_ParseEscape(Term, (char*)&Buffer[i]) - 1; + i += VT_int_ParseEscape(Term, (const char*)&Buffer[i]) - 1; continue; } diff --git a/Kernel/drvutil.c b/Kernel/drvutil.c index 00ab5ced..d19a0504 100644 --- a/Kernel/drvutil.c +++ b/Kernel/drvutil.c @@ -53,17 +53,17 @@ tVideo_IOCtl_Bitmap gDrvUtil_TextModeCursor = { // === CODE === // --- Video Driver Helpers --- -int DrvUtil_Video_2DStream(void *Ent, void *Buffer, int Length, +int DrvUtil_Video_2DStream(void *Ent, const void *Buffer, int Length, tDrvUtil_Video_2DHandlers *Handlers, int SizeofHandlers) { - void *stream = Buffer; + const Uint8 *stream = Buffer; int rem = Length; int op; while( rem ) { rem --; - op = *(Uint8*)stream; - stream = (void*)((tVAddr)stream + 1); + op = *stream; + stream ++; if(op > NUM_VIDEO_2DOPS) { Log_Warning("DrvUtil", @@ -84,7 +84,7 @@ int DrvUtil_Video_2DStream(void *Ent, void *Buffer, int Length, case VIDEO_2DOP_NOP: break; case VIDEO_2DOP_FILL: - if(rem < 12) return Length-rem; + if(rem < 10) return Length-rem; if(!Handlers->Fill) { Log_Warning("DrvUtil", "DrvUtil_Video_2DStream: Driver" @@ -94,13 +94,13 @@ int DrvUtil_Video_2DStream(void *Ent, void *Buffer, int Length, Handlers->Fill( Ent, - ((Uint16*)stream)[0], ((Uint16*)stream)[1], - ((Uint16*)stream)[2], ((Uint16*)stream)[3], - ((Uint32*)stream)[2] + ((const Uint16*)stream)[0], ((const Uint16*)stream)[1], + ((const Uint16*)stream)[2], ((const Uint16*)stream)[3], + ((const Uint32*)stream)[4] ); - rem -= 12; - stream = (void*)((tVAddr)stream + 12); + rem -= 10; + stream += 10; break; case VIDEO_2DOP_BLIT: @@ -114,13 +114,13 @@ int DrvUtil_Video_2DStream(void *Ent, void *Buffer, int Length, Handlers->Blit( Ent, - ((Uint16*)stream)[0], ((Uint16*)stream)[1], - ((Uint16*)stream)[2], ((Uint16*)stream)[3], - ((Uint16*)stream)[4], ((Uint16*)stream)[5] + ((const Uint16*)stream)[0], ((const Uint16*)stream)[1], + ((const Uint16*)stream)[2], ((const Uint16*)stream)[3], + ((const Uint16*)stream)[4], ((const Uint16*)stream)[5] ); rem -= 12; - stream = (void*)((tVAddr)stream + 12); + stream += 12; break; } @@ -128,10 +128,10 @@ int DrvUtil_Video_2DStream(void *Ent, void *Buffer, int Length, return 0; } -int DrvUtil_Video_WriteLFB(tDrvUtil_Video_BufInfo *FBInfo, size_t Offset, size_t Length, void *Buffer) +int DrvUtil_Video_WriteLFB(tDrvUtil_Video_BufInfo *FBInfo, size_t Offset, size_t Length, const void *Buffer) { Uint8 *dest; - Uint32 *src = Buffer; + const Uint32 *src = Buffer; int csr_x, csr_y; int x, y; int bytes_per_px = (FBInfo->Depth + 7) / 8; @@ -147,7 +147,7 @@ int DrvUtil_Video_WriteLFB(tDrvUtil_Video_BufInfo *FBInfo, size_t Offset, size_t { case VIDEO_BUFFMT_TEXT: { - tVT_Char *chars = Buffer; + const tVT_Char *chars = Buffer; int widthInChars = FBInfo->Width/giVT_CharWidth; int heightInChars = FBInfo->Height/giVT_CharHeight; int i; @@ -556,7 +556,7 @@ void DrvUtil_Video_2D_Blit(void *Ent, Uint16 DstX, Uint16 DstY, Uint16 SrcX, Uin // --- Disk Driver Helpers --- Uint64 DrvUtil_ReadBlock(Uint64 Start, Uint64 Length, void *Buffer, - tDrvUtil_Callback ReadBlocks, Uint64 BlockSize, Uint Argument) + tDrvUtil_Read_Callback ReadBlocks, Uint64 BlockSize, Uint Argument) { Uint8 tmp[BlockSize]; // C99 Uint64 block = Start / BlockSize; @@ -625,8 +625,8 @@ Uint64 DrvUtil_ReadBlock(Uint64 Start, Uint64 Length, void *Buffer, return Length; } -Uint64 DrvUtil_WriteBlock(Uint64 Start, Uint64 Length, void *Buffer, - tDrvUtil_Callback ReadBlocks, tDrvUtil_Callback WriteBlocks, +Uint64 DrvUtil_WriteBlock(Uint64 Start, Uint64 Length, const void *Buffer, + tDrvUtil_Read_Callback ReadBlocks, tDrvUtil_Write_Callback WriteBlocks, Uint64 BlockSize, Uint Argument) { Uint8 tmp[BlockSize]; // C99 diff --git a/Kernel/include/api_drv_disk.h b/Kernel/include/api_drv_disk.h index 68e5330d..94ea2c94 100644 --- a/Kernel/include/api_drv_disk.h +++ b/Kernel/include/api_drv_disk.h @@ -148,7 +148,8 @@ enum eTplDisk_CacheFlags * \param Buffer Destination for read blocks * \param Argument Argument provided in ::DrvUtil_ReadBlock and ::DrvUtil_WriteBlock */ -typedef Uint (*tDrvUtil_Callback)(Uint64 Address, Uint Count, void *Buffer, Uint Argument); +typedef Uint (*tDrvUtil_Read_Callback)(Uint64 Address, Uint Count, void *Buffer, Uint Argument); +typedef Uint (*tDrvUtil_Write_Callback)(Uint64 Address, Uint Count, const void *Buffer, Uint Argument); /** * \brief Reads a range from a block device using aligned reads @@ -161,7 +162,7 @@ typedef Uint (*tDrvUtil_Callback)(Uint64 Address, Uint Count, void *Buffer, Uint * \return Number of bytes read */ extern Uint64 DrvUtil_ReadBlock(Uint64 Start, Uint64 Length, void *Buffer, - tDrvUtil_Callback ReadBlocks, Uint64 BlockSize, Uint Argument); + tDrvUtil_Read_Callback ReadBlocks, Uint64 BlockSize, Uint Argument); /** * \brief Writes a range to a block device using aligned writes * \param Start Base byte offset @@ -173,8 +174,8 @@ extern Uint64 DrvUtil_ReadBlock(Uint64 Start, Uint64 Length, void *Buffer, * \param Argument An argument to pass to \a ReadBlocks and \a WriteBlocks * \return Number of bytes written */ -extern Uint64 DrvUtil_WriteBlock(Uint64 Start, Uint64 Length, void *Buffer, - tDrvUtil_Callback ReadBlocks, tDrvUtil_Callback WriteBlocks, +extern Uint64 DrvUtil_WriteBlock(Uint64 Start, Uint64 Length, const void *Buffer, + tDrvUtil_Read_Callback ReadBlocks, tDrvUtil_Write_Callback WriteBlocks, Uint64 BlockSize, Uint Argument); /** diff --git a/Kernel/include/api_drv_video.h b/Kernel/include/api_drv_video.h index f2d1a2d1..ff9c395b 100644 --- a/Kernel/include/api_drv_video.h +++ b/Kernel/include/api_drv_video.h @@ -435,7 +435,7 @@ typedef struct sDrvUtil_Video_2DHandlers * \param SizeofHandlers Size of \a tDrvUtil_Video_2DHandlers according * to the driver. Used as version control and error avoidence. */ -extern int DrvUtil_Video_2DStream(void *Ent, void *Buffer, int Length, +extern int DrvUtil_Video_2DStream(void *Ent, const void *Buffer, int Length, tDrvUtil_Video_2DHandlers *Handlers, int SizeofHandlers); /** @@ -449,7 +449,7 @@ extern int DrvUtil_Video_2DStream(void *Ent, void *Buffer, int Length, * Handles all write modes in software, using the VT font calls for rendering. * \note Calls the cursor clear and redraw if the cursor area is touched */ -extern int DrvUtil_Video_WriteLFB(tDrvUtil_Video_BufInfo *FBInfo, size_t Offset, size_t Length, void *Src); +extern int DrvUtil_Video_WriteLFB(tDrvUtil_Video_BufInfo *FBInfo, size_t Offset, size_t Length, const void *Src); /** * \name Software cursor rendering diff --git a/Kernel/include/vfs.h b/Kernel/include/vfs.h index 91771c8a..1aa073b2 100644 --- a/Kernel/include/vfs.h +++ b/Kernel/include/vfs.h @@ -26,6 +26,8 @@ */ typedef struct sVFS_SelectList tVFS_SelectList; +typedef struct sVFS_NodeType tVFS_NodeType; + /** * \name tVFS_Node Flags * \brief Flag values for tVFS_Node.Flags @@ -177,6 +179,22 @@ typedef struct sVFS_Node * \} */ + /** + * \brief Functions associated with the node + */ + tVFS_NodeType *Type; +} tVFS_Node; + +/** + * \brief Functions for a specific node type + */ +struct sVFS_NodeType +{ + /** + * \brief Debug name for the type + */ + const char *TypeName; + /** * \name Common Functions * \brief Functions that are used no matter the value of .Flags @@ -233,7 +251,7 @@ typedef struct sVFS_Node * \param Buffer Source of written data * \return Number of bytes read */ - Uint64 (*Write)(struct sVFS_Node *Node, Uint64 Offset, Uint64 Length, void *Buffer); + Uint64 (*Write)(struct sVFS_Node *Node, Uint64 Offset, Uint64 Length, const void *Buffer); /** * \brief Map a region of a file into memory @@ -299,14 +317,14 @@ typedef struct sVFS_Node * \param Node Pointer to this node (directory) * \param Child Node to create a new link to * \param NewName Name for the new link - * \return Zeron on success, non-zero on error (see errno.h) + * \retur Zeron on success, non-zero on error (see errno.h) */ int (*Link)(struct sVFS_Node *Node, struct sVFS_Node *Child, const char *NewName); /** * \} */ -} tVFS_Node; +}; /** * \brief VFS Driver (Filesystem) Definition diff --git a/Kernel/include/vfs_int.h b/Kernel/include/vfs_int.h index 4961f085..75de88bf 100644 --- a/Kernel/include/vfs_int.h +++ b/Kernel/include/vfs_int.h @@ -54,4 +54,13 @@ extern int VFS_CheckACL(tVFS_Node *Node, Uint Permissions); // --- mount.c --- extern tVFS_Mount *VFS_GetMountByIdent(Uint32 MountID); + +// --- VFS Helpers --- +static inline void _CloseNode(tVFS_Node *Node) +{ + if(Node && Node->Type && Node->Type->Close) + Node->Type->Close( Node ); +} + + #endif diff --git a/Kernel/vfs/dir.c b/Kernel/vfs/dir.c index 3d4018f9..aee7a603 100644 --- a/Kernel/vfs/dir.c +++ b/Kernel/vfs/dir.c @@ -73,7 +73,7 @@ int VFS_MkNod(const char *Path, Uint Flags) // Permissions Check if( !VFS_CheckACL(parent, VFS_PERM_EXECUTE|VFS_PERM_WRITE) ) { - if(parent->Close) parent->Close( parent ); + _CloseNode(parent); free(absPath); LEAVE('i', -1); return -1; @@ -81,20 +81,20 @@ int VFS_MkNod(const char *Path, Uint Flags) LOG("parent = %p", parent); - if(parent->MkNod == NULL) { + if(!parent->Type || !parent->Type->MkNod) { Warning("VFS_MkNod - Directory has no MkNod method"); LEAVE('i', -1); return -1; } // Create node - ret = parent->MkNod(parent, name, Flags); + ret = parent->Type->MkNod(parent, name, Flags); // Free allocated string free(absPath); // Free Parent - if(parent->Close) parent->Close( parent ); + _CloseNode(parent); // Error Check if(ret == 0) { @@ -116,48 +116,23 @@ int VFS_Symlink(const char *Name, const char *Link) { char *realLink; int fp; - char *_link; ENTER("sName sLink", Name, Link); // Get absolue path name - _link = VFS_GetAbsPath( Link ); - if(!_link) { + realLink = VFS_GetAbsPath( Link ); + if(!realLink) { Log_Warning("VFS", "Path '%s' is badly formed", Link); LEAVE('i', -1); return -1; } - LOG("_link = '%s'", _link); - - #if 1 - { - tVFS_Node *destNode = VFS_ParsePath( _link, &realLink, NULL ); - #if 0 - // Get true path and node - free(_link); - _link = NULL; - #else - realLink = _link; - #endif - - // Check if destination exists - if(!destNode) { - Log_Warning("VFS", "File '%s' does not exist, symlink not created", Link); - return -1; - } - - // Derefence the destination - if(destNode->Close) destNode->Close(destNode); - } - #else - realLink = _link; - #endif LOG("realLink = '%s'", realLink); // Make node if( VFS_MkNod(Name, VFS_FFLAG_SYMLINK) != 0 ) { Log_Warning("VFS", "Unable to create link node '%s'", Name); + free(realLink); LEAVE('i', -2); return -2; // Make link node } @@ -184,7 +159,7 @@ int VFS_ReadDir(int FD, char *Dest) //ENTER("ph pDest", h, Dest); - if(!h || h->Node->ReadDir == NULL) { + if(!h || !h->Node->Type || !h->Node->Type->ReadDir) { //LEAVE('i', 0); return 0; } @@ -195,7 +170,7 @@ int VFS_ReadDir(int FD, char *Dest) } do { - tmp = h->Node->ReadDir(h->Node, h->Position); + tmp = h->Node->Type->ReadDir(h->Node, h->Position); if((Uint)tmp < (Uint)VFS_MAXSKIP) h->Position += (Uint)tmp; else diff --git a/Kernel/vfs/fs/devfs.c b/Kernel/vfs/fs/devfs.c index 162f1113..b3f4a579 100644 --- a/Kernel/vfs/fs/devfs.c +++ b/Kernel/vfs/fs/devfs.c @@ -20,13 +20,17 @@ tVFS_Node *DevFS_FindDir(tVFS_Node *Node, const char *Name); tVFS_Driver gDevFS_Info = { "devfs", 0, DevFS_InitDevice, NULL, NULL }; +tVFS_NodeType gDevFS_DirType = { + .TypeName = "DevFS-Dir", + .ReadDir = DevFS_ReadDir, + .FindDir = DevFS_FindDir + }; tVFS_Node gDevFS_RootNode = { .Size = 0, .Flags = VFS_FFLAG_DIRECTORY, .NumACLs = 1, .ACLs = &gVFS_ACL_EveryoneRX, - .ReadDir = DevFS_ReadDir, - .FindDir = DevFS_FindDir + .Type = &gDevFS_DirType }; tDevFS_Driver *gDevFS_Drivers = NULL; int giDevFS_NextID = 1; diff --git a/Kernel/vfs/fs/root.c b/Kernel/vfs/fs/root.c index a12d1542..9fa1732b 100644 --- a/Kernel/vfs/fs/root.c +++ b/Kernel/vfs/fs/root.c @@ -17,7 +17,7 @@ tVFS_Node *Root_InitDevice(const char *Device, const char **Options); tVFS_Node *Root_FindDir(tVFS_Node *Node, const char *Name); char *Root_ReadDir(tVFS_Node *Node, int Pos); Uint64 Root_Read(tVFS_Node *Node, Uint64 Offset, Uint64 Length, void *Buffer); -Uint64 Root_Write(tVFS_Node *Node, Uint64 Offset, Uint64 Length, void *Buffer); +Uint64 Root_Write(tVFS_Node *Node, Uint64 Offset, Uint64 Length, const void *Buffer); tRamFS_File *Root_int_AllocFile(void); // === GLOBALS === @@ -35,6 +35,17 @@ tVFS_ACL RootFS_FileACLs[3] = { {{1,0}, {0,VFS_PERM_ALL^VFS_PERM_EXECUTE}}, // Group (Root) {{0,-1}, {0,VFS_PERM_READ}} // World (Nobody) }; +tVFS_NodeType gRootFS_DirType = { + .TypeName = "RootFS-Dir", + .ReadDir = Root_ReadDir, + .FindDir = Root_FindDir, + .MkNod = Root_MkNod +}; +tVFS_NodeType gRootFS_FileType = { + .TypeName = "RootFS-File", + .Read = Root_Read, + .Write = Root_Write, +}; // === CODE === /** @@ -57,12 +68,8 @@ tVFS_Node *Root_InitDevice(const char *Device, const char **Options) = root->Node.ATime = now(); root->Node.NumACLs = 3; root->Node.ACLs = RootFS_DirACLs; - - //root->Node.Close = Root_CloseFile; // Not Needed (It's a RAM Disk!) - //root->Node.Relink = Root_RelinkRoot; // Not Needed (Why relink the root of the tree) - root->Node.FindDir = Root_FindDir; - root->Node.ReadDir = Root_ReadDir; - root->Node.MkNod = Root_MkNod; + + root->Node.Type = &gRootFS_DirType; return &root->Node; } @@ -109,16 +116,13 @@ int Root_MkNod(tVFS_Node *Node, const char *Name, Uint Flags) if(Flags & VFS_FFLAG_DIRECTORY) { child->Node.ACLs = RootFS_DirACLs; - child->Node.ReadDir = Root_ReadDir; - child->Node.FindDir = Root_FindDir; - child->Node.MkNod = Root_MkNod; + child->Node.Type = &gRootFS_DirType; } else { if(Flags & VFS_FFLAG_SYMLINK) child->Node.ACLs = RootFS_DirACLs; else child->Node.ACLs = RootFS_FileACLs; - child->Node.Read = Root_Read; - child->Node.Write = Root_Write; + child->Node.Type = &gRootFS_FileType; } prev->Next = child; @@ -194,7 +198,7 @@ Uint64 Root_Read(tVFS_Node *Node, Uint64 Offset, Uint64 Length, void *Buffer) * \fn Uint64 Root_Write(tVFS_Node *Node, Uint64 Offset, Uint64 Length, void *Buffer) * \brief Write to a file in the root directory */ -Uint64 Root_Write(tVFS_Node *Node, Uint64 Offset, Uint64 Length, void *Buffer) +Uint64 Root_Write(tVFS_Node *Node, Uint64 Offset, Uint64 Length, const void *Buffer) { tRamFS_File *file = Node->ImplPtr; diff --git a/Kernel/vfs/io.c b/Kernel/vfs/io.c index 358d7039..e7a2a068 100644 --- a/Kernel/vfs/io.c +++ b/Kernel/vfs/io.c @@ -25,9 +25,9 @@ Uint64 VFS_Read(int FD, Uint64 Length, void *Buffer) if( !(h->Mode & VFS_OPENFLAG_READ) || h->Node->Flags & VFS_FFLAG_DIRECTORY ) LEAVE_RET('i', -1); - if(!h->Node->Read) LEAVE_RET('i', 0); + if(!h->Node->Type || !h->Node->Type->Read) LEAVE_RET('i', 0); - ret = h->Node->Read(h->Node, h->Position, Length, Buffer); + ret = h->Node->Type->Read(h->Node, h->Position, Length, Buffer); if(ret == -1) LEAVE_RET('i', -1); h->Position += ret; @@ -50,11 +50,11 @@ Uint64 VFS_ReadAt(int FD, Uint64 Offset, Uint64 Length, void *Buffer) if( !(h->Mode & VFS_OPENFLAG_READ) ) return -1; if( h->Node->Flags & VFS_FFLAG_DIRECTORY ) return -1; - if(!h->Node->Read) { + if( !h->Node->Type || !h->Node->Type->Read) { Warning("VFS_ReadAt - Node %p, does not have a read method", h->Node); return 0; } - ret = h->Node->Read(h->Node, Offset, Length, Buffer); + ret = h->Node->Type->Read(h->Node, Offset, Length, Buffer); if(ret == -1) return -1; return ret; } @@ -74,11 +74,11 @@ Uint64 VFS_Write(int FD, Uint64 Length, const void *Buffer) if( !(h->Mode & VFS_OPENFLAG_WRITE) ) return -1; if( h->Node->Flags & VFS_FFLAG_DIRECTORY ) return -1; - if(!h->Node->Write) return 0; + if( !h->Node->Type || !h->Node->Type->Write ) return 0; - // TODO: This is a hack, I need to change VFS_Node to have "const void*" - ret = h->Node->Write(h->Node, h->Position, Length, (void*)Buffer); + ret = h->Node->Type->Write(h->Node, h->Position, Length, Buffer); if(ret == -1) return -1; + h->Position += ret; return ret; } @@ -98,9 +98,9 @@ Uint64 VFS_WriteAt(int FD, Uint64 Offset, Uint64 Length, const void *Buffer) if( !(h->Mode & VFS_OPENFLAG_WRITE) ) return -1; if( h->Node->Flags & VFS_FFLAG_DIRECTORY ) return -1; - if(!h->Node->Write) return 0; - // TODO: This is a hack, I need to change VFS_Node to have "const void*" - ret = h->Node->Write(h->Node, Offset, Length, (void*)Buffer); + if(!h->Node->Type || !h->Node->Type->Write) return 0; + ret = h->Node->Type->Write(h->Node, Offset, Length, Buffer); + if(ret == -1) return -1; return ret; } @@ -166,8 +166,8 @@ int VFS_IOCtl(int FD, int ID, void *Buffer) h = VFS_GetHandle(FD); if(!h) return -1; - if(!h->Node->IOCtl) return -1; - return h->Node->IOCtl(h->Node, ID, Buffer); + if(!h->Node->Type || !h->Node->Type->IOCtl) return -1; + return h->Node->Type->IOCtl(h->Node, ID, Buffer); } /** diff --git a/Kernel/vfs/main.c b/Kernel/vfs/main.c index cb798c19..c6525f49 100644 --- a/Kernel/vfs/main.c +++ b/Kernel/vfs/main.c @@ -81,7 +81,7 @@ char *VFS_GetTruePath(const char *Path) //Log(" VFS_GetTruePath: node=%p, ret='%s'", node, ret); if(!node) return NULL; - if(node->Close) node->Close(node); + if(node->Type->Close) node->Type->Close(node); return ret; } diff --git a/Kernel/vfs/memfile.c b/Kernel/vfs/memfile.c index c197626f..14b39481 100644 --- a/Kernel/vfs/memfile.c +++ b/Kernel/vfs/memfile.c @@ -7,24 +7,23 @@ #include // === PROTOTYPES === -tVFS_Node *VFS_MemFile_Create(tVFS_Node *Unused, const char *Path); +tVFS_Node *VFS_MemFile_Create(const char *Path); void VFS_MemFile_Close(tVFS_Node *Node); Uint64 VFS_MemFile_Read(tVFS_Node *Node, Uint64 Offset, Uint64 Length, void *Buffer); -Uint64 VFS_MemFile_Write(tVFS_Node *Node, Uint64 Offset, Uint64 Length, void *Buffer); +Uint64 VFS_MemFile_Write(tVFS_Node *Node, Uint64 Offset, Uint64 Length, const void *Buffer); // === GLOBALS === -tVFS_Node gVFS_MemRoot = { - .Flags = VFS_FFLAG_DIRECTORY, - .NumACLs = 0, - .FindDir = VFS_MemFile_Create +tVFS_NodeType gVFS_MemFileType = { + .Close = VFS_MemFile_Close, + .Read = VFS_MemFile_Read, + .Write = VFS_MemFile_Write }; // === CODE === /** - * \fn tVFS_Node *VFS_MemFile_Create(tVFS_Node *Unused, const char *Path) - * \note Treated as finddir by VFS_ParsePath + * \fn tVFS_Node *VFS_MemFile_Create(const char *Path) */ -tVFS_Node *VFS_MemFile_Create(tVFS_Node *Unused, const char *Path) +tVFS_Node *VFS_MemFile_Create(const char *Path) { Uint base, size; const char *str = Path; @@ -73,9 +72,7 @@ tVFS_Node *VFS_MemFile_Create(tVFS_Node *Unused, const char *Path) ret->ACLs = &gVFS_ACL_EveryoneRWX; // Functions - ret->Close = VFS_MemFile_Close; - ret->Read = VFS_MemFile_Read; - ret->Write = VFS_MemFile_Write; + ret->Type = &gVFS_MemFileType; return ret; } @@ -119,7 +116,7 @@ Uint64 VFS_MemFile_Read(tVFS_Node *Node, Uint64 Offset, Uint64 Length, void *Buf * \fn Uint64 VFS_MemFile_Write(tVFS_Node *Node, Uint64 Offset, Uint64 Length, void *Buffer) * \brief Write to a memory file */ -Uint64 VFS_MemFile_Write(tVFS_Node *Node, Uint64 Offset, Uint64 Length, void *Buffer) +Uint64 VFS_MemFile_Write(tVFS_Node *Node, Uint64 Offset, Uint64 Length, const void *Buffer) { // Check for use of free'd file if(Node->ImplPtr == NULL) return 0; diff --git a/Kernel/vfs/mmap.c b/Kernel/vfs/mmap.c index f4132d55..9fe9282c 100644 --- a/Kernel/vfs/mmap.c +++ b/Kernel/vfs/mmap.c @@ -114,8 +114,13 @@ void *VFS_MMap(void *DestHint, size_t Length, int Protection, int Flags, int FD, { if( pb->PhysAddrs[pagenum - pb->BaseOffset] == 0 ) { - if( h->Node->MMap ) - h->Node->MMap(h->Node, pagenum*PAGE_SIZE, PAGE_SIZE, (void*)mapping_dest); + tVFS_NodeType *nt = h->Node->Type; + if( !nt ) + { + // TODO: error + } + else if( nt->MMap ) + nt->MMap(h->Node, pagenum*PAGE_SIZE, PAGE_SIZE, (void*)mapping_dest); else { int read_len; @@ -127,7 +132,7 @@ void *VFS_MMap(void *DestHint, size_t Length, int Protection, int Flags, int FD, return NULL; } // TODO: Clip read length - read_len = h->Node->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); // if( read_len != PAGE_SIZE ) { // memset( (void*)(mapping_dest+read_len), 0, PAGE_SIZE-read_len ); // } diff --git a/Kernel/vfs/nodecache.c b/Kernel/vfs/nodecache.c index ad85ac32..d2796c1b 100644 --- a/Kernel/vfs/nodecache.c +++ b/Kernel/vfs/nodecache.c @@ -178,8 +178,8 @@ void Inode_ClearCache(int Handle) ent->Node.ReferenceCount = 1; next = ent->Next; - if(ent->Node.Close) - ent->Node.Close( &ent->Node ); + if(ent->Node.Type && ent->Node.Type->Close) + ent->Node.Type->Close( &ent->Node ); free(ent); ent = next; diff --git a/Kernel/vfs/open.c b/Kernel/vfs/open.c index a886c451..448f09b1 100644 --- a/Kernel/vfs/open.c +++ b/Kernel/vfs/open.c @@ -15,9 +15,9 @@ #define MAX_PATH_LEN 255 // === IMPORTS === -extern tVFS_Node gVFS_MemRoot; extern tVFS_Mount *gVFS_RootMount; extern int VFS_AllocHandle(int bIsUser, tVFS_Node *Node, int Mode); +extern tVFS_Node *VFS_MemFile_Create(const char *Path); // === PROTOTYPES === int VFS_int_CreateHandle( tVFS_Node *Node, tVFS_Mount *Mount, int Mode ); @@ -176,13 +176,13 @@ tVFS_Node *VFS_ParsePath(const char *Path, char **TruePath, tVFS_Mount **MountPo ENTER("sPath pTruePath", Path, TruePath); - // Memory File - if(Path[0] == '$') { + // HACK: Memory File + if(Threads_GetUID() == 0 && Path[0] == '$') { if(TruePath) { *TruePath = malloc(strlen(Path)+1); strcpy(*TruePath, Path); } - curNode = gVFS_MemRoot.FindDir(&gVFS_MemRoot, Path); + curNode = VFS_MemFile_Create(Path); if(MountPoint) { *MountPoint = NULL; } @@ -268,48 +268,27 @@ restart_parse: // Check permissions on root of filesystem if( !VFS_CheckACL(curNode, VFS_PERM_EXECUTE) ) { - if(curNode->Close) curNode->Close( curNode ); - if(TruePath) { - free(*TruePath); - *TruePath = NULL; - } //Log("Permissions fail on '%s'", Path); - LEAVE('n'); - return NULL; + goto _error; } // Check if the node has a FindDir method - if( !curNode->FindDir ) + if( !curNode->Type->FindDir ) { - if(curNode->Close) curNode->Close(curNode); - if(TruePath) { - free(*TruePath); - *TruePath = NULL; - } //Log("FindDir fail on '%s'", Path); - LEAVE('n'); - return NULL; + goto _error; } - LOG("FindDir{=%p}(%p, '%s')", curNode->FindDir, curNode, pathEle); + LOG("FindDir{=%p}(%p, '%s')", curNode->Type->FindDir, curNode, pathEle); // Get Child Node - tmpNode = curNode->FindDir(curNode, pathEle); + tmpNode = curNode->Type->FindDir(curNode, pathEle); LOG("tmpNode = %p", tmpNode); - if(curNode->Close) { - //LOG2("curNode->Close = %p", curNode->Close); - curNode->Close(curNode); - } + _CloseNode( curNode ); curNode = tmpNode; // Error Check if(!curNode) { LOG("Node '%s' not found in dir '%s'", pathEle, Path); - if(TruePath) { - free(*TruePath); - *TruePath = NULL; - } - //Log("Child fail on '%s' ('%s)", Path, pathEle); - LEAVE('n'); - return NULL; + goto _error; } // Handle Symbolic Links @@ -318,19 +297,15 @@ restart_parse: free(*TruePath); *TruePath = NULL; } - if(!curNode->Read) { + if(!curNode->Type || !curNode->Type->Read) { Log_Warning("VFS", "VFS_ParsePath - Read of symlink node %p'%s' is NULL", curNode, Path); - if(curNode->Close) curNode->Close(curNode); - // No need to free *TruePath, it should already be NULL - LEAVE('n'); - return NULL; + goto _error; } if(iNestedLinks > MAX_NESTED_LINKS) { - if(curNode->Close) curNode->Close(curNode); - LEAVE('n'); - return NULL; + Log_Notice("VFS", "VFS_ParsePath - Nested link limit exceeded"); + goto _error; } // Parse Symlink Path @@ -339,12 +314,10 @@ restart_parse: { int remlen = strlen(Path) - (ofs + nextSlash); if( curNode->Size + remlen > MAX_PATH_LEN ) { - if(curNode->Close) curNode->Close(curNode); Log_Warning("VFS", "VFS_ParsePath - Symlinked path too long"); - LEAVE('n'); - return NULL; + goto _error; } - curNode->Read( curNode, 0, curNode->Size, path_buffer ); + curNode->Type->Read( curNode, 0, curNode->Size, path_buffer ); path_buffer[ curNode->Size ] = '\0'; LOG("path_buffer = '%s'", path_buffer); strcat(path_buffer, Path + ofs+nextSlash); @@ -363,9 +336,7 @@ restart_parse: if( !(curNode->Flags & VFS_FFLAG_DIRECTORY) ) { Log_Warning("VFS", "VFS_ParsePath - Path segment is not a directory"); - if(TruePath) free(*TruePath); - LEAVE('n'); - return NULL; + goto _error; } // Check if path needs extending @@ -376,11 +347,7 @@ restart_parse: // Check if allocation succeeded if(!tmp) { Log_Warning("VFS", "VFS_ParsePath - Unable to reallocate true path buffer"); - free(*TruePath); - *TruePath = NULL; - if(curNode->Close) curNode->Close(curNode); - LEAVE('n'); - return NULL; + goto _error; } *TruePath = tmp; // Append to path @@ -392,32 +359,23 @@ restart_parse: // - Extend Path retLength += nextSlash + 1; } - - if( !curNode->FindDir ) { - if(curNode->Close) curNode->Close(curNode); - if(TruePath) { - free(*TruePath); - *TruePath = NULL; - } + + // Check final finddir call + if( !curNode->Type || !curNode->Type->FindDir ) { Log_Warning("VFS", "VFS_ParsePath - FindDir doesn't exist for element of '%s'", Path); - LEAVE('n'); - return NULL; + goto _error; } // Get last node LOG("FindDir(%p, '%s')", curNode, &Path[ofs]); - tmpNode = curNode->FindDir(curNode, &Path[ofs]); + tmpNode = curNode->Type->FindDir(curNode, &Path[ofs]); LOG("tmpNode = %p", tmpNode); - if(curNode->Close) curNode->Close(curNode); // Check if file was found if(!tmpNode) { LOG("Node '%s' not found in dir '%s'", &Path[ofs], Path); - //Log("Child fail '%s' ('%s')", Path, &Path[ofs]); - if(TruePath) free(*TruePath); - if(curNode->Close) curNode->Close(curNode); - LEAVE('n'); - return NULL; + goto _error; } + _CloseNode( curNode ); if(TruePath) { @@ -426,10 +384,7 @@ restart_parse: // Check if allocation succeeded if(!tmp) { Log_Warning("VFS", "VFS_ParsePath - Unable to reallocate true path buffer"); - free(*TruePath); - if(tmpNode->Close) tmpNode->Close(curNode); - LEAVE('n'); - return NULL; + goto _error; } *TruePath = tmp; // Append to path @@ -445,6 +400,16 @@ restart_parse: LEAVE('p', tmpNode); return tmpNode; + +_error: + _CloseNode( curNode ); + + if(TruePath && *TruePath) { + free(*TruePath); + *TruePath = NULL; + } + LEAVE('n'); + return NULL; } /** @@ -465,7 +430,7 @@ int VFS_int_CreateHandle( tVFS_Node *Node, tVFS_Mount *Mount, int Mode ) // Permissions Check if( !VFS_CheckACL(Node, i) ) { - if(Node->Close) Node->Close( Node ); + _CloseNode( Node ); Log_Log("VFS", "VFS_int_CreateHandle: Permissions Failed"); errno = EACCES; LEAVE_RET('i', -1); @@ -521,14 +486,14 @@ int VFS_Open(const char *Path, Uint Mode) Log_Warning("VFS", "VFS_Open - Symlink is too long (%i)", node->Size); LEAVE_RET('i', -1); } - if( !node->Read ) { + if( !node->Type || !node->Type->Read ) { Log_Warning("VFS", "VFS_Open - No read method on symlink"); LEAVE_RET('i', -1); } // Read symlink's path - node->Read( node, 0, node->Size, tmppath ); + node->Type->Read( node, 0, node->Size, tmppath ); tmppath[ node->Size ] = '\0'; - if(node->Close) node->Close( node ); + _CloseNode( node ); // Open the target node = VFS_ParsePath(tmppath, NULL, &mnt); if(!node) { @@ -562,13 +527,20 @@ int VFS_OpenChild(int FD, const char *Name, Uint Mode) // Check for directory if( !(h->Node->Flags & VFS_FFLAG_DIRECTORY) ) { - Log_Warning("VFS", "VFS_OpenChild - Passed handle is not a directory", FD); + Log_Warning("VFS", "VFS_OpenChild - Passed handle is not a directory"); + errno = ENOTDIR; + LEAVE_RET('i', -1); + } + + // Sanity check + if( !h->Node->Type || !h->Node->Type->FindDir ) { + Log_Error("VFS", "VFS_OpenChild - Node does not have a type/is missing FindDir"); errno = ENOTDIR; LEAVE_RET('i', -1); } // Find Child - node = h->Node->FindDir(h->Node, Name); + node = h->Node->Type->FindDir(h->Node, Name); if(!node) { errno = ENOENT; LEAVE_RET('i', -1); @@ -633,8 +605,7 @@ void VFS_Close(int FD) } #endif - if(h->Node->Close) - h->Node->Close( h->Node ); + _CloseNode(h->Node); h->Node = NULL; } diff --git a/Modules/Display/BochsGA/bochsvbe.c b/Modules/Display/BochsGA/bochsvbe.c index 58a024f9..806c1c13 100644 --- a/Modules/Display/BochsGA/bochsvbe.c +++ b/Modules/Display/BochsGA/bochsvbe.c @@ -64,19 +64,20 @@ void BGA_int_SetMode(Uint16 width, Uint16 height); int BGA_int_MapFB(void *Dest); // Filesystem Uint64 BGA_Read(tVFS_Node *Node, Uint64 off, Uint64 len, void *buffer); -Uint64 BGA_Write(tVFS_Node *Node, Uint64 off, Uint64 len, void *buffer); +Uint64 BGA_Write(tVFS_Node *Node, Uint64 off, Uint64 len, const void *buffer); int BGA_IOCtl(tVFS_Node *Node, int ID, void *Data); // === GLOBALS === MODULE_DEFINE(0, VERSION, BochsGA, BGA_Install, NULL, "PCI", NULL); -tDevFS_Driver gBGA_DriverStruct = { - NULL, "BochsGA", - { +tVFS_NodeType gBGA_NodeType = { .Read = BGA_Read, .Write = BGA_Write, .IOCtl = BGA_IOCtl - } -}; + }; +tDevFS_Driver gBGA_DriverStruct = { + NULL, "BochsGA", + {.Type = &gBGA_NodeType} + }; int giBGA_CurrentMode = -1; tVideo_IOCtl_Pos gBGA_CursorPos = {-1,-1}; Uint *gBGA_Framebuffer; @@ -160,7 +161,7 @@ Uint64 BGA_Read(tVFS_Node *node, Uint64 off, Uint64 len, void *buffer) /** * \brief Write to the framebuffer */ -Uint64 BGA_Write(tVFS_Node *Node, Uint64 Offset, Uint64 Length, void *Buffer) +Uint64 BGA_Write(tVFS_Node *Node, Uint64 Offset, Uint64 Length, const void *Buffer) { if( giBGA_CurrentMode == -1 ) BGA_int_UpdateMode(0); return DrvUtil_Video_WriteLFB(&gBGA_DrvUtil_BufInfo, Offset, Length, Buffer); diff --git a/Modules/Display/VESA/main.c b/Modules/Display/VESA/main.c index 55083b04..a85d3137 100644 --- a/Modules/Display/VESA/main.c +++ b/Modules/Display/VESA/main.c @@ -24,7 +24,7 @@ // === PROTOTYPES === int Vesa_Install(char **Arguments); Uint64 Vesa_Read(tVFS_Node *Node, Uint64 Offset, Uint64 Length, void *Buffer); -Uint64 Vesa_Write(tVFS_Node *Node, Uint64 Offset, Uint64 Length, void *Buffer); +Uint64 Vesa_Write(tVFS_Node *Node, Uint64 Offset, Uint64 Length, const void *Buffer); int Vesa_IOCtl(tVFS_Node *Node, int ID, void *Data); int Vesa_Int_SetMode(int Mode); int Vesa_Int_FindMode(tVideo_IOCtl_Mode *data); @@ -35,14 +35,15 @@ void Vesa_FlipCursor(void *Arg); // === GLOBALS === MODULE_DEFINE(0, VERSION, Vesa, Vesa_Install, NULL, "PCI", "VM8086", NULL); -tDevFS_Driver gVesa_DriverStruct = { - NULL, "Vesa", - { +tVFS_NodeType gVesa_NodeType = { .Read = Vesa_Read, .Write = Vesa_Write, .IOCtl = Vesa_IOCtl - } -}; + }; +tDevFS_Driver gVesa_DriverStruct = { + NULL, "Vesa", + {.Type = &gVesa_NodeType} + }; tMutex glVesa_Lock; tVM8086 *gpVesa_BiosState; int giVesaDriverId = -1; @@ -178,7 +179,7 @@ Uint64 Vesa_Read(tVFS_Node *Node, Uint64 off, Uint64 len, void *buffer) /** * \brief Write to the framebuffer */ -Uint64 Vesa_Write(tVFS_Node *Node, Uint64 Offset, Uint64 Length, void *Buffer) +Uint64 Vesa_Write(tVFS_Node *Node, Uint64 Offset, Uint64 Length, const void *Buffer) { if( gVesa_Modes[giVesaCurrentMode].framebuffer == 0 ) { Log_Warning("VESA", "Vesa_Write - Non-LFB Modes not yet supported."); diff --git a/Modules/Filesystems/Ext2/dir.c b/Modules/Filesystems/Ext2/dir.c index c7d8dd89..5eb476f4 100644 --- a/Modules/Filesystems/Ext2/dir.c +++ b/Modules/Filesystems/Ext2/dir.c @@ -23,6 +23,23 @@ tVFS_Node *Ext2_FindDir(tVFS_Node *Node, const char *FileName); // --- Helpers --- tVFS_Node *Ext2_int_CreateNode(tExt2_Disk *Disk, Uint InodeId); +// === GLOBALS === +tVFS_NodeType gExt2_DirType = { + .TypeName = "ext2-dir", + .ReadDir = Ext2_ReadDir, + .FindDir = Ext2_FindDir, + .MkNod = Ext2_MkNod, + .Relink = Ext2_Relink, + .Link = Ext2_Link, + .Close = Ext2_CloseFile + }; +tVFS_NodeType gExt2_FileType = { + .TypeName = "ext2-file", + .Read = Ext2_Read, + .Write = Ext2_Write, + .Close = Ext2_CloseFile + }; + // === CODE === /** * \brief Reads a directory entry @@ -345,9 +362,7 @@ tVFS_Node *Ext2_int_CreateNode(tExt2_Disk *Disk, Uint InodeID) retNode.ACLs = VFS_UnixToAcessACL(inode.i_mode & 0777, inode.i_uid, inode.i_gid); // Set Function Pointers - retNode.Read = Ext2_Read; - retNode.Write = Ext2_Write; - retNode.Close = Ext2_CloseFile; + retNode.Type = &gExt2_FileType; switch(inode.i_mode & EXT2_S_IFMT) { @@ -362,11 +377,7 @@ tVFS_Node *Ext2_int_CreateNode(tExt2_Disk *Disk, Uint InodeID) break; // Directory case EXT2_S_IFDIR: - retNode.ReadDir = Ext2_ReadDir; - retNode.FindDir = Ext2_FindDir; - retNode.MkNod = Ext2_MkNod; - retNode.Relink = Ext2_Relink; - retNode.Link = Ext2_Link; + retNode.Type = &gExt2_DirType; retNode.Flags = VFS_FFLAG_DIRECTORY; retNode.Data = calloc( sizeof(Uint16), DivUp(retNode.Size, Disk->BlockSize) ); break; diff --git a/Modules/Filesystems/Ext2/ext2.c b/Modules/Filesystems/Ext2/ext2.c index ad96cc85..7c4bf973 100644 --- a/Modules/Filesystems/Ext2/ext2.c +++ b/Modules/Filesystems/Ext2/ext2.c @@ -12,6 +12,9 @@ #include "ext2_common.h" #include +// === IMPORTS === +extern tVFS_NodeType gExt2_DirType; + // === PROTOTYPES === int Ext2_Install(char **Arguments); // Interface Functions @@ -130,10 +133,8 @@ tVFS_Node *Ext2_InitDevice(const char *Device, const char **Options) disk->RootNode.ImplPtr = disk; // Save disk pointer disk->RootNode.Size = -1; // Fill in later (on readdir) disk->RootNode.Flags = VFS_FFLAG_DIRECTORY; - - disk->RootNode.ReadDir = Ext2_ReadDir; - disk->RootNode.FindDir = Ext2_FindDir; - //disk->RootNode.Relink = Ext2_Relink; + + disk->RootNode.Type = &gExt2_DirType; // Complete root node disk->RootNode.UID = inode.i_uid; diff --git a/Modules/Filesystems/Ext2/ext2_common.h b/Modules/Filesystems/Ext2/ext2_common.h index be4ae392..6ef9d7c8 100644 --- a/Modules/Filesystems/Ext2/ext2_common.h +++ b/Modules/Filesystems/Ext2/ext2_common.h @@ -42,6 +42,6 @@ extern int Ext2_Link(tVFS_Node *Parent, tVFS_Node *Node, const char *Name); // --- Read --- extern Uint64 Ext2_Read(tVFS_Node *node, Uint64 offset, Uint64 length, void *buffer); // --- Write --- -extern Uint64 Ext2_Write(tVFS_Node *node, Uint64 offset, Uint64 length, void *buffer); +extern Uint64 Ext2_Write(tVFS_Node *node, Uint64 offset, Uint64 length, const void *buffer); #endif diff --git a/Modules/Filesystems/Ext2/write.c b/Modules/Filesystems/Ext2/write.c index 5a7cfc02..03109e8a 100644 --- a/Modules/Filesystems/Ext2/write.c +++ b/Modules/Filesystems/Ext2/write.c @@ -12,7 +12,6 @@ #include "ext2_common.h" // === PROTOYPES === -Uint64 Ext2_Write(tVFS_Node *node, Uint64 offset, Uint64 length, void *buffer); Uint32 Ext2_int_AllocateBlock(tExt2_Disk *Disk, Uint32 PrevBlock); void Ext2_int_DeallocateBlock(tExt2_Disk *Disk, Uint32 Block); int Ext2_int_AppendBlock(tExt2_Disk *Disk, tExt2_Inode *Inode, Uint32 Block); @@ -22,7 +21,7 @@ void Ext2_int_DeallocateBlock(tExt2_Disk *Disk, Uint32 Block); * \fn Uint64 Ext2_Write(tVFS_Node *Node, Uint64 Offset, Uint64 Length, void *Buffer) * \brief Write to a file */ -Uint64 Ext2_Write(tVFS_Node *Node, Uint64 Offset, Uint64 Length, void *Buffer) +Uint64 Ext2_Write(tVFS_Node *Node, Uint64 Offset, Uint64 Length, const void *Buffer) { tExt2_Disk *disk = Node->ImplPtr; tExt2_Inode inode; diff --git a/Modules/Filesystems/FAT/fat.c b/Modules/Filesystems/FAT/fat.c index af733223..f5d19161 100644 --- a/Modules/Filesystems/FAT/fat.c +++ b/Modules/Filesystems/FAT/fat.c @@ -90,6 +90,24 @@ MODULE_DEFINE(0, (0<<8)|50 /*v0.50*/, VFAT, FAT_Install, NULL, NULL); tFAT_VolInfo gFAT_Disks[8]; int giFAT_PartCount = 0; tVFS_Driver gFAT_FSInfo = {"fat", 0, FAT_InitDevice, FAT_Unmount, FAT_GetNodeFromINode, NULL}; +tVFS_NodeType gFAT_DirType = { + .TypeName = "FAT-Dir", + .ReadDir = FAT_ReadDir, + .FindDir = FAT_FindDir, + #if SUPPORT_WRITE + .MkNod = FAT_Mknod, + .Relink = FAT_Relink, + #endif + .Close = FAT_CloseFile + }; +tVFS_NodeType gFAT_FileType = { + .TypeName = "FAT-File", + .Read = FAT_Read, + #if SUPPORT_WRITE + .Write = FAT_Write, + #endif + .Close = FAT_CloseFile + }; // === CODE === /** @@ -273,18 +291,8 @@ tVFS_Node *FAT_InitDevice(const char *Device, const char **Options) node->ACLs = &gVFS_ACL_EveryoneRWX; node->Flags = VFS_FFLAG_DIRECTORY; node->CTime = node->MTime = node->ATime = now(); - - node->Read = node->Write = NULL; - node->ReadDir = FAT_ReadDir; - node->FindDir = FAT_FindDir; - #if SUPPORT_WRITE - node->Relink = FAT_Relink; - node->MkNod = FAT_Mknod; - #else - node->Relink = NULL; - node->MkNod = NULL; - #endif - //node->Close = FAT_Unmount; + + node->Type = &gFAT_DirType; giFAT_PartCount ++; return node; @@ -977,21 +985,12 @@ tVFS_Node *FAT_int_CreateNode(tVFS_Node *Parent, fat_filetable *Entry, int Pos) // Set pointers if(node.Flags & VFS_FFLAG_DIRECTORY) { //Log_Debug("FAT", "Directory %08x has size 0x%x", node.Inode, node.Size); - node.ReadDir = FAT_ReadDir; - node.FindDir = FAT_FindDir; - #if SUPPORT_WRITE - node.MkNod = FAT_Mknod; - node.Relink = FAT_Relink; - #endif + node.Type = &gFAT_DirType; node.Size = -1; } else { - node.Read = FAT_Read; - #if SUPPORT_WRITE - node.Write = FAT_Write; - #endif + node.Type = &gFAT_FileType; } - node.Close = FAT_CloseFile; ret = Inode_CacheNode(disk->inodeHandle, &node); LEAVE('p', ret); diff --git a/Modules/Filesystems/NTFS/main.c b/Modules/Filesystems/NTFS/main.c index f5f99c72..dbda06e1 100644 --- a/Modules/Filesystems/NTFS/main.c +++ b/Modules/Filesystems/NTFS/main.c @@ -24,6 +24,12 @@ void NTFS_DumpEntry(tNTFS_Disk *Disk, Uint32 Entry); // === GLOBALS === MODULE_DEFINE(0, 0x0A /*v0.1*/, FS_NTFS, NTFS_Install, NULL); tVFS_Driver gNTFS_FSInfo = {"ntfs", 0, NTFS_InitDevice, NTFS_Unmount, NULL}; +tVFS_NodeType gNTFS_DirType = { + .TypeName = "NTFS-File", + .ReadDir = NTFS_ReadDir, + .FindDir = NTFS_FindDir, + .Close = NULL + }; tNTFS_Disk gNTFS_Disks; @@ -99,12 +105,8 @@ tVFS_Node *NTFS_InitDevice(const char *Device, const char **Options) disk->RootNode.NumACLs = 1; disk->RootNode.ACLs = &gVFS_ACL_EveryoneRX; - disk->RootNode.ReadDir = NTFS_ReadDir; - disk->RootNode.FindDir = NTFS_FindDir; - disk->RootNode.MkNod = NULL; - disk->RootNode.Link = NULL; - disk->RootNode.Relink = NULL; - disk->RootNode.Close = NULL; + disk->RootNode.Type = &gNTFS_DirType; + NTFS_DumpEntry(disk, 5); diff --git a/Modules/IPStack/interface.c b/Modules/IPStack/interface.c index 82d1b8c4..5bfcda77 100644 --- a/Modules/IPStack/interface.c +++ b/Modules/IPStack/interface.c @@ -32,6 +32,11 @@ tVFS_Node *IPStack_Iface_FindDir(tVFS_Node *Node, const char *Name); int IPStack_Iface_IOCtl(tVFS_Node *Node, int ID, void *Data); // === GLOBALS === +tVFS_NodeType gIP_InterfaceNodeType = { + .ReadDir = IPStack_Iface_ReadDir, + .FindDir = IPStack_Iface_FindDir, + .IOCtl = IPStack_Iface_IOCtl +}; //! Loopback (127.0.0.0/8, ::1) Pseudo-Interface tInterface gIP_LoopInterface = { .Node = { @@ -40,9 +45,7 @@ tInterface gIP_LoopInterface = { .Size = -1, .NumACLs = 1, .ACLs = &gVFS_ACL_EveryoneRX, - .ReadDir = IPStack_Iface_ReadDir, - .FindDir = IPStack_Iface_FindDir, - .IOCtl = IPStack_Iface_IOCtl + .Type = &gIP_InterfaceNodeType }, .Adapter = NULL, .Type = 0 @@ -234,13 +237,7 @@ tInterface *IPStack_AddInterface(const char *Device, const char *Name) iface->Node.Size = -1; iface->Node.NumACLs = 1; iface->Node.ACLs = &gVFS_ACL_EveryoneRX; - iface->Node.ReadDir = IPStack_Iface_ReadDir; - iface->Node.FindDir = IPStack_Iface_FindDir; - iface->Node.IOCtl = IPStack_Iface_IOCtl; - iface->Node.MkNod = NULL; - iface->Node.Link = NULL; - iface->Node.Relink = NULL; - iface->Node.Close = NULL; + iface->Node.Type = &gIP_InterfaceNodeType; // Set Defaults iface->TimeoutDelay = DEFAULT_TIMEOUT; diff --git a/Modules/IPStack/main.c b/Modules/IPStack/main.c index 5f650b33..9b9930e3 100644 --- a/Modules/IPStack/main.c +++ b/Modules/IPStack/main.c @@ -30,6 +30,11 @@ extern tRoute *IPStack_AddRoute(const char *Interface, void *Network, int Subnet // === GLOBALS === MODULE_DEFINE(0, VERSION, IPStack, IPStack_Install, NULL, NULL); +tVFS_NodeType gIP_RootNodeType = { + .ReadDir = IPStack_Root_ReadDir, + .FindDir = IPStack_Root_FindDir, + .IOCtl = IPStack_Root_IOCtl +}; tDevFS_Driver gIP_DriverInfo = { NULL, "ip", { @@ -37,9 +42,7 @@ tDevFS_Driver gIP_DriverInfo = { .NumACLs = 1, .ACLs = &gVFS_ACL_EveryoneRX, .Flags = VFS_FFLAG_DIRECTORY, - .ReadDir = IPStack_Root_ReadDir, - .FindDir = IPStack_Root_FindDir, - .IOCtl = IPStack_Root_IOCtl + .Type = &gIP_RootNodeType } }; diff --git a/Modules/IPStack/routing.c b/Modules/IPStack/routing.c index 1cde444f..0145f215 100644 --- a/Modules/IPStack/routing.c +++ b/Modules/IPStack/routing.c @@ -31,14 +31,20 @@ tRoute *IPStack_FindRoute(int AddressType, tInterface *Interface, void *Address) int giIP_NextRouteId = 1; tRoute *gIP_Routes; tRoute *gIP_RoutesEnd; +tVFS_NodeType gIP_RouteNodeType = { + .IOCtl = IPStack_Route_IOCtl +}; +tVFS_NodeType gIP_RouteDirNodeType = { + .ReadDir = IPStack_RouteDir_ReadDir, + .FindDir = IPStack_RouteDir_FindDir, + .IOCtl = IPStack_RouteDir_IOCtl +}; tVFS_Node gIP_RouteNode = { .Flags = VFS_FFLAG_DIRECTORY, .Size = -1, .NumACLs = 1, .ACLs = &gVFS_ACL_EveryoneRX, - .ReadDir = IPStack_RouteDir_ReadDir, - .FindDir = IPStack_RouteDir_FindDir, - .IOCtl = IPStack_RouteDir_IOCtl + .Type = &gIP_RouteDirNodeType }; // === CODE === @@ -192,7 +198,7 @@ tRoute *IPStack_Route_Create(const char *InterfaceName) return NULL; } iface = node->ImplPtr; - if(node->Close) node->Close(node); + if(node->Type->Close) node->Type->Close(node); } // Get the size of the specified address type @@ -210,7 +216,7 @@ tRoute *IPStack_Route_Create(const char *InterfaceName) rt->Node.Size = 0; rt->Node.NumACLs = 1, rt->Node.ACLs = &gVFS_ACL_EveryoneRO; - rt->Node.IOCtl = IPStack_Route_IOCtl; + rt->Node.Type = &gIP_RouteNodeType; // Set up state rt->AddressType = iface->Type; diff --git a/Modules/IPStack/tcp.c b/Modules/IPStack/tcp.c index e2cc4a8a..7ba25565 100644 --- a/Modules/IPStack/tcp.c +++ b/Modules/IPStack/tcp.c @@ -40,7 +40,7 @@ void TCP_Server_Close(tVFS_Node *Node); // --- Client tVFS_Node *TCP_Client_Init(tInterface *Interface); Uint64 TCP_Client_Read(tVFS_Node *Node, Uint64 Offset, Uint64 Length, void *Buffer); -Uint64 TCP_Client_Write(tVFS_Node *Node, Uint64 Offset, Uint64 Length, void *Buffer); +Uint64 TCP_Client_Write(tVFS_Node *Node, Uint64 Offset, Uint64 Length, const void *Buffer); int TCP_Client_IOCtl(tVFS_Node *Node, int ID, void *Data); void TCP_Client_Close(tVFS_Node *Node); // --- Helpers @@ -49,6 +49,20 @@ void TCP_Client_Close(tVFS_Node *Node); // === TEMPLATES === tSocketFile gTCP_ServerFile = {NULL, "tcps", TCP_Server_Init}; tSocketFile gTCP_ClientFile = {NULL, "tcpc", TCP_Client_Init}; +tVFS_NodeType gTCP_ServerNodeType = { + .TypeName = "TCP Server", + .ReadDir = TCP_Server_ReadDir, + .FindDir = TCP_Server_FindDir, + .IOCtl = TCP_Server_IOCtl, + .Close = TCP_Server_Close + }; +tVFS_NodeType gTCP_ClientNodeType = { + .TypeName = "TCP Client/Connection", + .Read = TCP_Client_Read, + .Write = TCP_Client_Write, + .IOCtl = TCP_Client_IOCtl, + .Close = TCP_Client_Close + }; // === GLOBALS === int giTCP_NumHalfopen = 0; @@ -226,9 +240,7 @@ void TCP_GetPacket(tInterface *Interface, void *Address, int Length, void *Buffe conn->Node.ACLs = &gVFS_ACL_EveryoneRW; conn->Node.ImplPtr = conn; conn->Node.ImplInt = srv->NextID ++; - conn->Node.Read = TCP_Client_Read; - conn->Node.Write = TCP_Client_Write; - //conn->Node.Close = TCP_SrvConn_Close; + conn->Node.Type = &gTCP_ClientNodeType; // TODO: Special type for the server end? // Hmm... Theoretically, this lock will never have to wait, // as the interface is locked to the watching thread, and this @@ -835,10 +847,7 @@ tVFS_Node *TCP_Server_Init(tInterface *Interface) srv->Node.ImplPtr = srv; srv->Node.NumACLs = 1; srv->Node.ACLs = &gVFS_ACL_EveryoneRW; - srv->Node.ReadDir = TCP_Server_ReadDir; - srv->Node.FindDir = TCP_Server_FindDir; - srv->Node.IOCtl = TCP_Server_IOCtl; - srv->Node.Close = TCP_Server_Close; + srv->Node.Type = &gTCP_ServerNodeType; SHORTLOCK(&glTCP_Listeners); srv->Next = gTCP_Listeners; @@ -1003,10 +1012,7 @@ tVFS_Node *TCP_Client_Init(tInterface *Interface) conn->Node.ImplPtr = conn; conn->Node.NumACLs = 1; conn->Node.ACLs = &gVFS_ACL_EveryoneRW; - conn->Node.Read = TCP_Client_Read; - conn->Node.Write = TCP_Client_Write; - conn->Node.IOCtl = TCP_Client_IOCtl; - conn->Node.Close = TCP_Client_Close; + conn->Node.Type = &gTCP_ClientNodeType; conn->RecievedBuffer = RingBuffer_Create( TCP_RECIEVE_BUFFER_SIZE ); #if 0 @@ -1086,7 +1092,7 @@ Uint64 TCP_Client_Read(tVFS_Node *Node, Uint64 Offset, Uint64 Length, void *Buff /** * \brief Send a data packet on a connection */ -void TCP_INT_SendDataPacket(tTCPConnection *Connection, size_t Length, void *Data) +void TCP_INT_SendDataPacket(tTCPConnection *Connection, size_t Length, const void *Data) { char buf[sizeof(tTCPHeader)+Length]; tTCPHeader *packet = (void*)buf; @@ -1115,7 +1121,7 @@ void TCP_INT_SendDataPacket(tTCPConnection *Connection, size_t Length, void *Dat /** * \brief Send some bytes on a connection */ -Uint64 TCP_Client_Write(tVFS_Node *Node, Uint64 Offset, Uint64 Length, void *Buffer) +Uint64 TCP_Client_Write(tVFS_Node *Node, Uint64 Offset, Uint64 Length, const void *Buffer) { tTCPConnection *conn = Node->ImplPtr; size_t rem = Length; diff --git a/Modules/IPStack/udp.c b/Modules/IPStack/udp.c index c75aab0c..7228f170 100644 --- a/Modules/IPStack/udp.c +++ b/Modules/IPStack/udp.c @@ -16,7 +16,7 @@ void UDP_SendPacketTo(tUDPChannel *Channel, int AddrType, void *Address, Uint16 // --- Client Channels tVFS_Node *UDP_Channel_Init(tInterface *Interface); Uint64 UDP_Channel_Read(tVFS_Node *Node, Uint64 Offset, Uint64 Length, void *Buffer); -Uint64 UDP_Channel_Write(tVFS_Node *Node, Uint64 Offset, Uint64 Length, void *Buffer); +Uint64 UDP_Channel_Write(tVFS_Node *Node, Uint64 Offset, Uint64 Length, const void *Buffer); int UDP_Channel_IOCtl(tVFS_Node *Node, int ID, void *Data); void UDP_Channel_Close(tVFS_Node *Node); // --- Helpers @@ -25,6 +25,12 @@ Uint16 UDP_int_AllocatePort(); void UDP_int_FreePort(Uint16 Port); // === GLOBALS === +tVFS_NodeType gUDP_NodeType = { + .Read = UDP_Channel_Read, + .Write = UDP_Channel_Write, + .IOCtl = UDP_Channel_IOCtl, + .Close = UDP_Channel_Close +}; tMutex glUDP_Channels; tUDPChannel *gpUDP_Channels; @@ -169,10 +175,7 @@ tVFS_Node *UDP_Channel_Init(tInterface *Interface) new->Node.ImplPtr = new; new->Node.NumACLs = 1; new->Node.ACLs = &gVFS_ACL_EveryoneRW; - new->Node.Read = UDP_Channel_Read; - new->Node.Write = UDP_Channel_Write; - new->Node.IOCtl = UDP_Channel_IOCtl; - new->Node.Close = UDP_Channel_Close; + new->Node.Type = &gUDP_NodeType; Mutex_Acquire(&glUDP_Channels); new->Next = gpUDP_Channels; @@ -244,7 +247,7 @@ Uint64 UDP_Channel_Read(tVFS_Node *Node, Uint64 Offset, Uint64 Length, void *Buf /** * \brief Write to the channel file (send a packet) */ -Uint64 UDP_Channel_Write(tVFS_Node *Node, Uint64 Offset, Uint64 Length, void *Buffer) +Uint64 UDP_Channel_Write(tVFS_Node *Node, Uint64 Offset, Uint64 Length, const void *Buffer) { tUDPChannel *chan = Node->ImplPtr; tUDPEndpoint *ep; diff --git a/Modules/Input/PS2KbMouse/kb.c b/Modules/Input/PS2KbMouse/kb.c index 56c98c27..a121b611 100644 --- a/Modules/Input/PS2KbMouse/kb.c +++ b/Modules/Input/PS2KbMouse/kb.c @@ -25,13 +25,12 @@ void KB_UpdateLEDs(void); int KB_IOCtl(tVFS_Node *Node, int Id, void *Data); // === GLOBALS === +tVFS_NodeType gKB_NodeType = { + .IOCtl = KB_IOCtl +}; tDevFS_Driver gKB_DevInfo = { NULL, "PS2Keyboard", - { - .NumACLs = 0, - .Size = 0, - .IOCtl = KB_IOCtl - } + { .Type = &gKB_NodeType } }; tKeybardCallback gKB_Callback = NULL; Uint32 **gpKB_Map = gpKBDUS; diff --git a/Modules/Input/PS2KbMouse/ps2mouse.c b/Modules/Input/PS2KbMouse/ps2mouse.c index e80a1413..44be3b7b 100644 --- a/Modules/Input/PS2KbMouse/ps2mouse.c +++ b/Modules/Input/PS2KbMouse/ps2mouse.c @@ -39,11 +39,15 @@ tJoystick_Callback gMouse_Callback; int giMouse_Cycle = 0; // IRQ Position Uint8 gaMouse_Bytes[4] = {0,0,0,0}; // - Driver definition +tVFS_NodeType gMouse_NodeType = { + .Read = PS2Mouse_Read, + .IOCtl = PS2Mouse_IOCtl +}; tDevFS_Driver gMouse_DriverStruct = { NULL, "PS2Mouse", { .NumACLs = 1, .ACLs = &gVFS_ACL_EveryoneRX, - .Read = PS2Mouse_Read, .IOCtl = PS2Mouse_IOCtl + .Type = &gMouse_NodeType } }; diff --git a/Modules/Network/NE2000/ne2000.c b/Modules/Network/NE2000/ne2000.c index 37d9c5a6..d05b2a33 100644 --- a/Modules/Network/NE2000/ne2000.c +++ b/Modules/Network/NE2000/ne2000.c @@ -86,7 +86,7 @@ typedef struct sNe2k_Card { char *Ne2k_ReadDir(tVFS_Node *Node, int Pos); tVFS_Node *Ne2k_FindDir(tVFS_Node *Node, const char *Name); int Ne2k_IOCtl(tVFS_Node *Node, int ID, void *Data); -Uint64 Ne2k_Write(tVFS_Node *Node, Uint64 Offset, Uint64 Length, void *Buffer); +Uint64 Ne2k_Write(tVFS_Node *Node, Uint64 Offset, Uint64 Length, const void *Buffer); Uint64 Ne2k_Read(tVFS_Node *Node, Uint64 Offset, Uint64 Length, void *Buffer); int Ne2k_int_ReadDMA(tCard *Card, int FirstPage, int NumPages, void *Buffer); @@ -95,15 +95,23 @@ void Ne2k_IRQHandler(int IntNum, void *Ptr); // === GLOBALS === MODULE_DEFINE(0, VERSION, Ne2k, Ne2k_Install, NULL, NULL); +tVFS_NodeType gNe2K_RootNodeType = { + .ReadDir = Ne2k_ReadDir, + .FindDir = Ne2k_FindDir, + .IOCtl = Ne2k_IOCtl + }; +tVFS_NodeType gNe2K_DevNodeType = { + .Write = Ne2k_Write, + .Read = Ne2k_Read, + .IOCtl = Ne2k_IOCtl + }; tDevFS_Driver gNe2k_DriverInfo = { NULL, "ne2k", { .NumACLs = 1, .ACLs = &gVFS_ACL_EveryoneRX, .Flags = VFS_FFLAG_DIRECTORY, - .ReadDir = Ne2k_ReadDir, - .FindDir = Ne2k_FindDir, - .IOCtl = Ne2k_IOCtl + .Type = &gNe2K_RootNodeType } }; Uint16 gNe2k_BaseAddress; @@ -202,9 +210,7 @@ int Ne2k_Install(char **Options) gpNe2k_Cards[ k ].Node.ImplPtr = &gpNe2k_Cards[ k ]; gpNe2k_Cards[ k ].Node.NumACLs = 0; // Root Only gpNe2k_Cards[ k ].Node.CTime = now(); - gpNe2k_Cards[ k ].Node.Write = Ne2k_Write; - gpNe2k_Cards[ k ].Node.Read = Ne2k_Read; - gpNe2k_Cards[ k ].Node.IOCtl = Ne2k_IOCtl; + gpNe2k_Cards[ k ].Node.Type = &gNe2K_DevNodeType; // Initialise packet semaphore // - Start at zero, no max @@ -275,13 +281,13 @@ int Ne2k_IOCtl(tVFS_Node *Node, int ID, void *Data) } /** - * \fn Uint64 Ne2k_Write(tVFS_Node *Node, Uint64 Offset, Uint64 Length, void *Buffer) + * \fn Uint64 Ne2k_Write(tVFS_Node *Node, Uint64 Offset, Uint64 Length, const void *Buffer) * \brief Send a packet from the network card */ -Uint64 Ne2k_Write(tVFS_Node *Node, Uint64 Offset, Uint64 Length, void *Buffer) +Uint64 Ne2k_Write(tVFS_Node *Node, Uint64 Offset, Uint64 Length, const void *Buffer) { tCard *Card = (tCard*)Node->ImplPtr; - Uint16 *buf = Buffer; + const Uint16 *buf = Buffer; int rem = Length; int page; diff --git a/Modules/Network/RTL8139/rtl8139.c b/Modules/Network/RTL8139/rtl8139.c index eb77812b..1e9ac899 100644 --- a/Modules/Network/RTL8139/rtl8139.c +++ b/Modules/Network/RTL8139/rtl8139.c @@ -95,21 +95,29 @@ char *RTL8139_ReadDir(tVFS_Node *Node, int Pos); tVFS_Node *RTL8139_FindDir(tVFS_Node *Node, const char *Filename); int RTL8139_RootIOCtl(tVFS_Node *Node, int ID, void *Arg); Uint64 RTL8139_Read(tVFS_Node *Node, Uint64 Offset, Uint64 Length, void *Buffer); -Uint64 RTL8139_Write(tVFS_Node *Node, Uint64 Offset, Uint64 Length, void *Buffer); +Uint64 RTL8139_Write(tVFS_Node *Node, Uint64 Offset, Uint64 Length, const void *Buffer); int RTL8139_IOCtl(tVFS_Node *Node, int ID, void *Arg); void RTL8139_IRQHandler(int Num, void *Ptr); // === GLOBALS === MODULE_DEFINE(0, VERSION, RTL8139, RTL8139_Install, NULL, NULL); +tVFS_NodeType gRTL8139_RootNodeType = { + .ReadDir = RTL8139_ReadDir, + .FindDir = RTL8139_FindDir, + .IOCtl = RTL8139_IOCtl + }; +tVFS_NodeType gRTL8139_DevNodeType = { + .Write = RTL8139_Write, + .Read = RTL8139_Read, + .IOCtl = RTL8139_IOCtl + }; tDevFS_Driver gRTL8139_DriverInfo = { NULL, "RTL8139", { .NumACLs = 1, .ACLs = &gVFS_ACL_EveryoneRX, .Flags = VFS_FFLAG_DIRECTORY, - .ReadDir = RTL8139_ReadDir, - .FindDir = RTL8139_FindDir, - .IOCtl = RTL8139_RootIOCtl + .Type = &gRTL8139_RootNodeType } }; int giRTL8139_CardCount; @@ -206,9 +214,7 @@ int RTL8139_Install(char **Options) card->Node.ImplPtr = card; card->Node.NumACLs = 0; card->Node.CTime = now(); - card->Node.Write = RTL8139_Write; - card->Node.Read = RTL8139_Read; - card->Node.IOCtl = RTL8139_IOCtl; + card->Node.Type = &gRTL8139_DevNodeType; Log_Log("RTL8139", "Card %i 0x%04x, IRQ %i %02x:%02x:%02x:%02x:%02x:%02x", i, card->IOBase, card->IRQ, @@ -307,7 +313,7 @@ retry: return Length; } -Uint64 RTL8139_Write(tVFS_Node *Node, Uint64 Offset, Uint64 Length, void *Buffer) +Uint64 RTL8139_Write(tVFS_Node *Node, Uint64 Offset, Uint64 Length, const void *Buffer) { int td; Uint32 status; diff --git a/Modules/Storage/ATA/main.c b/Modules/Storage/ATA/main.c index 958855fc..41228d88 100644 --- a/Modules/Storage/ATA/main.c +++ b/Modules/Storage/ATA/main.c @@ -27,14 +27,25 @@ Uint16 ATA_GetBasePort(int Disk); char *ATA_ReadDir(tVFS_Node *Node, int Pos); tVFS_Node *ATA_FindDir(tVFS_Node *Node, const char *Name); Uint64 ATA_ReadFS(tVFS_Node *Node, Uint64 Offset, Uint64 Length, void *Buffer); -Uint64 ATA_WriteFS(tVFS_Node *Node, Uint64 Offset, Uint64 Length, void *Buffer); +Uint64 ATA_WriteFS(tVFS_Node *Node, Uint64 Offset, Uint64 Length, const void *Buffer); int ATA_IOCtl(tVFS_Node *Node, int Id, void *Data); // Read/Write Interface/Quantiser Uint ATA_ReadRaw(Uint64 Address, Uint Count, void *Buffer, Uint Disk); -Uint ATA_WriteRaw(Uint64 Address, Uint Count, void *Buffer, Uint Disk); +Uint ATA_WriteRaw(Uint64 Address, Uint Count, const void *Buffer, Uint Disk); // === GLOBALS === MODULE_DEFINE(0, VERSION, i386ATA, ATA_Install, NULL, "PCI", NULL); +tVFS_NodeType gATA_RootNodeType = { + .TypeName = "ATA Root Node", + .ReadDir = ATA_ReadDir, + .FindDir = ATA_FindDir + }; +tVFS_NodeType gATA_DiskNodeType = { + .TypeName = "ATA Volume", + .Read = ATA_ReadFS, + .Write = ATA_WriteFS, + .IOCtl = ATA_IOCtl + }; tDevFS_Driver gATA_DriverInfo = { NULL, "ata", { @@ -42,8 +53,7 @@ tDevFS_Driver gATA_DriverInfo = { .Size = -1, .Flags = VFS_FFLAG_DIRECTORY, .ACLs = &gVFS_ACL_EveryoneRX, - .ReadDir = ATA_ReadDir, - .FindDir = ATA_FindDir + .Type = &gATA_RootNodeType } }; tATA_Disk gATA_Disks[MAX_ATA_DISKS]; @@ -171,12 +181,9 @@ int ATA_ScanDisk(int Disk) node->Inode = (Disk << 8) | 0xFF; node->ImplPtr = gATA_Disks[ Disk ].Name; - node->ATime = node->MTime - = node->CTime = now(); + node->ATime = node->MTime = node->CTime = now(); - node->Read = ATA_ReadFS; - node->Write = ATA_WriteFS; - node->IOCtl = ATA_IOCtl; + node->Type = &gATA_DiskNodeType; // --- Scan Partitions --- LOG("Reading MBR"); @@ -224,9 +231,7 @@ void ATA_int_MakePartition(tATA_Partition *Part, int Disk, int Num, Uint64 Start Part->Node.Inode = (Disk << 8) | Num; Part->Node.ImplPtr = Part->Name; - Part->Node.Read = ATA_ReadFS; - Part->Node.Write = ATA_WriteFS; - Part->Node.IOCtl = ATA_IOCtl; + Part->Node.Type = &gATA_DiskNodeType; Log_Notice("ATA", "Partition %s at 0x%llx+0x%llx", Part->Name, Part->Start, Part->Length); LOG("Made '%s' (&Node=%p)", Part->Name, &Part->Node); LEAVE('-'); @@ -330,9 +335,9 @@ Uint64 ATA_ReadFS(tVFS_Node *Node, Uint64 Offset, Uint64 Length, void *Buffer) } /** - * \fn Uint64 ATA_WriteFS(tVFS_Node *Node, Uint64 Offset, Uint64 Length, void *Buffer) + * \fn Uint64 ATA_WriteFS(tVFS_Node *Node, Uint64 Offset, Uint64 Length, const void *Buffer) */ -Uint64 ATA_WriteFS(tVFS_Node *Node, Uint64 Offset, Uint64 Length, void *Buffer) +Uint64 ATA_WriteFS(tVFS_Node *Node, Uint64 Offset, Uint64 Length, const void *Buffer) { int disk = Node->Inode >> 8; int part = Node->Inode & 0xFF; @@ -417,9 +422,9 @@ Uint ATA_ReadRaw(Uint64 Address, Uint Count, void *Buffer, Uint Disk) } /** - * \fn Uint ATA_WriteRaw(Uint64 Address, Uint Count, void *Buffer, Uint Disk) + * \fn Uint ATA_WriteRaw(Uint64 Address, Uint Count, const void *Buffer, Uint Disk) */ -Uint ATA_WriteRaw(Uint64 Address, Uint Count, void *Buffer, Uint Disk) +Uint ATA_WriteRaw(Uint64 Address, Uint Count, const void *Buffer, Uint Disk) { int ret; Uint offset; diff --git a/Modules/Storage/FDDv2/main.c b/Modules/Storage/FDDv2/main.c index 0821a589..bec157ce 100644 --- a/Modules/Storage/FDDv2/main.c +++ b/Modules/Storage/FDDv2/main.c @@ -32,6 +32,17 @@ Uint64 FDD_ReadFS(tVFS_Node *node, Uint64 off, Uint64 len, void *buffer); MODULE_DEFINE(0, FDD_VERSION, Storage_FDDv2, FDD_Install, NULL, "x86_ISADMA", NULL); tDrive gaFDD_Disks[MAX_DISKS]; tVFS_Node gaFDD_DiskNodes[MAX_DISKS]; +tVFS_NodeType gFDD_RootNodeType = { + .TypeName = "FDD Root Node", + .ReadDir = FDD_ReadDir, + .FindDir = FDD_FindDir, + .IOCtl = FDD_IOCtl + }; +tVFS_NodeType gFDD_DevNodeType = { + .TypeName = "FDD Device", + .Read = FDD_ReadFS, + .Write = NULL // FDD_WriteFS? + }; tDevFS_Driver gFDD_DriverInfo = { NULL, "fdd", { @@ -39,9 +50,7 @@ tDevFS_Driver gFDD_DriverInfo = { .NumACLs = 1, .ACLs = &gVFS_ACL_EveryoneRX, .Flags = VFS_FFLAG_DIRECTORY, - .ReadDir = FDD_ReadDir, - .FindDir = FDD_FindDir, - .IOCtl = FDD_IOCtl + .Type = &gFDD_RootNodeType } }; @@ -88,8 +97,7 @@ int FDD_RegisterFS(void) gaFDD_DiskNodes[i].Inode = i; gaFDD_DiskNodes[i].Flags = 0; gaFDD_DiskNodes[i].NumACLs = 0; - gaFDD_DiskNodes[i].Read = FDD_ReadFS; - gaFDD_DiskNodes[i].Write = NULL;//FDD_WriteFS; + gaFDD_DiskNodes[i].Type = &gFDD_DevNodeType; gaFDD_DiskNodes[i].Size = 1440*1024; // TODO: Non 1.44 disks } diff --git a/Modules/x86/VGAText/vga.c b/Modules/x86/VGAText/vga.c index d958956b..41f0bd01 100644 --- a/Modules/x86/VGAText/vga.c +++ b/Modules/x86/VGAText/vga.c @@ -13,10 +13,10 @@ // === PROTOTYPES === int VGA_Install(char **Arguments); -Uint64 VGA_Write(tVFS_Node *Node, Uint64 Offset, Uint64 Length, void *Buffer); +Uint64 VGA_Write(tVFS_Node *Node, Uint64 Offset, Uint64 Length, const void *Buffer); int VGA_IOCtl(tVFS_Node *Node, int Id, void *Data); Uint8 VGA_int_GetColourNibble(Uint16 col); -Uint16 VGA_int_GetWord(tVT_Char *Char); +Uint16 VGA_int_GetWord(const tVT_Char *Char); void VGA_int_SetCursor(Sint16 x, Sint16 y); // --- 2D Acceleration Functions -- void VGA_2D_Fill(void *Ent, Uint16 X, Uint16 Y, Uint16 W, Uint16 H, Uint32 Colour); @@ -24,14 +24,17 @@ void VGA_2D_Blit(void *Ent, Uint16 DstX, Uint16 DstY, Uint16 SrcX, Uint16 SrcY, // === GLOBALS === MODULE_DEFINE(0, 0x000A, x86_VGAText, VGA_Install, NULL, NULL); +tVFS_NodeType gVGA_NodeType = { + //.Read = VGA_Read, + .Write = VGA_Write, + .IOCtl = VGA_IOCtl + }; tDevFS_Driver gVGA_DevInfo = { NULL, "x86_VGAText", { .NumACLs = 0, .Size = VGA_WIDTH*VGA_HEIGHT*sizeof(tVT_Char), - //.Read = VGA_Read, - .Write = VGA_Write, - .IOCtl = VGA_IOCtl + .Type = &gVGA_NodeType } }; Uint16 *gVGA_Framebuffer = (void*)( KERNEL_BASE|0xB8000 ); @@ -65,17 +68,16 @@ int VGA_Install(char **Arguments) } /** - * \fn Uint64 VGA_Write(tVFS_Node *Node, Uint64 Offset, Uint64 Length, void *Buffer) * \brief Writes a string of bytes to the VGA controller */ -Uint64 VGA_Write(tVFS_Node *Node, Uint64 Offset, Uint64 Length, void *Buffer) +Uint64 VGA_Write(tVFS_Node *Node, Uint64 Offset, Uint64 Length, const void *Buffer) { if( giVGA_BufferFormat == VIDEO_BUFFMT_TEXT ) { int num = Length / sizeof(tVT_Char); int ofs = Offset / sizeof(tVT_Char); int i = 0; - tVT_Char *chars = Buffer; + const tVT_Char *chars = Buffer; Uint16 word; //ENTER("pNode XOffset XLength pBuffer", Node, Offset, Length, Buffer); @@ -197,7 +199,7 @@ Uint8 VGA_int_GetColourNibble(Uint16 col) * \fn Uint16 VGA_int_GetWord(tVT_Char *Char) * \brief Convers a character structure to a VGA character word */ -Uint16 VGA_int_GetWord(tVT_Char *Char) +Uint16 VGA_int_GetWord(const tVT_Char *Char) { Uint16 ret; Uint16 col; -- 2.20.1