📄 fdefrag.h
字号:
#ifndef _FAT1X_DEFRAG_H
#define _FAT1X_DEFRAG_H
struct defrag_dir {
unsigned short startCluster;
unsigned short parentCluster;
unsigned long block;
unsigned long entry;
};
/*************************************************************
Fuction : FAT_defrag
defrag FAT1x disk
// method
introduction:
1. Record all directories in defragDirList
2. Start defragging from root directory.
a) We move all entries upwards by removing all deleted entries
b) We defrag root directory entries, sorting every entry from
cluster number 2.
3. Then according to defragDirList, we go through the same
steps as we do to root directory. Finally, we update the cluster
values of '.' and '..' that might be swapped during defragging
4. Because we keep swapping and modifying fat tables from the above
three steps, we need to update fat tables by writing the fat buffer
back to flash.
ex: (original)
dir/file clusterNo
---------------------------------
\f1.txt 246
\f2.txt 247
\f3.txt 248
\4dos 249
\4dos\fat1x.txt 250
\4dos\abc 2
\4dos\abc\fat1x.txt 3, 4
ex: (after defragging)
dir/file clusterNo
---------------------------------
\f1.txt 2
\f2.txt 3
\f3.txt 4
\4dos 5
\4dos\fat1x.txt 6
\4dos\abc 7
\4dos\abc\fat1x.txt 8, 9
// method
Input:
Output:
0: no error is found
-1: error (see FATError)
**************************************************************/
int FAT_defrag(void);
/*************************************************************
Fuction : FAT_set_defragDirList
Record all the directories in the global variable "defragDirList"
(from root directory to all its subdirectories sorted in order)
Input:
drive - drive number
Output:
0: no error is found
-1: error (see FATError)
**************************************************************/
int FAT_set_defragDirList(short drive);
/*************************************************************
Fuction : FAT_defrag_root
defrag root directory
Input:
drive - drive number
Output:
0: no error is found
-1: error (see FATError)
**************************************************************/
int FAT_defrag_root(short drive);
/*************************************************************
Fuction : FAT_swap_cluster_data
swap the cluster data
Input:
drive - drive number
clusterNo1 - cluster number 1 that's going to be swapped
clusterNo2 - cluster number 2 that's going to be swapped
Output:
0: no error is found
-1: error (see FATError)
**************************************************************/
int FAT_swap_cluster_data(short drive, unsigned short clusterNo1, unsigned short clusterNo2);
/*************************************************************
Fuction : FAT_swap_fat_cluster
swap the cluster value in fat tables and directory entries
Input:
drive - drive number
clusterNo1 - cluster number 1 that's going to be swapped
clusterNo2 - cluster number 2 that's going to be swapped
Output:
0: no error is found
-1: error (see FATError)
**************************************************************/
int FAT_swap_fat_cluster(short drive, unsigned short clusterNo1, unsigned short clusterNo2);
/*************************************************************
Fuction : FAT_find_entry_location_by_startCluster
Search the block where startCluster value locates
Input:
drive - drive number
startCluster - cluster value that's going to be searched
Output:
0: no error is found
-1: error (see FATError)
block: the block number
entry: the entry in the block
isRoot: in the root directory?
**************************************************************/
int FAT_find_entry_location_by_startCluster(short drive, unsigned short startCluster, \
unsigned long *block, unsigned long *entry, int *isRoot);
/*************************************************************
Fuction : FAT_free_dirLinkList
free resources from directory linking list(defragDirList),
including the memory pointed to by the elementPointer
Input:
list - the pointer to the linking list
Output:
0: no error is found
-1: error (see FATError)
**************************************************************/
void FAT_free_dirLinkList(struct dLinkList *list);
/*************************************************************
Fuction : FAT_defrag_subdir
defrag all subdirectories
Input:
drive - drive number
Output:
0: no error is found
-1: error (see FATError)
**************************************************************/
int FAT_defrag_subdir(short drive);
/*************************************************************
Fuction : FAT_update_clustersInDefragList
update startCluster and parentCluster in defrag_dir if
they are swapped while defragging
Input:
swapClusterNo1 - cluster number 1 that's going to be swapped with swapClusterNo2
swapClusterNo2 - cluster number 2 that's going to be swapped with swapClusterNo1
Output:
**************************************************************/
void FAT_update_clustersInDefragList(unsigned short oldClusterNo, unsigned short newClusterNo);
/*************************************************************
Fuction : read_fat_cluster_from_fatBuffer
read cluster value from fat buffer
Input:
drive - drive number
clusterNo - the clusterNo-th entry in fat tables
Output:
the next cluster value
**************************************************************/
unsigned short read_fat_cluster_from_fatBuffer(short drive, unsigned short clusterNo);
/*************************************************************
Fuction : write_fat_cluster_to_fatBuffer
write cluster value to fat buffer
Input:
drive - drive number
clusterNo - the clusterNo-th entry in fat tables
cluster - the cluster value that's going to be written
Output:
**************************************************************/
void write_fat_cluster_to_fatBuffer(short drive, unsigned short clusterNo, unsigned short cluster);
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -