#ifndef _APPLELVMVOLUME_H
#define _APPLELVMVOLUME_H
#define kAppleLVMVolumeMagic "AppleLVMVolume"
#define kAppleLVMVolumeNextMagic "AppleLVMVolumeNext"
#define kAppleLVMVolumeFreeMagic "AppleLVMVolumeFree"
#define kAppleLVMVolumeOnDiskMinSize 0x1000 // 4K
typedef struct AppleLVMVolumeOnDisk
{
char lvMagic[32]; UInt32 lvHeaderSize; UInt32 lvExtentsStart; UInt32 lvExtentsCount; char reserved[20]; char plist[];
} AppleLVMVolumeOnDisk;
#define AppleLVMVolumeOnDiskSanityCheck() assert(sizeof(AppleLVMVolumeOnDisk) == 64);
#define ByteSwapLVMVolumeHeader(header) \
{ \
(header)->lvHeaderSize = OSSwapBigToHostInt32((header)->lvHeaderSize); \
(header)->lvExtentsStart = OSSwapBigToHostInt32((header)->lvExtentsStart); \
(header)->lvExtentsCount = OSSwapBigToHostInt32((header)->lvExtentsCount); \
}
#ifdef KERNEL
#define kAppleLVMSkipListSize 4 // keep even for alignment
typedef struct AppleLVMLogicalExtent
{
AppleLVMLogicalExtent * skip[kAppleLVMSkipListSize]; AppleLVMLogicalExtent * lvgNext; UInt64 lvExtentVolumeOffset; UInt64 lvExtentSize;
UInt64 lvExtentGroupOffset; UInt64 lvExtentMemberOffset; UInt32 lvMemberIndex; } AppleLVMLogicalExtent;
enum {
kLVMTypeConcat = 0x1,
kLVMTypeStripe = 0x2,
kLVMTypeMirror = 0x4,
kLVMTypeIsAVolume = 0x7,
kLVMTypeSnapRO = 0x10,
kLVMTypeSnapRW = 0x20,
kLVMTypeIsASnapShot = 0x30,
kLVMTypeBitMap = 0x40,
kLVMTypeMaster = 0x80
};
class AppleLVMGroup;
class AppleLVMVolume : public IOMedia
{
OSDeclareDefaultStructors(AppleLVMVolume)
protected:
UInt32 lvIndex; OSString * lvUUID;
UInt32 lvSequenceNumber; UInt64 lvClaimedSize; UInt64 lvCalculatedSize; UInt32 lvTypeID;
UInt64 lvEntryOffset;
UInt32 lvEntrySize;
OSDictionary * lvProps;
UInt64 lvExtentCount; AppleLVMLogicalExtent * lvExtent[kAppleLVMSkipListSize];
bool lvPublished;
AppleLVMVolume * lvParent;
AppleLVMVolume * lvSnapShot;
AppleLVMVolume * lvBitMap;
protected:
virtual bool init(void);
virtual AppleLVMLogicalExtent * addExtent(AppleLVMGroup * lvg, AppleRAIDExtentOnDisk * extent);
public:
using IOMedia::init;
static OSDictionary * propsFromHeader(AppleLVMVolumeOnDisk * lve);
static AppleLVMVolume * withHeader(AppleLVMVolumeOnDisk * lve, OSDictionary * lveProps = 0);
virtual bool initWithHeader(OSDictionary * lveProps);
virtual void free();
virtual OSDictionary * getVolumeProperties(void);
virtual const OSString * getVolumeUUID(void);
virtual const char * getVolumeUUIDString(void);
virtual const OSString * getGroupUUID(void);
virtual const OSString * getParentUUID(void);
virtual const OSString * getHint(void);
inline UInt64 getClaimedSize(void) { return lvClaimedSize; };
inline UInt64 getExtentCount(void) const { return lvExtentCount; };
inline UInt32 getSequenceNumber(void) const { return lvSequenceNumber; };
inline UInt32 getEntrySize(void) const { return lvEntrySize; };
virtual const OSString * getDiskName(void);
inline UInt32 getIndex(void) const { return lvIndex; };
inline void setIndex(UInt32 index) { lvIndex = index; };
inline UInt64 getEntryOffset(void) const { return lvEntryOffset; };
inline void setEntryOffset(UInt64 offset) { lvEntryOffset = offset; };
inline bool isPublished(void) const { return lvPublished; };
inline void setPublished(bool published) { lvPublished = published; };
virtual bool addExtents(AppleLVMGroup * lvg, AppleLVMVolumeOnDisk * lve);
virtual bool removeExtents(AppleLVMGroup * lvg);
virtual AppleLVMLogicalExtent * findExtent(UInt64 offset);
virtual bool hasExtentsOnMember(AppleRAIDMember * member);
virtual bool buildExtentList(AppleRAIDExtentOnDisk * extents);
inline bool isAVolume(void) const { return (lvTypeID & kLVMTypeIsAVolume) != 0; };
inline bool isASnapShot(void) const { return (lvTypeID & kLVMTypeIsASnapShot) != 0; };
inline bool isABitMap(void) const { return (lvTypeID & kLVMTypeBitMap) != 0; };
inline UInt32 getTypeID(void) const { return lvTypeID; };
inline AppleLVMVolume * parentVolume(void) const { return lvParent; };
inline AppleLVMVolume * snapShotVolume(void) const { return lvSnapShot; };
inline AppleLVMVolume * bitMapVolume(void) const { return lvBitMap; };
virtual bool setParent(AppleLVMVolume * parent);
virtual bool setSnapShot(AppleLVMVolume * snapshot);
virtual bool setBitMap(AppleLVMVolume * bitmap);
virtual bool zeroVolume(void);
};
#endif KERNEL
#endif _APPLELVMVOLUME_H