summaryrefslogtreecommitdiffhomepage
path: root/Private/KernelKit/DriveManager.hpp
blob: b5c0ad0cafa1c50ff12c2181d1a4ada8210eb300 (plain)
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
/*
 *	========================================================
 *
 *	hCore
 * 	Copyright 2024 Mahrouss Logic, all rights reserved.
 *
 * 	========================================================
 */

#pragma once

#include <CompilerKit/Compiler.hpp>
#include <NewKit/Defines.hpp>
#include <NewKit/String.hpp>

#include <KernelKit/Device.hpp>

#define kDriveInvalidID -1
#define kDriveNameLen 32

namespace hCore
{
enum
{
    kInvalidDrive = -1,
    kBlockDevice = 0xAD,
    kMassStorage = 0xDA,
    kFloppyDisc = 0xCD,
    kOpticalDisc = 0xDC, // CD-ROM/DVD-ROM/Blu-Ray
    kReadOnly = 0x10,    // Read only drive
    kXPMDrive = 0x11,    // eXplicit Partition Map.
    kXPTDrive = 0x12,    // GPT w/ XPM partition.
    kMBRDrive = 0x13,    // IBM PC classic partition scheme
};

typedef Int64 DriveID;

// Mounted drive.
struct DriveTraits final
{
    char fName[kDriveNameLen]; // /system, /boot...
    Int32 fKind;               // fMassStorage, fFloppy, fOpticalDisc.
    DriveID fId;               // Drive id.
    Int32 fFlags;              // fReadOnly, fXPMDrive, fXPTDrive

    //! disk mount, unmount operations
    void (*fMount)(void);
    void (*fUnmount)(void);

    bool (*fReady)(void); //! is drive ready?

    //! for StorageKit.
    struct DrivePacket final
    {
        voidPtr fPacketContent; // packet body.
        Char fPacketMime[32];   //! identify what we're sending.
        SizeT fPacketSize;      // packet size
    } fPacket;
};

#define kPacketBinary "file/x-binary"
#define kPacketSource "file/x-source"
#define kPacketASCII "file/x-ascii"
#define kPacketZip "file/x-zip"

//! drive as a device.
typedef DeviceInterface<DriveTraits> Drive;
typedef Drive *DrivePtr;

class DriveSelector final
{
  public:
    explicit DriveSelector();
    ~DriveSelector();

  public:
    HCORE_COPY_DEFAULT(DriveSelector);

    DriveTraits &GetMounted();
    bool Mount(DriveTraits *drive);
    DriveTraits *Unmount();

  private:
    DriveTraits *fDrive;
};
} // namespace hCore