try to make sure compiler/include/mmakefile is always refreshed correctly.
[AROS.git] / rom / dos / isbootable.c
blobf3d49dd727ef7d28cf3deb0992d39ff4430c845c
1 /*
2 Copyright © 1995-2016, The AROS Development Team. All rights reserved.
3 $Id$
5 Desc: Can this disk boot on your architecture?
6 Lang: english
7 */
9 #include <aros/debug.h>
10 #include <exec/alerts.h>
11 #include <proto/exec.h>
12 #include <proto/dos.h>
14 #include "dos_intern.h"
16 /* Signature file, contains (for example) 'pc-i386' */
17 #define AROS_BOOT_CHECKSIG ":AROS.boot"
18 /* Alternate variant: check if Shell is loadable
19 #define AROS_BOOT_CHECKEXEC ":C/Shell" */
21 BOOL __dos_IsBootable(struct DosLibrary * DOSBase, BPTR lock)
23 #if defined(AROS_BOOT_CHECKSIG)
24 BPTR fh;
25 STRPTR buffer;
26 LONG bufferLength;
27 struct FileInfoBlock *abfile_fib;
28 BOOL result = FALSE;
30 D(bug("[__dos_IsBootable] __dos_IsBootable('%s')\n", AROS_BOOT_CHECKSIG));
32 CurrentDir(lock);
33 fh = Open(AROS_BOOT_CHECKSIG, MODE_OLDFILE);
34 if (!fh)
36 #ifdef __mc68000
38 * Original Amiga disks don't contain this signature. They are obviously bootable on m68k.
39 * However if the disk DOES contain a signature, we should check it. This can happen to be
40 * a disk for another architecture. Attempting to boot from it will cause crash.
42 return TRUE;
43 #else
44 return FALSE;
45 #endif
48 D(bug("[__dos_IsBootable] Opened successfully\n"));
50 abfile_fib = AllocDosObject(DOS_FIB, NULL);
51 if (abfile_fib)
53 if (ExamineFH(fh, abfile_fib))
55 LONG readsize;
57 bufferLength = abfile_fib->fib_Size + 1;
59 buffer = AllocMem(bufferLength, MEMF_ANY);
60 D(bug("[__dos_IsBootable] Allocated %d bytes for Buffer @ %p\n", bufferLength, buffer));
62 if (!buffer)
64 Alert(AT_DeadEnd | AG_NoMemory | AN_DOSLib);
67 readsize = Read(fh, buffer, bufferLength - 1);
68 if (readsize > 0)
70 char *sigptr = NULL;
72 buffer[readsize] = '\0';
73 D(bug("[__dos_IsBootable] Buffer contains '%s'\n", buffer));
75 if ((sigptr = strstr(buffer, AROS_CPU)) != 0)
77 D(bug("[__dos_IsBootable] Signature '%s' found\n", AROS_CPU));
78 result = TRUE;
80 else
82 /* Something to more or less reflect "This disk is not bootable" */
83 SetIoErr(ERROR_OBJECT_WRONG_TYPE);
87 FreeDosObject(DOS_FIB, abfile_fib);
90 Close(fh);
92 D(bug("[__dos_IsBootable] returned %d\n", result));
93 return result;
95 #elif defined(AROS_BOOT_CHECKEXEC)
96 BPTR seg;
98 D(bug("[__dos_IsBootable]: Trying to load '%s' as an executable\n", AROS_BOOT_CHECKEXEC));
100 CurrentDir(lock);
101 if ((seg = LoadSeg(AROS_BOOT_CHECKEXEC)))
103 UnLoadSeg(seg);
105 D(bug("[__dos_IsBootable] Success!\n"));
106 return TRUE;
109 #else
110 return TRUE;
111 #endif