Overview   API Reference  

partition_driver.hpp

00001 #if !defined(__PARTITION_DRIVER_HPP__)
00002 #define __PARTITION_DRIVER_HPP__
00003 
00004 //
00005 // local includes
00006 //
00007 #include "core/drivers/block/partitions/partitions.hpp"
00008 #include "block_driver.hpp"
00009 
00017 struct partition_driver : public block_driver, private noncopyable
00018 {
00020     static const uint16_t DEFAULT_PARTITION_TYPE = 0x83;
00022     static const uint16_t START_SECTORS          = 30;
00024     static const uint16_t END_SECTORS            = 30;
00025 
00026   protected:
00028     static const efi::guid_t DUMMY_GUID;
00030     static const uint32_t DUMMY_UID;
00031 
00033     const uint16_t partition_type;
00034 
00036     block_driver * const driver;
00038     const l4_sector_t driver_start_lba;
00040     const l4_sector_t driver_end_lba;
00041 
00043     const l4_sector_t size;
00045     uint8_t start_sectors[START_SECTORS * SECTOR_SIZE];
00047     uint8_t end_sectors[END_SECTORS * SECTOR_SIZE];
00048 
00049   public:
00050     //
00051     // constructor & destructor
00052     //
00053     inline partition_driver(block_driver *driver,
00054                             const uint16_t partition_type=DEFAULT_PARTITION_TYPE)
00055         : partition_type(partition_type), driver(driver), driver_start_lba(START_SECTORS),
00056           driver_end_lba(START_SECTORS + (driver ? driver->sectors() : 0) - 1),
00057           size(driver ? START_SECTORS + driver->sectors() + END_SECTORS : 0)
00058     {
00059         if (is(READY))
00060             if (build_fake_sectors()) log::error("%s: disabled\n", name());
00061     }
00062 
00063     virtual inline ~partition_driver(void)
00064     {
00065         delete driver;
00066     }
00067 
00068     virtual inline int reset(void)
00069     {
00070         return driver ? driver->reset() : -L4_ENOTAVAIL;
00071     }
00072 
00073     //
00074     // block_driver: override name
00075     //
00076     virtual inline const char *name(void) const
00077     {
00078         return driver ? driver->name() : L4VMM_DRIVER" uninitialized partition driver";
00079     }
00080 
00081     //
00082     // block_driver: override state management functions
00083     //
00084     virtual inline bool is(const state_flags flags) const
00085     {
00086         return driver ? driver->is(flags) : false;
00087     }
00088 
00089     virtual inline const state_flags state(void) const
00090     {
00091         return driver ? driver->state() : static_cast<state_flags>(0);
00092     }
00093 
00094     //
00095     // block_driver: override medium functions
00096     //
00097     virtual inline l4_sector_t sectors(void) const
00098     {
00099         // return modified size
00100         return is(READY) ? size : 0;
00101     }
00102 
00103     virtual inline int read_sectors(uint8_t *buffer, l4_sector_t sector, l4_sector_t number)
00104     {
00105         return read_write_sectors(1, buffer, sector, number);
00106     }
00107 
00108     virtual inline int write_sectors(uint8_t *buffer, l4_sector_t sector, l4_sector_t number)
00109     {
00110         return read_write_sectors(0, buffer, sector, number);
00111     }
00112 
00113     virtual inline int flush_sectors(void)
00114     {
00115         return driver ? driver->flush_sectors() : -L4_ENOTAVAIL;
00116     }
00117 
00118   protected:
00122     virtual inline bool is_valid_partition(l4_sector_t start_lba, l4_sector_t end_lba)
00123     {
00124         return (start_lba >= driver_start_lba) && (end_lba >= driver_start_lba) &&
00125                (start_lba <= driver_end_lba)   && (end_lba <= driver_end_lba)   &&
00126                (start_lba <= end_lba);
00127     }
00128 
00133     virtual int write_mbr(uint8_t type, l4_sector_t start_lba, l4_sector_t end_lba, uint8_t attributes=0);
00134 
00138     virtual int write_gpt(uint8_t type, l4_sector_t start_lba, l4_sector_t end_lba, uint64_t attributes=0);
00139 
00143     virtual int build_fake_sectors(void);
00144 
00148     int read_write_sectors(uint8_t read_write, uint8_t *buffer, l4_sector_t sector, l4_sector_t number);
00149 };
00150 
00151 #endif
00152 
00153 // ***** end of source ***** //
00154 

L4vmm Reference Manual, written by Mario Schwalbe  © 2006-2008