View Single Post

   
  #7 (permalink)  
Old 01-05-2008, 03:06 AM
Ken Bell
 
Posts: n/a
Default Re: fsck does not fix the drive

In article <d25006a5.0408230225.44a83545@posting.google.com >,
vicebay <vsebay@edsamail.com> wrote:
>It's running in AIX 4.3.3. How do I manually fix it?


Included below is what I used back in the days of 4.1 .. it dumps
out the contents of superblocks #1 and #2, and if you're satisfied
with what you see, allows you to rewrite #1 by specifying the
"--copysb2tosb1" option.

As always, this carries no warranty - you use it at your own risk.
Please read and verify the code for yourself before you run it.


/*
* super.c
*
* Compare and optionally rewrite superblock 2 to superblock 1
*
* Ken Bell / kenbell@panix.com
*
*/
#include <unistd.h>
#include <stdio.h>
#include <string.h>
#include <fcntl.h>
#include <time.h>
#include <sys/filsys.h>
#include <sys/fstypes.h>
int main(int argc, char *argv[])
{
struct superblock sb0, sb1;
int fd;

off_t block[2] = {4096, 31*4096}; /* primary and secondary superblocks */
int magic0, magic1;
char time0[80], time1[80];
char *valid[2] = {"Not Valid", "Valid"};

char *copysb2tosb1 = "--copysb2tosb1", rewritesuperblock, *devicename;

if (argc < 2) {
printf("Usage: %s [ %s ] /dev/filesystemname\n",argv[0],copysb2tosb1);
exit(1);
}
if (strncmp(argv[1],copysb2tosb1,strlen(copysb2tosb1)) == 0) {
rewritesuperblock = 1;
devicename = argv[2];
}
else {
rewritesuperblock = 0;
devicename = argv[1];
}

printf(" Filesystem \"%s\":\n",devicename);

if ((fd=open(devicename,O_RDWR)) == -1) {
perror("open");
exit(1);
}

if (lseek(fd,block[0],SEEK_SET) == -1) {
perror("lseek.1");
exit(1);
}
if (read(fd,&sb0,(sizeof sb0)) != (sizeof sb0)) {
perror("read.1");
exit(1);
}

if (lseek(fd,block[1],SEEK_SET) == -1) {
perror("lseek.2");
exit(1);
}
if (read(fd,&sb1,(sizeof sb1)) != (sizeof sb1)) {
perror("read.2");
exit(1);
}

if (rewritesuperblock == 1) {
sb0.s_logserial = 0;
sb0.s_logdev = 0xffffffff;
if (lseek(fd,block[0],SEEK_SET) == -1) {
perror("lseek.1B");
exit(1);
}
if (write(fd,&sb0,(sizeof sb0)) != (sizeof sb0)) {
perror("write.1");
exit(1);
}
printf("Rewrote superblock #1\n");
}

magic0 = (strncmp(sb0.s_magic,fsv3magic,4)==0);
#ifdef AIX4
if (!magic0)
magic0 = (strncmp(sb0.s_magic,fsv3pmagic,4)==0);
#endif
magic1 = (strncmp(sb0.s_magic,fsv3magic,4)==0);
#ifdef AIX4
if (!magic1)
magic1 = (strncmp(sb0.s_magic,fsv3pmagic,4)==0);
#endif

printf("\n Superblock #1\t\t\tSuperblock #2\n");
printf( " -------------\t\t\t-------------\n");

printf(" magic = %x%x%x%x (%s)\t\t\t%x%x%x%x (%s)\n",
sb0.s_magic[0],sb0.s_magic[1],sb0.s_magic[2],sb0.s_magic[3],valid[magic0],
sb1.s_magic[0],sb1.s_magic[1],sb1.s_magic[2],sb1.s_magic[3],valid[magic1]);

printf(" flag = %2.2x%2.2x%2.2x%2.2x\t\t\t\t%2.2x%2.2x%2.2x%2.2x\n ",
sb0.s_flag[0],sb0.s_flag[1],sb0.s_flag[2],sb0.s_flag[3],
sb1.s_flag[0],sb1.s_flag[1],sb1.s_flag[2],sb1.s_flag[3]);

printf(" agsize = %d\t\t\t\t%d\n",sb0.s_agsize,sb1.s_agsize);
printf(" logserial = %d\t\t\t\t\t%d\n",sb0.s_logserial,sb1.s_logserial) ;
printf(" fsize = %ld\t\t\t\t%ld\n",sb0.s_fsize,sb1.s_fsize);
printf(" bsize = %d\t\t\t\t%d\n",sb0.s_bsize,sb1.s_bsize);
printf(" spare = %d (unused)\t\t\t%d (unused)\n",sb0.s_spare,sb1.s_spare);

if (magic0)
printf(" fname = %6.6s\t\t\t\t",sb0.s_fname);
else
printf(" fname = (?)\t\t\t\t");
if (magic1)
printf("%6.6s\n",sb1.s_fname);
else
printf("(?)\n");
if (magic0)
printf(" fpack = %6.6s\t\t\t\t",sb0.s_fpack);
else
printf(" fname = (?)\t\t\t\t");
if (magic1)
printf("%6.6s\n",sb1.s_fpack);
else
printf("(?)\n");

printf(" logdev = %4.4x\t\t\t\t%4.4x\n",sb0.s_logdev,sb1.s_logdev);
printf(" fmod = %x\t\t\t\t\t%x\n",sb0.s_fmod,sb1.s_fmod);
printf(" ronly = %x\t\t\t\t\t%x\n",sb0.s_ronly,sb1.s_ronly);

strncpy(time0,ctime(&sb0.s_time),sizeof time0);
strncpy(time1,ctime(&sb1.s_time),sizeof time1);
time0[strlen(time0) - 1] = 0;
time1[strlen(time1) - 1] = 0;
printf(" time = %4.4x\t\t\t\t%4.4x\n",sb0.s_time,sb1.s_time);
printf(" (%s)\t(%s)\n",time0,time1);

printf("%s%s\n"," --------------------------------------",
"---------------------------------------");
exit(0);
}

--
Ken Bell :: kenbell@panix.com :: (212) 475-4976 (voice)
Reply With Quote