xref: /linux/fs/ntfs/mft.h (revision 43e2fff9f4ec9ff5a9731bf874327eca21259867)
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 
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  */
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_mft_bioset_init(void);
46 void ntfs_mft_bioset_exit(void);
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 folio while preparing the write.  write_mft_record_nolock() waits
57  * for prior folio writeback before modifying the folio and keeps PG_writeback
58  * set until the submitted I/O completes.  Together these serialize dirty
59  * inode writes, page cache writeback, and neighbouring mft record writes in
60  * the same folio.
61  *
62  * Locking the page also serializes us against ->read_folio() if the page is not
63  * uptodate.
64  *
65  * On success, clean the mft record and return 0.  On allocation failure,
66  * redirty the record for retry.  Asynchronous callers return 0 after
67  * redirtying, while synchronous callers receive -ENOMEM.  On other errors,
68  * return -errno and mark the volume with errors.
69  */
70 static inline int write_mft_record(struct ntfs_inode *ni, struct mft_record *m, int sync)
71 {
72 	struct folio *folio = ni->folio;
73 	int err;
74 
75 	folio_lock(folio);
76 	err = write_mft_record_nolock(ni, m, sync);
77 	folio_unlock(folio);
78 
79 	return err;
80 }
81 
82 int ntfs_mft_record_alloc(struct ntfs_volume *vol, const int mode,
83 		struct ntfs_inode **ni, struct ntfs_inode *base_ni,
84 		struct mft_record **ni_mrec, const s64 mft_data_vcn);
85 int ntfs_mft_record_free(struct ntfs_volume *vol, struct ntfs_inode *ni);
86 int ntfs_mft_records_write(const struct ntfs_volume *vol, const u64 mref,
87 		const s64 count, struct mft_record *b);
88 int ntfs_mft_record_check(const struct ntfs_volume *vol, struct mft_record *m,
89 			  u64 mft_no);
90 int ntfs_mft_writepages(struct address_space *mapping,
91 		struct writeback_control *wbc);
92 void ntfs_mft_mark_dirty(struct folio *folio);
93 
94 #endif /* _LINUX_NTFS_MFT_H */
95