diff options
author | des <des@FreeBSD.org> | 2011-04-29 23:00:23 +0000 |
---|---|---|
committer | des <des@FreeBSD.org> | 2011-04-29 23:00:23 +0000 |
commit | e9b6a49782626401ce568d3d1e87a29ec181aed0 (patch) | |
tree | e58bb5eb7293c08ac870dd7b462cbf76cdde8ec2 /sbin/fsck_ffs/fsutil.c | |
parent | 5adbc718330a91ab900ef67c71de25f7154ab8b6 (diff) | |
download | FreeBSD-src-e9b6a49782626401ce568d3d1e87a29ec181aed0.zip FreeBSD-src-e9b6a49782626401ce568d3d1e87a29ec181aed0.tar.gz |
Add an -E option to mirror newfs's. The idea is that if you have a system
that was built before ffs grew support for TRIM, your filesystem will have
plenty of free blocks that the flash chip doesn't know are free, so it
can't take advantage of them for wear leveling. Once you've upgraded your
kernel, you enable TRIM on the filesystem (tunefs -t enable), then run
fsck_ffs -E on it before mounting it.
I tested this patch by half-filling an mdconfig'ed filesystem image,
running fsck_ffs -E on it, then verifying that the contents were not
damaged by comparing them to a pristine copy using rsync's checksum
functionality. There is no reliable way to test it on real hardware.
Many thanks to mckusick@, who provided the tricky parts of this patch and
reviewed the final version.
Reviewed by: mckusick@
MFC after: 3 weeks
Diffstat (limited to 'sbin/fsck_ffs/fsutil.c')
-rw-r--r-- | sbin/fsck_ffs/fsutil.c | 17 |
1 files changed, 16 insertions, 1 deletions
diff --git a/sbin/fsck_ffs/fsutil.c b/sbin/fsck_ffs/fsutil.c index 68d113a..85ea033 100644 --- a/sbin/fsck_ffs/fsutil.c +++ b/sbin/fsck_ffs/fsutil.c @@ -39,9 +39,10 @@ __FBSDID("$FreeBSD$"); #include <sys/time.h> #include <sys/types.h> #include <sys/sysctl.h> +#include <sys/disk.h> #include <sys/disklabel.h> +#include <sys/ioctl.h> #include <sys/stat.h> -#include <sys/disklabel.h> #include <ufs/ufs/dinode.h> #include <ufs/ufs/dir.h> @@ -421,6 +422,20 @@ blwrite(int fd, char *buf, ufs2_daddr_t blk, long size) return; } +void +blerase(int fd, ufs2_daddr_t blk, long size) +{ + off_t ioarg[2]; + + if (fd < 0) + return; + ioarg[0] = blk * dev_bsize; + ioarg[1] = size; + ioctl(fd, DIOCGDELETE, ioarg); + /* we don't really care if we succeed or not */ + return; +} + /* * Verify cylinder group's magic number and other parameters. If the * test fails, offer an option to rebuild the whole cylinder group. |