1.\" Author: Marshall Kirk McKusick <mckusick@freebsd.org> 2.\" Date: January 19, 2018 3.\" Description: 4.\" Manual page for libufs functions: 5.\" getinode(3) 6.\" putinode(3) 7.\" 8.\" This file is in the public domain. 9.\" 10.\" $FreeBSD$ 11.\" 12.Dd September 2, 2020 13.Dt GETINODE 3 14.Os 15.Sh NAME 16.Nm getinode , putinode 17.Nd fetch and store inodes on a UFS file system 18.Sh LIBRARY 19.Lb libufs 20.Sh SYNOPSIS 21.In ufs/ufs/dinode.h 22.In ufs/ffs/fs.h 23.In libufs.h 24.Ft int 25.Fn getinode "struct uufsd *disk" "union dinodep *dp" "ino_t inumber" 26.Ft int 27.Fn putinode "struct uufsd *disk" 28.Sh DESCRIPTION 29The 30.Fn getinode 31and 32.Fn putinode 33functions provide an inode fetch and store API for 34.Xr libufs 3 35consumers. 36They operate on a userland UFS disk structure. 37The 38.Fn getinode 39function fetches the specified inode from the filesystem. 40The 41.Fn putinode 42function stores the most recently fetched inode to the filesystem. 43.Pp 44The 45.Va dinodep 46union is defined as: 47.Bd -literal -offset indent 48union dinodep { 49 struct ufs1_dinode *dp1; 50 struct ufs2_dinode *dp2; 51}; 52.Ed 53.Pp 54Sample code to clear write permissions for inode number 55.Fa inumber 56stored on the filesystem described by 57.Fa diskp . 58.Bd -literal -offset indent 59#include <sys/stat.h> 60#include <err.h> 61 62#include <ufs/ufs/dinode.h> 63#include <ufs/ffs/fs.h> 64#include <libufs.h> 65 66void 67clearwrite(struct uufsd *diskp, ino_t inumber) 68{ 69 union dinodep dp; 70 71 if (getinode(diskp, &dp, inumber) == -1) 72 err(1, "getinode: %s", diskp->d_error); 73 switch (diskp->d_ufs) { 74 case 1: /* UFS 1 filesystem */ 75 dp.dp1->di_mode &= ~(S_IWUSR | S_IWGRP | S_IWOTH); 76 break; 77 case 2: /* UFS 2 filesystem */ 78 dp.dp2->di_mode &= ~(S_IWUSR | S_IWGRP | S_IWOTH); 79 break; 80 default: 81 errx(1, "unknown filesystem type"); 82 } 83 if (putinode(diskp) == -1) 84 err(1, "putinode: %s", diskp->d_error); 85} 86.Ed 87.Sh RETURN VALUES 88The 89.Fn getinode 90and 91.Fn putinode 92functions return 0 on success, or \-1 in case of any error. 93A string describing the error is stored in 94.Fa diskp->d_error . 95The global 96.Fa errno 97often provides additional information. 98.Sh ERRORS 99The function 100.Fn getinode 101may fail and set 102.Va errno 103for any of the errors specified for the library function 104.Xr pread 2 . 105It can also fail if the inode number is out of the range of inodes 106in the filesystem. 107.Pp 108The function 109.Fn putinode 110may fail and set 111.Va errno 112for any of the errors specified for the library functions 113.Xr ufs_disk_write 3 114or 115.Xr pwrite 2 . 116.Pp 117Additionally both functions may follow the 118.Xr libufs 3 119error methodologies in case of a device error. 120.Sh SEE ALSO 121.Xr pread 2 , 122.Xr pwrite 2 , 123.Xr libufs 3 , 124.Xr ufs_disk_write 3 125.Sh HISTORY 126These functions first appeared as part of 127.Xr libufs 3 128in 129.Fx 13.0 . 130.Sh AUTHORS 131.An Marshall Kirk McKusick Aq Mt mckusick@FreeBSD.org 132