1221807Sstas/*-
2221807Sstas * Copyright (c) 2005-2009 Stanislav Sedov <stas@FreeBSD.org>
3221807Sstas * All rights reserved.
4221807Sstas *
5221807Sstas * Redistribution and use in source and binary forms, with or without
6221807Sstas * modification, are permitted provided that the following conditions
7221807Sstas * are met:
8221807Sstas * 1. Redistributions of source code must retain the above copyright
9221807Sstas *    notice, this list of conditions and the following disclaimer.
10221807Sstas * 2. Redistributions in binary form must reproduce the above copyright
11221807Sstas *    notice, this list of conditions and the following disclaimer in the
12221807Sstas *    documentation and/or other materials provided with the distribution.
13221807Sstas *
14221807Sstas * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15221807Sstas * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16221807Sstas * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17221807Sstas * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18221807Sstas * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19221807Sstas * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20221807Sstas * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21221807Sstas * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22221807Sstas * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23221807Sstas * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24221807Sstas * SUCH DAMAGE.
25221807Sstas */
26221807Sstas#include <sys/cdefs.h>
27221807Sstas__FBSDID("$FreeBSD$");
28221807Sstas
29221807Sstas#include <sys/param.h>
30221807Sstas#include <sys/stat.h>
31221807Sstas#include <sys/time.h>
32221807Sstas#include <sys/vnode.h>
33221807Sstas#include <sys/buf.h>
34221807Sstas#define _KERNEL
35221807Sstas#include <sys/mount.h>
36221807Sstas#undef _KERNEL
37221807Sstas
38221807Sstas#include <netinet/in.h>
39221807Sstas
40221807Sstas#include <assert.h>
41221807Sstas#include <err.h>
42221807Sstas#include <kvm.h>
43221807Sstas#include <stdlib.h>
44221807Sstas
45221807Sstas#include <fs/udf/ecma167-udf.h>
46221807Sstas
47221807Sstas#include "libprocstat.h"
48221807Sstas#include "common_kvm.h"
49221807Sstas
50221807Sstas/* XXX */
51221807Sstasstruct udf_mnt {
52221807Sstas	int			im_flags;
53221807Sstas	struct mount		*im_mountp;
54221807Sstas	struct g_consumer	*im_cp;
55221807Sstas	struct bufobj		*im_bo;
56221807Sstas	struct cdev		*im_dev;
57221807Sstas	struct vnode		*im_devvp;
58221807Sstas	int			bsize;
59221807Sstas	int			bshift;
60221807Sstas	int			bmask;
61221807Sstas	uint32_t		part_start;
62221807Sstas	uint32_t		part_len;
63221807Sstas	uint64_t		root_id;
64221807Sstas	struct long_ad		root_icb;
65221807Sstas	int			p_sectors;
66221807Sstas	int			s_table_entries;
67221807Sstas	void			*s_table;
68221807Sstas	void			*im_d2l;
69221807Sstas};
70221807Sstasstruct udf_node {
71221807Sstas	struct vnode	*i_vnode;
72221807Sstas	struct udf_mnt	*udfmp;
73221807Sstas	ino_t		hash_id;
74221807Sstas	long		diroff;
75221807Sstas	struct file_entry *fentry;
76221807Sstas};
77221807Sstas#define VTON(vp)	((struct udf_node *)((vp)->v_data))
78221807Sstas
79221807Sstasint
80221807Sstasudf_filestat(kvm_t *kd, struct vnode *vp, struct vnstat *vn)
81221807Sstas{
82221807Sstas	struct udf_node node;
83221807Sstas	struct udf_mnt mnt;
84221807Sstas	int error;
85221807Sstas
86221807Sstas	assert(kd);
87221807Sstas	assert(vn);
88221807Sstas	error = kvm_read_all(kd, (unsigned long)VTON(vp), &node, sizeof(node));
89221807Sstas	if (error != 0) {
90221807Sstas		warnx("can't read udf fnode at %p", (void *)VTON(vp));
91221807Sstas		return (1);
92221807Sstas	}
93221807Sstas        error = kvm_read_all(kd, (unsigned long)node.udfmp, &mnt, sizeof(mnt));
94221807Sstas        if (error != 0) {
95221807Sstas                warnx("can't read udf_mnt at %p for vnode %p",
96221807Sstas                    (void *)node.udfmp, vp);
97221807Sstas                return (1);
98221807Sstas        }
99221807Sstas	vn->vn_fileid = node.hash_id;
100221807Sstas	vn->vn_fsid = dev2udev(kd, mnt.im_dev);
101221807Sstas	return (0);
102221807Sstas}
103