blob: 649c524f6123793614148e88a57e331854cf2df1 [file] [log] [blame]
Theodore Ts'o3839e651997-04-26 13:21:57 +00001/*
2 * bitmaps.c --- routines to read, write, and manipulate the inode and
3 * block bitmaps.
4 *
Theodore Ts'o21c84b71997-04-29 16:15:03 +00005 * Copyright (C) 1993, 1994, 1995, 1996 Theodore Ts'o.
6 *
7 * %Begin-Header%
Theodore Ts'o543547a2010-05-17 21:31:56 -04008 * This file may be redistributed under the terms of the GNU Library
9 * General Public License, version 2.
Theodore Ts'o21c84b71997-04-29 16:15:03 +000010 * %End-Header%
Theodore Ts'o3839e651997-04-26 13:21:57 +000011 */
12
13#include <stdio.h>
14#include <string.h>
Theodore Ts'o4cbe8af1997-08-10 23:07:40 +000015#if HAVE_UNISTD_H
Theodore Ts'o3839e651997-04-26 13:21:57 +000016#include <unistd.h>
Theodore Ts'o4cbe8af1997-08-10 23:07:40 +000017#endif
Theodore Ts'o3839e651997-04-26 13:21:57 +000018#include <fcntl.h>
19#include <time.h>
Theodore Ts'o1d2ff461997-10-19 23:00:21 +000020#if HAVE_SYS_STAT_H
Theodore Ts'o3839e651997-04-26 13:21:57 +000021#include <sys/stat.h>
Theodore Ts'o1d2ff461997-10-19 23:00:21 +000022#endif
23#if HAVE_SYS_TYPES_H
Theodore Ts'o3839e651997-04-26 13:21:57 +000024#include <sys/types.h>
Theodore Ts'o1d2ff461997-10-19 23:00:21 +000025#endif
Theodore Ts'o3839e651997-04-26 13:21:57 +000026
Theodore Ts'ob5abe6f1998-01-19 14:47:53 +000027#include "ext2_fs.h"
Theodore Ts'o3839e651997-04-26 13:21:57 +000028#include "ext2fs.h"
29
Theodore Ts'oa0553c92007-07-22 22:59:50 -040030void ext2fs_free_inode_bitmap(ext2fs_inode_bitmap bitmap)
Theodore Ts'o3839e651997-04-26 13:21:57 +000031{
Theodore Ts'oa0553c92007-07-22 22:59:50 -040032 ext2fs_free_generic_bitmap(bitmap);
Theodore Ts'o3839e651997-04-26 13:21:57 +000033}
34
Theodore Ts'oa0553c92007-07-22 22:59:50 -040035void ext2fs_free_block_bitmap(ext2fs_block_bitmap bitmap)
Theodore Ts'oa29f4d31997-04-29 21:26:48 +000036{
Theodore Ts'oa0553c92007-07-22 22:59:50 -040037 ext2fs_free_generic_bitmap(bitmap);
Theodore Ts'oa29f4d31997-04-29 21:26:48 +000038}
39
40errcode_t ext2fs_copy_bitmap(ext2fs_generic_bitmap src,
41 ext2fs_generic_bitmap *dest)
42{
Theodore Ts'oa0553c92007-07-22 22:59:50 -040043 return (ext2fs_copy_generic_bitmap(src, dest));
Theodore Ts'oa29f4d31997-04-29 21:26:48 +000044}
45
Theodore Ts'offf876b1997-09-13 00:32:29 +000046void ext2fs_set_bitmap_padding(ext2fs_generic_bitmap map)
47{
Theodore Ts'oa0553c92007-07-22 22:59:50 -040048 ext2fs_set_generic_bitmap_padding(map);
Theodore Ts'oefc6f622008-08-27 23:07:54 -040049}
Theodore Ts'oa29f4d31997-04-29 21:26:48 +000050
Theodore Ts'o1e3472c1997-04-29 14:53:37 +000051errcode_t ext2fs_allocate_inode_bitmap(ext2_filsys fs,
Theodore Ts'of3db3561997-04-26 13:34:30 +000052 const char *descr,
Theodore Ts'o1e3472c1997-04-29 14:53:37 +000053 ext2fs_inode_bitmap *ret)
Theodore Ts'o3839e651997-04-26 13:21:57 +000054{
Theodore Ts'o1e3472c1997-04-29 14:53:37 +000055 __u32 start, end, real_end;
Theodore Ts'of3db3561997-04-26 13:34:30 +000056
57 EXT2_CHECK_MAGIC(fs, EXT2_ET_MAGIC_EXT2FS_FILSYS);
Theodore Ts'o3839e651997-04-26 13:21:57 +000058
59 fs->write_bitmaps = ext2fs_write_bitmaps;
60
Theodore Ts'o1e3472c1997-04-29 14:53:37 +000061 start = 1;
62 end = fs->super->s_inodes_count;
63 real_end = (EXT2_INODES_PER_GROUP(fs->super) * fs->group_desc_count);
64
Theodore Ts'oa0553c92007-07-22 22:59:50 -040065 return (ext2fs_make_generic_bitmap(EXT2_ET_MAGIC_INODE_BITMAP, fs,
66 start, end, real_end,
67 descr, 0, ret));
Theodore Ts'o1e3472c1997-04-29 14:53:37 +000068}
69
70errcode_t ext2fs_allocate_block_bitmap(ext2_filsys fs,
71 const char *descr,
72 ext2fs_block_bitmap *ret)
73{
Theodore Ts'o1e3472c1997-04-29 14:53:37 +000074 __u32 start, end, real_end;
75
76 EXT2_CHECK_MAGIC(fs, EXT2_ET_MAGIC_EXT2FS_FILSYS);
77
78 fs->write_bitmaps = ext2fs_write_bitmaps;
79
80 start = fs->super->s_first_data_block;
81 end = fs->super->s_blocks_count-1;
Theodore Ts'oefc6f622008-08-27 23:07:54 -040082 real_end = (EXT2_BLOCKS_PER_GROUP(fs->super)
Theodore Ts'o1e3472c1997-04-29 14:53:37 +000083 * fs->group_desc_count)-1 + start;
Theodore Ts'oefc6f622008-08-27 23:07:54 -040084
Theodore Ts'oa0553c92007-07-22 22:59:50 -040085 return (ext2fs_make_generic_bitmap(EXT2_ET_MAGIC_BLOCK_BITMAP, fs,
86 start, end, real_end,
87 descr, 0, ret));
Theodore Ts'o3839e651997-04-26 13:21:57 +000088}
89
Theodore Ts'of3db3561997-04-26 13:34:30 +000090errcode_t ext2fs_fudge_inode_bitmap_end(ext2fs_inode_bitmap bitmap,
Theodore Ts'o31dbecd2001-01-11 04:54:39 +000091 ext2_ino_t end, ext2_ino_t *oend)
Theodore Ts'o3839e651997-04-26 13:21:57 +000092{
Theodore Ts'oa0553c92007-07-22 22:59:50 -040093
94 return (ext2fs_fudge_generic_bitmap_end(bitmap,
95 EXT2_ET_MAGIC_INODE_BITMAP,
96 EXT2_ET_FUDGE_INODE_BITMAP_END,
97 end, oend));
Theodore Ts'of3db3561997-04-26 13:34:30 +000098}
Theodore Ts'o3839e651997-04-26 13:21:57 +000099
Theodore Ts'of3db3561997-04-26 13:34:30 +0000100errcode_t ext2fs_fudge_block_bitmap_end(ext2fs_block_bitmap bitmap,
101 blk_t end, blk_t *oend)
102{
Theodore Ts'oa0553c92007-07-22 22:59:50 -0400103 return (ext2fs_fudge_generic_bitmap_end(bitmap,
104 EXT2_ET_MAGIC_BLOCK_BITMAP,
105 EXT2_ET_FUDGE_BLOCK_BITMAP_END,
106 end, oend));
Theodore Ts'of3db3561997-04-26 13:34:30 +0000107}
Theodore Ts'o3839e651997-04-26 13:21:57 +0000108
Theodore Ts'of3db3561997-04-26 13:34:30 +0000109void ext2fs_clear_inode_bitmap(ext2fs_inode_bitmap bitmap)
110{
Theodore Ts'oa0553c92007-07-22 22:59:50 -0400111 ext2fs_clear_generic_bitmap(bitmap);
Theodore Ts'of3db3561997-04-26 13:34:30 +0000112}
Theodore Ts'o3839e651997-04-26 13:21:57 +0000113
Theodore Ts'of3db3561997-04-26 13:34:30 +0000114void ext2fs_clear_block_bitmap(ext2fs_block_bitmap bitmap)
115{
Theodore Ts'oa0553c92007-07-22 22:59:50 -0400116 ext2fs_clear_generic_bitmap(bitmap);
Theodore Ts'of3db3561997-04-26 13:34:30 +0000117}
Theodore Ts'o50448d32007-07-22 23:42:14 -0400118
119errcode_t ext2fs_resize_inode_bitmap(__u32 new_end, __u32 new_real_end,
120 ext2fs_inode_bitmap bmap)
121{
122 return (ext2fs_resize_generic_bitmap(EXT2_ET_MAGIC_INODE_BITMAP,
123 new_end, new_real_end, bmap));
124}
125
126errcode_t ext2fs_resize_block_bitmap(__u32 new_end, __u32 new_real_end,
127 ext2fs_block_bitmap bmap)
128{
129 return (ext2fs_resize_generic_bitmap(EXT2_ET_MAGIC_BLOCK_BITMAP,
130 new_end, new_real_end, bmap));
131}
132
133errcode_t ext2fs_compare_block_bitmap(ext2fs_block_bitmap bm1,
134 ext2fs_block_bitmap bm2)
135{
136 return (ext2fs_compare_generic_bitmap(EXT2_ET_MAGIC_BLOCK_BITMAP,
137 EXT2_ET_NEQ_BLOCK_BITMAP,
138 bm1, bm2));
139}
140
141errcode_t ext2fs_compare_inode_bitmap(ext2fs_inode_bitmap bm1,
142 ext2fs_inode_bitmap bm2)
143{
144 return (ext2fs_compare_generic_bitmap(EXT2_ET_MAGIC_INODE_BITMAP,
145 EXT2_ET_NEQ_INODE_BITMAP,
146 bm1, bm2));
147}
148
Theodore Ts'of1f115a2007-07-23 04:32:48 -0400149errcode_t ext2fs_set_inode_bitmap_range(ext2fs_inode_bitmap bmap,
150 ext2_ino_t start, unsigned int num,
151 void *in)
152{
153 return (ext2fs_set_generic_bitmap_range(bmap,
154 EXT2_ET_MAGIC_INODE_BITMAP,
155 start, num, in));
156}
157
158errcode_t ext2fs_get_inode_bitmap_range(ext2fs_inode_bitmap bmap,
159 ext2_ino_t start, unsigned int num,
160 void *out)
161{
162 return (ext2fs_get_generic_bitmap_range(bmap,
163 EXT2_ET_MAGIC_INODE_BITMAP,
164 start, num, out));
165}
166
167errcode_t ext2fs_set_block_bitmap_range(ext2fs_block_bitmap bmap,
168 blk_t start, unsigned int num,
169 void *in)
170{
Theodore Ts'oefc6f622008-08-27 23:07:54 -0400171 return (ext2fs_set_generic_bitmap_range(bmap,
Theodore Ts'of1f115a2007-07-23 04:32:48 -0400172 EXT2_ET_MAGIC_BLOCK_BITMAP,
173 start, num, in));
174}
175
176errcode_t ext2fs_get_block_bitmap_range(ext2fs_block_bitmap bmap,
177 blk_t start, unsigned int num,
178 void *out)
179{
180 return (ext2fs_get_generic_bitmap_range(bmap,
181 EXT2_ET_MAGIC_BLOCK_BITMAP,
182 start, num, out));
183}