/* $NetBSD: direntry.h,v 1.14 1997/11/17 15:36:32 ws Exp $ */12/*-3* SPDX-License-Identifier: BSD-4-Clause4*5* Copyright (C) 1994, 1995, 1997 Wolfgang Solfrank.6* Copyright (C) 1994, 1995, 1997 TooLs GmbH.7* All rights reserved.8* Original code by Paul Popelka ([email protected]) (see below).9*10* Redistribution and use in source and binary forms, with or without11* modification, are permitted provided that the following conditions12* are met:13* 1. Redistributions of source code must retain the above copyright14* notice, this list of conditions and the following disclaimer.15* 2. Redistributions in binary form must reproduce the above copyright16* notice, this list of conditions and the following disclaimer in the17* documentation and/or other materials provided with the distribution.18* 3. All advertising materials mentioning features or use of this software19* must display the following acknowledgement:20* This product includes software developed by TooLs GmbH.21* 4. The name of TooLs GmbH may not be used to endorse or promote products22* derived from this software without specific prior written permission.23*24* THIS SOFTWARE IS PROVIDED BY TOOLS GMBH ``AS IS'' AND ANY EXPRESS OR25* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES26* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.27* IN NO EVENT SHALL TOOLS GMBH BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,28* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,29* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;30* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,31* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR32* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF33* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.34*/35/*-36* Written by Paul Popelka ([email protected])37*38* You can do anything you want with this software, just don't say you wrote39* it, and don't remove this notice.40*41* This software is provided "as is".42*43* The author supplies this software to be publicly redistributed on the44* understanding that the author is not responsible for the correct45* functioning of this software in any circumstances and is not liable for46* any damages caused by this software.47*48* October 199249*/50#ifndef _FS_MSDOSFS_DIRENTRY_H_51#define _FS_MSDOSFS_DIRENTRY_H_5253/*54* Structure of a dos directory entry.55*/56struct direntry {57uint8_t deName[11]; /* filename, blank filled */58#define SLOT_EMPTY 0x00 /* slot has never been used */59#define SLOT_E5 0x05 /* the real value is 0xe5 */60#define SLOT_DELETED 0xe5 /* file in this slot deleted */61uint8_t deAttributes; /* file attributes */62#define ATTR_NORMAL 0x00 /* normal file */63#define ATTR_READONLY 0x01 /* file is readonly */64#define ATTR_HIDDEN 0x02 /* file is hidden */65#define ATTR_SYSTEM 0x04 /* file is a system file */66#define ATTR_VOLUME 0x08 /* entry is a volume label */67#define ATTR_DIRECTORY 0x10 /* entry is a directory name */68#define ATTR_ARCHIVE 0x20 /* file is new or modified */69uint8_t deLowerCase; /* NT VFAT lower case flags */70#define LCASE_BASE 0x08 /* filename base in lower case */71#define LCASE_EXT 0x10 /* filename extension in lower case */72uint8_t deCHundredth; /* hundredth of seconds in CTime */73uint8_t deCTime[2]; /* create time */74uint8_t deCDate[2]; /* create date */75uint8_t deADate[2]; /* access date */76uint8_t deHighClust[2]; /* high bytes of cluster number */77uint8_t deMTime[2]; /* last update time */78uint8_t deMDate[2]; /* last update date */79uint8_t deStartCluster[2]; /* starting cluster of file */80uint8_t deFileSize[4]; /* size of file in bytes */81};8283/*84* Structure of a Win95 long name directory entry85*/86struct winentry {87uint8_t weCnt;88#define WIN_LAST 0x4089#define WIN_CNT 0x3f90uint8_t wePart1[10];91uint8_t weAttributes;92#define ATTR_WIN95 0x0f93uint8_t weReserved1;94uint8_t weChksum;95uint8_t wePart2[12];96uint16_t weReserved2;97uint8_t wePart3[4];98};99#define WIN_CHARS 13 /* Number of chars per winentry */100101/*102* Maximum number of winentries for a filename.103*/104#define WIN_MAXSUBENTRIES 20105106/*107* Maximum filename length in Win95108* Note: Must be < sizeof(dirent.d_name)109*/110#define WIN_MAXLEN 255111112/*113* This is the format of the contents of the deTime field in the direntry114* structure.115* We don't use bitfields because we don't know how compilers for116* arbitrary machines will lay them out.117*/118#define DT_2SECONDS_MASK 0x1F /* seconds divided by 2 */119#define DT_2SECONDS_SHIFT 0120#define DT_MINUTES_MASK 0x7E0 /* minutes */121#define DT_MINUTES_SHIFT 5122#define DT_HOURS_MASK 0xF800 /* hours */123#define DT_HOURS_SHIFT 11124125/*126* This is the format of the contents of the deDate field in the direntry127* structure.128*/129#define DD_DAY_MASK 0x1F /* day of month */130#define DD_DAY_SHIFT 0131#define DD_MONTH_MASK 0x1E0 /* month */132#define DD_MONTH_SHIFT 5133#define DD_YEAR_MASK 0xFE00 /* year - 1980 */134#define DD_YEAR_SHIFT 9135136#ifdef _KERNEL137struct mbnambuf {138size_t nb_len;139int nb_last_id;140char nb_buf[WIN_MAXLEN + 1];141};142143struct dirent;144struct msdosfsmount;145146char *mbnambuf_flush(struct mbnambuf *nbp, struct dirent *dp);147void mbnambuf_init(struct mbnambuf *nbp);148int mbnambuf_write(struct mbnambuf *nbp, char *name, int id);149int dos2unixfn(u_char dn[11], u_char *un, int lower,150struct msdosfsmount *pmp);151int unix2dosfn(const u_char *un, u_char dn[12], size_t unlen, u_int gen,152struct msdosfsmount *pmp);153int unix2winfn(const u_char *un, size_t unlen, struct winentry *wep, int cnt,154int chksum, struct msdosfsmount *pmp);155int winChkName(struct mbnambuf *nbp, const u_char *un, size_t unlen,156int chksum, struct msdosfsmount *pmp);157int win2unixfn(struct mbnambuf *nbp, struct winentry *wep, int chksum,158struct msdosfsmount *pmp);159uint8_t winChksum(uint8_t *name);160int winSlotCnt(const u_char *un, size_t unlen, struct msdosfsmount *pmp);161size_t winLenFixup(const u_char *un, size_t unlen);162#endif /* _KERNEL */163#endif /* !_FS_MSDOSFS_DIRENTRY_H_ */164165166