Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/dist/pdisk import pdisk utility from Eryk Vershen:



details:   https://anonhg.NetBSD.org/src/rev/ba31af1586aa
branches:  trunk
changeset: 533760:ba31af1586aa
user:      dbj <dbj%NetBSD.org@localhost>
date:      Tue Jul 09 05:49:02 2002 +0000

description:
import pdisk utility from Eryk Vershen:
  http://cantaforda.com/cfcl/eryk/linux/pdisk/index.html
this is the utility provided by mklinux and osX to manipulate
the Apple Partition map.

diffstat:

 dist/pdisk/ATA_media.c      |  1239 ++++++++++++++++++++++++++++++++++++++++
 dist/pdisk/ATA_media.h      |    64 ++
 dist/pdisk/DoSCSICommand.c  |   649 +++++++++++++++++++++
 dist/pdisk/DoSCSICommand.h  |   130 ++++
 dist/pdisk/HISTORY          |    68 ++
 dist/pdisk/MacSCSICommand.h |   420 +++++++++++++
 dist/pdisk/README           |   147 ++++
 dist/pdisk/SCSI_media.c     |  1108 ++++++++++++++++++++++++++++++++++++
 dist/pdisk/SCSI_media.h     |    65 ++
 dist/pdisk/bitfield.c       |   101 +++
 dist/pdisk/bitfield.h       |    72 ++
 dist/pdisk/convert.c        |   204 ++++++
 dist/pdisk/convert.h        |    65 ++
 dist/pdisk/cvt_pt.c         |   208 ++++++
 dist/pdisk/deblock_media.c  |   334 ++++++++++
 dist/pdisk/deblock_media.h  |    59 +
 dist/pdisk/dpme.h           |   219 +++++++
 dist/pdisk/dump.c           |   917 +++++++++++++++++++++++++++++
 dist/pdisk/dump.h           |    72 ++
 dist/pdisk/errors.c         |   173 +++++
 dist/pdisk/errors.h         |    62 ++
 dist/pdisk/file_media.c     |   574 ++++++++++++++++++
 dist/pdisk/file_media.h     |    60 +
 dist/pdisk/hfs_misc.c       |   253 ++++++++
 dist/pdisk/hfs_misc.h       |    41 +
 dist/pdisk/io.c             |   463 +++++++++++++++
 dist/pdisk/io.h             |    67 ++
 dist/pdisk/layout_dump.c    |   180 +++++
 dist/pdisk/layout_dump.h    |    78 ++
 dist/pdisk/makefile         |   212 ++++++
 dist/pdisk/media.c          |   228 +++++++
 dist/pdisk/media.h          |   139 ++++
 dist/pdisk/partition_map.c  |  1319 +++++++++++++++++++++++++++++++++++++++++++
 dist/pdisk/partition_map.h  |   119 +++
 dist/pdisk/pathname.c       |   247 ++++++++
 dist/pdisk/pathname.h       |    62 ++
 dist/pdisk/pdisk.8          |   222 +++++++
 dist/pdisk/pdisk.c          |  1072 ++++++++++++++++++++++++++++++++++
 dist/pdisk/pdisk.h          |    57 +
 dist/pdisk/pdisk.html       |   406 +++++++++++++
 dist/pdisk/pdisk.r          |   234 +++++++
 dist/pdisk/util.c           |   164 +++++
 dist/pdisk/util.h           |    62 ++
 dist/pdisk/validate.c       |   499 ++++++++++++++++
 dist/pdisk/validate.h       |    59 +
 dist/pdisk/version.h        |    82 ++
 46 files changed, 13275 insertions(+), 0 deletions(-)

diffs (truncated from 13459 to 300 lines):

