From: Simon Glass <simon.glass@canonical.com> Create a dedicated header file for filesystem encryption (fscrypt) stubs that are scattered throughout ext4_uboot.h In Linux, fscrypt provides filesystem-level encryption, but U-Boot does not support this feature. The new ext4_fscrypt.h contains: - Structure definitions (qstr, fscrypt_str, fscrypt_dummy_policy, fscrypt_name) - Inline functions (fscrypt_has_encryption_key, fscrypt_fname_siphash, fscrypt_match_name) - Operation stubs for encryption, directory operations, symlinks - Page I/O and readpage stubs - Function declarations for stub.c implementations This reduces ext4_uboot.h by ~90 lines and makes the fscrypt interface more maintainable by keeping all encryption-related stubs in one place. Co-developed-by: Claude Opus 4.5 <noreply@anthropic.com> Signed-off-by: Simon Glass <simon.glass@canonical.com> --- fs/ext4l/ext4_fscrypt.h | 144 ++++++++++++++++++++++++++++++++++++++++ fs/ext4l/ext4_uboot.h | 120 +++++---------------------------- 2 files changed, 160 insertions(+), 104 deletions(-) create mode 100644 fs/ext4l/ext4_fscrypt.h diff --git a/fs/ext4l/ext4_fscrypt.h b/fs/ext4l/ext4_fscrypt.h new file mode 100644 index 00000000000..da91af74343 --- /dev/null +++ b/fs/ext4l/ext4_fscrypt.h @@ -0,0 +1,144 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* + * fscrypt stubs for U-Boot ext4l + * + * In Linux, fscrypt provides filesystem-level encryption. In U-Boot, + * encryption is not supported, so all fscrypt operations are stubbed out. + */ + +#ifndef _EXT4_FSCRYPT_H +#define _EXT4_FSCRYPT_H + +#include <linux/types.h> +#include <linux/errno.h> +#include <linux/err.h> +#include <linux/string.h> + +/* Forward declarations */ +struct inode; +struct seq_file; +struct page; +struct folio; +struct bio; +struct buffer_head; +struct dentry; +struct super_block; + +/* qstr - quick string for filenames (needed by fscrypt_name) */ +struct qstr { + u32 hash; + u32 len; + const unsigned char *name; +}; + +/* fscrypt_str - encrypted filename string */ +struct fscrypt_str { + unsigned char *name; + u32 len; +}; + +/* fscrypt_dummy_policy - stub */ +struct fscrypt_dummy_policy { + int dummy; +}; + +/* fscrypt_name - stub structure for encrypted filenames */ +struct fscrypt_name { + const struct qstr *usr_fname; + struct fscrypt_str disk_name; + u32 hash; + u32 minor_hash; + bool is_nokey_name; +}; + +/* fscrypt context size */ +#define FSCRYPT_SET_CONTEXT_MAX_SIZE 40 + +/* IS_ENCRYPTED - always false in U-Boot */ +#define IS_ENCRYPTED(inode) (0) + +/* fscrypt inline functions */ +static inline bool fscrypt_has_encryption_key(const struct inode *inode) +{ + return false; +} + +static inline u64 fscrypt_fname_siphash(const struct inode *dir, + const struct qstr *name) +{ + return 0; +} + +static inline int fscrypt_match_name(const struct fscrypt_name *fname, + const u8 *de_name, u32 de_name_len) +{ + if (fname->usr_fname->len != de_name_len) + return 0; + + return !memcmp(fname->usr_fname->name, de_name, de_name_len); +} + +/* fscrypt operation stubs */ +#define fscrypt_prepare_new_inode(dir, i, e) ({ (void)(dir); (void)(i); (void)(e); 0; }) +#define fscrypt_set_context(inode, handle) ({ (void)(inode); (void)(handle); 0; }) +#define fscrypt_file_open(i, f) ({ (void)(i); (void)(f); 0; }) +#define fscrypt_inode_uses_fs_layer_crypto(i) (0) +#define fscrypt_decrypt_pagecache_blocks(f, l, o) ({ (void)(f); (void)(l); (void)(o); 0; }) +#define fscrypt_encrypt_pagecache_blocks(f, l, o, g) \ + ({ (void)(f); (void)(l); (void)(o); (void)(g); (struct page *)NULL; }) +#define fscrypt_zeroout_range(i, lb, pb, l) ({ (void)(i); (void)(lb); (void)(pb); (void)(l); 0; }) +#define fscrypt_limit_io_blocks(i, lb, l) (l) +#define fscrypt_prepare_setattr(d, a) ({ (void)(d); (void)(a); 0; }) +#define fscrypt_dio_supported(i) (1) +#define fscrypt_has_permitted_context(p, c) ({ (void)(p); (void)(c); 1; }) +#define fscrypt_is_nokey_name(d) ({ (void)(d); 0; }) +#define fscrypt_prepare_symlink(d, s, l, m, dl) \ + ({ (void)(d); (void)(m); (dl)->name = (unsigned char *)(s); (dl)->len = (l) + 1; 0; }) +#define fscrypt_encrypt_symlink(i, s, l, d) ({ (void)(i); (void)(s); (void)(l); (void)(d); 0; }) +#define fscrypt_prepare_link(o, d, n) ({ (void)(o); (void)(d); (void)(n); 0; }) +#define fscrypt_prepare_rename(od, ode, nd, nde, f) \ + ({ (void)(od); (void)(ode); (void)(nd); (void)(nde); (void)(f); 0; }) + +/* fscrypt directory operations */ +#define fscrypt_prepare_readdir(i) ({ (void)(i); 0; }) +#define fscrypt_fname_alloc_buffer(len, buf) ({ (void)(len); (void)(buf); 0; }) +#define fscrypt_fname_free_buffer(buf) do { (void)(buf); } while (0) +#define fscrypt_fname_disk_to_usr(i, h1, h2, d, u) \ + ({ (void)(i); (void)(h1); (void)(h2); (void)(d); (void)(u); 0; }) + +/* fscrypt symlink stubs */ +#define fscrypt_get_symlink(i, c, m, d) ({ (void)(i); (void)(c); (void)(m); (void)(d); ERR_PTR(-EOPNOTSUPP); }) +#define fscrypt_symlink_getattr(p, s) ({ (void)(p); (void)(s); 0; }) + +/* fscrypt inode operations */ +#define fscrypt_put_encryption_info(i) do { } while (0) +#define fscrypt_parse_test_dummy_encryption(p, d) ({ (void)(p); (void)(d); 0; }) + +/* fscrypt page-io stubs */ +#define fscrypt_is_bounce_folio(f) ({ (void)(f); 0; }) +#define fscrypt_pagecache_folio(f) (f) +#define fscrypt_free_bounce_page(p) do { (void)(p); } while (0) +#define fscrypt_set_bio_crypt_ctx_bh(bio, bh, gfp) \ + do { (void)(bio); (void)(bh); (void)(gfp); } while (0) +#define fscrypt_mergeable_bio_bh(bio, bh) \ + ({ (void)(bio); (void)(bh); true; }) + +/* fscrypt readpage stubs */ +#define fscrypt_decrypt_bio(bio) ({ (void)(bio); 0; }) +#define fscrypt_enqueue_decrypt_work(work) do { (void)(work); } while (0) +#define fscrypt_mergeable_bio(bio, inode, blk) \ + ({ (void)(bio); (void)(inode); (void)(blk); true; }) +#define fscrypt_set_bio_crypt_ctx(bio, inode, blk, gfp) \ + do { (void)(bio); (void)(inode); (void)(blk); (void)(gfp); } while (0) + +/* fscrypt function declarations (implemented in stub.c) */ +void fscrypt_free_dummy_policy(struct fscrypt_dummy_policy *policy); +int fscrypt_drop_inode(struct inode *inode); +void fscrypt_free_inode(struct inode *inode); +int fscrypt_is_dummy_policy_set(const struct fscrypt_dummy_policy *policy); +int fscrypt_dummy_policies_equal(const struct fscrypt_dummy_policy *p1, + const struct fscrypt_dummy_policy *p2); +void fscrypt_show_test_dummy_encryption(struct seq_file *seq, char sep, + struct super_block *sb); + +#endif /* _EXT4_FSCRYPT_H */ diff --git a/fs/ext4l/ext4_uboot.h b/fs/ext4l/ext4_uboot.h index 2ffa8ab271b..c6795b35501 100644 --- a/fs/ext4l/ext4_uboot.h +++ b/fs/ext4l/ext4_uboot.h @@ -41,6 +41,7 @@ #include <linux/time.h> /* For timespec64, time64_t */ #include <u-boot/crc.h> /* For crc32() used by crc32_be */ #include "ext4_trace.h" /* Trace event stubs */ +#include "ext4_fscrypt.h" /* fscrypt stubs */ /* * __CHAR_UNSIGNED__ - directory hash algorithm selection @@ -259,11 +260,7 @@ struct fiemap_extent_info { #define CAP_SYS_RESOURCE 0 #define capable(cap) (1) -/* fscrypt_str - stub */ -struct fscrypt_str { - unsigned char *name; - u32 len; -}; +/* fscrypt_str, qstr are now in ext4_fscrypt.h */ /* percpu rw semaphore - stubs */ struct percpu_rw_semaphore { @@ -281,12 +278,9 @@ static inline void memalloc_nofs_restore(unsigned int flags) { } /* Inode flags - stubs */ #define IS_CASEFOLDED(inode) (0) -#define IS_ENCRYPTED(inode) (0) +/* IS_ENCRYPTED and FSCRYPT_SET_CONTEXT_MAX_SIZE are in ext4_fscrypt.h */ #define S_NOQUOTA 0 -/* fscrypt context - stub */ -#define FSCRYPT_SET_CONTEXT_MAX_SIZE 40 - /* User namespace - stub */ struct user_namespace { int dummy; @@ -389,9 +383,7 @@ extern struct inode *new_inode(struct super_block *sb); #define clear_nlink(inode) do { } while (0) #define IS_DIRSYNC(inode) ({ (void)(inode); 0; }) -/* fscrypt stubs */ -#define fscrypt_prepare_new_inode(dir, i, e) ({ (void)(dir); (void)(i); (void)(e); 0; }) -#define fscrypt_set_context(inode, handle) ({ (void)(inode); (void)(handle); 0; }) +/* fscrypt_prepare_new_inode, fscrypt_set_context are in ext4_fscrypt.h */ /* ext4_init_acl is provided by acl.h */ /* xattr stubs for files that don't include xattr.h */ @@ -517,10 +509,7 @@ struct ratelimit_state { int dummy; }; -/* fscrypt_dummy_policy - stub */ -struct fscrypt_dummy_policy { - int dummy; -}; +/* fscrypt_dummy_policy and qstr are now in ext4_fscrypt.h */ /* errseq_t is defined in linux/fs.h */ /* time64_t is now in linux/time.h */ @@ -528,12 +517,6 @@ struct fscrypt_dummy_policy { /* IS_NOQUOTA - stub */ #define IS_NOQUOTA(inode) (0) -/* qstr - quick string for filenames (must be before dentry) */ -struct qstr { - const unsigned char *name; - unsigned int len; -}; - /* dentry - stub */ struct dentry { struct qstr d_name; @@ -981,17 +964,7 @@ struct dx_hash_info { /* seq_file - forward declaration */ struct seq_file; -/* fscrypt stubs - encryption not supported in U-Boot */ -static inline bool fscrypt_has_encryption_key(const struct inode *inode) -{ - return false; -} - -static inline u64 fscrypt_fname_siphash(const struct inode *dir, - const struct qstr *name) -{ - return 0; -} +/* fscrypt_has_encryption_key, fscrypt_fname_siphash are in ext4_fscrypt.h */ /* ext4 warning macros - stubs (only when ext4.h is not included) */ #ifdef EXT4_UBOOT_NO_EXT4_H @@ -1450,8 +1423,7 @@ static inline char *d_path(const struct path *path, char *buf, int buflen) return buf; } -/* fscrypt/fsverity stubs */ -#define fscrypt_file_open(i, f) ({ (void)(i); (void)(f); 0; }) +/* fscrypt_file_open is in ext4_fscrypt.h */ #define fsverity_file_open(i, f) ({ (void)(i); (void)(f); 0; }) /* Quota file open - stub */ @@ -1541,38 +1513,7 @@ static inline char *d_path(const struct path *path, char *buf, int buflen) #define map_bh(bh, sb, block) do { } while (0) #define write_begin_get_folio(iocb, m, idx, l) ({ (void)(iocb); (void)(m); (void)(idx); (void)(l); (struct folio *)NULL; }) -/* fscrypt stubs - additional */ -#define fscrypt_inode_uses_fs_layer_crypto(i) (0) -#define fscrypt_decrypt_pagecache_blocks(f, l, o) ({ (void)(f); (void)(l); (void)(o); 0; }) -#define fscrypt_encrypt_pagecache_blocks(f, l, o, g) ({ (void)(f); (void)(l); (void)(o); (void)(g); (struct page *)NULL; }) -#define fscrypt_zeroout_range(i, lb, pb, l) ({ (void)(i); (void)(lb); (void)(pb); (void)(l); 0; }) -#define fscrypt_limit_io_blocks(i, lb, l) (l) -#define fscrypt_prepare_setattr(d, a) ({ (void)(d); (void)(a); 0; }) -#define fscrypt_dio_supported(i) (1) -#define fscrypt_has_permitted_context(p, c) ({ (void)(p); (void)(c); 1; }) -#define fscrypt_is_nokey_name(d) ({ (void)(d); 0; }) -#define fscrypt_prepare_symlink(d, s, l, m, dl) ({ (void)(d); (void)(m); (dl)->name = (unsigned char *)(s); (dl)->len = (l) + 1; 0; }) -#define fscrypt_encrypt_symlink(i, s, l, d) ({ (void)(i); (void)(s); (void)(l); (void)(d); 0; }) -#define fscrypt_prepare_link(o, d, n) ({ (void)(o); (void)(d); (void)(n); 0; }) -#define fscrypt_prepare_rename(od, ode, nd, nde, f) ({ (void)(od); (void)(ode); (void)(nd); (void)(nde); (void)(f); 0; }) - -/* fscrypt_name - stub structure for encrypted filenames */ -struct fscrypt_name { - const struct qstr *usr_fname; - struct fscrypt_str disk_name; - u32 hash; - u32 minor_hash; - bool is_nokey_name; -}; - -static inline int fscrypt_match_name(const struct fscrypt_name *fname, - const u8 *de_name, u32 de_name_len) -{ - if (fname->usr_fname->len != de_name_len) - return 0; - - return !memcmp(fname->usr_fname->name, de_name, de_name_len); -} +/* fscrypt_name, fscrypt_match_name, and fscrypt stubs are in ext4_fscrypt.h */ /* fsverity stubs */ #define fsverity_prepare_setattr(d, a) ({ (void)(d); (void)(a); 0; }) @@ -1688,14 +1629,10 @@ extern struct inode *iget_locked(struct super_block *sb, unsigned long ino); * Additional stubs for dir.c */ -/* fscrypt_str - encrypted filename string */ +/* FSTR_INIT - fscrypt_str initializer (fscrypt_str defined in ext4_fscrypt.h) */ #define FSTR_INIT(n, l) { .name = (n), .len = (l) } -/* fscrypt directory operations */ -#define fscrypt_prepare_readdir(i) ({ (void)(i); 0; }) -#define fscrypt_fname_alloc_buffer(len, buf) ({ (void)(len); (void)(buf); 0; }) -#define fscrypt_fname_free_buffer(buf) do { (void)(buf); } while (0) -#define fscrypt_fname_disk_to_usr(i, h1, h2, d, u) ({ (void)(i); (void)(h1); (void)(h2); (void)(d); (void)(u); 0; }) +/* fscrypt directory operations are in ext4_fscrypt.h */ /* Readahead operations */ #define ra_has_index(ra, idx) ({ (void)(ra); (void)(idx); 0; }) @@ -1801,9 +1738,7 @@ static inline const char *simple_get_link(struct dentry *dentry, return inode->i_link; } -/* fscrypt symlink stubs */ -#define fscrypt_get_symlink(i, c, m, d) ({ (void)(i); (void)(c); (void)(m); (void)(d); ERR_PTR(-EOPNOTSUPP); }) -#define fscrypt_symlink_getattr(p, s) ({ (void)(p); (void)(s); 0; }) +/* fscrypt symlink stubs are in ext4_fscrypt.h */ /* * Additional stubs for super.c @@ -2215,10 +2150,7 @@ void wait_for_completion(struct completion *comp); /* DAX - declaration for stub.c */ void fs_put_dax(void *dax, void *holder); -/* fscrypt - declarations for stub.c */ -void fscrypt_free_dummy_policy(struct fscrypt_dummy_policy *policy); -int fscrypt_drop_inode(struct inode *inode); -void fscrypt_free_inode(struct inode *inode); +/* fscrypt declarations are in ext4_fscrypt.h */ /* Inode allocation - declaration for stub.c */ void *alloc_inode_sb(struct super_block *sb, struct kmem_cache *cache, @@ -2236,10 +2168,8 @@ int inode_generic_drop(struct inode *inode); #define invalidate_inode_buffers(i) do { } while (0) #define clear_inode(i) do { } while (0) -/* fscrypt/fsverity additional stubs */ -#define fscrypt_put_encryption_info(i) do { } while (0) +/* fsverity stubs (fscrypt macros are in ext4_fscrypt.h) */ #define fsverity_cleanup_inode(i) do { } while (0) -#define fscrypt_parse_test_dummy_encryption(p, d) ({ (void)(p); (void)(d); 0; }) /* NFS export helpers - declarations for stub.c */ struct dentry *generic_fh_to_dentry(struct super_block *sb, struct fid *fid, @@ -2259,12 +2189,7 @@ int IOPRIO_PRIO_VALUE(int class, int data); char *kmemdup_nul(const char *s, size_t len, gfp_t gfp); #define strscpy_pad(dst, src) strncpy(dst, src, sizeof(dst)) -/* fscrypt/fsverity declarations for stub.c */ -int fscrypt_is_dummy_policy_set(const struct fscrypt_dummy_policy *policy); -int fscrypt_dummy_policies_equal(const struct fscrypt_dummy_policy *p1, - const struct fscrypt_dummy_policy *p2); -void fscrypt_show_test_dummy_encryption(struct seq_file *seq, char sep, - struct super_block *sb); +/* fscrypt declarations are in ext4_fscrypt.h */ /* Memory allocation - declarations for stub.c */ void *kvzalloc(size_t size, gfp_t flags); @@ -2618,14 +2543,7 @@ struct folio_iter { /* GFP_NOIO - allocation without I/O */ #define GFP_NOIO 0 -/* fscrypt stubs for page-io.c */ -#define fscrypt_is_bounce_folio(f) ({ (void)(f); 0; }) -#define fscrypt_pagecache_folio(f) (f) -#define fscrypt_free_bounce_page(p) do { (void)(p); } while (0) -#define fscrypt_set_bio_crypt_ctx_bh(bio, bh, gfp) \ - do { (void)(bio); (void)(bh); (void)(gfp); } while (0) -#define fscrypt_mergeable_bio_bh(bio, bh) \ - ({ (void)(bio); (void)(bh); 1; }) +/* fscrypt page-io stubs are in ext4_fscrypt.h */ /* folio writeback operations */ #define folio_end_writeback(f) do { (void)(f); } while (0) @@ -2657,13 +2575,7 @@ typedef void *mempool_t; #define folio_end_read(f, success) do { (void)(f); (void)(success); } while (0) #define folio_set_mappedtodisk(f) do { (void)(f); } while (0) -/* fscrypt stubs for readpage.c */ -#define fscrypt_decrypt_bio(bio) ({ (void)(bio); 0; }) -#define fscrypt_enqueue_decrypt_work(work) do { (void)(work); } while (0) -#define fscrypt_mergeable_bio(bio, inode, blk) \ - ({ (void)(bio); (void)(inode); (void)(blk); 1; }) -#define fscrypt_set_bio_crypt_ctx(bio, inode, blk, gfp) \ - do { (void)(bio); (void)(inode); (void)(blk); (void)(gfp); } while (0) +/* fscrypt readpage stubs are in ext4_fscrypt.h */ /* fsverity stubs */ #define fsverity_verify_bio(bio) do { (void)(bio); } while (0) -- 2.43.0