2 * This file contains some code to guess where we have to load the
3 * RAM image device from, if started from CD. (In this case it's hard
4 * to tell where this is without diving into BIOS heuristics.)
6 * There is some nasty hard-codery in here ( MINIX cd label) that can be
10 * Jul 14, 2005 Created (Ben Gras)
11 * Feb 10, 2006 Changed into a standalone program (Philip Homburg)
12 * May 25, 2015 Installation CD overhaul (Jean-Baptiste Boric)
15 #define CD_SECTOR 2048
16 #define SUPER_OFF 1024
29 const int probelist
[AT_MINORS
] = { 2, 3, 1, 0, 6, 7, 5, 4 };
30 int controller
, disk
, r
, fd
;
32 char name
[] = "/dev/c0dX";
35 for(controller
= 0; controller
<= 1; controller
++) {
36 name
[6] = '0' + controller
;
37 for(disk
= 0; disk
< AT_MINORS
; disk
++) {
38 name
[8]= '0' + probelist
[disk
];
40 fprintf(stderr
, "Trying %s \r", name
);
43 fd
= open(name
, O_RDONLY
);
44 if ((fd
< 0) && (errno
!= ENXIO
)) {
45 fprintf(stderr
, "open '%s' failed: %s\n",
46 name
, strerror(errno
));
50 /* Try to read PVD. */
51 pos
= lseek(fd
, 16*CD_SECTOR
, SEEK_SET
);
52 if (pos
!= 16*CD_SECTOR
) {
56 r
= read(fd
, pvd
, sizeof(pvd
));
58 if (r
!= sizeof(pvd
)) {
63 if (pvd
[0] != 1 || pvd
[1] != 'C' || pvd
[2] != 'D' ||
64 pvd
[3] != '0' || pvd
[4] != '0' || pvd
[5] != '1' ||
66 strncmp(pvd
+ 40, "MINIX", 5) != 0) {
70 fprintf(stderr
, "\nFound.\n");
76 fprintf(stderr
, "\nNot found.\n");