This commit was manufactured by cvs2svn to create branch 'vserver'.
[linux-2.6.git] / fs / ntfs / quota.c
1 /*
2  * quota.c - NTFS kernel quota ($Quota) handling.  Part of the Linux-NTFS
3  *           project.
4  *
5  * Copyright (c) 2004 Anton Altaparmakov
6  *
7  * This program/include file is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License as published
9  * by the Free Software Foundation; either version 2 of the License, or
10  * (at your option) any later version.
11  *
12  * This program/include file is distributed in the hope that it will be
13  * useful, but WITHOUT ANY WARRANTY; without even the implied warranty
14  * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program (in the main directory of the Linux-NTFS
19  * distribution in the file COPYING); if not, write to the Free Software
20  * Foundation,Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
21  */
22
23 #ifdef NTFS_RW
24
25 #include "ntfs.h"
26 #include "index.h"
27 #include "quota.h"
28
29 /**
30  * ntfs_mark_quotas_out_of_date - mark the quotas out of date on an ntfs volume
31  * @vol:        ntfs volume on which to mark the quotas out of date
32  *
33  * Mark the quotas out of date on the ntfs volume @vol and return TRUE on
34  * success and FALSE on error.
35  */
36 BOOL ntfs_mark_quotas_out_of_date(ntfs_volume *vol)
37 {
38         ntfs_index_context *ictx;
39         QUOTA_CONTROL_ENTRY *qce;
40         const u32 qid = QUOTA_DEFAULTS_ID;
41         int err;
42
43         ntfs_debug("Entering.");
44         if (NVolQuotaOutOfDate(vol))
45                 goto done;
46         if (!vol->quota_ino || !vol->quota_q_ino) {
47                 ntfs_error(vol->sb, "Quota inodes are not open.");
48                 return FALSE;
49         }
50         down(&vol->quota_q_ino->i_sem);
51         ictx = ntfs_index_ctx_get(NTFS_I(vol->quota_q_ino));
52         if (!ictx) {
53                 ntfs_error(vol->sb, "Failed to get index context.");
54                 return FALSE;
55         }
56         err = ntfs_index_lookup(&qid, sizeof(qid), ictx);
57         if (err) {
58                 if (err == -ENOENT)
59                         ntfs_error(vol->sb, "Quota defaults entry is not "
60                                         "present.");
61                 else
62                         ntfs_error(vol->sb, "Lookup of quota defaults entry "
63                                         "failed.");
64                 goto err_out;
65         }
66         if (ictx->data_len < offsetof(QUOTA_CONTROL_ENTRY, sid)) {
67                 ntfs_error(vol->sb, "Quota defaults entry size is invalid.  "
68                                 "Run chkdsk.");
69                 goto err_out;
70         }
71         qce = (QUOTA_CONTROL_ENTRY*)ictx->data;
72         if (le32_to_cpu(qce->version) != QUOTA_VERSION) {
73                 ntfs_error(vol->sb, "Quota defaults entry version 0x%x is not "
74                                 "supported.", le32_to_cpu(qce->version));
75                 goto err_out;
76         }
77         ntfs_debug("Quota defaults flags = 0x%x.", le32_to_cpu(qce->flags));
78         /* If quotas are already marked out of date, no need to do anything. */
79         if (qce->flags & QUOTA_FLAG_OUT_OF_DATE)
80                 goto set_done;
81         /*
82          * If quota tracking is neither requested, nor enabled and there are no
83          * pending deletes, no need to mark the quotas out of date.
84          */
85         if (!(qce->flags & (QUOTA_FLAG_TRACKING_ENABLED |
86                         QUOTA_FLAG_TRACKING_REQUESTED |
87                         QUOTA_FLAG_PENDING_DELETES)))
88                 goto set_done;
89         /*
90          * Set the QUOTA_FLAG_OUT_OF_DATE bit thus marking quotas out of date.
91          * This is verified on WinXP to be sufficient to cause windows to
92          * rescan the volume on boot and update all quota entries.
93          */
94         qce->flags |= QUOTA_FLAG_OUT_OF_DATE;
95         /* Ensure the modified flags are written to disk. */
96         ntfs_index_entry_flush_dcache_page(ictx);
97         ntfs_index_entry_mark_dirty(ictx);
98 set_done:
99         ntfs_index_ctx_put(ictx);
100         up(&vol->quota_q_ino->i_sem);
101         /*
102          * We set the flag so we do not try to mark the quotas out of date
103          * again on remount.
104          */
105         NVolSetQuotaOutOfDate(vol);
106 done:
107         ntfs_debug("Done.");
108         return TRUE;
109 err_out:
110         ntfs_index_ctx_put(ictx);
111         up(&vol->quota_q_ino->i_sem);
112         return FALSE;
113 }
114
115 #endif /* NTFS_RW */