Hi Weichao, On Wed, Jul 12, 2023 at 06:23:31PM +0800, Weichao Guo via Linux-f2fs-devel wrote: > Signed-off-by: Weichao Guo <[email protected]> > Signed-off-by: Sheng Yong <[email protected]> > --- > fsck/mount.c | 44 +++++++++++++++++++++++++++--------------- > fsck/xattr.h | 54 +++++++++++++++++++++++++++++++++++++++++++--------- > 2 files changed, 74 insertions(+), 24 deletions(-) > > diff --git a/fsck/mount.c b/fsck/mount.c > index 397feb5..b9696c4 100644 > --- a/fsck/mount.c > +++ b/fsck/mount.c > @@ -196,7 +196,7 @@ static void print_xattr_entry(const struct > f2fs_xattr_entry *ent) > { > const u8 *value = (const u8 *)&ent->e_name[ent->e_name_len]; > const int size = le16_to_cpu(ent->e_value_size); > - const struct fscrypt_context *ctx; > + const union fscrypt_context *ctx; > int i; > > MSG(0, "\nxattr: e_name_index:%d e_name:", ent->e_name_index); > @@ -213,21 +213,35 @@ static void print_xattr_entry(const struct > f2fs_xattr_entry *ent) > return; > #endif > case F2FS_XATTR_INDEX_ENCRYPTION: > - ctx = (const struct fscrypt_context *)value; > - if (size != sizeof(*ctx) || > - ctx->format != FS_ENCRYPTION_CONTEXT_FORMAT_V1) > + ctx = (const union fscrypt_context *)value; > + if (size != fscrypt_context_size(ctx)) > break; > - MSG(0, "format: %d\n", ctx->format); > - MSG(0, "contents_encryption_mode: 0x%x\n", > ctx->contents_encryption_mode); > - MSG(0, "filenames_encryption_mode: 0x%x\n", > ctx->filenames_encryption_mode); > - MSG(0, "flags: 0x%x\n", ctx->flags); > - MSG(0, "master_key_descriptor: "); > - for (i = 0; i < FS_KEY_DESCRIPTOR_SIZE; i++) > - MSG(0, "%02X", ctx->master_key_descriptor[i]); > - MSG(0, "\nnonce: "); > - for (i = 0; i < FS_KEY_DERIVATION_NONCE_SIZE; i++) > - MSG(0, "%02X", ctx->nonce[i]); > - MSG(0, "\n"); > + switch (ctx->version) { > + case FSCRYPT_CONTEXT_V1: > + MSG(0, "format: %d\n", ctx->version); > + MSG(0, "contents_encryption_mode: 0x%x\n", > ctx->v1.contents_encryption_mode); > + MSG(0, "filenames_encryption_mode: 0x%x\n", > ctx->v1.filenames_encryption_mode); > + MSG(0, "flags: 0x%x\n", ctx->v1.flags); > + MSG(0, "master_key_descriptor: "); > + for (i = 0; i < FSCRYPT_KEY_DESCRIPTOR_SIZE; i++) > + MSG(0, "%02X", > ctx->v1.master_key_descriptor[i]); > + MSG(0, "\nnonce: "); > + for (i = 0; i < FSCRYPT_FILE_NONCE_SIZE; i++) > + MSG(0, "%02X", ctx->v1.nonce[i]); > + MSG(0, "\n"); > + case FSCRYPT_CONTEXT_V2: > + MSG(0, "format: %d\n", ctx->version); > + MSG(0, "contents_encryption_mode: 0x%x\n", > ctx->v2.contents_encryption_mode); > + MSG(0, "filenames_encryption_mode: 0x%x\n", > ctx->v2.filenames_encryption_mode); > + MSG(0, "flags: 0x%x\n", ctx->v2.flags); > + MSG(0, "master_key_identifier: "); > + for (i = 0; i < FSCRYPT_KEY_IDENTIFIER_SIZE; i++) > + MSG(0, "%02X", > ctx->v2.master_key_identifier[i]); > + MSG(0, "\nnonce: "); > + for (i = 0; i < FSCRYPT_FILE_NONCE_SIZE; i++) > + MSG(0, "%02X", ctx->v2.nonce[i]); > + MSG(0, "\n"); > + } > return;
The FSCRYPT_CONTEXT_V1 case is falling through to FSCRYPT_CONTEXT_V2. Also, this patch makes the values of encryption xattrs with unknown versions no longer be shown. To fix this, there needs to be a return at end of each case (v1 and v2), and the return after the switch statement needs to be a break. - Eric _______________________________________________ Linux-f2fs-devel mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
