-
Notifications
You must be signed in to change notification settings - Fork 2
/
debugfs-handle-inline_data-in-punch-command
141 lines (136 loc) · 4.03 KB
/
debugfs-handle-inline_data-in-punch-command
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
debugfs: handle inline_data in punch command
From: Zheng Liu <[email protected]>
Now punch command only can truncate an inode with inline_data.
Signed-off-by: Zheng Liu <[email protected]>
Signed-off-by: Theodore Ts'o <[email protected]>
---
lib/ext2fs/ext2fs.h | 2 ++
lib/ext2fs/inline_data.c | 81 ++++++++++++++++++++++++++++++++++++++++++++++--
lib/ext2fs/punch.c | 4 ++-
3 files changed, 84 insertions(+), 3 deletions(-)
diff --git a/lib/ext2fs/ext2fs.h b/lib/ext2fs/ext2fs.h
index 2f96eb8..8fea664 100644
--- a/lib/ext2fs/ext2fs.h
+++ b/lib/ext2fs/ext2fs.h
@@ -1373,6 +1373,8 @@ extern errcode_t ext2fs_try_to_write_inline_data(ext2_filsys fs, ext2_ino_t ino,
unsigned int *written);
extern errcode_t ext2fs_inline_data_dirsearch(ext2_filsys fs, ext2_ino_t ino,
const char *name, size_t namelen);
+extern errcode_t ext2fs_punch_inline_data(ext2_filsys fs, ext2_ino_t ino,
+ blk64_t start, blk64_t end);
/* inode.c */
extern void ext2fs_free_inode_cache(struct ext2_inode_cache *icache);
diff --git a/lib/ext2fs/inline_data.c b/lib/ext2fs/inline_data.c
index c881afc..8ac0a58 100644
--- a/lib/ext2fs/inline_data.c
+++ b/lib/ext2fs/inline_data.c
@@ -155,8 +155,6 @@ errcode_t ext2fs_inline_data_dirsearch(ext2_filsys fs, ext2_ino_t ino,
struct ext2_inode_large *inode;
struct ext2_dir_entry dirent;
struct inline_data data;
- unsigned int offset = 0;
- unsigned int rec_len;
char *inline_start;
unsigned int inline_size;
errcode_t retval = 0;
@@ -477,6 +475,85 @@ err:
ext2fs_free_mem(&inode);
return retval;
}
+
+errcode_t ext2fs_punch_inline_data(ext2_filsys fs, ext2_ino_t ino,
+ blk64_t start, blk64_t end)
+{
+ struct ext2_inode_large *inode;
+ struct inline_data data;
+ errcode_t retval = 0;
+ void *value;
+ unsigned int inline_size, value_len;
+
+ retval = ext2fs_get_mem(EXT2_INODE_SIZE(fs->super), &inode);
+ if (retval)
+ return retval;
+
+ retval = ext2fs_read_inode_full(fs, ino, (void *)inode,
+ EXT2_INODE_SIZE(fs->super));
+ if (retval)
+ goto out;
+
+ retval = ext2fs_iget_extra_inode(fs, inode, &data);
+ if (retval)
+ goto out;
+ inline_size = data.inline_size;
+
+ if (start > inline_size)
+ goto out;
+
+ if (start < inline_size) {
+ struct ext2_ext_attr_search s = {
+ .not_found = -1,
+ };
+ struct ext2_ext_attr_info i = {
+ .name_index = EXT4_EXT_ATTR_INDEX_SYSTEM,
+ .name = EXT4_EXT_ATTR_SYSTEM_DATA,
+ };
+
+ if (!data.inline_off)
+ goto out;
+
+ if (inode->i_extra_isize > (EXT2_INODE_SIZE(fs->super) -
+ EXT2_GOOD_OLD_INODE_SIZE)) {
+ retval = EXT2_ET_BAD_EXTRA_SIZE;
+ goto out;
+ }
+
+ (void)ext2fs_ibody_find_ext_attr(fs, inode, &i, &s);
+
+ value_len = ext2fs_le32_to_cpu(s.here->e_value_size);
+
+ retval = ext2fs_get_mem(s.here->e_value_size, &value);
+ if (retval)
+ goto out;
+
+ retval = ext2fs_ibody_get_ext_attr(fs, inode, i.name_index,
+ i.name, value, value_len);
+
+ if (!s.not_found) {
+ i.value = value;
+ i.value_len = start > EXT4_MIN_INLINE_DATA_SIZE ?
+ start - EXT4_MIN_INLINE_DATA_SIZE : 0;
+ }
+ retval = ext2fs_set_entry_ext_attr(&i, &s);
+ if (retval)
+ goto out;
+ }
+
+ if (start < EXT4_MIN_INLINE_DATA_SIZE) {
+ memset((char *)inode->i_block + start, 0,
+ EXT4_MIN_INLINE_DATA_SIZE - start);
+ }
+
+ inode->i_size = start;
+ retval = ext2fs_write_inode_full(fs, ino, (void *)inode,
+ EXT2_INODE_SIZE(fs->super));
+out:
+ ext2fs_free_mem(&inode);
+ return retval;
+}
+
errcode_t ext2fs_convert_inline_data(ext2_filsys fs,
ext2_ino_t ino,
void *priv_data)
diff --git a/lib/ext2fs/punch.c b/lib/ext2fs/punch.c
index b53653a..8de9649 100644
--- a/lib/ext2fs/punch.c
+++ b/lib/ext2fs/punch.c
@@ -307,7 +307,9 @@ extern errcode_t ext2fs_punch(ext2_filsys fs, ext2_ino_t ino,
return retval;
inode = &inode_buf;
}
- if (inode->i_flags & EXT4_EXTENTS_FL)
+ if (inode->i_flags & EXT4_INLINE_DATA_FL)
+ return ext2fs_punch_inline_data(fs, ino, start, end);
+ else if (inode->i_flags & EXT4_EXTENTS_FL)
retval = ext2fs_punch_extent(fs, ino, inode, start, end);
else {
blk_t count;