Exemplo n.º 1
0
void File_caract::generate_caracteristics_from_file(File_caract base_file)
{
    if(file_open(write_mode) != ERROR)
    {
        go_to_origin();
        if(base_file.file_open(read_mode) != ERROR)
        {
            int ID, i =0;
            caract_t caracteristics;
            unsigned int nb_caracts = 0;

            base_file.go_to_origin();

            do
            {
                ID = base_file.get_id();
                i = base_file.get_rects(caracteristics);

                if(i == 0)
                {
                    fprintf(get_file_id(), "<ID> %d <\\ID> ", ID);
                    set_rects(caracteristics);
                    fprintf(get_file_id(), "<D> %03d %07.1f %07.1f %07.1f %07.1f %05.3f <\\D> \n", 0, 0.f, 0.f, 0.f, 0.f, 0.f);
                    nb_caracts++;
                }
            }
            while(i == 0);

            set_nb_caract(nb_caracts);

            base_file.file_close();
        }
        file_close();
    }
}
Exemplo n.º 2
0
Arquivo: fsname.cpp Projeto: alimy/tfs
 string FSName::to_string()
 {
   char buffer[256];
   snprintf(buffer, 256, "block_id: %"PRI64_PREFIX"u, file_id: %"PRI64_PREFIX"u, seq_id: %u, suffix: %u, name: %s",
            get_block_id(), get_file_id(), get_seq_id(), get_suffix(), get_name());
   return string(buffer);
 }
Exemplo n.º 3
0
void
slab_free(const char *file, unsigned int line, void *ptr)
{
    alloc_header_t *hdr;
    size_t user, real;

    if (!ptr)
        return;
    verify(ptr);
    hdr = (alloc_header_t*)ptr - 1;
#if SLAB_DEBUG & SLAB_DEBUG_HEADER
    hdr->file_id = get_file_id(file);
    hdr->line = line;
    hdr->magic = FREE_MAGIC;
    user = hdr->size;
#else
    user = *hdr;
    (void)file; (void)line;
#endif
    real = (user + sizeof(*hdr) + SLAB_GRAIN - 1) & ~(SLAB_GRAIN - 1);
    if (real < SMALL_CUTOFF) {
        memset(hdr + 1, 0xde, real - sizeof(*hdr));
        slab_unalloc(hdr, real);
        slab_alloc_count--;
        slab_alloc_size -= user;
    } else {
        munmap(hdr, slab_round_up(real));
        big_alloc_count--;
        big_alloc_size -= user;
        slab_log_unmap(hdr);
    }
}
Exemplo n.º 4
0
void *
slab_malloc(const char *file, unsigned int line, size_t size)
{
    alloc_header_t *res;
    size_t real;

    assert(size < 1 << 24);
    real = (size + sizeof(*res) + SLAB_GRAIN - 1) & ~(SLAB_GRAIN - 1);
    if (real < SMALL_CUTOFF) {
        res = slab_alloc(slabset_create(real));
        slab_alloc_count++;
        slab_alloc_size += size;
    } else {
        res = slab_map(slab_round_up(real));
        big_alloc_count++;
        big_alloc_size += size;
        slab_log_alloc(res, size);
    }
#if SLAB_DEBUG & SLAB_DEBUG_HEADER
    res->file_id = get_file_id(file);
    res->size = size;
    res->line = line;
    res->magic = ALLOC_MAGIC;
#else
    *res = size;
    (void)file; (void)line;
#endif
    return res + 1;
}
Exemplo n.º 5
0
void *
x3_realloc(const char *file, unsigned int line, void *ptr, size_t size)
{
    struct alloc_header *block, *newblock;

    if (!ptr)
        return x3_malloc(file, line, size);

    verify(ptr);
    block = (struct alloc_header *)ptr - 1;

    if (block->size >= size)
        return block + 1;

    newblock = malloc(sizeof(*newblock) + size + sizeof(redzone));
    assert(newblock != NULL);
    memset(newblock, 0, sizeof(*newblock));
    memcpy(newblock + 1, block + 1, block->size);
    memset((char*)(newblock + 1) + block->size, 0, size - block->size);
    memcpy((char*)(newblock + 1) + size, redzone, sizeof(redzone));
    newblock->file_id = get_file_id(file);
    newblock->line = line;
    newblock->size = size;
    newblock->magic = ALLOC_MAGIC;
    alloc_count++;
    alloc_size += size;

    x3_free(file, line, block + 1);

    return newblock + 1;
}
Exemplo n.º 6
0
/**
 * Says whether a file is in already in the cache or not
 * @param database is the structure that contains everything that is
 *        related to the database (it's connexion for instance).
 * @param meta is the file's metadata that we want to know if it's already
 *        in the cache.
 * @returns a boolean that says TRUE if the file is already in the cache
 *          and FALSE if not.
 */
