Module Name:    src
Committed By:   bouyer
Date:           Fri Jan 28 18:36:06 UTC 2011

Modified Files:
        src/sys/ufs/ufs [bouyer-quota2]: quota2.h quota2_subr.c ufs_quota2.c

Log Message:
Introduce quota2_ufs_rwq2v() and quota2_ufs_rwq2e() functions, which
byteswap a quota2_val or quota2_entry if needed.
Use this to get quota2_entry in host order before calling q2etoprop().

quota2_walk_list() will byteswap the offset if needed to leave
it in FS byte order in callers.


To generate a diff of this commit:
cvs rdiff -u -r1.1.2.2 -r1.1.2.3 src/sys/ufs/ufs/quota2.h \
    src/sys/ufs/ufs/ufs_quota2.c
cvs rdiff -u -r1.1.2.1 -r1.1.2.2 src/sys/ufs/ufs/quota2_subr.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/ufs/ufs/quota2.h
diff -u src/sys/ufs/ufs/quota2.h:1.1.2.2 src/sys/ufs/ufs/quota2.h:1.1.2.3
--- src/sys/ufs/ufs/quota2.h:1.1.2.2	Fri Jan 21 16:58:06 2011
+++ src/sys/ufs/ufs/quota2.h	Fri Jan 28 18:36:06 2011
@@ -1,4 +1,4 @@
-/* $NetBSD: quota2.h,v 1.1.2.2 2011/01/21 16:58:06 bouyer Exp $ */
+/* $NetBSD: quota2.h,v 1.1.2.3 2011/01/28 18:36:06 bouyer Exp $ */
 /*-
   * Copyright (c) 2010 Manuel Bouyer
   * All rights reserved.
@@ -97,4 +97,6 @@
 /* quota2_subr.c */
 void quota2_addfreeq2e(struct quota2_header *, void *, uint64_t, uint64_t, int);
 void quota2_create_blk0(uint64_t, void *bp, int, int, int);
+void quota2_ufs_rwq2v(const struct quota2_val *, struct quota2_val *, int);
+void quota2_ufs_rwq2e(const struct quota2_entry *, struct quota2_entry *, int);
 #endif /*  _UFS_UFS_QUOTA2_H_ */
Index: src/sys/ufs/ufs/ufs_quota2.c
diff -u src/sys/ufs/ufs/ufs_quota2.c:1.1.2.2 src/sys/ufs/ufs/ufs_quota2.c:1.1.2.3
--- src/sys/ufs/ufs/ufs_quota2.c:1.1.2.2	Fri Jan 21 16:58:06 2011
+++ src/sys/ufs/ufs/ufs_quota2.c	Fri Jan 28 18:36:06 2011
@@ -1,4 +1,4 @@
-/* $NetBSD: ufs_quota2.c,v 1.1.2.2 2011/01/21 16:58:06 bouyer Exp $ */
+/* $NetBSD: ufs_quota2.c,v 1.1.2.3 2011/01/28 18:36:06 bouyer Exp $ */
 /*-
   * Copyright (c) 2010 Manuel Bouyer
   * All rights reserved.
@@ -28,7 +28,7 @@
   */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: ufs_quota2.c,v 1.1.2.2 2011/01/21 16:58:06 bouyer Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ufs_quota2.c,v 1.1.2.3 2011/01/28 18:36:06 bouyer Exp $");
 
 #include <sys/buf.h>
 #include <sys/param.h>
@@ -401,9 +401,10 @@
 	struct dquot *dq;
 	int error;
 	struct quota2_header *q2h;
-	struct quota2_entry *q2e;
+	struct quota2_entry *q2ep, q2e;
 	struct buf *bp;
 	prop_dictionary_t dict;
+	const int needswap = UFS_MPNEEDSWAP(ump);
 
 	if (ump->um_quotas[type] == NULLVP)
 		return ENODEV;
@@ -414,7 +415,7 @@
 			mutex_exit(&dqlock);
 			return error;
 		}
-		q2e = &q2h->q2h_defentry;
+		q2ep = &q2h->q2h_defentry;
 	} else {
 		error = dqget(NULLVP, id, ump, type, &dq);
 
@@ -426,11 +427,12 @@
 			return ENOENT;
 		}
 		error = getq2e(ump, type, dq->dq2_lblkno, dq->dq2_blkoff,
-		    &bp, &q2e, 0);
+		    &bp, &q2ep, 0);
 		if (error)
 			return error;
 	}
-	dict = q2etoprop(q2e, defaultq);
+	quota2_ufs_rwq2e(q2ep, &q2e, needswap);
+	dict = q2etoprop(&q2e, defaultq);
 	if (defaultq)
 		mutex_exit(&dqlock);
 	else
