1 /* SPDX-License-Identifier: GPL-2.0-or-later */
3 * mft.h - Defines for mft record handling in NTFS Linux kernel driver.
4 * Part of the Linux-NTFS project.
6 * Copyright (c) 2001-2004 Anton Altaparmakov
9 #ifndef _LINUX_NTFS_MFT_H
10 #define _LINUX_NTFS_MFT_H
13 #include <linux/highmem.h>
14 #include <linux/pagemap.h>
18 extern MFT_RECORD *map_mft_record(ntfs_inode *ni);
19 extern void unmap_mft_record(ntfs_inode *ni);
21 extern MFT_RECORD *map_extent_mft_record(ntfs_inode *base_ni, MFT_REF mref,
22 ntfs_inode **ntfs_ino);
24 static inline void unmap_extent_mft_record(ntfs_inode *ni)
33 * flush_dcache_mft_record_page - flush_dcache_page() for mft records
34 * @ni: ntfs inode structure of mft record
36 * Call flush_dcache_page() for the page in which an mft record resides.
38 * This must be called every time an mft record is modified, just after the
41 static inline void flush_dcache_mft_record_page(ntfs_inode *ni)
43 flush_dcache_page(ni->page);
46 extern void __mark_mft_record_dirty(ntfs_inode *ni);
49 * mark_mft_record_dirty - set the mft record and the page containing it dirty
50 * @ni: ntfs inode describing the mapped mft record
52 * Set the mapped (extent) mft record of the (base or extent) ntfs inode @ni,
53 * as well as the page containing the mft record, dirty. Also, mark the base
54 * vfs inode dirty. This ensures that any changes to the mft record are
55 * written out to disk.
57 * NOTE: Do not do anything if the mft record is already marked dirty.
59 static inline void mark_mft_record_dirty(ntfs_inode *ni)
61 if (!NInoTestSetDirty(ni))
62 __mark_mft_record_dirty(ni);
65 extern int ntfs_sync_mft_mirror(ntfs_volume *vol, const unsigned long mft_no,
66 MFT_RECORD *m, int sync);
68 extern int write_mft_record_nolock(ntfs_inode *ni, MFT_RECORD *m, int sync);
71 * write_mft_record - write out a mapped (extent) mft record
72 * @ni: ntfs inode describing the mapped (extent) mft record
73 * @m: mapped (extent) mft record to write
74 * @sync: if true, wait for i/o completion
76 * This is just a wrapper for write_mft_record_nolock() (see mft.c), which
77 * locks the page for the duration of the write. This ensures that there are
78 * no race conditions between writing the mft record via the dirty inode code
79 * paths and via the page cache write back code paths or between writing
80 * neighbouring mft records residing in the same page.
82 * Locking the page also serializes us against ->read_folio() if the page is not
85 * On success, clean the mft record and return 0. On error, leave the mft
86 * record dirty and return -errno.
88 static inline int write_mft_record(ntfs_inode *ni, MFT_RECORD *m, int sync)
90 struct page *page = ni->page;
95 err = write_mft_record_nolock(ni, m, sync);
100 extern bool ntfs_may_write_mft_record(ntfs_volume *vol,
101 const unsigned long mft_no, const MFT_RECORD *m,
102 ntfs_inode **locked_ni);
104 extern ntfs_inode *ntfs_mft_record_alloc(ntfs_volume *vol, const int mode,
105 ntfs_inode *base_ni, MFT_RECORD **mrec);
106 extern int ntfs_extent_mft_record_free(ntfs_inode *ni, MFT_RECORD *m);
110 #endif /* _LINUX_NTFS_MFT_H */