tools/bpf/bpftool/map.c
Source file repositories/reference/linux-study-clean/tools/bpf/bpftool/map.c
File Facts
- System
- Linux kernel
- Corpus path
tools/bpf/bpftool/map.c- Extension
.c- Size
- 33266 bytes
- Lines
- 1515
- Domain
- Support Tooling And Documentation
- Bucket
- tools
- Inferred role
- Support Tooling And Documentation: implementation source
- Status
- source implementation candidate
Why This File Exists
Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.
- Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
errno.hfcntl.hlinux/err.hlinux/kernel.hnet/if.hstdbool.hstdio.hstdlib.hstring.hunistd.hsys/types.hsys/stat.hbpf/bpf.hbpf/btf.hbpf/hashmap.hjson_writer.hmain.h
Detected Declarations
function map_is_per_cpufunction map_is_map_of_mapsfunction map_is_map_of_progsfunction map_type_from_strfunction do_dump_btffunction print_entry_jsonfunction print_entry_error_msgfunction print_entry_errorfunction print_entry_plainfunction fill_per_cpu_valuefunction parse_elemfunction is_prefixfunction show_map_header_jsonfunction show_map_close_jsonfunction show_map_header_plainfunction show_map_close_plainfunction do_show_subsetfunction do_showfunction dump_map_elemfunction maps_have_btffunction get_map_kv_btffunction free_map_kv_btffunction map_dumpfunction do_dumpfunction alloc_key_valuefunction do_updatefunction print_key_valuefunction do_lookupfunction do_getnextfunction do_deletefunction map_parse_read_only_fdfunction do_pinfunction do_createfunction do_pop_dequeuefunction do_freezefunction do_helpfunction do_map
Annotated Snippet
if (btf) {
struct btf_dumper d = {
.btf = btf,
.jw = json_wtr,
.is_plain_text = false,
};
jsonw_name(json_wtr, "formatted");
do_dump_btf(&d, info, key, value);
}
} else {
unsigned int i, n, step;
n = get_possible_cpus();
step = round_up(info->value_size, 8);
jsonw_name(json_wtr, "key");
print_hex_data_json(key, info->key_size);
jsonw_name(json_wtr, "values");
jsonw_start_array(json_wtr);
for (i = 0; i < n; i++) {
jsonw_start_object(json_wtr);
jsonw_int_field(json_wtr, "cpu", i);
jsonw_name(json_wtr, "value");
print_hex_data_json(value + i * step,
info->value_size);
jsonw_end_object(json_wtr);
}
jsonw_end_array(json_wtr);
if (btf) {
struct btf_dumper d = {
.btf = btf,
.jw = json_wtr,
.is_plain_text = false,
};
jsonw_name(json_wtr, "formatted");
do_dump_btf(&d, info, key, value);
}
}
jsonw_end_object(json_wtr);
}
static void
print_entry_error_msg(struct bpf_map_info *info, unsigned char *key,
const char *error_msg)
{
int msg_size = strlen(error_msg);
bool single_line, break_names;
break_names = info->key_size > 16 || msg_size > 16;
single_line = info->key_size + msg_size <= 24 && !break_names;
printf("key:%c", break_names ? '\n' : ' ');
fprint_hex(stdout, key, info->key_size, " ");
printf(single_line ? " " : "\n");
printf("value:%c%s", break_names ? '\n' : ' ', error_msg);
printf("\n");
}
static void
print_entry_error(struct bpf_map_info *map_info, void *key, int lookup_errno)
{
/* For prog_array maps or arrays of maps, failure to lookup the value
* means there is no entry for that key. Do not print an error message
* in that case.
*/
if ((map_is_map_of_maps(map_info->type) ||
map_is_map_of_progs(map_info->type)) && lookup_errno == ENOENT)
return;
if (json_output) {
jsonw_start_object(json_wtr); /* entry */
jsonw_name(json_wtr, "key");
print_hex_data_json(key, map_info->key_size);
jsonw_name(json_wtr, "value");
jsonw_start_object(json_wtr); /* error */
jsonw_string_field(json_wtr, "error", strerror(lookup_errno));
jsonw_end_object(json_wtr); /* error */
jsonw_end_object(json_wtr); /* entry */
} else {
const char *msg = NULL;
Annotation
- Immediate include surface: `errno.h`, `fcntl.h`, `linux/err.h`, `linux/kernel.h`, `net/if.h`, `stdbool.h`, `stdio.h`, `stdlib.h`.
- Detected declarations: `function map_is_per_cpu`, `function map_is_map_of_maps`, `function map_is_map_of_progs`, `function map_type_from_str`, `function do_dump_btf`, `function print_entry_json`, `function print_entry_error_msg`, `function print_entry_error`, `function print_entry_plain`, `function fill_per_cpu_value`.
- Atlas domain: Support Tooling And Documentation / tools.
- Implementation status: source implementation candidate.
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.