ext4l: Add stubs from various other linux headers

Add stub headers for various Linux kernel interfaces that ext4 code
expects:

- sched.h: scheduler stubs (task_struct, cond_resched, yield)
- wait.h: wait queue stubs
- rwsem.h: read-write semaphore stubs
- percpu_counter.h: percpu counter implementation (single-threaded)
- random.h: random number stubs
- quotaops.h: disk quota operation stubs
- part_stat.h: partition statistics stubs
- prefetch.h: prefetch operation stubs
- sort.h: sort wrapper using stdlib qsort
- swap.h: swap/memory management stubs

Update compat.h to include new headers and remove duplicate
definitions.

Co-developed-by: Claude Opus 4.5 <noreply@anthropic.com>
Signed-off-by: Simon Glass <simon.glass@canonical.com>

Series-to: concept
Cover-letter:
ext4l: Add Linux compatibility headers
This series extracts Linux kernel compatibility declarations from
include/linux/compat.h into their own header files, matching the
Linux kernel's organization. This makes it easier to port Linux
filesystem code to U-Boot and keeps the compatibility layer
maintainable.

The headers come from Linux v6.18

Headers added:
- export.h: EXPORT_SYMBOL macros
- stddef.h: sizeof_field() macro
- uaccess.h: copy_to/from_user stubs
- capability.h, cred.h, file.h, path.h, security.h, seq_file.h
- freezer.h: process freezer stubs
- slab.h, vmalloc.h: memory allocation
- module.h: kernel module stubs
- init.h: initcall macros
- kthread.h: kernel thread stubs
- timer.h, workqueue.h: timer and workqueue stubs
- sched.h, wait.h, rwsem.h: scheduler and synchronization
- percpu_counter.h, random.h, quotaops.h, part_stat.h, prefetch.h,
  sort.h, swap.h

All headers include appropriate copyright/author information from
the original Linux sources.
END
Series-links: 1:77
Series-version: 2

Signed-off-by: Simon Glass <simon.glass@canonical.com>
This commit is contained in:
Simon Glass
2025-12-16 13:43:56 -07:00
committed by Simon Glass
parent 205d4bc100
commit 5029b8c91b
12 changed files with 305 additions and 40 deletions

View File

