libfdisk.h revision aa1b14e7d68925d80eebf0ce8ed0b9cc55246546
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2009 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#ifndef _LIBFDISK_H_
#define _LIBFDISK_H_
#include <limits.h>
#ifdef __cplusplus
extern "C" {
#endif
#define MAX_LOGDRIVE_OFFSET 63
#define FDISK_ERRNO 200
#define FDISK_ETOOLONG (FDISK_ERRNO + 0)
#define FDISK_SUCCESS 0
#define FDISK_READ_DISK 0x00000001
#define LINUX_SWAP_MAGIC_LENGTH 10
enum {
PHYSGEOM = 0,
NCYL,
};
enum {
FDISK_MINOR_WRITE = 1,
};
#define FDISK_SECTS_PER_CYL(epp) \
((x)/(FDISK_SECTS_PER_CYL(epp))))
/*
* Extended partition structure :
* +--------------+
* |+--+ |
* || |----------+---> structure at the beginning of the extended partition
* ||--| | ( Lets call it the EBR - Extended Boot Record )
* || | +---+--->
* |+--+ | | Logical drive within the extended partition
* |+---------+--+| ( We will plainly call this a logical drive )
* || ||
* || ||
* || ||
* |+------------+|
* +--------------+
*
*
* EBR is effectively "struct ipart parts[2]".
* The picture below shows what the EBR contains. The EBR has
* two important pieces of information. The first is the offset and the size
* of the logical drive in this extended partition. The second is the offset
* and size of the next extended partition. The offsets are relative to
* beginning of the first extended partition. These extended partitions are
* arranged like a linked list.
* Note that (currently) only one extended partition can exist in the MBR.
* The system ID of a logical drive within the extended partition cannot be
* that of an extended partition.
*
* +------+
* | |
* +--------------+ | +-v------------+
* |+--+ | | |+--+ |
* || |---+ | | || | |
* ||--| | | | ||--| |
* || |---|------+-+ || | |
* |+--+ | | |+--+ |
* |+------v-----+| |+------------+|
* || || || ||
* || || || ||
* || || || ||
* |+------------+| |+------------+|
* +--------------+ +--------------+
*
*/
/*
* Main structure used to record changes to the partitions made.
* Changes are not written to disk everytime, but maintained in this structure.
* This information is used when the user chooses to commit the changes.
* A linked list of this structure represents the ondisk partitions.
*/
typedef struct logical_drive {
/* structure holding the EBR data */
/*
* Absolute beginning sector of the extended partition, and hence an
* indicator of where the EBR for this logical drive would go on disk.
* NOTE : In case the first logical drive in this extended partition is
* out of (disk) order, this indicates the beginning of the logical
* drive. The EBR will anyway be at the first sector of the extended
* partition, for the first logical drive.
*/
/*
* Offset of the logical drive from the beginning of its extended
* partition
*/
/* Size of the logical drive in sectors */
/* Beginning and ending cylinders of the extended partition */
/*
* Flag to indicate if this record is to be sync'ed to disk.
* It takes two values : FDISK_MAJOR_WRITE and FDISK_MINOR_WRITE
* If it is a minor write, there is no need to update the information
* in the kernel structures. Example of a minor write is correction of
* a corrupt boot signature.
*/
int modified;
/*
* This pointer points to the next extended partition in the order
* found on disk.
*/
struct logical_drive *next;
/*
* This pointer points to the next extended partition in a sorted list
* sorted in the ascending order of their beginning cylinders.
*/
struct logical_drive *sorted_next;
typedef struct fdisk_disk_geom {
typedef struct ext_part
{
/* Structure holding geometry information about the device */
char device_name[PATH_MAX];
int dev_fd;
int op_flag;
/*
* Head of the in memory structure (singly linked list) of extended
* partition information.
*/
/* Beginning cylinder of the extended partition */
/* Ending cylinder of the extended partition */
/* Beginning sector of the extended partition */
/* Ending sector of the extended partition */
/* Count of the number of logical drives in the extended partition */
int logical_drive_count;
/*
* Flag to keep track of the update to be made to the Extended Boot
* Record (EBR) when all logical drives are deleted. The EBR is filled
* with zeroes in such a case.
*/
int first_ebr_is_null;
/*
* Flag to indicate corrupt logical drives. Can happen when a partition
* manager creates an extended partition and does not null the first EBR
* or when important ondisk structures are overwritten by a bad program
*/
/*
* The boot block signature 0xAA55 might not be found on some of the
* EBRs. ( Even though the rest of the data might be good )
* The following array is used to store the list of such logical drive
* numbers.
*/
/*
* Can add a "next" pointer here in case support for multiple
* extended partitions becomes the standard someday.
*
* struct ext_part *next;
*/
} ext_part_t;
off_t *lsm_offset);
int opflag);
#ifdef __cplusplus
}
#endif
#endif /* _LIBFDISK_H_ */