Line data Source code
1 : #include "clusterautoconfig.h" 2 : 3 : #include <stdint.h> 4 : #include <unistd.h> 5 : #include <libintl.h> 6 : #include <string.h> 7 : 8 : #include <logging.h> 9 : #include "libgfs2.h" 10 : #include "osi_list.h" 11 : #include "inode_hash.h" 12 : #include "fsck.h" 13 : #define _(String) gettext(String) 14 : 15 1514 : struct inode_info *inodetree_find(struct fsck_cx *cx, uint64_t block) 16 : { 17 1514 : struct osi_node *node = cx->inodetree.osi_node; 18 : 19 1514 : while (node) { 20 0 : struct inode_info *data = (struct inode_info *)node; 21 : 22 0 : if (block < data->num.in_addr) 23 0 : node = node->osi_left; 24 0 : else if (block > data->num.in_addr) 25 0 : node = node->osi_right; 26 : else 27 0 : return data; 28 : } 29 1514 : return NULL; 30 : } 31 : 32 0 : struct inode_info *inodetree_insert(struct fsck_cx *cx, struct lgfs2_inum no) 33 : { 34 0 : struct osi_node **newn = &cx->inodetree.osi_node, *parent = NULL; 35 : struct inode_info *data; 36 : 37 : /* Figure out where to put new node */ 38 0 : while (*newn) { 39 0 : struct inode_info *cur = (struct inode_info *)*newn; 40 : 41 0 : parent = *newn; 42 0 : if (no.in_addr < cur->num.in_addr) 43 0 : newn = &((*newn)->osi_left); 44 0 : else if (no.in_addr > cur->num.in_addr) 45 0 : newn = &((*newn)->osi_right); 46 : else 47 0 : return cur; 48 : } 49 : 50 0 : data = calloc(1, sizeof(struct inode_info)); 51 0 : if (!data) { 52 0 : log_crit( _("Unable to allocate inode_info structure\n")); 53 0 : return NULL; 54 : } 55 : /* Add new node and rebalance tree. */ 56 0 : data->num = no; 57 0 : osi_link_node(&data->node, parent, newn); 58 0 : osi_insert_color(&data->node, &cx->inodetree); 59 : 60 0 : return data; 61 : } 62 : 63 0 : void inodetree_delete(struct fsck_cx *cx, struct inode_info *b) 64 : { 65 0 : osi_erase(&b->node, &cx->inodetree); 66 0 : free(b); 67 0 : }