From: John Hodge Date: Mon, 20 Aug 2012 11:36:28 +0000 (+0800) Subject: Misc code cleanup X-Git-Tag: rel0.15~706^2~33 X-Git-Url: https://git.ucc.asn.au/?a=commitdiff_plain;h=bf62604f78c2d8bc88cac3664e15ed02c6e6d581;p=tpg%2Facess2.git Misc code cleanup --- diff --git a/KernelLand/Kernel/drv/proc.c b/KernelLand/Kernel/drv/proc.c index b4483b04..e8cab198 100644 --- a/KernelLand/Kernel/drv/proc.c +++ b/KernelLand/Kernel/drv/proc.c @@ -250,8 +250,9 @@ int SysFS_UpdateFile(int ID, const char *Data, int Length) for( ent = gSysFS_FileList; ent; ent = ent->Next ) { // It's a reverse sorted list - if(ent->Node.Inode < ID) return 0; - if(ent->Node.Inode == ID) + if(ent->Node.Inode < (Uint64)ID) + return 0; + if(ent->Node.Inode == (Uint64)ID) { ent->Node.ImplPtr = (void*)Data; ent->Node.Size = Length; @@ -278,8 +279,8 @@ int SysFS_RemoveFile(int ID) for( ent = gSysFS_FileList; ent; prev = ent, ent = ent->Next ) { // It's a reverse sorted list - if(ent->Node.Inode < ID) return 0; - if(ent->Node.Inode == ID) break; + if(ent->Node.Inode < (Uint64)ID) return 0; + if(ent->Node.Inode == (Uint64)ID) break; } if(!ent) return 0; @@ -326,7 +327,7 @@ int SysFS_RemoveFile(int ID) char *SysFS_Comm_ReadDir(tVFS_Node *Node, int Pos) { tSysFS_Ent *child = (tSysFS_Ent*)Node->ImplPtr; - if(Pos < 0 || Pos >= Node->Size) return NULL; + if(Pos < 0 || (Uint64)Pos >= Node->Size) return NULL; for( ; child; child = child->Next, Pos-- ) { diff --git a/KernelLand/Kernel/drvutil_disk.c b/KernelLand/Kernel/drvutil_disk.c index 49dc7b23..a57917d0 100644 --- a/KernelLand/Kernel/drvutil_disk.c +++ b/KernelLand/Kernel/drvutil_disk.c @@ -10,16 +10,16 @@ #include // --- Disk Driver Helpers --- -Uint64 DrvUtil_ReadBlock(Uint64 Start, Uint64 Length, void *Buffer, - tDrvUtil_Read_Callback ReadBlocks, Uint64 BlockSize, void *Argument) +size_t DrvUtil_ReadBlock(Uint64 Start, size_t Length, void *Buffer, + tDrvUtil_Read_Callback ReadBlocks, size_t BlockSize, void *Argument) { Uint8 tmp[BlockSize]; // C99 Uint64 block = Start / BlockSize; int offset = Start - block * BlockSize; - int leading = BlockSize - offset; + size_t leading = BlockSize - offset; Uint64 num; int tailings; - Uint64 ret; + size_t ret; ENTER("XStart XLength pBuffer pReadBlocks XBlockSize pArgument", Start, Length, Buffer, ReadBlocks, BlockSize, Argument); @@ -82,17 +82,17 @@ Uint64 DrvUtil_ReadBlock(Uint64 Start, Uint64 Length, void *Buffer, return Length; } -Uint64 DrvUtil_WriteBlock(Uint64 Start, Uint64 Length, const void *Buffer, +size_t DrvUtil_WriteBlock(Uint64 Start, size_t Length, const void *Buffer, tDrvUtil_Read_Callback ReadBlocks, tDrvUtil_Write_Callback WriteBlocks, - Uint64 BlockSize, void *Argument) + size_t BlockSize, void *Argument) { Uint8 tmp[BlockSize]; // C99 Uint64 block = Start / BlockSize; - int offset = Start - block * BlockSize; - int leading = BlockSize - offset; + size_t offset = Start - block * BlockSize; + size_t leading = BlockSize - offset; Uint64 num; int tailings; - Uint64 ret; + size_t ret; ENTER("XStart XLength pBuffer pReadBlocks pWriteBlocks XBlockSize pArgument", Start, Length, Buffer, ReadBlocks, WriteBlocks, BlockSize, Argument); diff --git a/KernelLand/Kernel/include/api_drv_disk.h b/KernelLand/Kernel/include/api_drv_disk.h index c37dfec6..bde78ab2 100644 --- a/KernelLand/Kernel/include/api_drv_disk.h +++ b/KernelLand/Kernel/include/api_drv_disk.h @@ -161,8 +161,8 @@ typedef Uint (*tDrvUtil_Write_Callback)(Uint64 Address, Uint Count, const void * * \param Argument An argument to pass to \a ReadBlocks * \return Number of bytes read */ -extern Uint64 DrvUtil_ReadBlock(Uint64 Start, Uint64 Length, void *Buffer, - tDrvUtil_Read_Callback ReadBlocks, Uint64 BlockSize, void *Argument); +extern size_t DrvUtil_ReadBlock(Uint64 Start, size_t Length, void *Buffer, + tDrvUtil_Read_Callback ReadBlocks, size_t BlockSize, void *Argument); /** * \brief Writes a range to a block device using aligned writes * \param Start Base byte offset @@ -174,9 +174,9 @@ 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, const void *Buffer, +extern size_t DrvUtil_WriteBlock(Uint64 Start, size_t Length, const void *Buffer, tDrvUtil_Read_Callback ReadBlocks, tDrvUtil_Write_Callback WriteBlocks, - Uint64 BlockSize, void *Argument); + size_t BlockSize, void *Argument); /** * \} diff --git a/KernelLand/Kernel/include/vfs_ext.h b/KernelLand/Kernel/include/vfs_ext.h index 8cabfa18..d9bc833c 100644 --- a/KernelLand/Kernel/include/vfs_ext.h +++ b/KernelLand/Kernel/include/vfs_ext.h @@ -276,7 +276,7 @@ extern Uint64 VFS_Tell(int FD); * \param Buffer Destination of read data * \return Number of read bytes */ -extern Uint64 VFS_Read(int FD, Uint64 Length, void *Buffer); +extern size_t VFS_Read(int FD, size_t Length, void *Buffer); /** * \brief Writes data to a file * \param FD File handle returned by ::VFS_Open @@ -284,7 +284,7 @@ extern Uint64 VFS_Read(int FD, Uint64 Length, void *Buffer); * \param Buffer Source of written data * \return Number of bytes written */ -extern Uint64 VFS_Write(int FD, Uint64 Length, const void *Buffer); +extern size_t VFS_Write(int FD, size_t Length, const void *Buffer); /** * \brief Reads from a specific offset in the file @@ -294,7 +294,7 @@ extern Uint64 VFS_Write(int FD, Uint64 Length, const void *Buffer); * \param Buffer Source of read data * \return Number of bytes read */ -extern Uint64 VFS_ReadAt(int FD, Uint64 Offset, Uint64 Length, void *Buffer); +extern size_t VFS_ReadAt(int FD, Uint64 Offset, size_t Length, void *Buffer); /** * \brief Writes to a specific offset in the file * \param FD File handle returned by ::VFS_Open @@ -303,7 +303,7 @@ extern Uint64 VFS_ReadAt(int FD, Uint64 Offset, Uint64 Length, void *Buffer); * \param Buffer Source of written data * \return Number of bytes written */ -extern Uint64 VFS_WriteAt(int FD, Uint64 Offset, Uint64 Length, const void *Buffer); +extern size_t VFS_WriteAt(int FD, Uint64 Offset, size_t Length, const void *Buffer); /** * \brief Sends an IOCtl request to the driver diff --git a/KernelLand/Kernel/lib.c b/KernelLand/Kernel/lib.c index 68d2032f..36b877c3 100644 --- a/KernelLand/Kernel/lib.c +++ b/KernelLand/Kernel/lib.c @@ -124,7 +124,7 @@ int strpos8(const char *str, Uint32 Search) { // ASCII Range if(Search < 128) { - if(str[pos] == Search) return pos; + if(str[pos] == (char)Search) return pos; continue; } if(*(Uint8*)(str+pos) < 128) continue; @@ -387,7 +387,7 @@ int ModUtil_SetIdent(char *Dest, const char *Value) int Hex(char *Dest, size_t Size, const Uint8 *SourceData) { - int i; + size_t i; for( i = 0; i < Size; i ++ ) { sprintf(Dest + i*2, "%02x", SourceData[i]); @@ -400,8 +400,7 @@ int Hex(char *Dest, size_t Size, const Uint8 *SourceData) */ int UnHex(Uint8 *Dest, size_t DestSize, const char *SourceString) { - int i; - + size_t i; for( i = 0; i < DestSize*2; i += 2 ) { Uint8 val = 0; diff --git a/KernelLand/Kernel/vfs/dir.c b/KernelLand/Kernel/vfs/dir.c index 26f6f0f4..65218af0 100644 --- a/KernelLand/Kernel/vfs/dir.c +++ b/KernelLand/Kernel/vfs/dir.c @@ -163,7 +163,7 @@ int VFS_ReadDir(int FD, char *Dest) return 0; } - if(h->Node->Size != -1 && h->Position >= h->Node->Size) { + if(h->Node->Size != (Uint64)-1 && h->Position >= h->Node->Size) { //LEAVE('i', 0); return 0; } diff --git a/KernelLand/Kernel/vfs/io.c b/KernelLand/Kernel/vfs/io.c index 7379e3d2..dc55fe2a 100644 --- a/KernelLand/Kernel/vfs/io.c +++ b/KernelLand/Kernel/vfs/io.c @@ -4,18 +4,19 @@ */ #define DEBUG 0 #include -#include "vfs.h" -#include "vfs_int.h" +#include +#include +#include // === CODE === /** * \fn Uint64 VFS_Read(int FD, Uint64 Length, void *Buffer) * \brief Read data from a node (file) */ -Uint64 VFS_Read(int FD, Uint64 Length, void *Buffer) +size_t VFS_Read(int FD, size_t Length, void *Buffer) { tVFS_Handle *h; - Uint64 ret; + size_t ret; ENTER("iFD XLength pBuffer", FD, Length, Buffer); @@ -46,7 +47,7 @@ Uint64 VFS_Read(int FD, Uint64 Length, void *Buffer) } ret = h->Node->Type->Read(h->Node, h->Position, Length, Buffer); - if(ret == -1) LEAVE_RET('i', -1); + if(ret == (size_t)-1) LEAVE_RET('i', -1); h->Position += ret; LEAVE('X', ret); @@ -57,10 +58,10 @@ Uint64 VFS_Read(int FD, Uint64 Length, void *Buffer) * \fn Uint64 VFS_ReadAt(int FD, Uint64 Offset, Uint64 Length, void *Buffer) * \brief Read data from a given offset (atomic) */ -Uint64 VFS_ReadAt(int FD, Uint64 Offset, Uint64 Length, void *Buffer) +size_t VFS_ReadAt(int FD, Uint64 Offset, size_t Length, void *Buffer) { tVFS_Handle *h; - Uint64 ret; + size_t ret; h = VFS_GetHandle(FD); if(!h) return -1; @@ -80,7 +81,7 @@ Uint64 VFS_ReadAt(int FD, Uint64 Offset, Uint64 Length, void *Buffer) } ret = h->Node->Type->Read(h->Node, Offset, Length, Buffer); - if(ret == -1) return -1; + if(ret == (size_t)-1) return -1; return ret; } @@ -88,10 +89,10 @@ Uint64 VFS_ReadAt(int FD, Uint64 Offset, Uint64 Length, void *Buffer) * \fn Uint64 VFS_Write(int FD, Uint64 Length, const void *Buffer) * \brief Read data from a node (file) */ -Uint64 VFS_Write(int FD, Uint64 Length, const void *Buffer) +size_t VFS_Write(int FD, size_t Length, const void *Buffer) { tVFS_Handle *h; - Uint64 ret; + size_t ret; h = VFS_GetHandle(FD); if(!h) return -1; @@ -108,7 +109,7 @@ Uint64 VFS_Write(int FD, Uint64 Length, const void *Buffer) } ret = h->Node->Type->Write(h->Node, h->Position, Length, Buffer); - if(ret == -1) return -1; + if(ret == (size_t)-1) return -1; h->Position += ret; return ret; @@ -118,10 +119,10 @@ Uint64 VFS_Write(int FD, Uint64 Length, const void *Buffer) * \fn Uint64 VFS_WriteAt(int FD, Uint64 Offset, Uint64 Length, const void *Buffer) * \brief Write data to a file at a given offset */ -Uint64 VFS_WriteAt(int FD, Uint64 Offset, Uint64 Length, const void *Buffer) +size_t VFS_WriteAt(int FD, Uint64 Offset, size_t Length, const void *Buffer) { tVFS_Handle *h; - Uint64 ret; + size_t ret; h = VFS_GetHandle(FD); if(!h) return -1; @@ -137,7 +138,7 @@ Uint64 VFS_WriteAt(int FD, Uint64 Offset, Uint64 Length, const void *Buffer) return -1; } ret = h->Node->Type->Write(h->Node, Offset, Length, Buffer); - if(ret == -1) return -1; + if(ret == (size_t)-1) return -1; return ret; } @@ -180,7 +181,7 @@ int VFS_Seek(int FD, Sint64 Offset, int Whence) // Set relative to end of file if(Whence < 0) { - if( h->Node->Size == -1 ) return -1; + if( h->Node->Size == (Uint64)-1 ) return -1; h->Position = h->Node->Size - Offset; return 0; diff --git a/KernelLand/Kernel/vfs/main.c b/KernelLand/Kernel/vfs/main.c index 5ff0e7c2..38f7c808 100644 --- a/KernelLand/Kernel/vfs/main.c +++ b/KernelLand/Kernel/vfs/main.c @@ -27,7 +27,7 @@ void VFS_UpdateDriverFile(void); EXPORT(VFS_AddDriver); // === GLOBALS === -tVFS_Node NULLNode = {0}; +tVFS_Node NULLNode = {.Type=NULL}; tShortSpinlock slDriverListLock; tVFS_Driver *gVFS_Drivers = NULL; char *gsVFS_DriverFile = NULL; diff --git a/KernelLand/Modules/Filesystems/FAT/common.h b/KernelLand/Modules/Filesystems/FAT/common.h index 79513a96..b473bf73 100644 --- a/KernelLand/Modules/Filesystems/FAT/common.h +++ b/KernelLand/Modules/Filesystems/FAT/common.h @@ -46,7 +46,7 @@ struct sFAT_VolInfo Uint32 ClusterCount; //!< Total Cluster Count fat_bootsect bootsect; //!< Boot Sector tVFS_Node rootNode; //!< Root Node - int BytesPerCluster; + size_t BytesPerCluster; tMutex lNodeCache; tFAT_CachedNode *NodeCache; diff --git a/KernelLand/Modules/Storage/LVM/mbr.c b/KernelLand/Modules/Storage/LVM/mbr.c index c137a8a1..67fdbce0 100644 --- a/KernelLand/Modules/Storage/LVM/mbr.c +++ b/KernelLand/Modules/Storage/LVM/mbr.c @@ -76,7 +76,8 @@ int LVM_MBR_CountSubvolumes(tLVM_Vol *Volume, void *FirstSector) while(extendedLBA != 0) { extendedLBA = LVM_MBR_int_ReadExt(Volume, extendedLBA, &base, &len); - if( extendedLBA == -1 ) break; + if( extendedLBA == (Uint64)-1 ) + break; numPartitions ++; } LOG("numPartitions = %i", numPartitions); @@ -127,7 +128,8 @@ void LVM_MBR_PopulateSubvolumes(tLVM_Vol *Volume, void *FirstSector) while(extendedLBA != 0) { extendedLBA = LVM_MBR_int_ReadExt(Volume, extendedLBA, &base, &len); - if(extendedLBA == -1) break; + if(extendedLBA == (Uint64)-1) + break; LVM_int_SetSubvolume_Anon( Volume, j, base, len ); j ++ ; } diff --git a/Tools/DiskTool/src/actions.c b/Tools/DiskTool/src/actions.c index 665a5957..074aab99 100644 --- a/Tools/DiskTool/src/actions.c +++ b/Tools/DiskTool/src/actions.c @@ -84,8 +84,6 @@ int DiskTool_MountImage(const char *Identifier, const char *Path) // Translate path size_t tpath_len = DiskTool_int_TranslatePath(NULL, Path); - if(tpath_len == -1) - return -1; char tpath[tpath_len-1]; DiskTool_int_TranslatePath(tpath, Path); @@ -191,7 +189,7 @@ void DiskTool_LVM_Cleanup(void *Handle) int DiskTool_int_TranslateOpen(const char *File, int Flags) { size_t tpath_len = DiskTool_int_TranslatePath(NULL, File); - if(tpath_len == -1) + if(tpath_len == 0) return -1; char tpath[tpath_len-1]; DiskTool_int_TranslatePath(tpath, File);