[6ebaff9] | 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 |
|
---|
[0f57d0e] | 36 | #include "../../vfs/vfs.h"
|
---|
| 37 | #include <stdint.h>
|
---|
[6c8d267] | 38 | #include <libblock.h>
|
---|
[0f57d0e] | 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 | #define FAT_CLST_BAD 0xfff7
|
---|
| 46 | #define FAT_CLST_LAST1 0xfff8
|
---|
| 47 | #define FAT_CLST_LAST8 0xffff
|
---|
| 48 |
|
---|
| 49 | /* internally used to mark root directory's parent */
|
---|
| 50 | #define FAT_CLST_ROOTPAR FAT_CLST_RES0
|
---|
| 51 | /* internally used to mark root directory */
|
---|
| 52 | #define FAT_CLST_ROOT FAT_CLST_RES1
|
---|
| 53 |
|
---|
| 54 | /* forward declarations */
|
---|
| 55 | struct block;
|
---|
| 56 | struct fat_node;
|
---|
[cb682eb] | 57 | struct fat_bs;
|
---|
[0f57d0e] | 58 |
|
---|
| 59 | typedef uint16_t fat_cluster_t;
|
---|
| 60 |
|
---|
[e402382] | 61 | #define fat_clusters_get(numc, bs, dh, fc) \
|
---|
| 62 | fat_cluster_walk((bs), (dh), (fc), NULL, (numc), (uint16_t) -1)
|
---|
[991f645] | 63 | extern int fat_cluster_walk(struct fat_bs *, devmap_handle_t, fat_cluster_t,
|
---|
[e402382] | 64 | fat_cluster_t *, uint16_t *, uint16_t);
|
---|
[6c8d267] | 65 |
|
---|
[746f623] | 66 | extern int fat_block_get(block_t **, struct fat_bs *, struct fat_node *,
|
---|
| 67 | aoff64_t, int);
|
---|
[991f645] | 68 | extern int _fat_block_get(block_t **, struct fat_bs *, devmap_handle_t,
|
---|
[6da81e0] | 69 | fat_cluster_t, fat_cluster_t *, aoff64_t, int);
|
---|
[ed903174] | 70 |
|
---|
[cca29e3c] | 71 | extern int fat_append_clusters(struct fat_bs *, struct fat_node *,
|
---|
[377cce8] | 72 | fat_cluster_t, fat_cluster_t);
|
---|
[cca29e3c] | 73 | extern int fat_chop_clusters(struct fat_bs *, struct fat_node *,
|
---|
[913a821c] | 74 | fat_cluster_t);
|
---|
[991f645] | 75 | extern int fat_alloc_clusters(struct fat_bs *, devmap_handle_t, unsigned,
|
---|
[cb682eb] | 76 | fat_cluster_t *, fat_cluster_t *);
|
---|
[991f645] | 77 | extern int fat_free_clusters(struct fat_bs *, devmap_handle_t, fat_cluster_t);
|
---|
| 78 | extern int fat_alloc_shadow_clusters(struct fat_bs *, devmap_handle_t,
|
---|
[cb682eb] | 79 | fat_cluster_t *, unsigned);
|
---|
[991f645] | 80 | extern int fat_get_cluster(struct fat_bs *, devmap_handle_t, unsigned,
|
---|
[711e1f32] | 81 | fat_cluster_t, fat_cluster_t *);
|
---|
[991f645] | 82 | extern int fat_set_cluster(struct fat_bs *, devmap_handle_t, unsigned,
|
---|
[cb682eb] | 83 | fat_cluster_t, fat_cluster_t);
|
---|
[cca29e3c] | 84 | extern int fat_fill_gap(struct fat_bs *, struct fat_node *, fat_cluster_t,
|
---|
[ed903174] | 85 | aoff64_t);
|
---|
[991f645] | 86 | extern int fat_zero_cluster(struct fat_bs *, devmap_handle_t, fat_cluster_t);
|
---|
| 87 | extern int fat_sanity_check(struct fat_bs *, devmap_handle_t);
|
---|
[0f57d0e] | 88 |
|
---|
[6ebaff9] | 89 | #endif
|
---|
| 90 |
|
---|
| 91 | /**
|
---|
| 92 | * @}
|
---|
| 93 | */
|
---|