2 * Copyright (c) 2002-2004 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * The contents of this file constitute Original Code as defined in and
7 * are subject to the Apple Public Source License Version 1.1 (the
8 * "License"). You may not use this file except in compliance with the
9 * License. Please obtain a copy of the License at
10 * http://www.apple.com/publicsource and read it before using this file.
12 * This Original Code and all software distributed under the License are
13 * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
14 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
15 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
17 * License for the specific language governing rights and limitations
20 * @APPLE_LICENSE_HEADER_END@
24 * ufs_attrlist.c - UFS attribute list processing
26 * Copyright (c) 2002, Apple Computer, Inc. All Rights Reserved.
29 #include <sys/types.h>
30 #include <sys/systm.h>
31 #include <sys/vnode_internal.h>
32 #include <sys/malloc.h>
34 #include <sys/kernel.h>
35 #include <sys/kauth.h>
37 #include <architecture/byte_order.h>
38 #include <ufs/ufs/dinode.h>
39 #include <ufs/ffs/fs.h>
40 #include <sys/mount_internal.h>
43 static char ufs_label_magic
[4] = UFS_LABEL_MAGIC
;
45 /* Copied from diskdev_cmds/disklib/ufslabel.c */
51 /* Copied from diskdev_cmds/disklib/ufslabel.c */
57 /* Copied from diskdev_cmds/disklib/ufslabel.c */
58 static __inline__
void
64 *sum
= l_util
.s
[0] + l_util
.s
[1];
70 /* Copied from diskdev_cmds/disklib/ufslabel.c */
71 __private_extern__
unsigned short
72 ul_cksum(void *data
, int len
)
79 while ((len
-= 32) >= 0) {
80 sum
+= w
[0]; sum
+= w
[1];
81 sum
+= w
[2]; sum
+= w
[3];
82 sum
+= w
[4]; sum
+= w
[5];
83 sum
+= w
[6]; sum
+= w
[7];
84 sum
+= w
[8]; sum
+= w
[9];
85 sum
+= w
[10]; sum
+= w
[11];
86 sum
+= w
[12]; sum
+= w
[13];
87 sum
+= w
[14]; sum
+= w
[15];
91 while ((len
-= 8) >= 0) {
92 sum
+= w
[0]; sum
+= w
[1];
93 sum
+= w
[2]; sum
+= w
[3];
99 while ((len
-= 2) >= 0) {
103 if (len
== -1) { /* odd-length data */
104 short_union_t s_util
;
107 s_util
.c
[0] = *((char *)w
);
112 return (~sum
& 0xffff);
115 /* Adapted from diskdev_cmds/disklib/ufslabel.c */
116 __private_extern__ boolean_t
117 ufs_label_check(struct ufslabel
*ul_p
)
122 if (bcmp(&ul_p
->ul_magic
, ufs_label_magic
,
123 sizeof(ul_p
->ul_magic
))) {
125 printf("ufslabel_check: label has bad magic number\n");
129 if (ntohl(ul_p
->ul_version
) != UFS_LABEL_VERSION
) {
131 printf("ufslabel_check: label has incorect version %d "
132 "(should be %d)\n", ntohl(ul_p
->ul_version
),
137 if (ntohs(ul_p
->ul_namelen
) > UFS_MAX_LABEL_NAME
) {
139 printf("ufslabel_check: name length %d is too big (> %d)\n",
140 ntohs(ul_p
->ul_namelen
), UFS_MAX_LABEL_NAME
);
145 checksum
= ul_p
->ul_checksum
; /* Remember previous checksum. */
146 ul_p
->ul_checksum
= 0;
147 calc
= ul_cksum(ul_p
, sizeof(*ul_p
));
148 if (calc
!= checksum
) {
150 printf("ufslabel_check: label checksum %x (should be %x)\n",
158 __private_extern__
void
159 ufs_label_init(struct ufslabel
*ul_p
)
165 bzero(ul_p
, sizeof(*ul_p
));
166 ul_p
->ul_version
= htonl(UFS_LABEL_VERSION
);
167 bcopy(ufs_label_magic
, &ul_p
->ul_magic
, sizeof(ul_p
->ul_magic
));
168 ul_p
->ul_time
= htonl(tv
.tv_sec
);