jianfeng | 594baf1 | 2012-06-19 19:53:15 +0800 | [diff] [blame] | 1 | /* |
| 2 | *Copyright (c) 2012, The Linux Foundation. All rights reserved. |
| 3 | *Redistribution and use in source and binary forms, with or without |
| 4 | *modification, are permitted provided that the following conditions are |
| 5 | *met: |
| 6 | * Redistributions of source code must retain the above copyright |
| 7 | notice, this list of conditions and the following disclaimer. |
| 8 | * Redistributions in binary form must reproduce the above |
| 9 | copyright notice, this list of conditions and the following |
| 10 | disclaimer in the documentation and/or other materials provided |
| 11 | with the distribution. |
| 12 | * Neither the name of The Linux Foundation nor the names of its |
| 13 | contributors may be used to endorse or promote products derived |
| 14 | from this software without specific prior written permission. |
| 15 | |
| 16 | *THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED |
| 17 | *WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF |
| 18 | *MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT |
| 19 | *ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS |
| 20 | *BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
| 21 | *CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
| 22 | *SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR |
| 23 | *BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, |
| 24 | *WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE |
| 25 | *OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN |
| 26 | *IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE |
| 27 | */ |
| 28 | |
| 29 | #ifndef _FATCACHE_H_ |
| 30 | #define _FATCACHE_H_ |
| 31 | #include "dosfs.h" |
| 32 | #include "tree.h" |
| 33 | #include "stddef.h" |
| 34 | #include <cutils/log.h> |
| 35 | #include <android/log.h> |
| 36 | #define EMPTY_FAT (( struct cluster_chain_descriptor*)0) |
| 37 | #define EMPTY_CACHE (( struct fatcache*)0) |
| 38 | #define BIT(x,n) (((x)>>(n)) & 0x1) |
| 39 | #define SET_BIT(x,n) do{ \ |
| 40 | x |= 1<<n;}while(0) |
| 41 | #define CLEAR_BIT(x,n) do{ \ |
| 42 | x &= ~(1<<n);}while(0) |
| 43 | |
| 44 | /* |
| 45 | *print information when handle cluster chain |
| 46 | */ |
| 47 | #define FSCK_SLOGI(...) ((void)__android_log_buf_print(LOG_ID_SYSTEM, ANDROID_LOG_INFO,"fsck_msdos", __VA_ARGS__)) |
| 48 | #define FSCK_SLOGW(...) ((void)__android_log_buf_print(LOG_ID_SYSTEM, ANDROID_LOG_WARN,"fsck_msdos", __VA_ARGS__)) |
| 49 | #define FSCK_SLOGE(...) ((void)__android_log_buf_print(LOG_ID_SYSTEM, ANDROID_LOG_ERROR,"fsck_msdos", __VA_ARGS__)) |
| 50 | #define FSCK_SLOGD(...) ((void)__android_log_buf_print(LOG_ID_SYSTEM, ANDROID_LOG_DEBUG,"fsck_msdos", __VA_ARGS__)) |
| 51 | #define fsck_info FSCK_SLOGI |
| 52 | #define fsck_warn FSCK_SLOGW |
| 53 | #define fsck_err FSCK_SLOGE |
| 54 | #define fsck_debug FSCK_SLOGD |
Xiaogang Cui | bebe9b7 | 2014-07-22 14:34:39 +0800 | [diff] [blame] | 55 | |
| 56 | #ifndef offsetof |
jianfeng | 594baf1 | 2012-06-19 19:53:15 +0800 | [diff] [blame] | 57 | #define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *)0)->MEMBER) |
Xiaogang Cui | bebe9b7 | 2014-07-22 14:34:39 +0800 | [diff] [blame] | 58 | #endif |
| 59 | |
jianfeng | 594baf1 | 2012-06-19 19:53:15 +0800 | [diff] [blame] | 60 | #define container_of(ptr, type, member) \ |
| 61 | ((type *)((unsigned long)(ptr) - offsetof(type, member))) |
| 62 | int fsck_msdos_cache_compare(struct cluster_chain_descriptor *fat1,struct cluster_chain_descriptor *fat2); |
| 63 | RB_HEAD(FSCK_MSDOS_CACHE,cluster_chain_descriptor); |
Xiaogang Cui | bebe9b7 | 2014-07-22 14:34:39 +0800 | [diff] [blame] | 64 | struct cluster_chain_descriptor* FSCK_MSDOS_CACHE_RB_FIND(struct FSCK_MSDOS_CACHE* x, struct cluster_chain_descriptor *y); |
| 65 | struct cluster_chain_descriptor* FSCK_MSDOS_CACHE_RB_REMOVE(struct FSCK_MSDOS_CACHE* x, struct cluster_chain_descriptor *y); |
| 66 | struct cluster_chain_descriptor* FSCK_MSDOS_CACHE_RB_NEXT(struct cluster_chain_descriptor *y); |
| 67 | struct cluster_chain_descriptor* FSCK_MSDOS_CACHE_RB_INSERT(struct FSCK_MSDOS_CACHE* x, struct cluster_chain_descriptor *y); |
| 68 | struct cluster_chain_descriptor* FSCK_MSDOS_CACHE_RB_MINMAX(struct FSCK_MSDOS_CACHE* x, int val); |
jianfeng | 594baf1 | 2012-06-19 19:53:15 +0800 | [diff] [blame] | 69 | extern struct FSCK_MSDOS_CACHE rb_root; |
| 70 | extern unsigned int * fat_bitmap; |
| 71 | typedef unsigned char u_char; |
| 72 | /*if necessary ,we can find the nextclust from FAT table*/ |
| 73 | unsigned int GetNextClusFromFAT(struct bootblock *boot,u_char*fatable,unsigned int clust); |
| 74 | /*set the next cluster in FAT table*/ |
| 75 | void SetNextClusToFAT(struct bootblock*boot,u_char*fat ,unsigned int cl ,unsigned int next); |
| 76 | struct cluster_chain_descriptor* New_fatentry(void); |
| 77 | struct fatcache* New_fatcache(void); |
| 78 | /*insert an new fatcache to fatentry . if exist ,merge it*/ |
| 79 | int add_fatcache_To_ClusterChain(struct cluster_chain_descriptor *fatentry ,struct fatcache *new); |
| 80 | /*add an new fatcache to the tail of fatentry*/ |
| 81 | int add_fatcache_Totail(struct cluster_chain_descriptor *fatentry ,struct fatcache *new); |
| 82 | /*find the cache which the cl is belong to ,cache2 return the prev fatcache*/ |
| 83 | struct fatcache *Find_cache(struct cluster_chain_descriptor *fat,unsigned int cl,struct fatcache**cache2); |
| 84 | /*find the next cluster*/ |
| 85 | struct fatcache *Find_nextclus(struct cluster_chain_descriptor* fat,unsigned int clus, unsigned int* cl); |
| 86 | int delete_fatcache_below(struct cluster_chain_descriptor* fatentry,struct fatcache*cache); |
xiaogang | 45eb54c | 2013-05-16 10:29:23 -0700 | [diff] [blame] | 87 | void Trunc(struct bootblock *boot, struct cluster_chain_descriptor *fat, unsigned int cl); |
jianfeng | 594baf1 | 2012-06-19 19:53:15 +0800 | [diff] [blame] | 88 | void free_rb_tree(void); |
| 89 | /*for test*/ |
| 90 | void Dump_fatentry(struct cluster_chain_descriptor *fat); |
| 91 | #endif |