2 * Copyright (C) 2010 The Android Open Source Project
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
20 #define EXT4_ALLOCATE_FAILED (u32)(~0)
22 #include "ext4_utils/ext4_utils.h"
39 struct block_allocation {
40 struct region_list list;
41 struct region_list oob_list;
43 struct block_allocation* next;
46 struct block_group_info {
62 struct region *chunks;
65 void block_allocator_init();
66 void block_allocator_free();
68 struct block_allocation *allocate_blocks(u32 len);
69 int block_allocation_num_regions(struct block_allocation *alloc);
70 int block_allocation_len(struct block_allocation *alloc);
71 struct ext4_inode *get_inode(u32 inode);
72 struct ext4_xattr_header *get_xattr_block_for_inode(struct ext4_inode *inode);
73 void reduce_allocation(struct block_allocation *alloc, u32 len);
74 u32 get_block(struct block_allocation *alloc, u32 block);
75 u32 get_oob_block(struct block_allocation *alloc, u32 block);
76 void get_next_region(struct block_allocation *alloc);
77 void get_region(struct block_allocation *alloc, u32 *block, u32 *len);
78 u32 get_free_blocks(u32 bg);
79 u32 get_free_inodes(u32 bg);
80 u32 reserve_inodes(int bg, u32 inodes);
81 void add_directory(u32 inode);
82 u16 get_directories(int bg);
83 u16 get_bg_flags(int bg);
84 void init_unused_inode_tables(void);
86 void free_alloc(struct block_allocation *alloc);
87 int reserve_oob_blocks(struct block_allocation *alloc, int blocks);
88 int advance_blocks(struct block_allocation *alloc, int blocks);
89 int advance_oob_blocks(struct block_allocation *alloc, int blocks);
90 int last_region(struct block_allocation *alloc);
91 void rewind_alloc(struct block_allocation *alloc);
92 void append_region(struct block_allocation *alloc,
93 u32 block, u32 len, int bg);
94 struct block_allocation *create_allocation();
95 int append_oob_allocation(struct block_allocation *alloc, u32 len);
96 void region_list_append(struct region_list *list, struct region *reg);
97 void region_list_merge(struct region_list *list1, struct region_list *list2);
98 void print_blocks(FILE* f, struct block_allocation *alloc, char separator);
99 void reserve_bg_chunk(int bg, u32 start_block, u32 size);
100 int reserve_blocks_for_allocation(struct block_allocation *alloc);