1 #include "inc.h" 2 3 void free_extent(struct dir_extent *e) { 4 if (e == NULL) 5 return; 6 7 free_extent(e->next); 8 free(e); 9 } 10 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; 15 16 free(e->r_name); 17 e->r_name = NULL; 18 } 19 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; 23 24 if (block_id == 0 || block_id >= v_pri.volume_space_size_l) 25 return NULL; 26 27 if(lmfs_get_block(&bp, fs_dev, block_id, NORMAL) != OK) 28 return NULL; 29 30 return bp; 31 } 32 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; 36 37 if (e == NULL) 38 return 0; 39 40 /* Retrieve the extent on which the block lies. */ 41 while(block >= extent_offset + e->length) { 42 if (e->next == NULL) 43 return 0; 44 45 extent_offset += e->length; 46 e = e->next; 47 } 48 49 return e->location + block - extent_offset; 50 } 51 52 time_t date7_to_time_t(const u8_t *date) { 53 /* 54 * This function converts from the ISO 9660 7-byte time format to a 55 * time_t. 56 */ 57 struct tm ltime; 58 signed char time_zone = (signed char)date[6]; 59 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; 67 68 /* Offset from Greenwich Mean Time */ 69 if (time_zone >= -52 && time_zone <= 52) 70 ltime.tm_hour += time_zone; 71 72 return mktime(<ime); 73 } 74 75 void* alloc_mem(size_t s) { 76 void *ptr = calloc(1, s); 77 assert(ptr != NULL); 78 79 return ptr; 80 } 81