1/* 2 * Copyright (c) 2000-2008, 2010-2012 Apple Inc. All rights reserved. 3 * 4 * @APPLE_LICENSE_HEADER_START@ 5 * 6 * This file contains Original Code and/or Modifications of Original Code 7 * as defined in and that are subject to the Apple Public Source License 8 * Version 2.0 (the 'License'). You may not use this file except in 9 * compliance with the License. Please obtain a copy of the License at 10 * http://www.opensource.apple.com/apsl/ and read it before using this 11 * file. 12 * 13 * The Original Code and all software distributed under the License are 14 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER 15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, 16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, 17 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. 18 * Please see the License for the specific language governing rights and 19 * limitations under the License. 20 * 21 * @APPLE_LICENSE_HEADER_END@ 22 */ 23/* $FreeBSD: src/sys/msdosfs/direntry.h,v 1.15 1999/12/29 04:54:52 peter Exp $ */ 24/* $NetBSD: direntry.h,v 1.14 1997/11/17 15:36:32 ws Exp $ */ 25 26/*- 27 * Copyright (C) 1994, 1995, 1997 Wolfgang Solfrank. 28 * Copyright (C) 1994, 1995, 1997 TooLs GmbH. 29 * All rights reserved. 30 * Original code by Paul Popelka (paulp@uts.amdahl.com) (see below). 31 * 32 * Redistribution and use in source and binary forms, with or without 33 * modification, are permitted provided that the following conditions 34 * are met: 35 * 1. Redistributions of source code must retain the above copyright 36 * notice, this list of conditions and the following disclaimer. 37 * 2. Redistributions in binary form must reproduce the above copyright 38 * notice, this list of conditions and the following disclaimer in the 39 * documentation and/or other materials provided with the distribution. 40 * 3. All advertising materials mentioning features or use of this software 41 * must display the following acknowledgement: 42 * This product includes software developed by TooLs GmbH. 43 * 4. The name of TooLs GmbH may not be used to endorse or promote products 44 * derived from this software without specific prior written permission. 45 * 46 * THIS SOFTWARE IS PROVIDED BY TOOLS GMBH ``AS IS'' AND ANY EXPRESS OR 47 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 48 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 49 * IN NO EVENT SHALL TOOLS GMBH BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 50 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 51 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 52 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 53 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 54 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 55 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 56 */ 57/* 58 * Written by Paul Popelka (paulp@uts.amdahl.com) 59 * 60 * You can do anything you want with this software, just don't say you wrote 61 * it, and don't remove this notice. 62 * 63 * This software is provided "as is". 64 * 65 * The author supplies this software to be publicly redistributed on the 66 * understanding that the author is not responsible for the correct 67 * functioning of this software in any circumstances and is not liable for 68 * any damages caused by this software. 69 * 70 * October 1992 71 */ 72 73/* 74 * Structure of a dos directory entry. 75 */ 76struct dosdirentry { 77 u_int8_t deName[8]; /* filename, blank filled */ 78#define SLOT_EMPTY 0x00 /* slot has never been used */ 79#define SLOT_E5 0x05 /* the real value is 0xe5 */ 80#define SLOT_DELETED 0xe5 /* file in this slot deleted */ 81 u_int8_t deExtension[3]; /* extension, blank filled */ 82 u_int8_t deAttributes; /* file attributes */ 83#define ATTR_NORMAL 0x00 /* normal file */ 84#define ATTR_READONLY 0x01 /* file is read-only (immutable) */ 85#define ATTR_HIDDEN 0x02 /* file is hidden */ 86#define ATTR_SYSTEM 0x04 /* file is a system file */ 87#define ATTR_VOLUME 0x08 /* entry is a volume label */ 88#define ATTR_DIRECTORY 0x10 /* entry is a directory name */ 89#define ATTR_ARCHIVE 0x20 /* file is new or modified */ 90 u_int8_t deLowerCase; /* NT VFAT lower case flags */ 91#define LCASE_BASE 0x08 /* filename base in lower case */ 92#define LCASE_EXT 0x10 /* filename extension in lower case */ 93 u_int8_t deCHundredth; /* hundredth of seconds in CTime */ 94 u_int8_t deCTime[2]; /* create time */ 95 u_int8_t deCDate[2]; /* create date */ 96 u_int8_t deADate[2]; /* access date */ 97 u_int8_t deHighClust[2]; /* high bytes of cluster number */ 98 u_int8_t deMTime[2]; /* last update time */ 99 u_int8_t deMDate[2]; /* last update date */ 100 u_int8_t deStartCluster[2]; /* starting cluster of file */ 101 u_int8_t deFileSize[4]; /* size of file in bytes */ 102}; 103 104/* 105 * Structure of a Win95 long name directory entry 106 */ 107struct winentry { 108 u_int8_t weCnt; 109#define WIN_LAST 0x40 110#define WIN_CNT 0x3f 111 u_int8_t wePart1[10]; 112 u_int8_t weAttributes; 113#define ATTR_WIN95 0x0f 114#define ATTR_WIN95_MASK 0x3f 115 u_int8_t weReserved1; 116 u_int8_t weChksum; 117 u_int8_t wePart2[12]; 118 u_int16_t weReserved2; 119 u_int8_t wePart3[4]; 120}; 121#define WIN_CHARS 13 /* Number of chars per winentry */ 122 123/* 124 * Maximum filename length in Win95 125 * Note: Must be < sizeof(dirent.d_name) 126 */ 127#define WIN_MAXLEN 255 128 129/* 130 * Maximum filename length for short names: 131 * 8 bytes of filename plus 3 bytes of extension. 132 * The dot between the filename and extension is implied. 133 */ 134#define SHORT_NAME_LEN 11 135 136/* 137 * This is the format of the contents of the deTime field in the dosdirentry 138 * structure. 139 * We don't use bitfields because we don't know how compilers for 140 * arbitrary machines will lay them out. 141 */ 142#define DT_2SECONDS_MASK 0x1F /* seconds divided by 2 */ 143#define DT_2SECONDS_SHIFT 0 144#define DT_MINUTES_MASK 0x7E0 /* minutes */ 145#define DT_MINUTES_SHIFT 5 146#define DT_HOURS_MASK 0xF800 /* hours */ 147#define DT_HOURS_SHIFT 11 148 149/* 150 * This is the format of the contents of the deDate field in the dosdirentry 151 * structure. 152 */ 153#define DD_DAY_MASK 0x1F /* day of month */ 154#define DD_DAY_SHIFT 0 155#define DD_MONTH_MASK 0x1E0 /* month */ 156#define DD_MONTH_SHIFT 5 157#define DD_YEAR_MASK 0xFE00 /* year - 1980 */ 158#define DD_YEAR_SHIFT 9 159 160#ifdef KERNEL 161struct dirent; 162void msdosfs_unix2dostime(struct timespec *tsp, u_int16_t *ddp, 163 u_int16_t *dtp, u_int8_t *dhp); 164void msdosfs_dos2unixtime(u_int dd, u_int dt, u_int dh, struct timespec *tsp); 165size_t msdosfs_dos2unicodefn(u_char dn[SHORT_NAME_LEN], u_int16_t *un, int lower); 166int msdosfs_unicode_to_dos_name(const uint16_t *unicode, 167 size_t unicode_length, 168 uint8_t short_name[SHORT_NAME_LEN], 169 u_int8_t *lower_case); 170int msdosfs_apply_generation_to_short_name(uint8_t short_name[SHORT_NAME_LEN], 171 unsigned generation); 172int msdosfs_unicode2winfn(const u_int16_t *un, int unlen, struct winentry *wep, int cnt, int chksum); 173int msdosfs_winChkName(const u_int16_t *un, int unlen, struct winentry *wep, int chksum, u_int16_t *found_name, boolean_t *case_folded); 174int msdosfs_getunicodefn(struct winentry *wep, u_int16_t ucfn[WIN_MAXLEN], u_int16_t *unichars, int chksum); 175u_int8_t msdosfs_winChksum(u_int8_t *name); 176int msdosfs_winSlotCnt(const u_int16_t *un, int unlen); 177u_char msdosfs_unicode2dos(u_int16_t uc); 178int msdosfs_fsync_internal(vnode_t vp, int sync, int do_dirs, vfs_context_t context); 179 180#endif /* KERNEL */ 181