~aleteoryx/muditaos

ref: f9b9967b0ebea232eadffedcf7ed6a86c94c5e48 muditaos/module-vfs/include/internal/purefs/blkdev/disk_handle.hpp -rw-r--r-- 1.2 KiB
f9b9967b — Maciej-Mudita [EGD-4694] Add CPU frequency shift mechanism 5 years ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
// Copyright (c) 2017-2020, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md

#pragma once

#include <memory>
#include <string>
#include <purefs/blkdev/defs.hpp>

namespace purefs::blkdev
{
    class disk;
}

namespace purefs::blkdev::internal
{

    class disk_handle
    {
      public:
        static constexpr auto no_parition = -1;
        explicit disk_handle(std::weak_ptr<blkdev::disk> disk, std::string_view name, short partition = no_parition)
            : m_disk(disk), m_partition(partition), m_name(name)
        {}
        auto disk() const noexcept
        {
            return m_disk.lock();
        }
        auto partition() const noexcept
        {
            return m_partition;
        }
        auto has_partition() const noexcept
        {
            return m_partition != no_parition;
        }
        auto sectors() const noexcept -> sector_t;
        auto name() const noexcept
        {
            return m_name;
        }

      private:
        const std::weak_ptr<blkdev::disk> m_disk;
        const short m_partition{-1};
        mutable sector_t m_sectors{0};
        const std::string_view m_name;
    };
} // namespace purefs::blkdev::internal