]> CyberLeo.Net >> Repos - FreeBSD/releng/7.2.git/blob - sys/cddl/contrib/opensolaris/uts/common/fs/zfs/zfs_byteswap.c
Create releng/7.2 from stable/7 in preparation for 7.2-RELEASE.
[FreeBSD/releng/7.2.git] / sys / cddl / contrib / opensolaris / uts / common / fs / zfs / zfs_byteswap.c
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License, Version 1.0 only
6  * (the "License").  You may not use this file except in compliance
7  * with the License.
8  *
9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10  * or http://www.opensolaris.org/os/licensing.
11  * See the License for the specific language governing permissions
12  * and limitations under the License.
13  *
14  * When distributing Covered Code, include this CDDL HEADER in each
15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16  * If applicable, add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your own identifying
18  * information: Portions Copyright [yyyy] [name of copyright owner]
19  *
20  * CDDL HEADER END
21  */
22 /*
23  * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26
27 #pragma ident   "%Z%%M% %I%     %E% SMI"
28
29 #include <sys/zfs_context.h>
30 #include <sys/vfs.h>
31 #include <sys/fs/zfs.h>
32 #include <sys/zfs_znode.h>
33 #include <sys/zfs_acl.h>
34
35 void
36 zfs_ace_byteswap(ace_t *ace, int ace_cnt)
37 {
38         int i;
39
40         for (i = 0; i != ace_cnt; i++, ace++) {
41                 ace->a_who = BSWAP_32(ace->a_who);
42                 ace->a_access_mask = BSWAP_32(ace->a_access_mask);
43                 ace->a_flags = BSWAP_16(ace->a_flags);
44                 ace->a_type = BSWAP_16(ace->a_type);
45         }
46 }
47
48 /* ARGSUSED */
49 void
50 zfs_acl_byteswap(void *buf, size_t size)
51 {
52         int cnt;
53
54         /*
55          * Arggh, since we don't know how many ACEs are in
56          * the array, we have to swap the entire block
57          */
58
59         cnt = size / sizeof (ace_t);
60
61         zfs_ace_byteswap((ace_t *)buf, cnt);
62 }
63
64 void
65 zfs_znode_byteswap(void *buf, size_t size)
66 {
67         znode_phys_t *zp = buf;
68
69         ASSERT(size >= sizeof (znode_phys_t));
70
71         zp->zp_crtime[0] = BSWAP_64(zp->zp_crtime[0]);
72         zp->zp_crtime[1] = BSWAP_64(zp->zp_crtime[1]);
73         zp->zp_atime[0] = BSWAP_64(zp->zp_atime[0]);
74         zp->zp_atime[1] = BSWAP_64(zp->zp_atime[1]);
75         zp->zp_mtime[0] = BSWAP_64(zp->zp_mtime[0]);
76         zp->zp_mtime[1] = BSWAP_64(zp->zp_mtime[1]);
77         zp->zp_ctime[0] = BSWAP_64(zp->zp_ctime[0]);
78         zp->zp_ctime[1] = BSWAP_64(zp->zp_ctime[1]);
79         zp->zp_gen = BSWAP_64(zp->zp_gen);
80         zp->zp_mode = BSWAP_64(zp->zp_mode);
81         zp->zp_size = BSWAP_64(zp->zp_size);
82         zp->zp_parent = BSWAP_64(zp->zp_parent);
83         zp->zp_links = BSWAP_64(zp->zp_links);
84         zp->zp_xattr = BSWAP_64(zp->zp_xattr);
85         zp->zp_rdev = BSWAP_64(zp->zp_rdev);
86         zp->zp_flags = BSWAP_64(zp->zp_flags);
87         zp->zp_uid = BSWAP_64(zp->zp_uid);
88         zp->zp_gid = BSWAP_64(zp->zp_gid);
89         zp->zp_pad[0] = BSWAP_64(zp->zp_pad[0]);
90         zp->zp_pad[1] = BSWAP_64(zp->zp_pad[1]);
91         zp->zp_pad[2] = BSWAP_64(zp->zp_pad[2]);
92         zp->zp_pad[3] = BSWAP_64(zp->zp_pad[3]);
93
94         zp->zp_acl.z_acl_extern_obj = BSWAP_64(zp->zp_acl.z_acl_extern_obj);
95         zp->zp_acl.z_acl_count = BSWAP_32(zp->zp_acl.z_acl_count);
96         zp->zp_acl.z_acl_version = BSWAP_16(zp->zp_acl.z_acl_version);
97         zp->zp_acl.z_acl_pad = BSWAP_16(zp->zp_acl.z_acl_pad);
98         zfs_ace_byteswap(&zp->zp_acl.z_ace_data[0], ACE_SLOT_CNT);
99 }