mirror of
https://gitee.com/openharmony/third_party_f2fs-tools
synced 2024-11-26 19:51:32 +00:00
mkfs.f2fs: set required quota types only
commit 85cd72a2445a7c590852c829f3be23872c2cbe43 category: bugfix issue: #I6VAS0 CVE: NA Signed-off-by: DongSenhao <dongsenhao2@huawei.com> --------------------------------------- This patch modifies enabling quota options in which enables user/group quotas only if user specifies the "-O quota" especially. 1) -O quota : enables usr/grp 2) -O project_quota -O extra_attr : enabled prj 3) -O quota -O project_quota -O extra_attr : enables usr/grp/proj 4) -g android : enables usr/grp 5) -g android -O project_quota -O extra_attr : enables usr/grp/proj Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org> Signed-off-by: dongsenhao <dongsenhao2@huawei.com>
This commit is contained in:
parent
0f3b8d9c02
commit
d8cf06b01b
@ -504,6 +504,7 @@ struct f2fs_configuration {
|
||||
int large_nat_bitmap;
|
||||
int fix_chksum; /* fix old cp.chksum position */
|
||||
__le32 feature; /* defined features */
|
||||
unsigned int quota_bits; /* quota bits */
|
||||
time_t fixed_time;
|
||||
|
||||
/* mkfs parameters */
|
||||
|
@ -40,8 +40,6 @@ struct f2fs_checkpoint *cp;
|
||||
/* Return time fixed by the user or current time by default */
|
||||
#define mkfs_time ((c.fixed_time == -1) ? time(NULL) : c.fixed_time)
|
||||
|
||||
static unsigned int quotatype_bits = 0;
|
||||
|
||||
const char *media_ext_lists[] = {
|
||||
/* common prefix */
|
||||
"mp", // Covers mp3, mp4, mpeg, mpg
|
||||
@ -515,14 +513,8 @@ static int f2fs_prepare_super_block(void)
|
||||
set_sb(root_ino, 3);
|
||||
c.next_free_nid = 4;
|
||||
|
||||
if (c.feature & cpu_to_le32(F2FS_FEATURE_QUOTA_INO)) {
|
||||
quotatype_bits = QUOTA_USR_BIT | QUOTA_GRP_BIT;
|
||||
if (c.feature & cpu_to_le32(F2FS_FEATURE_PRJQUOTA))
|
||||
quotatype_bits |= QUOTA_PRJ_BIT;
|
||||
}
|
||||
|
||||
for (qtype = 0; qtype < F2FS_MAX_QUOTAS; qtype++) {
|
||||
if (!((1 << qtype) & quotatype_bits))
|
||||
if (!((1 << qtype) & c.quota_bits))
|
||||
continue;
|
||||
sb->qf_ino[qtype] = cpu_to_le32(c.next_free_nid++);
|
||||
MSG(0, "Info: add quota type = %u => %u\n",
|
||||
@ -869,7 +861,7 @@ static int f2fs_write_check_point_pack(void)
|
||||
get_cp(cur_node_segno[0]) * c.blks_per_seg);
|
||||
|
||||
for (qtype = 0, i = 1; qtype < F2FS_MAX_QUOTAS; qtype++) {
|
||||
if (sb->qf_ino[qtype] == 0)
|
||||
if (!((1 << qtype) & c.quota_bits))
|
||||
continue;
|
||||
journal->nat_j.entries[i].nid = sb->qf_ino[qtype];
|
||||
journal->nat_j.entries[i].ne.version = 0;
|
||||
@ -960,10 +952,11 @@ static int f2fs_write_check_point_pack(void)
|
||||
|
||||
off = 1;
|
||||
for (qtype = 0; qtype < F2FS_MAX_QUOTAS; qtype++) {
|
||||
if (sb->qf_ino[qtype] == 0)
|
||||
continue;
|
||||
int j;
|
||||
|
||||
if (!((1 << qtype) & c.quota_bits))
|
||||
continue;
|
||||
|
||||
for (j = 0; j < QUOTA_DATA(qtype); j++) {
|
||||
(sum_entry + off + j)->nid = sb->qf_ino[qtype];
|
||||
(sum_entry + off + j)->ofs_in_node = cpu_to_le16(j);
|
||||
@ -994,7 +987,7 @@ static int f2fs_write_check_point_pack(void)
|
||||
sum->entries[0].nid = sb->root_ino;
|
||||
sum->entries[0].ofs_in_node = 0;
|
||||
for (qtype = i = 0; qtype < F2FS_MAX_QUOTAS; qtype++) {
|
||||
if (sb->qf_ino[qtype] == 0)
|
||||
if (!((1 << qtype) & c.quota_bits))
|
||||
continue;
|
||||
sum->entries[1 + i].nid = sb->qf_ino[qtype];
|
||||
sum->entries[1 + i].ofs_in_node = 0;
|
||||
@ -1362,7 +1355,7 @@ static int f2fs_write_default_quota(int qtype, unsigned int blkaddr,
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int f2fs_write_qf_inode(int qtype)
|
||||
static int f2fs_write_qf_inode(int qtype, int offset)
|
||||
{
|
||||
struct f2fs_node *raw_node = NULL;
|
||||
u_int64_t data_blk_nor;
|
||||
@ -1384,11 +1377,9 @@ static int f2fs_write_qf_inode(int qtype)
|
||||
raw_node->i.i_blocks = cpu_to_le64(1 + QUOTA_DATA(qtype));
|
||||
|
||||
data_blk_nor = get_sb(main_blkaddr) +
|
||||
c.cur_seg[CURSEG_HOT_DATA] * c.blks_per_seg + 1;
|
||||
c.cur_seg[CURSEG_HOT_DATA] * c.blks_per_seg + 1
|
||||
+ offset * QUOTA_DATA(i);
|
||||
|
||||
for (i = 0; i < qtype; i++)
|
||||
if (sb->qf_ino[i])
|
||||
data_blk_nor += QUOTA_DATA(i);
|
||||
if (qtype == 0)
|
||||
raw_id = raw_node->i.i_uid;
|
||||
else if (qtype == 1)
|
||||
@ -1410,7 +1401,7 @@ static int f2fs_write_qf_inode(int qtype)
|
||||
|
||||
main_area_node_seg_blk_offset = get_sb(main_blkaddr);
|
||||
main_area_node_seg_blk_offset += c.cur_seg[CURSEG_HOT_NODE] *
|
||||
c.blks_per_seg + qtype + 1;
|
||||
c.blks_per_seg + offset + 1;
|
||||
|
||||
DBG(1, "\tWriting quota inode (hot node), %x %x %x at offset 0x%08"PRIu64"\n",
|
||||
get_sb(main_blkaddr),
|
||||
@ -1442,7 +1433,7 @@ static int f2fs_update_nat_root(void)
|
||||
|
||||
/* update quota */
|
||||
for (qtype = i = 0; qtype < F2FS_MAX_QUOTAS; qtype++) {
|
||||
if (sb->qf_ino[qtype] == 0)
|
||||
if (!((1 << qtype) & c.quota_bits))
|
||||
continue;
|
||||
nat_blk->entries[sb->qf_ino[qtype]].block_addr =
|
||||
cpu_to_le32(get_sb(main_blkaddr) +
|
||||
@ -1680,7 +1671,7 @@ static int f2fs_add_default_dentry_root(void)
|
||||
static int f2fs_create_root_dir(void)
|
||||
{
|
||||
enum quota_type qtype;
|
||||
int err = 0;
|
||||
int err = 0, i = 0;
|
||||
|
||||
err = f2fs_write_root_inode();
|
||||
if (err < 0) {
|
||||
@ -1689,9 +1680,9 @@ static int f2fs_create_root_dir(void)
|
||||
}
|
||||
|
||||
for (qtype = 0; qtype < F2FS_MAX_QUOTAS; qtype++) {
|
||||
if (sb->qf_ino[qtype] == 0)
|
||||
if (!((1 << qtype) & c.quota_bits))
|
||||
continue;
|
||||
err = f2fs_write_qf_inode(qtype);
|
||||
err = f2fs_write_qf_inode(qtype, i++);
|
||||
if (err < 0) {
|
||||
MSG(1, "\tError: Failed to write quota inode!!!\n");
|
||||
goto exit;
|
||||
|
@ -30,6 +30,7 @@
|
||||
#endif
|
||||
|
||||
#include "f2fs_fs.h"
|
||||
#include "quota.h"
|
||||
#include "f2fs_format_utils.h"
|
||||
|
||||
#ifdef WITH_ANDROID
|
||||
@ -129,9 +130,17 @@ static void add_default_options(void)
|
||||
c.feature |= cpu_to_le32(F2FS_FEATURE_CASEFOLD);
|
||||
#endif
|
||||
#ifdef CONF_PROJID
|
||||
c.feature |= cpu_to_le32(F2FS_FEATURE_QUOTA_INO);
|
||||
c.feature |= cpu_to_le32(F2FS_FEATURE_PRJQUOTA);
|
||||
c.feature |= cpu_to_le32(F2FS_FEATURE_EXTRA_ATTR);
|
||||
#endif
|
||||
|
||||
if (c.feature & cpu_to_le32(F2FS_FEATURE_QUOTA_INO))
|
||||
c.quota_bits = QUOTA_USR_BIT | QUOTA_GRP_BIT;
|
||||
if (c.feature & cpu_to_le32(F2FS_FEATURE_PRJQUOTA)) {
|
||||
c.feature |= cpu_to_le32(F2FS_FEATURE_QUOTA_INO);
|
||||
c.quota_bits |= QUOTA_PRJ_BIT;
|
||||
}
|
||||
}
|
||||
|
||||
static void f2fs_parse_options(int argc, char *argv[])
|
||||
|
Loading…
Reference in New Issue
Block a user