FDD-book/examples/part-02/ch08-working-with-device-files/userland/stat_myfirst.c
Abdelkader Boudih 127eb3863c refactor: adopt current style(9) license header order (copyright before SPDX)
Update all example sources, man pages, and chapter code blocks to the
current FreeBSD header convention: plain /* opening, copyright lines
first, SPDX-License-Identifier after them. Add missing headers to
ch21/ch22 example files and missing copyright lines in ch08/ch16/ch36.
Rewrite chapter 37 prose (en, pt_BR, es_ES, zh_CN) and the submission
checklist, which previously taught the /*- marker and SPDX-first order.
2026-08-26 02:32:55 +01:00

45 lines
993 B
C

/*
* Copyright (c) 2026 Edson Brandi
*
* SPDX-License-Identifier: BSD-2-Clause
*
* stat_myfirst: print stat(2) metadata for one or more device-file
* paths. Useful to confirm that a primary node and its alias resolve
* to the same cdev (same rdev) and that the advertised mode and
* ownership match what the driver asked for.
*
* Usage:
* stat_myfirst path [path ...]
*
* Compile:
* cc -Wall -Werror -o stat_myfirst stat_myfirst.c
*/
#include <err.h>
#include <stdio.h>
#include <sys/stat.h>
#include <sys/types.h>
int
main(int argc, char **argv)
{
struct stat sb;
int i;
if (argc < 2) {
fprintf(stderr, "usage: %s path [path ...]\n", argv[0]);
return (1);
}
for (i = 1; i < argc; i++) {
if (stat(argv[i], &sb) != 0)
err(1, "stat %s", argv[i]);
printf("%s: mode=%06o uid=%u gid=%u rdev=%#jx\n",
argv[i],
(unsigned)(sb.st_mode & 07777),
(unsigned)sb.st_uid,
(unsigned)sb.st_gid,
(uintmax_t)sb.st_rdev);
}
return (0);
}