source: mainline/uspace/srv/fs/exfat/exfat.h@ 7be14db

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 7be14db was 7be14db, checked in by Oleg Romanenko <romanenko.oleg@…>, 14 years ago

exFAT: make BPS, SPC and BPC values unsigned

  • Property mode set to 100644
File size: 6.0 KB
Line 
1/*
2 * Copyright (c) 2008 Jakub Jermar
3 * Copyright (c) 2011 Oleg Romanenko
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
30/** @addtogroup fs
31 * @{
32 */
33
34#ifndef EXFAT_EXFAT_H_
35#define EXFAT_EXFAT_H_
36
37#include "exfat_fat.h"
38#include <fibril_synch.h>
39#include <libfs.h>
40#include <atomic.h>
41#include <sys/types.h>
42#include <bool.h>
43#include "../../vfs/vfs.h"
44
45#ifndef dprintf
46#define dprintf(...) printf(__VA_ARGS__)
47#endif
48
49#define BS_BLOCK 0
50#define BS_SIZE 512
51
52#define BPS(bs) ((uint32_t) (1 << (bs->bytes_per_sector)))
53#define SPC(bs) ((uint32_t)(1 << (bs->sec_per_cluster)))
54#define BPC(bs) ((uint32_t)(BPS(bs)*SPC(bs)))
55#define VOL_FS(bs) uint64_t_le2host(bs->volume_start)
56#define VOL_CNT(bs) uint64_t_le2host(bs->volume_count)
57#define FAT_FS(bs) uint32_t_le2host(bs->fat_sector_start)
58#define FAT_CNT(bs) uint32_t_le2host(bs->fat_sector_count)
59#define DATA_FS(bs) uint32_t_le2host(bs->data_start_sector)
60#define DATA_CNT(bs) uint32_t_le2host(bs->data_clusters)
61#define ROOT_FC(bs) uint32_t_le2host(bs->rootdir_cluster)
62#define VOL_FLAGS(bs) uint16_t_le2host(bs->volume_flags)
63
64
65typedef struct exfat_bs {
66 uint8_t jump[3]; /* 0x00 jmp and nop instructions */
67 uint8_t oem_name[8]; /* 0x03 "EXFAT " */
68 uint8_t __reserved[53]; /* 0x0B always 0 */
69 uint64_t volume_start; /* 0x40 partition first sector */
70 uint64_t volume_count; /* 0x48 partition sectors count */
71 uint32_t fat_sector_start; /* 0x50 FAT first sector */
72 uint32_t fat_sector_count; /* 0x54 FAT sectors count */
73 uint32_t data_start_sector; /* 0x58 Data region first cluster sector */
74 uint32_t data_clusters; /* 0x5C total clusters count */
75 uint32_t rootdir_cluster; /* 0x60 first cluster of the root dir */
76 uint32_t volume_serial; /* 0x64 volume serial number */
77 struct { /* 0x68 FS version */
78 uint8_t minor;
79 uint8_t major;
80 } __attribute__ ((packed)) version;
81 uint16_t volume_flags; /* 0x6A volume state flags */
82 uint8_t bytes_per_sector; /* 0x6C sector size as (1 << n) */
83 uint8_t sec_per_cluster; /* 0x6D sectors per cluster as (1 << n) */
84 uint8_t fat_count; /* 0x6E always 1 */
85 uint8_t drive_no; /* 0x6F always 0x80 */
86 uint8_t allocated_percent; /* 0x70 percentage of allocated space */
87 uint8_t _reserved2[7]; /* 0x71 reserved */
88 uint8_t bootcode[390]; /* Boot code */
89 uint16_t signature; /* the value of 0xAA55 */
90} __attribute__((__packed__)) exfat_bs_t;
91
92typedef enum {
93 EXFAT_UNKNOW,
94 EXFAT_DIRECTORY,
95 EXFAT_FILE,
96 EXFAT_BITMAP,
97 EXFAT_UCTABLE
98} exfat_node_type_t;
99
100struct exfat_node;
101struct exfat_idx_t;
102
103typedef struct {
104 /** Used indices (position) hash table link. */
105 link_t uph_link;
106 /** Used indices (index) hash table link. */
107 link_t uih_link;
108
109 fibril_mutex_t lock;
110 devmap_handle_t devmap_handle;
111 fs_index_t index;
112
113 /* Does parent node fragmented or not? */
114 bool parent_fragmented;
115 /**
116 * Parent node's first cluster.
117 * Zero is used if this node is not linked, in which case nodep must
118 * contain a pointer to the in-core node structure.
119 * One is used when the parent is the root directory.
120 */
121 exfat_cluster_t pfc;
122 /** Directory entry index within the parent node. */
123 unsigned pdi;
124 /** Pointer to in-core node instance. */
125 struct exfat_node *nodep;
126} exfat_idx_t;
127
128/** exFAT in-core node. */
129typedef struct exfat_node {
130 /** Back pointer to the FS node. */
131 fs_node_t *bp;
132
133 fibril_mutex_t lock;
134 exfat_node_type_t type;
135 exfat_idx_t *idx;
136 /**
137 * Node's first cluster.
138 * Zero is used for zero-length nodes.
139 * One is used to mark root directory.
140 */
141 exfat_cluster_t firstc;
142 /** exFAT in-core node free list link. */
143 link_t ffn_link;
144 aoff64_t size;
145 unsigned lnkcnt;
146 unsigned refcnt;
147 bool dirty;
148 /* Should we do walk-on-FAT or not */
149 bool fragmented;
150
151 /*
152 * Cache of the node's last and "current" cluster to avoid some
153 * unnecessary FAT walks.
154 */
155 /* Node's last cluster in FAT. */
156 bool lastc_cached_valid;
157 exfat_cluster_t lastc_cached_value;
158 /* Node's "current" cluster, i.e. where the last I/O took place. */
159 bool currc_cached_valid;
160 aoff64_t currc_cached_bn;
161 exfat_cluster_t currc_cached_value;
162} exfat_node_t;
163
164
165extern vfs_out_ops_t exfat_ops;
166extern libfs_ops_t exfat_libfs_ops;
167
168extern int exfat_idx_get_new(exfat_idx_t **, devmap_handle_t);
169extern exfat_idx_t *exfat_idx_get_by_pos(devmap_handle_t, exfat_cluster_t, unsigned);
170extern exfat_idx_t *exfat_idx_get_by_index(devmap_handle_t, fs_index_t);
171extern void exfat_idx_destroy(exfat_idx_t *);
172extern void exfat_idx_hashin(exfat_idx_t *);
173extern void exfat_idx_hashout(exfat_idx_t *);
174
175extern int exfat_idx_init(void);
176extern void exfat_idx_fini(void);
177extern int exfat_idx_init_by_devmap_handle(devmap_handle_t);
178extern void exfat_idx_fini_by_devmap_handle(devmap_handle_t);
179
180#endif
181
182/**
183 * @}
184 */
Note: See TracBrowser for help on using the repository browser.