mft.h 3.2 KB

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