2 Copyright © 1995-2007, The AROS Development Team. All rights reserved.
5 Desc: MakeDosNode() - Create a DOS DeviceNode structure.
9 #include "expansion_intern.h"
10 #include <exec/memory.h>
12 #include <dos/dosextens.h>
13 #include <proto/exec.h>
17 # include <aros/debug.h>
19 /*****************************************************************************
22 #include <dos/filehandler.h>
23 #include <proto/expansion.h>
25 AROS_LH1(struct DeviceNode
*, MakeDosNode
,
28 AROS_LHA(APTR
, parmPacket
, A0
),
31 struct ExpansionBase
*, ExpansionBase
, 24, Expansion
)
34 MakeDosNode() will create a DeviceNode structure suitable for
35 passing to dos.library which contains all the information about
36 a device stored in the parmPacket array. This will allow you to
37 enter a DOS device into the system from the information contained
38 in a DosEnvec structure (such as in a RigidDiskBlock PartitionBlock
41 MakeDosNode() will allocate the memory that it needs to construct
42 the DeviceNode, the strings and a FileSysStartupMsg that is passed
43 to the filesystem handler on startup.
45 You can use AddBootNode() to add a node to the system.
48 parmPacket - an IPTR array containing the device parameters
49 required to initialize the structures. This is a
50 variable length structure. See also the DosEnvec
51 structure in dos/filehandler.h
55 0 Exec string with dos device name (eg. DH0)
56 1 Exec string with exec device name (eg. fdsk.device)
57 2 unit number of device to open
58 3 flags (for OpenDevice())
59 4 length of the remaining data
60 5-n environment data - consists of:
62 5 Size of standard device block in 32 bit longwords
64 7 # of heads - drive specific
65 8 # of sectors per block - not used; 0
66 9 # of blocks per track - drive specific
67 10 # of reserved blocks at the start of the partition
68 11 # of reserved blocks at the end of the partition
70 13 starting cylinder of partition
71 14 end cylinder of partition
72 15 initial number of buffers
73 16 type of memory for buffers (CHIP, FAST,...)
74 17 max number of bytes to transfer at one time
75 18 address mask allowable for DMA transfers
76 19 boot priority for autobootable devices
77 20 standard DOS filesystem ID (eg 'DOS\1')
78 21 baud rate for serial handler
79 22 control word for handler/filesystem
80 23 number of boot blocks on this partition
83 deviceNode - An initialized DeviceNode structure, or NULL if
84 the required memory could not be allocated. The
85 caller will have to modify this structure before
86 passing it to AddBootNode().
89 There are a number of fields of the DeviceNode structure that this
90 function cannot initialize due to a lack of information. You
91 should fill these in yourself.
98 AddBootNode(), AddDosNode(), dos.library/MakeDosEntry()
102 *****************************************************************************/
106 struct DeviceNode
*dn
;
107 struct FileSysStartupMsg
*fssm
;
109 struct DosEnvec
*newde
;
113 int strLen1
, strLen2
, sz1
, sz2
;
114 int i
; /* Loop variable */
116 if (parmPacket
== NULL
)
121 /* This is the environment structure */
122 de
= (struct DosEnvec
*)((IPTR
*)parmPacket
+ 4);
123 desize
= sizeof(IPTR
) * (de
->de_TableSize
+ 1);
124 newde
= AllocMem(desize
, MEMF_CLEAR
| MEMF_PUBLIC
);
129 CopyMemQuick(de
, newde
, desize
);
131 dn
= AllocMem(sizeof(struct DeviceNode
), MEMF_CLEAR
| MEMF_PUBLIC
);
135 FreeMem(newde
, desize
);
139 fssm
= AllocMem(sizeof(struct FileSysStartupMsg
),
140 MEMF_CLEAR
| MEMF_PUBLIC
);
144 FreeMem(newde
, desize
);
145 FreeMem(dn
, sizeof(struct DeviceNode
));
150 /* To help prevent fragmentation I will allocate both strings in the
151 same block of memory.
154 strLen1
= strlen((STRPTR
)((IPTR
*)parmPacket
)[0]);
155 /* Round size to alloc to nearest mutiple of 4 */
156 sz1
= (AROS_BSTR_MEMSIZE4LEN(strLen1
) + 3) & ~3;
158 /* There doesn't have to exist an underlying block device */
159 if ((STRPTR
)((IPTR
*)parmPacket
)[1] != NULL
)
161 strLen2
= strlen((STRPTR
)((IPTR
*)parmPacket
)[1]);
167 sz2
= AROS_BSTR_MEMSIZE4LEN(strLen2
);
169 s1
= AllocVec(sz1
+ sz2
, MEMF_CLEAR
| MEMF_PUBLIC
);
173 FreeMem(newde
, desize
);
174 FreeMem(dn
, sizeof(struct DeviceNode
));
175 FreeMem(fssm
, sizeof(struct FileSysStartupMsg
));
180 /* We have no more allocations */
186 for (i
= 0; i
< strLen1
; i
++)
188 AROS_BSTR_putchar(bs1
, i
, ((STRPTR
)((IPTR
*)parmPacket
)[0])[i
]);
191 for (i
= 0; i
< strLen2
; i
++)
193 AROS_BSTR_putchar(bs2
, i
, ((STRPTR
)((IPTR
*)parmPacket
)[1])[i
]);
196 AROS_BSTR_setstrlen(bs1
, strLen1
> 255 ? 255 : strLen1
);
197 AROS_BSTR_setstrlen(bs2
, strLen2
> 255 ? 255 : strLen2
);
199 /* Strings are done, now the FileSysStartupMsg */
200 fssm
->fssm_Unit
= ((IPTR
*)parmPacket
)[2];
201 fssm
->fssm_Device
= bs2
;
202 fssm
->fssm_Environ
= MKBADDR(newde
);
203 fssm
->fssm_Flags
= ((IPTR
*)parmPacket
)[3];
205 /* FSSM is done, now the DeviceNode */
206 dn
->dn_Startup
= MKBADDR(fssm
);
207 dn
->dn_Type
= DLT_DEVICE
;
209 dn
->dn_Ext
.dn_AROS
.dn_DevName
= AROS_BSTR_ADDR(bs1
);