/* void* change_entry(void* entry, int offset, int size) { } */ void* first_fit(kma_size_t size) { int min_size = sizeof(entry_t*); page_t* first_page = (page_t*)(gpage_entry->ptr); entry_t* entry = (entry_t*)(first_page->first); if(size < min_size) size = min_size; while(entry) { if(size > entry->size) { entry = entry->next; continue; } else if(size >= entry->size - min_size) { delete_entry(entry); return (void*)entry; } else { add_entry((void*)(entry + size), entry->size - size); delete_entry(entry); return (void*)entry; } } kma_page_t* new_page = get_page(); init_page(new_page); return first_fit(size); }
void combine_entry(partition_map *entry) { partition_map *p; u32 end; if (entry == NULL || istrncmp(entry->data->dpme_type, kFreeType, DPISTRLEN) != 0) { return; } if (entry->next_by_base != NULL) { p = entry->next_by_base; if (istrncmp(p->data->dpme_type, kFreeType, DPISTRLEN) != 0) { // next is not free } else if (entry->data->dpme_pblock_start + entry->data->dpme_pblocks != p->data->dpme_pblock_start) { // next is not contiguous (XXX this is bad) printf("next entry is not contiguous\n"); // start is already minimum // new end is maximum of two ends end = p->data->dpme_pblock_start + p->data->dpme_pblocks; if (end > entry->data->dpme_pblock_start + entry->data->dpme_pblocks) { entry->data->dpme_pblocks = end - entry->data->dpme_pblock_start; } entry->data->dpme_lblocks = entry->data->dpme_pblocks; delete_entry(p); } else { entry->data->dpme_pblocks += p->data->dpme_pblocks; entry->data->dpme_lblocks = entry->data->dpme_pblocks; delete_entry(p); } } if (entry->prev_by_base != NULL) { p = entry->prev_by_base; if (istrncmp(p->data->dpme_type, kFreeType, DPISTRLEN) != 0) { // previous is not free } else if (p->data->dpme_pblock_start + p->data->dpme_pblocks != entry->data->dpme_pblock_start) { // previous is not contiguous (XXX this is bad) printf("previous entry is not contiguous\n"); // new end is maximum of two ends end = p->data->dpme_pblock_start + p->data->dpme_pblocks; if (end < entry->data->dpme_pblock_start + entry->data->dpme_pblocks) { end = entry->data->dpme_pblock_start + entry->data->dpme_pblocks; } entry->data->dpme_pblocks = end - p->data->dpme_pblock_start; // new start is previous entry's start entry->data->dpme_pblock_start = p->data->dpme_pblock_start; entry->data->dpme_lblocks = entry->data->dpme_pblocks; delete_entry(p); } else { entry->data->dpme_pblock_start = p->data->dpme_pblock_start; entry->data->dpme_pblocks += p->data->dpme_pblocks; entry->data->dpme_lblocks = entry->data->dpme_pblocks; delete_entry(p); } } entry->contains_driver = contains_driver(entry); }
void CScriptCache::DecrementScriptUsage(uint32 scriptName) { CScriptCacheEntry *p_cache_entry=mp_cache_hash_table->GetItem(scriptName); if (p_cache_entry) { Dbg_MsgAssert(p_cache_entry->mUsage,("Zero cache entry usage for script '%s'",Script::FindChecksumName(scriptName))); --p_cache_entry->mUsage; if (p_cache_entry->mUsage==0) { #ifdef __NOPT_ASSERT__ --m_num_used_scripts; #endif if (m_delete_zero_usage_straight_away) { // For testing delete_entry(p_cache_entry); } else { add_to_zero_usage_list(p_cache_entry); } } } }
/** verify DS matches DNSKEY from a file */ static void dstest_file(const char* fname) { /* * The file contains a list of ldns-testpkts entries. * The first entry must be a query for DNSKEY. * The answer rrset is the keyset that will be used for verification */ struct regional* region = regional_create(); struct alloc_cache alloc; ldns_buffer* buf = ldns_buffer_new(65535); struct entry* e; struct entry* list = read_datafile(fname); struct module_env env; if(!list) fatal_exit("could not read %s: %s", fname, strerror(errno)); alloc_init(&alloc, NULL, 1); memset(&env, 0, sizeof(env)); env.scratch = region; env.scratch_buffer = buf; unit_assert(region && buf); /* ready to go! */ for(e = list; e; e = e->next) { dstest_entry(e, &alloc, region, buf, &env); } delete_entry(list); regional_destroy(region); alloc_clear(&alloc); ldns_buffer_free(buf); }
int main(int argc, char **argv) { if(argc != 3) { fprintf(stderr, "Usage: ext2_rm <image file name> <path to file>\n"); exit(1); } disk_initialization(argv[1]); /* initialize disk */ unsigned int dir_inode = inode_from_path(extract_parent_path(argv[2])); /* get inode index from path */ struct ext2_dir_entry_2 *de = dir_find(dir_inode, extract_filename(argv[2])); if (de == NULL) { fprintf(stderr, "No such file or directory\n"); exit(ENOENT); } unsigned int inode_index = de->inode; if (has_file_type(EXT2_INODE_FT_DIR, inode_index)) { fprintf(stderr, "%s: is a directory\n", argv[2]); exit(EISDIR); } else { /* remove directory entry associated with file */ delete_entry(dir_inode, extract_filename(argv[2])); } return 0; }
vm_exit_code handle_action_change(int pid, char *action, vm_act_state state) { Graph g; char msg[256], *this_state; vm_exit_code exit_status; peos_context_t *context = peos_get_context(pid); this_state = act_state_name(state); sprintf(msg, "%s %s %s %d ",login_name, this_state, action, pid); log_event(msg); g = context -> process_graph; if (g == NULL) { peos_error("handle_resource_event: process graph is null"); return VM_INTERNAL_ERROR; } if ((exit_status = set_act_state_graph(g, action, state)) == VM_DONE) { sprintf(msg,"%s DONE %s %d",login_name, context->model, pid); log_event(msg); delete_entry(context->pid); return exit_status; } if (exit_status == VM_INTERNAL_ERROR) { return exit_status; } return exit_status; }
int main() { if(count < 3) { count++; add_entry("Ankit Request","Monday","Cache",true); } if(count < 3) { count++; add_entry("Gupta Request","Friday","Namaste.txt",true); } cacheEntry * tmp = search_entry("Ankit Request"); printf("tmp file is %s\n",tmp->filename); if(count < 3) { printf("Added\n"); count++; add_entry("Atish Request","12-12-12","atish.txt",false); } print_cacheEntry(); if(count < 4) { count++;add_entry("amruth Request","11-11-11","atish.txt",false); } printf("***********NOW DELETE *********************"); delete_entry(); print_cacheEntry(); printf("****************NOW DELETE AND ADD************************"); updateremoveaddtoHead("Gupta Request","TIME X",false); print_cacheEntry(); return 0; }
int main(int argc, char** argv, char** envp) { int i; phone_entry* phonebook; phonebook=malloc(sizeof(phone_entry)*MAX_ENTRIES_IN_PHONEBOOK); for(i=0; i<MAX_ENTRIES_IN_PHONEBOOK; i++) { phone_entry_init(phonebook+i); // phone_entry_init(&phonebook[i]); } while(!over) { int selection=show_menu(); switch(selection) { case 1: add_entry(phonebook, MAX_ENTRIES_IN_PHONEBOOK); break; case 2: delete_entry(phonebook, MAX_ENTRIES_IN_PHONEBOOK); break; case 3: find_entry(phonebook, MAX_ENTRIES_IN_PHONEBOOK); break; case 4: print_phonebook(phonebook, MAX_ENTRIES_IN_PHONEBOOK); break; case 5: printf("terminating\n"); over=1; break; } } // release the memory free(phonebook); return EXIT_SUCCESS; }
static ModeMode run_mode_result ( Mode *sw, int mretv, char **input, unsigned int selected_line ) { RunModePrivateData *rmpd = (RunModePrivateData *) sw->private_data; ModeMode retv = MODE_EXIT; gboolean run_in_term = ( ( mretv & MENU_CUSTOM_ACTION ) == MENU_CUSTOM_ACTION ); if ( mretv & MENU_NEXT ) { retv = NEXT_DIALOG; } else if ( mretv & MENU_PREVIOUS ) { retv = PREVIOUS_DIALOG; } else if ( mretv & MENU_QUICK_SWITCH ) { retv = ( mretv & MENU_LOWER_MASK ); } else if ( ( mretv & MENU_OK ) && rmpd->cmd_list[selected_line] != NULL ) { exec_cmd ( rmpd->cmd_list[selected_line], run_in_term ); } else if ( ( mretv & MENU_CUSTOM_INPUT ) && *input != NULL && *input[0] != '\0' ) { exec_cmd ( *input, run_in_term ); } else if ( ( mretv & MENU_ENTRY_DELETE ) && rmpd->cmd_list[selected_line] ) { delete_entry ( rmpd->cmd_list[selected_line] ); // Clear the list. retv = RELOAD_DIALOG; run_mode_destroy ( sw ); run_mode_init ( sw ); } return retv; }
void filelist138 :: clear() { //clear every file for(unsigned i = 0; i < files.size(); i++) delete_entry(files[i]); files.clear(); //clear vector };
/** delete range */ static void replay_range_delete(struct replay_range* rng) { if(!rng) return; delete_entry(rng->match); free(rng); }
void BPTree::myDelete(pKey_Attr pPrimKey, _F_FileAddr& pRec) { setPath(); Key_Location KeyLoca; if(search(pPrimKey, &KeyLoca)) { pRec = getCurRecAddr(KeyLoca); delete_entry(KeyLoca.ptr, pPrimKey, pRec); } else throw 1023; }
static void ht_delete_entry_chain(const census_ht_option *options, ht_entry *first) { if (first == NULL) { return; } if (first->next != NULL) { ht_delete_entry_chain(options, first->next); } delete_entry(options, first); }
void do_unsetenv(char **t, t_env *env) { if (t[1] == NULL) return; if (my_strcmp_casse(t[1], "*") == 0) clean_list(&env->list); else delete_entry(&env->list, t[1]); clean_wordtab(env->environ); env->environ = convert_to_tab(env->list); }
void atf_list_append_list(atf_list_t *l, atf_list_t *src) { struct list_entry *e1, *e2, *ghost1, *ghost2; ghost1 = (struct list_entry *)l->m_end; ghost2 = (struct list_entry *)src->m_begin; e1 = ghost1->m_prev; e2 = ghost2->m_next; delete_entry(ghost1); delete_entry(ghost2); e1->m_next = e2; e2->m_prev = e1; l->m_end = src->m_end; l->m_size += src->m_size; }
/* Master deletion function. */ node * deletee(node * root, int key, int * value) { node * key_leaf; record * key_record; key_record = find(root, key, false, value); key_leaf = find_leaf(root, key, false); if (key_record != NULL && key_leaf != NULL) { root = delete_entry(root, key_leaf, key, key_record); free(key_record); } return root; }
/* * remove duplicate names in the table - the entries later * in the table are discarded. returns the new size of the * table */ int str_pairs_remove_duplicates(str_pair *table, int size) { int i, j; for(i=0; i < size-1; i++) for(j=i+1; j < size; j++) if (!strcasecmp(table[i].name, table[j].name)) { delete_entry(table, size, j); size--; j--; } return size; }
static imgtoolerr_t rsdos_diskimage_deletefile(imgtool::partition &partition, const char *fname) { imgtoolerr_t err; imgtool::image &image(partition.image()); int pos; struct rsdos_dirent ent; err = lookup_rsdos_file(image, fname, ent, &pos); if (err) return err; return delete_entry(image, ent, pos); }
static imgtoolerr_t rsdos_diskimage_deletefile(imgtool_partition *partition, const char *fname) { imgtoolerr_t err; imgtool_image *image = imgtool_partition_image(partition); int pos; struct rsdos_dirent ent; err = lookup_rsdos_file(image, fname, &ent, &pos); if (err) return err; return delete_entry(image, &ent, pos); }
void combine_entry(partition_map *entry) { partition_map *p; if (entry == NULL || strncmp(entry->data->dpme_type, kFreeType, DPISTRLEN) != 0) { return; } if (entry->next_by_base != NULL) { p = entry->next_by_base; if (strncmp(p->data->dpme_type, kFreeType, DPISTRLEN) != 0) { // next is not free } else if (entry->data->dpme_pblock_start + entry->data->dpme_pblocks != p->data->dpme_pblock_start) { // next is not contiguous (XXX this is bad) } else { entry->data->dpme_pblocks += p->data->dpme_pblocks; entry->data->dpme_lblocks = entry->data->dpme_pblocks; delete_entry(p); } } if (entry->prev_by_base != NULL) { p = entry->prev_by_base; if (strncmp(p->data->dpme_type, kFreeType, DPISTRLEN) != 0) { // previous is not free } else if (p->data->dpme_pblock_start + p->data->dpme_pblocks != entry->data->dpme_pblock_start) { // previous is not contiguous (XXX this is bad) } else { entry->data->dpme_pblock_start = p->data->dpme_pblock_start; entry->data->dpme_pblocks += p->data->dpme_pblocks; entry->data->dpme_lblocks = entry->data->dpme_pblocks; delete_entry(p); } } entry->contains_driver = contains_driver(entry); }
/** delete moment */ static void replay_moment_delete(struct replay_moment* mom) { if(!mom) return; if(mom->match) { delete_entry(mom->match); } free(mom->autotrust_id); free(mom->string); free(mom->variable); config_delstrlist(mom->file_content); free(mom); }
void stop_middleware_frontend(int sock) { if (myname[0] == '\0') { debug_out(2, "Not registered!\n"); exit(1); } if (!delete_entry(NSDB, myname)) { debug_out(2, "Failed to delete data from nameserver\n"); exit(1); } myname[0] = '\0'; close(sock); }
STATUS free_entries_and_head(entry *entry_head) { if(!entry_head) { DEBUG("free_entries_and_head-> !entry_head, OK\n"); return OK; } STATUS free_entries_status = free_entries_from_head(entry_head); if(free_entries_status != OK) { DEBUG("free_entries_and_head->free_entries_status !OK\n"); return free_entries_status; } return delete_entry(entry_head); }
int filelist138 :: delete_file(const char * path, int COMPARE_NAME) { //search for file in the filelist int find = find_file(path, COMPARE_NAME); if(find >= 0) { //delete delete_entry(files[find]); files.erase(files.begin() + find); return 1; }; return 0; };
// The scriptName is only passed so that the assert can print the name of the script // if no space could be freed up for it. void CScriptCache::remove_some_old_scripts(int space_required, uint32 scriptName) { while (true) { int largest_malloc_possible=Mem::Manager::sHandle().ScriptHeap()->LargestFreeBlock(); largest_malloc_possible-=128; // Actually, 32 seems OK, but have a bigger margin just to be sure. if (space_required <= largest_malloc_possible) { // Hurrah! It's all clear to decompress another script since we know there is enough heap to hold it. // Try to keep the total number of decompressed scripts within IDEAL_MAX_DECOMPRESSED_SCRIPTS // by removing unused ones until either enough have been removed or there are no more to remove. // This way the average memory usage can be controlled by tweaking IDEAL_MAX_DECOMPRESSED_SCRIPTS // whilst spikes in the number of scripts are still permitted up to the limit set by // the pool size of MAX_DECOMPRESSED_SCRIPTS. If that limit is reached, the code will assert. while (CScriptCacheEntry::SGetNumUsedItems() >= IDEAL_MAX_DECOMPRESSED_SCRIPTS && mp_last_zero_usage) { delete_entry(mp_last_zero_usage); } break; } // Free up some space by deleting the oldest zero-usage decompressed script. if (!mp_last_zero_usage) { // Eeeek! There's nothing left to delete ... Dbg_MsgAssert(0,("Script heap overflow when trying to allocate decompressed script '%s' of size %d bytes!",Script::FindChecksumName(scriptName),space_required)); } //printf("%d: Deleting %s from cache, new free space = %d\n",space_required,Script::FindChecksumName(mp_last_zero_usage->mScriptNameChecksum),Mem::Manager::sHandle().ScriptHeap()->LargestFreeBlock()-128); delete_entry(mp_last_zero_usage); } }
void delete_partition_from_map(partition_map *entry) { partition_map_header *map; DPME *data; if (istrncmp(entry->data->dpme_type, kMapType, DPISTRLEN) == 0) { printf("Can't delete entry for the map itself\n"); return; } if (entry->contains_driver) { printf("This program can't install drivers\n"); if (get_okay("are you sure you want to delete this driver? [n/y]: ", 0) != 1) { return; } } // if past end of disk, delete it completely if (entry->next_by_base == NULL && entry->data->dpme_pblock_start >= entry->the_map->media_size) { if (entry->contains_driver) { remove_driver(entry); // update block0 if necessary } delete_entry(entry); return; } // If at end of disk, incorporate extra disk space to partition if (entry->next_by_base == NULL) { entry->data->dpme_pblocks = entry->the_map->media_size - entry->data->dpme_pblock_start; } data = create_data(kFreeName, kFreeType, entry->data->dpme_pblock_start, entry->data->dpme_pblocks); if (data == NULL) { return; } if (entry->contains_driver) { remove_driver(entry); // update block0 if necessary } free(entry->data); free(entry->HFS_name); entry->HFS_kind = kHFS_not; entry->HFS_name = 0; entry->data = data; combine_entry(entry); map = entry->the_map; renumber_disk_addresses(map); map->changed = 1; }
STATUS free_entries_from_head(entry *entry_head) { entry *cursor = entry_head->next; while(cursor) { entry_head = cursor; cursor = cursor->next; STATUS delete_status = delete_entry(entry_head); if(delete_status != OK) { DEBUG("free_entries_from_head->delete_status !OK\n"); return delete_status; } } DEBUG("free_entries_from_head-> OK\n"); return OK; }
STATUS delete_entry_by_key(char *key, entry *entry_head) { entry *entry_ptr = find_entry_by_key(key, entry_head); if(!entry_ptr) { DEBUG("delete_entry_by_key-> !entry_ptr NO_KEY\n"); return NO_KEY; } STATUS delete_entry_status = delete_entry(entry_ptr); if(delete_entry_status != OK) { DEBUG("delete_entry_by_key->delete_entry_status !OK\n"); return delete_entry_status; } DEBUG("delete_entry_by_key-> OK\n"); return OK; }
// Needed for when a script is qbr'd. void CScriptCache::RefreshAfterReload(uint32 scriptName) { CScriptCacheEntry *p_cache_entry=mp_cache_hash_table->GetItem(scriptName); if (p_cache_entry) { // Store the old usage uint32 old_usage=p_cache_entry->mUsage; // Remove from the cache, then add it again so that it is up to date. delete_entry(p_cache_entry); GetScript(scriptName); // Put the usage value back. p_cache_entry=mp_cache_hash_table->GetItem(scriptName); Dbg_MsgAssert(p_cache_entry,("NULL p_cache_entry ?")); p_cache_entry->mUsage=old_usage; } }
/******************************************************************* * Adds entry to ARP Cache if not already in Cache. Also deletes any entries that are past * their expiration time. *******************************************************************/ void add_cache_entry(struct packet_state* ps,const uint32_t ip, const unsigned char* mac) { if(search_cache(ps, ip)==NULL) /*Entry is not already in cache so add. */ { struct arp_cache_entry* cache_walker=0; assert(ps); assert(mac); assert(ip); if(ps->sr->arp_cache ==0) /*If there are no entries in cache */ { ps->sr->arp_cache=(struct arp_cache_entry*)malloc(sizeof(struct arp_cache_entry)); assert(ps->sr->arp_cache); ps->sr->arp_cache->next=0; ps->sr->arp_cache->ip_add=ip; memmove(ps->sr->arp_cache->mac, mac,ETHER_ADDR_LEN); ps->sr->arp_cache->timenotvalid=time(NULL) +ARP_TIMEOUT; } else { cache_walker = ps->sr->arp_cache; while(cache_walker->next) { if(cache_walker->timenotvalid < time(NULL)) { cache_walker = delete_entry(ps,cache_walker); } else { cache_walker=cache_walker->next; } } cache_walker->next=(struct arp_cache_entry*)malloc(sizeof(struct arp_cache_entry)); assert(cache_walker->next); cache_walker=cache_walker->next; cache_walker->ip_add=ip; memmove(cache_walker->mac, mac,ETHER_ADDR_LEN); cache_walker->timenotvalid=time(NULL) +ARP_TIMEOUT; cache_walker->next=0; } } }