Expand PMF_FN_* macros.
[netbsd-mini2440.git] / dist / pdisk / media.c
blob2fb3fc96448febbb2e2fc7f3391a062ffc184b6d
1 /*
2 * media.c -
4 * Written by Eryk Vershen
5 */
7 /*
8 * Copyright 1997,1998 by Apple Computer, Inc.
9 * All Rights Reserved
11 * Permission to use, copy, modify, and distribute this software and
12 * its documentation for any purpose and without fee is hereby granted,
13 * provided that the above copyright notice appears in all copies and
14 * that both the copyright notice and this permission notice appear in
15 * supporting documentation.
17 * APPLE COMPUTER DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE
18 * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
19 * FOR A PARTICULAR PURPOSE.
21 * IN NO EVENT SHALL APPLE COMPUTER BE LIABLE FOR ANY SPECIAL, INDIRECT, OR
22 * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
23 * LOSS OF USE, DATA OR PROFITS, WHETHER IN ACTION OF CONTRACT,
24 * NEGLIGENCE, OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
25 * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
29 // for printf()
30 #include <stdio.h>
31 // for malloc() & free()
32 #include <stdlib.h>
34 #include "media.h"
38 * Defines
43 * Types
48 * Global Constants
53 * Global Variables
55 static long media_kind = 0;
58 * Forward declarations
63 * Routines
65 long
66 allocate_media_kind(void)
68 media_kind++;
69 return media_kind;
73 MEDIA
74 new_media(long size)
76 return (MEDIA) malloc(size);
80 void
81 delete_media(MEDIA m)
83 if (m == 0) {
84 return;
86 free(m);
90 unsigned long
91 media_granularity(MEDIA m)
93 if (m == 0) {
94 return 0;
95 } else {
96 return m->grain;
101 long long
102 media_total_size(MEDIA m)
104 if (m == 0) {
105 return 0;
106 } else {
107 return m->size_in_bytes;
112 long
113 read_media(MEDIA m, long long offset, unsigned long count, void *address)
115 long result;
117 if (m != 0 && m->do_read != 0) {
118 //printf("media: read type %d, offset %Ld, count %d\n\t", m->kind, offset, count);
119 result = (*m->do_read)(m, offset, count, address);
120 //printf(" - returns %d\n", result);
121 return result;
122 } else {
123 return 0;
128 long
129 write_media(MEDIA m, long long offset, unsigned long count, void *address)
131 long result;
133 if (m != 0 && m->do_write != 0) {
134 //printf("media: write type %d, offset %Ld, count %d\n\t", m->kind, offset, count);
135 result = (*m->do_write)(m, offset, count, address);
136 //printf(" - returns %d\n", result);
137 return result;
138 } else {
139 return 0;
144 void
145 close_media(MEDIA m)
147 if (m == 0) {
148 return;
150 if (m->kind != 0) {
151 if (m->do_close != 0) {
152 (*m->do_close)(m);
154 m->kind = 0;
155 delete_media(m);
160 void
161 os_reload_media(MEDIA m)
163 if (m != 0 && m->do_os_reload != 0) {
164 (*m->do_os_reload)(m);
169 #if !defined(__linux__) && !defined(__unix__)
170 #pragma mark -
171 #endif
175 MEDIA_ITERATOR
176 new_media_iterator(long size)
178 return (MEDIA_ITERATOR) malloc(size);
182 void
183 private_delete_media_iterator(MEDIA_ITERATOR m)
185 if (m == 0) {
186 return;
188 free(m);
192 void
193 reset_media_iterator(MEDIA_ITERATOR m)
195 if (m != 0 && m->do_reset != 0) {
196 (*m->do_reset)(m);
201 char *
202 step_media_iterator(MEDIA_ITERATOR m)
204 char *result;
206 if (m != 0 && m->do_step != 0) {
207 result = (*m->do_step)(m);
208 } else {
209 result = 0;
211 return result;
215 void
216 delete_media_iterator(MEDIA_ITERATOR m)
218 if (m == 0) {
219 return;
221 if (m->kind != 0) {
222 if (m->do_delete != 0) {
223 (*m->do_delete)(m);
225 m->kind = 0;
226 private_delete_media_iterator(m);