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