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