10daf62d9SStanislav Sedov /*-
2*4d846d26SWarner Losh * SPDX-License-Identifier: BSD-2-Clause
35e53a4f9SPedro F. Giffuni *
40daf62d9SStanislav Sedov * Copyright (c) 2005-2009 Stanislav Sedov <stas@FreeBSD.org>
50daf62d9SStanislav Sedov * All rights reserved.
60daf62d9SStanislav Sedov *
70daf62d9SStanislav Sedov * Redistribution and use in source and binary forms, with or without
80daf62d9SStanislav Sedov * modification, are permitted provided that the following conditions
90daf62d9SStanislav Sedov * are met:
100daf62d9SStanislav Sedov * 1. Redistributions of source code must retain the above copyright
110daf62d9SStanislav Sedov * notice, this list of conditions and the following disclaimer.
120daf62d9SStanislav Sedov * 2. Redistributions in binary form must reproduce the above copyright
130daf62d9SStanislav Sedov * notice, this list of conditions and the following disclaimer in the
140daf62d9SStanislav Sedov * documentation and/or other materials provided with the distribution.
150daf62d9SStanislav Sedov *
160daf62d9SStanislav Sedov * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
170daf62d9SStanislav Sedov * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
180daf62d9SStanislav Sedov * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
190daf62d9SStanislav Sedov * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
200daf62d9SStanislav Sedov * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
210daf62d9SStanislav Sedov * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
220daf62d9SStanislav Sedov * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
230daf62d9SStanislav Sedov * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
240daf62d9SStanislav Sedov * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
250daf62d9SStanislav Sedov * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
260daf62d9SStanislav Sedov * SUCH DAMAGE.
270daf62d9SStanislav Sedov */
280daf62d9SStanislav Sedov #include <sys/cdefs.h>
29a4b07a27SJason A. Harmening #include <stdbool.h>
30a4b07a27SJason A. Harmening
310daf62d9SStanislav Sedov #include <sys/param.h>
320daf62d9SStanislav Sedov #include <sys/stat.h>
330daf62d9SStanislav Sedov #include <sys/time.h>
340daf62d9SStanislav Sedov #include <sys/vnode.h>
350daf62d9SStanislav Sedov #define _KERNEL
360daf62d9SStanislav Sedov #include <sys/mount.h>
370daf62d9SStanislav Sedov #undef _KERNEL
380daf62d9SStanislav Sedov
390daf62d9SStanislav Sedov #include <netinet/in.h>
400daf62d9SStanislav Sedov
410daf62d9SStanislav Sedov #include <assert.h>
420daf62d9SStanislav Sedov #include <err.h>
430daf62d9SStanislav Sedov #include <kvm.h>
440daf62d9SStanislav Sedov #include <stdlib.h>
450daf62d9SStanislav Sedov
460daf62d9SStanislav Sedov #include <fs/udf/ecma167-udf.h>
470daf62d9SStanislav Sedov
480daf62d9SStanislav Sedov #include "libprocstat.h"
490daf62d9SStanislav Sedov #include "common_kvm.h"
500daf62d9SStanislav Sedov
510daf62d9SStanislav Sedov /* XXX */
520daf62d9SStanislav Sedov struct udf_mnt {
530daf62d9SStanislav Sedov int im_flags;
540daf62d9SStanislav Sedov struct mount *im_mountp;
550daf62d9SStanislav Sedov struct g_consumer *im_cp;
560daf62d9SStanislav Sedov struct bufobj *im_bo;
570daf62d9SStanislav Sedov struct cdev *im_dev;
580daf62d9SStanislav Sedov struct vnode *im_devvp;
590daf62d9SStanislav Sedov int bsize;
600daf62d9SStanislav Sedov int bshift;
610daf62d9SStanislav Sedov int bmask;
620daf62d9SStanislav Sedov uint32_t part_start;
630daf62d9SStanislav Sedov uint32_t part_len;
640daf62d9SStanislav Sedov uint64_t root_id;
650daf62d9SStanislav Sedov struct long_ad root_icb;
660daf62d9SStanislav Sedov int p_sectors;
670daf62d9SStanislav Sedov int s_table_entries;
680daf62d9SStanislav Sedov void *s_table;
690daf62d9SStanislav Sedov void *im_d2l;
700daf62d9SStanislav Sedov };
710daf62d9SStanislav Sedov struct udf_node {
720daf62d9SStanislav Sedov struct vnode *i_vnode;
730daf62d9SStanislav Sedov struct udf_mnt *udfmp;
740daf62d9SStanislav Sedov ino_t hash_id;
750daf62d9SStanislav Sedov long diroff;
760daf62d9SStanislav Sedov struct file_entry *fentry;
770daf62d9SStanislav Sedov };
780daf62d9SStanislav Sedov #define VTON(vp) ((struct udf_node *)((vp)->v_data))
790daf62d9SStanislav Sedov
800daf62d9SStanislav Sedov int
udf_filestat(kvm_t * kd,struct vnode * vp,struct vnstat * vn)810daf62d9SStanislav Sedov udf_filestat(kvm_t *kd, struct vnode *vp, struct vnstat *vn)
820daf62d9SStanislav Sedov {
830daf62d9SStanislav Sedov struct udf_node node;
840daf62d9SStanislav Sedov struct udf_mnt mnt;
850daf62d9SStanislav Sedov int error;
860daf62d9SStanislav Sedov
870daf62d9SStanislav Sedov assert(kd);
880daf62d9SStanislav Sedov assert(vn);
890daf62d9SStanislav Sedov error = kvm_read_all(kd, (unsigned long)VTON(vp), &node, sizeof(node));
900daf62d9SStanislav Sedov if (error != 0) {
910daf62d9SStanislav Sedov warnx("can't read udf fnode at %p", (void *)VTON(vp));
920daf62d9SStanislav Sedov return (1);
930daf62d9SStanislav Sedov }
940daf62d9SStanislav Sedov error = kvm_read_all(kd, (unsigned long)node.udfmp, &mnt, sizeof(mnt));
950daf62d9SStanislav Sedov if (error != 0) {
960daf62d9SStanislav Sedov warnx("can't read udf_mnt at %p for vnode %p",
970daf62d9SStanislav Sedov (void *)node.udfmp, vp);
980daf62d9SStanislav Sedov return (1);
990daf62d9SStanislav Sedov }
1000daf62d9SStanislav Sedov vn->vn_fileid = node.hash_id;
1010daf62d9SStanislav Sedov vn->vn_fsid = dev2udev(kd, mnt.im_dev);
1020daf62d9SStanislav Sedov return (0);
1030daf62d9SStanislav Sedov }
104