home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1992 March / Source_Code_CD-ROM_Walnut_Creek_March_1992.iso / usenet / altsrcs / 2 / 2124 < prev    next >
Encoding:
Internet Message Format  |  1990-12-28  |  8.2 KB

  1. From: src@scuzzy.in-berlin.de (Heiko Blume)
  2. Newsgroups: alt.sources
  3. Subject: little superblock editor for ISC
  4. Message-ID: <1990Nov19.164707.24512@scuzzy.in-berlin.de>
  5. Date: 19 Nov 90 16:47:07 GMT
  6.  
  7. well, i got some requests to post this. its was a hack i had to do
  8. to recover some largish filesystem :-) that might save your life...
  9. and don't tell me if it's ugly or something, it just did the job for me.
  10.  
  11. btw: does anyone know what the s_dinfo is ????
  12.      on my drives its always '1 400 0 0'. what
  13.      does that tell me? nothing!
  14.  
  15. /* The FSF GPL applies - hacked by Heiko Blume - src@scuzzy.in-berlin.de */
  16. /* BEWARE! you can really fuck up your superblock with this!! */
  17.  
  18. #include <stdio.h>
  19. #include <fcntl.h>
  20. #include <sys/types.h>
  21. #include <sys/fs/s5param.h>
  22. #include <sys/fs/s5filsys.h>
  23. #include <unistd.h>
  24.  
  25. struct filsys bla;
  26.  
  27. void display_info(special) 
  28. char *special;
  29. {
  30.     int fd;
  31.  
  32.     if((fd=open(special,O_RDONLY))==-1) {
  33.         perror("wrsup");
  34.         exit(-1);
  35.     }
  36.  
  37.     if(lseek(fd,512,0)==-1) {
  38.         perror("lseek");
  39.         exit(-2);
  40.     }
  41.  
  42.     if(read(fd,&bla,sizeof(struct filsys))!=sizeof(struct filsys)) {
  43.         perror("read");
  44.         exit(-3);
  45.     }
  46.     printf("Superblock of %s\n---------------------------------\n",special);
  47.     printf("Size of i-list in blocks (s_isize)   %u\n", bla.s_isize);
  48.     printf("Size of volume in blocks (s_fsize)   %u\n", bla.s_fsize);
  49.     printf("# of addr. in free list  (s_nfree)   %u\n", bla.s_nfree);
  50.     printf("# of inodes in           (s_ninode)  %u\n", bla.s_ninode);
  51.     printf("Free list lock           (s_flock)   %u\n", bla.s_flock);
  52.     printf("Inode list lock          (s_ilock)   %u\n", bla.s_ilock);
  53.     printf("Superblock modified flag (s_fmod)    %u\n", bla.s_fmod);
  54.     printf("Mounted read-only flag   (s_ronly)   %u\n", bla.s_ronly);
  55.     printf("Last superblock update   (s_time)    %s", ctime(&bla.s_time));
  56.     printf("Device information       (s_dinfo)   %u %u %u %u\n",
  57.         bla.s_dinfo[0], bla.s_dinfo[1], bla.s_dinfo[2], bla.s_dinfo[3]);
  58.     printf("Total free blocks        (s_tfree)   %u\n", bla.s_tfree);
  59.     printf("Total free inodes        (s_tinode)  %u\n", bla.s_tinode);
  60.     printf("File system name         (s_fname)   %s\n", bla.s_fname);
  61.     printf("File system pack name    (s_ifpack)  %s\n", bla.s_fpack);
  62.     printf("File system state        (s_state)   %x\n", bla.s_state);
  63.     printf("Magic number             (s_magic)   %x\n", bla.s_magic);
  64.     printf("File system type         (s_type)    %u\n", bla.s_type);
  65.     close(fd);
  66. }
  67.  
  68. void change_info(special)
  69. char *special;
  70. {
  71.     int fd;
  72.     unsigned long val;
  73.     char option[20];
  74.     char tmp[20];
  75.  
  76.     if((fd=open(special,O_RDWR))==-1) {
  77.         perror("wrsup");
  78.         exit(-1);
  79.     }
  80.  
  81.     if(lseek(fd,512,0)==-1) {
  82.         perror("lseek");
  83.         exit(-2);
  84.     }
  85.  
  86.     if(read(fd,&bla,sizeof(struct filsys))!=sizeof(struct filsys)) {
  87.         perror("read");
  88.         exit(-3);
  89.     }
  90.  
  91.     printf("Well! which info do you want to change ?\n");
  92.     printf("1  - isize    2  - fsize    3  - nfree    4  - ninode\n");
  93.     printf("5  - flock    6  - ilock    7  - fmod    8  - ronly\n");
  94.     printf("9  - time    10 - dinfo    11 - tfree    12 - tinode\n");
  95.     printf("13 - fname    14 - fpack    15 - state    16 - magic\n");
  96.     printf("17 - type\n");
  97.     printf("99 - exit\n");
  98.  
  99.     gets(option);
  100.     if(strcmp(option,"99")==0) return;
  101.  
  102.     if(strcmp(option,"1")==0) {
  103.         printf("Current value of isize is %u\n", bla.s_isize);
  104.         printf("Enter new value ->");
  105.         fflush(stdout);
  106.         scanf("%u",&val);
  107.         bla.s_isize = (ushort) val;
  108.         printf("New value is %u\n",bla.s_isize);
  109.     }
  110.     if(strcmp(option,"2")==0) {
  111.         printf("Current value of fsize is %u\n", bla.s_fsize);
  112.         printf("Enter new value ->");
  113.         fflush(stdout);
  114.         scanf("%u",&val);
  115.         bla.s_fsize=(daddr_t) val;
  116.         printf("New value is %u\n",bla.s_fsize);
  117.     }
  118.     if(strcmp(option,"3")==0) {
  119.         printf("Current value of nfree is %u\n", bla.s_nfree);
  120.         printf("Enter new value ->");
  121.         fflush(stdout);
  122.         scanf("%u",&val);
  123.         bla.s_nfree=(short) val;
  124.         printf("New value is %u\n",bla.s_nfree);
  125.     }
  126.     if(strcmp(option,"4")==0) {
  127.         printf("Current value of ninode is %u\n", bla.s_ninode);
  128.         printf("Enter new value ->");
  129.         fflush(stdout);
  130.         scanf("%u",&val);
  131.         bla.s_ninode=(short)val;
  132.         printf("New value is %u\n",bla.s_ninode);
  133.     }
  134.     if(strcmp(option,"5")==0) {
  135.         printf("Current value of flock is %u\n", bla.s_flock);
  136.         printf("Enter new value ->");
  137.         fflush(stdout);
  138.         scanf("%u",&val);
  139.         bla.s_flock=(char)val;
  140.         printf("New value is %u\n",bla.s_flock);
  141.     }
  142.     if(strcmp(option,"6")==0) {
  143.         printf("Current value of ilock is %u\n", bla.s_ilock);
  144.         printf("Enter new value ->");
  145.         fflush(stdout);
  146.         scanf("%u",&val);
  147.         bla.s_ilock=(char)val;
  148.         printf("New value is %u\n",bla.s_ilock);
  149.     }
  150.     if(strcmp(option,"7")==0) {
  151.         printf("Current value of fmod is %u\n", bla.s_fmod);
  152.         printf("Enter new value ->");
  153.         fflush(stdout);
  154.         scanf("%u",&val);
  155.         bla.s_fmod=(char)val;
  156.         printf("New value is %u\n",bla.s_fmod);
  157.     }
  158.     if(strcmp(option,"8")==0) {
  159.         printf("Current value of ronly is %u\n", bla.s_ronly);
  160.         printf("Enter new value ->");
  161.         fflush(stdout);
  162.         scanf("%u",&val);
  163.         bla.s_ronly=(char)val;
  164.         printf("New value is %u\n",bla.s_ronly);
  165.     }
  166.     if(strcmp(option,"9")==0) {
  167.         char Time[40];
  168.         printf("Current value of time is %u\n", bla.s_time);
  169.         printf("Enter new value ->");
  170.         fflush(stdout);
  171.         scanf("%s",&Time);
  172.     }
  173.     if(strcmp(option,"10")==0) {
  174.         int i;
  175.         printf("Current values of dinfo is %u %u %u %u\n",
  176.          bla.s_dinfo[0], bla.s_dinfo[1], bla.s_dinfo[2], bla.s_dinfo[3]);
  177.         for(i=0;i<4;i++) {
  178.             printf("Enter new value for dinfo[%d]->",i);
  179.             fflush(stdout);
  180.             scanf("%u",&val);
  181.             bla.s_dinfo[i]=(short)val;
  182.         }
  183.         printf("New values of dinfo is %u %u %u %u\n",
  184.          bla.s_dinfo[0], bla.s_dinfo[1], bla.s_dinfo[2], bla.s_dinfo[3]);
  185.     }
  186.     if(strcmp(option,"11")==0) {
  187.         printf("Current value of tfree is %u\n", bla.s_tfree);
  188.         printf("Enter new value ->");
  189.         fflush(stdout);
  190.         scanf("%u",&val);
  191.         bla.s_tfree=(daddr_t)val;
  192.         printf("New value is %u\n",bla.s_tfree);
  193.     }
  194.     if(strcmp(option,"12")==0) {
  195.         printf("Current value of tinode is %u\n", bla.s_tinode);
  196.         printf("Enter new value ->");
  197.         fflush(stdout);
  198.         scanf("%u",&val);
  199.         bla.s_tinode=(ushort)val;
  200.         printf("New value is %u\n",bla.s_tinode);
  201.     }
  202.     if(strcmp(option,"13")==0) {
  203.         printf("Current value of fname is %s\n", bla.s_fname);
  204.         printf("Enter new value (6 chars max!) ->");
  205.         fflush(stdout);
  206.         scanf("%s",&tmp);
  207.         strncpy(bla.s_fname,tmp,6);
  208.         printf("New value is %s\n",bla.s_fname);
  209.     }
  210.     if(strcmp(option,"14")==0) {
  211.         printf("Current value of fpack is %s\n", bla.s_fpack);
  212.         printf("Enter new value (6 chars max!) ->");
  213.         fflush(stdout);
  214.         scanf("%s",&tmp);
  215.         strncpy(bla.s_fpack,tmp,6);
  216.         printf("New value is %s\n",bla.s_fpack);
  217.     }
  218.     if(strcmp(option,"15")==0) {
  219.         printf("Current value of state is %x\n", bla.s_state);
  220.         printf("Enter new value ->");
  221.         fflush(stdout);
  222.         scanf("%lx",&bla.s_state);
  223.         printf("New value is %x\n",bla.s_state);
  224.     }
  225.     if(strcmp(option,"16")==0) {
  226.         printf("Current value of magic is %x\n", bla.s_magic);
  227.         printf("Enter new value ->");
  228.         fflush(stdout);
  229.         scanf("%lx",&bla.s_magic);
  230.         printf("New value is %x\n",bla.s_magic);
  231.     }
  232.     if(strcmp(option,"17")==0) {
  233.         printf("Current value of type is %u\n", bla.s_type);
  234.         printf("Enter new value ->");
  235.         fflush(stdout);
  236.         scanf("%lu",&bla.s_type);
  237.         printf("New value is %u\n",bla.s_type);
  238.     }
  239.  
  240.     printf("OK, do you really want to write the modified superblock ???\n");
  241.     printf("Enter 'YES' if you want to do it! ->");
  242.     fflush(stdout);
  243.     scanf("%s",&tmp);
  244.     if(strcmp(tmp,"YES")==0) {
  245.         if(lseek(fd,512,0)==-1) {
  246.             perror("wrsup");
  247.             exit(-4);
  248.         }
  249.         if(write(fd,&bla,sizeof(struct filsys))
  250.             !=sizeof(struct filsys)) {
  251.             perror("wrsup (PANIC!)");
  252.             exit(-5);
  253.         }
  254.     printf("Done.\n");
  255.     }
  256.     else printf("Superblock not written...\n");
  257.  
  258.     close(fd);
  259. }
  260.  
  261. void menu() {
  262.     printf("\nd - display superblock info\n");
  263.     printf("c - change superblock info\n");
  264.     printf("e - exit\n");
  265. }
  266.  
  267. main(argc,argv)
  268. int argc;
  269. char **argv;
  270. {
  271.     char option[20];
  272.  
  273.     if(argc != 2) {
  274.         printf("usage: wrsup <special of fs>\n");
  275.         exit(1);
  276.     }
  277.  
  278.     menu();
  279.     for(;;) {
  280.         gets(option);
  281.         switch(option[0]) {
  282.             case 'd': display_info(argv[1]); break;
  283.             case 'c': change_info(argv[1]); break;
  284.             case 'e': exit(); break;
  285.             default: menu();
  286.         }    
  287.             
  288.     }
  289. }
  290. -- 
  291.       Heiko Blume <-+-> src@scuzzy.in-berlin.de <-+-> (+49 30) 691 88 93
  292.                     public source archive [HST V.42bis]:
  293.         scuzzy Any ACU,f 38400 6919520 gin:--gin: nuucp sword: nuucp
  294.                      uucp scuzzy!/src/README /your/home
  295.