xaizek / tos (License: GPLv3 only) (since 2018-12-07)
This is an alternative version of sources presented as part of Write Your Own OS video tutorial by Viktor Engelmann.
<root> / src / fs / mbr.hpp (d0adde5fabaeaf3fe8d0a0c4ce15bb5ee6403186) (1,213B) (mode 100644) [raw]
#ifndef TOS__FILESYSTEM__MSDOSPART_HPP__
#define TOS__FILESYSTEM__MSDOSPART_HPP__

#include <cstdint>

#include "utils/struct.hpp"

namespace drv {
    class ATA;
}

namespace fs {

struct PartitionTableEntry
{
    Field<std::uint8_t> bootable;
    Field<std::uint32_t, 3> startCHS;
    Field<std::uint8_t> partition_id;
    Field<std::uint32_t, 3> endCHS;
    Field<std::uint32_t> start_lba;
    Field<std::uint32_t> length;

    explicit PartitionTableEntry(std::uint8_t *&data)
        : bootable(data), startCHS(data), partition_id(data), endCHS(data),
          start_lba(data), length(data)
    {
    }

    static constexpr std::ptrdiff_t size()
    {
        return 16;
    }
};

struct MasterBootRecord
{
    Fields<std::uint8_t, 440> bootloader;
    Field<std::uint32_t> signature;
    Field<std::uint16_t> unused;

    Fields<PartitionTableEntry, 4> primaryPartition;

    Field<std::uint16_t> magicnumber;

    explicit MasterBootRecord(std::uint8_t data[])
        : bootloader(data), signature(data), unused(data),
          primaryPartition(data), magicnumber(data)
    {
    }
};

class MBR
{
public:
    static void readPartitions(drv::ATA &hd);
};

}

#endif // TOS__FILESYSTEM__MSDOSPART_HPP__
Hints

Before first commit, do not forget to setup your git environment:
git config --global user.name "your_name_here"
git config --global user.email "your@email_here"

Clone this repository using HTTP(S):
git clone https://code.reversed.top/user/xaizek/tos

Clone this repository using ssh (do not forget to upload a key first):
git clone ssh://rocketgit@code.reversed.top/user/xaizek/tos

You are allowed to anonymously push to this repository.
This means that your pushed commits will automatically be transformed into a pull request:
... clone the repository ...
... make some changes and some commits ...
git push origin master