void mmap (struct intr_frame *f) { int fd = *value_stack_int(f->esp,4); //void * addr = *(void **)value_stack(f->esp,8); void * addr = *(void **)(f->esp + 8); if (!is_user_vaddr(addr) ) exit_mythread(-1); //fd 0 and 1 are not allowed ... MISSING PAGE ALIGN if(fd == 1 || fd == 0 || addr == 0 || (unsigned int)addr % PGSIZE != 0 ) { f->eax = -1; return ; } struct filed * file = find_file(fd); if ( file == NULL ) { exit_mythread(-1); } struct file * mfile = file_reopen(file->file); //get the file from the threads file table if ( mfile == NULL ) { exit_mythread(-1); } int size = file_length(mfile); //get the number of pages we need for the file int numberpages = size/PGSIZE; if (file_length(mfile) % PGSIZE != 0) numberpages += 1; //check if the virtual memory pages are free int i; for (i = 0; i < numberpages;i++) { if (page_lookup(addr + i*PGSIZE, thread_current()) != NULL) { file_close(mfile); f->eax=-1; return ; } } //add to filetable fd = add_filemmap(mfile,addr); off_t length = 0; //add the pages to the supplemental page table for (i = 0; i < numberpages; i++) { if (size >= PGSIZE) length = PGSIZE; else length = size; page_add_mmap (addr + i*PGSIZE, (off_t *) (i*PGSIZE),true,fd,length,i*PGSIZE); size -= length; } f->eax = fd; }
void cncEnvIn(int argc, char **argv, Context *context) { CNC_REQUIRE(argc == 5, "Usage: %s fileName1 fileName2 tileWidth tileHeight\n", argv[0]); // Open sequence input files FILE *file1 = open_file(argv[1]); FILE *file2 = open_file(argv[2]); size_t filesize1 = file_length(file1); size_t filesize2 = file_length(file2); // Allocate tile data item and read sequence data SeqData *data; size_t dataSize = sizeof(SeqData) + filesize1 + filesize2 + 2; cncHandle_t dataHandle = cncCreateItemSized_data(&data, dataSize); data->seq2offset = filesize1 + 1; size_t length1 = read_sequence(file1, 1, SEQ1(data), filesize1); size_t length2 = read_sequence(file2, 2, SEQ2(data), filesize2); // Tile width and height int tw = atoi(argv[3]); int th = atoi(argv[4]); PRINTF("Tile width: %d\n", tw); PRINTF("Tile height: %d\n", th); CNC_REQUIRE(tw <= length1 && th <= length2, "Tile size too large for given input.\n"); // Number of tiles wide and high int ntw = length1 / tw; int nth = length2 / th; PRINTF("Imported %d x %d tiles.\n", ntw, nth); // Initialize tile dimension data and put data->tw = tw; data->th = th; data->ntw = ntw; data->nth = nth; memcpy(data->score_matrix, ALIGNMENT_SCORES, sizeof(ALIGNMENT_SCORES)); cncPut_data(dataHandle, 0, context); // Record starting time struct timeval *startTime; cncHandle_t startTime_handle = cncCreateItem_startTime(&startTime, 1); gettimeofday(startTime, 0); cncPut_startTime(startTime_handle, 0, context); // Seed edges cncPrescribe_initAboveStep(tw, ntw, context); cncPrescribe_initLeftStep(th, nth, context); int i, j; for(i = 0; i < nth; i++){ for(j = 0; j < ntw; j++){ cncPrescribe_swStep(i, j, context); } } cncPrescribe_cncEnvOut(ntw, nth, tw, context); }
static void vorbis_quality_test (void) { /* ** Encode two files, one at quality 0.3 and one at quality 0.5 and then ** make sure that the quality 0.3 files is the smaller of the two. */ const char * q3_fname = "q3_vorbis.oga" ; const char * q5_fname = "q5_vorbis.oga" ; SNDFILE *q3_file, *q5_file ; SF_INFO sfinfo ; int q3_size, q5_size ; double quality ; int k ; print_test_name (__func__, "q[35]_vorbis.oga") ; memset (&sfinfo, 0, sizeof (sfinfo)) ; /* Set up output file type. */ sfinfo.format = SF_FORMAT_OGG | SF_FORMAT_VORBIS ; sfinfo.channels = 1 ; sfinfo.samplerate = SAMPLE_RATE ; /* Write the output file. */ q3_file = test_open_file_or_die (q3_fname, SFM_WRITE, &sfinfo, SF_FALSE, __LINE__) ; q5_file = test_open_file_or_die (q5_fname, SFM_WRITE, &sfinfo, SF_FALSE, __LINE__) ; quality = 0.3 ; sf_command (q3_file, SFC_SET_VBR_ENCODING_QUALITY, &quality, sizeof (quality)) ; quality = 0.5 ; sf_command (q5_file, SFC_SET_VBR_ENCODING_QUALITY, &quality, sizeof (quality)) ; for (k = 0 ; k < 5 ; k++) { gen_lowpass_noise_float (data_out, ARRAY_LEN (data_out)) ; test_write_float_or_die (q3_file, 0, data_out, ARRAY_LEN (data_out), __LINE__) ; test_write_float_or_die (q5_file, 0, data_out, ARRAY_LEN (data_out), __LINE__) ; } ; sf_close (q3_file) ; sf_close (q5_file) ; q3_size = file_length (q3_fname) ; q5_size = file_length (q5_fname) ; if (q3_size >= q5_size) { printf ("\n\nLine %d : q3 size (%d) >= q5 size (%d)\n\n", __LINE__, q3_size, q5_size) ; exit (1) ; } ; puts ("ok") ; unlink (q3_fname) ; unlink (q5_fname) ; } /* vorbis_quality_test */
int Ctbg::AddOtherFile(int pos, CString &newname) { iapfileheaders[pos+iapheader.tbgcount].filelength=file_length(m_othernames[pos]); if(iapfileheaders[pos+iapheader.tbgcount].filelength<1) return -2; newname=m_othernames[pos].Mid(bgfolder.GetLength()); return 0; }
/* * System Call: mapid_t mmap (int fd, void *addr) * Maps the file open as fd into the process's virtual address space. * The entire file is mapped into consecutive virtual pages starting * at addr. */ mapid_t mmap_handler (int fd, void *addr){ if(addr==NULL) return -1; if(pg_ofs(addr) != 0) return -1; if(fd<2) return -1; struct file *f_,*f; lock_acquire (&fic_m); f_ = findfd(fd); if(f_== NULL) { lock_release (&fic_m); return -1; } f = file_reopen(f_); lock_release (&fic_m); lock_acquire (&fic_m); int32_t size_f = file_length(f); lock_release (&fic_m); if (size_f == 0) return -1; if (addr+size_f>=thread_current()->saved_esp) return -1; if(validate_mapping(addr, size_f)){ size_t page_num = size_f/PGSIZE + 1; int ret = addfmap (f, addr, page_num, size_f); return ret; } return -1; }
void main() { int CurveLength = file_length(BalanceFile)/sizeof(var); var *Balances = file_content(BalanceFile); int M = CurveLength - DrawDownDays + 1; int T = TradeDays - DrawDownDays + 1; if(T < 1 || M <= T) { printf("Not enough samples!"); return; } var GMin=0, N=0; int i = 0; for(; i < M; i++) { var G = Balances[i+DrawDownDays-1] - Balances[i]; if(G <= -DrawDown) N += 1.; if(G < GMin) GMin = G; } var P; if(TradeDays > DrawDownDays) P = 1. - exp(logsum(M-N)+logsum(M-T)-logsum(M)-logsum(M-N-T)); else P = N/M; printf("\nTest period: %i days",CurveLength); printf("\nWorst test drawdown: %.f",-GMin); printf("\nM: %i N: %i T: %i",M,(int)N,T); printf("\nCold Blood Index: %.1f%%",100*P); }
static int sys_filesize(int fd) { struct thread *curr = thread_current(); struct opened_file_elem *opened_elem; struct list_elem *e; int check_valid=0; if(fd<2) return -1; for( e = list_begin(&curr->openfile_list) ; e != list_end(&curr->openfile_list) ; e = list_next(e) ) { opened_elem=list_entry(e,struct opened_file_elem,elem_f); if(opened_elem->fd==fd) { check_valid=1; return file_length(opened_elem->opened_file); } } if(check_valid==0) return -1; }
static int filesize_handler (int fd) { struct file_struct * file_sizing; int size; file_sizing = get_file(fd); size = file_length(file_sizing->sys_file); return size; }
/** * Read a file * @param file the path to the file * @param flen update with the length of the file * @return NULL on failure else the allocated text content */ static char *read_file( char *file, size_t *flen ) { char *data = NULL; FILE *fp = fopen( file, "r" ); if ( fp != NULL ) { int len = file_length( fp ); data = (char*)malloc( len+1 ); if ( data != NULL ) { int read = fread( data, 1, len, fp ); if ( read != len ) { fprintf(stderr,"failed to read %s\n",file); free( data ); data = NULL; *flen = 0; } else { data[len] = 0; *flen = len; } } else fprintf(stderr,"failed to allocate file buffer\n"); fclose( fp ); } return data; }
iridium_method(File, each_line) { object self = local(self); object filename = local(filename); // From self object fn = local(fn); object str = NULL; FILE * f = get_file(context, self); size_t file_size = file_length(context, f, filename); char * buffer = GC_MALLOC((file_size+1)*sizeof(char)); assert(buffer); int nchars; char * line = NULL; while ((nchars = getline(&buffer, &file_size, f)) != -1) { // Remove the newline, if present if (buffer[nchars-1] == '\n') { buffer[nchars-1] = 0; } line = GC_MALLOC((nchars + 1) * sizeof(char)); assert(line); strncpy(line, buffer, nchars); str = IR_STRING(line); calls(context, fn, array_push(array_new(), str)); } return NIL; }
int filespec_init(struct filespec *fs, const char *name, const char *mode) { /* set name and directory subfield of the directory */ filespec_setname_and_dir(fs, name); fs->file = fopen(name, mode); if (!fs->file) { fprintf(stderr, "%s: file doesn't exists.\n", name); clean_on_error(fs); /* remove the memory allocated */ exit(EXIT_FAILURE); return -1; } if (filespec_stat(fs, name) == -1) { clean_on_error(fs); return -1; } fs->last_modified = fs->st.st_mtime; fs->length = file_length(fs->file); /* postpone the file caching until call to filespec read takes place */ filecache_init(&fs->cache); fs->cached = 0; return 0; }
static int syscall_filesize(int fd) { struct file *f = file_find(fd); if(f == NULL) return -1; else return (int)file_length(f); }
/* Return file size */ int filesize(int fd) { struct thread* t = thread_current(); struct file* f = t->file_desc_table[fd]; if( f == NULL ) return (int)-1; else return (int)file_length(f); }
int filesize (int fd) { struct file *f = process_get_file (fd); if (!f) return -1; return file_length(f); }
static void sys_filesize(struct intr_frame *f_) { unsigned int *esp = f_->esp; int fd = *(esp + 1); struct file *f = file_search_in_fd(fd); if (f == NULL) f_->eax = -1; else f_->eax = file_length(f); }
int filesize (int fd) { lock_acquire(&file_lock); struct file *file = get_file(fd); int result = file ? file_length(file) : -1; lock_release(&file_lock); return result; }
/* Syscall handler for when a syscall filesize is invoked. */ static int filesize (int fd) { struct file_wrapper *curr = fd_to_file_wrapper(fd); if (!curr) exit(-1); lock_acquire(&file_lock); int size = file_length (curr->file); lock_release(&file_lock); return size; }
static int syscall_filesize (int fd) { struct file_with_lock fwl = fwl_from_fd (fm, fd); if (fwl.lock == NULL || fwl.mode == FM_MODE_MMAP) return -1; lock_acquire (fwl.lock); int retval = file_length (fwl.fp); lock_release (fwl.lock); return retval; }
int sys_filesize(int fd) { struct file* file = map_find(get_filemap(), fd); if (file != NULL) return file_length(file); return -1; }
Tail * tail_open (const char *path, const char *name, TrieIOMode mode) { Tail *t; TrieIndex i; uint16 sig; long file_size; t = (Tail *) malloc (sizeof (Tail)); t->file = file_open (path, name, ".tl", mode); if (!t->file) goto exit1; file_size = file_length (t->file); if (file_size != 0 && file_read_int16 (t->file, (int16 *) &sig) && sig != TAIL_SIGNATURE) { goto exit2; } /* init tails data */ if (file_size == 0) { t->first_free = 0; t->num_tails = 0; t->tails = NULL; t->is_dirty = TRUE; } else { file_read_int16 (t->file, &t->first_free); file_read_int16 (t->file, &t->num_tails); t->tails = (TailBlock *) malloc (t->num_tails * sizeof (TailBlock)); if (!t->tails) goto exit2; for (i = 0; i < t->num_tails; i++) { int8 length; file_read_int16 (t->file, &t->tails[i].next_free); file_read_int16 (t->file, &t->tails[i].data); file_read_int8 (t->file, &length); t->tails[i].suffix = (TrieChar *) malloc (length + 1); if (length > 0) file_read_chars (t->file, (char *)t->tails[i].suffix, length); t->tails[i].suffix[length] = '\0'; } t->is_dirty = FALSE; } return t; exit2: fclose (t->file); exit1: free (t); return NULL; }
int syscall_filesize(int fd) { // 0. Find fd. struct fd_list *found = Search_FD(&(thread_current()->FDs), fd); // 1. Call file_length(); lock_acquire(&(found->file->inode->lock)); int ret = file_length(found->file); lock_release(&(found->file->inode->lock)); return ret; }
void cache_object_add_file(struct cache_object *co, FILE *f) { size_t len = file_length(f); struct strbuf buf = STRBUF_INIT; if (strbuf_fread(&buf, len, f) < len) die("unable to read file\n"); cache_object_add(co, &buf); strbuf_release(&buf); }
/* Filesize system call. */ static int sys_filesize (int handle) { struct file_descriptor *fd = lookup_file_fd (handle); int size; size = file_length (fd->file); return size; }
void munmap (struct intr_frame *f) { int fd = *value_stack_int(f->esp,4); struct filed * filed = find_file(fd); //get the number of pages we need for the file int numberpages = file_length(filed->file)/PGSIZE; if (file_length(filed->file) % PGSIZE != 0) numberpages += 1; int i; for (i = 0;i < numberpages; i++) { //remove the pages from the supplemental page table page_remove (filed->vaddr + i * PGSIZE); } file_close(filed->file); list_remove(&filed->filed); free(filed); }
void st_rewind (st_parameter_filepos *fpp) { gfc_unit *u; library_start (&fpp->common); u = find_unit (fpp->common.unit); if (u != NULL) { if (u->flags.access == ACCESS_DIRECT) generate_error (&fpp->common, LIBERROR_BAD_OPTION, "Cannot REWIND a file opened for DIRECT access"); else { /* If there are previously written bytes from a write with ADVANCE="no", add a record marker before performing the ENDFILE. */ if (u->previous_nonadvancing_write) finish_last_advance_record (u); u->previous_nonadvancing_write = 0; fbuf_reset (u); u->last_record = 0; if (sseek (u->s, 0, SEEK_SET) < 0) generate_error (&fpp->common, LIBERROR_OS, NULL); /* Handle special files like /dev/null differently. */ if (!is_special (u->s)) { /* We are rewinding so we are not at the end. */ u->endfile = NO_ENDFILE; } else { /* Set this for compatibilty with g77 for /dev/null. */ if (file_length (u->s) == 0 && stell (u->s) == 0) u->endfile = AT_ENDFILE; /* Future refinements on special files can go here. */ } u->current_record = 0; u->strm_pos = 1; u->read_bad = 0; } /* Update position for INQUIRE. */ u->flags.position = POSITION_REWIND; unlock_unit (u); } library_end (); }
/* * System Call: int filesize (int fd) * Returns the size, in bytes, of the file open as fd. */ int filesize_handler(int fd) { //printf("sizing...\n"); lock_acquire (&fic_m); struct file* f = findfd(fd); if(f!=NULL){ int ret = file_length(f); lock_release (&fic_m); return ret; } lock_release (&fic_m); return -1; }
/* Filesize system call. */ static int sys_filesize (int handle) { struct file_descriptor *fd = lookup_fd (handle); int size; lock_acquire (&fs_lock); size = file_length (fd->file); lock_release (&fs_lock); return size; }
int filesize (int fd) { //Fail if file is not open struct file_info* f = get_file(fd); if (!f) return -1; //Do filesys call lock_acquire(&file_lock); int ret = file_length(f->file); lock_release(&file_lock); return ret; }
/* Returns size, in bytes, of file open as 'fd'. */ static int sys_filesize(int fd) { check_fd(fd); lock_acquire(&secure_file); struct file *f = get_file(fd); int length = file_length(f); lock_release(&secure_file); return length; }
/*! Get the file size give a fd. */ int filesize(uint32_t fd) { /* Find the fd in this process */ struct f_info* f = findfile(fd); /* Find the size of the file */ lock_acquire(&filesys_lock); int size = (int) file_length(f->f); lock_release(&filesys_lock); return size; }