Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
L
linux
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
linux
Commits
06ed4b31
Commit
06ed4b31
authored
Feb 20, 2007
by
Chris Mason
Committed by
David Woodhouse
Feb 20, 2007
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Btrfs: add mkfs.c
Signed-off-by:
Chris Mason
<
chris.mason@oracle.com
>
parent
d97e63b6
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
69 additions
and
0 deletions
+69
-0
fs/btrfs/mkfs.c
fs/btrfs/mkfs.c
+69
-0
No files found.
fs/btrfs/mkfs.c
0 → 100644
View file @
06ed4b31
#define _XOPEN_SOURCE 500
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include "kerncompat.h"
#include "radix-tree.h"
#include "ctree.h"
#include "disk-io.h"
int
mkfs
(
int
fd
)
{
struct
ctree_root_info
info
[
2
];
struct
leaf
empty_leaf
;
struct
item
item
;
struct
extent_item
extent_item
;
int
ret
;
memset
(
info
,
0
,
sizeof
(
info
));
info
[
0
].
blocknr
=
16
;
info
[
0
].
objectid
=
1
;
info
[
0
].
tree_root
=
17
;
info
[
0
].
alloc_extent
.
blocknr
=
0
;
info
[
0
].
alloc_extent
.
num_blocks
=
20
;
/* 0-17 are used (inclusive) */
info
[
0
].
alloc_extent
.
num_used
=
18
;
info
[
1
].
blocknr
=
16
;
info
[
1
].
objectid
=
2
;
info
[
1
].
tree_root
=
64
;
info
[
1
].
alloc_extent
.
blocknr
=
64
;
info
[
1
].
alloc_extent
.
num_blocks
=
8
;
info
[
1
].
alloc_extent
.
num_used
=
1
;
ret
=
pwrite
(
fd
,
info
,
sizeof
(
info
),
CTREE_SUPER_INFO_OFFSET
(
CTREE_BLOCKSIZE
));
if
(
ret
!=
sizeof
(
info
))
return
-
1
;
memset
(
&
empty_leaf
,
0
,
sizeof
(
empty_leaf
));
empty_leaf
.
header
.
parentid
=
1
;
empty_leaf
.
header
.
blocknr
=
17
;
ret
=
pwrite
(
fd
,
&
empty_leaf
,
sizeof
(
empty_leaf
),
17
*
CTREE_BLOCKSIZE
);
if
(
ret
!=
sizeof
(
empty_leaf
))
return
-
1
;
empty_leaf
.
header
.
parentid
=
2
;
empty_leaf
.
header
.
blocknr
=
64
;
empty_leaf
.
header
.
nritems
=
2
;
item
.
key
.
objectid
=
0
;
item
.
key
.
offset
=
64
;
item
.
key
.
flags
=
0
;
item
.
offset
=
LEAF_DATA_SIZE
-
sizeof
(
struct
extent_item
);
item
.
size
=
sizeof
(
struct
extent_item
);
extent_item
.
refs
=
1
;
extent_item
.
owner
=
1
;
memcpy
(
empty_leaf
.
items
,
&
item
,
sizeof
(
item
));
memcpy
(
empty_leaf
.
data
+
item
.
offset
,
&
extent_item
,
item
.
size
);
item
.
key
.
objectid
=
64
;
item
.
key
.
offset
=
64
;
item
.
offset
=
LEAF_DATA_SIZE
-
sizeof
(
struct
extent_item
)
*
2
;
extent_item
.
owner
=
2
;
memcpy
(
empty_leaf
.
items
+
1
,
&
item
,
sizeof
(
item
));
memcpy
(
empty_leaf
.
data
+
item
.
offset
,
&
extent_item
,
item
.
size
);
ret
=
pwrite
(
fd
,
&
empty_leaf
,
sizeof
(
empty_leaf
),
64
*
CTREE_BLOCKSIZE
);
if
(
ret
!=
sizeof
(
empty_leaf
))
return
-
1
;
return
0
;
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment