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
9#ifndef _LINUX_NTFS_MFT_H
10#define _LINUX_NTFS_MFT_H
11
12#include <linux/fs.h>
13#include <linux/highmem.h>
14#include <linux/pagemap.h>
15
16#include "inode.h"
17
18extern MFT_RECORD *map_mft_record(ntfs_inode *ni);
19extern void unmap_mft_record(ntfs_inode *ni);
20
21extern MFT_RECORD *map_extent_mft_record(ntfs_inode *base_ni, MFT_REF mref,
22 ntfs_inode **ntfs_ino);
23
24static inline void unmap_extent_mft_record(ntfs_inode *ni)
25{
26 unmap_mft_record(ni);
27 return;
28}
29
30#ifdef NTFS_RW
31
32/**
33 * flush_dcache_mft_record_page - flush_dcache_page() for mft records
34 * @ni: ntfs inode structure of mft record
35 *
36 * Call flush_dcache_page() for the page in which an mft record resides.
37 *
38 * This must be called every time an mft record is modified, just after the
39 * modification.
40 */
41static inline void flush_dcache_mft_record_page(ntfs_inode *ni)
42{
43 flush_dcache_page(page: ni->page);
44}
45
46extern void __mark_mft_record_dirty(ntfs_inode *ni);
47
48/**
49 * mark_mft_record_dirty - set the mft record and the page containing it dirty
50 * @ni: ntfs inode describing the mapped mft record
51 *
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.
56 *
57 * NOTE: Do not do anything if the mft record is already marked dirty.
58 */
59static inline void mark_mft_record_dirty(ntfs_inode *ni)
60{
61 if (!NInoTestSetDirty(ni))
62 __mark_mft_record_dirty(ni);
63}
64
65extern int ntfs_sync_mft_mirror(ntfs_volume *vol, const unsigned long mft_no,
66 MFT_RECORD *m, int sync);
67
68extern int write_mft_record_nolock(ntfs_inode *ni, MFT_RECORD *m, int sync);
69
70/**
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
75 *
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.
81 *
82 * Locking the page also serializes us against ->read_folio() if the page is not
83 * uptodate.
84 *
85 * On success, clean the mft record and return 0. On error, leave the mft
86 * record dirty and return -errno.
87 */
88static inline int write_mft_record(ntfs_inode *ni, MFT_RECORD *m, int sync)
89{
90 struct page *page = ni->page;
91 int err;
92
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
100extern bool ntfs_may_write_mft_record(ntfs_volume *vol,
101 const unsigned long mft_no, const MFT_RECORD *m,
102 ntfs_inode **locked_ni);
103
104extern ntfs_inode *ntfs_mft_record_alloc(ntfs_volume *vol, const int mode,
105 ntfs_inode *base_ni, MFT_RECORD **mrec);
106extern int ntfs_extent_mft_record_free(ntfs_inode *ni, MFT_RECORD *m);
107
108#endif /* NTFS_RW */
109
110#endif /* _LINUX_NTFS_MFT_H */
111

source code of linux/fs/ntfs/mft.h