1a1d312deSThomas Gleixner /* SPDX-License-Identifier: GPL-2.0-or-later */
2*aa0b42b7SRandy Dunlap /*
31da177e4SLinus Torvalds * aops.h - Defines for NTFS kernel address space operations and page cache
41da177e4SLinus Torvalds * handling. Part of the Linux-NTFS project.
51da177e4SLinus Torvalds *
61da177e4SLinus Torvalds * Copyright (c) 2001-2004 Anton Altaparmakov
71da177e4SLinus Torvalds * Copyright (c) 2002 Richard Russon
81da177e4SLinus Torvalds */
91da177e4SLinus Torvalds
101da177e4SLinus Torvalds #ifndef _LINUX_NTFS_AOPS_H
111da177e4SLinus Torvalds #define _LINUX_NTFS_AOPS_H
121da177e4SLinus Torvalds
131da177e4SLinus Torvalds #include <linux/mm.h>
141da177e4SLinus Torvalds #include <linux/highmem.h>
151da177e4SLinus Torvalds #include <linux/pagemap.h>
161da177e4SLinus Torvalds #include <linux/fs.h>
171da177e4SLinus Torvalds
181da177e4SLinus Torvalds #include "inode.h"
191da177e4SLinus Torvalds
201da177e4SLinus Torvalds /**
211da177e4SLinus Torvalds * ntfs_unmap_page - release a page that was mapped using ntfs_map_page()
221da177e4SLinus Torvalds * @page: the page to release
231da177e4SLinus Torvalds *
241da177e4SLinus Torvalds * Unpin, unmap and release a page that was obtained from ntfs_map_page().
251da177e4SLinus Torvalds */
ntfs_unmap_page(struct page * page)261da177e4SLinus Torvalds static inline void ntfs_unmap_page(struct page *page)
271da177e4SLinus Torvalds {
281da177e4SLinus Torvalds kunmap(page);
2909cbfeafSKirill A. Shutemov put_page(page);
301da177e4SLinus Torvalds }
311da177e4SLinus Torvalds
321da177e4SLinus Torvalds /**
331da177e4SLinus Torvalds * ntfs_map_page - map a page into accessible memory, reading it if necessary
341da177e4SLinus Torvalds * @mapping: address space for which to obtain the page
351da177e4SLinus Torvalds * @index: index into the page cache for @mapping of the page to map
361da177e4SLinus Torvalds *
371da177e4SLinus Torvalds * Read a page from the page cache of the address space @mapping at position
38ea1754a0SKirill A. Shutemov * @index, where @index is in units of PAGE_SIZE, and not in bytes.
391da177e4SLinus Torvalds *
40933906f8SMatthew Wilcox (Oracle) * If the page is not in memory it is loaded from disk first using the
41933906f8SMatthew Wilcox (Oracle) * read_folio method defined in the address space operations of @mapping
42933906f8SMatthew Wilcox (Oracle) * and the page is added to the page cache of @mapping in the process.
431da177e4SLinus Torvalds *
441da177e4SLinus Torvalds * If the page belongs to an mst protected attribute and it is marked as such
451da177e4SLinus Torvalds * in its ntfs inode (NInoMstProtected()) the mst fixups are applied but no
461da177e4SLinus Torvalds * error checking is performed. This means the caller has to verify whether
471da177e4SLinus Torvalds * the ntfs record(s) contained in the page are valid or not using one of the
481da177e4SLinus Torvalds * ntfs_is_XXXX_record{,p}() macros, where XXXX is the record type you are
491da177e4SLinus Torvalds * expecting to see. (For details of the macros, see fs/ntfs/layout.h.)
501da177e4SLinus Torvalds *
511da177e4SLinus Torvalds * If the page is in high memory it is mapped into memory directly addressible
521da177e4SLinus Torvalds * by the kernel.
531da177e4SLinus Torvalds *
541da177e4SLinus Torvalds * Finally the page count is incremented, thus pinning the page into place.
551da177e4SLinus Torvalds *
561da177e4SLinus Torvalds * The above means that page_address(page) can be used on all pages obtained
571da177e4SLinus Torvalds * with ntfs_map_page() to get the kernel virtual address of the page.
581da177e4SLinus Torvalds *
591da177e4SLinus Torvalds * When finished with the page, the caller has to call ntfs_unmap_page() to
601da177e4SLinus Torvalds * unpin, unmap and release the page.
611da177e4SLinus Torvalds *
621da177e4SLinus Torvalds * Note this does not grant exclusive access. If such is desired, the caller
631da177e4SLinus Torvalds * must provide it independently of the ntfs_{un}map_page() calls by using
641da177e4SLinus Torvalds * a {rw_}semaphore or other means of serialization. A spin lock cannot be
651da177e4SLinus Torvalds * used as ntfs_map_page() can block.
661da177e4SLinus Torvalds *
671da177e4SLinus Torvalds * The unlocked and uptodate page is returned on success or an encoded error
681da177e4SLinus Torvalds * on failure. Caller has to test for error using the IS_ERR() macro on the
69c49c3111SRichard Knutsson * return value. If that evaluates to 'true', the negative error code can be
701da177e4SLinus Torvalds * obtained using PTR_ERR() on the return value of ntfs_map_page().
711da177e4SLinus Torvalds */
ntfs_map_page(struct address_space * mapping,unsigned long index)721da177e4SLinus Torvalds static inline struct page *ntfs_map_page(struct address_space *mapping,
731da177e4SLinus Torvalds unsigned long index)
741da177e4SLinus Torvalds {
75090d2b18SPekka Enberg struct page *page = read_mapping_page(mapping, index, NULL);
761da177e4SLinus Torvalds
7762a3a4ddSMatthew Wilcox (Oracle) if (!IS_ERR(page))
781da177e4SLinus Torvalds kmap(page);
791da177e4SLinus Torvalds return page;
801da177e4SLinus Torvalds }
811da177e4SLinus Torvalds
821da177e4SLinus Torvalds #ifdef NTFS_RW
831da177e4SLinus Torvalds
841da177e4SLinus Torvalds extern void mark_ntfs_record_dirty(struct page *page, const unsigned int ofs);
851da177e4SLinus Torvalds
861da177e4SLinus Torvalds #endif /* NTFS_RW */
871da177e4SLinus Torvalds
881da177e4SLinus Torvalds #endif /* _LINUX_NTFS_AOPS_H */
89