Skip to content

Commit 4a67d9b

Browse files
chaseyuJaegeuk Kim
authored andcommitted
f2fs: compress: fix to disallow temp extension
This patch restricts to configure compress extension as format of: [filename + '.' + extension] rather than: [filename + '.' + extension + (optional: '.' + temp extension)] in order to avoid to enable compression incorrectly: 1. compress_extension=so 2. touch file.soa 3. touch file.so.tmp Fixes: 4c8ff70 ("f2fs: support data compression") Signed-off-by: Chao Yu <yuchao0@huawei.com> Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
1 parent e3c5483 commit 4a67d9b

1 file changed

Lines changed: 12 additions & 4 deletions

File tree

‎fs/f2fs/namei.c‎

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,8 @@ static struct inode *f2fs_new_inode(struct inode *dir, umode_t mode)
153153
return ERR_PTR(err);
154154
}
155155

156-
static inline int is_extension_exist(const unsigned char *s, const char *sub)
156+
static inline int is_extension_exist(const unsigned char *s, const char *sub,
157+
bool tmp_ext)
157158
{
158159
size_t slen = strlen(s);
159160
size_t sublen = strlen(sub);
@@ -169,6 +170,13 @@ static inline int is_extension_exist(const unsigned char *s, const char *sub)
169170
if (slen < sublen + 2)
170171
return 0;
171172

173+
if (!tmp_ext) {
174+
/* file has no temp extension */
175+
if (s[slen - sublen - 1] != '.')
176+
return 0;
177+
return !strncasecmp(s + slen - sublen, sub, sublen);
178+
}
179+
172180
for (i = 1; i < slen - sublen; i++) {
173181
if (s[i] != '.')
174182
continue;
@@ -194,7 +202,7 @@ static inline void set_file_temperature(struct f2fs_sb_info *sbi, struct inode *
194202
hot_count = sbi->raw_super->hot_ext_count;
195203

196204
for (i = 0; i < cold_count + hot_count; i++) {
197-
if (is_extension_exist(name, extlist[i]))
205+
if (is_extension_exist(name, extlist[i], true))
198206
break;
199207
}
200208

@@ -295,7 +303,7 @@ static void set_compress_inode(struct f2fs_sb_info *sbi, struct inode *inode,
295303
hot_count = sbi->raw_super->hot_ext_count;
296304

297305
for (i = cold_count; i < cold_count + hot_count; i++) {
298-
if (is_extension_exist(name, extlist[i])) {
306+
if (is_extension_exist(name, extlist[i], false)) {
299307
up_read(&sbi->sb_lock);
300308
return;
301309
}
@@ -306,7 +314,7 @@ static void set_compress_inode(struct f2fs_sb_info *sbi, struct inode *inode,
306314
ext = F2FS_OPTION(sbi).extensions;
307315

308316
for (i = 0; i < ext_cnt; i++) {
309-
if (!is_extension_exist(name, ext[i]))
317+
if (!is_extension_exist(name, ext[i], false))
310318
continue;
311319

312320
set_compress_context(inode);

0 commit comments

Comments
 (0)