[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Reiserfs patch
From: |
Yura Umanets |
Subject: |
Reiserfs patch |
Date: |
Sun, 06 Jan 2002 17:28:26 +0200 |
User-agent: |
Mozilla/5.0 (X11; U; Linux i686; en-US; rv:0.9.7) Gecko/20011221 |
Hi all!
This is a patch that provides reiserfs support for GNU Parted-1.5.5
Changed: reiserfs_probe
Added, reiserfs_open, reiserfs_close, reiserfs_check,
reiserfs_get_resize_constraint, and finally reiserfs_resize :))
reiserfs_create feature comming soon.
Best regards
--
Yury Umanets
IT Engineer of Priocom Corp.
Phone: +380 44 2011959, ICQ: 55494590
diff -rupN ./parted-1.5.5/libparted/fs_reiserfs/Makefile.am
./parted-reiser-1.5.5/libparted/fs_reiserfs/Makefile.am
--- ./parted-1.5.5/libparted/fs_reiserfs/Makefile.am Thu Dec 27 02:21:49 2001
+++ ./parted-reiser-1.5.5/libparted/fs_reiserfs/Makefile.am Mon Dec 31
17:28:00 2001
@@ -1,6 +1,8 @@
partedincludedir = -I$(top_srcdir)/include
noinst_LTLIBRARIES = libreiserfs.la
-libreiserfs_la_SOURCES = reiserfs.c
+libreiserfs_la_SOURCES = reiserfs.c reiserfs_fs.c reiserfs_fs.h \
+ reiserfs_tools.c reiserfs_tools.h \
+ reiserfs_io.c reiserfs_io.h
INCLUDES = $(partedincludedir) @INTLINCS@
diff -rupN ./parted-1.5.5/libparted/fs_reiserfs/reiserfs.c
./parted-reiser-1.5.5/libparted/fs_reiserfs/reiserfs.c
--- ./parted-1.5.5/libparted/fs_reiserfs/reiserfs.c Thu Dec 27 02:21:49 2001
+++ ./parted-reiser-1.5.5/libparted/fs_reiserfs/reiserfs.c Fri Jan 4
12:23:00 2002
@@ -17,6 +17,14 @@
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
+/*
+ Added reiserfs_open, reiserfs_close, reiserfs_resize,
+ reiserfs_get_resize_constraint, reiserfs_check
+ by Yury Umanets (address@hidden)
+*/
+
+static const char _reiserfs_c[] = "$Id: reiserfs.c,v 1.55 2002/01/04 19:57:11
yumanets Exp $";
+
#include "config.h"
#include <parted/parted.h>
@@ -27,61 +35,38 @@
# define _(String) dgettext (PACKAGE, String)
#else
# define _(String) (String)
-#endif /* ENABLE_NLS */
+#endif
#include <string.h>
-#define REISERFS_SIGNATURE "ReIsErFs"
-#define REISER2FS_SIGNATURE "ReIsEr2Fs"
-
-static PedSector reiser_super_offset[] = {
- 128,
- 16, /* versions 3.5 - 3.5.11 */
- -1
-};
-
-/* taken from reiserfs_fs.h included in reiserfsprogs */
-struct reiserfs_super_block_v1
-{
- __u32 s_block_count; /* blocks count */
- __u32 s_free_blocks; /* free blocks count */
- __u32 s_root_block; /* root block number */
- __u32 s_journal_block; /* journal block number */
- __u32 s_journal_dev; /* journal device number */
- __u32 s_orig_journal_size; /* size of the journal on FS creation.
used to make sure they don't overflow it */
- __u32 s_journal_trans_max ; /* max number of blocks in a transaction. */
- __u32 s_journal_block_count ; /* total size of the journal. can change
over time */
- __u32 s_journal_max_batch ; /* max number of blocks to batch into a
trans */
- __u32 s_journal_max_commit_age ; /* in seconds, how old can an async
commit be */
- __u32 s_journal_max_trans_age ; /* in seconds, how old can a transaction
be */
- __u16 s_blocksize; /* block size */
- __u16 s_oid_maxsize; /* max size of object id array, see
get_objectid() commentary */
- __u16 s_oid_cursize; /* current size of object id array */
- __u16 s_state; /* valid or error */
- char s_magic[10]; /* reiserfs magic string indicates that file
system is reiserfs */
- __u16 s_fsck_state; /* when fsck managed to build the tree
- it puts */
- __u32 s_hash_function_code; /* indicate, what hash fuction is being
use to sort names in a directory*/
- __u16 s_tree_height; /* height of disk tree */
- __u16 s_bmap_nr; /* amount of bitmap blocks needed to address
each block of file system */
- __u16 s_version;
- char padding[436];
-};
+#include "reiserfs_fs.h"
+#include "reiserfs_io.h"
+#include "reiserfs_tools.h"
+static int reiser_super_offset[] = {128, 16, -1};
static PedGeometry* reiserfs_probe (PedGeometry* geom);
static int reiserfs_clobber (PedGeometry* geom);
+static PedFileSystem* reiserfs_open (PedGeometry *geom);
+static int reiserfs_close (PedFileSystem* fs);
+static int reiserfs_check (PedFileSystem *fs, PedTimer* timer);
+
+static int reiserfs_resize (PedFileSystem* fs, PedGeometry* geom, PedTimer
*timer);
+static PedConstraint* reiserfs_get_resize_constraint (const PedFileSystem* fs);
+
+
static PedFileSystemOps reiserfs_ops = {
probe: reiserfs_probe,
clobber: reiserfs_clobber,
- open: NULL,
+ open: reiserfs_open,
create: NULL,
- close: NULL,
- check: NULL,
+ close: reiserfs_close,
+ check: reiserfs_check,
copy: NULL,
- resize: NULL,
+ resize: reiserfs_resize,
get_create_constraint: NULL,
- get_resize_constraint: NULL,
+ get_resize_constraint: reiserfs_get_resize_constraint,
get_copy_constraint: NULL
};
@@ -94,7 +79,6 @@ static PedFileSystemType reiserfs_type =
void
ped_file_system_reiserfs_init ()
{
- PED_ASSERT (sizeof (struct reiserfs_super_block_v1) == 512, return);
ped_file_system_type_register (&reiserfs_type);
}
@@ -107,44 +91,166 @@ ped_file_system_reiserfs_done ()
static PedGeometry*
reiserfs_probe (PedGeometry* geom)
{
- struct reiserfs_super_block_v1 sb;
- int i;
-
- for (i=0; reiser_super_offset[i] != -1; i++) {
- if (reiser_super_offset[i] >= geom->length)
- continue;
- if (!ped_geometry_read (geom, &sb, reiser_super_offset[i], 1))
- continue;
-
- if (strncmp (REISERFS_SIGNATURE, sb.s_magic,
- strlen (REISERFS_SIGNATURE)) == 0
- || strncmp (REISER2FS_SIGNATURE, sb.s_magic,
- strlen (REISER2FS_SIGNATURE)) == 0) {
- PedSector block_size;
- PedSector block_count;
-
- block_size = PED_LE16_TO_CPU(sb.s_blocksize) / 512;
- block_count = PED_LE32_TO_CPU(sb.s_block_count);
- return ped_geometry_new (geom->dev, geom->start,
- block_size * block_count);
- }
+ struct reiserfs_super_block *sb;
+ char buff[512];
+ int i;
+
+ for (i = 0; reiser_super_offset[i] != -1; i++) {
+ if (reiser_super_offset[i] >= geom->length)
+ continue;
+ if (!ped_geometry_read (geom, buff, reiser_super_offset[i], 1))
+ continue;
+ sb = (struct reiserfs_super_block *)buff;
+
+ if (is_any_reiserfs_magic_string (sb->s_v1.s_magic)) {
+ PedSector block_size;
+ PedSector block_count;
+
+ block_size = PED_LE16_TO_CPU(sb->s_v1.sb_blocksize) / 512;
+ block_count = PED_LE32_TO_CPU(sb->s_v1.sb_block_count);
+ return ped_geometry_new (geom->dev, geom->start,
+ block_size * block_count);
}
- return NULL;
+ }
+ return NULL;
}
static int
reiserfs_clobber (PedGeometry* geom)
{
- char buf[512];
- int i;
+ int i;
+ char buf[512];
- memset (buf, 0, 512);
- for (i=0; reiser_super_offset[i] != -1; i++) {
- if (reiser_super_offset[i] >= geom->length)
- continue;
- if (!ped_geometry_write (geom, buf, reiser_super_offset[i], 1))
- return 0;
- }
- return 1;
+ memset (buf, 0, 512);
+ for (i=0; reiser_super_offset[i] != -1; i++) {
+ if (reiser_super_offset[i] >= geom->length)
+ continue;
+ if (!ped_geometry_write (geom, buf, reiser_super_offset[i], 1))
+ return 0;
+ }
+ return 1;
+}
+
+static PedFileSystem *reiserfs_open (PedGeometry *geom) {
+ PedFileSystem *fs;
+ reiserfs_fs_t *fs_info;
+ struct reiserfs_io_handler *io_handler;
+ PedGeometry *fs_geom = ped_geometry_duplicate(geom);
+
+ io_handler = reiserfs_io_handler_create(fs_geom);
+ if (!io_handler) goto error;
+
+ fs_info = _reiserfs_fs_open(io_handler);
+ if (!fs_info) goto error_free_io_handler;
+
+ if (!_reiserfs_journal_open(fs_info))
+ goto error_free_fs_info;
+
+ if (!_reiserfs_bitmap_open(fs_info))
+ goto error_free_fs_info;
+
+ fs = (PedFileSystem*) ped_malloc (sizeof(PedFileSystem));
+ if (!fs) goto error_free_fs_info;
+
+ fs->type = &reiserfs_type;
+ fs->geom = fs_geom;
+ fs->type_specific = (void*) fs_info;
+
+ return fs;
+
+error_free_fs:
+ ped_free(fs);
+error_free_fs_info:
+ _reiserfs_fs_close(fs_info);
+error_free_io_handler:
+ reiserfs_io_handler_destroy(io_handler);
+error:
+ return NULL;
+}
+
+static int reiserfs_close (PedFileSystem* fs) {
+ struct reiserfs_io_handler *io_handler = ((reiserfs_fs_t
*)fs->type_specific)->io_handler;
+
+ if (io_handler) reiserfs_io_handler_destroy(io_handler);
+ _reiserfs_fs_close(fs->type_specific);
+ ped_free(fs);
+ return 1;
+}
+
+static PedConstraint* reiserfs_get_resize_constraint (const PedFileSystem* fs)
{
+ reiserfs_fs_t *fs_info = (reiserfs_fs_t *)fs->type_specific;
+ PedDevice *dev = fs->geom->dev;
+ PedAlignment start_align;
+ PedGeometry start_sector;
+ PedGeometry full_dev;
+ PedSector min_size;
+
+ if (!ped_alignment_init (&start_align, fs->geom->start, 0))
+ return NULL;
+ if (!ped_geometry_init (&full_dev, dev, 0, dev->length - 1))
+ return NULL;
+ if (!ped_geometry_init (&start_sector, dev, fs->geom->start, 1))
+ return NULL;
+
+ min_size = (fs_info->fs_super_bh->b_blocknr +
fs_info->fs_ondisk_sb->s_v1.sb_block_count -
+ fs_info->fs_ondisk_sb->s_v1.sb_free_blocks) * (fs_info->fs_blocksize /
PED_SECTOR_SIZE);
+
+ return ped_constraint_new (&start_align, ped_alignment_any,
+ &start_sector, &full_dev, min_size, dev->length);
+}
+
+static int reiserfs_resize (PedFileSystem* fs, PedGeometry *geom, PedTimer
*timer) {
+ reiserfs_fs_t *fs_info;
+ PedSector old_length = fs->geom->length;
+ unsigned long blocks;
+
+ if (fs->geom->dev != geom->dev) {
+ ped_exception_throw (PED_EXCEPTION_ERROR, PED_EXCEPTION_CANCEL,
+ _("Filesystem device isn't equals geometry device"));
+ return 0;
+ }
+
+ if (fs->geom->start != geom->start) {
+ ped_exception_throw (PED_EXCEPTION_ERROR, PED_EXCEPTION_CANCEL,
+ _("Sorry, can't move the start of reiserfs partitions yet"));
+ return 0;
+ }
+
+ fs_info = (reiserfs_fs_t *)fs->type_specific;
+
+ geom->dev->boot_dirty = 1;
+
+ blocks = (unsigned long)(geom->length /
+ (fs_info->fs_blocksize / PED_SECTOR_SIZE)) -
+ fs_info->fs_super_bh->b_blocknr;
+
+ if (old_length > geom->length) {
+ if (!_reiserfs_fs_resize(fs_info, blocks))
+ goto error;
+
+ fs->geom->length = geom->length;
+ fs->geom->end = fs->geom->start + geom->length - 1;
+ } else {
+ fs->geom->length = geom->length;
+ fs->geom->end = fs->geom->start + geom->length - 1;
+
+ if (!_reiserfs_fs_resize(fs_info, blocks))
+ goto error;
+ }
+
+ return 1;
+
+error:
+ fs->geom->length = old_length;
+ fs->geom->end = fs->geom->start + old_length - 1;
+
+ return 0;
}
+static int
+reiserfs_check (PedFileSystem *fs, PedTimer* timer)
+{
+ reiserfs_fs_t *fs_info = (reiserfs_fs_t *)fs->type_specific;
+
+ return _reiserfs_fs_is_consistent(fs_info);
+}
diff -rupN ./parted-1.5.5/libparted/fs_reiserfs/reiserfs_fs.c
./parted-reiser-1.5.5/libparted/fs_reiserfs/reiserfs_fs.c
--- ./parted-1.5.5/libparted/fs_reiserfs/reiserfs_fs.c Thu Jan 1 03:00:00 1970
+++ ./parted-reiser-1.5.5/libparted/fs_reiserfs/reiserfs_fs.c Sun Jan 6
08:17:18 2002
@@ -0,0 +1,788 @@
+/*
+ reiserfs_fs.c -- generic reiserfs stuff
+ Copyright (C) 1998, 1999, 2000, 2001 Free Software Foundation, Inc.
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+*/
+
+/*
+ Some parts of this code are from original reiserfs code,
+ as found in the linux kernel. Writen by Yury Umanets (address@hidden)
+*/
+
+static const char _reiserfs_fs_c[] = "$Id: reiserfs_fs.c,v 1.55 2002/01/04
19:55:11 yumanets Exp $";
+
+#include <parted/parted.h>
+
+#include "reiserfs_fs.h"
+#include "reiserfs_tools.h"
+
+#include <libintl.h>
+#if ENABLE_NLS
+# define _(String) dgettext (PACKAGE, String)
+#else
+# define _(String) (String)
+#endif
+
+#define _reiserfs_key_uniqueness get_key_uniqueness
+
+static struct key root_dir_key = {0, 0, {{0, 0},}};
+static struct key parent_root_dir_key = {0, 0, {{0, 0},}};
+
+/* Utilities */
+static int _reiserfs_bitmap_is_spread(reiserfs_fs_t *fs) {
+ return fs->fs_super_bh->b_blocknr != 2;
+}
+
+static int _reiserfs_journal_is_opened (reiserfs_fs_t *fs) {
+ return fs->fs_jh_bh ? 1 : 0;
+}
+
+static int _reiserfs_fs_is_found (reiserfs_fs_t *fs) {
+ return (fs->fs_blocksize == 0) ? 0 : 1;
+}
+
+static int _reiserfs_fs_is_newformat (reiserfs_fs_t *fs) {
+ return fs->fs_super_bh->b_blocknr != 2;
+}
+
+static void _reiserfs_make_const_keys (void) {
+ set_key_dirid (&root_dir_key, REISERFS_ROOT_PARENT_OBJECTID);
+ set_key_objectid (&root_dir_key, REISERFS_ROOT_OBJECTID);
+
+ set_key_dirid (&parent_root_dir_key, 0);
+ set_key_objectid (&parent_root_dir_key, REISERFS_ROOT_PARENT_OBJECTID);
+}
+
+/* buffer_head manipulations functions */
+static struct buffer_head *_reiserfs_block_get(int block, int size) {
+ struct buffer_head *bh;
+
+ bh = (struct buffer_head *)ped_malloc(sizeof(*bh));
+ memset(bh, 0, sizeof(*bh));
+ bh->b_data = ped_malloc(size);
+ memset(bh->b_data, 0, size);
+
+ bh->b_count = 1;
+ bh->b_size = size;
+ bh->b_blocknr = block;
+ bh->b_end_io = NULL;
+ bh->b_state = 0;
+
+ return bh;
+}
+
+static void _reiserfs_block_release(struct buffer_head *bh) {
+ if (bh == 0)
+ return;
+ ped_free(bh->b_data);
+ ped_free(bh);
+}
+
+struct buffer_head *_reiserfs_block_read(struct reiserfs_io_handler
*io_handler, unsigned long block, size_t size) {
+ struct buffer_head * bh;
+
+ bh = _reiserfs_block_get(block, size);
+ if (!io_handler->ops->read(io_handler, bh->b_data, block, 1, size)) {
+ _reiserfs_block_release(bh);
+ return 0;
+ }
+ return bh;
+}
+
+static int _reiserfs_block_write(struct reiserfs_io_handler *io_handler,
struct buffer_head *bh) {
+
+ if (bh->b_start_io)
+ bh->b_start_io (bh->b_blocknr);
+
+ if (!io_handler->ops->write(io_handler, bh->b_data,
+ bh->b_blocknr, 1, bh->b_size))
+ {
+ ped_exception_throw(PED_EXCEPTION_ERROR, PED_EXCEPTION_CANCEL,
+ _("Couldn't write block (%lu)"), bh->b_blocknr);
+ return 0;
+ }
+
+ if (bh->b_end_io)
+ bh->b_end_io(bh, 1);
+
+ return 1;
+}
+
+static unsigned long total_node_cnt = 0;
+static unsigned long blocks_used;
+static int block_count_mismatch = 0;
+
+static void _reiserfs_bitmap_set_bit (reiserfs_bitmap_t *bm,
+ unsigned int bit_number)
+{
+ if (test_bit (bit_number, bm->bm_map))
+ return;
+ set_bit(bit_number, bm->bm_map);
+ bm->bm_set_bits ++;
+}
+
+static void _reiserfs_bitmap_clear_bit (reiserfs_bitmap_t *bm,
+ unsigned int bit_number)
+{
+ if (!test_bit (bit_number, bm->bm_map))
+ return;
+ clear_bit (bit_number, bm->bm_map);
+ bm->bm_set_bits--;
+}
+
+static int _reiserfs_bitmap_test_bit (reiserfs_bitmap_t *bm,
+ unsigned int bit_number)
+{
+ return test_bit(bit_number, bm->bm_map);
+}
+
+static int _reiserfs_bitmap_find_zero_bit (reiserfs_bitmap_t *bm,
+ unsigned long * start)
+{
+ unsigned int bit_nr = *start;
+
+ bit_nr = find_next_zero_bit(bm->bm_map, bm->bm_bit_size, *start);
+
+ if (bit_nr >= bm->bm_bit_size)
+ return 1;
+
+ *start = bit_nr;
+ return 0;
+}
+
+/* Moving of the generic file system block */
+static unsigned long _reiserfs_block_move_generic(reiserfs_fs_t *fs,
+ unsigned long block, unsigned long bnd, int h)
+{
+ struct buffer_head *bh, *bh2;
+ unsigned long unused_block = 1;
+
+ /* primitive fsck */
+ if (block > get_sb_block_count(fs->fs_ondisk_sb)) {
+ ped_exception_throw(PED_EXCEPTION_ERROR, PED_EXCEPTION_CANCEL,
+ _("Invalid block number (%lu) found"), block);
+ return 0;
+ }
+ total_node_cnt ++;
+
+ /* infinite loop check */
+ if(total_node_cnt > blocks_used && !block_count_mismatch) {
+ ped_exception_throw(PED_EXCEPTION_WARNING, PED_EXCEPTION_IGNORE,
+ _("Block count exeeded"));
+ block_count_mismatch = 1;
+ }
+
+ if (block < bnd) return 0;
+
+ /* Move wrong block */
+ if (!(bh = _reiserfs_block_read(fs->io_handler, block, fs->fs_blocksize)))
{
+ ped_exception_throw(PED_EXCEPTION_ERROR, PED_EXCEPTION_CANCEL,
+ _("Couldn't read block (%lu)"), block);
+ return 0;
+ }
+
+ _reiserfs_bitmap_find_zero_bit(fs->fs_bitmap2, &unused_block);
+ if (unused_block == 0 || unused_block >= bnd) {
+ ped_exception_throw(PED_EXCEPTION_ERROR, PED_EXCEPTION_CANCEL,
+ _("Can't find free block"));
+ return 0;
+ }
+
+ /* blocknr changing */
+ bh2 = _reiserfs_block_get(unused_block, fs->fs_blocksize);
+ memcpy(bh2->b_data, bh->b_data, bh2->b_size);
+ _reiserfs_bitmap_clear_bit(fs->fs_bitmap2, block);
+ _reiserfs_bitmap_set_bit(fs->fs_bitmap2, unused_block);
+
+ _reiserfs_block_release(bh);
+ _reiserfs_block_write(fs->io_handler, bh2);
+ _reiserfs_block_release(bh2);
+
+ return unused_block;
+}
+
+static unsigned long _reiserfs_block_move_unformatted(reiserfs_fs_t *fs,
+ unsigned long block, unsigned long bnd, int h)
+{
+ unsigned long b;
+ b = _reiserfs_block_move_generic(fs, block, bnd, h);
+ return b;
+}
+
+#define V2_OFFSET_MASK 0xfffffffffffffffLL
+#define V2_TYPE_MASK 0xf000000000000000LL
+
+static int _reiserfs_uniqueness2type (__u32 uniqueness) {
+ switch (uniqueness) {
+ case V1_SD_UNIQUENESS: return KEY_TYPE_STAT_DATA;
+ case V1_INDIRECT_UNIQUENESS: return KEY_TYPE_INDIRECT;
+ case V1_DIRECT_UNIQUENESS: return KEY_TYPE_DIRECT;
+ case V1_DIRENTRY_UNIQUENESS: return KEY_TYPE_DIRENTRY;
+ }
+ return KEY_TYPE_UNKNOWN;
+}
+
+static __u32 _reiserfs_type2uniqueness (int type) {
+ switch (type) {
+ case KEY_TYPE_STAT_DATA: return V1_SD_UNIQUENESS;
+ case KEY_TYPE_INDIRECT: return V1_INDIRECT_UNIQUENESS;
+ case KEY_TYPE_DIRECT: return V1_DIRECT_UNIQUENESS;
+ case KEY_TYPE_DIRENTRY: return V1_DIRENTRY_UNIQUENESS;
+ }
+ return V1_UNKNOWN_UNIQUENESS;
+}
+
+static inline __u16 _reiserfs_key_type_v2 (const struct key * key) {
+ __u64 * p, tmp;
+
+ p = (__u64 *)(&(key->u.k2_offset_v2));
+ tmp = PED_LE64_TO_CPU (*p);
+ /* clear all bits but the ones the type is stored in */
+ tmp &= V2_TYPE_MASK;
+ /* type is stored in 4 highest bits */
+ tmp >>= 60;
+ return (__u16)tmp;
+}
+
+static int _reiserfs_key_format (const struct key * key) {
+ int type;
+
+ type = _reiserfs_key_type_v2 (key);
+
+ if (type == 0 || type == 15)
+ return KEY_FORMAT_1;
+
+ return KEY_FORMAT_2;
+}
+
+static int _reiserfs_key_type (const struct key *key) {
+ if (_reiserfs_key_format (key) == KEY_FORMAT_1)
+ return _reiserfs_uniqueness2type (_reiserfs_key_uniqueness (key));
+ return _reiserfs_key_type_v2 (key);
+}
+
+/* Moving formated blocks. Begins from root block */
+static unsigned long _reiserfs_block_move_formatted(reiserfs_fs_t * fs,
+ unsigned long block, unsigned long bnd, int h)
+{
+ struct buffer_head *bh;
+ struct item_head *ih;
+ unsigned long new_blocknr = 0;
+ int i, j;
+
+ if (!(bh = _reiserfs_block_read(fs->io_handler, block, fs->fs_blocksize)))
{
+ ped_exception_throw(PED_EXCEPTION_ERROR, PED_EXCEPTION_CANCEL,
+ _("Couldn't read block (%lu)"), block);
+ return 0;
+ }
+
+ if (is_leaf_node (bh)) {
+ /*
+ This is a leaf node. The small files lives directly in them.
+ And the big files, so called unformated blocks are chinden of
+ the leaves. Leaevs references them. The unformated blcoks are
+ files data. We move them here.
+ */
+ for (i = 0; i < B_NR_ITEMS(bh); i++) {
+ ih = B_N_PITEM_HEAD(bh, i);
+ if (is_indirect_ih(ih)) {
+ __u32 * indirect;
+
+ indirect = (__u32 *)B_I_PITEM (bh, ih);
+ for (j = 0; j < (int)I_UNFM_NUM(ih); j++) {
+ unsigned long unfm_block;
+
+ if (indirect [j] == 0)
+ continue;
+
+ unfm_block = _reiserfs_block_move_unformatted(fs,
+ PED_LE32_TO_CPU (indirect [j]), bnd, h + 1);
+ if (unfm_block)
+ indirect [j] = PED_CPU_TO_LE32(unfm_block);
+ }
+ }
+ }
+ } else if (is_internal_node (bh)) {
+
+ /*
+ This is a internal node. Internals nodes contains
+ other internals nodes and leaves. In all cases we
+ make recursive call to moving all children.
+ */
+
+ for (i = 0; i <= B_NR_ITEMS(bh); i++) {
+ unsigned long moved_block;
+ moved_block = _reiserfs_block_move_formatted(fs,
+ get_dc_child_blocknr (B_N_CHILD (bh, i)), bnd, h + 1);
+ if (moved_block)
+ set_dc_child_blocknr (B_N_CHILD (bh, i), moved_block);
+ }
+
+ } else {
+ ped_exception_throw(PED_EXCEPTION_ERROR, PED_EXCEPTION_CANCEL,
+ _("Block (%lu) has invalid format"), block);
+ return 0;
+ }
+
+ _reiserfs_block_write(fs->io_handler, bh);
+ _reiserfs_block_release(bh);
+
+ new_blocknr = _reiserfs_block_move_generic(fs, block, bnd, h);
+
+ return new_blocknr;
+}
+
+static int _reiserfs_fs_shrink(reiserfs_fs_t *fs, unsigned long blocks) {
+ unsigned long n_root_block;
+ unsigned int bmap_nr_new;
+
+
+ bmap_nr_new = (blocks - 1) / (8 * fs->fs_blocksize) + 1;
+
+ /* is shrinking possible ? */
+ if (get_sb_block_count(fs->fs_ondisk_sb) - blocks >
get_sb_free_blocks(fs->fs_ondisk_sb) +
+ get_sb_bmap_nr(fs->fs_ondisk_sb) - bmap_nr_new)
+ {
+ ped_exception_throw(PED_EXCEPTION_ERROR, PED_EXCEPTION_CANCEL,
+ _("Can't shrink filesystem. Too many blocks already allocated"));
+ return 0;
+ }
+
+ set_sb_state (fs->fs_ondisk_sb, REISERFS_FS_IS_ERROR);
+ _reiserfs_block_write(fs->io_handler, fs->fs_super_bh);
+
+ /* calculate number of data blocks */
+ blocks_used = get_sb_block_count(fs->fs_ondisk_sb)
+ - get_sb_free_blocks(fs->fs_ondisk_sb)
+ - get_sb_bmap_nr(fs->fs_ondisk_sb)
+ - get_jp_journal_size(sb_jp (fs->fs_ondisk_sb))
+ - fs->fs_super_bh->b_blocknr - 2;
+ /* superblock itself and 1 descriptor after the journal */
+
+ n_root_block = _reiserfs_block_move_formatted(fs,
get_sb_root_block(fs->fs_ondisk_sb), blocks, 0);
+ if (n_root_block)
+ set_sb_root_block (fs->fs_ondisk_sb, n_root_block);
+
+ if (block_count_mismatch) {
+ ped_exception_throw(PED_EXCEPTION_WARNING, PED_EXCEPTION_IGNORE,
+ _("Data block count %lu doesn't match data block count %lu from
super block"),
+ (unsigned long)total_node_cnt, blocks_used);
+ }
+
+ /* shrink bitmap */
+ fs->fs_bitmap2->bm_bit_size = blocks;
+ fs->fs_bitmap2->bm_byte_size = (blocks + 7) / 8;
+
+ set_sb_free_blocks (fs->fs_ondisk_sb, get_sb_free_blocks(fs->fs_ondisk_sb)
-
+ (get_sb_block_count(fs->fs_ondisk_sb) - blocks) +
(get_sb_bmap_nr(fs->fs_ondisk_sb) - bmap_nr_new));
+ set_sb_block_count (fs->fs_ondisk_sb, blocks);
+ set_sb_bmap_nr (fs->fs_ondisk_sb, bmap_nr_new);
+
+ return 1;
+}
+
+static int _reiserfs_bitmap_expand (reiserfs_bitmap_t *bm, unsigned int
blocks) {
+ unsigned int bytes = ((blocks + 7) / 8);
+
+ if (!(ped_realloc((void **)&bm->bm_map, bytes)))
+ return 0;
+
+ bm->bm_byte_size = bytes;
+ bm->bm_bit_size = blocks;
+ return 1;
+}
+
+static int _reiserfs_fs_expand(reiserfs_fs_t *fs, unsigned long blocks) {
+ int i;
+ unsigned int bmap_nr_new, bmap_nr_old;
+ struct reiserfs_super_block *sb;
+
+ sb = sb = fs->fs_ondisk_sb;
+ set_sb_state (fs->fs_ondisk_sb, REISERFS_FS_IS_ERROR);
+ _reiserfs_block_write(fs->io_handler, fs->fs_super_bh);
+
+ if (!_reiserfs_bitmap_expand(fs->fs_bitmap2, blocks)) {
+ ped_exception_throw(PED_EXCEPTION_ERROR, PED_EXCEPTION_CANCEL,
+ _("Can't expand bitmap"));
+ return 0;
+ }
+
+ /* count bitmap blocks in new fs */
+ bmap_nr_new = (blocks - 1) / (fs->fs_blocksize * 8) + 1;
+ bmap_nr_old = get_sb_bmap_nr(sb);
+
+ /* update super block buffer*/
+ set_sb_free_blocks (sb, get_sb_free_blocks(sb) +
+ (blocks - get_sb_block_count(sb)) -
+ (bmap_nr_new - bmap_nr_old));
+ set_sb_block_count (sb, blocks);
+ set_sb_bmap_nr (sb, bmap_nr_new);
+
+ /* mark new bitmap blocks as used */
+ for (i = bmap_nr_old; i < (int)bmap_nr_new; i++)
+ _reiserfs_bitmap_set_bit (fs->fs_bitmap2, i * fs->fs_blocksize * 8);
+
+ return 1;
+}
+
+static reiserfs_bitmap_t *_reiserfs_bitmap_create (unsigned int bit_count) {
+ reiserfs_bitmap_t *bm;
+
+ if (!(bm = (reiserfs_bitmap_t *)ped_malloc(sizeof(*bm))))
+ return 0;
+ memset(bm, 0, sizeof(*bm));
+
+ bm->bm_bit_size = bit_count;
+ bm->bm_byte_size = (bit_count + 7) / 8;
+ bm->bm_set_bits = 0;
+ if (!(bm->bm_map = (char *)ped_malloc(bm->bm_byte_size))) {
+ ped_free(bm);
+ return 0;
+ }
+ memset(bm->bm_map, 0, bm->bm_byte_size);
+ return bm;
+}
+
+static int _reiserfs_bitmap_fetch (reiserfs_bitmap_t * bm, reiserfs_fs_t * fs)
{
+ long to_copy;
+ int copied;
+ int i;
+ char * p;
+ int last_byte_unused_bits;
+ unsigned long block;
+ struct buffer_head * bh;
+
+
+ to_copy = (get_sb_block_count (fs->fs_ondisk_sb) + 7) / 8;
+
+ copied = fs->fs_blocksize;
+ p = bm->bm_map;
+ block = fs->fs_super_bh->b_blocknr + 1;
+
+ while (to_copy) {
+ bh = _reiserfs_block_read (fs->io_handler, block, fs->fs_blocksize);
+ if (!bh) {
+ ped_exception_throw(PED_EXCEPTION_ERROR, PED_EXCEPTION_CANCEL,
+ _("Couldn't read block (%lu)"), block);
+ return 0;
+ }
+
+ if (to_copy < fs->fs_blocksize)
+ copied = to_copy;
+
+ memcpy (p, bh->b_data, copied);
+ _reiserfs_block_release (bh);
+ p += copied;
+ to_copy -= copied;
+
+ /* Next bitmap block */
+ if (_reiserfs_bitmap_is_spread (fs))
+ block = (block / (fs->fs_blocksize * 8) + 1) * (fs->fs_blocksize *
8);
+ else
+ block ++;
+ }
+
+ /*
+ On disk bitmap has bits out of SB_BLOCK_COUNT set to 1, where as
+ reiserfs_bitmap_t has those bits set to 0
+ */
+ last_byte_unused_bits = bm->bm_byte_size * 8 - bm->bm_bit_size;
+ for (i = 0; i < last_byte_unused_bits; i ++)
+ clear_bit (bm->bm_bit_size + i, bm->bm_map);
+
+ bm->bm_set_bits = 0;
+
+ /*
+ Needed optimization
+ */
+ for (i = 0; i < (int)bm->bm_bit_size; i ++) {
+ if (_reiserfs_bitmap_test_bit (bm, i))
+ bm->bm_set_bits++;
+ }
+
+ return 1;
+}
+
+static void _reiserfs_journal_free (reiserfs_fs_t * fs) {
+ if (!_reiserfs_journal_is_opened (fs))
+ return;
+ _reiserfs_block_release (fs->fs_jh_bh);
+ fs->fs_jh_bh = 0;
+}
+
+static void _reiserfs_journal_close (reiserfs_fs_t *fs) {
+ _reiserfs_journal_free (fs);
+}
+
+static void _reiserfs_bitmap_delete (reiserfs_bitmap_t *bm) {
+ if (bm->bm_map) {
+ ped_free(bm->bm_map);
+ bm->bm_map = 0;
+ }
+ bm->bm_bit_size = 0;
+ bm->bm_byte_size = 0;
+ ped_free(bm);
+}
+
+static void _reiserfs_bitmap_free (reiserfs_fs_t *fs) {
+ if (fs->fs_bitmap2) {
+ _reiserfs_bitmap_delete(fs->fs_bitmap2);
+ fs->fs_bitmap2 = 0;
+ }
+}
+
+static int _reiserfs_bitmap_flush(reiserfs_bitmap_t *bm, reiserfs_fs_t *fs) {
+ char *p;
+ int i, copied, last_byte_unused_bits;
+ unsigned long to_copy, block;
+ struct buffer_head *bh;
+
+ /*
+ Make sure that the device is big enough
+ */
+ if (!(bh = _reiserfs_block_read (fs->io_handler, bm->bm_bit_size - 1,
fs->fs_blocksize))) {
+ ped_exception_throw(PED_EXCEPTION_WARNING, PED_EXCEPTION_IGNORE,
+ _("Couldn't read block (%lu)"), bm->bm_bit_size - 1);
+ }
+ _reiserfs_block_release (bh);
+
+ to_copy = bm->bm_byte_size;
+ copied = fs->fs_blocksize;
+ p = bm->bm_map;
+ block = fs->fs_super_bh->b_blocknr + 1;
+
+ while (to_copy) {
+ /*
+ We read to make sure that filesystem contains enough blocks
+ */
+ bh = _reiserfs_block_get(block, fs->fs_blocksize);
+ if (!bh) {
+ ped_exception_throw(PED_EXCEPTION_WARNING, PED_EXCEPTION_IGNORE,
+ _("Couldn't get block (%lu)"), block);
+ return 0;
+ }
+ memset (bh->b_data, 0xff, bh->b_size);
+
+ if ((int)to_copy < fs->fs_blocksize)
+ copied = to_copy;
+
+ memcpy (bh->b_data, p, copied);
+ if (copied == (int)to_copy) {
+ /*
+ Set unused bits of last byte of the bitmap to 1
+ */
+ last_byte_unused_bits = bm->bm_byte_size * 8 - bm->bm_bit_size;
+ for (i = 0; i < last_byte_unused_bits; i ++)
+ set_bit ((bm->bm_bit_size % (fs->fs_blocksize * 8)) + i,
bh->b_data);
+ }
+ _reiserfs_block_write(fs->io_handler, bh);
+ _reiserfs_block_release (bh);
+ p += copied;
+ to_copy -= copied;
+
+ /* next bitmap block */
+ if (_reiserfs_bitmap_is_spread(fs))
+ block = (block / (fs->fs_blocksize * 8) + 1) * (fs->fs_blocksize *
8);
+ else
+ block ++;
+ }
+
+ return 1;
+}
+
+static void _reiserfs_bitmap_close (reiserfs_fs_t * fs) {
+ if (!fs->fs_bitmap2)
+ return;
+ _reiserfs_bitmap_free(fs);
+}
+
+static void _reiserfs_fs_free (reiserfs_fs_t * fs) {
+ _reiserfs_journal_free (fs);
+ _reiserfs_bitmap_free (fs);
+ _reiserfs_block_release (fs->fs_super_bh);
+ fs->fs_super_bh = 0;
+ ped_free(fs);
+}
+
+/* Public functions */
+reiserfs_fs_t *_reiserfs_fs_open (struct reiserfs_io_handler *io_handler) {
+ int i;
+ reiserfs_fs_t *fs;
+ struct reiserfs_super_block *sb;
+ struct buffer_head *bh;
+ int super_offset[] = {16, 2, -1};
+
+ /*
+ Convert root dir key and parent root dir key to little
+ endian format
+ */
+ _reiserfs_make_const_keys();
+
+ fs = (reiserfs_fs_t *)ped_malloc(sizeof(*fs));
+ memset(fs, 0, sizeof(*fs));
+
+ fs->io_handler = io_handler;
+
+ for (i = 0; super_offset[i] != -1; i++) {
+ if (!(bh = _reiserfs_block_read (fs->io_handler, super_offset[i],
+ REISERFS_DEFAULT_BLOCK_SIZE)))
+ {
+ ped_exception_throw(PED_EXCEPTION_WARNING, PED_EXCEPTION_IGNORE,
+ _("Can't read block %d\n"), i);
+ } else {
+ sb = (struct reiserfs_super_block *)bh->b_data;
+
+ if (is_any_reiserfs_magic_string ((const char *)sb->s_v1.s_magic))
+ goto found;
+
+ /*
+ Reiserfs signature isn't found at the
+ reiserfs_super_offset[i]-th 4k block
+ */
+ _reiserfs_block_release (bh);
+ }
+ }
+
+ ped_free(fs);
+ return NULL;
+
+ found:
+ /*
+ We could make some check to make sure that super block looks
+ correctly
+ */
+ fs->fs_version = get_sb_version (sb);
+ fs->fs_blocksize = get_sb_block_size (sb);
+ fs->fs_super_bh = bh;
+ fs->fs_ondisk_sb = sb;
+
+ return fs;
+}
+
+int _reiserfs_journal_open (reiserfs_fs_t *fs) {
+ struct buffer_head * bh;
+ struct reiserfs_journal_header * j_head;
+ struct reiserfs_super_block * sb;
+
+
+ sb = fs->fs_ondisk_sb;
+
+ if (!(bh = _reiserfs_block_read (fs->io_handler, get_jp_journal_1st_block
(sb_jp (sb)) +
+ get_jp_journal_size (sb_jp (sb)), fs->fs_blocksize)))
+ return 0;
+
+ j_head = (struct reiserfs_journal_header *)(bh->b_data);
+
+ fs->fs_jh_bh = bh;
+ return 1;
+}
+
+int _reiserfs_bitmap_open (reiserfs_fs_t *fs) {
+ if (fs->fs_bitmap2) {
+ ped_exception_throw(PED_EXCEPTION_ERROR, PED_EXCEPTION_CANCEL,
+ _("Bitmap is initiaized already"));
+ return 0;
+ }
+ fs->fs_bitmap2 = _reiserfs_bitmap_create (get_sb_block_count
(fs->fs_ondisk_sb));
+ if (!fs->fs_bitmap2)
+ return 0;
+
+ _reiserfs_bitmap_fetch(fs->fs_bitmap2, fs);
+ return 1;
+}
+
+void _reiserfs_fs_close (reiserfs_fs_t *fs) {
+ _reiserfs_journal_close (fs);
+ _reiserfs_bitmap_close (fs);
+ _reiserfs_fs_free (fs);
+}
+
+int _reiserfs_fs_is_consistent (reiserfs_fs_t *fs) {
+ if (!_reiserfs_journal_is_opened (fs)) {
+ ped_exception_throw(PED_EXCEPTION_WARNING, PED_EXCEPTION_IGNORE,
+ _("Standart journal not opened"));
+ return 0;
+ }
+
+ /*
+ It is fany, but kernel reiserfs part doesn't know
+ about sb_mountid. So after unmounting reiserfs partition
+ we will have isconsistente state of the reiserfs filesystem
+ each time as we call this function
+ */
+
+ /*
+ if (get_sb_mount_id (fs->fs_ondisk_sb) !=
+ get_jh_mount_id ((struct reiserfs_journal_header
*)(fs->fs_jh_bh->b_data)))
+ return 0;
+ */
+
+ if (get_sb_fsck_state (fs->fs_ondisk_sb) != REISERFS_FS_IS_CONSISTENT)
+ return 0;
+
+ return 1;
+}
+
+int _reiserfs_fs_resize(reiserfs_fs_t *fs, unsigned long blocks) {
+ if (!_reiserfs_fs_is_found(fs)) {
+ ped_exception_throw(PED_EXCEPTION_ERROR, PED_EXCEPTION_CANCEL,
+ _("No reiserfs found"));
+ return 0;
+ }
+
+ if (!_reiserfs_bitmap_is_spread(fs)) {
+ ped_exception_throw(PED_EXCEPTION_ERROR, PED_EXCEPTION_CANCEL,
+ _("Can't resize reiserfs in old format"));
+ return 0;
+ }
+
+ /* Needs to check for mount state */
+ if (!_reiserfs_fs_is_consistent(fs)) {
+ ped_exception_throw(PED_EXCEPTION_ERROR, PED_EXCEPTION_CANCEL,
+ _("Filesystem isn't consistent. Run reiserfsck --check first"));
+ return 0;
+ }
+
+ if (get_sb_state(fs->fs_ondisk_sb) != REISERFS_FS_IS_VALID) {
+ ped_exception_throw(PED_EXCEPTION_ERROR, PED_EXCEPTION_CANCEL,
+ _("Filesystem isn't in valid state"));
+ return 0;
+ }
+
+ if (blocks > fs->io_handler->ops->blocks(fs->io_handler,
fs->fs_blocksize)) {
+ ped_exception_throw(PED_EXCEPTION_ERROR, PED_EXCEPTION_CANCEL,
+ _("Device is too small"));
+ return 0;
+ }
+
+ if (blocks == get_sb_block_count(fs->fs_ondisk_sb)) {
+ ped_exception_throw(PED_EXCEPTION_ERROR, PED_EXCEPTION_CANCEL,
+ _("New size is the same as previous one"));
+ return 0;
+ }
+
+ if (!(blocks > get_sb_block_count(fs->fs_ondisk_sb) ?
+ _reiserfs_fs_expand(fs, blocks) : _reiserfs_fs_shrink(fs, blocks)))
+ return 0;
+
+ set_sb_state(fs->fs_ondisk_sb, REISERFS_FS_IS_VALID);
+ _reiserfs_block_write(fs->io_handler, fs->fs_super_bh);
+ if (!_reiserfs_bitmap_flush(fs->fs_bitmap2, fs))
+ return 0;
+
+ return 1;
+}
+
diff -rupN ./parted-1.5.5/libparted/fs_reiserfs/reiserfs_fs.h
./parted-reiser-1.5.5/libparted/fs_reiserfs/reiserfs_fs.h
--- ./parted-1.5.5/libparted/fs_reiserfs/reiserfs_fs.h Thu Jan 1 03:00:00 1970
+++ ./parted-reiser-1.5.5/libparted/fs_reiserfs/reiserfs_fs.h Sun Jan 6
07:48:40 2002
@@ -0,0 +1,479 @@
+/*
+ reiserfs_fs.h -- generic reiserfs stuff
+ Copyright (C) 1998, 1999, 2000, 2001 Free Software Foundation, Inc.
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+*/
+
+/*
+ Some parts of this code are from original reiserfs code,
+ as found in the linux kernel. Writen by Yury Umanets (address@hidden)
+*/
+
+#ifndef REISERFS_FS_H
+#define REISERFS_FS_H
+
+static const char _reiserfs_fs_h[] = "$Id: reiserfs_fs.h,v 1.55 2002/01/04
19:56:19 yumanets Exp $";
+
+#include "reiserfs_io.h"
+#include <parted/endian.h>
+
+/*
+ Older and newer versions of the reiserfs
+*/
+#define REISERFS_FORMAT_3_5 0
+#define REISERFS_FORMAT_3_6 2
+
+/*
+ Max tree height in current version of the reiserfs,
+ but the grub-0.90 thinks tree height is 7
+*/
+#define REISERFS_TREE_MAX_HEIGHT 5
+
+/*
+ At the last phase of checking, reiserfsck marks super block
+ by 0xfaa0 if file systems isn't corrupted
+*/
+#define REISERFS_FS_IS_CONSISTENT 0xfaa0
+
+/*
+ All operations which performed on fs mark fs as error first
+ and when operation is done mark it as valid again. So if operation
+ has failed we will have invalid file system and will needed
+ to reiserfsck it
+*/
+#define REISERFS_FS_IS_VALID 1
+#define REISERFS_FS_IS_ERROR 2
+
+/*
+ Init key (id and parent id) for the tree root
+*/
+#define REISERFS_ROOT_OBJECTID 2
+#define REISERFS_ROOT_PARENT_OBJECTID 1
+
+/*
+ Tree levels
+*/
+#define REISERFS_FREE_LEVEL 0
+#define REISERFS_DISK_LEAF_LEVEL 1
+
+
+/*
+ Default block size. Needed by _reiserfs_fs_open
+ to read the super block and in other cases
+*/
+#define REISERFS_DEFAULT_BLOCK_SIZE 4096
+
+#define B_N_CHILD(p_s_bh,n_pos) \
+ ((struct disk_child *)((p_s_bh)->b_data + BLKH_SIZE + B_NR_ITEMS(p_s_bh) *\
+ KEY_SIZE + DC_SIZE * (n_pos)))
+
+#define MAX_CHILD_SIZE(blocksize) ((blocksize) - BLKH_SIZE)
+#define MAX_FREE_SPACE(blocksize) MAX_CHILD_SIZE(blocksize)
+
+#define B_CHILD_SIZE(cur) \
+ (MAX_CHILD_SIZE(cur->b_size)-(B_FREE_SPACE(cur)))
+
+#define B_I_PITEM(bh,ih) \
+ ((bh)->b_data + get_ih_location(ih))
+
+#define V1_SD_UNIQUENESS 0
+#define V1_DIRENTRY_UNIQUENESS 500
+#define V1_DIRECT_UNIQUENESS 0xffffffff
+#define V1_INDIRECT_UNIQUENESS 0xfffffffe
+#define V1_UNKNOWN_UNIQUENESS 555
+
+#define KEY_TYPE_STAT_DATA 0
+#define KEY_TYPE_INDIRECT 1
+#define KEY_TYPE_DIRECT 2
+#define KEY_TYPE_DIRENTRY 3
+#define KEY_TYPE_UNKNOWN 15
+
+#define KEY_FORMAT_1 0
+#define KEY_FORMAT_2 1
+
+#define KEY_IS_STAT_DATA_KEY(p_s_key) \
+ (_reiserfs_key_type (p_s_key) == KEY_TYPE_STAT_DATA)
+#define KEY_IS_DIRECTORY_KEY(p_s_key) \
+ (_reiserfs_key_type (p_s_key) == KEY_TYPE_DIRENTRY)
+#define KEY_IS_DIRECT_KEY(p_s_key) \
+ (_reiserfs_key_type (p_s_key) == KEY_TYPE_DIRECT)
+#define KEY_IS_INDIRECT_KEY(p_s_key) \
+ (_reiserfs_key_type (p_s_key) == KEY_TYPE_INDIRECT)
+
+#define is_indirect_key(key) KEY_IS_INDIRECT_KEY(key)
+#define is_direct_key(key) KEY_IS_DIRECT_KEY(key)
+#define is_direntry_key(key) KEY_IS_DIRECTORY_KEY(key)
+#define is_stat_data_key(key) KEY_IS_STAT_DATA_KEY(key)
+
+#define I_IS_STAT_DATA_ITEM(p_s_ih) \
+ KEY_IS_STAT_DATA_KEY(&((p_s_ih)->ih_key))
+#define I_IS_DIRECTORY_ITEM(p_s_ih) \
+ KEY_IS_DIRECTORY_KEY(&((p_s_ih)->ih_key))
+#define I_IS_DIRECT_ITEM(p_s_ih) \
+ KEY_IS_DIRECT_KEY(&((p_s_ih)->ih_key))
+#define I_IS_INDIRECT_ITEM(p_s_ih) \
+ KEY_IS_INDIRECT_KEY(&((p_s_ih)->ih_key))
+
+#define is_indirect_ih(ih) I_IS_INDIRECT_ITEM(ih)
+#define is_direct_ih(ih) I_IS_DIRECT_ITEM(ih)
+#define is_direntry_ih(ih) I_IS_DIRECTORY_ITEM(ih)
+#define is_stat_data_ih(ih) I_IS_STAT_DATA_ITEM(ih)
+
+#define B_N_PITEM_HEAD(bh, item_num) \
+ ((struct item_head * )((bh)->b_data + BLKH_SIZE) + (item_num))
+
+#define B_BLK_HEAD(p_s_bh) \
+ ((struct block_head *)((p_s_bh)->b_data))
+
+#define B_NR_ITEMS(bh) get_blkh_nr_items (B_BLK_HEAD(bh))
+#define B_LEVEL(bh) get_blkh_level (B_BLK_HEAD(bh))
+#define B_FREE_SPACE(bh) get_blkh_free_space (B_BLK_HEAD(bh))
+
+#define is_leaf_node(bh) is_leaf_block_head ((bh)->b_data)
+#define is_internal_node(bh) is_internal_block_head ((bh)->b_data)
+
+#define get_leXX(xx,p,field) \
+ (PED_LE##xx##_TO_CPU ((p)->##field))
+#define set_leXX(xx,p,field,val) \
+ do { (p)->##field = PED_CPU_TO_LE##xx(val); } while (0)
+
+#define get_le16(p,field) get_leXX (16, p, field)
+#define set_le16(p,field,val) set_leXX (16, p, field, val)
+
+#define get_le32(p,field) get_leXX (32, p, field)
+#define set_le32(p,field,val) set_leXX (32, p, field, val)
+
+#define get_le64(p,field) get_leXX (64, p, field)
+#define set_le64(p,field,val) set_leXX (64, p, field, val)
+
+struct reiserfs_bitmap {
+ unsigned long bm_byte_size;
+ unsigned long bm_bit_size;
+ char *bm_map;
+ unsigned long bm_set_bits;
+};
+
+typedef struct reiserfs_bitmap reiserfs_bitmap_t;
+
+struct buffer_head {
+ unsigned long b_blocknr;
+ unsigned long b_size;
+ char *b_data;
+ unsigned long b_state;
+ unsigned int b_count;
+ unsigned int b_list ;
+ void (*b_start_io) (unsigned long);
+ void (*b_end_io)(struct buffer_head *bh, int uptodate);
+};
+
+struct block_head {
+ __u16 blk2_level;
+ __u16 blk2_nr_item;
+ __u16 blk2_free_space;
+ __u16 blk_reserved;
+ __u32 reserved[4];
+};
+
+#define BLKH_SIZE (sizeof(struct block_head))
+
+#define get_blkh_level(blkh) get_le16 (blkh, blk2_level)
+#define set_blkh_level(blkh,val) set_le16 (blkh, blk2_level, val)
+
+#define get_blkh_nr_items(blkh) get_le16 (blkh, blk2_nr_item)
+#define set_blkh_nr_items(blkh,val) set_le16 (blkh, blk2_nr_item, val)
+
+#define get_blkh_free_space(blkh) get_le16 (blkh, blk2_free_space)
+#define set_blkh_free_space(blkh,val) set_le16 (blkh, blk2_free_space, val)
+
+#define is_leaf_block_head(buf) \
+ (get_blkh_level ((struct block_head *)(buf)) == REISERFS_DISK_LEAF_LEVEL)
+#define is_internal_block_head(buf) \
+ ((get_blkh_level (((struct block_head *)(buf))) >
REISERFS_DISK_LEAF_LEVEL) && \
+ (get_blkh_level (((struct block_head *)(buf))) <=
REISERFS_TREE_MAX_HEIGHT))
+
+struct offset_v1 {
+ __u32 k_offset;
+ __u32 k_uniqueness;
+} __attribute__ ((__packed__));
+
+struct offset_v2 {
+ __u64 k_offset: 60;
+ __u64 k_type: 4;
+} __attribute__ ((__packed__));
+
+struct key {
+ __u32 k2_dir_id;
+ __u32 k2_objectid;
+ union {
+ struct offset_v1 k2_offset_v1;
+ struct offset_v2 k2_offset_v2;
+ } __attribute__ ((__packed__)) u;
+} __attribute__ ((__packed__));
+
+#define get_key_uniqueness(k) get_le32 (k, u.k2_offset_v1.k_uniqueness)
+#define set_key_uniqueness(k,val) set_le32 (k, u.k2_offset_v1.k_uniqueness,
val)
+
+#define get_key_dirid(k) get_le32 (k, k2_dir_id)
+#define set_key_dirid(k,val) set_le32 (k, k2_dir_id, val)
+
+#define get_key_objectid(k) get_le32 (k, k2_objectid)
+#define set_key_objectid(k,val) set_le32 (k, k2_objectid, val)
+
+#define get_key_offset_v1(k) get_le32 (k, u.k2_offset_v1.k_offset)
+#define set_key_offset_v1(k,val) set_le32 (k, u.k2_offset_v1.k_offset, val)
+
+#define KEY_SIZE (sizeof(struct key))
+#define SHORT_KEY_SIZE (sizeof(__u32) + sizeof(__u32))
+
+#define UNFM_P_SIZE sizeof(__u32)
+#define I_UNFM_NUM(p_s_ih) (get_ih_item_len(p_s_ih) / UNFM_P_SIZE)
+
+struct item_head {
+ struct key ih_key;
+ union {
+ __u16 ih2_free_space;
+ __u16 ih2_entry_count;
+ } __attribute__ ((__packed__)) u;
+ __u16 ih2_item_len;
+ __u16 ih2_item_location;
+ __u16 ih_format;
+} __attribute__ ((__packed__));
+
+#define IH_SIZE (sizeof(struct item_head))
+
+#define get_ih_entry_count(ih) get_le16 (ih, u.ih2_entry_count)
+#define set_ih_entry_count(ih,val) set_le16 (ih, u.ih2_entry_count, val)
+
+#define get_ih_free_space(ih) get_le16 (ih, u.ih2_free_space)
+#define set_ih_free_space(ih,val) set_le16 (ih, u.ih2_free_space, 0)
+
+#define get_ih_item_len(ih) get_le16 (ih, ih2_item_len)
+#define set_ih_item_len(ih,val) set_le16 (ih, ih2_item_len, val)
+
+#define get_ih_location(ih) get_le16 (ih, ih2_item_location)
+#define set_ih_location(ih,val) set_le16 (ih, ih2_item_location, val)
+
+struct journal_params {
+ __u32 jp_journal_1st_block;
+ __u32 jp_journal_dev;
+ __u32 jp_journal_size;
+ __u32 jp_journal_trans_max;
+ __u32 jp_journal_magic;
+ __u32 jp_journal_max_batch;
+ __u32 jp_journal_max_commit_age;
+};
+
+struct reiserfs_journal_header {
+ __u32 jh_last_flush_trans_id;
+ __u32 jh_first_unflushed_offset;
+ __u32 jh_mount_id;
+ struct journal_params jh_journal;
+ __u32 jh_max_trans_age;
+};
+
+#define get_jp_journal_1st_block(jp) get_le32 (jp, jp_journal_1st_block)
+#define set_jp_journal_1st_block(jp,val) set_le32 (jp, jp_journal_1st_block,
val)
+
+#define get_jp_journal_dev(jp) get_le32 (jp, jp_journal_dev)
+#define set_jp_journal_dev(jp,val) set_le32 (jp, jp_journal_dev, val)
+
+#define get_jp_journal_size(jp) get_le32 (jp, jp_journal_size)
+#define set_jp_journal_size(jp,val) set_le32 (jp, jp_journal_size, val)
+
+#define get_jp_journal_max_trans_len(jp) get_le32 (jp, jp_journal_trans_max)
+#define set_jp_journal_max_trans_len(jp,val) set_le32 (jp,
jp_journal_trans_max, val)
+
+#define get_jp_journal_magic(jp) get_le32 (jp, jp_journal_magic)
+#define set_jp_journal_magic(jp,val) set_le32 (jp, jp_journal_magic, val)
+
+#define get_jp_journal_max_batch(jp) get_le32 (jp, jp_journal_max_batch)
+#define set_jp_journal_max_batch(jp,val) set_le32 (jp, jp_journal_max_batch,
val)
+
+#define get_jp_journal_max_commit_age(jp) get_le32 (jp,
jp_journal_max_commit_age)
+#define set_jp_journal_max_commit_age(jp,val) set_le32 (jp,
jp_journal_max_commit_age, val)
+
+#define get_jh_mount_id(jh) get_le32 (jh, jh_mount_id)
+#define set_jh_mount_id(jh,val) set_le32 (jh, jh_mount_id, val)
+
+#define get_jh_last_flushed(jh) get_le32 (jh, jh_last_flush_trans_id)
+#define set_jh_last_flushed(jh,val) set_le32 (jh, jh_last_flush_trans_id, val)
+
+#define get_jh_replay_start_offset(jh) get_le32 (jh, jh_first_unflushed_offset)
+#define set_jh_replay_start_offset(jh,val) set_le32 (jh,
jh_first_unflushed_offset, val)
+
+#define get_jh_max_trans_age(jh) get_le32 (jh, jh_max_trans_age)
+#define set_jh_max_trans_age(jh,val) set_le32 (jh, jh_max_trans_age, val)
+
+#define bh_desc(bh) ((struct reiserfs_journal_desc *)((bh)->b_data))
+#define bh_commit(bh) ((struct reiserfs_journal_commit *)((bh)->b_data))
+
+/*
+ Disk child pointer. The pointer from an internal node of the tree
+ to a node that is on disk.
+*/
+struct disk_child {
+ __u32 dc2_block_number;
+ __u16 dc2_size;
+ __u16 dc2_reserved;
+};
+
+#define DC_SIZE (sizeof(struct disk_child))
+
+#define get_dc_child_blocknr(dc) get_le32 (dc, dc2_block_number)
+#define set_dc_child_blocknr(dc,val) set_le32 (dc, dc2_block_number, val)
+
+#define get_dc_child_size(dc) get_le16 (dc, dc2_size)
+#define set_dc_child_size(dc,val) set_le16 (dc, dc2_size, val)
+
+struct reiserfs_super_block_v1 {
+ __u32 sb_block_count;
+ __u32 sb_free_blocks;
+ __u32 sb_root_block;
+
+ struct journal_params sb_journal;
+
+ __u32 sb_mountid;
+ __u16 sb_blocksize;
+ __u16 sb_oid_maxsize;
+ __u16 sb_oid_cursize;
+ __u16 sb_state;
+ char s_magic[10];
+ __u16 sb_fsck_state;
+ __u32 sb_hash_function_code;
+ __u16 sb_tree_height;
+ __u16 sb_bmap_nr;
+ __u16 sb_version;
+ __u16 sb_reserved_for_journal;
+} __attribute__ ((__packed__));
+
+#define SB_SIZE_V1 (sizeof(struct reiserfs_super_block_v1))
+#define sb_jp(sb) (&((sb)->s_v1.sb_journal))
+
+/* Structure of super block on disk */
+struct reiserfs_super_block {
+ struct reiserfs_super_block_v1 s_v1;
+ char sb_mnt_version[16];
+ char sb_mkfs_version[16];
+ char sb_fsck_version[16];
+ char sb_unused[204-16-16-16-SB_SIZE_V1];
+};
+
+#define SB_SIZE (sizeof(struct reiserfs_super_block))
+
+#define get_sb_block_count(sb) get_le32 (sb, s_v1.sb_block_count)
+#define set_sb_block_count(sb,val) set_le32 (sb, s_v1.sb_block_count, val)
+
+#define get_sb_free_blocks(sb) get_le32 (sb, s_v1.sb_free_blocks)
+#define set_sb_free_blocks(sb,val) set_le32 (sb, s_v1.sb_free_blocks, val)
+
+#define get_sb_root_block(sb) get_le32 (sb,s_v1.sb_root_block)
+#define set_sb_root_block(sb,val) set_le32 (sb, s_v1.sb_root_block, val)
+
+#define get_sb_mount_id(sb) get_le32 (sb,s_v1.sb_mountid)
+#define set_sb_mount_id(sb,val) set_le32 (sb, s_v1.sb_mountid, val)
+
+#define get_sb_block_size(sb) get_le16 (sb, s_v1.sb_blocksize)
+#define set_sb_block_size(sb,val) set_le16 (sb, s_v1.sb_blocksize, val)
+
+#define get_sb_oid_maxsize(sb) get_le16 (sb, s_v1.sb_oid_maxsize)
+#define set_sb_oid_maxsize(sb,val) set_le16 (sb, s_v1.sb_oid_maxsize, val)
+
+#define get_sb_oid_cursize(sb) get_le16 (sb, s_v1.sb_oid_cursize)
+#define set_sb_oid_cursize(sb,val) set_le16 (sb, s_v1.sb_oid_cursize, val)
+
+#define get_sb_state(sb) get_le16 (sb, s_v1.sb_state)
+#define set_sb_state(sb,val) set_le16 (sb, s_v1.sb_state, val)
+
+#define get_sb_fsck_state(sb) get_le16 (sb, s_v1.sb_fsck_state)
+#define set_sb_fsck_state(sb,val) set_le16 (sb, s_v1.sb_fsck_state, val)
+
+#define get_sb_hash_code(sb) get_le32 (sb, s_v1.sb_hash_function_code)
+#define set_sb_hash_code(sb,val) set_le32 (sb, s_v1.sb_hash_function_code, val)
+
+#define get_sb_tree_height(sb) get_le16 (sb, s_v1.sb_tree_height)
+#define set_sb_tree_height(sb,val) set_le16 (sb, s_v1.sb_tree_height, val)
+
+#define get_sb_bmap_nr(sb) get_le16 (sb, s_v1.sb_bmap_nr)
+#define set_sb_bmap_nr(sb,val) set_le16 (sb, s_v1.sb_bmap_nr, val)
+
+#define get_sb_version(sb) get_le16 (sb, s_v1.sb_version)
+#define set_sb_version(sb,val) set_le16 (sb, s_v1.sb_version, val)
+
+#define get_sb_reserved_for_journal(sb) get_le16 (sb,
s_v1.sb_reserved_for_journal)
+#define set_sb_reserved_for_journal(sb,val) set_le16 (sb,
s_v1.sb_reserved_for_journal, val)
+
+#define journal_is_relocated(sb) get_jp_journal_dev(sb_jp (sb))
+
+struct reiserfs_fs {
+ int fs_blocksize;
+ int fs_version;
+ struct buffer_head *fs_super_bh;
+ struct reiserfs_super_block *fs_ondisk_sb;
+
+ reiserfs_bitmap_t *fs_bitmap2;
+
+ struct buffer_head *fs_jh_bh;
+
+/* int (*block_allocator) (reiserfs_fs_t *fs,
+ unsigned long * free_blocknrs,
+ unsigned long start, int amount_needed);
+ int (*block_deallocator) (reiserfs_fs_t *fs, unsigned long block);*/
+ struct reiserfs_io_handler *io_handler;
+};
+
+typedef struct reiserfs_fs reiserfs_fs_t;
+
+struct reiserfs_de_head {
+ __u32 deh2_offset;
+ __u32 deh2_dir_id;
+ __u32 deh2_objectid;
+ __u16 deh2_location;
+ __u16 deh2_state;
+} __attribute__ ((__packed__));
+
+#define DEH_SIZE sizeof(struct reiserfs_de_head)
+
+#define get_deh_offset(deh) get_le32 (deh, deh2_offset)
+#define set_deh_offset(deh,val) set_le32 (deh, deh2_offset, val)
+
+#define get_deh_dirid(deh) get_le32 (deh, deh2_dir_id)
+#define set_deh_dirid(deh,val) set_le32 (deh, deh2_dir_id, val)
+
+#define get_deh_objectid(deh) get_le32 (deh, deh2_objectid)
+#define set_deh_objectid(deh,val) set_le32 (deh, deh2_objectid, val)
+
+#define get_deh_location(deh) get_le16 (deh, deh2_location)
+#define set_deh_location(deh,val) set_le16 (deh, deh2_location, val)
+
+#define get_deh_state(deh) get_le16 (deh, deh2_state)
+#define set_deh_state(deh,val) set_le16 (deh, deh2_state, val)
+
+#define B_I_DEH(bh,ih) \
+ ((struct reiserfs_de_head *)(B_I_PITEM(bh,ih)))
+
+#define REISERFS_MAX_NAME_LEN(block_size) \
+ (block_size - BLKH_SIZE - IH_SIZE - DEH_SIZE)
+
+reiserfs_fs_t *_reiserfs_fs_open (struct reiserfs_io_handler *io_handler);
+void _reiserfs_fs_close (reiserfs_fs_t *fs);
+int _reiserfs_fs_resize(reiserfs_fs_t *fs, unsigned long blocks);
+
+int _reiserfs_journal_open (reiserfs_fs_t *fs);
+int _reiserfs_bitmap_open (reiserfs_fs_t *fs);
+
+int _reiserfs_fs_is_consistent (reiserfs_fs_t *fs);
+
+#endif
diff -rupN ./parted-1.5.5/libparted/fs_reiserfs/reiserfs_io.c
./parted-reiser-1.5.5/libparted/fs_reiserfs/reiserfs_io.c
--- ./parted-1.5.5/libparted/fs_reiserfs/reiserfs_io.c Thu Jan 1 03:00:00 1970
+++ ./parted-reiser-1.5.5/libparted/fs_reiserfs/reiserfs_io.c Fri Jan 4
12:23:00 2002
@@ -0,0 +1,85 @@
+/*
+ reiserfs_io.c -- parted device i/o abstraction code
+ Copyright (C) 1998, 1999, 2000, 2001 Free Software Foundation, Inc.
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+*/
+
+/*
+ Writen by Yury Umanets (address@hidden)
+*/
+
+static const char _reiserfs_io_c[] = "$Id: reiserfs_io.c,v 1.55 2002/01/04
20:15:19 yumanets Exp $";
+
+#include <parted/parted.h>
+
+#include "reiserfs_io.h"
+
+static unsigned long _reiserfs_blocks(struct reiserfs_io_handler *io_handler,
+ unsigned long block_size)
+{
+ unsigned long k = (unsigned long)(block_size / PED_SECTOR_SIZE);
+ return (unsigned long)((io_handler->geom->length) / k);
+}
+
+static int _reiserfs_read(struct reiserfs_io_handler *io_handler, void *buff,
+ unsigned long block, unsigned long count, unsigned long block_size)
+{
+ unsigned long k = (unsigned int)(block_size / PED_SECTOR_SIZE);
+ PedSector block_pos = (PedSector)(block*k);
+ PedSector block_count = (PedSector)(count*k);
+
+/* printf("Reading: pos=%d, count=%d, geom->length=%d\n",
+ (unsigned long)block_pos, (unsigned long)block_count,
+ (unsigned long)io_handler->geom.length);*/
+
+ return ped_geometry_read(io_handler->geom, buff,
+ block_pos, block_count);
+}
+
+static int _reiserfs_write(struct reiserfs_io_handler *io_handler, void *buff,
+ unsigned long block, unsigned long count, unsigned long block_size)
+{
+ unsigned long k = (unsigned long)(block_size / PED_SECTOR_SIZE);
+ PedSector block_pos = (PedSector)(block*k);
+ PedSector block_count = (PedSector)(count*k);
+
+ return ped_geometry_write((PedGeometry *)io_handler->geom, buff,
block_pos, block_count);
+}
+
+static int _reiserfs_sync(struct reiserfs_io_handler *io_handler) {
+ return ped_geometry_sync((PedGeometry *)io_handler->geom);
+}
+
+static struct reiserfs_io_ops ops = {
+ blocks: _reiserfs_blocks,
+ read: _reiserfs_read,
+ write: _reiserfs_write,
+ sync: _reiserfs_sync
+};
+
+struct reiserfs_io_handler *reiserfs_io_handler_create(const PedGeometry
*geom) {
+ struct reiserfs_io_handler *io_handler =
+ (struct reiserfs_io_handler *)ped_malloc(sizeof(*io_handler));
+
+ io_handler->ops = &ops;
+ io_handler->geom = geom;
+
+ return io_handler;
+}
+
+void reiserfs_io_handler_destroy(struct reiserfs_io_handler *io_handler) {
+ ped_free(io_handler);
+}
diff -rupN ./parted-1.5.5/libparted/fs_reiserfs/reiserfs_io.h
./parted-reiser-1.5.5/libparted/fs_reiserfs/reiserfs_io.h
--- ./parted-1.5.5/libparted/fs_reiserfs/reiserfs_io.h Thu Jan 1 03:00:00 1970
+++ ./parted-reiser-1.5.5/libparted/fs_reiserfs/reiserfs_io.h Fri Jan 4
12:26:00 2002
@@ -0,0 +1,50 @@
+/*
+ reiserfs_io.h -- parted device i/o abstraction code
+ Copyright (C) 1998, 1999, 2000, 2001 Free Software Foundation, Inc.
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+*/
+
+/*
+ Writen by Yury Umanets (address@hidden)
+*/
+
+
+#ifndef REISERFS_IO_H
+#define REISERFS_IO_H
+
+static const char _reiserfs_io_h[] = "$Id: reiserfs_io.h,v 1.55 2002/01/04
20:16:19 yumanets Exp $";
+
+struct reiserfs_io_handler;
+
+struct reiserfs_io_ops {
+ unsigned long (*blocks)(struct reiserfs_io_handler *io_handler,
+ unsigned long block_size);
+ int (*read)(struct reiserfs_io_handler *io_handler, void *buff,
+ unsigned long block, unsigned long count, unsigned long block_size);
+ int (*write)(struct reiserfs_io_handler *io_handler, void *buff,
+ unsigned long block, unsigned long count, unsigned long block_size);
+ int (*sync)(struct reiserfs_io_handler *io_handler);
+};
+
+struct reiserfs_io_handler {
+ const PedGeometry *geom;
+ struct reiserfs_io_ops *ops;
+};
+
+struct reiserfs_io_handler *reiserfs_io_handler_create(const PedGeometry
*geom);
+void reiserfs_io_handler_destroy(struct reiserfs_io_handler *io_handler);
+
+#endif
diff -rupN ./parted-1.5.5/libparted/fs_reiserfs/reiserfs_tools.c
./parted-reiser-1.5.5/libparted/fs_reiserfs/reiserfs_tools.c
--- ./parted-1.5.5/libparted/fs_reiserfs/reiserfs_tools.c Thu Jan 1
03:00:00 1970
+++ ./parted-reiser-1.5.5/libparted/fs_reiserfs/reiserfs_tools.c Sun Jan
6 15:22:00 2002
@@ -0,0 +1,261 @@
+/*
+ reiserfs_tools.c -- reiserfs tools
+ Copyright (C) 1998, 1999, 2000, 2001 Free Software Foundation, Inc.
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+*/
+
+/*
+ Some parts of this code are from original reiserfs code,
+ as found in the reiserfs-progs-3.x.0k-pre10.
+ Writen by Yury Umanets (address@hidden)
+*/
+
+static const char _reiserfs_tools_c[] = "$Id: reiserfs_tools.c,v 1.55
2002/01/04 20:17:19 yumanets Exp $";
+
+#include <stdlib.h>
+#include <string.h>
+
+#include <parted/parted.h>
+#include <parted/endian.h>
+
+#include "reiserfs_tools.h"
+
+#include <libintl.h>
+#if ENABLE_NLS
+# define _(String) dgettext (PACKAGE, String)
+#else
+# define _(String) (String)
+#endif
+
+/* Bits manipulations and endianess functions */
+static inline int le_set_bit (int nr, void * addr) {
+ __u8 * p, mask;
+ int retval;
+
+ p = (__u8 *)addr;
+ p += nr >> 3;
+ mask = 1 << (nr & 0x7);
+ /*cli();*/
+ retval = (mask & *p) != 0;
+ *p |= mask;
+ /*sti();*/
+ return retval;
+}
+
+static inline int le_clear_bit (int nr, void * addr) {
+ __u8 * p, mask;
+ int retval;
+
+ p = (__u8 *)addr;
+ p += nr >> 3;
+ mask = 1 << (nr & 0x7);
+ /*cli();*/
+ retval = (mask & *p) != 0;
+ *p &= ~mask;
+ /*sti();*/
+ return retval;
+}
+
+static inline int le_test_bit(int nr, const void * addr) {
+ __u8 * p, mask;
+
+ p = (__u8 *)addr;
+ p += nr >> 3;
+ mask = 1 << (nr & 0x7);
+ return ((mask & *p) != 0);
+}
+
+static inline int le_find_first_zero_bit (const void *vaddr, unsigned size) {
+ const __u8 *p = vaddr, *addr = vaddr;
+ int res;
+
+ if (!size)
+ return 0;
+
+ size = (size >> 3) + ((size & 0x7) > 0);
+ while (*p++ == 255) {
+ if (--size == 0)
+ return (p - addr) << 3;
+ }
+
+ --p;
+ for (res = 0; res < 8; res++)
+ if (!test_bit (res, p))
+ break;
+ return (p - addr) * 8 + res;
+}
+
+static inline int le_find_next_zero_bit (const void *vaddr, unsigned size,
unsigned offset) {
+ const __u8 *addr = vaddr;
+ const __u8 *p = addr + (offset >> 3);
+ int bit = offset & 7, res;
+
+ if (offset >= size)
+ return size;
+
+ if (bit) {
+ /* Look for zero in first char */
+ for (res = bit; res < 8; res++)
+ if (!test_bit (res, p))
+ return (p - addr) * 8 + res;
+ p++;
+ }
+ /* No zero yet, search remaining full bytes for a zero */
+ res = find_first_zero_bit (p, size - 8 * (p - addr));
+ return (p - addr) * 8 + res;
+}
+
+static inline int be_set_bit (int nr, void * addr) {
+ __u8 mask = 1 << (nr & 0x7);
+ __u8 *p = (__u8 *) addr + (nr >> 3);
+ __u8 old = *p;
+
+ *p |= mask;
+
+ return (old & mask) != 0;
+}
+
+static inline int be_clear_bit (int nr, void * addr) {
+ __u8 mask = 1 << (nr & 0x07);
+ __u8 *p = (unsigned char *) addr + (nr >> 3);
+ __u8 old = *p;
+
+ *p = *p & ~mask;
+ return (old & mask) != 0;
+}
+
+static inline int be_test_bit(int nr, const void * addr) {
+ const __u8 *ADDR = (__const__ __u8 *) addr;
+
+ return ((ADDR[nr >> 3] >> (nr & 0x7)) & 1) != 0;
+}
+
+static inline int be_find_first_zero_bit (const void *vaddr, unsigned size) {
+ return find_next_zero_bit( vaddr, size, 0 );
+}
+
+static inline unsigned long ffz(unsigned long word) {
+ unsigned long result = 0;
+
+ while(word & 1) {
+ result++;
+ word >>= 1;
+ }
+ return result;
+}
+
+/* stolen from linux/include/asm-mips/bitops.h:ext2_find_next_zero_bit()
+ * the bitfield is assumed to be little endian, which is the case here,
+ * since we're reading/writing from the disk in LE order */
+static inline int be_find_next_zero_bit (const void *vaddr, unsigned size,
unsigned offset) {
+ __u32 *p = ((__u32 *) vaddr) + (offset >> 5);
+ __u32 result = offset & ~31UL;
+ __u32 tmp;
+
+ if (offset >= size)
+ return size;
+ size -= result;
+ offset &= 31UL;
+ if (offset) {
+ tmp = *(p++);
+ tmp |= PED_SWAP32(~0UL >> (32-offset));
+ if (size < 32)
+ goto found_first;
+ if (~tmp)
+ goto found_middle;
+ size -= 32;
+ result += 32;
+ }
+ while (size & ~31UL) {
+ if (~(tmp = *(p++)))
+ goto found_middle;
+ result += 32;
+ size -= 32;
+ }
+ if (!size)
+ return result;
+ tmp = *p;
+
+found_first:
+// return result + ffz(swab32(tmp) | (~0UL << size));
+ return result + ffz(PED_SWAP32(tmp) | (~0UL << size));
+found_middle:
+// return result + ffz(swab32(tmp));
+ return result + ffz(PED_SWAP32(tmp));
+}
+
+inline int set_bit (int nr, void * addr) {
+#ifndef WORDS_BIGENDIAN
+ return le_set_bit( nr, addr );
+#else
+ return be_set_bit( nr, addr );
+#endif
+ return 0;
+}
+
+inline int clear_bit (int nr, void * addr) {
+#ifndef WORDS_BIGENDIAN
+ return le_clear_bit( nr, addr );
+#else
+ return be_clear_bit( nr, addr );
+#endif
+ return 0;
+}
+
+inline int test_bit(int nr, const void * addr) {
+#ifndef WORDS_BIGENDIAN
+ return le_test_bit( nr, addr );
+#else
+ return be_test_bit( nr, addr );
+#endif
+ return 0;
+}
+
+inline int find_first_zero_bit (const void *vaddr, unsigned size) {
+#ifndef WORDS_BIGENDIAN
+ return le_find_first_zero_bit( vaddr, size );
+#else
+ return be_find_first_zero_bit( vaddr, size );
+#endif
+ return 0;
+}
+
+inline int find_next_zero_bit (const void *vaddr, unsigned size, unsigned
offset) {
+#ifndef WORDS_BIGENDIAN
+ return le_find_next_zero_bit( vaddr, size, offset );
+#else
+ return be_find_next_zero_bit( vaddr, size, offset );
+#endif
+ return 0;
+}
+
+/* Signature checking functions */
+int is_reiserfs_3_5_magic_string (const char *s_magic) {
+ return (!strncmp (s_magic, REISERFS_SUPER_MAGIC_STRING,
+ strlen (REISERFS_SUPER_MAGIC_STRING)));
+}
+
+int is_reiserfs_3_6_magic_string (const char *s_magic) {
+ return (!strncmp (s_magic, REISER2FS_SUPER_MAGIC_STRING,
+ strlen (REISER2FS_SUPER_MAGIC_STRING)));
+}
+
+int is_any_reiserfs_magic_string (const char *s_magic) {
+ if (is_reiserfs_3_5_magic_string (s_magic) ||
+ is_reiserfs_3_6_magic_string (s_magic))
+ return 1;
+ return 0;
+}
diff -rupN ./parted-1.5.5/libparted/fs_reiserfs/reiserfs_tools.h
./parted-reiser-1.5.5/libparted/fs_reiserfs/reiserfs_tools.h
--- ./parted-1.5.5/libparted/fs_reiserfs/reiserfs_tools.h Thu Jan 1
03:00:00 1970
+++ ./parted-reiser-1.5.5/libparted/fs_reiserfs/reiserfs_tools.h Sun Jan
6 15:23:00 2002
@@ -0,0 +1,45 @@
+/*
+ reiserfs_tools.h -- reiserfs tools
+ Copyright (C) 1998, 1999, 2000, 2001 Free Software Foundation, Inc.
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+*/
+
+/*
+ Some parts of this code are from original reiserfs code,
+ as found in the reiserfs-progs-3.x.0k-pre10.
+ Writen by Yury Umanets (address@hidden)
+*/
+
+#ifndef REISERFS_TOOLS_H
+#define REISERFS_TOOLS_H
+
+static const char _reiserfs_tools_h[] = "$Id: reiserfs_tools.h,v 1.55
2002/01/04 20:19:21 yumanets Exp $";
+
+inline int set_bit (int nr, void * addr);
+inline int clear_bit (int nr, void * addr);
+inline int test_bit(int nr, const void * addr);
+inline int find_first_zero_bit (const void *vaddr, unsigned size);
+inline int find_next_zero_bit (const void *vaddr, unsigned size, unsigned
offset);
+
+/* Signatures checking function */
+#define REISERFS_SUPER_MAGIC_STRING "ReIsErFs"
+#define REISER2FS_SUPER_MAGIC_STRING "ReIsEr2Fs"
+
+int is_reiserfs_3_5_magic_string (const char *s_magic);
+int is_reiserfs_3_6_magic_string (const char *s_magic);
+int is_any_reiserfs_magic_string (const char *s_magic);
+
+#endif
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- Reiserfs patch,
Yura Umanets <=