feat: owloysius - dynamic init function invocator
[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_meta* 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* dev = NULL;
21     struct device_meta *pos, *n;
22     llist_for_each(pos, n, &block_cat->children, siblings)
23     {
24         dev = resolve_device(pos);
25         if (!dev) {
26             continue;
27         }
28
29         int errno =
30           dev->ops.read(dev, (void*)volp, ISO9660_READ_OFF, ISO9660_BLKSZ);
31         if (errno < 0) {
32             kprintf(KINFO "failed %xh:%xh, /dev/%s",
33                     dev->ident.fn_grp,
34                     dev->ident.unique,
35                     dev->name.value);
36             dev = NULL;
37             goto done;
38         }
39
40         if (*(u32_t*)volp->header.std_id != ISO_SIGNATURE_LO) {
41             continue;
42         }
43
44         if (*(u32_t*)volp->sys_id == LUNAIX_ID) {
45             kprintf(KINFO "%xh:%xh, /dev/%s, %s",
46                     dev->ident.fn_grp,
47                     dev->ident.unique,
48                     dev->name.value,
49                     (char*)volp->vol_id);
50             break;
51         }
52     }
53
54 done:
55     vfree(volp);
56     return dev;
57 }