1/*
2 * media.h -
3 *
4 * Written by Eryk Vershen
5 */
6
7/*
8 * Copyright 1997,1998 by Apple Computer, Inc.
9 *              All Rights Reserved
10 *
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.
16 *
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.
20 *
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.
26 */
27
28#ifndef __media__
29#define __media__
30
31
32/*
33 * Media is an abstraction of a disk device.
34 *
35 * A media object has the following visible attributes:
36 *
37 *      a granularity       (e.g. 512, 1024, 1, etc.)
38 *      a total size in bytes
39 *
40 *  And the following operations are available:
41 *
42 *      open
43 *      read @ byte offset for size in bytes
44 *      write @ byte offset for size in bytes
45 *      close
46 *
47 * XXX Should really split public media interface from "protected" interface.
48 */
49
50
51/*
52 * Defines
53 */
54
55
56/*
57 * Types
58 */
59/* those whose use media objects need just the pointer type */
60typedef struct media *MEDIA;
61
62/* those who define media objects need the struct and internal routine types */
63typedef long (*media_read)(MEDIA m, long long offset, unsigned long count, void *address);
64typedef long (*media_write)(MEDIA m, long long offset, unsigned long count, void *address);
65typedef long (*media_close)(MEDIA m);
66typedef long (*media_os_reload)(MEDIA m);
67
68struct media {
69    long            kind;           /* kind of media - SCSI, IDE, etc. */
70    unsigned long   grain;          /* granularity (offset & size) */
71    long long       size_in_bytes;  /* offset granularity */
72    media_read      do_read;        /* device specific routines */
73    media_write     do_write;
74    media_close     do_close;
75    media_os_reload do_os_reload;
76				    /* specific media kinds will add extra info */
77};
78
79/* those whose use media object iterators need just the pointer type */
80typedef struct media_iterator *MEDIA_ITERATOR;
81
82/* those who define media object iterators need the struct and internal routine types */
83typedef void (*media_iterator_reset)(MEDIA_ITERATOR m);
84typedef char* (*media_iterator_step)(MEDIA_ITERATOR m);
85typedef void (*media_iterator_delete)(MEDIA_ITERATOR m);
86
87typedef enum {
88    kInit,
89    kReset,
90    kIterating,
91    kEnd
92} media_iterator_state;
93
94struct media_iterator {
95    long                    kind;           /* kind of media - SCSI, IDE, etc. */
96    media_iterator_state    state;          /* init, reset, iterating, at_end */
97    media_iterator_reset    do_reset;       /* device specific routines */
98    media_iterator_step     do_step;
99    media_iterator_delete   do_delete;
100					    /* specific media kinds will add extra info */
101};
102
103
104/*
105 * Global Constants
106 */
107
108
109/*
110 * Global Variables
111 */
112
113
114/*
115 * Forward declarations
116 */
117/* those whose use media objects need these routines */
118unsigned long media_granularity(MEDIA m);
119long long media_total_size(MEDIA m);
120long read_media(MEDIA m, long long offset, unsigned long count, void *address);
121long write_media(MEDIA m, long long offset, unsigned long count, void *address);
122void close_media(MEDIA m);
123void os_reload_media(MEDIA m);
124
125/* those who define media objects need these routines also */
126long allocate_media_kind(void);
127MEDIA new_media(long size);
128void delete_media(MEDIA m);
129
130/* those whose use media object iterators need these routines */
131void reset_media_iterator(MEDIA_ITERATOR m);
132char *step_media_iterator(MEDIA_ITERATOR m);
133void delete_media_iterator(MEDIA_ITERATOR m);
134
135/* those who define media object iterators need these routines also */
136MEDIA_ITERATOR new_media_iterator(long size);
137void private_delete_media_iterator(MEDIA_ITERATOR m);
138
139#endif /* __media__ */
140