GETINODE(3)

πŸ“¦ version 15.1, in freebsd 14.5, freebsd 15.1

πŸ’Ύ 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() and putinode() return 0 on success β€” slay πŸ’–
  • or -1 if 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 set errno for any of the errors specified for the library function pread(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 set errno for any of the errors specified for the library functions ufs_disk_write(3) or pwrite(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