summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorphk <phk@FreeBSD.org>2007-12-16 18:02:37 +0000
committerphk <phk@FreeBSD.org>2007-12-16 18:02:37 +0000
commitf9bd6ffc2d69fbf7654c64c285fb1ad394e53d25 (patch)
tree266edbea169e3c5da7e39384e9df2a767e149eae /lib
parent6aefba3fce090a5d9bd5fe453607870b1a7e3770 (diff)
downloadFreeBSD-src-f9bd6ffc2d69fbf7654c64c285fb1ad394e53d25.zip
FreeBSD-src-f9bd6ffc2d69fbf7654c64c285fb1ad394e53d25.tar.gz
Add a berase() function which uses ioctl(DIOCGDELETE) to erase a slab
of the disk.
Diffstat (limited to 'lib')
-rw-r--r--lib/libufs/Makefile1
-rw-r--r--lib/libufs/block.c19
-rw-r--r--lib/libufs/bread.329
-rw-r--r--lib/libufs/libufs.h1
4 files changed, 42 insertions, 8 deletions
diff --git a/lib/libufs/Makefile b/lib/libufs/Makefile
index 8d1d9ac..10726e4 100644
--- a/lib/libufs/Makefile
+++ b/lib/libufs/Makefile
@@ -8,6 +8,7 @@ INCS= libufs.h
MAN= bread.3 cgread.3 libufs.3 sbread.3 ufs_disk_close.3
MLINKS+= bread.3 bwrite.3
+MLINKS+= bread.3 berase.3
MLINKS+= cgread.3 cgread1.3
MLINKS+= cgread.3 cgwrite1.3
MLINKS+= sbread.3 sbwrite.3
diff --git a/lib/libufs/block.c b/lib/libufs/block.c
index c4ff304..5450a5d 100644
--- a/lib/libufs/block.c
+++ b/lib/libufs/block.c
@@ -30,6 +30,7 @@ __FBSDID("$FreeBSD$");
#include <sys/param.h>
#include <sys/mount.h>
+#include <sys/disk.h>
#include <sys/disklabel.h>
#include <sys/stat.h>
@@ -133,3 +134,21 @@ bwrite(struct uufsd *disk, ufs2_daddr_t blockno, const void *data, size_t size)
return (cnt);
}
+
+int
+berase(struct uufsd *disk, ufs2_daddr_t blockno, ufs2_daddr_t size)
+{
+ off_t ioarg[2];
+ int rv;
+
+ ERROR(disk, NULL);
+ rv = ufs_disk_write(disk);
+ if (rv == -1) {
+ ERROR(disk, "failed to open disk for writing");
+ return(rv);
+ }
+ ioarg[0] = blockno * disk->d_bsize;
+ ioarg[1] = size;
+ rv = ioctl(disk->d_fd, DIOCGDELETE, ioarg);
+ return (rv);
+}
diff --git a/lib/libufs/bread.3 b/lib/libufs/bread.3
index 80aa921..0a9b862 100644
--- a/lib/libufs/bread.3
+++ b/lib/libufs/bread.3
@@ -31,12 +31,17 @@
.Fa "struct uufsd *disk" "ufs2_daddr_t blockno"
.Fa "const void *data" "size_t size"
.Fc
+.Ft int
+.Fo berase
+.Fa "struct uufsd *disk" "ufs2_daddr_t blockno" "ufs2_daddr_t size"
+.Fc
.Sh DESCRIPTION
The
-.Fn bread
-and
+.Fn bread ,
.Fn bwrite
-functions provide a block read and write API for
+and
+.Fn berase
+functions provide a block read, write and erase API for
.Xr libufs 3
consumers.
They operate on a userland UFS disk structure, and perform the read
@@ -50,6 +55,10 @@ and
.Fn bwrite
functions return the amount read or written, or \-1 in case of any error,
including short read.
+.Pp
+The
+.Fn berase
+function returns non-zero on error.
.Sh ERRORS
The function
.Fn bread
@@ -59,10 +68,6 @@ for any of the errors specified for the library functions
.Xr ufs_disk_write 3
or
.Xr pread 2 .
-Additionally, it may follow the
-.Xr libufs 3
-error methodologies in situations where the amount of data read
-is not equal to the amount requested, or in case of device error.
.Pp
The function
.Fn bwrite
@@ -70,7 +75,15 @@ may fail and set
.Va errno
for any of the errors specified for the library function
.Xr pwrite 2 .
-Additionally, it may follow the
+.Pp
+The function
+.Fn berase
+may fail and set
+.Va errno
+for any of the errors specified for the library function
+.Xr ioctl 2 .
+.Pp
+Additionally all three functions may follow the
.Xr libufs 3
error methodologies in situations where the amount of data written
is not equal to the amount requested, or in case of a device error.
diff --git a/lib/libufs/libufs.h b/lib/libufs/libufs.h
index 92ab348..42a64f7 100644
--- a/lib/libufs/libufs.h
+++ b/lib/libufs/libufs.h
@@ -104,6 +104,7 @@ __BEGIN_DECLS
*/
ssize_t bread(struct uufsd *, ufs2_daddr_t, void *, size_t);
ssize_t bwrite(struct uufsd *, ufs2_daddr_t, const void *, size_t);
+int berase(struct uufsd *, ufs2_daddr_t, ufs2_daddr_t);
/*
* cgroup.c
OpenPOWER on IntegriCloud