Skip to content

Commit 554ec8f

Browse files
committed
btrfs-progs: image: factor out the create part from main.c
The functionality of create and restore is all in main.c, split the create functionality first. This is not the cleaniest diff to do it, the functions are entangled and the final result is from several compile and edit cycles. Signed-off-by: David Sterba <[email protected]>
1 parent c23b968 commit 554ec8f

File tree

6 files changed

+991
-929
lines changed

6 files changed

+991
-929
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@ convert_objects = convert/main.o convert/common.o convert/source-fs.o \
262262
convert/source-ext2.o convert/source-reiserfs.o \
263263
mkfs/common.o check/clear-cache.o
264264
mkfs_objects = mkfs/main.o mkfs/common.o mkfs/rootdir.o
265-
image_objects = image/main.o image/sanitize.o
265+
image_objects = image/main.o image/sanitize.o image/image-create.o image/common.o
266266
tune_objects = tune/main.o tune/seeding.o tune/change-uuid.o tune/change-metadata-uuid.o \
267267
tune/convert-bgt.o tune/change-csum.o check/clear-cache.o
268268
all_objects = $(objects) $(cmds_objects) $(libbtrfs_objects) $(convert_objects) \

image/common.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#include "kerncompat.h"
2+
#include <stddef.h>
3+
#include "kernel-shared/ctree.h"
4+
#include "crypto/crc32c.h"
5+
#include "image/common.h"
6+
7+
void csum_block(u8 *buf, size_t len)
8+
{
9+
u16 csum_size = btrfs_csum_type_size(BTRFS_CSUM_TYPE_CRC32);
10+
u8 result[csum_size];
11+
u32 crc = ~(u32)0;
12+
crc = crc32c(crc, buf + BTRFS_CSUM_SIZE, len - BTRFS_CSUM_SIZE);
13+
put_unaligned_le32(~crc, result);
14+
memcpy(buf, result, csum_size);
15+
}

image/common.h

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/*
2+
* This program is free software; you can redistribute it and/or
3+
* modify it under the terms of the GNU General Public
4+
* License v2 as published by the Free Software Foundation.
5+
*
6+
* This program is distributed in the hope that it will be useful,
7+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
8+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
9+
* General Public License for more details.
10+
*
11+
* You should have received a copy of the GNU General Public
12+
* License along with this program; if not, write to the
13+
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
14+
* Boston, MA 021110-1307, USA.
15+
*/
16+
17+
#ifndef __BTRFS_IMAGE_COMMON_H__
18+
#define __BTRFS_IMAGE_COMMON_H__
19+
20+
#include "kerncompat.h"
21+
22+
void csum_block(u8 *buf, size_t len);
23+
24+
#endif

0 commit comments

Comments
 (0)