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-03-02 12:23:43 +03:00
|
|
|
#if defined (uefi)
|
|
|
|
# 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-02 12:23:43 +03:00
|
|
|
#if defined (bios)
|
|
|
|
typedef int drive_t;
|
|
|
|
#elif defined (uefi)
|
2021-03-04 03:42:25 +03:00
|
|
|
typedef EFI_HANDLE drive_t;
|
2021-03-02 12:23:43 +03:00
|
|
|
#endif
|
|
|
|
|
2021-02-06 16:40:55 +03:00
|
|
|
struct volume {
|
2021-03-02 12:23:43 +03:00
|
|
|
drive_t drive;
|
2020-11-01 23:25:35 +03:00
|
|
|
int partition;
|
2020-11-05 19:18:45 +03:00
|
|
|
int sector_size;
|
2021-03-03 22:53:26 +03:00
|
|
|
int cache_status;
|
|
|
|
uint8_t *cache;
|
|
|
|
uint64_t cached_block;
|
2020-10-18 07:23:39 +03:00
|
|
|
uint64_t first_sect;
|
|
|
|
uint64_t sect_count;
|
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 03:42:25 +03:00
|
|
|
extern struct volume *volume_index;
|
|
|
|
extern size_t volume_index_i;
|
|
|
|
|
2021-02-06 16:40:55 +03:00
|
|
|
void volume_create_index(void);
|
2020-10-18 07:23:39 +03:00
|
|
|
|
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);
|
|
|
|
bool volume_get_by_guid(struct volume *part, struct guid *guid);
|
2021-03-02 12:23:43 +03:00
|
|
|
bool volume_get_by_coord(struct volume *part, drive_t drive, int partition);
|
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_) ({ \
|
|
|
|
bool _OK_ = true; \
|
|
|
|
struct volume _PART_ = _VOLUME_; \
|
|
|
|
for (int i = 0; ; i++) { \
|
|
|
|
int _PARTNUM_ = i - 1; \
|
|
|
|
_BODY_ ; \
|
|
|
|
switch (part_get(&_PART_, &_VOLUME_, i)) { \
|
|
|
|
case INVALID_TABLE: \
|
|
|
|
case END_OF_TABLE: \
|
|
|
|
_OK_ = false; \
|
|
|
|
break; \
|
|
|
|
default: \
|
|
|
|
continue; \
|
|
|
|
} \
|
|
|
|
break; \
|
|
|
|
} \
|
|
|
|
_OK_; \
|
|
|
|
})
|
|
|
|
|
2020-04-15 14:21:44 +03:00
|
|
|
#endif
|