Add a berase() function which uses ioctl(DIOCGDELETE) to erase a slab

of the disk.
This commit is contained in:
Poul-Henning Kamp 2007-12-16 18:02:37 +00:00
parent 2ec43f35f4
commit 20a0f65b77
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=174668
4 changed files with 42 additions and 8 deletions

View File

@ -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

View File

@ -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);
}

View File

@ -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.

View File

@ -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