@@ -448,12 +450,15 @@
 
 static int
 quota2_getall_callback(struct ufsmount *ump, uint64_t *offp,
-    struct quota2_entry *q2e, uint64_t off, void *v)
+    struct quota2_entry *q2ep, uint64_t off, void *v)
 {
 	prop_array_t replies = v;
 	prop_dictionary_t dict;
+	const int needswap = UFS_MPNEEDSWAP(ump);
+	struct quota2_entry q2e;
 
-	dict = q2etoprop(q2e, 0);	
+	quota2_ufs_rwq2e(q2ep, &q2e, needswap);
+	dict = q2etoprop(&q2e, 0);	
 	if (!prop_array_add_and_rel(replies, dict)) {
 		return ENOMEM;
 	}
@@ -465,6 +470,7 @@
 {
 	int error;
 	struct quota2_header *q2h;
+	struct quota2_entry q2e;
 	struct buf *hbp;
 	prop_dictionary_t dict;
 	uint64_t offset;
@@ -477,14 +483,15 @@
 	error = getq2h(ump, type, &hbp, &q2h, 0);
 	if (error)
 		return error;
-	dict = q2etoprop(&q2h->q2h_defentry, 1);
+	quota2_ufs_rwq2e(&q2h->q2h_defentry, &q2e, needswap);
+	dict = q2etoprop(&q2e, 1);
 	if (!prop_array_add_and_rel(replies, dict)) {
 		brelse(hbp, 0);
 		return ENOMEM;
 	}
 	quota2_hash_size = ufs_rw16(q2h->q2h_hash_size, needswap);
 	for (i = 0; i < quota2_hash_size ; i++) {
-		offset = ufs_rw64(q2h->q2h_entries[i], needswap);
+		offset = q2h->q2h_entries[i], needswap;
 		error = quota2_walk_list(ump, hbp, type, &offset, 0, replies,
 		    quota2_getall_callback);
 		if (error)
@@ -533,7 +540,6 @@
 	int error;
 	daddr_t offset;
 	u_long hash_mask;
-	const int needswap = UFS_MPNEEDSWAP(ump);
 	struct dq2get_callback c = {
 		.id = id,
 		.dq = dq
@@ -545,7 +551,7 @@
 		goto out_mutex;
 	/* look for our entry */
 	hash_mask = ((1 << q2h->q2h_hash_shift) - 1);
-	offset = ufs_rw64(q2h->q2h_entries[id & hash_mask], needswap);
+	offset = q2h->q2h_entries[id & hash_mask];
 	error = quota2_walk_list(ump, bp, type, &offset, 0, (void *)&c,
 	    dq2get_callback);
 	brelse(bp, 0);

Index: src/sys/ufs/ufs/quota2_subr.c
diff -u src/sys/ufs/ufs/quota2_subr.c:1.1.2.1 src/sys/ufs/ufs/quota2_subr.c:1.1.2.2
--- src/sys/ufs/ufs/quota2_subr.c:1.1.2.1	Thu Jan 20 14:25:03 2011
+++ src/sys/ufs/ufs/quota2_subr.c	Fri Jan 28 18:36:06 2011
@@ -1,4 +1,4 @@
-/* $NetBSD: quota2_subr.c,v 1.1.2.1 2011/01/20 14:25:03 bouyer Exp $ */
+/* $NetBSD: quota2_subr.c,v 1.1.2.2 2011/01/28 18:36:06 bouyer Exp $ */
 /*-
   * Copyright (c) 2010 Manuel Bouyer
   * All rights reserved.
@@ -84,3 +84,24 @@
 	/* first quota entry, after the hash table */
 	quota2_addfreeq2e(q2h, bp, quota2_full_header_size, bsize, ns);
 }
+
+void
+quota2_ufs_rwq2v(const struct quota2_val *s, struct quota2_val *d, int needswap)
+{
+	d->q2v_hardlimit = ufs_rw64(s->q2v_hardlimit, needswap);
+	d->q2v_softlimit = ufs_rw64(s->q2v_softlimit, needswap);
+	d->q2v_cur = ufs_rw64(s->q2v_cur, needswap);
+	d->q2v_time = ufs_rw64(s->q2v_time, needswap);
+	d->q2v_grace = ufs_rw64(s->q2v_grace, needswap);
+}
+
+void
+quota2_ufs_rwq2e(const struct quota2_entry *s, struct quota2_entry *d,
+int needswap)
+{
+	quota2_ufs_rwq2v(&s->q2e_val[Q2V_BLOCK], &d->q2e_val[Q2V_BLOCK],
+	    needswap);
+	quota2_ufs_rwq2v(&s->q2e_val[Q2V_FILE], &d->q2e_val[Q2V_FILE],
+	    needswap);
+	d->q2e_uid = ufs_rw32(s->q2e_uid, needswap);
+}

Reply via email to