Add a berase() function which uses ioctl(DIOCGDELETE) to erase a slab
of the disk.
This commit is contained in:
parent
2ec43f35f4
commit
20a0f65b77
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=174668
@ -8,6 +8,7 @@ INCS= libufs.h
|
|||||||
|
|
||||||
MAN= bread.3 cgread.3 libufs.3 sbread.3 ufs_disk_close.3
|
MAN= bread.3 cgread.3 libufs.3 sbread.3 ufs_disk_close.3
|
||||||
MLINKS+= bread.3 bwrite.3
|
MLINKS+= bread.3 bwrite.3
|
||||||
|
MLINKS+= bread.3 berase.3
|
||||||
MLINKS+= cgread.3 cgread1.3
|
MLINKS+= cgread.3 cgread1.3
|
||||||
MLINKS+= cgread.3 cgwrite1.3
|
MLINKS+= cgread.3 cgwrite1.3
|
||||||
MLINKS+= sbread.3 sbwrite.3
|
MLINKS+= sbread.3 sbwrite.3
|
||||||
|
@ -30,6 +30,7 @@ __FBSDID("$FreeBSD$");
|
|||||||
|
|
||||||
#include <sys/param.h>
|
#include <sys/param.h>
|
||||||
#include <sys/mount.h>
|
#include <sys/mount.h>
|
||||||
|
#include <sys/disk.h>
|
||||||
#include <sys/disklabel.h>
|
#include <sys/disklabel.h>
|
||||||
#include <sys/stat.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);
|
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);
|
||||||
|
}
|
||||||
|
@ -31,12 +31,17 @@
|
|||||||
.Fa "struct uufsd *disk" "ufs2_daddr_t blockno"
|
.Fa "struct uufsd *disk" "ufs2_daddr_t blockno"
|
||||||
.Fa "const void *data" "size_t size"
|
.Fa "const void *data" "size_t size"
|
||||||
.Fc
|
.Fc
|
||||||
|
.Ft int
|
||||||
|
.Fo berase
|
||||||
|
.Fa "struct uufsd *disk" "ufs2_daddr_t blockno" "ufs2_daddr_t size"
|
||||||
|
.Fc
|
||||||
.Sh DESCRIPTION
|
.Sh DESCRIPTION
|
||||||
The
|
The
|
||||||
.Fn bread
|
.Fn bread ,
|
||||||
and
|
|
||||||
.Fn bwrite
|
.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
|
.Xr libufs 3
|
||||||
consumers.
|
consumers.
|
||||||
They operate on a userland UFS disk structure, and perform the read
|
They operate on a userland UFS disk structure, and perform the read
|
||||||
@ -50,6 +55,10 @@ and
|
|||||||
.Fn bwrite
|
.Fn bwrite
|
||||||
functions return the amount read or written, or \-1 in case of any error,
|
functions return the amount read or written, or \-1 in case of any error,
|
||||||
including short read.
|
including short read.
|
||||||
|
.Pp
|
||||||
|
The
|
||||||
|
.Fn berase
|
||||||
|
function returns non-zero on error.
|
||||||
.Sh ERRORS
|
.Sh ERRORS
|
||||||
The function
|
The function
|
||||||
.Fn bread
|
.Fn bread
|
||||||
@ -59,10 +68,6 @@ for any of the errors specified for the library functions
|
|||||||
.Xr ufs_disk_write 3
|
.Xr ufs_disk_write 3
|
||||||
or
|
or
|
||||||
.Xr pread 2 .
|
.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
|
.Pp
|
||||||
The function
|
The function
|
||||||
.Fn bwrite
|
.Fn bwrite
|
||||||
@ -70,7 +75,15 @@ may fail and set
|
|||||||
.Va errno
|
.Va errno
|
||||||
for any of the errors specified for the library function
|
for any of the errors specified for the library function
|
||||||
.Xr pwrite 2 .
|
.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
|
.Xr libufs 3
|
||||||
error methodologies in situations where the amount of data written
|
error methodologies in situations where the amount of data written
|
||||||
is not equal to the amount requested, or in case of a device error.
|
is not equal to the amount requested, or in case of a device error.
|
||||||
|
@ -104,6 +104,7 @@ __BEGIN_DECLS
|
|||||||
*/
|
*/
|
||||||
ssize_t bread(struct uufsd *, ufs2_daddr_t, void *, size_t);
|
ssize_t bread(struct uufsd *, ufs2_daddr_t, void *, size_t);
|
||||||
ssize_t bwrite(struct uufsd *, ufs2_daddr_t, const 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
|
* cgroup.c
|
||||||
|
Loading…
Reference in New Issue
Block a user