Welcome to the Reiser4 Wiki, the Wiki for users and developers of the ReiserFS and Reiser4 filesystems.
For now, most of the documentation is just a snapshot of the old Namesys site (archive.org, 2007-09-29).
There was also a Reiser4 Wiki (archive.org, 2007-07-06) once on pub.namesys.com.
FAQ/bad-block-handling/reiserfs-add-badblock.c
From Reiser4 FS Wiki
/* -*- C -*- */ /* * reiserfs-add-badblock.c * Copyright: probably Vitaly Fertman <vitaly@namesys.com> */ #include <stdio.h> #include <unistd.h> #include <fcntl.h> #include <string.h> #include <errno.h> /* kludge to avoid including kernel headers */ /* from include/asm-i386/ioctl.h */ #define _IOC_NRBITS 8 #define _IOC_TYPEBITS 8 #define _IOC_SIZEBITS 14 #define _IOC_DIRBITS 2 #define _IOC_NRSHIFT 0 #define _IOC_TYPESHIFT (_IOC_NRSHIFT+_IOC_NRBITS) #define _IOC_SIZESHIFT (_IOC_TYPESHIFT+_IOC_TYPEBITS) #define _IOC_DIRSHIFT (_IOC_SIZESHIFT+_IOC_SIZEBITS) #define _IOC_WRITE 1U #define _IOC(dir,type,nr,size) \ (((dir) << _IOC_DIRSHIFT) | \ ((type) << _IOC_TYPESHIFT) | \ ((nr) << _IOC_NRSHIFT) | \ ((size) << _IOC_SIZESHIFT)) #define _IOW(type,nr,size) _IOC(_IOC_WRITE,(type),(nr),sizeof(size)) #define REISERFS_IOC_USED _IOW(0xCD,2,long) #define REISERFS_IOC_FREE _IOW(0xCD,3,long) #define REISERFS_IOC_BADCNT _IOW(0xCD,4,long) int main( int argc, char **argv ) { int return_code; return_code = 1; if( argc == 4 ) { int fd; fd = open( argv[ 1 ], O_RDONLY ); if( fd != -1 ) { unsigned long blocknr; char *end_ptr; blocknr = strtoul( argv[ 2 ], &end_ptr, 0 ); if( *end_ptr == 0 ) { int cmd; cmd = 0; if( !strcmp( argv[ 3 ], "free" ) ) { cmd = REISERFS_IOC_FREE; } else if( !strcmp( argv[ 3 ], "used" ) ) { cmd = REISERFS_IOC_USED; } else if( !strcmp( argv[ 3 ], "set" ) ) { cmd = REISERFS_IOC_BADCNT; } else { fprintf( stderr, "%s: third argument `%s' is neither \"free\" " "nor \"used\" or \"set\"", argv[ 0 ], argv[ 3 ] ); } if( cmd != 0 ) { if( ioctl( fd, cmd, blocknr ) == -1 ) { fprintf( stderr, "%s: ioctl: %s\n", argv[ 0 ], strerror( errno ) ); } else { return_code = 0; } } } else { fprintf( stderr, "%s: `%s' is not valid unsigned long integer\n", argv[ 0 ], argv[ 2 ] ); } } else { fprintf( stderr, "%s: cannot open `%s': %s\n", argv[ 0 ], argv[ 1 ], strerror( errno ) ); } } else { fprintf( stderr, "Usage: %s path blocknr free|used|set\n", argv[ 0 ] ); } return return_code; }