Deleted Added
full compact
quotafile.c (229403) quotafile.c (255007)
1/*-
2 * Copyright (c) 2008 Dag-Erling Co��dan Sm��rgrav
3 * Copyright (c) 2008 Marshall Kirk McKusick
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:

--- 11 unchanged lines hidden (view full) ---

20 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26 * SUCH DAMAGE.
27 *
1/*-
2 * Copyright (c) 2008 Dag-Erling Co��dan Sm��rgrav
3 * Copyright (c) 2008 Marshall Kirk McKusick
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:

--- 11 unchanged lines hidden (view full) ---

20 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26 * SUCH DAMAGE.
27 *
28 * $FreeBSD: head/lib/libutil/quotafile.c 229403 2012-01-03 18:51:58Z ed $
28 * $FreeBSD: head/lib/libutil/quotafile.c 255007 2013-08-28 21:10:37Z jilles $
29 */
30
31#include <sys/types.h>
32#include <sys/endian.h>
33#include <sys/mount.h>
34#include <sys/stat.h>
35
36#include <ufs/ufs/quota.h>

--- 95 unchanged lines hidden (view full) ---

132 qcmd = QCMD(Q_GETQUOTASIZE, quotatype);
133 if (quotactl(qf->fsname, qcmd, 0, &qf->wordsize) == 0)
134 return (qf);
135 if (serrno == 0) {
136 errno = EOPNOTSUPP;
137 goto error;
138 }
139 qf->accmode = openflags & O_ACCMODE;
29 */
30
31#include <sys/types.h>
32#include <sys/endian.h>
33#include <sys/mount.h>
34#include <sys/stat.h>
35
36#include <ufs/ufs/quota.h>

--- 95 unchanged lines hidden (view full) ---

132 qcmd = QCMD(Q_GETQUOTASIZE, quotatype);
133 if (quotactl(qf->fsname, qcmd, 0, &qf->wordsize) == 0)
134 return (qf);
135 if (serrno == 0) {
136 errno = EOPNOTSUPP;
137 goto error;
138 }
139 qf->accmode = openflags & O_ACCMODE;
140 if ((qf->fd = open(qf->qfname, qf->accmode)) < 0 &&
140 if ((qf->fd = open(qf->qfname, qf->accmode|O_CLOEXEC)) < 0 &&
141 (openflags & O_CREAT) != O_CREAT)
142 goto error;
143 /* File open worked, so process it */
144 if (qf->fd != -1) {
145 qf->wordsize = 32;
146 switch (read(qf->fd, &dqh, sizeof(dqh))) {
147 case -1:
148 goto error;

--- 14 unchanged lines hidden (view full) ---

163 return (qf);
164 default:
165 qf->wordsize = 32;
166 return (qf);
167 }
168 /* not reached */
169 }
170 /* open failed, but O_CREAT was specified, so create a new file */
141 (openflags & O_CREAT) != O_CREAT)
142 goto error;
143 /* File open worked, so process it */
144 if (qf->fd != -1) {
145 qf->wordsize = 32;
146 switch (read(qf->fd, &dqh, sizeof(dqh))) {
147 case -1:
148 goto error;

--- 14 unchanged lines hidden (view full) ---

163 return (qf);
164 default:
165 qf->wordsize = 32;
166 return (qf);
167 }
168 /* not reached */
169 }
170 /* open failed, but O_CREAT was specified, so create a new file */
171 if ((qf->fd = open(qf->qfname, O_RDWR|O_CREAT|O_TRUNC, 0)) < 0)
171 if ((qf->fd = open(qf->qfname, O_RDWR|O_CREAT|O_TRUNC|O_CLOEXEC, 0)) <
172 0)
172 goto error;
173 qf->wordsize = 64;
174 memset(&dqh, 0, sizeof(dqh));
175 memcpy(dqh.dqh_magic, Q_DQHDR64_MAGIC, sizeof(dqh.dqh_magic));
176 dqh.dqh_version = htobe32(Q_DQHDR64_VERSION);
177 dqh.dqh_hdrlen = htobe32(sizeof(struct dqhdr64));
178 dqh.dqh_reclen = htobe32(sizeof(struct dqblk64));
179 if (write(qf->fd, &dqh, sizeof(dqh)) != sizeof(dqh)) {

--- 349 unchanged lines hidden (view full) ---

529 }
530 *newqf = *qf;
531 snprintf(newqf->qfname, MAXPATHLEN + 1, "%s_%d.orig", qf->qfname,
532 qf->wordsize);
533 if (rename(qf->qfname, newqf->qfname) < 0) {
534 free(newqf);
535 return (-1);
536 }
173 goto error;
174 qf->wordsize = 64;
175 memset(&dqh, 0, sizeof(dqh));
176 memcpy(dqh.dqh_magic, Q_DQHDR64_MAGIC, sizeof(dqh.dqh_magic));
177 dqh.dqh_version = htobe32(Q_DQHDR64_VERSION);
178 dqh.dqh_hdrlen = htobe32(sizeof(struct dqhdr64));
179 dqh.dqh_reclen = htobe32(sizeof(struct dqblk64));
180 if (write(qf->fd, &dqh, sizeof(dqh)) != sizeof(dqh)) {

--- 349 unchanged lines hidden (view full) ---

530 }
531 *newqf = *qf;
532 snprintf(newqf->qfname, MAXPATHLEN + 1, "%s_%d.orig", qf->qfname,
533 qf->wordsize);
534 if (rename(qf->qfname, newqf->qfname) < 0) {
535 free(newqf);
536 return (-1);
537 }
537 if ((newqf->fd = open(qf->qfname, O_RDWR|O_CREAT|O_TRUNC, 0)) < 0) {
538 if ((newqf->fd = open(qf->qfname, O_RDWR|O_CREAT|O_TRUNC|O_CLOEXEC,
539 0)) < 0) {
538 serrno = errno;
539 goto error;
540 }
541 newqf->wordsize = wordsize;
542 if (wordsize == 64) {
543 memset(&dqh, 0, sizeof(dqh));
544 memcpy(dqh.dqh_magic, Q_DQHDR64_MAGIC, sizeof(dqh.dqh_magic));
545 dqh.dqh_version = htobe32(Q_DQHDR64_VERSION);

--- 48 unchanged lines hidden ---
540 serrno = errno;
541 goto error;
542 }
543 newqf->wordsize = wordsize;
544 if (wordsize == 64) {
545 memset(&dqh, 0, sizeof(dqh));
546 memcpy(dqh.dqh_magic, Q_DQHDR64_MAGIC, sizeof(dqh.dqh_magic));
547 dqh.dqh_version = htobe32(Q_DQHDR64_VERSION);

--- 48 unchanged lines hidden ---