linux: Add buffer_head.h and journal-head.h stubs
Add stub headers for buffer head management: - buffer_head.h: buffer head structure and state management functions (bh_*_bit helpers, BUFFER_FNS/TAS_BUFFER_FNS macros) - journal-head.h: journal buffer head structure for jbd2 These provide minimal interfaces needed for ext4l filesystem compilation in U-Boot. Co-developed-by: Claude Opus 4.5 <noreply@anthropic.com> Signed-off-by: Simon Glass <simon.glass@canonical.com>
This commit is contained in:
187
include/linux/buffer_head.h
Normal file
187
include/linux/buffer_head.h
Normal file
@@ -0,0 +1,187 @@
|
||||
/* SPDX-License-Identifier: GPL-2.0 */
|
||||
/*
|
||||
* include/linux/buffer_head.h
|
||||
*
|
||||
* Everything to do with buffer_heads.
|
||||
* Minimal version for U-Boot ext4l - based on Linux 6.18
|
||||
*/
|
||||
|
||||
#ifndef _LINUX_BUFFER_HEAD_H
|
||||
#define _LINUX_BUFFER_HEAD_H
|
||||
|
||||
#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
|
||||
|
||||
enum bh_state_bits {
|
||||
BH_Uptodate, /* Contains valid data */
|
||||
BH_Dirty, /* Is dirty */
|
||||
BH_Lock, /* Is locked */
|
||||
BH_Req, /* Has been submitted for I/O */
|
||||
|
||||
BH_Mapped, /* Has a disk mapping */
|
||||
BH_New, /* Disk mapping was newly created by get_block */
|
||||
BH_Async_Read, /* Is under end_buffer_async_read I/O */
|
||||
BH_Async_Write, /* Is under end_buffer_async_write I/O */
|
||||
BH_Delay, /* Buffer is not yet allocated on disk */
|
||||
BH_Boundary, /* Block is followed by a discontiguity */
|
||||
BH_Write_EIO, /* I/O error on write */
|
||||
BH_Unwritten, /* Buffer is allocated on disk but not written */
|
||||
BH_Quiet, /* Buffer Error Prinks to be quiet */
|
||||
BH_Meta, /* Buffer contains metadata */
|
||||
BH_Prio, /* Buffer should be submitted with REQ_PRIO */
|
||||
BH_Defer_Completion, /* Defer AIO completion to workqueue */
|
||||
BH_Migrate, /* Buffer is being migrated (norefs) */
|
||||
|
||||
BH_PrivateStart,/* not a state bit, but the first bit available
|
||||
* for private allocation by other entities
|
||||
*/
|
||||
};
|
||||
|
||||
#define MAX_BUF_PER_PAGE (PAGE_SIZE / 512)
|
||||
|
||||
struct page;
|
||||
struct folio;
|
||||
struct buffer_head;
|
||||
struct address_space;
|
||||
struct block_device;
|
||||
typedef void (bh_end_io_t)(struct buffer_head *bh, int uptodate);
|
||||
|
||||
/*
|
||||
* Historically, a buffer_head was used to map a single block
|
||||
* within a page, and of course as the unit of I/O through the
|
||||
* filesystem and block layers. Nowadays the basic I/O unit
|
||||
* is the bio, and buffer_heads are used for extracting block
|
||||
* mappings (via a get_block_t call), for tracking state within
|
||||
* a folio (via a folio_mapping) and for wrapping bio submission
|
||||
* for backward compatibility reasons (e.g. submit_bh).
|
||||
*/
|
||||
struct buffer_head {
|
||||
unsigned long b_state; /* buffer state bitmap (see above) */
|
||||
struct buffer_head *b_this_page;/* circular list of page's buffers */
|
||||
union {
|
||||
struct page *b_page; /* the page this bh is mapped to */
|
||||
struct folio *b_folio; /* the folio this bh is mapped to */
|
||||
};
|
||||
|
||||
sector_t b_blocknr; /* start block number */
|
||||
size_t b_size; /* size of mapping */
|
||||
char *b_data; /* pointer to data within the page */
|
||||
|
||||
struct block_device *b_bdev;
|
||||
bh_end_io_t *b_end_io; /* I/O completion */
|
||||
void *b_private; /* reserved for b_end_io */
|
||||
struct list_head b_assoc_buffers; /* associated with another mapping */
|
||||
struct address_space *b_assoc_map; /* mapping this buffer is
|
||||
associated with */
|
||||
atomic_t b_count; /* users using this buffer_head */
|
||||
spinlock_t b_uptodate_lock; /* Used by the first bh in a page, to
|
||||
* serialise IO completion of other
|
||||
* buffers in the page */
|
||||
};
|
||||
|
||||
/*
|
||||
* Buffer head bit operations - inline implementations.
|
||||
* These don't use the extern set_bit/clear_bit from asm/bitops.h
|
||||
* since sandbox doesn't implement them.
|
||||
*/
|
||||
static inline void bh_set_bit(int nr, unsigned long *addr)
|
||||
{
|
||||
*addr |= (1UL << nr);
|
||||
}
|
||||
|
||||
static inline void bh_clear_bit(int nr, unsigned long *addr)
|
||||
{
|
||||
*addr &= ~(1UL << nr);
|
||||
}
|
||||
|
||||
static inline int bh_test_bit(int nr, const unsigned long *addr)
|
||||
{
|
||||
return (*addr >> nr) & 1;
|
||||
}
|
||||
|
||||
static inline int bh_test_and_set_bit(int nr, unsigned long *addr)
|
||||
{
|
||||
int old = (*addr >> nr) & 1;
|
||||
*addr |= (1UL << nr);
|
||||
return old;
|
||||
}
|
||||
|
||||
static inline int bh_test_and_clear_bit(int nr, unsigned long *addr)
|
||||
{
|
||||
int old = (*addr >> nr) & 1;
|
||||
*addr &= ~(1UL << nr);
|
||||
return old;
|
||||
}
|
||||
|
||||
/*
|
||||
* macro tricks to expand the set_buffer_foo(), clear_buffer_foo()
|
||||
* and buffer_foo() functions.
|
||||
*/
|
||||
#define BUFFER_FNS(bit, name) \
|
||||
static __always_inline void set_buffer_##name(struct buffer_head *bh) \
|
||||
{ \
|
||||
if (!bh_test_bit(BH_##bit, &(bh)->b_state)) \
|
||||
bh_set_bit(BH_##bit, &(bh)->b_state); \
|
||||
} \
|
||||
static __always_inline void clear_buffer_##name(struct buffer_head *bh) \
|
||||
{ \
|
||||
bh_clear_bit(BH_##bit, &(bh)->b_state); \
|
||||
} \
|
||||
static __always_inline int buffer_##name(const struct buffer_head *bh) \
|
||||
{ \
|
||||
return bh_test_bit(BH_##bit, &(bh)->b_state); \
|
||||
}
|
||||
|
||||
/*
|
||||
* test_set_buffer_foo() and test_clear_buffer_foo()
|
||||
*/
|
||||
#define TAS_BUFFER_FNS(bit, name) \
|
||||
static __always_inline int test_set_buffer_##name(struct buffer_head *bh) \
|
||||
{ \
|
||||
return bh_test_and_set_bit(BH_##bit, &(bh)->b_state); \
|
||||
} \
|
||||
static __always_inline int test_clear_buffer_##name(struct buffer_head *bh) \
|
||||
{ \
|
||||
return bh_test_and_clear_bit(BH_##bit, &(bh)->b_state); \
|
||||
}
|
||||
|
||||
BUFFER_FNS(Uptodate, uptodate)
|
||||
BUFFER_FNS(Dirty, dirty)
|
||||
BUFFER_FNS(Lock, locked)
|
||||
BUFFER_FNS(Req, req)
|
||||
BUFFER_FNS(Mapped, mapped)
|
||||
BUFFER_FNS(New, new)
|
||||
BUFFER_FNS(Async_Read, async_read)
|
||||
BUFFER_FNS(Async_Write, async_write)
|
||||
BUFFER_FNS(Delay, delay)
|
||||
BUFFER_FNS(Boundary, boundary)
|
||||
BUFFER_FNS(Write_EIO, write_io_error)
|
||||
BUFFER_FNS(Unwritten, unwritten)
|
||||
BUFFER_FNS(Meta, meta)
|
||||
BUFFER_FNS(Prio, prio)
|
||||
BUFFER_FNS(Defer_Completion, defer_completion)
|
||||
|
||||
static inline void get_bh(struct buffer_head *bh)
|
||||
{
|
||||
atomic_inc(&bh->b_count);
|
||||
}
|
||||
|
||||
static inline void put_bh(struct buffer_head *bh)
|
||||
{
|
||||
atomic_dec(&bh->b_count);
|
||||
}
|
||||
|
||||
/* Stubs for U-Boot */
|
||||
#define brelse(bh) do { if (bh) put_bh(bh); } while (0)
|
||||
#define __brelse(bh) do { put_bh(bh); } while (0)
|
||||
|
||||
#endif /* _LINUX_BUFFER_HEAD_H */
|
||||
114
include/linux/journal-head.h
Normal file
114
include/linux/journal-head.h
Normal file
@@ -0,0 +1,114 @@
|
||||
/* SPDX-License-Identifier: GPL-2.0 */
|
||||
/*
|
||||
* include/linux/journal-head.h
|
||||
*
|
||||
* buffer_head fields for JBD
|
||||
*
|
||||
* 27 May 2001 Andrew Morton
|
||||
* Created - pulled out of fs.h
|
||||
*/
|
||||
|
||||
#ifndef JOURNAL_HEAD_H_INCLUDED
|
||||
#define JOURNAL_HEAD_H_INCLUDED
|
||||
|
||||
#include <linux/spinlock.h>
|
||||
|
||||
typedef unsigned int tid_t; /* Unique transaction ID */
|
||||
typedef struct transaction_s transaction_t; /* Compound transaction type */
|
||||
|
||||
|
||||
struct buffer_head;
|
||||
|
||||
struct journal_head {
|
||||
/*
|
||||
* Points back to our buffer_head. [jbd_lock_bh_journal_head()]
|
||||
*/
|
||||
struct buffer_head *b_bh;
|
||||
|
||||
/*
|
||||
* Protect the buffer head state
|
||||
*/
|
||||
spinlock_t b_state_lock;
|
||||
|
||||
/*
|
||||
* Reference count - see description in journal.c
|
||||
* [jbd_lock_bh_journal_head()]
|
||||
*/
|
||||
int b_jcount;
|
||||
|
||||
/*
|
||||
* Journalling list for this buffer [b_state_lock]
|
||||
* NOTE: We *cannot* combine this with b_modified into a bitfield
|
||||
* as gcc would then (which the C standard allows but which is
|
||||
* very unuseful) make 64-bit accesses to the bitfield and clobber
|
||||
* b_jcount if its update races with bitfield modification.
|
||||
*/
|
||||
unsigned b_jlist;
|
||||
|
||||
/*
|
||||
* This flag signals the buffer has been modified by
|
||||
* the currently running transaction
|
||||
* [b_state_lock]
|
||||
*/
|
||||
unsigned b_modified;
|
||||
|
||||
/*
|
||||
* Copy of the buffer data frozen for writing to the log.
|
||||
* [b_state_lock]
|
||||
*/
|
||||
char *b_frozen_data;
|
||||
|
||||
/*
|
||||
* Pointer to a saved copy of the buffer containing no uncommitted
|
||||
* deallocation references, so that allocations can avoid overwriting
|
||||
* uncommitted deletes. [b_state_lock]
|
||||
*/
|
||||
char *b_committed_data;
|
||||
|
||||
/*
|
||||
* Pointer to the compound transaction which owns this buffer's
|
||||
* metadata: either the running transaction or the committing
|
||||
* transaction (if there is one). Only applies to buffers on a
|
||||
* transaction's data or metadata journaling list.
|
||||
* [j_list_lock] [b_state_lock]
|
||||
* Either of these locks is enough for reading, both are needed for
|
||||
* changes.
|
||||
*/
|
||||
transaction_t *b_transaction;
|
||||
|
||||
/*
|
||||
* Pointer to the running compound transaction which is currently
|
||||
* modifying the buffer's metadata, if there was already a transaction
|
||||
* committing it when the new transaction touched it.
|
||||
* [t_list_lock] [b_state_lock]
|
||||
*/
|
||||
transaction_t *b_next_transaction;
|
||||
|
||||
/*
|
||||
* Doubly-linked list of buffers on a transaction's data, metadata or
|
||||
* forget queue. [t_list_lock] [b_state_lock]
|
||||
*/
|
||||
struct journal_head *b_tnext, *b_tprev;
|
||||
|
||||
/*
|
||||
* Pointer to the compound transaction against which this buffer
|
||||
* is checkpointed. Only dirty buffers can be checkpointed.
|
||||
* [j_list_lock]
|
||||
*/
|
||||
transaction_t *b_cp_transaction;
|
||||
|
||||
/*
|
||||
* Doubly-linked list of buffers still remaining to be flushed
|
||||
* before an old transaction can be checkpointed.
|
||||
* [j_list_lock]
|
||||
*/
|
||||
struct journal_head *b_cpnext, *b_cpprev;
|
||||
|
||||
/* Trigger type */
|
||||
struct jbd2_buffer_trigger_type *b_triggers;
|
||||
|
||||
/* Trigger type for the committing transaction's frozen data */
|
||||
struct jbd2_buffer_trigger_type *b_frozen_triggers;
|
||||
};
|
||||
|
||||
#endif /* JOURNAL_HEAD_H_INCLUDED */
|
||||
Reference in New Issue
Block a user