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

Last change on this file was b1834a01, checked in by Jakub Jermar <jakub@…>, 7 years ago

Categorize the remaining orphan doxygroups

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