1789Sahrens /*
2789Sahrens * CDDL HEADER START
3789Sahrens *
4789Sahrens * The contents of this file are subject to the terms of the
55331Samw * Common Development and Distribution License (the "License").
65331Samw * You may not use this file except in compliance with the License.
7789Sahrens *
8789Sahrens * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9789Sahrens * or http://www.opensolaris.org/os/licensing.
10789Sahrens * See the License for the specific language governing permissions
11789Sahrens * and limitations under the License.
12789Sahrens *
13789Sahrens * When distributing Covered Code, include this CDDL HEADER in each
14789Sahrens * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15789Sahrens * If applicable, add the following below this CDDL HEADER, with the
16789Sahrens * fields enclosed by brackets "[]" replaced with your own identifying
17789Sahrens * information: Portions Copyright [yyyy] [name of copyright owner]
18789Sahrens *
19789Sahrens * CDDL HEADER END
20789Sahrens */
21789Sahrens /*
22*11935SMark.Shellenbaum@Sun.COM * Copyright 2010 Sun Microsystems, Inc. All rights reserved.
23789Sahrens * Use is subject to license terms.
24789Sahrens */
25789Sahrens
26789Sahrens #include <sys/zfs_context.h>
27789Sahrens #include <sys/vfs.h>
28789Sahrens #include <sys/fs/zfs.h>
29789Sahrens #include <sys/zfs_znode.h>
30*11935SMark.Shellenbaum@Sun.COM #include <sys/zfs_sa.h>
31789Sahrens #include <sys/zfs_acl.h>
32789Sahrens
33789Sahrens void
zfs_oldace_byteswap(ace_t * ace,int ace_cnt)345331Samw zfs_oldace_byteswap(ace_t *ace, int ace_cnt)
35789Sahrens {
36789Sahrens int i;
37789Sahrens
38789Sahrens for (i = 0; i != ace_cnt; i++, ace++) {
39789Sahrens ace->a_who = BSWAP_32(ace->a_who);
40789Sahrens ace->a_access_mask = BSWAP_32(ace->a_access_mask);
41789Sahrens ace->a_flags = BSWAP_16(ace->a_flags);
42789Sahrens ace->a_type = BSWAP_16(ace->a_type);
43789Sahrens }
44789Sahrens }
45789Sahrens
465331Samw /*
475331Samw * swap ace_t and ace_oject_t
485331Samw */
495331Samw void
zfs_ace_byteswap(void * buf,size_t size,boolean_t zfs_layout)505331Samw zfs_ace_byteswap(void *buf, size_t size, boolean_t zfs_layout)
515331Samw {
525331Samw caddr_t end;
535331Samw caddr_t ptr;
545331Samw zfs_ace_t *zacep;
555331Samw ace_t *acep;
565331Samw uint16_t entry_type;
575331Samw size_t entry_size;
585331Samw int ace_type;
595331Samw
605331Samw end = (caddr_t)buf + size;
615331Samw ptr = buf;
625331Samw
635331Samw while (ptr < end) {
645331Samw if (zfs_layout) {
658283STim.Haley@Sun.COM /*
668283STim.Haley@Sun.COM * Avoid overrun. Embedded aces can have one
678283STim.Haley@Sun.COM * of several sizes. We don't know exactly
688283STim.Haley@Sun.COM * how many our present, only the size of the
698283STim.Haley@Sun.COM * buffer containing them. That size may be
708283STim.Haley@Sun.COM * larger than needed to hold the aces
718283STim.Haley@Sun.COM * present. As long as we do not do any
728283STim.Haley@Sun.COM * swapping beyond the end of our block we are
738283STim.Haley@Sun.COM * okay. It it safe to swap any non-ace data
748283STim.Haley@Sun.COM * within the block since it is just zeros.
758283STim.Haley@Sun.COM */
768283STim.Haley@Sun.COM if (ptr + sizeof (zfs_ace_hdr_t) > end) {
778283STim.Haley@Sun.COM break;
788283STim.Haley@Sun.COM }
795331Samw zacep = (zfs_ace_t *)ptr;
805331Samw zacep->z_hdr.z_access_mask =
815331Samw BSWAP_32(zacep->z_hdr.z_access_mask);
825331Samw zacep->z_hdr.z_flags = BSWAP_16(zacep->z_hdr.z_flags);
835331Samw ace_type = zacep->z_hdr.z_type =
845331Samw BSWAP_16(zacep->z_hdr.z_type);
855331Samw entry_type = zacep->z_hdr.z_flags & ACE_TYPE_FLAGS;
865331Samw } else {
878283STim.Haley@Sun.COM /* Overrun avoidance */
888283STim.Haley@Sun.COM if (ptr + sizeof (ace_t) > end) {
898283STim.Haley@Sun.COM break;
908283STim.Haley@Sun.COM }
915331Samw acep = (ace_t *)ptr;
925331Samw acep->a_access_mask = BSWAP_32(acep->a_access_mask);
935331Samw acep->a_flags = BSWAP_16(acep->a_flags);
945331Samw ace_type = acep->a_type = BSWAP_16(acep->a_type);
955331Samw acep->a_who = BSWAP_32(acep->a_who);
965331Samw entry_type = acep->a_flags & ACE_TYPE_FLAGS;
975331Samw }
985331Samw switch (entry_type) {
995331Samw case ACE_OWNER:
1005331Samw case ACE_EVERYONE:
1015331Samw case (ACE_IDENTIFIER_GROUP | ACE_GROUP):
1025331Samw entry_size = zfs_layout ?
1035331Samw sizeof (zfs_ace_hdr_t) : sizeof (ace_t);
1045331Samw break;
1055331Samw case ACE_IDENTIFIER_GROUP:
1065331Samw default:
1078283STim.Haley@Sun.COM /* Overrun avoidance */
1085331Samw if (zfs_layout) {
1098283STim.Haley@Sun.COM if (ptr + sizeof (zfs_ace_t) <= end) {
1108283STim.Haley@Sun.COM zacep->z_fuid = BSWAP_64(zacep->z_fuid);
1118283STim.Haley@Sun.COM } else {
1128283STim.Haley@Sun.COM entry_size = sizeof (zfs_ace_t);
1138283STim.Haley@Sun.COM break;
1148283STim.Haley@Sun.COM }
1155331Samw }
1165331Samw switch (ace_type) {
1175331Samw case ACE_ACCESS_ALLOWED_OBJECT_ACE_TYPE:
1185331Samw case ACE_ACCESS_DENIED_OBJECT_ACE_TYPE:
1195331Samw case ACE_SYSTEM_AUDIT_OBJECT_ACE_TYPE:
1205331Samw case ACE_SYSTEM_ALARM_OBJECT_ACE_TYPE:
1215331Samw entry_size = zfs_layout ?
1225331Samw sizeof (zfs_object_ace_t) :
1235331Samw sizeof (ace_object_t);
1245331Samw break;
1255331Samw default:
1265331Samw entry_size = zfs_layout ? sizeof (zfs_ace_t) :
1275331Samw sizeof (ace_t);
1285331Samw break;
1295331Samw }
1305331Samw }
1315331Samw ptr = ptr + entry_size;
1325331Samw }
1335331Samw }
1345331Samw
135789Sahrens /* ARGSUSED */
136789Sahrens void
zfs_oldacl_byteswap(void * buf,size_t size)1375331Samw zfs_oldacl_byteswap(void *buf, size_t size)
138789Sahrens {
139789Sahrens int cnt;
140789Sahrens
141789Sahrens /*
142789Sahrens * Arggh, since we don't know how many ACEs are in
143789Sahrens * the array, we have to swap the entire block
144789Sahrens */
145789Sahrens
146789Sahrens cnt = size / sizeof (ace_t);
147789Sahrens
1485331Samw zfs_oldace_byteswap((ace_t *)buf, cnt);
1495331Samw }
1505331Samw
1515331Samw /* ARGSUSED */
1525331Samw void
zfs_acl_byteswap(void * buf,size_t size)1535331Samw zfs_acl_byteswap(void *buf, size_t size)
1545331Samw {
1555331Samw zfs_ace_byteswap(buf, size, B_TRUE);
156789Sahrens }
157789Sahrens
158789Sahrens void
zfs_znode_byteswap(void * buf,size_t size)159789Sahrens zfs_znode_byteswap(void *buf, size_t size)
160789Sahrens {
161789Sahrens znode_phys_t *zp = buf;
162789Sahrens
163789Sahrens ASSERT(size >= sizeof (znode_phys_t));
164789Sahrens
165789Sahrens zp->zp_crtime[0] = BSWAP_64(zp->zp_crtime[0]);
166789Sahrens zp->zp_crtime[1] = BSWAP_64(zp->zp_crtime[1]);
167789Sahrens zp->zp_atime[0] = BSWAP_64(zp->zp_atime[0]);
168789Sahrens zp->zp_atime[1] = BSWAP_64(zp->zp_atime[1]);
169789Sahrens zp->zp_mtime[0] = BSWAP_64(zp->zp_mtime[0]);
170789Sahrens zp->zp_mtime[1] = BSWAP_64(zp->zp_mtime[1]);
171789Sahrens zp->zp_ctime[0] = BSWAP_64(zp->zp_ctime[0]);
172789Sahrens zp->zp_ctime[1] = BSWAP_64(zp->zp_ctime[1]);
173789Sahrens zp->zp_gen = BSWAP_64(zp->zp_gen);
174789Sahrens zp->zp_mode = BSWAP_64(zp->zp_mode);
175789Sahrens zp->zp_size = BSWAP_64(zp->zp_size);
176789Sahrens zp->zp_parent = BSWAP_64(zp->zp_parent);
177789Sahrens zp->zp_links = BSWAP_64(zp->zp_links);
178789Sahrens zp->zp_xattr = BSWAP_64(zp->zp_xattr);
179789Sahrens zp->zp_rdev = BSWAP_64(zp->zp_rdev);
180789Sahrens zp->zp_flags = BSWAP_64(zp->zp_flags);
181789Sahrens zp->zp_uid = BSWAP_64(zp->zp_uid);
182789Sahrens zp->zp_gid = BSWAP_64(zp->zp_gid);
1835331Samw zp->zp_zap = BSWAP_64(zp->zp_zap);
184789Sahrens zp->zp_pad[0] = BSWAP_64(zp->zp_pad[0]);
185789Sahrens zp->zp_pad[1] = BSWAP_64(zp->zp_pad[1]);
186789Sahrens zp->zp_pad[2] = BSWAP_64(zp->zp_pad[2]);
187789Sahrens
188789Sahrens zp->zp_acl.z_acl_extern_obj = BSWAP_64(zp->zp_acl.z_acl_extern_obj);
1895331Samw zp->zp_acl.z_acl_size = BSWAP_32(zp->zp_acl.z_acl_size);
190789Sahrens zp->zp_acl.z_acl_version = BSWAP_16(zp->zp_acl.z_acl_version);
1915331Samw zp->zp_acl.z_acl_count = BSWAP_16(zp->zp_acl.z_acl_count);
1925331Samw if (zp->zp_acl.z_acl_version == ZFS_ACL_VERSION) {
1935331Samw zfs_acl_byteswap((void *)&zp->zp_acl.z_ace_data[0],
1945331Samw ZFS_ACE_SPACE);
1958283STim.Haley@Sun.COM } else {
1965331Samw zfs_oldace_byteswap((ace_t *)&zp->zp_acl.z_ace_data[0],
1975331Samw ACE_SLOT_CNT);
1988283STim.Haley@Sun.COM }
199789Sahrens }
200