
;
; Virtual Server Project
; Per Context Quota/Disk Limit Support
;
; (C) 2003-2004 Herbert Pötzl <herbert@13thfloor.at>
;
; this patch is free software; you can redistribute it and/or
; modify it under the terms of the GNU General Public License
; as published by the Free Software Foundation; either version 2
; of the License, or (at your option) any later version.
;
; this patch is distributed in the hope that it will be useful,
; but WITHOUT ANY WARRANTY; without even the implied warranty of
; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
; GNU General Public License for more details.
;

diff -NurpP --minimal linux-2.4.25-rc2-vs1.26/Documentation/Configure.help linux-2.4.25-rc2-vs1.26-q0.13/Documentation/Configure.help
--- linux-2.4.25-rc2-vs1.26/Documentation/Configure.help	2004-02-12 23:21:43.000000000 +0100
+++ linux-2.4.25-rc2-vs1.26-q0.13/Documentation/Configure.help	2004-02-13 00:53:54.000000000 +0100
@@ -13649,6 +13649,19 @@ CONFIG_VIOCD
   If you are running Linux on an IBM iSeries system and you want to
   read a CD drive owned by OS/400, say Y here.
 
+# Choice
+Persistent Context ID for files
+CONFIG_INOXID_NONE
+  Persistent Context IDs for your filesystem (ext2/ext3/jfs/reiser)
+  make it possible to do permission checks and per context quota,
+  which otherwise wouldn't be possible.
+
+  Disabled is the default (no context ids are stored on disc)
+  UID32/GID16 reduces GID to 16 bits, but leaves UID at 32
+  UID24/GID24 uses 8bit from UID and GID each for context id
+  UID32/GID32 uses otherwise reserved inode fields on disk
+              (only supported on ext2/ext3 for now)
+
 Quota support
 CONFIG_QUOTA
   If you say Y here, you will be able to set per user limits for disk
