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#define _KERNEL 34221807Sstas#include <sys/mount.h> 35221807Sstas#undef _KERNEL 36221807Sstas 37221807Sstas#include <netinet/in.h> 38221807Sstas 39221807Sstas#include <assert.h> 40221807Sstas#include <err.h> 41221807Sstas#include <kvm.h> 42221807Sstas#include <stdlib.h> 43221807Sstas 44221807Sstas#include <fs/smbfs/smbfs.h> 45221807Sstas#include <fs/smbfs/smbfs_node.h> 46221807Sstas 47221807Sstas#include "libprocstat.h" 48221807Sstas#include "common_kvm.h" 49221807Sstas 50221807Sstasint 51221807Sstassmbfs_filestat(kvm_t *kd, struct vnode *vp, struct vnstat *vn) 52221807Sstas{ 53221807Sstas struct smbnode node; 54221807Sstas struct mount mnt; 55221807Sstas int error; 56221807Sstas 57221807Sstas assert(kd); 58221807Sstas assert(vn); 59221807Sstas error = kvm_read_all(kd, (unsigned long)VTOSMB(vp), &node, 60221807Sstas sizeof(node)); 61221807Sstas if (error != 0) { 62221807Sstas warnx("can't read smbfs fnode at %p", (void *)VTOSMB(vp)); 63221807Sstas return (1); 64221807Sstas } 65221807Sstas error = kvm_read_all(kd, (unsigned long)getvnodemount(vp), &mnt, 66221807Sstas sizeof(mnt)); 67221807Sstas if (error != 0) { 68221807Sstas warnx("can't read mount at %p for vnode %p", 69221807Sstas (void *)getvnodemount(vp), vp); 70221807Sstas return (1); 71221807Sstas } 72221807Sstas vn->vn_fileid = node.n_ino; 73221807Sstas if (vn->vn_fileid == 0) 74221807Sstas vn->vn_fileid = 2; 75221807Sstas vn->vn_fsid = mnt.mnt_stat.f_fsid.val[0]; 76221807Sstas return (0); 77221807Sstas} 78