Ejemplo n.º 1
0
/// read super block and write to image head
extern void initial_image_hdr(char* device, image_head* image_hdr)
{
    reiser4_bitmap_t       *fs_bitmap;
    unsigned long long free_blocks=0;

    fs_open(device);
    fs_bitmap = reiser4_bitmap_create(reiser4_format_get_len(fs->format));
    reiser4_alloc_extract(fs->alloc, fs_bitmap);
    free_blocks = reiser4_format_get_free(fs->format);
    memcpy(image_hdr->magic, IMAGE_MAGIC, IMAGE_MAGIC_SIZE);
    memcpy(image_hdr->fs, reiser4_MAGIC, FS_MAGIC_SIZE);
    image_hdr->block_size = (int)get_ms_blksize(SUPER(fs->master));
    image_hdr->totalblock = (unsigned long long)reiser4_format_get_len(fs->format);
    image_hdr->usedblocks = (unsigned long long)(reiser4_format_get_len(fs->format) - free_blocks);
    image_hdr->device_size =(unsigned long long)(image_hdr->block_size * image_hdr->totalblock);
    fs_close();
}
Ejemplo n.º 2
0
/* This function opens journal on specified device and returns instance of
   opened journal. */
reiser4_journal_t *reiser4_journal_open(
	reiser4_fs_t *fs,	        /* fs journal will be opened on */
	aal_device_t *device)	        /* device journal will be opened on */
{
	rid_t pid;
	blk_t start;
	count_t blocks;
	uint32_t blksize;
	reiser4_plug_t *plug;
	reiser4_journal_t *journal;
	
	aal_assert("umka-095", fs != NULL);
	aal_assert("umka-1695", fs->format != NULL);
	
	/* Allocating memory for journal instance and initialize its fields. */
	if (!(journal = aal_calloc(sizeof(*journal), 0)))
		return NULL;

	journal->fs = fs;
	journal->device = device;
	journal->fs->journal = journal;

	if ((pid = reiser4_format_journal_pid(fs->format)) == INVAL_PID) {
		aal_error("Invalid journal plugin id has been found.");
		goto error_free_journal;
	}
 
	/* Getting plugin by its id from plugin factory */
	if (!(plug = reiser4_factory_ifind(JOURNAL_PLUG_TYPE, pid))) {
		aal_error("Can't find journal plugin by its "
			  "id 0x%x.", pid);
		goto error_free_journal;
	}

	start = reiser4_format_start(fs->format);
	blocks = reiser4_format_get_len(fs->format);

	blksize = reiser4_master_get_blksize(fs->master);
	
	/* Initializing journal entity by means of calling "open" method from
	   found journal plugin. */
	if (!(journal->ent = plugcall((reiser4_journal_plug_t *)plug, 
				      open, journal->device, blksize,
				      fs->format->ent, fs->oid->ent,
				      start, blocks))) 
	{
		aal_error("Can't open journal %s on %s.",
			  plug->label, device->name);
		goto error_free_journal;
	}
	
	return journal;

 error_free_journal:
	aal_free(journal);
	return NULL;
}
Ejemplo n.º 3
0
reiser4_journal_t *repair_journal_unpack(reiser4_fs_t *fs, 
					 aal_stream_t *stream) 
{
	reiser4_journal_t *journal;
	reiser4_plug_t *plug;
	uint32_t blksize;
	count_t blocks;
	uint32_t read;
	blk_t start;
	rid_t pid;
	
	aal_assert("vpf-1753", fs != NULL);
	aal_assert("vpf-1754", stream != NULL);

	read = aal_stream_read(stream, &pid, sizeof(pid));
	if (read != sizeof(pid)) {
		aal_error("Can't unpack the journal. Stream is over?");
		return NULL;
	}
	
	/* Getting needed plugin from plugin factory by its id */
	if (!(plug = reiser4_factory_ifind(JOURNAL_PLUG_TYPE, pid))) {
		aal_error("Can't find journal plugin "
			  "by its id 0x%x.", pid);
		return NULL;
	}

	/* Allocating memory and finding plugin */
	if (!(journal = aal_calloc(sizeof(*journal), 0)))
		return NULL;

	journal->fs = fs;
	journal->device = fs->device;
	
	start = reiser4_format_start(fs->format);
	blocks = reiser4_format_get_len(fs->format);
	blksize = reiser4_master_get_blksize(fs->master);

	/* Creating journal entity. */
	if (!(journal->ent = plugcall((reiser4_journal_plug_t *)plug, unpack,
				      fs->device, blksize, fs->format->ent,
				      fs->oid->ent, start, blocks, stream)))
	{
		aal_error("Can't unpack journal %s on %s.",
			  plug->label, fs->device->name);
		goto error;
	}

	return journal;
	
 error:
	aal_free(journal);
	return NULL;
}
Ejemplo n.º 4
0
/// readbitmap - read bitmap
extern void readbitmap(char* device, image_head image_hdr, char*bitmap, int pui)
{
    reiser4_bitmap_t       *fs_bitmap;
    unsigned long long     bit, block, bused = 0, bfree = 0;
    int start = 0;
    int bit_size = 1;

    fs_open(device);
    fs_bitmap = reiser4_bitmap_create(reiser4_format_get_len(fs->format));
    reiser4_alloc_extract(fs->alloc, fs_bitmap);

    /// init progress
    progress_bar   prog;	/// progress_bar structure defined in progress.h
    progress_init(&prog, start, image_hdr.totalblock, bit_size);


    for(bit = 0; bit < reiser4_format_get_len(fs->format); bit++){
        block = bit ;
        if(reiser4_bitmap_test(fs_bitmap, bit)){
            bused++;
            bitmap[block] = 1;
            log_mesg(3, 0, 0, fs_opt.debug, "%s: bitmap is used %lli", block, __FILE__);
        } else {
            bitmap[block] = 0;
            bfree++;
            log_mesg(3, 0, 0, fs_opt.debug, "%s: bitmap is free %lli", block, __FILE__);
        }
        /// update progress
        update_pui(&prog, bit, 0);

    }

    if(bfree != reiser4_format_get_free(fs->format))
        log_mesg(0, 1, 1, fs_opt.debug, "%s: bitmap free count err, bfree:%lli, sfree=%lli\n", __FILE__, bfree, reiser4_format_get_free(fs->format));

    fs_close();
    /// update progress
    update_pui(&prog, bit, 1);
}
Ejemplo n.º 5
0
/* Creates journal on specified jopurnal. Returns initialized instance */
reiser4_journal_t *reiser4_journal_create(
	reiser4_fs_t *fs,	        /* fs journal will be opened on */
	aal_device_t *device)	        /* device journal will be created on */
{
	rid_t pid;
	blk_t start;
	count_t blocks;
	uint32_t blksize;
	reiser4_plug_t *plug;
	reiser4_journal_t *journal;

	aal_assert("umka-1697", fs != NULL);
	aal_assert("umka-1696", fs->format != NULL);
	
	/* Allocating memory and finding plugin */
	if (!(journal = aal_calloc(sizeof(*journal), 0)))
		return NULL;

	journal->fs = fs;
	journal->device = device;

	/* Getting journal plugin to be used. */
	if ((pid = reiser4_format_journal_pid(fs->format)) == INVAL_PID) {
		aal_error("Invalid journal plugin id has been found.");
		goto error_free_journal;
	}
    
	if (!(plug = reiser4_factory_ifind(JOURNAL_PLUG_TYPE, pid)))  {
		aal_error("Can't find journal plugin by its id 0x%x.", pid);
		goto error_free_journal;
	}
    
	start = reiser4_format_start(fs->format);
	blocks = reiser4_format_get_len(fs->format);

	blksize = reiser4_master_get_blksize(fs->master);
	
	/* Creating journal entity. */
	if (!(journal->ent = plugcall((reiser4_journal_plug_t *)plug,
				      create, journal->device, blksize,
				      fs->format->ent, fs->oid->ent,
				      start, blocks)))
	{
		aal_error("Can't create journal %s on %s.",
			  plug->label, journal->device->name);
		goto error_free_journal;
	}
	
	if (reiser4_journal_mark(journal)) {
		aal_error("Can't mark journal blocks used in "
			  "block allocator.");
		goto error_free_entity;
	}
	
	return journal;

 error_free_entity:
	reiser4call(journal, close);
	
 error_free_journal:
	aal_free(journal);
	return NULL;
}