2 * Acess2 Logical Volume Manager
3 * - By John Hodge (thePowersGang)
6 * - LVM Core definitions
9 #define VERSION VER2(0,1)
13 #include <api_drv_disk.h>
17 int LVM_Initialise(char **Arguments);
18 void LVM_Cleanup(void);
20 char *LVM_Root_ReadDir(tVFS_Node *Node, int ID);
21 tVFS_Node *LVM_Root_FindDir(tVFS_Node *Node, const char *Name);
22 char *LVM_Vol_ReadDir(tVFS_Node *Node, int ID);
23 tVFS_Node *LVM_Vol_FindDir(tVFS_Node *Node, const char *Name);
24 size_t LVM_Vol_Read(tVFS_Node *Node, off_t Offset, size_t Length, void *Buffer);
25 size_t LVM_Vol_Write(tVFS_Node *Node, off_t Offset, size_t Length, const void *Buffer);
26 size_t LVM_SubVol_Read(tVFS_Node *Node, off_t Offset, size_t Length, void *Buffer);
27 size_t LVM_SubVol_Write(tVFS_Node *Node, off_t Offset, size_t Length, const void *Buffer);
29 Uint LVM_int_DrvUtil_ReadBlock(Uint64 Address, Uint Count, void *Buffer, void *Argument);
30 Uint LVM_int_DrvUtil_WriteBlock(Uint64 Address, Uint Count, const void *Buffer, void *Argument);
33 MODULE_DEFINE(0, VERSION, LVM, LVM_Initialise, LVM_Cleanup, NULL);
34 tVFS_NodeType gLVM_RootNodeType = {
35 .ReadDir = LVM_Root_ReadDir,
36 .FindDir = LVM_Root_FindDir
38 tVFS_NodeType gLVM_VolNodeType = {
39 .ReadDir = LVM_Vol_ReadDir,
40 .FindDir = LVM_Vol_FindDir,
42 .Write = LVM_Vol_Write
44 tVFS_NodeType gLVM_SubVolNodeType = {
45 .Read = LVM_SubVol_Read,
46 .Write = LVM_SubVol_Write
48 tDevFS_Driver gLVM_DevFS = {
50 {.Flags = VFS_FFLAG_DIRECTORY, .Type = &gLVM_RootNodeType, .Size = -1}
53 tLVM_Vol *gpLVM_FirstVolume;
54 tLVM_Vol *gpLVM_LastVolume = (void*)&gpLVM_FirstVolume;
57 int LVM_Initialise(char **Arguments)
59 DevFS_AddDevice( &gLVM_DevFS );
63 void LVM_Cleanup(void)
68 // --------------------------------------------------------------------
70 // --------------------------------------------------------------------
71 char *LVM_Root_ReadDir(tVFS_Node *Node, int ID)
75 if( ID < 0 ) return NULL;
77 for( vol = gpLVM_FirstVolume; vol && ID --; vol = vol->Next );
80 return strdup(vol->Name);
84 tVFS_Node *LVM_Root_FindDir(tVFS_Node *Node, const char *Name)
87 for( vol = gpLVM_FirstVolume; vol; vol = vol->Next )
89 if( strcmp(vol->Name, Name) == 0 )
97 char *LVM_Vol_ReadDir(tVFS_Node *Node, int ID)
99 tLVM_Vol *vol = Node->ImplPtr;
101 if( ID < 0 || ID >= vol->nSubVolumes+1 )
105 return strdup("ROOT");
107 return strdup( vol->SubVolumes[ID-1]->Name );
109 tVFS_Node *LVM_Vol_FindDir(tVFS_Node *Node, const char *Name)
111 tLVM_Vol *vol = Node->ImplPtr;
113 if( strcmp("ROOT", Name) == 0 )
114 return &vol->VolNode;
116 for( int i = 0; i < vol->nSubVolumes; i ++ )
118 if( strcmp(vol->SubVolumes[i]->Name, Name) == 0 )
120 return &vol->SubVolumes[i]->Node;
127 size_t LVM_Vol_Read(tVFS_Node *Node, off_t Offset, size_t Length, void *Buffer)
129 tLVM_Vol *vol = Node->ImplPtr;
130 Uint64 byte_size = vol->BlockCount * vol->BlockSize;
132 if( Offset > byte_size )
134 if( Length > byte_size )
136 if( Offset + Length > byte_size )
137 Length = byte_size - Offset;
139 return DrvUtil_ReadBlock(
140 Offset, Length, Buffer,
141 LVM_int_DrvUtil_ReadBlock, vol->BlockSize, vol
145 size_t LVM_Vol_Write(tVFS_Node *Node, off_t Offset, size_t Length, const void *Buffer)
150 size_t LVM_SubVol_Read(tVFS_Node *Node, off_t Offset, size_t Length, void *Buffer)
152 tLVM_SubVolume *sv = Node->ImplPtr;
153 Uint64 byte_size = sv->BlockCount * sv->Vol->BlockSize;
155 if( Offset > byte_size )
157 if( Length > byte_size )
159 if( Offset + Length > byte_size )
160 Length = byte_size - Offset;
162 LOG("Reading (0x%llx+0x%llx)+0x%x to %p",
163 (Uint64)(sv->FirstBlock * sv->Vol->BlockSize), Offset,
167 Offset += sv->FirstBlock * sv->Vol->BlockSize;
169 return DrvUtil_ReadBlock(
170 Offset, Length, Buffer,
171 LVM_int_DrvUtil_ReadBlock, sv->Vol->BlockSize, sv->Vol
174 size_t LVM_SubVol_Write(tVFS_Node *Node, off_t Offset, size_t Length, const void *Buffer)
176 tLVM_SubVolume *sv = Node->ImplPtr;
177 Uint64 byte_size = sv->BlockCount * sv->Vol->BlockSize;
179 if( Offset > byte_size )
181 if( Length > byte_size )
183 if( Offset + Length > byte_size )
184 Length = byte_size - Offset;
186 Offset += sv->FirstBlock * sv->Vol->BlockSize;
188 return DrvUtil_WriteBlock(
189 Offset, Length, Buffer,
190 LVM_int_DrvUtil_ReadBlock, LVM_int_DrvUtil_WriteBlock,
191 sv->Vol->BlockSize, sv->Vol
195 Uint LVM_int_DrvUtil_ReadBlock(Uint64 Address, Uint Count, void *Buffer, void *Argument)
197 return LVM_int_ReadVolume( Argument, Address, Count, Buffer );
200 Uint LVM_int_DrvUtil_WriteBlock(Uint64 Address, Uint Count, const void *Buffer, void *Argument)
202 return LVM_int_WriteVolume( Argument, Address, Count, Buffer );