| 1 | /* | 
|---|
| 2 | * fatfs_private.h - fat32 partition descriptors & helper functions | 
|---|
| 3 | * | 
|---|
| 4 | * Copyright (c) 2008,2009,2010,2011,2012 Ghassan Almaless | 
|---|
| 5 | * Copyright (c) 2011,2012 UPMC Sorbonne Universites | 
|---|
| 6 | * | 
|---|
| 7 | * This file is part of ALMOS-kernel. | 
|---|
| 8 | * | 
|---|
| 9 | * ALMOS-kernel is free software; you can redistribute it and/or modify it | 
|---|
| 10 | * under the terms of the GNU General Public License as published by | 
|---|
| 11 | * the Free Software Foundation; version 2.0 of the License. | 
|---|
| 12 | * | 
|---|
| 13 | * ALMOS-kernel is distributed in the hope that it will be useful, but | 
|---|
| 14 | * WITHOUT ANY WARRANTY; without even the implied warranty of | 
|---|
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU | 
|---|
| 16 | * General Public License for more details. | 
|---|
| 17 | * | 
|---|
| 18 | * You should have received a copy of the GNU General Public License | 
|---|
| 19 | * along with ALMOS-kernel; if not, write to the Free Software Foundation, | 
|---|
| 20 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | 
|---|
| 21 | */ | 
|---|
| 22 |  | 
|---|
| 23 | #ifndef __VFAT_PRIVATE_H__ | 
|---|
| 24 | #define __VFAT_PRIVATE_H__ | 
|---|
| 25 |  | 
|---|
| 26 | #include <stdint.h> | 
|---|
| 27 | #include <rwlock.h> | 
|---|
| 28 |  | 
|---|
| 29 | #define VFAT_DEBUG      CONFIG_VFAT_DEBUG | 
|---|
| 30 | #define VFAT_INSTRUMENT CONFIG_VFAT_INSTRUMENT | 
|---|
| 31 |  | 
|---|
| 32 | struct vfat_bpb_s | 
|---|
| 33 | { | 
|---|
| 34 | uint8_t     BS_jmpBoot[3]; | 
|---|
| 35 | uint8_t     BS_OEMName[8]; | 
|---|
| 36 | uint16_t    BPB_BytsPerSec; | 
|---|
| 37 | uint8_t     BPB_SecPerClus; | 
|---|
| 38 | uint16_t    BPB_RsvdSecCnt; | 
|---|
| 39 | uint8_t     BPB_NumFATs; | 
|---|
| 40 | uint16_t    BPB_RootEntCnt; | 
|---|
| 41 | uint16_t        BPB_TotSec16; | 
|---|
| 42 | uint8_t     BPB_Media; | 
|---|
| 43 | uint16_t        BPB_FATSz16; | 
|---|
| 44 | uint16_t        BPB_SecPerTrk; | 
|---|
| 45 | uint16_t        BPB_NumHeads; | 
|---|
| 46 | uint32_t        BPB_HiddSec; | 
|---|
| 47 | uint32_t        BPB_TotSec32; | 
|---|
| 48 | uint32_t        BPB_FATSz32; | 
|---|
| 49 | uint16_t        BPB_ExtFlags; | 
|---|
| 50 | uint16_t        BPB_VFVer; | 
|---|
| 51 | uint32_t        BPB_RootClus; | 
|---|
| 52 | uint16_t        BPB_FSInfo; | 
|---|
| 53 | uint16_t        BPB_BkBootSec; | 
|---|
| 54 | uint8_t     BPB_Reserved[12]; | 
|---|
| 55 | uint8_t     BS_DrvNum; | 
|---|
| 56 | uint8_t     BS_Reserved1; | 
|---|
| 57 | uint8_t     BS_BootSig; | 
|---|
| 58 | uint32_t    BS_VolID; | 
|---|
| 59 | uint8_t     BS_VolLab[11]; | 
|---|
| 60 | uint8_t     BS_FilSysType[8]; | 
|---|
| 61 | } __attribute__ ((packed)); | 
|---|
| 62 |  | 
|---|
| 63 |  | 
|---|
| 64 | struct vfat_DirEntry_s | 
|---|
| 65 | { | 
|---|
| 66 | uint8_t     DIR_Name[11]; | 
|---|
| 67 | uint8_t     DIR_Attr; | 
|---|
| 68 | uint8_t     DIR_NTRes; | 
|---|
| 69 | uint8_t     DIR_CrtTimeTenth; | 
|---|
| 70 | uint16_t        DIR_CrtTime; | 
|---|
| 71 | uint16_t        DIR_CrtDate; | 
|---|
| 72 | uint16_t        DIR_LstAccTime; | 
|---|
| 73 | uint16_t        DIR_FstClusHI; | 
|---|
| 74 | uint16_t        DIR_WrtTime; | 
|---|
| 75 | uint16_t        DIR_WrtDate; | 
|---|
| 76 | uint16_t        DIR_FstClusLO; | 
|---|
| 77 | uint32_t        DIR_FileSize; | 
|---|
| 78 | } __attribute__ ((packed)); | 
|---|
| 79 |  | 
|---|
| 80 |  | 
|---|
| 81 | #define VFAT_ATTR_READ_ONLY     0x01 | 
|---|
| 82 | #define VFAT_ATTR_HIDDEN        0x02 | 
|---|
| 83 | #define VFAT_ATTR_SYSTEM        0x04 | 
|---|
| 84 | #define VFAT_ATTR_VOLUME_ID     0x08 | 
|---|
| 85 | #define VFAT_ATTR_DIRECTORY     0x10 | 
|---|
| 86 | #define VFAT_ATTR_ARCHIVE       0x20 | 
|---|
| 87 | #define VFAT_ATTR_LONG_NAME     0x0F | 
|---|
| 88 |  | 
|---|
| 89 |  | 
|---|
| 90 | struct device_s; | 
|---|
| 91 | struct rwlock_s; | 
|---|
| 92 |  | 
|---|
| 93 |  | 
|---|
| 94 | struct vfat_inode_s | 
|---|
| 95 | { | 
|---|
| 96 | uint32_t flags; | 
|---|
| 97 | vfat_cluster_t first_cluster; | 
|---|
| 98 | }; | 
|---|
| 99 |  | 
|---|
| 100 | struct vfat_entry_request_s | 
|---|
| 101 | { | 
|---|
| 102 | struct vfat_DirEntry_s *entry; | 
|---|
| 103 | struct vfat_context_s *ctx; | 
|---|
| 104 | struct vfs_inode_s *parent; | 
|---|
| 105 | char *entry_name; | 
|---|
| 106 | uint_t *entry_index; | 
|---|
| 107 | }; | 
|---|
| 108 |  | 
|---|
| 109 | extern const struct vfs_inode_op_s vfat_i_op; | 
|---|
| 110 | extern const struct vfs_dirent_op_s vfat_d_op; | 
|---|
| 111 | extern const struct vfs_file_op_s vfat_f_op; | 
|---|
| 112 | extern const struct mapper_op_s vfat_file_mapper_op; | 
|---|
| 113 | extern const struct mapper_op_s vfat_inode_mapper_op; | 
|---|
| 114 |  | 
|---|
| 115 |  | 
|---|
| 116 | /** | 
|---|
| 117 | * Gives the LBA of the first sector of a vfat cluster. | 
|---|
| 118 | * | 
|---|
| 119 | * @ctx         vfat_context | 
|---|
| 120 | * @cluster     cluster to be converted | 
|---|
| 121 | */ | 
|---|
| 122 | #define VFAT_CONVERT_CLUSTER(ctx,cluster) (ctx)->cluster_begin_lba +    \ | 
|---|
| 123 | ((cluster) - 2) * (ctx)->sectors_per_cluster | 
|---|
| 124 |  | 
|---|
| 125 | int vfat_cluster_count(struct vfat_context_s *ctx, vfat_cluster_t cluster_index); | 
|---|
| 126 |  | 
|---|
| 127 | error_t vfat_query_fat(struct vfat_context_s* ctx, | 
|---|
| 128 | vfat_cluster_t cluster_index, | 
|---|
| 129 | vfat_cluster_t *next_cluster_index); | 
|---|
| 130 |  | 
|---|
| 131 | error_t vfat_alloc_fat_entry(struct vfat_context_s* ctx, | 
|---|
| 132 | vfat_cluster_t *new_cluster); | 
|---|
| 133 |  | 
|---|
| 134 | error_t vfat_extend_cluster(struct vfat_context_s* ctx, | 
|---|
| 135 | vfat_cluster_t current_vfat_cluster, | 
|---|
| 136 | vfat_cluster_t *next_cluster); | 
|---|
| 137 |  | 
|---|
| 138 | error_t vfat_free_fat_entry(struct vfat_context_s* ctx, | 
|---|
| 139 | vfat_cluster_t start_cluster); | 
|---|
| 140 |  | 
|---|
| 141 | error_t vfat_locate_entry(struct vfat_entry_request_s *rq); | 
|---|
| 142 |  | 
|---|
| 143 | inline void vfat_getshortname(char *from, char *to); | 
|---|
| 144 |  | 
|---|
| 145 | error_t vfat_cluster_lookup(struct vfat_context_s* ctx, | 
|---|
| 146 | vfat_cluster_t node_cluster, | 
|---|
| 147 | vfat_cluster_t cluster_rank, | 
|---|
| 148 | vfat_cluster_t *cluster_index, | 
|---|
| 149 | uint_t *extended); | 
|---|
| 150 |  | 
|---|
| 151 |  | 
|---|
| 152 | #if VFAT_INSTRUMENT | 
|---|
| 153 | extern uint32_t blk_rd_count; | 
|---|
| 154 | extern uint32_t rd_count; | 
|---|
| 155 | extern uint32_t wr_count; | 
|---|
| 156 | #endif | 
|---|
| 157 |  | 
|---|
| 158 |  | 
|---|
| 159 | #endif | 
|---|