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