Example #1
0
void
byte_swap_sbout(struct fs *sb)
{
	u_int16_t *usptr;
	unsigned long size;
	/* Got these magic numbers from mkfs.c in newfs */
	if (sb->fs_nrpos != 8 || sb->fs_cpc > 16) {
		usptr = (u_int16_t *)((u_int8_t *)(sb) + (sb)->fs_postbloff);
		size = sb->fs_cpc * sb->fs_nrpos;
		byte_swap_shorts(usptr,size);	/* fs_postbloff */
	}

	byte_swap_ints(((int32_t *)&sb->fs_firstfield), 52);
	byte_swap_int(sb->fs_cgrotor);
	byte_swap_int(sb->fs_cpc);
        byte_swap_shorts((int16_t *)sb->fs_opostbl,
                         sizeof(sb->fs_opostbl) / sizeof(int16_t));
        byte_swap_int(sb->fs_avgfilesize);
        byte_swap_int(sb->fs_avgfpdir);
        byte_swap_ints((int32_t *)sb->fs_sparecon,
                       sizeof(sb->fs_sparecon) / sizeof(int32_t));
	byte_swap_ints((int32_t *)&sb->fs_contigsumsize, 3);
	byte_swap_longlongs((u_int64_t *)&sb->fs_maxfilesize,3);
	byte_swap_ints((int32_t *)&sb->fs_state, 6);
}
Example #2
0
void
byte_swap_sbin(struct fs *sb)
{
	u_int16_t *usptr;
	unsigned long size;

	byte_swap_ints(((int32_t *)&sb->fs_firstfield), 52);
	byte_swap_int(sb->fs_cgrotor);
	byte_swap_int(sb->fs_cpc);
        byte_swap_shorts((int16_t *)sb->fs_opostbl,
                         sizeof(sb->fs_opostbl) / sizeof(int16_t));
        byte_swap_int(sb->fs_avgfilesize);
        byte_swap_int(sb->fs_avgfpdir);
        byte_swap_ints((int32_t *)sb->fs_sparecon,
                       sizeof(sb->fs_sparecon) / sizeof(int32_t));
	byte_swap_ints((int32_t *)&sb->fs_contigsumsize, 3);
	byte_swap_longlongs((u_int64_t *)&sb->fs_maxfilesize,3);
	byte_swap_ints((int32_t *)&sb->fs_state, 6);

	/* Got these magic numbers from mkfs.c in newfs */
	if (sb->fs_nrpos != 8 || sb->fs_cpc > 16) {
		size = sb->fs_cpc * sb->fs_nrpos;
		if (sb->fs_postbloff < 0)
			return;	/* invalid, so skip block list */
		if ((sb->fs_postbloff + size*sizeof(short)) >= SBSIZE)
			return;	/* don't stray outside our buffer! */

		usptr = (u_int16_t *)((u_int8_t *)(sb) + (sb)->fs_postbloff);
		byte_swap_shorts(usptr,size);	/* fs_postbloff */
	}
}
Example #3
0
void
byte_swap_dirtemplate_in(struct dirtemplate *dirt)
{
	byte_swap_int(dirt->dot_ino);
	byte_swap_short(dirt->dot_reclen);
	byte_swap_int(dirt->dotdot_ino);
	byte_swap_short(dirt->dotdot_reclen);
}
Example #4
0
void
byte_swap_ints(int *array, int count)
{
	register int	i;

	for (i = 0;  i < count;  i++)
		byte_swap_int(array[i]);
}
void ide::buffer_uncompress(const char* packed, std::size_t packed_sz, int* values)
{
    int current = 0;
    unsigned int j = 0;
    short s;
    char c;
    int i;
    bool le = little_endian();

    while (j < packed_sz)
    {
        c = packed[j];
        j += 1;

        if (c != -128)
        {
            current += c;
            *values=current;
            values++;
            continue;
        }

        ((u_s *) & s)[0].b[0] = packed[j];
        ((u_s *) & s)[0].b[1] = packed[j + 1];
        j += 2;

        if (!le)
        {
            byte_swap_short((char *) &s);
        }

        if (s != -32768)
        {
            current += s;
            *values=current;
            values++;
            continue;
        }

        ((u_i *) & i)[0].b[0] = packed[j];
        ((u_i *) & i)[0].b[1] = packed[j + 1];
        ((u_i *) & i)[0].b[2] = packed[j + 2];
        ((u_i *) & i)[0].b[3] = packed[j + 3];
        j += 4;

        if (!le)
        {
            byte_swap_int((char *) &i);
        }

        current += i;
        *values=current;
        values++;
    }

}
Example #6
0
void
byte_swap_dir_block_in(struct bufarea *bp)
{
	struct direct	*ep;
	int		entryoffsetinblk = 0;
	char * addr;

	addr =  bp->b_un.b_buf;
	ep = (struct direct *)addr;
	while (entryoffsetinblk < bp->b_size) {
		ep = (struct direct *) (entryoffsetinblk + addr);
		byte_swap_int(ep->d_ino);
		byte_swap_short(ep->d_reclen);
		entryoffsetinblk += ep->d_reclen;
		if (ep->d_reclen < 12)		/* handle garbage in dirs */
			break;
	}
}
Example #7
0
void
byte_swap_dir_block_out(struct bufarea *bp)
{
	struct direct	*ep;
	int		reclen, entryoffsetinblk = 0;
	char * bdata;

	bdata = bp->b_un.b_buf;
	ep = (struct direct *)bdata;
	while (entryoffsetinblk < bp->b_size) {
		ep = (struct direct *) (entryoffsetinblk + bdata);
		reclen = ep->d_reclen;
		entryoffsetinblk += reclen;
		byte_swap_int(ep->d_ino);
		byte_swap_short(ep->d_reclen);
		if (reclen < 12)
			break;
	}
}
Example #8
0
void
byte_swap_minidir_in(struct direct *dirp)
{
	byte_swap_int(dirp->d_ino);
	byte_swap_short(dirp->d_reclen);
}
Example #9
0
// This is for the new 4.4 cylinder group block
void
byte_swap_cgout(struct cg *cg, struct fs * fs)
{
	int32_t * ulptr;
	int16_t * usptr;
	int size;

	byte_swap_int(cg->cg_firstfield);
	byte_swap_int(cg->cg_magic);
	byte_swap_int(cg->cg_time);
	byte_swap_int(cg->cg_cgx);
	byte_swap_short(cg->cg_ncyl);
	byte_swap_short(cg->cg_niblk);
	byte_swap_int(cg->cg_ndblk);
	byte_swap_csum(&cg->cg_cs);
	byte_swap_int(cg->cg_rotor);
	byte_swap_int(cg->cg_frotor);
	byte_swap_int(cg->cg_irotor);
	byte_swap_ints(cg->cg_frsum, MAXFRAG);
	byte_swap_int(cg->cg_freeoff);
	byte_swap_int(cg->cg_nextfreeoff);
	byte_swap_int(cg->cg_nclusterblks);
	byte_swap_ints(cg->cg_sparecon, 13);

	byte_swap_int(cg->cg_iusedoff);
	byte_swap_int(cg->cg_clusteroff);
	ulptr = ((int32_t *)((u_int8_t *)(cg) + (cg)->cg_btotoff));
	size = fs->fs_cpg;
	byte_swap_ints(ulptr, size);	/*cg_btotoff*/
	byte_swap_int(cg->cg_btotoff);

	usptr = ((int16_t *)((u_int8_t *)(cg) + (cg)->cg_boff));
	size = fs->fs_cpg * fs->fs_nrpos;

	byte_swap_shorts(usptr,size);	/*cg_boff*/
	byte_swap_int(cg->cg_boff);

	if ((unsigned int)fs->fs_contigsumsize > 0) {
	ulptr = ((int32_t *)((u_int8_t *)(cg) + (cg)->cg_clustersumoff));
		size = (fs->fs_contigsumsize + 1);
		byte_swap_ints(ulptr, size);	/*cg_clustersumoff*/

	}
	byte_swap_int(cg->cg_clustersumoff);

}
Example #10
0
/* This is for the new 4.4 cylinder group block */
void
byte_swap_cgin(struct cg *cg, struct fs * fs)
{
	int32_t * ulptr;
	int16_t * usptr;
	size_t size;

	byte_swap_int(cg->cg_firstfield);
	byte_swap_int(cg->cg_magic);
	byte_swap_int(cg->cg_time);
	byte_swap_int(cg->cg_cgx);
	byte_swap_short(cg->cg_ncyl);
	byte_swap_short(cg->cg_niblk);
	byte_swap_int(cg->cg_ndblk);
	byte_swap_csum(&cg->cg_cs);
	byte_swap_int(cg->cg_rotor);
	byte_swap_int(cg->cg_frotor);
	byte_swap_int(cg->cg_irotor);
	byte_swap_ints(cg->cg_frsum, MAXFRAG);
	byte_swap_int(cg->cg_iusedoff);
	byte_swap_int(cg->cg_freeoff);
	byte_swap_int(cg->cg_nextfreeoff);
	byte_swap_int(cg->cg_clusteroff);
	byte_swap_int(cg->cg_nclusterblks);
	byte_swap_ints(cg->cg_sparecon, 13);

	byte_swap_int(cg->cg_btotoff);
	if (cg->cg_btotoff < 0 || cg->cg_btotoff > sblock.fs_bsize) {
		pfatal("CG bad on input:  block total offset out of range (%d)\n",
			cg->cg_btotoff);
	} else {
		ulptr = ((int32_t *)((u_int8_t *)(cg) + (cg)->cg_btotoff));
		size = fs->fs_cpg;

		if (size > sblock.fs_bsize ||
			(u_int8_t*)(ulptr + size) > ((u_int8_t*)cg + sblock.fs_bsize)) {
			pfatal("CG bad on input:  Block totals array out of range\n");
		} else {
			byte_swap_ints(ulptr, size);	/*cg_btotoff*/
		}
	}

	byte_swap_int(cg->cg_boff);
	if (cg->cg_boff < 0 || cg->cg_boff > sblock.fs_bsize) {
		pfatal("CG bad on input:  free block offset out of range (%d)\n",
			cg->cg_boff);
	} else {
		usptr = ((int16_t *)((u_int8_t *)(cg) + (cg)->cg_boff));
		size = fs->fs_cpg * fs->fs_nrpos;
		if (size > sblock.fs_bsize ||
			(u_int8_t*)(usptr + size) > ((u_int8_t*)cg + sblock.fs_bsize)) {
			pfatal("CG bad on input:  free block array out of bounds\n");
		} else {
			byte_swap_shorts(usptr,size);	/*cg_boff*/
		}
	}
	byte_swap_int(cg->cg_clustersumoff);

	if ((unsigned int)cg->cg_clustersumoff > sblock.fs_bsize) {
		pfatal("CG bad on input:  sum offset array out of range (%d)\n",
			cg->cg_clustersumoff);
	} else {
		if ((unsigned int)fs->fs_contigsumsize > 0) {
			ulptr = ((int32_t *)((u_int8_t *)(cg) + (cg)->cg_clustersumoff));
			size = (fs->fs_contigsumsize + 1);
			if (size > sblock.fs_bsize ||
				(u_int8_t*)(ulptr + size) > ((u_int8_t*)cg + sblock.fs_bsize)) {
				pfatal("CG bad on input:  sum array out of bounds\n");
			} else {
				byte_swap_ints(ulptr, size);	/*cg_clustersumoff*/
			}
		}
	}
}
std::vector<char>
ide::buffer_compress(const int* values, const std::size_t& sz)
{
    std::vector<char> packed(0);
    int current = 0;
    int delta, i;
    unsigned int j;
    bool le = little_endian();
    short s;
    char c;
    char * b;

    for (j = 0; j < sz; j++)
    {
        delta = values[j] - current;

        if ((-127 <= delta) && (delta < 128))
        {
            c = (char) delta;
            packed.push_back(c);
            current += delta;
            continue;
        }

        packed.push_back(-128);

        if ((-32767 <= delta) && (delta < 32768))
        {
            s = (short) delta;
            b = ((u_s *) & s)[0].b;

            if (!le)
            {
                byte_swap_short(b);
            }

            packed.push_back(b[0]);
            packed.push_back(b[1]);
            current += delta;
            continue;
        }
        s = -32768;
        b = ((u_s *) & s)[0].b;

        if (!le)
        {
            byte_swap_short(b);
        }

        packed.push_back(b[0]);
        packed.push_back(b[1]);

        if ((-2147483647 <= delta) && (delta <= 2147483647))
        {
            i = delta;
            b = ((u_i *) & i)[0].b;

            if (!le)
            {
                byte_swap_int(b);
            }

            packed.push_back(b[0]);
            packed.push_back(b[1]);
            packed.push_back(b[2]);
            packed.push_back(b[3]);
            current += delta;
            continue;
        }

        /* FIXME I should not get here */
        //fail silently or throw an exception?
    }

    return packed;
}