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
This commit is contained in:
François Revol 2008-11-23 01:00:26 +00:00
parent ed17f94af7
commit 5b07eaa9b5
2 changed files with 40 additions and 0 deletions

View File

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

39
src/bin/badblocks.c Normal file
View File

@ -0,0 +1,39 @@
#include <stdio.h>
#include <errno.h>
#include <fcntl.h>
#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;
}