diff -r 4ff2a478081f -r ba31af1586aa dist/pdisk/ATA_media.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/dist/pdisk/ATA_media.c    Tue Jul 09 05:49:02 2002 +0000
@@ -0,0 +1,1239 @@
+/*
+ * ATA_media.c -
+ *
+ * Written by Eryk Vershen
+ */
+
+/*
+ * Copyright 1997,1998 by Apple Computer, Inc.
+ *              All Rights Reserved 
+ *  
+ * Permission to use, copy, modify, and distribute this software and 
+ * its documentation for any purpose and without fee is hereby granted, 
+ * provided that the above copyright notice appears in all copies and 
+ * that both the copyright notice and this permission notice appear in 
+ * supporting documentation. 
+ *  
+ * APPLE COMPUTER DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE 
+ * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 
+ * FOR A PARTICULAR PURPOSE. 
+ *  
+ * IN NO EVENT SHALL APPLE COMPUTER BE LIABLE FOR ANY SPECIAL, INDIRECT, OR 
+ * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM 
+ * LOSS OF USE, DATA OR PROFITS, WHETHER IN ACTION OF CONTRACT, 
+ * NEGLIGENCE, OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION 
+ * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 
+ */
+
+
+// for printf()
+#include <stdio.h>
+// for malloc() & free()
+#include <stdlib.h>
+#include <ATA.h>
+// for SCSI command structures
+#include "MacSCSICommand.h"
+#include "ATA_media.h"
+#include "util.h"
+
+
+/*
+ * Defines
+ */
+#define RESULT_OFFSET(type) \
+    ((sizeof(type) == 1) ? 3 : ((sizeof(type) == 2) ? 1 : 0))
+#define TBTrapTableAddress(trapNum) (((trapNum & 0x03FF) << 2) + 0xE00)
+#define SWAP_SHORTS(x)  ((((x) & 0xFFFF) << 16) | (((x) >> 16) & 0xFFFF))
+#define LBA_CAPABLE 0x0200
+
+
+/*
+ * Types
+ */
+typedef struct ATA_info *ATA_INFO;
+
+struct ATA_info {
+    long           lba;
+    long           heads;
+    long           sectors;
+};
+
+typedef struct ATA_media *ATA_MEDIA;
+
+struct ATA_media {
+    struct media    m;
+    long            id;
+    struct ATA_info info;
+};
+
+struct ATA_manager {
+    long        exists;
+    long        kind;
+    struct {
+       char    major;
+       char    minor;
+    } version;
+    short       busCount;
+    long       *bus_list;
+};
+
+typedef struct ATA_media_iterator *ATA_MEDIA_ITERATOR;
+
+struct ATA_media_iterator {
+    struct media_iterator   m;
+    long                    bus_index;
+    long                    bus;
+    long                    id;
+};
+
+struct ATA_identify_drive_info {        /* word */
+    unsigned short  config_bits;        /*  0 */
+    unsigned short  num_cylinders;      /*  1 */
+    unsigned short  reserved2;          /*  2 */
+    unsigned short  num_heads;          /*  3 */
+    unsigned short  bytes_per_track;    /*  4 */
+    unsigned short  bytes_per_sector;   /*  5 */
+    unsigned short  sectors_per_track;  /*  6 */
+    unsigned short  vendor7[3];         /*  7-9 */
+    char            serial_number[20];  /* 10-19 */
+    unsigned short  buffer_type;        /* 20 */
+    unsigned short  buffer_size;        /* 21 */
+    unsigned short  num_of_ecc_bytes;   /* 22 */
+    char            firmware_rev[8];    /* 23-26 */
+    char            model_number[40];   /* 27-46 */
+    unsigned short  word47;             /* 47 */
+    unsigned short  double_word_io;     /* 48 */
+    unsigned short  capabilities;       /* 49 */
+    unsigned short  reserved50;         /* 50 */
+    unsigned short  pio_timing;         /* 51 */
+    unsigned short  dma_timing;         /* 52 */
+    unsigned short  current_is_valid;   /* 53 */
+    unsigned short  cur_cylinders;      /* 54 */
+    unsigned short  cur_heads;          /* 55 */
+    unsigned short  cur_sec_per_track;  /* 56 */
+    unsigned long   total_sectors;      /* 57-58 */
+    unsigned short  multiple_sectors;   /* 59 */
+    unsigned long   lba_sectors;        /* 60-61 */
+    unsigned short  singleword_dma;     /* 62 */
+    unsigned short  multiword_dma;      /* 63 */
+    unsigned short  reserved64[64];     /* 64-127 */
+    unsigned short  vendor128[32];      /* 128-159 */
+    unsigned short  reserved160[96];    /* 160-255 */
+};
+
+struct ATAPI_identify_drive_info {      /* word */
+    unsigned short  config_bits;        /*  0 */
+    unsigned short  retired1[9];        /*  1-9 */
+    char            serial_number[20];  /* 10-19 */
+    unsigned short  retired20[3];       /* 20-22 */
+    char            firmware_rev[8];    /* 23-26 */
+    char            model_number[40];   /* 27-46 */
+    unsigned short  retired47[2];       /* 47-48 */
+    unsigned short  capabilities;       /* 49 */
+    unsigned short  reserved50;         /* 50 */
+    unsigned short  pio_timing;         /* 51 */
+    unsigned short  dma_timing;         /* 52 */
+    unsigned short  current_is_valid;   /* 53 */
+    unsigned short  retired54[8];       /* 54-61 */
+    unsigned short  singleword_dma;     /* 62 */
+    unsigned short  multiword_dma;      /* 63 */
+    unsigned short  pio_transfer;       /* 64 */
+    unsigned short  min_cycle_time;     /* 65 */
+    unsigned short  rec_cycle_time;     /* 66 */
+    unsigned short  min_wo_flow;        /* 67 */
+    unsigned short  min_with_flow;      /* 68 */
+    unsigned short  reserved69[2];      /* 69-70 */
+    unsigned short  release_over;       /* 71 */
+    unsigned short  release_service;    /* 72 */
+    unsigned short  major_rev;          /* 73 */
+    unsigned short  minor_rev;          /* 74 */
+    unsigned short  reserved75[53];     /* 75-127 */
+    unsigned short  vendor128[32];      /* 128-159 */
+    unsigned short  reserved160[96];    /* 160-255 */
+};
+
+/* Identifies the bus protocol type. */
+enum {
+    kDevUnknown     =   0,
+    kDevATA         =   1,
+    kDevATAPI       =   2,
+    kDevPCMCIA      =   3
+};
+
+
+/*
+ * Global Constants
+ */
+enum {
+    kNoDevice = 0x00FF,
+    kATAtimeout = 3000,
+    kATAcmdATAPIPacket          = 0x00A0                        /* ATAPI packet command */
+};
+
+
+/*
+ * Global Variables
+ */
+static long ata_inited = 0;
+static struct ATA_manager ata_mgr;
+
+/*
+ * Forward declarations
+ */
+int ATAManagerPresent(void);
+int ATAHardwarePresent(void);
+pascal SInt16 ataManager(ataPB *pb);
+void ata_init(void);
+ATA_MEDIA new_ata_media(void);
+long read_ata_media(MEDIA m, long long offset, unsigned long count, void *address);
+long write_ata_media(MEDIA m, long long offset, unsigned long count, void *address);
+long close_ata_media(MEDIA m);
+long os_reload_ata_media(MEDIA m);
+long compute_id(long bus, long device);
+pascal SInt16 ataManager(ataPB *pb);
+int ATA_ReadBlock(UInt32 deviceID, ATA_INFO info, UInt32 block_size, UInt32 block, UInt8 *address);
+int ATA_WriteBlock(UInt32 deviceID, ATA_INFO info, UInt32 block_size, UInt32 block, UInt8 *address);
+long get_info(long id, struct ATA_identify_drive_info *ip);
+long get_pi_info(long id, struct ATAPI_identify_drive_info *ip);
+long is_atapi(long id);
+long read_atapi_media(MEDIA m, long long offset, unsigned long count, void *address);
+long write_atapi_media(MEDIA m, long long offset, unsigned long count, void *address);
+int ATAPI_ReadBlock(UInt32 deviceID, UInt32 block_size, UInt32 block, UInt8 *address);
+int ATAPI_TestUnitReady(UInt32 deviceID);
+int ATAPI_ReadCapacity(UInt32 deviceID, unsigned long *block_size, unsigned long *blocks);
+ATA_MEDIA_ITERATOR new_ata_iterator(void);
+void reset_ata_iterator(MEDIA_ITERATOR m);
+char *step_ata_iterator(MEDIA_ITERATOR m);
+void delete_ata_iterator(MEDIA_ITERATOR m);
+int ata_bus_present(int num);
+
+
+/*
+ * Routines
+ */
+#if GENERATINGPOWERPC
+pascal SInt16
+ataManager(ataPB *pb)
+{
+    #ifdef applec
+       #if sizeof(SInt16) > 4
+           #error "Result types larger than 4 bytes are not supported."
+       #endif
+    #endif
+    long    private_result;
+
+    private_result = CallUniversalProc(
+       *(UniversalProcPtr*)TBTrapTableAddress(0xAAF1),
+       kPascalStackBased
+        | RESULT_SIZE(SIZE_CODE(sizeof(SInt16)))
+        | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(pb))),
+       pb);
+    return *(((SInt16*)&private_result) + RESULT_OFFSET(SInt16));
+}
+#endif
+
+
+int
+ATAHardwarePresent(void)
+{
+    UInt16  configFlags;
+
+    // Hardware configuration flags
+    configFlags = LMGetHWCfgFlags();
+    
+    return ((configFlags & 0x0080) != 0);
+}
+
+
+int
+ATAManagerPresent(void)
+{
+    if (ATAHardwarePresent()) {
+       return (TrapAvailable(kATATrap));
+    } else {
+       return 0;
+    }
+}
+
+void
+ata_init(void)
+{
+    ataMgrInquiry   pb;
+    OSErr           status;
+    int i;
+    int j;
+
+    if (ata_inited != 0) {
+       return;
+    }
+    ata_inited = 1;
+    
+    if (ATAManagerPresent() == 0) {
+       ata_mgr.exists = 0;
+       return;
+    }
+
+    ata_mgr.exists = 1;
+    ata_mgr.kind = allocate_media_kind();
+
+    clear_memory((void *)&pb, sizeof(pb));
+    
+    pb.ataPBFunctionCode =  kATAMgrManagerInquiry;
+    pb.ataPBVers =          kATAPBVers1;
+
+    status = ataManager((ataPB*) &pb );
+    
+    if (status != noErr) {
+       ata_mgr.exists = 0;
+       return;
+    }
+    ata_mgr.version.major = pb.ataMgrVersion.majorRev;
+    ata_mgr.version.minor = pb.ataMgrVersion.minorAndBugRev >> 4;
+    ata_mgr.busCount = pb.ataBusCnt;
+
+    ata_mgr.bus_list = (long *) calloc(ata_mgr.busCount, sizeof(long));
+    if (ata_mgr.bus_list == 0) {
+       ata_mgr.busCount = 0;



Home | Main Index | Thread Index | Old Index