GETINODE(3)
πΎ getinode, putinode β your inode fetch-and-store era β¨
okay bestie, so this is a page from the Library Functions Manual for libufs β the UFS File System Access Library, linked with -lufs π«Ά. And honey, these two little functions? They're literally the fetch-and-stash besties of the inode world. Let's get into it π
πΈ SYNOPSIS πΈ
like, include these first, obviously:
#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 π
so the way that getinode() and putinode() work is they give you an inode fetch-and-store API for all you libufs(3) consumers out there π. They operate on a userland UFS disk structure, no cap.
getinode()fetches the specified inode from the filesystem β like it goes and grabs it for you, iconic behavior.putinode()stores the most recently fetched inode back to the filesystem. it's giving "save your work before you close the tab" fr fr π«Ά
the dinodep union is defined like this:
union dinodep {
struct ufs1_dinode *dp1;
struct ufs2_dinode *dp2;
};
π¦ sample code (yes, the whole thing) π¦
okay this sample clears write permissions for inode number inumber stored on the filesystem described by diskp. look at her go:
#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 β¨
- both
getinode()andputinode()return0on success β slay π - or
-1if literally anything goes wrong π
a string describing the error gets stored in diskp->d_error, and the global errno often provides additional info too. so like, check both, bestie. π
π ERRORS π
getinode()may fail and seterrnofor any of the errors specified for the library functionpread(2). it can also fail if the inode number is out of the range of inodes in the filesystem β like, out of bounds, not it π©putinode()may fail and seterrnofor any of the errors specified for the library functionsufs_disk_write(3)orpwrite(2).
π and additionally, both functions may follow the libufs(3) error methodologies in case of a device error. so, y'know, be aware.
π SEE ALSO π
β HISTORY β
these functions first appeared as part of libufs(3) in FreeBSD 13.0. a moment in history honestly π₯
π AUTHORS π
Marshall Kirk McKusick <mckusick@FreeBSD.org> β the main character of this whole thing, we stan π«Άπ
π and that's the page, bestie! this one's from Debian, dated September 2, 2020 β so like, vintage but still eating π β¨
stay hydrated and always put your inode back where you found it π§π
π¦ where this page comes from
- freebsd 14.5: base 14.5
- freebsd 15.1: base 15.1
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms