direntry.h revision 163647
1226031Sstas/* $FreeBSD: head/sys/fs/msdosfs/direntry.h 163647 2006-10-24 11:14:05Z phk $ */ 2226031Sstas/* $NetBSD: direntry.h,v 1.14 1997/11/17 15:36:32 ws Exp $ */ 3226031Sstas 4226031Sstas/*- 5226031Sstas * Copyright (C) 1994, 1995, 1997 Wolfgang Solfrank. 6226031Sstas * Copyright (C) 1994, 1995, 1997 TooLs GmbH. 7226031Sstas * All rights reserved. 8226031Sstas * Original code by Paul Popelka (paulp@uts.amdahl.com) (see below). 9226031Sstas * 10226031Sstas * Redistribution and use in source and binary forms, with or without 11226031Sstas * modification, are permitted provided that the following conditions 12226031Sstas * are met: 13226031Sstas * 1. Redistributions of source code must retain the above copyright 14226031Sstas * notice, this list of conditions and the following disclaimer. 15226031Sstas * 2. Redistributions in binary form must reproduce the above copyright 16226031Sstas * notice, this list of conditions and the following disclaimer in the 17226031Sstas * documentation and/or other materials provided with the distribution. 18226031Sstas * 3. All advertising materials mentioning features or use of this software 19226031Sstas * must display the following acknowledgement: 20226031Sstas * This product includes software developed by TooLs GmbH. 21226031Sstas * 4. The name of TooLs GmbH may not be used to endorse or promote products 22226031Sstas * derived from this software without specific prior written permission. 23226031Sstas * 24226031Sstas * THIS SOFTWARE IS PROVIDED BY TOOLS GMBH ``AS IS'' AND ANY EXPRESS OR 25226031Sstas * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 26226031Sstas * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 27226031Sstas * IN NO EVENT SHALL TOOLS GMBH BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 28226031Sstas * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 29226031Sstas * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 30226031Sstas * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 31226031Sstas * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 32226031Sstas * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 33226031Sstas * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 34226031Sstas */ 35226031Sstas/*- 36226031Sstas * Written by Paul Popelka (paulp@uts.amdahl.com) 37226031Sstas * 38226031Sstas * You can do anything you want with this software, just don't say you wrote 39226031Sstas * it, and don't remove this notice. 40226031Sstas * 41226031Sstas * This software is provided "as is". 42226031Sstas * 43226031Sstas * The author supplies this software to be publicly redistributed on the 44226031Sstas * understanding that the author is not responsible for the correct 45226031Sstas * functioning of this software in any circumstances and is not liable for 46226031Sstas * any damages caused by this software. 47226031Sstas * 48226031Sstas * October 1992 49226031Sstas */ 50226031Sstas 51226031Sstas/* 52226031Sstas * Structure of a dos directory entry. 53226031Sstas */ 54226031Sstasstruct direntry { 55226031Sstas u_int8_t deName[8]; /* filename, blank filled */ 56226031Sstas#define SLOT_EMPTY 0x00 /* slot has never been used */ 57226031Sstas#define SLOT_E5 0x05 /* the real value is 0xe5 */ 58226031Sstas#define SLOT_DELETED 0xe5 /* file in this slot deleted */ 59226031Sstas u_int8_t deExtension[3]; /* extension, blank filled */ 60226031Sstas u_int8_t deAttributes; /* file attributes */ 61226031Sstas#define ATTR_NORMAL 0x00 /* normal file */ 62226031Sstas#define ATTR_READONLY 0x01 /* file is readonly */ 63226031Sstas#define ATTR_HIDDEN 0x02 /* file is hidden */ 64226031Sstas#define ATTR_SYSTEM 0x04 /* file is a system file */ 65226031Sstas#define ATTR_VOLUME 0x08 /* entry is a volume label */ 66226031Sstas#define ATTR_DIRECTORY 0x10 /* entry is a directory name */ 67#define ATTR_ARCHIVE 0x20 /* file is new or modified */ 68 u_int8_t deLowerCase; /* NT VFAT lower case flags */ 69#define LCASE_BASE 0x08 /* filename base in lower case */ 70#define LCASE_EXT 0x10 /* filename extension in lower case */ 71 u_int8_t deCHundredth; /* hundredth of seconds in CTime */ 72 u_int8_t deCTime[2]; /* create time */ 73 u_int8_t deCDate[2]; /* create date */ 74 u_int8_t deADate[2]; /* access date */ 75 u_int8_t deHighClust[2]; /* high bytes of cluster number */ 76 u_int8_t deMTime[2]; /* last update time */ 77 u_int8_t deMDate[2]; /* last update date */ 78 u_int8_t deStartCluster[2]; /* starting cluster of file */ 79 u_int8_t deFileSize[4]; /* size of file in bytes */ 80}; 81 82/* 83 * Structure of a Win95 long name directory entry 84 */ 85struct winentry { 86 u_int8_t weCnt; 87#define WIN_LAST 0x40 88#define WIN_CNT 0x3f 89 u_int8_t wePart1[10]; 90 u_int8_t weAttributes; 91#define ATTR_WIN95 0x0f 92 u_int8_t weReserved1; 93 u_int8_t weChksum; 94 u_int8_t wePart2[12]; 95 u_int16_t weReserved2; 96 u_int8_t wePart3[4]; 97}; 98#define WIN_CHARS 13 /* Number of chars per winentry */ 99 100/* 101 * Maximum number of winentries for a filename. 102 */ 103#define WIN_MAXSUBENTRIES 20 104 105/* 106 * Maximum filename length in Win95 107 * Note: Must be < sizeof(dirent.d_name) 108 */ 109#define WIN_MAXLEN 255 110 111/* 112 * This is the format of the contents of the deTime field in the direntry 113 * structure. 114 * We don't use bitfields because we don't know how compilers for 115 * arbitrary machines will lay them out. 116 */ 117#define DT_2SECONDS_MASK 0x1F /* seconds divided by 2 */ 118#define DT_2SECONDS_SHIFT 0 119#define DT_MINUTES_MASK 0x7E0 /* minutes */ 120#define DT_MINUTES_SHIFT 5 121#define DT_HOURS_MASK 0xF800 /* hours */ 122#define DT_HOURS_SHIFT 11 123 124/* 125 * This is the format of the contents of the deDate field in the direntry 126 * structure. 127 */ 128#define DD_DAY_MASK 0x1F /* day of month */ 129#define DD_DAY_SHIFT 0 130#define DD_MONTH_MASK 0x1E0 /* month */ 131#define DD_MONTH_SHIFT 5 132#define DD_YEAR_MASK 0xFE00 /* year - 1980 */ 133#define DD_YEAR_SHIFT 9 134 135#ifdef _KERNEL 136struct dirent; 137struct msdosfsmount; 138 139char *mbnambuf_flush(struct dirent *dp); 140void mbnambuf_init(void); 141void mbnambuf_write(char *name, int id); 142int dos2unixfn(u_char dn[11], u_char *un, int lower, 143 struct msdosfsmount *pmp); 144int unix2dosfn(const u_char *un, u_char dn[12], size_t unlen, u_int gen, 145 struct msdosfsmount *pmp); 146int unix2winfn(const u_char *un, size_t unlen, struct winentry *wep, int cnt, 147 int chksum, struct msdosfsmount *pmp); 148int winChkName(const u_char *un, size_t unlen, int chksum, 149 struct msdosfsmount *pmp); 150int win2unixfn(struct winentry *wep, int chksum, struct msdosfsmount *pmp); 151u_int8_t winChksum(struct direntry *dep); 152int winSlotCnt(const u_char *un, size_t unlen, struct msdosfsmount *pmp); 153size_t winLenFixup(const u_char *un, size_t unlen); 154#endif /* _KERNEL */ 155