From: John Hodge Date: Tue, 18 Jun 2013 14:32:43 +0000 (+0800) Subject: Modules/LVM - Added handle return to LVM volume creation X-Git-Tag: rel0.15~433 X-Git-Url: https://git.ucc.asn.au/?a=commitdiff_plain;h=0a2505c2daeb54fddb569516d72aa6d606fa0bfd;p=tpg%2Facess2.git Modules/LVM - Added handle return to LVM volume creation --- diff --git a/KernelLand/Modules/Storage/LVM/include/lvm.h b/KernelLand/Modules/Storage/LVM/include/lvm.h index c106f771..804843b5 100644 --- a/KernelLand/Modules/Storage/LVM/include/lvm.h +++ b/KernelLand/Modules/Storage/LVM/include/lvm.h @@ -22,7 +22,8 @@ struct sLVM_VolType }; -extern int LVM_AddVolume(const tLVM_VolType *Type, const char *Name, void *Ptr, size_t BlockSize, size_t BlockCount); +extern void *LVM_AddVolume(const tLVM_VolType *Type, const char *Name, void *Ptr, size_t BlockSize, size_t BlockCount); +extern void LVM_DelVolume(void *Handle); #endif diff --git a/KernelLand/Modules/Storage/LVM/volumes.c b/KernelLand/Modules/Storage/LVM/volumes.c index cf1a60d1..d7091bbd 100644 --- a/KernelLand/Modules/Storage/LVM/volumes.c +++ b/KernelLand/Modules/Storage/LVM/volumes.c @@ -23,17 +23,15 @@ int LVM_AddVolumeVFS(const char *Name, int FD) return 0; } -int LVM_AddVolume(const tLVM_VolType *Type, const char *Name, void *Ptr, size_t BlockSize, size_t BlockCount) +void *LVM_AddVolume(const tLVM_VolType *Type, const char *Name, void *Ptr, size_t BlockSize, size_t BlockCount) { tLVM_Vol dummy_vol; - tLVM_Vol *real_vol; tLVM_Format *fmt; - void *first_block; if( BlockCount == 0 || BlockSize == 0 ) { Log_Error("LVM", "BlockSize(0x%x)/BlockCount(0x%x) invalid in LVM_AddVolume", BlockSize, BlockCount); - return 1; + return NULL; } dummy_vol.Type = Type; @@ -42,10 +40,10 @@ int LVM_AddVolume(const tLVM_VolType *Type, const char *Name, void *Ptr, size_t dummy_vol.BlockSize = BlockSize; // Read the first block of the volume - first_block = malloc(BlockSize); + void *first_block = malloc(BlockSize); if( !first_block ) { - Log_Error("VLM", "LVM_AddVolume - malloc error on %i bytes", BlockSize); - return -1; + Log_Error("LVM", "LVM_AddVolume - malloc error on %i bytes", BlockSize); + return NULL; } Type->Read(Ptr, 0, 1, first_block); @@ -58,7 +56,13 @@ int LVM_AddVolume(const tLVM_VolType *Type, const char *Name, void *Ptr, size_t // Create real volume descriptor // TODO: If this needs to be rescanned later, having the subvolume list separate might be an idea - real_vol = malloc( sizeof(tLVM_Vol) + strlen(Name) + 1 + sizeof(tLVM_SubVolume*) * dummy_vol.nSubVolumes ); + size_t allocsize = sizeof(tLVM_Vol) + strlen(Name) + 1 + sizeof(tLVM_SubVolume*) * dummy_vol.nSubVolumes; + tLVM_Vol *real_vol = malloc( allocsize ); + if( !real_vol ) { + Log_Error("LVM", "LVM_AddVolume - malloc error on %i bytes", allocsize); + free(first_block); + return NULL; + } real_vol->Next = NULL; real_vol->Type = Type; real_vol->Ptr = Ptr; @@ -88,7 +92,7 @@ int LVM_AddVolume(const tLVM_VolType *Type, const char *Name, void *Ptr, size_t gpLVM_LastVolume->Next = real_vol; gpLVM_LastVolume = real_vol; - return 0; + return real_vol; } void LVM_int_SetSubvolume_Anon(tLVM_Vol *Volume, int Index, Uint64 FirstBlock, Uint64 BlockCount)