aboutsummaryrefslogtreecommitdiffstats
path: root/meta/recipes-devtools/btrfs-tools/btrfs-tools/mkfs-xin-fixes.patch
blob: 847e8706693e887251f0d426ca4e97aeb562c1ac (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
Upstream-Status: Pending

This patch is made by xin.zhong@intel.com to implement these supported 
features in mkfs.btrfs:
  * populate fs image from a directory while creating it
  * reduce minimum size of the created image from 256MB to around 24MB
  * while creating image use the specified device name rather than output.img 

Patch tested and incorporated in poky by:
Nitin A Kamble <nitin.a.kamble@intel.com> 2011/06/20

diff --git a/file-item.c b/file-item.c
index 9732282..aed42c3 100644
--- a/file-item.c
+++ b/file-item.c
@@ -193,7 +193,7 @@ int btrfs_csum_file_block(struct btrfs_trans_handle *trans,
 			  struct btrfs_root *root, u64 alloc_end,
 			  u64 bytenr, char *data, size_t len)
 {
-	int ret;
+	int ret = 0;
 	struct btrfs_key file_key;
 	struct btrfs_key found_key;
 	u64 next_offset = (u64)-1;
diff --git a/mkfs.c b/mkfs.c
index 57c88f9..e953a33 100644
--- a/mkfs.c
+++ b/mkfs.c
@@ -36,7 +36,7 @@
 #include <uuid/uuid.h>
 #include <linux/fs.h>
 #include <ctype.h>
-#include <attr/xattr.h>
+#include <sys/xattr.h>
 #include "kerncompat.h"
 #include "ctree.h"
 #include "disk-io.h"
@@ -517,7 +517,6 @@ static int add_inode_items(struct btrfs_trans_handle *trans,
 fail:
 	return ret;
 }
-
 static int add_xattr_item(struct btrfs_trans_handle *trans,
 			  struct btrfs_root *root, u64 objectid,
 			  const char *file_name)
@@ -532,8 +531,10 @@ static int add_xattr_item(struct btrfs_trans_handle *trans,
 
 	ret = llistxattr(file_name, xattr_list, XATTR_LIST_MAX);
 	if (ret < 0) {
-		fprintf(stderr, "get a list of xattr failed for %s\n",
-			file_name);
+		if(errno == ENOTSUP)
+			return 0;
+		fprintf(stderr, "get a list of xattr failed for %s errno %d\n",
+				file_name, errno);
 		return ret;
 	}
 	if (ret == 0)
@@ -546,8 +547,11 @@ static int add_xattr_item(struct btrfs_trans_handle *trans,
 
 		ret = getxattr(file_name, cur_name, cur_value, XATTR_SIZE_MAX);
 		if (ret < 0) {
-			fprintf(stderr, "get a xattr value failed for %s\n",
-				cur_name);
+			if(errno == ENOTSUP)
+				return 0;
+			fprintf(stderr, "get a xattr value failed for %s attr %s errno %d\n",
+				file_name, cur_name, errno);
+			return ret;
 		}
 
 		ret = btrfs_insert_xattr_item(trans, root, cur_name,
@@ -563,7 +567,6 @@ static int add_xattr_item(struct btrfs_trans_handle *trans,
 
 	return ret;
 }
-
 static int custom_alloc_extent(struct btrfs_root *root, u64 num_bytes,
 			       u64 hint_byte, struct btrfs_key *ins)
 {
@@ -923,27 +926,27 @@ static int traverse_directory(struct btrfs_trans_handle *trans,
 				fprintf(stderr, "add_inode_items failed\n");
 				goto fail;
 			}
-
 			ret = add_xattr_item(trans, root,
 					     cur_inum, cur_file->d_name);
 			if (ret) {
 				fprintf(stderr, "add_xattr_item failed\n");
-				goto fail;
+				if(ret != -ENOTSUP)
+					goto fail;
 			}
-
 			if (S_ISDIR(st.st_mode)) {
 				dir_entry = malloc(sizeof(struct directory_name_entry));
 				dir_entry->dir_name = cur_file->d_name;
 				dir_entry->path = make_path(parent_dir_entry->path,
 							    cur_file->d_name);
 				dir_entry->inum = cur_inum;
-				list_add_tail(&dir_entry->list,	&dir_head->list);
+				list_add_tail(&dir_entry->list, &dir_head->list);
 			} else if (S_ISREG(st.st_mode)) {
 				ret = add_file_items(trans, root, &cur_inode,
 						     cur_inum, parent_inum, &st,
 						     cur_file->d_name, out_fd);
 				if (ret) {
-					fprintf(stderr, "add_file_items failed\n");
+					fprintf(stderr, "add_file_items failed %s\n",
+						cur_file->d_name);
 					goto fail;
 				}
 			} else if (S_ISLNK(st.st_mode)) {
@@ -987,7 +990,7 @@ static int create_chunks(struct btrfs_trans_handle *trans,
 	u64 chunk_size;
 	u64 meta_type = BTRFS_BLOCK_GROUP_METADATA;
 	u64 data_type = BTRFS_BLOCK_GROUP_DATA;
-	u64 minimum_data_chunk_size = 64 * 1024 * 1024;
+	u64 minimum_data_chunk_size = 8 * 1024 * 1024;
 	u64 i;
 	int ret;
 
@@ -1062,7 +1065,6 @@ static u64 size_sourcedir(char *dir_name, u64 sectorsize,
 	char path[512];
 	char *file_name = "temp_file";
 	FILE *file;
-	u64 minimum_data_size = 256 * 1024 * 1024;	/* 256MB */
 	u64 default_chunk_size = 8 * 1024 * 1024;	/* 8MB */
 	u64 allocated_meta_size = 8 * 1024 * 1024;	/* 8MB */
 	u64 allocated_total_size = 20 * 1024 * 1024;	/* 20MB */
@@ -1101,9 +1103,6 @@ static u64 size_sourcedir(char *dir_name, u64 sectorsize,
 
 	*num_of_meta_chunks_ret = num_of_meta_chunks;
 
-	if (total_size < minimum_data_size)
-		total_size = minimum_data_size;
-
 	return total_size;
 }
 
@@ -1158,9 +1157,9 @@ int main(int ac, char **av)
 
 	char *source_dir = NULL;
 	int source_dir_set = 0;
-	char *output = "output.img";
 	u64 num_of_meta_chunks = 0;
 	u64 size_of_data = 0;
+	u64 source_dir_size = 0;
 
 	while(1) {
 		int c;
@@ -1224,8 +1223,6 @@ int main(int ac, char **av)
 		fprintf(stderr, "Illegal nodesize %u\n", nodesize);
 		exit(1);
 	}
-	if (source_dir_set)
-		ac++;
 	ac = ac - optind;
 	if (ac == 0)
 		print_usage();
@@ -1257,17 +1254,19 @@ int main(int ac, char **av)
 			block_count = dev_block_count;
 	} else {
 		ac = 0;
-		fd = open_target(output);
+		file = av[optind++];
+		fd = open_target(file);
 		if (fd < 0) {
 			fprintf(stderr, "unable to open the %s\n", file);
 			exit(1);
 		}
 
-		file = output;
 		first_fd = fd;
 		first_file = file;
-		block_count = size_sourcedir(source_dir, sectorsize,
+		source_dir_size = size_sourcedir(source_dir, sectorsize,
 					     &num_of_meta_chunks, &size_of_data);
+		if(block_count < source_dir_size)
+			block_count = source_dir_size;
 		ret = zero_output_file(fd, block_count, sectorsize);
 		if (ret) {
 			fprintf(stderr, "unable to zero the output file\n");