Update Red Hat Copyright Notices
[nbdkit.git] / plugins / partitioning / virtual-disk.h
blob88702203fb2ee085bcae1a420d0fa0602a21e059
1 /* nbdkit
2 * Copyright Red Hat
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
6 * met:
8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
11 * * Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
15 * * Neither the name of Red Hat nor the names of its contributors may be
16 * used to endorse or promote products derived from this software without
17 * specific prior written permission.
19 * THIS SOFTWARE IS PROVIDED BY RED HAT AND CONTRIBUTORS ''AS IS'' AND
20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
21 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
22 * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL RED HAT OR
23 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
26 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
27 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
28 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
29 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30 * SUCH DAMAGE.
33 #ifndef NBDKIT_VIRTUAL_DISK_H
34 #define NBDKIT_VIRTUAL_DISK_H
36 #include <stdbool.h>
37 #include <sys/types.h>
38 #include <sys/stat.h>
40 #include "rounding.h"
42 #include "gpt.h"
43 #include "regions.h"
45 #define SECTOR_SIZE UINT64_C (512)
47 /* Maximum size of MBR disks. This is an approximation based on the
48 * known limit (2^32 sectors) and an estimate based on the amount of
49 * padding between partitions.
51 #define MAX_MBR_DISK_SIZE (UINT32_MAX * SECTOR_SIZE - 5 * MAX_ALIGNMENT)
53 /* For GPT, the number of entries in the partition table array (PTA),
54 * and the number of LBAs which the PTA occupies. The latter will be
55 * 32 if the number of files is <= GPT_MIN_PARTITIONS, which is the
56 * normal case.
58 #define GPT_PTA_SIZE ROUND_UP (the_files.len, GPT_MIN_PARTITIONS)
59 #define GPT_PTA_LBAs (GPT_PTA_SIZE * GPT_PT_ENTRY_SIZE / SECTOR_SIZE)
61 /* Maximum possible and default alignment between partitions. */
62 #define MAX_ALIGNMENT (2048 * SECTOR_SIZE)
63 #define DEFAULT_ALIGNMENT MAX_ALIGNMENT
65 /* Default MBR partition ID and GPT partition type GUID. */
66 #define DEFAULT_MBR_ID 0x83
67 #define DEFAULT_TYPE_GUID "0FC63DAF-8483-4772-8E79-3D69D8477DE4"
69 extern int partitioning_debug_regions;
71 extern unsigned long alignment;
72 extern uint8_t mbr_id;
73 extern char type_guid[16];
75 #define PARTTYPE_UNSET 0
76 #define PARTTYPE_MBR 1
77 #define PARTTYPE_GPT 2
78 extern int parttype;
80 /* A file supplied on the command line. */
81 struct file {
82 const char *filename; /* file= supplied on the command line */
83 int fd;
84 struct stat statbuf;
85 char guid[16]; /* random GUID used for GPT */
86 unsigned long alignment; /* alignment of this partition */
87 uint8_t mbr_id; /* MBR ID of this partition */
88 char type_guid[16]; /* partition type GUID of this partition */
91 DEFINE_VECTOR_TYPE (files, struct file);
93 extern files the_files;
94 extern regions the_regions;
95 extern unsigned char *primary, *secondary, **ebr;
97 /* Main entry point called after files array has been populated. */
98 extern int create_virtual_disk_layout (void);
100 /* Parse a GPT GUID. Note that GPT GUIDs have peculiar
101 * characteristics which make them unlike general GUIDs.
103 extern int parse_guid (const char *str, char *out)
104 __attribute__ ((__nonnull__ (1, 2)));
106 /* Internal function for creating a single MBR PTE. The GPT code
107 * calls this for creating the protective MBR.
109 extern void create_mbr_partition_table_entry (const struct region *,
110 bool bootable, int partition_id,
111 unsigned char *)
112 __attribute__ ((__nonnull__ (1, 4)));
114 /* Create MBR or GPT layout. */
115 extern void create_mbr_layout (void);
116 extern void create_gpt_layout (void);
118 #endif /* NBDKIT_VIRTUAL_DISK_H */