1*8086f46eSthorpej /* $NetBSD: direntry.h,v 1.12 2021/10/23 16:58:17 thorpej Exp $ */
298d58548Sjdolecek
398d58548Sjdolecek /*-
498d58548Sjdolecek * Copyright (C) 1994, 1995, 1997 Wolfgang Solfrank.
598d58548Sjdolecek * Copyright (C) 1994, 1995, 1997 TooLs GmbH.
698d58548Sjdolecek * All rights reserved.
798d58548Sjdolecek * Original code by Paul Popelka (paulp@uts.amdahl.com) (see below).
898d58548Sjdolecek *
998d58548Sjdolecek * Redistribution and use in source and binary forms, with or without
1098d58548Sjdolecek * modification, are permitted provided that the following conditions
1198d58548Sjdolecek * are met:
1298d58548Sjdolecek * 1. Redistributions of source code must retain the above copyright
1398d58548Sjdolecek * notice, this list of conditions and the following disclaimer.
1498d58548Sjdolecek * 2. Redistributions in binary form must reproduce the above copyright
1598d58548Sjdolecek * notice, this list of conditions and the following disclaimer in the
1698d58548Sjdolecek * documentation and/or other materials provided with the distribution.
1798d58548Sjdolecek * 3. All advertising materials mentioning features or use of this software
1898d58548Sjdolecek * must display the following acknowledgement:
1998d58548Sjdolecek * This product includes software developed by TooLs GmbH.
2098d58548Sjdolecek * 4. The name of TooLs GmbH may not be used to endorse or promote products
2198d58548Sjdolecek * derived from this software without specific prior written permission.
2298d58548Sjdolecek *
2398d58548Sjdolecek * THIS SOFTWARE IS PROVIDED BY TOOLS GMBH ``AS IS'' AND ANY EXPRESS OR
2498d58548Sjdolecek * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
2598d58548Sjdolecek * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
2698d58548Sjdolecek * IN NO EVENT SHALL TOOLS GMBH BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
2798d58548Sjdolecek * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
2898d58548Sjdolecek * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
2998d58548Sjdolecek * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
3098d58548Sjdolecek * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
3198d58548Sjdolecek * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
3298d58548Sjdolecek * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
3398d58548Sjdolecek */
3498d58548Sjdolecek /*
3598d58548Sjdolecek * Written by Paul Popelka (paulp@uts.amdahl.com)
3698d58548Sjdolecek *
3798d58548Sjdolecek * You can do anything you want with this software, just don't say you wrote
3898d58548Sjdolecek * it, and don't remove this notice.
3998d58548Sjdolecek *
4098d58548Sjdolecek * This software is provided "as is".
4198d58548Sjdolecek *
4298d58548Sjdolecek * The author supplies this software to be publicly redistributed on the
4398d58548Sjdolecek * understanding that the author is not responsible for the correct
4498d58548Sjdolecek * functioning of this software in any circumstances and is not liable for
4598d58548Sjdolecek * any damages caused by this software.
4698d58548Sjdolecek *
4798d58548Sjdolecek * October 1992
4898d58548Sjdolecek */
494bffed72Schristos #ifndef _MSDOSFS_DIRENTRY_H_
504bffed72Schristos #define _MSDOSFS_DIRENTRY_H_
5198d58548Sjdolecek
5298d58548Sjdolecek /*
5398d58548Sjdolecek * Structure of a dos directory entry.
5498d58548Sjdolecek */
5598d58548Sjdolecek struct direntry {
5625ebd283Sdholland uint8_t deName[8]; /* filename, blank filled */
5798d58548Sjdolecek #define SLOT_EMPTY 0x00 /* slot has never been used */
5898d58548Sjdolecek #define SLOT_E5 0x05 /* the real value is 0xe5 */
5998d58548Sjdolecek #define SLOT_DELETED 0xe5 /* file in this slot deleted */
6025ebd283Sdholland uint8_t deExtension[3]; /* extension, blank filled */
6125ebd283Sdholland uint8_t deAttributes; /* file attributes */
6298d58548Sjdolecek #define ATTR_NORMAL 0x00 /* normal file */
6398d58548Sjdolecek #define ATTR_READONLY 0x01 /* file is readonly */
6498d58548Sjdolecek #define ATTR_HIDDEN 0x02 /* file is hidden */
6598d58548Sjdolecek #define ATTR_SYSTEM 0x04 /* file is a system file */
6698d58548Sjdolecek #define ATTR_VOLUME 0x08 /* entry is a volume label */
6798d58548Sjdolecek #define ATTR_DIRECTORY 0x10 /* entry is a directory name */
6898d58548Sjdolecek #define ATTR_ARCHIVE 0x20 /* file is new or modified */
6925ebd283Sdholland uint8_t deReserved; /* reserved */
7025ebd283Sdholland uint8_t deCHundredth; /* hundredth of seconds in CTime */
7125ebd283Sdholland uint8_t deCTime[2]; /* create time */
7225ebd283Sdholland uint8_t deCDate[2]; /* create date */
7325ebd283Sdholland uint8_t deADate[2]; /* access date */
7425ebd283Sdholland uint8_t deHighClust[2]; /* high bytes of cluster number */
7525ebd283Sdholland uint8_t deMTime[2]; /* last update time */
7625ebd283Sdholland uint8_t deMDate[2]; /* last update date */
7725ebd283Sdholland uint8_t deStartCluster[2]; /* starting cluster of file */
7825ebd283Sdholland uint8_t deFileSize[4]; /* size of file in bytes */
7998d58548Sjdolecek };
8098d58548Sjdolecek
81de0d394bSchristos static __inline uint8_t
msdos_dirchar(const struct direntry * de,size_t i)82de0d394bSchristos msdos_dirchar(const struct direntry *de, size_t i) {
83de0d394bSchristos return i < sizeof(de->deName) ? de->deName[i] :
84de0d394bSchristos de->deExtension[i - sizeof(de->deName)];
85de0d394bSchristos }
86de0d394bSchristos
8798d58548Sjdolecek /*
8898d58548Sjdolecek * Structure of a Win95 long name directory entry
8998d58548Sjdolecek */
9098d58548Sjdolecek struct winentry {
9125ebd283Sdholland uint8_t weCnt;
9298d58548Sjdolecek #define WIN_LAST 0x40
9398d58548Sjdolecek #define WIN_CNT 0x3f
9425ebd283Sdholland uint8_t wePart1[10];
9525ebd283Sdholland uint8_t weAttributes;
9698d58548Sjdolecek #define ATTR_WIN95 0x0f
9725ebd283Sdholland uint8_t weReserved1;
9825ebd283Sdholland uint8_t weChksum;
9925ebd283Sdholland uint8_t wePart2[12];
10025ebd283Sdholland uint16_t weReserved2;
10125ebd283Sdholland uint8_t wePart3[4];
10298d58548Sjdolecek };
10398d58548Sjdolecek #define WIN_CHARS 13 /* Number of chars per winentry */
10498d58548Sjdolecek
10598d58548Sjdolecek /*
10698d58548Sjdolecek * This is the format of the contents of the deTime field in the direntry
10798d58548Sjdolecek * structure.
10898d58548Sjdolecek * We don't use bitfields because we don't know how compilers for
10998d58548Sjdolecek * arbitrary machines will lay them out.
11098d58548Sjdolecek */
11198d58548Sjdolecek #define DT_2SECONDS_MASK 0x1F /* seconds divided by 2 */
11298d58548Sjdolecek #define DT_2SECONDS_SHIFT 0
11398d58548Sjdolecek #define DT_MINUTES_MASK 0x7E0 /* minutes */
11498d58548Sjdolecek #define DT_MINUTES_SHIFT 5
11598d58548Sjdolecek #define DT_HOURS_MASK 0xF800 /* hours */
11698d58548Sjdolecek #define DT_HOURS_SHIFT 11
11798d58548Sjdolecek
11898d58548Sjdolecek /*
11998d58548Sjdolecek * This is the format of the contents of the deDate field in the direntry
12098d58548Sjdolecek * structure.
12198d58548Sjdolecek */
12298d58548Sjdolecek #define DD_DAY_MASK 0x1F /* day of month */
12398d58548Sjdolecek #define DD_DAY_SHIFT 0
12498d58548Sjdolecek #define DD_MONTH_MASK 0x1E0 /* month */
12598d58548Sjdolecek #define DD_MONTH_SHIFT 5
12698d58548Sjdolecek #define DD_YEAR_MASK 0xFE00 /* year - 1980 */
12798d58548Sjdolecek #define DD_YEAR_SHIFT 9
12898d58548Sjdolecek
129929f8943Schristos #if defined(_KERNEL) || defined(MAKEFS)
130929f8943Schristos struct dirent;
131*8086f46eSthorpej void msdosfs_unix2dostime(const struct timespec *tsp, int gmtoff,
132*8086f46eSthorpej uint16_t *ddp, uint16_t *dtp, uint8_t *dhp);
133*8086f46eSthorpej void msdosfs_dos2unixtime(unsigned int dd, unsigned int dt, unsigned int dh,
134398f5724Sdholland int gmtoff, struct timespec *tsp);
135*8086f46eSthorpej int msdosfs_dos2unixfn(unsigned char dn[11], unsigned char *un, int lower);
136*8086f46eSthorpej int msdosfs_unix2dosfn(const unsigned char *un, unsigned char dn[12],
137*8086f46eSthorpej int unlen, unsigned int gen);
138*8086f46eSthorpej int msdosfs_unix2winfn(const unsigned char *un, int unlen,
139*8086f46eSthorpej struct winentry *wep, int cnt, int chksum, int utf8);
140*8086f46eSthorpej int msdosfs_winChkName(const unsigned char *un, int unlen,
141*8086f46eSthorpej struct winentry *wep, int chksum, int utf8);
142*8086f46eSthorpej int msdosfs_win2unixfn(struct winentry *wep, struct dirent *dp, int chksum,
14376530fdbSchristos uint16_t *namlen, int utf8);
144*8086f46eSthorpej uint8_t msdosfs_winChksum(uint8_t *name);
145*8086f46eSthorpej int msdosfs_winSlotCnt(const unsigned char *un, int unlen, int utf8);
146929f8943Schristos #endif /* _KERNEL || MAKEFS */
1474bffed72Schristos #endif /* _MSDOSFS_DIRENTRY_H_ */
148