xref: /freebsd/lib/libutil/quotafile.3 (revision f5463265955b829775bbb32e1fd0bc11dafc36ce)
1.\"-
2.\" Copyright (c) 2009 Dag-Erling 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.Dd December 28, 2009
27.Dt QUOTAFILE 3
28.Os
29.Sh NAME
30.Nm quota_open ,
31.Nm quota_close ,
32.Nm quota_on ,
33.Nm quota_off ,
34.Nm quota_read ,
35.Nm quota_write_limits ,
36.Nm quota_write_usage ,
37.Nm quota_fsname ,
38.Nm quota_qfname ,
39.Nm quota_maxid ,
40.Nm quota_check_path ,
41.Nm quota_convert
42.Nd "Manipulate quotas"
43.Sh LIBRARY
44.Lb libutil
45.Sh SYNOPSIS
46.In sys/param.h
47.In sys/mount.h
48.In ufs/ufs/quota.h
49.In fcntl.h
50.In fstab.h
51.In libutil.h
52.Ft "struct quotafile *"
53.Fn quota_open "struct fstab *fs" "int quotatype" "int openflags"
54.Ft int
55.Fn quota_close "struct quotafile *qf"
56.Ft int
57.Fn quota_on "const struct quotafile *qf"
58.Ft int
59.Fn quota_off "const struct quotafile *qf"
60.Ft int
61.Fn quota_read "struct quotafile *qf" "struct dqblk *dqb" "int id"
62.Ft int
63.Fn quota_write_limits "struct quotafile *qf" "struct dqblk *dqb" "int id"
64.Ft int
65.Fn quota_write_usage "struct quotafile *qf" "struct dqblk *dqb" "int id"
66.Ft "const char *"
67.Fn quota_fsname "const struct quotafile *qf"
68.Ft "const char *"
69.Fn quota_qfname "const struct quotafile *qf"
70.Ft int
71.Fn quota_maxid "const struct quotafile *qf"
72.Ft int
73.Fn quota_check_path "const struct quotafile *qf" "const char *path"
74.Ft int
75.Fn quota_convert "struct quotafile *qf" "int wordsize"
76.Sh DESCRIPTION
77These functions are designed to simplify access to filesystem quotas.
78If quotas are active on a filesystem,
79these functions will access them directly from the kernel using the
80.Fn quotactl
81system call.
82If quotas are not active,
83these functions will access them by reading and writing
84the quota files directly.
85.Pp
86The
87.Fn quota_open
88function takes a pointer to an
89.Vt fstab
90entry corresponding to the filesystem on which quotas
91are to be accessed.
92The
93.Va quotatype
94field indicates the type of quotas being sought, either
95.Dv USRQUOTA
96or
97.Dv GRPQUOTA .
98The
99.Va openflags
100are those used by the
101.Fn open
102system call, usually either
103.Dv O_RDONLY
104if the quotas are just to be read, or
105.Dv O_RDWR
106if the quotas are to be updated.
107The
108.Dv O_CREAT
109flag should be specified if a new quota file of the requested type
110should be created if it does not already exist.
111.Pp
112The
113.Fn quota_close
114function closes any open file descriptors and frees any storage
115associated with the filesystem and quota type referenced by
116.Va qf .
117.Pp
118The
119.Fn quota_on
120function enables quotas for the filesystem associated with its
121.Va qf
122argument which may have been opened with
123.Dv O_RDONLY
124or
125.Dv O_RDWR .
126The
127.Fn quota_on
128function returns 0 if successful;
129otherwise the value\~-1 is returned and the global variable
130.Va errno
131is set to indicate the error, see
132.Xr quotactl 2
133for the possible errors.
134.Pp
135The
136.Fn quota_off
137function disables quotas for the filesystem associated with its
138.Va qf
139argument which may have been opened with
140.Dv O_RDONLY
141or
142.Dv O_RDWR .
143The
144.Fn quota_off
145function returns 0 if successful;
146otherwise the value\~-1 is returned and the global variable
147.Va errno
148is set to indicate the error, see
149.Xr quotactl 2
150for the possible errors.
151.Pp
152The
153.Fn quota_read
154function reads the quota from the filesystem and quota type referenced by
155.Va qf
156for the user (or group) specified by
157.Va id
158into the
159.Vt dqblk
160quota structure pointed to by
161.Va dqb .
162.Pp
163The
164.Fn quota_write_limits
165function updates the limit fields (but not the usage fields)
166for the filesystem and quota type referenced by
167.Va qf
168for the user (or group) specified by
169.Va id
170from the
171.Vt dqblk
172quota structure pointed to by
173.Va dqb .
174.Pp
175The
176.Fn quota_write_usage
177function updates the usage fields (but not the limit fields)
178for the filesystem and quota type referenced by
179.Va qf
180for the user (or group) specified by
181.Va id
182from the
183.Vt dqblk
184quota structure pointed to by
185.Va dqb .
186.Pp
187The
188.Fn quota_fsname
189function returns a pointer to a buffer containing the path to the root
190of the file system that corresponds to its
191.Va qf
192argument, as listed in
193.Pa /etc/fstab .
194Note that this may be a symbolic link to the actual directory.
195.Pp
196The
197.Fn quota_qfname
198function returns a pointer to a buffer containing the name of the
199quota file that corresponds to its
200.Va qf
201argument.
202Note that this may be a symbolic link to the actual file.
203.Pp
204The
205.Fn quota_maxid
206function returns the maximum user (or group)
207.Va id
208contained in the quota file associated with its
209.Va qf
210argument.
211.Pp
212The
213.Fn quota_check_path
214function checks if the specified path is within the filesystem that
215corresponds to its
216.Va qf
217argument.
218If the
219.Va path
220argument refers to a symbolic link,
221.Fn quota_check_path
222will follow it.
223.Pp
224The
225.Fn quota_convert
226function converts the quota file associated with its
227.Va qf
228argument to the data size specified by its
229.Va wordsize
230argument.
231The supported wordsize arguments are 32 for the old 32-bit
232quota file format and 64 for the new 64-bit quota file format.
233The
234.Fn quota_convert
235function may only be called to operate on quota files that
236are not currently active.
237.Sh IMPLEMENTATION NOTES
238If the underlying quota file is in or converted to the old 32-bit format,
239limit and usage values written to the quota file will be clipped to 32 bits.
240.Sh RETURN VALUES
241If the filesystem has quotas associated with it,
242.Fn quota_open
243returns a pointer to a
244.Vt quotafile
245structure used in subsequent quota access calls.
246If the filesystem has no quotas, or access permission is denied
247.Dv NULL
248is returned and
249.Va errno
250is set to indicate the error.
251.Pp
252The
253.Fn quota_check_path
254function returns\~1 for a positive result and\~0 for a negative
255result.
256If an error occurs, it returns\~-1 and sets
257.Va errno
258to indicate the error.
259.Pp
260The
261.Fn quota_read ,
262.Fn quota_write_limits ,
263.Fn quota_write_usage ,
264.Fn quota_convert ,
265and
266.Fn quota_close
267functions return zero on success.
268On error they return\~-1
269and set
270.Va errno
271to indicate the error.
272.Sh SEE ALSO
273.Xr quotactl 2 ,
274.Xr quota.group 5 ,
275.Xr quota.user 5
276.Sh HISTORY
277The
278.Nm quotafile
279functions first appeared in
280.Fx 8.1 .
281.Sh AUTHORS
282.An -nosplit
283The
284.Nm quotafile
285functions and this manual page were written by
286.An Dag-Erling Sm\(/orgrav Aq Mt des@FreeBSD.org
287and
288.An Marshall Kirk McKusick Aq Mt mckusick@mckusick.com .
289