media.h revision 1.2.10.2 1 1.2.10.2 yamt /*
2 1.2.10.2 yamt * media.h -
3 1.2.10.2 yamt *
4 1.2.10.2 yamt * Written by Eryk Vershen
5 1.2.10.2 yamt */
6 1.2.10.2 yamt
7 1.2.10.2 yamt /*
8 1.2.10.2 yamt * Copyright 1997,1998 by Apple Computer, Inc.
9 1.2.10.2 yamt * All Rights Reserved
10 1.2.10.2 yamt *
11 1.2.10.2 yamt * Permission to use, copy, modify, and distribute this software and
12 1.2.10.2 yamt * its documentation for any purpose and without fee is hereby granted,
13 1.2.10.2 yamt * provided that the above copyright notice appears in all copies and
14 1.2.10.2 yamt * that both the copyright notice and this permission notice appear in
15 1.2.10.2 yamt * supporting documentation.
16 1.2.10.2 yamt *
17 1.2.10.2 yamt * APPLE COMPUTER DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE
18 1.2.10.2 yamt * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
19 1.2.10.2 yamt * FOR A PARTICULAR PURPOSE.
20 1.2.10.2 yamt *
21 1.2.10.2 yamt * IN NO EVENT SHALL APPLE COMPUTER BE LIABLE FOR ANY SPECIAL, INDIRECT, OR
22 1.2.10.2 yamt * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
23 1.2.10.2 yamt * LOSS OF USE, DATA OR PROFITS, WHETHER IN ACTION OF CONTRACT,
24 1.2.10.2 yamt * NEGLIGENCE, OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
25 1.2.10.2 yamt * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
26 1.2.10.2 yamt */
27 1.2.10.2 yamt
28 1.2.10.2 yamt #ifndef __media__
29 1.2.10.2 yamt #define __media__
30 1.2.10.2 yamt
31 1.2.10.2 yamt
32 1.2.10.2 yamt /*
33 1.2.10.2 yamt * Media is an abstraction of a disk device.
34 1.2.10.2 yamt *
35 1.2.10.2 yamt * A media object has the following visible attributes:
36 1.2.10.2 yamt *
37 1.2.10.2 yamt * a granularity (e.g. 512, 1024, 1, etc.)
38 1.2.10.2 yamt * a total size in bytes
39 1.2.10.2 yamt *
40 1.2.10.2 yamt * And the following operations are available:
41 1.2.10.2 yamt *
42 1.2.10.2 yamt * open
43 1.2.10.2 yamt * read @ byte offset for size in bytes
44 1.2.10.2 yamt * write @ byte offset for size in bytes
45 1.2.10.2 yamt * close
46 1.2.10.2 yamt *
47 1.2.10.2 yamt * XXX Should really split public media interface from "protected" interface.
48 1.2.10.2 yamt */
49 1.2.10.2 yamt
50 1.2.10.2 yamt
51 1.2.10.2 yamt /*
52 1.2.10.2 yamt * Defines
53 1.2.10.2 yamt */
54 1.2.10.2 yamt
55 1.2.10.2 yamt
56 1.2.10.2 yamt /*
57 1.2.10.2 yamt * Types
58 1.2.10.2 yamt */
59 1.2.10.2 yamt /* those whose use media objects need just the pointer type */
60 1.2.10.2 yamt typedef struct media *MEDIA;
61 1.2.10.2 yamt
62 1.2.10.2 yamt /* those who define media objects need the struct and internal routine types */
63 1.2.10.2 yamt typedef long (*media_read)(MEDIA m, long long offset, uint32_t count, void *address);
64 1.2.10.2 yamt typedef long (*media_write)(MEDIA m, long long offset, uint32_t count, void *address);
65 1.2.10.2 yamt typedef long (*media_close)(MEDIA m);
66 1.2.10.2 yamt typedef long (*media_os_reload)(MEDIA m);
67 1.2.10.2 yamt
68 1.2.10.2 yamt struct media {
69 1.2.10.2 yamt long kind; /* kind of media - SCSI, IDE, etc. */
70 1.2.10.2 yamt uint32_t grain; /* granularity (offset & size) */
71 1.2.10.2 yamt long long size_in_bytes; /* offset granularity */
72 1.2.10.2 yamt media_read do_read; /* device specific routines */
73 1.2.10.2 yamt media_write do_write;
74 1.2.10.2 yamt media_close do_close;
75 1.2.10.2 yamt media_os_reload do_os_reload;
76 1.2.10.2 yamt /* specific media kinds will add extra info */
77 1.2.10.2 yamt };
78 1.2.10.2 yamt
79 1.2.10.2 yamt /* those whose use media object iterators need just the pointer type */
80 1.2.10.2 yamt typedef struct media_iterator *MEDIA_ITERATOR;
81 1.2.10.2 yamt
82 1.2.10.2 yamt /* those who define media object iterators need the struct and internal routine types */
83 1.2.10.2 yamt typedef void (*media_iterator_reset)(MEDIA_ITERATOR m);
84 1.2.10.2 yamt typedef char* (*media_iterator_step)(MEDIA_ITERATOR m);
85 1.2.10.2 yamt typedef void (*media_iterator_delete)(MEDIA_ITERATOR m);
86 1.2.10.2 yamt
87 1.2.10.2 yamt typedef enum {
88 1.2.10.2 yamt kInit,
89 1.2.10.2 yamt kReset,
90 1.2.10.2 yamt kIterating,
91 1.2.10.2 yamt kEnd
92 1.2.10.2 yamt } media_iterator_state;
93 1.2.10.2 yamt
94 1.2.10.2 yamt struct media_iterator {
95 1.2.10.2 yamt long kind; /* kind of media - SCSI, IDE, etc. */
96 1.2.10.2 yamt media_iterator_state state; /* init, reset, iterating, at_end */
97 1.2.10.2 yamt media_iterator_reset do_reset; /* device specific routines */
98 1.2.10.2 yamt media_iterator_step do_step;
99 1.2.10.2 yamt media_iterator_delete do_delete;
100 1.2.10.2 yamt /* specific media kinds will add extra info */
101 1.2.10.2 yamt };
102 1.2.10.2 yamt
103 1.2.10.2 yamt
104 1.2.10.2 yamt /*
105 1.2.10.2 yamt * Global Constants
106 1.2.10.2 yamt */
107 1.2.10.2 yamt
108 1.2.10.2 yamt
109 1.2.10.2 yamt /*
110 1.2.10.2 yamt * Global Variables
111 1.2.10.2 yamt */
112 1.2.10.2 yamt
113 1.2.10.2 yamt
114 1.2.10.2 yamt /*
115 1.2.10.2 yamt * Forward declarations
116 1.2.10.2 yamt */
117 1.2.10.2 yamt /* those whose use media objects need these routines */
118 1.2.10.2 yamt uint32_t media_granularity(MEDIA m);
119 1.2.10.2 yamt long long media_total_size(MEDIA m);
120 1.2.10.2 yamt long read_media(MEDIA m, long long offset, uint32_t count, void *address);
121 1.2.10.2 yamt long write_media(MEDIA m, long long offset, uint32_t count, void *address);
122 1.2.10.2 yamt void close_media(MEDIA m);
123 1.2.10.2 yamt void os_reload_media(MEDIA m);
124 1.2.10.2 yamt
125 1.2.10.2 yamt /* those who define media objects need these routines also */
126 1.2.10.2 yamt long allocate_media_kind(void);
127 1.2.10.2 yamt MEDIA new_media(long size);
128 1.2.10.2 yamt void delete_media(MEDIA m);
129 1.2.10.2 yamt
130 1.2.10.2 yamt /* those whose use media object iterators need these routines */
131 1.2.10.2 yamt void reset_media_iterator(MEDIA_ITERATOR m);
132 1.2.10.2 yamt char *step_media_iterator(MEDIA_ITERATOR m);
133 1.2.10.2 yamt void delete_media_iterator(MEDIA_ITERATOR m);
134 1.2.10.2 yamt
135 1.2.10.2 yamt /* those who define media object iterators need these routines also */
136 1.2.10.2 yamt MEDIA_ITERATOR new_media_iterator(long size);
137 1.2.10.2 yamt void private_delete_media_iterator(MEDIA_ITERATOR m);
138 1.2.10.2 yamt
139 1.2.10.2 yamt #endif /* __media__ */
140