@@ -11,16 +11,21 @@
#include <linux/types.h>
#include <linux/err.h>
#include <linux/cred.h>
#include <linux/export.h>
#include <linux/freezer.h>
#include <linux/init.h>
#include <linux/kernel.h>
#include <linux/kthread.h>
#include <linux/module.h>
#include <linux/random.h>
#include <linux/rwsem.h>
#include <linux/sched.h>
#include <linux/slab.h>
#include <linux/timer.h>
#include <linux/uaccess.h>
#include <linux/vmalloc.h>
#include <linux/wait.h>
#include <linux/workqueue.h>
#ifdef CONFIG_XEN
@@ -30,16 +35,6 @@
struct unused {};
typedef struct unused unused_t;
struct p_current{
int pid;
};
extern struct p_current *current;
#define DECLARE_WAITQUEUE(...) do { } while (0)
#define add_wait_queue(...) do { } while (0)
#define remove_wait_queue(...) do { } while (0)
#ifndef CONFIG_XEN
#define eventchn_poll()
#endif
@@ -93,8 +88,6 @@ extern struct p_current *current;
#define PAGE_SIZE 4096
#endif
/* drivers/char/random.c */
#define get_random_bytes(...)
/* include/linux/leds.h */
struct led_trigger {};
@@ -158,16 +151,12 @@ typedef unsigned long blkcnt_t;
#define volume_sysfs_init(...) 0
#define volume_sysfs_close(...) do { } while (0)
#define init_waitqueue_head(...) do { } while (0)
#define wait_event_interruptible(...) 0
#define wake_up_interruptible(...) do { } while (0)
#define dump_stack(...) do { } while (0)
typedef unused_t spinlock_t;
typedef int wait_queue_head_t;
#define spin_lock_init(lock) do {} while (0)
#define spin_lock(lock) do {} while (0)
@@ -180,23 +169,9 @@ typedef int wait_queue_head_t;
#define mutex_lock(...)
#define mutex_unlock(...)
#define init_rwsem(...) do { } while (0)
#define down_read(...) do { } while (0)
#define down_write(...) do { } while (0)
#define down_write_trylock(...) 1
#define up_read(...) do { } while (0)
#define up_write(...) do { } while (0)
#define cond_resched() do { } while (0)
#define yield() do { } while (0)
struct rw_semaphore { int i; };
#define down_write(...) do { } while (0)
#define up_write(...) do { } while (0)
#define down_read(...) do { } while (0)
#define up_read(...) do { } while (0)
struct device {
struct device *parent;
struct class *class;
@@ -217,15 +192,7 @@ struct cdev {
#define cdev_add(...) 0
#define cdev_del(...) do { } while (0)
#define prandom_u32(...) 0
typedef struct {
uid_t val;
} kuid_t;
typedef struct {
gid_t val;
} kgid_t;
/* from include/linux/types.h */

16
include/linux/part_stat.h Normal file
View File

@@ -0,0 +1,16 @@
/* SPDX-License-Identifier: GPL-2.0 */
/*
* Stub definitions for partition statistics.
* U-Boot doesn't track I/O statistics.
*/
#ifndef _LINUX_PART_STAT_H
#define _LINUX_PART_STAT_H
#define STAT_READ 0
#define STAT_WRITE 1
#define part_stat_read(bdev, field) 0
#define part_stat_inc(bdev, field) do { } while (0)
#define part_stat_add(bdev, field, val) do { } while (0)
#endif /* _LINUX_PART_STAT_H */

View File

@@ -0,0 +1,80 @@
/* SPDX-License-Identifier: GPL-2.0 */
/*
* A simple "approximate counter" for use in ext2 and ext3 superblocks.
*
* WARNING: these things are HUGE. 4 kbytes per counter on 32-way P4.
*
* Stub definitions for percpu counters.
* U-Boot is single-threaded, use simple counters.
*/
#ifndef _LINUX_PERCPU_COUNTER_H
#define _LINUX_PERCPU_COUNTER_H
#include <linux/types.h>
struct percpu_counter {
s64 count;
};
static inline int percpu_counter_init(struct percpu_counter *fbc, s64 amount,
gfp_t gfp)
{
fbc->count = amount;
return 0;
}
static inline void percpu_counter_destroy(struct percpu_counter *fbc)
{
}
static inline void percpu_counter_set(struct percpu_counter *fbc, s64 amount)
{
fbc->count = amount;
}
static inline void percpu_counter_add(struct percpu_counter *fbc, s64 amount)
{
fbc->count += amount;
}
static inline void percpu_counter_sub(struct percpu_counter *fbc, s64 amount)
{
fbc->count -= amount;
}
static inline void percpu_counter_inc(struct percpu_counter *fbc)
{
fbc->count++;
}
static inline void percpu_counter_dec(struct percpu_counter *fbc)
{
fbc->count--;
}
static inline s64 percpu_counter_read(struct percpu_counter *fbc)
{
return fbc->count;
}
static inline s64 percpu_counter_read_positive(struct percpu_counter *fbc)
{
return fbc->count > 0 ? fbc->count : 0;
}
static inline s64 percpu_counter_sum(struct percpu_counter *fbc)
{
return fbc->count;
}
static inline s64 percpu_counter_sum_positive(struct percpu_counter *fbc)
{
return fbc->count > 0 ? fbc->count : 0;
}
static inline bool percpu_counter_initialized(struct percpu_counter *fbc)
{
return true;
}
#endif /* _LINUX_PERCPU_COUNTER_H */

17
include/linux/prefetch.h Normal file
View File

@@ -0,0 +1,17 @@
/* SPDX-License-Identifier: GPL-2.0 */
/*
* Generic cache management functions. Everything is arch-specific,
* but this header exists to make sure the defines/functions can be
* used in a generic way.
*
* 2000-11-13 Arjan van de Ven <arjan@fenrus.demon.nl>
*
* Stub definitions for prefetch operations.
*/
#ifndef _LINUX_PREFETCH_H
#define _LINUX_PREFETCH_H
#define prefetch(x) do { } while (0)
#define prefetchw(x) do { } while (0)
#endif /* _LINUX_PREFETCH_H */

38
include/linux/quotaops.h Normal file
View File

@@ -0,0 +1,38 @@
/* SPDX-License-Identifier: GPL-2.0 */
/*
* Definitions for diskquota-operations. When diskquota is configured these
* macros expand to the right source-code.
*
* Author: Marco van Wieringen <mvw@planets.elm.net>
*
* Stub definitions for quota operations.
* U-Boot doesn't support disk quotas.
*/
#ifndef _LINUX_QUOTAOPS_H
#define _LINUX_QUOTAOPS_H
struct inode;
struct dentry;
struct kqid;
#define dquot_initialize(inode) 0
#define dquot_drop(inode) do { } while (0)
#define dquot_alloc_inode(inode) 0
#define dquot_free_inode(inode) do { } while (0)
#define dquot_transfer(inode, attr) 0
#define dquot_claim_space_nodirty(inode, nr) 0
#define dquot_reclaim_space_nodirty(inode, nr) do { } while (0)
#define dquot_disable(sb, type, flags) 0
#define dquot_suspend(sb, type) 0
#define dquot_resume(sb, type) 0
#define dquot_file_open(inode, file) 0
#define sb_has_quota_usage_enabled(sb, type) 0
#define sb_has_quota_limits_enabled(sb, type) 0
#define sb_has_quota_suspended(sb, type) 0
#define sb_has_quota_loaded(sb, type) 0
#define sb_has_quota_active(sb, type) 0
#define sb_any_quota_loaded(sb) 0
#define sb_any_quota_active(sb) 0
#endif /* _LINUX_QUOTAOPS_H */

15
include/linux/random.h Normal file
View File

@@ -0,0 +1,15 @@
/* SPDX-License-Identifier: GPL-2.0 */
/*
* Stub definitions for random number generation.
*/
#ifndef _LINUX_RANDOM_H
#define _LINUX_RANDOM_H
#include <linux/types.h>
#define get_random_bytes(buf, len) do { } while (0)
#define prandom_u32() 0
#define get_random_u32() 0
#define get_random_u64() 0ULL
#endif /* _LINUX_RANDOM_H */

28
include/linux/rwsem.h Normal file
View File

@@ -0,0 +1,28 @@
/* SPDX-License-Identifier: GPL-2.0 */
/* rwsem.h: R/W semaphores, public interface
*
* Written by David Howells (dhowells@redhat.com).
* Derived from asm-i386/semaphore.h
*
* Stub definitions for Linux kernel read-write semaphores.
* U-Boot is single-threaded, no locking needed.
*/
#ifndef _LINUX_RWSEM_H
#define _LINUX_RWSEM_H
struct rw_semaphore {
int count;
};
#define DECLARE_RWSEM(name) struct rw_semaphore name = { 0 }
#define init_rwsem(sem) do { } while (0)
#define down_read(sem) do { } while (0)
#define down_read_trylock(sem) 1
#define up_read(sem) do { } while (0)
#define down_write(sem) do { } while (0)
#define down_write_trylock(sem) 1
#define up_write(sem) do { } while (0)
#define downgrade_write(sem) do { } while (0)
#endif /* _LINUX_RWSEM_H */

36
include/linux/sched.h Normal file
View File

@@ -0,0 +1,36 @@
/* SPDX-License-Identifier: GPL-2.0 */
/*
* Define 'struct task_struct' and provide the main scheduler
* APIs (schedule(), wakeup variants, etc.)
*
* Stub definitions for Linux kernel scheduler.
* U-Boot is single-threaded.
*/
#ifndef _LINUX_SCHED_H
#define _LINUX_SCHED_H
#include <linux/types.h>
struct task_struct {
int pid;
char comm[16];
};
extern struct task_struct *current;
#define TASK_RUNNING 0
#define TASK_INTERRUPTIBLE 1
#define TASK_UNINTERRUPTIBLE 2
#define cond_resched() do { } while (0)
#define yield() do { } while (0)
/* Note: schedule() is implemented in common/cyclic.c */
#define in_interrupt() 0
#define in_atomic() 0
#define in_task() 1
#define signal_pending(task) 0
#define fatal_signal_pending(task) 0
#endif /* _LINUX_SCHED_H */

19
include/linux/sort.h Normal file
View File

@@ -0,0 +1,19 @@
/* SPDX-License-Identifier: GPL-2.0 */
/*
* Sorting functions - use stdlib qsort.
*/
#ifndef _LINUX_SORT_H
#define _LINUX_SORT_H
#include <linux/types.h>
#include <stdlib.h>
typedef int (*cmp_func_t)(const void *, const void *);
static inline void sort(void *base, size_t num, size_t size,
cmp_func_t cmp, void *swap)
{
qsort(base, num, size, cmp);
}
#endif /* _LINUX_SORT_H */

18
include/linux/swap.h Normal file
View File

@@ -0,0 +1,18 @@
/* SPDX-License-Identifier: GPL-2.0 */
/*
* Stub definitions for swap/memory management.
* U-Boot doesn't use swap.
*/
#ifndef _LINUX_SWAP_H
#define _LINUX_SWAP_H
#define mark_page_accessed(page) do { } while (0)
struct address_space;
struct folio;
static inline void folio_mark_accessed(struct folio *folio)
{
}
#endif /* _LINUX_SWAP_H */

31
include/linux/wait.h Normal file
View File

@@ -0,0 +1,31 @@
/* SPDX-License-Identifier: GPL-2.0 */
/*
* Linux wait queue related types and methods
*
* Stub definitions for Linux kernel wait queues.
* U-Boot doesn't use wait queues.
*/
#ifndef _LINUX_WAIT_H
#define _LINUX_WAIT_H
typedef int wait_queue_head_t;
struct wait_queue_entry {
int dummy;
};
#define DECLARE_WAITQUEUE(name, task) do { } while (0)
#define DECLARE_WAIT_QUEUE_HEAD(name) do { } while (0)
#define init_waitqueue_head(wq) do { } while (0)
#define add_wait_queue(wq, entry) do { } while (0)
#define remove_wait_queue(wq, entry) do { } while (0)
#define wake_up(wq) do { } while (0)
#define wake_up_all(wq) do { } while (0)
#define wake_up_interruptible(wq) do { } while (0)
#define wake_up_interruptible_all(wq) do { } while (0)
#define wait_event(wq, condition) do { } while (0)
#define wait_event_interruptible(wq, condition) 0
#endif /* _LINUX_WAIT_H */

View File

@@ -5,10 +5,10 @@
#include <asm/cache.h>
#include <linux/compat.h>
struct p_current cur = {
struct task_struct cur = {
.pid = 1,
};
__maybe_unused struct p_current *current = &cur;
__maybe_unused struct task_struct *current = &cur;
void *kmalloc(size_t size, gfp_t flags)
{