samples/vfs/test-statx.c
Source file repositories/reference/linux-study-clean/samples/vfs/test-statx.c
File Facts
- System
- Linux kernel
- Corpus path
samples/vfs/test-statx.c- Extension
.c- Size
- 6795 bytes
- Lines
- 272
- Domain
- Support Tooling And Documentation
- Bucket
- samples
- 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
stdio.hstdlib.hstring.hunistd.hctype.herrno.htime.hsys/syscall.hsys/types.hlinux/stat.hlinux/fcntl.hsys/stat.h
Detected Declarations
struct statxstruct statx_timestampfunction __attribute__function print_timefunction dump_statxfunction dump_hexfunction main
Annotated Snippet
switch (stx->stx_mode & S_IFMT) {
case S_IFIFO: printf(" FIFO\n"); ft = 'p'; break;
case S_IFCHR: printf(" character special file\n"); ft = 'c'; break;
case S_IFDIR: printf(" directory\n"); ft = 'd'; break;
case S_IFBLK: printf(" block special file\n"); ft = 'b'; break;
case S_IFREG: printf(" regular file\n"); ft = '-'; break;
case S_IFLNK: printf(" symbolic link\n"); ft = 'l'; break;
case S_IFSOCK: printf(" socket\n"); ft = 's'; break;
default:
printf(" unknown type (%o)\n", stx->stx_mode & S_IFMT);
break;
}
} else {
printf(" no type\n");
}
sprintf(buffer, "%02x:%02x", stx->stx_dev_major, stx->stx_dev_minor);
printf("Device: %-15s", buffer);
if (stx->stx_mask & STATX_INO)
printf(" Inode: %-11llu", (unsigned long long) stx->stx_ino);
if (stx->stx_mask & STATX_NLINK)
printf(" Links: %-5u", stx->stx_nlink);
if (stx->stx_mask & STATX_TYPE) {
switch (stx->stx_mode & S_IFMT) {
case S_IFBLK:
case S_IFCHR:
printf(" Device type: %u,%u",
stx->stx_rdev_major, stx->stx_rdev_minor);
break;
}
}
printf("\n");
if (stx->stx_mask & STATX_MODE)
printf("Access: (%04o/%c%c%c%c%c%c%c%c%c%c) ",
stx->stx_mode & 07777,
ft,
stx->stx_mode & S_IRUSR ? 'r' : '-',
stx->stx_mode & S_IWUSR ? 'w' : '-',
stx->stx_mode & S_IXUSR ? 'x' : '-',
stx->stx_mode & S_IRGRP ? 'r' : '-',
stx->stx_mode & S_IWGRP ? 'w' : '-',
stx->stx_mode & S_IXGRP ? 'x' : '-',
stx->stx_mode & S_IROTH ? 'r' : '-',
stx->stx_mode & S_IWOTH ? 'w' : '-',
stx->stx_mode & S_IXOTH ? 'x' : '-');
if (stx->stx_mask & STATX_UID)
printf("Uid: %5d ", stx->stx_uid);
if (stx->stx_mask & STATX_GID)
printf("Gid: %5d\n", stx->stx_gid);
if (stx->stx_mask & STATX_ATIME)
print_time("Access: ", &stx->stx_atime);
if (stx->stx_mask & STATX_MTIME)
print_time("Modify: ", &stx->stx_mtime);
if (stx->stx_mask & STATX_CTIME)
print_time("Change: ", &stx->stx_ctime);
if (stx->stx_mask & STATX_BTIME)
print_time(" Birth: ", &stx->stx_btime);
if (stx->stx_attributes_mask) {
unsigned char bits, mbits;
int loop, byte;
static char attr_representation[64 + 1] =
/* STATX_ATTR_ flags: */
"????????" /* 63-56 */
"????????" /* 55-48 */
"????????" /* 47-40 */
"????????" /* 39-32 */
"????????" /* 31-24 0x00000000-ff000000 */
"????????" /* 23-16 0x00000000-00ff0000 */
"???me???" /* 15- 8 0x00000000-0000ff00 */
"?dai?c??" /* 7- 0 0x00000000-000000ff */
;
printf("Attributes: %016llx (",
(unsigned long long)stx->stx_attributes);
for (byte = 64 - 8; byte >= 0; byte -= 8) {
bits = stx->stx_attributes >> byte;
mbits = stx->stx_attributes_mask >> byte;
for (loop = 7; loop >= 0; loop--) {
int bit = byte + loop;
if (!(mbits & 0x80))
putchar('.'); /* Not supported */
else if (bits & 0x80)
putchar(attr_representation[63 - bit]);
else
putchar('-'); /* Not set */
Annotation
- Immediate include surface: `stdio.h`, `stdlib.h`, `string.h`, `unistd.h`, `ctype.h`, `errno.h`, `time.h`, `sys/syscall.h`.
- Detected declarations: `struct statx`, `struct statx_timestamp`, `function __attribute__`, `function print_time`, `function dump_statx`, `function dump_hex`, `function main`.
- Atlas domain: Support Tooling And Documentation / samples.
- 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.