-
Notifications
You must be signed in to change notification settings - Fork 0
/
fs_media.c
executable file
·274 lines (244 loc) · 6.87 KB
/
fs_media.c
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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
/*
64NET Media testing routines.
(C)Copyright Paul Gardner-Stephen 1995, All rights reserved.
This code is indended soley for use in the 64net/2 system.
*/
#include "config.h"
#include "fs.h"
#include "fs_func.h"
int
fs64_mediatype (uchar *path)
{
/* find out the media type for the path
media_BAD will be returned if the path is bad
and media_NOTFS if the path points to a file which is not a file system
If the end of the path is a subdirectory then it will be media_UFS
If the end of the path is a .D64 it will be media_D64
If the end of the path is a .T64 it will be media_T64
*/
/* BUGS: This routine should parse through each slash seperately, as at
present a subdirectory in a disk image, or a subdirectory itself for
that matter, ending in .D64 or .T64 will mistakenly be recognuised as a
disk/tape image */
#ifdef AMIGA
BPTR filelock;
struct FileInfoBlock myFIB;
#else
struct stat buf;
#endif
int n;
uchar temp[1024];
/* get file info */
/* BUGS: The following is *very* kludgy! */
if (path[0] == '@')
{
/* @ sounds like a good way to start the internet file system :) */
return (media_NET);
}
#ifdef AMIGA
if ((filelock = Lock (path, ACCESS_READ)) != 0)
{
if (!Examine (filelock, &myFIB))
{
UnLock (filelock);
/* try stripping the / off the end */
if (path[strlen (path) - 1] == '/')
{
strcpy (temp, path);
temp[strlen (path) - 1] = 0;
return (fs64_mediatype (temp));
}
else
/* no go */
return (media_BAD); /* file/path not found */
}
}
#else
if (stat ((char*)path, &buf))
{
/* try stripping the / off the end */
if (path[strlen (path) - 1] == '/')
{
strcpy ((char*)temp, (char*)path);
temp[strlen (path) - 1] = 0;
return (fs64_mediatype (temp));
}
else
/* no go */
return (media_BAD); /* file/path not found */
}
#endif
/* Check for file types now */
/* Check for media_UFS */
#ifdef AMIGA
if (myFIB.fib_DirEntryType > 0)
{
UnLock (filelock);
return (media_UFS); /* dir = unix filesystem */
}
#else
if (buf.st_mode & S_IFDIR)
return (media_UFS); /* dir = unix filesystem */
#endif
n = strlen (path);
if ((path[n - 4] == '.') && (toupper (path[n - 3]) == 'D') && (path[n - 2] == '7') && (path[n - 1] == '1'))
return (media_D71);
if ((path[n - 4] == '.') && (toupper (path[n - 3]) == 'D') && (path[n - 2] == '8') && (path[n - 1] == '1'))
return (media_D81);
if ((path[n - 4] == '.') && (toupper (path[n - 3]) == 'D') && (toupper (path[n - 2]) == 'H') && (toupper (path[n - 1]) == 'D'))
return (media_DHD);
if ((path[n - 4] == '.') && (path[n - 2] == '6') && (path[n - 1] == '4'))
{
/* the end of the filename is '.?64' */
/* this routine doesnt seem to check for .N64s, and yet
N64's can still be accessed .. hmmm */
/* Check for .D64 */
if ((path[n - 3] == 'd') || (path[n - 3] == 'D'))
{
/* its a D64 file! */
return (media_D64);
}
if ((path[n - 3] == 't') || (path[n - 3] == 'T'))
{
/* Its a T64 file! */
return (media_T64);
}
/* it matches no known archive type - so its a media_NOTFS */
return (media_NOTFS);
}
if ((path[n - 4] == '.') && (toupper (path[n - 3]) == 'L') &&
(toupper (path[n - 2]) == 'N') && (toupper (path[n - 1]) == 'X'))
{
/* .LNX file */
return (media_LNX);
}
/* no match */
/* default = unix's native FS */
return (media_UFS);
}
int
fs64_readts (fs64_filesystem * fs, int track, int sector, uchar *sb)
{
return (readts (fs, track, sector, sb));
}
int
fs64_writets (fs64_filesystem * fs, int track, int sector, uchar *sb)
{
return (writets (fs, track, sector, sb));
}
int
fs64_deallocateblock (fs64_filesystem * fs, int track, int sector)
{
/* mark block allocated, return(0) if ok, or return(-1) if the
block was previously allocated */
switch (fs->media)
{
case media_UFS:
return (fs_ufs_deallocateblock (fs, track, sector));
case media_D64:
return (fs_d64_deallocateblock (fs, track, sector));
case media_D71:
return (fs_d71_deallocateblock (fs, track, sector));
case media_D81:
return (fs_d81_deallocateblock (fs, track, sector));
case media_DHD:
return (fs_dhd_deallocateblock (fs, track, sector));
default:
/* unknown media */
/* 74,DRIVE NOT READY,00,00 */
set_error (74, 0, 0);
return (-2);
} /* end switch media */
} /* end fs64_deallocateblock() */
int
fs64_allocateblock (fs64_filesystem * fs, int track, int sector)
{
/* mark block allocated, return(0) if ok, or return(-1) if the
block was previously allocated */
switch (fs->media)
{
case media_UFS:
return (fs_ufs_allocateblock (fs, track, sector));
break;
case media_D64:
return (fs_d64_allocateblock (fs, track, sector));
break;
case media_D71:
return (fs_d71_allocateblock (fs, track, sector));
break;
case media_D81:
return (fs_d81_allocateblock (fs, track, sector));
break;
case media_DHD:
return (fs_dhd_allocateblock (fs, track, sector));
break;
default:
/* unknown media */
/* 74,DRIVE NOT READY,00,00 */
set_error (74, 0, 0);
return (-2);
} /* end switch media */
} /* end fs64_allocateblock() */
int
fs64_findfreeblock (fs64_filesystem * fs, int *track, int *sector)
{
/* locate the first empty sector on the disk */
switch (fs->media)
{
case media_UFS:
return (fs_ufs_findfreeblock (fs, track, sector));
break;
case media_D64:
return (fs_d64_findfreeblock (fs, track, sector));
break;
case media_D71:
return (fs_d71_findfreeblock (fs, track, sector));
break;
case media_D81:
return (fs_d81_findfreeblock (fs, track, sector));
break;
case media_DHD:
return (fs_dhd_findfreeblock (fs, track, sector));
break;
default:
/* if in doubt - its full! ;) */
/* give no error, as its only a query */
*track = -1;
*sector = -1;
return (-1);
} /* end switch media */
} /* end fs64_findfreeblock */
int
fs64_blocksfree (fs64_filesystem * fs)
{
/* tell us how many free blocks in a file system object
Called by fs64_writeblock to determine if there is any free space,
and by directory searches to provide the BLOCKS FREE line */
// debug_msg ("fs64_blocksfree(M=%d)\n", fs->media);
switch (fs->media)
{
case media_UFS:
return (fs_ufs_blocksfree (fs));
break;
case media_D64:
return (fs_d64_blocksfree (fs));
break;
case media_D71:
return (fs_d71_blocksfree (fs));
break;
case media_D81:
return (fs_d81_blocksfree (fs));
break;
case media_DHD:
return (fs_dhd_blocksfree (fs));
break;
case media_NET:
return (fs_net_blocksfree (fs));
break;
default:
/* if in doubt - its full! ;) */
/* 74,DRIVE NOT READY,00,00 */
set_error (74, 0, 0);
return (0);
} /* end switch media */
} /* end fs64_blocksfree */