ChangeLog, Makefile.in, e2image.h, ext2_err.et.in, ext2fs.h, imager.c:
imager.c (ext2fs_image_{inode,super,bitmap}_{read,write}, ext2_fs.h,
Makefile.in: New file that has routines that save ext2fs metadata to a
file.
ext2_err.et.in (EXT2_ET_MAGIC_E2IMAGE): New error code assigned.
e2image.h: New file which defines the file format for the ext2 image
file. (Saved copy of ext2 metadata to a file as a saving throw
against worst-case damage.)
ChangeLog, Makefile.in, e2image.c:
e2image.c, Makefile.in: New program which saves ext2 metadata to a
file for people who need a last-ditch saving throw.
2000-11-12 22:32:20 +03:00
|
|
|
/*
|
|
|
|
* image.c --- writes out the critical parts of the filesystem as a
|
|
|
|
* flat file.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2000 Theodore Ts'o.
|
|
|
|
*
|
|
|
|
* Note: this uses the POSIX IO interfaces, unlike most of the other
|
2008-08-28 07:07:54 +04:00
|
|
|
* functions in this library. So sue me.
|
ChangeLog, Makefile.in, e2image.h, ext2_err.et.in, ext2fs.h, imager.c:
imager.c (ext2fs_image_{inode,super,bitmap}_{read,write}, ext2_fs.h,
Makefile.in: New file that has routines that save ext2fs metadata to a
file.
ext2_err.et.in (EXT2_ET_MAGIC_E2IMAGE): New error code assigned.
e2image.h: New file which defines the file format for the ext2 image
file. (Saved copy of ext2 metadata to a file as a saving throw
against worst-case damage.)
ChangeLog, Makefile.in, e2image.c:
e2image.c, Makefile.in: New program which saves ext2 metadata to a
file for people who need a last-ditch saving throw.
2000-11-12 22:32:20 +03:00
|
|
|
*
|
|
|
|
* %Begin-Header%
|
2010-05-18 05:31:56 +04:00
|
|
|
* This file may be redistributed under the terms of the GNU Library
|
|
|
|
* General Public License, version 2.
|
ChangeLog, Makefile.in, e2image.h, ext2_err.et.in, ext2fs.h, imager.c:
imager.c (ext2fs_image_{inode,super,bitmap}_{read,write}, ext2_fs.h,
Makefile.in: New file that has routines that save ext2fs metadata to a
file.
ext2_err.et.in (EXT2_ET_MAGIC_E2IMAGE): New error code assigned.
e2image.h: New file which defines the file format for the ext2 image
file. (Saved copy of ext2 metadata to a file as a saving throw
against worst-case damage.)
ChangeLog, Makefile.in, e2image.c:
e2image.c, Makefile.in: New program which saves ext2 metadata to a
file for people who need a last-ditch saving throw.
2000-11-12 22:32:20 +03:00
|
|
|
* %End-Header%
|
|
|
|
*/
|
|
|
|
|
2011-09-19 01:34:37 +04:00
|
|
|
#include "config.h"
|
ChangeLog, Makefile.in, e2image.h, ext2_err.et.in, ext2fs.h, imager.c:
imager.c (ext2fs_image_{inode,super,bitmap}_{read,write}, ext2_fs.h,
Makefile.in: New file that has routines that save ext2fs metadata to a
file.
ext2_err.et.in (EXT2_ET_MAGIC_E2IMAGE): New error code assigned.
e2image.h: New file which defines the file format for the ext2 image
file. (Saved copy of ext2 metadata to a file as a saving throw
against worst-case damage.)
ChangeLog, Makefile.in, e2image.c:
e2image.c, Makefile.in: New program which saves ext2 metadata to a
file for people who need a last-ditch saving throw.
2000-11-12 22:32:20 +03:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
#if HAVE_UNISTD_H
|
|
|
|
#include <unistd.h>
|
|
|
|
#endif
|
|
|
|
#if HAVE_ERRNO_H
|
|
|
|
#include <errno.h>
|
|
|
|
#endif
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <time.h>
|
|
|
|
#if HAVE_SYS_STAT_H
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#endif
|
|
|
|
#if HAVE_SYS_TYPES_H
|
|
|
|
#include <sys/types.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "ext2_fs.h"
|
|
|
|
#include "ext2fs.h"
|
|
|
|
|
2003-04-13 08:44:19 +04:00
|
|
|
#ifndef HAVE_TYPE_SSIZE_T
|
|
|
|
typedef int ssize_t;
|
|
|
|
#endif
|
|
|
|
|
ChangeLog, Makefile.in, e2image.h, ext2_err.et.in, ext2fs.h, imager.c:
imager.c (ext2fs_image_{inode,super,bitmap}_{read,write}, ext2_fs.h,
Makefile.in: New file that has routines that save ext2fs metadata to a
file.
ext2_err.et.in (EXT2_ET_MAGIC_E2IMAGE): New error code assigned.
e2image.h: New file which defines the file format for the ext2 image
file. (Saved copy of ext2 metadata to a file as a saving throw
against worst-case damage.)
ChangeLog, Makefile.in, e2image.c:
e2image.c, Makefile.in: New program which saves ext2 metadata to a
file for people who need a last-ditch saving throw.
2000-11-12 22:32:20 +03:00
|
|
|
/*
|
|
|
|
* This function returns 1 if the specified block is all zeros
|
|
|
|
*/
|
|
|
|
static int check_zero_block(char *buf, int blocksize)
|
|
|
|
{
|
|
|
|
char *cp = buf;
|
|
|
|
int left = blocksize;
|
|
|
|
|
|
|
|
while (left > 0) {
|
|
|
|
if (*cp++)
|
|
|
|
return 0;
|
|
|
|
left--;
|
|
|
|
}
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Write the inode table out as a single block.
|
|
|
|
*/
|
|
|
|
#define BUF_BLOCKS 32
|
|
|
|
|
|
|
|
errcode_t ext2fs_image_inode_write(ext2_filsys fs, int fd, int flags)
|
|
|
|
{
|
|
|
|
unsigned int group, left, c, d;
|
|
|
|
char *buf, *cp;
|
2010-06-13 19:00:00 +04:00
|
|
|
blk64_t blk;
|
ChangeLog, Makefile.in, e2image.h, ext2_err.et.in, ext2fs.h, imager.c:
imager.c (ext2fs_image_{inode,super,bitmap}_{read,write}, ext2_fs.h,
Makefile.in: New file that has routines that save ext2fs metadata to a
file.
ext2_err.et.in (EXT2_ET_MAGIC_E2IMAGE): New error code assigned.
e2image.h: New file which defines the file format for the ext2 image
file. (Saved copy of ext2 metadata to a file as a saving throw
against worst-case damage.)
ChangeLog, Makefile.in, e2image.c:
e2image.c, Makefile.in: New program which saves ext2 metadata to a
file for people who need a last-ditch saving throw.
2000-11-12 22:32:20 +03:00
|
|
|
ssize_t actual;
|
|
|
|
errcode_t retval;
|
2013-12-12 22:14:50 +04:00
|
|
|
off_t r;
|
ChangeLog, Makefile.in, e2image.h, ext2_err.et.in, ext2fs.h, imager.c:
imager.c (ext2fs_image_{inode,super,bitmap}_{read,write}, ext2_fs.h,
Makefile.in: New file that has routines that save ext2fs metadata to a
file.
ext2_err.et.in (EXT2_ET_MAGIC_E2IMAGE): New error code assigned.
e2image.h: New file which defines the file format for the ext2 image
file. (Saved copy of ext2 metadata to a file as a saving throw
against worst-case damage.)
ChangeLog, Makefile.in, e2image.c:
e2image.c, Makefile.in: New program which saves ext2 metadata to a
file for people who need a last-ditch saving throw.
2000-11-12 22:32:20 +03:00
|
|
|
|
|
|
|
buf = malloc(fs->blocksize * BUF_BLOCKS);
|
|
|
|
if (!buf)
|
|
|
|
return ENOMEM;
|
2008-08-28 07:07:54 +04:00
|
|
|
|
ChangeLog, Makefile.in, e2image.h, ext2_err.et.in, ext2fs.h, imager.c:
imager.c (ext2fs_image_{inode,super,bitmap}_{read,write}, ext2_fs.h,
Makefile.in: New file that has routines that save ext2fs metadata to a
file.
ext2_err.et.in (EXT2_ET_MAGIC_E2IMAGE): New error code assigned.
e2image.h: New file which defines the file format for the ext2 image
file. (Saved copy of ext2 metadata to a file as a saving throw
against worst-case damage.)
ChangeLog, Makefile.in, e2image.c:
e2image.c, Makefile.in: New program which saves ext2 metadata to a
file for people who need a last-ditch saving throw.
2000-11-12 22:32:20 +03:00
|
|
|
for (group = 0; group < fs->group_desc_count; group++) {
|
Convert to use block group accessor functions
Convert direct accesses to use the following block group accessor
functions: ext2fs_block_bitmap_loc(), ext2fs_inode_bitmap_loc(),
ext2fs_inode_table_loc(), ext2fs_bg_itable_unused(),
ext2fs_block_bitmap_loc_set(), ext2fs_inode_bitmap_loc_set(),
ext2fs_inode_table_loc_set(), ext2fs_bg_free_inodes_count(),
ext2fs_ext2fs_bg_used_dirs_count(), ext2fs_bg_free_inodes_count_set(),
ext2fs_bg_free_blocks_count_set(), ext2fs_bg_used_dirs_count_set()
Signed-off-by: Valerie Aurora Henson <vaurora@redhat.com>
Signed-off-by: Nick Dokos <nicholas.dokos@hp.com>
Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
2009-10-26 04:43:47 +03:00
|
|
|
blk = ext2fs_inode_table_loc(fs, (unsigned)group);
|
2007-03-22 00:43:37 +03:00
|
|
|
if (!blk) {
|
|
|
|
retval = EXT2_ET_MISSING_INODE_TABLE;
|
|
|
|
goto errout;
|
|
|
|
}
|
ChangeLog, Makefile.in, e2image.h, ext2_err.et.in, ext2fs.h, imager.c:
imager.c (ext2fs_image_{inode,super,bitmap}_{read,write}, ext2_fs.h,
Makefile.in: New file that has routines that save ext2fs metadata to a
file.
ext2_err.et.in (EXT2_ET_MAGIC_E2IMAGE): New error code assigned.
e2image.h: New file which defines the file format for the ext2 image
file. (Saved copy of ext2 metadata to a file as a saving throw
against worst-case damage.)
ChangeLog, Makefile.in, e2image.c:
e2image.c, Makefile.in: New program which saves ext2 metadata to a
file for people who need a last-ditch saving throw.
2000-11-12 22:32:20 +03:00
|
|
|
left = fs->inode_blocks_per_group;
|
|
|
|
while (left) {
|
|
|
|
c = BUF_BLOCKS;
|
|
|
|
if (c > left)
|
|
|
|
c = left;
|
2009-09-08 05:14:24 +04:00
|
|
|
retval = io_channel_read_blk64(fs->io, blk, c, buf);
|
ChangeLog, Makefile.in, e2image.h, ext2_err.et.in, ext2fs.h, imager.c:
imager.c (ext2fs_image_{inode,super,bitmap}_{read,write}, ext2_fs.h,
Makefile.in: New file that has routines that save ext2fs metadata to a
file.
ext2_err.et.in (EXT2_ET_MAGIC_E2IMAGE): New error code assigned.
e2image.h: New file which defines the file format for the ext2 image
file. (Saved copy of ext2 metadata to a file as a saving throw
against worst-case damage.)
ChangeLog, Makefile.in, e2image.c:
e2image.c, Makefile.in: New program which saves ext2 metadata to a
file for people who need a last-ditch saving throw.
2000-11-12 22:32:20 +03:00
|
|
|
if (retval)
|
|
|
|
goto errout;
|
|
|
|
cp = buf;
|
|
|
|
while (c) {
|
|
|
|
if (!(flags & IMAGER_FLAG_SPARSEWRITE)) {
|
|
|
|
d = c;
|
|
|
|
goto skip_sparse;
|
|
|
|
}
|
|
|
|
/* Skip zero blocks */
|
|
|
|
if (check_zero_block(cp, fs->blocksize)) {
|
|
|
|
c--;
|
|
|
|
blk++;
|
|
|
|
left--;
|
|
|
|
cp += fs->blocksize;
|
2013-12-12 22:14:50 +04:00
|
|
|
r = lseek(fd, fs->blocksize, SEEK_CUR);
|
|
|
|
if (r < 0) {
|
|
|
|
retval = errno;
|
|
|
|
goto errout;
|
|
|
|
}
|
ChangeLog, Makefile.in, e2image.h, ext2_err.et.in, ext2fs.h, imager.c:
imager.c (ext2fs_image_{inode,super,bitmap}_{read,write}, ext2_fs.h,
Makefile.in: New file that has routines that save ext2fs metadata to a
file.
ext2_err.et.in (EXT2_ET_MAGIC_E2IMAGE): New error code assigned.
e2image.h: New file which defines the file format for the ext2 image
file. (Saved copy of ext2 metadata to a file as a saving throw
against worst-case damage.)
ChangeLog, Makefile.in, e2image.c:
e2image.c, Makefile.in: New program which saves ext2 metadata to a
file for people who need a last-ditch saving throw.
2000-11-12 22:32:20 +03:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
/* Find non-zero blocks */
|
|
|
|
for (d=1; d < c; d++) {
|
|
|
|
if (check_zero_block(cp + d*fs->blocksize, fs->blocksize))
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
skip_sparse:
|
|
|
|
actual = write(fd, cp, fs->blocksize * d);
|
|
|
|
if (actual == -1) {
|
2001-01-12 20:26:05 +03:00
|
|
|
retval = errno;
|
ChangeLog, Makefile.in, e2image.h, ext2_err.et.in, ext2fs.h, imager.c:
imager.c (ext2fs_image_{inode,super,bitmap}_{read,write}, ext2_fs.h,
Makefile.in: New file that has routines that save ext2fs metadata to a
file.
ext2_err.et.in (EXT2_ET_MAGIC_E2IMAGE): New error code assigned.
e2image.h: New file which defines the file format for the ext2 image
file. (Saved copy of ext2 metadata to a file as a saving throw
against worst-case damage.)
ChangeLog, Makefile.in, e2image.c:
e2image.c, Makefile.in: New program which saves ext2 metadata to a
file for people who need a last-ditch saving throw.
2000-11-12 22:32:20 +03:00
|
|
|
goto errout;
|
|
|
|
}
|
2003-12-07 09:28:50 +03:00
|
|
|
if (actual != (ssize_t) (fs->blocksize * d)) {
|
ChangeLog, Makefile.in, e2image.h, ext2_err.et.in, ext2fs.h, imager.c:
imager.c (ext2fs_image_{inode,super,bitmap}_{read,write}, ext2_fs.h,
Makefile.in: New file that has routines that save ext2fs metadata to a
file.
ext2_err.et.in (EXT2_ET_MAGIC_E2IMAGE): New error code assigned.
e2image.h: New file which defines the file format for the ext2 image
file. (Saved copy of ext2 metadata to a file as a saving throw
against worst-case damage.)
ChangeLog, Makefile.in, e2image.c:
e2image.c, Makefile.in: New program which saves ext2 metadata to a
file for people who need a last-ditch saving throw.
2000-11-12 22:32:20 +03:00
|
|
|
retval = EXT2_ET_SHORT_WRITE;
|
|
|
|
goto errout;
|
|
|
|
}
|
|
|
|
blk += d;
|
|
|
|
left -= d;
|
|
|
|
cp += fs->blocksize * d;
|
|
|
|
c -= d;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
retval = 0;
|
|
|
|
|
|
|
|
errout:
|
|
|
|
free(buf);
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Read in the inode table and stuff it into place
|
|
|
|
*/
|
2008-08-28 07:07:54 +04:00
|
|
|
errcode_t ext2fs_image_inode_read(ext2_filsys fs, int fd,
|
2003-12-07 09:28:50 +03:00
|
|
|
int flags EXT2FS_ATTR((unused)))
|
ChangeLog, Makefile.in, e2image.h, ext2_err.et.in, ext2fs.h, imager.c:
imager.c (ext2fs_image_{inode,super,bitmap}_{read,write}, ext2_fs.h,
Makefile.in: New file that has routines that save ext2fs metadata to a
file.
ext2_err.et.in (EXT2_ET_MAGIC_E2IMAGE): New error code assigned.
e2image.h: New file which defines the file format for the ext2 image
file. (Saved copy of ext2 metadata to a file as a saving throw
against worst-case damage.)
ChangeLog, Makefile.in, e2image.c:
e2image.c, Makefile.in: New program which saves ext2 metadata to a
file for people who need a last-ditch saving throw.
2000-11-12 22:32:20 +03:00
|
|
|
{
|
2001-01-12 20:26:05 +03:00
|
|
|
unsigned int group, c, left;
|
ChangeLog, Makefile.in, e2image.h, ext2_err.et.in, ext2fs.h, imager.c:
imager.c (ext2fs_image_{inode,super,bitmap}_{read,write}, ext2_fs.h,
Makefile.in: New file that has routines that save ext2fs metadata to a
file.
ext2_err.et.in (EXT2_ET_MAGIC_E2IMAGE): New error code assigned.
e2image.h: New file which defines the file format for the ext2 image
file. (Saved copy of ext2 metadata to a file as a saving throw
against worst-case damage.)
ChangeLog, Makefile.in, e2image.c:
e2image.c, Makefile.in: New program which saves ext2 metadata to a
file for people who need a last-ditch saving throw.
2000-11-12 22:32:20 +03:00
|
|
|
char *buf;
|
2010-06-13 19:00:00 +04:00
|
|
|
blk64_t blk;
|
ChangeLog, Makefile.in, e2image.h, ext2_err.et.in, ext2fs.h, imager.c:
imager.c (ext2fs_image_{inode,super,bitmap}_{read,write}, ext2_fs.h,
Makefile.in: New file that has routines that save ext2fs metadata to a
file.
ext2_err.et.in (EXT2_ET_MAGIC_E2IMAGE): New error code assigned.
e2image.h: New file which defines the file format for the ext2 image
file. (Saved copy of ext2 metadata to a file as a saving throw
against worst-case damage.)
ChangeLog, Makefile.in, e2image.c:
e2image.c, Makefile.in: New program which saves ext2 metadata to a
file for people who need a last-ditch saving throw.
2000-11-12 22:32:20 +03:00
|
|
|
ssize_t actual;
|
|
|
|
errcode_t retval;
|
|
|
|
|
|
|
|
buf = malloc(fs->blocksize * BUF_BLOCKS);
|
|
|
|
if (!buf)
|
|
|
|
return ENOMEM;
|
2008-08-28 07:07:54 +04:00
|
|
|
|
ChangeLog, Makefile.in, e2image.h, ext2_err.et.in, ext2fs.h, imager.c:
imager.c (ext2fs_image_{inode,super,bitmap}_{read,write}, ext2_fs.h,
Makefile.in: New file that has routines that save ext2fs metadata to a
file.
ext2_err.et.in (EXT2_ET_MAGIC_E2IMAGE): New error code assigned.
e2image.h: New file which defines the file format for the ext2 image
file. (Saved copy of ext2 metadata to a file as a saving throw
against worst-case damage.)
ChangeLog, Makefile.in, e2image.c:
e2image.c, Makefile.in: New program which saves ext2 metadata to a
file for people who need a last-ditch saving throw.
2000-11-12 22:32:20 +03:00
|
|
|
for (group = 0; group < fs->group_desc_count; group++) {
|
Convert to use block group accessor functions
Convert direct accesses to use the following block group accessor
functions: ext2fs_block_bitmap_loc(), ext2fs_inode_bitmap_loc(),
ext2fs_inode_table_loc(), ext2fs_bg_itable_unused(),
ext2fs_block_bitmap_loc_set(), ext2fs_inode_bitmap_loc_set(),
ext2fs_inode_table_loc_set(), ext2fs_bg_free_inodes_count(),
ext2fs_ext2fs_bg_used_dirs_count(), ext2fs_bg_free_inodes_count_set(),
ext2fs_bg_free_blocks_count_set(), ext2fs_bg_used_dirs_count_set()
Signed-off-by: Valerie Aurora Henson <vaurora@redhat.com>
Signed-off-by: Nick Dokos <nicholas.dokos@hp.com>
Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
2009-10-26 04:43:47 +03:00
|
|
|
blk = ext2fs_inode_table_loc(fs, (unsigned)group);
|
2001-01-12 20:26:05 +03:00
|
|
|
if (!blk) {
|
|
|
|
retval = EXT2_ET_MISSING_INODE_TABLE;
|
|
|
|
goto errout;
|
|
|
|
}
|
ChangeLog, Makefile.in, e2image.h, ext2_err.et.in, ext2fs.h, imager.c:
imager.c (ext2fs_image_{inode,super,bitmap}_{read,write}, ext2_fs.h,
Makefile.in: New file that has routines that save ext2fs metadata to a
file.
ext2_err.et.in (EXT2_ET_MAGIC_E2IMAGE): New error code assigned.
e2image.h: New file which defines the file format for the ext2 image
file. (Saved copy of ext2 metadata to a file as a saving throw
against worst-case damage.)
ChangeLog, Makefile.in, e2image.c:
e2image.c, Makefile.in: New program which saves ext2 metadata to a
file for people who need a last-ditch saving throw.
2000-11-12 22:32:20 +03:00
|
|
|
left = fs->inode_blocks_per_group;
|
|
|
|
while (left) {
|
|
|
|
c = BUF_BLOCKS;
|
|
|
|
if (c > left)
|
|
|
|
c = left;
|
|
|
|
actual = read(fd, buf, fs->blocksize * c);
|
|
|
|
if (actual == -1) {
|
2001-01-12 20:26:05 +03:00
|
|
|
retval = errno;
|
ChangeLog, Makefile.in, e2image.h, ext2_err.et.in, ext2fs.h, imager.c:
imager.c (ext2fs_image_{inode,super,bitmap}_{read,write}, ext2_fs.h,
Makefile.in: New file that has routines that save ext2fs metadata to a
file.
ext2_err.et.in (EXT2_ET_MAGIC_E2IMAGE): New error code assigned.
e2image.h: New file which defines the file format for the ext2 image
file. (Saved copy of ext2 metadata to a file as a saving throw
against worst-case damage.)
ChangeLog, Makefile.in, e2image.c:
e2image.c, Makefile.in: New program which saves ext2 metadata to a
file for people who need a last-ditch saving throw.
2000-11-12 22:32:20 +03:00
|
|
|
goto errout;
|
|
|
|
}
|
2003-12-07 09:28:50 +03:00
|
|
|
if (actual != (ssize_t) (fs->blocksize * c)) {
|
ChangeLog, Makefile.in, e2image.h, ext2_err.et.in, ext2fs.h, imager.c:
imager.c (ext2fs_image_{inode,super,bitmap}_{read,write}, ext2_fs.h,
Makefile.in: New file that has routines that save ext2fs metadata to a
file.
ext2_err.et.in (EXT2_ET_MAGIC_E2IMAGE): New error code assigned.
e2image.h: New file which defines the file format for the ext2 image
file. (Saved copy of ext2 metadata to a file as a saving throw
against worst-case damage.)
ChangeLog, Makefile.in, e2image.c:
e2image.c, Makefile.in: New program which saves ext2 metadata to a
file for people who need a last-ditch saving throw.
2000-11-12 22:32:20 +03:00
|
|
|
retval = EXT2_ET_SHORT_READ;
|
|
|
|
goto errout;
|
|
|
|
}
|
2009-09-08 05:14:24 +04:00
|
|
|
retval = io_channel_write_blk64(fs->io, blk, c, buf);
|
ChangeLog, Makefile.in, e2image.h, ext2_err.et.in, ext2fs.h, imager.c:
imager.c (ext2fs_image_{inode,super,bitmap}_{read,write}, ext2_fs.h,
Makefile.in: New file that has routines that save ext2fs metadata to a
file.
ext2_err.et.in (EXT2_ET_MAGIC_E2IMAGE): New error code assigned.
e2image.h: New file which defines the file format for the ext2 image
file. (Saved copy of ext2 metadata to a file as a saving throw
against worst-case damage.)
ChangeLog, Makefile.in, e2image.c:
e2image.c, Makefile.in: New program which saves ext2 metadata to a
file for people who need a last-ditch saving throw.
2000-11-12 22:32:20 +03:00
|
|
|
if (retval)
|
|
|
|
goto errout;
|
2008-08-28 07:07:54 +04:00
|
|
|
|
ChangeLog, Makefile.in, e2image.h, ext2_err.et.in, ext2fs.h, imager.c:
imager.c (ext2fs_image_{inode,super,bitmap}_{read,write}, ext2_fs.h,
Makefile.in: New file that has routines that save ext2fs metadata to a
file.
ext2_err.et.in (EXT2_ET_MAGIC_E2IMAGE): New error code assigned.
e2image.h: New file which defines the file format for the ext2 image
file. (Saved copy of ext2 metadata to a file as a saving throw
against worst-case damage.)
ChangeLog, Makefile.in, e2image.c:
e2image.c, Makefile.in: New program which saves ext2 metadata to a
file for people who need a last-ditch saving throw.
2000-11-12 22:32:20 +03:00
|
|
|
blk += c;
|
|
|
|
left -= c;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
retval = ext2fs_flush_icache(fs);
|
|
|
|
|
|
|
|
errout:
|
|
|
|
free(buf);
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Write out superblock and group descriptors
|
|
|
|
*/
|
2008-08-28 07:07:54 +04:00
|
|
|
errcode_t ext2fs_image_super_write(ext2_filsys fs, int fd,
|
2003-12-07 09:28:50 +03:00
|
|
|
int flags EXT2FS_ATTR((unused)))
|
ChangeLog, Makefile.in, e2image.h, ext2_err.et.in, ext2fs.h, imager.c:
imager.c (ext2fs_image_{inode,super,bitmap}_{read,write}, ext2_fs.h,
Makefile.in: New file that has routines that save ext2fs metadata to a
file.
ext2_err.et.in (EXT2_ET_MAGIC_E2IMAGE): New error code assigned.
e2image.h: New file which defines the file format for the ext2 image
file. (Saved copy of ext2 metadata to a file as a saving throw
against worst-case damage.)
ChangeLog, Makefile.in, e2image.c:
e2image.c, Makefile.in: New program which saves ext2 metadata to a
file for people who need a last-ditch saving throw.
2000-11-12 22:32:20 +03:00
|
|
|
{
|
|
|
|
char *buf, *cp;
|
|
|
|
ssize_t actual;
|
|
|
|
errcode_t retval;
|
|
|
|
|
|
|
|
buf = malloc(fs->blocksize);
|
|
|
|
if (!buf)
|
|
|
|
return ENOMEM;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Write out the superblock
|
|
|
|
*/
|
|
|
|
memset(buf, 0, fs->blocksize);
|
|
|
|
memcpy(buf, fs->super, SUPERBLOCK_SIZE);
|
|
|
|
actual = write(fd, buf, fs->blocksize);
|
|
|
|
if (actual == -1) {
|
2001-01-12 20:26:05 +03:00
|
|
|
retval = errno;
|
ChangeLog, Makefile.in, e2image.h, ext2_err.et.in, ext2fs.h, imager.c:
imager.c (ext2fs_image_{inode,super,bitmap}_{read,write}, ext2_fs.h,
Makefile.in: New file that has routines that save ext2fs metadata to a
file.
ext2_err.et.in (EXT2_ET_MAGIC_E2IMAGE): New error code assigned.
e2image.h: New file which defines the file format for the ext2 image
file. (Saved copy of ext2 metadata to a file as a saving throw
against worst-case damage.)
ChangeLog, Makefile.in, e2image.c:
e2image.c, Makefile.in: New program which saves ext2 metadata to a
file for people who need a last-ditch saving throw.
2000-11-12 22:32:20 +03:00
|
|
|
goto errout;
|
|
|
|
}
|
2003-12-07 09:28:50 +03:00
|
|
|
if (actual != (ssize_t) fs->blocksize) {
|
ChangeLog, Makefile.in, e2image.h, ext2_err.et.in, ext2fs.h, imager.c:
imager.c (ext2fs_image_{inode,super,bitmap}_{read,write}, ext2_fs.h,
Makefile.in: New file that has routines that save ext2fs metadata to a
file.
ext2_err.et.in (EXT2_ET_MAGIC_E2IMAGE): New error code assigned.
e2image.h: New file which defines the file format for the ext2 image
file. (Saved copy of ext2 metadata to a file as a saving throw
against worst-case damage.)
ChangeLog, Makefile.in, e2image.c:
e2image.c, Makefile.in: New program which saves ext2 metadata to a
file for people who need a last-ditch saving throw.
2000-11-12 22:32:20 +03:00
|
|
|
retval = EXT2_ET_SHORT_WRITE;
|
|
|
|
goto errout;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Now write out the block group descriptors
|
|
|
|
*/
|
|
|
|
cp = (char *) fs->group_desc;
|
|
|
|
actual = write(fd, cp, fs->blocksize * fs->desc_blocks);
|
|
|
|
if (actual == -1) {
|
2001-01-12 20:26:05 +03:00
|
|
|
retval = errno;
|
ChangeLog, Makefile.in, e2image.h, ext2_err.et.in, ext2fs.h, imager.c:
imager.c (ext2fs_image_{inode,super,bitmap}_{read,write}, ext2_fs.h,
Makefile.in: New file that has routines that save ext2fs metadata to a
file.
ext2_err.et.in (EXT2_ET_MAGIC_E2IMAGE): New error code assigned.
e2image.h: New file which defines the file format for the ext2 image
file. (Saved copy of ext2 metadata to a file as a saving throw
against worst-case damage.)
ChangeLog, Makefile.in, e2image.c:
e2image.c, Makefile.in: New program which saves ext2 metadata to a
file for people who need a last-ditch saving throw.
2000-11-12 22:32:20 +03:00
|
|
|
goto errout;
|
|
|
|
}
|
2003-12-07 09:28:50 +03:00
|
|
|
if (actual != (ssize_t) (fs->blocksize * fs->desc_blocks)) {
|
ChangeLog, Makefile.in, e2image.h, ext2_err.et.in, ext2fs.h, imager.c:
imager.c (ext2fs_image_{inode,super,bitmap}_{read,write}, ext2_fs.h,
Makefile.in: New file that has routines that save ext2fs metadata to a
file.
ext2_err.et.in (EXT2_ET_MAGIC_E2IMAGE): New error code assigned.
e2image.h: New file which defines the file format for the ext2 image
file. (Saved copy of ext2 metadata to a file as a saving throw
against worst-case damage.)
ChangeLog, Makefile.in, e2image.c:
e2image.c, Makefile.in: New program which saves ext2 metadata to a
file for people who need a last-ditch saving throw.
2000-11-12 22:32:20 +03:00
|
|
|
retval = EXT2_ET_SHORT_WRITE;
|
|
|
|
goto errout;
|
|
|
|
}
|
2008-08-28 07:07:54 +04:00
|
|
|
|
ChangeLog, Makefile.in, e2image.h, ext2_err.et.in, ext2fs.h, imager.c:
imager.c (ext2fs_image_{inode,super,bitmap}_{read,write}, ext2_fs.h,
Makefile.in: New file that has routines that save ext2fs metadata to a
file.
ext2_err.et.in (EXT2_ET_MAGIC_E2IMAGE): New error code assigned.
e2image.h: New file which defines the file format for the ext2 image
file. (Saved copy of ext2 metadata to a file as a saving throw
against worst-case damage.)
ChangeLog, Makefile.in, e2image.c:
e2image.c, Makefile.in: New program which saves ext2 metadata to a
file for people who need a last-ditch saving throw.
2000-11-12 22:32:20 +03:00
|
|
|
retval = 0;
|
|
|
|
|
|
|
|
errout:
|
|
|
|
free(buf);
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Read the superblock and group descriptors and overwrite them.
|
|
|
|
*/
|
2008-08-28 07:07:54 +04:00
|
|
|
errcode_t ext2fs_image_super_read(ext2_filsys fs, int fd,
|
2003-12-07 09:28:50 +03:00
|
|
|
int flags EXT2FS_ATTR((unused)))
|
ChangeLog, Makefile.in, e2image.h, ext2_err.et.in, ext2fs.h, imager.c:
imager.c (ext2fs_image_{inode,super,bitmap}_{read,write}, ext2_fs.h,
Makefile.in: New file that has routines that save ext2fs metadata to a
file.
ext2_err.et.in (EXT2_ET_MAGIC_E2IMAGE): New error code assigned.
e2image.h: New file which defines the file format for the ext2 image
file. (Saved copy of ext2 metadata to a file as a saving throw
against worst-case damage.)
ChangeLog, Makefile.in, e2image.c:
e2image.c, Makefile.in: New program which saves ext2 metadata to a
file for people who need a last-ditch saving throw.
2000-11-12 22:32:20 +03:00
|
|
|
{
|
2001-01-12 20:26:05 +03:00
|
|
|
char *buf;
|
ChangeLog, Makefile.in, e2image.h, ext2_err.et.in, ext2fs.h, imager.c:
imager.c (ext2fs_image_{inode,super,bitmap}_{read,write}, ext2_fs.h,
Makefile.in: New file that has routines that save ext2fs metadata to a
file.
ext2_err.et.in (EXT2_ET_MAGIC_E2IMAGE): New error code assigned.
e2image.h: New file which defines the file format for the ext2 image
file. (Saved copy of ext2 metadata to a file as a saving throw
against worst-case damage.)
ChangeLog, Makefile.in, e2image.c:
e2image.c, Makefile.in: New program which saves ext2 metadata to a
file for people who need a last-ditch saving throw.
2000-11-12 22:32:20 +03:00
|
|
|
ssize_t actual, size;
|
|
|
|
errcode_t retval;
|
|
|
|
|
|
|
|
size = fs->blocksize * (fs->group_desc_count + 1);
|
|
|
|
buf = malloc(size);
|
|
|
|
if (!buf)
|
|
|
|
return ENOMEM;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Read it all in.
|
|
|
|
*/
|
|
|
|
actual = read(fd, buf, size);
|
|
|
|
if (actual == -1) {
|
2001-01-12 20:26:05 +03:00
|
|
|
retval = errno;
|
ChangeLog, Makefile.in, e2image.h, ext2_err.et.in, ext2fs.h, imager.c:
imager.c (ext2fs_image_{inode,super,bitmap}_{read,write}, ext2_fs.h,
Makefile.in: New file that has routines that save ext2fs metadata to a
file.
ext2_err.et.in (EXT2_ET_MAGIC_E2IMAGE): New error code assigned.
e2image.h: New file which defines the file format for the ext2 image
file. (Saved copy of ext2 metadata to a file as a saving throw
against worst-case damage.)
ChangeLog, Makefile.in, e2image.c:
e2image.c, Makefile.in: New program which saves ext2 metadata to a
file for people who need a last-ditch saving throw.
2000-11-12 22:32:20 +03:00
|
|
|
goto errout;
|
|
|
|
}
|
|
|
|
if (actual != size) {
|
|
|
|
retval = EXT2_ET_SHORT_READ;
|
|
|
|
goto errout;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Now copy in the superblock and group descriptors
|
|
|
|
*/
|
|
|
|
memcpy(fs->super, buf, SUPERBLOCK_SIZE);
|
|
|
|
|
|
|
|
memcpy(fs->group_desc, buf + fs->blocksize,
|
|
|
|
fs->blocksize * fs->group_desc_count);
|
|
|
|
|
|
|
|
retval = 0;
|
|
|
|
|
|
|
|
errout:
|
|
|
|
free(buf);
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Write the block/inode bitmaps.
|
|
|
|
*/
|
|
|
|
errcode_t ext2fs_image_bitmap_write(ext2_filsys fs, int fd, int flags)
|
|
|
|
{
|
2007-07-23 12:32:48 +04:00
|
|
|
ext2fs_generic_bitmap bmap;
|
2013-01-01 22:28:27 +04:00
|
|
|
errcode_t retval;
|
2007-07-23 12:32:48 +04:00
|
|
|
ssize_t actual;
|
2014-07-26 15:40:36 +04:00
|
|
|
size_t c;
|
|
|
|
__u64 itr, cnt, size, total_size;
|
2007-07-23 12:32:48 +04:00
|
|
|
char buf[1024];
|
ChangeLog, Makefile.in, e2image.h, ext2_err.et.in, ext2fs.h, imager.c:
imager.c (ext2fs_image_{inode,super,bitmap}_{read,write}, ext2_fs.h,
Makefile.in: New file that has routines that save ext2fs metadata to a
file.
ext2_err.et.in (EXT2_ET_MAGIC_E2IMAGE): New error code assigned.
e2image.h: New file which defines the file format for the ext2 image
file. (Saved copy of ext2 metadata to a file as a saving throw
against worst-case damage.)
ChangeLog, Makefile.in, e2image.c:
e2image.c, Makefile.in: New program which saves ext2 metadata to a
file for people who need a last-ditch saving throw.
2000-11-12 22:32:20 +03:00
|
|
|
|
|
|
|
if (flags & IMAGER_FLAG_INODEMAP) {
|
|
|
|
if (!fs->inode_map) {
|
|
|
|
retval = ext2fs_read_inode_bitmap(fs);
|
|
|
|
if (retval)
|
|
|
|
return retval;
|
|
|
|
}
|
2007-07-23 12:32:48 +04:00
|
|
|
bmap = fs->inode_map;
|
|
|
|
itr = 1;
|
|
|
|
cnt = EXT2_INODES_PER_GROUP(fs->super) * fs->group_desc_count;
|
2001-05-03 08:02:29 +04:00
|
|
|
size = (EXT2_INODES_PER_GROUP(fs->super) / 8);
|
ChangeLog, Makefile.in, e2image.h, ext2_err.et.in, ext2fs.h, imager.c:
imager.c (ext2fs_image_{inode,super,bitmap}_{read,write}, ext2_fs.h,
Makefile.in: New file that has routines that save ext2fs metadata to a
file.
ext2_err.et.in (EXT2_ET_MAGIC_E2IMAGE): New error code assigned.
e2image.h: New file which defines the file format for the ext2 image
file. (Saved copy of ext2 metadata to a file as a saving throw
against worst-case damage.)
ChangeLog, Makefile.in, e2image.c:
e2image.c, Makefile.in: New program which saves ext2 metadata to a
file for people who need a last-ditch saving throw.
2000-11-12 22:32:20 +03:00
|
|
|
} else {
|
|
|
|
if (!fs->block_map) {
|
|
|
|
retval = ext2fs_read_block_bitmap(fs);
|
|
|
|
if (retval)
|
|
|
|
return retval;
|
|
|
|
}
|
2007-07-23 12:32:48 +04:00
|
|
|
bmap = fs->block_map;
|
|
|
|
itr = fs->super->s_first_data_block;
|
2014-07-26 15:40:36 +04:00
|
|
|
cnt = EXT2_GROUPS_TO_BLOCKS(fs->super, fs->group_desc_count);
|
ChangeLog, Makefile.in, e2image.h, ext2_err.et.in, ext2fs.h, imager.c:
imager.c (ext2fs_image_{inode,super,bitmap}_{read,write}, ext2_fs.h,
Makefile.in: New file that has routines that save ext2fs metadata to a
file.
ext2_err.et.in (EXT2_ET_MAGIC_E2IMAGE): New error code assigned.
e2image.h: New file which defines the file format for the ext2 image
file. (Saved copy of ext2 metadata to a file as a saving throw
against worst-case damage.)
ChangeLog, Makefile.in, e2image.c:
e2image.c, Makefile.in: New program which saves ext2 metadata to a
file for people who need a last-ditch saving throw.
2000-11-12 22:32:20 +03:00
|
|
|
size = EXT2_BLOCKS_PER_GROUP(fs->super) / 8;
|
|
|
|
}
|
2007-07-23 12:32:48 +04:00
|
|
|
total_size = size * fs->group_desc_count;
|
|
|
|
|
|
|
|
while (cnt > 0) {
|
|
|
|
size = sizeof(buf);
|
|
|
|
if (size > (cnt >> 3))
|
|
|
|
size = (cnt >> 3);
|
|
|
|
|
2009-08-05 08:27:10 +04:00
|
|
|
retval = ext2fs_get_generic_bmap_range(bmap, itr,
|
|
|
|
size << 3, buf);
|
2007-07-23 12:32:48 +04:00
|
|
|
if (retval)
|
|
|
|
return retval;
|
|
|
|
|
|
|
|
actual = write(fd, buf, size);
|
|
|
|
if (actual == -1)
|
|
|
|
return errno;
|
|
|
|
if (actual != (int) size)
|
|
|
|
return EXT2_ET_SHORT_READ;
|
2008-08-28 07:07:54 +04:00
|
|
|
|
2007-07-23 12:32:48 +04:00
|
|
|
itr += size << 3;
|
|
|
|
cnt -= size << 3;
|
ChangeLog, Makefile.in, e2image.h, ext2_err.et.in, ext2fs.h, imager.c:
imager.c (ext2fs_image_{inode,super,bitmap}_{read,write}, ext2_fs.h,
Makefile.in: New file that has routines that save ext2fs metadata to a
file.
ext2_err.et.in (EXT2_ET_MAGIC_E2IMAGE): New error code assigned.
e2image.h: New file which defines the file format for the ext2 image
file. (Saved copy of ext2 metadata to a file as a saving throw
against worst-case damage.)
ChangeLog, Makefile.in, e2image.c:
e2image.c, Makefile.in: New program which saves ext2 metadata to a
file for people who need a last-ditch saving throw.
2000-11-12 22:32:20 +03:00
|
|
|
}
|
2007-07-23 12:32:48 +04:00
|
|
|
|
|
|
|
size = total_size % fs->blocksize;
|
|
|
|
memset(buf, 0, sizeof(buf));
|
ChangeLog, Makefile.in, e2image.h, ext2_err.et.in, ext2fs.h, imager.c:
imager.c (ext2fs_image_{inode,super,bitmap}_{read,write}, ext2_fs.h,
Makefile.in: New file that has routines that save ext2fs metadata to a
file.
ext2_err.et.in (EXT2_ET_MAGIC_E2IMAGE): New error code assigned.
e2image.h: New file which defines the file format for the ext2 image
file. (Saved copy of ext2 metadata to a file as a saving throw
against worst-case damage.)
ChangeLog, Makefile.in, e2image.c:
e2image.c, Makefile.in: New program which saves ext2 metadata to a
file for people who need a last-ditch saving throw.
2000-11-12 22:32:20 +03:00
|
|
|
if (size) {
|
|
|
|
size = fs->blocksize - size;
|
|
|
|
while (size) {
|
|
|
|
c = size;
|
2007-07-23 12:32:48 +04:00
|
|
|
if (c > (int) sizeof(buf))
|
|
|
|
c = sizeof(buf);
|
|
|
|
actual = write(fd, buf, c);
|
2014-07-26 15:40:36 +04:00
|
|
|
if (actual < 0)
|
2007-07-23 12:32:48 +04:00
|
|
|
return errno;
|
2014-07-26 15:40:36 +04:00
|
|
|
if ((size_t) actual != c)
|
2007-07-23 12:32:48 +04:00
|
|
|
return EXT2_ET_SHORT_WRITE;
|
ChangeLog, Makefile.in, e2image.h, ext2_err.et.in, ext2fs.h, imager.c:
imager.c (ext2fs_image_{inode,super,bitmap}_{read,write}, ext2_fs.h,
Makefile.in: New file that has routines that save ext2fs metadata to a
file.
ext2_err.et.in (EXT2_ET_MAGIC_E2IMAGE): New error code assigned.
e2image.h: New file which defines the file format for the ext2 image
file. (Saved copy of ext2 metadata to a file as a saving throw
against worst-case damage.)
ChangeLog, Makefile.in, e2image.c:
e2image.c, Makefile.in: New program which saves ext2 metadata to a
file for people who need a last-ditch saving throw.
2000-11-12 22:32:20 +03:00
|
|
|
size -= c;
|
|
|
|
}
|
|
|
|
}
|
2007-07-23 12:32:48 +04:00
|
|
|
return 0;
|
ChangeLog, Makefile.in, e2image.h, ext2_err.et.in, ext2fs.h, imager.c:
imager.c (ext2fs_image_{inode,super,bitmap}_{read,write}, ext2_fs.h,
Makefile.in: New file that has routines that save ext2fs metadata to a
file.
ext2_err.et.in (EXT2_ET_MAGIC_E2IMAGE): New error code assigned.
e2image.h: New file which defines the file format for the ext2 image
file. (Saved copy of ext2 metadata to a file as a saving throw
against worst-case damage.)
ChangeLog, Makefile.in, e2image.c:
e2image.c, Makefile.in: New program which saves ext2 metadata to a
file for people who need a last-ditch saving throw.
2000-11-12 22:32:20 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Read the block/inode bitmaps.
|
|
|
|
*/
|
|
|
|
errcode_t ext2fs_image_bitmap_read(ext2_filsys fs, int fd, int flags)
|
|
|
|
{
|
2007-07-23 12:32:48 +04:00
|
|
|
ext2fs_generic_bitmap bmap;
|
2013-01-01 22:28:27 +04:00
|
|
|
errcode_t retval;
|
2014-07-26 15:40:36 +04:00
|
|
|
__u64 itr, cnt;
|
2007-07-23 12:32:48 +04:00
|
|
|
char buf[1024];
|
|
|
|
unsigned int size;
|
|
|
|
ssize_t actual;
|
ChangeLog, Makefile.in, e2image.h, ext2_err.et.in, ext2fs.h, imager.c:
imager.c (ext2fs_image_{inode,super,bitmap}_{read,write}, ext2_fs.h,
Makefile.in: New file that has routines that save ext2fs metadata to a
file.
ext2_err.et.in (EXT2_ET_MAGIC_E2IMAGE): New error code assigned.
e2image.h: New file which defines the file format for the ext2 image
file. (Saved copy of ext2 metadata to a file as a saving throw
against worst-case damage.)
ChangeLog, Makefile.in, e2image.c:
e2image.c, Makefile.in: New program which saves ext2 metadata to a
file for people who need a last-ditch saving throw.
2000-11-12 22:32:20 +03:00
|
|
|
|
|
|
|
if (flags & IMAGER_FLAG_INODEMAP) {
|
|
|
|
if (!fs->inode_map) {
|
|
|
|
retval = ext2fs_read_inode_bitmap(fs);
|
|
|
|
if (retval)
|
|
|
|
return retval;
|
|
|
|
}
|
2007-07-23 12:32:48 +04:00
|
|
|
bmap = fs->inode_map;
|
|
|
|
itr = 1;
|
|
|
|
cnt = EXT2_INODES_PER_GROUP(fs->super) * fs->group_desc_count;
|
2001-05-03 08:02:29 +04:00
|
|
|
size = (EXT2_INODES_PER_GROUP(fs->super) / 8);
|
ChangeLog, Makefile.in, e2image.h, ext2_err.et.in, ext2fs.h, imager.c:
imager.c (ext2fs_image_{inode,super,bitmap}_{read,write}, ext2_fs.h,
Makefile.in: New file that has routines that save ext2fs metadata to a
file.
ext2_err.et.in (EXT2_ET_MAGIC_E2IMAGE): New error code assigned.
e2image.h: New file which defines the file format for the ext2 image
file. (Saved copy of ext2 metadata to a file as a saving throw
against worst-case damage.)
ChangeLog, Makefile.in, e2image.c:
e2image.c, Makefile.in: New program which saves ext2 metadata to a
file for people who need a last-ditch saving throw.
2000-11-12 22:32:20 +03:00
|
|
|
} else {
|
|
|
|
if (!fs->block_map) {
|
|
|
|
retval = ext2fs_read_block_bitmap(fs);
|
|
|
|
if (retval)
|
|
|
|
return retval;
|
|
|
|
}
|
2007-07-23 12:32:48 +04:00
|
|
|
bmap = fs->block_map;
|
|
|
|
itr = fs->super->s_first_data_block;
|
2014-07-26 15:40:36 +04:00
|
|
|
cnt = EXT2_GROUPS_TO_BLOCKS(fs->super, fs->group_desc_count);
|
ChangeLog, Makefile.in, e2image.h, ext2_err.et.in, ext2fs.h, imager.c:
imager.c (ext2fs_image_{inode,super,bitmap}_{read,write}, ext2_fs.h,
Makefile.in: New file that has routines that save ext2fs metadata to a
file.
ext2_err.et.in (EXT2_ET_MAGIC_E2IMAGE): New error code assigned.
e2image.h: New file which defines the file format for the ext2 image
file. (Saved copy of ext2 metadata to a file as a saving throw
against worst-case damage.)
ChangeLog, Makefile.in, e2image.c:
e2image.c, Makefile.in: New program which saves ext2 metadata to a
file for people who need a last-ditch saving throw.
2000-11-12 22:32:20 +03:00
|
|
|
size = EXT2_BLOCKS_PER_GROUP(fs->super) / 8;
|
|
|
|
}
|
|
|
|
|
2007-07-23 12:32:48 +04:00
|
|
|
while (cnt > 0) {
|
|
|
|
size = sizeof(buf);
|
|
|
|
if (size > (cnt >> 3))
|
|
|
|
size = (cnt >> 3);
|
ChangeLog, Makefile.in, e2image.h, ext2_err.et.in, ext2fs.h, imager.c:
imager.c (ext2fs_image_{inode,super,bitmap}_{read,write}, ext2_fs.h,
Makefile.in: New file that has routines that save ext2fs metadata to a
file.
ext2_err.et.in (EXT2_ET_MAGIC_E2IMAGE): New error code assigned.
e2image.h: New file which defines the file format for the ext2 image
file. (Saved copy of ext2 metadata to a file as a saving throw
against worst-case damage.)
ChangeLog, Makefile.in, e2image.c:
e2image.c, Makefile.in: New program which saves ext2 metadata to a
file for people who need a last-ditch saving throw.
2000-11-12 22:32:20 +03:00
|
|
|
|
2007-07-23 12:32:48 +04:00
|
|
|
actual = read(fd, buf, size);
|
|
|
|
if (actual == -1)
|
|
|
|
return errno;
|
|
|
|
if (actual != (int) size)
|
|
|
|
return EXT2_ET_SHORT_READ;
|
|
|
|
|
2009-08-05 08:27:10 +04:00
|
|
|
retval = ext2fs_set_generic_bmap_range(bmap, itr,
|
|
|
|
size << 3, buf);
|
2007-07-23 12:32:48 +04:00
|
|
|
if (retval)
|
|
|
|
return retval;
|
|
|
|
|
|
|
|
itr += size << 3;
|
|
|
|
cnt -= size << 3;
|
ChangeLog, Makefile.in, e2image.h, ext2_err.et.in, ext2fs.h, imager.c:
imager.c (ext2fs_image_{inode,super,bitmap}_{read,write}, ext2_fs.h,
Makefile.in: New file that has routines that save ext2fs metadata to a
file.
ext2_err.et.in (EXT2_ET_MAGIC_E2IMAGE): New error code assigned.
e2image.h: New file which defines the file format for the ext2 image
file. (Saved copy of ext2 metadata to a file as a saving throw
against worst-case damage.)
ChangeLog, Makefile.in, e2image.c:
e2image.c, Makefile.in: New program which saves ext2 metadata to a
file for people who need a last-ditch saving throw.
2000-11-12 22:32:20 +03:00
|
|
|
}
|
2007-07-23 12:32:48 +04:00
|
|
|
return 0;
|
ChangeLog, Makefile.in, e2image.h, ext2_err.et.in, ext2fs.h, imager.c:
imager.c (ext2fs_image_{inode,super,bitmap}_{read,write}, ext2_fs.h,
Makefile.in: New file that has routines that save ext2fs metadata to a
file.
ext2_err.et.in (EXT2_ET_MAGIC_E2IMAGE): New error code assigned.
e2image.h: New file which defines the file format for the ext2 image
file. (Saved copy of ext2 metadata to a file as a saving throw
against worst-case damage.)
ChangeLog, Makefile.in, e2image.c:
e2image.c, Makefile.in: New program which saves ext2 metadata to a
file for people who need a last-ditch saving throw.
2000-11-12 22:32:20 +03:00
|
|
|
}
|