quota.c 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  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. #ifdef NTFS_RW
  23. #include "index.h"
  24. #include "quota.h"
  25. #include "debug.h"
  26. #include "ntfs.h"
  27. /**
  28. * ntfs_mark_quotas_out_of_date - mark the quotas out of date on an ntfs volume
  29. * @vol: ntfs volume on which to mark the quotas out of date
  30. *
  31. * Mark the quotas out of date on the ntfs volume @vol and return 'true' on
  32. * success and 'false' on error.
  33. */
  34. bool ntfs_mark_quotas_out_of_date(ntfs_volume *vol)
  35. {
  36. ntfs_index_context *ictx;
  37. QUOTA_CONTROL_ENTRY *qce;
  38. const le32 qid = QUOTA_DEFAULTS_ID;
  39. int err;
  40. ntfs_debug("Entering.");
  41. if (NVolQuotaOutOfDate(vol))
  42. goto done;
  43. if (!vol->quota_ino || !vol->quota_q_ino) {
  44. ntfs_error(vol->sb, "Quota inodes are not open.");
  45. return false;
  46. }
  47. mutex_lock(&vol->quota_q_ino->i_mutex);
  48. ictx = ntfs_index_ctx_get(NTFS_I(vol->quota_q_ino));
  49. if (!ictx) {
  50. ntfs_error(vol->sb, "Failed to get index context.");
  51. goto err_out;
  52. }
  53. err = ntfs_index_lookup(&qid, sizeof(qid), ictx);
  54. if (err) {
  55. if (err == -ENOENT)
  56. ntfs_error(vol->sb, "Quota defaults entry is not "
  57. "present.");
  58. else
  59. ntfs_error(vol->sb, "Lookup of quota defaults entry "
  60. "failed.");
  61. goto err_out;
  62. }
  63. if (ictx->data_len < offsetof(QUOTA_CONTROL_ENTRY, sid)) {
  64. ntfs_error(vol->sb, "Quota defaults entry size is invalid. "
  65. "Run chkdsk.");
  66. goto err_out;
  67. }
  68. qce = (QUOTA_CONTROL_ENTRY*)ictx->data;
  69. if (le32_to_cpu(qce->version) != QUOTA_VERSION) {
  70. ntfs_error(vol->sb, "Quota defaults entry version 0x%x is not "
  71. "supported.", le32_to_cpu(qce->version));
  72. goto err_out;
  73. }
  74. ntfs_debug("Quota defaults flags = 0x%x.", le32_to_cpu(qce->flags));
  75. /* If quotas are already marked out of date, no need to do anything. */
  76. if (qce->flags & QUOTA_FLAG_OUT_OF_DATE)
  77. goto set_done;
  78. /*
  79. * If quota tracking is neither requested, nor enabled and there are no
  80. * pending deletes, no need to mark the quotas out of date.
  81. */
  82. if (!(qce->flags & (QUOTA_FLAG_TRACKING_ENABLED |
  83. QUOTA_FLAG_TRACKING_REQUESTED |
  84. QUOTA_FLAG_PENDING_DELETES)))
  85. goto set_done;
  86. /*
  87. * Set the QUOTA_FLAG_OUT_OF_DATE bit thus marking quotas out of date.
  88. * This is verified on WinXP to be sufficient to cause windows to
  89. * rescan the volume on boot and update all quota entries.
  90. */
  91. qce->flags |= QUOTA_FLAG_OUT_OF_DATE;
  92. /* Ensure the modified flags are written to disk. */
  93. ntfs_index_entry_flush_dcache_page(ictx);
  94. ntfs_index_entry_mark_dirty(ictx);
  95. set_done:
  96. ntfs_index_ctx_put(ictx);
  97. mutex_unlock(&vol->quota_q_ino->i_mutex);
  98. /*
  99. * We set the flag so we do not try to mark the quotas out of date
  100. * again on remount.
  101. */
  102. NVolSetQuotaOutOfDate(vol);
  103. done:
  104. ntfs_debug("Done.");
  105. return true;
  106. err_out:
  107. if (ictx)
  108. ntfs_index_ctx_put(ictx);
  109. mutex_unlock(&vol->quota_q_ino->i_mutex);
  110. return false;
  111. }
  112. #endif /* NTFS_RW */