File: api_device.html

package info (click to toggle)
unadf 0.7.11a-7
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,660 kB
  • sloc: ansic: 5,455; cpp: 404; makefile: 127; sh: 78
file content (334 lines) | stat: -rw-r--r-- 7,472 bytes parent folder | download | duplicates (7)
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
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
<HTML>
<HEAD>
<TITLE>Device</TITLE>
</HEAD>


<BODY>

<H1 ALIGN=CENTER>the Device API</H1>

<HR>
<H1>Use cases</H1>

<UL>

<P>
<LI>Mounting volume of a existing device (ADF dump or real one) :
 <OL>
 <LI>adfMountDev()
 <LI>adfMount()
 <LI>adfUnMount()
 <LI>adfUnMountDev()
 </OL>

<P>
<LI>Creating an ADF dump of a floppy :
 <OL>
 <LI>adfCreateDumpDevice()
 <LI>adfCreateFlop()
 <LI>adfMount()
 <LI>adfUnMount()
 <LI>adfUnMountDev()
 </OL>

<P>
<LI>Creating an ADF dump of a harddisk :
 <OL>
 <LI>adfCreateDumpDevice()
 <LI>adfCreateHd()
 <LI>adfMount()
 <LI>adfUnMount()
 <LI>adfUnMountDev()
 </OL>

<P>
<LI>Creating an new filesystem for an harddisk on a real device :
 <OL>
 <LI>adfMountDev()
 <LI>adfCreateHd()
 <LI>adfMount()
 <LI>adfUnMount()
 <LI>adfUnMountDev()
 </OL>

</UL>

<HR>

<H1>Data structures</H1>

<P>
<B>
Warning ! None of the fields of the structure below must be modified directly. In this case,
i can not tell how will behave the library. Unless specified, read access
is of course allowed.
</B>
<P>
The dynamic memory allocation/releasing is done by the library (i hope :). 
<P>

<PRE>
struct Device {
    int devType;                      /* DEVTYPE_FLOPDD, DEVTYPE_FLOPHD or DEVTYPE_HARDDISK */
    long size;                        /* size in bytes of the media. ADFlib is limited to 4Gb */
    
    int nVol;                         /* number of partitions (volumes) */
    struct Volume* *volList;          /* volumes */

    long cylinders, heads, sectors;   /* device geometry */
    
    BOOL isNativeDev;

    void *nativeDev;                  /* native specific and private structure */
}
</PRE>

<P>
The Partition structure is used with adfCreateHd().


<PRE>
struct Partition{
    long startCyl;      /* starting cylinder of the usable space : should be 2 */
    long lenCyl;        /* length of this area, in cylinders */

    char* volName;      /* name of the volume, if any. Instead filled with 0.  */

    int volType;        /* filesystem caracteristics : use the flags FSMASK_FFS, 
                            FSMASK_INTL and FSMASK_DIRCACHE                     */

} 
</PRE>


<HR>


<P ALIGN=CENTER><FONT SIZE=+2> adfMountDev() </FONT></P>

<H2>Syntax</H2>

 <B>struct Device*</B> adfMountDev( <B>char*</B> name)

<H2>Description</H2>

Mounts a device. The name could be a filename for an ADF dump, or a
real device name like "|F:" for the Win32 F: partition. <BR>
The real device name is plateform dependent.

<H2>Return values</H2>

 NULL if an error occurs, a Device structure pointer instead.

<H2>Internals</H2>
<OL>
<LI>Allocation of <I>struct Device *dev</I>
<LI>Calls <I>adfIsNativeDev()</I> to determine if the name point out
a ADF dump or a real (native) device. The field <I>dev->isNativeDev</I> is filled.
<LI>Initialize the (real or dump) device. The field <I>dev->size</I> is filled. 
<LI><I>dev->devType</I> is filled.
<LI>The device is mounted : <I>dev->nVol, dev->volList[], dev->cylinders,
dev->heads, dev->sectors</I> are filled.
<LI><I>dev</I> is returned
</OL>
Warning, in each <I>dev->volList[i]</I> volumes (vol), 
only <I>vol->volName</I> (might be NULL), <I>vol->firstBlock, vol->lastBlock</I>
and <I>vol->rootBlock</I> are filled !

<H2>See also</H2>

 struct Device, real (native) devices

<H2>Files</H2>

Real devices allocation : adf_nativ.c, adf_nativ.h <BR>
ADF allocation : adf_dump.c, adf_dump.h
<P>

<HR>
<P ALIGN=CENTER><FONT SIZE=+2> adfUnMountDev() </FONT></P>


<H2>Syntax</H2>

<B>void</B> adfUnMountDev( <B>struct Device*</B> dev)

<H2>Description</H2>

Releases a Device and frees related resources.

<H2>Internals</H2>

