rulimine/stage23/lib/part.h

98 lines
2.1 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 uefi == 1
2021-03-02 12:23:43 +03:00
# include <efi.h>
#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 uefi == 1
2021-03-04 11:15:10 +03:00
EFI_HANDLE efi_handle;
EFI_HANDLE efi_part_handle;
EFI_BLOCK_IO *block_io;
bool unique_sector_valid;
uint32_t unique_sector_crc32;
#elif bios == 1
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;
2020-04-15 14:21:44 +03:00
};
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);
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);
2021-06-12 14:13:19 +03:00
struct volume *volume_get_by_coord(bool optical, int drive, int partition);
#if bios == 1
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
2021-03-04 00:38:28 +03:00
#define volume_iterate_parts(_VOLUME_, _BODY_) ({ \
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); \
_PART_CNT++; \
2021-03-13 11:08:01 +03:00
if (_PART == NULL) \
continue; \
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
} \
2021-03-04 00:38:28 +03:00
})
2020-04-15 14:21:44 +03:00
#endif