X-Git-Url: http://www.aleph1.co.uk/gitweb/?p=yaffs2.git;a=blobdiff_plain;f=yaffs_allocator.c;h=b9fe31e70d475840e8c613d8eb2a2fa29663913e;hp=b304b67f176f0e654f0eb9ab53be02ba862fe905;hb=23ad7f93a1c1c93f541835a002121dfa4e307289;hpb=976dbeae825b18e6759f3903073a6784248cc244 diff --git a/yaffs_allocator.c b/yaffs_allocator.c index b304b67..b9fe31e 100644 --- a/yaffs_allocator.c +++ b/yaffs_allocator.c @@ -11,8 +11,6 @@ * published by the Free Software Foundation. */ - - #include "yaffs_allocator.h" #include "yaffs_guts.h" #include "yaffs_trace.h" @@ -30,12 +28,12 @@ void yaffs_init_raw_tnodes_and_objs(struct yaffs_dev *dev) dev = dev; } -yaffs_tnode_t *yaffs_alloc_raw_tnode(struct yaffs_dev *dev) +struct yaffs_tnode *yaffs_alloc_raw_tnode(struct yaffs_dev *dev) { - return (yaffs_tnode_t *)YMALLOC(dev->tnode_size); + return (struct yaffs_tnode *)YMALLOC(dev->tnode_size); } -void yaffs_free_raw_tnode(struct yaffs_dev *dev, yaffs_tnode_t *tn) +void yaffs_free_raw_tnode(struct yaffs_dev *dev, struct yaffs_tnode *tn) { dev = dev; YFREE(tn); @@ -54,10 +52,9 @@ void yaffs_deinit_raw_objs(struct yaffs_dev *dev) struct yaffs_obj *yaffs_alloc_raw_obj(struct yaffs_dev *dev) { dev = dev; - return (struct yaffs_obj *) YMALLOC(sizeof(struct yaffs_obj)); + return (struct yaffs_obj *)YMALLOC(sizeof(struct yaffs_obj)); } - void yaffs_free_raw_obj(struct yaffs_dev *dev, struct yaffs_obj *obj) { @@ -69,41 +66,36 @@ void yaffs_free_raw_obj(struct yaffs_dev *dev, struct yaffs_obj *obj) struct yaffs_tnode_list { struct yaffs_tnode_list *next; - yaffs_tnode_t *tnodes; + struct yaffs_tnode *tnodes; }; -typedef struct yaffs_tnode_list yaffs_tnodelist_t; - -struct yaffs_obj_list_struct { +struct yaffs_obj_list { + struct yaffs_obj_list *next; struct yaffs_obj *objects; - struct yaffs_obj_list_struct *next; }; -typedef struct yaffs_obj_list_struct yaffs_obj_list; - - struct yaffs_allocator { int n_tnodes_created; - yaffs_tnode_t *free_tnodes; + struct yaffs_tnode *free_tnodes; int n_free_tnodes; - yaffs_tnodelist_t *alloc_tnode_list; + struct yaffs_tnode_list *alloc_tnode_list; int n_obj_created; struct yaffs_obj *free_objs; int n_free_objects; - yaffs_obj_list *allocated_obj_list; + struct yaffs_obj_list *allocated_obj_list; }; - static void yaffs_deinit_raw_tnodes(struct yaffs_dev *dev) { - struct yaffs_allocator *allocator = (struct yaffs_allocator *)dev->allocator; + struct yaffs_allocator *allocator = + (struct yaffs_allocator *)dev->allocator; - yaffs_tnodelist_t *tmp; + struct yaffs_tnode_list *tmp; - if(!allocator){ + if (!allocator) { YBUG(); return; } @@ -126,26 +118,28 @@ static void yaffs_init_raw_tnodes(struct yaffs_dev *dev) { struct yaffs_allocator *allocator = dev->allocator; - if(allocator){ + if (allocator) { allocator->alloc_tnode_list = NULL; allocator->free_tnodes = NULL; allocator->n_free_tnodes = 0; allocator->n_tnodes_created = 0; - } else + } else { YBUG(); + } } static int yaffs_create_tnodes(struct yaffs_dev *dev, int n_tnodes) { - struct yaffs_allocator *allocator = (struct yaffs_allocator *)dev->allocator; + struct yaffs_allocator *allocator = + (struct yaffs_allocator *)dev->allocator; int i; - yaffs_tnode_t *new_tnodes; + struct yaffs_tnode *new_tnodes; u8 *mem; - yaffs_tnode_t *curr; - yaffs_tnode_t *next; - yaffs_tnodelist_t *tnl; + struct yaffs_tnode *curr; + struct yaffs_tnode *next; + struct yaffs_tnode_list *tnl; - if(!allocator){ + if (!allocator) { YBUG(); return YAFFS_FAIL; } @@ -153,28 +147,27 @@ static int yaffs_create_tnodes(struct yaffs_dev *dev, int n_tnodes) if (n_tnodes < 1) return YAFFS_OK; - /* make these things */ new_tnodes = YMALLOC(n_tnodes * dev->tnode_size); - mem = (u8 *)new_tnodes; + mem = (u8 *) new_tnodes; if (!new_tnodes) { T(YAFFS_TRACE_ERROR, - (TSTR("yaffs: Could not allocate Tnodes" TENDSTR))); + (TSTR("yaffs: Could not allocate Tnodes" TENDSTR))); return YAFFS_FAIL; } /* New hookup for wide tnodes */ for (i = 0; i < n_tnodes - 1; i++) { - curr = (yaffs_tnode_t *) &mem[i * dev->tnode_size]; - next = (yaffs_tnode_t *) &mem[(i+1) * dev->tnode_size]; + curr = (struct yaffs_tnode *)&mem[i * dev->tnode_size]; + next = (struct yaffs_tnode *)&mem[(i + 1) * dev->tnode_size]; curr->internal[0] = next; } - curr = (yaffs_tnode_t *) &mem[(n_tnodes - 1) * dev->tnode_size]; + curr = (struct yaffs_tnode *)&mem[(n_tnodes - 1) * dev->tnode_size]; curr->internal[0] = allocator->free_tnodes; - allocator->free_tnodes = (yaffs_tnode_t *)mem; + allocator->free_tnodes = (struct yaffs_tnode *)mem; allocator->n_free_tnodes += n_tnodes; allocator->n_tnodes_created += n_tnodes; @@ -184,12 +177,12 @@ static int yaffs_create_tnodes(struct yaffs_dev *dev, int n_tnodes) * but it just means we can't free this bunch of tnodes later. */ - tnl = YMALLOC(sizeof(yaffs_tnodelist_t)); + tnl = YMALLOC(sizeof(struct yaffs_tnode_list)); if (!tnl) { T(YAFFS_TRACE_ERROR, (TSTR ("yaffs: Could not add tnodes to management list" TENDSTR))); - return YAFFS_FAIL; + return YAFFS_FAIL; } else { tnl->tnodes = new_tnodes; tnl->next = allocator->alloc_tnode_list; @@ -201,13 +194,13 @@ static int yaffs_create_tnodes(struct yaffs_dev *dev, int n_tnodes) return YAFFS_OK; } - -yaffs_tnode_t *yaffs_alloc_raw_tnode(struct yaffs_dev *dev) +struct yaffs_tnode *yaffs_alloc_raw_tnode(struct yaffs_dev *dev) { - struct yaffs_allocator *allocator = (struct yaffs_allocator *)dev->allocator; - yaffs_tnode_t *tn = NULL; + struct yaffs_allocator *allocator = + (struct yaffs_allocator *)dev->allocator; + struct yaffs_tnode *tn = NULL; - if(!allocator){ + if (!allocator) { YBUG(); return NULL; } @@ -226,11 +219,11 @@ yaffs_tnode_t *yaffs_alloc_raw_tnode(struct yaffs_dev *dev) } /* FreeTnode frees up a tnode and puts it back on the free list */ -void yaffs_free_raw_tnode(struct yaffs_dev *dev, yaffs_tnode_t *tn) +void yaffs_free_raw_tnode(struct yaffs_dev *dev, struct yaffs_tnode *tn) { struct yaffs_allocator *allocator = dev->allocator; - if(!allocator){ + if (!allocator) { YBUG(); return; } @@ -240,29 +233,28 @@ void yaffs_free_raw_tnode(struct yaffs_dev *dev, yaffs_tnode_t *tn) allocator->free_tnodes = tn; allocator->n_free_tnodes++; } - dev->checkpoint_blocks_required = 0; /* force recalculation*/ + dev->checkpoint_blocks_required = 0; /* force recalculation */ } - - static void yaffs_init_raw_objs(struct yaffs_dev *dev) { struct yaffs_allocator *allocator = dev->allocator; - if(allocator) { + if (allocator) { allocator->allocated_obj_list = NULL; allocator->free_objs = NULL; allocator->n_free_objects = 0; - } else + } else { YBUG(); + } } static void yaffs_deinit_raw_objs(struct yaffs_dev *dev) { struct yaffs_allocator *allocator = dev->allocator; - yaffs_obj_list *tmp; + struct yaffs_obj_list *tmp; - if(!allocator){ + if (!allocator) { YBUG(); return; } @@ -280,16 +272,15 @@ static void yaffs_deinit_raw_objs(struct yaffs_dev *dev) allocator->n_obj_created = 0; } - static int yaffs_create_free_objs(struct yaffs_dev *dev, int n_obj) { struct yaffs_allocator *allocator = dev->allocator; int i; struct yaffs_obj *new_objs; - yaffs_obj_list *list; + struct yaffs_obj_list *list; - if(!allocator){ + if (!allocator) { YBUG(); return YAFFS_FAIL; } @@ -299,14 +290,14 @@ static int yaffs_create_free_objs(struct yaffs_dev *dev, int n_obj) /* make these things */ new_objs = YMALLOC(n_obj * sizeof(struct yaffs_obj)); - list = YMALLOC(sizeof(yaffs_obj_list)); + list = YMALLOC(sizeof(struct yaffs_obj_list)); if (!new_objs || !list) { - if (new_objs){ + if (new_objs) { YFREE(new_objs); new_objs = NULL; } - if (list){ + if (list) { YFREE(list); list = NULL; } @@ -318,7 +309,7 @@ static int yaffs_create_free_objs(struct yaffs_dev *dev, int n_obj) /* Hook them into the free list */ for (i = 0; i < n_obj - 1; i++) { new_objs[i].siblings.next = - (struct ylist_head *)(&new_objs[i + 1]); + (struct list_head *)(&new_objs[i + 1]); } new_objs[n_obj - 1].siblings.next = (void *)allocator->free_objs; @@ -340,7 +331,7 @@ struct yaffs_obj *yaffs_alloc_raw_obj(struct yaffs_dev *dev) struct yaffs_obj *obj = NULL; struct yaffs_allocator *allocator = dev->allocator; - if(!allocator) { + if (!allocator) { YBUG(); return obj; } @@ -352,24 +343,23 @@ struct yaffs_obj *yaffs_alloc_raw_obj(struct yaffs_dev *dev) if (allocator->free_objs) { obj = allocator->free_objs; allocator->free_objs = - (struct yaffs_obj *) (allocator->free_objs->siblings.next); + (struct yaffs_obj *)(allocator->free_objs->siblings.next); allocator->n_free_objects--; } return obj; } - void yaffs_free_raw_obj(struct yaffs_dev *dev, struct yaffs_obj *obj) { struct yaffs_allocator *allocator = dev->allocator; - if(!allocator) + if (!allocator) YBUG(); else { /* Link into the free list. */ - obj->siblings.next = (struct ylist_head *)(allocator->free_objs); + obj->siblings.next = (struct list_head *)(allocator->free_objs); allocator->free_objs = obj; allocator->n_free_objects++; } @@ -377,30 +367,31 @@ void yaffs_free_raw_obj(struct yaffs_dev *dev, struct yaffs_obj *obj) void yaffs_deinit_raw_tnodes_and_objs(struct yaffs_dev *dev) { - if(dev->allocator){ + if (dev->allocator) { yaffs_deinit_raw_tnodes(dev); yaffs_deinit_raw_objs(dev); YFREE(dev->allocator); - dev->allocator=NULL; - } else + dev->allocator = NULL; + } else { YBUG(); + } } void yaffs_init_raw_tnodes_and_objs(struct yaffs_dev *dev) { struct yaffs_allocator *allocator; - if(!dev->allocator){ + if (!dev->allocator) { allocator = YMALLOC(sizeof(struct yaffs_allocator)); - if(allocator){ + if (allocator) { dev->allocator = allocator; yaffs_init_raw_tnodes(dev); yaffs_init_raw_objs(dev); } - } else + } else { YBUG(); + } } - #endif