xref: /freebsd/sys/fs/msdosfs/direntry.h (revision 952a6212d9abd0f11fe608fe552437a24822d41f)
1952a6212SJordan K. Hubbard /*	$Id: direntry.h,v 1.4 1997/02/22 09:40:45 peter Exp $ */
2952a6212SJordan K. Hubbard /*	$NetBSD: direntry.h,v 1.14 1997/11/17 15:36:32 ws Exp $	*/
327a0bc89SDoug Rabson 
427a0bc89SDoug Rabson /*-
5952a6212SJordan K. Hubbard  * Copyright (C) 1994, 1995, 1997 Wolfgang Solfrank.
6952a6212SJordan K. Hubbard  * Copyright (C) 1994, 1995, 1997 TooLs GmbH.
727a0bc89SDoug Rabson  * All rights reserved.
827a0bc89SDoug Rabson  * Original code by Paul Popelka (paulp@uts.amdahl.com) (see below).
927a0bc89SDoug Rabson  *
1027a0bc89SDoug Rabson  * Redistribution and use in source and binary forms, with or without
1127a0bc89SDoug Rabson  * modification, are permitted provided that the following conditions
1227a0bc89SDoug Rabson  * are met:
1327a0bc89SDoug Rabson  * 1. Redistributions of source code must retain the above copyright
1427a0bc89SDoug Rabson  *    notice, this list of conditions and the following disclaimer.
1527a0bc89SDoug Rabson  * 2. Redistributions in binary form must reproduce the above copyright
1627a0bc89SDoug Rabson  *    notice, this list of conditions and the following disclaimer in the
1727a0bc89SDoug Rabson  *    documentation and/or other materials provided with the distribution.
1827a0bc89SDoug Rabson  * 3. All advertising materials mentioning features or use of this software
1927a0bc89SDoug Rabson  *    must display the following acknowledgement:
2027a0bc89SDoug Rabson  *	This product includes software developed by TooLs GmbH.
2127a0bc89SDoug Rabson  * 4. The name of TooLs GmbH may not be used to endorse or promote products
2227a0bc89SDoug Rabson  *    derived from this software without specific prior written permission.
2327a0bc89SDoug Rabson  *
2427a0bc89SDoug Rabson  * THIS SOFTWARE IS PROVIDED BY TOOLS GMBH ``AS IS'' AND ANY EXPRESS OR
2527a0bc89SDoug Rabson  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
2627a0bc89SDoug Rabson  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
2727a0bc89SDoug Rabson  * IN NO EVENT SHALL TOOLS GMBH BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
2827a0bc89SDoug Rabson  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
2927a0bc89SDoug Rabson  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
3027a0bc89SDoug Rabson  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
3127a0bc89SDoug Rabson  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
3227a0bc89SDoug Rabson  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
3327a0bc89SDoug Rabson  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
3427a0bc89SDoug Rabson  */
3527a0bc89SDoug Rabson /*
3627a0bc89SDoug Rabson  * Written by Paul Popelka (paulp@uts.amdahl.com)
3727a0bc89SDoug Rabson  *
3827a0bc89SDoug Rabson  * You can do anything you want with this software, just don't say you wrote
3927a0bc89SDoug Rabson  * it, and don't remove this notice.
4027a0bc89SDoug Rabson  *
4127a0bc89SDoug Rabson  * This software is provided "as is".
4227a0bc89SDoug Rabson  *
4327a0bc89SDoug Rabson  * The author supplies this software to be publicly redistributed on the
4427a0bc89SDoug Rabson  * understanding that the author is not responsible for the correct
4527a0bc89SDoug Rabson  * functioning of this software in any circumstances and is not liable for
4627a0bc89SDoug Rabson  * any damages caused by this software.
4727a0bc89SDoug Rabson  *
4827a0bc89SDoug Rabson  * October 1992
4927a0bc89SDoug Rabson  */
5027a0bc89SDoug Rabson 
5127a0bc89SDoug Rabson /*
5227a0bc89SDoug Rabson  * Structure of a dos directory entry.
5327a0bc89SDoug Rabson  */
5427a0bc89SDoug Rabson struct direntry {
55952a6212SJordan K. Hubbard 	u_int8_t	deName[8];	/* filename, blank filled */
5627a0bc89SDoug Rabson #define	SLOT_EMPTY	0x00		/* slot has never been used */
5727a0bc89SDoug Rabson #define	SLOT_E5		0x05		/* the real value is 0xe5 */
5827a0bc89SDoug Rabson #define	SLOT_DELETED	0xe5		/* file in this slot deleted */
59952a6212SJordan K. Hubbard 	u_int8_t	deExtension[3];	/* extension, blank filled */
60952a6212SJordan K. Hubbard 	u_int8_t	deAttributes;	/* file attributes */
6127a0bc89SDoug Rabson #define	ATTR_NORMAL	0x00		/* normal file */
6227a0bc89SDoug Rabson #define	ATTR_READONLY	0x01		/* file is readonly */
6327a0bc89SDoug Rabson #define	ATTR_HIDDEN	0x02		/* file is hidden */
6427a0bc89SDoug Rabson #define	ATTR_SYSTEM	0x04		/* file is a system file */
6527a0bc89SDoug Rabson #define	ATTR_VOLUME	0x08		/* entry is a volume label */
6627a0bc89SDoug Rabson #define	ATTR_DIRECTORY	0x10		/* entry is a directory name */
6727a0bc89SDoug Rabson #define	ATTR_ARCHIVE	0x20		/* file is new or modified */
68952a6212SJordan K. Hubbard 	u_int8_t	deReserved[1];	/* reserved */
69952a6212SJordan K. Hubbard 	u_int8_t	deCHundredth;	/* hundredth of seconds in CTime */
70952a6212SJordan K. Hubbard 	u_int8_t	deCTime[2];	/* create time */
71952a6212SJordan K. Hubbard 	u_int8_t	deCDate[2];	/* create date */
72952a6212SJordan K. Hubbard 	u_int8_t	deADate[2];	/* access date */
73952a6212SJordan K. Hubbard 	u_int8_t	deHighClust[2];	/* high bytes of cluster number */
74952a6212SJordan K. Hubbard 	u_int8_t	deMTime[2];	/* last update time */
75952a6212SJordan K. Hubbard 	u_int8_t	deMDate[2];	/* last update date */
76952a6212SJordan K. Hubbard 	u_int8_t	deStartCluster[2]; /* starting cluster of file */
77952a6212SJordan K. Hubbard 	u_int8_t	deFileSize[4];	/* size of file in bytes */
7827a0bc89SDoug Rabson };
7927a0bc89SDoug Rabson 
8027a0bc89SDoug Rabson /*
81952a6212SJordan K. Hubbard  * Structure of a Win95 long name directory entry
82952a6212SJordan K. Hubbard  */
83952a6212SJordan K. Hubbard struct winentry {
84952a6212SJordan K. Hubbard 	u_int8_t	weCnt;
85952a6212SJordan K. Hubbard #define	WIN_LAST	0x40
86952a6212SJordan K. Hubbard #define	WIN_CNT		0x3f
87952a6212SJordan K. Hubbard 	u_int8_t	wePart1[10];
88952a6212SJordan K. Hubbard 	u_int8_t	weAttributes;
89952a6212SJordan K. Hubbard #define	ATTR_WIN95	0x0f
90952a6212SJordan K. Hubbard 	u_int8_t	weReserved1;
91952a6212SJordan K. Hubbard 	u_int8_t	weChksum;
92952a6212SJordan K. Hubbard 	u_int8_t	wePart2[12];
93952a6212SJordan K. Hubbard 	u_int16_t	weReserved2;
94952a6212SJordan K. Hubbard 	u_int8_t	wePart3[4];
95952a6212SJordan K. Hubbard };
96952a6212SJordan K. Hubbard #define	WIN_CHARS	13	/* Number of chars per winentry */
97952a6212SJordan K. Hubbard 
98952a6212SJordan K. Hubbard /*
99952a6212SJordan K. Hubbard  * Maximum filename length in Win95
100952a6212SJordan K. Hubbard  * Note: Must be < sizeof(dirent.d_name)
101952a6212SJordan K. Hubbard  */
102952a6212SJordan K. Hubbard #define	WIN_MAXLEN	255
103952a6212SJordan K. Hubbard 
104952a6212SJordan K. Hubbard /*
10527a0bc89SDoug Rabson  * This is the format of the contents of the deTime field in the direntry
10627a0bc89SDoug Rabson  * structure.
10727a0bc89SDoug Rabson  * We don't use bitfields because we don't know how compilers for
10827a0bc89SDoug Rabson  * arbitrary machines will lay them out.
10927a0bc89SDoug Rabson  */
11027a0bc89SDoug Rabson #define DT_2SECONDS_MASK	0x1F	/* seconds divided by 2 */
11127a0bc89SDoug Rabson #define DT_2SECONDS_SHIFT	0
11227a0bc89SDoug Rabson #define DT_MINUTES_MASK		0x7E0	/* minutes */
11327a0bc89SDoug Rabson #define DT_MINUTES_SHIFT	5
11427a0bc89SDoug Rabson #define DT_HOURS_MASK		0xF800	/* hours */
11527a0bc89SDoug Rabson #define DT_HOURS_SHIFT		11
11627a0bc89SDoug Rabson 
11727a0bc89SDoug Rabson /*
11827a0bc89SDoug Rabson  * This is the format of the contents of the deDate field in the direntry
11927a0bc89SDoug Rabson  * structure.
12027a0bc89SDoug Rabson  */
12127a0bc89SDoug Rabson #define DD_DAY_MASK		0x1F	/* day of month */
12227a0bc89SDoug Rabson #define DD_DAY_SHIFT		0
12327a0bc89SDoug Rabson #define DD_MONTH_MASK		0x1E0	/* month */
12427a0bc89SDoug Rabson #define DD_MONTH_SHIFT		5
12527a0bc89SDoug Rabson #define DD_YEAR_MASK		0xFE00	/* year - 1980 */
12627a0bc89SDoug Rabson #define DD_YEAR_SHIFT		9
12727a0bc89SDoug Rabson 
12827a0bc89SDoug Rabson #ifdef KERNEL
129952a6212SJordan K. Hubbard struct dirent;
130952a6212SJordan K. Hubbard void unix2dostime __P((struct timespec *tsp, u_int16_t *ddp,
131952a6212SJordan K. Hubbard 	     u_int16_t *dtp, u_int8_t *dhp));
132952a6212SJordan K. Hubbard void dos2unixtime __P((u_int dd, u_int dt, u_int dh, struct timespec *tsp));
133952a6212SJordan K. Hubbard int dos2unixfn __P((u_char dn[11], u_char *un, int lower));
134952a6212SJordan K. Hubbard int unix2dosfn __P((const u_char *un, u_char dn[12], int unlen, u_int gen));
135952a6212SJordan K. Hubbard int unix2winfn __P((const u_char *un, int unlen, struct winentry *wep, int cnt, int chksum));
136952a6212SJordan K. Hubbard int winChkName __P((const u_char *un, int unlen, struct winentry *wep, int chksum));
137952a6212SJordan K. Hubbard int win2unixfn __P((struct winentry *wep, struct dirent *dp, int chksum));
138952a6212SJordan K. Hubbard u_int8_t winChksum __P((u_int8_t *name));
139952a6212SJordan K. Hubbard int winSlotCnt __P((const u_char *un, int unlen));
14027a0bc89SDoug Rabson #endif	/* KERNEL */
141