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_SubVol_Read(tVFS_Node *Node, off_t Offset, size_t Length, void *Buffer);
25 size_t LVM_SubVol_Write(tVFS_Node *Node, off_t Offset, size_t Length, const void *Buffer);
27 Uint LVM_int_DrvUtil_ReadBlock(Uint64 Address, Uint Count, void *Buffer, void *Argument);
28 Uint LVM_int_DrvUtil_WriteBlock(Uint64 Address, Uint Count, const void *Buffer, void *Argument);
31 MODULE_DEFINE(0, VERSION, LVM, LVM_Initialise, LVM_Cleanup, NULL);
32 tVFS_NodeType gLVM_RootNodeType = {
33 .ReadDir = LVM_Root_ReadDir,
34 .FindDir = LVM_Root_FindDir
36 tVFS_NodeType gLVM_VolNodeType = {
37 .ReadDir = LVM_Vol_ReadDir,
38 .FindDir = LVM_Vol_FindDir
40 tVFS_NodeType gLVM_SubVolNodeType = {
41 .Read = LVM_SubVol_Read,
42 .Write = LVM_SubVol_Write
44 tDevFS_Driver gLVM_DevFS = {
46 {.Flags = VFS_FFLAG_DIRECTORY, .Type = &gLVM_RootNodeType}
49 tLVM_Vol *gpLVM_FirstVolume;
50 tLVM_Vol *gpLVM_LastVolume = (void*)&gpLVM_FirstVolume;
53 int LVM_Initialise(char **Arguments)
55 DevFS_AddDevice( &gLVM_DevFS );
59 void LVM_Cleanup(void)
64 // --------------------------------------------------------------------
66 // --------------------------------------------------------------------
67 char *LVM_Root_ReadDir(tVFS_Node *Node, int ID)
71 if( ID < 0 ) return NULL;
73 for( vol = gpLVM_FirstVolume; vol && ID --; vol = vol->Next );
76 return strdup(vol->Name);
80 tVFS_Node *LVM_Root_FindDir(tVFS_Node *Node, const char *Name)
83 for( vol = gpLVM_FirstVolume; vol; vol = vol->Next )
85 if( strcmp(vol->Name, Name) == 0 )
93 char *LVM_Vol_ReadDir(tVFS_Node *Node, int ID)
95 tLVM_Vol *vol = Node->ImplPtr;
97 if( ID < 0 || ID >= vol->nSubVolumes )
100 return strdup( vol->SubVolumes[ID]->Name );
102 tVFS_Node *LVM_Vol_FindDir(tVFS_Node *Node, const char *Name)
104 tLVM_Vol *vol = Node->ImplPtr;
106 for( int i = 0; i < vol->nSubVolumes; i ++ )
108 if( strcmp(vol->SubVolumes[i]->Name, Name) == 0 )
110 return &vol->SubVolumes[i]->Node;
117 size_t LVM_SubVol_Read(tVFS_Node *Node, off_t Offset, size_t Length, void *Buffer)
119 tLVM_SubVolume *sv = Node->ImplPtr;
120 Uint64 byte_size = sv->BlockCount * sv->Vol->BlockSize;
122 if( Offset > byte_size )
124 if( Length > byte_size )
126 if( Offset + Length > byte_size )
127 Length = byte_size - Offset;
129 Offset += sv->FirstBlock * sv->Vol->BlockSize;
131 return DrvUtil_ReadBlock(
132 Offset, Length, Buffer,
133 LVM_int_DrvUtil_ReadBlock, sv->Vol->BlockSize, sv->Vol
136 size_t LVM_SubVol_Write(tVFS_Node *Node, off_t Offset, size_t Length, const void *Buffer)
138 tLVM_SubVolume *sv = Node->ImplPtr;
139 Uint64 byte_size = sv->BlockCount * sv->Vol->BlockSize;
141 if( Offset > byte_size )
143 if( Length > byte_size )
145 if( Offset + Length > byte_size )
146 Length = byte_size - Offset;
148 Offset += sv->FirstBlock * sv->Vol->BlockSize;
150 return DrvUtil_WriteBlock(
151 Offset, Length, Buffer,
152 LVM_int_DrvUtil_ReadBlock, LVM_int_DrvUtil_WriteBlock,
153 sv->Vol->BlockSize, sv->Vol
157 Uint LVM_int_DrvUtil_ReadBlock(Uint64 Address, Uint Count, void *Buffer, void *Argument)
159 return LVM_int_ReadVolume( Argument, Address, Count, Buffer );
162 Uint LVM_int_DrvUtil_WriteBlock(Uint64 Address, Uint Count, const void *Buffer, void *Argument)
164 return LVM_int_WriteVolume( Argument, Address, Count, Buffer );