mft.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. /*
  2. * mft.h - Defines for mft record handling in NTFS Linux kernel driver.
  3. * Part of the Linux-NTFS project.
  4. *
  5. * Copyright (c) 2001-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. #ifndef _LINUX_NTFS_MFT_H
  23. #define _LINUX_NTFS_MFT_H
  24. #include <linux/fs.h>
  25. #include <linux/highmem.h>
  26. #include <linux/pagemap.h>
  27. #include "inode.h"
  28. extern MFT_RECORD *map_mft_record(ntfs_inode *ni);
  29. extern void unmap_mft_record(ntfs_inode *ni);
  30. extern MFT_RECORD *map_extent_mft_record(ntfs_inode *base_ni, MFT_REF mref,
  31. ntfs_inode **ntfs_ino);
  32. static inline void unmap_extent_mft_record(ntfs_inode *ni)
  33. {
  34. unmap_mft_record(ni);
  35. return;
  36. }
  37. #ifdef NTFS_RW
  38. /**
  39. * flush_dcache_mft_record_page - flush_dcache_page() for mft records
  40. * @ni: ntfs inode structure of mft record
  41. *
  42. * Call flush_dcache_page() for the page in which an mft record resides.
  43. *
  44. * This must be called every time an mft record is modified, just after the
  45. * modification.
  46. */
  47. static inline void flush_dcache_mft_record_page(ntfs_inode *ni)
  48. {
  49. flush_dcache_page(ni->page);
  50. }
  51. extern void __mark_mft_record_dirty(ntfs_inode *ni);
  52. /**
  53. * mark_mft_record_dirty - set the mft record and the page containing it dirty
  54. * @ni: ntfs inode describing the mapped mft record
  55. *
  56. * Set the mapped (extent) mft record of the (base or extent) ntfs inode @ni,
  57. * as well as the page containing the mft record, dirty. Also, mark the base
  58. * vfs inode dirty. This ensures that any changes to the mft record are
  59. * written out to disk.
  60. *
  61. * NOTE: Do not do anything if the mft record is already marked dirty.
  62. */
  63. static inline void mark_mft_record_dirty(ntfs_inode *ni)
  64. {
  65. if (!NInoTestSetDirty(ni))
  66. __mark_mft_record_dirty(ni);
  67. }
  68. extern int ntfs_sync_mft_mirror(ntfs_volume *vol, const unsigned long mft_no,
  69. MFT_RECORD *m, int sync);
  70. extern int write_mft_record_nolock(ntfs_inode *ni, MFT_RECORD *m, int sync);
  71. /**
  72. * write_mft_record - write out a mapped (extent) mft record
  73. * @ni: ntfs inode describing the mapped (extent) mft record
  74. * @m: mapped (extent) mft record to write
  75. * @sync: if true, wait for i/o completion
  76. *
  77. * This is just a wrapper for write_mft_record_nolock() (see mft.c), which
  78. * locks the page for the duration of the write. This ensures that there are
  79. * no race conditions between writing the mft record via the dirty inode code
  80. * paths and via the page cache write back code paths or between writing
  81. * neighbouring mft records residing in the same page.
  82. *
  83. * Locking the page also serializes us against ->readpage() if the page is not
  84. * uptodate.
  85. *
  86. * On success, clean the mft record and return 0. On error, leave the mft
  87. * record dirty and return -errno.
  88. */
  89. static inline int write_mft_record(ntfs_inode *ni, MFT_RECORD *m, int sync)
  90. {
  91. struct page *page = ni->page;
  92. int err;
  93. BUG_ON(!page);
  94. lock_page(page);
  95. err = write_mft_record_nolock(ni, m, sync);
  96. unlock_page(page);
  97. return err;
  98. }
  99. extern bool ntfs_may_write_mft_record(ntfs_volume *vol,
  100. const unsigned long mft_no, const MFT_RECORD *m,
  101. ntfs_inode **locked_ni);
  102. extern ntfs_inode *ntfs_mft_record_alloc(ntfs_volume *vol, const int mode,
  103. ntfs_inode *base_ni, MFT_RECORD **mrec);
  104. extern int ntfs_extent_mft_record_free(ntfs_inode *ni, MFT_RECORD *m);
  105. #endif /* NTFS_RW */
  106. #endif /* _LINUX_NTFS_MFT_H */