xref: /freebsd/share/man/man9/VOP_ATTRIB.9 (revision 6990ffd8a95caaba6858ad44ff1b3157d1efba8f)
1.\" -*- nroff -*-
2.\"
3.\" Copyright (c) 1996 Doug Rabson
4.\"
5.\" All rights reserved.
6.\"
7.\" This program is free software.
8.\"
9.\" Redistribution and use in source and binary forms, with or without
10.\" modification, are permitted provided that the following conditions
11.\" are met:
12.\" 1. Redistributions of source code must retain the above copyright
13.\"    notice, this list of conditions and the following disclaimer.
14.\" 2. Redistributions in binary form must reproduce the above copyright
15.\"    notice, this list of conditions and the following disclaimer in the
16.\"    documentation and/or other materials provided with the distribution.
17.\"
18.\" THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY EXPRESS OR
19.\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
20.\" OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
21.\" IN NO EVENT SHALL THE DEVELOPERS BE LIABLE FOR ANY DIRECT, INDIRECT,
22.\" INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
23.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24.\" DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25.\" THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26.\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
27.\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28.\"
29.\" $FreeBSD$
30.\"
31.Dd July 24, 1996
32.Os
33.Dt VOP_ATTRIB 9
34.Sh NAME
35.Nm VOP_GETATTR ,
36.Nm VOP_SETATTR
37.Nd get and set attributes on a file or directory
38.Sh SYNOPSIS
39.Fd #include <sys/param.h>
40.Fd #include <sys/vnode.h>
41.Ft int
42.Fn VOP_GETATTR "struct vnode *vp" "struct vattr *vap" "struct ucred *cred" "struct proc *p"
43.Ft int
44.Fn VOP_SETATTR "struct vnode *vp" "struct vattr *vap" "struct ucred *cred" "struct proc *p"
45.Sh DESCRIPTION
46These entry points manipulate various attributes of a file or directory,
47including file permissions, owner, group, size,
48access time and modification time.
49.Pp
50The arguments are:
51.Bl -tag -width cred
52.It Ar vp
53the vnode of the file
54.It Ar vap
55the attributes of the file
56.It Ar cred
57the user credentials of the calling process
58.It Ar p
59the process
60.El
61.Pp
62Attributes which are not being modified by
63.Xr VOP_SETATTR 9
64should be set to the value
65.Dv VNOVAL .
66.Sh LOCKS
67.Xr VOP_GETATTR 9
68expects the vnode to be locked on entry and will leave the vnode locked on
69return.
70.Pp
71.Xr VOP_SETATTR 9
72expects the vnode to be locked on entry and will leave the vnode locked on
73return.
74.Sh RETURN VALUES
75.Xr VOP_GETATTR 9
76returns information about the file in
77.Fa *vap .
78.Xr VOP_SETATTR 9
79returns zero if the attributes were changed successfully, otherwise an
80appropriate error is returned.
81.Sh PSEUDOCODE
82.Bd -literal
83int
84vop_getattr(struct vnode *vp, struct vattr *vap,
85	    struct ucred *cred, struct proc *p)
86{
87    /*
88     * Fill in the contents of *vap with information from
89     * the filesystem.
90     */
91    ...;
92
93    return 0;
94}
95
96int
97vop_setattr(struct vnode *vp, struct vattr *vap,
98	    struct ucred *cred, struct proc *p)
99{
100    /*
101     * Check for unsettable attributes.
102     */
103    if ((vap->va_type != VNON) || (vap->va_nlink != VNOVAL) ||
104	(vap->va_fsid != VNOVAL) || (vap->va_fileid != VNOVAL) ||
105	(vap->va_blocksize != VNOVAL) || (vap->va_rdev != VNOVAL) ||
106	((int)vap->va_bytes != VNOVAL) || (vap->va_gen != VNOVAL)) {
107	return (EINVAL);
108    }
109
110    if (vap->va_flags != VNOVAL) {
111	/*
112	 * Set the immutable and append flags of the file.
113	 */
114    }
115
116    if (vap->va_uid != (uid_t)VNOVAL || vap->va_gid != (gid_t)VNOVAL) {
117	/*
118	 * Change owner and/or group of the file.
119	 */
120    }
121
122    if (vap->va_size != VNOVAL) {
123	/*
124	 * Truncate the file to the specified size.
125	 */
126    }
127
128    if (vap->va_atime.tv_sec != VNOVAL || vap->va_mtime.tv_sec != VNOVAL) {
129	/*
130	 * Change access and/or modification time of file.
131	 */
132    }
133
134    if (vap->va_mode != (mode_t)VNOVAL) {
135	/*
136	 * Change permissions of file.
137	 */
138    }
139
140    return 0;
141}
142.Ed
143.Sh ERRORS
144.Bl -tag -width Er
145.It Bq Er EPERM
146The file is immutable
147.It Bq Er EACCES
148Permission denied
149.It Bq Er EROFS
150The filesystem is readonly
151.El
152.Sh SEE ALSO
153.Xr vnode 9 ,
154.Xr VOP_ACCESS 9
155.Sh AUTHORS
156This man page was written by
157.An Doug Rabson .
158