1c3aac50fSPeter Wemm /* $FreeBSD$ */ 2952a6212SJordan K. Hubbard /* $NetBSD: direntry.h,v 1.14 1997/11/17 15:36:32 ws Exp $ */ 327a0bc89SDoug Rabson 427a0bc89SDoug Rabson /*- 5952a6212SJordan K. Hubbard * Copyright (C) 1994, 1995, 1997 Wolfgang Solfrank. 6952a6212SJordan K. Hubbard * Copyright (C) 1994, 1995, 1997 TooLs GmbH. 727a0bc89SDoug Rabson * All rights reserved. 827a0bc89SDoug Rabson * Original code by Paul Popelka (paulp@uts.amdahl.com) (see below). 927a0bc89SDoug Rabson * 1027a0bc89SDoug Rabson * Redistribution and use in source and binary forms, with or without 1127a0bc89SDoug Rabson * modification, are permitted provided that the following conditions 1227a0bc89SDoug Rabson * are met: 1327a0bc89SDoug Rabson * 1. Redistributions of source code must retain the above copyright 1427a0bc89SDoug Rabson * notice, this list of conditions and the following disclaimer. 1527a0bc89SDoug Rabson * 2. Redistributions in binary form must reproduce the above copyright 1627a0bc89SDoug Rabson * notice, this list of conditions and the following disclaimer in the 1727a0bc89SDoug Rabson * documentation and/or other materials provided with the distribution. 1827a0bc89SDoug Rabson * 3. All advertising materials mentioning features or use of this software 1927a0bc89SDoug Rabson * must display the following acknowledgement: 2027a0bc89SDoug Rabson * This product includes software developed by TooLs GmbH. 2127a0bc89SDoug Rabson * 4. The name of TooLs GmbH may not be used to endorse or promote products 2227a0bc89SDoug Rabson * derived from this software without specific prior written permission. 2327a0bc89SDoug Rabson * 2427a0bc89SDoug Rabson * THIS SOFTWARE IS PROVIDED BY TOOLS GMBH ``AS IS'' AND ANY EXPRESS OR 2527a0bc89SDoug Rabson * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 2627a0bc89SDoug Rabson * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 2727a0bc89SDoug Rabson * IN NO EVENT SHALL TOOLS GMBH BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 2827a0bc89SDoug Rabson * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 2927a0bc89SDoug Rabson * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 3027a0bc89SDoug Rabson * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 3127a0bc89SDoug Rabson * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 3227a0bc89SDoug Rabson * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 3327a0bc89SDoug Rabson * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 3427a0bc89SDoug Rabson */ 35d167cf6fSWarner Losh /*- 3627a0bc89SDoug Rabson * Written by Paul Popelka (paulp@uts.amdahl.com) 3727a0bc89SDoug Rabson * 3827a0bc89SDoug Rabson * You can do anything you want with this software, just don't say you wrote 3927a0bc89SDoug Rabson * it, and don't remove this notice. 4027a0bc89SDoug Rabson * 4127a0bc89SDoug Rabson * This software is provided "as is". 4227a0bc89SDoug Rabson * 4327a0bc89SDoug Rabson * The author supplies this software to be publicly redistributed on the 4427a0bc89SDoug Rabson * understanding that the author is not responsible for the correct 4527a0bc89SDoug Rabson * functioning of this software in any circumstances and is not liable for 4627a0bc89SDoug Rabson * any damages caused by this software. 4727a0bc89SDoug Rabson * 4827a0bc89SDoug Rabson * October 1992 4927a0bc89SDoug Rabson */ 5048d1bcf8SKonstantin Belousov #ifndef _FS_MSDOSFS_DIRENTRY_H_ 5148d1bcf8SKonstantin Belousov #define _FS_MSDOSFS_DIRENTRY_H_ 5227a0bc89SDoug Rabson 5327a0bc89SDoug Rabson /* 5427a0bc89SDoug Rabson * Structure of a dos directory entry. 5527a0bc89SDoug Rabson */ 5627a0bc89SDoug Rabson struct direntry { 5748d1bcf8SKonstantin Belousov u_int8_t deName[11]; /* filename, blank filled */ 5827a0bc89SDoug Rabson #define SLOT_EMPTY 0x00 /* slot has never been used */ 5927a0bc89SDoug Rabson #define SLOT_E5 0x05 /* the real value is 0xe5 */ 6027a0bc89SDoug Rabson #define SLOT_DELETED 0xe5 /* file in this slot deleted */ 61952a6212SJordan K. Hubbard u_int8_t deAttributes; /* file attributes */ 6227a0bc89SDoug Rabson #define ATTR_NORMAL 0x00 /* normal file */ 6327a0bc89SDoug Rabson #define ATTR_READONLY 0x01 /* file is readonly */ 6427a0bc89SDoug Rabson #define ATTR_HIDDEN 0x02 /* file is hidden */ 6527a0bc89SDoug Rabson #define ATTR_SYSTEM 0x04 /* file is a system file */ 6627a0bc89SDoug Rabson #define ATTR_VOLUME 0x08 /* entry is a volume label */ 6727a0bc89SDoug Rabson #define ATTR_DIRECTORY 0x10 /* entry is a directory name */ 6827a0bc89SDoug Rabson #define ATTR_ARCHIVE 0x20 /* file is new or modified */ 69bad3d41dSDmitrij Tejblum u_int8_t deLowerCase; /* NT VFAT lower case flags */ 70bad3d41dSDmitrij Tejblum #define LCASE_BASE 0x08 /* filename base in lower case */ 71bad3d41dSDmitrij Tejblum #define LCASE_EXT 0x10 /* filename extension in lower case */ 72952a6212SJordan K. Hubbard u_int8_t deCHundredth; /* hundredth of seconds in CTime */ 73952a6212SJordan K. Hubbard u_int8_t deCTime[2]; /* create time */ 74952a6212SJordan K. Hubbard u_int8_t deCDate[2]; /* create date */ 75952a6212SJordan K. Hubbard u_int8_t deADate[2]; /* access date */ 76952a6212SJordan K. Hubbard u_int8_t deHighClust[2]; /* high bytes of cluster number */ 77952a6212SJordan K. Hubbard u_int8_t deMTime[2]; /* last update time */ 78952a6212SJordan K. Hubbard u_int8_t deMDate[2]; /* last update date */ 79952a6212SJordan K. Hubbard u_int8_t deStartCluster[2]; /* starting cluster of file */ 80952a6212SJordan K. Hubbard u_int8_t deFileSize[4]; /* size of file in bytes */ 8127a0bc89SDoug Rabson }; 8227a0bc89SDoug Rabson 8327a0bc89SDoug Rabson /* 84952a6212SJordan K. Hubbard * Structure of a Win95 long name directory entry 85952a6212SJordan K. Hubbard */ 86952a6212SJordan K. Hubbard struct winentry { 87952a6212SJordan K. Hubbard u_int8_t weCnt; 88952a6212SJordan K. Hubbard #define WIN_LAST 0x40 89952a6212SJordan K. Hubbard #define WIN_CNT 0x3f 90952a6212SJordan K. Hubbard u_int8_t wePart1[10]; 91952a6212SJordan K. Hubbard u_int8_t weAttributes; 92952a6212SJordan K. Hubbard #define ATTR_WIN95 0x0f 93952a6212SJordan K. Hubbard u_int8_t weReserved1; 94952a6212SJordan K. Hubbard u_int8_t weChksum; 95952a6212SJordan K. Hubbard u_int8_t wePart2[12]; 96952a6212SJordan K. Hubbard u_int16_t weReserved2; 97952a6212SJordan K. Hubbard u_int8_t wePart3[4]; 98952a6212SJordan K. Hubbard }; 99952a6212SJordan K. Hubbard #define WIN_CHARS 13 /* Number of chars per winentry */ 100952a6212SJordan K. Hubbard 101952a6212SJordan K. Hubbard /* 10267425e46SBruce Evans * Maximum number of winentries for a filename. 103c4f02a89SMax Khon */ 104c4f02a89SMax Khon #define WIN_MAXSUBENTRIES 20 105c4f02a89SMax Khon 106c4f02a89SMax Khon /* 107952a6212SJordan K. Hubbard * Maximum filename length in Win95 108952a6212SJordan K. Hubbard * Note: Must be < sizeof(dirent.d_name) 109952a6212SJordan K. Hubbard */ 110952a6212SJordan K. Hubbard #define WIN_MAXLEN 255 111952a6212SJordan K. Hubbard 112952a6212SJordan K. Hubbard /* 11327a0bc89SDoug Rabson * This is the format of the contents of the deTime field in the direntry 11427a0bc89SDoug Rabson * structure. 11527a0bc89SDoug Rabson * We don't use bitfields because we don't know how compilers for 11627a0bc89SDoug Rabson * arbitrary machines will lay them out. 11727a0bc89SDoug Rabson */ 11827a0bc89SDoug Rabson #define DT_2SECONDS_MASK 0x1F /* seconds divided by 2 */ 11927a0bc89SDoug Rabson #define DT_2SECONDS_SHIFT 0 12027a0bc89SDoug Rabson #define DT_MINUTES_MASK 0x7E0 /* minutes */ 12127a0bc89SDoug Rabson #define DT_MINUTES_SHIFT 5 12227a0bc89SDoug Rabson #define DT_HOURS_MASK 0xF800 /* hours */ 12327a0bc89SDoug Rabson #define DT_HOURS_SHIFT 11 12427a0bc89SDoug Rabson 12527a0bc89SDoug Rabson /* 12627a0bc89SDoug Rabson * This is the format of the contents of the deDate field in the direntry 12727a0bc89SDoug Rabson * structure. 12827a0bc89SDoug Rabson */ 12927a0bc89SDoug Rabson #define DD_DAY_MASK 0x1F /* day of month */ 13027a0bc89SDoug Rabson #define DD_DAY_SHIFT 0 13127a0bc89SDoug Rabson #define DD_MONTH_MASK 0x1E0 /* month */ 13227a0bc89SDoug Rabson #define DD_MONTH_SHIFT 5 13327a0bc89SDoug Rabson #define DD_YEAR_MASK 0xFE00 /* year - 1980 */ 13427a0bc89SDoug Rabson #define DD_YEAR_SHIFT 9 13527a0bc89SDoug Rabson 136c4473420SPeter Wemm #ifdef _KERNEL 137c2819440SBruce Evans struct mbnambuf { 138c2819440SBruce Evans size_t nb_len; 139c2819440SBruce Evans int nb_last_id; 140c2819440SBruce Evans char nb_buf[WIN_MAXLEN + 1]; 141c2819440SBruce Evans }; 142c2819440SBruce Evans 143952a6212SJordan K. Hubbard struct dirent; 14467425e46SBruce Evans struct msdosfsmount; 14567425e46SBruce Evans 146c2819440SBruce Evans char *mbnambuf_flush(struct mbnambuf *nbp, struct dirent *dp); 147c2819440SBruce Evans void mbnambuf_init(struct mbnambuf *nbp); 148c2819440SBruce Evans void mbnambuf_write(struct mbnambuf *nbp, char *name, int id); 14967425e46SBruce Evans int dos2unixfn(u_char dn[11], u_char *un, int lower, 15067425e46SBruce Evans struct msdosfsmount *pmp); 151bddcdc51STim J. Robbins int unix2dosfn(const u_char *un, u_char dn[12], size_t unlen, u_int gen, 15267425e46SBruce Evans struct msdosfsmount *pmp); 153bddcdc51STim J. Robbins int unix2winfn(const u_char *un, size_t unlen, struct winentry *wep, int cnt, 15467425e46SBruce Evans int chksum, struct msdosfsmount *pmp); 155c2819440SBruce Evans int winChkName(struct mbnambuf *nbp, const u_char *un, size_t unlen, 156c2819440SBruce Evans int chksum, struct msdosfsmount *pmp); 157c2819440SBruce Evans int win2unixfn(struct mbnambuf *nbp, struct winentry *wep, int chksum, 15867425e46SBruce Evans struct msdosfsmount *pmp); 15948d1bcf8SKonstantin Belousov u_int8_t winChksum(u_int8_t *name); 160bddcdc51STim J. Robbins int winSlotCnt(const u_char *un, size_t unlen, struct msdosfsmount *pmp); 161bddcdc51STim J. Robbins size_t winLenFixup(const u_char *un, size_t unlen); 162c4473420SPeter Wemm #endif /* _KERNEL */ 16348d1bcf8SKonstantin Belousov #endif /* !_FS_MSDOSFS_DIRENTRY_H_ */ 164