static void cachedev_initialize (struct cache_if *c, void (**issuefunc)(void *,ioreq_event *), void *issueparam, struct ioq * (**queuefind)(void *,int), void *queuefindparam, void (**wakeupfunc)(void *, struct cacheevent *), void *wakeupparam, int numdevs) { struct cache_dev *cache = (struct cache_dev *)c; StaticAssert (sizeof(struct cache_dev_event) <= DISKSIM_EVENT_SIZE); #ifdef DEBUG_CACHEDEV fprintf (outputfile, "*** %f: Entered cachedev::cachedev_initialize\n", simtime ); #endif cache->issuefunc = issuefunc; cache->issueparam = issueparam; cache->queuefind = queuefind; cache->queuefindparam = queuefindparam; cache->wakeupfunc = wakeupfunc; cache->wakeupparam = wakeupparam; cache->bufferspace = 0; cache->ongoing_requests = NULL; bzero (cache->validmap, bitstr_size(cache->size)); bzero (cache->dirtymap, bitstr_size(cache->size)); cachedev_resetstats(c); if (cache->flush_idledelay > 0.0) { struct ioq *queue = (*queuefind)(queuefindparam,cache->real_devno); ASSERT (queue != NULL); ioqueue_set_idlework_function (queue, &disksim->idlework_cachedev, cache, cache->flush_idledelay); } if (device_get_number_of_blocks(cache->cache_devno) < cache->size) { fprintf (stderr, "Size of cachedev exceeds that of actual cache device (devno %d): %d > %d\n", cache->cache_devno, cache->size, device_get_number_of_blocks(cache->cache_devno)); ddbg_assert(0); } }
void ip_initid(void) { mtx_init(&id_mtx, "ip id", NULL, 0); array_ptr = 0; size_t bits_sz = bitstr_size(65536); id_array = (u_int16_t *) malloc(array_size * sizeof(u_int16_t)); bzero(id_array, array_size * sizeof(u_int16_t)); id_bits = (bitstr_t *) malloc(bits_sz); bzero(id_bits, bits_sz); }
static TEE_Result maybe_grow_files(struct tee_fs_dirfile_dirh *dirh, int idx) { void *p; if (idx < dirh->nbits) return TEE_SUCCESS; p = realloc(dirh->files, bitstr_size(idx + 1)); if (!p) return TEE_ERROR_OUT_OF_MEMORY; dirh->files = p; bit_nclear(dirh->files, dirh->nbits, idx); dirh->nbits = idx + 1; return TEE_SUCCESS; }
int32_t kbd_process_keys(bthid_session_p s) { bitstr_t diff[bitstr_size(xsize)]; int32_t f1, f2, i; assert(s != NULL); assert(s->srv != NULL); /* Check if the new keys have been pressed */ bit_ffs(s->keys1, xsize, &f1); /* Check if old keys still pressed */ bit_ffs(s->keys2, xsize, &f2); if (f1 == -1) { /* no new key pressed */ if (f2 != -1) { /* release old keys */ kbd_write(s->keys2, f2, 0, s->vkbd); memset(s->keys2, 0, bitstr_size(xsize)); } return (0); } if (f2 == -1) { /* no old keys, but new keys pressed */ assert(f1 != -1); memcpy(s->keys2, s->keys1, bitstr_size(xsize)); kbd_write(s->keys1, f1, 1, s->vkbd); memset(s->keys1, 0, bitstr_size(xsize)); return (0); } /* new keys got pressed, old keys got released */ memset(diff, 0, bitstr_size(xsize)); for (i = f2; i < xsize; i ++) { if (bit_test(s->keys2, i)) { if (!bit_test(s->keys1, i)) { bit_clear(s->keys2, i); bit_set(diff, i); } } } for (i = f1; i < xsize; i++) { if (bit_test(s->keys1, i)) { if (!bit_test(s->keys2, i)) bit_set(s->keys2, i); else bit_clear(s->keys1, i); } } bit_ffs(diff, xsize, &f2); if (f2 > 0) kbd_write(diff, f2, 0, s->vkbd); bit_ffs(s->keys1, xsize, &f1); if (f1 > 0) { kbd_write(s->keys1, f1, 1, s->vkbd); memset(s->keys1, 0, bitstr_size(xsize)); } return (0); }
static void DISKSIM_CACHEDEV_CACHE_SIZE_loader(struct cache_dev * result, int i) { if (! (i >= 0)) { // foo } if(result->validmap || result->dirtymap) { fprintf(stderr, "*** ignoring repeat cache size definition.\n"); } else { result->size = i; result->validmap = (bitstr_t *) DISKSIM_malloc(bitstr_size(result->size)); result->dirtymap = (bitstr_t *) DISKSIM_malloc(bitstr_size(result->size)); ASSERT ((result->validmap != NULL) && (result->dirtymap != NULL)); } }
int write_file_to_disk(int fd, struct cf_t *file, time_t time_date) /* write the data on the disk */ { cl_t *line = NULL; env_t *env = NULL; char write_buf[WRITE_BUF_LEN]; int write_buf_used = 0; /* put program's version : it permits to daemon not to load * a file which he won't understand the syntax, for exemple * a file using a depreciated format generated by an old fcrontab, * if the syntax has changed */ /* an binary fcrontab *must* start by such a header */ Save_lint(fd, S_HEADER_T, S_FILEVERSION, write_buf, &write_buf_used); /* put the user's name : needed to check if his uid has not changed */ /* S_USER_T *must* be the 2nd field of a binary fcrontab */ Save_str(fd, S_USER_T, file->cf_user, write_buf, &write_buf_used); /* put the time & date of saving : this is use for calcutating * the system down time. As it is a new file, we set it to 0 */ /* S_USER_T *must* be the 3rd field of a binary fcrontab */ Save_lint(fd, S_TIMEDATE_T, time_date, write_buf, &write_buf_used); /* Save the time diff between local (real) and system hour (if any) */ if ( file->cf_tzdiff != 0 ) Save_lint(fd, S_TZDIFF_T, file->cf_tzdiff, write_buf, &write_buf_used); /* env variables, */ for (env = file->cf_env_base; env; env = env->e_next) Save_str(fd, S_ENVVAR_T, env->e_val, write_buf, &write_buf_used); /* then, lines. */ for (line = file->cf_line_base; line; line = line->cl_next) { /* this ones are saved for every lines */ Save_str(fd, S_SHELL_T, line->cl_shell, write_buf, &write_buf_used); Save_str(fd, S_RUNAS_T, line->cl_runas, write_buf, &write_buf_used); Save_str(fd, S_MAILTO_T, line->cl_mailto, write_buf, &write_buf_used); Save_strn(fd, S_OPTION_T, (char *)line->cl_option, OPTION_SIZE, (char *)write_buf, &write_buf_used); /* the following are saved only if needed */ if ( is_volatile(line->cl_option) && is_freq(line->cl_option) ) { Save_lint(fd, S_FIRST_T, line->cl_first, write_buf, &write_buf_used); } else Save_lint(fd, S_NEXTEXE_T, line->cl_nextexe, write_buf, &write_buf_used); if ( line->cl_numexe ) Save_strn(fd, S_NUMEXE_T, (char *)&line->cl_numexe, 1, (char *)write_buf, &write_buf_used); if ( is_lavg(line->cl_option) ) Save_strn(fd, S_LAVG_T, (char *)line->cl_lavg, LAVG_SIZE, (char *)write_buf, &write_buf_used); if ( line->cl_until > 0 ) Save_lint(fd, S_UNTIL_T, line->cl_until, write_buf, &write_buf_used); if ( line->cl_nice != 0 ) Save_strn(fd, S_NICE_T, &line->cl_nice, 1, write_buf, &write_buf_used); if ( line->cl_runfreq > 0 ) { Save_lint(fd, S_RUNFREQ_T, line->cl_runfreq, write_buf, &write_buf_used); Save_lint(fd, S_REMAIN_T, line->cl_remain, write_buf, &write_buf_used); } if ( is_freq(line->cl_option) ) { /* save the frequency to run the line */ Save_lint(fd, S_TIMEFREQ_T, line->cl_timefreq, write_buf, &write_buf_used); } else { /* save the time and date bit fields */ Save_strn(fd, S_MINS_T, (char *)line->cl_mins, bitstr_size(60), (char *)write_buf, &write_buf_used); Save_strn(fd, S_HRS_T, (char *)line->cl_hrs, bitstr_size(24), (char *)write_buf, &write_buf_used); Save_strn(fd, S_DAYS_T, (char *)line->cl_days, bitstr_size(32), (char *)write_buf, &write_buf_used); Save_strn(fd, S_MONS_T, (char *)line->cl_mons, bitstr_size(12), (char *)write_buf, &write_buf_used); Save_strn(fd, S_DOW_T, (char *)line->cl_dow, bitstr_size(8), (char *)write_buf, &write_buf_used); } /* This field *must* be the last of each line */ Save_type(fd, S_ENDLINE_T, write_buf, &write_buf_used); } if ( write_buf_to_disk(fd, write_buf, &write_buf_used) == ERR ) return ERR; return OK; }