source: mainline/uspace/srv/fs/fat/fat_fat.h@ a8c14aa

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since a8c14aa was b5db2ae, checked in by Oleg Romanenko <romanenko.oleg@…>, 14 years ago
  1. Add macros for determining first cluster of root directory (FAT_ROOT_CLST)
  2. Root directory (FAT32) can consist of many clusters rather than of only one.
  3. Using FAT_CLST_ROOT value to determining root directory first cluster

is applicable only to FAT12/16 filesystem.

  • Property mode set to 100644
File size: 5.2 KB
Line 
1/*
2 * Copyright (c) 2008 Jakub Jermar
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * - Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * - Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * - The name of the author may not be used to endorse or promote products
15 * derived from this software without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28
29/** @addtogroup fs
30 * @{
31 */
32
33#ifndef FAT_FAT_FAT_H_
34#define FAT_FAT_FAT_H_
35
36#include "../../vfs/vfs.h"
37#include <stdint.h>
38#include <libblock.h>
39
40#define FAT1 0
41
42#define FAT_CLST_RES0 0x0000
43#define FAT_CLST_RES1 0x0001
44#define FAT_CLST_FIRST 0x0002
45
46#define FAT12_CLST_BAD 0x0ff7
47#define FAT12_CLST_LAST1 0x0ff8
48#define FAT12_CLST_LAST8 0x0fff
49#define FAT16_CLST_BAD 0xfff7
50#define FAT16_CLST_LAST1 0xfff8
51#define FAT16_CLST_LAST8 0xffff
52#define FAT32_CLST_BAD 0x0ffffff7
53#define FAT32_CLST_LAST1 0x0ffffff8
54#define FAT32_CLST_LAST8 0x0fffffff
55
56#define FAT12_MASK 0x0fff
57#define FAT16_MASK 0xffff
58#define FAT32_MASK 0x0fffffff
59
60#define FAT12_CLST_MAX 4085
61#define FAT16_CLST_MAX 65525
62
63/* Size in bytes for cluster value of FAT */
64#define FAT12_CLST_SIZE 2
65#define FAT16_CLST_SIZE 2
66#define FAT32_CLST_SIZE 4
67
68/* internally used to mark root directory's parent */
69#define FAT_CLST_ROOTPAR FAT_CLST_RES0
70/* internally used to mark root directory */
71#define FAT_CLST_ROOT FAT_CLST_RES1
72
73/*
74 * Convenience macros for computing some frequently used values from the
75 * primitive boot sector members.
76 */
77#define RDS(bs) ((sizeof(fat_dentry_t) * RDE((bs))) / BPS((bs))) + \
78 (((sizeof(fat_dentry_t) * RDE((bs))) % BPS((bs))) != 0)
79#define SSA(bs) (RSCNT((bs)) + FATCNT((bs)) * SF((bs)) + RDS(bs))
80#define DS(bs) (TS(bs) - SSA(bs))
81#define CC(bs) (DS(bs) / SPC(bs))
82
83#define FAT_IS_FAT12(bs) (CC(bs) < FAT12_CLST_MAX)
84#define FAT_IS_FAT16(bs) \
85 ((CC(bs) >= FAT12_CLST_MAX) && (CC(bs) < FAT16_CLST_MAX))
86#define FAT_IS_FAT32(bs) (CC(bs) >= FAT16_CLST_MAX)
87
88#define FAT_CLST_LAST1(bs) \
89 (FAT_IS_FAT12(bs) ? FAT12_CLST_LAST1 : \
90 (FAT_IS_FAT32(bs) ? FAT32_CLST_LAST1 : FAT16_CLST_LAST1))
91#define FAT_CLST_LAST8(bs) \
92 (FAT_IS_FAT12(bs) ? FAT12_CLST_LAST8 : \
93 (FAT_IS_FAT32(bs) ? FAT32_CLST_LAST8 : FAT16_CLST_LAST8))
94#define FAT_CLST_BAD(bs) \
95 (FAT_IS_FAT12(bs) ? FAT12_CLST_BAD : \
96 (FAT_IS_FAT32(bs) ? FAT32_CLST_BAD : FAT16_CLST_BAD))
97
98#define FAT_CLST_SIZE(bs) \
99 (FAT_IS_FAT32(bs) ? FAT32_CLST_SIZE : FAT16_CLST_SIZE)
100
101#define FAT_MASK(bs) \
102 (FAT_IS_FAT12(bs) ? FAT12_MASK : \
103 (FAT_IS_FAT32(bs) ? FAT32_MASK : FAT16_MASK))
104
105#define FAT_ROOT_CLST(bs) \
106 (FAT_IS_FAT32(bs) ? uint32_t_le2host(bs->fat32.root_cluster) : \
107 FAT_CLST_ROOT)
108
109/* forward declarations */
110struct block;
111struct fat_node;
112struct fat_bs;
113
114typedef uint32_t fat_cluster_t;
115
116#define fat_clusters_get(numc, bs, dh, fc) \
117 fat_cluster_walk((bs), (dh), (fc), NULL, (numc), (uint16_t) -1)
118extern int fat_cluster_walk(struct fat_bs *, devmap_handle_t, fat_cluster_t,
119 fat_cluster_t *, uint16_t *, uint16_t);
120
121extern int fat_block_get(block_t **, struct fat_bs *, struct fat_node *,
122 aoff64_t, int);
123extern int _fat_block_get(block_t **, struct fat_bs *, devmap_handle_t,
124 fat_cluster_t, fat_cluster_t *, aoff64_t, int);
125
126extern int fat_append_clusters(struct fat_bs *, struct fat_node *,
127 fat_cluster_t, fat_cluster_t);
128extern int fat_chop_clusters(struct fat_bs *, struct fat_node *,
129 fat_cluster_t);
130extern int fat_alloc_clusters(struct fat_bs *, devmap_handle_t, unsigned,
131 fat_cluster_t *, fat_cluster_t *);
132extern int fat_free_clusters(struct fat_bs *, devmap_handle_t, fat_cluster_t);
133extern int fat_alloc_shadow_clusters(struct fat_bs *, devmap_handle_t,
134 fat_cluster_t *, unsigned);
135extern int fat_get_cluster(struct fat_bs *, devmap_handle_t, unsigned,
136 fat_cluster_t, fat_cluster_t *);
137extern int fat_set_cluster(struct fat_bs *, devmap_handle_t, unsigned,
138 fat_cluster_t, fat_cluster_t);
139extern int fat_fill_gap(struct fat_bs *, struct fat_node *, fat_cluster_t,
140 aoff64_t);
141extern int fat_zero_cluster(struct fat_bs *, devmap_handle_t, fat_cluster_t);
142extern int fat_sanity_check(struct fat_bs *, devmap_handle_t);
143
144#endif
145
146/**
147 * @}
148 */
Note: See TracBrowser for help on using the repository browser.