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