Merge branch 'interrupt-rework' into prog-loader
[lunaix-os.git] / lunaix-os / kernel / fs / iso9660 / rockridge.c
1 #include <lunaix/fs/iso9660.h>
2
3 int
4 isorr_parse_px(struct iso_drecache* cache, void* px_start)
5 {
6     struct isorr_px* px = (struct isorr_px*)px_start;
7     cache->fno = px->sn.le;
8     // TODO read other file attributes
9     return px->header.length;
10 }
11
12 time_t
13 isorr_tf_gettime(struct isorr_tf* tf, int* index, u32_t type)
14 {
15     time_t t = 0;
16     if ((tf->flags & type)) {
17         if ((tf->flags & ISORR_TF_LONG_FORM)) {
18             t =
19               iso9660_dt2unix((struct iso_datetime*)(tf->times + 17 * *index));
20         } else {
21             t =
22               iso9660_dt22unix((struct iso_datetime2*)(tf->times + 7 * *index));
23         }
24         *index = *index + 1;
25     }
26     return t;
27 }
28
29 int
30 isorr_parse_tf(struct iso_drecache* cache, void* tf_start)
31 {
32     struct isorr_tf* tf = (struct isorr_tf*)tf_start;
33     int i = 0;
34     cache->ctime = isorr_tf_gettime(tf, &i, ISORR_TF_CTIME);
35     cache->mtime = isorr_tf_gettime(tf, &i, ISORR_TF_MTIME);
36     cache->atime = isorr_tf_gettime(tf, &i, ISORR_TF_ATIME);
37     // TODO read other file attributes
38     return tf->header.length;
39 }
40
41 int
42 isorr_parse_nm(struct iso_drecache* cache, void* nm_start)
43 {
44     u32_t i = 0, adv = 0;
45     struct isorr_nm* nm;
46
47     do {
48         nm = (struct isorr_nm*)(nm_start + adv);
49         u32_t len_name = nm->header.length - sizeof(*nm);
50         memcpy(cache->name_val + i, nm->name, len_name);
51         i += len_name;
52         adv += nm->header.length;
53     } while ((nm->flags & ISORR_NM_CONT) && i < ISO9660_IDLEN - 1);
54
55     cache->name_val[i] = 0;
56     cache->name = HSTR(cache->name_val, i);
57     hstr_rehash(&cache->name, HSTR_FULL_HASH);
58
59     return adv;
60 }