fs/ubifs/io.c
Source file repositories/reference/linux-study-clean/fs/ubifs/io.c
File Facts
- System
- Linux kernel
- Corpus path
fs/ubifs/io.c- Extension
.c- Size
- 37156 bytes
- Lines
- 1263
- Domain
- Core OS
- Bucket
- VFS And Filesystem Core
- Inferred role
- Core OS: implementation source
- Status
- source implementation candidate
Why This File Exists
Core operating-system implementation surface: boot, tasks, memory, VFS, syscall-facing interfaces, synchronization, credentials, and isolation.
- Core operating-system implementation surface: boot, tasks, memory, VFS, syscall-facing interfaces, synchronization, credentials, and isolation.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- Allocates kernel memory; connect allocation flags and lifetime to context constraints.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/crc32.hlinux/slab.hubifs.h
Detected Declarations
function Copyrightfunction ubifs_leb_readfunction ubifs_leb_writefunction ubifs_leb_changefunction ubifs_leb_unmapfunction ubifs_leb_mapfunction ubifs_is_mappedfunction record_magic_errorfunction record_node_errorfunction record_crc_errorfunction ubifs_check_nodefunction patternfunction next_sqnumfunction ubifs_init_nodefunction ubifs_crc_nodefunction ubifs_prepare_node_hmacfunction ubifs_prepare_nodefunction ubifs_prep_grp_nodefunction wbuf_timer_callback_nolockfunction new_wbuf_timer_nolockfunction cancel_wbuf_timer_nolockfunction ubifs_wbuf_sync_nolockfunction ubifs_wbuf_seek_nolockfunction ubifs_bg_wbufs_syncfunction ubifs_wbuf_write_nolockfunction ubifs_write_node_hmacfunction ubifs_write_nodefunction ubifs_read_node_wbuffunction ubifs_read_nodefunction ubifs_wbuf_initfunction ubifs_wbuf_add_ino_nolockfunction wbuf_has_inofunction ubifs_sync_wbufs_by_inode
Annotated Snippet
if (sqnum >= SQNUM_WATERMARK) {
ubifs_err(c, "sequence number overflow %llu, end of life",
sqnum);
ubifs_ro_mode(c, -EINVAL);
}
ubifs_warn(c, "running out of sequence numbers, end of life soon");
}
return sqnum;
}
void ubifs_init_node(struct ubifs_info *c, void *node, int len, int pad)
{
struct ubifs_ch *ch = node;
unsigned long long sqnum = next_sqnum(c);
ubifs_assert(c, len >= UBIFS_CH_SZ);
ch->magic = cpu_to_le32(UBIFS_NODE_MAGIC);
ch->len = cpu_to_le32(len);
ch->group_type = UBIFS_NO_NODE_GROUP;
ch->sqnum = cpu_to_le64(sqnum);
ch->padding[0] = ch->padding[1] = 0;
if (pad) {
len = ALIGN(len, 8);
pad = ALIGN(len, c->min_io_size) - len;
ubifs_pad(c, node + len, pad);
}
}
void ubifs_crc_node(void *node, int len)
{
struct ubifs_ch *ch = node;
uint32_t crc;
crc = crc32(UBIFS_CRC32_INIT, node + 8, len - 8);
ch->crc = cpu_to_le32(crc);
}
/**
* ubifs_prepare_node_hmac - prepare node to be written to flash.
* @c: UBIFS file-system description object
* @node: the node to pad
* @len: node length
* @hmac_offs: offset of the HMAC in the node
* @pad: if the buffer has to be padded
*
* This function prepares node at @node to be written to the media - it
* calculates node CRC, fills the common header, and adds proper padding up to
* the next minimum I/O unit if @pad is not zero. if @hmac_offs is positive then
* a HMAC is inserted into the node at the given offset.
*
* This function returns 0 for success or a negative error code otherwise.
*/
int ubifs_prepare_node_hmac(struct ubifs_info *c, void *node, int len,
int hmac_offs, int pad)
{
int err;
ubifs_init_node(c, node, len, pad);
if (hmac_offs > 0) {
err = ubifs_node_insert_hmac(c, node, len, hmac_offs);
if (err)
return err;
}
ubifs_crc_node(node, len);
return 0;
}
/**
* ubifs_prepare_node - prepare node to be written to flash.
* @c: UBIFS file-system description object
* @node: the node to pad
* @len: node length
* @pad: if the buffer has to be padded
*
* This function prepares node at @node to be written to the media - it
* calculates node CRC, fills the common header, and adds proper padding up to
* the next minimum I/O unit if @pad is not zero.
*/
void ubifs_prepare_node(struct ubifs_info *c, void *node, int len, int pad)
{
/*
* Deliberately ignore return value since this function can only fail
* when a hmac offset is given.
*/
Annotation
- Immediate include surface: `linux/crc32.h`, `linux/slab.h`, `ubifs.h`.
- Detected declarations: `function Copyright`, `function ubifs_leb_read`, `function ubifs_leb_write`, `function ubifs_leb_change`, `function ubifs_leb_unmap`, `function ubifs_leb_map`, `function ubifs_is_mapped`, `function record_magic_error`, `function record_node_error`, `function record_crc_error`.
- Atlas domain: Core OS / VFS And Filesystem Core.
- Implementation status: source implementation candidate.
- Synchronization appears in or near this file; preserve lock ordering, sleepability, and interrupt-context constraints.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.