fs/ubifs/tnc.c
Source file repositories/reference/linux-study-clean/fs/ubifs/tnc.c
File Facts
- System
- Linux kernel
- Corpus path
fs/ubifs/tnc.c- Extension
.c- Size
- 94994 bytes
- Lines
- 3576
- 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 do_insert_old_idxfunction insert_old_idxfunction insert_old_idx_znodefunction ins_clr_old_idx_znodefunction destroy_old_idxfunction add_idx_dirtfunction replace_znodefunction lnc_addfunction lnc_add_directlyfunction lnc_freefunction tnc_read_hashed_nodefunction truefunction fallible_read_nodefunction matches_namefunction tnc_nextfunction tnc_prevfunction nodefunction fallible_matches_namefunction fallible_resolve_collisionfunction matches_positionfunction knownfunction downfunction ubifs_lookup_level0function lookup_level0_dirtyfunction maybe_leb_gcedfunction ubifs_tnc_locatefunction ubifs_tnc_get_bu_keysfunction read_wbuffunction validate_data_nodefunction ubifs_tnc_bulk_readfunction do_lookup_nmfunction ubifs_tnc_lookup_nmfunction search_dh_cookiefunction do_lookup_dhfunction ubifs_tnc_lookup_dhfunction correct_parent_keysfunction insert_zbranchfunction tnc_insertfunction ubifs_tnc_addfunction ubifs_tnc_replacefunction ubifs_tnc_add_nmfunction tnc_deletefunction ubifs_tnc_removefunction ubifs_tnc_remove_nmfunction ubifs_tnc_remove_dhfunction key_in_rangefunction ubifs_tnc_remove_rangefunction ubifs_tnc_remove_ino
Annotated Snippet
if (zbr->len) {
err = insert_old_idx(c, zbr->lnum, zbr->offs);
if (err)
return err;
zbr->lnum = 0;
zbr->offs = 0;
zbr->len = 0;
}
} else
if (c->zroot.len) {
err = insert_old_idx(c, c->zroot.lnum, c->zroot.offs);
if (err)
return err;
c->zroot.lnum = 0;
c->zroot.offs = 0;
c->zroot.len = 0;
}
return 0;
}
/**
* destroy_old_idx - destroy the old_idx RB-tree.
* @c: UBIFS file-system description object
*
* During start commit, the old_idx RB-tree is used to avoid overwriting index
* nodes that were in the index last commit but have since been deleted. This
* is necessary for recovery i.e. the old index must be kept intact until the
* new index is successfully written. The old-idx RB-tree is used for the
* in-the-gaps method of writing index nodes and is destroyed every commit.
*/
void destroy_old_idx(struct ubifs_info *c)
{
struct ubifs_old_idx *old_idx, *n;
rbtree_postorder_for_each_entry_safe(old_idx, n, &c->old_idx, rb)
kfree(old_idx);
c->old_idx = RB_ROOT;
}
/**
* copy_znode - copy a dirty znode.
* @c: UBIFS file-system description object
* @znode: znode to copy
*
* A dirty znode being committed may not be changed, so it is copied.
*/
static struct ubifs_znode *copy_znode(struct ubifs_info *c,
struct ubifs_znode *znode)
{
struct ubifs_znode *zn;
zn = kmemdup(znode, c->max_znode_sz, GFP_NOFS);
if (unlikely(!zn))
return ERR_PTR(-ENOMEM);
zn->cnext = NULL;
__set_bit(DIRTY_ZNODE, &zn->flags);
__clear_bit(COW_ZNODE, &zn->flags);
return zn;
}
/**
* add_idx_dirt - add dirt due to a dirty znode.
* @c: UBIFS file-system description object
* @lnum: LEB number of index node
* @dirt: size of index node
*
* This function updates lprops dirty space and the new size of the index.
*/
static int add_idx_dirt(struct ubifs_info *c, int lnum, int dirt)
{
c->calc_idx_sz -= ALIGN(dirt, 8);
return ubifs_add_dirt(c, lnum, dirt);
}
/**
* replace_znode - replace old znode with new znode.
* @c: UBIFS file-system description object
* @new_zn: new znode
* @old_zn: old znode
* @zbr: the branch of parent znode
*
* Replace old znode with new znode in TNC.
*/
static void replace_znode(struct ubifs_info *c, struct ubifs_znode *new_zn,
struct ubifs_znode *old_zn, struct ubifs_zbranch *zbr)
{
ubifs_assert(c, !ubifs_zn_obsolete(old_zn));
Annotation
- Immediate include surface: `linux/crc32.h`, `linux/slab.h`, `ubifs.h`.
- Detected declarations: `function do_insert_old_idx`, `function insert_old_idx`, `function insert_old_idx_znode`, `function ins_clr_old_idx_znode`, `function destroy_old_idx`, `function add_idx_dirt`, `function replace_znode`, `function lnc_add`, `function lnc_add_directly`, `function lnc_free`.
- 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.