]> CyberLeo.Net >> Repos - FreeBSD/releng/8.0.git/blob - sys/cddl/contrib/opensolaris/uts/common/fs/zfs/zfs_byteswap.c
Adjust to reflect 8.0-RELEASE.
[FreeBSD/releng/8.0.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 (the "License").
6  * You may not use this file except in compliance with the License.
7  *
8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9  * or http://www.opensolaris.org/os/licensing.
10  * See the License for the specific language governing permissions
11  * and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL HEADER in each
14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15  * If applicable, add the following below this CDDL HEADER, with the
16  * fields enclosed by brackets "[]" replaced with your own identifying
17  * information: Portions Copyright [yyyy] [name of copyright owner]
18  *
19  * CDDL HEADER END
20  */
21 /*
22  * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
23  * Use is subject to license terms.
24  */
25
26 #pragma ident   "%Z%%M% %I%     %E% SMI"
27
28 #include <sys/zfs_context.h>
29 #include <sys/vfs.h>
30 #include <sys/fs/zfs.h>
31 #include <sys/zfs_znode.h>
32 #include <sys/zfs_acl.h>
33
34 void
35 zfs_oldace_byteswap(ace_t *ace, int ace_cnt)
36 {
37         int i;
38
39         for (i = 0; i != ace_cnt; i++, ace++) {
40                 ace->a_who = BSWAP_32(ace->a_who);
41                 ace->a_access_mask = BSWAP_32(ace->a_access_mask);
42                 ace->a_flags = BSWAP_16(ace->a_flags);
43                 ace->a_type = BSWAP_16(ace->a_type);
44         }
45 }
46
47 /*
48  * swap ace_t and ace_oject_t
49  */
50 void
51 zfs_ace_byteswap(void *buf, size_t size, boolean_t zfs_layout)
52 {
53 #ifdef TODO
54         caddr_t end;
55         caddr_t ptr;
56         zfs_ace_t *zacep;
57         ace_t *acep;
58         uint16_t entry_type;
59         size_t entry_size;
60         int ace_type;
61
62         end = (caddr_t)buf + size;
63         ptr = buf;
64
65         while (ptr < end) {
66                 if (zfs_layout) {
67                         zacep = (zfs_ace_t *)ptr;
68                         zacep->z_hdr.z_access_mask =
69                             BSWAP_32(zacep->z_hdr.z_access_mask);
70                         zacep->z_hdr.z_flags = BSWAP_16(zacep->z_hdr.z_flags);
71                         ace_type = zacep->z_hdr.z_type =
72                             BSWAP_16(zacep->z_hdr.z_type);
73                         entry_type = zacep->z_hdr.z_flags & ACE_TYPE_FLAGS;
74                 } else {
75                         acep = (ace_t *)ptr;
76                         acep->a_access_mask = BSWAP_32(acep->a_access_mask);
77                         acep->a_flags = BSWAP_16(acep->a_flags);
78                         ace_type = acep->a_type = BSWAP_16(acep->a_type);
79                         acep->a_who = BSWAP_32(acep->a_who);
80                         entry_type = acep->a_flags & ACE_TYPE_FLAGS;
81                 }
82                 switch (entry_type) {
83                 case ACE_OWNER:
84                 case ACE_EVERYONE:
85                 case (ACE_IDENTIFIER_GROUP | ACE_GROUP):
86                         entry_size = zfs_layout ?
87                             sizeof (zfs_ace_hdr_t) : sizeof (ace_t);
88                         break;
89                 case ACE_IDENTIFIER_GROUP:
90                 default:
91                         if (zfs_layout) {
92                                 zacep->z_fuid = BSWAP_64(zacep->z_fuid);
93                         }
94                         switch (ace_type) {
95                         case ACE_ACCESS_ALLOWED_OBJECT_ACE_TYPE:
96                         case ACE_ACCESS_DENIED_OBJECT_ACE_TYPE:
97                         case ACE_SYSTEM_AUDIT_OBJECT_ACE_TYPE:
98                         case ACE_SYSTEM_ALARM_OBJECT_ACE_TYPE:
99                                 entry_size = zfs_layout ?
100                                     sizeof (zfs_object_ace_t) :
101                                     sizeof (ace_object_t);
102                                 break;
103                         default:
104                                 entry_size = zfs_layout ? sizeof (zfs_ace_t) :
105                                     sizeof (ace_t);
106                                 break;
107                         }
108                 }
109                 ptr = ptr + entry_size;
110         }
111 #else   /* TODO */
112         panic("%s:%u: TODO", __func__, __LINE__);
113 #endif  /* TODO */
114 }
115
116 /* ARGSUSED */
117 void
118 zfs_oldacl_byteswap(void *buf, size_t size)
119 {
120         int cnt;
121
122         /*
123          * Arggh, since we don't know how many ACEs are in
124          * the array, we have to swap the entire block
125          */
126
127         cnt = size / sizeof (ace_t);
128
129         zfs_oldace_byteswap((ace_t *)buf, cnt);
130 }
131
132 /* ARGSUSED */
133 void
134 zfs_acl_byteswap(void *buf, size_t size)
135 {
136         zfs_ace_byteswap(buf, size, B_TRUE);
137 }
138
139 void
140 zfs_znode_byteswap(void *buf, size_t size)
141 {
142         znode_phys_t *zp = buf;
143
144         ASSERT(size >= sizeof (znode_phys_t));
145
146         zp->zp_crtime[0] = BSWAP_64(zp->zp_crtime[0]);
147         zp->zp_crtime[1] = BSWAP_64(zp->zp_crtime[1]);
148         zp->zp_atime[0] = BSWAP_64(zp->zp_atime[0]);
149         zp->zp_atime[1] = BSWAP_64(zp->zp_atime[1]);
150         zp->zp_mtime[0] = BSWAP_64(zp->zp_mtime[0]);
151         zp->zp_mtime[1] = BSWAP_64(zp->zp_mtime[1]);
152         zp->zp_ctime[0] = BSWAP_64(zp->zp_ctime[0]);
153         zp->zp_ctime[1] = BSWAP_64(zp->zp_ctime[1]);
154         zp->zp_gen = BSWAP_64(zp->zp_gen);
155         zp->zp_mode = BSWAP_64(zp->zp_mode);
156         zp->zp_size = BSWAP_64(zp->zp_size);
157         zp->zp_parent = BSWAP_64(zp->zp_parent);
158         zp->zp_links = BSWAP_64(zp->zp_links);
159         zp->zp_xattr = BSWAP_64(zp->zp_xattr);
160         zp->zp_rdev = BSWAP_64(zp->zp_rdev);
161         zp->zp_flags = BSWAP_64(zp->zp_flags);
162         zp->zp_uid = BSWAP_64(zp->zp_uid);
163         zp->zp_gid = BSWAP_64(zp->zp_gid);
164         zp->zp_zap = BSWAP_64(zp->zp_zap);
165         zp->zp_pad[0] = BSWAP_64(zp->zp_pad[0]);
166         zp->zp_pad[1] = BSWAP_64(zp->zp_pad[1]);
167         zp->zp_pad[2] = BSWAP_64(zp->zp_pad[2]);
168
169         zp->zp_acl.z_acl_extern_obj = BSWAP_64(zp->zp_acl.z_acl_extern_obj);
170         zp->zp_acl.z_acl_size = BSWAP_32(zp->zp_acl.z_acl_size);
171         zp->zp_acl.z_acl_version = BSWAP_16(zp->zp_acl.z_acl_version);
172         zp->zp_acl.z_acl_count = BSWAP_16(zp->zp_acl.z_acl_count);
173         if (zp->zp_acl.z_acl_version == ZFS_ACL_VERSION) {
174                 zfs_acl_byteswap((void *)&zp->zp_acl.z_ace_data[0],
175                     ZFS_ACE_SPACE);
176         } else
177                 zfs_oldace_byteswap((ace_t *)&zp->zp_acl.z_ace_data[0],
178                     ACE_SLOT_CNT);
179 }