xref: /titanic_51/usr/src/stand/lib/fs/common/diskread.c (revision da14cebe459d3275048785f25bd869cb09b5307f)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License, Version 1.0 only
6  * (the "License").  You may not use this file except in compliance
7  * with the License.
8  *
9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10  * or http://www.opensolaris.org/os/licensing.
11  * See the License for the specific language governing permissions
12  * and limitations under the License.
13  *
14  * When distributing Covered Code, include this CDDL HEADER in each
15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16  * If applicable, add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your own identifying
18  * information: Portions Copyright [yyyy] [name of copyright owner]
19  *
20  * CDDL HEADER END
21  */
22 /*
23  * Copyright 1994-1996, 2002-2003 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 #pragma ident	"%Z%%M%	%I%	%E% SMI"
28 
29 #include <sys/param.h>
30 #include <sys/vnode.h>
31 #include <sys/fs/ufs_fsdir.h>
32 #include <sys/fs/ufs_fs.h>
33 #include <sys/fs/ufs_inode.h>
34 #include <sys/sysmacros.h>
35 #include <sys/promif.h>
36 #include <sys/filep.h>
37 #include <sys/salib.h>
38 
39 static	char	prom_dev_type = 0;
40 
41 /*
42  * unix root slice offset for PROMS that do
43  * not know about fdisk partitions or Solaris
44  * slices.
45  * the default is 0 for machines with proms that
46  * do know how to interpret solaris slices.
47  */
48 unsigned long unix_startblk = 0;
49 
50 /*
51  *	The various flavors of PROM make this grotesque.
52  */
53 int
54 diskread(fileid_t *filep)
55 {
56 	int err;
57 	devid_t	*devp;
58 	uint_t blocknum;
59 
60 	/* add in offset of root slice */
61 	blocknum = filep->fi_blocknum + unix_startblk;
62 
63 	devp = filep->fi_devp;
64 
65 	err = prom_seek(devp->di_dcookie,
66 	    (unsigned long long)blocknum * (unsigned long long)DEV_BSIZE);
67 	if (err == -1) {
68 		printf("Seek error at block %x\n", blocknum);
69 		return (-1);
70 	}
71 
72 	if ((err = prom_read(devp->di_dcookie, filep->fi_memp, filep->fi_count,
73 	    blocknum, prom_dev_type)) != filep->fi_count) {
74 		printf("Short read.  0x%x chars read\n", err);
75 		return (-1);
76 	}
77 
78 	return (0);
79 }
80