| 453 | } |
| 454 | |
| 455 | int |
| 456 | quota_write_limits(struct quotafile *qf, struct dqblk *dqb, int id) |
| 457 | { |
| 458 | struct dqblk dqbuf; |
| 459 | int qcmd; |
| 460 | |
| 461 | if (qf->fd == -1) { |
| 462 | qcmd = QCMD(Q_SETQUOTA, qf->quotatype); |
| 463 | return (quotactl(qf->fsname, qcmd, id, dqb)); |
| 464 | } |
| 465 | /* |
| 466 | * Have to do read-modify-write of quota in file. |
| 467 | */ |
| 468 | if ((qf->accmode & O_RDWR) != O_RDWR) { |
| 469 | errno = EBADF; |
| 470 | return (-1); |
| 471 | } |
| 472 | if (quota_read(qf, &dqbuf, id) != 0) |
| 473 | return (-1); |
| 474 | /* |
| 475 | * Reset time limit if have a soft limit and were |
| 476 | * previously under it, but are now over it |
| 477 | * or if there previously was no soft limit, but |
| 478 | * now have one and are over it. |
| 479 | */ |
| 480 | if (dqbuf.dqb_bsoftlimit && id != 0 && |
| 481 | dqbuf.dqb_curblocks < dqbuf.dqb_bsoftlimit && |
| 482 | dqbuf.dqb_curblocks >= dqb->dqb_bsoftlimit) |
| 483 | dqb->dqb_btime = 0; |
| 484 | if (dqbuf.dqb_bsoftlimit == 0 && id != 0 && |
| 485 | dqb->dqb_bsoftlimit > 0 && |
| 486 | dqbuf.dqb_curblocks >= dqb->dqb_bsoftlimit) |
| 487 | dqb->dqb_btime = 0; |
| 488 | if (dqbuf.dqb_isoftlimit && id != 0 && |
| 489 | dqbuf.dqb_curinodes < dqbuf.dqb_isoftlimit && |
| 490 | dqbuf.dqb_curinodes >= dqb->dqb_isoftlimit) |
| 491 | dqb->dqb_itime = 0; |
| 492 | if (dqbuf.dqb_isoftlimit == 0 && id !=0 && |
| 493 | dqb->dqb_isoftlimit > 0 && |
| 494 | dqbuf.dqb_curinodes >= dqb->dqb_isoftlimit) |
| 495 | dqb->dqb_itime = 0; |
| 496 | dqb->dqb_curinodes = dqbuf.dqb_curinodes; |
| 497 | dqb->dqb_curblocks = dqbuf.dqb_curblocks; |
| 498 | /* |
| 499 | * Write it back. |
| 500 | */ |
| 501 | switch (qf->wordsize) { |
| 502 | case 32: |
| 503 | return (quota_write32(qf, dqb, id)); |
| 504 | case 64: |
| 505 | return (quota_write64(qf, dqb, id)); |
| 506 | default: |
| 507 | errno = EINVAL; |
| 508 | return (-1); |
| 509 | } |
| 510 | /* not reached */ |
| 511 | } |
| 512 |
nothing calls this directly
no test coverage detected