a935fc44181b8c7ce9fd1fabbe3dafbcca1642a8
[lunaix-os.git] / lunaix-os / kernel / fs / probe_boot.c
1 #include <lunaix/fs/iso9660.h>
2 #include <lunaix/fs/probe_boot.h>
3 #include <lunaix/mm/valloc.h>
4 #include <lunaix/syslog.h>
5
6 LOG_MODULE("PROBE")
7
8 #define LUNAIX_ID 0x414e554cUL // "LUNA"
9
10 struct device*
11 probe_boot_medium()
12 {
13     struct device* block_cat = device_getbyname(NULL, "block", 5);
14     if (!block_cat) {
15         return NULL;
16     }
17
18     struct iso_vol_primary* volp = valloc(ISO9660_BLKSZ);
19
20     struct device *pos, *n;
21     llist_for_each(pos, n, &block_cat->children, siblings)
22     {
23         int errno =
24           pos->ops.read(pos, (void*)volp, ISO9660_READ_OFF, ISO9660_BLKSZ);
25         if (errno < 0) {
26             kprintf(KINFO "failed %x:%d:%d, /dev/%s\n",
27                     pos->class->meta,
28                     pos->class->device,
29                     pos->class->variant,
30                     pos->name.value);
31             pos = NULL;
32             goto done;
33         }
34
35         if (*(u32_t*)volp->header.std_id != ISO_SIGNATURE_LO) {
36             continue;
37         }
38
39         if (*(u32_t*)volp->sys_id == LUNAIX_ID) {
40             kprintf(KINFO "%x:%d:%d, /dev/%s, %s\n",
41                     pos->class->meta,
42                     pos->class->device,
43                     pos->class->variant,
44                     pos->name.value,
45                     (char*)volp->vol_id);
46             break;
47         }
48     }
49
50 done:
51     vfree(volp);
52     return pos;
53 }