/* Minimal GPT parser
   Copyright (C) 2026 Alexander Larsson <alexl@redhat.com>

   This file is free software: you can redistribute it and/or modify
   it under the terms of the GNU Lesser General Public License as
   published by the Free Software Foundation; either version 2.1 of the
   License, or (at your option) any later version.

   This file is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU Lesser General Public License for more details.

   You should have received a copy of the GNU Lesser General Public License
   along with this program.  If not, see <https://www.gnu.org/licenses/>.
*/
#include <stdbool.h>
#include <stdint.h>

#define GPT_NAME_MAX 36

typedef struct {
    char name[GPT_NAME_MAX + 1];
    uint64_t offset;
    uint64_t size;
} GptPartition;

typedef struct {
    uint32_t n_partitions;
    GptPartition *partitions;
} GptPartitionTable;

extern bool
gpt_parse(int fd, GptPartitionTable *out);

extern GptPartition *
gpt_find_partition(GptPartitionTable *table, const char *name);

extern void
gpt_partition_table_free(GptPartitionTable *table);
