xref: /illumos-gate/usr/src/lib/smbclnt/libfksmbfs/common/fake_stat.c (revision 33c72b7598992897b94815b1f47b7b8077e53808)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License (the "License").
6  * You may not use this file except in compliance with the License.
7  *
8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9  * or http://www.opensolaris.org/os/licensing.
10  * See the License for the specific language governing permissions
11  * and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL HEADER in each
14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15  * If applicable, add the following below this CDDL HEADER, with the
16  * fields enclosed by brackets "[]" replaced with your own identifying
17  * information: Portions Copyright [yyyy] [name of copyright owner]
18  *
19  * CDDL HEADER END
20  */
21 
22 /*
23  * Copyright (c) 1994, 2010, Oracle and/or its affiliates. All rights reserved.
24  * Copyright 2017 Nexenta Systems, Inc.  All rights reserved.
25  */
26 
27 /*	Copyright (c) 1983, 1984, 1985, 1986, 1987, 1988, 1989 AT&T	*/
28 /*	  All Rights Reserved	*/
29 
30 /*
31  * Portions of this source code were derived from Berkeley 4.3 BSD
32  * under license from the Regents of the University of California.
33  */
34 
35 /*
36  * Get file attribute information through a file name or a file descriptor.
37  */
38 
39 #include <sys/param.h>
40 #include <sys/isa_defs.h>
41 #include <sys/types.h>
42 #include <sys/sysmacros.h>
43 #include <sys/cred.h>
44 #include <sys/systm.h>
45 #include <sys/errno.h>
46 #include <sys/fcntl.h>
47 #include <sys/pathname.h>
48 #include <sys/stat.h>
49 #include <sys/vfs.h>
50 #include <sys/vnode.h>
51 #include <sys/mode.h>
52 #include <sys/file.h>
53 #include <sys/proc.h>
54 #include <sys/uio.h>
55 #include <sys/debug.h>
56 #include <sys/cmn_err.h>
57 #include <fs/fs_subr.h>
58 
59 #include <libfksmbfs.h>
60 
61 int
62 fake_stat(vnode_t *vp, struct stat64 *ubp, int flag)
63 {
64 	cred_t *cr = CRED();
65 	struct vfssw *vswp;
66 	struct stat64 lsb;
67 	vattr_t vattr;
68 	int error;
69 
70 	vattr.va_mask = AT_STAT | AT_NBLOCKS | AT_BLKSIZE | AT_SIZE;
71 	if (error = VOP_GETATTR(vp, &vattr, flag, cr, NULL))
72 		return (error);
73 
74 	bzero(&lsb, sizeof (lsb));
75 	lsb.st_dev = vattr.va_fsid;
76 	lsb.st_ino = vattr.va_nodeid;
77 	lsb.st_mode = VTTOIF(vattr.va_type) | vattr.va_mode;
78 	lsb.st_nlink = vattr.va_nlink;
79 	lsb.st_uid = vattr.va_uid;
80 	lsb.st_gid = vattr.va_gid;
81 	lsb.st_rdev = vattr.va_rdev;
82 	lsb.st_size = vattr.va_size;
83 	lsb.st_atim = vattr.va_atime;
84 	lsb.st_mtim = vattr.va_mtime;
85 	lsb.st_ctim = vattr.va_ctime;
86 	lsb.st_blksize = vattr.va_blksize;
87 	lsb.st_blocks = vattr.va_nblocks;
88 	if (vp->v_vfsp != NULL) {
89 		vswp = &vfssw[vp->v_vfsp->vfs_fstype];
90 		if (vswp->vsw_name && *vswp->vsw_name)
91 			(void) strcpy(lsb.st_fstype, vswp->vsw_name);
92 	}
93 	if (copyout(&lsb, ubp, sizeof (lsb)))
94 		return (EFAULT);
95 	return (0);
96 }
97