fs/hostfs/hostfs_user.c
Source file repositories/reference/linux-study-clean/fs/hostfs/hostfs_user.c
File Facts
- System
- Linux kernel
- Corpus path
fs/hostfs/hostfs_user.c- Extension
.c- Size
- 7917 bytes
- Lines
- 422
- 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.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
stdio.hstddef.hunistd.hdirent.herrno.hfcntl.hstring.hsys/stat.hsys/time.hsys/types.hsys/vfs.hsys/syscall.hhostfs.hutime.h
Detected Declarations
function Copyrightfunction stat_filefunction access_filefunction open_filefunction seek_dirfunction read_filefunction write_filefunction lseek_filefunction fsync_filefunction replace_filefunction close_filefunction close_dirfunction file_createfunction set_attrfunction make_symlinkfunction unlink_filefunction do_mkdirfunction hostfs_do_rmdirfunction do_mknodfunction link_filefunction hostfs_do_readlinkfunction rename_filefunction rename2_filefunction do_statfs
Annotated Snippet
if (fd >= 0) {
if (fchmod(fd, attrs->ia_mode) != 0)
return -errno;
} else if (chmod(file, attrs->ia_mode) != 0) {
return -errno;
}
}
if (attrs->ia_valid & HOSTFS_ATTR_UID) {
if (fd >= 0) {
if (fchown(fd, attrs->ia_uid, -1))
return -errno;
} else if (chown(file, attrs->ia_uid, -1)) {
return -errno;
}
}
if (attrs->ia_valid & HOSTFS_ATTR_GID) {
if (fd >= 0) {
if (fchown(fd, -1, attrs->ia_gid))
return -errno;
} else if (chown(file, -1, attrs->ia_gid)) {
return -errno;
}
}
if (attrs->ia_valid & HOSTFS_ATTR_SIZE) {
if (fd >= 0) {
if (ftruncate(fd, attrs->ia_size))
return -errno;
} else if (truncate(file, attrs->ia_size)) {
return -errno;
}
}
/*
* Update accessed and/or modified time, in two parts: first set
* times according to the changes to perform, and then call futimes()
* or utimes() to apply them.
*/
ma = (HOSTFS_ATTR_ATIME_SET | HOSTFS_ATTR_MTIME_SET);
if (attrs->ia_valid & ma) {
err = stat_file(file, &st, fd);
if (err != 0)
return err;
times[0].tv_sec = st.atime.tv_sec;
times[0].tv_usec = st.atime.tv_nsec / 1000;
times[1].tv_sec = st.mtime.tv_sec;
times[1].tv_usec = st.mtime.tv_nsec / 1000;
if (attrs->ia_valid & HOSTFS_ATTR_ATIME_SET) {
times[0].tv_sec = attrs->ia_atime.tv_sec;
times[0].tv_usec = attrs->ia_atime.tv_nsec / 1000;
}
if (attrs->ia_valid & HOSTFS_ATTR_MTIME_SET) {
times[1].tv_sec = attrs->ia_mtime.tv_sec;
times[1].tv_usec = attrs->ia_mtime.tv_nsec / 1000;
}
if (fd >= 0) {
if (futimes(fd, times) != 0)
return -errno;
} else if (utimes(file, times) != 0) {
return -errno;
}
}
/* Note: ctime is not handled */
if (attrs->ia_valid & (HOSTFS_ATTR_ATIME | HOSTFS_ATTR_MTIME)) {
err = stat_file(file, &st, fd);
attrs->ia_atime = st.atime;
attrs->ia_mtime = st.mtime;
if (err != 0)
return err;
}
return 0;
}
int make_symlink(const char *from, const char *to)
{
int err;
err = symlink(to, from);
if (err)
return -errno;
return 0;
}
int unlink_file(const char *file)
{
int err;
Annotation
- Immediate include surface: `stdio.h`, `stddef.h`, `unistd.h`, `dirent.h`, `errno.h`, `fcntl.h`, `string.h`, `sys/stat.h`.
- Detected declarations: `function Copyright`, `function stat_file`, `function access_file`, `function open_file`, `function seek_dir`, `function read_file`, `function write_file`, `function lseek_file`, `function fsync_file`, `function replace_file`.
- Atlas domain: Core OS / VFS And Filesystem Core.
- 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.