blob: 5c26792cd439309fb97a2785b46a04ed4cb1426a [file] [log] [blame]
Colin Crossec0a2e82010-06-11 14:21:37 -07001/*
2 * Copyright (C) 2010 The Android Open Source Project
3 *
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
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
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.
15 */
16
Colin Cross33f96c62010-12-22 18:40:14 -080017#ifndef _ALLOCATE_H_
18#define _ALLOCATE_H_
19
Colin Crossec0a2e82010-06-11 14:21:37 -070020#define EXT4_ALLOCATE_FAILED (u32)(~0)
21
22#include "ext4_utils.h"
Colin Crossec0a2e82010-06-11 14:21:37 -070023
Doug Zongkerbec598e2014-08-12 11:35:37 -070024struct region;
25
26struct region_list {
27 struct region *first;
28 struct region *last;
29 struct region *iter;
30 u32 partial_iter;
31};
32
33struct block_allocation {
34 struct region_list list;
35 struct region_list oob_list;
36 char* filename;
37 struct block_allocation* next;
38};
39
Colin Crossec0a2e82010-06-11 14:21:37 -070040
41void block_allocator_init();
42void block_allocator_free();
43u32 allocate_block();
44struct block_allocation *allocate_blocks(u32 len);
45int block_allocation_num_regions(struct block_allocation *alloc);
46int block_allocation_len(struct block_allocation *alloc);
47struct ext4_inode *get_inode(u32 inode);
Nick Kralevich4df62f32013-02-07 14:21:34 -080048struct ext4_xattr_header *get_xattr_block_for_inode(struct ext4_inode *inode);
Colin Crossec0a2e82010-06-11 14:21:37 -070049void reduce_allocation(struct block_allocation *alloc, u32 len);
50u32 get_block(struct block_allocation *alloc, u32 block);
51u32 get_oob_block(struct block_allocation *alloc, u32 block);
52void get_next_region(struct block_allocation *alloc);
53void get_region(struct block_allocation *alloc, u32 *block, u32 *len);
54u32 get_free_blocks(u32 bg);
55u32 get_free_inodes(u32 bg);
56u32 reserve_inodes(int bg, u32 inodes);
57void add_directory(u32 inode);
58u16 get_directories(int bg);
Colin Cross56497f22013-02-04 00:44:55 -080059u16 get_bg_flags(int bg);
Ken Sumrall107a9f12011-06-29 20:28:30 -070060void init_unused_inode_tables(void);
Colin Crossec0a2e82010-06-11 14:21:37 -070061u32 allocate_inode();
62void free_alloc(struct block_allocation *alloc);
63int reserve_oob_blocks(struct block_allocation *alloc, int blocks);
64int advance_blocks(struct block_allocation *alloc, int blocks);
65int advance_oob_blocks(struct block_allocation *alloc, int blocks);
66int last_region(struct block_allocation *alloc);
67void rewind_alloc(struct block_allocation *alloc);
68void append_region(struct block_allocation *alloc,
Colin Cross8aef66d2010-06-20 23:22:12 -070069 u32 block, u32 len, int bg);
Colin Crossec0a2e82010-06-11 14:21:37 -070070struct block_allocation *create_allocation();
71int append_oob_allocation(struct block_allocation *alloc, u32 len);
Doug Zongkerbec598e2014-08-12 11:35:37 -070072void print_blocks(FILE* f, struct block_allocation *alloc);
Colin Cross33f96c62010-12-22 18:40:14 -080073
74#endif