---
name: "getinode"
section: "3"
platform: "freebsd"
package: "base"
version: "16.0-CURRENT-20261027-61c70dc16a79"
release: "FreeBSD 16.0-CURRENT (2026-10-27)"
platforms: ["freebsd"]
url: "https://new.carta.tech/getinode"
---

# getinode(3)

fetch and store inodes on a UFS file system

## NAME

**getinode**, **putinode** – fetch and store inodes on a UFS file system

## LIBRARY

library “libufs”

## SYNOPSIS

**#include \<ufs/ufs/dinode.h\>**

**#include \<ufs/ffs/fs.h\>**

**#include \<libufs.h\>**

*int*\

**getinode**(*struct uufsd \*disk*, *union dinodep \*dp*, *ino\_t inumber*);

*int*\

**putinode**(*struct uufsd \*disk*);

## DESCRIPTION

The **getinode**() and **putinode**() functions provide an inode fetch and store API for [libufs(3)](/libufs/3.md) consumers. They operate on a userland UFS disk structure. The **getinode**() function fetches the specified inode from the filesystem. The **putinode**() function stores the most recently fetched inode to the filesystem.

The *dinodep* union is defined as:

```
union dinodep {
	struct ufs1_dinode *dp1;
	struct ufs2_dinode *dp2;
};
```

Sample code to clear write permissions for inode number *inumber* stored on the filesystem described by *diskp*.

```
#include <sys/stat.h>
#include <err.h>
#include <ufs/ufs/dinode.h>
#include <ufs/ffs/fs.h>
#include <libufs.h>
void
clearwrite(struct uufsd *diskp, ino_t inumber)
{
	union dinodep dp;
	if (getinode(diskp, &dp, inumber) == -1)
		err(1, "getinode: %s", diskp->d_error);
	switch (diskp->d_ufs) {
	case 1: /* UFS 1 filesystem */
		dp.dp1->di_mode &= ~(S_IWUSR | S_IWGRP | S_IWOTH);
		break;
	case 2: /* UFS 2 filesystem */
		dp.dp2->di_mode &= ~(S_IWUSR | S_IWGRP | S_IWOTH);
		break;
	default:
		errx(1, "unknown filesystem type");
	}
	if (putinode(diskp) == -1)
		err(1, "putinode: %s", diskp->d_error);
}
```

## RETURN VALUES

The **getinode**() and **putinode**() functions return 0 on success, or -1 in case of any error. A string describing the error is stored in *diskp-\>d\_error*. The global *errno* often provides additional information.

## ERRORS

The function **getinode**() may fail and set *errno* for any of the errors specified for the library function [pread(2)](/pread/2.md). It can also fail if the inode number is out of the range of inodes in the filesystem.

The function **putinode**() may fail and set *errno* for any of the errors specified for the library functions [ufs\_disk\_write(3)](/ufs_disk_write/3.md) or [pwrite(2)](/pwrite/2.md).

Additionally both functions may follow the [libufs(3)](/libufs/3.md) error methodologies in case of a device error.

## SEE ALSO

[pread(2)](/pread/2.md), [pwrite(2)](/pwrite/2.md), [libufs(3)](/libufs/3.md), [ufs\_disk\_write(3)](/ufs_disk_write/3.md)

## HISTORY

These functions first appeared as part of [libufs(3)](/libufs/3.md) in FreeBSD 13.0.

## AUTHORS

Marshall Kirk McKusick ⟨*mckusick@FreeBSD.org*⟩
