Changeset View
Changeset View
Standalone View
Standalone View
lib/libutil/quotafile.c
Show First 20 Lines • Show All 113 Lines • ▼ Show 20 Lines | |||||
struct quotafile * | struct quotafile * | ||||
quota_open(struct fstab *fs, int quotatype, int openflags) | quota_open(struct fstab *fs, int quotatype, int openflags) | ||||
{ | { | ||||
struct quotafile *qf; | struct quotafile *qf; | ||||
struct dqhdr64 dqh; | struct dqhdr64 dqh; | ||||
struct group *grp; | struct group *grp; | ||||
struct stat st; | struct stat st; | ||||
int qcmd, serrno; | int qcmd, serrno; | ||||
int ufs; | |||||
if ((qf = calloc(1, sizeof(*qf))) == NULL) | if ((qf = calloc(1, sizeof(*qf))) == NULL) | ||||
return (NULL); | return (NULL); | ||||
qf->fd = -1; | qf->fd = -1; | ||||
qf->quotatype = quotatype; | qf->quotatype = quotatype; | ||||
strlcpy(qf->fsname, fs->fs_file, sizeof(qf->fsname)); | strlcpy(qf->fsname, fs->fs_file, sizeof(qf->fsname)); | ||||
if (stat(qf->fsname, &st) != 0) | if (stat(qf->fsname, &st) != 0) | ||||
goto error; | goto error; | ||||
qf->dev = st.st_dev; | qf->dev = st.st_dev; | ||||
qcmd = QCMD(Q_GETQUOTASIZE, quotatype); | qcmd = QCMD(Q_GETQUOTASIZE, quotatype); | ||||
ufs = strcmp(fs->fs_vfstype, "ufs") == 0; | |||||
/* | |||||
* On UFS, hasquota() fills in qf->qfname. But we only care about | |||||
* this for UFS. So we need to call hasquota() for UFS, first. | |||||
*/ | |||||
if (ufs) { | |||||
serrno = hasquota(fs, quotatype, qf->qfname, | |||||
sizeof(qf->qfname)); | |||||
} | |||||
if (quotactl(qf->fsname, qcmd, 0, &qf->wordsize) == 0) | if (quotactl(qf->fsname, qcmd, 0, &qf->wordsize) == 0) | ||||
return (qf); | return (qf); | ||||
/* We only check the quota file for ufs */ | if (!ufs) { | ||||
if (strcmp(fs->fs_vfstype, "ufs")) { | |||||
errno = 0; | errno = 0; | ||||
goto error; | goto error; | ||||
} | } else if (serrno == 0) { | ||||
serrno = hasquota(fs, quotatype, qf->qfname, sizeof(qf->qfname)); | |||||
if (serrno == 0) { | |||||
errno = EOPNOTSUPP; | errno = EOPNOTSUPP; | ||||
goto error; | goto error; | ||||
} | } | ||||
qf->accmode = openflags & O_ACCMODE; | qf->accmode = openflags & O_ACCMODE; | ||||
if ((qf->fd = open(qf->qfname, qf->accmode|O_CLOEXEC)) < 0 && | if ((qf->fd = open(qf->qfname, qf->accmode|O_CLOEXEC)) < 0 && | ||||
(openflags & O_CREAT) != O_CREAT) | (openflags & O_CREAT) != O_CREAT) | ||||
goto error; | goto error; | ||||
/* File open worked, so process it */ | /* File open worked, so process it */ | ||||
▲ Show 20 Lines • Show All 452 Lines • Show Last 20 Lines |