2 * Acess2 Logical Volume Manager
3 * - By John Hodge (thePowersGang)
12 int LVM_int_VFSReadEmul(void *Arg, Uint64 BlockStart, size_t BlockCount, void *Dest);
13 int LVM_int_VFSWriteEmul(void *Arg, Uint64 BlockStart, size_t BlockCount, const void *Source);
16 // --------------------------------------------------------------------
17 // Managment / Initialisation
18 // --------------------------------------------------------------------
19 int LVM_AddVolumeVFS(const char *Name, int FD)
21 // Assuming 512-byte blocks, not a good idea
22 // return LVM_AddVolume(Name, (void*)(Uint)FD, 512, LVM_int_VFSReadEmul, LVM_int_VFSWriteEmul);
26 int LVM_AddVolume(const tLVM_VolType *Type, const char *Name, void *Ptr, size_t BlockSize, size_t BlockCount)
33 dummy_vol.Type = Type;
35 dummy_vol.BlockCount = BlockCount;
36 dummy_vol.BlockSize = BlockSize;
38 // Read the first block of the volume
39 first_block = malloc(BlockSize);
40 Type->Read(Ptr, 0, 1, first_block);
43 // TODO: Determine format
46 // Type->CountSubvolumes
47 dummy_vol.nSubVolumes = fmt->CountSubvolumes(&dummy_vol, first_block);
49 // Create real volume descriptor
50 // TODO: If this needs to be rescanned later, having the subvolume list separate might be an idea
51 real_vol = malloc( sizeof(tLVM_Vol) + strlen(Name) + 1 + sizeof(tLVM_SubVolume*) * dummy_vol.nSubVolumes );
52 real_vol->Next = NULL;
53 real_vol->Type = Type;
55 real_vol->BlockCount = BlockCount;
56 real_vol->nSubVolumes = dummy_vol.nSubVolumes;
57 real_vol->SubVolumes = (void*)( real_vol->Name + strlen(Name) + 1 );
58 real_vol->BlockSize = BlockSize;
59 strcpy(real_vol->Name, Name);
60 memset(real_vol->SubVolumes, 0, sizeof(tLVM_SubVolume*) * real_vol->nSubVolumes);
62 memset(&real_vol->DirNode, 0, sizeof(tVFS_Node));
63 real_vol->DirNode.Type = &gLVM_VolNodeType;
64 real_vol->DirNode.ImplPtr = real_vol;
65 real_vol->DirNode.Flags = VFS_FFLAG_DIRECTORY;
66 real_vol->DirNode.Size = -1;
67 memset(&real_vol->VolNode, 0, sizeof(tVFS_Node));
68 real_vol->VolNode.Type = &gLVM_VolNodeType;
69 real_vol->VolNode.ImplPtr = real_vol;
70 real_vol->VolNode.Size = BlockCount * BlockSize;
72 // Type->PopulateSubvolumes
73 fmt->PopulateSubvolumes(real_vol, first_block);
77 gpLVM_LastVolume->Next = real_vol;
78 gpLVM_LastVolume = real_vol;
83 void LVM_int_SetSubvolume_Anon(tLVM_Vol *Volume, int Index, Uint64 FirstBlock, Uint64 BlockCount)
88 if( Index < 0 || Index >= Volume->nSubVolumes ) {
89 Log_Warning("LVM", "SV ID is out of range (0 < %i < %i)",
90 Index, Volume->nSubVolumes);
94 if( Volume->SubVolumes[Index] ) {
95 Log_Warning("LVM", "Attempt to set SV %i of %p twice", Index, Volume);
99 namelen = snprintf(NULL, 0, "%i", Index);
101 sv = malloc( sizeof(tLVM_SubVolume) + namelen + 1 );
106 Volume->SubVolumes[Index] = sv;
109 sprintf(sv->Name, "%i", Index);
110 sv->FirstBlock = FirstBlock;
111 sv->BlockCount = BlockCount;
112 memset(&sv->Node, 0, sizeof(tVFS_Node));
114 sv->Node.ImplPtr = sv;
115 sv->Node.Type = &gLVM_SubVolNodeType;
116 sv->Node.Size = BlockCount * Volume->BlockSize;
118 Log_Log("LVM", "Partition %s/%s - 0x%llx+0x%llx blocks",
119 Volume->Name, sv->Name, FirstBlock, BlockCount);
122 // --------------------------------------------------------------------
124 // --------------------------------------------------------------------
125 size_t LVM_int_ReadVolume(tLVM_Vol *Volume, Uint64 BlockNum, size_t BlockCount, void *Dest)
127 return Volume->Type->Read(Volume->Ptr, BlockNum, BlockCount, Dest);
130 size_t LVM_int_WriteVolume(tLVM_Vol *Volume, Uint64 BlockNum, size_t BlockCount, const void *Src)
132 return Volume->Type->Write(Volume->Ptr, BlockNum, BlockCount, Src);
135 int LVM_int_VFSReadEmul(void *Arg, Uint64 BlockStart, size_t BlockCount, void *Dest)
140 blocksize = 512; // TODO: Don't assume
142 rv = VFS_ReadAt( (int)(Uint)Arg, BlockStart * blocksize, BlockCount * blocksize, Dest );
147 int LVM_int_VFSWriteEmul(void *Arg, Uint64 BlockStart, size_t BlockCount, const void *Source)
152 blocksize = 512; // TODO: Don't assume
154 rv = VFS_WriteAt( (int)(Uint)Arg, BlockStart * blocksize, BlockCount * blocksize, Source );