static void yaffs_deinit_raw_tnodes(yaffs_dev_t *dev) { yaffs_Allocator *allocator = (yaffs_Allocator *)dev->allocator; yaffs_tnodelist_t *tmp; if(!allocator){ YBUG(); return; } while (allocator->allocatedTnodeList) { tmp = allocator->allocatedTnodeList->next; YFREE(allocator->allocatedTnodeList->tnodes); YFREE(allocator->allocatedTnodeList); allocator->allocatedTnodeList = tmp; } allocator->freeTnodes = NULL; allocator->nFreeTnodes = 0; allocator->n_tnodesCreated = 0; }
/* Defines the used database. */ void command_use(cli_t *cli, char *pt) { int rc; // check connection if needed if (!check_connection(cli)) return; // request if (!strlen(pt) || !strcasecmp(pt, "default")) { // use default database if ((rc = finedb_setdb(cli->finedb, NULL)) != 0) { printf_color("red", "Unable to use the default database (%d).", rc); printf("\n"); } else { YFREE(cli->dbname); printf_decorated("faint", "Use the default database"); printf("\n"); } } else { // set a new database if ((rc = finedb_setdb(cli->finedb, pt)) != 0) { printf_color("red", "Unable to use the '%s' database (%d).", rc); printf("\n"); } else { YFREE(cli->dbname); cli->dbname = strdup(pt); printf_decorated("faint", "Use the '%s' database", pt); printf("\n"); } } }
int yaffs_CheckpointClose(yaffs_Device *dev) { if (dev->checkpointOpenForWrite) { if (dev->checkpointByteOffset != 0) yaffs_CheckpointFlushBuffer(dev); } else { int i; for (i = 0; i < dev->blocksInCheckpoint && dev->checkpointBlockList[i] >= 0; i++) { yaffs_BlockInfo *bi = yaffs_GetBlockInfo(dev, dev->checkpointBlockList[i]); if (bi->blockState == YAFFS_BLOCK_STATE_EMPTY) bi->blockState = YAFFS_BLOCK_STATE_CHECKPOINT; else { /* Todo this looks odd... */ } } YFREE(dev->checkpointBlockList); dev->checkpointBlockList = NULL; } dev->nFreeChunks -= dev->blocksInCheckpoint * dev->nChunksPerBlock; dev->nErasedBlocks -= dev->blocksInCheckpoint; T(YAFFS_TRACE_CHECKPOINT, (TSTR("checkpoint byte count %d" TENDSTR), dev->checkpointByteCount)); if (dev->checkpointBuffer) { /* free the buffer */ YFREE(dev->checkpointBuffer); dev->checkpointBuffer = NULL; return 1; } else return 0; }
static void yaffs_DeinitialiseRawTnodes(yaffs_Device *dev) { yaffs_Allocator *allocator = (yaffs_Allocator *)dev->allocator; yaffs_TnodeList *tmp; if(!allocator){ YBUG(); return; } while (allocator->allocatedTnodeList) { tmp = allocator->allocatedTnodeList->next; YFREE(allocator->allocatedTnodeList->tnodes); YFREE(allocator->allocatedTnodeList); allocator->allocatedTnodeList = tmp; } allocator->freeTnodes = NULL; allocator->nFreeTnodes = 0; allocator->nTnodesCreated = 0; }
static int CheckInit(yaffs_Device *dev) { static int initialised = 0; int i; int fail = 0; int nAllocated = 0; if(initialised) { return YAFFS_OK; } initialised = 1; ramdisk.nBlocks = (SIZE_IN_MB * 1024 * 1024)/(16 * 1024); ramdisk.block = YMALLOC(sizeof(yflash_Block *) * ramdisk.nBlocks); if(!ramdisk.block) return 0; for(i=0; i <ramdisk.nBlocks; i++) { ramdisk.block[i] = NULL; } for(i=0; i <ramdisk.nBlocks && !fail; i++) { if((ramdisk.block[i] = YMALLOC(sizeof(yflash_Block))) == 0) { fail = 1; } else { yflash_EraseBlockInNAND(dev,i); nAllocated++; } } if(fail) { for(i = 0; i < nAllocated; i++) { YFREE(ramdisk.block[i]); } YFREE(ramdisk.block); T(YAFFS_TRACE_ALWAYS,("Allocation failed, could only allocate %dMB of %dMB requested.\n", nAllocated/64,ramdisk.nBlocks * YAFFS_BYTES_PER_BLOCK)); return 0; } return 1; }
/** * _yht_remove * Remove an element from a hash table, using a string or an integer key. */ static ybool_t _yht_remove(yhashtable_t *hashtable, yht_hash_value_t hash_value, const char *key, ybool_t try_to_destroy) { yht_hash_value_t modulo_value; yht_bucket_t *bucket; yht_element_t *element; yht_list_t *item; size_t offset; ybool_t found = YFALSE; float load_factor; /* compute the key's hash value */ if (key != NULL) hash_value = yht_hash(key); modulo_value = hash_value % hashtable->size; /* retreiving the bucket */ bucket = &(hashtable->buckets[modulo_value]); if (bucket->nbr_elements == 0) return (YFALSE); /* searching in the bucket */ for (offset = 0, element = bucket->elements; offset < bucket->nbr_elements; offset++, element = element->next) { if (element->hash_value == hash_value && ((key == NULL && element->key == NULL) || (key != NULL && element->key != NULL && !strcmp(key, element->key)))) { found = YTRUE; if (try_to_destroy && hashtable->destroy_func != NULL) hashtable->destroy_func(element->hash_value, element->key, element->data, hashtable->destroy_data); item = element->item; if (hashtable->used == 1) YFREE(hashtable->items); else { item->next->previous = item->previous; item->previous->next = item->next; YFREE(item); } if (bucket->nbr_elements == 1) YFREE(bucket->elements); else { element->next->previous = element->previous; element->previous->next = element->next; YFREE(element); } break; } } if (found) { bucket->nbr_elements--; hashtable->used--; /* resize the map if its load factor will fall under the limit */ load_factor = (float)(hashtable->used + 1) / hashtable->size; if (load_factor < YHT_MIN_LOAD_FACTOR) yht_resize(hashtable, (hashtable->size / 2)); } return (found); }
static int yaffs_create_free_objs(yaffs_dev_t *dev, int n_obj) { yaffs_Allocator *allocator = dev->allocator; int i; yaffs_obj_t *newObjects; yaffs_obj_tList *list; if(!allocator){ YBUG(); return YAFFS_FAIL; } if (n_obj < 1) return YAFFS_OK; /* make these things */ newObjects = YMALLOC(n_obj * sizeof(yaffs_obj_t)); list = YMALLOC(sizeof(yaffs_obj_tList)); if (!newObjects || !list) { if (newObjects){ YFREE(newObjects); newObjects = NULL; } if (list){ YFREE(list); list = NULL; } T(YAFFS_TRACE_ALLOCATE, (TSTR("yaffs: Could not allocate more objects" TENDSTR))); return YAFFS_FAIL; } /* Hook them into the free list */ for (i = 0; i < n_obj - 1; i++) { newObjects[i].siblings.next = (struct ylist_head *)(&newObjects[i + 1]); } newObjects[n_obj - 1].siblings.next = (void *)allocator->freeObjects; allocator->freeObjects = newObjects; allocator->nFreeObjects += n_obj; allocator->n_objCreated += n_obj; /* Now add this bunch of Objects to a list for freeing up. */ list->objects = newObjects; list->next = allocator->allocatedObjectList; allocator->allocatedObjectList = list; return YAFFS_OK; }