X-Git-Url: https://git.ucc.asn.au/?a=blobdiff_plain;f=Kernel%2Fvfs%2Ffs%2Ffat.c;h=bfae4058e82d30a4925cb3b4d592ef00f43ba9a7;hb=1a96e0dd77d6922078edd703fc7c2e809b9499b8;hp=c4f667134122b1f2a5560173d237b3d551fa4ad4;hpb=8bc40333b1401d7616b225945fee53d972c2f418;p=tpg%2Facess2.git diff --git a/Kernel/vfs/fs/fat.c b/Kernel/vfs/fs/fat.c index c4f66713..bfae4058 100644 --- a/Kernel/vfs/fs/fat.c +++ b/Kernel/vfs/fs/fat.c @@ -39,7 +39,7 @@ typedef struct s_lfncache { // === PROTOTYPES === int FAT_Install(char **Arguments); tVFS_Node *FAT_InitDevice(char *device, char *options); -void FAT_CloseDevice(tVFS_Node *node); +void FAT_Unmount(tVFS_Node *Node); Uint64 FAT_Read(tVFS_Node *node, Uint64 offset, Uint64 length, void *buffer); Uint64 FAT_Write(tVFS_Node *node, Uint64 offset, Uint64 length, void *buffer); char *FAT_ReadDir(tVFS_Node *dirNode, int dirpos); @@ -59,7 +59,7 @@ Uint32 *fat_cache[8]; t_lfncache *fat_lfncache; #endif tVFS_Driver gFAT_FSInfo = { - "fat", 0, FAT_InitDevice, NULL + "fat", 0, FAT_InitDevice, FAT_Unmount, NULL }; // === CODE === @@ -73,7 +73,9 @@ int FAT_Install(char **Arguments) return 0; } -/* Reads the boot sector of a disk and prepares the structures for it +/** + * \fn tVFS_Node *FAT_InitDevice(char *Device, char *options) + * \brief Reads the boot sector of a disk and prepares the structures for it */ tVFS_Node *FAT_InitDevice(char *Device, char *options) { @@ -146,7 +148,6 @@ tVFS_Node *FAT_InitDevice(char *Device, char *options) #endif //Get Name - //puts(" Name: "); if(diskInfo->type == FAT32) { for(i=0;i<11;i++) diskInfo->name[i] = (bs->spec.fat32.label[i] == ' ' ? '\0' : bs->spec.fat32.label[i]); @@ -156,7 +157,6 @@ tVFS_Node *FAT_InitDevice(char *Device, char *options) diskInfo->name[i] = (bs->spec.fat16.label[i] == ' ' ? '\0' : bs->spec.fat16.label[i]); } diskInfo->name[11] = '\0'; - //puts(diskInfo->name); putch('\n'); //Compute Root directory offset if(diskInfo->type == FAT32) @@ -224,16 +224,15 @@ tVFS_Node *FAT_InitDevice(char *Device, char *options) Log(" FAT_InitDisk: Inode Cache handle is %i\n", gFAT_Disks[giFAT_PartCount].inodeHandle); #endif - //== VFS Interface + // == VFS Interface node = &gFAT_Disks[giFAT_PartCount].rootNode; - //node->Name = gFAT_Disks[giFAT_PartCount].name; node->Inode = diskInfo->rootOffset; - node->Size = bs->files_in_root; //Unknown - To be set on readdir + node->Size = bs->files_in_root; // Unknown - To be set on readdir node->ImplInt = giFAT_PartCount; node->ReferenceCount = 1; - node->UID = 0; node->GID= 0; + node->UID = 0; node->GID = 0; node->NumACLs = 1; node->ACLs = &gVFS_ACL_EveryoneRWX; node->Flags = VFS_FFLAG_DIRECTORY; @@ -244,26 +243,24 @@ tVFS_Node *FAT_InitDevice(char *Device, char *options) node->FindDir = FAT_FindDir; node->Relink = FAT_Relink; node->MkNod = FAT_Mknod; - node->Close = FAT_CloseDevice; + //node->Close = FAT_CloseDevice; giFAT_PartCount ++; return node; } /** - * \fn void FAT_CloseDevice(tVFS_Node *node) + * \fn void FAT_Unmount(tVFS_Node *Node) * \brief Closes a mount and marks it as free */ -void FAT_CloseDevice(tVFS_Node *node) +void FAT_Unmount(tVFS_Node *Node) { - node->ReferenceCount --; - - if(node->ReferenceCount > 0) return; - // Close Disk Handle - VFS_Close( gFAT_Disks[node->ImplInt].fileHandle ); - Inode_ClearCache(gFAT_Disks[node->ImplInt].inodeHandle); - gFAT_Disks[node->ImplInt].fileHandle = -2; + VFS_Close( gFAT_Disks[Node->ImplInt].fileHandle ); + // Clear Node Cache + Inode_ClearCache(gFAT_Disks[Node->ImplInt].inodeHandle); + // Mark as unused + gFAT_Disks[Node->ImplInt].fileHandle = -2; return; } @@ -345,6 +342,18 @@ Uint64 FAT_Read(tVFS_Node *node, Uint64 offset, Uint64 length, void *buffer) return 0; } + // Sanity Check offset + if(offset > node->Size) { + //Log("FAT_Read: Reading past EOF (%i > %i)", offset, node->Size); + return 0; + } + // Clamp Size + if(offset + length > node->Size) { + //Log("FAT_Read: Reading past EOF (%lli + %lli > %lli), clamped to %lli", + // offset, length, node->Size, node->Size - offset); + length = node->Size - offset; + } + // Single Cluster including offset if(length + offset < bpc) { @@ -352,7 +361,7 @@ Uint64 FAT_Read(tVFS_Node *node, Uint64 offset, Uint64 length, void *buffer) memcpy( buffer, (void*)( tmpBuf + offset%bpc ), length ); free(tmpBuf); LEAVE('i', 1); - return 1; + return length; } preSkip = offset / bpc; @@ -382,7 +391,7 @@ Uint64 FAT_Read(tVFS_Node *node, Uint64 offset, Uint64 length, void *buffer) if (count == 1) { free(tmpBuf); LEAVE('i', 1); - return 1; + return length; } cluster = FAT_int_GetFatValue(handle, cluster); @@ -492,8 +501,6 @@ tVFS_Node *FAT_int_CreateNode(tVFS_Node *parent, fat_filetable *ft, char *LongFi ENTER("pParent pFT sLongFileName", parent, ft, LongFileName); - // Get Name - //node.Name = FAT_int_CreateName(parent, ft, LongFileName); // Set Other Data node.Inode = ft->cluster | (ft->clusterHi<<16); node.Size = ft->size; @@ -532,6 +539,7 @@ tVFS_Node *FAT_int_CreateNode(tVFS_Node *parent, fat_filetable *ft, char *LongFi node.ReadDir = FAT_ReadDir; node.FindDir = FAT_FindDir; node.MkNod = FAT_Mknod; + node.Size = -1; } else { node.Read = FAT_Read; node.Write = FAT_Write; @@ -669,16 +677,16 @@ char *FAT_ReadDir(tVFS_Node *dirNode, int dirpos) // Offset in sector a = dirpos & 0xF; - LOG("offset=%i, a=%i\n", (Uint)offset, a); + LOG("offset=%i, a=%i", (Uint)offset, a); // Read Sector VFS_ReadAt(disk->fileHandle, offset*512, 512, fileinfo); // Read Dir Data - LOG("name[0] = 0x%x\n", (Uint8)fileinfo[a].name[0]); + LOG("name[0] = 0x%x", (Uint8)fileinfo[a].name[0]); //Check if this is the last entry if(fileinfo[a].name[0] == '\0') { dirNode->Size = dirpos; - LOG("End of list\n"); + LOG("End of list"); LEAVE('n'); return NULL; // break } @@ -703,7 +711,7 @@ char *FAT_ReadDir(tVFS_Node *dirNode, int dirpos) // Get the current length len = strlen(lfn); - // Sanity Check (FAT implementations do not allow >255 bytes) + // Sanity Check (FAT implementations should not allow >255 bytes) if(len + 13 > 255) return VFS_SKIP; // Rebase all bytes for(a=len+1;a--;) lfn[a+13] = lfn[a];