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