2 Copyright © 1995-2011, The AROS Development Team. All rights reserved.
7 #include <dos/rdargs.h>
8 #include <exec/lists.h>
9 #include <exec/memory.h>
10 #include <workbench/icon.h>
11 #include <proto/dos.h>
12 #include <proto/exec.h>
13 #include <proto/icon.h>
14 #include <proto/uuid.h>
23 #include "hdtoolbox_support.h"
26 struct List tabletypelist
;
28 struct TableTypeNode
*findTableTypeNodeName(STRPTR name
)
30 struct TableTypeNode
*ttn
;
32 D(bug("[HDToolBox] findTableTypeNodeName('%s')\n", name
));
34 ttn
= (struct TableTypeNode
*)tabletypelist
.lh_Head
;
35 while (ttn
->ln
.ln_Succ
)
37 if (strcmp(ttn
->pti
->pti_Name
, name
) == 0)
39 ttn
= (struct TableTypeNode
*)ttn
->ln
.ln_Succ
;
44 struct TableTypeNode
*findTableTypeNode(ULONG tabletype
)
46 struct TableTypeNode
*ttn
;
48 D(bug("[HDToolBox] findTableTypeNode()\n"));
50 ttn
= (struct TableTypeNode
*)tabletypelist
.lh_Head
;
51 while (ttn
->ln
.ln_Succ
)
53 if (ttn
->pti
->pti_Type
== tabletype
)
55 ttn
= (struct TableTypeNode
*)ttn
->ln
.ln_Succ
;
60 struct TypeNode
*findPartitionType(struct PartitionType
*type
, ULONG tabletype
)
62 struct TableTypeNode
*ttn
;
65 D(bug("[HDToolBox] findPartitionType()\n"));
67 ttn
= findTableTypeNode(tabletype
);
70 tn
= (struct TypeNode
*)ttn
->typelist
->lh_Head
;
71 while (tn
->ln
.ln_Succ
)
73 if (tn
->type
.id_len
== type
->id_len
)
75 if (memcmp(tn
->type
.id
, type
->id
, type
->id_len
) == 0)
78 tn
= (struct TypeNode
*)tn
->ln
.ln_Succ
;
84 void getTableTypeList(struct List
*list
)
86 struct TableTypeNode
*ttn
;
89 D(bug("[HDToolBox] getTableTypeList()\n"));
91 NEWLIST(&tabletypelist
);
92 for (i
=0;PartitionBase
->tables
[i
];i
++)
94 ttn
= AllocMem(sizeof(struct TableTypeNode
), MEMF_PUBLIC
| MEMF_CLEAR
);
98 AllocMem(sizeof(struct List
), MEMF_PUBLIC
| MEMF_CLEAR
);
99 if (ttn
->typelist
!= NULL
)
101 ttn
->pti
= PartitionBase
->tables
[i
];
102 NEWLIST(ttn
->typelist
);
103 AddTail(list
, &ttn
->ln
);
107 FreeMem(ttn
, sizeof(struct TableTypeNode
));
114 static LONG
parseType(struct TableTypeNode
*ttn
, ULONG id_len
, char *ident
, struct CSource
*csrc
, WORD line
)
119 struct TypeNode
*tn
= AllocMem(sizeof(struct TypeNode
), MEMF_PUBLIC
| MEMF_CLEAR
);
122 return ERROR_NO_FREE_STORE
;
124 tn
->type
.id_len
= id_len
;
126 switch (ttn
->pti
->pti_Type
)
129 UUID_Parse(ident
, (uuid_t
*)&tn
->type
.id
);
133 strcpyESC(tn
->type
.id
, ident
);
137 res
= ReadItem(ident
, 256, csrc
);
145 res
= ReadItem(ident
, 256, csrc
);
153 res
= strlen(ident
) + 1;
155 tn
->ln
.ln_Name
= AllocVec(res
, MEMF_PUBLIC
| MEMF_CLEAR
);
156 if (tn
->ln
.ln_Name
== NULL
)
157 return ERROR_NO_FREE_STORE
;
159 CopyMem(ident
, tn
->ln
.ln_Name
, res
);
164 printf("LINE %d: Quoted expression expected\n", line
);
170 printf("LINE %d: Unexpected item after table id\n", line
);
174 AddTail(ttn
->typelist
, &tn
->ln
);
177 printf("LINE %d: Missing partition table type or IDLen\n", line
);
189 LONG
parsePrefs(char *buffer
, LONG size
)
191 struct TableTypeNode
*ttn
=NULL
;
192 struct CSource csrc
= {buffer
, size
, 0};
193 struct DiskObject
*hdtbicon
=NULL
;
197 WORD current
= Section_Root
;
200 D(bug("[HDToolBox] parsePrefs()\n"));
202 while (csrc
.CS_CurChr
< csrc
.CS_Length
)
204 DB2(bug("[parsePrefs] Cur %d, Length %d\n", csrc
.CS_CurChr
, csrc
.CS_Length
));
205 res
= ReadItem(ident
, 256, &csrc
);
207 DB2(bug("[parsePrefs] Got item %d (%s)\n", res
, ident
));
214 if (strcasecmp(ident
, "[Devices]") == 0)
215 current
= Section_Devices
;
216 else if (strcasecmp(ident
, "[TableIDs]") == 0)
218 current
= Section_TableIDs
;
226 case Section_Devices
:
227 addDeviceName(ident
);
230 case Section_TableIDs
:
231 if (strcasecmp(ident
, "TableType") == 0)
233 res
= ReadItem(ident
, 256, &csrc
);
241 res
= ReadItem(ident
, 256, &csrc
);
249 ttn
= findTableTypeNodeName(ident
);
253 ttn
= findTableTypeNode(strtoul(ident
, NULL
, 0));
257 printf("LINE %d: Unexpected item in TableType\n", line
);
263 printf("LINE %d: Unknown Table %s\n", line
, ident
);
269 printf("LINE %d: Unexpected item after TableType\n", line
);
273 else if (strcasecmp(ident
, "IDLen") == 0)
275 res
= ReadItem(ident
, 256, &csrc
);
283 res
= ReadItem(ident
, 256, &csrc
);
291 id_len
= strtoul(ident
, NULL
, 0);
294 printf("LINE %d: Illegal value of IDLen\n", line
);
300 printf("LINE %d: Value in IDLen expected\n", line
);
306 printf("LINE %d: Unexpected item after IDLen\n", line
);
310 else if (strcasecmp(ident
, "Default") == 0)
314 res
= ReadItem(ident
, 256, &csrc
);
323 res
= ReadItem(ident
, 256, &csrc
);
330 ttn
->defaulttype
.id_len
= id_len
;
331 strcpyESC(ttn
->defaulttype
.id
, ident
);
335 printf("LINE %d: Unexpected expression after Default\n", line
);
341 printf("LINE %d: Unexpected item after IDLen\n", line
);
347 printf("LINE %d: Unknown option '%s'\n", line
, ident
);
353 res
= parseType(ttn
, id_len
, ident
, &csrc
, line
);
361 printf("LINE %d: Unexpected item '%s' in prefs\n", line
, ident
);
368 res
= parseType(ttn
, id_len
, ident
, &csrc
, line
);
380 * Intentional ReadItem() bug workaround.
381 * Ungets '\n' every time, causing an infinite loop without this adjustment.
383 if ((csrc
.CS_CurChr
< csrc
.CS_Length
) && (buffer
[csrc
.CS_CurChr
] == '\n'))
387 hdtbicon
= GetIconTags("HDToolBox",
388 ICONGETA_FailIfUnavailable
, TRUE
,
389 ICONGETA_IsDefaultIcon
, FALSE
,
392 if (hdtbicon
!= NULL
)
394 D(bug("[HDToolBox] Got our Icon..\n"));
395 if (hdtbicon
->do_ToolTypes
)
397 char *tt
= NULL
, *devicename
;
399 D(bug("[HDToolBox] Icon has tooltypes..\n"));
401 while ((tt
= hdtbicon
->do_ToolTypes
[i
]) != NULL
)
403 if (strncmp(hdtbicon
->do_ToolTypes
[i
], "DEVICE=", 7) == 0)
405 devicename
= hdtbicon
->do_ToolTypes
[i
] + 7;
406 D(bug("[HDToolBox] Adding Device '%s' from ToolType\n", devicename
));
407 addDeviceName(devicename
);
414 // EBR uses same types as MBR
415 findTableTypeNode(PHPTT_EBR
)->typelist
=
416 findTableTypeNode(PHPTT_MBR
)->typelist
;
421 void LoadPrefs(STRPTR filename
)
423 struct FileInfoBlock fib
;
429 D(bug("[HDToolBox] LoadPrefs('%s')\n", filename
));
431 getTableTypeList(&tabletypelist
);
432 fh
= Open(filename
, MODE_OLDFILE
);
435 if (ExamineFH(fh
, &fib
))
439 buffer
= AllocMem(fib
.fib_Size
, MEMF_PUBLIC
| MEMF_CLEAR
);
442 size
= Read(fh
, buffer
, fib
.fib_Size
);
443 if (size
== fib
.fib_Size
)
445 retval
= parsePrefs(buffer
, size
);
447 PrintFault(retval
, filename
);
449 FreeMem(buffer
, fib
.fib_Size
);
452 PrintFault(ERROR_NO_FREE_STORE
, filename
);
458 PrintFault(IoErr(), filename
);