summaryrefslogtreecommitdiff
path: root/sbin/pdisk/media.h
blob: f631e157a525705ec338033be1440a83290ee5fc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
/*
 * media.h -
 *
 * Written by Eryk Vershen (eryk@apple.com)
 */

/*
 * Copyright 1997,1998 by Apple Computer, Inc.
 *              All Rights Reserved 
 *  
 * Permission to use, copy, modify, and distribute this software and 
 * its documentation for any purpose and without fee is hereby granted, 
 * provided that the above copyright notice appears in all copies and 
 * that both the copyright notice and this permission notice appear in 
 * supporting documentation. 
 *  
 * APPLE COMPUTER DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE 
 * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 
 * FOR A PARTICULAR PURPOSE. 
 *  
 * IN NO EVENT SHALL APPLE COMPUTER BE LIABLE FOR ANY SPECIAL, INDIRECT, OR 
 * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM 
 * LOSS OF USE, DATA OR PROFITS, WHETHER IN ACTION OF CONTRACT, 
 * NEGLIGENCE, OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION 
 * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 
 */

#ifndef __media__
#define __media__


/*
 * Media is an abstraction of a disk device.
 *
 * A media object has the following visible attributes:
 *
 *      a granularity       (e.g. 512, 1024, 1, etc.)
 *      a total size in bytes 
 *
 *  And the following operations are available:
 *
 *      open
 *      read @ byte offset for size in bytes
 *      write @ byte offset for size in bytes
 *      close
 *
 * XXX Should really split public media interface from "protected" interface.
 */


/*
 * Defines
 */


/*
 * Types
 */
/* those whose use media objects need just the pointer type */
typedef struct media *MEDIA;

/* those who define media objects need the struct and internal routine types */
typedef long (*media_read)(MEDIA m, long long offset, unsigned long count, void *address);
typedef long (*media_write)(MEDIA m, long long offset, unsigned long count, void *address);
typedef long (*media_close)(MEDIA m);
typedef long (*media_os_reload)(MEDIA m);

struct media {
    long            kind;           /* kind of media - SCSI, IDE, etc. */
    unsigned long   grain;          /* granularity (offset & size) */
    long long       size_in_bytes;  /* offset granularity */
    media_read      do_read;        /* device specific routines */
    media_write     do_write;
    media_close     do_close;
    media_os_reload do_os_reload;
				    /* specific media kinds will add extra info */
};

/* those whose use media object iterators need just the pointer type */
typedef struct media_iterator *MEDIA_ITERATOR;

/* those who define media object iterators need the struct and internal routine types */
typedef void (*media_iterator_reset)(MEDIA_ITERATOR m);
typedef char* (*media_iterator_step)(MEDIA_ITERATOR m);
typedef void (*media_iterator_delete)(MEDIA_ITERATOR m);

typedef enum {
    kInit,
    kReset,
    kIterating,
    kEnd
} media_iterator_state;

struct media_iterator {
    long                    kind;           /* kind of media - SCSI, IDE, etc. */
    media_iterator_state    state;          /* init, reset, iterating, at_end */
    media_iterator_reset    do_reset;       /* device specific routines */
    media_iterator_step     do_step;
    media_iterator_delete   do_delete;
					    /* specific media kinds will add extra info */
};


/*
 * Global Constants
 */


/*
 * Global Variables
 */


/*
 * Forward declarations
 */
/* those whose use media objects need these routines */
unsigned long media_granularity(MEDIA m);
long long media_total_size(MEDIA m);
long read_media(MEDIA m, long long offset, unsigned long count, void *address);
long write_media(MEDIA m, long long offset, unsigned long count, void *address);
void close_media(MEDIA m);
void os_reload_media(MEDIA m);

/* those who define media objects need these routines also */
long allocate_media_kind(void);
MEDIA new_media(long size);
void delete_media(MEDIA m);

/* those whose use media object iterators need these routines */
void reset_media_iterator(MEDIA_ITERATOR m);
char *step_media_iterator(MEDIA_ITERATOR m);
void delete_media_iterator(MEDIA_ITERATOR m);

/* those who define media object iterators need these routines also */
MEDIA_ITERATOR new_media_iterator(long size);
void private_delete_media_iterator(MEDIA_ITERATOR m);

#endif /* __media__ */