* volumes.c
* - Volume management
*/
+#define DEBUG 1
#include "lvm_int.h"
// === PROTOTYPES ===
int LVM_AddVolumeVFS(const char *Name, int FD)
{
// Assuming 512-byte blocks, not a good idea
- return LVM_AddVolume(Name, (void*)(Uint)FD, 512, LVM_int_VFSReadEmul, LVM_int_VFSWriteEmul);
+// return LVM_AddVolume(Name, (void*)(Uint)FD, 512, LVM_int_VFSReadEmul, LVM_int_VFSWriteEmul);
+ return 0;
}
-int LVM_AddVolume(const char *Name, void *Ptr, size_t BlockSize, tLVM_ReadFcn Read, tLVM_WriteFcn Write)
+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 *type;
+ tLVM_Format *fmt;
void *first_block;
+ dummy_vol.Type = Type;
dummy_vol.Ptr = Ptr;
- dummy_vol.Read = Read;
- dummy_vol.Write = Write;
+ dummy_vol.BlockCount = BlockCount;
dummy_vol.BlockSize = BlockSize;
// Read the first block of the volume
first_block = malloc(BlockSize);
- Read(Ptr, 0, 1, first_block);
+ Type->Read(Ptr, 0, 1, first_block);
- // Determine Type
- // TODO: Determine type
- type = &gLVM_MBRType;
+ // Determine Format
+ // TODO: Determine format
+ fmt = &gLVM_MBRType;
// Type->CountSubvolumes
- dummy_vol.nSubVolumes = type->CountSubvolumes(&dummy_vol, first_block);
+ dummy_vol.nSubVolumes = fmt->CountSubvolumes(&dummy_vol, first_block);
// 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->Read = Read;
- real_vol->Write = Write;
real_vol->BlockSize = BlockSize;
+ real_vol->BlockCount = BlockCount;
real_vol->nSubVolumes = dummy_vol.nSubVolumes;
real_vol->SubVolumes = (void*)( real_vol->Name + strlen(Name) + 1 );
strcpy(real_vol->Name, Name);
real_vol->DirNode.Type = &gLVM_VolNodeType;
real_vol->DirNode.ImplPtr = real_vol;
real_vol->DirNode.Flags = VFS_FFLAG_DIRECTORY;
+ real_vol->DirNode.Size = -1;
memset(&real_vol->VolNode, 0, sizeof(tVFS_Node));
real_vol->VolNode.Type = &gLVM_VolNodeType;
real_vol->VolNode.ImplPtr = real_vol;
- real_vol->VolNode.Flags = VFS_FFLAG_DIRECTORY;
+ real_vol->VolNode.Size = BlockCount * BlockSize;
// Type->PopulateSubvolumes
- type->PopulateSubvolumes(real_vol, first_block);
+ fmt->PopulateSubvolumes(real_vol, first_block);
free(first_block);
// Add to volume list
sv->Node.ImplPtr = sv;
sv->Node.Type = &gLVM_SubVolNodeType;
+ sv->Node.Size = BlockCount * Volume->BlockSize;
+
+ Log_Log("LVM", "Partition %s/%s - 0x%llx+0x%llx blocks",
+ Volume->Name, sv->Name, FirstBlock, BlockCount);
}
// --------------------------------------------------------------------
// --------------------------------------------------------------------
size_t LVM_int_ReadVolume(tLVM_Vol *Volume, Uint64 BlockNum, size_t BlockCount, void *Dest)
{
- return Volume->Read(Volume->Ptr, BlockNum, BlockCount, Dest);
+ return Volume->Type->Read(Volume->Ptr, BlockNum, BlockCount, Dest);
}
size_t LVM_int_WriteVolume(tLVM_Vol *Volume, Uint64 BlockNum, size_t BlockCount, const void *Src)
{
- return Volume->Write(Volume->Ptr, BlockNum, BlockCount, Src);
+ return Volume->Type->Write(Volume->Ptr, BlockNum, BlockCount, Src);
}
int LVM_int_VFSReadEmul(void *Arg, Uint64 BlockStart, size_t BlockCount, void *Dest)