1/* 2 * ntfs_attr_list.h - Defines for attribute list attribute handling in the NTFS 3 * kernel driver. 4 * 5 * Copyright (c) 2006-2008 Anton Altaparmakov. All Rights Reserved. 6 * Portions Copyright (c) 2006-2008 Apple Inc. All Rights Reserved. 7 * 8 * Redistribution and use in source and binary forms, with or without 9 * modification, are permitted provided that the following conditions are met: 10 * 11 * 1. Redistributions of source code must retain the above copyright notice, 12 * this list of conditions and the following disclaimer. 13 * 2. Redistributions in binary form must reproduce the above copyright notice, 14 * this list of conditions and the following disclaimer in the documentation 15 * and/or other materials provided with the distribution. 16 * 3. Neither the name of Apple Inc. ("Apple") nor the names of its 17 * contributors may be used to endorse or promote products derived from this 18 * software without specific prior written permission. 19 * 20 * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY 21 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 22 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 23 * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY 24 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 25 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 26 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 27 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 29 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 * 31 * ALTERNATIVELY, provided that this notice and licensing terms are retained in 32 * full, this file may be redistributed and/or modified under the terms of the 33 * GNU General Public License (GPL) Version 2, in which case the provisions of 34 * that version of the GPL will apply to you instead of the license terms 35 * above. You can obtain a copy of the GPL Version 2 at 36 * http://developer.apple.com/opensource/licenses/gpl-2.txt. 37 */ 38 39#ifndef _OSX_NTFS_ATTR_LIST_H 40#define _OSX_NTFS_ATTR_LIST_H 41 42#include <sys/errno.h> 43 44#include "ntfs_attr.h" 45#include "ntfs_endian.h" 46#include "ntfs_inode.h" 47#include "ntfs_layout.h" 48#include "ntfs_types.h" 49 50__private_extern__ errno_t ntfs_attr_list_is_needed(ntfs_inode *ni, 51 ATTR_LIST_ENTRY *skip_entry, BOOL *attr_list_is_needed); 52 53__private_extern__ errno_t ntfs_attr_list_delete(ntfs_inode *ni, 54 ntfs_attr_search_ctx *ctx); 55 56__private_extern__ errno_t ntfs_attr_list_add(ntfs_inode *ni, MFT_RECORD *m, 57 ntfs_attr_search_ctx *ctx); 58 59__private_extern__ errno_t ntfs_attr_list_sync_shrink(ntfs_inode *ni, 60 const unsigned start_ofs, ntfs_attr_search_ctx *ctx); 61 62__private_extern__ errno_t ntfs_attr_list_sync_extend(ntfs_inode *base_ni, 63 MFT_RECORD *base_m, unsigned al_ofs, 64 ntfs_attr_search_ctx *ctx); 65 66/** 67 * ntfs_attr_list_sync - update the attribute list content of an ntfs inode 68 * @ni: base ntfs inode whose attribute list attribugte to update 69 * @start_ofs: byte offset into attribute list attribute from which to write 70 * @ctx: initialized attribute search context 71 * 72 * Write the attribute list attribute value cached in @ni starting at byte 73 * offset @start_ofs into it to the attribute list attribute record (if the 74 * attribute list attribute is resident) or to disk as specified by the runlist 75 * of the attribute list attribute. 76 * 77 * This function only works when the attribute list content but not its size 78 * has changed. 79 * 80 * @ctx is an initialized, ready to use attribute search context that we use to 81 * look up the attribute list attribute in the mapped, base mft record. 82 * 83 * Return 0 on success and -errno on error. 84 */ 85static inline int ntfs_attr_list_sync(ntfs_inode *ni, const unsigned start_ofs, 86 ntfs_attr_search_ctx *ctx) 87{ 88 return ntfs_attr_list_sync_shrink(ni, start_ofs, ctx); 89} 90 91__private_extern__ void ntfs_attr_list_entries_delete(ntfs_inode *ni, 92 ATTR_LIST_ENTRY *start_entry, ATTR_LIST_ENTRY *end_entry); 93 94/** 95 * ntfs_attr_list_entry_delete - delete an attribute list entry 96 * @ni: base ntfs inode whose attribute list to delete from 97 * @target_entry: attribute list entry to be deleted 98 * 99 * Delete the attribute list attribute entry @target_entry from the attribute 100 * list attribute belonging to the base ntfs inode @ni. 101 * 102 * This function cannot fail. 103 */ 104static inline void ntfs_attr_list_entry_delete(ntfs_inode *ni, 105 ATTR_LIST_ENTRY *target_entry) 106{ 107 ntfs_attr_list_entries_delete(ni, target_entry, 108 (ATTR_LIST_ENTRY*)((u8*)target_entry + 109 le16_to_cpu(target_entry->length))); 110} 111 112#endif /* !_OSX_NTFS_ATTR_LIST_H */ 113