File: virtual-disk.h

package info (click to toggle)
nbdkit 1.42.9-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 14,696 kB
  • sloc: ansic: 59,224; sh: 16,793; makefile: 6,463; python: 1,837; cpp: 1,116; ml: 504; perl: 502; tcl: 62
file content (117 lines) | stat: -rw-r--r-- 4,252 bytes parent folder | download | duplicates (2)
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
/* nbdkit
 * Copyright Red Hat
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are
 * met:
 *
 * * Redistributions of source code must retain the above copyright
 * notice, this list of conditions and the following disclaimer.
 *
 * * Redistributions in binary form must reproduce the above copyright
 * notice, this list of conditions and the following disclaimer in the
 * documentation and/or other materials provided with the distribution.
 *
 * * Neither the name of Red Hat nor the names of its contributors may be
 * used to endorse or promote products derived from this software without
 * specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY RED HAT AND CONTRIBUTORS ''AS IS'' AND
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
 * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL RED HAT OR
 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 * SUCH DAMAGE.
 */

#ifndef NBDKIT_VIRTUAL_DISK_H
#define NBDKIT_VIRTUAL_DISK_H

#include <stdbool.h>
#include <sys/types.h>

#include "rounding.h"

#include "gpt.h"
#include "regions.h"

#define SECTOR_SIZE UINT64_C (512)

/* Maximum size of MBR disks.  This is an approximation based on the
 * known limit (2^32 sectors) and an estimate based on the amount of
 * padding between partitions.
 */
#define MAX_MBR_DISK_SIZE (UINT32_MAX * SECTOR_SIZE - 5 * MAX_ALIGNMENT)

/* For GPT, the number of entries in the partition table array (PTA),
 * and the number of LBAs which the PTA occupies.  The latter will be
 * 32 if the number of files is <= GPT_MIN_PARTITIONS, which is the
 * normal case.
 */
#define GPT_PTA_SIZE ROUND_UP (the_files.len, GPT_MIN_PARTITIONS)
#define GPT_PTA_LBAs (GPT_PTA_SIZE * GPT_PT_ENTRY_SIZE / SECTOR_SIZE)

/* Maximum possible and default alignment between partitions. */
#define MAX_ALIGNMENT (2048 * SECTOR_SIZE)
#define DEFAULT_ALIGNMENT MAX_ALIGNMENT

/* Default MBR partition ID and GPT partition type GUID. */
#define DEFAULT_MBR_ID 0x83
#define DEFAULT_TYPE_GUID "0FC63DAF-8483-4772-8E79-3D69D8477DE4"

extern int partitioning_debug_regions;

extern unsigned long alignment;
extern uint8_t mbr_id;
extern char type_guid[16];

#define PARTTYPE_UNSET 0
#define PARTTYPE_MBR   1
#define PARTTYPE_GPT   2
extern int parttype;

/* A file supplied on the command line. */
struct file {
  const char *filename;         /* file= supplied on the command line */
  int fd;
  int64_t size;
  char guid[16];                /* random GUID used for GPT */
  unsigned long alignment;      /* alignment of this partition */
  uint8_t mbr_id;               /* MBR ID of this partition */
  char type_guid[16];           /* partition type GUID of this partition */
};

DEFINE_VECTOR_TYPE (files, struct file);

extern files the_files;
extern regions the_regions;
extern unsigned char *primary, *secondary, **ebr;

/* Main entry point called after files array has been populated. */
extern int create_virtual_disk_layout (void);

/* Parse a GPT GUID.  Note that GPT GUIDs have peculiar
 * characteristics which make them unlike general GUIDs.
 */
extern int parse_guid (const char *str, char *out)
  __attribute__ ((__nonnull__ (1, 2)));

/* Internal function for creating a single MBR PTE.  The GPT code
 * calls this for creating the protective MBR.
 */
extern void create_mbr_partition_table_entry (const struct region *,
                                              bool bootable, int partition_id,
                                              unsigned char *)
  __attribute__ ((__nonnull__ (1, 4)));

/* Create MBR or GPT layout. */
extern void create_mbr_layout (void);
extern void create_gpt_layout (void);

#endif /* NBDKIT_VIRTUAL_DISK_H */