gboolean is_file_in_cache(db_t *database, meta_data_t *meta)
{
    file_row_t *row = NULL;

    if (meta != NULL && database != NULL)
        {

            row = get_file_id(database, meta);

            if (row != NULL)
                {
                    if (row->nb_row == 0) /* No row has been returned. It means that the file isn't in the cache */
                        {
                            free_file_row_t(row);
                            return FALSE;
                        }
                    else
                        { /* At least one row has been returned */
                            free_file_row_t(row);
                            return TRUE;
                        }
                }
            else
                {
                    return FALSE;
                }
        }
    else
        {
            return FALSE;
        }
}
Exemplo n.º 7
0
int open_file(char *filename)
{
    int value = read_tarfs_file(filename, (char *) binary_start,
            (char *) binary_end);
    if (value == 0)
    {
        return -1;
    }
    int id = get_file_id();
    if (id == -1)
    {
        return -1;
    }
    struct file_info file_info = file_info_arr[id];
    file_info.file_start = -1;
    file_info.file_current = -1;
    file_info.end_of_file = 0;
    uint64_t address = get_address_file(filename, (char *) binary_start,
            (char*) binary_end);
    if (address != 0)
    {
        file_info.file_start = address;
        file_info.end_of_file = 0;
        file_info.file_current = address;
        file_info_arr[id] = file_info;
        return id;
    }
    else
    {
        return -1;
    }
}
Exemplo n.º 8
0
void File_caract::compute_variances()
{
    if(file_open(read_update_mode) != ERROR)
    {
        int eof, count_image;
        float sum, scare_sum, variance, mean, mini, maxi;
        fpos_t position1, position2;

        rewind(get_file_id());
        do
        {
            eof = go_to_data();
            if(eof != ERROR)
            {
                fgetpos (get_file_id(), &position1);
                fscanf(get_file_id(), "%d %f %f %f %f %f <\\D>", &count_image, &mini, &maxi, &sum, &scare_sum, &variance);
                fgetpos (get_file_id(), &position2);

                mean = sum / (float)count_image;
                variance = scare_sum - mean*mean;
                variance = variance >= 0 ? sqrtf(variance) : VARIANCE_ERROR;

                fsetpos (get_file_id(), &position1);
                fprintf(get_file_id(), " %03d %07.1f %07.1f %07.1f %07.1f %05.1f", count_image, mini, maxi, sum, scare_sum, variance);
                fsetpos (get_file_id(), &position2);
            }
        }
        while(eof != ERROR);

        file_close();
    }
}
Exemplo n.º 9
0
void File_caract::generate_caracteristics_45d(int x, int y, int length, int height, unsigned int &nb_caracts)
{
    /*
        L
          --
       -- -- -- H
    xy -- --
       --
    */
    if((x + length + height - 2 <= INIT_SIZE) && (y - length + 1 >= 0) && (y + height - 1 <= INIT_SIZE))
    {
        unsigned int nb_caract, nb_rectangle;

         for(nb_caract = 0; nb_caract < all_caract_type.size(); nb_caract++)
        {
            fprintf(get_file_id(), "<ID> %u <\\ID> ", nb_caract+10);
            for(nb_rectangle = 0; nb_rectangle < all_caract_type[nb_caract].nb_rect; nb_rectangle++)
            {
                fprintf(get_file_id(), "<R> ");
                if(nb_rectangle == 0)
                    fprintf(get_file_id(), "%d %d %d %d %d ", x, y, length, height, FIRST_RECT_WIEGHT);
                else
                {
                    define_caract_t define_caract = all_caract_type[nb_caract];
                    define_rect_caract_t rect_caract = define_caract.caract[nb_rectangle - 1];

                    int temp_length = length / rect_caract.length_factor;
                    int temp_hieght = height / rect_caract.height_factor;
                    int temp_x = x;
                    int temp_y = y;

                    if(rect_caract.offset_x != SAME_POSITION)
                    {
                        temp_x += length / rect_caract.offset_x;
                        temp_y -= length / rect_caract.offset_x;
                    }

                    if(rect_caract.offset_y != SAME_POSITION)
                    {
                        temp_y += height / rect_caract.offset_y;
                        temp_x += height / rect_caract.offset_y;
                    }

                    fprintf(get_file_id(), "%d %d %d %d %d ", temp_x, temp_y, temp_length, temp_hieght, rect_caract.wieght);
                }
                fprintf(get_file_id(), "<\\R> ");
            }
            fprintf(get_file_id(), "<D> ");
            fprintf(get_file_id(), "%03d %07.1f %07.1f %07.1f %07.1f %05.3f", 0, 0., 0., 0., 0., 0.);//count image, sum, scare_sum, variance
            fprintf(get_file_id(), " <\\D> \n");

            nb_caracts++;
        }
    }
}
Exemplo n.º 10
0
/**
 * 获取db_file_info
 */
