1997-04-26 17:34:30 +04:00
|
|
|
/*
|
|
|
|
* rw_bitmaps.c --- routines to read and write the inode and block bitmaps.
|
|
|
|
*
|
1997-04-29 20:17:09 +04:00
|
|
|
* Copyright (C) 1993, 1994, 1994, 1996 Theodore Ts'o.
|
|
|
|
*
|
|
|
|
* %Begin-Header%
|
|
|
|
* This file may be redistributed under the terms of the GNU Public
|
|
|
|
* License.
|
|
|
|
* %End-Header%
|
1997-04-26 17:34:30 +04:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
1997-08-11 03:07:40 +04:00
|
|
|
#if HAVE_UNISTD_H
|
1997-04-26 17:34:30 +04:00
|
|
|
#include <unistd.h>
|
1997-08-11 03:07:40 +04:00
|
|
|
#endif
|
1997-04-26 17:34:30 +04:00
|
|
|
#include <fcntl.h>
|
|
|
|
#include <time.h>
|
1997-10-20 04:52:43 +04:00
|
|
|
#ifdef HAVE_SYS_STAT_H
|
1997-04-26 17:34:30 +04:00
|
|
|
#include <sys/stat.h>
|
1997-10-20 04:52:43 +04:00
|
|
|
#endif
|
|
|
|
#ifdef HAVE_SYS_TYPES_H
|
1997-04-26 17:34:30 +04:00
|
|
|
#include <sys/types.h>
|
1997-10-20 04:52:43 +04:00
|
|
|
#endif
|
1997-04-26 17:34:30 +04:00
|
|
|
|
Many files:
inode.c (ext2fs_open_inode_scan): Initialize the group variables
so that we don't need to call get_next_blockgroup() the first
time around. Saves a bit of time, and prevents us from
needing to assign -1 to current_group (which is an unsigned
value).
icount.c (insert_icount_el): Cast the estimated number of inodes
from a float to an ino_t.
alloc.c, alloc_tables.c, badlbocks.c, bb_compat.c, bb_inode.c,
bitmaps.c, bitops.c, block.c, bmap.c, bmove.c, brel_ma.c,
check_desc.c, closefs.c, cmp_bitmaps.c, dblist.c,
dblist_dir.c, dir_iterate.c, dirblock.c, dupfs.c, expanddir.c,
ext2fs.h, fileio.c, freefs.c, get_pathname.c, getsize.c,
icount.c, initialize.c, inline.c, inode.c, irel_ma.c,
ismounted.c, link.c, lookup.c, mkdir.c, namei.c, native.c,
newdir.c, openfs.c, read_bb.c, read_bb_file.c, rs_bitmap.c,
rw_bitmaps.c, swapfs.c, test_io.c, tst_badblocks.c,
tst_getsize.c, tst_iscan.c, unix_io.c, unlink.c, valid_blk.c,
version.c: If EXT2_FLAT_INCLUDES is defined, then assume all
of the ext2-specific header files are in a flat directory.
block.c, bmove.c, dirblock.c, fileio.c: Explicitly cast
all assignments from void * to be compatible with C++.
closefs.c (ext2fs_flush): Add a call to io_channel_flush() to
make sure the contents of the disk are flushed to disk.
dblist.c (ext2fs_add_dir_block): Change new to be new_entry to
avoid C++ namespace clash.
bitmaps.c (ext2fs_copy_bitmap): Change new to be new_map to
avoid C++ namespace clash.
ext2fs.h, bb_inode.c, block.c, bmove.c, brel.h, brel_ma.c,
irel.h, irel_ma.c, dblist.c, dblist_dir.c, dir_iterate.c,
ext2fsP.h, expanddir.c, get_pathname.c, inode.c, link.c,
unlink.c: Change private to be priv_data (to avoid C++
namespace clash)
1998-01-19 17:47:53 +03:00
|
|
|
#include "ext2_fs.h"
|
1997-04-26 17:34:30 +04:00
|
|
|
#include "ext2fs.h"
|
2001-05-03 08:02:29 +04:00
|
|
|
#include "e2image.h"
|
1997-04-26 17:34:30 +04:00
|
|
|
|
ChangeLog, Makefile.in, swapfs.c, unix.c:
Makefile.in: Add message.c and swapfs.c to the list of source files to
build the make depend.
swapfs.c, unix.c: Only support the -s and -S options to e2fsck if
ENABLE_SWAPFS is defined.
Many files:
ext2fs.h, bitops.h, block.c, bmap.c, closefs.c, dirblock.c, inode.c,
native.c, openfs.c, rw_bitmaps.c, swapfs.c: Only include the
byte-swapping logic if ENABLE_SWAPFS is turned on or if we're on a
big-endian machine.
initialize.c (ext2fs_initialize):Use WORDS_BIGENDIAN directly to set
EXT2_FLAG_SWAP_BYTES, instead of using ext2fs_native_flag.
native.c (ext2fs_native_flag): Use WORDS_BIGENDIAN provided by
autoconf to determine whether or not return EXT2_FLAG_SWAP_BYTES.
2001-06-11 11:00:04 +04:00
|
|
|
#if defined(__powerpc__) && defined(EXT2FS_ENABLE_SWAPFS)
|
ChangeLog, .del-io.h~72680822, irel_ma.c, llseek.c, rw_bitmaps.c:
io.h: Change the prototype of ext2fs_llseek() to use int's instead of
unsigned int's.
llseek.c: Change to allow PIC and !HAVE_LLSEEK. Add a prototype to
make life easer for GNU Libc 2.
rw_bitmaps.c: On the PowerPC, the big-endian variant of the ext2
filesystem has its bitmaps stored as 32-bit words with bit 0 as the
LSB of each word. Thus a bitmap with only bit 0 set would be, as a
string of bytes, 00 00 00 01 00 ... To cope with this, we
byte-reverse each word of a bitmap if we have a big-endian filesystem,
that is, if we are *not* byte-swapping other word-sized numbers.
ChangeLog, expect.1, image.gz:
f_badinode: Modify test to check for "bad" character and block devices
(i.e., ones which contain garbage block entries)
1997-08-14 21:20:42 +04:00
|
|
|
/*
|
|
|
|
* On the PowerPC, the big-endian variant of the ext2 filesystem
|
|
|
|
* has its bitmaps stored as 32-bit words with bit 0 as the LSB
|
|
|
|
* of each word. Thus a bitmap with only bit 0 set would be, as
|
|
|
|
* a string of bytes, 00 00 00 01 00 ...
|
|
|
|
* To cope with this, we byte-reverse each word of a bitmap if
|
|
|
|
* we have a big-endian filesystem, that is, if we are *not*
|
|
|
|
* byte-swapping other word-sized numbers.
|
|
|
|
*/
|
|
|
|
#define EXT2_BIG_ENDIAN_BITMAPS
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef EXT2_BIG_ENDIAN_BITMAPS
|
2002-10-03 06:07:17 +04:00
|
|
|
static void ext2fs_swap_bitmap(ext2_filsys fs, char *bitmap, int nbytes)
|
ChangeLog, .del-io.h~72680822, irel_ma.c, llseek.c, rw_bitmaps.c:
io.h: Change the prototype of ext2fs_llseek() to use int's instead of
unsigned int's.
llseek.c: Change to allow PIC and !HAVE_LLSEEK. Add a prototype to
make life easer for GNU Libc 2.
rw_bitmaps.c: On the PowerPC, the big-endian variant of the ext2
filesystem has its bitmaps stored as 32-bit words with bit 0 as the
LSB of each word. Thus a bitmap with only bit 0 set would be, as a
string of bytes, 00 00 00 01 00 ... To cope with this, we
byte-reverse each word of a bitmap if we have a big-endian filesystem,
that is, if we are *not* byte-swapping other word-sized numbers.
ChangeLog, expect.1, image.gz:
f_badinode: Modify test to check for "bad" character and block devices
(i.e., ones which contain garbage block entries)
1997-08-14 21:20:42 +04:00
|
|
|
{
|
|
|
|
__u32 *p = (__u32 *) bitmap;
|
|
|
|
int n;
|
|
|
|
|
|
|
|
for (n = nbytes / sizeof(__u32); n > 0; --n, ++p)
|
|
|
|
*p = ext2fs_swab32(*p);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2006-04-23 20:43:40 +04:00
|
|
|
static errcode_t write_bitmaps(ext2_filsys fs, int do_inode, int do_block)
|
1997-04-26 17:34:30 +04:00
|
|
|
{
|
1998-09-03 05:22:57 +04:00
|
|
|
dgrp_t i;
|
2003-12-07 09:28:50 +03:00
|
|
|
unsigned int j;
|
2006-04-23 20:43:40 +04:00
|
|
|
int block_nbytes, inode_nbytes;
|
2003-12-07 09:28:50 +03:00
|
|
|
unsigned int nbits;
|
1997-04-26 17:34:30 +04:00
|
|
|
errcode_t retval;
|
2006-04-23 20:43:40 +04:00
|
|
|
char *block_bitmap, *inode_bitmap;
|
|
|
|
char *block_buf, *inode_buf;
|
2006-05-09 04:17:26 +04:00
|
|
|
int lazy_flag = 0;
|
1997-04-29 20:17:09 +04:00
|
|
|
blk_t blk;
|
1997-04-26 17:34:30 +04:00
|
|
|
|
|
|
|
EXT2_CHECK_MAGIC(fs, EXT2_ET_MAGIC_EXT2FS_FILSYS);
|
|
|
|
|
|
|
|
if (!(fs->flags & EXT2_FLAG_RW))
|
|
|
|
return EXT2_ET_RO_FILSYS;
|
2006-05-09 04:17:26 +04:00
|
|
|
if (EXT2_HAS_COMPAT_FEATURE(fs->super,
|
|
|
|
EXT2_FEATURE_COMPAT_LAZY_BG))
|
|
|
|
lazy_flag = 1;
|
2006-04-23 20:43:40 +04:00
|
|
|
inode_nbytes = block_nbytes = 0;
|
|
|
|
block_bitmap = inode_bitmap = 0;
|
|
|
|
if (do_block) {
|
|
|
|
block_bitmap = fs->block_map->bitmap;
|
|
|
|
block_nbytes = EXT2_BLOCKS_PER_GROUP(fs->super) / 8;
|
|
|
|
retval = ext2fs_get_mem(fs->blocksize, &block_buf);
|
|
|
|
if (retval)
|
|
|
|
return retval;
|
|
|
|
memset(block_buf, 0xff, fs->blocksize);
|
|
|
|
}
|
|
|
|
if (do_inode) {
|
|
|
|
inode_bitmap = fs->inode_map->bitmap;
|
|
|
|
inode_nbytes = (size_t)
|
|
|
|
((EXT2_INODES_PER_GROUP(fs->super)+7) / 8);
|
|
|
|
retval = ext2fs_get_mem(fs->blocksize, &inode_buf);
|
|
|
|
if (retval)
|
|
|
|
return retval;
|
|
|
|
memset(inode_buf, 0xff, fs->blocksize);
|
|
|
|
}
|
|
|
|
|
1997-04-26 17:34:30 +04:00
|
|
|
for (i = 0; i < fs->group_desc_count; i++) {
|
2006-04-23 20:43:40 +04:00
|
|
|
if (!block_bitmap || !do_block)
|
|
|
|
goto skip_block_bitmap;
|
2006-05-09 04:17:26 +04:00
|
|
|
|
|
|
|
if (lazy_flag && fs->group_desc[i].bg_flags &
|
|
|
|
EXT2_BG_BLOCK_UNINIT)
|
|
|
|
goto skip_this_block_bitmap;
|
2006-04-23 20:43:40 +04:00
|
|
|
|
|
|
|
memcpy(block_buf, block_bitmap, block_nbytes);
|
1997-04-26 17:34:30 +04:00
|
|
|
if (i == fs->group_desc_count - 1) {
|
|
|
|
/* Force bitmap padding for the last group */
|
2003-12-07 09:28:50 +03:00
|
|
|
nbits = ((fs->super->s_blocks_count
|
|
|
|
- fs->super->s_first_data_block)
|
|
|
|
% EXT2_BLOCKS_PER_GROUP(fs->super));
|
1997-04-26 17:34:30 +04:00
|
|
|
if (nbits)
|
|
|
|
for (j = nbits; j < fs->blocksize * 8; j++)
|
2006-04-23 20:43:40 +04:00
|
|
|
ext2fs_set_bit(j, block_buf);
|
1997-04-26 17:34:30 +04:00
|
|
|
}
|
1997-04-29 20:17:09 +04:00
|
|
|
blk = fs->group_desc[i].bg_block_bitmap;
|
|
|
|
if (blk) {
|
ChangeLog, .del-io.h~72680822, irel_ma.c, llseek.c, rw_bitmaps.c:
io.h: Change the prototype of ext2fs_llseek() to use int's instead of
unsigned int's.
llseek.c: Change to allow PIC and !HAVE_LLSEEK. Add a prototype to
make life easer for GNU Libc 2.
rw_bitmaps.c: On the PowerPC, the big-endian variant of the ext2
filesystem has its bitmaps stored as 32-bit words with bit 0 as the
LSB of each word. Thus a bitmap with only bit 0 set would be, as a
string of bytes, 00 00 00 01 00 ... To cope with this, we
byte-reverse each word of a bitmap if we have a big-endian filesystem,
that is, if we are *not* byte-swapping other word-sized numbers.
ChangeLog, expect.1, image.gz:
f_badinode: Modify test to check for "bad" character and block devices
(i.e., ones which contain garbage block entries)
1997-08-14 21:20:42 +04:00
|
|
|
#ifdef EXT2_BIG_ENDIAN_BITMAPS
|
|
|
|
if (!((fs->flags & EXT2_FLAG_SWAP_BYTES) ||
|
|
|
|
(fs->flags & EXT2_FLAG_SWAP_BYTES_WRITE)))
|
2006-04-23 20:43:40 +04:00
|
|
|
ext2fs_swap_bitmap(fs, block_buf,
|
|
|
|
block_nbytes);
|
ChangeLog, .del-io.h~72680822, irel_ma.c, llseek.c, rw_bitmaps.c:
io.h: Change the prototype of ext2fs_llseek() to use int's instead of
unsigned int's.
llseek.c: Change to allow PIC and !HAVE_LLSEEK. Add a prototype to
make life easer for GNU Libc 2.
rw_bitmaps.c: On the PowerPC, the big-endian variant of the ext2
filesystem has its bitmaps stored as 32-bit words with bit 0 as the
LSB of each word. Thus a bitmap with only bit 0 set would be, as a
string of bytes, 00 00 00 01 00 ... To cope with this, we
byte-reverse each word of a bitmap if we have a big-endian filesystem,
that is, if we are *not* byte-swapping other word-sized numbers.
ChangeLog, expect.1, image.gz:
f_badinode: Modify test to check for "bad" character and block devices
(i.e., ones which contain garbage block entries)
1997-08-14 21:20:42 +04:00
|
|
|
#endif
|
1997-04-29 20:17:09 +04:00
|
|
|
retval = io_channel_write_blk(fs->io, blk, 1,
|
2006-04-23 20:43:40 +04:00
|
|
|
block_buf);
|
1997-04-29 20:17:09 +04:00
|
|
|
if (retval)
|
|
|
|
return EXT2_ET_BLOCK_BITMAP_WRITE;
|
|
|
|
}
|
2006-05-09 04:17:26 +04:00
|
|
|
skip_this_block_bitmap:
|
2006-04-23 20:43:40 +04:00
|
|
|
block_bitmap += block_nbytes;
|
|
|
|
skip_block_bitmap:
|
|
|
|
|
|
|
|
if (!inode_bitmap || !do_inode)
|
|
|
|
continue;
|
|
|
|
|
2006-05-09 04:17:26 +04:00
|
|
|
if (lazy_flag && fs->group_desc[i].bg_flags &
|
|
|
|
EXT2_BG_INODE_UNINIT)
|
|
|
|
goto skip_this_inode_bitmap;
|
|
|
|
|
2006-04-23 20:43:40 +04:00
|
|
|
memcpy(inode_buf, inode_bitmap, inode_nbytes);
|
|
|
|
blk = fs->group_desc[i].bg_inode_bitmap;
|
|
|
|
if (blk) {
|
|
|
|
#ifdef EXT2_BIG_ENDIAN_BITMAPS
|
|
|
|
if (!((fs->flags & EXT2_FLAG_SWAP_BYTES) ||
|
|
|
|
(fs->flags & EXT2_FLAG_SWAP_BYTES_WRITE)))
|
|
|
|
ext2fs_swap_bitmap(fs, inode_buf,
|
|
|
|
inode_nbytes);
|
|
|
|
#endif
|
|
|
|
retval = io_channel_write_blk(fs->io, blk, 1,
|
|
|
|
inode_buf);
|
|
|
|
if (retval)
|
|
|
|
return EXT2_ET_INODE_BITMAP_WRITE;
|
|
|
|
}
|
2006-05-09 04:17:26 +04:00
|
|
|
skip_this_inode_bitmap:
|
2006-04-23 20:43:40 +04:00
|
|
|
inode_bitmap += inode_nbytes;
|
|
|
|
|
|
|
|
}
|
|
|
|
if (do_block) {
|
|
|
|
fs->flags &= ~EXT2_FLAG_BB_DIRTY;
|
|
|
|
ext2fs_free_mem(&block_buf);
|
|
|
|
}
|
|
|
|
if (do_inode) {
|
|
|
|
fs->flags &= ~EXT2_FLAG_IB_DIRTY;
|
|
|
|
ext2fs_free_mem(&inode_buf);
|
1997-04-26 17:34:30 +04:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static errcode_t read_bitmaps(ext2_filsys fs, int do_inode, int do_block)
|
|
|
|
{
|
1998-09-03 05:22:57 +04:00
|
|
|
dgrp_t i;
|
1997-04-26 17:58:21 +04:00
|
|
|
char *block_bitmap = 0, *inode_bitmap = 0;
|
1997-04-26 17:34:30 +04:00
|
|
|
char *buf;
|
|
|
|
errcode_t retval;
|
Many files:
dosio.c: New file to do DOS/BIOS disk accesses.
namei.c (open_namei): Make pathlen be of type size_t.
llseek.c: Always #include stdlib.h since it's need to define
size_t.
io.h: Use errcode_t for magic numbers.
icount.c (get_icount_el), dupfs.c (ext2fs_dup_handle), dblist.c
(dir_block_cmp): Use size_t where appropriate.
read_bb.c (ext2fs_read_bb_inode), cmp_bitmaps.c
(ext2fs_compare_inode_bitmap): Use blk_t, ino_t and size_t
where appropriate.
closefs.c (ext2fs_flush): Use dgrp_t instead of int where
appropriate.
openfs.c (ext2fs_open), check_desc.c (ext2fs_check_desc): Use blk_t
instead of int where appropriate.
rw_bitmaps.c (read_bitmaps), irel_ma.c, inode.c (ext2fs_write_inode),
initialize.c (ext2fs_initialize): brel_ma.c: Fix to make be
16-bit safe.
link.c (ext2fs_link), unlink.c (ext2fs_unlink), lookup.c (lookup_proc),
ismounted.c (ext2fs_check_if_mounted), block.c (xlate_func):
Add #pragma argsused for Turbo C.
1997-08-12 00:29:22 +04:00
|
|
|
int block_nbytes = (int) EXT2_BLOCKS_PER_GROUP(fs->super) / 8;
|
|
|
|
int inode_nbytes = (int) EXT2_INODES_PER_GROUP(fs->super) / 8;
|
2006-05-09 04:17:26 +04:00
|
|
|
int lazy_flag = 0;
|
1997-04-29 20:17:09 +04:00
|
|
|
blk_t blk;
|
1997-04-26 17:34:30 +04:00
|
|
|
|
|
|
|
EXT2_CHECK_MAGIC(fs, EXT2_ET_MAGIC_EXT2FS_FILSYS);
|
|
|
|
|
|
|
|
fs->write_bitmaps = ext2fs_write_bitmaps;
|
|
|
|
|
2006-05-09 04:17:26 +04:00
|
|
|
if (EXT2_HAS_COMPAT_FEATURE(fs->super,
|
|
|
|
EXT2_FEATURE_COMPAT_LAZY_BG))
|
|
|
|
lazy_flag = 1;
|
|
|
|
|
2003-08-01 17:41:07 +04:00
|
|
|
retval = ext2fs_get_mem(strlen(fs->device_name) + 80, &buf);
|
1997-10-26 06:41:24 +03:00
|
|
|
if (retval)
|
|
|
|
return retval;
|
1997-04-26 17:34:30 +04:00
|
|
|
if (do_block) {
|
|
|
|
if (fs->block_map)
|
|
|
|
ext2fs_free_block_bitmap(fs->block_map);
|
|
|
|
sprintf(buf, "block bitmap for %s", fs->device_name);
|
|
|
|
retval = ext2fs_allocate_block_bitmap(fs, buf, &fs->block_map);
|
|
|
|
if (retval)
|
|
|
|
goto cleanup;
|
|
|
|
block_bitmap = fs->block_map->bitmap;
|
|
|
|
}
|
|
|
|
if (do_inode) {
|
|
|
|
if (fs->inode_map)
|
|
|
|
ext2fs_free_inode_bitmap(fs->inode_map);
|
|
|
|
sprintf(buf, "inode bitmap for %s", fs->device_name);
|
|
|
|
retval = ext2fs_allocate_inode_bitmap(fs, buf, &fs->inode_map);
|
|
|
|
if (retval)
|
|
|
|
goto cleanup;
|
|
|
|
inode_bitmap = fs->inode_map->bitmap;
|
|
|
|
}
|
2003-08-01 17:41:07 +04:00
|
|
|
ext2fs_free_mem(&buf);
|
1997-04-26 17:34:30 +04:00
|
|
|
|
2001-05-03 08:02:29 +04:00
|
|
|
if (fs->flags & EXT2_FLAG_IMAGE_FILE) {
|
|
|
|
if (inode_bitmap) {
|
|
|
|
blk = (fs->image_header->offset_inodemap /
|
|
|
|
fs->blocksize);
|
2004-07-29 05:11:48 +04:00
|
|
|
retval = io_channel_read_blk(fs->image_io, blk,
|
2001-05-03 08:02:29 +04:00
|
|
|
-(inode_nbytes * fs->group_desc_count),
|
|
|
|
inode_bitmap);
|
|
|
|
if (retval)
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
if (block_bitmap) {
|
|
|
|
blk = (fs->image_header->offset_blockmap /
|
|
|
|
fs->blocksize);
|
2004-07-29 05:11:48 +04:00
|
|
|
retval = io_channel_read_blk(fs->image_io, blk,
|
2001-05-03 08:02:29 +04:00
|
|
|
-(block_nbytes * fs->group_desc_count),
|
|
|
|
block_bitmap);
|
|
|
|
if (retval)
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
1997-04-26 17:34:30 +04:00
|
|
|
for (i = 0; i < fs->group_desc_count; i++) {
|
1997-04-26 17:58:21 +04:00
|
|
|
if (block_bitmap) {
|
1997-04-29 20:17:09 +04:00
|
|
|
blk = fs->group_desc[i].bg_block_bitmap;
|
2006-05-09 04:17:26 +04:00
|
|
|
if (lazy_flag && fs->group_desc[i].bg_flags &
|
|
|
|
EXT2_BG_BLOCK_UNINIT)
|
|
|
|
blk = 0;
|
1997-04-29 20:17:09 +04:00
|
|
|
if (blk) {
|
|
|
|
retval = io_channel_read_blk(fs->io, blk,
|
|
|
|
-block_nbytes, block_bitmap);
|
|
|
|
if (retval) {
|
|
|
|
retval = EXT2_ET_BLOCK_BITMAP_READ;
|
|
|
|
goto cleanup;
|
|
|
|
}
|
ChangeLog, .del-io.h~72680822, irel_ma.c, llseek.c, rw_bitmaps.c:
io.h: Change the prototype of ext2fs_llseek() to use int's instead of
unsigned int's.
llseek.c: Change to allow PIC and !HAVE_LLSEEK. Add a prototype to
make life easer for GNU Libc 2.
rw_bitmaps.c: On the PowerPC, the big-endian variant of the ext2
filesystem has its bitmaps stored as 32-bit words with bit 0 as the
LSB of each word. Thus a bitmap with only bit 0 set would be, as a
string of bytes, 00 00 00 01 00 ... To cope with this, we
byte-reverse each word of a bitmap if we have a big-endian filesystem,
that is, if we are *not* byte-swapping other word-sized numbers.
ChangeLog, expect.1, image.gz:
f_badinode: Modify test to check for "bad" character and block devices
(i.e., ones which contain garbage block entries)
1997-08-14 21:20:42 +04:00
|
|
|
#ifdef EXT2_BIG_ENDIAN_BITMAPS
|
|
|
|
if (!((fs->flags & EXT2_FLAG_SWAP_BYTES) ||
|
|
|
|
(fs->flags & EXT2_FLAG_SWAP_BYTES_READ)))
|
|
|
|
ext2fs_swap_bitmap(fs, block_bitmap, block_nbytes);
|
|
|
|
#endif
|
1997-04-29 20:17:09 +04:00
|
|
|
} else
|
2006-05-09 04:17:26 +04:00
|
|
|
memset(block_bitmap, 0xff, block_nbytes);
|
1997-04-26 17:34:30 +04:00
|
|
|
block_bitmap += block_nbytes;
|
|
|
|
}
|
1997-04-26 17:58:21 +04:00
|
|
|
if (inode_bitmap) {
|
1997-04-29 20:17:09 +04:00
|
|
|
blk = fs->group_desc[i].bg_inode_bitmap;
|
2006-05-09 04:17:26 +04:00
|
|
|
if (lazy_flag && fs->group_desc[i].bg_flags &
|
|
|
|
EXT2_BG_INODE_UNINIT)
|
|
|
|
blk = 0;
|
1997-04-29 20:17:09 +04:00
|
|
|
if (blk) {
|
|
|
|
retval = io_channel_read_blk(fs->io, blk,
|
|
|
|
-inode_nbytes, inode_bitmap);
|
|
|
|
if (retval) {
|
|
|
|
retval = EXT2_ET_INODE_BITMAP_READ;
|
|
|
|
goto cleanup;
|
|
|
|
}
|
ChangeLog, .del-io.h~72680822, irel_ma.c, llseek.c, rw_bitmaps.c:
io.h: Change the prototype of ext2fs_llseek() to use int's instead of
unsigned int's.
llseek.c: Change to allow PIC and !HAVE_LLSEEK. Add a prototype to
make life easer for GNU Libc 2.
rw_bitmaps.c: On the PowerPC, the big-endian variant of the ext2
filesystem has its bitmaps stored as 32-bit words with bit 0 as the
LSB of each word. Thus a bitmap with only bit 0 set would be, as a
string of bytes, 00 00 00 01 00 ... To cope with this, we
byte-reverse each word of a bitmap if we have a big-endian filesystem,
that is, if we are *not* byte-swapping other word-sized numbers.
ChangeLog, expect.1, image.gz:
f_badinode: Modify test to check for "bad" character and block devices
(i.e., ones which contain garbage block entries)
1997-08-14 21:20:42 +04:00
|
|
|
#ifdef EXT2_BIG_ENDIAN_BITMAPS
|
|
|
|
if (!((fs->flags & EXT2_FLAG_SWAP_BYTES) ||
|
|
|
|
(fs->flags & EXT2_FLAG_SWAP_BYTES_READ)))
|
|
|
|
ext2fs_swap_bitmap(fs, inode_bitmap, inode_nbytes);
|
|
|
|
#endif
|
1997-04-29 20:17:09 +04:00
|
|
|
} else
|
2006-05-09 04:17:26 +04:00
|
|
|
memset(inode_bitmap, 0xff, inode_nbytes);
|
1997-04-26 17:34:30 +04:00
|
|
|
inode_bitmap += inode_nbytes;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
cleanup:
|
|
|
|
if (do_block) {
|
2003-08-01 17:41:07 +04:00
|
|
|
ext2fs_free_mem(&fs->block_map);
|
1997-04-26 17:34:30 +04:00
|
|
|
fs->block_map = 0;
|
|
|
|
}
|
|
|
|
if (do_inode) {
|
2003-08-01 17:41:07 +04:00
|
|
|
ext2fs_free_mem(&fs->inode_map);
|
1997-04-26 17:34:30 +04:00
|
|
|
fs->inode_map = 0;
|
|
|
|
}
|
|
|
|
if (buf)
|
2003-08-01 17:41:07 +04:00
|
|
|
ext2fs_free_mem(&buf);
|
1997-04-26 17:34:30 +04:00
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
2006-04-23 20:43:40 +04:00
|
|
|
errcode_t ext2fs_read_inode_bitmap(ext2_filsys fs)
|
1997-04-26 17:34:30 +04:00
|
|
|
{
|
|
|
|
return read_bitmaps(fs, 1, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
errcode_t ext2fs_read_block_bitmap(ext2_filsys fs)
|
|
|
|
{
|
|
|
|
return read_bitmaps(fs, 0, 1);
|
|
|
|
}
|
|
|
|
|
2006-04-23 20:43:40 +04:00
|
|
|
errcode_t ext2fs_write_inode_bitmap(ext2_filsys fs)
|
1997-04-26 17:34:30 +04:00
|
|
|
{
|
2006-04-23 20:43:40 +04:00
|
|
|
return write_bitmaps(fs, 1, 0);
|
|
|
|
}
|
1997-04-26 17:34:30 +04:00
|
|
|
|
2006-04-23 20:43:40 +04:00
|
|
|
errcode_t ext2fs_write_block_bitmap (ext2_filsys fs)
|
|
|
|
{
|
|
|
|
return write_bitmaps(fs, 0, 1);
|
|
|
|
}
|
1997-04-26 17:34:30 +04:00
|
|
|
|
2006-04-23 20:43:40 +04:00
|
|
|
errcode_t ext2fs_read_bitmaps(ext2_filsys fs)
|
|
|
|
{
|
1998-02-17 01:00:37 +03:00
|
|
|
if (fs->inode_map && fs->block_map)
|
|
|
|
return 0;
|
|
|
|
|
1997-04-26 17:34:30 +04:00
|
|
|
return read_bitmaps(fs, !fs->inode_map, !fs->block_map);
|
|
|
|
}
|
|
|
|
|
|
|
|
errcode_t ext2fs_write_bitmaps(ext2_filsys fs)
|
|
|
|
{
|
2006-04-23 20:43:40 +04:00
|
|
|
int do_inode = fs->inode_map && ext2fs_test_ib_dirty(fs);
|
|
|
|
int do_block = fs->block_map && ext2fs_test_bb_dirty(fs);
|
1997-04-26 17:34:30 +04:00
|
|
|
|
2006-04-23 20:43:40 +04:00
|
|
|
if (!do_inode && !do_block)
|
|
|
|
return 0;
|
1997-04-26 17:34:30 +04:00
|
|
|
|
2006-04-23 20:43:40 +04:00
|
|
|
return write_bitmaps(fs, do_inode, do_block);
|
|
|
|
}
|