Lines Matching +full:dev +full:- +full:active +full:- +full:grp
1 /*-
2 * SPDX-License-Identifier: BSD-2-Clause
4 * Copyright (c) 2008 Dag-Erling Smørgrav
41 #include <grp.h>
51 int fd; /* -1 means using quotactl for access */
53 int wordsize; /* 32-bit or 64-bit limits */
55 dev_t dev; /* device */ member
85 strcpy(buf, fs->fs_mntops); in hasquota()
99 if (statfs(fs->fs_file, &sfb) != 0 || in hasquota()
100 strcmp(fs->fs_file, sfb.f_mntonname)) { in hasquota()
106 (void)snprintf(qfnamep, qfbufsize, "%s/%s.%s", fs->fs_file, in hasquota()
117 struct group *grp; in quota_open() local
124 qf->fd = -1; in quota_open()
125 qf->quotatype = quotatype; in quota_open()
126 strlcpy(qf->fsname, fs->fs_file, sizeof(qf->fsname)); in quota_open()
127 if (stat(qf->fsname, &st) != 0) in quota_open()
129 qf->dev = st.st_dev; in quota_open()
131 ufs = strcmp(fs->fs_vfstype, "ufs") == 0; in quota_open()
133 * On UFS, hasquota() fills in qf->qfname. But we only care about in quota_open()
137 serrno = hasquota(fs, quotatype, qf->qfname, in quota_open()
138 sizeof(qf->qfname)); in quota_open()
140 if (quotactl(qf->fsname, qcmd, 0, &qf->wordsize) == 0) in quota_open()
149 qf->accmode = openflags & O_ACCMODE; in quota_open()
150 if ((qf->fd = open(qf->qfname, qf->accmode|O_CLOEXEC)) < 0 && in quota_open()
154 if (qf->fd != -1) { in quota_open()
155 qf->wordsize = 32; in quota_open()
156 switch (read(qf->fd, &dqh, sizeof(dqh))) { in quota_open()
157 case -1: in quota_open()
162 qf->wordsize = 32; in quota_open()
172 qf->wordsize = 64; in quota_open()
175 qf->wordsize = 32; in quota_open()
181 if ((qf->fd = open(qf->qfname, O_RDWR|O_CREAT|O_TRUNC|O_CLOEXEC, 0)) < in quota_open()
184 qf->wordsize = 64; in quota_open()
190 if (write(qf->fd, &dqh, sizeof(dqh)) != sizeof(dqh)) { in quota_open()
192 unlink(qf->qfname); in quota_open()
195 grp = getgrnam(QUOTAGROUP); in quota_open()
196 fchown(qf->fd, 0, grp ? grp->gr_gid : 0); in quota_open()
197 fchmod(qf->fd, 0640); in quota_open()
202 if (qf->fd != -1) in quota_open()
203 close(qf->fd); in quota_open()
213 if (qf->fd != -1) in quota_close()
214 close(qf->fd); in quota_close()
223 qcmd = QCMD(Q_QUOTAON, qf->quotatype); in quota_on()
224 return (quotactl(qf->fsname, qcmd, 0, qf->qfname)); in quota_on()
231 return (quotactl(qf->fsname, QCMD(Q_QUOTAOFF, qf->quotatype), 0, 0)); in quota_off()
238 return (qf->fsname); in quota_fsname()
245 return (qf->qfname); in quota_qfname()
253 if (stat(path, &st) == -1) in quota_check_path()
254 return (-1); in quota_check_path()
255 return (st.st_dev == qf->dev); in quota_check_path()
264 if (stat(qf->qfname, &st) < 0) in quota_maxid()
266 switch (qf->wordsize) { in quota_maxid()
268 maxid = st.st_size / sizeof(struct dqblk32) - 1; in quota_maxid()
271 maxid = st.st_size / sizeof(struct dqblk64) - 2; in quota_maxid()
287 if (lseek(qf->fd, off, SEEK_SET) == -1) in quota_read32()
288 return (-1); in quota_read32()
289 switch (read(qf->fd, &dqb32, sizeof(dqb32))) { in quota_read32()
294 dqb->dqb_bhardlimit = dqb32.dqb_bhardlimit; in quota_read32()
295 dqb->dqb_bsoftlimit = dqb32.dqb_bsoftlimit; in quota_read32()
296 dqb->dqb_curblocks = dqb32.dqb_curblocks; in quota_read32()
297 dqb->dqb_ihardlimit = dqb32.dqb_ihardlimit; in quota_read32()
298 dqb->dqb_isoftlimit = dqb32.dqb_isoftlimit; in quota_read32()
299 dqb->dqb_curinodes = dqb32.dqb_curinodes; in quota_read32()
300 dqb->dqb_btime = dqb32.dqb_btime; in quota_read32()
301 dqb->dqb_itime = dqb32.dqb_itime; in quota_read32()
304 return (-1); in quota_read32()
315 if (lseek(qf->fd, off, SEEK_SET) == -1) in quota_read64()
316 return (-1); in quota_read64()
317 switch (read(qf->fd, &dqb64, sizeof(dqb64))) { in quota_read64()
322 dqb->dqb_bhardlimit = be64toh(dqb64.dqb_bhardlimit); in quota_read64()
323 dqb->dqb_bsoftlimit = be64toh(dqb64.dqb_bsoftlimit); in quota_read64()
324 dqb->dqb_curblocks = be64toh(dqb64.dqb_curblocks); in quota_read64()
325 dqb->dqb_ihardlimit = be64toh(dqb64.dqb_ihardlimit); in quota_read64()
326 dqb->dqb_isoftlimit = be64toh(dqb64.dqb_isoftlimit); in quota_read64()
327 dqb->dqb_curinodes = be64toh(dqb64.dqb_curinodes); in quota_read64()
328 dqb->dqb_btime = be64toh(dqb64.dqb_btime); in quota_read64()
329 dqb->dqb_itime = be64toh(dqb64.dqb_itime); in quota_read64()
332 return (-1); in quota_read64()
341 if (qf->fd == -1) { in quota_read()
342 qcmd = QCMD(Q_GETQUOTA, qf->quotatype); in quota_read()
343 return (quotactl(qf->fsname, qcmd, id, dqb)); in quota_read()
345 switch (qf->wordsize) { in quota_read()
352 return (-1); in quota_read()
365 dqb32.dqb_bhardlimit = CLIP32(dqb->dqb_bhardlimit); in quota_write32()
366 dqb32.dqb_bsoftlimit = CLIP32(dqb->dqb_bsoftlimit); in quota_write32()
367 dqb32.dqb_curblocks = CLIP32(dqb->dqb_curblocks); in quota_write32()
368 dqb32.dqb_ihardlimit = CLIP32(dqb->dqb_ihardlimit); in quota_write32()
369 dqb32.dqb_isoftlimit = CLIP32(dqb->dqb_isoftlimit); in quota_write32()
370 dqb32.dqb_curinodes = CLIP32(dqb->dqb_curinodes); in quota_write32()
371 dqb32.dqb_btime = CLIP32(dqb->dqb_btime); in quota_write32()
372 dqb32.dqb_itime = CLIP32(dqb->dqb_itime); in quota_write32()
375 if (lseek(qf->fd, off, SEEK_SET) == -1) in quota_write32()
376 return (-1); in quota_write32()
377 if (write(qf->fd, &dqb32, sizeof(dqb32)) == sizeof(dqb32)) in quota_write32()
379 return (-1); in quota_write32()
388 dqb64.dqb_bhardlimit = htobe64(dqb->dqb_bhardlimit); in quota_write64()
389 dqb64.dqb_bsoftlimit = htobe64(dqb->dqb_bsoftlimit); in quota_write64()
390 dqb64.dqb_curblocks = htobe64(dqb->dqb_curblocks); in quota_write64()
391 dqb64.dqb_ihardlimit = htobe64(dqb->dqb_ihardlimit); in quota_write64()
392 dqb64.dqb_isoftlimit = htobe64(dqb->dqb_isoftlimit); in quota_write64()
393 dqb64.dqb_curinodes = htobe64(dqb->dqb_curinodes); in quota_write64()
394 dqb64.dqb_btime = htobe64(dqb->dqb_btime); in quota_write64()
395 dqb64.dqb_itime = htobe64(dqb->dqb_itime); in quota_write64()
398 if (lseek(qf->fd, off, SEEK_SET) == -1) in quota_write64()
399 return (-1); in quota_write64()
400 if (write(qf->fd, &dqb64, sizeof(dqb64)) == sizeof(dqb64)) in quota_write64()
402 return (-1); in quota_write64()
411 if (qf->fd == -1) { in quota_write_usage()
412 qcmd = QCMD(Q_SETUSE, qf->quotatype); in quota_write_usage()
413 return (quotactl(qf->fsname, qcmd, id, dqb)); in quota_write_usage()
416 * Have to do read-modify-write of quota in file. in quota_write_usage()
418 if ((qf->accmode & O_RDWR) != O_RDWR) { in quota_write_usage()
420 return (-1); in quota_write_usage()
423 return (-1); in quota_write_usage()
430 dqb->dqb_curblocks >= dqbuf.dqb_bsoftlimit) in quota_write_usage()
434 dqb->dqb_curinodes >= dqbuf.dqb_isoftlimit) in quota_write_usage()
436 dqbuf.dqb_curinodes = dqb->dqb_curinodes; in quota_write_usage()
437 dqbuf.dqb_curblocks = dqb->dqb_curblocks; in quota_write_usage()
441 switch (qf->wordsize) { in quota_write_usage()
448 return (-1); in quota_write_usage()
459 if (qf->fd == -1) { in quota_write_limits()
460 qcmd = QCMD(Q_SETQUOTA, qf->quotatype); in quota_write_limits()
461 return (quotactl(qf->fsname, qcmd, id, dqb)); in quota_write_limits()
464 * Have to do read-modify-write of quota in file. in quota_write_limits()
466 if ((qf->accmode & O_RDWR) != O_RDWR) { in quota_write_limits()
468 return (-1); in quota_write_limits()
471 return (-1); in quota_write_limits()
480 dqbuf.dqb_curblocks >= dqb->dqb_bsoftlimit) in quota_write_limits()
481 dqb->dqb_btime = 0; in quota_write_limits()
483 dqb->dqb_bsoftlimit > 0 && in quota_write_limits()
484 dqbuf.dqb_curblocks >= dqb->dqb_bsoftlimit) in quota_write_limits()
485 dqb->dqb_btime = 0; in quota_write_limits()
488 dqbuf.dqb_curinodes >= dqb->dqb_isoftlimit) in quota_write_limits()
489 dqb->dqb_itime = 0; in quota_write_limits()
491 dqb->dqb_isoftlimit > 0 && in quota_write_limits()
492 dqbuf.dqb_curinodes >= dqb->dqb_isoftlimit) in quota_write_limits()
493 dqb->dqb_itime = 0; in quota_write_limits()
494 dqb->dqb_curinodes = dqbuf.dqb_curinodes; in quota_write_limits()
495 dqb->dqb_curblocks = dqbuf.dqb_curblocks; in quota_write_limits()
499 switch (qf->wordsize) { in quota_write_limits()
506 return (-1); in quota_write_limits()
520 struct group *grp; in quota_convert() local
524 * Quotas must not be active and quotafile must be open in quota_convert()
527 if ((qf->accmode & O_RDWR) != O_RDWR || qf->fd == -1) { in quota_convert()
529 return (-1); in quota_convert()
532 wordsize == qf->wordsize) { in quota_convert()
534 return (-1); in quota_convert()
539 return (-1); in quota_convert()
542 snprintf(newqf->qfname, MAXPATHLEN + 1, "%s_%d.orig", qf->qfname, in quota_convert()
543 qf->wordsize); in quota_convert()
544 if (rename(qf->qfname, newqf->qfname) < 0) { in quota_convert()
546 return (-1); in quota_convert()
548 if ((newqf->fd = open(qf->qfname, O_RDWR|O_CREAT|O_TRUNC|O_CLOEXEC, in quota_convert()
553 newqf->wordsize = wordsize; in quota_convert()
560 if (write(newqf->fd, &dqh, sizeof(dqh)) != sizeof(dqh)) { in quota_convert()
565 grp = getgrnam(QUOTAGROUP); in quota_convert()
566 fchown(newqf->fd, 0, grp ? grp->gr_gid : 0); in quota_convert()
567 fchmod(newqf->fd, 0640); in quota_convert()
571 switch (newqf->wordsize) { in quota_convert()
593 fd = qf->fd; in quota_convert()
594 qf->fd = newqf->fd; in quota_convert()
595 newqf->fd = fd; in quota_convert()
596 qf->wordsize = newqf->wordsize; in quota_convert()
601 (void) rename(newqf->qfname, qf->qfname); in quota_convert()
604 return (-1); in quota_convert()