|
|
1.1 root 1: /*
2: * Mach Operating System
3: * Copyright (c) 1993,1991,1990,1989 Carnegie Mellon University
4: * All Rights Reserved.
5: *
6: * Permission to use, copy, modify and distribute this software and its
7: * documentation is hereby granted, provided that both the copyright
8: * notice and this permission notice appear in all copies of the
9: * software, derivative works or modified versions, and any portions
10: * thereof, and that both notices appear in supporting documentation.
11: *
12: * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
13: * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
14: * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
15: *
16: * Carnegie Mellon requests users of this software to return to
17: *
18: * Software Distribution Coordinator or [email protected]
19: * School of Computer Science
20: * Carnegie Mellon University
21: * Pittsburgh PA 15213-3890
22: *
23: * any improvements or extensions that they make and grant Carnegie Mellon
24: * the rights to redistribute these changes.
25: */
26: /* This goes away as soon as we move it in the Ux server */
27:
28:
29:
30: #include <mach/std_types.h>
31: #include <scsi/compat_30.h>
32: #include <scsi/scsi.h>
33: #include <scsi/scsi_defs.h>
34: #include <scsi/rz.h>
35: #include <scsi/rz_labels.h>
36: #include <sys/types.h>
37: #include <sys/ioctl.h>
38:
39: #if (NSCSI > 0)
40: #define LABEL_DEBUG(x,y) if (label_flag&x) y
41:
42: #include <i386at/disk.h>
43: #include <device/device_types.h>
44: #include <device/disk_status.h>
45:
46:
47: int scsi_abs_sec = -1;
48: int scsi_abs_count = -1;
49:
50: scsi_rw_abs(dev, data, rw, sec, count)
51: dev_t dev;
52: {
53: io_req_t ior;
54: io_return_t error;
55:
56: io_req_alloc(ior,0);
57: ior->io_next = 0;
58: ior->io_unit = dev & (~(MAXPARTITIONS-1)); /* sort of */
59: ior->io_unit |= PARTITION_ABSOLUTE;
60: ior->io_data = (io_buf_ptr_t)data;
61: ior->io_count = count;
62: ior->io_recnum = sec;
63: ior->io_error = 0;
64: if (rw == IO_READ)
65: ior->io_op = IO_READ;
66: else
67: ior->io_op = IO_WRITE;
68: scdisk_strategy(ior);
69: iowait(ior);
70: error = ior->io_error;
71: io_req_free(ior);
72: return(error);
73: }
74:
75: io_return_t
76: scsi_i386_get_status(dev, tgt, flavor, status, status_count)
77: int dev;
78: target_info_t *tgt;
79: int flavor;
80: dev_status_t status;
81: unsigned int *status_count;
82: {
83:
84: switch (flavor) {
85: case V_GETPARMS: {
86: struct disklabel *lp = &tgt->dev_info.disk.l;
87: struct disk_parms *dp = (struct disk_parms *)status;
88: extern struct disklabel default_label;
89: int part = rzpartition(dev);
90:
91: if (*status_count < sizeof (struct disk_parms)/sizeof(int))
92: return (D_INVALID_OPERATION);
93: dp->dp_type = DPT_WINI;
94: dp->dp_secsiz = lp->d_secsize;
95: if (lp->d_nsectors == default_label.d_nsectors &&
96: lp->d_ntracks == default_label.d_ntracks &&
97: lp->d_ncylinders == default_label.d_ncylinders) {
98: /* I guess there is nothing there */
99: /* Well, then, Adaptec's like ... */
100: dp->dp_sectors = 32;
101: dp->dp_heads = 64;
102: dp->dp_cyls = lp->d_secperunit / 64 / 32 ;
103: } else {
104: dp->dp_sectors = lp->d_nsectors;
105: dp->dp_heads = lp->d_ntracks;
106: dp->dp_cyls = lp->d_ncylinders;
107: }
108:
109: dp->dp_dossectors = 32;
110: dp->dp_dosheads = 64;
111: dp->dp_doscyls = lp->d_secperunit / 64 / 32;
112: dp->dp_ptag = 0;
113: dp->dp_pflag = 0;
114: /* !!! partition changes */
115: printf("USING PARTIOION TABLE\n");
116: dp->dp_pstartsec = lp->d_partitions[part].p_offset;
117: dp->dp_pnumsec = lp->d_partitions[part].p_size;
118: *status_count = sizeof(struct disk_parms)/sizeof(int);
119: break;
120: }
121: case V_RDABS:
122: if (*status_count < DEV_BSIZE/sizeof (int)) {
123: printf("RDABS bad size %x", *status_count);
124: return (D_INVALID_OPERATION);
125: }
126: if (scsi_rw_abs(dev, status, IO_READ, scsi_abs_sec, DEV_BSIZE) != D_SUCCESS)
127: return(D_INVALID_OPERATION);
128: *status_count = DEV_BSIZE/sizeof(int);
129: break;
130: case V_VERIFY: {
131: int count = scsi_abs_count * DEV_BSIZE;
132: int sec = scsi_abs_sec;
133: char *scsi_verify_buf;
134: #include "vm/vm_kern.h"
135:
136: (void) kmem_alloc(kernel_map, &scsi_verify_buf, PAGE_SIZE);
137:
138: *status = 0;
139: while (count > 0) {
140: int xcount = (count < PAGE_SIZE) ? count : PAGE_SIZE;
141: if (scsi_rw_abs(dev, scsi_verify_buf, IO_READ, sec, xcount) != D_SUCCESS) {
142: *status = BAD_BLK;
143: break;
144: } else {
145: count -= xcount;
146: sec += xcount / DEV_BSIZE;
147: }
148: }
149: (void) kmem_free(kernel_map, scsi_verify_buf, PAGE_SIZE);
150: *status_count = 1;
151: break;
152: }
153: default:
154: return(D_INVALID_OPERATION);
155: }
156: return D_SUCCESS;
157: }
158:
159: io_return_t
160: scsi_i386_set_status(dev, tgt, flavor, status, status_count)
161: int dev;
162: target_info_t *tgt;
163: int flavor;
164: int *status;
165: unsigned int status_count;
166: {
167: io_req_t ior;
168:
169: switch (flavor) {
170: case V_SETPARMS:
171: printf("scsdisk_set_status: invalid flavor V_SETPARMS\n");
172: return(D_INVALID_OPERATION);
173: break;
174: case V_REMOUNT:
175: tgt->flags &= ~TGT_ONLINE;
176: break;
177: case V_ABS:
178: scsi_abs_sec = status[0];
179: if (status_count == 2)
180: scsi_abs_count = status[1];
181: break;
182: case V_WRABS:
183: if (status_count < DEV_BSIZE/sizeof (int)) {
184: printf("RDABS bad size %x", status_count);
185: return (D_INVALID_OPERATION);
186: }
187: if (scsi_rw_abs(dev, status, IO_WRITE, scsi_abs_sec, DEV_BSIZE) != D_SUCCESS)
188: return(D_INVALID_OPERATION);
189: break;
190: default:
191: return(D_INVALID_OPERATION);
192: }
193: return D_SUCCESS;
194: }
195: #endif /* NSCSI > 0 */
196:
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.