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->Type = Type;
54 real_vol->BlockCount = BlockCount;
55 real_vol->nSubVolumes = dummy_vol.nSubVolumes;
56 real_vol->SubVolumes = (void*)( real_vol->Name + strlen(Name) + 1 );
57 strcpy(real_vol->Name, Name);
58 memset(real_vol->SubVolumes, 0, sizeof(tLVM_SubVolume*) * real_vol->nSubVolumes);
60 memset(&real_vol->DirNode, 0, sizeof(tVFS_Node));
61 real_vol->DirNode.Type = &gLVM_VolNodeType;
62 real_vol->DirNode.ImplPtr = real_vol;
63 real_vol->DirNode.Flags = VFS_FFLAG_DIRECTORY;
64 real_vol->DirNode.Size = -1;
65 memset(&real_vol->VolNode, 0, sizeof(tVFS_Node));
66 real_vol->VolNode.Type = &gLVM_VolNodeType;
67 real_vol->VolNode.ImplPtr = real_vol;
68 real_vol->VolNode.Size = BlockCount * BlockSize;
70 // Type->PopulateSubvolumes
71 fmt->PopulateSubvolumes(real_vol, first_block);
75 gpLVM_LastVolume->Next = real_vol;
76 gpLVM_LastVolume = real_vol;
81 void LVM_int_SetSubvolume_Anon(tLVM_Vol *Volume, int Index, Uint64 FirstBlock, Uint64 BlockCount)
86 if( Index < 0 || Index >= Volume->nSubVolumes ) {
87 Log_Warning("LVM", "SV ID is out of range (0 < %i < %i)",
88 Index, Volume->nSubVolumes);
92 if( Volume->SubVolumes[Index] ) {
93 Log_Warning("LVM", "Attempt to set SV %i of %p twice", Index, Volume);
97 namelen = snprintf(NULL, 0, "%i", Index);
99 sv = malloc( sizeof(tLVM_SubVolume) + namelen + 1 );
104 Volume->SubVolumes[Index] = sv;
107 sprintf(sv->Name, "%i", Index);
108 sv->FirstBlock = FirstBlock;
109 sv->BlockCount = BlockCount;
110 memset(&sv->Node, 0, sizeof(tVFS_Node));
112 sv->Node.ImplPtr = sv;
113 sv->Node.Type = &gLVM_SubVolNodeType;
114 sv->Node.Size = BlockCount * Volume->BlockSize;
116 Log_Log("LVM", "Partition %s/%s - 0x%llx+0x%llx blocks",
117 Volume->Name, sv->Name, FirstBlock, BlockCount);
120 // --------------------------------------------------------------------
122 // --------------------------------------------------------------------
123 size_t LVM_int_ReadVolume(tLVM_Vol *Volume, Uint64 BlockNum, size_t BlockCount, void *Dest)
125 return Volume->Type->Read(Volume->Ptr, BlockNum, BlockCount, Dest);
128 size_t LVM_int_WriteVolume(tLVM_Vol *Volume, Uint64 BlockNum, size_t BlockCount, const void *Src)
130 return Volume->Type->Write(Volume->Ptr, BlockNum, BlockCount, Src);
133 int LVM_int_VFSReadEmul(void *Arg, Uint64 BlockStart, size_t BlockCount, void *Dest)
138 blocksize = 512; // TODO: Don't assume
140 rv = VFS_ReadAt( (int)(Uint)Arg, BlockStart * blocksize, BlockCount * blocksize, Dest );
145 int LVM_int_VFSWriteEmul(void *Arg, Uint64 BlockStart, size_t BlockCount, const void *Source)
150 blocksize = 512; // TODO: Don't assume
152 rv = VFS_WriteAt( (int)(Uint)Arg, BlockStart * blocksize, BlockCount * blocksize, Source );