aruu

[MIRROR] Actual replacement for Busybox | suckless
git clone https://git.daat.foo/aruu.git
Log | Files | Refs | README | LICENSE

gpt.h (2420B)


      1 /* see LICENSE file for copyright and license details */
      2 #ifndef ARUU_LIBDISK_GPT_H
      3 #define ARUU_LIBDISK_GPT_H
      4 
      5 /* the tables as they are on a disk, and reading and writing the GPT
      6  * itself. fdisk edits these directly; libdisk's label.c is the same
      7  * tables as a list of partitions, for anything that is not a command
      8  * line over them */
      9 
     10 #include "../diskutil.h"
     11 
     12 #include <stddef.h>
     13 #include <stdint.h>
     14 
     15 struct MbrPartition {
     16   uint8_t  boot;
     17   uint8_t  start_chs[3];
     18   uint8_t  type;
     19   uint8_t  end_chs[3];
     20   uint32_t start_lba;
     21   uint32_t size;
     22 } __attribute__((packed));
     23 
     24 struct MbrHeader {
     25   uint8_t             code[446];
     26   struct MbrPartition parts[4];
     27   uint8_t             sig[2];
     28 } __attribute__((packed));
     29 
     30 struct GptHeader {
     31   uint8_t  sig[8];
     32   uint32_t rev;
     33   uint32_t size;
     34   uint32_t crc;
     35   uint32_t reserved;
     36   uint64_t current_lba;
     37   uint64_t backup_lba;
     38   uint64_t first_usable;
     39   uint64_t last_usable;
     40   uint8_t  disk_guid[16];
     41   uint64_t partition_lba;
     42   uint32_t num_parts;
     43   uint32_t part_size;
     44   uint32_t parts_crc;
     45 } __attribute__((packed));
     46 
     47 struct GptPartition {
     48   uint8_t  type_guid[16];
     49   uint8_t  part_guid[16];
     50   uint64_t start_lba;
     51   uint64_t end_lba;
     52   uint64_t flags;
     53   uint16_t name[36];
     54 } __attribute__((packed));
     55 
     56 #define GPT_ENTRIES  128
     57 #define GPT_ENTRY_SZ 128
     58 /* the table of known partition types, gdisk's four hex digit codes */
     59 struct GptType {
     60   const char *code;
     61   const char *name;
     62   const char *guid; /* canonical form */
     63   uint8_t     mbr;  /* the byte MBR uses for it, 0 for none */
     64 };
     65 extern const struct GptType gpt_types[];
     66 extern const int            gpt_ntypes;
     67 
     68 uint32_t disk_crc32(uint32_t crc, const void *buf, size_t len);
     69 int      parse_guid_string(const char *s, uint8_t out[16]);
     70 void     format_guid(const uint8_t guid[16], char out[37]);
     71 /* the GUID of a type code or canonical GUID string; unknown ones give the
     72  * linux filesystem type, with a warning */
     73 void gpt_type_guid(const char *type, uint8_t out[16]);
     74 /* the type of a GUID: its table entry, NULL when it is none of them */
     75 const struct GptType *gpt_type_of(const uint8_t guid[16]);
     76 int                   gpt_random_guid(uint8_t out[16]);
     77 void                  gpt_set_name(uint16_t name[36], const char *s);
     78 int gpt_read(struct BlockDev *dev, struct GptHeader *hdr, struct GptPartition *parts);
     79 int gpt_write(struct BlockDev *dev, struct GptHeader *hdr, struct GptPartition *parts);
     80 
     81 #endif