From 5b07eaa9b5859048b2e6198ff9a94051862ca1e2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Revol?= Date: Sun, 23 Nov 2008 01:00:26 +0000 Subject: [PATCH] An old tool to detect bad blocks on disk. Will need that RSN :^) Needs some spicing up. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@28722 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/bin/Jamfile | 1 + src/bin/badblocks.c | 39 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+) create mode 100644 src/bin/badblocks.c diff --git a/src/bin/Jamfile b/src/bin/Jamfile index 78188075c4..c84b457699 100644 --- a/src/bin/Jamfile +++ b/src/bin/Jamfile @@ -17,6 +17,7 @@ AddResources urlwrapper : urlwrapper.rdef ; # standard commands that don't need any additional library StdBinCommands + badblocks.c cal.c catattr.cpp chop.c diff --git a/src/bin/badblocks.c b/src/bin/badblocks.c new file mode 100644 index 0000000000..e5c2c564a8 --- /dev/null +++ b/src/bin/badblocks.c @@ -0,0 +1,39 @@ +#include +#include +#include + +#define BS 256 + +char buff[BS]; + +int main(int argc, char **argv) +{ + off_t at = 0LL; + off_t block = 0L; + int fd; + if (argc < 2) { + printf("badblocks /dev/disk/...\n"); + return 1; + } + fd = open(argv[1], O_RDONLY); + if (fd < 0) { + perror("open"); + return 1; + } + for (; ; block++, at+=BS) { + if (lseek(fd, at, SEEK_SET) < 0) { + perror("lseek"); + return 1; + } + if (read(fd, buff, BS) < BS) { + if (errno != EIO && errno != ENXIO) { + perror("read"); + return 1; + } + printf("%Ld\n", block); + fflush(stdout); + } + } + close(fd); + return 0; +}