Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0-or-later */
0002 /*
0003  * mft.h - Defines for mft record handling in NTFS Linux kernel driver.
0004  *     Part of the Linux-NTFS project.
0005  *
0006  * Copyright (c) 2001-2004 Anton Altaparmakov
0007  */
0008 
0009 #ifndef _LINUX_NTFS_MFT_H
0010 #define _LINUX_NTFS_MFT_H
0011 
0012 #include <linux/fs.h>
0013 #include <linux/highmem.h>
0014 #include <linux/pagemap.h>
0015 
0016 #include "inode.h"
0017 
0018 extern MFT_RECORD *map_mft_record(ntfs_inode *ni);
0019 extern void unmap_mft_record(ntfs_inode *ni);
0020 
0021 extern MFT_RECORD *map_extent_mft_record(ntfs_inode *base_ni, MFT_REF mref,
0022         ntfs_inode **ntfs_ino);
0023 
0024 static inline void unmap_extent_mft_record(ntfs_inode *ni)
0025 {
0026     unmap_mft_record(ni);
0027     return;
0028 }
0029 
0030 #ifdef NTFS_RW
0031 
0032 /**
0033  * flush_dcache_mft_record_page - flush_dcache_page() for mft records
0034  * @ni:     ntfs inode structure of mft record
0035  *
0036  * Call flush_dcache_page() for the page in which an mft record resides.
0037  *
0038  * This must be called every time an mft record is modified, just after the
0039  * modification.
0040  */
0041 static inline void flush_dcache_mft_record_page(ntfs_inode *ni)
0042 {
0043     flush_dcache_page(ni->page);
0044 }
0045 
0046 extern void __mark_mft_record_dirty(ntfs_inode *ni);
0047 
0048 /**
0049  * mark_mft_record_dirty - set the mft record and the page containing it dirty
0050  * @ni:     ntfs inode describing the mapped mft record
0051  *
0052  * Set the mapped (extent) mft record of the (base or extent) ntfs inode @ni,
0053  * as well as the page containing the mft record, dirty.  Also, mark the base
0054  * vfs inode dirty.  This ensures that any changes to the mft record are
0055  * written out to disk.
0056  *
0057  * NOTE:  Do not do anything if the mft record is already marked dirty.
0058  */
0059 static inline void mark_mft_record_dirty(ntfs_inode *ni)
0060 {
0061     if (!NInoTestSetDirty(ni))
0062         __mark_mft_record_dirty(ni);
0063 }
0064 
0065 extern int ntfs_sync_mft_mirror(ntfs_volume *vol, const unsigned long mft_no,
0066         MFT_RECORD *m, int sync);
0067 
0068 extern int write_mft_record_nolock(ntfs_inode *ni, MFT_RECORD *m, int sync);
0069 
0070 /**
0071  * write_mft_record - write out a mapped (extent) mft record
0072  * @ni:     ntfs inode describing the mapped (extent) mft record
0073  * @m:      mapped (extent) mft record to write
0074  * @sync:   if true, wait for i/o completion
0075  *
0076  * This is just a wrapper for write_mft_record_nolock() (see mft.c), which
0077  * locks the page for the duration of the write.  This ensures that there are
0078  * no race conditions between writing the mft record via the dirty inode code
0079  * paths and via the page cache write back code paths or between writing
0080  * neighbouring mft records residing in the same page.
0081  *
0082  * Locking the page also serializes us against ->read_folio() if the page is not
0083  * uptodate.
0084  *
0085  * On success, clean the mft record and return 0.  On error, leave the mft
0086  * record dirty and return -errno.
0087  */
0088 static inline int write_mft_record(ntfs_inode *ni, MFT_RECORD *m, int sync)
0089 {
0090     struct page *page = ni->page;
0091     int err;
0092 
0093     BUG_ON(!page);
0094     lock_page(page);
0095     err = write_mft_record_nolock(ni, m, sync);
0096     unlock_page(page);
0097     return err;
0098 }
0099 
0100 extern bool ntfs_may_write_mft_record(ntfs_volume *vol,
0101         const unsigned long mft_no, const MFT_RECORD *m,
0102         ntfs_inode **locked_ni);
0103 
0104 extern ntfs_inode *ntfs_mft_record_alloc(ntfs_volume *vol, const int mode,
0105         ntfs_inode *base_ni, MFT_RECORD **mrec);
0106 extern int ntfs_extent_mft_record_free(ntfs_inode *ni, MFT_RECORD *m);
0107 
0108 #endif /* NTFS_RW */
0109 
0110 #endif /* _LINUX_NTFS_MFT_H */