From 51fb042070317c283395fd7170157adbbc879898 Mon Sep 17 00:00:00 2001 From: pjd Date: Tue, 31 Oct 2006 21:21:48 +0000 Subject: Implement cgwrite1(3) function which stored a given cylinder group on disk. Sponsored by: home.pl --- lib/libufs/Makefile | 1 + lib/libufs/cgread.3 | 23 +++++++++++++++++++++-- lib/libufs/cgroup.c | 14 ++++++++++++++ lib/libufs/libufs.3 | 1 + lib/libufs/libufs.h | 1 + 5 files changed, 38 insertions(+), 2 deletions(-) (limited to 'lib/libufs') diff --git a/lib/libufs/Makefile b/lib/libufs/Makefile index 855af17..8d1d9ac 100644 --- a/lib/libufs/Makefile +++ b/lib/libufs/Makefile @@ -9,6 +9,7 @@ INCS= libufs.h MAN= bread.3 cgread.3 libufs.3 sbread.3 ufs_disk_close.3 MLINKS+= bread.3 bwrite.3 MLINKS+= cgread.3 cgread1.3 +MLINKS+= cgread.3 cgwrite1.3 MLINKS+= sbread.3 sbwrite.3 MLINKS+= ufs_disk_close.3 ufs_disk_fillout.3 MLINKS+= ufs_disk_close.3 ufs_disk_fillout_blank.3 diff --git a/lib/libufs/cgread.3 b/lib/libufs/cgread.3 index f98da40..38edf17 100644 --- a/lib/libufs/cgread.3 +++ b/lib/libufs/cgread.3 @@ -4,6 +4,7 @@ .\" Manual page for libufs functions: .\" cgread(3) .\" cgread1(3) +.\" cgwrite1(3) .\" .\" This file is in the public domain. .\" @@ -13,8 +14,8 @@ .Dt CGREAD 3 .Os .Sh NAME -.Nm cgread , cgread1 -.Nd read cylinder groups of UFS disks +.Nm cgread , cgread1, cgwrite1 +.Nd read/write cylinder groups of UFS disks .Sh LIBRARY .Lb libufs .Sh SYNOPSIS @@ -28,6 +29,8 @@ .Fn cgread "struct uufsd *disk" .Ft int .Fn cgread1 "struct uufsd *disk" "int c" +.Ft int +.Fn cgwrite1 "struct uufsd *disk" "int c" .Sh DESCRIPTION The .Fn cgread @@ -60,6 +63,14 @@ with a cylinder group specifier equivalent to the value of the current field, and then incrementing the .Va d_ccg field. +.Pp +The +.Fn cgwrite1 +function stores cylinder group specified by +.Fa c +from +.Va d_cg +field of a userland UFS disk structure on disk. .Sh RETURN VALUES Both functions return 0 if there are no more cylinder groups to read, 1 if there are more cylinder groups, and \-1 on error. @@ -75,8 +86,16 @@ The function .Fn cgread1 has semantically identical failure conditions to those of .Fn cgread . +.Pp +The function +.Fn cgwrite1 +may fail and set +.Va errno +for any of the errors specified for the library function +.Xr bwrite 3 . .Sh SEE ALSO .Xr bread 3 , +.Xr bwrite 3 , .Xr libufs 3 .Sh HISTORY These functions first appeared as part of diff --git a/lib/libufs/cgroup.c b/lib/libufs/cgroup.c index d615b18..2185682 100644 --- a/lib/libufs/cgroup.c +++ b/lib/libufs/cgroup.c @@ -71,3 +71,17 @@ cgread1(struct uufsd *disk, int c) disk->d_lcg = c; return (1); } + +int +cgwrite1(struct uufsd *disk, int c) +{ + struct fs *fs; + + fs = &disk->d_fs; + if (bwrite(disk, fsbtodb(fs, cgtod(fs, c)), + disk->d_cgunion.d_buf, fs->fs_bsize) == -1) { + ERROR(disk, "unable to write cylinder group"); + return (-1); + } + return (0); +} diff --git a/lib/libufs/libufs.3 b/lib/libufs/libufs.3 index ecdfb27..6a2c7f6 100644 --- a/lib/libufs/libufs.3 +++ b/lib/libufs/libufs.3 @@ -57,6 +57,7 @@ to a string describing the error. .Xr bwrite 3 , .Xr cgread 3 , .Xr cgread1 3 , +.Xr cgwrite1 3 , .Xr sbread 3 , .Xr sbwrite 3 , .Xr ufs_disk_close 3 , diff --git a/lib/libufs/libufs.h b/lib/libufs/libufs.h index 57062f9..92ab348 100644 --- a/lib/libufs/libufs.h +++ b/lib/libufs/libufs.h @@ -110,6 +110,7 @@ ssize_t bwrite(struct uufsd *, ufs2_daddr_t, const void *, size_t); */ int cgread(struct uufsd *); int cgread1(struct uufsd *, int); +int cgwrite1(struct uufsd *, int); /* * inode.c -- cgit v1.1