devname(3)

devname3

Get device name

Usage

#include <sys/stat.h>

#include <stdlib.h>

char *

devname(dev_t dev, mode_t type);

char *

devname_r(dev_t dev, mode_t type, char *buf, int len);

char *

fdevname(int fd);

char *

fdevname_r(int fd, char *buf, int len);

Library

Standard C Library (libc, -lc)

Overview

The devname() function returns a pointer to the name of the block or character device in /dev with a device number of dev, and a file type matching the one encoded in type which must be one of S_IFBLK or S_IFCHR. To find the right name, devname() asks the kernel via the kern.devname sysctl. If it is unable to come up with a suitable name, it will format the information encapsulated in dev and type in a human-readable format.

The fdevname() and fdevname_r() function obtains the device name directly from a file descriptor pointing to a character device. If it is unable to come up with a suitable name, these functions will return a NULL pointer.

devname() and fdevname() return the name stored in a static buffer which will be overwritten on subsequent calls. devname_r() and fdevname_r() take a buffer and length as argument to avoid this problem.

Examples

int fd;
struct stat buf;
char *name;
	fd = open("/dev/tun");
	fstat(fd, &buf);
	printf("devname is /dev/%s\n", devname(buf.st_rdev, S_IFCHR));
	printf("fdevname is /dev/%s\n", fdevname(fd));

Releases

87 releases since FreeBSD 2.0.5-RELEASE; the text changed 48 times.

  1. 2.0.5–2.1.7.1
  2. 2.2.2–2.2.5
  3. 2.2.6–3.4
  4. 3.5–3.5.1
  5. 4.0
  6. 4.1–4.2
  7. 4.3
  8. 4.4
  9. 4.5
  10. 4.6–4.7
  11. 4.8–4.11
  12. 5.0
  13. 5.1
  14. 5.2–5.3
  15. 5.4–5.5
  16. 6.0–6.3
  17. 6.4
  18. 7.0
  19. 7.1
  20. 7.2
  21. 7.3
  22. 7.4
  23. 8.0
  24. 8.1
  25. 8.2
  26. 8.3
  27. 8.4
  28. 9.0
  29. 9.1
  30. 9.2
  31. 9.3
  32. 10.0
  33. 10.1
  34. 10.2
  35. 10.3
  36. 10.4
  37. 11.0
  38. 11.1
  39. 11.2
  40. 11.3
  41. 11.4
  42. 12.0
  43. 12.1
  44. 12.2
  45. 12.3
  46. 12.4
  47. 13.0–13.2
  48. 13.3–14.5
  49. 15.0–16.0

History

The devname() function appeared in 4.4BSD. The fdevname() function appeared in FreeBSD 8.0.

From base 16.0-CURRENT-20261027-61c70dc16a79 in FreeBSD 16.0-CURRENT (2026-10-27). Parsed by carta from the page's mdoc source.