VxWorks API Reference : OS Libraries

usrFdiskPartLib

NAME

usrFdiskPartLib - FDISK-style partition handler

ROUTINES

usrFdiskPartRead( ) - read an FDISK-style partition table
usrFdiskPartCreate( ) - create an FDISK-like partition table on a disk
usrFdiskPartShow( ) - parse and display partition data

DESCRIPTION

This module is provided is source code to accommodate various customizations of partition table handling, resulting from variations in the partition table format in a particular configuration. It is intended for use with dpartCbio partition manager.

This code supports both mounting MSDOS file systems and displaying partition tables written by MSDOS FDISK.exe or by any other MSDOS FDISK.exe compatible partitioning software.

The first partition table is contained within a hard drives Master Boot Record (MBR) sector, which is defined as sector one, cylinder zero, head zero or logical block address zero.

The mounting and displaying routines within this code will first parse the MBR partition tables entries (defined below) and also recursively parse any "extended" partition tables, which may reside within another sector further into the hard disk. MSDOS file systems within extended partitions are known to those familiar with the MSDOS FDISK.exe utility as "Logical drives within the extended partition".

Here is a picture showing the layout of a single disk containing multiple MSDOS file systems:

  +---------------------------------------------------------+
  |<---------------------The entire disk------------------->|
  |M                                                        |
  |B<---C:--->                                              |
  |R           /---- First extended partition--------------\|
  |           E<---D:---><-Rest of the ext part------------>|
  |P          x                                             |
  |A          t          E<---E:--->E<Rest of the ext part->|
  |R                     x          x                       |
  |T                     t          t<---------F:---------->|
  +---------------------------------------------------------+
  (Ext == extended partition sector)
  C: is a primary partiion
  D:, E:, and F: are logical drives within the extended partition.
A MS-DOS partition table resides within one sector on a hard disk. There is always one in the first sector of a hard disk partitioned with FDISK.exe. There first partition table may contain references to "extended" partition tables residing on other sectors if there are multiple partitions. The first sector of the disk is the starting point. Partition tables are of the format:

Offset from     
the beginning 
of the sector          Description
-------------          -------------------------
   0x1be               Partition 1 table entry  (16 bytes)
   0x1ce               Partition 2 table entry  (16 bytes)
   0x1de               Partition 3 table entry  (16 bytes)
   0x1ee               Partition 4 table entry  (16 bytes)
   0x1fe               Signature  (0x55aa, 2 bytes)
