Merge branch 'master' of git://localhost/acess2
[tpg/acess2.git] / KernelLand / Modules / Storage / LVM / volumes.c
index 3505498..cf1a60d 100644 (file)
@@ -23,23 +23,31 @@ int LVM_AddVolumeVFS(const char *Name, int FD)
        return 0;
 }
 
-int LVM_AddVolume(const tLVM_VolType *Type, const char *Name, void *Ptr, size_t BlockCount)
+int 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;
+       }
+
        dummy_vol.Type = Type;
        dummy_vol.Ptr = Ptr;
        dummy_vol.BlockCount = BlockCount;
+       dummy_vol.BlockSize = BlockSize;
 
        // Read the first block of the volume   
-       LOG("Type->BlockSize = %i", Type->BlockSize);
-       first_block = malloc(Type->BlockSize);
-       LOG("first_block = %p", first_block);
+       first_block = malloc(BlockSize);
+       if( !first_block ) {
+               Log_Error("VLM", "LVM_AddVolume - malloc error on %i bytes", BlockSize);
+               return -1;
+       }
        Type->Read(Ptr, 0, 1, first_block);
-       LOG("first block read");
        
        // Determine Format
        // TODO: Determine format
@@ -51,11 +59,14 @@ 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 );
+       real_vol->Next = NULL;
        real_vol->Type = Type;
        real_vol->Ptr = Ptr;
+       real_vol->BlockSize = BlockSize;
        real_vol->BlockCount = BlockCount;
        real_vol->nSubVolumes = dummy_vol.nSubVolumes;
        real_vol->SubVolumes = (void*)( real_vol->Name + strlen(Name) + 1 );
+       real_vol->BlockSize = BlockSize;
        strcpy(real_vol->Name, Name);
        memset(real_vol->SubVolumes, 0, sizeof(tLVM_SubVolume*) * real_vol->nSubVolumes);
        // - VFS Nodes
@@ -67,7 +78,7 @@ int LVM_AddVolume(const tLVM_VolType *Type, const char *Name, void *Ptr, size_t
        memset(&real_vol->VolNode, 0, sizeof(tVFS_Node));
        real_vol->VolNode.Type = &gLVM_VolNodeType;
        real_vol->VolNode.ImplPtr = real_vol;
-       real_vol->VolNode.Size = BlockCount * Type->BlockSize;
+       real_vol->VolNode.Size = BlockCount * BlockSize;
 
        // Type->PopulateSubvolumes
        fmt->PopulateSubvolumes(real_vol, first_block);
@@ -113,7 +124,7 @@ void LVM_int_SetSubvolume_Anon(tLVM_Vol *Volume, int Index, Uint64 FirstBlock, U
        
        sv->Node.ImplPtr = sv;
        sv->Node.Type = &gLVM_SubVolNodeType;
-       sv->Node.Size = BlockCount * Volume->Type->BlockSize;
+       sv->Node.Size = BlockCount * Volume->BlockSize;
        
        Log_Log("LVM", "Partition %s/%s - 0x%llx+0x%llx blocks",
                Volume->Name, sv->Name, FirstBlock, BlockCount);

UCC git Repository :: git.ucc.asn.au