File: DoReadWrite.c

package info (click to toggle)
mac-fdisk 0.1-18
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster, sid
  • size: 372 kB
  • ctags: 870
  • sloc: ansic: 5,880; makefile: 151; sh: 35
file content (126 lines) | stat: -rw-r--r-- 3,360 bytes parent folder | download | duplicates (8)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
/*
 * Copyright 1993-97 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. 
 */
#include "SCSIStuff.h"
int DoRead(UInt8 targetID, UInt32 block, UInt16 count, char* addr);
int DoWrite(UInt8 targetID, UInt32 block, UInt16 count, char* addr);

int
DoRead(
	UInt8               targetID,
	UInt32              block,
	UInt16              count,
	char *              addr
    )
{
    OSErr                   status;
    Str255                  errorText;
    char*       msg;
    static SCSI_10_Byte_Command gReadCommand = {
	kScsiCmdRead10, 0, 0, 0, 0, 0, 0, 0, 0, 0
    };
    SCSI_Sense_Data         senseData;
    DeviceIdent scsiDevice;
    int rtn_value;

    scsiDevice.diReserved = 0;
    scsiDevice.bus = kOriginalSCSIBusAdaptor;
    scsiDevice.targetID = targetID;
    scsiDevice.LUN = 0;

    gReadCommand.lbn4 = (block >> 24) & 0xFF;
    gReadCommand.lbn3 = (block >> 16) & 0xFF;
    gReadCommand.lbn2 = (block >> 8) & 0xFF;
    gReadCommand.lbn1 = block & 0xFF;

    gReadCommand.len2 = (count >> 8) & 0xFF;
    gReadCommand.len1 = count & 0xFF;

    status = DoSCSICommand(
			    scsiDevice,
			    "\pRead",
			    (SCSI_CommandPtr) &gReadCommand,
			    (Ptr) addr,
			    count * 512,
			    scsiDirectionIn,
			    NULL,
			    &senseData,
			    errorText
	    );
    if (status == noErr) {
	rtn_value = 1;
    } else {
	rtn_value = 0;
    }
    return rtn_value;
}

int
DoWrite(
	UInt8               targetID,
	UInt32              block,
	UInt16              count,
	char *              addr
    )
{
    OSErr                   status;
    Str255                  errorText;
    char*       msg;
    static SCSI_10_Byte_Command gWriteCommand = {
	kScsiCmdWrite10, 0, 0, 0, 0, 0, 0, 0, 0, 0
    };
    SCSI_Sense_Data         senseData;
    DeviceIdent scsiDevice;
    int rtn_value;

    scsiDevice.diReserved = 0;
    scsiDevice.bus = 0xff;
    scsiDevice.targetID = targetID;
    scsiDevice.LUN = 0;

    gWriteCommand.lbn4 = (block >> 24) & 0xFF;
    gWriteCommand.lbn3 = (block >> 16) & 0xFF;
    gWriteCommand.lbn2 = (block >> 8) & 0xFF;
    gWriteCommand.lbn1 = block & 0xFF;

    gWriteCommand.len2 = (count >> 8) & 0xFF;
    gWriteCommand.len1 = count & 0xFF;

    status = DoSCSICommand(
			    scsiDevice,
			    "\pWrite",
			    (SCSI_CommandPtr) &gWriteCommand,
			    (Ptr) addr,
			    count * 512,
			    scsiDirectionOut,
			    NULL,
			    &senseData,
			    errorText
	    );
    if (status == noErr) {
	rtn_value = 1;
    } else {
	rtn_value = 0;
    }
    return rtn_value;
}