openblt

a hobby OS from the late 90s
git clone http://frotz.net/git/openblt.git
Log | Files | Refs | LICENSE

disk.h (10710B)


      1 /* $Id: //depot/blt/include/blt/disk.h#4 $
      2 **
      3 ** Copyright 1999 Sidney Cammeresi
      4 ** All rights reserved.
      5 **
      6 ** Redistribution and use in source and binary forms, with or without
      7 ** modification, are permitted provided that the following conditions
      8 ** are met:
      9 ** 1. Redistributions of source code must retain the above copyright
     10 **    notice, this list of conditions, and the following disclaimer.
     11 ** 2. Redistributions in binary form must reproduce the above copyright
     12 **    notice, this list of conditions, and the following disclaimer in the
     13 **    documentation and/or other materials provided with the distribution.
     14 ** 3. The name of the author may not be used to endorse or promote products
     15 **    derived from this software without specific prior written permission.
     16 **
     17 ** THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     18 ** IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     19 ** OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     20 ** IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     21 ** INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     22 ** NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     23 ** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     24 ** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     25 ** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     26 ** THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     27 */
     28 
     29 #ifndef _BLT_DISK_H_
     30 #define _BLT_DISK_H_
     31 
     32 #include <blt/blkdev.h>
     33 
     34 #define FDISK_TYPE_EMPTY         0x00
     35 #define FDISK_TYPE_FAT12         0x01
     36 #define FDISK_TYPE_FAT16_SMALL   0x04
     37 #define FDISK_TYPE_EXTENDED      0x05
     38 #define FDISK_TYPE_FAT16_BIG     0x06
     39 #define FDISK_TYPE_NTFS          0x07
     40 #define FDISK_TYPE_LINUX_SWAP    0x82
     41 #define FDISK_TYPE_EXT2          0x83
     42 #define FDISK_TYPE_FREEBSD       0xa5
     43 #define FDISK_TYPE_OPENBSD       0xa6
     44 #define FDISK_TYPE_BFS           0xeb
     45 
     46 #define FREEBSD_FFS              0x100
     47 #define FREEBSD_SWAP             0x101
     48 #define OPENBSD_FFS              0x102
     49 #define OPENBSD_SWAP             0x103
     50 
     51 typedef struct
     52 {
     53 	unsigned char bootflag;
     54 	unsigned char start0;
     55 	unsigned char start1;
     56 	unsigned char start2;
     57 	unsigned char type;
     58 	unsigned char end0;
     59 	unsigned char end1;
     60 	unsigned char end2;
     61 	unsigned int start_sect_num;
     62 	unsigned int num_sects;
     63 } fdisk_partition;
     64 
     65 typedef struct
     66 {
     67 	char name[3]; /* 0, 0a, etc. */
     68 	int type;
     69 	unsigned long long start, size;
     70 } partition_t;
     71 
     72 typedef struct
     73 {
     74 	blkdev_t *dev;
     75 	int numparts;
     76 	partition_t *partition;
     77 } disk_t;
     78 
     79 #ifdef __cplusplus
     80 extern "C" {
     81 #endif
     82 
     83 	disk_t *disk_alloc (blkdev_t *dev);
     84 	void disk_free (disk_t *disk);
     85 	const char *disk_partition_name (disk_t *disk, int partition);
     86 	unsigned long long disk_partition_start (disk_t *disk, int partition);
     87 	unsigned long long disk_partition_size (disk_t *disk, int partition);
     88 	unsigned int disk_partition_type (disk_t *disk, int partition);
     89 
     90 #ifdef __cplusplus
     91 }
     92 #endif
     93 
     94 
     95 /*
     96  * Copyright (c) 1987, 1988, 1993
     97  *  The Regents of the University of California.  All rights reserved.
     98  *
     99  * Redistribution and use in source and binary forms, with or without
    100  * modification, are permitted provided that the following conditions
    101  * are met:
    102  * 1. Redistributions of source code must retain the above copyright
    103  *    notice, this list of conditions and the following disclaimer.
    104  * 2. Redistributions in binary form must reproduce the above copyright
    105  *    notice, this list of conditions and the following disclaimer in the
    106  *    documentation and/or other materials provided with the distribution.
    107  * 3. All advertising materials mentioning features or use of this software
    108  *    must display the following acknowledgement:
    109  *        This product includes software developed by the University of
    110  *        California, Berkeley and its contributors.
    111  * 4. Neither the name of the University nor the names of its contributors
    112  *    may be used to endorse or promote products derived from this software
    113  *    without specific prior written permission.
    114  *
    115  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
    116  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
    117  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
    118  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
    119  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
    120  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
    121  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
    122  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
    123  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
    124  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
    125  * SUCH DAMAGE.
    126  *
    127  *  @(#)disklabel.h 8.2 (Berkeley) 7/10/94
    128  */
    129 
    130 #define NDDATA 5
    131 #define NSPARE 5
    132 #define BSD_MAXSLICES 16
    133 #define BSD_DISKLABEL_MAGIC    0x82564557
    134 
    135 typedef struct
    136 {
    137     unsigned int d_magic;      /* the magic number */
    138     unsigned short d_type;     /* drive type */
    139     unsigned short d_subtype;  /* controller/d_type specific */
    140     char d_typename[16];       /* type name, e.g. "eagle" */
    141 
    142     /*
    143      * d_packname contains the pack identifier and is returned when
    144      * the disklabel is read off the disk or in-core copy.
    145      * d_boot0 and d_boot1 are the (optional) names of the
    146      * primary (block 0) and secondary (block 1-15) bootstraps
    147      * as found in /usr/mdec.  These are returned when using
    148      * getdiskbyname(3) to retrieve the values from /etc/disktab.
    149      */
    150     union
    151 	{
    152         char un_d_packname[16];  /* pack identifier */
    153         struct
    154 		{
    155             char *un_d_boot0;    /* primary bootstrap name */
    156             char *un_d_boot1;    /* secondary bootstrap name */
    157         } un_b;
    158     } d_un;
    159 
    160     /* disk geometry: */
    161     unsigned int d_secsize;        /* # of bytes per sector */
    162     unsigned int d_nsectors;       /* # of data sectors per track */
    163     unsigned int d_ntracks;        /* # of tracks per cylinder */
    164     unsigned int d_ncylinders;     /* # of data cylinders per unit */
    165     unsigned int d_secpercyl;      /* # of data sectors per cylinder */
    166     unsigned int d_secperunit;     /* # of data sectors per unit */
    167 
    168     /*
    169      * Spares (bad sector replacements) below are not counted in
    170      * d_nsectors or d_secpercyl.  Spare sectors are assumed to
    171      * be physical sectors which occupy space at the end of each
    172      * track and/or cylinder.
    173      */
    174     unsigned short d_sparespertrack; /* # of spare sectors per track */
    175     unsigned short d_sparespercyl;   /* # of spare sectors per cylinder */
    176 
    177     /*
    178      * Alternate cylinders include maintenance, replacement, configuration
    179      * description areas, etc.
    180      */
    181     unsigned int d_acylinders;     /* # of alt. cylinders per unit */
    182 
    183     /*
    184      * d_interleave, d_trackskew and d_cylskew describe perturbations
    185      * in the media format used to compensate for a slow controller.
    186      * Interleave is physical sector interleave, set up by the
    187      * formatter or controller when formatting.  When interleaving is
    188      * in use, logically adjacent sectors are not physically
    189      * contiguous, but instead are separated by some number of
    190      * sectors.  It is specified as the ratio of physical sectors
    191      * traversed per logical sector.  Thus an interleave of 1:1
    192      * implies contiguous layout, while 2:1 implies that logical
    193      * sector 0 is separated by one sector from logical sector 1.
    194      * d_trackskew is the offset of sector 0 on track N relative to
    195      * sector 0 on track N-1 on the same cylinder.  Finally, d_cylskew
    196      * is the offset of sector 0 on cylinder N relative to sector 0
    197      * on cylinder N-1.
    198      */
    199     unsigned short d_rpm;              /* rotational speed */
    200     unsigned short d_interleave;       /* hardware sector interleave */
    201     unsigned short d_trackskew;        /* sector 0 skew, per track */
    202     unsigned short d_cylskew;          /* sector 0 skew, per cylinder */
    203     unsigned int d_headswitch;         /* head switch time, usec */
    204     unsigned int d_trkseek;            /* track-to-track seek, usec */
    205     unsigned int d_flags;              /* generic flags */
    206     unsigned int d_drivedata[NDDATA];  /* drive-type specific information */
    207     unsigned int d_spare[NSPARE];      /* reserved for future use */
    208     unsigned int d_magic2;             /* the magic number (again) */
    209     unsigned short d_checksum;         /* xor of data incl. partitions */
    210 
    211     /* filesystem and partition information: */
    212     unsigned short d_npartitions;      /* number of partitions in following */
    213     unsigned int d_bbsize;             /* size of boot area at sn0, bytes */
    214     unsigned int d_sbsize;             /* max size of fs superblock, bytes */
    215 
    216     struct partition                   /* the partition table */
    217 	{                          
    218         unsigned int p_size;           /* number of sectors in partition */
    219         unsigned int p_offset;         /* starting sector */
    220         unsigned int p_fsize;          /* filesystem basic fragment size */
    221         unsigned char p_fstype;        /* filesystem type, see below */
    222         unsigned char p_frag;          /* filesystem fragments per block */
    223         union
    224 		{
    225             unsigned short cpg;        /* UFS: FS cylinders per group */
    226             unsigned short sgs;        /* LFS: FS segment shift */
    227         } p_u1;
    228     } d_partitions[BSD_MAXSLICES];     /* actually may be more */
    229 } bsd_disklabel;
    230 
    231 #define BSD_FS_UNUSED   0       /* unused */
    232 #define BSD_FS_SWAP     1       /* swap */
    233 #define BSD_FS_V6       2       /* Sixth Edition */
    234 #define BSD_FS_V7       3       /* Seventh Edition */
    235 #define BSD_FS_SYSV     4       /* System V */
    236 #define BSD_FS_V71K     5       /* V7 with 1K blocks (4.1, 2.9) */
    237 #define BSD_FS_V8       6       /* Eighth Edition, 4K blocks */
    238 #define BSD_FS_BSDFFS   7       /* 4.2BSD fast file system */
    239 #define BSD_FS_MSDOS    8       /* MSDOS file system */
    240 #define BSD_FS_BSDLFS   9       /* 4.4BSD log-structured file system */
    241 #define BSD_FS_OTHER    10      /* in use, but unknown/unsupported */
    242 #define BSD_FS_HPFS     11      /* OS/2 high-performance file system */
    243 #define BSD_FS_ISO9660  12      /* ISO 9660, normally CD-ROM */
    244 #define BSD_FS_BOOT     13      /* partition contains bootstrap */
    245 #define BSD_FS_ADOS     14      /* AmigaDOS fast file system */
    246 #define BSD_FS_HFS      15      /* Macintosh HFS */
    247 #define BSD_FS_ADFS     16      /* Acorn Disk Filing System */
    248 #define BSD_FS_EXT2FS   17      /* ext2fs */
    249 #define BSD_FS_CCD      18      /* ccd component */
    250 
    251 #endif
    252