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