]>
Commit | Line | Data |
---|---|---|
1c79356b A |
1 | /* |
2 | * Copyright (c) 2000 Apple Computer, Inc. All rights reserved. | |
3 | * | |
4 | * @APPLE_LICENSE_HEADER_START@ | |
5 | * | |
e5568f75 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 | * |
e5568f75 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, | |
e5568f75 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; | |
71 | size = uio->uio_resid; | |
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 | { | |
91 | register struct iovec *iov; | |
92 | long offset; | |
93 | long size; | |
94 | int c; | |
95 | unsigned char cc; | |
96 | long wrote = 0; | |
97 | int error = 0; | |
98 | ||
99 | offset = uio->uio_offset; | |
100 | size = uio->uio_resid; | |
101 | ||
102 | for (wrote = 0; wrote < size; wrote++, offset++) { | |
103 | c = uwritec(uio); | |
104 | if (c < 0) { | |
105 | return 0; | |
106 | } | |
107 | cc = (unsigned char)c; | |
108 | error = PEnvwrite(offset, 1, &cc); | |
109 | } | |
110 | return error; | |
111 | } |