1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
|
/* $OpenBSD: kvm_udf.c,v 1.4 2011/07/04 20:35:35 deraadt Exp $ */
/*
* Copyright (c) 2001, 2002 Scott Long <scottl@freebsd.org>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#include <sys/param.h>
#include <sys/ucred.h>
#define _KERNEL
#include <sys/mount.h>
#undef _KERNEL
#include <sys/vnode.h>
#include <sys/sysctl.h>
#include <sys/specdev.h>
#include <isofs/udf/ecma167-udf.h>
#include <isofs/udf/udf.h>
#include <isofs/udf/udf_extern.h>
#include <stdint.h>
#include <limits.h>
#include <kvm.h>
#include <db.h>
#include "kvm_private.h"
/* Convert file entry permission (5 bits per owner/group/user) to a mode_t */
static mode_t
udf_permtomode(struct unode *up)
{
uint32_t perm;
uint16_t flags;
mode_t mode;
perm = letoh32(up->u_fentry->perm);
flags = letoh16(up->u_fentry->icbtag.flags);
mode = perm & UDF_FENTRY_PERM_USER_MASK;
mode |= ((perm & UDF_FENTRY_PERM_GRP_MASK) >> 2);
mode |= ((perm & UDF_FENTRY_PERM_OWNER_MASK) >> 4);
mode |= ((flags & UDF_ICB_TAG_FLAGS_STICKY) << 4);
mode |= ((flags & UDF_ICB_TAG_FLAGS_SETGID) << 6);
mode |= ((flags & UDF_ICB_TAG_FLAGS_SETUID) << 8);
return (mode);
}
int
_kvm_stat_udf(kvm_t *kd, struct kinfo_file2 *kf, struct vnode *vp)
{
struct unode up;
struct file_entry fentry;
struct umount um;
if (KREAD(kd, (u_long)VTOU(vp), &up)) {
_kvm_err(kd, kd->program, "can't read unode at %p", VTOU(vp));
return (-1);
}
if (KREAD(kd, (u_long)up.u_fentry, &fentry)) {
_kvm_err(kd, kd->program, "can't read file_entry at %p",
up.u_fentry);
return (-1);
}
if (KREAD(kd, (u_long)up.u_ump, &um)) {
_kvm_err(kd, kd->program, "can't read umount at %p",
up.u_ump);
return (-1);
}
kf->va_fsid = up.u_dev;
kf->va_fileid = (long)up.u_ino;
kf->va_mode = udf_permtomode(&up); /* XXX */
kf->va_rdev = 0;
if (vp->v_type & VDIR) {
/*
* Directories that are recorded within their ICB will show
* as having 0 blocks recorded. Since tradition dictates
* that directories consume at least one logical block,
* make it appear so.
*/
if (fentry.logblks_rec != 0) {
kf->va_size =
letoh64(fentry.logblks_rec) * um.um_bsize;
} else {
kf->va_size = um.um_bsize;
}
} else {
kf->va_size = letoh64(fentry.inf_len);
}
return (0);
}
|