Remove building with NOCRYPTO option
[minix.git] / minix / fs / isofs / utility.c
blobe2d99769b6c25ae68f4180e8fa7c68cfd6100752
1 #include "inc.h"
3 void free_extent(struct dir_extent *e) {
4 if (e == NULL)
5 return;
7 free_extent(e->next);
8 free(e);
11 /* Free the contents of an inode dir entry, but not the pointer itself. */
12 void free_inode_dir_entry(struct inode_dir_entry *e) {
13 if (e == NULL)
14 return;
16 free(e->r_name);
17 e->r_name = NULL;
20 struct buf* read_extent_block(struct dir_extent *e, size_t block) {
21 size_t block_id = get_extent_absolute_block_id(e, block);
22 struct buf *bp;
24 if (block_id == 0 || block_id >= v_pri.volume_space_size_l)
25 return NULL;
27 if(lmfs_get_block(&bp, fs_dev, block_id, NORMAL) != OK)
28 return NULL;
30 return bp;
33 size_t get_extent_absolute_block_id(struct dir_extent *e, size_t block) {
34 size_t extent_offset = 0;
35 block /= v_pri.logical_block_size_l;
37 if (e == NULL)
38 return 0;
40 /* Retrieve the extent on which the block lies. */
41 while(block >= extent_offset + e->length) {
42 if (e->next == NULL)
43 return 0;
45 extent_offset += e->length;
46 e = e->next;
49 return e->location + block - extent_offset;
52 time_t date7_to_time_t(const u8_t *date) {
54 * This function converts from the ISO 9660 7-byte time format to a
55 * time_t.
57 struct tm ltime;
58 signed char time_zone = (signed char)date[6];
60 ltime.tm_year = date[0];
61 ltime.tm_mon = date[1] - 1;
62 ltime.tm_mday = date[2];
63 ltime.tm_hour = date[3];
64 ltime.tm_min = date[4];
65 ltime.tm_sec = date[5];
66 ltime.tm_isdst = 0;
68 /* Offset from Greenwich Mean Time */
69 if (time_zone >= -52 && time_zone <= 52)
70 ltime.tm_hour += time_zone;
72 return mktime(&ltime);
75 void* alloc_mem(size_t s) {
76 void *ptr = calloc(1, s);
77 assert(ptr != NULL);
79 return ptr;