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