tools/testing/selftests/filesystems/fuse/fuse_mnt.c
Source file repositories/reference/linux-study-clean/tools/testing/selftests/filesystems/fuse/fuse_mnt.c
File Facts
- System
- Linux kernel
- Corpus path
tools/testing/selftests/filesystems/fuse/fuse_mnt.c- Extension
.c- Size
- 2718 bytes
- Lines
- 147
- 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
fuse.hstdio.hstring.herrno.hfcntl.hstdlib.hunistd.h
Detected Declarations
function test_getattrfunction test_readdirfunction test_openfunction test_readfunction test_writefunction test_truncatefunction main
Annotated Snippet
// SPDX-License-Identifier: GPL-2.0
/*
* fusectl test file-system
* Creates a simple FUSE filesystem with a single read-write file (/test)
*/
#define FUSE_USE_VERSION 26
#include <fuse.h>
#include <stdio.h>
#include <string.h>
#include <errno.h>
#include <fcntl.h>
#include <stdlib.h>
#include <unistd.h>
#define MAX(a, b) ((a) > (b) ? (a) : (b))
static char *content;
static size_t content_size = 0;
static const char test_path[] = "/test";
static int test_getattr(const char *path, struct stat *st)
{
memset(st, 0, sizeof(*st));
if (!strcmp(path, "/")) {
st->st_mode = S_IFDIR | 0755;
st->st_nlink = 2;
return 0;
}
if (!strcmp(path, test_path)) {
st->st_mode = S_IFREG | 0664;
st->st_nlink = 1;
st->st_size = content_size;
return 0;
}
return -ENOENT;
}
static int test_readdir(const char *path, void *buf, fuse_fill_dir_t filler,
off_t offset, struct fuse_file_info *fi)
{
if (strcmp(path, "/"))
return -ENOENT;
filler(buf, ".", NULL, 0);
filler(buf, "..", NULL, 0);
filler(buf, test_path + 1, NULL, 0);
return 0;
}
static int test_open(const char *path, struct fuse_file_info *fi)
{
if (strcmp(path, test_path))
return -ENOENT;
return 0;
}
static int test_read(const char *path, char *buf, size_t size, off_t offset,
struct fuse_file_info *fi)
{
if (strcmp(path, test_path) != 0)
return -ENOENT;
if (!content || content_size == 0)
return 0;
if (offset >= content_size)
return 0;
if (offset + size > content_size)
size = content_size - offset;
memcpy(buf, content + offset, size);
return size;
}
static int test_write(const char *path, const char *buf, size_t size,
off_t offset, struct fuse_file_info *fi)
{
size_t new_size;
if (strcmp(path, test_path) != 0)
return -ENOENT;
Annotation
- Immediate include surface: `fuse.h`, `stdio.h`, `string.h`, `errno.h`, `fcntl.h`, `stdlib.h`, `unistd.h`.
- Detected declarations: `function test_getattr`, `function test_readdir`, `function test_open`, `function test_read`, `function test_write`, `function test_truncate`, `function main`.
- 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.