1/*
2 * ntfs_page.h - Defines for page handling in the NTFS kernel driver.
3 *
4 * Copyright (c) 2006-2008 Anton Altaparmakov.  All Rights Reserved.
5 * Portions Copyright (c) 2006-2008 Apple Inc.  All Rights Reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions are met:
9 *
10 * 1. Redistributions of source code must retain the above copyright notice,
11 *    this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright notice,
13 *    this list of conditions and the following disclaimer in the documentation
14 *    and/or other materials provided with the distribution.
15 * 3. Neither the name of Apple Inc. ("Apple") nor the names of its
16 *    contributors may be used to endorse or promote products derived from this
17 *    software without specific prior written permission.
18 *
19 * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
20 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
21 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22 * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
23 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
24 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
26 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
28 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 *
30 * ALTERNATIVELY, provided that this notice and licensing terms are retained in
31 * full, this file may be redistributed and/or modified under the terms of the
32 * GNU General Public License (GPL) Version 2, in which case the provisions of
33 * that version of the GPL will apply to you instead of the license terms
34 * above.  You can obtain a copy of the GPL Version 2 at
35 * http://developer.apple.com/opensource/licenses/gpl-2.txt.
36 */
37
38#ifndef _OSX_NTFS_PAGE_H
39#define _OSX_NTFS_PAGE_H
40
41#include <sys/errno.h>
42#include <sys/ubc.h>
43
44#include "ntfs_inode.h"
45#include "ntfs_types.h"
46
47__private_extern__ int ntfs_pagein(ntfs_inode *ni, s64 attr_ofs, unsigned size,
48		upl_t upl, upl_offset_t upl_ofs, int flags);
49
50__private_extern__ errno_t ntfs_page_map_ext(ntfs_inode *ni, s64 ofs,
51		upl_t *upl, upl_page_info_array_t *pl, u8 **kaddr,
52		const BOOL uptodate, const BOOL rw);
53
54/**
55 * ntfs_page_map - map a page of a vnode into memory
56 * @ni:		ntfs inode of which to map a page
57 * @ofs:	byte offset into @ni of which to map a page
58 * @upl:	destination page list for the page
59 * @pl:		destination array of pages containing the page itself
60 * @kaddr:	destination pointer for the address of the mapped page contents
61 * @rw:		if true we intend to modify the page and if false we do not
62 *
63 * Map the page corresponding to byte offset @ofs into the ntfs inode @ni into
64 * memory and return the page list in @upl, the array of pages containing the
65 * page in @pl and the address of the mapped page contents in @kaddr.
66 *
67 * The page is returned uptodate.
68 *
69 * The caller must set @rw to true if the page is going to be modified and to
70 * false otherwise.
71 *
72 * Note: @ofs must be page aligned.
73 *
74 * Locking: - Caller must hold an iocount reference on the vnode of @ni.
75 *	    - Caller must hold @ni->lock for reading or writing.
76 */
77static inline errno_t ntfs_page_map(ntfs_inode *ni, s64 ofs, upl_t *upl,
78		upl_page_info_array_t *pl, u8 **kaddr, const BOOL rw)
79{
80	return ntfs_page_map_ext(ni, ofs, upl, pl, kaddr, TRUE, rw);
81}
82
83/**
84 * ntfs_page_grab - map a page of a vnode into memory
85 * @ni:		ntfs inode of which to map a page
86 * @ofs:	byte offset into @ni of which to map a page
87 * @upl:	destination page list for the page
88 * @pl:		destination array of pages containing the page itself
89 * @kaddr:	destination pointer for the address of the mapped page contents
90 * @rw:		if true we intend to modify the page and if false we do not
91 *
92 * Map the page corresponding to byte offset @ofs into the ntfs inode @ni into
93 * memory and return the page list in @upl, the array of pages containing the
94 * page in @pl and the address of the mapped page contents in @kaddr.
95 *
96 * The page is returned in whatever state it is obtained from the VM, i.e. it
97 * may or may not be uptodate.
98 *
99 * The caller must set @rw to true if the page is going to be modified and to
100 * false otherwise.
101 *
102 * Note: @ofs must be page aligned.
103 *
104 * Locking: - Caller must hold an iocount reference on the vnode of @ni.
105 *	    - Caller must hold @ni->lock for reading or writing.
106 */
107static inline errno_t ntfs_page_grab(ntfs_inode *ni, s64 ofs, upl_t *upl,
108		upl_page_info_array_t *pl, u8 **kaddr, const BOOL rw)
109{
110	return ntfs_page_map_ext(ni, ofs, upl, pl, kaddr, FALSE, rw);
111}
112
113__private_extern__ void ntfs_page_unmap(ntfs_inode *ni, upl_t upl,
114		upl_page_info_array_t pl, const BOOL mark_dirty);
115
116__private_extern__ void ntfs_page_dump(ntfs_inode *ni, upl_t upl,
117		upl_page_info_array_t pl);
118
119#endif /* !_OSX_NTFS_PAGE_H */
120