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