xref: /freebsd/sys/geom/part/g_part.h (revision f13174303d43685d1f0134c4cf4e9827eccdd2fa)
11d3aed33SMarcel Moolenaar /*-
2f6aa3fccSMarcel Moolenaar  * Copyright (c) 2006-2008 Marcel Moolenaar
31d3aed33SMarcel Moolenaar  * All rights reserved.
41d3aed33SMarcel Moolenaar  *
51d3aed33SMarcel Moolenaar  * Redistribution and use in source and binary forms, with or without
61d3aed33SMarcel Moolenaar  * modification, are permitted provided that the following conditions
71d3aed33SMarcel Moolenaar  * are met:
81d3aed33SMarcel Moolenaar  *
91d3aed33SMarcel Moolenaar  * 1. Redistributions of source code must retain the above copyright
101d3aed33SMarcel Moolenaar  *    notice, this list of conditions and the following disclaimer.
111d3aed33SMarcel Moolenaar  * 2. Redistributions in binary form must reproduce the above copyright
121d3aed33SMarcel Moolenaar  *    notice, this list of conditions and the following disclaimer in the
131d3aed33SMarcel Moolenaar  *    documentation and/or other materials provided with the distribution.
141d3aed33SMarcel Moolenaar  *
151d3aed33SMarcel Moolenaar  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
161d3aed33SMarcel Moolenaar  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
171d3aed33SMarcel Moolenaar  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
181d3aed33SMarcel Moolenaar  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
191d3aed33SMarcel Moolenaar  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
201d3aed33SMarcel Moolenaar  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
211d3aed33SMarcel Moolenaar  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
221d3aed33SMarcel Moolenaar  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
231d3aed33SMarcel Moolenaar  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
241d3aed33SMarcel Moolenaar  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
251d3aed33SMarcel Moolenaar  *
261d3aed33SMarcel Moolenaar  * $FreeBSD$
271d3aed33SMarcel Moolenaar  */
281d3aed33SMarcel Moolenaar 
291d3aed33SMarcel Moolenaar #ifndef _GEOM_PART_H_
301d3aed33SMarcel Moolenaar #define	_GEOM_PART_H_
311d3aed33SMarcel Moolenaar 
321d3aed33SMarcel Moolenaar #define	G_PART_TRACE(args)	g_trace args
331d3aed33SMarcel Moolenaar 
341d3aed33SMarcel Moolenaar #define G_PART_PROBE_PRI_LOW	-10
351d3aed33SMarcel Moolenaar #define	G_PART_PROBE_PRI_NORM	-5
361d3aed33SMarcel Moolenaar #define	G_PART_PROBE_PRI_HIGH	0
371d3aed33SMarcel Moolenaar 
381d3aed33SMarcel Moolenaar enum g_part_alias {
39f1317430SRui Paulo 	G_PART_ALIAS_APPLE_BOOT,	/* An Apple boot partition entry. */
40f1317430SRui Paulo 	G_PART_ALIAS_APPLE_HFS,		/* An HFS+ file system entry. */
41f1317430SRui Paulo 	G_PART_ALIAS_APPLE_LABEL,	/* An Apple label partition entry. */
42f1317430SRui Paulo 	G_PART_ALIAS_APPLE_RAID,	/* An Apple RAID partition entry. */
43f1317430SRui Paulo 	G_PART_ALIAS_APPLE_RAID_OFFLINE,/* An Apple RAID (offline) part entry.*/
44f1317430SRui Paulo 	G_PART_ALIAS_APPLE_TV_RECOVERY,	/* An Apple TV recovery part entry. */
45f1317430SRui Paulo 	G_PART_ALIAS_APPLE_UFS,		/* An Apple UFS partition entry. */
461d3aed33SMarcel Moolenaar 	G_PART_ALIAS_EFI,		/* A EFI system partition entry. */
471d3aed33SMarcel Moolenaar 	G_PART_ALIAS_FREEBSD,		/* A BSD labeled partition entry. */
48f352a0d4SJohn Baldwin 	G_PART_ALIAS_FREEBSD_BOOT,	/* A FreeBSD boot partition entry. */
491d3aed33SMarcel Moolenaar 	G_PART_ALIAS_FREEBSD_SWAP,	/* A swap partition entry. */
501d3aed33SMarcel Moolenaar 	G_PART_ALIAS_FREEBSD_UFS,	/* A UFS/UFS2 file system entry. */
511d3aed33SMarcel Moolenaar 	G_PART_ALIAS_FREEBSD_VINUM,	/* A Vinum partition entry. */
52a1fedf91SMarcel Moolenaar 	G_PART_ALIAS_FREEBSD_ZFS,	/* A ZFS file system entry. */
531d3aed33SMarcel Moolenaar 	G_PART_ALIAS_MBR,		/* A MBR (extended) partition entry. */
54f1317430SRui Paulo 	G_PART_ALIAS_LINUX_DATA,	/* A Linux data partition entry. */
55f1317430SRui Paulo 	G_PART_ALIAS_LINUX_LVM,		/* A Linux LVM partition entry. */
56f1317430SRui Paulo 	G_PART_ALIAS_LINUX_RAID,	/* A Linux RAID partition entry. */
57f1317430SRui Paulo 	G_PART_ALIAS_LINUX_SWAP,	/* A Linux swap partition entry. */
581d3aed33SMarcel Moolenaar 	/* Keep the following last */
591d3aed33SMarcel Moolenaar 	G_PART_ALIAS_COUNT
601d3aed33SMarcel Moolenaar };
611d3aed33SMarcel Moolenaar 
621d3aed33SMarcel Moolenaar const char *g_part_alias_name(enum g_part_alias);
631d3aed33SMarcel Moolenaar 
641d3aed33SMarcel Moolenaar /* G_PART scheme (KOBJ class). */
651d3aed33SMarcel Moolenaar struct g_part_scheme {
661d3aed33SMarcel Moolenaar 	KOBJ_CLASS_FIELDS;
671d3aed33SMarcel Moolenaar 	size_t		gps_entrysz;
681d3aed33SMarcel Moolenaar 	int		gps_minent;
691d3aed33SMarcel Moolenaar 	int		gps_maxent;
704d32fcb4SMarcel Moolenaar 	int		gps_bootcodesz;
714ffca444SMarcel Moolenaar 	TAILQ_ENTRY(g_part_scheme) scheme_list;
721d3aed33SMarcel Moolenaar };
731d3aed33SMarcel Moolenaar 
741d3aed33SMarcel Moolenaar struct g_part_entry {
751d3aed33SMarcel Moolenaar 	LIST_ENTRY(g_part_entry) gpe_entry;
761d3aed33SMarcel Moolenaar 	struct g_provider *gpe_pp;	/* Corresponding provider. */
771d3aed33SMarcel Moolenaar 	off_t		gpe_offset;	/* Byte offset. */
781d3aed33SMarcel Moolenaar 	quad_t		gpe_start;	/* First LBA of partition. */
791d3aed33SMarcel Moolenaar 	quad_t		gpe_end;	/* Last LBA of partition. */
801d3aed33SMarcel Moolenaar 	int		gpe_index;
811d3aed33SMarcel Moolenaar 	int		gpe_created:1;	/* Entry is newly created. */
821d3aed33SMarcel Moolenaar 	int		gpe_deleted:1;	/* Entry has been deleted. */
831d3aed33SMarcel Moolenaar 	int		gpe_modified:1;	/* Entry has been modified. */
845aaa8fefSMarcel Moolenaar 	int		gpe_internal:1;	/* Entry is not a used entry. */
851d3aed33SMarcel Moolenaar };
861d3aed33SMarcel Moolenaar 
871d3aed33SMarcel Moolenaar /* G_PART table (KOBJ instance). */
881d3aed33SMarcel Moolenaar struct g_part_table {
891d3aed33SMarcel Moolenaar 	KOBJ_FIELDS;
901d3aed33SMarcel Moolenaar 	struct g_part_scheme *gpt_scheme;
911d3aed33SMarcel Moolenaar 	struct g_geom	*gpt_gp;
921d3aed33SMarcel Moolenaar 	LIST_HEAD(, g_part_entry) gpt_entry;
931d3aed33SMarcel Moolenaar 	quad_t		gpt_first;	/* First allocatable LBA */
941d3aed33SMarcel Moolenaar 	quad_t		gpt_last;	/* Last allocatable LBA */
951d3aed33SMarcel Moolenaar 	int		gpt_entries;
961d3aed33SMarcel Moolenaar 	/*
971d3aed33SMarcel Moolenaar 	 * gpt_smhead and gpt_smtail are bitmaps representing the first
981d3aed33SMarcel Moolenaar 	 * 32 sectors on the disk (gpt_smhead) and the last 32 sectors
991d3aed33SMarcel Moolenaar 	 * on the disk (gpt_smtail). These maps are used by the commit
1001d3aed33SMarcel Moolenaar 	 * verb to clear sectors previously used by a scheme after the
1011d3aed33SMarcel Moolenaar 	 * partitioning scheme has been destroyed.
1021d3aed33SMarcel Moolenaar 	 */
1031d3aed33SMarcel Moolenaar 	uint32_t	gpt_smhead;
1041d3aed33SMarcel Moolenaar 	uint32_t	gpt_smtail;
1050081f96eSMarcel Moolenaar 	/*
1060081f96eSMarcel Moolenaar 	 * gpt_sectors and gpt_heads are the fixed or synchesized number
1070081f96eSMarcel Moolenaar 	 * of sectors per track and heads (resp) that make up a disks
1080081f96eSMarcel Moolenaar 	 * geometry. This is to support partitioning schemes as well as
1090081f96eSMarcel Moolenaar 	 * file systems that work on a geometry. The MBR scheme and the
1100081f96eSMarcel Moolenaar 	 * MS-DOS (FAT) file system come to mind.
1110081f96eSMarcel Moolenaar 	 * We keep track of whether the geometry is fixed or synchesized
1120081f96eSMarcel Moolenaar 	 * so that a partitioning scheme can correct the synthesized
1130081f96eSMarcel Moolenaar 	 * geometry, based on the on-disk metadata.
1140081f96eSMarcel Moolenaar 	 */
1150081f96eSMarcel Moolenaar 	uint32_t	gpt_sectors;
1160081f96eSMarcel Moolenaar 	uint32_t	gpt_heads;
1171d3aed33SMarcel Moolenaar 
1181d3aed33SMarcel Moolenaar 	int		gpt_depth;	/* Sub-partitioning level. */
1191d3aed33SMarcel Moolenaar 	int		gpt_isleaf:1;	/* Cannot be sub-partitioned. */
1201d3aed33SMarcel Moolenaar 	int		gpt_created:1;	/* Newly created. */
1211d3aed33SMarcel Moolenaar 	int		gpt_modified:1;	/* Table changes have been made. */
1221d3aed33SMarcel Moolenaar 	int		gpt_opened:1;	/* Permissions obtained. */
1230081f96eSMarcel Moolenaar 	int		gpt_fixgeom:1;	/* Geometry is fixed. */
1241d3aed33SMarcel Moolenaar };
1251d3aed33SMarcel Moolenaar 
1261d3aed33SMarcel Moolenaar struct g_part_entry *g_part_new_entry(struct g_part_table *, int, quad_t,
1271d3aed33SMarcel Moolenaar     quad_t);
1281d3aed33SMarcel Moolenaar 
1297ca4fa83SMarcel Moolenaar enum g_part_ctl {
1307ca4fa83SMarcel Moolenaar 	G_PART_CTL_NONE,
1317ca4fa83SMarcel Moolenaar 	G_PART_CTL_ADD,
1327ca4fa83SMarcel Moolenaar 	G_PART_CTL_BOOTCODE,
1337ca4fa83SMarcel Moolenaar 	G_PART_CTL_COMMIT,
1347ca4fa83SMarcel Moolenaar 	G_PART_CTL_CREATE,
1357ca4fa83SMarcel Moolenaar 	G_PART_CTL_DELETE,
1367ca4fa83SMarcel Moolenaar 	G_PART_CTL_DESTROY,
1377ca4fa83SMarcel Moolenaar 	G_PART_CTL_MODIFY,
1387ca4fa83SMarcel Moolenaar 	G_PART_CTL_MOVE,
1397ca4fa83SMarcel Moolenaar 	G_PART_CTL_RECOVER,
1407ca4fa83SMarcel Moolenaar 	G_PART_CTL_RESIZE,
1417ca4fa83SMarcel Moolenaar 	G_PART_CTL_SET,
1427ca4fa83SMarcel Moolenaar 	G_PART_CTL_UNDO,
1437ca4fa83SMarcel Moolenaar 	G_PART_CTL_UNSET
1447ca4fa83SMarcel Moolenaar };
1457ca4fa83SMarcel Moolenaar 
1461d3aed33SMarcel Moolenaar /* G_PART ctlreq parameters. */
1471d3aed33SMarcel Moolenaar #define	G_PART_PARM_ENTRIES	0x0001
1481d3aed33SMarcel Moolenaar #define	G_PART_PARM_FLAGS	0x0002
1491d3aed33SMarcel Moolenaar #define	G_PART_PARM_GEOM	0x0004
1501d3aed33SMarcel Moolenaar #define	G_PART_PARM_INDEX	0x0008
1511d3aed33SMarcel Moolenaar #define	G_PART_PARM_LABEL	0x0010
152d287f590SMarcel Moolenaar #define	G_PART_PARM_OUTPUT	0x0020
153d287f590SMarcel Moolenaar #define	G_PART_PARM_PROVIDER	0x0040
154d287f590SMarcel Moolenaar #define	G_PART_PARM_SCHEME	0x0080
155d287f590SMarcel Moolenaar #define	G_PART_PARM_SIZE	0x0100
156d287f590SMarcel Moolenaar #define	G_PART_PARM_START	0x0200
157d287f590SMarcel Moolenaar #define	G_PART_PARM_TYPE	0x0400
158d287f590SMarcel Moolenaar #define	G_PART_PARM_VERSION	0x0800
1594d32fcb4SMarcel Moolenaar #define	G_PART_PARM_BOOTCODE	0x1000
160f6aa3fccSMarcel Moolenaar #define	G_PART_PARM_ATTRIB	0x2000
1611d3aed33SMarcel Moolenaar 
1621d3aed33SMarcel Moolenaar struct g_part_parms {
1631d3aed33SMarcel Moolenaar 	unsigned int	gpp_parms;
1641d3aed33SMarcel Moolenaar 	unsigned int	gpp_entries;
1651d3aed33SMarcel Moolenaar 	const char	*gpp_flags;
1661d3aed33SMarcel Moolenaar 	struct g_geom	*gpp_geom;
1671d3aed33SMarcel Moolenaar 	unsigned int	gpp_index;
1681d3aed33SMarcel Moolenaar 	const char	*gpp_label;
1691d3aed33SMarcel Moolenaar 	struct g_provider *gpp_provider;
1701d3aed33SMarcel Moolenaar 	struct g_part_scheme *gpp_scheme;
1711d3aed33SMarcel Moolenaar 	quad_t		gpp_size;
1721d3aed33SMarcel Moolenaar 	quad_t		gpp_start;
1731d3aed33SMarcel Moolenaar 	const char	*gpp_type;
174d287f590SMarcel Moolenaar 	unsigned int	gpp_version;
1754d32fcb4SMarcel Moolenaar 	const void	*gpp_codeptr;
1764d32fcb4SMarcel Moolenaar 	unsigned int	gpp_codesize;
177f6aa3fccSMarcel Moolenaar 	const char	*gpp_attrib;
1781d3aed33SMarcel Moolenaar };
1791d3aed33SMarcel Moolenaar 
1800081f96eSMarcel Moolenaar void g_part_geometry_heads(off_t, u_int, off_t *, u_int *);
1810081f96eSMarcel Moolenaar 
1824ffca444SMarcel Moolenaar int g_part_modevent(module_t, int, struct g_part_scheme *);
1834ffca444SMarcel Moolenaar 
1844ffca444SMarcel Moolenaar #define	G_PART_SCHEME_DECLARE(name)				\
1854ffca444SMarcel Moolenaar     static int name##_modevent(module_t mod, int tp, void *d)	\
1864ffca444SMarcel Moolenaar     {								\
1874ffca444SMarcel Moolenaar 	return (g_part_modevent(mod, tp, d));			\
1884ffca444SMarcel Moolenaar     }								\
1894ffca444SMarcel Moolenaar     static moduledata_t name##_mod = {				\
1904ffca444SMarcel Moolenaar 	#name,							\
1914ffca444SMarcel Moolenaar 	name##_modevent,					\
1924ffca444SMarcel Moolenaar 	&name##_scheme						\
1934ffca444SMarcel Moolenaar     };								\
194e0fbffe6SMarcel Moolenaar     DECLARE_MODULE(name, name##_mod, SI_SUB_DRIVERS, SI_ORDER_ANY)
1954ffca444SMarcel Moolenaar 
1961d3aed33SMarcel Moolenaar #endif /* !_GEOM_PART_H_ */
197