| 1 | /*	$NetBSD: direntry.h,v 1.12 2021/10/23 16:58:17 thorpej Exp $	*/ |
| 2 | |
| 3 | /*- |
| 4 | * Copyright (C) 1994, 1995, 1997 Wolfgang Solfrank. |
| 5 | * Copyright (C) 1994, 1995, 1997 TooLs GmbH. |
| 6 | * All rights reserved. |
| 7 | * Original code by Paul Popelka (paulp@uts.amdahl.com) (see below). |
| 8 | * |
| 9 | * Redistribution and use in source and binary forms, with or without |
| 10 | * modification, are permitted provided that the following conditions |
| 11 | * are met: |
| 12 | * 1. Redistributions of source code must retain the above copyright |
| 13 | * notice, this list of conditions and the following disclaimer. |
| 14 | * 2. Redistributions in binary form must reproduce the above copyright |
| 15 | * notice, this list of conditions and the following disclaimer in the |
| 16 | * documentation and/or other materials provided with the distribution. |
| 17 | * 3. All advertising materials mentioning features or use of this software |
| 18 | * must display the following acknowledgement: |
| 19 | *	This product includes software developed by TooLs GmbH. |
| 20 | * 4. The name of TooLs GmbH may not be used to endorse or promote products |
| 21 | * derived from this software without specific prior written permission. |
| 22 | * |
| 23 | * THIS SOFTWARE IS PROVIDED BY TOOLS GMBH ``AS IS'' AND ANY EXPRESS OR |
| 24 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
| 25 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
| 26 | * IN NO EVENT SHALL TOOLS GMBH BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 27 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
| 28 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; |
| 29 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, |
| 30 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR |
| 31 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF |
| 32 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 33 | */ |
| 34 | /* |
| 35 | * Written by Paul Popelka (paulp@uts.amdahl.com) |
| 36 | * |
| 37 | * You can do anything you want with this software, just don't say you wrote |
| 38 | * it, and don't remove this notice. |
| 39 | * |
| 40 | * This software is provided "as is". |
| 41 | * |
| 42 | * The author supplies this software to be publicly redistributed on the |
| 43 | * understanding that the author is not responsible for the correct |
| 44 | * functioning of this software in any circumstances and is not liable for |
| 45 | * any damages caused by this software. |
| 46 | * |
| 47 | * October 1992 |
| 48 | */ |
| 49 | #ifndef _MSDOSFS_DIRENTRY_H_ |
| 50 | #define _MSDOSFS_DIRENTRY_H_ |
| 51 | |
| 52 | /* |
| 53 | * Structure of a dos directory entry. |
| 54 | */ |
| 55 | struct direntry { |
| 56 | 	uint8_t		deName[8];	/* filename, blank filled */ |
| 57 | #define	SLOT_EMPTY	0x00		/* slot has never been used */ |
| 58 | #define	SLOT_E5		0x05		/* the real value is 0xe5 */ |
| 59 | #define	SLOT_DELETED	0xe5		/* file in this slot deleted */ |
| 60 | 	uint8_t		deExtension[3];	/* extension, blank filled */ |
| 61 | 	uint8_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 */ |
| 69 | 	uint8_t		deReserved;	/* reserved */ |
| 70 | 	uint8_t		deCHundredth;	/* hundredth of seconds in CTime */ |
| 71 | 	uint8_t		deCTime[2];	/* create time */ |
| 72 | 	uint8_t		deCDate[2];	/* create date */ |
| 73 | 	uint8_t		deADate[2];	/* access date */ |
| 74 | 	uint8_t		deHighClust[2];	/* high bytes of cluster number */ |
| 75 | 	uint8_t		deMTime[2];	/* last update time */ |
| 76 | 	uint8_t		deMDate[2];	/* last update date */ |
| 77 | 	uint8_t		deStartCluster[2]; /* starting cluster of file */ |
| 78 | 	uint8_t		deFileSize[4];	/* size of file in bytes */ |
| 79 | }; |
| 80 | |
| 81 | static __inline uint8_t |
| 82 | msdos_dirchar(const struct direntry *de, size_t i) { |
| 83 | 	return i < sizeof(de->deName) ? de->deName[i] : |
| 84 | 	 de->deExtension[i - sizeof(de->deName)]; |
| 85 | } |
| 86 | |
| 87 | /* |
| 88 | * Structure of a Win95 long name directory entry |
| 89 | */ |
| 90 | struct winentry { |
| 91 | 	uint8_t		weCnt; |
| 92 | #define	WIN_LAST	0x40 |
| 93 | #define	WIN_CNT		0x3f |
| 94 | 	uint8_t		wePart1[10]; |
| 95 | 	uint8_t		weAttributes; |
| 96 | #define	ATTR_WIN95	0x0f |
| 97 | 	uint8_t		weReserved1; |
| 98 | 	uint8_t		weChksum; |
| 99 | 	uint8_t		wePart2[12]; |
| 100 | 	uint16_t	weReserved2; |
| 101 | 	uint8_t		wePart3[4]; |
| 102 | }; |
| 103 | #define	WIN_CHARS	13	/* Number of chars per winentry */ |
| 104 | |
| 105 | /* |
| 106 | * This is the format of the contents of the deTime field in the direntry |
| 107 | * structure. |
| 108 | * We don't use bitfields because we don't know how compilers for |
| 109 | * arbitrary machines will lay them out. |
| 110 | */ |
| 111 | #define DT_2SECONDS_MASK	0x1F	/* seconds divided by 2 */ |
| 112 | #define DT_2SECONDS_SHIFT	0 |
| 113 | #define DT_MINUTES_MASK		0x7E0	/* minutes */ |
| 114 | #define DT_MINUTES_SHIFT	5 |
| 115 | #define DT_HOURS_MASK		0xF800	/* hours */ |
| 116 | #define DT_HOURS_SHIFT		11 |
| 117 | |
| 118 | /* |
| 119 | * This is the format of the contents of the deDate field in the direntry |
| 120 | * structure. |
| 121 | */ |
| 122 | #define DD_DAY_MASK		0x1F	/* day of month */ |
| 123 | #define DD_DAY_SHIFT		0 |
| 124 | #define DD_MONTH_MASK		0x1E0	/* month */ |
| 125 | #define DD_MONTH_SHIFT		5 |
| 126 | #define DD_YEAR_MASK		0xFE00	/* year - 1980 */ |
| 127 | #define DD_YEAR_SHIFT		9 |
| 128 | |
| 129 | #if defined(_KERNEL) || defined(MAKEFS) |
| 130 | struct dirent; |
| 131 | void	msdosfs_unix2dostime(const struct timespec *tsp, int gmtoff, |
| 132 | 	 uint16_t *ddp, uint16_t *dtp, uint8_t *dhp); |
| 133 | void	msdosfs_dos2unixtime(unsigned int dd, unsigned int dt, unsigned int dh, |
| 134 | 	 int gmtoff, struct timespec *tsp); |
| 135 | int	msdosfs_dos2unixfn(unsigned char dn[11], unsigned char *un, int lower); |
| 136 | int	msdosfs_unix2dosfn(const unsigned char *un, unsigned char dn[12], |
| 137 | 	 int unlen, unsigned int gen); |
| 138 | int	msdosfs_unix2winfn(const unsigned char *un, int unlen, |
| 139 | 	 struct winentry *wep, int cnt, int chksum, int utf8); |
| 140 | int	msdosfs_winChkName(const unsigned char *un, int unlen, |
| 141 | 	 struct winentry *wep, int chksum, int utf8); |
| 142 | int	msdosfs_win2unixfn(struct winentry *wep, struct dirent *dp, int chksum,	 |
| 143 | 	 uint16_t *namlen, int utf8); |
| 144 | uint8_t msdosfs_winChksum(uint8_t *name); |
| 145 | int	msdosfs_winSlotCnt(const unsigned char *un, int unlen, int utf8); |
| 146 | #endif /* _KERNEL || MAKEFS */ |
| 147 | #endif /* _MSDOSFS_DIRENTRY_H_ */ |