1/* 2 * ntfs_sfm.c - Services For Macintosh (SFM) associated code. 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#include "ntfs_endian.h" 39#include "ntfs_sfm.h" 40#include "ntfs_types.h" 41#include "ntfs_unistr.h" 42#include "ntfs_volume.h" 43 44/* 45 * A zerofilled finder info structure for fast checking of the finder info 46 * being zero. 47 */ 48const FINDER_INFO ntfs_empty_finder_info; 49 50/* 51 * These are the names used for the various named streams used by Services For 52 * Macintosh (SFM) and the OS X SMB implementation and thus also by the OS X 53 * NTFS driver. 54 * 55 * The following names are defined: 56 * 57 * AFP_AfpInfo 58 * AFP_DeskTop 59 * AFP_IdIndex 60 * AFP_Resource 61 * Comments 62 * 63 * See ntfs_sfm.h for further details. 64 */ 65 66ntfschar NTFS_SFM_AFPINFO_NAME[12] = { const_cpu_to_le16('A'), 67 const_cpu_to_le16('F'), const_cpu_to_le16('P'), 68 const_cpu_to_le16('_'), const_cpu_to_le16('A'), 69 const_cpu_to_le16('f'), const_cpu_to_le16('p'), 70 const_cpu_to_le16('I'), const_cpu_to_le16('n'), 71 const_cpu_to_le16('f'), const_cpu_to_le16('o'), 0 }; 72 73ntfschar NTFS_SFM_DESKTOP_NAME[12] = { const_cpu_to_le16('A'), 74 const_cpu_to_le16('F'), const_cpu_to_le16('P'), 75 const_cpu_to_le16('_'), const_cpu_to_le16('D'), 76 const_cpu_to_le16('e'), const_cpu_to_le16('s'), 77 const_cpu_to_le16('k'), const_cpu_to_le16('T'), 78 const_cpu_to_le16('o'), const_cpu_to_le16('p'), 0 }; 79 80ntfschar NTFS_SFM_IDINDEX_NAME[12] = { const_cpu_to_le16('A'), 81 const_cpu_to_le16('F'), const_cpu_to_le16('P'), 82 const_cpu_to_le16('_'), const_cpu_to_le16('I'), 83 const_cpu_to_le16('d'), const_cpu_to_le16('I'), 84 const_cpu_to_le16('n'), const_cpu_to_le16('d'), 85 const_cpu_to_le16('e'), const_cpu_to_le16('x'), 0 }; 86 87ntfschar NTFS_SFM_RESOURCEFORK_NAME[13] = { const_cpu_to_le16('A'), 88 const_cpu_to_le16('F'), const_cpu_to_le16('P'), 89 const_cpu_to_le16('_'), const_cpu_to_le16('R'), 90 const_cpu_to_le16('e'), const_cpu_to_le16('s'), 91 const_cpu_to_le16('o'), const_cpu_to_le16('u'), 92 const_cpu_to_le16('r'), const_cpu_to_le16('c'), 93 const_cpu_to_le16('e'), 0 }; 94 95ntfschar NTFS_SFM_COMMENTS_NAME[9] = { const_cpu_to_le16('C'), 96 const_cpu_to_le16('o'), const_cpu_to_le16('m'), 97 const_cpu_to_le16('m'), const_cpu_to_le16('e'), 98 const_cpu_to_le16('n'), const_cpu_to_le16('t'), 99 const_cpu_to_le16('s'), 0 }; 100 101/** 102 * ntfs_is_sfm_name - check if a name is a protected SFM name 103 * @name: name (in NTFS Unicode) to check 104 * @len: length of name in NTFS Unicode characters to check 105 * 106 * Return true if the NTFS Unicode name @name of length @len characters is a 107 * Services For Macintosh (SFM) protected name and false otherwise. 108 */ 109BOOL ntfs_is_sfm_name(ntfs_volume *vol, 110 const ntfschar *name, const unsigned len) 111{ 112 const ntfschar *upcase = vol->upcase; 113 const unsigned upcase_len = vol->upcase_len; 114 const BOOL case_sensitive = NVolCaseSensitive(vol); 115 116 return (ntfs_are_names_equal(name, len, NTFS_SFM_AFPINFO_NAME, 11, 117 case_sensitive, upcase, upcase_len) || 118 ntfs_are_names_equal(name, len, NTFS_SFM_DESKTOP_NAME, 119 11, case_sensitive, upcase, upcase_len) || 120 ntfs_are_names_equal(name, len, NTFS_SFM_IDINDEX_NAME, 121 11, case_sensitive, upcase, upcase_len) || 122 ntfs_are_names_equal(name, len, 123 NTFS_SFM_RESOURCEFORK_NAME, 12, case_sensitive, upcase, 124 upcase_len) || 125 ntfs_are_names_equal(name, len, NTFS_SFM_COMMENTS_NAME, 126 8, case_sensitive, upcase, upcase_len)); 127} 128