xref: /freebsd/share/man/man9/VOP_ATTRIB.9 (revision a8445737e740901f5f2c8d24c12ef7fc8b00134e)
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.\" $Id: VOP_ATTRIB.9,v 1.5 1997/04/13 14:48:50 bde Exp $
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 vpp
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
67The file should not be locked on entry.
68.Sh RETURN VALUES
69.Xr VOP_GETATTR 9
70returns information about the file in
71.Fa *vap .
72.Xr VOP_SETATTR 9
73returns zero if the attributes were changed successfully, otherwise an
74appropriate error is returned.
75.Sh PSEUDOCODE
76.Bd -literal
77int
78vop_getattr(struct vnode *vp, struct vattr *vpp,
79	    struct ucred *cred, struct proc *p)
80{
81    /*
82     * Fill in the contents of *vpp with information from
83     * the filesystem.
84     */
85    ...;
86
87    return 0;
88}
89
90int
91vop_setattr(struct vnode *vp, struct vattr *vpp,
92	    struct ucred *cred, struct proc *p)
93{
94    /*
95     * Check for unsettable attributes.
96     */
97    if ((vap->va_type != VNON) || (vap->va_nlink != VNOVAL) ||
98	(vap->va_fsid != VNOVAL) || (vap->va_fileid != VNOVAL) ||
99	(vap->va_blocksize != VNOVAL) || (vap->va_rdev != VNOVAL) ||
100	((int)vap->va_bytes != VNOVAL) || (vap->va_gen != VNOVAL)) {
101	return (EINVAL);
102    }
103
104    if (vap->va_flags != VNOVAL) {
105	/*
106	 * Set the immutable and append flags of the file.
107	 */
108    }
109
110    if (vap->va_uid != (uid_t)VNOVAL || vap->va_gid != (gid_t)VNOVAL) {
111	/*
112	 * Change owner and/or group of the file.
113	 */
114    }
115
116    if (vap->va_size != VNOVAL) {
117	/*
118	 * Truncate the file to the specified size.
119	 */
120    }
121
122    if (vap->va_atime.tv_sec != VNOVAL || vap->va_mtime.tv_sec != VNOVAL) {
123	/*
124	 * Change access and/or modification time of file.
125	 */
126    }
127
128    if (vap->va_mode != (mode_t)VNOVAL) {
129	/*
130	 * Change permissions of file.
131	 */
132    }
133
134    return 0;
135}
136.Ed
137.Sh ERRORS
138.Bl -tag -width Er
139.It Bq Er EPERM
140The file is immutable
141.It Bq Er EACCES
142Permission denied
143.It Bq Er EROFS
144The filesystem is readonly
145.El
146.Sh SEE ALSO
147.Xr vnode 9 ,
148.Xr VOP_ACCESS 9
149.Sh AUTHORS
150This man page was written by
151.An Doug Rabson .
152