aac987e283684933a4fe4e5d981436f6b378d3c3
[tpg/acess2.git] / KernelLand / Modules / Storage / LVM / volumes.c
1 /*
2  * Acess2 Logical Volume Manager
3  * - By John Hodge (thePowersGang)
4  *
5  * volumes.c
6  * - Volume management
7  */
8 #include "lvm_int.h"
9
10 // === PROTOTYPES ===
11
12 // === CODE ===
13 // --------------------------------------------------------------------
14 // Managment / Initialisation
15 // --------------------------------------------------------------------
16 int LVM_AddVolume(const char *Name, int FD)
17 {
18         // Make dummy volume descriptor (for the read code)
19
20         // Determine Type
21
22         // Type->CountSubvolumes
23         
24         // Create real volume descriptor
25
26         // Type->PopulateSubvolumes
27
28         // Add to volume list
29
30         return 0;
31 }
32
33 void LVM_int_SetSubvolume_Anon(tLVM_Vol *Volume, int Index, Uint64 FirstBlock, Uint64 BlockCount)
34 {
35         tLVM_SubVolume  *sv;
36          int    namelen;
37
38         if( Index < 0 || Index >= Volume->nSubVolumes ) {
39                 Log_Warning("LVM", "SV ID is out of range (0 < %i < %i)",
40                         Index, Volume->nSubVolumes);
41                 return ;
42         }
43
44         if( Volume->SubVolumes[Index] ) {
45                 Log_Warning("LVM", "Attempt to set SV %i of %p twice", Index, Volume);
46                 return ;
47         }
48         
49         namelen = snprintf(NULL, 0, "%i", Index);
50
51         sv = malloc( sizeof(tLVM_SubVolume) + namelen + 1 );
52         if(!sv) {
53                 // Oh, f*ck
54                 return ;
55         }
56         Volume->SubVolumes[Index] = sv; 
57
58         sv->Vol = Volume;
59         sprintf(sv->Name, "%i", Index);
60         sv->FirstBlock = FirstBlock;
61         sv->BlockCount = BlockCount;
62         memset(&sv->Node, 0, sizeof(tVFS_Node));
63         
64         sv->Node.ImplPtr = sv;
65         sv->Node.Type = &gLVM_SubVolNodeType;
66 }
67
68 // --------------------------------------------------------------------
69 // IO
70 // --------------------------------------------------------------------
71 size_t LVM_int_ReadVolume(tLVM_Vol *Volume, Uint64 BlockNum, size_t BlockCount, void *Dest)
72 {
73         size_t  rv;
74         rv = VFS_ReadAt(
75                 Volume->BackingDescriptor,
76                 BlockNum * Volume->BlockSize,
77                 BlockCount * Volume->BlockSize,
78                 Dest
79                 );
80         return rv / Volume->BlockSize;
81 }
82
83 size_t LVM_int_WriteVolume(tLVM_Vol *Volume, Uint64 BlockNum, size_t BlockCount, const void *Src)
84 {
85         size_t  rv;
86         rv = VFS_WriteAt(
87                 Volume->BackingDescriptor,
88                 BlockNum * Volume->BlockSize,
89                 BlockCount * Volume->BlockSize,
90                 Src
91                 );
92         return rv / Volume->BlockSize;
93 }
94

UCC git Repository :: git.ucc.asn.au