limine/common/lib/part.h

113 lines
2.5 KiB
C
Raw Normal View History

2020-04-15 14:21:44 +03:00
#ifndef __LIB__PART_H__
#define __LIB__PART_H__
#include <stdint.h>
#include <stddef.h>
2020-10-18 07:23:39 +03:00
#include <stdbool.h>
2020-11-02 11:20:34 +03:00
#include <lib/guid.h>
#if defined (UEFI)
2021-03-02 12:23:43 +03:00
# include <efi.h>
# include <crypt/blake2b.h>
2021-03-02 12:23:43 +03:00
#endif
2020-04-15 14:21:44 +03:00
#define NO_PARTITION (-1)
#define INVALID_TABLE (-2)
#define END_OF_TABLE (-3)
2021-03-04 11:15:10 +03:00
struct volume {
#if defined (UEFI)
2021-03-04 11:15:10 +03:00
EFI_HANDLE efi_handle;
// Block storage
EFI_HANDLE efi_part_handle;
EFI_BLOCK_IO *block_io;
// PXE
EFI_PXE_BASE_CODE_PROTOCOL *pxe_base_code;
bool unique_sector_valid;
2022-01-14 04:04:22 +03:00
uint64_t unique_sector;
uint8_t unique_sector_b2b[BLAKE2B_OUT_BYTES];
#elif defined (BIOS)
2021-06-12 14:13:19 +03:00
int drive;
2021-03-02 12:23:43 +03:00
#endif
size_t fastest_xfer_size;
2021-06-12 14:13:19 +03:00
int index;
bool is_optical;
2021-03-13 11:08:01 +03:00
bool pxe;
2020-11-01 23:25:35 +03:00
int partition;
int sector_size;
2021-03-04 11:15:10 +03:00
struct volume *backing_dev;
int max_partition;
int cache_status;
uint8_t *cache;
uint64_t cached_block;
2021-03-04 11:15:10 +03:00
2020-10-18 07:23:39 +03:00
uint64_t first_sect;
uint64_t sect_count;
2021-03-04 11:15:10 +03:00
2020-11-01 23:25:35 +03:00
bool guid_valid;
2020-10-18 07:23:39 +03:00
struct guid guid;
bool part_guid_valid;
struct guid part_guid;
bool fslabel_valid;
char *fslabel;
2020-04-15 14:21:44 +03:00
};
void list_volumes(void);
bool is_valid_mbr(struct volume *volume);
2021-03-04 11:15:10 +03:00
extern struct volume **volume_index;
extern size_t volume_index_i;
2021-03-02 12:23:43 +03:00
bool gpt_get_guid(struct guid *guid, struct volume *volume);
2022-03-16 08:49:41 +03:00
uint32_t mbr_get_id(struct volume *volume);
2021-03-02 12:23:43 +03:00
int part_get(struct volume *part, struct volume *volume, int partition);
2021-03-04 11:15:10 +03:00
struct volume *volume_get_by_guid(struct guid *guid);
struct volume *volume_get_by_fslabel(char *fslabel);
2021-06-12 14:13:19 +03:00
struct volume *volume_get_by_coord(bool optical, int drive, int partition);
#if defined (BIOS)
2021-06-12 14:13:19 +03:00
struct volume *volume_get_by_bios_drive(int drive);
#endif
2020-11-02 12:17:20 +03:00
bool volume_read(struct volume *part, void *buffer, uint64_t loc, uint64_t count);
2020-11-02 12:17:20 +03:00
2022-08-27 00:30:00 +03:00
#define volume_iterate_parts(_VOLUME_, _BODY_) do { \
2021-03-04 11:15:10 +03:00
struct volume *_VOLUME = _VOLUME_; \
2021-03-13 11:08:01 +03:00
if (_VOLUME->pxe) { \
do { \
struct volume *_PART = _VOLUME; \
_BODY_ \
} while (0); \
} else { \
while (_VOLUME->backing_dev != NULL) { \
_VOLUME = _VOLUME->backing_dev; \
} \
2021-03-04 11:15:10 +03:00
\
2021-03-13 11:08:01 +03:00
int _PART_CNT = -1; \
2021-06-12 14:13:19 +03:00
for (size_t _PARTNO = 0; ; _PARTNO++) { \
2021-03-13 11:08:01 +03:00
if (_PART_CNT > _VOLUME->max_partition) \
break; \
2021-03-04 11:15:10 +03:00
\
2021-06-12 14:13:19 +03:00
struct volume *_PART = volume_get_by_coord(_VOLUME->is_optical, \
_VOLUME->index, _PARTNO); \
2021-03-13 11:08:01 +03:00
if (_PART == NULL) \
continue; \
\
_PART_CNT++; \
2021-03-04 11:15:10 +03:00
\
2021-03-13 11:08:01 +03:00
_BODY_ \
} \
2021-03-04 11:15:10 +03:00
} \
2022-08-27 00:30:00 +03:00
} while (0)
2021-03-04 00:38:28 +03:00
2020-04-15 14:21:44 +03:00
#endif