blob: 67af7c112270a45689ebd4f49129b8093ea14535 [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 *
Mohamad Ayyash95791982016-02-20 03:46:00 +00008 * http://www.apache.org/licenses/LICENSE-2.0
Colin Crossec0a2e82010-06-11 14:21:37 -07009 *
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
Tao Bao06ca8112016-10-05 12:44:18 -070022#include "ext4_utils/ext4_utils.h"
Colin Crossec0a2e82010-06-11 14:21:37 -070023
Mohamad Ayyash95791982016-02-20 03:46:00 +000024struct region {
25 u32 block;
26 u32 len;
27 int bg;
28 struct region *next;
29 struct region *prev;
30};
Doug Zongkerbec598e2014-08-12 11:35:37 -070031
32struct region_list {
33 struct region *first;
34 struct region *last;
35 struct region *iter;
36 u32 partial_iter;
37};
38
39struct block_allocation {
40 struct region_list list;
41 struct region_list oob_list;
42 char* filename;
43 struct block_allocation* next;
44};
45
Mohamad Ayyash95791982016-02-20 03:46:00 +000046struct block_group_info {
47 u32 first_block;
48 int header_blocks;
49 int data_blocks_used;
50 int has_superblock;
51 u8 *bitmaps;
52 u8 *block_bitmap;
53 u8 *inode_bitmap;
54 u8 *inode_table;
55 u32 free_blocks;
56 u32 free_inodes;
57 u32 first_free_inode;
58 u16 flags;
59 u16 used_dirs;
60 int chunk_count;
61 int max_chunk_count;
62 struct region *chunks;
63};
Colin Crossec0a2e82010-06-11 14:21:37 -070064
65void block_allocator_init();
66void block_allocator_free();
67u32 allocate_block();
68struct block_allocation *allocate_blocks(u32 len);
69int block_allocation_num_regions(struct block_allocation *alloc);
70int block_allocation_len(struct block_allocation *alloc);
71struct ext4_inode *get_inode(u32 inode);
Nick Kralevich4df62f32013-02-07 14:21:34 -080072struct ext4_xattr_header *get_xattr_block_for_inode(struct ext4_inode *inode);
Colin Crossec0a2e82010-06-11 14:21:37 -070073void reduce_allocation(struct block_allocation *alloc, u32 len);
74u32 get_block(struct block_allocation *alloc, u32 block);
75u32 get_oob_block(struct block_allocation *alloc, u32 block);
76void get_next_region(struct block_allocation *alloc);
77void get_region(struct block_allocation *alloc, u32 *block, u32 *len);
78u32 get_free_blocks(u32 bg);
79u32 get_free_inodes(u32 bg);
80u32 reserve_inodes(int bg, u32 inodes);
81void add_directory(u32 inode);
82u16 get_directories(int bg);
Colin Cross56497f22013-02-04 00:44:55 -080083u16 get_bg_flags(int bg);
Ken Sumrall107a9f12011-06-29 20:28:30 -070084void init_unused_inode_tables(void);
Colin Crossec0a2e82010-06-11 14:21:37 -070085u32 allocate_inode();
86void free_alloc(struct block_allocation *alloc);
87int reserve_oob_blocks(struct block_allocation *alloc, int blocks);
88int advance_blocks(struct block_allocation *alloc, int blocks);
89int advance_oob_blocks(struct block_allocation *alloc, int blocks);
90int last_region(struct block_allocation *alloc);
91void rewind_alloc(struct block_allocation *alloc);
92void append_region(struct block_allocation *alloc,
Colin Cross8aef66d2010-06-20 23:22:12 -070093 u32 block, u32 len, int bg);
Colin Crossec0a2e82010-06-11 14:21:37 -070094struct block_allocation *create_allocation();
95int append_oob_allocation(struct block_allocation *alloc, u32 len);
Mohamad Ayyash95791982016-02-20 03:46:00 +000096void region_list_append(struct region_list *list, struct region *reg);
Mohamad Ayyashf7124d62016-04-29 11:14:02 -070097void region_list_merge(struct region_list *list1, struct region_list *list2);
Mohamad Ayyash95791982016-02-20 03:46:00 +000098void print_blocks(FILE* f, struct block_allocation *alloc, char separator);
99void reserve_bg_chunk(int bg, u32 start_block, u32 size);
100int reserve_blocks_for_allocation(struct block_allocation *alloc);
Colin Cross33f96c62010-12-22 18:40:14 -0800101#endif