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