1 /* This file contains some code to guess where we have to load the
2 * RAM image device from, if started from CD. (In this case it's hard
3 * to tell where this is without diving into BIOS heuristics.)
5 * There is some nasty hard-codery in here ( MINIX cd label) that can be
9 * Jul 14, 2005 Created (Ben Gras)
10 * Feb 10, 2006 Changed into a standalone program (Philip Homburg)
13 #define CD_SECTOR 2048
14 #define SUPER_OFF 1024
25 #include "mfs/const.h"
29 /*===========================================================================*
31 *===========================================================================*/
34 int controller
, disk
, r
, fd
, minor
, found
;
37 char name1
[]= "/dev/c0dX";
38 char name2
[]= "/dev/c0dXpY";
39 int probelist
[AT_MINORS
] = { 2, 3, 1, 0, 6, 7, 5, 4 };
42 for(controller
= 0; controller
<= 1; controller
++) {
43 name1
[6] = '0' + controller
;
44 name2
[6] = '0' + controller
;
45 for(disk
= 0; disk
< AT_MINORS
; disk
++) {
46 name1
[8]= '0' + probelist
[disk
];
48 fprintf(stderr
, "Trying %s \r", name1
);
51 fd
= open(name1
, O_RDONLY
);
56 fprintf(stderr
, "open '%s' failed: %s\n",
57 name1
, strerror(errno
));
62 pos
= lseek(fd
, 16*CD_SECTOR
, SEEK_SET
);
63 if (pos
!= 16*CD_SECTOR
)
65 /* Strange, do we need to issue a warning? */
69 r
= read(fd
, pvd
, sizeof(pvd
));
73 "error reading CD label from '%s': %s\n",
74 name1
, strerror(errno
));
81 if (pvd
[0] != 1 || pvd
[1] != 'C' || pvd
[2] != 'D' ||
82 pvd
[3] != '0' || pvd
[4] != '0' || pvd
[5] != '1' ||
84 strncmp(pvd
+ 40, "MINIX", 5) != 0) {
88 /* 3. Both cXdYp1 and p2 should have a superblock. */
89 found
= 1; /* Assume everything is okay */
90 for (minor
= 1; minor
<= 2; minor
++) {
91 name2
[8]= '0' + probelist
[disk
];
92 name2
[10]= '0' + minor
;
94 fd
= open(name2
, O_RDONLY
);
100 "open '%s' failed: %s\n",
101 name2
, strerror(errno
));
106 r
= read(fd
, pvd
, sizeof(pvd
));
107 if (r
!= sizeof(pvd
))
110 "error reading super block from '%s': %s\n",
111 name2
, strerror(errno
));
118 magicp
= (u16_t
*)&pvd
[SUPER_OFF
+MAGIC_OFF
];
119 if (*magicp
!= SUPER_V3
)
121 fprintf(stderr
, "bad super block on %s\n",
130 fprintf(stderr
, "\nFound.\n");
131 printf("%s\n", name1
);
136 fprintf(stderr
, "\nNot found.\n");