The Design and Implementation of the FreeBSD Operating System, Second Edition
Now available: The Design and Implementation of the FreeBSD Operating System (Second Edition)


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]

FreeBSD/Linux Kernel Cross Reference
sys/ufs/ext2fs/ext2fs_bswap.c

Version: -  FREEBSD  -  FREEBSD-13-STABLE  -  FREEBSD-13-0  -  FREEBSD-12-STABLE  -  FREEBSD-12-0  -  FREEBSD-11-STABLE  -  FREEBSD-11-0  -  FREEBSD-10-STABLE  -  FREEBSD-10-0  -  FREEBSD-9-STABLE  -  FREEBSD-9-0  -  FREEBSD-8-STABLE  -  FREEBSD-8-0  -  FREEBSD-7-STABLE  -  FREEBSD-7-0  -  FREEBSD-6-STABLE  -  FREEBSD-6-0  -  FREEBSD-5-STABLE  -  FREEBSD-5-0  -  FREEBSD-4-STABLE  -  FREEBSD-3-STABLE  -  FREEBSD22  -  l41  -  OPENBSD  -  linux-2.6  -  MK84  -  PLAN9  -  xnu-8792 
SearchContext: -  none  -  3  -  10 

    1 /*      $NetBSD: ext2fs_bswap.c,v 1.8 2003/10/05 17:48:49 bouyer 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 Manuel Bouyer.
   17  * 4. The name of the author may not be used to endorse or promote products
   18  *    derived from this software without specific prior written permission.
   19  *
   20  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
   21  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   22  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
   23  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
   24  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
   25  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
   26  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
   27  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
   28  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
   29  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
   30  *
   31  */
   32 
   33 #include <sys/cdefs.h>
   34 __KERNEL_RCSID(0, "$NetBSD: ext2fs_bswap.c,v 1.8 2003/10/05 17:48:49 bouyer Exp $");
   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 #if !defined(_KERNEL)
   42 #include <string.h>
   43 #endif
   44 
   45 /* These functions are only needed if native byte order is not big endian */
   46 #if BYTE_ORDER == BIG_ENDIAN
   47 void
   48 e2fs_sb_bswap(old, new)
   49         struct ext2fs *old, *new;
   50 {
   51         /* preserve unused fields */
   52         memcpy(new, old, sizeof(struct ext2fs));
   53         new->e2fs_icount        =       bswap32(old->e2fs_icount);
   54         new->e2fs_bcount        =       bswap32(old->e2fs_bcount);
   55         new->e2fs_rbcount       =       bswap32(old->e2fs_rbcount);
   56         new->e2fs_fbcount       =       bswap32(old->e2fs_fbcount);
   57         new->e2fs_ficount       =       bswap32(old->e2fs_ficount);
   58         new->e2fs_first_dblock  =       bswap32(old->e2fs_first_dblock);
   59         new->e2fs_log_bsize     =       bswap32(old->e2fs_log_bsize);
   60         new->e2fs_fsize         =       bswap32(old->e2fs_fsize);
   61         new->e2fs_bpg           =       bswap32(old->e2fs_bpg);
   62         new->e2fs_fpg           =       bswap32(old->e2fs_fpg);
   63         new->e2fs_ipg           =       bswap32(old->e2fs_ipg);
   64         new->e2fs_mtime         =       bswap32(old->e2fs_mtime);
   65         new->e2fs_wtime         =       bswap32(old->e2fs_wtime);
   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_minrev        =       bswap16(old->e2fs_minrev);
   72         new->e2fs_lastfsck      =       bswap32(old->e2fs_lastfsck);
   73         new->e2fs_fsckintv      =       bswap32(old->e2fs_fsckintv);
   74         new->e2fs_creator       =       bswap32(old->e2fs_creator);
   75         new->e2fs_rev           =       bswap32(old->e2fs_rev);
   76         new->e2fs_ruid          =       bswap16(old->e2fs_ruid);
   77         new->e2fs_rgid          =       bswap16(old->e2fs_rgid);
   78         new->e2fs_first_ino     =       bswap32(old->e2fs_first_ino);
   79         new->e2fs_inode_size    =       bswap16(old->e2fs_inode_size);
   80         new->e2fs_block_group_nr =      bswap16(old->e2fs_block_group_nr);
   81         new->e2fs_features_compat =     bswap32(old->e2fs_features_compat);
   82         new->e2fs_features_incompat =   bswap32(old->e2fs_features_incompat);
   83         new->e2fs_features_rocompat =   bswap32(old->e2fs_features_rocompat);
   84         new->e2fs_algo          =       bswap32(old->e2fs_algo);
   85 }
   86 
   87 void e2fs_cg_bswap(old, new, size)
   88         struct  ext2_gd *old, *new;
   89         int size;
   90 {
   91         int i;
   92         for (i=0; i < (size / sizeof(struct  ext2_gd)); i++) {
   93                 new[i].ext2bgd_b_bitmap = bswap32(old[i].ext2bgd_b_bitmap);
   94                 new[i].ext2bgd_i_bitmap = bswap32(old[i].ext2bgd_i_bitmap);
   95                 new[i].ext2bgd_i_tables = bswap32(old[i].ext2bgd_i_tables);
   96                 new[i].ext2bgd_nbfree   = bswap16(old[i].ext2bgd_nbfree);
   97                 new[i].ext2bgd_nifree   = bswap16(old[i].ext2bgd_nifree);
   98                 new[i].ext2bgd_ndirs    = bswap16(old[i].ext2bgd_ndirs);
   99         }
  100 }
  101 
  102 void e2fs_i_bswap(old, new)
  103         struct ext2fs_dinode *old, *new;
  104 {
  105         new->e2di_mode          =       bswap16(old->e2di_mode);
  106         new->e2di_uid           =       bswap16(old->e2di_uid);
  107         new->e2di_gid           =       bswap16(old->e2di_gid);
  108         new->e2di_nlink         =       bswap16(old->e2di_nlink);
  109         new->e2di_size          =       bswap32(old->e2di_size);
  110         new->e2di_atime         =       bswap32(old->e2di_atime);
  111         new->e2di_ctime         =       bswap32(old->e2di_ctime);
  112         new->e2di_mtime         =       bswap32(old->e2di_mtime);
  113         new->e2di_dtime         =       bswap32(old->e2di_dtime);
  114         new->e2di_nblock        =       bswap32(old->e2di_nblock);
  115         new->e2di_flags         =       bswap32(old->e2di_flags);
  116         new->e2di_gen           =       bswap32(old->e2di_gen);
  117         new->e2di_facl          =       bswap32(old->e2di_facl);
  118         new->e2di_dacl          =       bswap32(old->e2di_dacl);
  119         new->e2di_faddr         =       bswap32(old->e2di_faddr);
  120         memcpy(&new->e2di_blocks[0], &old->e2di_blocks[0],
  121                 (NDADDR+NIADDR) * sizeof(int));
  122 }
  123 #endif

Cache object: 4017a76b38e5663e3f026d164d5bc781


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]


This page is part of the FreeBSD/Linux Linux Kernel Cross-Reference, and was automatically generated using a modified version of the LXR engine.