xref: /illumos-gate/usr/src/common/fs/pcfs.c (revision c40a6cd785e883b3f052b122c332e21174fc1871)
1*7c478bd9Sstevel@tonic-gate /*
2*7c478bd9Sstevel@tonic-gate  * CDDL HEADER START
3*7c478bd9Sstevel@tonic-gate  *
4*7c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*7c478bd9Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
6*7c478bd9Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
7*7c478bd9Sstevel@tonic-gate  * with the License.
8*7c478bd9Sstevel@tonic-gate  *
9*7c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10*7c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
11*7c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
12*7c478bd9Sstevel@tonic-gate  * and limitations under the License.
13*7c478bd9Sstevel@tonic-gate  *
14*7c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
15*7c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16*7c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
17*7c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
18*7c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
19*7c478bd9Sstevel@tonic-gate  *
20*7c478bd9Sstevel@tonic-gate  * CDDL HEADER END
21*7c478bd9Sstevel@tonic-gate  */
22*7c478bd9Sstevel@tonic-gate /*
23*7c478bd9Sstevel@tonic-gate  * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
24*7c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
25*7c478bd9Sstevel@tonic-gate  */
26*7c478bd9Sstevel@tonic-gate 
27*7c478bd9Sstevel@tonic-gate /*
28*7c478bd9Sstevel@tonic-gate  * Basic file system reading code for standalone I/O system.
29*7c478bd9Sstevel@tonic-gate  * Simulates a primitive UNIX I/O system (read(), write(), open(), etc).
30*7c478bd9Sstevel@tonic-gate  * Does not support writes.
31*7c478bd9Sstevel@tonic-gate  */
32*7c478bd9Sstevel@tonic-gate 
33*7c478bd9Sstevel@tonic-gate /*
34*7c478bd9Sstevel@tonic-gate  * WARNING:
35*7c478bd9Sstevel@tonic-gate  * This is currently used by installgrub for creating bootable floppy.
36*7c478bd9Sstevel@tonic-gate  * The special part is diskread_callback/fileread_callback for gathering
37*7c478bd9Sstevel@tonic-gate  * fileblock list.
38*7c478bd9Sstevel@tonic-gate  */
39*7c478bd9Sstevel@tonic-gate 
40*7c478bd9Sstevel@tonic-gate #include <sys/param.h>
41*7c478bd9Sstevel@tonic-gate #include <sys/sysmacros.h>
42*7c478bd9Sstevel@tonic-gate #include <sys/vnode.h>
43*7c478bd9Sstevel@tonic-gate #include <sys/fs/pc_label.h>
44*7c478bd9Sstevel@tonic-gate #include <sys/bootvfs.h>
45*7c478bd9Sstevel@tonic-gate #include <sys/filep.h>
46*7c478bd9Sstevel@tonic-gate #include "pcfilep.h"
47*7c478bd9Sstevel@tonic-gate 
48*7c478bd9Sstevel@tonic-gate #if	defined(_BOOT)
49*7c478bd9Sstevel@tonic-gate #include "../common/util.h"
50*7c478bd9Sstevel@tonic-gate #elif	defined(_KERNEL)
51*7c478bd9Sstevel@tonic-gate #include <sys/sunddi.h>
52*7c478bd9Sstevel@tonic-gate #else
53*7c478bd9Sstevel@tonic-gate #include <stdio.h>
54*7c478bd9Sstevel@tonic-gate #include <strings.h>
55*7c478bd9Sstevel@tonic-gate #include <ctype.h>
56*7c478bd9Sstevel@tonic-gate #endif
57*7c478bd9Sstevel@tonic-gate 
58*7c478bd9Sstevel@tonic-gate #if	defined(_BOOT)
59*7c478bd9Sstevel@tonic-gate #define	dprintf	if (bootrd_debug) printf
60*7c478bd9Sstevel@tonic-gate #elif	defined(_KERNEL)
61*7c478bd9Sstevel@tonic-gate #define	printf	kobj_printf
62*7c478bd9Sstevel@tonic-gate #define	dprintf	if (bootrd_debug) kobj_printf
63*7c478bd9Sstevel@tonic-gate 
64*7c478bd9Sstevel@tonic-gate /* PRINTLIKE */
65*7c478bd9Sstevel@tonic-gate extern void kobj_printf(char *, ...);
66*7c478bd9Sstevel@tonic-gate #else
67*7c478bd9Sstevel@tonic-gate #define	dprintf if (bootrd_debug) printf
68*7c478bd9Sstevel@tonic-gate #endif
69*7c478bd9Sstevel@tonic-gate 
70*7c478bd9Sstevel@tonic-gate #define	FI_STARTCLUST(fp)	(*(ushort_t *)(fp)->fi_buf)
71*7c478bd9Sstevel@tonic-gate #define	FI_LENGTH(fp)		(*(long *)((fp)->fi_buf + 4))
72*7c478bd9Sstevel@tonic-gate 
73*7c478bd9Sstevel@tonic-gate extern int bootrd_debug;
74*7c478bd9Sstevel@tonic-gate extern void *bkmem_alloc(size_t);
75*7c478bd9Sstevel@tonic-gate extern void bkmem_free(void *, size_t);
76*7c478bd9Sstevel@tonic-gate 
77*7c478bd9Sstevel@tonic-gate /*
78*7c478bd9Sstevel@tonic-gate  * NOTE: The fileread_callback is set by the calling program
79*7c478bd9Sstevel@tonic-gate  * during a file read. diskread_callback is set to fileread_callback
80*7c478bd9Sstevel@tonic-gate  * only if reading a file block. It needs to be NULL while reading
81*7c478bd9Sstevel@tonic-gate  * cluster blocks.
82*7c478bd9Sstevel@tonic-gate  */
83*7c478bd9Sstevel@tonic-gate extern int (*diskread_callback)(int, int);
84*7c478bd9Sstevel@tonic-gate extern int (*fileread_callback)(int, int);
85*7c478bd9Sstevel@tonic-gate 
86*7c478bd9Sstevel@tonic-gate /*
87*7c478bd9Sstevel@tonic-gate  *  Local prototypes
88*7c478bd9Sstevel@tonic-gate  */
89*7c478bd9Sstevel@tonic-gate static int lookuppn(char *, _dir_entry_p);
90*7c478bd9Sstevel@tonic-gate static fileid_t *find_fp(int);
91*7c478bd9Sstevel@tonic-gate static void *readblock(int, int);
92*7c478bd9Sstevel@tonic-gate static int fat_map(int, int);
93*7c478bd9Sstevel@tonic-gate static int cluster_valid(long, int);
94*7c478bd9Sstevel@tonic-gate static int fat_ctodb(int, int);
95*7c478bd9Sstevel@tonic-gate 
96*7c478bd9Sstevel@tonic-gate static int bpcfs_mountroot(char *str);
97*7c478bd9Sstevel@tonic-gate static int bpcfs_unmountroot(void);
98*7c478bd9Sstevel@tonic-gate static int bpcfs_open(char *str, int flags);
99*7c478bd9Sstevel@tonic-gate static int bpcfs_close(int fd);
100*7c478bd9Sstevel@tonic-gate static void bpcfs_closeall(void);
101*7c478bd9Sstevel@tonic-gate static ssize_t bpcfs_read(int fdesc, char *buf, size_t count);
102*7c478bd9Sstevel@tonic-gate static off_t bpcfs_lseek(int fdesc, off_t addr, int whence);
103*7c478bd9Sstevel@tonic-gate 
104*7c478bd9Sstevel@tonic-gate static fileid_t *head;
105*7c478bd9Sstevel@tonic-gate static _fat_controller_p pcfsp;
106*7c478bd9Sstevel@tonic-gate 
107*7c478bd9Sstevel@tonic-gate /* cache the cluster */
108*7c478bd9Sstevel@tonic-gate static int nsec_cache;
109*7c478bd9Sstevel@tonic-gate static int nsec_start;
110*7c478bd9Sstevel@tonic-gate static char *cluster_cache;
111*7c478bd9Sstevel@tonic-gate 
112*7c478bd9Sstevel@tonic-gate /*ARGSUSED*/
113*7c478bd9Sstevel@tonic-gate static int
bpcfs_mountroot(char * str)114*7c478bd9Sstevel@tonic-gate bpcfs_mountroot(char *str)
115*7c478bd9Sstevel@tonic-gate {
116*7c478bd9Sstevel@tonic-gate 	int ncluster;
117*7c478bd9Sstevel@tonic-gate 	if (pcfsp != NULL)
118*7c478bd9Sstevel@tonic-gate 		return (0);	/* already mounted */
119*7c478bd9Sstevel@tonic-gate 
120*7c478bd9Sstevel@tonic-gate 	pcfsp = bkmem_alloc(sizeof (_fat_controller_t));
121*7c478bd9Sstevel@tonic-gate 	head = (fileid_t *)bkmem_alloc(sizeof (fileid_t));
122*7c478bd9Sstevel@tonic-gate 	head->fi_back = head->fi_forw = head;
123*7c478bd9Sstevel@tonic-gate 	head->fi_filedes = 0;
124*7c478bd9Sstevel@tonic-gate 	head->fi_taken = 0;
125*7c478bd9Sstevel@tonic-gate 
126*7c478bd9Sstevel@tonic-gate 	/* read of first floppy sector */
127*7c478bd9Sstevel@tonic-gate 	head->fi_blocknum = 0;
128*7c478bd9Sstevel@tonic-gate 	head->fi_count = SECSIZ;
129*7c478bd9Sstevel@tonic-gate 	head->fi_memp = (caddr_t)pcfsp->f_sector;
130*7c478bd9Sstevel@tonic-gate 	if (diskread(head)) {
131*7c478bd9Sstevel@tonic-gate 		printf("failed to read first sector\n");
132*7c478bd9Sstevel@tonic-gate 		bkmem_free(pcfsp, sizeof (*pcfsp));
133*7c478bd9Sstevel@tonic-gate 		pcfsp = NULL;
134*7c478bd9Sstevel@tonic-gate 		return (-1);
135*7c478bd9Sstevel@tonic-gate 	}
136*7c478bd9Sstevel@tonic-gate 
137*7c478bd9Sstevel@tonic-gate 	if (pcfsp->f_bpb.bs_spc == 0) {
138*7c478bd9Sstevel@tonic-gate 		printf("invalid bios paramet block\n");
139*7c478bd9Sstevel@tonic-gate 		return (-1);
140*7c478bd9Sstevel@tonic-gate 	}
141*7c478bd9Sstevel@tonic-gate 
142*7c478bd9Sstevel@tonic-gate 	pcfsp->f_rootsec =
143*7c478bd9Sstevel@tonic-gate 	    (pcfsp->f_bpb.bs_num_fats * ltohs(pcfsp->f_bpb.bs_spf)) +
144*7c478bd9Sstevel@tonic-gate 	    ltohs(pcfsp->f_bpb.bs_resv_sectors);
145*7c478bd9Sstevel@tonic-gate 	pcfsp->f_rootlen =
146*7c478bd9Sstevel@tonic-gate 	    ltohs(pcfsp->f_bpb.bs_num_root_entries) *
147*7c478bd9Sstevel@tonic-gate 	    sizeof (_dir_entry_t) / SECSIZ;
148*7c478bd9Sstevel@tonic-gate 	pcfsp->f_adjust = 0;
149*7c478bd9Sstevel@tonic-gate 	pcfsp->f_dclust = CLUSTER_ROOTDIR;
150*7c478bd9Sstevel@tonic-gate 	pcfsp->f_filesec = pcfsp->f_rootsec + pcfsp->f_rootlen;
151*7c478bd9Sstevel@tonic-gate 	pcfsp->f_nxtfree = CLUSTER_FIRST;
152*7c478bd9Sstevel@tonic-gate 
153*7c478bd9Sstevel@tonic-gate 	/* figure out the number of clusters in this partition */
154*7c478bd9Sstevel@tonic-gate 	ncluster = (((ulong_t)ltohs(pcfsp->f_bpb.bs_siv) ?
155*7c478bd9Sstevel@tonic-gate 	    (ulong_t)ltohs(pcfsp->f_bpb.bs_siv) :
156*7c478bd9Sstevel@tonic-gate 	    (ulong_t)ltohi(pcfsp->f_bpb.bs_siv)) -
157*7c478bd9Sstevel@tonic-gate 	    pcfsp->f_filesec) / (ulong_t)pcfsp->f_bpb.bs_spc;
158*7c478bd9Sstevel@tonic-gate 	pcfsp->f_16bit = ncluster >= CLUSTER_MAX_12;
159*7c478bd9Sstevel@tonic-gate 	pcfsp->f_ncluster = ncluster;
160*7c478bd9Sstevel@tonic-gate 
161*7c478bd9Sstevel@tonic-gate 	/* cache the cluster */
162*7c478bd9Sstevel@tonic-gate 	if (pcfsp->f_16bit)
163*7c478bd9Sstevel@tonic-gate 		nsec_cache = (((ncluster << 1) + 511) >> 9);
164*7c478bd9Sstevel@tonic-gate 	else
165*7c478bd9Sstevel@tonic-gate 		nsec_cache = (ncluster + ((ncluster + 1) >> 1) + 511) >> 9;
166*7c478bd9Sstevel@tonic-gate 	cluster_cache = bkmem_alloc(nsec_cache * SECSIZ);
167*7c478bd9Sstevel@tonic-gate 	if (cluster_cache == NULL) {
168*7c478bd9Sstevel@tonic-gate 		printf("bpcfs_mountroot: out of memory\n");
169*7c478bd9Sstevel@tonic-gate 		bkmem_free(pcfsp, sizeof (*pcfsp));
170*7c478bd9Sstevel@tonic-gate 		pcfsp = NULL;
171*7c478bd9Sstevel@tonic-gate 		return (-1);
172*7c478bd9Sstevel@tonic-gate 	}
173*7c478bd9Sstevel@tonic-gate 
174*7c478bd9Sstevel@tonic-gate 	head->fi_blocknum = nsec_start =
175*7c478bd9Sstevel@tonic-gate 	    ltohs(pcfsp->f_bpb.bs_resv_sectors) + pcfsp->f_adjust;
176*7c478bd9Sstevel@tonic-gate 	head->fi_count = nsec_cache * SECSIZ;
177*7c478bd9Sstevel@tonic-gate 	head->fi_memp = cluster_cache;
178*7c478bd9Sstevel@tonic-gate 	if (diskread(head)) {
179*7c478bd9Sstevel@tonic-gate 		printf("bpcfs_mountroot: failed to read cluster\n");
180*7c478bd9Sstevel@tonic-gate 		bkmem_free(pcfsp, sizeof (*pcfsp));
181*7c478bd9Sstevel@tonic-gate 		pcfsp = NULL;
182*7c478bd9Sstevel@tonic-gate 		return (-1);
183*7c478bd9Sstevel@tonic-gate 	}
184*7c478bd9Sstevel@tonic-gate 	dprintf("read cluster sectors %d starting at %d\n",
185*7c478bd9Sstevel@tonic-gate 	    nsec_cache, nsec_start);
186*7c478bd9Sstevel@tonic-gate 	return (0);
187*7c478bd9Sstevel@tonic-gate }
188*7c478bd9Sstevel@tonic-gate 
189*7c478bd9Sstevel@tonic-gate static int
bpcfs_unmountroot(void)190*7c478bd9Sstevel@tonic-gate bpcfs_unmountroot(void)
191*7c478bd9Sstevel@tonic-gate {
192*7c478bd9Sstevel@tonic-gate 	if (pcfsp == NULL)
193*7c478bd9Sstevel@tonic-gate 		return (-1);
194*7c478bd9Sstevel@tonic-gate 
195*7c478bd9Sstevel@tonic-gate 	(void) bpcfs_closeall();
196*7c478bd9Sstevel@tonic-gate 
197*7c478bd9Sstevel@tonic-gate 	return (0);
198*7c478bd9Sstevel@tonic-gate }
199*7c478bd9Sstevel@tonic-gate 
200*7c478bd9Sstevel@tonic-gate /*
201*7c478bd9Sstevel@tonic-gate  * Open a file.
202*7c478bd9Sstevel@tonic-gate  */
203*7c478bd9Sstevel@tonic-gate /*ARGSUSED*/
204*7c478bd9Sstevel@tonic-gate int
bpcfs_open(char * str,int flags)205*7c478bd9Sstevel@tonic-gate bpcfs_open(char *str, int flags)
206*7c478bd9Sstevel@tonic-gate {
207*7c478bd9Sstevel@tonic-gate 	static int filedes = 1;
208*7c478bd9Sstevel@tonic-gate 
209*7c478bd9Sstevel@tonic-gate 	fileid_t *filep;
210*7c478bd9Sstevel@tonic-gate 	_dir_entry_t d;
211*7c478bd9Sstevel@tonic-gate 
212*7c478bd9Sstevel@tonic-gate 	dprintf("open %s\n", str);
213*7c478bd9Sstevel@tonic-gate 	filep = (fileid_t *)bkmem_alloc(sizeof (fileid_t));
214*7c478bd9Sstevel@tonic-gate 	filep->fi_back = head->fi_back;
215*7c478bd9Sstevel@tonic-gate 	filep->fi_forw = head;
216*7c478bd9Sstevel@tonic-gate 	head->fi_back->fi_forw = filep;
217*7c478bd9Sstevel@tonic-gate 	head->fi_back = filep;
218*7c478bd9Sstevel@tonic-gate 	filep->fi_filedes = filedes++;
219*7c478bd9Sstevel@tonic-gate 	filep->fi_taken = 1;
220*7c478bd9Sstevel@tonic-gate 	filep->fi_path = (char *)bkmem_alloc(strlen(str) + 1);
221*7c478bd9Sstevel@tonic-gate 	(void) strcpy(filep->fi_path, str);
222*7c478bd9Sstevel@tonic-gate 
223*7c478bd9Sstevel@tonic-gate 	if (lookuppn(str, &d)) {
224*7c478bd9Sstevel@tonic-gate 		(void) bpcfs_close(filep->fi_filedes);
225*7c478bd9Sstevel@tonic-gate 		return (-1);
226*7c478bd9Sstevel@tonic-gate 	}
227*7c478bd9Sstevel@tonic-gate 
228*7c478bd9Sstevel@tonic-gate 	filep->fi_offset = 0;
229*7c478bd9Sstevel@tonic-gate 	FI_STARTCLUST(filep) = d.d_cluster;
230*7c478bd9Sstevel@tonic-gate 	FI_LENGTH(filep) = d.d_size;
231*7c478bd9Sstevel@tonic-gate 	dprintf("file %s size = %ld\n", str, d.d_size);
232*7c478bd9Sstevel@tonic-gate 	return (filep->fi_filedes);
233*7c478bd9Sstevel@tonic-gate }
234*7c478bd9Sstevel@tonic-gate 
235*7c478bd9Sstevel@tonic-gate int
bpcfs_close(int fd)236*7c478bd9Sstevel@tonic-gate bpcfs_close(int fd)
237*7c478bd9Sstevel@tonic-gate {
238*7c478bd9Sstevel@tonic-gate 	fileid_t *filep;
239*7c478bd9Sstevel@tonic-gate 
240*7c478bd9Sstevel@tonic-gate 	dprintf("close %d\n", fd);
241*7c478bd9Sstevel@tonic-gate 	if (!(filep = find_fp(fd)))
242*7c478bd9Sstevel@tonic-gate 		return (-1);
243*7c478bd9Sstevel@tonic-gate 
244*7c478bd9Sstevel@tonic-gate 	if (filep->fi_taken == 0 || filep == head) {
245*7c478bd9Sstevel@tonic-gate 		printf("File descripter %d no allocated!\n", fd);
246*7c478bd9Sstevel@tonic-gate 		return (-1);
247*7c478bd9Sstevel@tonic-gate 	}
248*7c478bd9Sstevel@tonic-gate 
249*7c478bd9Sstevel@tonic-gate 	/* unlink and deallocate node */
250*7c478bd9Sstevel@tonic-gate 	filep->fi_forw->fi_back = filep->fi_back;
251*7c478bd9Sstevel@tonic-gate 	filep->fi_back->fi_forw = filep->fi_forw;
252*7c478bd9Sstevel@tonic-gate 	bkmem_free(filep->fi_path, strlen(filep->fi_path) + 1);
253*7c478bd9Sstevel@tonic-gate 	bkmem_free((char *)filep, sizeof (fileid_t));
254*7c478bd9Sstevel@tonic-gate 	dprintf("close done\n");
255*7c478bd9Sstevel@tonic-gate 	return (0);
256*7c478bd9Sstevel@tonic-gate }
257*7c478bd9Sstevel@tonic-gate 
258*7c478bd9Sstevel@tonic-gate static void
bpcfs_closeall(void)259*7c478bd9Sstevel@tonic-gate bpcfs_closeall(void)
260*7c478bd9Sstevel@tonic-gate {
261*7c478bd9Sstevel@tonic-gate 	fileid_t *filep;
262*7c478bd9Sstevel@tonic-gate 
263*7c478bd9Sstevel@tonic-gate 	while ((filep = head->fi_forw) != head)
264*7c478bd9Sstevel@tonic-gate 		if (filep->fi_taken && bpcfs_close(filep->fi_filedes))
265*7c478bd9Sstevel@tonic-gate 			printf("Filesystem may be inconsistent.\n");
266*7c478bd9Sstevel@tonic-gate 
267*7c478bd9Sstevel@tonic-gate 	bkmem_free(pcfsp, sizeof (*pcfsp));
268*7c478bd9Sstevel@tonic-gate 	bkmem_free(head, sizeof (fileid_t));
269*7c478bd9Sstevel@tonic-gate 	pcfsp = NULL;
270*7c478bd9Sstevel@tonic-gate 	head = NULL;
271*7c478bd9Sstevel@tonic-gate }
272*7c478bd9Sstevel@tonic-gate 
273*7c478bd9Sstevel@tonic-gate static ssize_t
bpcfs_read(int fd,caddr_t b,size_t c)274*7c478bd9Sstevel@tonic-gate bpcfs_read(int fd, caddr_t b, size_t c)
275*7c478bd9Sstevel@tonic-gate {
276*7c478bd9Sstevel@tonic-gate 	ulong_t sector;
277*7c478bd9Sstevel@tonic-gate 	uint_t count = 0, xfer, i;
278*7c478bd9Sstevel@tonic-gate 	char *block;
279*7c478bd9Sstevel@tonic-gate 	ulong_t off, blk;
280*7c478bd9Sstevel@tonic-gate 	int rd, spc;
281*7c478bd9Sstevel@tonic-gate 	fileid_t *fp;
282*7c478bd9Sstevel@tonic-gate 
283*7c478bd9Sstevel@tonic-gate 	dprintf("bpcfs_read: fd = %d, buf = %p, size = %d\n",
284*7c478bd9Sstevel@tonic-gate 		fd, (void *)b, c);
285*7c478bd9Sstevel@tonic-gate 	fp = find_fp(fd);
286*7c478bd9Sstevel@tonic-gate 	if (fp == NULL) {
287*7c478bd9Sstevel@tonic-gate 		printf("invalid file descriptor %d\n", fd);
288*7c478bd9Sstevel@tonic-gate 		return (-1);
289*7c478bd9Sstevel@tonic-gate 	}
290*7c478bd9Sstevel@tonic-gate 
291*7c478bd9Sstevel@tonic-gate 	spc = pcfsp->f_bpb.bs_spc;
292*7c478bd9Sstevel@tonic-gate 	off = fp->fi_offset;
293*7c478bd9Sstevel@tonic-gate 	blk = FI_STARTCLUST(fp);
294*7c478bd9Sstevel@tonic-gate 	rd = blk == CLUSTER_ROOTDIR ? 1 : 0;
295*7c478bd9Sstevel@tonic-gate 
296*7c478bd9Sstevel@tonic-gate 	spc = pcfsp->f_bpb.bs_spc;
297*7c478bd9Sstevel@tonic-gate 	off = fp->fi_offset;
298*7c478bd9Sstevel@tonic-gate 	blk = FI_STARTCLUST(fp);
299*7c478bd9Sstevel@tonic-gate 	rd = (blk == CLUSTER_ROOTDIR) ? 1 : 0;
300*7c478bd9Sstevel@tonic-gate 
301*7c478bd9Sstevel@tonic-gate 	if ((c = MIN(FI_LENGTH(fp) - off, c)) == 0)
302*7c478bd9Sstevel@tonic-gate 		return (0);
303*7c478bd9Sstevel@tonic-gate 
304*7c478bd9Sstevel@tonic-gate 	while (off >= pcfsp->f_bpb.bs_spc * SECSIZ) {
305*7c478bd9Sstevel@tonic-gate 		blk = fat_map(blk, rd);
306*7c478bd9Sstevel@tonic-gate 		off -= pcfsp->f_bpb.bs_spc * SECSIZ;
307*7c478bd9Sstevel@tonic-gate 
308*7c478bd9Sstevel@tonic-gate 		if (!cluster_valid(blk, rd)) {
309*7c478bd9Sstevel@tonic-gate 			printf("bpcfs_read: invalid cluster: %ld, %d\n",
310*7c478bd9Sstevel@tonic-gate 			    blk, rd);
311*7c478bd9Sstevel@tonic-gate 			return (-1);
312*7c478bd9Sstevel@tonic-gate 		}
313*7c478bd9Sstevel@tonic-gate 	}
314*7c478bd9Sstevel@tonic-gate 
315*7c478bd9Sstevel@tonic-gate 	while (count < c) {
316*7c478bd9Sstevel@tonic-gate 		sector = fat_ctodb(blk, rd);
317*7c478bd9Sstevel@tonic-gate 		diskread_callback = fileread_callback;
318*7c478bd9Sstevel@tonic-gate 		for (i = ((off / SECSIZ) % pcfsp->f_bpb.bs_spc); i < spc; i++) {
319*7c478bd9Sstevel@tonic-gate 			xfer = MIN(SECSIZ - (off % SECSIZ), c - count);
320*7c478bd9Sstevel@tonic-gate 			if (xfer == 0)
321*7c478bd9Sstevel@tonic-gate 				break;	/* last sector done */
322*7c478bd9Sstevel@tonic-gate 
323*7c478bd9Sstevel@tonic-gate 			block = (char *)readblock(sector + i, 1);
324*7c478bd9Sstevel@tonic-gate 			if (block == NULL) {
325*7c478bd9Sstevel@tonic-gate 				return (-1);
326*7c478bd9Sstevel@tonic-gate 			}
327*7c478bd9Sstevel@tonic-gate 			dprintf("bpcfs_read: read %d bytes\n", xfer);
328*7c478bd9Sstevel@tonic-gate 			if (diskread_callback == NULL)
329*7c478bd9Sstevel@tonic-gate 				(void) bcopy(&block[off % SECSIZ], b, xfer);
330*7c478bd9Sstevel@tonic-gate 			count += xfer;
331*7c478bd9Sstevel@tonic-gate 			off += xfer;
332*7c478bd9Sstevel@tonic-gate 			b += xfer;
333*7c478bd9Sstevel@tonic-gate 		}
334*7c478bd9Sstevel@tonic-gate 
335*7c478bd9Sstevel@tonic-gate 		diskread_callback = NULL;
336*7c478bd9Sstevel@tonic-gate 		if (count < c) {
337*7c478bd9Sstevel@tonic-gate 			blk = fat_map(blk, rd);
338*7c478bd9Sstevel@tonic-gate 			if (!cluster_valid(blk, rd)) {
339*7c478bd9Sstevel@tonic-gate 				printf("bpcfs_read: invalid cluster: %ld, %d\n",
340*7c478bd9Sstevel@tonic-gate 				    blk, rd);
341*7c478bd9Sstevel@tonic-gate 				break;
342*7c478bd9Sstevel@tonic-gate 			}
343*7c478bd9Sstevel@tonic-gate 		}
344*7c478bd9Sstevel@tonic-gate 	}
345*7c478bd9Sstevel@tonic-gate 
346*7c478bd9Sstevel@tonic-gate 	fp->fi_offset += count;
347*7c478bd9Sstevel@tonic-gate 	return (count);
348*7c478bd9Sstevel@tonic-gate }
349*7c478bd9Sstevel@tonic-gate 
350*7c478bd9Sstevel@tonic-gate /*
351*7c478bd9Sstevel@tonic-gate  * This version of seek() only performs absolute seeks (whence == 0).
352*7c478bd9Sstevel@tonic-gate  */
353*7c478bd9Sstevel@tonic-gate static off_t
bpcfs_lseek(int fd,off_t addr,int whence)354*7c478bd9Sstevel@tonic-gate bpcfs_lseek(int fd, off_t addr, int whence)
355*7c478bd9Sstevel@tonic-gate {
356*7c478bd9Sstevel@tonic-gate 	fileid_t *filep;
357*7c478bd9Sstevel@tonic-gate 
358*7c478bd9Sstevel@tonic-gate 	dprintf("lseek %d, off = %lx\n", fd, addr);
359*7c478bd9Sstevel@tonic-gate 	if (!(filep = find_fp(fd)))
360*7c478bd9Sstevel@tonic-gate 		return (-1);
361*7c478bd9Sstevel@tonic-gate 
362*7c478bd9Sstevel@tonic-gate 	switch (whence) {
363*7c478bd9Sstevel@tonic-gate 	case SEEK_CUR:
364*7c478bd9Sstevel@tonic-gate 		filep->fi_offset += addr;
365*7c478bd9Sstevel@tonic-gate 		break;
366*7c478bd9Sstevel@tonic-gate 	case SEEK_SET:
367*7c478bd9Sstevel@tonic-gate 		filep->fi_offset = addr;
368*7c478bd9Sstevel@tonic-gate 		break;
369*7c478bd9Sstevel@tonic-gate 	default:
370*7c478bd9Sstevel@tonic-gate 	case SEEK_END:
371*7c478bd9Sstevel@tonic-gate 		printf("lseek(): invalid whence value %d\n", whence);
372*7c478bd9Sstevel@tonic-gate 		break;
373*7c478bd9Sstevel@tonic-gate 	}
374*7c478bd9Sstevel@tonic-gate 
375*7c478bd9Sstevel@tonic-gate 	filep->fi_blocknum = addr / DEV_BSIZE;
376*7c478bd9Sstevel@tonic-gate 	filep->fi_count = 0;
377*7c478bd9Sstevel@tonic-gate 	return (0);
378*7c478bd9Sstevel@tonic-gate }
379*7c478bd9Sstevel@tonic-gate 
380*7c478bd9Sstevel@tonic-gate static fileid_t *
find_fp(int fd)381*7c478bd9Sstevel@tonic-gate find_fp(int fd)
382*7c478bd9Sstevel@tonic-gate {
383*7c478bd9Sstevel@tonic-gate 	fileid_t *filep = head;
384*7c478bd9Sstevel@tonic-gate 
385*7c478bd9Sstevel@tonic-gate 	if (fd >= 0) {
386*7c478bd9Sstevel@tonic-gate 		while ((filep = filep->fi_forw) != head)
387*7c478bd9Sstevel@tonic-gate 			if (fd == filep->fi_filedes)
388*7c478bd9Sstevel@tonic-gate 				return (filep->fi_taken ? filep : 0);
389*7c478bd9Sstevel@tonic-gate 	}
390*7c478bd9Sstevel@tonic-gate 
391*7c478bd9Sstevel@tonic-gate 	return (0);
392*7c478bd9Sstevel@tonic-gate }
393*7c478bd9Sstevel@tonic-gate 
394*7c478bd9Sstevel@tonic-gate static int
cluster_valid(long c,int rd)395*7c478bd9Sstevel@tonic-gate cluster_valid(long c, int rd)
396*7c478bd9Sstevel@tonic-gate {
397*7c478bd9Sstevel@tonic-gate 	return ((rd && (c == 0)) ? 1 : (c >= CLUSTER_RES_16_0 ? 0 : c));
398*7c478bd9Sstevel@tonic-gate }
399*7c478bd9Sstevel@tonic-gate 
400*7c478bd9Sstevel@tonic-gate static int
fat_ctodb(int blk,int r)401*7c478bd9Sstevel@tonic-gate fat_ctodb(int blk, int r)
402*7c478bd9Sstevel@tonic-gate {
403*7c478bd9Sstevel@tonic-gate 	uint_t s;
404*7c478bd9Sstevel@tonic-gate 
405*7c478bd9Sstevel@tonic-gate 	s = r ? blk + pcfsp->f_rootsec + pcfsp->f_adjust :
406*7c478bd9Sstevel@tonic-gate 	    ((blk - 2) * pcfsp->f_bpb.bs_spc) +
407*7c478bd9Sstevel@tonic-gate 	    pcfsp->f_filesec + pcfsp->f_adjust;
408*7c478bd9Sstevel@tonic-gate 
409*7c478bd9Sstevel@tonic-gate 	return (s);
410*7c478bd9Sstevel@tonic-gate }
411*7c478bd9Sstevel@tonic-gate 
412*7c478bd9Sstevel@tonic-gate static int
fat_map(int blk,int rootdir)413*7c478bd9Sstevel@tonic-gate fat_map(int blk, int rootdir)
414*7c478bd9Sstevel@tonic-gate {
415*7c478bd9Sstevel@tonic-gate 	ulong_t sectn, fat_index;
416*7c478bd9Sstevel@tonic-gate 	uchar_t *fp;
417*7c478bd9Sstevel@tonic-gate 
418*7c478bd9Sstevel@tonic-gate 	if (rootdir) {
419*7c478bd9Sstevel@tonic-gate 		return (blk > pcfsp->f_rootlen ? CLUSTER_EOF : blk + 1);
420*7c478bd9Sstevel@tonic-gate 	}
421*7c478bd9Sstevel@tonic-gate 
422*7c478bd9Sstevel@tonic-gate 	/* ---- Find out what sector this cluster is in ---- */
423*7c478bd9Sstevel@tonic-gate 	fat_index = (pcfsp->f_16bit) ? ((ulong_t)blk << 1) :
424*7c478bd9Sstevel@tonic-gate 	    ((ulong_t)blk + ((uint_t)blk >> 1));
425*7c478bd9Sstevel@tonic-gate 
426*7c478bd9Sstevel@tonic-gate 	sectn = (fat_index / SECSIZ) + ltohs(pcfsp->f_bpb.bs_resv_sectors)
427*7c478bd9Sstevel@tonic-gate 	    + pcfsp->f_adjust;
428*7c478bd9Sstevel@tonic-gate 
429*7c478bd9Sstevel@tonic-gate 	/*
430*7c478bd9Sstevel@tonic-gate 	 * Read two sectors so that if our fat_index points at the last byte
431*7c478bd9Sstevel@tonic-gate 	 * byte we'll have the data needed.  This is only a problem for fat12
432*7c478bd9Sstevel@tonic-gate 	 * entries.
433*7c478bd9Sstevel@tonic-gate 	 */
434*7c478bd9Sstevel@tonic-gate 	if (!(fp = (uchar_t *)readblock(sectn, 2))) {
435*7c478bd9Sstevel@tonic-gate 		printf("fat_map: bad cluster\n");
436*7c478bd9Sstevel@tonic-gate 		return (CLUSTER_BAD_16);
437*7c478bd9Sstevel@tonic-gate 	}
438*7c478bd9Sstevel@tonic-gate 
439*7c478bd9Sstevel@tonic-gate 	fp += (fat_index % SECSIZ);
440*7c478bd9Sstevel@tonic-gate 
441*7c478bd9Sstevel@tonic-gate 	if (pcfsp->f_16bit)
442*7c478bd9Sstevel@tonic-gate 		blk = fp[0] | (fp[1] << 8);
443*7c478bd9Sstevel@tonic-gate 	else {
444*7c478bd9Sstevel@tonic-gate 		if (blk & 1)
445*7c478bd9Sstevel@tonic-gate 			blk = ((fp[0] >> 4) & 0xf) | (fp[1] << 4);
446*7c478bd9Sstevel@tonic-gate 		else
447*7c478bd9Sstevel@tonic-gate 			blk = ((fp[1] & 0xf) << 8) | fp[0];
448*7c478bd9Sstevel@tonic-gate 
449*7c478bd9Sstevel@tonic-gate 		/*
450*7c478bd9Sstevel@tonic-gate 		 * This makes compares easier because we can just compare
451*7c478bd9Sstevel@tonic-gate 		 * against one value instead of two.
452*7c478bd9Sstevel@tonic-gate 		 */
453*7c478bd9Sstevel@tonic-gate 		if (blk >= CLUSTER_RES_12_0)
454*7c478bd9Sstevel@tonic-gate 			blk |= CLUSTER_RES_16_0;
455*7c478bd9Sstevel@tonic-gate 	}
456*7c478bd9Sstevel@tonic-gate 	return (blk);
457*7c478bd9Sstevel@tonic-gate }
458*7c478bd9Sstevel@tonic-gate 
459*7c478bd9Sstevel@tonic-gate static int
namecmp(char * pn,char * dn,int cs)460*7c478bd9Sstevel@tonic-gate namecmp(char *pn, char *dn, int cs)
461*7c478bd9Sstevel@tonic-gate {
462*7c478bd9Sstevel@tonic-gate 	dprintf("namecmp %s, %s, len = %d\n", pn, dn, cs);
463*7c478bd9Sstevel@tonic-gate 
464*7c478bd9Sstevel@tonic-gate 	/* starting char must match */
465*7c478bd9Sstevel@tonic-gate 	while (*pn && *dn) {
466*7c478bd9Sstevel@tonic-gate 		--cs;
467*7c478bd9Sstevel@tonic-gate 		if (toupper(*pn++) != toupper(*dn++))
468*7c478bd9Sstevel@tonic-gate 			return (1);
469*7c478bd9Sstevel@tonic-gate 	}
470*7c478bd9Sstevel@tonic-gate 
471*7c478bd9Sstevel@tonic-gate 	dprintf("namecmp: cs = %d\n", cs);
472*7c478bd9Sstevel@tonic-gate 	/* remainder should be either ~# or all spaces */
473*7c478bd9Sstevel@tonic-gate 	if (cs > 0 && *dn == '~')
474*7c478bd9Sstevel@tonic-gate 		return (0);
475*7c478bd9Sstevel@tonic-gate 	while (cs > 0) {
476*7c478bd9Sstevel@tonic-gate 		if (*dn++ != ' ')
477*7c478bd9Sstevel@tonic-gate 			return (1);
478*7c478bd9Sstevel@tonic-gate 		--cs;
479*7c478bd9Sstevel@tonic-gate 	}
480*7c478bd9Sstevel@tonic-gate 	return (0);
481*7c478bd9Sstevel@tonic-gate }
482*7c478bd9Sstevel@tonic-gate 
483*7c478bd9Sstevel@tonic-gate static int
dircmp(char * name,char * d_name,char * d_ext)484*7c478bd9Sstevel@tonic-gate dircmp(char *name, char *d_name, char *d_ext)
485*7c478bd9Sstevel@tonic-gate {
486*7c478bd9Sstevel@tonic-gate 	int ret;
487*7c478bd9Sstevel@tonic-gate 	char *sep, *ext;
488*7c478bd9Sstevel@tonic-gate 
489*7c478bd9Sstevel@tonic-gate 	sep = (char *)strchr(name, '.');
490*7c478bd9Sstevel@tonic-gate 
491*7c478bd9Sstevel@tonic-gate 	if (sep) {
492*7c478bd9Sstevel@tonic-gate 		*sep = '\0';
493*7c478bd9Sstevel@tonic-gate 		ext = sep + 1;
494*7c478bd9Sstevel@tonic-gate 	} else
495*7c478bd9Sstevel@tonic-gate 		ext = "   ";
496*7c478bd9Sstevel@tonic-gate 
497*7c478bd9Sstevel@tonic-gate 	if (namecmp(name, d_name, NAMESIZ) || namecmp(ext, d_ext, EXTSIZ))
498*7c478bd9Sstevel@tonic-gate 		ret = 1;
499*7c478bd9Sstevel@tonic-gate 	else
500*7c478bd9Sstevel@tonic-gate 		ret = 0;
501*7c478bd9Sstevel@tonic-gate 	if (sep)
502*7c478bd9Sstevel@tonic-gate 		*sep = '.';
503*7c478bd9Sstevel@tonic-gate 	return (ret);
504*7c478bd9Sstevel@tonic-gate }
505*7c478bd9Sstevel@tonic-gate 
506*7c478bd9Sstevel@tonic-gate static int
lookup(char * n,_dir_entry_p dp,ulong_t dir_blk)507*7c478bd9Sstevel@tonic-gate lookup(char *n, _dir_entry_p dp, ulong_t dir_blk)
508*7c478bd9Sstevel@tonic-gate {
509*7c478bd9Sstevel@tonic-gate 	int spc = pcfsp->f_bpb.bs_spc;
510*7c478bd9Sstevel@tonic-gate 	int rd = (dir_blk == CLUSTER_ROOTDIR ? 1 : 0);
511*7c478bd9Sstevel@tonic-gate 	_dir_entry_p dxp;
512*7c478bd9Sstevel@tonic-gate 	int j, sector;
513*7c478bd9Sstevel@tonic-gate 
514*7c478bd9Sstevel@tonic-gate 	dprintf("lookup: name = %s\n", n);
515*7c478bd9Sstevel@tonic-gate 
516*7c478bd9Sstevel@tonic-gate 	while (cluster_valid(dir_blk, rd)) {
517*7c478bd9Sstevel@tonic-gate 		sector = fat_ctodb(dir_blk, rd);
518*7c478bd9Sstevel@tonic-gate 		dxp = readblock(sector, 1);	/* read one sector */
519*7c478bd9Sstevel@tonic-gate 		if (dxp == NULL)
520*7c478bd9Sstevel@tonic-gate 			return (0);
521*7c478bd9Sstevel@tonic-gate 		for (j = 0; j < DIRENTS * spc; j++, dxp++) {
522*7c478bd9Sstevel@tonic-gate 			dprintf("lookup: dir entry %s.%s;\n",
523*7c478bd9Sstevel@tonic-gate 			    dxp->d_name, dxp->d_ext);
524*7c478bd9Sstevel@tonic-gate 			if (dxp->d_name[0] == 0)
525*7c478bd9Sstevel@tonic-gate 				return (0);
526*7c478bd9Sstevel@tonic-gate 			if ((uchar_t)dxp->d_name[0] != 0xE5 &&
527*7c478bd9Sstevel@tonic-gate 			    (dxp->d_attr & (DE_LABEL|DE_HIDDEN)) == 0 &&
528*7c478bd9Sstevel@tonic-gate 			    dircmp(n, dxp->d_name, dxp->d_ext) == 0) {
529*7c478bd9Sstevel@tonic-gate 				dprintf("lookup: match found\n");
530*7c478bd9Sstevel@tonic-gate 				(void) bcopy(dxp, dp, sizeof (*dp));
531*7c478bd9Sstevel@tonic-gate 				return (1);
532*7c478bd9Sstevel@tonic-gate 			}
533*7c478bd9Sstevel@tonic-gate 		}
534*7c478bd9Sstevel@tonic-gate 		/* next cluster */
535*7c478bd9Sstevel@tonic-gate 		dir_blk = fat_map(dir_blk, rd);
536*7c478bd9Sstevel@tonic-gate 	}
537*7c478bd9Sstevel@tonic-gate 
538*7c478bd9Sstevel@tonic-gate 	return (0);
539*7c478bd9Sstevel@tonic-gate }
540*7c478bd9Sstevel@tonic-gate 
541*7c478bd9Sstevel@tonic-gate static int
lookuppn(char * n,_dir_entry_p dp)542*7c478bd9Sstevel@tonic-gate lookuppn(char *n, _dir_entry_p dp)
543*7c478bd9Sstevel@tonic-gate {
544*7c478bd9Sstevel@tonic-gate 	long dir_blk;
545*7c478bd9Sstevel@tonic-gate 	char name[8 + 1 + 3 + 1];	/* <8>.<3>'\0' */
546*7c478bd9Sstevel@tonic-gate 	char *p, *ep;
547*7c478bd9Sstevel@tonic-gate 	_dir_entry_t dd;
548*7c478bd9Sstevel@tonic-gate 
549*7c478bd9Sstevel@tonic-gate 	dprintf("lookuppn: path = %s\n", n);
550*7c478bd9Sstevel@tonic-gate 	dir_blk = pcfsp->f_dclust;
551*7c478bd9Sstevel@tonic-gate 	if ((*n == '\\') || (*n == '/')) {
552*7c478bd9Sstevel@tonic-gate 		dir_blk = CLUSTER_ROOTDIR;
553*7c478bd9Sstevel@tonic-gate 		while ((*n == '\\') || (*n == '/'))
554*7c478bd9Sstevel@tonic-gate 			n++;
555*7c478bd9Sstevel@tonic-gate 		if (*n == '\0') {
556*7c478bd9Sstevel@tonic-gate 			(void) bzero(dp, sizeof (*dp));
557*7c478bd9Sstevel@tonic-gate 			dp->d_cluster = CLUSTER_ROOTDIR;
558*7c478bd9Sstevel@tonic-gate 			dp->d_attr = DE_DIRECTORY;
559*7c478bd9Sstevel@tonic-gate 			return (0);
560*7c478bd9Sstevel@tonic-gate 		}
561*7c478bd9Sstevel@tonic-gate 	}
562*7c478bd9Sstevel@tonic-gate 
563*7c478bd9Sstevel@tonic-gate 	ep = &name[0] + sizeof (name);
564*7c478bd9Sstevel@tonic-gate 	while (*n) {
565*7c478bd9Sstevel@tonic-gate 		(void) bzero(name, sizeof (name));
566*7c478bd9Sstevel@tonic-gate 		p = &name[0];
567*7c478bd9Sstevel@tonic-gate 		while (*n && (*n != '\\') && (*n != '/'))
568*7c478bd9Sstevel@tonic-gate 			if (p != ep)
569*7c478bd9Sstevel@tonic-gate 				*p++ = *n++;
570*7c478bd9Sstevel@tonic-gate 			else {
571*7c478bd9Sstevel@tonic-gate 				dprintf("return, name %s is too long\n", name);
572*7c478bd9Sstevel@tonic-gate 				return (-1);	/* name is too long */
573*7c478bd9Sstevel@tonic-gate 			}
574*7c478bd9Sstevel@tonic-gate 		while ((*n == '\\') || (*n == '/'))
575*7c478bd9Sstevel@tonic-gate 			n++;
576*7c478bd9Sstevel@tonic-gate 		if (lookup(name, &dd, dir_blk) == 0) {
577*7c478bd9Sstevel@tonic-gate 			dprintf("return, name %s not found\n", name);
578*7c478bd9Sstevel@tonic-gate 			return (-1);
579*7c478bd9Sstevel@tonic-gate 		}
580*7c478bd9Sstevel@tonic-gate 		dprintf("dd = %x:%x:%x attr = %x\n",
581*7c478bd9Sstevel@tonic-gate 		    *(int *)&dd, *(((int *)&dd) + 1),
582*7c478bd9Sstevel@tonic-gate 		    *(((int *)&dd) + 2), dd.d_attr);
583*7c478bd9Sstevel@tonic-gate 		if (*n && ((dd.d_attr & DE_DIRECTORY) == 0)) {
584*7c478bd9Sstevel@tonic-gate 			dprintf("return, not a directory\n");
585*7c478bd9Sstevel@tonic-gate 			return (-1);
586*7c478bd9Sstevel@tonic-gate 		}
587*7c478bd9Sstevel@tonic-gate 
588*7c478bd9Sstevel@tonic-gate 		dir_blk = dd.d_cluster;
589*7c478bd9Sstevel@tonic-gate 	}
590*7c478bd9Sstevel@tonic-gate 	(void) bcopy(&dd, dp, sizeof (dd));
591*7c478bd9Sstevel@tonic-gate 	return (0);
592*7c478bd9Sstevel@tonic-gate }
593*7c478bd9Sstevel@tonic-gate 
594*7c478bd9Sstevel@tonic-gate static void *
readblock(int sector,int nsec)595*7c478bd9Sstevel@tonic-gate readblock(int sector, int nsec)
596*7c478bd9Sstevel@tonic-gate {
597*7c478bd9Sstevel@tonic-gate 	if (sector >= nsec_start && sector + nsec <= nsec_start + nsec_cache)
598*7c478bd9Sstevel@tonic-gate 		return (cluster_cache + (sector - nsec_start) * SECSIZ);
599*7c478bd9Sstevel@tonic-gate 
600*7c478bd9Sstevel@tonic-gate 	/* read disk sectors */
601*7c478bd9Sstevel@tonic-gate 	head->fi_blocknum = sector;
602*7c478bd9Sstevel@tonic-gate 	head->fi_count = nsec * SECSIZ;
603*7c478bd9Sstevel@tonic-gate 	head->fi_memp = head->fi_buf;
604*7c478bd9Sstevel@tonic-gate 	if (diskread(head)) {
605*7c478bd9Sstevel@tonic-gate 		printf("failed to %d sectors at %d\n", nsec, sector);
606*7c478bd9Sstevel@tonic-gate 		return (NULL);
607*7c478bd9Sstevel@tonic-gate 	}
608*7c478bd9Sstevel@tonic-gate 
609*7c478bd9Sstevel@tonic-gate 	return (head->fi_buf);
610*7c478bd9Sstevel@tonic-gate }
611*7c478bd9Sstevel@tonic-gate 
612*7c478bd9Sstevel@tonic-gate struct boot_fs_ops bpcfs_ops = {
613*7c478bd9Sstevel@tonic-gate 	"boot_pcfs",
614*7c478bd9Sstevel@tonic-gate 	bpcfs_mountroot,
615*7c478bd9Sstevel@tonic-gate 	bpcfs_unmountroot,
616*7c478bd9Sstevel@tonic-gate 	bpcfs_open,
617*7c478bd9Sstevel@tonic-gate 	bpcfs_close,
618*7c478bd9Sstevel@tonic-gate 	bpcfs_read,
619*7c478bd9Sstevel@tonic-gate 	bpcfs_lseek,
620*7c478bd9Sstevel@tonic-gate 	NULL
621*7c478bd9Sstevel@tonic-gate };
622