-
Notifications
You must be signed in to change notification settings - Fork 0
/
part.h
51 lines (43 loc) · 1.42 KB
/
part.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#ifndef __PART_H_
#define __PART_H_
#include <stdio.h> /* dprintf */
#include <stdlib.h> /* free */
#include <stdint.h> /* uint8_t */
#include <sys/types.h> /* off_t */
#include <stdbool.h>
#define warnf(e, ...) dprintf(2, e, __VA_ARGS__)
struct partinfo;
struct partinfo {
struct partinfo *next; /* next partition */
const char *kind; /* type string (usually "L" or "U"); corresponds to EFI type */
off_t srcsz; /* size of partition image (always <= partsz) */
int64_t startlba; /* starting LBA */
int64_t nsectors; /* size in sectors */
int srcfd; /* source image */
int num; /* partition number (only valid if !hidden) */
uint8_t dc; /* dos partition type; only used for DOS partition tables */
bool hidden; /* area is reserved but not an actual partition */
};
static inline struct partinfo *
last_part(struct partinfo *head)
{
while (head->next)
head = head->next;
return head;
}
static inline void
free_parts(struct partinfo **head)
{
if (!*head)
return;
if ((*head)->next)
free_parts(&(*head)->next);
free(*head);
*head = NULL;
}
int kernel_add_part(int fd, int pnum, long long start, long long length);
/* check_parts() checks a list of partitions
* for sanity and returns a (negative) error
* if something looks wrong */
int check_parts(const struct partinfo *head, int64_t nlbas);
#endif