1N/A/*
1N/A libparted - a library for manipulating disk partitions
1N/A Copyright (C) 1999-2002, 2007-2010 Free Software Foundation, Inc.
1N/A
1N/A This program is free software; you can redistribute it and/or modify
1N/A it under the terms of the GNU General Public License as published by
1N/A the Free Software Foundation; either version 3 of the License, or
1N/A (at your option) any later version.
1N/A
1N/A This program is distributed in the hope that it will be useful,
1N/A but WITHOUT ANY WARRANTY; without even the implied warranty of
1N/A MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1N/A GNU General Public License for more details.
1N/A
1N/A You should have received a copy of the GNU General Public License
1N/A along with this program. If not, see <http://www.gnu.org/licenses/>.
1N/A*/
1N/A
1N/A/**
1N/A * \addtogroup PedDisk
1N/A * @{
1N/A */
1N/A
1N/A/** \file disk.h */
1N/A
1N/A#ifndef PED_DISK_H_INCLUDED
1N/A#define PED_DISK_H_INCLUDED
1N/A
1N/A/**
1N/A * Disk flags
1N/A */
1N/Aenum _PedDiskFlag {
1N/A /* This flag (which defaults to true) controls if disk types for
1N/A which cylinder alignment is optional do cylinder alignment when a
1N/A new partition gets added.
1N/A This flag is available for msdos and sun disklabels (for sun labels
1N/A it only controls the aligning of the end of the partition) */
1N/A PED_DISK_CYLINDER_ALIGNMENT=1,
1N/A};
1N/A#define PED_DISK_FIRST_FLAG PED_DISK_CYLINDER_ALIGNMENT
1N/A#define PED_DISK_LAST_FLAG PED_DISK_CYLINDER_ALIGNMENT
1N/A
1N/A/**
1N/A * Partition types
1N/A */
1N/Aenum _PedPartitionType {
1N/A PED_PARTITION_NORMAL = 0x00,
1N/A PED_PARTITION_LOGICAL = 0x01,
1N/A PED_PARTITION_EXTENDED = 0x02,
1N/A PED_PARTITION_FREESPACE = 0x04,
1N/A PED_PARTITION_METADATA = 0x08,
1N/A PED_PARTITION_PROTECTED = 0x10
1N/A};
1N/A
1N/A/**
1N/A * Partition flags.
1N/A */
1N/Aenum _PedPartitionFlag {
1N/A PED_PARTITION_BOOT=1,
1N/A PED_PARTITION_ROOT=2,
1N/A PED_PARTITION_SWAP=3,
1N/A PED_PARTITION_HIDDEN=4,
1N/A PED_PARTITION_RAID=5,
1N/A PED_PARTITION_LVM=6,
1N/A PED_PARTITION_LBA=7,
1N/A PED_PARTITION_HPSERVICE=8,
1N/A PED_PARTITION_PALO=9,
1N/A PED_PARTITION_PREP=10,
1N/A PED_PARTITION_MSFT_RESERVED=11,
1N/A PED_PARTITION_BIOS_GRUB=12,
1N/A PED_PARTITION_APPLE_TV_RECOVERY=13,
1N/A PED_PARTITION_DIAG=14
1N/A};
1N/A#define PED_PARTITION_FIRST_FLAG PED_PARTITION_BOOT
1N/A#define PED_PARTITION_LAST_FLAG PED_PARTITION_DIAG
1N/A
1N/Aenum _PedDiskTypeFeature {
1N/A PED_DISK_TYPE_EXTENDED=1, /**< supports extended partitions */
1N/A PED_DISK_TYPE_PARTITION_NAME=2 /**< supports partition names */
1N/A};
1N/A#define PED_DISK_TYPE_FIRST_FEATURE PED_DISK_TYPE_EXTENDED
1N/A#define PED_DISK_TYPE_LAST_FEATURE PED_DISK_TYPE_PARTITION_NAME
1N/A
1N/Astruct _PedDisk;
1N/Astruct _PedPartition;
1N/Astruct _PedDiskOps;
1N/Astruct _PedDiskType;
1N/Astruct _PedDiskArchOps;
1N/A
1N/Atypedef enum _PedDiskFlag PedDiskFlag;
1N/Atypedef enum _PedPartitionType PedPartitionType;
1N/Atypedef enum _PedPartitionFlag PedPartitionFlag;
1N/Atypedef enum _PedDiskTypeFeature PedDiskTypeFeature;
1N/Atypedef struct _PedDisk PedDisk;
1N/Atypedef struct _PedPartition PedPartition;
1N/Atypedef const struct _PedDiskOps PedDiskOps;
1N/Atypedef struct _PedDiskType PedDiskType;
1N/Atypedef const struct _PedDiskArchOps PedDiskArchOps;
1N/A
1N/A#include <parted/device.h>
1N/A#include <parted/filesys.h>
1N/A#include <parted/natmath.h>
1N/A#include <parted/geom.h>
1N/A#include <stdbool.h>
1N/A
1N/A/** @} */
1N/A
1N/A/**
1N/A * \addtogroup PedPartition
1N/A *
1N/A * @{
1N/A */
1N/A
1N/A/** \file disk.h */
1N/A
1N/A/**
1N/A * PedPartition structure represents a partition.
1N/A */
1N/Astruct _PedPartition {
1N/A PedPartition* prev;
1N/A PedPartition* next;
1N/A
1N/A /**< the partition table of the partition */
1N/A PedDisk* disk;
1N/A PedGeometry geom; /**< geometry of the partition */
1N/A
1N/A /**< the partition number: In Linux, this is the
1N/A same as the minor number. No assumption
1N/A should be made about "num" and "type"
1N/A - different disk labels have different rules. */
1N/A
1N/A int num;
1N/A PedPartitionType type; /**< the type of partition: a bit field of
1N/A PED_PARTITION_LOGICAL, PED_PARTITION_EXTENDED,
1N/A PED_PARTITION_METADATA
1N/A and PED_PARTITION_FREESPACE.
1N/A Both the first two, and the last two are
1N/A mutually exclusive.
1N/A An extended partition is a primary
1N/A partition that may contain logical partitions.
1N/A There is at most one extended partition on
1N/A a disk.
1N/A A logical partition is like a primary
1N/A partition, except it's inside an extended
1N/A partition. Internally, pseudo partitions are
1N/A allocated to represent free space, or disk
1N/A label meta-data. These have the
1N/A PED_PARTITION_FREESPACE or
1N/A PED_PARTITION_METADATA bit set. */
1N/A
1N/A /**< The type of file system on the partition. NULL if unknown. */
1N/A const PedFileSystemType* fs_type;
1N/A
1N/A /**< Only used for an extended partition. The list of logical
1N/A partitions (and free space and metadata within the extended
1N/A partition). */
1N/A PedPartition* part_list;
1N/A
1N/A void* disk_specific;
1N/A};
1N/A
1N/A/** @} */
1N/A
1N/A/**
1N/A * \addtogroup PedDisk
1N/A * @{
1N/A */
1N/A
1N/A/**
1N/A * Represents a disk label (partition table).
1N/A */
1N/Astruct _PedDisk {
1N/A PedDevice* dev; /**< the device where the
1N/A partition table lies */
1N/A const PedDiskType* type; /**< type of disk label */
1N/A const int* block_sizes; /**< block sizes supported
1N/A by this label */
1N/A PedPartition* part_list; /**< list of partitions. Access with
1N/A ped_disk_next_partition() */
1N/A
1N/A void* disk_specific;
1N/A
1N/A/* office use only ;-) */
1N/A int needs_clobber; /**< clobber before write? */
1N/A int update_mode; /**< mode without free/metadata
1N/A partitions, for easier
1N/A update */
1N/A};
1N/A
1N/Astruct _PedDiskOps {
1N/A /* disk label operations */
1N/A int (*probe) (const PedDevice *dev);
1N/A int (*clobber) (PedDevice* dev);
1N/A PedDisk* (*alloc) (const PedDevice* dev);
1N/A PedDisk* (*duplicate) (const PedDisk* disk);
1N/A void (*free) (PedDisk* disk);
1N/A int (*read) (PedDisk* disk);
1N/A int (*write) (const PedDisk* disk);
1N/A int (*disk_set_flag) (
1N/A PedDisk *disk,
1N/A PedDiskFlag flag,
1N/A int state);
1N/A int (*disk_get_flag) (
1N/A const PedDisk *disk,
1N/A PedDiskFlag flag);
1N/A int (*disk_is_flag_available) (
1N/A const PedDisk *disk,
1N/A PedDiskFlag flag);
1N/A /** \todo add label guessing op here */
1N/A
1N/A /* partition operations */
1N/A PedPartition* (*partition_new) (
1N/A const PedDisk* disk,
1N/A PedPartitionType part_type,
1N/A const PedFileSystemType* fs_type,
1N/A PedSector start,
1N/A PedSector end);
1N/A PedPartition* (*partition_duplicate) (const PedPartition* part);
1N/A void (*partition_destroy) (PedPartition* part);
1N/A int (*partition_set_system) (PedPartition* part,
1N/A const PedFileSystemType* fs_type);
1N/A int (*partition_set_flag) (
1N/A PedPartition* part,
1N/A PedPartitionFlag flag,
1N/A int state);
1N/A int (*partition_get_flag) (
1N/A const PedPartition* part,
1N/A PedPartitionFlag flag);
1N/A int (*partition_is_flag_available) (
1N/A const PedPartition* part,
1N/A PedPartitionFlag flag);
1N/A void (*partition_set_name) (PedPartition* part, const char* name);
1N/A const char* (*partition_get_name) (const PedPartition* part);
1N/A int (*partition_align) (PedPartition* part,
1N/A const PedConstraint* constraint);
1N/A int (*partition_enumerate) (PedPartition* part);
1N/A bool (*partition_check) (const PedPartition* part);
1N/A
1N/A /* other */
1N/A int (*alloc_metadata) (PedDisk* disk);
1N/A int (*get_max_primary_partition_count) (const PedDisk* disk);
1N/A bool (*get_max_supported_partition_count) (const PedDisk* disk,
1N/A int* supported);
1N/A PedAlignment *(*get_partition_alignment)(const PedDisk *disk);
1N/A PedSector (*max_length) (void);
1N/A PedSector (*max_start_sector) (void);
1N/A};
1N/A
1N/Astruct _PedDiskType {
1N/A PedDiskType* next;
1N/A const char* name; /**< the name of the partition table type.
1N/A \todo not very intuitive name */
1N/A PedDiskOps* const ops;
1N/A
1N/A PedDiskTypeFeature features; /**< bitmap of supported features */
1N/A};
1N/A
1N/A/**
1N/A * Architecture-specific operations. i.e. communication with kernel (or
1N/A * whatever) about changes, etc.
1N/A */
1N/Astruct _PedDiskArchOps {
1N/A char* (*partition_get_path) (const PedPartition* part);
1N/A int (*partition_is_busy) (const PedPartition* part);
1N/A int (*disk_commit) (PedDisk* disk);
1N/A};
1N/A
1N/Aextern void ped_disk_type_register (PedDiskType* type);
1N/Aextern void ped_disk_type_unregister (PedDiskType* type);
1N/A
1N/Aextern PedDiskType* ped_disk_type_get_next (PedDiskType const *type);
1N/Aextern PedDiskType* ped_disk_type_get (const char* name);
1N/Aextern int ped_disk_type_check_feature (const PedDiskType* disk_type,
1N/A PedDiskTypeFeature feature);
1N/A
1N/Aextern PedDiskType* ped_disk_probe (PedDevice* dev);
1N/Aextern int ped_disk_clobber (PedDevice* dev);
1N/Aextern PedDisk* ped_disk_new (PedDevice* dev);
1N/Aextern PedDisk* ped_disk_new_fresh (PedDevice* dev,
1N/A const PedDiskType* disk_type);
1N/Aextern PedDisk* ped_disk_duplicate (const PedDisk* old_disk);
1N/Aextern void ped_disk_destroy (PedDisk* disk);
1N/Aextern int ped_disk_commit (PedDisk* disk);
1N/Aextern int ped_disk_commit_to_dev (PedDisk* disk);
1N/Aextern int ped_disk_commit_to_os (PedDisk* disk);
1N/Aextern int ped_disk_check (const PedDisk* disk);
1N/Aextern void ped_disk_print (const PedDisk* disk);
1N/A
1N/Aextern int ped_disk_get_primary_partition_count (const PedDisk* disk);
1N/Aextern int ped_disk_get_last_partition_num (const PedDisk* disk);
1N/Aextern int ped_disk_get_max_primary_partition_count (const PedDisk* disk);
1N/Aextern bool ped_disk_get_max_supported_partition_count(const PedDisk* disk,
1N/A int* supported);
1N/Aextern PedAlignment *ped_disk_get_partition_alignment(const PedDisk *disk);
1N/A
1N/Aextern int ped_disk_set_flag(PedDisk *disk, PedDiskFlag flag, int state);
1N/Aextern int ped_disk_get_flag(const PedDisk *disk, PedDiskFlag flag);
1N/Aextern int ped_disk_is_flag_available(const PedDisk *disk, PedDiskFlag flag);
1N/A
1N/Aextern const char *ped_disk_flag_get_name(PedDiskFlag flag);
1N/Aextern PedDiskFlag ped_disk_flag_get_by_name(const char *name);
1N/Aextern PedDiskFlag ped_disk_flag_next(PedDiskFlag flag);
1N/A
1N/A/** @} */
1N/A
1N/A/**
1N/A * \addtogroup PedPartition
1N/A *
1N/A * @{
1N/A */
1N/A
1N/Aextern PedPartition* ped_partition_new (const PedDisk* disk,
1N/A PedPartitionType type,
1N/A const PedFileSystemType* fs_type,
1N/A PedSector start,
1N/A PedSector end);
1N/Aextern void ped_partition_destroy (PedPartition* part);
1N/Aextern int ped_partition_is_active (const PedPartition* part);
1N/Aextern int ped_partition_set_flag (PedPartition* part, PedPartitionFlag flag,
1N/A int state);
1N/Aextern int ped_partition_get_flag (const PedPartition* part,
1N/A PedPartitionFlag flag);
1N/Aextern int ped_partition_is_flag_available (const PedPartition* part,
1N/A PedPartitionFlag flag);
1N/Aextern int ped_partition_set_system (PedPartition* part,
1N/A const PedFileSystemType* fs_type);
1N/Aextern int ped_partition_set_name (PedPartition* part, const char* name);
1N/Aextern const char* ped_partition_get_name (const PedPartition* part);
1N/Aextern int ped_partition_is_busy (const PedPartition* part);
1N/Aextern char* ped_partition_get_path (const PedPartition* part);
1N/A
1N/Aextern const char* ped_partition_type_get_name (PedPartitionType part_type);
1N/Aextern const char* ped_partition_flag_get_name (PedPartitionFlag flag);
1N/Aextern PedPartitionFlag ped_partition_flag_get_by_name (const char* name);
1N/Aextern PedPartitionFlag ped_partition_flag_next (PedPartitionFlag flag);
1N/A
1N/A/** @} */
1N/A
1N/A/**
1N/A * \addtogroup PedDisk
1N/A * @{
1N/A */
1N/A
1N/Aextern int ped_disk_add_partition (PedDisk* disk, PedPartition* part,
1N/A const PedConstraint* constraint);
1N/Aextern int ped_disk_remove_partition (PedDisk* disk, PedPartition* part);
1N/Aextern int ped_disk_delete_partition (PedDisk* disk, PedPartition* part);
1N/Aextern int ped_disk_delete_all (PedDisk* disk);
1N/Aextern int ped_disk_set_partition_geom (PedDisk* disk, PedPartition* part,
1N/A const PedConstraint* constraint,
1N/A PedSector start, PedSector end);
1N/Aextern int ped_disk_maximize_partition (PedDisk* disk, PedPartition* part,
1N/A const PedConstraint* constraint);
1N/Aextern PedGeometry* ped_disk_get_max_partition_geometry (PedDisk* disk,
1N/A PedPartition* part, const PedConstraint* constraint);
1N/Aextern int ped_disk_minimize_extended_partition (PedDisk* disk);
1N/A
1N/Aextern PedPartition* ped_disk_next_partition (const PedDisk* disk,
1N/A const PedPartition* part);
1N/Aextern PedPartition* ped_disk_get_partition (const PedDisk* disk, int num);
1N/Aextern PedPartition* ped_disk_get_partition_by_sector (const PedDisk* disk,
1N/A PedSector sect);
1N/Aextern PedPartition* ped_disk_extended_partition (const PedDisk* disk);
1N/A
1N/Aextern PedSector ped_disk_max_partition_length (const PedDisk *disk);
1N/Aextern PedSector ped_disk_max_partition_start_sector (const PedDisk *disk);
1N/A
1N/A/* internal functions */
1N/Aextern PedDisk* _ped_disk_alloc (const PedDevice* dev, const PedDiskType* type);
1N/Aextern void _ped_disk_free (PedDisk* disk);
1N/A
1N/A
1N/A/** @} */
1N/A
1N/A/**
1N/A * \addtogroup PedPartition
1N/A *
1N/A * @{
1N/A */
1N/A
1N/Aextern PedPartition* _ped_partition_alloc (const PedDisk* disk,
1N/A PedPartitionType type,
1N/A const PedFileSystemType* fs_type,
1N/A PedSector start,
1N/A PedSector end);
1N/Aextern void _ped_partition_free (PedPartition* part);
1N/A
1N/Aextern int _ped_partition_attempt_align (
1N/A PedPartition* part, const PedConstraint* external,
1N/A PedConstraint* internal);
1N/A
1N/A#endif /* PED_DISK_H_INCLUDED */
1N/A
1N/A/** @} */