Home | History | Annotate | Line # | Download | only in ffs
ffs_bswap.c revision 1.2
      1  1.2   ragge /*	$NetBSD: ffs_bswap.c,v 1.2 1998/06/08 17:59:08 ragge Exp $	*/
      2  1.1  bouyer 
      3  1.1  bouyer /*
      4  1.1  bouyer  * Copyright (c) 1998 Manuel Bouyer.
      5  1.1  bouyer  *
      6  1.1  bouyer  * Redistribution and use in source and binary forms, with or without
      7  1.1  bouyer  * modification, are permitted provided that the following conditions
      8  1.1  bouyer  * are met:
      9  1.1  bouyer  * 1. Redistributions of source code must retain the above copyright
     10  1.1  bouyer  *    notice, this list of conditions and the following disclaimer.
     11  1.1  bouyer  * 2. Redistributions in binary form must reproduce the above copyright
     12  1.1  bouyer  *    notice, this list of conditions and the following disclaimer in the
     13  1.1  bouyer  *    documentation and/or other materials provided with the distribution.
     14  1.1  bouyer  * 3. All advertising materials mentioning features or use of this software
     15  1.1  bouyer  *    must display the following acknowledgement:
     16  1.1  bouyer  *	This product includes software developed by the University of
     17  1.1  bouyer  *	California, Berkeley and its contributors.
     18  1.1  bouyer  * 4. Neither the name of the University nor the names of its contributors
     19  1.1  bouyer  *    may be used to endorse or promote products derived from this software
     20  1.1  bouyer  *    without specific prior written permission.
     21  1.1  bouyer  *
     22  1.1  bouyer  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     23  1.1  bouyer  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     24  1.1  bouyer  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     25  1.1  bouyer  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     26  1.1  bouyer  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     27  1.1  bouyer  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     28  1.1  bouyer  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     29  1.1  bouyer  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     30  1.1  bouyer  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     31  1.1  bouyer  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     32  1.1  bouyer  * SUCH DAMAGE.
     33  1.1  bouyer  *
     34  1.1  bouyer  */
     35  1.1  bouyer 
     36  1.1  bouyer #include <sys/types.h>
     37  1.2   ragge #include <sys/param.h>
     38  1.1  bouyer #include <sys/systm.h>
     39  1.1  bouyer #include <ufs/ufs/dinode.h>
     40  1.1  bouyer #include <ufs/ufs/ufs_bswap.h>
     41  1.1  bouyer #include <ufs/ffs/fs.h>
     42  1.1  bouyer #include <ufs/ffs/ffs_extern.h>
     43  1.1  bouyer 
     44  1.1  bouyer void
     45  1.1  bouyer ffs_sb_swap(o, n, ns)
     46  1.1  bouyer 	struct fs *o, *n;
     47  1.1  bouyer 	int ns;
     48  1.1  bouyer {
     49  1.1  bouyer 	int i;
     50  1.1  bouyer 	u_int32_t *o32, *n32;
     51  1.1  bouyer 	u_int16_t *o16, *n16;
     52  1.1  bouyer 
     53  1.1  bouyer 	/* in order to avoid a lot of lines, as the first 52 fields of
     54  1.1  bouyer 	 * the superblock are u_int32_t, we loop here to convert it.
     55  1.1  bouyer 	 */
     56  1.1  bouyer 	o32 = (u_int32_t *)o;
     57  1.1  bouyer 	n32 = (u_int32_t *)n;
     58  1.1  bouyer 	for (i=0; i< 52; i++)
     59  1.1  bouyer 		n32[i] = bswap32(o32[i]);
     60  1.1  bouyer 
     61  1.1  bouyer 	n->fs_cpc = bswap32(o->fs_cpc);
     62  1.1  bouyer 	n->fs_fscktime = bswap32(o->fs_fscktime);
     63  1.1  bouyer 	n->fs_contigsumsize = bswap32(o->fs_contigsumsize);
     64  1.1  bouyer 	n->fs_maxsymlinklen = bswap32(o->fs_maxsymlinklen);
     65  1.1  bouyer 	n->fs_inodefmt = bswap32(o->fs_inodefmt);
     66  1.1  bouyer 	n->fs_maxfilesize = bswap64(o->fs_maxfilesize);
     67  1.1  bouyer 	n->fs_qbmask = bswap64(o->fs_qbmask);
     68  1.1  bouyer 	n->fs_qfmask = bswap64(o->fs_qfmask);
     69  1.1  bouyer 	n->fs_state = bswap32(o->fs_state);
     70  1.1  bouyer 	n->fs_postblformat = bswap32(o->fs_postblformat);
     71  1.1  bouyer 	n->fs_nrpos = bswap32(o->fs_nrpos);
     72  1.1  bouyer 	n->fs_postbloff = bswap32(o->fs_postbloff);
     73  1.1  bouyer 	n->fs_rotbloff = bswap32(o->fs_rotbloff);
     74  1.1  bouyer 	n->fs_magic = bswap32(o->fs_magic);
     75  1.1  bouyer 	/* byteswap the postbl */
     76  1.1  bouyer 	o16 = (ufs_rw32(o->fs_postblformat, ns) == FS_42POSTBLFMT)
     77  1.1  bouyer 		? o->fs_opostbl[0]
     78  1.1  bouyer 		: (int16_t *)((u_int8_t *)o + ufs_rw32(o->fs_postbloff, ns));
     79  1.1  bouyer 	n16 = (ufs_rw32(o->fs_postblformat, ns) == FS_42POSTBLFMT)
     80  1.1  bouyer 		? n->fs_opostbl[0]
     81  1.1  bouyer 		: (int16_t *)((u_int8_t *)n + ufs_rw32(n->fs_postbloff, ns));
     82  1.1  bouyer 	for (i = 0;
     83  1.1  bouyer 		i < ufs_rw32(o->fs_cpc, ns) * ufs_rw32(o->fs_nrpos, ns);
     84  1.1  bouyer 		i++)
     85  1.1  bouyer 		n16[i] = bswap16(o16[i]);
     86  1.1  bouyer }
     87  1.1  bouyer 
     88  1.1  bouyer void
     89  1.1  bouyer ffs_dinode_swap(o, n)
     90  1.1  bouyer 	struct dinode *o, *n;
     91  1.1  bouyer {
     92  1.1  bouyer 	n->di_mode = bswap16(o->di_mode);
     93  1.1  bouyer 	n->di_nlink = bswap16(o->di_nlink);
     94  1.1  bouyer 	n->di_u.oldids[0] = bswap16(o->di_u.oldids[0]);
     95  1.1  bouyer 	n->di_u.oldids[1] = bswap16(o->di_u.oldids[1]);
     96  1.1  bouyer 	n->di_size = bswap64(o->di_size);
     97  1.1  bouyer 	n->di_atime = bswap32(o->di_atime);
     98  1.1  bouyer 	n->di_atimensec = bswap32(o->di_atimensec);
     99  1.1  bouyer 	n->di_mtime = bswap32(o->di_mtime);
    100  1.1  bouyer 	n->di_mtimensec = bswap32(o->di_mtimensec);
    101  1.1  bouyer 	n->di_ctime = bswap32(o->di_ctime);
    102  1.1  bouyer 	n->di_ctimensec = bswap32(o->di_ctimensec);
    103  1.1  bouyer 	bcopy(o->di_db, n->di_db, (NDADDR + NIADDR) * sizeof(u_int32_t));
    104  1.1  bouyer 	n->di_flags = bswap32(o->di_flags);
    105  1.1  bouyer 	n->di_blocks = bswap32(o->di_blocks);
    106  1.1  bouyer 	n->di_gen = bswap32(o->di_gen);
    107  1.1  bouyer 	n->di_uid = bswap32(o->di_uid);
    108  1.1  bouyer 	n->di_gid = bswap32(o->di_gid);
    109  1.1  bouyer }
    110  1.1  bouyer 
    111  1.1  bouyer void
    112  1.1  bouyer ffs_csum_swap(o, n, size)
    113  1.1  bouyer 	struct csum *o, *n;
    114  1.1  bouyer 	int size;
    115  1.1  bouyer {
    116  1.1  bouyer 	int i;
    117  1.1  bouyer 	u_int32_t *oint, *nint;
    118  1.1  bouyer 
    119  1.1  bouyer 	oint = (u_int32_t*)o;
    120  1.1  bouyer 	nint = (u_int32_t*)n;
    121  1.1  bouyer 
    122  1.1  bouyer 	for (i = 0; i < size / sizeof(u_int32_t); i++)
    123  1.1  bouyer 		nint[i] = bswap32(oint[i]);
    124  1.1  bouyer }
    125