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