179455Sobrien/*
279455Sobrien * Copyright (C) 1995, 1996, 1997 Wolfgang Solfrank
379455Sobrien * Copyright (c) 1995 Martin Husemann
479455Sobrien * Some structure declaration borrowed from Paul Popelka
579455Sobrien * (paulp@uts.amdahl.com), see /sys/msdosfs/ for reference.
679455Sobrien *
779455Sobrien * Redistribution and use in source and binary forms, with or without
879455Sobrien * modification, are permitted provided that the following conditions
979455Sobrien * are met:
1079455Sobrien * 1. Redistributions of source code must retain the above copyright
1179455Sobrien *    notice, this list of conditions and the following disclaimer.
1279455Sobrien * 2. Redistributions in binary form must reproduce the above copyright
1379455Sobrien *    notice, this list of conditions and the following disclaimer in the
1479455Sobrien *    documentation and/or other materials provided with the distribution.
1579455Sobrien *
1679455Sobrien * THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR
1779455Sobrien * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
1879455Sobrien * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
1979455Sobrien * IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY DIRECT, INDIRECT,
2079455Sobrien * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
2179455Sobrien * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
2279455Sobrien * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
2379455Sobrien * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
2479455Sobrien * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
2579455Sobrien * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2679455Sobrien *	$NetBSD: dosfs.h,v 1.4 1997/01/03 14:32:48 ws Exp $
2779455Sobrien * $FreeBSD$
2879455Sobrien */
2979455Sobrien
3079455Sobrien#ifndef DOSFS_H
3179455Sobrien#define DOSFS_H
3279455Sobrien
3379455Sobrien#define DOSBOOTBLOCKSIZE 512
3479455Sobrien
3579455Sobrientypedef	u_int32_t	cl_t;	/* type holding a cluster number */
3679455Sobrien
3779455Sobrien/*
3879455Sobrien * architecture independent description of all the info stored in a
3979455Sobrien * FAT boot block.
4079455Sobrien */
4179455Sobrienstruct bootblock {
42203874Skib	u_int	bpbBytesPerSec;		/* bytes per sector */
43203874Skib	u_int	bpbSecPerClust;		/* sectors per cluster */
44203874Skib	u_int	bpbResSectors;		/* number of reserved sectors */
45203874Skib	u_int	bpbFATs;		/* number of bpbFATs */
46203874Skib	u_int	bpbRootDirEnts;		/* number of root directory entries */
47203874Skib	u_int32_t bpbSectors;		/* total number of sectors */
48203874Skib	u_int	bpbMedia;		/* media descriptor */
49203874Skib	u_int	bpbFATsmall;		/* number of sectors per FAT */
5079455Sobrien	u_int	SecPerTrack;		/* sectors per track */
51203874Skib	u_int	bpbHeads;		/* number of heads */
52203874Skib	u_int32_t bpbHiddenSecs;	/* # of hidden sectors */
53203874Skib	u_int32_t bpbHugeSectors;	/* # of sectors if bpbbpbSectors == 0 */
54203874Skib	cl_t	bpbRootClust;		/* Start of Root Directory */
55203874Skib	u_int	bpbFSInfo;		/* FSInfo sector */
56203874Skib	u_int	bpbBackup;		/* Backup of Bootblocks */
57203874Skib	cl_t	FSFree;			/* Number of free clusters acc. FSInfo */
58203874Skib	cl_t	FSNext;			/* Next free cluster acc. FSInfo */
59203874Skib
60203874Skib	/* and some more calculated values */
61203874Skib	u_int	flags;			/* some flags: */
62203872Skib#define	FAT32		1		/* this is a FAT32 file system */
63203872Skib					/*
64203872Skib					 * Maybe, we should separate out
65203872Skib					 * various parts of FAT32?	XXX
66203872Skib					 */
6779455Sobrien	int	ValidFat;		/* valid fat if FAT32 non-mirrored */
6879455Sobrien	cl_t	ClustMask;		/* mask for entries in FAT */
6979455Sobrien	cl_t	NumClusters;		/* # of entries in a FAT */
7079455Sobrien	u_int32_t NumSectors;		/* how many sectors are there */
7179455Sobrien	u_int32_t FATsecs;		/* how many sectors are in FAT */
7279455Sobrien	u_int32_t NumFatEntries;	/* how many entries really are there */
7379455Sobrien	u_int	ClusterOffset;		/* at what sector would sector 0 start */
7479455Sobrien	u_int	ClusterSize;		/* Cluster size in bytes */
7579455Sobrien
7679455Sobrien	/* Now some statistics: */
7779455Sobrien	u_int	NumFiles;		/* # of plain files */
7879455Sobrien	u_int	NumFree;		/* # of free clusters */
7979455Sobrien	u_int	NumBad;			/* # of bad clusters */
8079455Sobrien};
8179455Sobrien
8279455Sobrienstruct fatEntry {
8379455Sobrien	cl_t	next;			/* pointer to next cluster */
8479455Sobrien	cl_t	head;			/* pointer to start of chain */
8579455Sobrien	u_int32_t length;		/* number of clusters on chain */
8679455Sobrien	int	flags;			/* see below */
8779455Sobrien};
8879455Sobrien
8979455Sobrien#define	CLUST_FREE	0		/* 0 means cluster is free */
9079455Sobrien#define	CLUST_FIRST	2		/* 2 is the minimum valid cluster number */
9179455Sobrien#define	CLUST_RSRVD	0xfffffff6	/* start of reserved clusters */
9279455Sobrien#define	CLUST_BAD	0xfffffff7	/* a cluster with a defect */
9379455Sobrien#define	CLUST_EOFS	0xfffffff8	/* start of EOF indicators */
9479455Sobrien#define	CLUST_EOF	0xffffffff	/* standard value for last cluster */
9579455Sobrien
9679455Sobrien/*
9779455Sobrien * Masks for cluster values
9879455Sobrien */
9979455Sobrien#define	CLUST12_MASK	0xfff
10079455Sobrien#define	CLUST16_MASK	0xffff
10179455Sobrien#define	CLUST32_MASK	0xfffffff
10279455Sobrien
10379455Sobrien#define	FAT_USED	1		/* This fat chain is used in a file */
10479455Sobrien
10579455Sobrien#define	DOSLONGNAMELEN	256		/* long name maximal length */
10679455Sobrien#define LRFIRST		0x40		/* first long name record */
10779455Sobrien#define	LRNOMASK	0x1f		/* mask to extract long record
10879455Sobrien					 * sequence number */
10979455Sobrien
11079455Sobrien/*
11179455Sobrien * Architecture independent description of a directory entry
11279455Sobrien */
11379455Sobrienstruct dosDirEntry {
11479455Sobrien	struct dosDirEntry
11579455Sobrien		*parent,		/* previous tree level */
11679455Sobrien		*next,			/* next brother */
11779455Sobrien		*child;			/* if this is a directory */
11879455Sobrien	char name[8+1+3+1];		/* alias name first part */
11979455Sobrien	char lname[DOSLONGNAMELEN];	/* real name */
12079455Sobrien	uint flags;			/* attributes */
12179455Sobrien	cl_t head;			/* cluster no */
12279455Sobrien	u_int32_t size;			/* filesize in bytes */
12379455Sobrien	uint fsckflags;			/* flags during fsck */
12479455Sobrien};
12579455Sobrien/* Flags in fsckflags: */
12679455Sobrien#define	DIREMPTY	1
12779455Sobrien#define	DIREMPWARN	2
12879455Sobrien
12979455Sobrien/*
13079455Sobrien *  TODO-list of unread directories
13179455Sobrien */
13279455Sobrienstruct dirTodoNode {
13379455Sobrien	struct dosDirEntry *dir;
13479455Sobrien	struct dirTodoNode *next;
13579455Sobrien};
13679455Sobrien
13779455Sobrien#endif
138