4 * Written by Eryk Vershen
8 * Copyright 1997,1998 by Apple Computer, Inc.
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.
33 #include "file_media.h"
35 #if !defined(__linux__) && !defined(__unix__)
36 #include "SCSI_media.h"
37 #include "ATA_media.h"
62 * Forward declarations
71 * Note that open_pathname_as_media() and get_linux_name() have almost
72 * identical structures. If one changes the other must also!
75 open_pathname_as_media(char *path
, int oflag
)
78 #if !defined(__linux__) && !defined(__unix__)
82 if (strncmp("/dev/", path
, 5) == 0) {
83 if (strncmp("/dev/scsi", path
, 9) == 0) {
84 if (path
[9] >= '0' && path
[9] <= '7' && path
[10] == 0) {
87 m
= open_old_scsi_as_media(id
);
88 } else if (path
[9] >= '0' && path
[9] <= '7' && path
[10] == '.'
89 && path
[11] >= '0' && path
[11] <= '7' && path
[12] == 0) {
93 m
= open_scsi_as_media(bus
, id
);
95 } else if (strncmp("/dev/ata", path
, 8) == 0
96 || strncmp("/dev/ide", path
, 8) == 0) {
97 if (path
[8] >= '0' && path
[8] <= '7' && path
[9] == 0) {
100 m
= open_ata_as_media(bus
, 0);
101 } else if (path
[8] >= '0' && path
[8] <= '7' && path
[9] == '.'
102 && path
[10] >= '0' && path
[10] <= '1' && path
[11] == 0) {
103 // ata[0-7].[0-1], ide[0-7].[0-1]
106 m
= open_ata_as_media(bus
, id
);
108 } else if (strncmp("/dev/sd", path
, 7) == 0) {
109 if (path
[7] >= 'a' && path
[7] <= 'z' && path
[8] == 0) {
112 m
= open_linux_scsi_as_media(id
, 0);
113 } else if (path
[7] >= 'a' && path
[7] <= 'z' && path
[8] == '.'
114 && path
[9] >= 'a' && path
[9] <= 'z' && path
[10] == 0) {
119 m
= open_linux_scsi_as_media(id
, 0);
121 } else if (strncmp("/dev/scd", path
, 8) == 0) {
122 if (path
[8] >= '0' && path
[8] <= '9' && path
[9] == 0) {
125 m
= open_linux_scsi_as_media(id
, 1);
127 } else if (strncmp("/dev/hd", path
, 7) == 0) {
128 if (path
[7] >= 'a' && path
[7] <= 'z' && path
[8] == 0) {
131 m
= open_linux_ata_as_media(id
);
138 m
= open_file_as_media(path
, oflag
);
145 get_linux_name(char *path
)
148 #if !defined(__linux__) && !defined(__unix__)
152 if (strncmp("/dev/", path
, 5) == 0) {
153 if (strncmp("/dev/scsi", path
, 9) == 0) {
154 if (path
[9] >= '0' && path
[9] <= '7' && path
[10] == 0) {
158 result
= linux_old_scsi_name(id
);
159 } else if (path
[9] >= '0' && path
[9] <= '7' && path
[10] == '.'
160 && path
[11] >= '0' && path
[11] <= '7' && path
[12] == 0) {
165 result
= linux_scsi_name(bus
, id
);
167 } else if (strncmp("/dev/ata", path
, 8) == 0
168 || strncmp("/dev/ide", path
, 8) == 0) {
169 if (path
[8] >= '0' && path
[8] <= '7' && path
[9] == 0) {
170 /* ata/ide - master device */
171 // ata[0-7], ide[0-7]
173 result
= linux_ata_name(bus
, 0);
174 } else if (path
[8] >= '0' && path
[8] <= '7' && path
[9] == '.'
175 && path
[10] >= '0' && path
[10] <= '1' && path
[11] == 0) {
177 // ata[0-7].[0-1], ide[0-7].[0-1]
180 result
= linux_ata_name(bus
, id
);
191 first_media_kind(long *state
)
194 return next_media_kind(state
);
199 next_media_kind(long *state
)
201 MEDIA_ITERATOR result
;
209 #if defined(__linux__) || defined(__unix__)
210 result
= create_file_iterator();
216 /* fall through to next interface */
219 #if !defined(__linux__) && !defined(__unix__)
220 result
= create_ata_iterator();
226 /* fall through to next interface */
229 #if !defined(__linux__) && !defined(__unix__)
230 result
= create_scsi_iterator();
236 /* fall through to next interface */