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