2020-04-15 14:21:44 +03:00
|
|
|
#ifndef __LIB__PART_H__
|
|
|
|
#define __LIB__PART_H__
|
|
|
|
|
|
|
|
#include <stdint.h>
|
2021-03-04 03:42:25 +03:00
|
|
|
#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>
|
2021-07-15 11:03:47 +03:00
|
|
|
#if uefi == 1
|
2021-03-02 12:23:43 +03:00
|
|
|
# include <efi.h>
|
|
|
|
#endif
|
2020-04-15 14:21:44 +03:00
|
|
|
|
2020-11-09 17:04:53 +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 {
|
2021-07-15 11:03:47 +03:00
|
|
|
#if uefi == 1
|
2021-03-04 11:15:10 +03:00
|
|
|
EFI_HANDLE efi_handle;
|
2021-09-27 05:04:15 +03:00
|
|
|
EFI_HANDLE efi_part_handle;
|
2021-09-02 00:01:03 +03:00
|
|
|
EFI_BLOCK_IO *block_io;
|
|
|
|
|
|
|
|
bool unique_sector_valid;
|
|
|
|
uint32_t unique_sector_crc32;
|
2021-07-15 11:03:47 +03:00
|
|
|
#elif bios == 1
|
2021-06-12 14:13:19 +03:00
|
|
|
int drive;
|
2021-03-02 12:23:43 +03:00
|
|
|
#endif
|
|
|
|
|
2021-08-22 17:27:06 +03:00
|
|
|
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;
|
2020-11-05 19:18:45 +03:00
|
|
|
int sector_size;
|
2021-03-04 11:15:10 +03:00
|
|
|
struct volume *backing_dev;
|
|
|
|
|
|
|
|
int max_partition;
|
|
|
|
|
2021-03-03 22:53:26 +03:00
|
|
|
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;
|
2020-12-10 09:13:52 +03:00
|
|
|
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;
|
2021-03-04 03:42:25 +03:00
|
|
|
extern size_t volume_index_i;
|
|
|
|
|
2021-03-02 12:23:43 +03:00
|
|
|
bool gpt_get_guid(struct guid *guid, struct volume *volume);
|
|
|
|
|
2021-02-06 16:40:55 +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);
|
2021-06-12 14:13:19 +03:00
|
|
|
struct volume *volume_get_by_coord(bool optical, int drive, int partition);
|
2021-07-15 11:03:47 +03:00
|
|
|
#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
|
|
|
|
2021-03-03 22:53:26 +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); \
|
2022-01-09 22:43:51 +03:00
|
|
|
_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
|