Home | History | Annotate | Line # | Download | only in ext2fs
ext2fs_bswap.c revision 1.2
      1 /*	$NetBSD: ext2fs_bswap.c,v 1.2 1998/08/09 20:15:38 perry Exp $	*/
      2 
      3 /*
      4  * Copyright (c) 1997 Manuel Bouyer.
      5  *
      6  * Redistribution and use in source and binary forms, with or without
      7  * modification, are permitted provided that the following conditions
      8  * are met:
      9  * 1. Redistributions of source code must retain the above copyright
     10  *    notice, this list of conditions and the following disclaimer.
     11  * 2. Redistributions in binary form must reproduce the above copyright
     12  *    notice, this list of conditions and the following disclaimer in the
     13  *    documentation and/or other materials provided with the distribution.
     14  * 3. All advertising materials mentioning features or use of this software
     15  *    must display the following acknowledgement:
     16  *	This product includes software developed by the University of
     17  *	California, Berkeley and its contributors.
     18  * 4. Neither the name of the University nor the names of its contributors
     19  *    may be used to endorse or promote products derived from this software
     20  *    without specific prior written permission.
     21  *
     22  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     23  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     24  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     25  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     26  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     27  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     28  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     29  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     30  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     31  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     32  * SUCH DAMAGE.
     33  *
     34  */
     35 
     36 #include <sys/types.h>
     37 #include <sys/systm.h>
     38 #include <ufs/ext2fs/ext2fs.h>
     39 #include <ufs/ext2fs/ext2fs_dinode.h>
     40 
     41 /* These functions are only needed if native byte order is not big endian */
     42 #if BYTE_ORDER == BIG_ENDIAN
     43 void
     44 e2fs_sb_bswap(old, new)
     45 	struct ext2fs *old, *new;
     46 {
     47 	/* preserve unused fields */
     48 	memcpy(new, old, sizeof(struct ext2fs));
     49 	new->e2fs_icount		=		bswap32(old->e2fs_icount);
     50 	new->e2fs_bcount		=		bswap32(old->e2fs_bcount);
     51 	new->e2fs_rbcount		=		bswap32(old->e2fs_rbcount);
     52 	new->e2fs_fbcount		=		bswap32(old->e2fs_fbcount);
     53 	new->e2fs_ficount		=		bswap32(old->e2fs_ficount);
     54 	new->e2fs_first_dblock	=		bswap32(old->e2fs_first_dblock);
     55 	new->e2fs_log_bsize		=		bswap32(old->e2fs_log_bsize);
     56 	new->e2fs_fsize			=		bswap32(old->e2fs_fsize);
     57 	new->e2fs_bpg			=		bswap32(old->e2fs_bpg);
     58 	new->e2fs_fpg			=		bswap32(old->e2fs_fpg);
     59 	new->e2fs_ipg			=		bswap32(old->e2fs_ipg);
     60 	new->e2fs_mtime			=		bswap32(old->e2fs_mtime);
     61 	new->e2fs_wtime			=		bswap32(old->e2fs_wtime);
     62 	new->e2fs_lastfsck		=		bswap32(old->e2fs_lastfsck);
     63 	new->e2fs_fsckintv		=		bswap32(old->e2fs_fsckintv);
     64 	new->e2fs_creator		=		bswap32(old->e2fs_creator);
     65 	new->e2fs_rev			=		bswap32(old->e2fs_rev);
     66 	new->e2fs_mnt_count		=		bswap16(old->e2fs_mnt_count);
     67 	new->e2fs_max_mnt_count	=		bswap16(old->e2fs_max_mnt_count);
     68 	new->e2fs_magic			=		bswap16(old->e2fs_magic);
     69 	new->e2fs_state			=		bswap16(old->e2fs_state);
     70 	new->e2fs_beh			=		bswap16(old->e2fs_beh);
     71 	new->e2fs_ruid			=		bswap16(old->e2fs_ruid);
     72 	new->e2fs_rgid			=		bswap16(old->e2fs_rgid);
     73 }
     74 
     75 void e2fs_cg_bswap(old, new, size)
     76 	struct  ext2_gd *old, *new;
     77 	int size;
     78 {
     79 	int i;
     80 	for (i=0; i < (size / sizeof(struct  ext2_gd)); i++) {
     81 		new[i].ext2bgd_b_bitmap	=	bswap32(old[i].ext2bgd_b_bitmap);
     82 		new[i].ext2bgd_i_bitmap	=	bswap32(old[i].ext2bgd_i_bitmap);
     83 		new[i].ext2bgd_i_tables	=	bswap32(old[i].ext2bgd_i_tables);
     84 		new[i].ext2bgd_nbfree	=	bswap16(old[i].ext2bgd_nbfree);
     85 		new[i].ext2bgd_nifree	=	bswap16(old[i].ext2bgd_nifree);
     86 		new[i].ext2bgd_ndirs	=	bswap16(old[i].ext2bgd_ndirs);
     87 	}
     88 }
     89 
     90 void e2fs_i_bswap(old, new)
     91 	struct ext2fs_dinode *old, *new;
     92 {
     93 	new->e2di_mode		=	bswap16(old->e2di_mode);
     94 	new->e2di_uid		=	bswap16(old->e2di_uid);
     95 	new->e2di_gid		=	bswap16(old->e2di_gid);
     96 	new->e2di_nlink		=	bswap16(old->e2di_nlink);
     97 	new->e2di_size		=	bswap32(old->e2di_size);
     98 	new->e2di_atime		=	bswap32(old->e2di_atime);
     99 	new->e2di_ctime		=	bswap32(old->e2di_ctime);
    100 	new->e2di_mtime		=	bswap32(old->e2di_mtime);
    101 	new->e2di_dtime		=	bswap32(old->e2di_dtime);
    102 	new->e2di_nblock	=	bswap32(old->e2di_nblock);
    103 	new->e2di_flags		=	bswap32(old->e2di_flags);
    104 	new->e2di_gen		=	bswap32(old->e2di_gen);
    105 	new->e2di_facl		=	bswap32(old->e2di_facl);
    106 	new->e2di_dacl		=	bswap32(old->e2di_dacl);
    107 	new->e2di_faddr		=	bswap32(old->e2di_faddr);
    108 	memcpy(&new->e2di_blocks[0], &old->e2di_blocks[0],
    109 		(NDADDR+NIADDR) * sizeof(int));
    110 }
    111 #endif
    112