<OL>
<LI>Frees <I>dev->volList[]</I>
<LI>Releases the ADF dump or real (native) device : call the suited function.
</OL>

<HR>
<P ALIGN=CENTER><FONT SIZE=+2> adfCreateHd() </FONT></P>

<H2>Syntax</H2>

<B>RETCODE</B> adfCreateHd(<B>struct Device*</B> dev, <B>int</B> nPart,
 <B>struct Partition*</B> *partList )

<H2>Description</H2>

Create the filesystem of a device which will be used as an Harddisk.
<I>AdfMount()</I> must be used after to mount
a volume (partition).
<P>
In case of a new ADF dump, <I>adfCreateDumpDevice()</I> must be called before to
create an empty media of the right size.
<P>
An Harddisk ADF dump created with ADFlib -can not be- used back by the AmigaDOS,
since some fields of the header structures are missing : they can not be
automatically determined.

<H2>Return values</H2>

RC_OK, or Something different in case of error.

<H2>Examples</H2>

Creation of an ADF Zip disk dump : <BR>

<PRE>
struct Partition part1;
struct Partition **partList;
struct Device *hd;
RETCODE rc;

/* Env init */

/* cyl = 2891, heads = 1, sectors = 68 */
hd = adfCreateDumpDevice("newdev",2891,1,68);
if (!hd) { /* cleanup and exit */ }

/* allocation of partlist[] */

/* the filesystem definition : size, FFS with DIRCACHE */
part1.startCyl = 2;
part1.lenCyl = 2889;
part1.volName = strdup("zip");
part1.volType = FSMASK_FFS|FSMASK_DIRCACHE;

partList[0] = &part1;

/* creates the filesystem */
rc = adfCreateHd(hd,1,partList);
if (rc!=RC_OK) { /* something wrong, cleaning up and exit */ }

/* freeing of partList[] and part1.volName */

/* device usage */

adfUnMountDev(hd);

/* Env cleanup */

</PRE>


<H2>Internals</H2>

<OL>
<LI>Creates and fill <I>dev->volList[]</I>
<LI>Creates the Harddisk header structures on the media. It uses usually the
2 first cylinders of the device.
</OL>



<HR>
<P ALIGN=CENTER><FONT SIZE=+2> adfCreateFlop() </FONT></P>

<H2>Syntax</H2>

<B>RETCODE</B> adfCreateFlop(<B>struct Device*</B> dev, 
 <B>char*</B> volName, <B>int</B> volType )

<H2>Description</H2>

Creates the filesystem of a DD or HD floppy. 
<I>AdfMount()</I> must be used after to mount the only volume.
<P>
In case of a new ADF dump, <I>adfCreateDumpDevice()</I> must be called before to
create an empty media of the right size.
<P>
An Harddisk ADF dump created with ADFlib -can be- used back by the AmigaDOS.


<H2>Return values</H2>

RC_OK, or Something different in case of error.


<H2>Examples</H2>

<PRE>
struct Device *flop;

/* Env init */

/* creates a DD floppy empty dump */
/* cyl = 80, heads = 2, sectors = 11. HD floppies has 22 sectors */
flop = adfCreateDumpDevice("newdev", 80, 2, 11);
if (!flop) { /* cleanup and exit */ }

/* create the filesystem : OFS with DIRCACHE */
rc = adfCreateFlop( flop, "empty", FSMASK_DIRCACHE );
if (rc!=RC_OK) { /* error : cleanup and exit() */

/* device usage */

adfUnMountDev(flop);

/* Env cleanup */

</PRE>

<H2>Internals</H2>

<OL>
<LI>Allocation of dev->volList[]. It contains one volume.
<LI>Creation of the volume
</OL>

<HR>

<P ALIGN=CENTER><FONT SIZE=+2> ADF only : adfCreateDumpDevice() </FONT></P>

<H2>Syntax</H2>

<B>struct Device*</B> adfCreateDumpDevice(<B>char*</B> filename,
<B>long</B> cyl, <B>long</B> heads, <B>long</B> sect)

<H2>Description</H2>

Create a file of the right size, and fills some fields of the Device
structure. Must be followed by adfCreateFlop() and adfCreateHd().

<H2>Return values</H2>

the Device, NULL in case of error.

<H2>Examples</H2>
See adfCreateFlop() and adfCreateHd() examples.

<H2>Internals</H2>

<OL>
<LI>Allocate <I>struct Device* dev</I>
<LI>Allocate <I>dev->nativeDev</I>
<LI>Create an empty file with a size equals to : cyl*heads*sect*512.
<LI>Open this file with "rb+" mode
<LI>Fills <I>dev->cylinders, dev->heads, dev->sectors, dev->size,
 dev->devType</I>, and <I>dev->nVol</I> = 0.
<LI>Returns <I>dev</I>
</OL>

</BODY>

</HTML>