11d3aed33SMarcel Moolenaar /*- 23728855aSPedro F. Giffuni * SPDX-License-Identifier: BSD-2-Clause-FreeBSD 33728855aSPedro F. Giffuni * 4f6aa3fccSMarcel Moolenaar * Copyright (c) 2006-2008 Marcel Moolenaar 51d3aed33SMarcel Moolenaar * All rights reserved. 61d3aed33SMarcel Moolenaar * 71d3aed33SMarcel Moolenaar * Redistribution and use in source and binary forms, with or without 81d3aed33SMarcel Moolenaar * modification, are permitted provided that the following conditions 91d3aed33SMarcel Moolenaar * are met: 101d3aed33SMarcel Moolenaar * 111d3aed33SMarcel Moolenaar * 1. Redistributions of source code must retain the above copyright 121d3aed33SMarcel Moolenaar * notice, this list of conditions and the following disclaimer. 131d3aed33SMarcel Moolenaar * 2. Redistributions in binary form must reproduce the above copyright 141d3aed33SMarcel Moolenaar * notice, this list of conditions and the following disclaimer in the 151d3aed33SMarcel Moolenaar * documentation and/or other materials provided with the distribution. 161d3aed33SMarcel Moolenaar * 171d3aed33SMarcel Moolenaar * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 181d3aed33SMarcel Moolenaar * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 191d3aed33SMarcel Moolenaar * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 201d3aed33SMarcel Moolenaar * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 211d3aed33SMarcel Moolenaar * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 221d3aed33SMarcel Moolenaar * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 231d3aed33SMarcel Moolenaar * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 241d3aed33SMarcel Moolenaar * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 251d3aed33SMarcel Moolenaar * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 261d3aed33SMarcel Moolenaar * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 271d3aed33SMarcel Moolenaar * 281d3aed33SMarcel Moolenaar * $FreeBSD$ 291d3aed33SMarcel Moolenaar */ 301d3aed33SMarcel Moolenaar 311d3aed33SMarcel Moolenaar #ifndef _GEOM_PART_H_ 321d3aed33SMarcel Moolenaar #define _GEOM_PART_H_ 331d3aed33SMarcel Moolenaar 341d3aed33SMarcel Moolenaar #define G_PART_TRACE(args) g_trace args 351d3aed33SMarcel Moolenaar 361d3aed33SMarcel Moolenaar #define G_PART_PROBE_PRI_LOW -10 371d3aed33SMarcel Moolenaar #define G_PART_PROBE_PRI_NORM -5 381d3aed33SMarcel Moolenaar #define G_PART_PROBE_PRI_HIGH 0 391d3aed33SMarcel Moolenaar 401d3aed33SMarcel Moolenaar enum g_part_alias { 41b42712a8SConrad Meyer G_PART_ALIAS_APPLE_APFS, /* An Apple APFS partition. */ 42f1317430SRui Paulo G_PART_ALIAS_APPLE_BOOT, /* An Apple boot partition entry. */ 439c0c355fSAllan Jude G_PART_ALIAS_APPLE_CORE_STORAGE,/* An Apple Core Storage partition. */ 44f1317430SRui Paulo G_PART_ALIAS_APPLE_HFS, /* An HFS+ file system entry. */ 45f1317430SRui Paulo G_PART_ALIAS_APPLE_LABEL, /* An Apple label partition entry. */ 46f1317430SRui Paulo G_PART_ALIAS_APPLE_RAID, /* An Apple RAID partition entry. */ 47f1317430SRui Paulo G_PART_ALIAS_APPLE_RAID_OFFLINE,/* An Apple RAID (offline) part entry.*/ 48f1317430SRui Paulo G_PART_ALIAS_APPLE_TV_RECOVERY, /* An Apple TV recovery part entry. */ 49f1317430SRui Paulo G_PART_ALIAS_APPLE_UFS, /* An Apple UFS partition entry. */ 509c0c355fSAllan Jude G_PART_ALIAS_BIOS_BOOT, /* A GRUB 2 boot partition entry. */ 519c0c355fSAllan Jude G_PART_ALIAS_CHROMEOS_FIRMWARE, /* A ChromeOS firmware part. entry. */ 529c0c355fSAllan Jude G_PART_ALIAS_CHROMEOS_KERNEL, /* A ChromeOS Kernel part. entry. */ 539c0c355fSAllan Jude G_PART_ALIAS_CHROMEOS_RESERVED, /* ChromeOS. Reserved for future use. */ 549c0c355fSAllan Jude G_PART_ALIAS_CHROMEOS_ROOT, /* A ChromeOS root part. entry. */ 559c0c355fSAllan Jude G_PART_ALIAS_DFBSD, /* A DfBSD label32 partition entry */ 569c0c355fSAllan Jude G_PART_ALIAS_DFBSD64, /* A DfBSD label64 partition entry */ 579c0c355fSAllan Jude G_PART_ALIAS_DFBSD_CCD, /* A DfBSD CCD partition entry */ 589c0c355fSAllan Jude G_PART_ALIAS_DFBSD_HAMMER, /* A DfBSD HAMMER FS partition entry */ 599c0c355fSAllan Jude G_PART_ALIAS_DFBSD_HAMMER2, /* A DfBSD HAMMER2 FS partition entry */ 609c0c355fSAllan Jude G_PART_ALIAS_DFBSD_LEGACY, /* A DfBSD legacy partition entry */ 619c0c355fSAllan Jude G_PART_ALIAS_DFBSD_SWAP, /* A DfBSD swap partition entry */ 629c0c355fSAllan Jude G_PART_ALIAS_DFBSD_UFS, /* A DfBSD UFS partition entry */ 639c0c355fSAllan Jude G_PART_ALIAS_DFBSD_VINUM, /* A DfBSD Vinum partition entry */ 649c0c355fSAllan Jude G_PART_ALIAS_EBR, /* A EBR partition entry. */ 651d3aed33SMarcel Moolenaar G_PART_ALIAS_EFI, /* A EFI system partition entry. */ 661d3aed33SMarcel Moolenaar G_PART_ALIAS_FREEBSD, /* A BSD labeled partition entry. */ 67f352a0d4SJohn Baldwin G_PART_ALIAS_FREEBSD_BOOT, /* A FreeBSD boot partition entry. */ 68f24a8224SMarcel Moolenaar G_PART_ALIAS_FREEBSD_NANDFS, /* A FreeBSD nandfs partition entry. */ 691d3aed33SMarcel Moolenaar G_PART_ALIAS_FREEBSD_SWAP, /* A swap partition entry. */ 701d3aed33SMarcel Moolenaar G_PART_ALIAS_FREEBSD_UFS, /* A UFS/UFS2 file system entry. */ 711d3aed33SMarcel Moolenaar G_PART_ALIAS_FREEBSD_VINUM, /* A Vinum partition entry. */ 72a1fedf91SMarcel Moolenaar G_PART_ALIAS_FREEBSD_ZFS, /* A ZFS file system entry. */ 73f1317430SRui Paulo G_PART_ALIAS_LINUX_DATA, /* A Linux data partition entry. */ 74f1317430SRui Paulo G_PART_ALIAS_LINUX_LVM, /* A Linux LVM partition entry. */ 75f1317430SRui Paulo G_PART_ALIAS_LINUX_RAID, /* A Linux RAID partition entry. */ 76f1317430SRui Paulo G_PART_ALIAS_LINUX_SWAP, /* A Linux swap partition entry. */ 779c0c355fSAllan Jude G_PART_ALIAS_MBR, /* A MBR (extended) partition entry. */ 7833f7a412SRui Paulo G_PART_ALIAS_MS_BASIC_DATA, /* A Microsoft Data part. entry. */ 799c0c355fSAllan Jude G_PART_ALIAS_MS_FAT16, /* A Microsoft FAT16 partition entry. */ 809c0c355fSAllan Jude G_PART_ALIAS_MS_FAT32, /* A Microsoft FAT32 partition entry. */ 81b525a10aSEd Maste G_PART_ALIAS_MS_FAT32LBA, /* A Microsoft FAT32 LBA partition entry */ 8233f7a412SRui Paulo G_PART_ALIAS_MS_LDM_DATA, /* A Microsoft LDM Data part. entry. */ 8333f7a412SRui Paulo G_PART_ALIAS_MS_LDM_METADATA, /* A Microsoft LDM Metadata entry. */ 84c6b2b6fcSRui Paulo G_PART_ALIAS_MS_NTFS, /* A Microsoft NTFS partition entry */ 859c0c355fSAllan Jude G_PART_ALIAS_MS_RECOVERY, /* A Microsoft recovery part. entry. */ 869c0c355fSAllan Jude G_PART_ALIAS_MS_RESERVED, /* A Microsoft Reserved part. entry. */ 879c0c355fSAllan Jude G_PART_ALIAS_MS_SPACES, /* A Microsoft Spaces part. entry. */ 8833f7a412SRui Paulo G_PART_ALIAS_NETBSD_CCD, /* A NetBSD CCD partition entry. */ 8933f7a412SRui Paulo G_PART_ALIAS_NETBSD_CGD, /* A NetBSD CGD partition entry. */ 9033f7a412SRui Paulo G_PART_ALIAS_NETBSD_FFS, /* A NetBSD FFS partition entry. */ 919c0c355fSAllan Jude G_PART_ALIAS_NETBSD_LFS, /* A NetBSD LFS partition entry. */ 9233f7a412SRui Paulo G_PART_ALIAS_NETBSD_RAID, /* A NetBSD RAID partition entry. */ 9333f7a412SRui Paulo G_PART_ALIAS_NETBSD_SWAP, /* A NetBSD swap partition entry. */ 949c0c355fSAllan Jude G_PART_ALIAS_OPENBSD_DATA, /* An OpenBSD data partition entry. */ 959c0c355fSAllan Jude G_PART_ALIAS_PREP_BOOT, /* A PREP/CHRP boot partition entry. */ 96b20e4de3SDmitry Morozovsky G_PART_ALIAS_VMFS, /* A VMware VMFS partition entry */ 97b20e4de3SDmitry Morozovsky G_PART_ALIAS_VMKDIAG, /* A VMware vmkDiagnostic partition entry */ 98b20e4de3SDmitry Morozovsky G_PART_ALIAS_VMRESERVED, /* A VMware reserved partition entry */ 995cc596c4SDmitry Morozovsky G_PART_ALIAS_VMVSANHDR, /* A VMware vSAN header partition entry */ 1001d3aed33SMarcel Moolenaar /* Keep the following last */ 1011d3aed33SMarcel Moolenaar G_PART_ALIAS_COUNT 1021d3aed33SMarcel Moolenaar }; 1031d3aed33SMarcel Moolenaar 1041d3aed33SMarcel Moolenaar const char *g_part_alias_name(enum g_part_alias); 1051d3aed33SMarcel Moolenaar 1061d3aed33SMarcel Moolenaar /* G_PART scheme (KOBJ class). */ 1071d3aed33SMarcel Moolenaar struct g_part_scheme { 1081d3aed33SMarcel Moolenaar KOBJ_CLASS_FIELDS; 1091d3aed33SMarcel Moolenaar size_t gps_entrysz; 1101d3aed33SMarcel Moolenaar int gps_minent; 1111d3aed33SMarcel Moolenaar int gps_maxent; 1124d32fcb4SMarcel Moolenaar int gps_bootcodesz; 1134ffca444SMarcel Moolenaar TAILQ_ENTRY(g_part_scheme) scheme_list; 1141d3aed33SMarcel Moolenaar }; 1151d3aed33SMarcel Moolenaar 1161d3aed33SMarcel Moolenaar struct g_part_entry { 1171d3aed33SMarcel Moolenaar LIST_ENTRY(g_part_entry) gpe_entry; 1181d3aed33SMarcel Moolenaar struct g_provider *gpe_pp; /* Corresponding provider. */ 1191d3aed33SMarcel Moolenaar off_t gpe_offset; /* Byte offset. */ 1201d3aed33SMarcel Moolenaar quad_t gpe_start; /* First LBA of partition. */ 1211d3aed33SMarcel Moolenaar quad_t gpe_end; /* Last LBA of partition. */ 1221d3aed33SMarcel Moolenaar int gpe_index; 1231d3aed33SMarcel Moolenaar int gpe_created:1; /* Entry is newly created. */ 1241d3aed33SMarcel Moolenaar int gpe_deleted:1; /* Entry has been deleted. */ 1251d3aed33SMarcel Moolenaar int gpe_modified:1; /* Entry has been modified. */ 1265aaa8fefSMarcel Moolenaar int gpe_internal:1; /* Entry is not a used entry. */ 1271d3aed33SMarcel Moolenaar }; 1281d3aed33SMarcel Moolenaar 1291d3aed33SMarcel Moolenaar /* G_PART table (KOBJ instance). */ 1301d3aed33SMarcel Moolenaar struct g_part_table { 1311d3aed33SMarcel Moolenaar KOBJ_FIELDS; 1321d3aed33SMarcel Moolenaar struct g_part_scheme *gpt_scheme; 1331d3aed33SMarcel Moolenaar struct g_geom *gpt_gp; 1341d3aed33SMarcel Moolenaar LIST_HEAD(, g_part_entry) gpt_entry; 1351d3aed33SMarcel Moolenaar quad_t gpt_first; /* First allocatable LBA */ 1361d3aed33SMarcel Moolenaar quad_t gpt_last; /* Last allocatable LBA */ 1371d3aed33SMarcel Moolenaar int gpt_entries; 1381d3aed33SMarcel Moolenaar /* 1391d3aed33SMarcel Moolenaar * gpt_smhead and gpt_smtail are bitmaps representing the first 1401d3aed33SMarcel Moolenaar * 32 sectors on the disk (gpt_smhead) and the last 32 sectors 1411d3aed33SMarcel Moolenaar * on the disk (gpt_smtail). These maps are used by the commit 1421d3aed33SMarcel Moolenaar * verb to clear sectors previously used by a scheme after the 1431d3aed33SMarcel Moolenaar * partitioning scheme has been destroyed. 1441d3aed33SMarcel Moolenaar */ 1451d3aed33SMarcel Moolenaar uint32_t gpt_smhead; 1461d3aed33SMarcel Moolenaar uint32_t gpt_smtail; 1470081f96eSMarcel Moolenaar /* 1480081f96eSMarcel Moolenaar * gpt_sectors and gpt_heads are the fixed or synchesized number 1490081f96eSMarcel Moolenaar * of sectors per track and heads (resp) that make up a disks 1500081f96eSMarcel Moolenaar * geometry. This is to support partitioning schemes as well as 1510081f96eSMarcel Moolenaar * file systems that work on a geometry. The MBR scheme and the 1520081f96eSMarcel Moolenaar * MS-DOS (FAT) file system come to mind. 1530081f96eSMarcel Moolenaar * We keep track of whether the geometry is fixed or synchesized 1540081f96eSMarcel Moolenaar * so that a partitioning scheme can correct the synthesized 1550081f96eSMarcel Moolenaar * geometry, based on the on-disk metadata. 1560081f96eSMarcel Moolenaar */ 1570081f96eSMarcel Moolenaar uint32_t gpt_sectors; 1580081f96eSMarcel Moolenaar uint32_t gpt_heads; 1591d3aed33SMarcel Moolenaar 1601d3aed33SMarcel Moolenaar int gpt_depth; /* Sub-partitioning level. */ 1611d3aed33SMarcel Moolenaar int gpt_isleaf:1; /* Cannot be sub-partitioned. */ 1621d3aed33SMarcel Moolenaar int gpt_created:1; /* Newly created. */ 1631d3aed33SMarcel Moolenaar int gpt_modified:1; /* Table changes have been made. */ 1641d3aed33SMarcel Moolenaar int gpt_opened:1; /* Permissions obtained. */ 1650081f96eSMarcel Moolenaar int gpt_fixgeom:1; /* Geometry is fixed. */ 166e7926a37SAndrey V. Elsukov int gpt_corrupt:1; /* Table is corrupt. */ 1671d3aed33SMarcel Moolenaar }; 1681d3aed33SMarcel Moolenaar 1691d3aed33SMarcel Moolenaar struct g_part_entry *g_part_new_entry(struct g_part_table *, int, quad_t, 1701d3aed33SMarcel Moolenaar quad_t); 1711d3aed33SMarcel Moolenaar 1727ca4fa83SMarcel Moolenaar enum g_part_ctl { 1737ca4fa83SMarcel Moolenaar G_PART_CTL_NONE, 1747ca4fa83SMarcel Moolenaar G_PART_CTL_ADD, 1757ca4fa83SMarcel Moolenaar G_PART_CTL_BOOTCODE, 1767ca4fa83SMarcel Moolenaar G_PART_CTL_COMMIT, 1777ca4fa83SMarcel Moolenaar G_PART_CTL_CREATE, 1787ca4fa83SMarcel Moolenaar G_PART_CTL_DELETE, 1797ca4fa83SMarcel Moolenaar G_PART_CTL_DESTROY, 1807ca4fa83SMarcel Moolenaar G_PART_CTL_MODIFY, 1817ca4fa83SMarcel Moolenaar G_PART_CTL_MOVE, 1827ca4fa83SMarcel Moolenaar G_PART_CTL_RECOVER, 1837ca4fa83SMarcel Moolenaar G_PART_CTL_RESIZE, 1847ca4fa83SMarcel Moolenaar G_PART_CTL_SET, 1857ca4fa83SMarcel Moolenaar G_PART_CTL_UNDO, 1867ca4fa83SMarcel Moolenaar G_PART_CTL_UNSET 1877ca4fa83SMarcel Moolenaar }; 1887ca4fa83SMarcel Moolenaar 1891d3aed33SMarcel Moolenaar /* G_PART ctlreq parameters. */ 1901d3aed33SMarcel Moolenaar #define G_PART_PARM_ENTRIES 0x0001 1911d3aed33SMarcel Moolenaar #define G_PART_PARM_FLAGS 0x0002 1921d3aed33SMarcel Moolenaar #define G_PART_PARM_GEOM 0x0004 1931d3aed33SMarcel Moolenaar #define G_PART_PARM_INDEX 0x0008 1941d3aed33SMarcel Moolenaar #define G_PART_PARM_LABEL 0x0010 195d287f590SMarcel Moolenaar #define G_PART_PARM_OUTPUT 0x0020 196d287f590SMarcel Moolenaar #define G_PART_PARM_PROVIDER 0x0040 197d287f590SMarcel Moolenaar #define G_PART_PARM_SCHEME 0x0080 198d287f590SMarcel Moolenaar #define G_PART_PARM_SIZE 0x0100 199d287f590SMarcel Moolenaar #define G_PART_PARM_START 0x0200 200d287f590SMarcel Moolenaar #define G_PART_PARM_TYPE 0x0400 201d287f590SMarcel Moolenaar #define G_PART_PARM_VERSION 0x0800 2024d32fcb4SMarcel Moolenaar #define G_PART_PARM_BOOTCODE 0x1000 203f6aa3fccSMarcel Moolenaar #define G_PART_PARM_ATTRIB 0x2000 204e7926a37SAndrey V. Elsukov #define G_PART_PARM_FORCE 0x4000 205*cdd2df88SDag-Erling Smørgrav #define G_PART_PARM_SKIP_DSN 0x8000 2061d3aed33SMarcel Moolenaar 2071d3aed33SMarcel Moolenaar struct g_part_parms { 2081d3aed33SMarcel Moolenaar unsigned int gpp_parms; 2091d3aed33SMarcel Moolenaar unsigned int gpp_entries; 2101d3aed33SMarcel Moolenaar const char *gpp_flags; 2111d3aed33SMarcel Moolenaar struct g_geom *gpp_geom; 2121d3aed33SMarcel Moolenaar unsigned int gpp_index; 2131d3aed33SMarcel Moolenaar const char *gpp_label; 2141d3aed33SMarcel Moolenaar struct g_provider *gpp_provider; 2151d3aed33SMarcel Moolenaar struct g_part_scheme *gpp_scheme; 2161d3aed33SMarcel Moolenaar quad_t gpp_size; 2171d3aed33SMarcel Moolenaar quad_t gpp_start; 2181d3aed33SMarcel Moolenaar const char *gpp_type; 219d287f590SMarcel Moolenaar unsigned int gpp_version; 2204d32fcb4SMarcel Moolenaar const void *gpp_codeptr; 2214d32fcb4SMarcel Moolenaar unsigned int gpp_codesize; 222f6aa3fccSMarcel Moolenaar const char *gpp_attrib; 223e7926a37SAndrey V. Elsukov unsigned int gpp_force; 224*cdd2df88SDag-Erling Smørgrav unsigned int gpp_skip_dsn; 2251d3aed33SMarcel Moolenaar }; 2261d3aed33SMarcel Moolenaar 2270081f96eSMarcel Moolenaar void g_part_geometry_heads(off_t, u_int, off_t *, u_int *); 2280081f96eSMarcel Moolenaar 2294ffca444SMarcel Moolenaar int g_part_modevent(module_t, int, struct g_part_scheme *); 2304ffca444SMarcel Moolenaar 2314ffca444SMarcel Moolenaar #define G_PART_SCHEME_DECLARE(name) \ 2324ffca444SMarcel Moolenaar static int name##_modevent(module_t mod, int tp, void *d) \ 2334ffca444SMarcel Moolenaar { \ 2344ffca444SMarcel Moolenaar return (g_part_modevent(mod, tp, d)); \ 2354ffca444SMarcel Moolenaar } \ 2364ffca444SMarcel Moolenaar static moduledata_t name##_mod = { \ 2374ffca444SMarcel Moolenaar #name, \ 2384ffca444SMarcel Moolenaar name##_modevent, \ 2394ffca444SMarcel Moolenaar &name##_scheme \ 2404ffca444SMarcel Moolenaar }; \ 2415284aff5SAndrey V. Elsukov DECLARE_MODULE(name, name##_mod, SI_SUB_DRIVERS, SI_ORDER_ANY); \ 2425284aff5SAndrey V. Elsukov MODULE_DEPEND(name, g_part, 0, 0, 0) 2434ffca444SMarcel Moolenaar 2441d3aed33SMarcel Moolenaar #endif /* !_GEOM_PART_H_ */ 245