diff -NurpP --minimal linux-2.4.25-rc2-vs1.26/drivers/char/sysrq.c linux-2.4.25-rc2-vs1.26-q0.13/drivers/char/sysrq.c
--- linux-2.4.25-rc2-vs1.26/drivers/char/sysrq.c	2003-08-25 13:44:41.000000000 +0200
+++ linux-2.4.25-rc2-vs1.26-q0.13/drivers/char/sysrq.c	2004-02-13 00:53:54.000000000 +0100
@@ -146,6 +146,7 @@ static void go_sync(struct super_block *
 	if (remount_flag) { /* Remount R/O */
 		int ret, flags;
 		struct list_head *p;
+		struct dqhash *dqh;
 
 		if (sb->s_flags & MS_RDONLY) {
 			printk("R/O\n");
@@ -160,7 +161,9 @@ static void go_sync(struct super_block *
 				file->f_mode &= ~2;
 		}
 		file_list_unlock();
-		DQUOT_OFF(sb);
+		
+		list_for_each_entry(dqh, &sb->s_dqhs, dqh_sblist)
+			DQUOT_OFF(dqh);
 		fsync_dev(sb->s_dev);
 		flags = MS_RDONLY;
 		if (sb->s_op && sb->s_op->remount_fs) {
diff -NurpP --minimal linux-2.4.25-rc2-vs1.26/fs/Config.in linux-2.4.25-rc2-vs1.26-q0.13/fs/Config.in
--- linux-2.4.25-rc2-vs1.26/fs/Config.in	2004-02-12 22:58:34.000000000 +0100
+++ linux-2.4.25-rc2-vs1.26-q0.13/fs/Config.in	2004-02-13 00:53:54.000000000 +0100
@@ -4,6 +4,12 @@
 mainmenu_option next_comment
 comment 'File systems'
 
+choice 'Persistent Context ID for files'	\
+        "Disabled	CONFIG_INOXID_NONE	\
+         UID32/GID16	CONFIG_INOXID_GID16	\
+         UID24/GID24	CONFIG_INOXID_GID24	\
+         UID32/GID32	CONFIG_INOXID_GID32" Disabled
+
 bool 'Quota support' CONFIG_QUOTA
 dep_tristate '  VFS v0 quota format support' CONFIG_QFMT_V2 $CONFIG_QUOTA
 
diff -NurpP --minimal linux-2.4.25-rc2-vs1.26/fs/attr.c linux-2.4.25-rc2-vs1.26-q0.13/fs/attr.c
--- linux-2.4.25-rc2-vs1.26/fs/attr.c	2002-02-25 20:38:07.000000000 +0100
+++ linux-2.4.25-rc2-vs1.26-q0.13/fs/attr.c	2004-02-13 00:53:54.000000000 +0100
@@ -133,6 +133,7 @@ int notify_change(struct dentry * dentry
 	else {
 		error = inode_change_ok(inode, attr);
 		if (!error) {
+			/* should verify disk limit here */
 			if ((ia_valid & ATTR_UID && attr->ia_uid != inode->i_uid) ||
 			    (ia_valid & ATTR_GID && attr->ia_gid != inode->i_gid))
 				error = DQUOT_TRANSFER(inode, attr) ? -EDQUOT : 0;
@@ -143,6 +144,8 @@ int notify_change(struct dentry * dentry
 	unlock_kernel();
 	if (!error) {
 		unsigned long dn_mask = setattr_mask(ia_valid);
+
+		vx_dq_cond_modify(inode, current->vx_id);
 		if (dn_mask)
 			dnotify_parent(dentry, dn_mask);
 	}
diff -NurpP --minimal linux-2.4.25-rc2-vs1.26/fs/buffer.c linux-2.4.25-rc2-vs1.26-q0.13/fs/buffer.c
--- linux-2.4.25-rc2-vs1.26/fs/buffer.c	2004-02-12 22:58:34.000000000 +0100
+++ linux-2.4.25-rc2-vs1.26-q0.13/fs/buffer.c	2004-02-13 00:53:54.000000000 +0100
@@ -374,12 +374,14 @@ int sync_buffers(kdev_t dev, int wait)
 
 int fsync_super(struct super_block *sb)
 {
+	struct dqhash *dqh;
 	kdev_t dev = sb->s_dev;
 	sync_buffers(dev, 0);
 
 	lock_kernel();
 	sync_inodes_sb(sb);
-	DQUOT_SYNC_SB(sb);
+	list_for_each_entry(dqh, &sb->s_dqhs, dqh_sblist)
+		DQUOT_SYNC_DQH(dqh);
 	lock_super(sb);
 	if (sb->s_dirt && sb->s_op && sb->s_op->write_super)
 		sb->s_op->write_super(sb);
diff -NurpP --minimal linux-2.4.25-rc2-vs1.26/fs/dquot.c linux-2.4.25-rc2-vs1.26-q0.13/fs/dquot.c
--- linux-2.4.25-rc2-vs1.26/fs/dquot.c	2004-02-12 22:58:34.000000000 +0100
+++ linux-2.4.25-rc2-vs1.26-q0.13/fs/dquot.c	2004-02-13 00:53:54.000000000 +0100
@@ -68,6 +68,7 @@
 #include <linux/init.h>
 #include <linux/module.h>
 #include <linux/proc_fs.h>
+#include <linux/quotaops.h>
 
 #include <asm/uaccess.h>
 
@@ -150,7 +151,6 @@ static void put_quota_format(struct quot
 
 static LIST_HEAD(inuse_list);
 static LIST_HEAD(free_dquots);
-static struct list_head dquot_hash[NR_DQHASH];
 
 static void dqput(struct dquot *);
 static struct dquot *dqduplicate(struct dquot *);
@@ -175,31 +175,80 @@ static inline void put_dquot_dup_ref(str
 	dquot->dq_dup_ref--;
 }
 
-static inline int const hashfn(struct super_block *sb, unsigned int id, int type)
+	/* dqhash hash (meta) */
+
+static struct list_head dqhash_hash[NR_DQH_HASH];
+
+#define HASHSB(sb) ((unsigned int ) (sb))
+
+static inline int const dqh_hashfn(struct super_block *sb, unsigned int xid)
 {
-	return((HASHDEV(sb->s_dev) ^ id) * (MAXQUOTAS - type)) % NR_DQHASH;
+	return (HASHSB(sb) ^ xid) % NR_DQH_HASH;
 }
 
-static inline void insert_dquot_hash(struct dquot *dquot)
+static inline void insert_dqhash_hash(struct dqhash *hash)
 {
-	struct list_head *head = dquot_hash + hashfn(dquot->dq_sb, dquot->dq_id, dquot->dq_type);
+	unsigned int hashent = dqh_hashfn(hash->dqh_sb, hash->dqh_xid);
+	struct list_head *head = dqhash_hash + hashent;
+	
+	list_add(&hash->dqh_list, head);
+	list_add(&hash->dqh_sblist, &hash->dqh_sb->s_dqhs);
+}
+
+static inline void remove_dqhash_hash(struct dqhash *hash)
+{
+	list_del_init(&hash->dqh_list);
+	list_del_init(&hash->dqh_sblist);
+}
+
+static inline struct dqhash *find_dqhash(unsigned int hashent, struct super_block *sb, unsigned int xid)
+{
+	struct list_head *head;
+	struct dqhash *dqh;
+
+	for (head = dqhash_hash[hashent].next; head != dqhash_hash+hashent; head = head->next) {
+		dqh = list_entry(head, struct dqhash, dqh_list);
+		if (dqh->dqh_sb == sb && dqh->dqh_xid == xid)
+			return dqh;
+	}
+	return NULL;
+}
+
+/* Add a dquot to the head of the free list */
+
+	/* dquot hash functions */
+
+static inline int const hashfn(unsigned int id, int type)
+{
+	return ((id + 42) * (MAXQUOTAS - type)) % NR_DQHASH;
+}
+
+static inline void insert_dquot_hash(struct dqhash *hash, struct dquot *dquot)
+{
+	struct list_head *head = hash->dqh_hash + hashfn(dquot->dq_id, dquot->dq_type);
 	list_add(&dquot->dq_hash, head);
+	dquot->dq_dqh = dqhget(hash);
 }
 
 static inline void remove_dquot_hash(struct dquot *dquot)
 {
-	list_del(&dquot->dq_hash);
-	INIT_LIST_HEAD(&dquot->dq_hash);
+	struct dqhash *dqh = dquot->dq_dqh;
+
+	if (!dqh)
+		BUG();
+	list_del_init(&dquot->dq_hash);
+	dquot->dq_dqh = NULL;
+	dqhput(dqh);
 }
 
-static inline struct dquot *find_dquot(unsigned int hashent, struct super_block *sb, unsigned int id, int type)
+static inline struct dquot *find_dquot(struct dqhash *hash, unsigned int hashent, unsigned int id, int type)
 {
 	struct list_head *head;
 	struct dquot *dquot;
 
-	for (head = dquot_hash[hashent].next; head != dquot_hash+hashent; head = head->next) {
+	for (head = hash->dqh_hash[hashent].next; head != hash->dqh_hash+hashent; head = head->next) {
 		dquot = list_entry(head, struct dquot, dq_hash);
-		if (dquot->dq_sb == sb && dquot->dq_id == id && dquot->dq_type == type)
+		if (dquot->dq_id == id && dquot->dq_type == type)
 			return dquot;
 	}
 	return NODQUOT;
@@ -230,8 +279,7 @@ static inline void remove_free_dquot(str
 {
 	if (list_empty(&dquot->dq_free))
 		return;
-	list_del(&dquot->dq_free);
-	INIT_LIST_HEAD(&dquot->dq_free);
+	list_del_init(&dquot->dq_free);
 	dqstats.free_dquots--;
 }
 
@@ -317,7 +365,7 @@ repeat:
 static int read_dqblk(struct dquot *dquot)
 {
 	int ret;
-	struct quota_info *dqopt = sb_dqopt(dquot->dq_sb);
+	struct quota_info *dqopt = dqh_dqopt(dquot->dq_dqh);
 
 	lock_dquot(dquot);
 	down(&dqopt->dqio_sem);
@@ -330,7 +378,7 @@ static int read_dqblk(struct dquot *dquo
 static int commit_dqblk(struct dquot *dquot)
 {
 	int ret;
-	struct quota_info *dqopt = sb_dqopt(dquot->dq_sb);
+	struct quota_info *dqopt = dqh_dqopt(dquot->dq_dqh);
 
 	down(&dqopt->dqio_sem);
 	ret = dqopt->ops[dquot->dq_type]->commit_dqblk(dquot);
@@ -341,50 +389,126 @@ static int commit_dqblk(struct dquot *dq
 /* Invalidate all dquots on the list, wait for all users. Note that this function is called
  * after quota is disabled so no new quota might be created. As we only insert to the end of
  * inuse list, we don't have to restart searching... */
-static void invalidate_dquots(struct super_block *sb, int type)
+static void invalidate_dquots(struct dqhash *hash, int type)
 {
-	struct dquot *dquot;
-	struct list_head *head;
+	int i, temp;
 
-restart:
-	list_for_each(head, &inuse_list) {
-		dquot = list_entry(head, struct dquot, dq_inuse);
-		if (dquot->dq_sb != sb)
-			continue;
-		if (dquot->dq_type != type)
-			continue;
-		dquot->dq_flags |= DQ_INVAL;
-		if (dquot->dq_count)
-			/*
-			 *  Wait for any users of quota. As we have already cleared the flags in
-			 *  superblock and cleared all pointers from inodes we are assured
-			 *  that there will be no new users of this quota.
-			 */
-			__wait_dquot_unused(dquot);
-		/* Quota now have no users and it has been written on last dqput() */
-		remove_dquot_hash(dquot);
-		remove_free_dquot(dquot);
-		remove_inuse(dquot);
-		kmem_cache_free(dquot_cachep, dquot);
-		goto restart;
+	for (i=0; i<NR_DQHASH; i++) {
+		struct list_head *head = &hash->dqh_hash[i];
+
+		while ((head = head->next) != &hash->dqh_hash[i]) {
+			struct dquot *dquot = list_entry(head, struct dquot, dq_hash);
+
+			if (dquot->dq_type != type)
+				continue;
+
+			temp = dquot->dq_flags;
+			dquot->dq_flags |= DQ_INVAL;
+			if (dquot->dq_count) {
+				printk("··· quota in use: %p (%d)\n", dquot, dquot->dq_count);
+				printk("··· dquot (%d,%d,%d) dqh: %p (%d)\n",
+					dquot->dq_id, dquot->dq_type, temp,
+					dquot->dq_dqh, (dquot->dq_dqh?dquot->dq_dqh->dqh_xid:-1));
+				/*
+				 *  Wait for any users of quota. As we have already cleared the flags in
+				 *  superblock and cleared all pointers from inodes we are assured
+				 *  that there will be no new users of this quota.
+				 */
+				__wait_dquot_unused(dquot);
+			}
+				
+			remove_dquot_hash(dquot);
+			remove_free_dquot(dquot);
+			remove_inuse(dquot);
+			kmem_cache_free(dquot_cachep, dquot);
+			/* now restart */
+			head = &hash->dqh_hash[i];
+		}
 	}
 }
 
-static int vfs_quota_sync(struct super_block *sb, int type)
+/* Dquota Hash Management Functions */
+
+static unsigned int dqhash_id = 0;
+
+struct dqhash *new_dqhash(struct super_block *sb, unsigned int xid)
+{
+	struct dqhash *hash;
+	int i;
+	
+	hash = kmalloc(sizeof(struct dqhash),  GFP_USER);
+	if (!hash)
+		return ERR_PTR(-ENOMEM);
+
+	memset(hash, 0, sizeof(struct dqhash));
+	hash->dqh_id = dqhash_id++;
+	hash->dqh_xid = xid;
+	atomic_set(&hash->dqh_count, 1);
+	INIT_LIST_HEAD(&hash->dqh_list);
+	INIT_LIST_HEAD(&hash->dqh_sblist);
+	for (i = 0; i < NR_DQHASH; i++)
+		INIT_LIST_HEAD(hash->dqh_hash + i);
+	sema_init(&hash->dqh_dqopt.dqio_sem, 1);
+	sema_init(&hash->dqh_dqopt.dqoff_sem, 1);
+	hash->dqh_qop = sb->s_qop;
+	hash->dqh_qcop = sb->s_qcop;
+	hash->dqh_sb = sb;
+
+	hash->dqh_dlimit.dl_ilimit = NOILIMIT;
+	hash->dqh_dlimit.dl_blimit = NOBLIMIT;
+	hash->dqh_dlimit.dl_l2bsize = sb->s_blocksize_bits;
+	hash->dqh_dlimit.dl_nrlmult = (1 << 10) * 90 / 100;
+	init_rwsem(&hash->dqh_dlimit.dl_sem);
+
+	lock_kernel();
+	dprintk("··· new_dqhash: *%p[%d,#%d] sb:%p\n",
+		hash, hash->dqh_id, hash->dqh_xid, hash->dqh_sb);
+	insert_dqhash_hash(hash);
+	unlock_kernel();
+	return hash;
+}
+
+void destroy_dqhash(struct dqhash *hash)
+{
+	int cnt;
+
+	dprintk("··· destroy_dqhash: *%p[%d,#%d] sb:%p\n",
+		hash, hash->dqh_id, hash->dqh_xid, hash->dqh_sb);
+	lock_kernel();
+	remove_dqhash_hash(hash);
+	unlock_kernel();
+	for (cnt = 0; cnt < MAXQUOTAS; cnt++)	/* should not be required anymore! */
+		invalidate_dquots(hash, cnt);
+	hash->dqh_xid = -1;
+	kfree(hash);
+}
+
+struct dqhash *get_dqhash(struct super_block *sb, unsigned int xid)
+{
+	unsigned int hashent = dqh_hashfn(sb, xid);
+	struct dqhash *hash;
+
+	if ((hash = find_dqhash(hashent, sb, xid)))
+		return dqhget(hash);
+	return NULL;
+}
+
+
+static int vfs_quota_sync(struct dqhash *hash, int type)
 {
 	struct list_head *head;
 	struct dquot *dquot;
-	struct quota_info *dqopt = sb_dqopt(sb);
+	struct quota_info *dqopt = dqh_dqopt(hash);
 	int cnt;
 
 restart:
 	list_for_each(head, &inuse_list) {
 		dquot = list_entry(head, struct dquot, dq_inuse);
-		if (sb && dquot->dq_sb != sb)
+		if (hash && dquot->dq_dqh != hash)
 			continue;
                 if (type != -1 && dquot->dq_type != type)
 			continue;
-		if (!dquot->dq_sb)	/* Invalidated? */
+		if (!dquot->dq_dqh)	/* Invalidated? */
 			continue;
 		if (!dquot_dirty(dquot) && !(dquot->dq_flags & DQ_LOCKED))
 			continue;
@@ -396,16 +520,16 @@ restart:
 		if (dquot->dq_flags & DQ_LOCKED)
 			wait_on_dquot(dquot);
 		if (dquot_dirty(dquot))
-			sb->dq_op->write_dquot(dquot);
+			hash->dqh_qop->write_dquot(dquot);
 		dqput(dquot);
 		goto restart;
 	}
 	for (cnt = 0; cnt < MAXQUOTAS; cnt++)
-		if ((cnt == type || type == -1) && sb_has_quota_enabled(sb, cnt))
+		if ((cnt == type || type == -1) && dqh_has_quota_enabled(hash, cnt))
 			dqopt->info[cnt].dqi_flags &= ~DQF_ANY_DQUOT_DIRTY;
 	for (cnt = 0; cnt < MAXQUOTAS; cnt++)
-		if ((cnt == type || type == -1) && sb_has_quota_enabled(sb, cnt) && info_dirty(&dqopt->info[cnt]))
-			dqopt->ops[cnt]->write_file_info(sb, cnt);
+		if ((cnt == type || type == -1) && dqh_has_quota_enabled(hash, cnt) && info_dirty(&dqopt->info[cnt]))
+			dqopt->ops[cnt]->write_file_info(hash, cnt);
 	dqstats.syncs++;
 
 	return 0;
@@ -420,11 +544,19 @@ restart:
 	spin_lock(&sb_lock);
 	list_for_each(head, &super_blocks) {
 		struct super_block *sb = list_entry(head, struct super_block, s_list);
+		struct list_head *qhead;
 
-		for (cnt = 0, dirty = 0; cnt < MAXQUOTAS; cnt++)
-			if ((type == cnt || type == -1) && sb_has_quota_enabled(sb, cnt)
-			    && sb_dqopt(sb)->info[cnt].dqi_flags & DQF_ANY_DQUOT_DIRTY)
-				dirty = 1;
+		dirty = 0;
+		list_for_each(qhead, &sb->s_dqhs) {
+			struct dqhash *dqh = list_entry(qhead, struct dqhash, dqh_sblist);
+
+			for (cnt = 0; cnt < MAXQUOTAS; cnt++)
+				if ((type == cnt || type == -1) && dqh_has_quota_enabled(dqh, cnt)
+				&& dqh_dqopt(dqh)->info[cnt].dqi_flags & DQF_ANY_DQUOT_DIRTY)
+					dirty = 1;
+			if (dirty)
+				break;
+		}
 		if (!dirty)
 			continue;
 		sb->s_count++;
@@ -440,35 +572,44 @@ restart:
 	return NULL;
 }
 
+void sync_dquots_sb(struct super_block *sb, int type)
+{
+	struct list_head *head;
+	
+	lock_kernel();
+	list_for_each(head, &sb->s_dqhs) {
+		struct dqhash *dqh = list_entry(head, struct dqhash, dqh_sblist);
+
+		if (dqh->dqh_qcop->quota_sync)
+			dqh->dqh_qcop->quota_sync(dqh, type);
+	}
+	unlock_kernel();
+}
+
+
 void sync_dquots_dev(kdev_t dev, int type)
 {
 	struct super_block *sb;
 
 	if (dev) {
 		if ((sb = get_super(dev))) {
-			lock_kernel();
-			if (sb->s_qcop->quota_sync)
-				sb->s_qcop->quota_sync(sb, type);
-			unlock_kernel();
+			sync_dquots_sb(sb, type);
 			drop_super(sb);
 		}
 	}
 	else {
 		while ((sb = get_super_to_sync(type))) {
-			lock_kernel();
-			if (sb->s_qcop->quota_sync)
-				sb->s_qcop->quota_sync(sb, type);
-			unlock_kernel();
+			sync_dquots_sb(sb, type);
 			drop_super(sb);
 		}
 	}
 }
 
-void sync_dquots_sb(struct super_block *sb, int type)
+void sync_dquots_dqh(struct dqhash *hash, int type)
 {
 	lock_kernel();
-	if (sb->s_qcop->quota_sync)
-		sb->s_qcop->quota_sync(sb, type);
+	if (dqhash_valid(hash) && hash->dqh_qcop->quota_sync)
+		hash->dqh_qcop->quota_sync(hash, type);
 	unlock_kernel();
 }
 
@@ -543,7 +684,7 @@ we_slept:
 		return;
 	}
 	if (dquot_dirty(dquot)) {
-		dquot->dq_sb->dq_op->write_dquot(dquot);
+		dquot->dq_dqh->dqh_qop->write_dquot(dquot);
 		goto we_slept;
 	}
 
@@ -560,7 +701,7 @@ we_slept:
 	wake_up(&dquot->dq_wait_free);
 }
 
-static struct dquot *get_empty_dquot(struct super_block *sb, int type)
+static struct dquot *get_empty_dquot(kdev_t dev, int type)
 {
 	struct dquot *dquot;
 
@@ -574,8 +715,8 @@ static struct dquot *get_empty_dquot(str
 	INIT_LIST_HEAD(&dquot->dq_free);
 	INIT_LIST_HEAD(&dquot->dq_inuse);
 	INIT_LIST_HEAD(&dquot->dq_hash);
-	dquot->dq_sb = sb;
-	dquot->dq_dev = sb->s_dev;
+	dquot->dq_dqh = NULL;
+	dquot->dq_dev = dev;
 	dquot->dq_type = type;
 	dquot->dq_count = 1;
 	/* all dquots go on the inuse_list */
@@ -584,11 +725,11 @@ static struct dquot *get_empty_dquot(str
 	return dquot;
 }
 
-static struct dquot *dqget(struct super_block *sb, unsigned int id, int type)
+static struct dquot *dqget(struct dqhash *hash, unsigned int id, int type)
 {
-	unsigned int hashent = hashfn(sb, id, type);
+	unsigned int hashent = hashfn(id, type);
 	struct dquot *dquot, *empty = NODQUOT;
-	struct quota_info *dqopt = sb_dqopt(sb);
+	struct quota_info *dqopt = dqh_dqopt(hash);
 
 we_slept:
         if (!is_enabled(dqopt, type)) {
@@ -597,16 +738,17 @@ we_slept:
                 return NODQUOT;
 	}
 
-	if ((dquot = find_dquot(hashent, sb, id, type)) == NODQUOT) {
+	if ((dquot = find_dquot(hash, hashent, id, type)) == NODQUOT) {
 		if (empty == NODQUOT) {
-			if ((empty = get_empty_dquot(sb, type)) == NODQUOT)
+			kdev_t dev = hash->dqh_sb->s_dev;
+			if ((empty = get_empty_dquot(dev, type)) == NODQUOT)
 				schedule();	/* Try to wait for a moment... */
 			goto we_slept;
 		}
 		dquot = empty;
 		dquot->dq_id = id;
 		/* hash it first so it can be found */
-		insert_dquot_hash(dquot);
+		insert_dquot_hash(hash, dquot);
 		read_dqblk(dquot);
 	} else {
 		if (!dquot->dq_count)
@@ -618,7 +760,7 @@ we_slept:
 			dqput(empty);
 	}
 
-	if (!dquot->dq_sb) {	/* Has somebody invalidated entry under us? */
+	if (!dquot->dq_dqh) {	/* Has somebody invalidated entry under us? */
 		printk(KERN_ERR "VFS: dqget(): Quota invalidated in dqget()!\n");
 		dqput(dquot);
 		return NODQUOT;
@@ -634,7 +776,7 @@ static struct dquot *dqduplicate(struct 
 	if (dquot == NODQUOT)
 		return NODQUOT;
 	get_dquot_ref(dquot);
-	if (!dquot->dq_sb) {
+	if (!dquot->dq_dqh) {
 		printk(KERN_ERR "VFS: dqduplicate(): Invalidated quota to be duplicated!\n");
 		put_dquot_ref(dquot);
 		return NODQUOT;
@@ -675,20 +817,32 @@ static int dqinit_needed(struct inode *i
 	return 0;
 }
 
-static void add_dquot_ref(struct super_block *sb, int type)
+static void add_dquot_ref(struct dqhash *hash, int type)
 {
 	struct list_head *p;
+	struct super_block *sb = hash->dqh_sb;
 
 restart:
 	file_list_lock();
 	list_for_each(p, &sb->s_files) {
 		struct file *filp = list_entry(p, struct file, f_list);
 		struct inode *inode = filp->f_dentry->d_inode;
-		if (filp->f_mode & FMODE_WRITE && dqinit_needed(inode, type)) {
+
+		CHECK_DQHASH(inode);
+		if (filp->f_mode & FMODE_WRITE
+			&& hash->dqh_xid == inode->i_xid
+			&& dqinit_needed(inode, type)) {
 			struct vfsmount *mnt = mntget(filp->f_vfsmnt);
 			struct dentry *dentry = dget(filp->f_dentry);
+
+			/* an open file might have an xid but no hash yet */
+			if (inode->i_dqh && hash != inode->i_dqh)
+				printk("··· BAD INODE: add_dquot_ref(%p[%d], %d) %p[%d](%p) »%*s«\n",
+					hash, hash->dqh_xid, type, inode, inode->i_xid, inode->i_dqh,
+					filp->f_dentry->d_name.len, filp->f_dentry->d_name.name);
+
 			file_list_unlock();
-			sb->dq_op->initialize(inode, type);
+			hash->dqh_qop->initialize(inode, type);
 			dput(dentry);
 			mntput(mnt);
 			/* As we may have blocked we had better restart... */
@@ -696,6 +850,7 @@ restart:
 		}
 	}
 	file_list_unlock();
+	dqhget(hash);
 }
 
 /* Return 0 if dqput() won't block (note that 1 doesn't necessarily mean blocking) */
@@ -747,8 +902,7 @@ void put_dquot_list(struct list_head *to
 	while (act_head != tofree_head) {
 		dquot = list_entry(act_head, struct dquot, dq_free);
 		act_head = act_head->next;
-		list_del(&dquot->dq_free);	/* Remove dquot from the list so we won't have problems... */
-		INIT_LIST_HEAD(&dquot->dq_free);
+		list_del_init(&dquot->dq_free);	/* Remove from list to avoid problems... */
 		dqput(dquot);
 	}
 	unlock_kernel();
@@ -820,7 +974,7 @@ static void print_warning(struct dquot *
 	if (!need_print_warning(dquot, flag))
 		return;
 	dquot->dq_flags |= flag;
-	tty_write_message(current->tty, (char *)bdevname(dquot->dq_sb->s_dev));
+	tty_write_message(current->tty, (char *)bdevname(dquot->dq_dqh->dqh_sb->s_dev));
 	if (warntype == ISOFTWARN || warntype == BSOFTWARN)
 		tty_write_message(current->tty, ": warning, ");
 	else
@@ -860,7 +1014,7 @@ static inline void flush_warnings(struct
 
 static inline char ignore_hardlimit(struct dquot *dquot)
 {
-	struct mem_dqinfo *info = &sb_dqopt(dquot->dq_sb)->info[dquot->dq_type];
+	struct mem_dqinfo *info = &dqh_dqopt(dquot->dq_dqh)->info[dquot->dq_type];
 
 	return capable(CAP_SYS_RESOURCE) &&
 	    (info->dqi_format->qf_fmt_id != QFMT_VFS_OLD || !(info->dqi_flags & V1_DQF_RSQUASH));
@@ -891,7 +1045,7 @@ static int check_idq(struct dquot *dquot
 	   (dquot->dq_dqb.dqb_curinodes + inodes) > dquot->dq_dqb.dqb_isoftlimit &&
 	    dquot->dq_dqb.dqb_itime == 0) {
 		*warntype = ISOFTWARN;
-		dquot->dq_dqb.dqb_itime = CURRENT_TIME + sb_dqopt(dquot->dq_sb)->info[dquot->dq_type].dqi_igrace;
+		dquot->dq_dqb.dqb_itime = CURRENT_TIME + dqh_dqopt(dquot->dq_dqh)->info[dquot->dq_type].dqi_igrace;
 	}
 
 	return QUOTA_OK;
@@ -925,7 +1079,7 @@ static int check_bdq(struct dquot *dquot
 	    dquot->dq_dqb.dqb_btime == 0) {
 		if (!prealloc) {
 			*warntype = BSOFTWARN;
-			dquot->dq_dqb.dqb_btime = CURRENT_TIME + sb_dqopt(dquot->dq_sb)->info[dquot->dq_type].dqi_bgrace;
+			dquot->dq_dqb.dqb_btime = CURRENT_TIME + dqh_dqopt(dquot->dq_dqh)->info[dquot->dq_type].dqi_bgrace;
 		}
 		else
 			/*
@@ -946,17 +1100,30 @@ static int check_bdq(struct dquot *dquot
 void dquot_initialize(struct inode *inode, int type)
 {
 	struct dquot *dquot[MAXQUOTAS];
+	struct dqhash *dqh = NULL;
 	unsigned int id = 0;
 	int cnt;
 
+	dprintk("··· dquot_initialize(A): \t" DFM_INO ": " DFM_DQH ", " DFM_DQH "\n",
+		DBD_INO(inode), DBD_DQH(inode->i_dqh), DBD_DQH(dqh));
 	if (IS_NOQUOTA(inode))
 		return;
+
+	dqh = get_dqhash(inode->i_sb, current->vx_id);
+	dprintk("··· dquot_initialize: \t" DFM_INO ": " DFM_DQH ", " DFM_DQH "\n",
+		DBD_INO(inode), DBD_DQH(inode->i_dqh), DBD_DQH(dqh));
+	if (dqh && !inode->i_dqh) {
+		dprintk("··· MISSING DQH: \t" DFM_INO " add " DFM_DQH "\n",
+			DBD_INO(inode), DBD_DQH(dqh));
+		inode->i_dqh = dqh;
+	}
+
 	/* Build list of quotas to initialize... We can block here */
 	for (cnt = 0; cnt < MAXQUOTAS; cnt++) {
 		dquot[cnt] = NODQUOT;
 		if (type != -1 && cnt != type)
 			continue;
-		if (!sb_has_quota_enabled(inode->i_sb, cnt))
+		if (!dqh_has_quota_enabled(dqh, cnt))
 			continue;
 		if (inode->i_dquot[cnt] == NODQUOT) {
 			switch (cnt) {
@@ -967,13 +1134,17 @@ void dquot_initialize(struct inode *inod
 					id = inode->i_gid;
 					break;
 			}
-			dquot[cnt] = dqget(inode->i_sb, id, cnt);
+			dquot[cnt] = dqget(dqh, id, cnt);
 		}
 	}
+	dqhput(dqh);
+
 	/* NOBLOCK START: Here we shouldn't block */
 	for (cnt = 0; cnt < MAXQUOTAS; cnt++) {
-		if (dquot[cnt] == NODQUOT || !sb_has_quota_enabled(inode->i_sb, cnt) || inode->i_dquot[cnt] != NODQUOT)
+		if (dquot[cnt] == NODQUOT || !dqh_has_quota_enabled(dqh, cnt) || inode->i_dquot[cnt] != NODQUOT)
 			continue;
+		dprintk("··+ initialize: \t" DFM_INO ": " DFM_DQH " (%d)\n",
+			DBD_INO(inode), DBD_DQH(inode->i_dqh), cnt);
 		inode->i_dquot[cnt] = dquot[cnt];
 		dquot[cnt] = NODQUOT;
 		inode->i_flags |= S_QUOTA;
@@ -1057,7 +1228,7 @@ int dquot_alloc_inode(const struct inode
 	}
 	/* NOBLOCK Start */
 	for (cnt = 0; cnt < MAXQUOTAS; cnt++) {
-		dquot[cnt] = dqduplicate(inode -> i_dquot[cnt]);
+		dquot[cnt] = dqduplicate(inode->i_dquot[cnt]);
 		if (dquot[cnt] == NODQUOT)
 			continue;
 		if (check_idq(dquot[cnt], number, warntype+cnt) == NO_QUOTA)
@@ -1120,18 +1291,28 @@ void dquot_free_inode(const struct inode
 
 /*
  * Transfer the number of inode and blocks from one diskquota to an other.
- *
+ * If requested this, is also done from one quota hash to another.
  * This operation can block, but only after everything is updated
  */
-int dquot_transfer(struct inode *inode, struct iattr *iattr)
+int __dquot_transfer(struct inode *inode, struct iattr *iattr, struct dqhash *hash)
 {
 	qsize_t space;
 	struct dquot *transfer_from[MAXQUOTAS];
 	struct dquot *transfer_to[MAXQUOTAS];
-	int cnt, ret = NO_QUOTA, chuid = (iattr->ia_valid & ATTR_UID) && inode->i_uid != iattr->ia_uid,
-	    chgid = (iattr->ia_valid & ATTR_GID) && inode->i_gid != iattr->ia_gid;
+	struct dqhash *dqh = inode->i_dqh; /* use find_xid_dqhash(inode->i_sb) */
+	uid_t new_uid = (iattr->ia_valid & ATTR_UID) ? iattr->ia_uid : inode->i_uid;
+	gid_t new_gid = (iattr->ia_valid & ATTR_GID) ? iattr->ia_gid : inode->i_gid;
+	int cnt, chuid, chgid;
 	char warntype[MAXQUOTAS];
 
+	if (hash == dqh) {
+		chuid = (iattr->ia_valid & ATTR_UID) && inode->i_uid != iattr->ia_uid;
+		chgid = (iattr->ia_valid & ATTR_GID) && inode->i_gid != iattr->ia_gid;
+	}
+	/* transfer between quota hashes */
+	else
+		chuid = chgid = 1;
+
 	/* Clear the arrays */
 	for (cnt = 0; cnt < MAXQUOTAS; cnt++) {
 		transfer_to[cnt] = transfer_from[cnt] = NODQUOT;
@@ -1139,30 +1320,34 @@ int dquot_transfer(struct inode *inode, 
 	}
 	/* First build the transfer_to list - here we can block on reading of dquots... */
 	for (cnt = 0; cnt < MAXQUOTAS; cnt++) {
-		if (!sb_has_quota_enabled(inode->i_sb, cnt))
+		if (!dqh_has_quota_enabled(hash, cnt))
 			continue;
 		switch (cnt) {
 			case USRQUOTA:
 				if (!chuid)
 					continue;
-				transfer_to[cnt] = dqget(inode->i_sb, iattr->ia_uid, cnt);
+				transfer_to[cnt] = dqget(hash, new_uid, cnt);
+				dprintk("··+ usr transfer to: \t" DFM_DQH " (%d,%d) = $%p\n",
+					DBD_DQH(hash), new_uid, cnt, transfer_to[cnt]);
 				break;
 			case GRPQUOTA:
 				if (!chgid)
 					continue;
-				transfer_to[cnt] = dqget(inode->i_sb, iattr->ia_gid, cnt);
+				transfer_to[cnt] = dqget(hash, new_gid, cnt);
+				dprintk("··+ grp transfer to: \t" DFM_DQH " (%d,%d) = $%p\n",
+					DBD_DQH(hash), new_uid, cnt, transfer_to[cnt]);
 				break;
 		}
 	}
+
 	/* NOBLOCK START: From now on we shouldn't block */
 	space = inode_get_bytes(inode);
 	/* Build the transfer_from list and check the limits */
 	for (cnt = 0; cnt < MAXQUOTAS; cnt++) {
-		/* The second test can fail when quotaoff is in progress... */
-		if (transfer_to[cnt] == NODQUOT || !sb_has_quota_enabled(inode->i_sb, cnt))
-			continue;
-		transfer_from[cnt] = dqduplicate(inode->i_dquot[cnt]);
-		if (transfer_from[cnt] == NODQUOT)	/* Can happen on quotafiles (quota isn't initialized on them)... */
+		if (dqh_has_quota_enabled(dqh, cnt))
+			transfer_from[cnt] = dqduplicate(inode->i_dquot[cnt]);
+		if (transfer_to[cnt] == NODQUOT || !dqh_has_quota_enabled(hash, cnt))
+			/* transfer to noquota domain ... */
 			continue;
 		if (check_idq(transfer_to[cnt], 1, warntype+cnt) == NO_QUOTA ||
 		    check_bdq(transfer_to[cnt], space, 0, warntype+cnt) == NO_QUOTA)
@@ -1172,30 +1357,38 @@ int dquot_transfer(struct inode *inode, 
 	/*
 	 * Finally perform the needed transfer from transfer_from to transfer_to
 	 */
+	inode->i_flags &= ~S_QUOTA;
 	for (cnt = 0; cnt < MAXQUOTAS; cnt++) {
-		/*
-		 * Skip changes for same uid or gid or for non-existing quota-type.
-		 */
-		if (transfer_from[cnt] == NODQUOT || transfer_to[cnt] == NODQUOT)
+		if (transfer_from[cnt] == NODQUOT && transfer_to[cnt] == NODQUOT)
+			/* nothing to transfer ... */
 			continue;
 
-		dquot_decr_inodes(transfer_from[cnt], 1);
-		dquot_decr_space(transfer_from[cnt], space);
-
-		dquot_incr_inodes(transfer_to[cnt], 1);
-		dquot_incr_space(transfer_to[cnt], space);
-
-		if (inode->i_dquot[cnt] == NODQUOT)
-			BUG();
+		if (transfer_from[cnt] != NODQUOT) {
+			dprintk("··+ decrement: $%p\n", transfer_from[cnt]);
+			dquot_decr_inodes(transfer_from[cnt], 1);
+			dquot_decr_space(transfer_from[cnt], space);
+		}
+		if (transfer_to[cnt] != NODQUOT) {
+			dprintk("··+ increment: $%p\n", transfer_to[cnt]);
+			dquot_incr_inodes(transfer_to[cnt], 1);
+			dquot_incr_space(transfer_to[cnt], space);
+			inode->i_flags |= S_QUOTA;
+		}
 		inode->i_dquot[cnt] = transfer_to[cnt];
-		/*
-		 * We've got to release transfer_from[] twice - once for dquot_transfer() and
-		 * once for inode. We don't want to release transfer_to[] as it's now placed in inode
-		 */
-		transfer_to[cnt] = transfer_from[cnt];
 	}
+	
 	/* NOBLOCK END. From now on we can block as we wish */
-	ret = QUOTA_OK;
+
+	for (cnt = 0; cnt < MAXQUOTAS; cnt++) {
+		/* First we must put duplicate - otherwise we might deadlock */
+		if (transfer_from[cnt] != NODQUOT) {
+			dqputduplicate(transfer_from[cnt]);
+			/* release for inode */
+			dqput(transfer_from[cnt]);
+		}
+	}
+	return QUOTA_OK;
+
 warn_put_all:
 	flush_warnings(transfer_to, warntype);
 	for (cnt = 0; cnt < MAXQUOTAS; cnt++) {
@@ -1205,9 +1398,58 @@ warn_put_all:
 		if (transfer_to[cnt] != NODQUOT)
 			dqput(transfer_to[cnt]);
 	}
+	return NO_QUOTA;
+}
+
+int dquot_transfer(struct inode *inode, struct iattr *iattr)
+{
+	return __dquot_transfer(inode, iattr, inode->i_dqh);
+}
+
+int dqhash_transfer(struct inode *inode, struct dqhash *hash)
+{
+	struct iattr iattr;
+	int ret = 0;
+	
+	dprintk("··· dqhash_transfer(A): \t" DFM_INO ": " DFM_DQH " -> " DFM_DQH "\n",
+		DBD_INO(inode), DBD_DQH(inode->i_dqh), DBD_DQH(hash));
+	if (hash == inode->i_dqh)
+		return ret;
+	dprintk("··· dqhash_transfer(B): \t" DFM_INO ": " DFM_DQH " -> " DFM_DQH "\n",
+		DBD_INO(inode), DBD_DQH(inode->i_dqh), DBD_DQH(hash));
+	if (IS_NOQUOTA(inode) || (!IS_QUOTAINIT(inode) && inode->i_dqh))
+		return ret;
+	dprintk("··· dqhash_transfer: \t" DFM_INO ": " DFM_DQH " -> " DFM_DQH "\n",
+		DBD_INO(inode), DBD_DQH(inode->i_dqh), DBD_DQH(hash));
+	iattr.ia_valid = 0;
+	ret = __dquot_transfer(inode, &iattr, hash);
+	return ret;
+}
+
+int dlimit_transfer(struct inode *inode, struct dqhash *hash)
+{
+	qsize_t space;
+	int ret = 0;
+
+	if (hash == inode->i_dqh)
+		return ret;
+
+	space = inode_get_bytes(inode);
+
+	/* check for available space, and then? */
+	
+	if (dqhash_valid(inode->i_dqh)) {
+		dlimit_decr_inodes(inode->i_dqh, 1);
+		dlimit_decr_space(inode->i_dqh, space);
+	}
+	if (dqhash_valid(hash)) {
+		dlimit_incr_inodes(hash, 1);
+		dlimit_incr_space(hash, space);
+	}
 	return ret;
 }
 
+
 /*
  * Definitions of diskquota operations.
  */
@@ -1253,19 +1495,17 @@ static inline void reset_enable_flags(st
 }
 
 /* Function in inode.c - remove pointers to dquots in icache */
-extern void remove_dquot_ref(struct super_block *, int);
+extern void remove_dquot_ref(struct dqhash *, int);
 
 /*
- * Turn quota off on a device. type == -1 ==> quotaoff for all types (umount)
+ * Turn quota off on a hash. type == -1 ==> quotaoff for all types (umount)
  */
-int vfs_quota_off(struct super_block *sb, int type)
+int vfs_quota_off(struct dqhash *hash, int type)
 {
 	int cnt;
-	struct quota_info *dqopt = sb_dqopt(sb);
+	struct quota_info *dqopt = dqh_dqopt(hash);
 
 	lock_kernel();
-	if (!sb)
-		goto out;
 
 	/* We need to serialize quota_off() for device */
 	down(&dqopt->dqoff_sem);
@@ -1277,12 +1517,12 @@ int vfs_quota_off(struct super_block *sb
 		reset_enable_flags(dqopt, cnt);
 
 		/* Note: these are blocking operations */
-		remove_dquot_ref(sb, cnt);
-		invalidate_dquots(sb, cnt);
+		remove_dquot_ref(hash, cnt);
+		invalidate_dquots(hash, cnt);
 		if (info_dirty(&dqopt->info[cnt]))
-			dqopt->ops[cnt]->write_file_info(sb, cnt);
+			dqopt->ops[cnt]->write_file_info(hash, cnt);
 		if (dqopt->ops[cnt]->free_file_info)
-			dqopt->ops[cnt]->free_file_info(sb, cnt);
+			dqopt->ops[cnt]->free_file_info(hash, cnt);
 		put_quota_format(dqopt->info[cnt].dqi_format);
 
 		fput(dqopt->files[cnt]);
@@ -1293,16 +1533,15 @@ int vfs_quota_off(struct super_block *sb
 		dqopt->ops[cnt] = NULL;
 	}
 	up(&dqopt->dqoff_sem);
-out:
 	unlock_kernel();
 	return 0;
 }
 
-int vfs_quota_on(struct super_block *sb, int type, int format_id, char *path)
+int vfs_quota_on(struct dqhash *hash, int type, int format_id, char *path)
 {
 	struct file *f = NULL;
 	struct inode *inode;
-	struct quota_info *dqopt = sb_dqopt(sb);
+	struct quota_info *dqopt = dqh_dqopt(hash);
 	struct quota_format_type *fmt = find_quota_format(format_id);
 	int error;
 
@@ -1314,9 +1553,11 @@ int vfs_quota_on(struct super_block *sb,
 	}
 
 	down(&dqopt->dqoff_sem);
+	dprintk("··· vfs_quota_on: %p, type=%d, format=%d, path=%s\n", hash, type, format_id, path);
 
 	f = filp_open(path, O_RDWR, 0600);
 
+	dprintk("··· vfs_quota_on: file=%p\n", f);
 	error = PTR_ERR(f);
 	if (IS_ERR(f))
 		goto out_lock;
@@ -1329,7 +1570,7 @@ int vfs_quota_on(struct super_block *sb,
 	if (!S_ISREG(inode->i_mode))
 		goto out_f;
 	error = -EINVAL;
-	if (!fmt->qf_ops->check_quota_file(sb, type))
+	if (!fmt->qf_ops->check_quota_file(hash, type))
 		goto out_f;
 	/* We don't want quota and atime on quota files */
 	dquot_drop(inode);
@@ -1337,11 +1578,11 @@ int vfs_quota_on(struct super_block *sb,
 
 	dqopt->ops[type] = fmt->qf_ops;
 	dqopt->info[type].dqi_format = fmt;
-	if ((error = dqopt->ops[type]->read_file_info(sb, type)) < 0)
+	if ((error = dqopt->ops[type]->read_file_info(hash, type)) < 0)
 		goto out_f;
 	set_enable_flags(dqopt, type);
 
-	add_dquot_ref(sb, type);
+	add_dquot_ref(hash, type);
 
 	up(&dqopt->dqoff_sem);
 	return 0;
@@ -1374,9 +1615,9 @@ static void do_get_dqblk(struct dquot *d
 	di->dqb_valid = QIF_ALL;
 }
 
-int vfs_get_dqblk(struct super_block *sb, int type, qid_t id, struct if_dqblk *di)
+int vfs_get_dqblk(struct dqhash *hash, int type, qid_t id, struct if_dqblk *di)
 {
-	struct dquot *dquot = dqget(sb, id, type);
+	struct dquot *dquot = dqget(hash, id, type);
 
 	if (!dquot)
 		return -EINVAL;
@@ -1420,7 +1661,7 @@ static void do_set_dqblk(struct dquot *d
 			dquot->dq_flags &= ~DQ_BLKS;
 		}
 		else if (!(di->dqb_valid & QIF_BTIME))	/* Set grace only if user hasn't provided his own... */
-			dm->dqb_btime = CURRENT_TIME + sb_dqopt(dquot->dq_sb)->info[dquot->dq_type].dqi_bgrace;
+			dm->dqb_btime = CURRENT_TIME + dqh_dqopt(dquot->dq_dqh)->info[dquot->dq_type].dqi_bgrace;
 	}
 	if (check_ilim) {
 		if (!dm->dqb_isoftlimit || dm->dqb_curinodes < dm->dqb_isoftlimit) {
@@ -1428,7 +1669,7 @@ static void do_set_dqblk(struct dquot *d
 			dquot->dq_flags &= ~DQ_INODES;
 		}
 		else if (!(di->dqb_valid & QIF_ITIME))	/* Set grace only if user hasn't provided his own... */
-			dm->dqb_itime = CURRENT_TIME + sb_dqopt(dquot->dq_sb)->info[dquot->dq_type].dqi_igrace;
+			dm->dqb_itime = CURRENT_TIME + dqh_dqopt(dquot->dq_dqh)->info[dquot->dq_type].dqi_igrace;
 	}
 	if (dm->dqb_bhardlimit || dm->dqb_bsoftlimit || dm->dqb_ihardlimit || dm->dqb_isoftlimit)
 		dquot->dq_flags &= ~DQ_FAKE;
@@ -1437,9 +1678,9 @@ static void do_set_dqblk(struct dquot *d
 	dquot->dq_flags |= DQ_MOD;
 }
 
-int vfs_set_dqblk(struct super_block *sb, int type, qid_t id, struct if_dqblk *di)
+int vfs_set_dqblk(struct dqhash *hash, int type, qid_t id, struct if_dqblk *di)
 {
-	struct dquot *dquot = dqget(sb, id, type);
+	struct dquot *dquot = dqget(hash, id, type);
 
 	if (!dquot)
 		return -EINVAL;
@@ -1449,9 +1690,9 @@ int vfs_set_dqblk(struct super_block *sb
 }
 
 /* Generic routine for getting common part of quota file information */
-int vfs_get_dqinfo(struct super_block *sb, int type, struct if_dqinfo *ii)
+int vfs_get_dqinfo(struct dqhash *hash, int type, struct if_dqinfo *ii)
 {
-	struct mem_dqinfo *mi = sb_dqopt(sb)->info + type;
+	struct mem_dqinfo *mi = dqh_dqopt(hash)->info + type;
 
 	ii->dqi_bgrace = mi->dqi_bgrace;
 	ii->dqi_igrace = mi->dqi_igrace;
@@ -1461,9 +1702,9 @@ int vfs_get_dqinfo(struct super_block *s
 }
 
 /* Generic routine for setting common part of quota file information */
-int vfs_set_dqinfo(struct super_block *sb, int type, struct if_dqinfo *ii)
+int vfs_set_dqinfo(struct dqhash *hash, int type, struct if_dqinfo *ii)
 {
-	struct mem_dqinfo *mi = sb_dqopt(sb)->info + type;
+	struct mem_dqinfo *mi = dqh_dqopt(hash)->info + type;
 
 	if (ii->dqi_valid & IIF_BGRACE)
 		mi->dqi_bgrace = ii->dqi_bgrace;
@@ -1507,13 +1748,19 @@ static ctl_table sys_table[] = {
 	{},
 };
 
-static int __init dquot_init(void)
+int	__init init_dqhash_hash(void)
 {
 	int i;
 
+	dprintk("··· dqhash init?\n");
+	for (i = 0; i < NR_DQH_HASH; i++)
+		INIT_LIST_HEAD(dqhash_hash + i);
+	return 0;
+}
+
+static int __init dquot_init(void)
+{
 	register_sysctl_table(sys_table, 0);
-	for (i = 0; i < NR_DQHASH; i++)
-		INIT_LIST_HEAD(dquot_hash + i);
 	printk(KERN_NOTICE "VFS: Disk quotas v%s\n", __DQUOT_VERSION__);
 
 	return 0;
diff -NurpP --minimal linux-2.4.25-rc2-vs1.26/fs/ext2/balloc.c linux-2.4.25-rc2-vs1.26-q0.13/fs/ext2/balloc.c
--- linux-2.4.25-rc2-vs1.26/fs/ext2/balloc.c	2003-06-13 16:51:37.000000000 +0200
+++ linux-2.4.25-rc2-vs1.26-q0.13/fs/ext2/balloc.c	2004-02-13 00:53:54.000000000 +0100
@@ -359,7 +359,7 @@ int ext2_new_block (struct inode * inode
 	struct buffer_head * bh2;
 	char * p, * r;
 	int i, j, k, tmp;
-	int bitmap_nr;
+	int bitmap_nr, sys_res;
 	struct super_block * sb;
 	struct ext2_group_desc * gdp;
 	struct ext2_super_block * es;
@@ -374,12 +374,14 @@ int ext2_new_block (struct inode * inode
 	}
 
 	lock_super (sb);
+	sys_res = (sb->u.ext2_sb.s_resuid == current->fsuid) ||
+		(sb->u.ext2_sb.s_resgid != 0 &&
+	          in_group_p (sb->u.ext2_sb.s_resgid)) ||
+	        capable(CAP_SYS_RESOURCE);
+
 	es = sb->u.ext2_sb.s_es;
 	if (le32_to_cpu(es->s_free_blocks_count) <= le32_to_cpu(es->s_r_blocks_count) &&
-	    ((sb->u.ext2_sb.s_resuid != current->fsuid) &&
-	     (sb->u.ext2_sb.s_resgid == 0 ||
-	      !in_group_p (sb->u.ext2_sb.s_resgid)) && 
-	     !capable(CAP_SYS_RESOURCE)))
+		!sys_res)
 		goto out;
 
 	ext2_debug ("goal=%lu.\n", goal);
@@ -508,7 +510,11 @@ got_block:
 	/*
 	 * Check quota for allocation of this block.
 	 */
-	if(DQUOT_ALLOC_BLOCK(inode, 1)) {
+	if (!dlimit_block_avail(inode->i_sb, sys_res, 1)) {
+		*err = -ENOSPC;
+		goto out;
+	}
+	if (DQUOT_ALLOC_BLOCK(inode, 1)) {
 		*err = -EDQUOT;
 		goto out;
 	}
@@ -553,6 +559,8 @@ got_block:
 		for (k = 1;
 		     k < prealloc_goal && (j + k) < EXT2_BLOCKS_PER_GROUP(sb);
 		     k++, next_block++) {
+			if (!dlimit_block_avail(inode->i_sb, sys_res, 1))
+				break;
 			if (DQUOT_PREALLOC_BLOCK(inode, 1))
 				break;
 			/* Writer: ->i_prealloc* */
diff -NurpP --minimal linux-2.4.25-rc2-vs1.26/fs/ext2/ialloc.c linux-2.4.25-rc2-vs1.26-q0.13/fs/ext2/ialloc.c
--- linux-2.4.25-rc2-vs1.26/fs/ext2/ialloc.c	2004-02-12 23:21:43.000000000 +0100
+++ linux-2.4.25-rc2-vs1.26-q0.13/fs/ext2/ialloc.c	2004-02-13 00:53:54.000000000 +0100
@@ -327,6 +327,8 @@ struct inode * ext2_new_inode (const str
 	inode = new_inode(sb);
 	if (!inode)
 		return ERR_PTR(-ENOMEM);
+	if (!dlimit_inodes_avail(sb, 1))
+		return ERR_PTR(-ENOSPC);
 
 	lock_super (sb);
 	es = sb->u.ext2_sb.s_es;
@@ -396,7 +398,7 @@ repeat:
 	mark_inode_dirty(inode);
 
 	unlock_super (sb);
-	if(DQUOT_ALLOC_INODE(inode)) {
+	if (DQUOT_ALLOC_INODE(inode)) {
 		DQUOT_DROP(inode);
 		inode->i_flags |= S_NOQUOTA;
 		inode->i_nlink = 0;
diff -NurpP --minimal linux-2.4.25-rc2-vs1.26/fs/ext2/inode.c linux-2.4.25-rc2-vs1.26-q0.13/fs/ext2/inode.c
--- linux-2.4.25-rc2-vs1.26/fs/ext2/inode.c	2004-02-12 23:21:43.000000000 +0100
+++ linux-2.4.25-rc2-vs1.26-q0.13/fs/ext2/inode.c	2004-02-13 00:53:54.000000000 +0100
@@ -924,6 +924,8 @@ void ext2_read_inode (struct inode * ino
 	unsigned long block;
 	unsigned long offset;
 	struct ext2_group_desc * gdp;
+	uid_t uid;
+	gid_t gid;
 
 	if ((inode->i_ino != EXT2_ROOT_INO && inode->i_ino != EXT2_ACL_IDX_INO &&
 	     inode->i_ino != EXT2_ACL_DATA_INO &&
@@ -966,12 +968,19 @@ void ext2_read_inode (struct inode * ino
 	raw_inode = (struct ext2_inode *) (bh->b_data + offset);
 
 	inode->i_mode = le16_to_cpu(raw_inode->i_mode);
-	inode->i_uid = (uid_t)le16_to_cpu(raw_inode->i_uid_low);
-	inode->i_gid = (gid_t)le16_to_cpu(raw_inode->i_gid_low);
+	uid = (uid_t)le16_to_cpu(raw_inode->i_uid_low);
+	gid = (gid_t)le16_to_cpu(raw_inode->i_gid_low);
 	if(!(test_opt (inode->i_sb, NO_UID32))) {
-		inode->i_uid |= le16_to_cpu(raw_inode->i_uid_high) << 16;
-		inode->i_gid |= le16_to_cpu(raw_inode->i_gid_high) << 16;
+		uid |= le16_to_cpu(raw_inode->i_uid_high) << 16;
+		gid |= le16_to_cpu(raw_inode->i_gid_high) << 16;
 	}
+	inode->i_uid = INOXID_UID(uid, gid);
+	inode->i_gid = INOXID_GID(uid, gid);
+	if (inode->i_sb->s_flags & MS_TAGXID) {
+		int xid = INOXID_XID(uid, gid, le16_to_cpu(raw_inode->i_raw_xid));
+		__vx_dq_modify(inode, xid);
+	}	
+
 	inode->i_nlink = le16_to_cpu(raw_inode->i_links_count);
 	inode->i_size = le32_to_cpu(raw_inode->i_size);
 	inode->i_atime = le32_to_cpu(raw_inode->i_atime);
@@ -1054,6 +1063,8 @@ static int ext2_update_inode(struct inod
 	unsigned long offset;
 	int err = 0;
 	struct ext2_group_desc * gdp;
+	uid_t uid;
+	gid_t gid;
 
 	if ((inode->i_ino != EXT2_ROOT_INO &&
 	     inode->i_ino < EXT2_FIRST_INO(inode->i_sb)) ||
@@ -1098,27 +1109,33 @@ static int ext2_update_inode(struct inod
 	if (inode->u.ext2_i.i_state & EXT2_STATE_NEW)
 		memset(raw_inode, 0, EXT2_SB(inode->i_sb)->s_inode_size);
 
+	uid = XIDINO_UID(inode->i_uid, inode->i_xid);
+	gid = XIDINO_GID(inode->i_gid, inode->i_xid);
+
 	raw_inode->i_mode = cpu_to_le16(inode->i_mode);
 	if(!(test_opt(inode->i_sb, NO_UID32))) {
-		raw_inode->i_uid_low = cpu_to_le16(low_16_bits(inode->i_uid));
-		raw_inode->i_gid_low = cpu_to_le16(low_16_bits(inode->i_gid));
+		raw_inode->i_uid_low = cpu_to_le16(low_16_bits(uid));
+		raw_inode->i_gid_low = cpu_to_le16(low_16_bits(gid));
 /*
  * Fix up interoperability with old kernels. Otherwise, old inodes get
  * re-used with the upper 16 bits of the uid/gid intact
  */
 		if(!inode->u.ext2_i.i_dtime) {
-			raw_inode->i_uid_high = cpu_to_le16(high_16_bits(inode->i_uid));
-			raw_inode->i_gid_high = cpu_to_le16(high_16_bits(inode->i_gid));
+			raw_inode->i_uid_high = cpu_to_le16(high_16_bits(uid));
+			raw_inode->i_gid_high = cpu_to_le16(high_16_bits(gid));
 		} else {
 			raw_inode->i_uid_high = 0;
 			raw_inode->i_gid_high = 0;
 		}
 	} else {
-		raw_inode->i_uid_low = cpu_to_le16(fs_high2lowuid(inode->i_uid));
-		raw_inode->i_gid_low = cpu_to_le16(fs_high2lowgid(inode->i_gid));
+		raw_inode->i_uid_low = cpu_to_le16(fs_high2lowuid(uid));
+		raw_inode->i_gid_low = cpu_to_le16(fs_high2lowgid(gid));
 		raw_inode->i_uid_high = 0;
 		raw_inode->i_gid_high = 0;
 	}
+#ifdef CONFIG_INOXID_GID32	
+	raw_inode->i_raw_xid = cpu_to_le16(inode->i_xid);
+#endif
 	raw_inode->i_links_count = cpu_to_le16(inode->i_nlink);
 	raw_inode->i_size = cpu_to_le32(inode->i_size);
 	raw_inode->i_atime = cpu_to_le32(inode->i_atime);
diff -NurpP --minimal linux-2.4.25-rc2-vs1.26/fs/ext2/super.c linux-2.4.25-rc2-vs1.26-q0.13/fs/ext2/super.c
--- linux-2.4.25-rc2-vs1.26/fs/ext2/super.c	2004-02-12 22:58:34.000000000 +0100
+++ linux-2.4.25-rc2-vs1.26-q0.13/fs/ext2/super.c	2004-02-13 00:53:54.000000000 +0100
@@ -180,6 +180,10 @@ static int parse_options (char * options
 		else if (!strcmp (this_char, "nouid32")) {
 			set_opt (*mount_options, NO_UID32);
 		}
+		else if (!strcmp (this_char, "tagctx"))
+			set_opt (*mount_options, TAG_XID);
+		else if (!strcmp (this_char, "tagxid"))
+			set_opt (*mount_options, TAG_XID);
 		else if (!strcmp (this_char, "check")) {
 			if (!value || !*value || !strcmp (value, "none"))
 				clear_opt (*mount_options, CHECK);
@@ -450,6 +454,8 @@ struct super_block * ext2_read_super (st
 	    &sb->u.ext2_sb.s_mount_opt)) {
 		return NULL;
 	}
+	if (sb->u.ext2_sb.s_mount_opt & EXT2_MOUNT_TAG_XID)
+		sb->s_flags |= MS_TAGXID;
 
 	if (set_blocksize(dev, blocksize) < 0) {
 		printk ("EXT2-fs: unable to set blocksize %d\n", blocksize);
diff -NurpP --minimal linux-2.4.25-rc2-vs1.26/fs/ext3/balloc.c linux-2.4.25-rc2-vs1.26-q0.13/fs/ext3/balloc.c
--- linux-2.4.25-rc2-vs1.26/fs/ext3/balloc.c	2003-06-13 16:51:37.000000000 +0200
+++ linux-2.4.25-rc2-vs1.26-q0.13/fs/ext3/balloc.c	2004-02-13 00:53:54.000000000 +0100
@@ -538,7 +538,7 @@ int ext3_new_block (handle_t *handle, st
 	char * p, * r;
 #endif
 	int i, j, k, tmp, alloctmp;
-	int bitmap_nr;
+	int bitmap_nr, sys_res;
 	int fatal = 0, err;
 	int performed_allocation = 0;
 	struct super_block * sb;
@@ -563,13 +563,20 @@ int ext3_new_block (handle_t *handle, st
 	}
 
 	lock_super (sb);
+	sys_res = (sb->u.ext3_sb.s_resuid == current->fsuid) ||
+		(sb->u.ext3_sb.s_resgid != 0 &&
+		 in_group_p (sb->u.ext3_sb.s_resgid)) ||
+		capable(CAP_SYS_RESOURCE);
+
+	if (!dlimit_block_avail(inode->i_sb, sys_res, 1)) {
+		*errp = -ENOSPC;
+		goto out;
+	}
+
 	es = sb->u.ext3_sb.s_es;
 	if (le32_to_cpu(es->s_free_blocks_count) <=
 			le32_to_cpu(es->s_r_blocks_count) &&
-	    ((sb->u.ext3_sb.s_resuid != current->fsuid) &&
-	     (sb->u.ext3_sb.s_resgid == 0 ||
-	      !in_group_p (sb->u.ext3_sb.s_resgid)) && 
-	     !capable(CAP_SYS_RESOURCE)))
+			!sys_res)
 		goto out;
 
 	ext3_debug ("goal=%lu.\n", goal);
@@ -747,6 +754,8 @@ got_block:
 		for (k = 1;
 		     k < prealloc_goal && (j + k) < EXT3_BLOCKS_PER_GROUP(sb);
 		     k++, next_block++) {
+			if (!dlimit_block_avail(inode->i_sb, sys_res, 1))
+				break;
 			if (DQUOT_PREALLOC_BLOCK(inode, 1))
 				break;
 			/* Writer: ->i_prealloc* */
diff -NurpP --minimal linux-2.4.25-rc2-vs1.26/fs/ext3/ialloc.c linux-2.4.25-rc2-vs1.26-q0.13/fs/ext3/ialloc.c
--- linux-2.4.25-rc2-vs1.26/fs/ext3/ialloc.c	2004-02-12 23:21:43.000000000 +0100
+++ linux-2.4.25-rc2-vs1.26-q0.13/fs/ext3/ialloc.c	2004-02-13 00:53:54.000000000 +0100
@@ -318,6 +318,8 @@ struct inode * ext3_new_inode (handle_t 
 	inode = new_inode(sb);
 	if (!inode)
 		return ERR_PTR(-ENOMEM);
+	if (!dlimit_inodes_avail(sb, 1))
+			return ERR_PTR(-ENOSPC);
 	init_rwsem(&inode->u.ext3_i.truncate_sem);
 
 	lock_super (sb);
@@ -511,7 +513,7 @@ repeat:
 	if (err) goto fail;
 	
 	unlock_super (sb);
-	if(DQUOT_ALLOC_INODE(inode)) {
+	if (DQUOT_ALLOC_INODE(inode)) {
 		DQUOT_DROP(inode);
 		inode->i_flags |= S_NOQUOTA;
 		inode->i_nlink = 0;
diff -NurpP --minimal linux-2.4.25-rc2-vs1.26/fs/ext3/inode.c linux-2.4.25-rc2-vs1.26-q0.13/fs/ext3/inode.c
--- linux-2.4.25-rc2-vs1.26/fs/ext3/inode.c	2004-02-12 23:21:43.000000000 +0100
+++ linux-2.4.25-rc2-vs1.26-q0.13/fs/ext3/inode.c	2004-02-13 00:53:54.000000000 +0100
@@ -2112,6 +2112,8 @@ void ext3_read_inode(struct inode * inod
 	struct ext3_inode *raw_inode;
 	struct buffer_head *bh;
 	int block;
+	uid_t uid;
+	gid_t gid;
 	
 	if(ext3_get_inode_loc(inode, &iloc))
 		goto bad_inode;
@@ -2119,12 +2121,19 @@ void ext3_read_inode(struct inode * inod
 	raw_inode = iloc.raw_inode;
 	init_rwsem(&inode->u.ext3_i.truncate_sem);
 	inode->i_mode = le16_to_cpu(raw_inode->i_mode);
-	inode->i_uid = (uid_t)le16_to_cpu(raw_inode->i_uid_low);
-	inode->i_gid = (gid_t)le16_to_cpu(raw_inode->i_gid_low);
+	uid = (uid_t)le16_to_cpu(raw_inode->i_uid_low);
+	gid = (gid_t)le16_to_cpu(raw_inode->i_gid_low);
 	if(!(test_opt (inode->i_sb, NO_UID32))) {
-		inode->i_uid |= le16_to_cpu(raw_inode->i_uid_high) << 16;
-		inode->i_gid |= le16_to_cpu(raw_inode->i_gid_high) << 16;
+		uid |= le16_to_cpu(raw_inode->i_uid_high) << 16;
+		gid |= le16_to_cpu(raw_inode->i_gid_high) << 16;
 	}
+	inode->i_uid = INOXID_UID(uid, gid);
+	inode->i_gid = INOXID_GID(uid, gid);
+	if (inode->i_sb->s_flags & MS_TAGXID) {
+		int xid = INOXID_XID(uid, gid, le16_to_cpu(raw_inode->i_raw_xid));
+		__vx_dq_modify(inode, xid);
+	}
+	
 	inode->i_nlink = le16_to_cpu(raw_inode->i_links_count);
 	inode->i_size = le32_to_cpu(raw_inode->i_size);
 	inode->i_atime = le32_to_cpu(raw_inode->i_atime);
@@ -2223,6 +2232,8 @@ static int ext3_do_update_inode(handle_t
 	struct ext3_inode *raw_inode = iloc->raw_inode;
 	struct buffer_head *bh = iloc->bh;
 	int err = 0, rc, block;
+	uid_t uid;
+	gid_t gid;
 
 	if (handle) {
 		BUFFER_TRACE(bh, "get_write_access");
@@ -2235,31 +2246,37 @@ static int ext3_do_update_inode(handle_t
 	if (EXT3_I(inode)->i_state & EXT3_STATE_NEW)
 		memset(raw_inode, 0, EXT3_SB(inode->i_sb)->s_inode_size);
 
+	uid = XIDINO_UID(inode->i_uid, inode->i_xid);
+	gid = XIDINO_GID(inode->i_gid, inode->i_xid);
+	
 	raw_inode->i_mode = cpu_to_le16(inode->i_mode);
 	if(!(test_opt(inode->i_sb, NO_UID32))) {
-		raw_inode->i_uid_low = cpu_to_le16(low_16_bits(inode->i_uid));
-		raw_inode->i_gid_low = cpu_to_le16(low_16_bits(inode->i_gid));
+		raw_inode->i_uid_low = cpu_to_le16(low_16_bits(uid));
+		raw_inode->i_gid_low = cpu_to_le16(low_16_bits(gid));
 /*
  * Fix up interoperability with old kernels. Otherwise, old inodes get
  * re-used with the upper 16 bits of the uid/gid intact
  */
 		if(!inode->u.ext3_i.i_dtime) {
 			raw_inode->i_uid_high =
-				cpu_to_le16(high_16_bits(inode->i_uid));
+				cpu_to_le16(high_16_bits(uid));
 			raw_inode->i_gid_high =
-				cpu_to_le16(high_16_bits(inode->i_gid));
+				cpu_to_le16(high_16_bits(gid));
 		} else {
 			raw_inode->i_uid_high = 0;
 			raw_inode->i_gid_high = 0;
 		}
 	} else {
 		raw_inode->i_uid_low =
-			cpu_to_le16(fs_high2lowuid(inode->i_uid));
+			cpu_to_le16(fs_high2lowuid(uid));
 		raw_inode->i_gid_low =
-			cpu_to_le16(fs_high2lowgid(inode->i_gid));
+			cpu_to_le16(fs_high2lowgid(gid));
 		raw_inode->i_uid_high = 0;
 		raw_inode->i_gid_high = 0;
 	}
+#ifdef CONFIG_INOXID_GID32
+        raw_inode->i_raw_xid = cpu_to_le16(inode->i_xid);
+#endif
 	raw_inode->i_links_count = cpu_to_le16(inode->i_nlink);
 	raw_inode->i_size = cpu_to_le32(inode->u.ext3_i.i_disksize);
 	raw_inode->i_atime = cpu_to_le32(inode->i_atime);
diff -NurpP --minimal linux-2.4.25-rc2-vs1.26/fs/ext3/ioctl.c linux-2.4.25-rc2-vs1.26-q0.13/fs/ext3/ioctl.c
--- linux-2.4.25-rc2-vs1.26/fs/ext3/ioctl.c	2004-02-12 23:21:43.000000000 +0100
+++ linux-2.4.25-rc2-vs1.26-q0.13/fs/ext3/ioctl.c	2004-02-13 00:53:54.000000000 +0100
@@ -149,6 +149,38 @@ flags_err:
 			return ret;
 		}
 #endif
+#ifndef CONFIG_INOXID_NONE
+	case EXT3_IOC_SETXID: {
+		handle_t *handle;
+		struct ext3_iloc iloc;
+		int xid;
+		int err;
+
+		/* fixme: if stealth, return -ENOTTY */
+		if (!capable(CAP_CONTEXT))
+			return -EPERM;
+		if (IS_RDONLY(inode))
+			return -EROFS;
+		if (!(inode->i_sb->s_flags & MS_TAGXID))
+			return -ENOSYS;
+		if (get_user(xid, (int *) arg))
+			return -EFAULT;	
+
+		handle = ext3_journal_start(inode, 1);
+		if (IS_ERR(handle))
+			return PTR_ERR(handle);
+		err = ext3_reserve_inode_write(handle, inode, &iloc);
+		if (err)
+			return err;
+
+		inode->i_xid = (xid & 0xFFFF);
+		inode->i_ctime = CURRENT_TIME;
+
+		err = ext3_mark_iloc_dirty(handle, inode, &iloc);
+		ext3_journal_stop(handle, inode);
+		return err;
+	}
+#endif
 	default:
 		return -ENOTTY;
 	}
diff -NurpP --minimal linux-2.4.25-rc2-vs1.26/fs/ext3/super.c linux-2.4.25-rc2-vs1.26-q0.13/fs/ext3/super.c
--- linux-2.4.25-rc2-vs1.26/fs/ext3/super.c	2004-02-12 22:58:34.000000000 +0100
+++ linux-2.4.25-rc2-vs1.26-q0.13/fs/ext3/super.c	2004-02-13 00:53:54.000000000 +0100
@@ -521,6 +521,10 @@ static int parse_options (char * options
 		else if (!strcmp (this_char, "nouid32")) {
 			set_opt (*mount_options, NO_UID32);
 		}
+		else if (!strcmp (this_char, "tagctx"))
+			set_opt (*mount_options, TAG_XID);
+		else if (!strcmp (this_char, "tagxid"))
+			set_opt (*mount_options, TAG_XID);
 		else if (!strcmp (this_char, "abort"))
 			set_opt (*mount_options, ABORT);
 		else if (!strcmp (this_char, "check")) {
@@ -955,6 +959,8 @@ struct super_block * ext3_read_super (st
 		sb->s_dev = 0;
 		goto out_fail;
 	}
+	if (sbi->s_mount_opt & EXT3_MOUNT_TAG_XID)
+		sb->s_flags |= MS_TAGXID;
 
 	sb->s_blocksize = blocksize;
 	set_blocksize (dev, blocksize);
@@ -1154,7 +1160,7 @@ struct super_block * ext3_read_super (st
 	 * set up enough so that it can read an inode
 	 */
 	sb->s_op = &ext3_sops;
-	sb->dq_op = &ext3_qops;
+	sb->s_qop = &ext3_qops;
 	INIT_LIST_HEAD(&sbi->s_orphan); /* unlinked but open files */
 
 	sb->s_root = 0;
@@ -1808,7 +1814,7 @@ static int ext3_write_dquot(struct dquot
 {
 	int nblocks, ret;
 	handle_t *handle;
-	struct quota_info *dqops = sb_dqopt(dquot->dq_sb);
+	struct quota_info *dqops = dqh_dqopt(dquot->dq_dqh);
 	struct inode *qinode;
 
 	switch (dqops->info[dquot->dq_type].dqi_format->qf_fmt_id) {
diff -NurpP --minimal linux-2.4.25-rc2-vs1.26/fs/inode.c linux-2.4.25-rc2-vs1.26-q0.13/fs/inode.c
--- linux-2.4.25-rc2-vs1.26/fs/inode.c	2004-02-12 22:58:34.000000000 +0100
+++ linux-2.4.25-rc2-vs1.26-q0.13/fs/inode.c	2004-02-13 00:53:54.000000000 +0100
@@ -97,6 +97,11 @@ static struct inode *alloc_inode(struct 
 		struct address_space * const mapping = &inode->i_data;
 
 		inode->i_sb = sb;
+		if (sb->s_flags & MS_TAGXID)
+			inode->i_xid = current->vx_id;
+		else
+			inode->i_xid = 0;       /* maybe xid -1 would be better? */
+		inode->i_dqh = get_dqhash(sb, inode->i_xid);
 		inode->i_dev = sb->s_dev;
 		inode->i_blkbits = sb->s_blocksize_bits;
 		inode->i_flags = 0;
@@ -125,6 +130,8 @@ static struct inode *alloc_inode(struct 
 
 static void destroy_inode(struct inode *inode) 
 {
+	if (dqhash_valid(inode->i_dqh))
+		dqhput(inode->i_dqh);
 	if (inode_has_buffers(inode))
 		BUG();
 	/* Reinitialise the waitqueue head because __wait_on_freeing_inode()
@@ -1397,13 +1404,14 @@ void update_mctime (struct inode *inode)
 void put_dquot_list(struct list_head *);
 int remove_inode_dquot_ref(struct inode *, short, struct list_head *);
 
-void remove_dquot_ref(struct super_block *sb, short type)
+void remove_dquot_ref(struct dqhash *hash, short type)
 {
 	struct inode *inode;
 	struct list_head *act_head;
+	struct super_block *sb = hash->dqh_sb;
 	LIST_HEAD(tofree_head);
 
-	if (!sb->dq_op)
+	if (!hash->dqh_qop)
 		return;	/* nothing to do */
 	/* We have to be protected against other CPUs */
 	lock_kernel();		/* This lock is for quota code */
@@ -1411,33 +1419,75 @@ void remove_dquot_ref(struct super_block
  
 	list_for_each(act_head, &inode_in_use) {
 		inode = list_entry(act_head, struct inode, i_list);
-		if (inode->i_sb == sb && IS_QUOTAINIT(inode))
+		if (inode->i_dqh == hash && IS_QUOTAINIT(inode))
 			remove_inode_dquot_ref(inode, type, &tofree_head);
 	}
 	list_for_each(act_head, &inode_unused) {
 		inode = list_entry(act_head, struct inode, i_list);
-		if (inode->i_sb == sb && IS_QUOTAINIT(inode))
+		if (inode->i_dqh == hash && IS_QUOTAINIT(inode))
 			remove_inode_dquot_ref(inode, type, &tofree_head);
 	}
 	list_for_each(act_head, &inode_unused_pagecache) {
 		inode = list_entry(act_head, struct inode, i_list);
-		if (inode->i_sb == sb && IS_QUOTAINIT(inode))
+		if (inode->i_dqh == hash && IS_QUOTAINIT(inode))
 			remove_inode_dquot_ref(inode, type, &tofree_head);
 	}
 	list_for_each(act_head, &sb->s_dirty) {
 		inode = list_entry(act_head, struct inode, i_list);
-		if (IS_QUOTAINIT(inode))
+		if (inode->i_dqh == hash && IS_QUOTAINIT(inode))
 			remove_inode_dquot_ref(inode, type, &tofree_head);
 	}
 	list_for_each(act_head, &sb->s_locked_inodes) {
 		inode = list_entry(act_head, struct inode, i_list);
-		if (IS_QUOTAINIT(inode))
+		if (inode->i_dqh == hash && IS_QUOTAINIT(inode))
 			remove_inode_dquot_ref(inode, type, &tofree_head);
 	}
 	spin_unlock(&inode_lock);
 	unlock_kernel();
 
 	put_dquot_list(&tofree_head);
+	dqhput(hash); /* is this required? */
+}
+
+int remove_inode_dqhash_ref(struct inode *);
+
+void remove_dqhash_ref(struct dqhash *hash)
+{
+	struct list_head *act_head;
+	struct super_block *sb = hash->dqh_sb;
+	struct inode *inode;
+
+	lock_kernel();          /* This lock is for quota code */
+	spin_lock(&inode_lock); /* This lock is for inodes code */
+
+	list_for_each(act_head, &inode_in_use) {
+		inode = list_entry(act_head, struct inode, i_list);
+		if (inode->i_dqh == hash)
+			remove_inode_dqhash_ref(inode);
+	}
+	list_for_each(act_head, &inode_unused) {
+		inode = list_entry(act_head, struct inode, i_list);
+		if (inode->i_dqh == hash)
+			remove_inode_dqhash_ref(inode);
+	}
+	list_for_each(act_head, &inode_unused_pagecache) {
+		inode = list_entry(act_head, struct inode, i_list);
+		if (inode->i_dqh == hash)
+			remove_inode_dqhash_ref(inode);
+	}
+	list_for_each(act_head, &sb->s_dirty) {
+		inode = list_entry(act_head, struct inode, i_list);
+		if (inode->i_dqh == hash)
+			remove_inode_dqhash_ref(inode);
+	}
+	list_for_each(act_head, &sb->s_locked_inodes) {
+		inode = list_entry(act_head, struct inode, i_list);
+		if (inode->i_dqh == hash)
+			remove_inode_dqhash_ref(inode);
+	}
+	spin_unlock(&inode_lock);
+	unlock_kernel();
 }
 
+
 #endif
diff -NurpP --minimal linux-2.4.25-rc2-vs1.26/fs/ioctl.c linux-2.4.25-rc2-vs1.26-q0.13/fs/ioctl.c
--- linux-2.4.25-rc2-vs1.26/fs/ioctl.c	2004-02-12 23:21:43.000000000 +0100
+++ linux-2.4.25-rc2-vs1.26-q0.13/fs/ioctl.c	2004-02-13 00:53:54.000000000 +0100
@@ -115,6 +115,40 @@ asmlinkage long sys_ioctl(unsigned int f
 			else
 				error = -ENOTTY;
 			break;
+#ifndef CONFIG_INOXID_NONE
+		case FIOC_GETXID: {
+			struct inode *inode = filp->f_dentry->d_inode;
+
+			/* fixme: if stealth, return -ENOTTY */
+			error = -EPERM;
+			if (capable(CAP_CONTEXT))
+				error = put_user(inode->i_xid, (int *) arg);
+			break;
+		}
+		case FIOC_SETXID: {
+			struct inode *inode = filp->f_dentry->d_inode;
+			int xid;
+
+			/* fixme: if stealth, return -ENOTTY */
+			error = -EPERM;
+			if (!capable(CAP_CONTEXT))
+				break;
+			error = -EROFS;
+			if (IS_RDONLY(inode))
+				break;
+			error = -ENOSYS;
+			if (!(inode->i_sb->s_flags & MS_TAGXID))
+				break;
+			error = -EFAULT;
+			if (get_user(xid, (int *) arg))
+				break;
+			error = 0;
+			inode->i_xid = (xid & 0xFFFF);
+			inode->i_ctime = CURRENT_TIME;
+			mark_inode_dirty(inode);
+			break;	
+		}
+#endif
 		case FIOC_GETXFLG:
 		case FIOC_SETXFLG:
 			error = -ENOTTY;
diff -NurpP --minimal linux-2.4.25-rc2-vs1.26/fs/jfs/jfs_imap.c linux-2.4.25-rc2-vs1.26-q0.13/fs/jfs/jfs_imap.c
--- linux-2.4.25-rc2-vs1.26/fs/jfs/jfs_imap.c	2003-11-28 19:26:21.000000000 +0100
+++ linux-2.4.25-rc2-vs1.26-q0.13/fs/jfs/jfs_imap.c	2004-02-13 00:53:54.000000000 +0100
@@ -3101,14 +3101,21 @@ static void duplicateIXtree(struct super
 static int copy_from_dinode(struct dinode * dip, struct inode *ip)
 {
 	struct jfs_inode_info *jfs_ip = JFS_IP(ip);
+	uid_t uid;
+	gid_t gid;
 
 	jfs_ip->fileset = le32_to_cpu(dip->di_fileset);
 	jfs_ip->mode2 = le32_to_cpu(dip->di_mode);
 
 	ip->i_mode = le32_to_cpu(dip->di_mode) & 0xffff;
 	ip->i_nlink = le32_to_cpu(dip->di_nlink);
-	ip->i_uid = le32_to_cpu(dip->di_uid);
-	ip->i_gid = le32_to_cpu(dip->di_gid);
+
+	uid = le32_to_cpu(dip->di_uid);
+	gid = le32_to_cpu(dip->di_gid);
+	ip->i_uid = INOXID_UID(uid, gid);
+	ip->i_gid = INOXID_GID(uid, gid);
+	ip->i_xid = INOXID_XID(uid, gid, 0);
+	
 	ip->i_size = le64_to_cpu(dip->di_size);
 	ip->i_atime = le32_to_cpu(dip->di_atime.tv_sec);
 	ip->i_mtime = le32_to_cpu(dip->di_mtime.tv_sec);
@@ -3154,6 +3161,8 @@ static int copy_from_dinode(struct dinod
 static void copy_to_dinode(struct dinode * dip, struct inode *ip)
 {
 	struct jfs_inode_info *jfs_ip = JFS_IP(ip);
+	uid_t uid;
+	gid_t gid;
 
 	dip->di_fileset = cpu_to_le32(jfs_ip->fileset);
 	dip->di_inostamp = cpu_to_le32(JFS_SBI(ip->i_sb)->inostamp);
@@ -3162,8 +3171,11 @@ static void copy_to_dinode(struct dinode
 	dip->di_size = cpu_to_le64(ip->i_size);
 	dip->di_nblocks = cpu_to_le64(PBLK2LBLK(ip->i_sb, ip->i_blocks));
 	dip->di_nlink = cpu_to_le32(ip->i_nlink);
-	dip->di_uid = cpu_to_le32(ip->i_uid);
-	dip->di_gid = cpu_to_le32(ip->i_gid);
+
+	uid = XIDINO_UID(ip->i_uid, ip->i_xid);
+	gid = XIDINO_GID(ip->i_gid, ip->i_xid);
+	dip->di_uid = cpu_to_le32(uid);
+	dip->di_gid = cpu_to_le32(gid);
 	/*
 	 * mode2 is only needed for storing the higher order bits.
 	 * Trust i_mode for the lower order ones
diff -NurpP --minimal linux-2.4.25-rc2-vs1.26/fs/namei.c linux-2.4.25-rc2-vs1.26-q0.13/fs/namei.c
--- linux-2.4.25-rc2-vs1.26/fs/namei.c	2004-02-12 23:21:43.000000000 +0100
+++ linux-2.4.25-rc2-vs1.26-q0.13/fs/namei.c	2004-02-13 00:53:54.000000000 +0100
@@ -206,10 +206,22 @@ int vfs_permission(struct inode * inode,
 	return -EACCES;
 }
 
+static inline int xid_permission(struct inode *inode)
+{
+	if (inode->i_xid == 0)
+		return 0;
+	if (vx_check(inode->i_xid, VX_ADMIN|VX_WATCH|VX_IDENT))
+		return 0;
+	return -EACCES;
+}
+
 int permission(struct inode * inode,int mask)
 {
+	int retval = 0;
+
+	if ((retval = xid_permission(inode)))
+		return retval;
 	if (inode->i_op && inode->i_op->permission) {
-		int retval;
 		lock_kernel();
 		retval = inode->i_op->permission(inode, mask);
 		unlock_kernel();
@@ -1057,6 +1069,7 @@ do_last:
 
 	/* Negative dentry, just create the file */
 	if (!dentry->d_inode) {
+		vx_dq_cond_modify(dir->d_inode, current->vx_id);
 		error = vfs_create(dir->d_inode, dentry,
 				   mode & ~current->fs->umask);
 		up(&dir->d_inode->i_sem);
@@ -1129,7 +1142,7 @@ ok:
 		flag &= ~O_TRUNC;
 	} else {
 		error = -EROFS;
-		if (IS_RDONLY(inode) && (flag & 2))
+		if (IS_RDONLY(inode) && (flag & FMODE_WRITE))
 			goto exit;
 	}
 	/*
@@ -1171,6 +1184,9 @@ ok:
 		if (flag & FMODE_WRITE)
 			DQUOT_INIT(inode);
 
+	if ((flag & FMODE_WRITE) || (flag & O_TRUNC))
+		vx_dq_cond_modify(inode, current->vx_id);
+
 	return 0;
 
 exit_dput:
@@ -1492,6 +1508,8 @@ int vfs_unlink(struct inode *dir, struct
 			else {
 				lock_kernel();
 				error = dir->i_op->unlink(dir, dentry);
+				if (!error)
+					vx_dq_unlink(dentry->d_inode);
 				unlock_kernel();
 				if (!error)
 					d_delete(dentry);
diff -NurpP --minimal linux-2.4.25-rc2-vs1.26/fs/namespace.c linux-2.4.25-rc2-vs1.26-q0.13/fs/namespace.c
--- linux-2.4.25-rc2-vs1.26/fs/namespace.c	2004-02-12 22:58:34.000000000 +0100
+++ linux-2.4.25-rc2-vs1.26-q0.13/fs/namespace.c	2004-02-13 00:53:54.000000000 +0100
@@ -25,6 +25,7 @@ struct vfsmount *do_kern_mount(const cha
 int do_remount_sb(struct super_block *sb, int flags, void * data);
 void kill_super(struct super_block *sb);
 extern int __init init_rootfs(void);
+extern int __init init_dqhash_hash(void);
 
 static struct list_head *mount_hashtable;
 static int hash_mask, hash_bits;
@@ -334,10 +335,12 @@ static int do_umount(struct vfsmount *mn
 	spin_lock(&dcache_lock);
 
 	if (atomic_read(&sb->s_active) == 1) {
+		struct list_head *head;
 		/* last instance - try to be smart */
 		spin_unlock(&dcache_lock);
 		lock_kernel();
-		DQUOT_OFF(sb);
+		list_for_each(head, &sb->s_dqhs)
+			DQUOT_OFF(list_entry(head, struct dqhash, dqh_sblist));
 		acct_auto_close(sb->s_dev);
 		unlock_kernel();
 		spin_lock(&dcache_lock);
@@ -1068,6 +1071,7 @@ void __init mnt_init(unsigned long mempa
 		d++;
 		i--;
 	} while (i);
+	init_dqhash_hash();
 	init_rootfs();
 	init_mount_tree();
 }
diff -NurpP --minimal linux-2.4.25-rc2-vs1.26/fs/open.c linux-2.4.25-rc2-vs1.26-q0.13/fs/open.c
--- linux-2.4.25-rc2-vs1.26/fs/open.c	2004-02-12 23:21:43.000000000 +0100
+++ linux-2.4.25-rc2-vs1.26-q0.13/fs/open.c	2004-02-13 00:53:54.000000000 +0100
@@ -37,6 +37,79 @@ int vfs_statfs(struct super_block *sb, s
 }
 
 
+static inline void ctx_modify_statfs(struct super_block *sb, struct statfs *buf)
+{
+	struct dqhash *dqh;
+	struct dqh_dlimit *dl;
+	__u64 blimit, bfree, bavail;
+	__u32 ifree;
+
+	dqh = get_dqhash(sb, current->vx_id);
+	if (!dqhash_valid(dqh))
+		return;
+
+	dprintk("··· statfs %ld/%ld %ld/%ld/%ld (dqh=%p)\n",
+		buf->f_ffree, buf->f_files,
+		buf->f_bavail, buf->f_bfree, buf->f_blocks,
+		dqh);
+
+	dl = &dqh->dqh_dlimit;
+	down_read(&dl->dl_sem);
+
+	dprintk("··· dlimit %u/%u %Lu/%Lu\n",
+		dl->dl_inodes, dl->dl_ilimit,
+		dl->dl_bytes, dl->dl_blimit);
+
+	if (dl->dl_ilimit == NOILIMIT)
+		goto no_ilim;
+
+	/* reduce max inodes available to limit */
+	if (buf->f_files > dl->dl_ilimit)
+		buf->f_files = dl->dl_ilimit;
+
+	ifree = dl->dl_ilimit - dl->dl_inodes;
+	/* reduce free inodes to min */
+	if (ifree < buf->f_ffree)
+		buf->f_ffree = ifree;
+
+no_ilim:
+	if (dl->dl_blimit == NOBLIMIT)
+		goto no_blim;
+
+	blimit = dl->dl_blimit >> dl->dl_l2bsize;
+
+	if (dl->dl_blimit < dl->dl_bytes)
+		bfree = 0;
+	else
+		bfree = (dl->dl_blimit - dl->dl_bytes) >> dl->dl_l2bsize;
+
+	bavail = ((dl->dl_blimit >> 10) * dl->dl_nrlmult);
+	if (bavail < dl->dl_bytes)
+		bavail = 0;
+	else
+		bavail = (bavail - dl->dl_bytes) >> dl->dl_l2bsize;
+
+	/* reduce max space available to limit */
+	if (buf->f_blocks > blimit)
+		buf->f_blocks = blimit;
+
+	/* reduce free space to min */
+	if (bfree < buf->f_bfree)
+		buf->f_bfree = bfree;
+
+	/* reduce avail space to min */
+	if (bavail < buf->f_bavail)
+		buf->f_bavail = bavail;
+
+no_blim:
+	up_read(&dl->dl_sem);
+	dqhput(dqh);
+
+	dprintk("··· sctxfs %ld/%ld %ld/%ld/%ld\n",
+		buf->f_ffree, buf->f_files,
+		buf->f_bavail, buf->f_bfree, buf->f_blocks);
+}
+
 asmlinkage long sys_statfs(const char * path, struct statfs * buf)
 {
 	struct nameidata nd;
@@ -46,6 +119,8 @@ asmlinkage long sys_statfs(const char * 
 	if (!error) {
 		struct statfs tmp;
 		error = vfs_statfs(nd.dentry->d_inode->i_sb, &tmp);
+		if (!error)
+			ctx_modify_statfs(nd.dentry->d_inode->i_sb, &tmp);
 		if (!error && copy_to_user(buf, &tmp, sizeof(struct statfs)))
 			error = -EFAULT;
 		path_release(&nd);
@@ -64,6 +139,8 @@ asmlinkage long sys_fstatfs(unsigned int
 	if (!file)
 		goto out;
 	error = vfs_statfs(file->f_dentry->d_inode->i_sb, &tmp);
+	if (!error)
+		ctx_modify_statfs(file->f_dentry->d_inode->i_sb, &tmp);
 	if (!error && copy_to_user(buf, &tmp, sizeof(struct statfs)))
 		error = -EFAULT;
 	fput(file);
@@ -569,6 +646,10 @@ static int chown_common(struct dentry * 
 		user = inode->i_uid;
 	if (group == (gid_t) -1)
 		group = inode->i_gid;
+
+	if ((user > MAX_UID) || (group > MAX_GID))
+		goto out;
+	
 	newattrs.ia_mode = inode->i_mode;
 	newattrs.ia_uid = user;
 	newattrs.ia_gid = group;
diff -NurpP --minimal linux-2.4.25-rc2-vs1.26/fs/quota.c linux-2.4.25-rc2-vs1.26-q0.13/fs/quota.c
--- linux-2.4.25-rc2-vs1.26/fs/quota.c	2004-02-12 23:21:43.000000000 +0100
+++ linux-2.4.25-rc2-vs1.26-q0.13/fs/quota.c	2004-02-13 00:53:54.000000000 +0100
@@ -21,63 +21,63 @@
 struct dqstats dqstats;
 
 /* Check validity of quotactl */
-static int check_quotactl_valid(struct super_block *sb, int type, int cmd, qid_t id)
+static int check_quotactl_valid(struct dqhash *hash, int type, int cmd, qid_t id)
 {
 	if (type >= MAXQUOTAS)
 		return -EINVAL;
-	if (!sb && cmd != Q_SYNC)
+	if (!hash && cmd != Q_SYNC)
 		return -ENODEV;
 	/* Is operation supported? */
-	if (sb && !sb->s_qcop)
+	if (hash && !hash->dqh_qcop)
 		return -ENOSYS;
 
 	switch (cmd) {
 		case Q_GETFMT:
 			break;
 		case Q_QUOTAON:
-			if (!sb->s_qcop->quota_on)
+			if (!hash->dqh_qcop->quota_on)
 				return -ENOSYS;
 			break;
 		case Q_QUOTAOFF:
-			if (!sb->s_qcop->quota_off)
+			if (!hash->dqh_qcop->quota_off)
 				return -ENOSYS;
 			break;
 		case Q_SETINFO:
-			if (!sb->s_qcop->set_info)
+			if (!hash->dqh_qcop->set_info)
 				return -ENOSYS;
 			break;
 		case Q_GETINFO:
-			if (!sb->s_qcop->get_info)
+			if (!hash->dqh_qcop->get_info)
 				return -ENOSYS;
 			break;
 		case Q_SETQUOTA:
-			if (!sb->s_qcop->set_dqblk)
+			if (!hash->dqh_qcop->set_dqblk)
 				return -ENOSYS;
 			break;
 		case Q_GETQUOTA:
-			if (!sb->s_qcop->get_dqblk)
+			if (!hash->dqh_qcop->get_dqblk)
 				return -ENOSYS;
 			break;
 		case Q_SYNC:
-			if (sb && !sb->s_qcop->quota_sync)
+			if (hash && !hash->dqh_qcop->quota_sync)
 				return -ENOSYS;
 			break;
 		case Q_XQUOTAON:
 		case Q_XQUOTAOFF:
 		case Q_XQUOTARM:
-			if (!sb->s_qcop->set_xstate)
+			if (!hash->dqh_qcop->set_xstate)
 				return -ENOSYS;
 			break;
 		case Q_XGETQSTAT:
-			if (!sb->s_qcop->get_xstate)
+			if (!hash->dqh_qcop->get_xstate)
 				return -ENOSYS;
 			break;
 		case Q_XSETQLIM:
-			if (!sb->s_qcop->set_xquota)
+			if (!hash->dqh_qcop->set_xquota)
 				return -ENOSYS;
 			break;
 		case Q_XGETQUOTA:
-			if (!sb->s_qcop->get_xquota)
+			if (!hash->dqh_qcop->get_xquota)
 				return -ENOSYS;
 			break;
 		default:
@@ -92,7 +92,7 @@ static int check_quotactl_valid(struct s
 		case Q_SETINFO:
 		case Q_SETQUOTA:
 		case Q_GETQUOTA:
-			if (!sb_has_quota_enabled(sb, type))
+			if (!dqh_has_quota_enabled(hash, type))
 				return -ESRCH;
 	}
 	/* Check privileges */
@@ -198,7 +198,7 @@ out:
 }
 
 /* Copy parameters and call proper function */
-static int do_quotactl(struct super_block *sb, int type, int cmd, qid_t id, caddr_t addr)
+static int do_quotactl(struct dqhash *hash, int type, int cmd, qid_t id, caddr_t addr)
 {
 	int ret;
 
@@ -208,17 +208,17 @@ static int do_quotactl(struct super_bloc
 
 			if (IS_ERR(pathname = getname(addr)))
 				return PTR_ERR(pathname);
-			ret = sb->s_qcop->quota_on(sb, type, id, pathname);
+			ret = hash->dqh_qcop->quota_on(hash, type, id, pathname);
 			putname(pathname);
 			return ret;
 		}
 		case Q_QUOTAOFF:
-			return sb->s_qcop->quota_off(sb, type);
+			return hash->dqh_qcop->quota_off(hash, type);
 
 		case Q_GETFMT: {
 			__u32 fmt;
 
-			fmt = sb_dqopt(sb)->info[type].dqi_format->qf_fmt_id;
+			fmt = dqh_dqopt(hash)->info[type].dqi_format->qf_fmt_id;
 			if (copy_to_user(addr, &fmt, sizeof(fmt)))
 				return -EFAULT;
 			return 0;
@@ -226,7 +226,7 @@ static int do_quotactl(struct super_bloc
 		case Q_GETINFO: {
 			struct if_dqinfo info;
 
-			if ((ret = sb->s_qcop->get_info(sb, type, &info)))
+			if ((ret = hash->dqh_qcop->get_info(hash, type, &info)))
 				return ret;
 			if (copy_to_user(addr, &info, sizeof(info)))
 				return -EFAULT;
@@ -237,12 +237,12 @@ static int do_quotactl(struct super_bloc
 
 			if (copy_from_user(&info, addr, sizeof(info)))
 				return -EFAULT;
-			return sb->s_qcop->set_info(sb, type, &info);
+			return hash->dqh_qcop->set_info(hash, type, &info);
 		}
 		case Q_GETQUOTA: {
 			struct if_dqblk idq;
 
-			if ((ret = sb->s_qcop->get_dqblk(sb, type, id, &idq)))
+			if ((ret = hash->dqh_qcop->get_dqblk(hash, type, id, &idq)))
 				return ret;
 			if (copy_to_user(addr, &idq, sizeof(idq)))
 				return -EFAULT;
@@ -253,11 +253,11 @@ static int do_quotactl(struct super_bloc
 
 			if (copy_from_user(&idq, addr, sizeof(idq)))
 				return -EFAULT;
-			return sb->s_qcop->set_dqblk(sb, type, id, &idq);
+			return hash->dqh_qcop->set_dqblk(hash, type, id, &idq);
 		}
 		case Q_SYNC:
-			if (sb)
-				return sb->s_qcop->quota_sync(sb, type);
+			if (hash)
+				return hash->dqh_qcop->quota_sync(hash, type);
 			sync_dquots_dev(NODEV, type);
 			return 0;
 		case Q_XQUOTAON:
@@ -267,12 +267,12 @@ static int do_quotactl(struct super_bloc
 
 			if (copy_from_user(&flags, addr, sizeof(flags)))
 				return -EFAULT;
-			return sb->s_qcop->set_xstate(sb, flags, cmd);
+			return hash->dqh_qcop->set_xstate(hash, flags, cmd);
 		}
 		case Q_XGETQSTAT: {
 			struct fs_quota_stat fqs;
 		
-			if ((ret = sb->s_qcop->get_xstate(sb, &fqs)))
+			if ((ret = hash->dqh_qcop->get_xstate(hash, &fqs)))
 				return ret;
 			if (copy_to_user(addr, &fqs, sizeof(fqs)))
 				return -EFAULT;
@@ -283,12 +283,12 @@ static int do_quotactl(struct super_bloc
 
 			if (copy_from_user(&fdq, addr, sizeof(fdq)))
 				return -EFAULT;
-		       return sb->s_qcop->set_xquota(sb, type, id, &fdq);
+		       return hash->dqh_qcop->set_xquota(hash, type, id, &fdq);
 		}
 		case Q_XGETQUOTA: {
 			struct fs_disk_quota fdq;
 
-			if ((ret = sb->s_qcop->get_xquota(sb, type, id, &fdq)))
+			if ((ret = hash->dqh_qcop->get_xquota(hash, type, id, &fdq)))
 				return ret;
 			if (copy_to_user(addr, &fdq, sizeof(fdq)))
 				return -EFAULT;
@@ -301,40 +301,40 @@ static int do_quotactl(struct super_bloc
 	return 0;
 }
 
-static int check_compat_quotactl_valid(struct super_block *sb, int type, int cmd, qid_t id)
+static int check_compat_quotactl_valid(struct dqhash *hash, int type, int cmd, qid_t id)
 {
 	if (type >= MAXQUOTAS)
 		return -EINVAL;
 	/* Is operation supported? */
 	/* sb==NULL for GETSTATS calls */
-	if (sb && !sb->s_qcop)
+	if (hash && !hash->dqh_qcop)
 		return -ENOSYS;
 
 	switch (cmd) {
 		case Q_COMP_QUOTAON:
-			if (!sb->s_qcop->quota_on)
+			if (!hash || !hash->dqh_qcop->quota_on)
 				return -ENOSYS;
 			break;
 		case Q_COMP_QUOTAOFF:
-			if (!sb->s_qcop->quota_off)
+			if (!hash || !hash->dqh_qcop->quota_off)
 				return -ENOSYS;
 			break;
 		case Q_COMP_SYNC:
-			if (sb && !sb->s_qcop->quota_sync)
+			if (!hash || !hash->dqh_qcop->quota_sync)
 				return -ENOSYS;
 			break;
 		case Q_V1_SETQLIM:
 		case Q_V1_SETUSE:
 		case Q_V1_SETQUOTA:
-			if (!sb->s_qcop->set_dqblk)
+			if (!hash || !hash->dqh_qcop->set_dqblk)
 				return -ENOSYS;
 			break;
 		case Q_V1_GETQUOTA:
-			if (!sb->s_qcop->get_dqblk)
+			if (!hash || !hash->dqh_qcop->get_dqblk)
 				return -ENOSYS;
 			break;
 		case Q_V1_RSQUASH:
-			if (!sb->s_qcop->set_info)
+			if (!hash || !hash->dqh_qcop->set_info)
 				return -ENOSYS;
 			break;
 		case Q_V1_GETSTATS:
@@ -359,13 +359,14 @@ static int check_compat_quotactl_valid(s
 		case Q_V2_SETUSE:
 		case Q_V1_GETQUOTA:
 		case Q_V2_GETQUOTA:
-			if (!sb_has_quota_enabled(sb, type))
+			if (!dqh_has_quota_enabled(hash, type))
 				return -ESRCH;
 	}
 	if (cmd != Q_COMP_QUOTAON &&
 	    cmd != Q_COMP_QUOTAOFF &&
 	    cmd != Q_COMP_SYNC &&
-	    sb_dqopt(sb)->info[type].dqi_format->qf_fmt_id != QFMT_VFS_OLD)
+	    hash &&
+	    dqh_dqopt(hash)->info[type].dqi_format->qf_fmt_id != QFMT_VFS_OLD)
 		return -ESRCH;
 
 	/* Check privileges */
@@ -381,21 +382,21 @@ static int check_compat_quotactl_valid(s
 	return 0;
 }
 
-static int v1_set_rsquash(struct super_block *sb, int type, int flag)
+static int v1_set_rsquash(struct dqhash *hash, int type, int flag)
 {
 	struct if_dqinfo info;
 
 	info.dqi_valid = IIF_FLAGS;
 	info.dqi_flags = flag ? V1_DQF_RSQUASH : 0;
-	return sb->s_qcop->set_info(sb, type, &info);
+	return hash->dqh_qcop->set_info(hash, type, &info);
 }
 
-static int v1_get_dqblk(struct super_block *sb, int type, qid_t id, struct v1c_mem_dqblk *mdq)
+static int v1_get_dqblk(struct dqhash *hash, int type, qid_t id, struct v1c_mem_dqblk *mdq)
 {
 	struct if_dqblk idq;
 	int ret;
 
-	if ((ret = sb->s_qcop->get_dqblk(sb, type, id, &idq)) < 0)
+	if ((ret = hash->dqh_qcop->get_dqblk(hash, type, id, &idq)) < 0)
 		return ret;
 	mdq->dqb_ihardlimit = idq.dqb_ihardlimit;
 	mdq->dqb_isoftlimit = idq.dqb_isoftlimit;
@@ -408,7 +409,7 @@ static int v1_get_dqblk(struct super_blo
 	if (id == 0) {	/* Times for id 0 are in fact grace times */
 		struct if_dqinfo info;
 
-		if ((ret = sb->s_qcop->get_info(sb, type, &info)) < 0)
+		if ((ret = hash->dqh_qcop->get_info(hash, type, &info)) < 0)
 			return ret;
 		mdq->dqb_btime = info.dqi_bgrace;
 		mdq->dqb_itime = info.dqi_igrace;
@@ -416,7 +417,7 @@ static int v1_get_dqblk(struct super_blo
 	return 0;
 }
 
-static int v1_set_dqblk(struct super_block *sb, int type, int cmd, qid_t id, struct v1c_mem_dqblk *mdq)
+static int v1_set_dqblk(struct dqhash *hash, int type, int cmd, qid_t id, struct v1c_mem_dqblk *mdq)
 {
 	struct if_dqblk idq;
 	int ret;
@@ -434,14 +435,14 @@ static int v1_set_dqblk(struct super_blo
 		idq.dqb_curspace = ((qsize_t)mdq->dqb_curblocks) << QUOTABLOCK_BITS;
 		idq.dqb_valid |= QIF_USAGE;
 	}
-	ret = sb->s_qcop->set_dqblk(sb, type, id, &idq);
+	ret = hash->dqh_qcop->set_dqblk(hash, type, id, &idq);
 	if (!ret && id == 0 && cmd == Q_V1_SETQUOTA) {	/* Times for id 0 are in fact grace times */
 		struct if_dqinfo info;
 
 		info.dqi_bgrace = mdq->dqb_btime;
 		info.dqi_igrace = mdq->dqb_itime;
 		info.dqi_valid = IIF_BGRACE | IIF_IGRACE;
-		ret = sb->s_qcop->set_info(sb, type, &info);
+		ret = hash->dqh_qcop->set_info(hash, type, &info);
 	}
 	return ret;
 }
@@ -452,7 +453,7 @@ static void v1_get_stats(struct v1c_dqst
 }
 
 /* Handle requests to old interface */
-static int do_compat_quotactl(struct super_block *sb, int type, int cmd, qid_t id, caddr_t addr)
+static int do_compat_quotactl(struct dqhash *hash, int type, int cmd, qid_t id, caddr_t addr)
 {
 	int ret;
 
@@ -462,15 +463,15 @@ static int do_compat_quotactl(struct sup
 
 			if (IS_ERR(pathname = getname(addr)))
 				return PTR_ERR(pathname);
-			ret = sb->s_qcop->quota_on(sb, type, QFMT_VFS_OLD, pathname);
+			ret = hash->dqh_qcop->quota_on(hash, type, QFMT_VFS_OLD, pathname);
 			putname(pathname);
 			return ret;
 		}
 		case Q_COMP_QUOTAOFF:
-			return sb->s_qcop->quota_off(sb, type);
+			return hash->dqh_qcop->quota_off(hash, type);
 		case Q_COMP_SYNC:
-			if (sb)
-				return sb->s_qcop->quota_sync(sb, type);
+			if (hash)
+				return hash->dqh_qcop->quota_sync(hash, type);
 			sync_dquots_dev(NODEV, type);
 			return 0;
 		case Q_V1_RSQUASH: {
@@ -478,12 +479,12 @@ static int do_compat_quotactl(struct sup
 
 			if (copy_from_user(&flag, addr, sizeof(flag)))
 				return -EFAULT;
-			return v1_set_rsquash(sb, type, flag);
+			return v1_set_rsquash(hash, type, flag);
 		}
 		case Q_V1_GETQUOTA: {
 			struct v1c_mem_dqblk mdq;
 
-			if ((ret = v1_get_dqblk(sb, type, id, &mdq)))
+			if ((ret = v1_get_dqblk(hash, type, id, &mdq)))
 				return ret;
 			if (copy_to_user(addr, &mdq, sizeof(mdq)))
 				return -EFAULT;
@@ -496,7 +497,7 @@ static int do_compat_quotactl(struct sup
 
 			if (copy_from_user(&mdq, addr, sizeof(mdq)))
 				return -EFAULT;
-			return v1_set_dqblk(sb, type, cmd, id, &mdq);
+			return v1_set_dqblk(hash, type, cmd, id, &mdq);
 		}
 		case Q_V1_GETSTATS: {
 			struct v1c_dqstats dst;
@@ -515,6 +516,124 @@ static int do_compat_quotactl(struct sup
 #define NEW_COMMAND(c) ((c) & (0x80 << 16))
 #define XQM_COMMAND(c) (((c) & ('X' << 8)) == ('X' << 8))
 
+int remove_dqhash_ref(struct dqhash *hash);
+
+int remove_inode_dqhash_ref(struct inode *inode)
+{
+	lock_kernel();
+	if (!dqhash_valid(inode->i_dqh))
+		BUG();
+	if (inode->i_dqh->dqh_qop->drop)
+		inode->i_dqh->dqh_qop->drop(inode);
+	dqhput(inode->i_dqh);
+	if (inode->i_flags & S_QUOTA)
+		printk("··· QUOTA still on for %p (%d)", inode, inode->i_xid);
+	inode->i_dqh = NULL;
+	unlock_kernel();
+	return 0;
+}
+
+int do_dqhashctl(struct super_block *sb, int xid, uint cmds)
+{
+	int ret = -EINVAL;
+	struct dqhash *dqh = get_dqhash(sb, xid);
+
+	if (!dqhash_valid(dqh) && (cmds == Q_ADD_DQHASH)) {
+		if (!(sb->s_flags & MS_TAGXID))
+			return -ENOSYS;
+		dqh = new_dqhash(sb, xid);
+		/* keep one refcount to hash */
+		return 0;
+	}
+	if (dqhash_valid(dqh) && (cmds == Q_REM_DQHASH)) {
+		remove_dqhash_ref(dqh);
+
+		dprintk("··· dqhash : %p [%d]\n", dqh, atomic_read(&dqh->dqh_count));
+		ret = 0;
+		if (atomic_read(&dqh->dqh_count) > 2)
+			ret = -EBUSY;
+		else	/* put last but one refcount */
+			dqhput(dqh);
+	}
+	dqhput(dqh);
+	return ret;
+}
+
+int do_dqlimitctl(struct super_block *sb, uint cmds, qid_t id, caddr_t addr)
+{
+	struct dqhash *dqh;
+	struct dqh_dlimit *dl;
+	struct dli_limits dli;
+	int ret = 0;
+
+	if (!vx_check(0, VX_ADMIN|VX_WATCH))
+		/* stealth should return EINVAL? */
+		return -EPERM;
+
+	dqh = get_dqhash(sb, id);
+	if (!dqhash_valid(dqh))
+		return -ENXIO;
+	
+	if (cmds == Q_GET_DLIMIT) {
+		dl = &dqh->dqh_dlimit;
+		down_read(&dl->dl_sem);
+
+		if (dl->dl_ilimit != NOILIMIT) {
+			dli.dli_inodes_total = dl->dl_ilimit;
+			dli.dli_inodes_used = dl->dl_inodes;
+		}
+		if (dl->dl_blimit != NOBLIMIT) {
+			dli.dli_blocks_total = dl->dl_blimit >> 10;
+			dli.dli_blocks_used = dl->dl_bytes >> 10;
+		}
+		dli.dli_reserved = 100 - ((dl->dl_nrlmult * 100
+			+ (1 << (10-1))) >> 10);
+		up_read(&dl->dl_sem);
+		
+		ret = -EFAULT;
+		if (copy_to_user(addr, &dli, sizeof(dli)))
+			goto out;
+		ret = 0;
+	}
+	if (cmds == Q_SET_DLIMIT) {
+		ret = -EFAULT;
+		if (copy_from_user(&dli, addr, sizeof(dli)))
+			goto out;
+		ret = -EINVAL;
+		if ((dli.dli_reserved > 100) ||
+			(dli.dli_inodes_used > dli.dli_inodes_total) ||
+			(dli.dli_blocks_used > dli.dli_blocks_total))
+			goto out;
+
+		dl = &dqh->dqh_dlimit;
+		down_write(&dl->dl_sem);
+
+		if (dli.dli_inodes_total)
+			dl->dl_ilimit = dli.dli_inodes_total;
+		else
+			dl->dl_ilimit = NOILIMIT;
+		dl->dl_inodes = dli.dli_inodes_used;
+
+		if (dli.dli_blocks_total) {
+			dl->dl_blimit = dli.dli_blocks_total;
+			dl->dl_blimit <<= 10;	/* was dl->dl_l2bsize; */
+		}
+		else
+			dl->dl_blimit = NOBLIMIT;
+		dl->dl_bytes = dli.dli_blocks_used;
+		dl->dl_bytes <<= 10;	/* was dl->dl_l2bsize; */
+
+		/* calc mult for non-root free blocks */
+		dl->dl_nrlmult = (1 << 10) * (100 - dli.dli_reserved) / 100;
+		
+		up_write(&dl->dl_sem);
+		ret = 0;
+	}
+out:	
+	dqhput(dqh);
+	return ret;
+}
+
 /*
  * This is the system call interface. This communicates with
  * the user-level programs. Currently this only supports diskquota
@@ -525,6 +644,7 @@ asmlinkage long sys_quotactl(unsigned in
 {
 	uint cmds, type;
 	struct super_block *sb = NULL;
+	struct dqhash *dqh = NULL;
 	int ret = -EINVAL;
 
 	lock_kernel();
@@ -534,18 +654,39 @@ asmlinkage long sys_quotactl(unsigned in
 	if (cmds != Q_V1_GETSTATS && cmds != Q_V2_GETSTATS && IS_ERR(sb = resolve_dev(special))) {
 		ret = PTR_ERR(sb);
 		sb = NULL;
-		goto out;
+		goto out_sb;
+	}
+	else if (sb) {
+		if ((cmds == Q_SET_DLIMIT) || (cmds == Q_GET_DLIMIT)) {
+			ret = -EPERM;
+			if (vx_check(0, VX_ADMIN))
+				ret = do_dqlimitctl(sb, cmds, id, addr);
+			goto out_sb;
+		}
+		if ((cmds == Q_ADD_DQHASH) || (cmds == Q_REM_DQHASH)) {
+			ret = -EPERM;
+			if (vx_check(0, VX_ADMIN))
+				ret = do_dqhashctl(sb, id, cmds);
+			goto out_sb;
+		}
+		ret = -ENXIO;
+		dqh = get_dqhash(sb, current->vx_id);
+		if (!dqhash_valid(dqh))
+			goto out;
 	}
 	if (!NEW_COMMAND(cmds) && !XQM_COMMAND(cmds)) {
-		if ((ret = check_compat_quotactl_valid(sb, type, cmds, id)) < 0)
+		if ((ret = check_compat_quotactl_valid(dqh, type, cmds, id)) < 0)
 			goto out;
-		ret = do_compat_quotactl(sb, type, cmds, id, addr);
+		ret = do_compat_quotactl(dqh, type, cmds, id, addr);
 		goto out;
 	}
-	if ((ret = check_quotactl_valid(sb, type, cmds, id)) < 0)
+	if ((ret = check_quotactl_valid(dqh, type, cmds, id)) < 0)
 		goto out;
-	ret = do_quotactl(sb, type, cmds, id, addr);
+	ret = do_quotactl(dqh, type, cmds, id, addr);
 out:
+	if (dqh)
+		dqhput(dqh);
+out_sb:
 	if (sb)
 		drop_super(sb);
 	unlock_kernel();
diff -NurpP --minimal linux-2.4.25-rc2-vs1.26/fs/quota_v1.c linux-2.4.25-rc2-vs1.26-q0.13/fs/quota_v1.c
--- linux-2.4.25-rc2-vs1.26/fs/quota_v1.c	2003-11-28 19:26:21.000000000 +0100
+++ linux-2.4.25-rc2-vs1.26-q0.13/fs/quota_v1.c	2004-02-13 00:53:54.000000000 +0100
@@ -42,7 +42,7 @@ static int v1_read_dqblk(struct dquot *d
 	loff_t offset;
 	struct v1_disk_dqblk dqblk;
 
-	filp = sb_dqopt(dquot->dq_sb)->files[type];
+	filp = dqh_dqopt(dquot->dq_dqh)->files[type];
 	if (filp == (struct file *)NULL)
 		return -EINVAL;
 
@@ -71,7 +71,7 @@ static int v1_commit_dqblk(struct dquot 
 	ssize_t ret;
 	struct v1_disk_dqblk dqblk;
 
-	filp = sb_dqopt(dquot->dq_sb)->files[type];
+	filp = dqh_dqopt(dquot->dq_dqh)->files[type];
 	offset = v1_dqoff(dquot->dq_id);
 	fs = get_fs();
 	set_fs(KERNEL_DS);
@@ -83,8 +83,8 @@ static int v1_commit_dqblk(struct dquot 
 	v1_mem2disk_dqblk(&dqblk, &dquot->dq_dqb);
 	dquot->dq_flags &= ~DQ_MOD;
 	if (dquot->dq_id == 0) {
-		dqblk.dqb_btime = sb_dqopt(dquot->dq_sb)->info[type].dqi_bgrace;
-		dqblk.dqb_itime = sb_dqopt(dquot->dq_sb)->info[type].dqi_igrace;
+		dqblk.dqb_btime = dqh_dqopt(dquot->dq_dqh)->info[type].dqi_bgrace;
+		dqblk.dqb_itime = dqh_dqopt(dquot->dq_dqh)->info[type].dqi_igrace;
 	}
 	ret = 0;
 	if (filp)
@@ -117,9 +117,9 @@ struct v2_disk_dqheader {
 	__u32 dqh_version;      /* File version */
 };
 
-static int v1_check_quota_file(struct super_block *sb, int type)
+static int v1_check_quota_file(struct dqhash *hash, int type)
 {
-	struct file *f = sb_dqopt(sb)->files[type];
+	struct file *f = dqh_dqopt(hash)->files[type];
 	struct inode *inode = f->f_dentry->d_inode;
 	ulong blocks;
 	size_t off; 
@@ -144,13 +144,13 @@ static int v1_check_quota_file(struct su
 		return 1;	/* Probably not new format */
 	if (le32_to_cpu(dqhead.dqh_magic) != quota_magics[type])
 		return 1;	/* Definitely not new format */
-	printk(KERN_INFO "VFS: %s: Refusing to turn on old quota format on given file. It probably contains newer quota format.\n", kdevname(sb->s_dev));
+	printk(KERN_INFO "VFS: %s: Refusing to turn on old quota format on given file. It probably contains newer quota format.\n", kdevname(hash->dqh_sb->s_dev));
         return 0;		/* Seems like a new format file -> refuse it */
 }
 
-static int v1_read_file_info(struct super_block *sb, int type)
+static int v1_read_file_info(struct dqhash *hash, int type)
 {
-	struct quota_info *dqopt = sb_dqopt(sb);
+	struct quota_info *dqopt = dqh_dqopt(hash);
 	mm_segment_t fs;
 	loff_t offset;
 	struct file *filp = dqopt->files[type];
@@ -175,9 +175,9 @@ out:
 	return ret;
 }
 
-static int v1_write_file_info(struct super_block *sb, int type)
+static int v1_write_file_info(struct dqhash *hash, int type)
 {
-	struct quota_info *dqopt = sb_dqopt(sb);
+	struct quota_info *dqopt = dqh_dqopt(hash);
 	mm_segment_t fs;
 	struct file *filp = dqopt->files[type];
 	struct v1_disk_dqblk dqblk;
diff -NurpP --minimal linux-2.4.25-rc2-vs1.26/fs/quota_v2.c linux-2.4.25-rc2-vs1.26-q0.13/fs/quota_v2.c
--- linux-2.4.25-rc2-vs1.26/fs/quota_v2.c	2003-08-25 13:44:43.000000000 +0200
+++ linux-2.4.25-rc2-vs1.26-q0.13/fs/quota_v2.c	2004-02-13 00:53:54.000000000 +0100
@@ -22,10 +22,10 @@ typedef char *dqbuf_t;
 #define GETENTRIES(buf) ((struct v2_disk_dqblk *)(((char *)buf)+sizeof(struct v2_disk_dqdbheader)))
 
 /* Check whether given file is really vfsv0 quotafile */
-static int v2_check_quota_file(struct super_block *sb, int type)
+static int v2_check_quota_file(struct dqhash *hash, int type)
 {
 	struct v2_disk_dqheader dqhead;
-	struct file *f = sb_dqopt(sb)->files[type];
+	struct file *f = dqh_dqopt(hash)->files[type];
 	mm_segment_t fs;
 	ssize_t size;
 	loff_t offset = 0;
@@ -45,12 +45,12 @@ static int v2_check_quota_file(struct su
 }
 
 /* Read information header from quota file */
-static int v2_read_file_info(struct super_block *sb, int type)
+static int v2_read_file_info(struct dqhash *hash, int type)
 {
 	mm_segment_t fs;
 	struct v2_disk_dqinfo dinfo;
-	struct mem_dqinfo *info = sb_dqopt(sb)->info+type;
-	struct file *f = sb_dqopt(sb)->files[type];
+	struct mem_dqinfo *info = dqh_dqopt(hash)->info+type;
+	struct file *f = dqh_dqopt(hash)->files[type];
 	ssize_t size;
 	loff_t offset = V2_DQINFOOFF;
 
@@ -73,12 +73,12 @@ static int v2_read_file_info(struct supe
 }
 
 /* Write information header to quota file */
-static int v2_write_file_info(struct super_block *sb, int type)
+static int v2_write_file_info(struct dqhash *hash, int type)
 {
 	mm_segment_t fs;
 	struct v2_disk_dqinfo dinfo;
-	struct mem_dqinfo *info = sb_dqopt(sb)->info+type;
-	struct file *f = sb_dqopt(sb)->files[type];
+	struct mem_dqinfo *info = dqh_dqopt(hash)->info+type;
+	struct file *f = dqh_dqopt(hash)->files[type];
 	ssize_t size;
 	loff_t offset = V2_DQINFOOFF;
 
@@ -281,8 +281,8 @@ out_buf:
 /* Find space for dquot */
 static uint find_free_dqentry(struct dquot *dquot, int *err)
 {
-	struct file *filp = sb_dqopt(dquot->dq_sb)->files[dquot->dq_type];
-	struct mem_dqinfo *info = sb_dqopt(dquot->dq_sb)->info+dquot->dq_type;
+	struct file *filp = dqh_dqopt(dquot->dq_dqh)->files[dquot->dq_type];
+	struct mem_dqinfo *info = dqh_dqopt(dquot->dq_dqh)->info+dquot->dq_type;
 	uint blk, i;
 	struct v2_disk_dqdbheader *dh;
 	struct v2_disk_dqblk *ddquot;
@@ -342,8 +342,8 @@ out_buf:
 /* Insert reference to structure into the trie */
 static int do_insert_tree(struct dquot *dquot, uint *treeblk, int depth)
 {
-	struct file *filp = sb_dqopt(dquot->dq_sb)->files[dquot->dq_type];
-	struct mem_dqinfo *info = sb_dqopt(dquot->dq_sb)->info + dquot->dq_type;
+	struct file *filp = dqh_dqopt(dquot->dq_dqh)->files[dquot->dq_type];
+	struct mem_dqinfo *info = dqh_dqopt(dquot->dq_dqh)->info + dquot->dq_type;
 	dqbuf_t buf;
 	int ret = 0, newson = 0, newact = 0;
 	u32 *ref;
@@ -416,7 +416,7 @@ static int v2_write_dquot(struct dquot *
 			printk(KERN_ERR "VFS: Error %d occured while creating quota.\n", ret);
 			return ret;
 		}
-	filp = sb_dqopt(dquot->dq_sb)->files[type];
+	filp = dqh_dqopt(dquot->dq_dqh)->files[type];
 	offset = dquot->dq_off;
 	mem2diskdqb(&ddquot, &dquot->dq_dqb, dquot->dq_id);
 	fs = get_fs();
@@ -437,8 +437,8 @@ static int v2_write_dquot(struct dquot *
 /* Free dquot entry in data block */
 static int free_dqentry(struct dquot *dquot, uint blk)
 {
-	struct file *filp = sb_dqopt(dquot->dq_sb)->files[dquot->dq_type];
-	struct mem_dqinfo *info = sb_dqopt(dquot->dq_sb)->info + dquot->dq_type;
+	struct file *filp = dqh_dqopt(dquot->dq_dqh)->files[dquot->dq_type];
+	struct mem_dqinfo *info = dqh_dqopt(dquot->dq_dqh)->info + dquot->dq_type;
 	struct v2_disk_dqdbheader *dh;
 	dqbuf_t buf = getdqbuf();
 	int ret = 0;
@@ -486,8 +486,8 @@ out_buf:
 /* Remove reference to dquot from tree */
 static int remove_tree(struct dquot *dquot, uint *blk, int depth)
 {
-	struct file *filp = sb_dqopt(dquot->dq_sb)->files[dquot->dq_type];
-	struct mem_dqinfo *info = sb_dqopt(dquot->dq_sb)->info + dquot->dq_type;
+	struct file *filp = dqh_dqopt(dquot->dq_dqh)->files[dquot->dq_type];
+	struct mem_dqinfo *info = dqh_dqopt(dquot->dq_dqh)->info + dquot->dq_type;
 	dqbuf_t buf = getdqbuf();
 	int ret = 0;
 	uint newblk;
@@ -536,7 +536,7 @@ static int v2_delete_dquot(struct dquot 
 /* Find entry in block */
 static loff_t find_block_dqentry(struct dquot *dquot, uint blk)
 {
-	struct file *filp = sb_dqopt(dquot->dq_sb)->files[dquot->dq_type];
+	struct file *filp = dqh_dqopt(dquot->dq_dqh)->files[dquot->dq_type];
 	dqbuf_t buf = getdqbuf();
 	loff_t ret = 0;
 	int i;
@@ -573,7 +573,7 @@ out_buf:
 /* Find entry for given id in the tree */
 static loff_t find_tree_dqentry(struct dquot *dquot, uint blk, int depth)
 {
-	struct file *filp = sb_dqopt(dquot->dq_sb)->files[dquot->dq_type];
+	struct file *filp = dqh_dqopt(dquot->dq_dqh)->files[dquot->dq_type];
 	dqbuf_t buf = getdqbuf();
 	loff_t ret = 0;
 	u32 *ref = (u32 *)buf;
@@ -612,10 +612,10 @@ static int v2_read_dquot(struct dquot *d
 	struct v2_disk_dqblk ddquot;
 	int ret = 0;
 
-	filp = sb_dqopt(dquot->dq_sb)->files[type];
+	filp = dqh_dqopt(dquot->dq_dqh)->files[type];
 
 #ifdef __QUOTA_V2_PARANOIA
-	if (!filp || !dquot->dq_sb) {	/* Invalidated quota? */
+	if (!filp || !dquot->dq_dqh) {	/* Invalidated quota? */
 		printk(KERN_ERR "VFS: Quota invalidated while reading!\n");
 		return -EIO;
 	}
diff -NurpP --minimal linux-2.4.25-rc2-vs1.26/fs/reiserfs/inode.c linux-2.4.25-rc2-vs1.26-q0.13/fs/reiserfs/inode.c
--- linux-2.4.25-rc2-vs1.26/fs/reiserfs/inode.c	2004-02-12 23:21:43.000000000 +0100
+++ linux-2.4.25-rc2-vs1.26-q0.13/fs/reiserfs/inode.c	2004-02-13 00:53:54.000000000 +0100
@@ -978,12 +978,19 @@ static void init_inode (struct inode * i
 	// new stat data found, but object may have old items
 	// (directories and symlinks)
 	struct stat_data * sd = (struct stat_data *)B_I_PITEM (bh, ih);
+	uid_t uid;
+	gid_t gid;
 
 	inode->i_mode   = sd_v2_mode(sd);
 	inode->i_nlink  = sd_v2_nlink(sd);
-	inode->i_uid    = sd_v2_uid(sd);
+
+	uid = sd_v2_uid(sd);
+	gid = sd_v2_gid(sd);
+	inode->i_uid    = INOXID_UID(uid, gid);
+	inode->i_gid    = INOXID_GID(uid, gid);
+	inode->i_xid	= INOXID_XID(uid, gid, 0);
+
 	inode->i_size   = sd_v2_size(sd);
-	inode->i_gid    = sd_v2_gid(sd);
 	inode->i_mtime  = sd_v2_mtime(sd);
 	inode->i_atime  = sd_v2_atime(sd);
 	inode->i_ctime  = sd_v2_ctime(sd);
@@ -1030,12 +1037,18 @@ static void inode2sd (void * sd, struct 
 {
     struct stat_data * sd_v2 = (struct stat_data *)sd;
     __u16 flags;
+    uid_t uid;
+    gid_t gid;
 
     set_sd_v2_mode(sd_v2, inode->i_mode );
     set_sd_v2_nlink(sd_v2, inode->i_nlink );
-    set_sd_v2_uid(sd_v2, inode->i_uid );
+
+    uid = XIDINO_UID(inode->i_uid, inode->i_xid);
+    gid = XIDINO_GID(inode->i_gid, inode->i_xid);
+    set_sd_v2_uid(sd_v2, uid );
+    set_sd_v2_gid(sd_v2, gid );
+
     set_sd_v2_size(sd_v2, inode->i_size );
-    set_sd_v2_gid(sd_v2, inode->i_gid );
     set_sd_v2_mtime(sd_v2, inode->i_mtime );
     set_sd_v2_atime(sd_v2, inode->i_atime );
     set_sd_v2_ctime(sd_v2, inode->i_ctime );
diff -NurpP --minimal linux-2.4.25-rc2-vs1.26/fs/super.c linux-2.4.25-rc2-vs1.26-q0.13/fs/super.c
--- linux-2.4.25-rc2-vs1.26/fs/super.c	2003-08-25 13:44:43.000000000 +0200
+++ linux-2.4.25-rc2-vs1.26-q0.13/fs/super.c	2004-02-13 00:53:54.000000000 +0100
@@ -271,6 +271,7 @@ static struct super_block *alloc_super(v
 		INIT_LIST_HEAD(&s->s_locked_inodes);
 		INIT_LIST_HEAD(&s->s_files);
 		INIT_LIST_HEAD(&s->s_instances);
+		INIT_LIST_HEAD(&s->s_dqhs);
 		init_rwsem(&s->s_umount);
 		sema_init(&s->s_lock, 1);
 		down_write(&s->s_umount);
@@ -278,11 +279,9 @@ static struct super_block *alloc_super(v
 		atomic_set(&s->s_active, 1);
 		sema_init(&s->s_vfs_rename_sem,1);
 		sema_init(&s->s_nfsd_free_path_sem,1);
-		sema_init(&s->s_dquot.dqio_sem, 1);
-		sema_init(&s->s_dquot.dqoff_sem, 1);
 		s->s_maxbytes = MAX_NON_LFS;
 		s->s_op = &empty_sops;
-		s->dq_op = sb_dquot_ops;
+		s->s_qop = sb_dquot_ops;
 		s->s_qcop = sb_quotactl_ops;
 	}
 	return s;
@@ -296,6 +295,12 @@ static struct super_block *alloc_super(v
  */
 static inline void destroy_super(struct super_block *s)
 {
+	struct list_head *pos, *n;
+
+	list_for_each_safe(pos, n, &s->s_dqhs)
+		dqhput(list_entry(pos, struct dqhash, dqh_sblist));
+	list_for_each_safe(pos, n, &s->s_dqhs)
+		destroy_dqhash(list_entry(pos, struct dqhash, dqh_sblist));
 	kfree(s);
 }
 
diff -NurpP --minimal linux-2.4.25-rc2-vs1.26/fs/udf/super.c linux-2.4.25-rc2-vs1.26-q0.13/fs/udf/super.c
--- linux-2.4.25-rc2-vs1.26/fs/udf/super.c	2002-08-03 02:39:45.000000000 +0200
+++ linux-2.4.25-rc2-vs1.26-q0.13/fs/udf/super.c	2004-02-13 00:53:54.000000000 +0100
@@ -1435,7 +1435,7 @@ udf_read_super(struct super_block *sb, v
 
 	/* Fill in the rest of the superblock */
 	sb->s_op = &udf_sb_ops;
-	sb->dq_op = NULL;
+	sb->s_qop = NULL;
 	sb->s_dirt = 0;
 	sb->s_magic = UDF_SUPER_MAGIC;
 
diff -NurpP --minimal linux-2.4.25-rc2-vs1.26/fs/ufs/super.c linux-2.4.25-rc2-vs1.26-q0.13/fs/ufs/super.c
--- linux-2.4.25-rc2-vs1.26/fs/ufs/super.c	2002-08-03 02:39:45.000000000 +0200
+++ linux-2.4.25-rc2-vs1.26-q0.13/fs/ufs/super.c	2004-02-13 00:53:54.000000000 +0100
@@ -744,7 +744,7 @@ magic_found:
 	sb->s_blocksize = fs32_to_cpu(sb, usb1->fs_fsize);
 	sb->s_blocksize_bits = fs32_to_cpu(sb, usb1->fs_fshift);
 	sb->s_op = &ufs_super_ops;
-	sb->dq_op = NULL; /***/
+	sb->s_qop = NULL;
 	sb->s_magic = fs32_to_cpu(sb, usb3->fs_magic);
 
 	uspi->s_sblkno = fs32_to_cpu(sb, usb1->fs_sblkno);
diff -NurpP --minimal linux-2.4.25-rc2-vs1.26/include/linux/ext2_fs.h linux-2.4.25-rc2-vs1.26-q0.13/include/linux/ext2_fs.h
--- linux-2.4.25-rc2-vs1.26/include/linux/ext2_fs.h	2004-02-12 23:23:23.000000000 +0100
+++ linux-2.4.25-rc2-vs1.26-q0.13/include/linux/ext2_fs.h	2004-02-13 00:53:54.000000000 +0100
@@ -247,7 +247,7 @@ struct ext2_inode {
 		struct {
 			__u8	l_i_frag;	/* Fragment number */
 			__u8	l_i_fsize;	/* Fragment size */
-			__u16	i_pad1;
+			__u16	l_i_xid;	/* LRU Context */
 			__u16	l_i_uid_high;	/* these 2 fields    */
 			__u16	l_i_gid_high;	/* were reserved2[0] */
 			__u32	l_i_reserved2;
@@ -279,6 +279,7 @@ struct ext2_inode {
 #define i_gid_low	i_gid
 #define i_uid_high	osd2.linux2.l_i_uid_high
 #define i_gid_high	osd2.linux2.l_i_gid_high
+#define i_raw_xid	osd2.linux2.l_i_xid
 #define i_reserved2	osd2.linux2.l_i_reserved2
 #endif
 
@@ -315,6 +316,7 @@ struct ext2_inode {
 #define EXT2_MOUNT_ERRORS_PANIC		0x0040	/* Panic on errors */
 #define EXT2_MOUNT_MINIX_DF		0x0080	/* Mimics the Minix statfs */
 #define EXT2_MOUNT_NO_UID32		0x0200  /* Disable 32-bit UIDs */
+#define EXT2_MOUNT_TAG_XID		0x4000  /* Enable Context Tags */
 
 #define clear_opt(o, opt)		o &= ~EXT2_MOUNT_##opt
 #define set_opt(o, opt)			o |= EXT2_MOUNT_##opt
diff -NurpP --minimal linux-2.4.25-rc2-vs1.26/include/linux/ext3_fs.h linux-2.4.25-rc2-vs1.26-q0.13/include/linux/ext3_fs.h
--- linux-2.4.25-rc2-vs1.26/include/linux/ext3_fs.h	2004-02-12 23:23:30.000000000 +0100
+++ linux-2.4.25-rc2-vs1.26-q0.13/include/linux/ext3_fs.h	2004-02-13 00:53:54.000000000 +0100
@@ -227,6 +227,7 @@ struct ext3_group_desc
 #ifdef CONFIG_JBD_DEBUG
 #define EXT3_IOC_WAIT_FOR_READONLY	_IOR('f', 99, long)
 #endif
+#define	EXT3_IOC_SETXID		FIOC_SETXIDJ
 
 /*
  * Structure of an inode on the disk
@@ -263,7 +264,7 @@ struct ext3_inode {
 		struct {
 			__u8	l_i_frag;	/* Fragment number */
 			__u8	l_i_fsize;	/* Fragment size */
-			__u16	i_pad1;
+			__u16	l_i_xid;	/* LRU Context */
 			__u16	l_i_uid_high;	/* these 2 fields    */
 			__u16	l_i_gid_high;	/* were reserved2[0] */
 			__u32	l_i_reserved2;
@@ -295,6 +296,7 @@ struct ext3_inode {
 #define i_gid_low	i_gid
 #define i_uid_high	osd2.linux2.l_i_uid_high
 #define i_gid_high	osd2.linux2.l_i_gid_high
+#define i_raw_xid	osd2.linux2.l_i_xid
 #define i_reserved2	osd2.linux2.l_i_reserved2
 
 #elif defined(__GNU__)
@@ -340,6 +342,7 @@ struct ext3_inode {
   #define EXT3_MOUNT_WRITEBACK_DATA	0x0C00	/* No data ordering */
 #define EXT3_MOUNT_UPDATE_JOURNAL	0x1000	/* Update the journal format */
 #define EXT3_MOUNT_NO_UID32		0x2000  /* Disable 32-bit UIDs */
+#define EXT3_MOUNT_TAG_XID		0x4000  /* Enable Context Tags */
 
 /* Compatibility, for having both ext2_fs.h and ext3_fs.h included at once */
 #ifndef _LINUX_EXT2_FS_H
diff -NurpP --minimal linux-2.4.25-rc2-vs1.26/include/linux/fs.h linux-2.4.25-rc2-vs1.26-q0.13/include/linux/fs.h
--- linux-2.4.25-rc2-vs1.26/include/linux/fs.h	2004-02-12 23:22:05.000000000 +0100
+++ linux-2.4.25-rc2-vs1.26-q0.13/include/linux/fs.h	2004-02-13 00:53:54.000000000 +0100
@@ -21,6 +21,7 @@
 #include <linux/cache.h>
 #include <linux/stddef.h>
 #include <linux/string.h>
+#include <linux/vxid.h>
 
 #include <asm/atomic.h>
 #include <asm/bitops.h>
@@ -111,6 +112,7 @@ extern int leases_enable, dir_notify_ena
 #define MS_MOVE		8192
 #define MS_REC		16384
 #define MS_VERBOSE	32768
+#define MS_TAGXID	(1<<24)	/* tag inodes with context information */
 #define MS_ACTIVE	(1<<30)
 #define MS_NOUSER	(1<<31)
 
@@ -456,6 +458,7 @@ struct inode {
 	nlink_t			i_nlink;
 	uid_t			i_uid;
 	gid_t			i_gid;
+	unsigned int		i_xid;
 	kdev_t			i_rdev;
 	loff_t			i_size;
 	time_t			i_atime;
@@ -476,6 +479,7 @@ struct inode {
 	struct file_lock	*i_flock;
 	struct address_space	*i_mapping;
 	struct address_space	i_data;
+	struct dqhash		*i_dqh;
 	struct dquot		*i_dquot[MAXQUOTAS];
 	/* These three should probably be a union */
 	struct list_head	i_devices;
@@ -753,7 +757,7 @@ struct super_block {
 	unsigned long long	s_maxbytes;	/* Max file size */
 	struct file_system_type	*s_type;
 	struct super_operations	*s_op;
-	struct dquot_operations	*dq_op;
+	struct dquot_operations	*s_qop;
 	struct quotactl_ops	*s_qcop;
 	unsigned long		s_flags;
 	unsigned long		s_magic;
@@ -769,7 +773,7 @@ struct super_block {
 
 	struct block_device	*s_bdev;
 	struct list_head	s_instances;
-	struct quota_info	s_dquot;	/* Diskquota specific options */
+	struct list_head	s_dqhs;		/* Diskquota hashes */
 
 	union {
 		struct minix_sb_info	minix_sb;
diff -NurpP --minimal linux-2.4.25-rc2-vs1.26/include/linux/quota.h linux-2.4.25-rc2-vs1.26-q0.13/include/linux/quota.h
--- linux-2.4.25-rc2-vs1.26/include/linux/quota.h	2004-02-12 23:22:05.000000000 +0100
+++ linux-2.4.25-rc2-vs1.26-q0.13/include/linux/quota.h	2004-02-13 00:53:54.000000000 +0100
@@ -57,6 +57,14 @@ typedef __u64 qsize_t;          /* Type 
 #define kb2qb(x) ((x) >> (QUOTABLOCK_BITS-10))
 #define toqb(x) (((x) + QUOTABLOCK_SIZE - 1) >> QUOTABLOCK_BITS)
 
+/* are NULL dqhash ptrs valid? */
+#define HANDLE_DQHASH_NULL
+#ifdef	HANDLE_DQHASH_NULL
+#define	dqhash_valid(hash)	((hash) != NULL)
+#else
+#define	dqhash_valid(hash)	(0 == 0)
+#endif
+
 #define MAXQUOTAS 2
 #define USRQUOTA  0		/* element used for user quotas */
 #define GRPQUOTA  1		/* element used for group quotas */
@@ -182,7 +190,7 @@ extern inline void mark_info_dirty(struc
 #define info_any_dirty(info) ((info)->dqi_flags & DQF_INFO_DIRTY ||\
 			      (info)->dqi_flags & DQF_ANY_DQUOT_DIRTY)
 
-#define sb_dqopt(sb) (&(sb)->s_dquot)
+#define dqh_dqopt(dqh) (&(dqh)->dqh_dqopt)
 
 struct dqstats {
 	int lookups;
@@ -197,7 +205,8 @@ struct dqstats {
 
 extern struct dqstats dqstats;
 
-#define NR_DQHASH 43            /* Just an arbitrary number */
+#define NR_DQHASH	13	/* Just an arbitrary number */
+#define NR_DQH_HASH	17	/* Just an arbitrary number */
 
 #define DQ_LOCKED     0x01	/* dquot under IO */
 #define DQ_MOD        0x02	/* dquot modified since read */
@@ -216,7 +225,7 @@ struct dquot {
 	int dq_dup_ref;			/* Number of duplicated refences */
 
 	/* fields after this point are cleared when invalidating */
-	struct super_block *dq_sb;	/* superblock this applies to */
+	struct dqhash *dq_dqh;		/* quota hash backpointer */
 	unsigned int dq_id;		/* ID this applies to (uid, gid) */
 	kdev_t dq_dev;			/* Device this applies to */
 	loff_t dq_off;			/* Offset of dquot on disk */
@@ -232,12 +241,12 @@ struct dquot {
 
 /* Operations which must be implemented by each quota format */
 struct quota_format_ops {
-	int (*check_quota_file)(struct super_block *sb, int type);	/* Detect whether file is in our format */
-	int (*read_file_info)(struct super_block *sb, int type);	/* Read main info about file - called on quotaon() */
-	int (*write_file_info)(struct super_block *sb, int type);	/* Write main info about file */
-	int (*free_file_info)(struct super_block *sb, int type);	/* Called on quotaoff() */
-	int (*read_dqblk)(struct dquot *dquot);		/* Read structure for one user */
-	int (*commit_dqblk)(struct dquot *dquot);	/* Write (or delete) structure for one user */
+	int (*check_quota_file)(struct dqhash *, int);	/* Detect whether file is in our format */
+	int (*read_file_info)(struct dqhash *, int);	/* Read main info about file - called on quotaon() */
+	int (*write_file_info)(struct dqhash *, int);	/* Write main info about file */
+	int (*free_file_info)(struct dqhash *, int);	/* Called on quotaoff() */
+	int (*read_dqblk)(struct dquot *);		/* Read structure for one user */
+	int (*commit_dqblk)(struct dquot *);		/* Write (or delete) structure for one user */
 };
 
 /* Operations working with dquots */
@@ -254,17 +263,17 @@ struct dquot_operations {
 
 /* Operations handling requests from userspace */
 struct quotactl_ops {
-	int (*quota_on)(struct super_block *, int, int, char *);
-	int (*quota_off)(struct super_block *, int);
-	int (*quota_sync)(struct super_block *, int);
-	int (*get_info)(struct super_block *, int, struct if_dqinfo *);
-	int (*set_info)(struct super_block *, int, struct if_dqinfo *);
-	int (*get_dqblk)(struct super_block *, int, qid_t, struct if_dqblk *);
-	int (*set_dqblk)(struct super_block *, int, qid_t, struct if_dqblk *);
-	int (*get_xstate)(struct super_block *, struct fs_quota_stat *);
-	int (*set_xstate)(struct super_block *, unsigned int, int);
-	int (*get_xquota)(struct super_block *, int, qid_t, struct fs_disk_quota *);
-	int (*set_xquota)(struct super_block *, int, qid_t, struct fs_disk_quota *);
+	int (*quota_on)(struct dqhash *, int, int, char *);
+	int (*quota_off)(struct dqhash *, int);
+	int (*quota_sync)(struct dqhash *, int);
+	int (*get_info)(struct dqhash *, int, struct if_dqinfo *);
+	int (*set_info)(struct dqhash *, int, struct if_dqinfo *);
+	int (*get_dqblk)(struct dqhash *, int, qid_t, struct if_dqblk *);
+	int (*set_dqblk)(struct dqhash *, int, qid_t, struct if_dqblk *);
+	int (*get_xstate)(struct dqhash *, struct fs_quota_stat *);
+	int (*set_xstate)(struct dqhash *, unsigned int, int);
+	int (*get_xquota)(struct dqhash *, int, qid_t, struct fs_disk_quota *);
+	int (*set_xquota)(struct dqhash *, int, qid_t, struct fs_disk_quota *);
 };
 
 struct quota_format_type {
@@ -286,11 +295,6 @@ struct quota_info {
 	struct quota_format_ops *ops[MAXQUOTAS];	/* Operations for each type */
 };
 
-/* Inline would be better but we need to dereference super_block which is not defined yet */
-#define mark_dquot_dirty(dquot) do {\
-	dquot->dq_flags |= DQ_MOD;\
-	sb_dqopt(dquot->dq_sb)->info[dquot->dq_type].dqi_flags |= DQF_ANY_DQUOT_DIRTY;\
-} while (0)
 
 #define dquot_dirty(dquot) ((dquot)->dq_flags & DQ_MOD)
 
@@ -305,14 +309,91 @@ static inline int is_enabled(struct quot
 	return 0;
 }
 
-#define sb_any_quota_enabled(sb) (is_enabled(sb_dqopt(sb), USRQUOTA) | is_enabled(sb_dqopt(sb), GRPQUOTA))
+#define dqh_any_quota_enabled(hash) (dqhash_valid(hash) && \
+	(is_enabled(dqh_dqopt(hash), USRQUOTA) || is_enabled(dqh_dqopt(hash), GRPQUOTA)))
 
-#define sb_has_quota_enabled(sb, type) (is_enabled(sb_dqopt(sb), type))
+#define dqh_has_quota_enabled(hash, type) (dqhash_valid(hash) && is_enabled(dqh_dqopt(hash), type))
 
 int register_quota_format(struct quota_format_type *fmt);
 void unregister_quota_format(struct quota_format_type *fmt);
 void init_dquot_operations(struct dquot_operations *fsdqops);
 
+struct dqh_dlimit {
+	__u32 dl_inodes;		/* total inodes */
+	__u32 dl_ilimit;		/* maximum inodes */
+
+	__u64 dl_bytes;			/* total bytes */
+	__u64 dl_blimit;		/* maximum bytes */
+
+	unsigned int dl_nrlmult;	/* non root limit mult */
+	unsigned int dl_l2bsize;	/* bsize shift (bits) */
+	struct rw_semaphore dl_sem;	/* lock limits */
+};
+
+struct dqhash {
+	struct list_head dqh_list;	/* quota hashes within hash slot */
+	struct list_head dqh_sblist;	/* all superblock quota hashes */
+	atomic_t dqh_count;		/* Use count */
+	unsigned int dqh_id;		/* ID for hash */
+	unsigned int dqh_xid;		/* context */
+	struct quota_info dqh_dqopt;	/* Diskquota specific options */
+	struct dquot_operations	*dqh_qop;
+	struct quotactl_ops *dqh_qcop;
+	struct super_block *dqh_sb;	/* super block */
+	struct dqh_dlimit dqh_dlimit;	/* per hash disk limits */
+	struct list_head dqh_hash[NR_DQHASH];
+};
+
+struct dli_limits {
+	__u32 dli_inodes_used;
+	__u32 dli_inodes_total;
+	
+	__u32 dli_blocks_used;
+	__u32 dli_blocks_total;
+	
+	__u32 dli_reserved;
+};
+
+#if defined(CONFIG_QUOTA)
+
+
+struct dqhash *new_dqhash(struct super_block *, unsigned int);
+struct dqhash *get_dqhash(struct super_block *, unsigned int);
+
+void destroy_dqhash(struct dqhash *);
+
+static inline void dqhput(struct dqhash *hash)
+{
+	if (dqhash_valid(hash))
+		if (atomic_dec_and_test(&hash->dqh_count))
+			destroy_dqhash(hash);
+}
+
+static inline struct dqhash *dqhget(struct dqhash *hash)
+{
+	if (dqhash_valid(hash))
+		atomic_inc(&hash->dqh_count);
+	return hash;
+}
+
+
+static inline void mark_dquot_dirty(struct dquot *dq)
+{
+	dq->dq_flags |= DQ_MOD;
+	dqh_dqopt(dq->dq_dqh)->info[dq->dq_type].dqi_flags |= DQF_ANY_DQUOT_DIRTY;
+}
+
+#else /* CONFIG_QUOTA */
+
+#define new_dqhash(sb, xid)		(0)
+#define get_dqhash(sb, xid)		(0)
+#define destroy_dqhash(hash)		do { } while(0)
+
+#define dqhput(hash)			do { } while(0)
+#define dqhget(hash)			(hash)
+
+#endif /* CONFIG_QUOTA */
+
 #else
 
 # /* nodep */ include <sys/cdefs.h>
diff -NurpP --minimal linux-2.4.25-rc2-vs1.26/include/linux/quotacompat.h linux-2.4.25-rc2-vs1.26-q0.13/include/linux/quotacompat.h
--- linux-2.4.25-rc2-vs1.26/include/linux/quotacompat.h	2004-02-12 23:27:16.000000000 +0100
+++ linux-2.4.25-rc2-vs1.26-q0.13/include/linux/quotacompat.h	2004-02-13 00:53:54.000000000 +0100
@@ -83,4 +83,9 @@ struct v2c_dqstats {
 #define Q_V2_SETUSE   0x0F00	/* set usage */
 #define Q_V2_GETSTATS 0x1100	/* get collected stats */
 
+#define Q_ADD_DQHASH  0x2100	/* add dqhash */
+#define Q_REM_DQHASH  0x2200	/* remove dqhash */
+#define Q_GET_DLIMIT  0x2300	/* get disk limit */
+#define Q_SET_DLIMIT  0x2400	/* set disk limit */
+
 #endif
diff -NurpP --minimal linux-2.4.25-rc2-vs1.26/include/linux/quotaops.h linux-2.4.25-rc2-vs1.26-q0.13/include/linux/quotaops.h
--- linux-2.4.25-rc2-vs1.26/include/linux/quotaops.h	2004-02-12 23:22:39.000000000 +0100
+++ linux-2.4.25-rc2-vs1.26-q0.13/include/linux/quotaops.h	2004-02-13 00:53:54.000000000 +0100
@@ -17,11 +17,27 @@
 
 #include <linux/fs.h>
 
+// #define	DEBUG_MACROS
+// #define	DEBUG_HASHES
+// #define	DEBUG_DLIMIT
+// #define	DEBUG_QALLOC
+// #define	DEBUG_EXTERN
+
+#define	DQH_ID(h)	((h)?((h)->dqh_id):0)
+#define	DQH_XID(h)	((h)?((h)->dqh_xid):0)
+
+#define	DFM_INO		"i%p[%5lu,#%3d]"
+#define	DBD_INO(i)	(i), (i)->i_ino, (i)->i_xid
+
+#define	DFM_DQH		"*%p[%2d,#%3d]"
+#define	DBD_DQH(h)	(h), DQH_ID(h), DQH_XID(h)
+
+
 /*
  * declaration of quota_function calls in kernel.
  */
 extern void sync_dquots_dev(kdev_t dev, int type);
-extern void sync_dquots_sb(struct super_block *sb, int type);
+extern void sync_dquots_dqh(struct dqhash *hash, int type);
 
 extern void dquot_initialize(struct inode *inode, int type);
 extern void dquot_drop(struct inode *inode);
@@ -33,6 +49,173 @@ extern void dquot_free_space(struct inod
 extern void dquot_free_inode(const struct inode *inode, unsigned long number);
 
 extern int  dquot_transfer(struct inode *inode, struct iattr *iattr);
+extern int  dqhash_transfer(struct inode *inode, struct dqhash *hash);
+
+extern int  dlimit_transfer(struct inode *inode, struct dqhash *hash);
+
+#ifdef DEBUG_HASHES
+#define dprintk(...)	printk(__VA_ARGS__)
+#else
+#define dprintk(...)
+#endif
+
+static __inline__ void __vx_dq_modify(struct inode *inode, unsigned int xid)
+{
+	struct dqhash *dqh = get_dqhash(inode->i_sb, xid);
+
+	if (dqh != inode->i_dqh) {
+		dprintk("··· __vx_dq_modify: \t" DFM_INO ": " DFM_DQH " != " DFM_DQH "\n",
+			DBD_INO(inode), DBD_DQH(inode->i_dqh), DBD_DQH(dqh));
+		dqhash_transfer(inode, dqh);
+		dlimit_transfer(inode, dqh);
+		dqhput(inode->i_dqh);
+		inode->i_dqh = dqh;
+	} else
+		dqhput(dqh);
+	inode->i_xid = xid;
+}
+
+static __inline__ void vx_dq_modify(struct inode *inode, unsigned int xid)
+{
+	if (!(inode->i_sb->s_flags & MS_TAGXID))
+		return;
+	dprintk("··· vx_dq_modify: \t" DFM_INO ": xid->#%d\n", DBD_INO(inode), xid);
+	__vx_dq_modify(inode, xid);
+	mark_inode_dirty(inode);
+}
+
+static __inline__ void vx_dq_cond_modify(struct inode *inode, unsigned int xid)
+{
+	if (inode->i_xid != xid)
+		vx_dq_modify(inode, xid);
+}
+
+static __inline__ void vx_dq_unlink(struct inode *inode)
+{
+	if (inode->i_nlink == 0)
+		return;
+	/* inode from other context? */
+	if (inode->i_xid != current->vx_id)
+		return;
+	/* inode still referenced ... */
+	if (inode->i_xid == 0)
+		return;
+	/* transfer back to xid zero hash */
+	vx_dq_modify(inode, 0);
+}
+
+static __inline__ void CHECK_DQHASH(struct inode *inode)
+{
+	if (!dqhash_valid(inode->i_dqh))
+		return;
+	if (inode->i_xid != inode->i_dqh->dqh_xid) {
+		printk("··· CHECK_DQHASH: " DFM_INO " xid != " DFM_DQH "\n",
+			DBD_INO(inode), DBD_DQH(inode->i_dqh));
+		dump_stack();
+		// BUG();
+	}
+}
+
+
+#undef dprintk
+#ifdef DEBUG_DLIMIT
+#define dprintk(...)	printk(__VA_ARGS__)
+#else
+#define dprintk(...)
+#endif
+
+
+#define	NOILIMIT	((__u32)0)
+#define	NOBLIMIT	((__u64)0)
+
+static __inline__ int dlimit_inodes_avail(struct super_block *sb, unsigned long number)
+{
+	struct dqhash *dqh = get_dqhash(sb, current->vx_id);
+	struct dqh_dlimit *dl;
+	int ret;
+
+	if (!dqhash_valid(dqh))
+		return 1;
+
+	dl = &dqh->dqh_dlimit;
+	down_read(&dl->dl_sem);
+	ret = (dl->dl_ilimit == NOILIMIT) ||
+		(dl->dl_ilimit >= (dl->dl_inodes + number));
+	if (!ret)
+		dprintk("··· dlimit_inodes_avail: %d + %ld > %d\n",
+			dl->dl_inodes, number, dl->dl_ilimit);
+	up_read(&dl->dl_sem);
+	dqhput(dqh);
+	return ret;
+}
+
+static __inline__ int dlimit_space_avail(struct super_block *sb, int sres, qsize_t number)
+{
+	struct dqhash *dqh = get_dqhash(sb, current->vx_id);
+	struct dqh_dlimit *dl;
+	int ret;
+
+	if (!dqhash_valid(dqh))
+		return 1;
+
+	dl = &dqh->dqh_dlimit;
+	down_read(&dl->dl_sem);
+	ret = (dl->dl_blimit == NOBLIMIT) || ((sres ? dl->dl_blimit :
+		((dl->dl_blimit * dl->dl_nrlmult) >> 10)) >= (dl->dl_bytes + number));
+	if (!ret)
+		dprintk("··· dlimit_space_avail: %lld + %ld > %lld\n",
+			dl->dl_bytes, (long)number, dl->dl_blimit);
+	up_read(&dl->dl_sem);
+	dqhput(dqh);
+	return ret;
+}
+
+#define dlimit_block_avail(sb, sr, nr) \
+	dlimit_space_avail(sb, sr, ((unsigned long long)(nr)) << (sb)->s_blocksize_bits)
+
+
+static	__inline__ void dlimit_incr_inodes(struct dqhash *hash, unsigned long number)
+{
+        if (!dqhash_valid(hash))
+		return;
+	down_write(&hash->dqh_dlimit.dl_sem);
+	hash->dqh_dlimit.dl_inodes += number;
+	up_write(&hash->dqh_dlimit.dl_sem);
+}
+
+static	__inline__ void dlimit_decr_inodes(struct dqhash *hash, unsigned long number)
+{
+        if (!dqhash_valid(hash))
+		return;
+	down_write(&hash->dqh_dlimit.dl_sem);
+	if (hash->dqh_dlimit.dl_inodes > number)
+		hash->dqh_dlimit.dl_inodes -= number;
+	else
+		hash->dqh_dlimit.dl_inodes = 0;
+	up_write(&hash->dqh_dlimit.dl_sem);
+}
+
+static	__inline__ void dlimit_incr_space(struct dqhash *hash, qsize_t number)
+{
+        if (!dqhash_valid(hash))
+		return;
+	down_write(&hash->dqh_dlimit.dl_sem);
+	hash->dqh_dlimit.dl_bytes += number;
+	up_write(&hash->dqh_dlimit.dl_sem);
+}
+
+static	__inline__ void dlimit_decr_space(struct dqhash *hash, qsize_t number)
+{
+        if (!dqhash_valid(hash))
+		return;
+	down_write(&hash->dqh_dlimit.dl_sem);
+	if (hash->dqh_dlimit.dl_bytes > number)
+		hash->dqh_dlimit.dl_bytes -= number;
+	else
+		hash->dqh_dlimit.dl_bytes = 0;
+	up_write(&hash->dqh_dlimit.dl_sem);
+}
+
 
 /*
  * Operations supported for diskquotas.
@@ -40,6 +223,13 @@ extern int  dquot_transfer(struct inode 
 extern struct dquot_operations dquot_operations;
 extern struct quotactl_ops vfs_quotactl_ops;
 
+#undef dprintk
+#ifdef DEBUG_MACROS
+#define dprintk(...)	printk(__VA_ARGS__)
+#else
+#define dprintk(...)
+#endif
+
 #define sb_dquot_ops (&dquot_operations)
 #define sb_quotactl_ops (&vfs_quotactl_ops)
 
@@ -48,34 +238,54 @@ static __inline__ void DQUOT_INIT(struct
 	if (!inode->i_sb)
 		out_of_line_bug();
 	lock_kernel();
-	if (sb_any_quota_enabled(inode->i_sb) && !IS_NOQUOTA(inode))
-		inode->i_sb->dq_op->initialize(inode, -1);
+	dprintk("··· DQUOT_INIT: sb:%p " DFM_INO ": " DFM_DQH "\n",
+		inode->i_sb, DBD_INO(inode), DBD_DQH(inode->i_dqh));
+	CHECK_DQHASH(inode);
+	if (!dqhash_valid(inode->i_dqh))
+		goto out;
+	if (dqh_any_quota_enabled(inode->i_dqh) && !IS_NOQUOTA(inode))
+		inode->i_dqh->dqh_qop->initialize(inode, -1);
+out:
 	unlock_kernel();
 }
 
 static __inline__ void DQUOT_DROP(struct inode *inode)
 {
 	lock_kernel();
+	dprintk("··· DQUOT_DROP: sb:%p " DFM_INO ": " DFM_DQH "\n",
+		inode->i_sb, DBD_INO(inode), DBD_DQH(inode->i_dqh));
 	if (IS_QUOTAINIT(inode)) {
-		if (!inode->i_sb)
-			out_of_line_bug();
-		inode->i_sb->dq_op->drop(inode);	/* Ops must be set when there's any quota... */
+		if (inode->i_dqh)
+			inode->i_dqh->dqh_qop->drop(inode);	/* Ops must be set when there's any quota... */
+		else
+			printk("DQUOT_DROP: inode without dqh!");
 	}
 	unlock_kernel();
 }
 
+#undef dprintk
+#ifdef DEBUG_QALLOC
+#define dprintk(...)	printk(__VA_ARGS__)
+#else
+#define dprintk(...)
+#endif
+
 static __inline__ int DQUOT_PREALLOC_SPACE_NODIRTY(struct inode *inode, qsize_t nr)
 {
 	lock_kernel();
-	if (sb_any_quota_enabled(inode->i_sb)) {
+	CHECK_DQHASH(inode);
+	dprintk("··· DQUOT_PREALLOC_SPACE_NODIRTY: " DFM_INO ": " DFM_DQH " (%d)\n",
+		DBD_INO(inode), DBD_DQH(inode->i_dqh), nr);
+	if (dqh_any_quota_enabled(inode->i_dqh)) {
 		/* Used space is updated in alloc_space() */
-		if (inode->i_sb->dq_op->alloc_space(inode, nr, 1) == NO_QUOTA) {
+		if (inode->i_dqh->dqh_qop->alloc_space(inode, nr, 1) == NO_QUOTA) {
 			unlock_kernel();
 			return 1;
 		}
 	}
 	else
 		inode_add_bytes(inode, nr);
+	dlimit_incr_space(inode->i_dqh, nr);
 	unlock_kernel();
 	return 0;
 }
@@ -91,15 +301,19 @@ static __inline__ int DQUOT_PREALLOC_SPA
 static __inline__ int DQUOT_ALLOC_SPACE_NODIRTY(struct inode *inode, qsize_t nr)
 {
 	lock_kernel();
-	if (sb_any_quota_enabled(inode->i_sb)) {
+	CHECK_DQHASH(inode);
+	dprintk("··· DQUOT_ALLOC_SPACE_NODIRTY: " DFM_INO ": " DFM_DQH " (%d)\n",
+		DBD_INO(inode), DBD_DQH(inode->i_dqh), nr);
+	if (dqh_any_quota_enabled(inode->i_dqh)) {
 		/* Used space is updated in alloc_space() */
-		if (inode->i_sb->dq_op->alloc_space(inode, nr, 0) == NO_QUOTA) {
+		if (inode->i_dqh->dqh_qop->alloc_space(inode, nr, 0) == NO_QUOTA) {
 			unlock_kernel();
 			return 1;
 		}
 	}
 	else
 		inode_add_bytes(inode, nr);
+	dlimit_incr_space(inode->i_dqh, nr);
 	unlock_kernel();
 	return 0;
 }
@@ -115,13 +329,17 @@ static __inline__ int DQUOT_ALLOC_SPACE(
 static __inline__ int DQUOT_ALLOC_INODE(struct inode *inode)
 {
 	lock_kernel();
-	if (sb_any_quota_enabled(inode->i_sb)) {
+	CHECK_DQHASH(inode);
+	dprintk("··· DQUOT_ALLOC_INODE: " DFM_INO ": " DFM_DQH "\n",
+		DBD_INO(inode), DBD_DQH(inode->i_dqh));
+	if (dqh_any_quota_enabled(inode->i_dqh)) {
 		DQUOT_INIT(inode);
-		if (inode->i_sb->dq_op->alloc_inode(inode, 1) == NO_QUOTA) {
+		if (inode->i_dqh->dqh_qop->alloc_inode(inode, 1) == NO_QUOTA) {
 			unlock_kernel();
 			return 1;
 		}
 	}
+	dlimit_incr_inodes(inode->i_dqh, 1);
 	unlock_kernel();
 	return 0;
 }
@@ -129,10 +347,13 @@ static __inline__ int DQUOT_ALLOC_INODE(
 static __inline__ void DQUOT_FREE_SPACE_NODIRTY(struct inode *inode, qsize_t nr)
 {
 	lock_kernel();
-	if (sb_any_quota_enabled(inode->i_sb))
-		inode->i_sb->dq_op->free_space(inode, nr);
+	dprintk("··· DQUOT_FREE_SPACE_NODIRTY: " DFM_INO ": " DFM_DQH " (%d)\n",
+		DBD_INO(inode), DBD_DQH(inode->i_dqh), nr);
+	if (dqh_any_quota_enabled(inode->i_dqh))
+		inode->i_dqh->dqh_qop->free_space(inode, nr);
 	else
 		inode_sub_bytes(inode, nr);
+	dlimit_decr_space(inode->i_dqh, nr);
 	unlock_kernel();
 }
 
@@ -145,17 +366,22 @@ static __inline__ void DQUOT_FREE_SPACE(
 static __inline__ void DQUOT_FREE_INODE(struct inode *inode)
 {
 	lock_kernel();
-	if (sb_any_quota_enabled(inode->i_sb))
-		inode->i_sb->dq_op->free_inode(inode, 1);
+	dprintk("··· DQUOT_FREE_INODE: " DFM_INO ": " DFM_DQH "\n",
+		DBD_INO(inode), DBD_DQH(inode->i_dqh));
+	dlimit_decr_inodes(inode->i_dqh, 1);
+	if (dqh_any_quota_enabled(inode->i_dqh))
+		inode->i_dqh->dqh_qop->free_inode(inode, 1);
 	unlock_kernel();
 }
 
 static __inline__ int DQUOT_TRANSFER(struct inode *inode, struct iattr *iattr)
 {
 	lock_kernel();
-	if (sb_any_quota_enabled(inode->i_sb) && !IS_NOQUOTA(inode)) {
+	dprintk("··· DQUOT_TRANSFER: " DFM_INO ": " DFM_DQH "\n",
+		DBD_INO(inode), DBD_DQH(inode->i_dqh));
+	if (dqh_any_quota_enabled(inode->i_dqh) && !IS_NOQUOTA(inode)) {
 		DQUOT_INIT(inode);
-		if (inode->i_sb->dq_op->transfer(inode, iattr) == NO_QUOTA) {
+		if (inode->i_dqh->dqh_qop->transfer(inode, iattr) == NO_QUOTA) {
 			unlock_kernel();
 			return 1;
 		}
@@ -165,19 +391,27 @@ static __inline__ int DQUOT_TRANSFER(str
 }
 
 #define DQUOT_SYNC_DEV(dev)	sync_dquots_dev(dev, -1)
-#define DQUOT_SYNC_SB(sb)	sync_dquots_sb(sb, -1)
+#define DQUOT_SYNC_DQH(hash)	sync_dquots_dqh(hash, -1)
 
-static __inline__ int DQUOT_OFF(struct super_block *sb)
+static __inline__ int DQUOT_OFF(struct dqhash *hash)
 {
 	int ret = -ENOSYS;
 
 	lock_kernel();
-	if (sb->s_qcop && sb->s_qcop->quota_off)
-		ret = sb->s_qcop->quota_off(sb, -1);
+	dprintk("··· DQUOT_OFF: " DFM_DQH "\n", DBD_DQH(hash));
+	if (hash->dqh_qcop && hash->dqh_qcop->quota_off)
+		ret = hash->dqh_qcop->quota_off(hash, -1);
 	unlock_kernel();
 	return ret;
 }
 
+#undef dprintk
+#ifdef DEBUG_EXTERN
+#define dprintk(...)	printk(__VA_ARGS__)
+#else
+#define dprintk(...)
+#endif
+
 #else
 
 /*
@@ -191,9 +425,20 @@ static __inline__ int DQUOT_OFF(struct s
 #define DQUOT_ALLOC_INODE(inode)		(0)
 #define DQUOT_FREE_INODE(inode)			do { } while(0)
 #define DQUOT_SYNC_DEV(dev)			do { } while(0)
-#define DQUOT_SYNC_SB(sb)			do { } while(0)
-#define DQUOT_OFF(sb)				do { } while(0)
+#define DQUOT_SYNC_DQH(hash)			do { } while(0)
+#define DQUOT_OFF(hash)				do { } while(0)
 #define DQUOT_TRANSFER(inode, iattr)		(0)
+
+#define new_dqhash(sb, xid)			(0)
+#define get_dqhash(sb, xid)			(0)
+#define destroy_dqhash(hash)			do { } while(0)
+
+#define vx_dq_modify(inode, xid)		do { } while(0)
+#define vx_dq_cond_modify(inode, xid)		do { } while(0)
+#define vx_dq_unlink(inode)			do { } while(0)
+
+#define CHECK_DQHASH(inode)			do { } while(0)
+
 extern __inline__ int DQUOT_PREALLOC_SPACE_NODIRTY(struct inode *inode, qsize_t nr)
 {
 	lock_kernel();
diff -NurpP --minimal linux-2.4.25-rc2-vs1.26/include/linux/vxid.h linux-2.4.25-rc2-vs1.26-q0.13/include/linux/vxid.h
--- linux-2.4.25-rc2-vs1.26/include/linux/vxid.h	1970-01-01 01:00:00.000000000 +0100
+++ linux-2.4.25-rc2-vs1.26-q0.13/include/linux/vxid.h	2004-02-13 00:53:54.000000000 +0100
@@ -0,0 +1,64 @@
+#ifndef _LINUX_VXID_H_
+#define _LINUX_VXID_H_
+
+#ifdef CONFIG_INOXID_NONE
+
+#define	INOXID_UID(uid, gid)		(uid)
+#define	INOXID_GID(uid, gid)		(gid)
+#define	INOXID_XID(uid, gid, xid)	(0)
+
+#define	XIDINO_UID(uid, xid)		(uid)
+#define	XIDINO_GID(gid, xid)		(gid)
+
+#define	MAX_UID		0xFFFFFFFF
+#define	MAX_GID		0xFFFFFFFF
+
+#endif
+
+#ifdef CONFIG_INOXID_GID16
+
+#define	INOXID_UID(uid, gid)		(uid)
+#define	INOXID_GID(uid, gid)		((gid) & 0xFFFF)
+#define	INOXID_XID(uid, gid, xid)	(((gid) >> 16) & 0xFFFF)
+
+#define	XIDINO_UID(uid, xid)		(uid)
+#define	XIDINO_GID(gid, xid)		(((gid) & 0xFFFF) | ((xid) << 16))
+
+#define	MAX_UID		0xFFFFFFFF
+#define	MAX_GID		0x0000FFFF
+
+#endif
+
+#ifdef CONFIG_INOXID_GID24
+
+#define	INOXID_UID(uid, gid)		((uid) & 0xFFFFFF)
+#define	INOXID_GID(uid, gid)		((gid) & 0xFFFFFF)
+#define	INOXID_XID(uid, gid, xid)	((((uid) >> 16) & 0xFF00) | (((gid) >> 24) & 0xFF))
+
+#define	XIDINO_UID(uid, xid)		(((uid) & 0xFFFFFF) | (((xid) & 0xFF00) << 16))
+#define	XIDINO_GID(gid, xid)		(((gid) & 0xFFFFFF) | (((xid) & 0x00FF) << 24))
+
+#define	MAX_UID		0x00FFFFFF
+#define	MAX_GID		0x00FFFFFF
+
+#endif
+
+#ifdef CONFIG_INOXID_GID32
+
+#define	INOXID_UID(uid, gid)		(uid)
+#define	INOXID_GID(uid, gid)		(gid)
+#define	INOXID_XID(uid, gid, xid)	(xid)
+
+#define	XIDINO_UID(uid, xid)		(uid)
+#define	XIDINO_GID(gid, xid)		(gid)
+
+#define	MAX_UID		0xFFFFFFFF
+#define	MAX_GID		0xFFFFFFFF
+
+#endif
+
+#define	FIOC_GETXID	_IOR('x', 1, long)
+#define	FIOC_SETXID	_IOW('x', 2, long)
+#define	FIOC_SETXIDJ	_IOW('x', 3, long)
+
+#endif
