2 * Copyright (c) 2002-2004 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_OSREFERENCE_HEADER_START@
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. The rights granted to you under the
10 * License may not be used to create, or enable the creation or
11 * redistribution of, unlawful or unlicensed copies of an Apple operating
12 * system, or to circumvent, violate, or enable the circumvention or
13 * violation of, any terms of an Apple operating system software license
16 * Please obtain a copy of the License at
17 * http://www.opensource.apple.com/apsl/ and read it before using this
20 * The Original Code and all software distributed under the License are
21 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
22 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
23 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
24 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
25 * Please see the License for the specific language governing rights and
26 * limitations under the License.
28 * @APPLE_LICENSE_OSREFERENCE_HEADER_END@
32 * ufs_attrlist.c - UFS attribute list processing
34 * Copyright (c) 2002, Apple Computer, Inc. All Rights Reserved.
37 #include <sys/types.h>
38 #include <sys/systm.h>
39 #include <sys/vnode_internal.h>
40 #include <sys/malloc.h>
42 #include <sys/kernel.h>
43 #include <sys/kauth.h>
45 #include <ufs/ufs/dinode.h>
46 #include <ufs/ffs/fs.h>
47 #include <sys/mount_internal.h>
50 static char ufs_label_magic
[4] = UFS_LABEL_MAGIC
;
52 /* Copied from diskdev_cmds/disklib/ufslabel.c */
58 /* Copied from diskdev_cmds/disklib/ufslabel.c */
64 /* Copied from diskdev_cmds/disklib/ufslabel.c */
65 static __inline__
void
71 *sum
= l_util
.s
[0] + l_util
.s
[1];
77 /* Copied from diskdev_cmds/disklib/ufslabel.c */
78 __private_extern__
unsigned short
79 ul_cksum(void *data
, int len
)
86 while ((len
-= 32) >= 0) {
87 sum
+= w
[0]; sum
+= w
[1];
88 sum
+= w
[2]; sum
+= w
[3];
89 sum
+= w
[4]; sum
+= w
[5];
90 sum
+= w
[6]; sum
+= w
[7];
91 sum
+= w
[8]; sum
+= w
[9];
92 sum
+= w
[10]; sum
+= w
[11];
93 sum
+= w
[12]; sum
+= w
[13];
94 sum
+= w
[14]; sum
+= w
[15];
98 while ((len
-= 8) >= 0) {
99 sum
+= w
[0]; sum
+= w
[1];
100 sum
+= w
[2]; sum
+= w
[3];
106 while ((len
-= 2) >= 0) {
110 if (len
== -1) { /* odd-length data */
111 short_union_t s_util
;
114 s_util
.c
[0] = *((char *)w
);
119 return (~sum
& 0xffff);
122 /* Adapted from diskdev_cmds/disklib/ufslabel.c */
123 __private_extern__ boolean_t
124 ufs_label_check(struct ufslabel
*ul_p
)
129 if (bcmp(&ul_p
->ul_magic
, ufs_label_magic
,
130 sizeof(ul_p
->ul_magic
))) {
132 printf("ufslabel_check: label has bad magic number\n");
136 if (ntohl(ul_p
->ul_version
) != UFS_LABEL_VERSION
) {
138 printf("ufslabel_check: label has incorect version %d "
139 "(should be %d)\n", ntohl(ul_p
->ul_version
),
144 if (ntohs(ul_p
->ul_namelen
) > UFS_MAX_LABEL_NAME
) {
146 printf("ufslabel_check: name length %d is too big (> %d)\n",
147 ntohs(ul_p
->ul_namelen
), UFS_MAX_LABEL_NAME
);
152 checksum
= ul_p
->ul_checksum
; /* Remember previous checksum. */
153 ul_p
->ul_checksum
= 0;
154 calc
= ul_cksum(ul_p
, sizeof(*ul_p
));
155 if (calc
!= checksum
) {
157 printf("ufslabel_check: label checksum %x (should be %x)\n",
165 __private_extern__
void
166 ufs_label_init(struct ufslabel
*ul_p
)
172 bzero(ul_p
, sizeof(*ul_p
));
173 ul_p
->ul_version
= htonl(UFS_LABEL_VERSION
);
174 bcopy(ufs_label_magic
, &ul_p
->ul_magic
, sizeof(ul_p
->ul_magic
));
175 ul_p
->ul_time
= htonl(tv
.tv_sec
);