Lines Matching refs:qf

117 	struct quotafile *qf;
124 if ((qf = calloc(1, sizeof(*qf))) == NULL)
126 qf->fd = -1;
127 qf->quotatype = quotatype;
128 strlcpy(qf->fsname, fs->fs_file, sizeof(qf->fsname));
129 if (stat(qf->fsname, &st) != 0)
131 qf->dev = st.st_dev;
135 * On UFS, hasquota() fills in qf->qfname. But we only care about
139 serrno = hasquota(fs, quotatype, qf->qfname,
140 sizeof(qf->qfname));
142 if (quotactl(qf->fsname, qcmd, 0, &qf->wordsize) == 0)
143 return (qf);
151 qf->accmode = openflags & O_ACCMODE;
152 if ((qf->fd = open(qf->qfname, qf->accmode|O_CLOEXEC)) < 0 &&
156 if (qf->fd != -1) {
157 qf->wordsize = 32;
158 switch (read(qf->fd, &dqh, sizeof(dqh))) {
164 qf->wordsize = 32;
165 return (qf);
174 qf->wordsize = 64;
175 return (qf);
177 qf->wordsize = 32;
178 return (qf);
183 if ((qf->fd = open(qf->qfname, O_RDWR|O_CREAT|O_TRUNC|O_CLOEXEC, 0)) <
186 qf->wordsize = 64;
192 if (write(qf->fd, &dqh, sizeof(dqh)) != sizeof(dqh)) {
194 unlink(qf->qfname);
198 fchown(qf->fd, 0, grp ? grp->gr_gid : 0);
199 fchmod(qf->fd, 0640);
200 return (qf);
204 if (qf->fd != -1)
205 close(qf->fd);
206 free(qf);
212 quota_close(struct quotafile *qf)
215 if (qf->fd != -1)
216 close(qf->fd);
217 free(qf);
221 quota_on(struct quotafile *qf)
225 qcmd = QCMD(Q_QUOTAON, qf->quotatype);
226 return (quotactl(qf->fsname, qcmd, 0, qf->qfname));
230 quota_off(struct quotafile *qf)
233 return (quotactl(qf->fsname, QCMD(Q_QUOTAOFF, qf->quotatype), 0, 0));
237 quota_fsname(const struct quotafile *qf)
240 return (qf->fsname);
244 quota_qfname(const struct quotafile *qf)
247 return (qf->qfname);
251 quota_check_path(const struct quotafile *qf, const char *path)
257 return (st.st_dev == qf->dev);
261 quota_maxid(struct quotafile *qf)
266 if (stat(qf->qfname, &st) < 0)
268 switch (qf->wordsize) {
283 quota_read32(struct quotafile *qf, struct dqblk *dqb, int id)
289 if (lseek(qf->fd, off, SEEK_SET) == -1)
291 switch (read(qf->fd, &dqb32, sizeof(dqb32))) {
311 quota_read64(struct quotafile *qf, struct dqblk *dqb, int id)
317 if (lseek(qf->fd, off, SEEK_SET) == -1)
319 switch (read(qf->fd, &dqb64, sizeof(dqb64))) {
339 quota_read(struct quotafile *qf, struct dqblk *dqb, int id)
343 if (qf->fd == -1) {
344 qcmd = QCMD(Q_GETQUOTA, qf->quotatype);
345 return (quotactl(qf->fsname, qcmd, id, dqb));
347 switch (qf->wordsize) {
349 return (quota_read32(qf, dqb, id));
351 return (quota_read64(qf, dqb, id));
362 quota_write32(struct quotafile *qf, const struct dqblk *dqb, int id)
377 if (lseek(qf->fd, off, SEEK_SET) == -1)
379 if (write(qf->fd, &dqb32, sizeof(dqb32)) == sizeof(dqb32))
385 quota_write64(struct quotafile *qf, const struct dqblk *dqb, int id)
400 if (lseek(qf->fd, off, SEEK_SET) == -1)
402 if (write(qf->fd, &dqb64, sizeof(dqb64)) == sizeof(dqb64))
408 quota_write_usage(struct quotafile *qf, struct dqblk *dqb, int id)
413 if (qf->fd == -1) {
414 qcmd = QCMD(Q_SETUSE, qf->quotatype);
415 return (quotactl(qf->fsname, qcmd, id, dqb));
420 if ((qf->accmode & O_RDWR) != O_RDWR) {
424 if (quota_read(qf, &dqbuf, id) != 0)
443 switch (qf->wordsize) {
445 return (quota_write32(qf, &dqbuf, id));
447 return (quota_write64(qf, &dqbuf, id));
456 quota_write_limits(struct quotafile *qf, struct dqblk *dqb, int id)
461 if (qf->fd == -1) {
462 qcmd = QCMD(Q_SETQUOTA, qf->quotatype);
463 return (quotactl(qf->fsname, qcmd, id, dqb));
468 if ((qf->accmode & O_RDWR) != O_RDWR) {
472 if (quota_read(qf, &dqbuf, id) != 0)
501 switch (qf->wordsize) {
503 return (quota_write32(qf, dqb, id));
505 return (quota_write64(qf, dqb, id));
517 quota_convert(struct quotafile *qf, int wordsize)
529 if ((qf->accmode & O_RDWR) != O_RDWR || qf->fd == -1) {
534 wordsize == qf->wordsize) {
538 maxid = quota_maxid(qf);
539 if ((newqf = calloc(1, sizeof(*qf))) == NULL) {
543 *newqf = *qf;
544 snprintf(newqf->qfname, MAXPATHLEN + 1, "%s_%d.orig", qf->qfname,
545 qf->wordsize);
546 if (rename(qf->qfname, newqf->qfname) < 0) {
550 if ((newqf->fd = open(qf->qfname, O_RDWR|O_CREAT|O_TRUNC|O_CLOEXEC,
571 if ((quota_read(qf, &dqblk, id)) < 0)
595 fd = qf->fd;
596 qf->fd = newqf->fd;
598 qf->wordsize = newqf->wordsize;
603 (void) rename(newqf->qfname, qf->qfname);