blob: e6c2849144d2213e87ce93a7c373720d1aba4424 [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%
8 * This file may be redistributed under the terms of the GNU Public
9 * License.
10 * %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'offf876b1997-09-13 00:32:29 +000049}
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 errcode_t retval;
56 __u32 start, end, real_end;
Theodore Ts'of3db3561997-04-26 13:34:30 +000057
58 EXT2_CHECK_MAGIC(fs, EXT2_ET_MAGIC_EXT2FS_FILSYS);
Theodore Ts'o3839e651997-04-26 13:21:57 +000059
60 fs->write_bitmaps = ext2fs_write_bitmaps;
61
Theodore Ts'o1e3472c1997-04-29 14:53:37 +000062 start = 1;
63 end = fs->super->s_inodes_count;
64 real_end = (EXT2_INODES_PER_GROUP(fs->super) * fs->group_desc_count);
65
Theodore Ts'oa0553c92007-07-22 22:59:50 -040066 return (ext2fs_make_generic_bitmap(EXT2_ET_MAGIC_INODE_BITMAP, fs,
67 start, end, real_end,
68 descr, 0, ret));
Theodore Ts'o1e3472c1997-04-29 14:53:37 +000069}
70
71errcode_t ext2fs_allocate_block_bitmap(ext2_filsys fs,
72 const char *descr,
73 ext2fs_block_bitmap *ret)
74{
Theodore Ts'o1e3472c1997-04-29 14:53:37 +000075 errcode_t retval;
76 __u32 start, end, real_end;
77
78 EXT2_CHECK_MAGIC(fs, EXT2_ET_MAGIC_EXT2FS_FILSYS);
79
80 fs->write_bitmaps = ext2fs_write_bitmaps;
81
82 start = fs->super->s_first_data_block;
83 end = fs->super->s_blocks_count-1;
84 real_end = (EXT2_BLOCKS_PER_GROUP(fs->super)
85 * fs->group_desc_count)-1 + start;
86
Theodore Ts'oa0553c92007-07-22 22:59:50 -040087 return (ext2fs_make_generic_bitmap(EXT2_ET_MAGIC_BLOCK_BITMAP, fs,
88 start, end, real_end,
89 descr, 0, ret));
Theodore Ts'o3839e651997-04-26 13:21:57 +000090}
91
Theodore Ts'of3db3561997-04-26 13:34:30 +000092errcode_t ext2fs_fudge_inode_bitmap_end(ext2fs_inode_bitmap bitmap,
Theodore Ts'o31dbecd2001-01-11 04:54:39 +000093 ext2_ino_t end, ext2_ino_t *oend)
Theodore Ts'o3839e651997-04-26 13:21:57 +000094{
Theodore Ts'oa0553c92007-07-22 22:59:50 -040095
96 return (ext2fs_fudge_generic_bitmap_end(bitmap,
97 EXT2_ET_MAGIC_INODE_BITMAP,
98 EXT2_ET_FUDGE_INODE_BITMAP_END,
99 end, oend));
Theodore Ts'of3db3561997-04-26 13:34:30 +0000100}
Theodore Ts'o3839e651997-04-26 13:21:57 +0000101
Theodore Ts'of3db3561997-04-26 13:34:30 +0000102errcode_t ext2fs_fudge_block_bitmap_end(ext2fs_block_bitmap bitmap,
103 blk_t end, blk_t *oend)
104{
Theodore Ts'oa0553c92007-07-22 22:59:50 -0400105 return (ext2fs_fudge_generic_bitmap_end(bitmap,
106 EXT2_ET_MAGIC_BLOCK_BITMAP,
107 EXT2_ET_FUDGE_BLOCK_BITMAP_END,
108 end, oend));
Theodore Ts'of3db3561997-04-26 13:34:30 +0000109}
Theodore Ts'o3839e651997-04-26 13:21:57 +0000110
Theodore Ts'of3db3561997-04-26 13:34:30 +0000111void ext2fs_clear_inode_bitmap(ext2fs_inode_bitmap bitmap)
112{
Theodore Ts'oa0553c92007-07-22 22:59:50 -0400113 ext2fs_clear_generic_bitmap(bitmap);
Theodore Ts'of3db3561997-04-26 13:34:30 +0000114}
Theodore Ts'o3839e651997-04-26 13:21:57 +0000115
Theodore Ts'of3db3561997-04-26 13:34:30 +0000116void ext2fs_clear_block_bitmap(ext2fs_block_bitmap bitmap)
117{
Theodore Ts'oa0553c92007-07-22 22:59:50 -0400118 ext2fs_clear_generic_bitmap(bitmap);
Theodore Ts'of3db3561997-04-26 13:34:30 +0000119}