xref: /titanic_52/usr/src/stand/lib/fs/common/promfs.c (revision e7cbe64f7a72dae5cb44f100db60ca88f3313c65)
1*e7cbe64fSgw25295 /*
2*e7cbe64fSgw25295  * CDDL HEADER START
3*e7cbe64fSgw25295  *
4*e7cbe64fSgw25295  * The contents of this file are subject to the terms of the
5*e7cbe64fSgw25295  * Common Development and Distribution License (the "License").
6*e7cbe64fSgw25295  * You may not use this file except in compliance with the License.
7*e7cbe64fSgw25295  *
8*e7cbe64fSgw25295  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9*e7cbe64fSgw25295  * or http://www.opensolaris.org/os/licensing.
10*e7cbe64fSgw25295  * See the License for the specific language governing permissions
11*e7cbe64fSgw25295  * and limitations under the License.
12*e7cbe64fSgw25295  *
13*e7cbe64fSgw25295  * When distributing Covered Code, include this CDDL HEADER in each
14*e7cbe64fSgw25295  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15*e7cbe64fSgw25295  * If applicable, add the following below this CDDL HEADER, with the
16*e7cbe64fSgw25295  * fields enclosed by brackets "[]" replaced with your own identifying
17*e7cbe64fSgw25295  * information: Portions Copyright [yyyy] [name of copyright owner]
18*e7cbe64fSgw25295  *
19*e7cbe64fSgw25295  * CDDL HEADER END
20*e7cbe64fSgw25295  */
21*e7cbe64fSgw25295 /*
22*e7cbe64fSgw25295  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
23*e7cbe64fSgw25295  * Use is subject to license terms.
24*e7cbe64fSgw25295  */
25*e7cbe64fSgw25295 #pragma ident	"%Z%%M%	%I%	%E% SMI"
26*e7cbe64fSgw25295 
27*e7cbe64fSgw25295 #include <sys/param.h>
28*e7cbe64fSgw25295 #include <sys/sysmacros.h>
29*e7cbe64fSgw25295 #include <sys/stat.h>
30*e7cbe64fSgw25295 #include <sys/bootvfs.h>
31*e7cbe64fSgw25295 #include <sys/bootsyms.h>
32*e7cbe64fSgw25295 #include <sys/promif.h>
33*e7cbe64fSgw25295 #include <sys/salib.h>
34*e7cbe64fSgw25295 
35*e7cbe64fSgw25295 /*
36*e7cbe64fSgw25295  *  Function prototypes
37*e7cbe64fSgw25295  */
38*e7cbe64fSgw25295 static int	promfs_mountroot(char *str);
39*e7cbe64fSgw25295 static int	promfs_unmountroot(void);
40*e7cbe64fSgw25295 static int	promfs_open(char *filename, int flags);
41*e7cbe64fSgw25295 static int	promfs_close(int fd);
42*e7cbe64fSgw25295 static ssize_t	promfs_read(int fd, caddr_t buf, size_t size);
43*e7cbe64fSgw25295 static off_t	promfs_lseek(int fd, off_t offset, int whence);
44*e7cbe64fSgw25295 static int	promfs_fstat(int fd, struct bootstat *stp);
45*e7cbe64fSgw25295 static void	promfs_closeall(int flag);
46*e7cbe64fSgw25295 
47*e7cbe64fSgw25295 struct boot_fs_ops promfs_ops = {
48*e7cbe64fSgw25295 	"promfs",
49*e7cbe64fSgw25295 	promfs_mountroot,
50*e7cbe64fSgw25295 	promfs_unmountroot,
51*e7cbe64fSgw25295 	promfs_open,
52*e7cbe64fSgw25295 	promfs_close,
53*e7cbe64fSgw25295 	promfs_read,
54*e7cbe64fSgw25295 	promfs_lseek,
55*e7cbe64fSgw25295 	promfs_fstat,
56*e7cbe64fSgw25295 	promfs_closeall,
57*e7cbe64fSgw25295 	NULL
58*e7cbe64fSgw25295 };
59*e7cbe64fSgw25295 
60*e7cbe64fSgw25295 static ihandle_t fsih;
61*e7cbe64fSgw25295 
62*e7cbe64fSgw25295 static int
63*e7cbe64fSgw25295 promfs_mountroot(char *str)
64*e7cbe64fSgw25295 {
65*e7cbe64fSgw25295 
66*e7cbe64fSgw25295 	(void) prom_getprop(prom_chosennode(), str, (caddr_t)&fsih);
67*e7cbe64fSgw25295 	return (fsih == -1);
68*e7cbe64fSgw25295 }
69*e7cbe64fSgw25295 
70*e7cbe64fSgw25295 static int
71*e7cbe64fSgw25295 promfs_unmountroot(void)
72*e7cbe64fSgw25295 {
73*e7cbe64fSgw25295 	(void) prom_close(fsih);
74*e7cbe64fSgw25295 	return (0);
75*e7cbe64fSgw25295 }
76*e7cbe64fSgw25295 
77*e7cbe64fSgw25295 /*ARGSUSED*/
78*e7cbe64fSgw25295 static int
79*e7cbe64fSgw25295 promfs_open(char *filename, int flags)
80*e7cbe64fSgw25295 {
81*e7cbe64fSgw25295 	return (prom_fopen(fsih, filename));
82*e7cbe64fSgw25295 }
83*e7cbe64fSgw25295 
84*e7cbe64fSgw25295 static int
85*e7cbe64fSgw25295 promfs_close(int fd)
86*e7cbe64fSgw25295 {
87*e7cbe64fSgw25295 	prom_fclose(fsih, fd);
88*e7cbe64fSgw25295 	return (0);
89*e7cbe64fSgw25295 }
90*e7cbe64fSgw25295 
91*e7cbe64fSgw25295 static ssize_t
92*e7cbe64fSgw25295 promfs_read(int fd, caddr_t buf, size_t size)
93*e7cbe64fSgw25295 {
94*e7cbe64fSgw25295 	return (prom_fread(fsih, fd, buf, size));
95*e7cbe64fSgw25295 }
96*e7cbe64fSgw25295 
97*e7cbe64fSgw25295 /*ARGSUSED*/
98*e7cbe64fSgw25295 static off_t
99*e7cbe64fSgw25295 promfs_lseek(int fd, off_t offset, int whence)
100*e7cbe64fSgw25295 {
101*e7cbe64fSgw25295 	return (prom_fseek(fsih, fd, offset));
102*e7cbe64fSgw25295 }
103*e7cbe64fSgw25295 
104*e7cbe64fSgw25295 static int
105*e7cbe64fSgw25295 promfs_fstat(int fd, struct bootstat *stp)
106*e7cbe64fSgw25295 {
107*e7cbe64fSgw25295 	return (prom_fsize(fsih, fd, (size_t *)&stp->st_size));
108*e7cbe64fSgw25295 }
109*e7cbe64fSgw25295 
110*e7cbe64fSgw25295 /*ARGSUSED*/
111*e7cbe64fSgw25295 static void
112*e7cbe64fSgw25295 promfs_closeall(int flag)
113*e7cbe64fSgw25295 {
114*e7cbe64fSgw25295 }
115