xref: /freebsd/share/man/man9/VOP_ATTRIB.9 (revision df7f5d4de4592a8948a25ce01e5bddfbb7ce39dc)
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.3 1997/03/07 03:16:52 mpp 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/vnode.h>
40.Ft int
41.Fn VOP_GETATTR "struct vnode *vp" "struct vattr *vap" "struct ucred *cred" "struct proc *p"
42.Ft int
43.Fn VOP_SETATTR "struct vnode *vp" "struct vattr *vap" "struct ucred *cred" "struct proc *p"
44.Sh DESCRIPTION
45These entry points manipulate various attributes of a file or directory,
46including file permissions, owner, group, size,
47access time and modification time.
48.Pp
49The arguments are:
50.Bl -tag -width cred
51.It Ar vp
52the vnode of the file
53.It Ar vpp
54the attributes of the file
55.It Ar cred
56the user credentials of the calling process
57.It Ar p
58the process
59.El
60.Pp
61Attributes which are not being modified by
62.Xr VOP_SETATTR 9
63should be set to the value
64.Dv VNOVAL .
65.Sh LOCKS
66The file should not be locked on entry.
67.Sh RETURN VALUES
68.Xr VOP_GETATTR 9
69returns information about the file in
70.Fa *vap .
71.Xr VOP_SETATTR 9
72returns zero if the attributes were changed successfully, otherwise an
73appropriate error is returned.
74.Sh PSEUDOCODE
75.Bd -literal
76int
77vop_getattr(struct vnode *vp, struct vattr *vpp,
78	    struct ucred *cred, struct proc *p)
79{
80    /*
81     * Fill in the contents of *vpp with information from
82     * the filesystem.
83     */
84    ...;
85
86    return 0;
87}
88
89int
90vop_setattr(struct vnode *vp, struct vattr *vpp,
91	    struct ucred *cred, struct proc *p)
92{
93    /*
94     * Check for unsettable attributes.
95     */
96    if ((vap->va_type != VNON) || (vap->va_nlink != VNOVAL) ||
97	(vap->va_fsid != VNOVAL) || (vap->va_fileid != VNOVAL) ||
98	(vap->va_blocksize != VNOVAL) || (vap->va_rdev != VNOVAL) ||
99	((int)vap->va_bytes != VNOVAL) || (vap->va_gen != VNOVAL)) {
100	return (EINVAL);
101    }
102
103    if (vap->va_flags != VNOVAL) {
104	/*
105	 * Set the immutable and append flags of the file.
106	 */
107    }
108
109    if (vap->va_uid != (uid_t)VNOVAL || vap->va_gid != (gid_t)VNOVAL) {
110	/*
111	 * Change owner and/or group of the file.
112	 */
113    }
114
115    if (vap->va_size != VNOVAL) {
116	/*
117	 * Truncate the file to the specified size.
118	 */
119    }
120
121    if (vap->va_atime.tv_sec != VNOVAL || vap->va_mtime.tv_sec != VNOVAL) {
122	/*
123	 * Change access and/or modification time of file.
124	 */
125    }
126
127    if (vap->va_mode != (mode_t)VNOVAL) {
128	/*
129	 * Change permissions of file.
130	 */
131    }
132
133    return 0;
134}
135.Ed
136.Sh ERRORS
137.Bl -tag -width Er
138.It Bq Er EPERM
139The file is immutable
140.It Bq Er EACCES
141Permission denied
142.It Bq Er EROFS
143The filesystem is readonly
144.El
145.Sh SEE ALSO
146.Xr vnode 9 ,
147.Xr VOP_ACCESS 9
148.Sh AUTHORS
149This man page was written by Doug Rabson.
150