Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
openeuler
raspberrypi-kernel
提交
123abc88
R
raspberrypi-kernel
项目概览
openeuler
/
raspberrypi-kernel
通知
13
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
R
raspberrypi-kernel
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
123abc88
编写于
3月 14, 2007
作者:
C
Chris Mason
提交者:
David Woodhouse
3月 14, 2007
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Btrfs: variable block size support
Signed-off-by:
N
Chris Mason
<
chris.mason@oracle.com
>
上级
4beb1b8b
变更
10
展开全部
隐藏空白更改
内联
并排
Showing
10 changed file
with
238 addition
and
300 deletion
+238
-300
fs/btrfs/ctree.c
fs/btrfs/ctree.c
+111
-114
fs/btrfs/ctree.h
fs/btrfs/ctree.h
+35
-27
fs/btrfs/disk-io.c
fs/btrfs/disk-io.c
+23
-19
fs/btrfs/disk-io.h
fs/btrfs/disk-io.h
+4
-5
fs/btrfs/extent-tree.c
fs/btrfs/extent-tree.c
+2
-4
fs/btrfs/mkfs.c
fs/btrfs/mkfs.c
+51
-120
fs/btrfs/print-tree.c
fs/btrfs/print-tree.c
+8
-7
fs/btrfs/print-tree.h
fs/btrfs/print-tree.h
+1
-1
fs/btrfs/quick-test.c
fs/btrfs/quick-test.c
+1
-1
fs/btrfs/root-tree.c
fs/btrfs/root-tree.c
+2
-2
未找到文件。
fs/btrfs/ctree.c
浏览文件 @
123abc88
此差异已折叠。
点击以展开。
fs/btrfs/ctree.h
浏览文件 @
123abc88
...
...
@@ -5,7 +5,6 @@
#include "kerncompat.h"
#define BTRFS_MAGIC "_BtRfS_M"
#define BTRFS_BLOCKSIZE 1024
#define BTRFS_ROOT_TREE_OBJECTID 1
#define BTRFS_EXTENT_TREE_OBJECTID 2
...
...
@@ -52,8 +51,11 @@ struct btrfs_header {
}
__attribute__
((
__packed__
));
#define BTRFS_MAX_LEVEL 8
#define NODEPTRS_PER_BLOCK ((BTRFS_BLOCKSIZE - sizeof(struct btrfs_header)) / \
(sizeof(struct btrfs_disk_key) + sizeof(u64)))
#define BTRFS_NODEPTRS_PER_BLOCK(r) (((r)->blocksize - \
sizeof(struct btrfs_header)) / \
(sizeof(struct btrfs_disk_key) + sizeof(u64)))
#define __BTRFS_LEAF_DATA_SIZE(bs) ((bs) - sizeof(struct btrfs_header))
#define BTRFS_LEAF_DATA_SIZE(r) (__BTRFS_LEAF_DATA_SIZE(r->blocksize))
struct
btrfs_buffer
;
...
...
@@ -86,6 +88,7 @@ struct btrfs_root {
int
ref_cows
;
struct
btrfs_root_item
root_item
;
struct
btrfs_key
root_key
;
u32
blocksize
;
};
/*
...
...
@@ -97,7 +100,7 @@ struct btrfs_super_block {
__le64
blocknr
;
/* this block number */
__le32
csum
;
__le64
magic
;
__le
16
blocksize
;
__le
32
blocksize
;
__le64
generation
;
__le64
root
;
__le64
total_blocks
;
...
...
@@ -111,7 +114,7 @@ struct btrfs_super_block {
*/
struct
btrfs_item
{
struct
btrfs_disk_key
key
;
__le
16
offset
;
__le
32
offset
;
__le16
size
;
}
__attribute__
((
__packed__
));
...
...
@@ -122,24 +125,23 @@ struct btrfs_item {
* The data is separate from the items to get the keys closer together
* during searches.
*/
#define LEAF_DATA_SIZE (BTRFS_BLOCKSIZE - sizeof(struct btrfs_header))
struct
btrfs_leaf
{
struct
btrfs_header
header
;
union
{
struct
btrfs_item
items
[
LEAF_DATA_SIZE
/
sizeof
(
struct
btrfs_item
)];
u8
data
[
BTRFS_BLOCKSIZE
-
sizeof
(
struct
btrfs_header
)];
};
struct
btrfs_item
items
[];
}
__attribute__
((
__packed__
));
/*
* all non-leaf blocks are nodes, they hold only keys and pointers to
* other blocks
*/
struct
btrfs_key_ptr
{
struct
btrfs_disk_key
key
;
__le64
blockptr
;
}
__attribute__
((
__packed__
));
struct
btrfs_node
{
struct
btrfs_header
header
;
struct
btrfs_disk_key
keys
[
NODEPTRS_PER_BLOCK
];
__le64
blockptrs
[
NODEPTRS_PER_BLOCK
];
struct
btrfs_key_ptr
ptrs
[];
}
__attribute__
((
__packed__
));
/*
...
...
@@ -186,28 +188,28 @@ static inline void btrfs_set_extent_refs(struct btrfs_extent_item *ei, u32 val)
static
inline
u64
btrfs_node_blockptr
(
struct
btrfs_node
*
n
,
int
nr
)
{
return
le64_to_cpu
(
n
->
blockptrs
[
nr
]
);
return
le64_to_cpu
(
n
->
ptrs
[
nr
].
blockptr
);
}
static
inline
void
btrfs_set_node_blockptr
(
struct
btrfs_node
*
n
,
int
nr
,
u64
val
)
{
n
->
blockptrs
[
nr
]
=
cpu_to_le64
(
val
);
n
->
ptrs
[
nr
].
blockptr
=
cpu_to_le64
(
val
);
}
static
inline
u
16
btrfs_item_offset
(
struct
btrfs_item
*
item
)
static
inline
u
32
btrfs_item_offset
(
struct
btrfs_item
*
item
)
{
return
le
16
_to_cpu
(
item
->
offset
);
return
le
32
_to_cpu
(
item
->
offset
);
}
static
inline
void
btrfs_set_item_offset
(
struct
btrfs_item
*
item
,
u
16
val
)
static
inline
void
btrfs_set_item_offset
(
struct
btrfs_item
*
item
,
u
32
val
)
{
item
->
offset
=
cpu_to_le
16
(
val
);
item
->
offset
=
cpu_to_le
32
(
val
);
}
static
inline
u
16
btrfs_item_end
(
struct
btrfs_item
*
item
)
static
inline
u
32
btrfs_item_end
(
struct
btrfs_item
*
item
)
{
return
le
16
_to_cpu
(
item
->
offset
)
+
le16_to_cpu
(
item
->
size
);
return
le
32
_to_cpu
(
item
->
offset
)
+
le16_to_cpu
(
item
->
size
);
}
static
inline
u16
btrfs_item_size
(
struct
btrfs_item
*
item
)
...
...
@@ -390,20 +392,26 @@ static inline void btrfs_set_super_blocks_used(struct btrfs_super_block *s,
s
->
blocks_used
=
cpu_to_le64
(
val
);
}
static
inline
u
16
btrfs_super_blocksize
(
struct
btrfs_super_block
*
s
)
static
inline
u
32
btrfs_super_blocksize
(
struct
btrfs_super_block
*
s
)
{
return
le
16
_to_cpu
(
s
->
blocksize
);
return
le
32
_to_cpu
(
s
->
blocksize
);
}
static
inline
void
btrfs_set_super_blocksize
(
struct
btrfs_super_block
*
s
,
u16
val
)
u32
val
)
{
s
->
blocksize
=
cpu_to_le32
(
val
);
}
static
inline
u8
*
btrfs_leaf_data
(
struct
btrfs_leaf
*
l
)
{
s
->
blocksize
=
cpu_to_le16
(
val
)
;
return
(
u8
*
)
l
->
items
;
}
/* helper function to cast into the data area of the leaf. */
#define btrfs_item_ptr(leaf, slot, type) \
((type *)((leaf)->data + btrfs_item_offset((leaf)->items + (slot))))
((type *)(btrfs_leaf_data(leaf) + \
btrfs_item_offset((leaf)->items + (slot))))
struct
btrfs_buffer
*
btrfs_alloc_free_block
(
struct
btrfs_root
*
root
);
int
btrfs_inc_ref
(
struct
btrfs_root
*
root
,
struct
btrfs_buffer
*
buf
);
...
...
@@ -416,7 +424,7 @@ int btrfs_del_item(struct btrfs_root *root, struct btrfs_path *path);
int
btrfs_insert_item
(
struct
btrfs_root
*
root
,
struct
btrfs_key
*
key
,
void
*
data
,
int
data_size
);
int
btrfs_next_leaf
(
struct
btrfs_root
*
root
,
struct
btrfs_path
*
path
);
int
btrfs_leaf_free_space
(
struct
btrfs_leaf
*
leaf
);
int
btrfs_leaf_free_space
(
struct
btrfs_
root
*
root
,
struct
btrfs_
leaf
*
leaf
);
int
btrfs_drop_snapshot
(
struct
btrfs_root
*
root
,
struct
btrfs_buffer
*
snap
);
int
btrfs_finish_extent_commit
(
struct
btrfs_root
*
root
);
int
btrfs_del_root
(
struct
btrfs_root
*
root
,
struct
btrfs_key
*
key
);
...
...
fs/btrfs/disk-io.c
浏览文件 @
123abc88
...
...
@@ -46,7 +46,8 @@ struct btrfs_buffer *alloc_tree_block(struct btrfs_root *root, u64 blocknr)
{
struct
btrfs_buffer
*
buf
;
int
ret
;
buf
=
malloc
(
sizeof
(
struct
btrfs_buffer
));
buf
=
malloc
(
sizeof
(
struct
btrfs_buffer
)
+
root
->
blocksize
);
if
(
!
buf
)
return
buf
;
allocated_blocks
++
;
...
...
@@ -84,7 +85,7 @@ struct btrfs_buffer *find_tree_block(struct btrfs_root *root, u64 blocknr)
struct
btrfs_buffer
*
read_tree_block
(
struct
btrfs_root
*
root
,
u64
blocknr
)
{
loff_t
offset
=
blocknr
*
BTRFS_BLOCKSIZE
;
loff_t
offset
=
blocknr
*
root
->
blocksize
;
struct
btrfs_buffer
*
buf
;
int
ret
;
...
...
@@ -95,8 +96,8 @@ struct btrfs_buffer *read_tree_block(struct btrfs_root *root, u64 blocknr)
buf
=
alloc_tree_block
(
root
,
blocknr
);
if
(
!
buf
)
return
NULL
;
ret
=
pread
(
root
->
fp
,
&
buf
->
node
,
BTRFS_BLOCKSIZE
,
offset
);
if
(
ret
!=
BTRFS_BLOCKSIZE
)
{
ret
=
pread
(
root
->
fp
,
&
buf
->
node
,
root
->
blocksize
,
offset
);
if
(
ret
!=
root
->
blocksize
)
{
free
(
buf
);
return
NULL
;
}
...
...
@@ -127,13 +128,13 @@ int clean_tree_block(struct btrfs_root *root, struct btrfs_buffer *buf)
int
write_tree_block
(
struct
btrfs_root
*
root
,
struct
btrfs_buffer
*
buf
)
{
u64
blocknr
=
buf
->
blocknr
;
loff_t
offset
=
blocknr
*
BTRFS_BLOCKSIZE
;
loff_t
offset
=
blocknr
*
root
->
blocksize
;
int
ret
;
if
(
buf
->
blocknr
!=
btrfs_header_blocknr
(
&
buf
->
node
.
header
))
BUG
();
ret
=
pwrite
(
root
->
fp
,
&
buf
->
node
,
BTRFS_BLOCKSIZE
,
offset
);
if
(
ret
!=
BTRFS_BLOCKSIZE
)
ret
=
pwrite
(
root
->
fp
,
&
buf
->
node
,
root
->
blocksize
,
offset
);
if
(
ret
!=
root
->
blocksize
)
return
ret
;
return
0
;
}
...
...
@@ -215,7 +216,8 @@ int btrfs_commit_transaction(struct btrfs_root *root,
return
ret
;
}
static
int
__setup_root
(
struct
btrfs_root
*
root
,
u64
objectid
,
int
fp
)
static
int
__setup_root
(
struct
btrfs_super_block
*
super
,
struct
btrfs_root
*
root
,
u64
objectid
,
int
fp
)
{
INIT_LIST_HEAD
(
&
root
->
trans
);
INIT_LIST_HEAD
(
&
root
->
cache
);
...
...
@@ -223,6 +225,8 @@ static int __setup_root(struct btrfs_root *root, u64 objectid, int fp)
root
->
fp
=
fp
;
root
->
node
=
NULL
;
root
->
commit_root
=
NULL
;
root
->
blocksize
=
btrfs_super_blocksize
(
super
);
root
->
ref_cows
=
0
;
memset
(
&
root
->
current_insert
,
0
,
sizeof
(
root
->
current_insert
));
memset
(
&
root
->
last_insert
,
0
,
sizeof
(
root
->
last_insert
));
memset
(
&
root
->
root_key
,
0
,
sizeof
(
root
->
root_key
));
...
...
@@ -230,19 +234,19 @@ static int __setup_root(struct btrfs_root *root, u64 objectid, int fp)
return
0
;
}
static
int
find_and_setup_root
(
struct
btrfs_root
*
tree_root
,
u64
objectid
,
struct
btrfs_root
*
root
,
int
fp
)
static
int
find_and_setup_root
(
struct
btrfs_super_block
*
super
,
struct
btrfs_root
*
tree_root
,
u64
objectid
,
struct
btrfs_root
*
root
,
int
fp
)
{
int
ret
;
__setup_root
(
root
,
objectid
,
fp
);
__setup_root
(
super
,
root
,
objectid
,
fp
);
ret
=
btrfs_find_last_root
(
tree_root
,
objectid
,
&
root
->
root_item
,
&
root
->
root_key
);
BUG_ON
(
ret
);
root
->
node
=
read_tree_block
(
root
,
btrfs_root_blocknr
(
&
root
->
root_item
));
root
->
ref_cows
=
0
;
BUG_ON
(
!
root
->
node
);
return
0
;
}
...
...
@@ -277,28 +281,28 @@ struct btrfs_root *open_ctree(char *filename, struct btrfs_super_block *super)
INIT_RADIX_TREE
(
&
tree_root
->
cache_radix
,
GFP_KERNEL
);
ret
=
pread
(
fp
,
super
,
sizeof
(
struct
btrfs_super_block
),
BTRFS_SUPER_INFO_OFFSET
(
BTRFS_BLOCKSIZE
)
);
BTRFS_SUPER_INFO_OFFSET
);
if
(
ret
==
0
||
btrfs_super_root
(
super
)
==
0
)
{
printf
(
"making new FS!
\n
"
);
ret
=
mkfs
(
fp
,
0
,
BTRFS_BLOCKSIZE
);
ret
=
mkfs
(
fp
,
0
,
1024
);
if
(
ret
)
return
NULL
;
ret
=
pread
(
fp
,
super
,
sizeof
(
struct
btrfs_super_block
),
BTRFS_SUPER_INFO_OFFSET
(
BTRFS_BLOCKSIZE
)
);
BTRFS_SUPER_INFO_OFFSET
);
if
(
ret
!=
sizeof
(
struct
btrfs_super_block
))
return
NULL
;
}
BUG_ON
(
ret
<
0
);
__setup_root
(
tree_root
,
BTRFS_ROOT_TREE_OBJECTID
,
fp
);
__setup_root
(
super
,
tree_root
,
BTRFS_ROOT_TREE_OBJECTID
,
fp
);
tree_root
->
node
=
read_tree_block
(
tree_root
,
btrfs_super_root
(
super
));
BUG_ON
(
!
tree_root
->
node
);
ret
=
find_and_setup_root
(
tree_root
,
BTRFS_EXTENT_TREE_OBJECTID
,
ret
=
find_and_setup_root
(
super
,
tree_root
,
BTRFS_EXTENT_TREE_OBJECTID
,
extent_root
,
fp
);
BUG_ON
(
ret
);
ret
=
find_and_setup_root
(
tree_root
,
BTRFS_FS_TREE_OBJECTID
,
ret
=
find_and_setup_root
(
super
,
tree_root
,
BTRFS_FS_TREE_OBJECTID
,
root
,
fp
);
BUG_ON
(
ret
);
...
...
@@ -313,7 +317,7 @@ int write_ctree_super(struct btrfs_root *root, struct btrfs_super_block *s)
int
ret
;
btrfs_set_super_root
(
s
,
root
->
tree_root
->
node
->
blocknr
);
ret
=
pwrite
(
root
->
fp
,
s
,
sizeof
(
*
s
),
BTRFS_SUPER_INFO_OFFSET
(
BTRFS_BLOCKSIZE
)
);
BTRFS_SUPER_INFO_OFFSET
);
if
(
ret
!=
sizeof
(
*
s
))
{
fprintf
(
stderr
,
"failed to write new super block err %d
\n
"
,
ret
);
return
ret
;
...
...
fs/btrfs/disk-io.h
浏览文件 @
123abc88
...
...
@@ -5,12 +5,12 @@
struct
btrfs_buffer
{
u64
blocknr
;
int
count
;
struct
list_head
dirty
;
struct
list_head
cache
;
union
{
struct
btrfs_node
node
;
struct
btrfs_leaf
leaf
;
};
struct
list_head
dirty
;
struct
list_head
cache
;
};
struct
btrfs_buffer
*
read_tree_block
(
struct
btrfs_root
*
root
,
u64
blocknr
);
...
...
@@ -24,9 +24,8 @@ struct btrfs_root *open_ctree(char *filename, struct btrfs_super_block *s);
int
close_ctree
(
struct
btrfs_root
*
root
,
struct
btrfs_super_block
*
s
);
void
btrfs_block_release
(
struct
btrfs_root
*
root
,
struct
btrfs_buffer
*
buf
);
int
write_ctree_super
(
struct
btrfs_root
*
root
,
struct
btrfs_super_block
*
s
);
int
mkfs
(
int
fd
,
u64
num_blocks
,
u16
blocksize
);
int
mkfs
(
int
fd
,
u64
num_blocks
,
u32
blocksize
);
#define BTRFS_SUPER_INFO_OFFSET
(bs) (16 * (bs)
)
#define BTRFS_SUPER_INFO_OFFSET
(16 * 1024
)
#endif
fs/btrfs/extent-tree.c
浏览文件 @
123abc88
...
...
@@ -143,7 +143,6 @@ static int __free_extent(struct btrfs_root *root, u64 blocknr, u64 num_blocks)
struct
btrfs_key
key
;
struct
btrfs_root
*
extent_root
=
root
->
extent_root
;
int
ret
;
struct
btrfs_item
*
item
;
struct
btrfs_extent_item
*
ei
;
struct
btrfs_key
ins
;
u32
refs
;
...
...
@@ -161,9 +160,8 @@ static int __free_extent(struct btrfs_root *root, u64 blocknr, u64 num_blocks)
printf
(
"failed to find %Lu
\n
"
,
key
.
objectid
);
BUG
();
}
item
=
path
.
nodes
[
0
]
->
leaf
.
items
+
path
.
slots
[
0
];
ei
=
(
struct
btrfs_extent_item
*
)(
path
.
nodes
[
0
]
->
leaf
.
data
+
btrfs_item_offset
(
item
));
ei
=
btrfs_item_ptr
(
&
path
.
nodes
[
0
]
->
leaf
,
path
.
slots
[
0
],
struct
btrfs_extent_item
);
BUG_ON
(
ei
->
refs
==
0
);
refs
=
btrfs_extent_refs
(
ei
)
-
1
;
btrfs_set_extent_refs
(
ei
,
refs
);
...
...
fs/btrfs/mkfs.c
浏览文件 @
123abc88
...
...
@@ -10,19 +10,20 @@
#include "ctree.h"
#include "disk-io.h"
int
mkfs
(
int
fd
,
u64
num_blocks
,
u
16
blocksize
)
int
mkfs
(
int
fd
,
u64
num_blocks
,
u
32
blocksize
)
{
struct
btrfs_super_block
super
;
struct
btrfs_leaf
empty_leaf
;
struct
btrfs_leaf
*
empty_leaf
;
struct
btrfs_root_item
root_item
;
struct
btrfs_item
item
;
struct
btrfs_extent_item
extent_item
;
char
*
block
;
int
ret
;
u16
itemoff
;
u32
itemoff
;
u32
start_block
=
BTRFS_SUPER_INFO_OFFSET
/
blocksize
;
btrfs_set_super_blocknr
(
&
super
,
16
);
btrfs_set_super_root
(
&
super
,
17
);
btrfs_set_super_blocknr
(
&
super
,
start_block
);
btrfs_set_super_root
(
&
super
,
start_block
+
1
);
strcpy
((
char
*
)(
&
super
.
magic
),
BTRFS_MAGIC
);
btrfs_set_super_blocksize
(
&
super
,
blocksize
);
btrfs_set_super_total_blocks
(
&
super
,
num_blocks
);
...
...
@@ -32,168 +33,98 @@ int mkfs(int fd, u64 num_blocks, u16 blocksize)
memset
(
block
,
0
,
blocksize
);
BUG_ON
(
sizeof
(
super
)
>
blocksize
);
memcpy
(
block
,
&
super
,
sizeof
(
super
));
ret
=
pwrite
(
fd
,
block
,
blocksize
,
BTRFS_SUPER_INFO_OFFSET
(
blocksize
)
);
ret
=
pwrite
(
fd
,
block
,
blocksize
,
BTRFS_SUPER_INFO_OFFSET
);
BUG_ON
(
ret
!=
blocksize
);
/* create the tree of root objects */
memset
(
&
empty_leaf
,
0
,
sizeof
(
empty_leaf
));
btrfs_set_header_parentid
(
&
empty_leaf
.
header
,
BTRFS_ROOT_TREE_OBJECTID
);
btrfs_set_header_blocknr
(
&
empty_leaf
.
header
,
17
);
btrfs_set_header_nritems
(
&
empty_leaf
.
header
,
2
);
empty_leaf
=
malloc
(
blocksize
);
memset
(
empty_leaf
,
0
,
blocksize
);
btrfs_set_header_parentid
(
&
empty_leaf
->
header
,
BTRFS_ROOT_TREE_OBJECTID
);
btrfs_set_header_blocknr
(
&
empty_leaf
->
header
,
start_block
+
1
);
btrfs_set_header_nritems
(
&
empty_leaf
->
header
,
2
);
/* create the items for the root tree */
btrfs_set_root_blocknr
(
&
root_item
,
18
);
btrfs_set_root_blocknr
(
&
root_item
,
start_block
+
2
);
btrfs_set_root_refs
(
&
root_item
,
1
);
itemoff
=
LEAF_DATA_SIZE
-
sizeof
(
root_item
);
itemoff
=
__BTRFS_LEAF_DATA_SIZE
(
blocksize
)
-
sizeof
(
root_item
);
btrfs_set_item_offset
(
&
item
,
itemoff
);
btrfs_set_item_size
(
&
item
,
sizeof
(
root_item
));
btrfs_set_key_objectid
(
&
item
.
key
,
BTRFS_EXTENT_TREE_OBJECTID
);
btrfs_set_key_offset
(
&
item
.
key
,
0
);
btrfs_set_key_flags
(
&
item
.
key
,
0
);
memcpy
(
empty_leaf
.
items
,
&
item
,
sizeof
(
item
));
memcpy
(
empty_leaf
.
data
+
itemoff
,
&
root_item
,
sizeof
(
root_item
));
memcpy
(
empty_leaf
->
items
,
&
item
,
sizeof
(
item
));
memcpy
(
btrfs_leaf_data
(
empty_leaf
)
+
itemoff
,
&
root_item
,
sizeof
(
root_item
));
btrfs_set_root_blocknr
(
&
root_item
,
19
);
btrfs_set_root_blocknr
(
&
root_item
,
start_block
+
3
);
itemoff
=
itemoff
-
sizeof
(
root_item
);
btrfs_set_item_offset
(
&
item
,
itemoff
);
btrfs_set_key_objectid
(
&
item
.
key
,
BTRFS_FS_TREE_OBJECTID
);
memcpy
(
empty_leaf
.
items
+
1
,
&
item
,
sizeof
(
item
));
memcpy
(
empty_leaf
.
data
+
itemoff
,
&
root_item
,
sizeof
(
root_item
));
ret
=
pwrite
(
fd
,
&
empty_leaf
,
blocksize
,
17
*
blocksize
);
memcpy
(
empty_leaf
->
items
+
1
,
&
item
,
sizeof
(
item
));
memcpy
(
btrfs_leaf_data
(
empty_leaf
)
+
itemoff
,
&
root_item
,
sizeof
(
root_item
));
ret
=
pwrite
(
fd
,
empty_leaf
,
blocksize
,
(
start_block
+
1
)
*
blocksize
);
/* create the items for the extent tree */
btrfs_set_header_parentid
(
&
empty_leaf
.
header
,
btrfs_set_header_parentid
(
&
empty_leaf
->
header
,
BTRFS_EXTENT_TREE_OBJECTID
);
btrfs_set_header_blocknr
(
&
empty_leaf
.
header
,
18
);
btrfs_set_header_nritems
(
&
empty_leaf
.
header
,
4
);
btrfs_set_header_blocknr
(
&
empty_leaf
->
header
,
start_block
+
2
);
btrfs_set_header_nritems
(
&
empty_leaf
->
header
,
4
);
/* item1, reserve blocks 0-16 */
btrfs_set_key_objectid
(
&
item
.
key
,
0
);
btrfs_set_key_offset
(
&
item
.
key
,
17
);
btrfs_set_key_offset
(
&
item
.
key
,
start_block
+
1
);
btrfs_set_key_flags
(
&
item
.
key
,
0
);
itemoff
=
LEAF_DATA_SIZE
-
sizeof
(
struct
btrfs_extent_item
);
itemoff
=
__BTRFS_LEAF_DATA_SIZE
(
blocksize
)
-
sizeof
(
struct
btrfs_extent_item
);
btrfs_set_item_offset
(
&
item
,
itemoff
);
btrfs_set_item_size
(
&
item
,
sizeof
(
struct
btrfs_extent_item
));
btrfs_set_extent_refs
(
&
extent_item
,
1
);
btrfs_set_extent_owner
(
&
extent_item
,
0
);
memcpy
(
empty_leaf
.
items
,
&
item
,
sizeof
(
item
));
memcpy
(
empty_leaf
.
data
+
btrfs_item_offset
(
&
item
),
&
extent_item
,
btrfs_item_size
(
&
item
));
memcpy
(
empty_leaf
->
items
,
&
item
,
sizeof
(
item
));
memcpy
(
btrfs_leaf_data
(
empty_leaf
)
+
btrfs_item_offset
(
&
item
)
,
&
extent_item
,
btrfs_item_size
(
&
item
));
/* item2, give block 17 to the root */
btrfs_set_key_objectid
(
&
item
.
key
,
17
);
btrfs_set_key_objectid
(
&
item
.
key
,
start_block
+
1
);
btrfs_set_key_offset
(
&
item
.
key
,
1
);
itemoff
=
itemoff
-
sizeof
(
struct
btrfs_extent_item
);
btrfs_set_item_offset
(
&
item
,
itemoff
);
btrfs_set_extent_owner
(
&
extent_item
,
BTRFS_ROOT_TREE_OBJECTID
);
memcpy
(
empty_leaf
.
items
+
1
,
&
item
,
sizeof
(
item
));
memcpy
(
empty_leaf
.
data
+
btrfs_item_offset
(
&
item
),
&
extent_item
,
btrfs_item_size
(
&
item
));
memcpy
(
empty_leaf
->
items
+
1
,
&
item
,
sizeof
(
item
));
memcpy
(
btrfs_leaf_data
(
empty_leaf
)
+
btrfs_item_offset
(
&
item
)
,
&
extent_item
,
btrfs_item_size
(
&
item
));
/* item3, give block 18 to the extent root */
btrfs_set_key_objectid
(
&
item
.
key
,
18
);
btrfs_set_key_objectid
(
&
item
.
key
,
start_block
+
2
);
btrfs_set_key_offset
(
&
item
.
key
,
1
);
itemoff
=
itemoff
-
sizeof
(
struct
btrfs_extent_item
);
btrfs_set_item_offset
(
&
item
,
itemoff
);
btrfs_set_extent_owner
(
&
extent_item
,
BTRFS_EXTENT_TREE_OBJECTID
);
memcpy
(
empty_leaf
.
items
+
2
,
&
item
,
sizeof
(
item
));
memcpy
(
empty_leaf
.
data
+
btrfs_item_offset
(
&
item
),
&
extent_item
,
btrfs_item_size
(
&
item
));
memcpy
(
empty_leaf
->
items
+
2
,
&
item
,
sizeof
(
item
));
memcpy
(
btrfs_leaf_data
(
empty_leaf
)
+
btrfs_item_offset
(
&
item
)
,
&
extent_item
,
btrfs_item_size
(
&
item
));
/* item4, give block 19 to the FS root */
btrfs_set_key_objectid
(
&
item
.
key
,
19
);
btrfs_set_key_objectid
(
&
item
.
key
,
start_block
+
3
);
btrfs_set_key_offset
(
&
item
.
key
,
1
);
itemoff
=
itemoff
-
sizeof
(
struct
btrfs_extent_item
);
btrfs_set_item_offset
(
&
item
,
itemoff
);
btrfs_set_extent_owner
(
&
extent_item
,
BTRFS_FS_TREE_OBJECTID
);
memcpy
(
empty_leaf
.
items
+
3
,
&
item
,
sizeof
(
item
));
memcpy
(
empty_leaf
.
data
+
btrfs_item_offset
(
&
item
),
&
extent_item
,
btrfs_item_size
(
&
item
));
ret
=
pwrite
(
fd
,
&
empty_leaf
,
blocksize
,
18
*
blocksize
);
if
(
ret
!=
sizeof
(
empty_leaf
)
)
memcpy
(
empty_leaf
->
items
+
3
,
&
item
,
sizeof
(
item
));
memcpy
(
btrfs_leaf_data
(
empty_leaf
)
+
btrfs_item_offset
(
&
item
)
,
&
extent_item
,
btrfs_item_size
(
&
item
));
ret
=
pwrite
(
fd
,
empty_leaf
,
blocksize
,
(
start_block
+
2
)
*
blocksize
);
if
(
ret
!=
blocksize
)
return
-
1
;
/* finally create the FS root */
btrfs_set_header_parentid
(
&
empty_leaf
.
header
,
BTRFS_FS_TREE_OBJECTID
);
btrfs_set_header_blocknr
(
&
empty_leaf
.
header
,
19
);
btrfs_set_header_nritems
(
&
empty_leaf
.
header
,
0
);
ret
=
pwrite
(
fd
,
&
empty_leaf
,
blocksize
,
19
*
blocksize
);
if
(
ret
!=
sizeof
(
empty_leaf
)
)
btrfs_set_header_parentid
(
&
empty_leaf
->
header
,
BTRFS_FS_TREE_OBJECTID
);
btrfs_set_header_blocknr
(
&
empty_leaf
->
header
,
start_block
+
3
);
btrfs_set_header_nritems
(
&
empty_leaf
->
header
,
0
);
ret
=
pwrite
(
fd
,
empty_leaf
,
blocksize
,
(
start_block
+
3
)
*
blocksize
);
if
(
ret
!=
blocksize
)
return
-
1
;
return
0
;
}
#if 0
int mkfs(int fd)
{
struct btrfs_root_info info[2];
struct btrfs_leaf empty_leaf;
struct btrfs_item item;
struct btrfs_extent_item extent_item;
int ret;
/* setup the super block area */
memset(info, 0, sizeof(info));
btrfs_set_root_blocknr(info, 16);
btrfs_set_root_objectid(info, 1);
btrfs_set_root_tree_root(info, 17);
btrfs_set_root_blocknr(info + 1, 16);
btrfs_set_root_objectid(info + 1, 2);
btrfs_set_root_tree_root(info + 1, 18);
ret = pwrite(fd, info, sizeof(info),
BTRFS_SUPER_INFO_OFFSET(BTRFS_BLOCKSIZE));
if (ret != sizeof(info))
return -1;
/* create leaves for the tree root and extent root */
memset(&empty_leaf, 0, sizeof(empty_leaf));
btrfs_set_header_parentid(&empty_leaf.header, 1);
btrfs_set_header_blocknr(&empty_leaf.header, 17);
ret = pwrite(fd, &empty_leaf, sizeof(empty_leaf), 17 * BTRFS_BLOCKSIZE);
if (ret != sizeof(empty_leaf))
return -1;
btrfs_set_header_parentid(&empty_leaf.header, 2);
btrfs_set_header_blocknr(&empty_leaf.header, 18);
btrfs_set_header_nritems(&empty_leaf.header, 3);
/* item1, reserve blocks 0-16 */
btrfs_set_key_objectid(&item.key, 0);
btrfs_set_key_offset(&item.key, 17);
btrfs_set_key_flags(&item.key, 0);
btrfs_set_item_offset(&item, LEAF_DATA_SIZE -
sizeof(struct btrfs_extent_item));
btrfs_set_item_size(&item, sizeof(struct btrfs_extent_item));
btrfs_set_extent_refs(&extent_item, 1);
btrfs_set_extent_owner(&extent_item, 0);
memcpy(empty_leaf.items, &item, sizeof(item));
memcpy(empty_leaf.data + btrfs_item_offset(&item), &extent_item,
btrfs_item_size(&item));
/* item2, give block 17 to the root */
btrfs_set_key_objectid(&item.key, 17);
btrfs_set_key_offset(&item.key, 1);
btrfs_set_item_offset(&item, LEAF_DATA_SIZE -
sizeof(struct btrfs_extent_item) * 2);
btrfs_set_extent_owner(&extent_item, 1);
memcpy(empty_leaf.items + 1, &item, sizeof(item));
memcpy(empty_leaf.data + btrfs_item_offset(&item), &extent_item,
btrfs_item_size(&item));
/* item3, give block 18 for the extent root */
btrfs_set_key_objectid(&item.key, 18);
btrfs_set_key_offset(&item.key, 1);
btrfs_set_item_offset(&item, LEAF_DATA_SIZE -
sizeof(struct btrfs_extent_item) * 3);
btrfs_set_extent_owner(&extent_item, 2);
memcpy(empty_leaf.items + 2, &item, sizeof(item));
memcpy(empty_leaf.data + btrfs_item_offset(&item), &extent_item,
btrfs_item_size(&item));
ret = pwrite(fd, &empty_leaf, sizeof(empty_leaf), 18 * BTRFS_BLOCKSIZE);
if (ret != sizeof(empty_leaf))
return -1;
return 0;
}
#endif
fs/btrfs/print-tree.c
浏览文件 @
123abc88
...
...
@@ -5,7 +5,7 @@
#include "ctree.h"
#include "disk-io.h"
void
btrfs_print_leaf
(
struct
btrfs_leaf
*
l
)
void
btrfs_print_leaf
(
struct
btrfs_
root
*
root
,
struct
btrfs_
leaf
*
l
)
{
int
i
;
u32
nr
=
btrfs_header_nritems
(
&
l
->
header
);
...
...
@@ -13,7 +13,8 @@ void btrfs_print_leaf(struct btrfs_leaf *l)
struct
btrfs_extent_item
*
ei
;
struct
btrfs_root_item
*
ri
;
printf
(
"leaf %Lu total ptrs %d free space %d
\n
"
,
btrfs_header_blocknr
(
&
l
->
header
),
nr
,
btrfs_leaf_free_space
(
l
));
btrfs_header_blocknr
(
&
l
->
header
),
nr
,
btrfs_leaf_free_space
(
root
,
l
));
fflush
(
stdout
);
for
(
i
=
0
;
i
<
nr
;
i
++
)
{
item
=
l
->
items
+
i
;
...
...
@@ -25,7 +26,7 @@ void btrfs_print_leaf(struct btrfs_leaf *l)
btrfs_item_offset
(
item
),
btrfs_item_size
(
item
));
printf
(
"
\t\t
item data %.*s
\n
"
,
btrfs_item_size
(
item
),
l
->
data
+
btrfs_item_offset
(
item
));
btrfs_leaf_data
(
l
)
+
btrfs_item_offset
(
item
));
ei
=
btrfs_item_ptr
(
l
,
i
,
struct
btrfs_extent_item
);
printf
(
"
\t\t
extent data refs %u owner %Lu
\n
"
,
btrfs_extent_refs
(
ei
),
btrfs_extent_owner
(
ei
));
...
...
@@ -46,18 +47,18 @@ void btrfs_print_tree(struct btrfs_root *root, struct btrfs_buffer *t)
c
=
&
t
->
node
;
nr
=
btrfs_header_nritems
(
&
c
->
header
);
if
(
btrfs_is_leaf
(
c
))
{
btrfs_print_leaf
((
struct
btrfs_leaf
*
)
c
);
btrfs_print_leaf
(
root
,
(
struct
btrfs_leaf
*
)
c
);
return
;
}
printf
(
"node %Lu level %d total ptrs %d free spc %u
\n
"
,
t
->
blocknr
,
btrfs_header_level
(
&
c
->
header
),
nr
,
(
u32
)
NODEPTRS_PER_BLOCK
-
nr
);
(
u32
)
BTRFS_NODEPTRS_PER_BLOCK
(
root
)
-
nr
);
fflush
(
stdout
);
for
(
i
=
0
;
i
<
nr
;
i
++
)
{
printf
(
"
\t
key %d (%Lu %u %Lu) block %Lu
\n
"
,
i
,
c
->
keys
[
i
].
objectid
,
c
->
keys
[
i
].
flags
,
c
->
keys
[
i
].
offset
,
btrfs_node_blockptr
(
c
,
i
));
c
->
ptrs
[
i
].
key
.
objectid
,
c
->
ptrs
[
i
].
key
.
flags
,
c
->
ptrs
[
i
].
key
.
offset
,
btrfs_node_blockptr
(
c
,
i
));
fflush
(
stdout
);
}
for
(
i
=
0
;
i
<
nr
;
i
++
)
{
...
...
fs/btrfs/print-tree.h
浏览文件 @
123abc88
void
btrfs_print_leaf
(
struct
btrfs_leaf
*
l
);
void
btrfs_print_leaf
(
struct
btrfs_
root
*
root
,
struct
btrfs_
leaf
*
l
);
void
btrfs_print_tree
(
struct
btrfs_root
*
root
,
struct
btrfs_buffer
*
t
);
fs/btrfs/quick-test.c
浏览文件 @
123abc88
...
...
@@ -73,7 +73,7 @@ int main(int ac, char **av) {
printf
(
"node %p level %d total ptrs %d free spc %lu
\n
"
,
root
->
node
,
btrfs_header_level
(
&
root
->
node
->
node
.
header
),
btrfs_header_nritems
(
&
root
->
node
->
node
.
header
),
NODEPTRS_PER_BLOCK
-
BTRFS_NODEPTRS_PER_BLOCK
(
root
)
-
btrfs_header_nritems
(
&
root
->
node
->
node
.
header
));
printf
(
"all searches good, deleting some items
\n
"
);
i
=
0
;
...
...
fs/btrfs/root-tree.c
浏览文件 @
123abc88
...
...
@@ -31,7 +31,7 @@ int btrfs_find_last_root(struct btrfs_root *root, u64 objectid,
ret
=
1
;
goto
out
;
}
memcpy
(
item
,
l
->
data
+
btrfs_item_offset
(
l
->
items
+
slot
),
memcpy
(
item
,
btrfs_item_ptr
(
l
,
slot
,
struct
btrfs_root_item
),
sizeof
(
*
item
));
btrfs_disk_key_to_cpu
(
key
,
&
l
->
items
[
slot
].
key
);
btrfs_release_path
(
root
,
&
path
);
...
...
@@ -55,7 +55,7 @@ int btrfs_update_root(struct btrfs_root *root, struct btrfs_key *key,
BUG_ON
(
ret
!=
0
);
l
=
&
path
.
nodes
[
0
]
->
leaf
;
slot
=
path
.
slots
[
0
];
memcpy
(
l
->
data
+
btrfs_item_offset
(
l
->
items
+
slot
),
item
,
memcpy
(
btrfs_item_ptr
(
l
,
slot
,
struct
btrfs_root_item
),
item
,
sizeof
(
*
item
));
out:
btrfs_release_path
(
root
,
&
path
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录