1/* 2 * ntfs_mft.h - Defines for mft record 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_MFT_H 39#define _OSX_NTFS_MFT_H 40 41#include <sys/errno.h> 42 43#include "ntfs_inode.h" 44#include "ntfs_layout.h" 45#include "ntfs_types.h" 46#include "ntfs_volume.h" 47 48__private_extern__ errno_t ntfs_mft_record_map_ext(ntfs_inode *ni, 49 MFT_RECORD **m, const BOOL mft_is_locked); 50 51/** 52 * ntfs_mft_record_map - map and lock an mft record 53 * @ni: ntfs inode whose mft record to map 54 * @m: destination pointer for the mapped mft record 55 * 56 * The buffer containing the mft record belonging to the ntfs inode @ni is 57 * mapped which on OS X means it is held for exclusive via the BL_BUSY flag in 58 * the buffer. The mapped mft record is returned in *@m. 59 * 60 * Return 0 on success and errno on error. 61 * 62 * Note: Caller must hold an iocount reference on the vnode of the base inode 63 * of @ni. 64 */ 65static inline errno_t ntfs_mft_record_map(ntfs_inode *ni, MFT_RECORD **m) 66{ 67 return ntfs_mft_record_map_ext(ni, m, FALSE); 68} 69 70__private_extern__ void ntfs_mft_record_unmap(ntfs_inode *ni); 71 72__private_extern__ errno_t ntfs_extent_mft_record_map_ext(ntfs_inode *base_ni, 73 MFT_REF mref, ntfs_inode **nni, MFT_RECORD **nm, 74 const BOOL mft_is_locked); 75 76/** 77 * ntfs_extent_mft_record_map - load an extent inode and attach it to its base 78 * @base_ni: base ntfs inode 79 * @mref: mft reference of the extent inode to load 80 * @ext_ni: on successful return, pointer to the ntfs inode structure 81 * @ext_mrec: on successful return, pointer to the mft record structure 82 * 83 * Load the extent mft record @mref and attach it to its base inode @base_ni. 84 * Return the mapped extent mft record if success. 85 * 86 * On successful return, @ext_ni contains a pointer to the ntfs inode structure 87 * of the mapped extent inode and @ext_mrec contains a pointer to the mft 88 * record structure of the mapped extent inode. 89 * 90 * Note: The caller must hold an iocount reference on the vnode of the base 91 * inode. 92 */ 93static inline errno_t ntfs_extent_mft_record_map(ntfs_inode *base_ni, 94 MFT_REF mref, ntfs_inode **ext_ni, MFT_RECORD **ext_mrec) 95{ 96 return ntfs_extent_mft_record_map_ext(base_ni, mref, ext_ni, ext_mrec, 97 FALSE); 98} 99 100static inline void ntfs_extent_mft_record_unmap(ntfs_inode *ni) 101{ 102 ntfs_mft_record_unmap(ni); 103} 104 105__private_extern__ errno_t ntfs_mft_record_sync(ntfs_inode *ni); 106 107__private_extern__ errno_t ntfs_mft_mirror_sync(ntfs_volume *vol, 108 const s64 rec_no, const MFT_RECORD *m, const BOOL sync); 109 110__private_extern__ errno_t ntfs_mft_record_alloc(ntfs_volume *vol, 111 struct vnode_attr *va, struct componentname *cn, 112 ntfs_inode *base_ni, ntfs_inode **new_ni, MFT_RECORD **new_m, 113 ATTR_RECORD **new_a); 114 115__private_extern__ errno_t ntfs_extent_mft_record_free(ntfs_inode *base_ni, 116 ntfs_inode *ni, MFT_RECORD *m); 117 118#endif /* !_OSX_NTFS_MFT_H */ 119