Individual MSDOS partition table entries are of the format:
Offset   Size      Description
------   ----      ------------------------------
 0x0     8 bits    boot type
 0x1     8 bits    beginning sector head value
 0x2     8 bits    beginning sector (2 high bits of cylinder#)
 0x3     8 bits    beginning cylinder# (low order bits of cylinder#)
 0x4     8 bits    system indicator
 0x5     8 bits    ending sector head value
 0x6     8 bits    ending sector (2 high bits of cylinder#)
 0x7     8 bits    ending cylinder# (low order bits of cylinder#)
 0x8    32 bits    number of sectors preceding the partition
 0xc    32 bits    number of sectors in the partition
The Cylinder, Head and Sector values herein are not used, instead the 32-bit partition offset and size (also known as LBA addresses) are used exclusively to determine partition geometry.

If a non-partitioned disk is detected, in which case the 0'th block is a DosFs boot block rather then an MBR, the entire disk will be configured as partition 0, so that disks formatted with VxWorks and disks formatted on MS-DOS or Windows can be accepted interchangeably.

The usrFdiskPartCreate( ) will create a partition table with up to four partitions, which can be later used with usrFdiskPartRead( ) and dpartCbio to manage a partitioned disk on VxWorks.

However, it can not be guaranteed that this partition table can be used on another system due to several BIOS specific paramaters in the boot area. If interchangeability via removable disks is a requirement, partition tables should be created and volumes should be formatted on the other system with which the data is to be interchanged/

CAUTION

The partition decode function is recursive, up to the maximum number of partitions expected, which is no more then 24.

Sufficient stack space needs to be provided via taskSpawn( ) to accommodate the recursion level.

SEE ALSO

dpartCbio


OS Libraries : Routines

usrFdiskPartRead( )

NAME

usrFdiskPartRead( ) - read an FDISK-style partition table

SYNOPSIS

STATUS usrFdiskPartRead
    (
    CBIO_DEV_ID        cDev,     /* device from which to read blocks */
    PART_TABLE_ENTRY * pPartTab, /* table where to fill results */
    int                nPart     /* # of entries in pPartTable */
    )

DESCRIPTION

This function will read and decode a PC formatted partition table on a disk, and fill the appropriate partition table array with the resulting geometry, which should be used by the dpartCbio partition manager to access a partitioned disk with a shared disk cache.

EXAMPLE

The following example shows how a hard disk which is expected to have up to two partitions might be configured, assuming the physical level initialization resulted in the blkIoDevId handle:

devCbio = dcacheDevCreate( blkIoDevId, 0, 0x20000, "Hard Disk");
mainDevId = dpartDevCreate( devCbio, 2, usrFdiskPartRead )
dosFsDevCreate(  "/disk0a", dpartPartGet (mainDevId, 0), 0,0,0);
dosFsDevCreate(  "/disk0b", dpartPartGet (mainDevId, 1), 0,0,0);

RETURNS

OK or ERROR if partition table is corrupt

SEE ALSO

usrFdiskPartLib


OS Libraries : Routines

usrFdiskPartCreate( )

NAME

usrFdiskPartCreate( ) - create an FDISK-like partition table on a disk

SYNOPSIS

STATUS usrFdiskPartCreate
    (
    CBIO_DEV_ID cDev,         /* device representing the entire disk */
    int         nPart,        /* how many partitions needed, default=1, max=4 */
    int         size1,        /* space percentage for second partition */
    int         size2,        /* space percentage for third partition */
    int         size3         /* space percentage for fourth partition */
    )

DESCRIPTION

This function may be used to create a basic PC partition table. Such partition table however is not intended to be compatible with other operating systems, it is intended for disks connected to a VxWorks target, but without the access to a PC which may be used to create the partition table.

This function is capable of creating only one partition table - the MBR, and will not create any Bootable or Extended partitions. Therefore, 4 partitions are supported.

dev is a CBIO device handle for an entire disk, e.g. a handle returned by dcacheDevCreate( ), or if dpartCbio is used, it can be either the Master partition manager handle, or the one of the 0th partition if the disk does not contain a partition table at all.

The nPart argument contains the number of partitions to create. If nPart is 0 or 1, then a single partition covering the entire disk is created. If nPart is between 2 and 4, then the arguments size1, size2 and size3 contain the percentage of disk space to be assigned to the 2nd, 3rd, and 4th partitions respectively. The first partition (partition 0) will be assigned the remainder of space left (space hog).

Partition sizes will be round down to be multiple of whole tracks so that partition Cylinder/Head/Track fields will be initialized as well as the LBA fields. Although the CHS fields are written they are not used in VxWorks, and can not be guaranteed to work correctly on other systems.

RETURNS

OK or ERROR writing a partition table to disk

SEE ALSO

usrFdiskPartLib


OS Libraries : Routines

usrFdiskPartShow( )

NAME

usrFdiskPartShow( ) - parse and display partition data

SYNOPSIS

STATUS usrFdiskPartShow
    (
    CBIO_DEV_ID cbio,          /* device CBIO handle */
    block_t     extPartOffset, /* user should pass zero */
    block_t     currentOffset, /* user should pass zero */
    int         extPartLevel   /* user should pass zero */
    )

DESCRIPTION

This routine is intended to be user callable.

A device dependent partition table show routine. This routine outputs formatted data for all partition table fields for every partition table found on a given disk, starting with the MBR sectors partition table. This code can be removed to reduce code size by undefining: INCLUDE_PART_SHOW and rebuilding this library and linking to the new library.

This routine takes three arguments. First, a CBIO pointer (assigned for the entire physical disk) usually obtained from dcacheDevCreate( ). It also takes two block_t type arguments and one signed int, the user shall pass zero in these paramaters.

For example:

sp usrFdiskPartShow (pCbio,0,0,0)
Developers may use sizearch to view code size.

NOTE

RETURNS

OK or ERROR

SEE ALSO

usrFdiskPartLib