Imported reiserfsprogs-3.6.2
This commit is contained in:
1 parent
e7102bdb66
commit
b69459eb80
86 files changed
+23136
-13423
No files matched your search
+161
-92
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 1996-2001 Hans Reiser
|
||||
* Copyright 1996-2002 Hans Reiser
|
||||
*/
|
||||
#include "fsck.h"
|
||||
|
||||
@@ -10,25 +10,28 @@
|
||||
*/
|
||||
|
||||
|
||||
|
||||
/* is it marked used in super block's objectid map */
|
||||
int is_objectid_used (reiserfs_filsys_t s, __u32 objectid)
|
||||
#if 0
|
||||
/* is it marked used in super block's objectid map. fixme: binary search could
|
||||
be used here */
|
||||
int is_objectid_used (reiserfs_filsys_t * fs, __u32 objectid)
|
||||
{
|
||||
__u32 * objectid_map;
|
||||
int i = 0;
|
||||
|
||||
objectid_map = (__u32 *)((char *)(s->s_rs) + (sb_size(s)));
|
||||
|
||||
objectid_map = (__u32 *)((char *)(fs->fs_ondisk_sb) + (sb_size(fs)));
|
||||
|
||||
while (i < SB_OBJECTID_MAP_SIZE (s)) {
|
||||
if (objectid == objectid_map[i]) {
|
||||
while (i < get_sb_oid_cursize (fs->fs_ondisk_sb)) {
|
||||
if (objectid == le32_to_cpu (objectid_map[i])) {
|
||||
return 1; /* objectid is used */
|
||||
}
|
||||
|
||||
if (objectid > objectid_map[i] && objectid < objectid_map[i+1]) {
|
||||
if (objectid > le32_to_cpu(objectid_map[i]) &&
|
||||
objectid < le32_to_cpu(objectid_map[i+1])) {
|
||||
return 1; /* objectid is used */
|
||||
}
|
||||
|
||||
if (objectid < objectid_map[i])
|
||||
if (objectid < le32_to_cpu(objectid_map[i]))
|
||||
break;
|
||||
|
||||
i += 2;
|
||||
@@ -37,25 +40,22 @@ int is_objectid_used (reiserfs_filsys_t s, __u32 objectid)
|
||||
/* objectid is free */
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
/* true objectid map */
|
||||
|
||||
|
||||
/* size of 1 piece of map */
|
||||
#define MAP_SIZE 4096 /* must be n * 2 * sizeof(__u32) */
|
||||
#define MAX_MAP_SIZE 1 /* % of available memory? */
|
||||
|
||||
|
||||
|
||||
/* increase area by MAP_SIZE bytes */
|
||||
static void grow_id_map (struct id_map * map)
|
||||
{
|
||||
/*
|
||||
if (map->m_page_count && ((map->m_page_count % 5) == 0)) {
|
||||
fsck_log ("grow_id_map: objectid map expanded: used %lu, %d blocks\n",
|
||||
map->m_used_slots_count, map->m_page_count);
|
||||
}
|
||||
*/
|
||||
map->m_begin = expandmem (map->m_begin, map->m_page_count * MAP_SIZE, MAP_SIZE);
|
||||
map->m_page_count ++;
|
||||
}
|
||||
@@ -64,9 +64,11 @@ static void grow_id_map (struct id_map * map)
|
||||
static void try_to_shrink_id_map (struct id_map * map)
|
||||
{
|
||||
if (map->m_used_slots_count * sizeof(__u32) <= (map->m_page_count - 1) * MAP_SIZE) {
|
||||
/*
|
||||
if (map->m_page_count && ((map->m_page_count % 5) == 0))
|
||||
fsck_log ("shrink_id_map: objectid map shrinked: used %lu, %d blocks\n",
|
||||
map->m_used_slots_count, map->m_page_count);
|
||||
*/
|
||||
map->m_begin = expandmem (map->m_begin, map->m_page_count * MAP_SIZE,
|
||||
-MAP_SIZE);
|
||||
map->m_page_count--;
|
||||
@@ -81,42 +83,26 @@ static void try_to_shrink_id_map (struct id_map * map)
|
||||
static void check_id_search_result(struct id_map * map, int res, __u32 pos,
|
||||
__u32 id)
|
||||
{
|
||||
if (res != ITEM_FOUND && res != ITEM_NOT_FOUND)
|
||||
if (res != POSITION_FOUND && res != POSITION_NOT_FOUND)
|
||||
die("check_id_search_result: get wrong result from ubin_search (%d)", res);
|
||||
|
||||
if (res == 1 && *(map->m_begin + pos) != id)
|
||||
die("check_id_search_result: wrong id found %u %u", id, *(map->m_begin + pos));
|
||||
if (res == 1 && le32_to_cpu (map->m_begin[pos]) != id)
|
||||
die("check_id_search_result: wrong id found %u %u", id, le32_to_cpu(map->m_begin[pos]));
|
||||
|
||||
if (res == 1)
|
||||
{
|
||||
if (pos > map->m_used_slots_count)
|
||||
die("check_id_search_result: get bad position (%u), used %u",
|
||||
die("check_id_search_result: get bad position (%u), used %u",
|
||||
pos, map->m_used_slots_count);
|
||||
if (pos >= 0 && pos <= map->m_used_slots_count && *(map->m_begin + pos - 1) >= id)
|
||||
if (pos >= 0 && pos <= map->m_used_slots_count && le32_to_cpu(map->m_begin[pos - 1]) >= id)
|
||||
die("check_id_search_result: previous id (%u) not less than (%u)",
|
||||
*(map->m_begin + pos - 1), id);
|
||||
if (pos >= 0 && pos < map->m_used_slots_count && *(map->m_begin + pos) < id)
|
||||
le32_to_cpu(map->m_begin[pos - 1]), id);
|
||||
if (pos >= 0 && pos < map->m_used_slots_count && le32_to_cpu(map->m_begin[pos]) < id)
|
||||
die("check_id_search_result: found id (%u) not much than (%u)",
|
||||
*(map->m_begin + pos), id);
|
||||
le32_to_cpu(map->m_begin[pos]), id);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static int comp_ids (void * p1, void * p2)
|
||||
{
|
||||
__u32 * id1, * id2;
|
||||
|
||||
id1 = p1;
|
||||
id2 = p2;
|
||||
|
||||
if ( *id1 < *id2 )
|
||||
return -1;
|
||||
if ( *id1 > *id2 )
|
||||
return 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/* */
|
||||
struct id_map * init_id_map (void)
|
||||
{
|
||||
@@ -132,18 +118,18 @@ struct id_map * init_id_map (void)
|
||||
|
||||
|
||||
/* free whole map */
|
||||
void free_id_map (struct id_map ** map)
|
||||
void free_id_map (struct id_map * map)
|
||||
{
|
||||
freemem ((*map)->m_begin);
|
||||
freemem (*map);
|
||||
*map = 0;
|
||||
freemem (map->m_begin);
|
||||
freemem (map);
|
||||
}
|
||||
|
||||
|
||||
/* return 1 if id is marked used, 0 otherwise */
|
||||
int is_objectid_really_used (struct id_map * map, __u32 id, int * ppos)
|
||||
int is_objectid_really_used (struct id_map * map, __u32 id, __u32 * ppos)
|
||||
{
|
||||
int res;
|
||||
__u32 le_id = cpu_to_le32 (id);
|
||||
|
||||
*ppos = 0;
|
||||
|
||||
@@ -151,13 +137,14 @@ int is_objectid_really_used (struct id_map * map, __u32 id, int * ppos)
|
||||
return 0;
|
||||
|
||||
/* smth exists in the map, find proper place to insert or this id */
|
||||
res = ubin_search (&id, map->m_begin, map->m_used_slots_count, sizeof (__u32), ppos, comp_ids);
|
||||
res = reiserfs_bin_search (&le_id, map->m_begin, map->m_used_slots_count,
|
||||
sizeof (__u32), ppos, comp_ids);
|
||||
#if 1
|
||||
check_id_search_result (map, res, *ppos, id);
|
||||
#endif
|
||||
/* *ppos is position in objectid map of the element which is equal id
|
||||
or position of an element which is smallest and greater than id */
|
||||
if (res == ITEM_NOT_FOUND)
|
||||
if (res == POSITION_NOT_FOUND)
|
||||
/* id is not found in the map. if returned position is odd -
|
||||
id is marked used */
|
||||
return (*ppos % 2);
|
||||
@@ -166,26 +153,30 @@ int is_objectid_really_used (struct id_map * map, __u32 id, int * ppos)
|
||||
return !(*ppos % 2);
|
||||
}
|
||||
|
||||
|
||||
static void check_objectid_map (struct id_map * map)
|
||||
static void check_objectid_map (struct id_map * map, int pos)
|
||||
{
|
||||
/* check only previous id, current and 2 next ones,
|
||||
if not specified to check evth */
|
||||
int count = 3;
|
||||
int i;
|
||||
int first = pos;
|
||||
|
||||
for (i = 1; i < map->m_used_slots_count; i ++)
|
||||
if (map->m_begin [i - 1] >= map->m_begin [i])
|
||||
if (first == 0) {
|
||||
first = 1;
|
||||
} else if (first == -1) {
|
||||
count = map->m_used_slots_count - 1;
|
||||
first = 1;
|
||||
}
|
||||
|
||||
if (first + count > map->m_used_slots_count)
|
||||
count = map->m_used_slots_count - first;
|
||||
|
||||
for (i = first; i < first + count; i ++)
|
||||
if (le32_to_cpu(map->m_begin [i - 1]) >= le32_to_cpu(map->m_begin [i]))
|
||||
die ("check_objectid_map: map corrupted");
|
||||
}
|
||||
|
||||
|
||||
/* returns 1 objectid is marked used already, 0 otherwise */
|
||||
int mark_objectid_really_used (struct id_map * map, __u32 id)
|
||||
{
|
||||
int pos;
|
||||
|
||||
|
||||
/* check whether id is used and get place if used or place to insert if not */
|
||||
if (is_objectid_really_used (map, id, &pos) == 1)
|
||||
return 1;
|
||||
int __mark_objectid_really_used(struct id_map *map, __u32 id, __u32 pos) {
|
||||
|
||||
map->objectids_marked ++;
|
||||
if (pos % 2 == 0){
|
||||
@@ -200,7 +191,7 @@ int mark_objectid_really_used (struct id_map * map, __u32 id)
|
||||
/* we can mark id as used w/o expanding of id map */
|
||||
map->m_begin[pos] = cpu_to_le32 (id);
|
||||
|
||||
check_objectid_map (map);
|
||||
check_objectid_map (map, pos);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -215,7 +206,7 @@ int mark_objectid_really_used (struct id_map * map, __u32 id)
|
||||
map->m_begin[pos] = cpu_to_le32 (id);
|
||||
map->m_begin[pos+1] = cpu_to_le32 (id + 1);
|
||||
|
||||
check_objectid_map (map);
|
||||
check_objectid_map (map, pos);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -226,19 +217,31 @@ int mark_objectid_really_used (struct id_map * map, __u32 id)
|
||||
/* if end id of current interval == start id of next interval we
|
||||
eliminated a sequence of unused objectids */
|
||||
if (pos + 1 < map->m_used_slots_count &&
|
||||
map->m_begin[pos + 1] == map->m_begin[pos]) {
|
||||
map->m_begin[pos + 1] == map->m_begin[pos]) { /* safe, both are le */
|
||||
memmove (map->m_begin + pos, map->m_begin + pos + 2, (map->m_used_slots_count - pos - 2) * sizeof (__u32));
|
||||
map->m_used_slots_count -= 2;
|
||||
try_to_shrink_id_map (map);
|
||||
}
|
||||
|
||||
check_objectid_map (map);
|
||||
check_objectid_map (map, pos);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* returns 1 objectid is marked used already, 0 otherwise */
|
||||
int mark_objectid_really_used (struct id_map * map, __u32 id)
|
||||
{
|
||||
__u32 pos;
|
||||
|
||||
static __u32 get_free_id (reiserfs_filsys_t fs)
|
||||
/* check whether id is used and get place if used or place to insert if not */
|
||||
if (is_objectid_really_used (map, id, &pos) == 1)
|
||||
return 1;
|
||||
|
||||
return __mark_objectid_really_used(map, id, pos) ;
|
||||
}
|
||||
|
||||
|
||||
static __u32 get_free_id (reiserfs_filsys_t * fs)
|
||||
{
|
||||
struct id_map * map;
|
||||
|
||||
@@ -256,13 +259,14 @@ static __u32 get_free_id (reiserfs_filsys_t fs)
|
||||
}
|
||||
|
||||
|
||||
__u32 get_unused_objectid (reiserfs_filsys_t fs)
|
||||
__u32 get_unused_objectid (reiserfs_filsys_t * fs)
|
||||
{
|
||||
__u32 objectid;
|
||||
|
||||
objectid = get_free_id (fs);
|
||||
if (mark_objectid_really_used (proper_id_map (fs), objectid))
|
||||
die ("get_unused_objectid: could not mark %lu used", objectid);
|
||||
die ("get_unused_objectid: could not mark %lu used",
|
||||
( long unsigned ) objectid);
|
||||
|
||||
return objectid;
|
||||
}
|
||||
@@ -274,7 +278,7 @@ __u32 get_unused_objectid (reiserfs_filsys_t fs)
|
||||
#if 0
|
||||
/* returns 0 if on-disk objectid map matches to the correct one, 1
|
||||
otherwise */
|
||||
int compare_id_maps (reiserfs_filsys_t fs)
|
||||
int compare_id_maps (reiserfs_filsys_t * fs)
|
||||
{
|
||||
struct id_map * map;
|
||||
int disk_size;
|
||||
@@ -293,7 +297,7 @@ int compare_id_maps (reiserfs_filsys_t fs)
|
||||
|
||||
|
||||
/* copy objectid map into buffer containing super block */
|
||||
void correct_objectid_map (reiserfs_filsys_t fs)
|
||||
void correct_objectid_map (reiserfs_filsys_t * fs)
|
||||
{
|
||||
struct id_map * map;
|
||||
int size, disk_max;
|
||||
@@ -320,17 +324,15 @@ void correct_objectid_map (reiserfs_filsys_t fs)
|
||||
#endif
|
||||
|
||||
|
||||
#if 0
|
||||
/* print the map of objectids */
|
||||
void print_objectid_list ()
|
||||
void print_objectid_list (__u32 *map, int count)
|
||||
{
|
||||
int i;
|
||||
printf ("\n control id map: all %d, used:%d", id_map.m_page_count * MAP_SIZE, id_map.m_used_slots_count);
|
||||
|
||||
for (i = 0; i < id_map.m_used_slots_count; i += 2)
|
||||
printf ("\n[%u-%u]", id_map.m_begin[i], id_map.m_begin[i + 1] - 1);
|
||||
for (i = 0; i < count ; i += 2)
|
||||
printf ("\n[%u-%u]", le32_to_cpu(map[i]),le32_to_cpu(map[i+1]));
|
||||
}
|
||||
|
||||
#if 0
|
||||
/* print on-disk map of objectids */
|
||||
void print_disk_objectid_list (void)
|
||||
{
|
||||
@@ -339,53 +341,120 @@ void print_disk_objectid_list (void)
|
||||
printf ("\n on-disk id map. used:%lu", SB_OBJECTID_MAP_SIZE(&g_sb));
|
||||
|
||||
for (i = 0; i < SB_OBJECTID_MAP_SIZE(&g_sb); i += 2)
|
||||
printf ("\n[%u-%u]", objectid_map[i], objectid_map[i + 1] - 1);
|
||||
printf ("\n[%u-%u]", objectid_map[i], objectid_map[i + 1] - 1);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
void flush_objectid_map (struct id_map * map, reiserfs_filsys_t fs)
|
||||
void flush_objectid_map (struct id_map * map, reiserfs_filsys_t * fs)
|
||||
{
|
||||
int size, max;
|
||||
int sb_size;
|
||||
__u32 * sb_objectid_map;
|
||||
|
||||
sb_size = (is_reiser2fs_magic_string (fs->s_rs) ? SB_SIZE : SB_SIZE_V1);
|
||||
sb_objectid_map = (__u32 *)((char *)(fs->s_rs) + sb_size);
|
||||
sb_size = reiserfs_super_block_size (fs->fs_ondisk_sb);
|
||||
sb_objectid_map = (__u32 *)((char *)(fs->fs_ondisk_sb) + sb_size);
|
||||
|
||||
check_objectid_map (map);
|
||||
|
||||
max = ((fs->s_blocksize - sb_size) >> 3 << 1);
|
||||
set_objectid_map_max_size (fs->s_rs, max);
|
||||
max = ((fs->fs_blocksize - sb_size) >> 3 << 1);
|
||||
set_sb_oid_maxsize (fs->fs_ondisk_sb, max);
|
||||
if (map->m_used_slots_count > max)
|
||||
size = max;
|
||||
else
|
||||
size = map->m_used_slots_count;
|
||||
|
||||
check_objectid_map (map, -1);
|
||||
|
||||
memcpy (sb_objectid_map, map->m_begin, size * sizeof (__u32));
|
||||
memset (sb_objectid_map + size, 0, (max - size) * sizeof (__u32));
|
||||
|
||||
set_objectid_map_size (fs->s_rs, size);
|
||||
set_sb_oid_cursize (fs->fs_ondisk_sb, size);
|
||||
if (size == max)
|
||||
/*((__u32 *)((char *)(fs->s_rs) + sb_size))*/
|
||||
sb_objectid_map [max - 1] = map->m_begin [map->m_used_slots_count - 1];
|
||||
sb_objectid_map [max - 1] = map->m_begin [map->m_used_slots_count - 1];
|
||||
|
||||
check_objectid_map (map);
|
||||
// check_objectid_map (map);
|
||||
|
||||
}
|
||||
|
||||
|
||||
void fetch_objectid_map (struct id_map * map, reiserfs_filsys_t fs)
|
||||
void fetch_objectid_map (struct id_map * map, reiserfs_filsys_t * fs)
|
||||
{
|
||||
int sb_size;
|
||||
__u32 * sb_objectid_map;
|
||||
|
||||
sb_size = (is_reiser2fs_magic_string (fs->s_rs) ? SB_SIZE : SB_SIZE_V1);
|
||||
sb_objectid_map = (__u32 *)((char *)(fs->s_rs) + sb_size);
|
||||
sb_size = reiserfs_super_block_size (fs->fs_ondisk_sb);
|
||||
sb_objectid_map = (__u32 *)((char *)(fs->fs_ondisk_sb) + sb_size);
|
||||
|
||||
if (map->m_page_count != 1)
|
||||
die ("fetch_objectid_map: can not fetch long map");
|
||||
grow_id_map (map);
|
||||
memcpy (map->m_begin, sb_objectid_map, rs_objectid_map_size (fs->s_rs) * sizeof (__u32));
|
||||
map->m_used_slots_count = rs_objectid_map_size (fs->s_rs);
|
||||
memcpy (map->m_begin, sb_objectid_map, get_sb_oid_cursize (fs->fs_ondisk_sb) * sizeof (__u32));
|
||||
map->m_used_slots_count = get_sb_oid_cursize (fs->fs_ondisk_sb);
|
||||
}
|
||||
|
||||
#define OBJMAP_START_MAGIC 375331
|
||||
#define OBJMAP_END_MAGIC 7700472
|
||||
|
||||
void reiserfs_objectid_map_save (FILE * fp, struct id_map * id_map)
|
||||
{
|
||||
__u32 v;
|
||||
int i;
|
||||
|
||||
v = OBJMAP_START_MAGIC;
|
||||
fwrite (&v, 4, 1, fp);
|
||||
|
||||
v = id_map->m_used_slots_count;
|
||||
fwrite (&v, 4, 1, fp);
|
||||
|
||||
for (i = 0; i < id_map->m_page_count - 1; i++) {
|
||||
fwrite ((char *)id_map->m_begin + MAP_SIZE * i, 4, 1, fp);
|
||||
}
|
||||
|
||||
for (i = 0; i < id_map->m_used_slots_count * sizeof(__u32) - (id_map->m_page_count - 1) * MAP_SIZE; i++) {
|
||||
fwrite ((char *)id_map->m_begin + MAP_SIZE * (id_map->m_page_count - 1) + i, 4, 1, fp);
|
||||
}
|
||||
|
||||
v = OBJMAP_END_MAGIC;
|
||||
fwrite (&v, 4, 1, fp);
|
||||
}
|
||||
|
||||
struct id_map * reiserfs_objectid_map_load (FILE * fp)
|
||||
{
|
||||
__u32 v;
|
||||
int i;
|
||||
struct id_map * id_map;
|
||||
|
||||
fread (&v, 4, 1, fp);
|
||||
if (v != OBJMAP_START_MAGIC) {
|
||||
reiserfs_warning (stderr, "reiserfs_objectid_map_load: no objectid map begin magic found");
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* read bit size of objectid map */
|
||||
fread (&v, 4, 1, fp);
|
||||
|
||||
id_map = init_id_map ();
|
||||
|
||||
id_map->m_used_slots_count = v;
|
||||
id_map->m_page_count = v / MAP_SIZE + 1;
|
||||
|
||||
id_map->m_begin = expandmem (id_map->m_begin, 0, id_map->m_page_count * MAP_SIZE);
|
||||
|
||||
for (i = 0; i < id_map->m_page_count - 1; i++) {
|
||||
fread ((char *)id_map->m_begin + MAP_SIZE * i, 4, 1, fp);
|
||||
}
|
||||
|
||||
for (i = 0; i < id_map->m_used_slots_count * sizeof(__u32) - (id_map->m_page_count - 1) * MAP_SIZE; i++) {
|
||||
fread ((char *)id_map->m_begin + MAP_SIZE * (id_map->m_page_count - 1) + i, 4, 1, fp);
|
||||
}
|
||||
|
||||
fread (&v, 4, 1, fp);
|
||||
|
||||
if (v != OBJMAP_END_MAGIC) {
|
||||
reiserfs_warning (stderr, "reiserfs_objectid_map_load: no objectid map end magic found");
|
||||
return 0;
|
||||
}
|
||||
|
||||
fflush (stderr);
|
||||
return id_map;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user