Loading...
1/*
2 * mft.h - Defines for mft record handling in NTFS Linux kernel driver.
3 * Part of the Linux-NTFS project.
4 *
5 * Copyright (c) 2001-2004 Anton Altaparmakov
6 *
7 * This program/include file is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License as published
9 * by the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * This program/include file is distributed in the hope that it will be
13 * useful, but WITHOUT ANY WARRANTY; without even the implied warranty
14 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program (in the main directory of the Linux-NTFS
19 * distribution in the file COPYING); if not, write to the Free Software
20 * Foundation,Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 */
22
23#ifndef _LINUX_NTFS_MFT_H
24#define _LINUX_NTFS_MFT_H
25
26#include <linux/fs.h>
27#include <linux/highmem.h>
28#include <linux/pagemap.h>
29
30#include "inode.h"
31
32extern MFT_RECORD *map_mft_record(ntfs_inode *ni);
33extern void unmap_mft_record(ntfs_inode *ni);
34
35extern MFT_RECORD *map_extent_mft_record(ntfs_inode *base_ni, MFT_REF mref,
36 ntfs_inode **ntfs_ino);
37
38static inline void unmap_extent_mft_record(ntfs_inode *ni)
39{
40 unmap_mft_record(ni);
41 return;
42}
43
44#ifdef NTFS_RW
45
46/**
47 * flush_dcache_mft_record_page - flush_dcache_page() for mft records
48 * @ni: ntfs inode structure of mft record
49 *
50 * Call flush_dcache_page() for the page in which an mft record resides.
51 *
52 * This must be called every time an mft record is modified, just after the
53 * modification.
54 */
55static inline void flush_dcache_mft_record_page(ntfs_inode *ni)
56{
57 flush_dcache_page(ni->page);
58}
59
60extern void __mark_mft_record_dirty(ntfs_inode *ni);
61
62/**
63 * mark_mft_record_dirty - set the mft record and the page containing it dirty
64 * @ni: ntfs inode describing the mapped mft record
65 *
66 * Set the mapped (extent) mft record of the (base or extent) ntfs inode @ni,
67 * as well as the page containing the mft record, dirty. Also, mark the base
68 * vfs inode dirty. This ensures that any changes to the mft record are
69 * written out to disk.
70 *
71 * NOTE: Do not do anything if the mft record is already marked dirty.
72 */
73static inline void mark_mft_record_dirty(ntfs_inode *ni)
74{
75 if (!NInoTestSetDirty(ni))
76 __mark_mft_record_dirty(ni);
77}
78
79extern int ntfs_sync_mft_mirror(ntfs_volume *vol, const unsigned long mft_no,
80 MFT_RECORD *m, int sync);
81
82extern int write_mft_record_nolock(ntfs_inode *ni, MFT_RECORD *m, int sync);
83
84/**
85 * write_mft_record - write out a mapped (extent) mft record
86 * @ni: ntfs inode describing the mapped (extent) mft record
87 * @m: mapped (extent) mft record to write
88 * @sync: if true, wait for i/o completion
89 *
90 * This is just a wrapper for write_mft_record_nolock() (see mft.c), which
91 * locks the page for the duration of the write. This ensures that there are
92 * no race conditions between writing the mft record via the dirty inode code
93 * paths and via the page cache write back code paths or between writing
94 * neighbouring mft records residing in the same page.
95 *
96 * Locking the page also serializes us against ->readpage() if the page is not
97 * uptodate.
98 *
99 * On success, clean the mft record and return 0. On error, leave the mft
100 * record dirty and return -errno.
101 */
102static inline int write_mft_record(ntfs_inode *ni, MFT_RECORD *m, int sync)
103{
104 struct page *page = ni->page;
105 int err;
106
107 BUG_ON(!page);
108 lock_page(page);
109 err = write_mft_record_nolock(ni, m, sync);
110 unlock_page(page);
111 return err;
112}
113
114extern bool ntfs_may_write_mft_record(ntfs_volume *vol,
115 const unsigned long mft_no, const MFT_RECORD *m,
116 ntfs_inode **locked_ni);
117
118extern ntfs_inode *ntfs_mft_record_alloc(ntfs_volume *vol, const int mode,
119 ntfs_inode *base_ni, MFT_RECORD **mrec);
120extern int ntfs_extent_mft_record_free(ntfs_inode *ni, MFT_RECORD *m);
121
122#endif /* NTFS_RW */
123
124#endif /* _LINUX_NTFS_MFT_H */
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(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 ->readpage() 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 */