]>
Commit | Line | Data |
---|---|---|
1c79356b | 1 | /* |
91447636 | 2 | * Copyright (c) 2000-2004 Apple Computer, Inc. All rights reserved. |
1c79356b A |
3 | * |
4 | * @APPLE_LICENSE_HEADER_START@ | |
5 | * | |
37839358 A |
6 | * The contents of this file constitute Original Code as defined in and |
7 | * are subject to the Apple Public Source License Version 1.1 (the | |
8 | * "License"). You may not use this file except in compliance with the | |
9 | * License. Please obtain a copy of the License at | |
10 | * http://www.apple.com/publicsource and read it before using this file. | |
1c79356b | 11 | * |
37839358 A |
12 | * This Original Code and all software distributed under the License are |
13 | * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER | |
1c79356b A |
14 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, |
15 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, | |
37839358 A |
16 | * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the |
17 | * License for the specific language governing rights and limitations | |
18 | * under the License. | |
1c79356b A |
19 | * |
20 | * @APPLE_LICENSE_HEADER_END@ | |
21 | */ | |
22 | /* | |
23 | * BSD driver for Non-volatile RAM. | |
24 | * Stub functions call the real thing in the Platform Expert. | |
25 | * | |
26 | * Suurballe 11 Feb 1999 | |
27 | */ | |
28 | ||
29 | #include <sys/types.h> | |
30 | #include <sys/param.h> | |
31 | ||
32 | extern int PEnvopen ( dev_t, int, int, struct proc * ); | |
33 | extern int PEnvclose ( dev_t, int, int, struct proc * ); | |
34 | extern int PEnvread ( long, int, unsigned char *); | |
35 | extern int PEnvwrite ( long, int, unsigned char * ); | |
36 | ||
37 | ||
38 | nvopen(dev, flag, devtype, pp) | |
39 | dev_t dev; | |
40 | int flag, devtype; | |
41 | struct proc *pp; | |
42 | { | |
43 | return PEnvopen(dev,flag,devtype,pp); | |
44 | } | |
45 | ||
46 | ||
47 | ||
48 | nvclose(dev, flag, mode, pp) | |
49 | dev_t dev; | |
50 | int flag, mode; | |
51 | struct proc *pp; | |
52 | { | |
53 | return PEnvclose(dev,flag,mode,pp); | |
54 | } | |
55 | ||
56 | ||
57 | ||
58 | nvread(dev, uio, ioflag) | |
59 | dev_t dev; | |
60 | struct uio *uio; | |
61 | int ioflag; | |
62 | { | |
63 | long offset; | |
64 | long size; | |
65 | int c; | |
66 | unsigned char cc; | |
67 | long read = 0; | |
68 | int error = 0; | |
69 | ||
70 | offset = uio->uio_offset; | |
91447636 | 71 | size = uio_resid(uio); |
1c79356b A |
72 | |
73 | for (read = 0; read < size; read++, offset++) { | |
74 | error = PEnvread(offset, 1, &cc); | |
75 | if ( error ) { | |
76 | return error; | |
77 | } | |
78 | c = (int)cc; | |
79 | error = ureadc(c, uio); | |
80 | if (error) { | |
81 | return error; | |
82 | } | |
83 | } | |
84 | return error; | |
85 | } | |
86 | ||
87 | ||
88 | ||
89 | nvwrite(dev_t dev, struct uio *uio, int ioflag) | |
90 | { | |
1c79356b A |
91 | long offset; |
92 | long size; | |
93 | int c; | |
94 | unsigned char cc; | |
95 | long wrote = 0; | |
96 | int error = 0; | |
97 | ||
98 | offset = uio->uio_offset; | |
91447636 | 99 | size = uio_resid(uio); |
1c79356b A |
100 | |
101 | for (wrote = 0; wrote < size; wrote++, offset++) { | |
102 | c = uwritec(uio); | |
103 | if (c < 0) { | |
104 | return 0; | |
105 | } | |
106 | cc = (unsigned char)c; | |
107 | error = PEnvwrite(offset, 1, &cc); | |
108 | } | |
109 | return error; | |
110 | } |