blob: 6db35a6807cd056613678dc760f290d0066c239d [file] [log] [blame]
jianfeng594baf12012-06-19 19:53:15 +08001/*
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 Cuibebe9b72014-07-22 14:34:39 +080055
56#ifndef offsetof
jianfeng594baf12012-06-19 19:53:15 +080057#define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *)0)->MEMBER)
Xiaogang Cuibebe9b72014-07-22 14:34:39 +080058#endif
59
jianfeng594baf12012-06-19 19:53:15 +080060#define container_of(ptr, type, member) \
61 ((type *)((unsigned long)(ptr) - offsetof(type, member)))
62int fsck_msdos_cache_compare(struct cluster_chain_descriptor *fat1,struct cluster_chain_descriptor *fat2);
63RB_HEAD(FSCK_MSDOS_CACHE,cluster_chain_descriptor);
Xiaogang Cuibebe9b72014-07-22 14:34:39 +080064struct cluster_chain_descriptor* FSCK_MSDOS_CACHE_RB_FIND(struct FSCK_MSDOS_CACHE* x, struct cluster_chain_descriptor *y);
65struct cluster_chain_descriptor* FSCK_MSDOS_CACHE_RB_REMOVE(struct FSCK_MSDOS_CACHE* x, struct cluster_chain_descriptor *y);
66struct cluster_chain_descriptor* FSCK_MSDOS_CACHE_RB_NEXT(struct cluster_chain_descriptor *y);
67struct cluster_chain_descriptor* FSCK_MSDOS_CACHE_RB_INSERT(struct FSCK_MSDOS_CACHE* x, struct cluster_chain_descriptor *y);
68struct cluster_chain_descriptor* FSCK_MSDOS_CACHE_RB_MINMAX(struct FSCK_MSDOS_CACHE* x, int val);
jianfeng594baf12012-06-19 19:53:15 +080069extern struct FSCK_MSDOS_CACHE rb_root;
70extern unsigned int * fat_bitmap;
71typedef unsigned char u_char;
72/*if necessary ,we can find the nextclust from FAT table*/
73unsigned int GetNextClusFromFAT(struct bootblock *boot,u_char*fatable,unsigned int clust);
74/*set the next cluster in FAT table*/
75void SetNextClusToFAT(struct bootblock*boot,u_char*fat ,unsigned int cl ,unsigned int next);
76struct cluster_chain_descriptor* New_fatentry(void);
77struct fatcache* New_fatcache(void);
78/*insert an new fatcache to fatentry . if exist ,merge it*/
79int add_fatcache_To_ClusterChain(struct cluster_chain_descriptor *fatentry ,struct fatcache *new);
80/*add an new fatcache to the tail of fatentry*/
81int 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*/
83struct fatcache *Find_cache(struct cluster_chain_descriptor *fat,unsigned int cl,struct fatcache**cache2);
84/*find the next cluster*/
85struct fatcache *Find_nextclus(struct cluster_chain_descriptor* fat,unsigned int clus, unsigned int* cl);
86int delete_fatcache_below(struct cluster_chain_descriptor* fatentry,struct fatcache*cache);
xiaogang45eb54c2013-05-16 10:29:23 -070087void Trunc(struct bootblock *boot, struct cluster_chain_descriptor *fat, unsigned int cl);
jianfeng594baf12012-06-19 19:53:15 +080088void free_rb_tree(void);
89/*for test*/
90void Dump_fatentry(struct cluster_chain_descriptor *fat);
91#endif