xref: /freebsd/lib/libutil/quotafile.3 (revision d8a0fe102c0cfdfcd5b818f850eff09d8536c9bc)
1.\"-
2.\" Copyright (c) 2009 Dag-Erling Coïdan Smørgrav and
3.\" Marshall Kirk McKusick. All rights reserved.
4.\"
5.\" Redistribution and use in source and binary forms, with or without
6.\" modification, are permitted provided that the following conditions
7.\" are met:
8.\" 1. Redistributions of source code must retain the above copyright
9.\"    notice, this list of conditions and the following disclaimer.
10.\" 2. Redistributions in binary form must reproduce the above copyright
11.\"    notice, this list of conditions and the following disclaimer in the
12.\"    documentation and/or other materials provided with the distribution.
13.\"
14.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24.\" SUCH DAMAGE.
25.\"
26.\" $FreeBSD$
27.\"
28.Dd December 28, 2009
29.Dt QUOTAFILE 3
30.Os
31.Sh NAME
32.Nm quota_open
33.Nm quota_close
34.Nm quota_on
35.Nm quota_off
36.Nm quota_read
37.Nm quota_write_limits
38.Nm quota_write_usage
39.Nm quota_fsname
40.Nm quota_qfname
41.Nm quota_maxid
42.Nm quota_check_path
43.Nm quota_convert
44.Nd "Manipulate quotas"
45.Sh LIBRARY
46.Lb libutil
47.Sh SYNOPSIS
48.In sys/param.h
49.In sys/mount.h
50.In ufs/ufs/quota.h
51.In fcntl.h
52.In fstab.h
53.In libutil.h
54.Ft "struct quotafile *"
55.Fn quota_open "struct fstab *fs" "int quotatype" "int openflags"
56.Ft int
57.Fn quota_close "struct quotafile *qf"
58.Ft int
59.Fn quota_on "const struct quotafile *qf"
60.Ft int
61.Fn quota_off "const struct quotafile *qf"
62.Ft int
63.Fn quota_read "struct quotafile *qf" "struct dqblk *dqb" "int id"
64.Ft int
65.Fn quota_write_limits "struct quotafile *qf" "struct dqblk *dqb" "int id"
66.Ft int
67.Fn quota_write_usage "struct quotafile *qf" "struct dqblk *dqb" "int id"
68.Ft "const char *"
69.Fn quota_fsname "const struct quotafile *qf"
70.Ft "const char *"
71.Fn quota_qfname "const struct quotafile *qf"
72.Ft int
73.Fn quota_maxid "const struct quotafile *qf"
74.Ft int
75.Fn quota_check_path "const struct quotafile *qf" "const char *path"
76.Ft int
77.Fn quota_convert "struct quotafile *qf" "int wordsize"
78.Sh DESCRIPTION
79These functions are designed to simplify access to filesystem quotas.
80If quotas are active on a filesystem,
81these functions will access them directly from the kernel using the
82.Fn quotactl
83system call.
84If quotas are not active,
85these functions will access them by reading and writing
86the quota files directly.
87.Pp
88The
89.Fn quota_open
90function takes a pointer to an
91.Vt fstab
92entry corresponding to the filesystem on which quotas
93are to be accessed.
94The
95.Va quotatype
96field indicates the type of quotas being sought, either
97.Dv USRQUOTA
98or
99.Dv GRPQUOTA .
100The
101.Va openflags
102are those used by the
103.Fn open
104system call, usually either
105.Dv O_RDONLY
106if the quotas are just to be read, or
107.Dv O_RDWR
108if the quotas are to be updated.
109The
110.Dv O_CREAT
111flag should be specified if a new quota file of the requested type
112should be created if it does not already exist.
113.Pp
114The
115.Fn quota_close
116function closes any open file descriptors and frees any storage
117associated with the filesystem and quota type referenced by
118.Va qf .
119.Pp
120The
121.Fn quota_on
122function enables quotas for the filesystem associated with its
123.Va qf
124argument which may have been opened with
125.Dv O_RDONLY
126or
127.Dv O_RDWR .
128The
129.Fn quota_on
130function returns 0 if successful;
131otherwise the value\~-1 is returned and the global variable
132.Va errno
133is set to indicate the error, see
134.Xr quotactl 2
135for the possible errors.
136.Pp
137The
138.Fn quota_off
139function disables quotas for the filesystem associated with its
140.Va qf
141argument which may have been opened with
142.Dv O_RDONLY
143or
144.Dv O_RDWR .
145The
146.Fn quota_off
147function returns 0 if successful;
148otherwise the value\~-1 is returned and the global variable
149.Va errno
150is set to indicate the error, see
151.Xr quotactl 2
152for the possible errors.
153.Pp
154The
155.Fn quota_read
156function reads the quota from the filesystem and quota type referenced by
157.Va qf
158for the user (or group) specified by
159.Va id
160into the
161.Vt dqblk
162quota structure pointed to by
163.Va dqb .
164.Pp
165The
166.Fn quota_write_limits
167function updates the limit fields (but not the usage fields)
168for the filesystem and quota type referenced by
169.Va qf
170for the user (or group) specified by
171.Va id
172from the
173.Vt dqblk
174quota structure pointed to by
175.Va dqb .
176.Pp
177The
178.Fn quota_write_usage
179function updates the usage fields (but not the limit fields)
180for the filesystem and quota type referenced by
181.Va qf
182for the user (or group) specified by
183.Va id
184from the
185.Vt dqblk
186quota structure pointed to by
187.Va dqb .
188.Pp
189The
190.Fn quota_fsname
191function returns a pointer to a buffer containing the path to the root
192of the file system that corresponds to its
193.Va qf
194argument, as listed in
195.Pa /etc/fstab .
196Note that this may be a symbolic link to the actual directory.
197.Pp
198The
199.Fn quota_qfname
200function returns a pointer to a buffer containing the name of the
201quota file that corresponds to its
202.Va qf
203argument.
204Note that this may be a symbolic link to the actual file.
205.Pp
206The
207.Fn quota_maxid
208function returns the maximum user (or group)
209.Va id
210contained in the quota file associated with its
211.Va qf
212argument.
213.Pp
214The
215.Fn quota_check_path
216function checks if the specified path is within the filesystem that
217corresponds to its
218.Va qf
219argument.
220If the
221.Va path
222argument refers to a symbolic link,
223.Fn quota_check_path
224will follow it.
225.Pp
226The
227.Fn quota_convert
228function converts the quota file associated with its
229.Va qf
230argument to the data size specified by its
231.Va wordsize
232argument.
233The supported wordsize arguments are 32 for the old 32-bit
234quota file format and 64 for the new 64-bit quota file format.
235The
236.Fn quota_convert
237function may only be called to operate on quota files that
238are not currently active.
239.Sh IMPLEMENTATION NOTES
240If the underlying quota file is in or converted to the old 32-bit format,
241limit and usage values written to the quota file will be clipped to 32 bits.
242.Sh RETURN VALUES
243If the filesystem has quotas associated with it,
244.Fn quota_open
245returns a pointer to a
246.Vt quotafile
247structure used in subsequent quota access calls.
248If the filesystem has no quotas, or access permission is denied
249.Dv NULL
250is returned and
251.Va errno
252is set to indicate the error.
253.Pp
254The
255.Fn quota_check_path
256function returns\~1 for a positive result and\~0 for a negative
257result.
258If an error occurs, it returns\~-1 and sets
259.Va errno
260to indicate the error.
261.Pp
262The
263.Fn quota_read ,
264.Fn quota_write_limits ,
265.Fn quota_write_usage ,
266.Fn quota_convert ,
267and
268.Fn quota_close
269functions return zero on success.
270On error they return\~-1
271and set
272.Va errno
273to indicate the error.
274.Sh SEE ALSO
275.Xr quotactl 2 ,
276.Xr quota.group 5 ,
277.Xr quota.user 5
278.Sh HISTORY
279The
280.Nm quotafile
281functions first appeared in
282.Fx 8.1 .
283.Sh AUTHORS
284.An -nosplit
285The
286.Nm quotafile
287functions and this manual page were written by
288.An Dag-Erling Sm\(/orgrav Aq Mt des@FreeBSD.org
289and
290.An Marshall Kirk McKusick Aq Mt mckusick@mckusick.com .
291