blob: 0d9f60021afbf51c2615586f14dd397a896e323a [file] [log] [blame]
San Mehat58d4c6c2009-06-25 08:08:05 -07001/*
2 * Copyright (C) 1995, 1996, 1997 Wolfgang Solfrank
3 * Copyright (c) 1995 Martin Husemann
4 * Some structure declaration borrowed from Paul Popelka
5 * (paulp@uts.amdahl.com), see /sys/msdosfs/ for reference.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * 3. All advertising materials mentioning features or use of this software
16 * must display the following acknowledgement:
17 * This product includes software developed by Martin Husemann
18 * and Wolfgang Solfrank.
19 * 4. Neither the name of the University nor the names of its contributors
20 * may be used to endorse or promote products derived from this software
21 * without specific prior written permission.
22 *
23 * THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR
24 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
25 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
26 * IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY DIRECT, INDIRECT,
27 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
28 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
29 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
30 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
31 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
32 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 * $NetBSD: dosfs.h,v 1.4 1997/01/03 14:32:48 ws Exp $
34 * $FreeBSD: src/sbin/fsck_msdosfs/dosfs.h,v 1.3 2003/12/26 17:24:37 trhodes Exp $
35 */
36
37#ifndef DOSFS_H
38#define DOSFS_H
39
40#define DOSBOOTBLOCKSIZE 512
jianfeng594baf12012-06-19 19:53:15 +080041#include "tree.h"
42typedef unsigned int cl_t; /* type holding a cluster number */
43typedef unsigned int u_int;
44typedef unsigned int u_int32_t;
San Mehat58d4c6c2009-06-25 08:08:05 -070045/*
46 * architecture independent description of all the info stored in a
47 * FAT boot block.
48 */
49struct bootblock {
50 u_int BytesPerSec; /* bytes per sector */
51 u_int SecPerClust; /* sectors per cluster */
52 u_int ResSectors; /* number of reserved sectors */
53 u_int FATs; /* number of FATs */
54 u_int RootDirEnts; /* number of root directory entries */
55 u_int Media; /* media descriptor */
56 u_int FATsmall; /* number of sectors per FAT */
57 u_int SecPerTrack; /* sectors per track */
58 u_int Heads; /* number of heads */
59 u_int32_t Sectors; /* total number of sectors */
60 u_int32_t HiddenSecs; /* # of hidden sectors */
61 u_int32_t HugeSectors; /* # of sectors if bpbSectors == 0 */
62 u_int FSInfo; /* FSInfo sector */
63 u_int Backup; /* Backup of Bootblocks */
64 cl_t RootCl; /* Start of Root Directory */
65 cl_t FSFree; /* Number of free clusters acc. FSInfo */
66 cl_t FSNext; /* Next free cluster acc. FSInfo */
67
68 /* and some more calculated values */
69 u_int flags; /* some flags: */
70#define FAT32 1 /* this is a FAT32 file system */
71 /*
72 * Maybe, we should separate out
73 * various parts of FAT32? XXX
74 */
75 int ValidFat; /* valid fat if FAT32 non-mirrored */
76 cl_t ClustMask; /* mask for entries in FAT */
77 cl_t NumClusters; /* # of entries in a FAT */
78 u_int32_t NumSectors; /* how many sectors are there */
79 u_int32_t FATsecs; /* how many sectors are in FAT */
80 u_int32_t NumFatEntries; /* how many entries really are there */
81 u_int ClusterOffset; /* at what sector would sector 0 start */
82 u_int ClusterSize; /* Cluster size in bytes */
83
84 /* Now some statistics: */
85 u_int NumFiles; /* # of plain files */
86 u_int NumFree; /* # of free clusters */
87 u_int NumBad; /* # of bad clusters */
88};
89
jianfeng594baf12012-06-19 19:53:15 +080090
91struct fatcache {
92 struct fatcache *next;
93 cl_t head;
94 u_int32_t length;
95};
96struct cluster_chain_descriptor {
97 struct fatcache* child;
98 cl_t head; /* pointer to start of chain */
99 u_int32_t length; /* how many cluster this file contains*/
100 RB_ENTRY(cluster_chain_descriptor) rb;
101 u_int32_t flag;
San Mehat58d4c6c2009-06-25 08:08:05 -0700102};
103
104#define CLUST_FREE 0 /* 0 means cluster is free */
105#define CLUST_FIRST 2 /* 2 is the minimum valid cluster number */
106#define CLUST_RSRVD 0xfffffff6 /* start of reserved clusters */
107#define CLUST_BAD 0xfffffff7 /* a cluster with a defect */
108#define CLUST_EOFS 0xfffffff8 /* start of EOF indicators */
109#define CLUST_EOF 0xffffffff /* standard value for last cluster */
110
111/*
112 * Masks for cluster values
113 */
114#define CLUST12_MASK 0xfff
115#define CLUST16_MASK 0xffff
116#define CLUST32_MASK 0xfffffff
117
118#define FAT_USED 1 /* This fat chain is used in a file */
119
120#define DOSLONGNAMELEN 256 /* long name maximal length */
121#define LRFIRST 0x40 /* first long name record */
122#define LRNOMASK 0x1f /* mask to extract long record
123 * sequence number */
124
125/*
126 * Architecture independent description of a directory entry
127 */
128struct dosDirEntry {
129 struct dosDirEntry
130 *parent, /* previous tree level */
131 *next, /* next brother */
132 *child; /* if this is a directory */
133 char name[8+1+3+1]; /* alias name first part */
134 char lname[DOSLONGNAMELEN]; /* real name */
jianfeng594baf12012-06-19 19:53:15 +0800135 u_int32_t flags; /* attributes */
San Mehat58d4c6c2009-06-25 08:08:05 -0700136 cl_t head; /* cluster no */
137 u_int32_t size; /* filesize in bytes */
jianfeng594baf12012-06-19 19:53:15 +0800138 u_int32_t fsckflags; /* flags during fsck */
San Mehat58d4c6c2009-06-25 08:08:05 -0700139};
140/* Flags in fsckflags: */
141#define DIREMPTY 1
142#define DIREMPWARN 2
143
144/*
145 * TODO-list of unread directories
146 */
147struct dirTodoNode {
148 struct dosDirEntry *dir;
149 struct dirTodoNode *next;
150};
151
152#endif