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