예제 #1
0
int main(){
	mf_handle_t file;
	VAC(file = mf_open(FILENAME));

	long it = 0;
	long last_ok = 0;
	for (it = 0; it < FILESIZE; it += rand() % 4096){
		mf_mapmem_handle_t loc_handle;
		void *loc_ptr = mf_map(file, 0, it, &loc_handle);
		if (loc_ptr != NULL){
			last_ok = it;
			mf_unmap(file, loc_handle);
		}
	}

	printf("Last OK: %lgGB\n", ((double)last_ok)/((double)GB));

	char *buf = malloc(SAMPLESIZE);
  	if (buf == NULL)
		return 2;
	long ret = mf_read(file, buf, SAMPLESIZE, last_ok - SAMPLESIZE);
	if (ret != SAMPLESIZE)
		return 3;
	mf_close(file);
	return 0;
}
예제 #2
0
int main(int argc, const char * argv[]) {
    errno = 0;
    mf_handle_t file = mf_open("/Users/ivanmatveev/Desktop/speech_2.pages", 0);
    printf("file:%p\n errno = %d\n", file, errno);
    size_t size_buf = 100;
    unsigned char *buf = malloc(size_buf*sizeof(char));
    if (buf == NULL) {
        printf("error\n");
        return 0;
    }
    int i;
    ssize_t ret;
    for (i = 0; i < size_buf; i++)
        buf[i] = 'a';
    errno = 0;
    if ((ret = mf_read(file, 0, size_buf, buf)) < 0){
        printf("error in read with value %zd\nerrno = %d\n", ret, errno);
        printf("%s", strerror(errno));
    } else {
        printf("ret = %zd\n", ret);
        printf("read from file:\n");
        for (i = 0; i < size_buf; i++)
            printf("0x%02x %c ", buf[i], buf[i]);
        printf("\n");
    }
    free(buf);
    return 0;
}
예제 #3
0
int ptest_1(const char* filename) {
    mf_handle_t handle = mf_open(filename);
    size_t size = (size_t)mf_file_size(handle);
    size_t bufsize = 32768;
    void *buf = malloc(bufsize);

    int counter = 1337 + 8; // number of ones (1) exists in file
    int counter1 = 1000;
    int counter2 = 300;
    int counter3 = 30;
    int counter4 = 7;
    size_t readbytes = 0;
    char current;
    for (size_t j = 0; readbytes < size; j += bufsize) {
        readbytes += (size_t)mf_read(handle, buf, bufsize, j);
//        printf("buf = %s\n", buf);
        for (int i = 0; i < bufsize; ++i) {
            current = ((char *) buf)[i];
            if (current != '9') counter--;
            if (current == '1') counter1--;
            if (current == '2') counter2--;
            if (current == '3') counter3--;
            if (current == '4') counter4--;
        }
    }
//    printf("\ntotal: %d\n1: %d\n2: %d\n3: %d\n4: %d\n", counter, counter1, counter2, counter3, counter4);
    if (counter || counter1 || counter2 || counter3 || counter4)
        return TESTFAILED;
    free(buf);
    return mf_close(handle);
}
예제 #4
0
파일: memfile.c 프로젝트: Addisonbean/vim
/*
 * Get existing block "nr" with "page_count" pages.
 *
 * Note: The caller should first check a negative nr with mf_trans_del()
 */
    bhdr_T *
mf_get(memfile_T *mfp, blocknr_T nr, int page_count)
{
    bhdr_T    *hp;
						/* doesn't exist */
    if (nr >= mfp->mf_blocknr_max || nr <= mfp->mf_blocknr_min)
	return NULL;

    /*
     * see if it is in the cache
     */
    hp = mf_find_hash(mfp, nr);
    if (hp == NULL)	/* not in the hash list */
    {
	if (nr < 0 || nr >= mfp->mf_infile_count)   /* can't be in the file */
	    return NULL;

	/* could check here if the block is in the free list */

	/*
	 * Check if we need to flush an existing block.
	 * If so, use that block.
	 * If not, allocate a new block.
	 */
	hp = mf_release(mfp, page_count);
	if (hp == NULL && (hp = mf_alloc_bhdr(mfp, page_count)) == NULL)
	    return NULL;

	hp->bh_bnum = nr;
	hp->bh_flags = 0;
	hp->bh_page_count = page_count;
	if (mf_read(mfp, hp) == FAIL)	    /* cannot read the block! */
	{
	    mf_free_bhdr(hp);
	    return NULL;
	}
    }
    else
    {
	mf_rem_used(mfp, hp);	/* remove from list, insert in front below */
	mf_rem_hash(mfp, hp);
    }

    hp->bh_flags |= BH_LOCKED;
    mf_ins_used(mfp, hp);	/* put in front of used list */
    mf_ins_hash(mfp, hp);	/* put in front of hash list */

    return hp;
}
예제 #5
0
int main(){
	//printf("1erwerwer\n");
	mf_handle_t mf = mf_open("test");
	//printf("2\n");
	char buf[20	] = "1111";
	mf_write(mf, buf, 4, 3);
	//printf("3\n");
	mf_read(mf, buf, 10, 1);
	//printf("4\n");
	printf("%s\n %d\n", buf, (int)mf_file_size(mf));
	//printf("%d\n", 40*1024*(1024*1024/sysconf(_SC_PAGE_SIZE)));
	
	mf_close(mf);
	//printf("5\n");
	return 0;
}