@@ -6,4 +6,5 @@
obj-y := interface.o stub.o
obj-y += balloc.o bitmap.o block_validity.o ext4_jbd2.o extents.o \
- extents_status.o hash.o ialloc.o indirect.o
+ extents_status.o hash.o ialloc.o indirect.o \
+ orphan.o
@@ -48,8 +48,24 @@ typedef struct { long counter; } atomic64_t;
#define atomic_read(v) ((v)->counter)
#define atomic_set(v, i) ((v)->counter = (i))
+#define atomic_inc(v) ((v)->counter++)
+#define atomic_dec(v) ((v)->counter--)
#define atomic64_read(v) ((v)->counter)
#define atomic64_set(v, i) ((v)->counter = (i))
+#define atomic_dec_if_positive(v) (--(v)->counter)
+
+/* SMP stubs - U-Boot is single-threaded */
+#define raw_smp_processor_id() 0
+
+/* cmpxchg - compare and exchange, single-threaded version */
+#define cmpxchg(ptr, old, new) ({ \
+ typeof(*(ptr)) __old = (old); \
+ typeof(*(ptr)) __new = (new); \
+ typeof(*(ptr)) __ret = *(ptr); \
+ if (__ret == __old) \
+ *(ptr) = __new; \
+ __ret; \
+})
/* Reference count type */
typedef struct { atomic_t refs; } refcount_t;
@@ -58,10 +74,10 @@ typedef struct { atomic_t refs; } refcount_t;
typedef int rwlock_t;
/* spinlock_t is defined in linux/compat.h */
-#define read_lock(l) do { (void)(l); } while (0)
-#define read_unlock(l) do { (void)(l); } while (0)
-#define write_lock(l) do { (void)(l); } while (0)
-#define write_unlock(l) do { (void)(l); } while (0)
+#define read_lock(l) do { } while (0)
+#define read_unlock(l) do { } while (0)
+#define write_lock(l) do { } while (0)
+#define write_unlock(l) do { } while (0)
/* RB tree types - stubs */
struct rb_node {
@@ -374,7 +390,12 @@ struct qstr;
int __ext4_xattr_set_credits(struct super_block *sb, struct inode *inode,
struct buffer_head *block_bh, size_t value_len,
bool is_create);
-/* ext4_init_security is declared in xattr.h */
+/* ext4_init_security - stub for files that don't include xattr.h */
+static inline int ext4_init_security(void *handle, struct inode *inode,
+ struct inode *dir, const struct qstr *qstr)
+{
+ return 0;
+}
/* inode state stubs */
#define is_bad_inode(inode) (0)
@@ -431,7 +452,7 @@ int __ext4_xattr_set_credits(struct super_block *sb, struct inode *inode,
#define rb_next(node) ((node)->rb_right)
#define rb_prev(node) ((node)->rb_left)
#define rb_insert_color(node, root) do { } while (0)
-#define rb_erase(node, root) do { (void)(node); (void)(root); } while (0)
+#define rb_erase(node, root) do { } while (0)
#define rb_link_node(node, parent, rb_link) do { *(rb_link) = (node); } while (0)
#define RB_EMPTY_ROOT(root) ((root)->rb_node == NULL)
#define rbtree_postorder_for_each_entry_safe(pos, n, root, field) \
@@ -563,6 +584,9 @@ struct fstrim_range {
/* block_device is defined in linux/fs.h */
+/* Superblock flags */
+#define SB_RDONLY (1 << 0)
+
/* super_block - minimal stub */
struct super_block {
void *s_fs_info;
@@ -570,6 +594,7 @@ struct super_block {
unsigned char s_blocksize_bits;
unsigned long s_magic;
loff_t s_maxbytes;
+ unsigned long s_flags;
struct rw_semaphore s_umount;
struct sb_writers s_writers;
struct block_device *s_bdev;
@@ -577,9 +602,19 @@ struct super_block {
struct dentry *s_root;
};
+/* Block device read-only check - stub */
+static inline int bdev_read_only(struct block_device *bdev)
+{
+ return 0;
+}
+
/* kuid_t and kgid_t - from linux/cred.h */
#include <linux/cred.h>
+/* Inode state bits */
+#define I_NEW (1 << 0)
+#define I_FREEING (1 << 1)
+
/* inode - minimal stub */
struct inode {
struct super_block *i_sb;
@@ -594,6 +629,7 @@ struct inode {
unsigned int i_generation;
unsigned int i_flags;
unsigned int i_blkbits;
+ unsigned long i_state;
struct timespec64 i_atime;
struct timespec64 i_mtime;
struct timespec64 i_ctime;
@@ -1741,7 +1741,6 @@ int ext4_seq_es_shrinker_info_show(struct seq_file *seq, void *v)
max->vfs_inode.i_ino, max->i_es_all_nr, max->i_es_shk_nr,
div_u64(es_stats->es_stats_max_scan_time, 1000));
- (void)es_stats; /* Used only by seq_printf which is stubbed */
return 0;
}
@@ -16,7 +16,6 @@
#include "ext4_uboot.h"
#include "ext4.h"
#include "ext4_jbd2.h"
-#include "xattr.h"
/*
* ialloc.c contains the inodes allocation and deallocation routines
@@ -1,10 +1,9 @@
+// SPDX-License-Identifier: GPL-2.0
/*
* Ext4 orphan inode handling
*/
-#include <linux/fs.h>
-#include <linux/quotaops.h>
-#include <linux/buffer_head.h>
+#include "ext4_uboot.h"
#include "ext4.h"
#include "ext4_jbd2.h"
@@ -395,3 +395,40 @@ int ext4_init_security(void *handle, struct inode *inode, struct inode *dir,
{
return 0;
}
+
+/*
+ * Stubs for orphan.c
+ */
+struct ext4_iloc;
+
+int ext4_reserve_inode_write(void *handle, struct inode *inode,
+ struct ext4_iloc *iloc)
+{
+ return 0;
+}
+
+void ext4_superblock_csum_set(struct super_block *sb)
+{
+}
+
+int ext4_mark_iloc_dirty(void *handle, struct inode *inode,
+ struct ext4_iloc *iloc)
+{
+ return 0;
+}
+
+int ext4_truncate(struct inode *inode)
+{
+ return 0;
+}
+
+int ext4_feature_set_ok(struct super_block *sb, int readonly)
+{
+ return 1;
+}
+
+struct buffer_head *ext4_bread(void *handle, struct inode *inode,
+ unsigned long long block, int create)
+{
+ return NULL;
+}
new file mode 100644
@@ -0,0 +1,13 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+#ifndef _KUNIT_STATIC_STUB_H
+#define _KUNIT_STATIC_STUB_H
+
+/*
+ * Stub header for U-Boot ext4l.
+ *
+ * KUnit static stubs are for kernel unit testing - not needed in U-Boot.
+ */
+
+#define KUNIT_STATIC_STUB_REDIRECT(func, args...) do { } while (0)
+
+#endif /* _KUNIT_STATIC_STUB_H */
@@ -12,14 +12,10 @@
#include <linux/types.h>
#include <linux/list.h>
#include <linux/spinlock.h>
-
-/* Simple atomic_inc/dec for U-Boot (single-threaded) */
-#ifndef atomic_inc
-#define atomic_inc(v) ((v)->counter++)
-#endif
-#ifndef atomic_dec
-#define atomic_dec(v) ((v)->counter--)
-#endif
+/*
+ * Note: atomic_t and sector_t are expected to be defined by the including
+ * file (ext4_uboot.h) before including this header.
+ */
enum bh_state_bits {
BH_Uptodate, /* Contains valid data */
new file mode 100644
@@ -0,0 +1,14 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+#ifndef _LINUX_NOSPEC_H
+#define _LINUX_NOSPEC_H
+
+/*
+ * Stub header for U-Boot ext4l.
+ *
+ * array_index_nospec bounds-checks array access, but in U-Boot's
+ * single-user environment this is not necessary.
+ */
+
+#define array_index_nospec(index, size) (index)
+
+#endif /* _LINUX_NOSPEC_H */
@@ -11,9 +11,8 @@ struct seq_file {
void *private;
};
-#define seq_printf(m, fmt, ...) \
- do { (void)(m); (void)(fmt); } while (0)
-#define seq_puts(m, s) do { (void)(m); (void)(s); } while (0)
-#define seq_putc(m, c) do { (void)(m); (void)(c); } while (0)
+#define seq_printf(m, fmt, ...) do { } while (0)
+#define seq_puts(m, s) do { } while (0)
+#define seq_putc(m, c) do { } while (0)
#endif /* _LINUX_SEQ_FILE_H */
@@ -67,6 +67,16 @@ static inline void kfree(const void *block)
free((void *)block);
}
+static inline void kvfree(const void *addr)
+{
+ kfree(addr);
+}
+
+static inline void *kvmalloc_array(size_t n, size_t size, gfp_t flags)
+{
+ return kmalloc_array(n, size, flags);
+}
+
static inline void *krealloc(const void *p, size_t new_size, gfp_t flags)
{
return realloc((void *)p, new_size);