⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 usrfdiskpartlib.c

📁 vxworks源码源码解读是学习vxworks的最佳途径
💻 C
📖 第 1 页 / 共 4 页
字号:
/* usrFdiskPartLib.c - FDISK-style partition handler *//* Copyright 1997-1998 Wind River Systems, Inc. */#include "copyright_wrs.h"/*modification history--------------------02j,31aug99,jkf  changes for new CBIO API.02i,31jul99,jkf  changed usrFdiskPartCreate. SPR#2828502h,31jul99,jkf  reentrancy overhaul. SPR#2827802g,31jul99,jkf  fixed blind resetting cbio in show routine. SPR#2827902f,31jul99,jkf  fixed bugs introduced in 02a adaptation:                  useFdiskPartParse offset calculation fixed, SPR#2828002e,31jul99,jkf  T2 merge, tidiness & spelling.02d,07dec98,lrn  partition table creation routine (SPR#21977), terse Show02c,15sep98,lrn  enabled SHOW by default, assume non-partitioned disk 		 if all partitions are nil02b,02jul98,lrn  DosFs 2.0 pre-release02a,21jun98,lrn  adopted from rev 01c by jkf.01a,01sep97,jkf  adapted from dosPartLibAta.c.*//*DESCRIPTION:This module is provided is source code to accommodate variouscustomizations of partition table handling, resulting fromvariations 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 anddisplaying partition tables written by MSDOS FDISK.exe orby any other MSDOS FDISK.exe compatible partitioning software.  The first partition table is contained within a hard drivesMaster Boot Record (MBR) sector, which is defined as sectorone, 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 knownto 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 containingmultiple MSDOS file systems:.CS  +---------------------------------------------------------+  |<---------------------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..CEA MS-DOS partition table resides within one sector on a harddisk.  There is always one in the first sector of a hard diskpartitioned with FDISK.exe.  There first partition table maycontain references to "extended" partition tables residing onother sectors if there are multiple partitions.  The first sector of the disk is the starting point.  Partition tablesare of the format:.CSOffset 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).CEIndividual MSDOS partition table entries are of the format:.CSOffset   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.CEThe Cylinder, Head and Sector values herein are not used,instead the 32-bit partition offset and size (also known as LBAaddresses) are used exclusively to determine partition geometry.If a non-partitioned disk is detected, in which case the 0'th blockis a DosFs boot block rather then an MBR, the entire disk will beconfigured as partition 0, so that disks formatted with VxWorks anddisks formatted on MS-DOS or Windows can be accepted interchangeably.The usrFdiskPartCreate() will create a partition table with up to fourpartitions, which can be later used with usrFdiskPartRead() anddpartCbio to manage a partitioned disk on VxWorks.However, it can not be guaranteed that this partition table can be usedon another system due to several BIOS specific paramaters in the bootarea.  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/CAUTIONThe partition decode function is recursive, up to the maximumnumber 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*//* includes */#include "vxWorks.h"#include "stdio.h"#include "stdlib.h"#include "string.h"#include "tickLib.h"#include "dosFsLib.h"#include "private/dosFsLibP.h"	/* for byte swapping macros */#include "dpartCbio.h"/* defines *//* may be undefine the following to conserve memory space */#define	INCLUDE_PART_SHOW	/* include the show function by default *//* partition table structure offsets */#define PART_SIG_ADRS           0x1fe   /* dos partition signature  */#define PART_SIG_MSB            0x55    /* msb of the partition sig */#define PART_SIG_LSB            0xaa    /* lsb of the partition sig */#define BYTES_PER_SECTOR        0x200   /* 512 bytes per sector     */#define PART_IS_BOOTABLE        0x80    /* a dos bootable partition */#define PART_NOT_BOOTABLE       0x00    /* not a bootable partition */#define PART_TYPE_DOS4          0x06    /* dos 16b FAT, 32b secnum  */#define PART_TYPE_DOSEXT        0x05    /* msdos extended partition */#define PART_TYPE_DOS3          0x04    /* dos 16b FAT, 16b secnum  */#define PART_TYPE_DOS12         0x01    /* dos 12b FAT, 32b secnum  */#define PART_TYPE_DOS32         0x0b    /* dos 32b FAT, 32b secnum  */#define PART_TYPE_DOS32X        0x0c    /* dos 32b FAT, 32b secnum  */#define PART_TYPE_WIN95_D4      0x0e    /* Win95 dosfs  16bf 32bs   */#define PART_TYPE_WIN95_EXT     0x0f    /* Win95 extended partition */#define BOOT_TYPE_OFFSET    0x0   /* boot type                      */#define STARTSEC_HD_OFFSET  0x1   /* beginning sector head value    */#define STARTSEC_SEC_OFFSET 0x2   /* beginning sector               */#define STARTSEC_CYL_OFFSET 0x3   /* beginning cylinder             */#define SYSTYPE_OFFSET      0x4   /* system indicator               */#define ENDSEC_HD_OFFSET    0x5   /* ending sector head value       */#define ENDSEC_SEC_OFFSET   0x6   /* ending sector                  */#define ENDSEC_CYL_OFFSET   0x7   /* ending cylinder                */#define NSECTORS_OFFSET     0x8   /* sector offset from reference   */#define NSECTORS_TOTAL      0xc   /* number of sectors in part      *//* declarations */STATUS usrFdiskPartRead    (    CBIO_DEV_ID dev,        /* device from which to read blocks */    PART_TABLE_ENTRY *pPartTab, /* table where to fill results */    int nPart               /* # of entries in <pPartTable> */    );STATUS usrFdiskPartCreate    (    CBIO_DEV_ID dev, 	/* 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 */    );/* locals */LOCAL STATUS useFdiskPartParse    (    CBIO_DEV_ID dev,        	/* device from which to read blocks */    CBIO_PARAMS * pCbioParams,    PART_TABLE_ENTRY *pPartTab, /* table where to fill results */    int nPart,               	/* # of entries in <pPartTable> */    ULONG startBlock,		/* where to expect part table */    ULONG extStartBlock		/* Offset to extended partition */    );#ifdef INCLUDE_PART_SHOWSTATUS usrFdiskPartShow    (    CBIO_DEV_ID cbio_dev,     /* device CBIO handle */    block_t extPartOffset,    /* user should pass zero */    block_t currentOffset,    /* user should pass zero */    int extPartLevel          /* user should pass zero */    );LOCAL const struct partType /* Some partition type values & names. */    {                       /* Only MSDOS are used in this code.   */    const UINT8 partTypeNum;          const char *partTypeName;        } partNames[] =         {        {0x00, "Empty (NULL) Partition"},        {0x01, "MSDOS Partition 12-bit FAT"},           {0x02, "XENIX / (slash) Partition"},                {0x03, "XENIX /usr Partition"},         {0x04, "MSDOS 16-bit FAT <32M Partition"},          {0x05, "MSDOS Extended Partition"},         {0x06, "MSDOS 16-bit FAT >=32M Partition"},        {0x07, "HPFS / NTFS Partition"},        {0x08, "AIX boot or SplitDrive Partition"},        {0x09, "AIX data or Coherent Partition"},        {0x0a, "OS/2 Boot Manager Partition"},        {0x0b, "Win95 FAT32 Partition"},        {0x0c, "Win95 FAT32 (LBA) Partition"},        {0x0e, "Win95 FAT16 (LBA) Partition"},        {0x0f, "Win95 Extended (LBA) Partition"},        {0x10, "OPUS Partition"},        {0x11, "Hidden DOS FAT12 Partition"},        {0x12, "Compaq diagnostics Partition"},        {0x14, "Hidden DOS FAT16 Partition"},        {0x16, "Hidden DOS FAT16 (big) Partition"},        {0x17, "Hidden HPFS/NTFS Partition"},        {0x18, "AST Windows swapfile Partition"},        {0x24, "NEC DOS Partition"},        {0x3c, "PartitionMagic recovery Partition"},        {0x40, "Venix 80286 Partition"},        {0x41, "Linux/MINIX (shared with DRDOS) Partition"},        {0x42, "SFS or Linux swap part (shared with DRDOS)"},        {0x43, "Linux native (shared with DRDOS) Partition"},        {0x50, "DM (disk manager) Partition"},        {0x51, "DM6 Aux1 (or Novell) Partition"},        {0x52, "CP/M or Microport SysV/AT Partition"},        {0x53, "DM6 Aux3 Partition"},        {0x54, "DM6 Partition"},        {0x55, "EZ-Drive (disk manager) Partition"},        {0x56, "Golden Bow (disk manager) Partition"},        {0x5c, "Priam Edisk (disk manager) Partition"},        {0x61, "SpeedStor Partition"},        {0x63, "GNU HURD or Mach or Sys V/386 (ISC UNIX)"},        {0x64, "Novell Netware 286 Partition"},        {0x65, "Novell Netware 386 Partition"},        {0x70, "DiskSecure Multi-Boot Partition"},        {0x75, "PC/IX Partition"},        {0x77, "QNX4.x Partition"},        {0x78, "QNX4.x 2nd part Partition"},        {0x79, "QNX4.x 3rd part Partition"},        {0x80, "MINIX until 1.4a Partition"},        {0x81, "MINIX / old Linux Partition"},        {0x82, "Linux swap Partition"},        {0x83, "Linux native Partition"},        {0x84, "OS/2 hidden C: drive Partition"},        {0x85, "Linux extended Partition"},        {0x86, "NTFS volume set Partition"},        {0x87, "NTFS volume set Partition"},        {0x93, "Amoeba Partition"},        {0x94, "Amoeba BBT Partition"},         {0xa0, "IBM Thinkpad hibernation Partition"},        {0xa5, "BSD/386 Partition"},        {0xa7, "NeXTSTEP 486 Partition"},        {0xb7, "BSDI fs Partition"},        {0xb8, "BSDI swap Partition"},        {0xc1, "DRDOS/sec (FAT-12) Partition"},        {0xc4, "DRDOS/sec (FAT-16, < 32M) Partition"},        {0xc6, "DRDOS/sec (FAT-16, >= 32M) Partition"},        {0xc7, "Syrinx Partition"},        {0xdb, "CP/M-Concurrent CP/M-Concurrent DOS-CTOS"},        {0xe1, "DOS access-SpeedStor 12-bit FAT ext."},        {0xe3, "DOS R/O or SpeedStor Partition"},        {0xe4, "SpeedStor 16-bit FAT Ext Part. < 1024 cyl."},        {0xf1, "SpeedStor Partition"},        {0xf2, "DOS 3.3+ secondary Partition"},        {0xf4, "SpeedStor large partition Partition"},        {0xfe, "SpeedStor >1024 cyl. or LANstep Partition"},        {0xff, "Xenix Bad Block Table Partition"},     };#endif /* INCLUDE_PART_SHOW *//******************************************************************************* useFdiskPartParse - parse partitions on given disk** This routine is not intended to be user callable.* * This routine parses all existing partition tables on a disk.* It adds partition node data entries to a table which it has been * passed  for any partition which contains a* file system mountable by dosFsLib().  The size (in sectors)* of the partition and the absolute offset (in sectors) from the* start of the drive are also stored, since that is what VxWorks* CBIO device create routines need to overlay partitions. * * The partition table must appear to be valid when checked with* 0x55aa signature.   The partition table in the Master Boot Record* will be parsed first.  If there are any extended partitions found,* a (recursive) call to itself is made to parse the extended* partition(s) in the new sector(s).  Recursive functions may use a lot* of stack space. Developer should beware of stack overflow.** RETURNS: ERROR or a (positive) number of partitions decoded and filled.*

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -