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.cpp (6c32bc48071ed95a53cf2a847b9d721cffaa40dd) (892B) (mode 100644) [raw]
#include "fs/mbr.hpp"

#include "drv/ATA.hpp"
#include "fs/fat.hpp"
#include "fs/mbr.hpp"
#include "print.hpp"

using namespace fs;

void
MBR::readPartitions(drv::ATA &hd)
{
    kprint("MBR: ");

    std::uint8_t mbrSector[512];
    hd.read28(0, mbrSector);

    MasterBootRecord mbr(mbrSector);

    if (mbr.magicnumber != 0xAA55) {
        kprint("illegal MBR");
        return;
    }

    kprint("\n");
    for (std::uint8_t i = 0; i < 4; ++i) {
        const std::uint8_t id = mbr.primaryPartition[i]->partition_id;
        if (id == 0x00) {
            continue;
        }

        const char *is = mbr.primaryPartition[i]->bootable == 0x80 ? ""
                                                                   : " not";
        kprint(" Partition ", i, is, " bootable.  Type 0x", id, ".\n");

        FAT fat(hd, mbr.primaryPartition[i]->start_lba);
        fat.printFiles();
    }
}
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