示例#1
0
文件: storage.cpp 项目: bradc6/libdar
    storage::storage(generic_file & f, const infinint & size)
    {
        U_32 lu, tmp;
        make_alloc(size, first, last);
        struct cellule *ptr = first;

        try
        {
            while(ptr != NULL)
            {
                lu = 0;

                do
                {
                    tmp = f.read(((char *)(ptr->data))+lu, ptr->size - lu);
                    lu += tmp;
                }
                while(lu < ptr->size && tmp != 0);

                if(lu < ptr->size)
                    throw Erange("storage::storage", gettext("Not enough data to initialize storage field"));
                ptr = ptr->next;
            }
        }
        catch(...)
        {
            detruit(first);
	    first = NULL;
	    last = NULL;
            throw;
        }
    }
示例#2
0
    void slice_layout::read(generic_file & f)
    {
	char tmp;

	first_size.read(f);
	other_size.read(f);
	first_slice_header.read(f);
	other_slice_header.read(f);
	if(f.read(&tmp , 1) == 1)
	{
	    switch(tmp)
	    {
	    case OLDER_THAN_V8:
		older_sar_than_v8 = true;
		break;
	    case V8:
		older_sar_than_v8 = false;
		break;
	    default:
		throw SRC_BUG;
	    }
	}
	else
	    throw Erange("slice_layout::read", gettext("Missing data while reading slice_layout object"));
    }
示例#3
0
    void slice_layout::write(generic_file & f) const
    {
	char tmp = older_sar_than_v8 ? OLDER_THAN_V8 : V8;
	first_size.dump(f);
	other_size.dump(f);
	first_slice_header.dump(f);
	other_slice_header.dump(f);
	f.write(&tmp, 1);
    }
示例#4
0
文件: storage.cpp 项目: bradc6/libdar
    void storage::dump(generic_file & f) const
    {
        const struct cellule *ptr = first;

        while(ptr != NULL)
        {
            f.write((const char *)(ptr->data), ptr->size);
            ptr = ptr->next;
        }
    }
示例#5
0
hide_file::hide_file(generic_file &f) : generic_file(gf_read_only)
{
    if(f.get_mode() == gf_write_only)
        throw Erange("hide_file::hide_file", gettext("hide_file cannot be initialized with write-only file"));

    ref = &f;
    if(ref == NULL)
        throw SRC_BUG; // NULL argument given
    is_init = false;
    pos_index = 0;
    pos_relicat = 0;
}
    void filesystem_specific_attribute_list::write(generic_file & f) const
    {
	infinint size = fsa.size();
	vector<filesystem_specific_attribute *>::const_iterator it = fsa.begin();

	size.dump(f);

	while(it != fsa.end())
	{
	    string tmp;

	    if(*it == NULL)
		throw SRC_BUG;

	    tmp = family_to_signature((*it)->get_family());
	    f.write(tmp.c_str(), tmp.size());
	    tmp = nature_to_signature((*it)->get_nature());
	    f.write(tmp.c_str(), tmp.size());
	    (*it)->write(f);

	    ++it;
	}
    }
    fsa_bool::fsa_bool(generic_file & f, fsa_family fam, fsa_nature nat):
	filesystem_specific_attribute(f, fam, nat)
    {
	char ch;
	S_I lu = f.read(&ch, 1);

	if(lu == 1)
	{
	    switch(ch)
	    {
	    case 'T':
		val = true;
		break;
	    case 'F':
		val = false;
		break;
	    default:
		throw Edata(gettext("Unexepected value for boolean FSA, data corruption may have occurred"));
	    }
	}
	else
	    throw Erange("fsa_bool::fsa_bool", string(gettext("Error while reading FSA: ")) + strerror(errno));
    }
    void filesystem_specific_attribute_list::read(generic_file & f)
    {
	infinint size = infinint(f);
	U_I sub_size;

	do
	{
	    sub_size = 0;
	    size.unstack(sub_size);
	    if(size > 0 && sub_size == 0)
		throw SRC_BUG;

	    while(sub_size > 0)
	    {
		char buffer[FAM_SIG_WIDTH + NAT_SIG_WIDTH + 1];
		fsa_family fam;
		fsa_nature nat;
		filesystem_specific_attribute *ptr = NULL;

		f.read(buffer, FAM_SIG_WIDTH);
		buffer[FAM_SIG_WIDTH] = '\0';
		fam = signature_to_family(buffer);

		f.read(buffer, NAT_SIG_WIDTH);
		buffer[NAT_SIG_WIDTH] = '\0';
		nat = signature_to_nature(buffer);

		switch(nat)
		{
		case fsan_unset:
		    throw SRC_BUG;
		case fsan_creation_date:
		    ptr = new (nothrow) fsa_infinint(f, fam, nat);
		    break;
		case fsan_append_only:
		case fsan_compressed:
		case fsan_no_dump:
		case fsan_immutable:
		case fsan_data_journalling:
		case fsan_secure_deletion:
		case fsan_no_tail_merging:
		case fsan_undeletable:
		case fsan_noatime_update:
		case fsan_synchronous_directory:
		case fsan_synchronous_update:
		case fsan_top_of_dir_hierarchy:
		    ptr = new (nothrow) fsa_bool(f, fam, nat);
		    break;
		default:
		    throw SRC_BUG;
		}

		if(ptr == NULL)
		    throw Ememory("filesystem_specific_attribute_list::read");
		fsa.push_back(ptr);
		ptr = NULL;

		--sub_size;
	    }
	}
	while(size > 0);

	update_familes();
	sort_fsa();
    }
