Changeset 611:5d49dff3c766
- Timestamp:
- 06/13/08 11:18:41 (7 months ago)
- Author:
- Maxime Petazzoni <maxime.petazzoni@…>
- Branch:
- default
- Message:
-
WIP on the best_overall
- Files:
-
Legend:
- Unmodified
- Added
- Removed
-
|
r610
|
r611
|
|
| 921 | 921 | |
| 922 | 922 | fs_err_t nx_fs_defrag_best_overall(void) { |
| 923 | | U32 hole_start = 0, next_hole = 0, freeblock_size = 0, next_origin = 0; |
| | 923 | U32 hole_start = 0, next_hole = 0, next_origin = 0; |
| 924 | 924 | U32 files, used, free_pages, wasted, mean_space_per_file = 0; |
| 925 | 925 | U32 i; |
| … |
… |
|
| 943 | 943 | |
| 944 | 944 | i = FS_PAGE_START; |
| | 945 | |
| | 946 | /* First, pull the first block at the beginning of the flash. */ |
| | 947 | if (nx_fs_find_next_origin(i, &next_origin) != FS_ERR_NO_ERROR) { |
| | 948 | return FS_ERR_NO_ERROR; |
| | 949 | } |
| | 950 | |
| | 951 | if (nx_fs_find_next_hole(next_origin, &hole_start) != FS_ERR_NO_ERROR) { |
| | 952 | hole_start = FS_PAGE_END-1; |
| | 953 | } |
| | 954 | |
| | 955 | nx_fs_move_region(next_origin, i, hole_start - next_origin); |
| | 956 | |
| 945 | 957 | while (i < FS_PAGE_END) { |
| 946 | 958 | if (nx_fs_page_has_magic(i)) { |
| 947 | | /* Calculate free space after file */ |
| | 959 | size_t hole_size; |
| | 960 | |
| | 961 | /* Calculate the size of the hole directly after this block. */ |
| 948 | 962 | nx_fs_find_next_hole(i, &hole_start); |
| 949 | 963 | nx_fs_find_next_origin(hole_start, &next_origin); |
| 950 | | freeblock_size = next_origin - hole_start; |
| 951 | | |
| 952 | | /* frag operations */ |
| 953 | | if (freeblock_size > mean_space_per_file) { |
| | 964 | hole_size = next_origin - hole_start; |
| | 965 | |
| | 966 | /* When the size of the hole following this file is greater than |
| | 967 | * what we want to put after it, move the rest of the current |
| | 968 | * block a bit forward to make room after this file. |
| | 969 | */ |
| | 970 | if (hole_size > mean_space_per_file) { |
| | 971 | // TODO |
| 954 | 972 | size_t size = nx_fs_get_file_size_from_metadata(metadata); |
| 955 | | nx_fs_move_region(i, hole_start + mean_space_per_file, |
| 956 | | nx_fs_get_file_page_count(size)); |
| 957 | | } else if (freeblock_size < mean_space_per_file) { |
| 958 | | nx_fs_find_next_hole(next_origin, &next_hole); |
| | 973 | nx_fs_move_region(i + size, mean_space_per_file, |
| | 974 | hole_start - i); |
| | 975 | } |
| | 976 | |
| | 977 | /* Otherwise, if the hole is smaller than what we want, move the |
| | 978 | * following block a bit forward, when possible. |
| | 979 | */ |
| | 980 | else if (hole_size < mean_space_per_file) { |
| | 981 | if (nx_fs_find_next_hole(next_origin, &next_hole) != FS_ERR_NO_ERROR) { |
| | 982 | /* We can't move the next block :/ */ |
| | 983 | return FS_ERR_NO_SPACE_LEFT_ON_DEVICE; /* TODO: ?? */ |
| | 984 | } |
| | 985 | |
| 959 | 986 | nx_fs_move_region(next_origin, hole_start + mean_space_per_file, |
| 960 | 987 | next_hole - next_origin); |