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.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or https://opensource.org/licenses/CDDL-1.0.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
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]
22 * Copyright 2010 Sun Microsystems, Inc. All rights reserved.
23 * Use is subject to license terms.
26 #include <sys/zfs_context.h>
28 #include <sys/fs/zfs.h>
29 #include <sys/zfs_znode.h>
30 #include <sys/zfs_sa.h>
31 #include <sys/zfs_acl.h>
37 zfs_oldace_byteswap(ace_t
*ace
, int ace_cnt
)
39 for (int 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
);
48 * swap ace_t and ace_object_t
54 zfs_ace_byteswap(void *buf
, size_t size
, boolean_t zfs_layout
)
58 zfs_ace_t
*zacep
= NULL
;
64 end
= (caddr_t
)buf
+ size
;
70 * Avoid overrun. Embedded aces can have one
71 * of several sizes. We don't know exactly
72 * how many our present, only the size of the
73 * buffer containing them. That size may be
74 * larger than needed to hold the aces
75 * present. As long as we do not do any
76 * swapping beyond the end of our block we are
77 * okay. It is safe to swap any non-ace data
78 * within the block since it is just zeros.
80 if (ptr
+ sizeof (zfs_ace_hdr_t
) > end
) {
83 zacep
= (zfs_ace_t
*)ptr
;
84 zacep
->z_hdr
.z_access_mask
=
85 BSWAP_32(zacep
->z_hdr
.z_access_mask
);
86 zacep
->z_hdr
.z_flags
= BSWAP_16(zacep
->z_hdr
.z_flags
);
87 ace_type
= zacep
->z_hdr
.z_type
=
88 BSWAP_16(zacep
->z_hdr
.z_type
);
89 entry_type
= zacep
->z_hdr
.z_flags
& ACE_TYPE_FLAGS
;
91 /* Overrun avoidance */
92 if (ptr
+ sizeof (ace_t
) > end
) {
96 acep
->a_access_mask
= BSWAP_32(acep
->a_access_mask
);
97 acep
->a_flags
= BSWAP_16(acep
->a_flags
);
98 ace_type
= acep
->a_type
= BSWAP_16(acep
->a_type
);
99 acep
->a_who
= BSWAP_32(acep
->a_who
);
100 entry_type
= acep
->a_flags
& ACE_TYPE_FLAGS
;
102 switch (entry_type
) {
105 case (ACE_IDENTIFIER_GROUP
| ACE_GROUP
):
106 entry_size
= zfs_layout
?
107 sizeof (zfs_ace_hdr_t
) : sizeof (ace_t
);
109 case ACE_IDENTIFIER_GROUP
:
111 /* Overrun avoidance */
113 if (ptr
+ sizeof (zfs_ace_t
) <= end
) {
114 zacep
->z_fuid
= BSWAP_64(zacep
->z_fuid
);
116 entry_size
= sizeof (zfs_ace_t
);
121 case ACE_ACCESS_ALLOWED_OBJECT_ACE_TYPE
:
122 case ACE_ACCESS_DENIED_OBJECT_ACE_TYPE
:
123 case ACE_SYSTEM_AUDIT_OBJECT_ACE_TYPE
:
124 case ACE_SYSTEM_ALARM_OBJECT_ACE_TYPE
:
125 entry_size
= zfs_layout
?
126 sizeof (zfs_object_ace_t
) :
127 sizeof (ace_object_t
);
130 entry_size
= zfs_layout
? sizeof (zfs_ace_t
) :
135 ptr
= ptr
+ entry_size
;
140 zfs_oldacl_byteswap(void *buf
, size_t size
)
143 * Arggh, since we don't know how many ACEs are in
144 * the array, we have to swap the entire block
146 zfs_oldace_byteswap((ace_t
*)buf
, size
/ sizeof (ace_t
));
150 zfs_acl_byteswap(void *buf
, size_t size
)
152 zfs_ace_byteswap(buf
, size
, B_TRUE
);
156 zfs_znode_byteswap(void *buf
, size_t size
)
158 znode_phys_t
*zp
= buf
;
160 ASSERT(size
>= sizeof (znode_phys_t
));
162 zp
->zp_crtime
[0] = BSWAP_64(zp
->zp_crtime
[0]);
163 zp
->zp_crtime
[1] = BSWAP_64(zp
->zp_crtime
[1]);
164 zp
->zp_atime
[0] = BSWAP_64(zp
->zp_atime
[0]);
165 zp
->zp_atime
[1] = BSWAP_64(zp
->zp_atime
[1]);
166 zp
->zp_mtime
[0] = BSWAP_64(zp
->zp_mtime
[0]);
167 zp
->zp_mtime
[1] = BSWAP_64(zp
->zp_mtime
[1]);
168 zp
->zp_ctime
[0] = BSWAP_64(zp
->zp_ctime
[0]);
169 zp
->zp_ctime
[1] = BSWAP_64(zp
->zp_ctime
[1]);
170 zp
->zp_gen
= BSWAP_64(zp
->zp_gen
);
171 zp
->zp_mode
= BSWAP_64(zp
->zp_mode
);
172 zp
->zp_size
= BSWAP_64(zp
->zp_size
);
173 zp
->zp_parent
= BSWAP_64(zp
->zp_parent
);
174 zp
->zp_links
= BSWAP_64(zp
->zp_links
);
175 zp
->zp_xattr
= BSWAP_64(zp
->zp_xattr
);
176 zp
->zp_rdev
= BSWAP_64(zp
->zp_rdev
);
177 zp
->zp_flags
= BSWAP_64(zp
->zp_flags
);
178 zp
->zp_uid
= BSWAP_64(zp
->zp_uid
);
179 zp
->zp_gid
= BSWAP_64(zp
->zp_gid
);
180 zp
->zp_zap
= BSWAP_64(zp
->zp_zap
);
181 zp
->zp_pad
[0] = BSWAP_64(zp
->zp_pad
[0]);
182 zp
->zp_pad
[1] = BSWAP_64(zp
->zp_pad
[1]);
183 zp
->zp_pad
[2] = BSWAP_64(zp
->zp_pad
[2]);
185 zp
->zp_acl
.z_acl_extern_obj
= BSWAP_64(zp
->zp_acl
.z_acl_extern_obj
);
186 zp
->zp_acl
.z_acl_size
= BSWAP_32(zp
->zp_acl
.z_acl_size
);
187 zp
->zp_acl
.z_acl_version
= BSWAP_16(zp
->zp_acl
.z_acl_version
);
188 zp
->zp_acl
.z_acl_count
= BSWAP_16(zp
->zp_acl
.z_acl_count
);
189 if (zp
->zp_acl
.z_acl_version
== ZFS_ACL_VERSION
) {
190 zfs_acl_byteswap((void *)&zp
->zp_acl
.z_ace_data
[0],
193 zfs_oldace_byteswap((ace_t
*)&zp
->zp_acl
.z_ace_data
[0],
199 EXPORT_SYMBOL(zfs_oldacl_byteswap
);
200 EXPORT_SYMBOL(zfs_acl_byteswap
);
201 EXPORT_SYMBOL(zfs_znode_byteswap
);