示例#9
0
文件: elastic.cpp 项目: bradc6/libdar
    elastic::elastic(generic_file &f, elastic_direction dir,  const archive_version & reading_ver)
    {
	U_32 count = 0;
	S_I (generic_file::*lecture)(char &a) = (dir == elastic_forward ? &generic_file::read_forward : &generic_file::read_back);
	unsigned char first_mark = (dir == elastic_forward ? get_low_mark(reading_ver) : get_high_mark(reading_ver));
	unsigned char last_mark  = (dir == elastic_forward ? get_high_mark(reading_ver) : get_low_mark(reading_ver));
	unsigned char a;

	while((f.*lecture)((char &)a) && a != SINGLE_MARK && a != first_mark)
	    ++count;

	if(a != SINGLE_MARK && a != first_mark)
	    throw Erange("elastic::elastic", gettext("elastic buffer incoherent structure"));
	else
	    ++count;

	if(a == SINGLE_MARK)
	    if(count == 1)
		taille = 1;
	    else
		throw Erange("elastic::elastic", gettext("elastic buffer incoherent structure"));
	else // elastic buffer size is greater than one
	{
	    U_32 power_base = 1;
	    U_I base = base_from_version(reading_ver);
	    const U_32 int_width = sizeof(U_32);
	    U_32 byte_counter = 0;
		// now reading total size

	    taille = 0;
	    while((f.*lecture)((char &)a) && a != last_mark)
	    {
		if(dir != elastic_forward)
		{
		    taille *= base;
		    taille += a;
		}
		else
		{
		    taille += power_base * a;
		    power_base *= base;
		}

		count++;
		if(++byte_counter > int_width)
		    throw Erange("elastic::elastic", gettext("too large elastic buffer or elastic buffer incoherent structure"));
	    }

	    if(a != last_mark)
		throw Erange("elastic::elastic", gettext("elastic buffer incoherent structure"));
	    else
		count++;

	    if(taille == 0 && byte_counter == 0)
		taille = 2; // this is the trivial buffer of size 2
	    else
		if(taille < 3)
		    throw Erange("elastic::elastic", gettext("elastic buffer incoherent structure"));

		// now skipping to the "end" of the elastic buffer
	    if(count < taille)
		if(dir == elastic_forward)
		    f.skip_relative(taille - count);
		else
		    f.skip_relative(count - taille);
	    else
		if(count > taille)
		    throw Erange("elastic::elastic", gettext("elastic buffer incoherent structure"));
	}
    }
示例#10
0
 compressor::compressor(compression algo, generic_file & compressed_side, U_I compression_level) : generic_file(compressed_side.get_mode())
 {
     init(algo, &compressed_side, compression_level);
     compressed_owner = false;
 }
示例#11
0
    void compressor::lzo_block_header::set_from(generic_file & f)
    {
	f.read(&type, 1);
	size.read(f);
    }
示例#12
0
    void compressor::lzo_block_header::dump(generic_file & f)
    {
	f.write(&type, 1);
	size.dump(f);
    }