xref: /freebsd/sys/fs/msdosfs/direntry.h (revision 71625ec9ad2a9bc8c09784fbd23b759830e0ee5f)
1952a6212SJordan K. Hubbard /*	$NetBSD: direntry.h,v 1.14 1997/11/17 15:36:32 ws Exp $	*/
227a0bc89SDoug Rabson 
327a0bc89SDoug Rabson /*-
4d63027b6SPedro F. Giffuni  * SPDX-License-Identifier: BSD-4-Clause
5d63027b6SPedro F. Giffuni  *
6952a6212SJordan K. Hubbard  * Copyright (C) 1994, 1995, 1997 Wolfgang Solfrank.
7952a6212SJordan K. Hubbard  * Copyright (C) 1994, 1995, 1997 TooLs GmbH.
827a0bc89SDoug Rabson  * All rights reserved.
927a0bc89SDoug Rabson  * Original code by Paul Popelka (paulp@uts.amdahl.com) (see below).
1027a0bc89SDoug Rabson  *
1127a0bc89SDoug Rabson  * Redistribution and use in source and binary forms, with or without
1227a0bc89SDoug Rabson  * modification, are permitted provided that the following conditions
1327a0bc89SDoug Rabson  * are met:
1427a0bc89SDoug Rabson  * 1. Redistributions of source code must retain the above copyright
1527a0bc89SDoug Rabson  *    notice, this list of conditions and the following disclaimer.
1627a0bc89SDoug Rabson  * 2. Redistributions in binary form must reproduce the above copyright
1727a0bc89SDoug Rabson  *    notice, this list of conditions and the following disclaimer in the
1827a0bc89SDoug Rabson  *    documentation and/or other materials provided with the distribution.
1927a0bc89SDoug Rabson  * 3. All advertising materials mentioning features or use of this software
2027a0bc89SDoug Rabson  *    must display the following acknowledgement:
2127a0bc89SDoug Rabson  *	This product includes software developed by TooLs GmbH.
2227a0bc89SDoug Rabson  * 4. The name of TooLs GmbH may not be used to endorse or promote products
2327a0bc89SDoug Rabson  *    derived from this software without specific prior written permission.
2427a0bc89SDoug Rabson  *
2527a0bc89SDoug Rabson  * THIS SOFTWARE IS PROVIDED BY TOOLS GMBH ``AS IS'' AND ANY EXPRESS OR
2627a0bc89SDoug Rabson  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
2727a0bc89SDoug Rabson  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
2827a0bc89SDoug Rabson  * IN NO EVENT SHALL TOOLS GMBH BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
2927a0bc89SDoug Rabson  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
3027a0bc89SDoug Rabson  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
3127a0bc89SDoug Rabson  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
3227a0bc89SDoug Rabson  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
3327a0bc89SDoug Rabson  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
3427a0bc89SDoug Rabson  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
3527a0bc89SDoug Rabson  */
36d167cf6fSWarner Losh /*-
3727a0bc89SDoug Rabson  * Written by Paul Popelka (paulp@uts.amdahl.com)
3827a0bc89SDoug Rabson  *
3927a0bc89SDoug Rabson  * You can do anything you want with this software, just don't say you wrote
4027a0bc89SDoug Rabson  * it, and don't remove this notice.
4127a0bc89SDoug Rabson  *
4227a0bc89SDoug Rabson  * This software is provided "as is".
4327a0bc89SDoug Rabson  *
4427a0bc89SDoug Rabson  * The author supplies this software to be publicly redistributed on the
4527a0bc89SDoug Rabson  * understanding that the author is not responsible for the correct
4627a0bc89SDoug Rabson  * functioning of this software in any circumstances and is not liable for
4727a0bc89SDoug Rabson  * any damages caused by this software.
4827a0bc89SDoug Rabson  *
4927a0bc89SDoug Rabson  * October 1992
5027a0bc89SDoug Rabson  */
5148d1bcf8SKonstantin Belousov #ifndef _FS_MSDOSFS_DIRENTRY_H_
5248d1bcf8SKonstantin Belousov #define	_FS_MSDOSFS_DIRENTRY_H_
5327a0bc89SDoug Rabson 
5427a0bc89SDoug Rabson /*
5527a0bc89SDoug Rabson  * Structure of a dos directory entry.
5627a0bc89SDoug Rabson  */
5727a0bc89SDoug Rabson struct direntry {
5823c53312SEd Maste 	uint8_t		deName[11];	/* filename, blank filled */
5927a0bc89SDoug Rabson #define	SLOT_EMPTY	0x00		/* slot has never been used */
6027a0bc89SDoug Rabson #define	SLOT_E5		0x05		/* the real value is 0xe5 */
6127a0bc89SDoug Rabson #define	SLOT_DELETED	0xe5		/* file in this slot deleted */
6223c53312SEd Maste 	uint8_t		deAttributes;	/* file attributes */
6327a0bc89SDoug Rabson #define	ATTR_NORMAL	0x00		/* normal file */
6427a0bc89SDoug Rabson #define	ATTR_READONLY	0x01		/* file is readonly */
6527a0bc89SDoug Rabson #define	ATTR_HIDDEN	0x02		/* file is hidden */
6627a0bc89SDoug Rabson #define	ATTR_SYSTEM	0x04		/* file is a system file */
6727a0bc89SDoug Rabson #define	ATTR_VOLUME	0x08		/* entry is a volume label */
6827a0bc89SDoug Rabson #define	ATTR_DIRECTORY	0x10		/* entry is a directory name */
6927a0bc89SDoug Rabson #define	ATTR_ARCHIVE	0x20		/* file is new or modified */
7023c53312SEd Maste 	uint8_t		deLowerCase;	/* NT VFAT lower case flags */
71bad3d41dSDmitrij Tejblum #define	LCASE_BASE	0x08		/* filename base in lower case */
72bad3d41dSDmitrij Tejblum #define	LCASE_EXT	0x10		/* filename extension in lower case */
7323c53312SEd Maste 	uint8_t		deCHundredth;	/* hundredth of seconds in CTime */
7423c53312SEd Maste 	uint8_t		deCTime[2];	/* create time */
7523c53312SEd Maste 	uint8_t		deCDate[2];	/* create date */
7623c53312SEd Maste 	uint8_t		deADate[2];	/* access date */
7723c53312SEd Maste 	uint8_t		deHighClust[2];	/* high bytes of cluster number */
7823c53312SEd Maste 	uint8_t		deMTime[2];	/* last update time */
7923c53312SEd Maste 	uint8_t		deMDate[2];	/* last update date */
8023c53312SEd Maste 	uint8_t		deStartCluster[2]; /* starting cluster of file */
8123c53312SEd Maste 	uint8_t		deFileSize[4];	/* size of file in bytes */
8227a0bc89SDoug Rabson };
8327a0bc89SDoug Rabson 
8427a0bc89SDoug Rabson /*
85952a6212SJordan K. Hubbard  * Structure of a Win95 long name directory entry
86952a6212SJordan K. Hubbard  */
87952a6212SJordan K. Hubbard struct winentry {
8823c53312SEd Maste 	uint8_t		weCnt;
89952a6212SJordan K. Hubbard #define	WIN_LAST	0x40
90952a6212SJordan K. Hubbard #define	WIN_CNT		0x3f
9123c53312SEd Maste 	uint8_t		wePart1[10];
9223c53312SEd Maste 	uint8_t		weAttributes;
93952a6212SJordan K. Hubbard #define	ATTR_WIN95	0x0f
9423c53312SEd Maste 	uint8_t		weReserved1;
9523c53312SEd Maste 	uint8_t		weChksum;
9623c53312SEd Maste 	uint8_t		wePart2[12];
9723c53312SEd Maste 	uint16_t	weReserved2;
9823c53312SEd Maste 	uint8_t		wePart3[4];
99952a6212SJordan K. Hubbard };
100952a6212SJordan K. Hubbard #define	WIN_CHARS	13	/* Number of chars per winentry */
101952a6212SJordan K. Hubbard 
102952a6212SJordan K. Hubbard /*
10367425e46SBruce Evans  * Maximum number of winentries for a filename.
104c4f02a89SMax Khon  */
105c4f02a89SMax Khon #define	WIN_MAXSUBENTRIES 20
106c4f02a89SMax Khon 
107c4f02a89SMax Khon /*
108952a6212SJordan K. Hubbard  * Maximum filename length in Win95
109952a6212SJordan K. Hubbard  * Note: Must be < sizeof(dirent.d_name)
110952a6212SJordan K. Hubbard  */
111952a6212SJordan K. Hubbard #define	WIN_MAXLEN	255
112952a6212SJordan K. Hubbard 
113952a6212SJordan K. Hubbard /*
11427a0bc89SDoug Rabson  * This is the format of the contents of the deTime field in the direntry
11527a0bc89SDoug Rabson  * structure.
11627a0bc89SDoug Rabson  * We don't use bitfields because we don't know how compilers for
11727a0bc89SDoug Rabson  * arbitrary machines will lay them out.
11827a0bc89SDoug Rabson  */
11927a0bc89SDoug Rabson #define DT_2SECONDS_MASK	0x1F	/* seconds divided by 2 */
12027a0bc89SDoug Rabson #define DT_2SECONDS_SHIFT	0
12127a0bc89SDoug Rabson #define DT_MINUTES_MASK		0x7E0	/* minutes */
12227a0bc89SDoug Rabson #define DT_MINUTES_SHIFT	5
12327a0bc89SDoug Rabson #define DT_HOURS_MASK		0xF800	/* hours */
12427a0bc89SDoug Rabson #define DT_HOURS_SHIFT		11
12527a0bc89SDoug Rabson 
12627a0bc89SDoug Rabson /*
12727a0bc89SDoug Rabson  * This is the format of the contents of the deDate field in the direntry
12827a0bc89SDoug Rabson  * structure.
12927a0bc89SDoug Rabson  */
13027a0bc89SDoug Rabson #define DD_DAY_MASK		0x1F	/* day of month */
13127a0bc89SDoug Rabson #define DD_DAY_SHIFT		0
13227a0bc89SDoug Rabson #define DD_MONTH_MASK		0x1E0	/* month */
13327a0bc89SDoug Rabson #define DD_MONTH_SHIFT		5
13427a0bc89SDoug Rabson #define DD_YEAR_MASK		0xFE00	/* year - 1980 */
13527a0bc89SDoug Rabson #define DD_YEAR_SHIFT		9
13627a0bc89SDoug Rabson 
137*6ae00e30SEd Maste #ifdef _KERNEL
138c2819440SBruce Evans struct mbnambuf {
139c2819440SBruce Evans 	size_t	nb_len;
140c2819440SBruce Evans 	int	nb_last_id;
141c2819440SBruce Evans 	char	nb_buf[WIN_MAXLEN + 1];
142c2819440SBruce Evans };
143c2819440SBruce Evans 
144952a6212SJordan K. Hubbard struct dirent;
14567425e46SBruce Evans struct msdosfsmount;
14667425e46SBruce Evans 
147c2819440SBruce Evans char	*mbnambuf_flush(struct mbnambuf *nbp, struct dirent *dp);
148c2819440SBruce Evans void	mbnambuf_init(struct mbnambuf *nbp);
14966527f74SKristof Provost int	mbnambuf_write(struct mbnambuf *nbp, char *name, int id);
15067425e46SBruce Evans int	dos2unixfn(u_char dn[11], u_char *un, int lower,
15167425e46SBruce Evans 	    struct msdosfsmount *pmp);
152bddcdc51STim J. Robbins int	unix2dosfn(const u_char *un, u_char dn[12], size_t unlen, u_int gen,
15367425e46SBruce Evans 	    struct msdosfsmount *pmp);
154bddcdc51STim J. Robbins int	unix2winfn(const u_char *un, size_t unlen, struct winentry *wep, int cnt,
15567425e46SBruce Evans 	    int chksum, struct msdosfsmount *pmp);
156c2819440SBruce Evans int	winChkName(struct mbnambuf *nbp, const u_char *un, size_t unlen,
157c2819440SBruce Evans 	    int chksum, struct msdosfsmount *pmp);
158c2819440SBruce Evans int	win2unixfn(struct mbnambuf *nbp, struct winentry *wep, int chksum,
15967425e46SBruce Evans 	    struct msdosfsmount *pmp);
16023c53312SEd Maste uint8_t winChksum(uint8_t *name);
161bddcdc51STim J. Robbins int	winSlotCnt(const u_char *un, size_t unlen, struct msdosfsmount *pmp);
162bddcdc51STim J. Robbins size_t	winLenFixup(const u_char *un, size_t unlen);
163*6ae00e30SEd Maste #endif	/* _KERNEL */
16448d1bcf8SKonstantin Belousov #endif	/* !_FS_MSDOSFS_DIRENTRY_H_ */
165