miniOS
x86_64 hobby kernel with SMP, VFS, and POSIX process model
Loading...
Searching...
No Matches
block_device.h
Go to the documentation of this file.
1// MIT License
2//
3// Copyright (c) 2026 Christian Spoo
4//
5// Permission is hereby granted, free of charge, to any person obtaining a copy
6// of this software and associated documentation files (the "Software"), to deal
7// in the Software without restriction, including without limitation the rights
8// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9// copies of the Software, and to permit persons to whom the Software is
10// furnished to do so, subject to the following conditions:
11//
12// The above copyright notice and this permission notice shall be included in all
13// copies or substantial portions of the Software.
14//
15// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21// SOFTWARE.
22
23#ifndef _MINIOS_DRIVERS_BLOCK_DEVICE_H_
24#define _MINIOS_DRIVERS_BLOCK_DEVICE_H_
25
26#include <miniOS/types.h>
27
28/* Maximum number of tracked block devices (1 disk + up to 15 partitions). */
29#define BLKDEV_MAX 16
30
31#define BLKDEV_MAJOR_SATA 8 /* SCSI/ATA disk major, matching Linux convention */
32
33typedef struct {
34 char name[16]; /* "sda", "sda1", "sda2", ... */
37 uint64_t lba_start; /* first LBA (0 for whole-disk entry) */
38 uint64_t lba_end; /* last LBA inclusive (0 for whole-disk entry) */
41
46void blkdev_init(void);
47
59int blkdev_register(const char *name, uint8_t major, uint8_t minor,
60 uint64_t lba_start, uint64_t lba_end, bool is_partition);
61
68const block_device_t *blkdev_find(uint8_t major, uint8_t minor);
69
75const block_device_t *blkdev_get(int index);
76
80int blkdev_count(void);
81
82#endif /* _MINIOS_DRIVERS_BLOCK_DEVICE_H_ */
int blkdev_register(const char *name, uint8_t major, uint8_t minor, uint64_t lba_start, uint64_t lba_end, bool is_partition)
Definition block_device.c:35
const block_device_t * blkdev_find(uint8_t major, uint8_t minor)
Definition block_device.c:52
int blkdev_count(void)
Definition block_device.c:66
void blkdev_init(void)
Definition block_device.c:30
const block_device_t * blkdev_get(int index)
Definition block_device.c:60
Definition block_device.h:33
char name[16]
Definition block_device.h:34
uint8_t major
Definition block_device.h:35
uint64_t lba_start
Definition block_device.h:37
uint8_t minor
Definition block_device.h:36
bool is_partition
Definition block_device.h:39
uint64_t lba_end
Definition block_device.h:38
unsigned long int uint64_t
Definition types.h:37
unsigned char uint8_t
Definition types.h:28