db_file_info*
get_file_info(char *fileName, char *dirName, char *diskName){

	//获取磁盘ID
	char *file_id = (char *) malloc(MAX_BUF_SIZE);
	file_id = get_file_id(fileName, dirName, diskName);
	free_result();

	//采用orm获取file_info
	db_file_info *file_info;
	file_info = db_file_info__new();
	file_info = db_file_info__get_by_id(atoi(file_id));

    return file_info;
}
Exemplo n.º 11
0
int global_cached_io::preload(off_t start, long size) {
	if (size > cache_size) {
		fprintf(stderr, "we can't preload data larger than the cache size\n");
		exit(1);
	}

	assert(ROUND_PAGE(start) == start);
	for (long offset = start; offset < start + size; offset += PAGE_SIZE) {
		page_id_t pg_id(get_file_id(), ROUND_PAGE(offset));
		page_id_t old_id;
		thread_safe_page *p = (thread_safe_page *) (get_global_cache()->search(
					pg_id, old_id));
		// This is mainly for testing. I don't need to really read data from disks.
		if (!p->data_ready()) {
			p->set_io_pending(false);
			p->set_data_ready(true);
		}
		p->dec_ref();
	}
	return 0;
}
Exemplo n.º 12
0
void *
x3_malloc(const char *file, unsigned int line, size_t size)
{
    struct alloc_header *block;

    block = malloc(sizeof(*block) + size + sizeof(redzone));
    assert(block != NULL);
    if (block->magic == ALLOC_MAGIC && block->file_id < file_ids_used) {
        /* Only report the error, due to possible false positives. */
        log_module(MAIN_LOG, LOG_WARNING, "Detected possible reallocation: %p (called by %s:%u/%lu; allocated by %u:%u/%u).",
                   block, file, line, (unsigned long)size,
                   block->file_id, block->line, block->size);
    }
    memset(block, 0, sizeof(*block) + size);
    memcpy((char*)(block + 1) + size, redzone, sizeof(redzone));
    block->file_id = get_file_id(file);
    block->line = line;
    block->size = size;
    block->magic = ALLOC_MAGIC;
    alloc_count++;
    alloc_size += size;
    return block + 1;
}
Exemplo n.º 13
0
/* Makes sorted by path list of entries that.  The trie is used to keep track of
 * identical files.  With non-zero dups_only, new files aren't added to the
 * trie. */
static entries_t
make_diff_list(trie_t *trie, FileView *view, int *next_id, CompareType ct,
		int skip_empty, int dups_only)
{
	int i;
	strlist_t files = {};
	entries_t r = {};
	int last_progress = 0;

	show_progress("Listing...", 0);
	if(flist_custom_active(view) &&
			ONE_OF(view->custom.type, CV_REGULAR, CV_VERY))
	{
		list_view_entries(view, &files);
	}
	else
	{
		list_files_recursively(flist_get_dir(view), view->hide_dot, &files);
	}

	show_progress("Querying...", 0);
	for(i = 0; i < files.nitems && !ui_cancellation_requested(); ++i)
	{
		char progress_msg[128];
		int progress;
		int existing_id;
		char *fingerprint;
		const char *const path = files.items[i];
		dir_entry_t *const entry = entry_list_add(view, &r.entries, &r.nentries,
				path);

		if(skip_empty && entry->size == 0)
		{
			free_dir_entry(view, entry);
			--r.nentries;
			continue;
		}

		fingerprint = get_file_fingerprint(path, entry, ct);
		/* In case we couldn't obtain fingerprint (e.g., comparing by contents and
		 * files isn't readable), ignore the file and keep going. */
		if(is_null_or_empty(fingerprint))
		{
			free(fingerprint);
			free_dir_entry(view, entry);
			--r.nentries;
			continue;
		}

		entry->tag = i;
		if(get_file_id(trie, path, fingerprint, &existing_id, ct))
		{
			entry->id = existing_id;
		}
		else if(dups_only)
		{
			entry->id = -1;
		}
		else
		{
			entry->id = *next_id;
			++*next_id;
			put_file_id(trie, path, fingerprint, entry->id, ct);
		}

		free(fingerprint);

		progress = (i*100)/files.nitems;
		if(progress != last_progress)
		{
			last_progress = progress;
			snprintf(progress_msg, sizeof(progress_msg), "Querying... %d (% 2d%%)", i,
					progress);
			show_progress(progress_msg, -1);
		}
	}

	free_string_array(files.items, files.nitems);
	return r;
}
Exemplo n.º 14
0
int     check_file_id(int fd, const char *name)
{
    return (strcmp(get_file_id(fd), name));
}