home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #16 / NN_1992_16.iso / spool / de / comp / os / unix / 1304 < prev    next >
Encoding:
Text File  |  1992-07-26  |  12.4 KB  |  439 lines

  1. Path: sparky!uunet!darwin.sura.net!Sirius.dfn.de!zrz.tu-berlin.de!news.netmbx.de!Germany.EU.net!unido!news.Hamburg.Germany.EU.net!oops!fs
  2. From: fs@oops.zigzag.hanse.de (Frank Seitz @ home)
  3. Newsgroups: de.comp.os.unix
  4. Subject: Re: HILFE: Daten retten von einer unmountable Disk ?
  5. Keywords: System kapput.
  6. Message-ID: <1992Jul26.143059.5512@oops.zigzag.hanse.de>
  7. Date: 26 Jul 92 14:30:59 GMT
  8. References: <1992Jul23.123336.10381@chamber.in-berlin.de>
  9. Organization: OOPS (Netzwerke/Datenbanksysteme/Sprachverarbeitung)
  10. Lines: 427
  11.  
  12. root@chamber.in-berlin.de (Patrick Wendt) writes:
  13.  
  14. ()Vor einigen Tagen hat mir wohl ein defekter Controller die ersten
  15. ()beiden meiner Platten (ESDI) verstoert, soll heissen, er hat es
  16. ()fuer notwendig befunden, einige Bad-Sectors strategisch guenstig
  17. ()in den Boot-Block, diverse Superblocks, etc. zu schreiben ...
  18.  
  19. ()Leider befanden sich gerade auf diesen Platten sowohl das
  20. ()ROOT-Filesystem als auch /usr. - Da auf /usr noch diverse Daten
  21. ()liegen (vielleicht :-<), insbesondere /usr/mail/*, waere ich
  22. ()daran interessiert zu wissen, ob es IRGENDEINE Moeglichkeit
  23. ()gibt, an selbige ranzukommen ?!
  24.  
  25. Je nach Zustand des Filesystems kann das kompliziert
  26. bis unmoeglich sein. Wenn "nur" der Superblock
  27. zernagelt ist, kannst Du folgendes versuchen:
  28.  
  29.     1. Mit /etc/ncheck die Inode-Nummern
  30.        der Dich interessierenden Files bestimmen. Gebrauch
  31.        siehe Man-Page.
  32.     2. Mit fslook (anbei) die den Inodes zugeordneten
  33.        Daten (Files) selektiv vom nicht-mountbaren Filesystem
  34.        herunterkopieren.
  35.  
  36. Eine intimere Kenntnis der Filesystem-Struktur (es geht hier um System V,
  37. wenn ich nicht irre) kann von Nutzen sein. Literatur (z.B.):
  38.  
  39. Haviland, Keith; Salama, Ben; 1987; "Unix System Programming";
  40.     Addison-Wesley; pp 77-85.
  41.  
  42. Bach, Maurice J.; "The Design of the Unix Operating System";
  43.     Prentice Hall; pp 60-74.
  44.  
  45. Anbei fslook. Sind weniger als 10k und sicher auch fuer manch
  46. anderen interessant. Schliesslich crasht es frueher oder spaeter
  47. bei jedem mal ;-)
  48.  
  49. #!/bin/sh
  50. # This is a shell archive (produced by shar 3.49)
  51. # To extract the files from this archive, save it to a file, remove
  52. # everything above the "!/bin/sh" line above, and type "sh file_name".
  53. #
  54. # made 07/26/1992 14:11 UTC by root@oops
  55. # Source directory /usr/tmp/fslook
  56. #
  57. # existing files will NOT be overwritten unless -c is specified
  58. #
  59. # This shar contains:
  60. # length  mode       name
  61. # ------ ---------- ------------------------------------------
  62. #   3618 -rw-rw-r-- POSTER
  63. #   5525 -rw-rw-r-- fslook.c
  64. #
  65. # ============= POSTER ==============
  66. if test -f 'POSTER' -a X"$1" != X"-c"; then
  67.     echo 'x - skipping POSTER (File already exists)'
  68. else
  69. echo 'x - extracting POSTER (Text)'
  70. sed 's/^X//' << 'SHAR_EOF' > 'POSTER' &&
  71. Path: oops!abqhh!mcshh!unido!mcsun!uunet!snorkelwacker.mit.edu!bloom-picayune.mit.edu!athena.mit.edu!jik
  72. XFrom: jik@athena.mit.edu (Jonathan I. Kamens)
  73. Newsgroups: alt.sources
  74. Subject: [comp.unix.internals] Generating files from inodes (Was Re: BSD inodes vs. SYSV inodes?)
  75. Message-ID: <1991Dec31.193457.4903@athena.mit.edu>
  76. Date: 31 Dec 91 19:34:57 +0100
  77. Article-I.D.: athena.1991Dec31.193457.4903
  78. Sender: news@athena.mit.edu (News system)
  79. Followup-To: alt.sources.d
  80. Organization: Massachusetts Institute of Technology
  81. Lines: 354
  82. Nntp-Posting-Host: pit-manager.mit.edu
  83. X
  84. Archive-name: fslook/part01
  85. Submitted-by: root@candle.uucp (Bruce Momjian)
  86. X
  87. Article: 4209 of comp.unix.internals
  88. Path: bloom-picayune.mit.edu!mintaka.lcs.mit.edu!yale!yale.edu!qt.cs.utexas.edu!zaphod.mps.ohio-state.edu!unix.cis.pitt.edu!gvlf3.gvl.unisys.com!lgnp1.ls.com!candle!root
  89. XFrom: root@candle.uucp (Bruce Momjian)
  90. Newsgroups: comp.unix.internals
  91. Subject: Generating files from inodes (Was Re: BSD inodes vs. SYSV inodes?)
  92. Keywords: direct blocks, indirect blocks, fragments
  93. Message-ID: <1991Dec31.034942.5936@candle.uucp>
  94. Date: 31 Dec 91 03:49:42 GMT
  95. References: <1991Dec17.151027.26915@candle.uucp> <11470@auspex-gw.auspex.com> <1991Dec27.092639.18130@wlbr.imsd.contel.com>
  96. Organization: private system
  97. Lines: 333
  98. X
  99. [Note:  I am cross-posting to comp.unix.admin because this program may
  100. be useful in restoring files from corrupted System V file systems. ]
  101. X
  102. Two weeks ago, I posted a program that generated a file's contents from
  103. an inode number and file system device file, using the block numbers
  104. stored in the inode.  Unfortunately, I have discovered a bug in the
  105. handling of the 2nd and 3rd indirect blocks.  I am reposting the entire
  106. program.  I don't have a copy of the original posted source code.
  107. X
  108. I have now tested the program on every file on my system, as well as
  109. one sparse file to test triple indirection.  The new program uses
  110. l3tol, as recommended by several posters.  It now allows the start byte
  111. and length to be optional, and if they are not provided, the entire
  112. file is piped to the standard output.
  113. The program was designed on AT&T 386 Unix SVr3.1, but should work on
  114. SVr3.2 or earlier System V(?).  To test it on your /usr file system,
  115. try this: 
  116. X
  117. cd /usr
  118. ncheck -a /dev/usr | grep -v 'FIFO' | grep -v '/dev/' | while read LINE
  119. do
  120. X    echo "$LINE"
  121. X    fslook /dev/usr `echo "$LINE" | cut -d\      -f1` | \
  122. X        cmp -s - /usr/`echo "$LINE" | cut -d\     -f2` 
  123. X    [ "$?" -ne 0 ] && echo "$LINE" >>/tmp/usr.bad
  124. done
  125. X
  126. It will display each file as it tests it, and put the bad ones in the
  127. file /tmp/usr.bad.
  128. X
  129. For administrators, this program could be used to recover files from a
  130. file system whose super block is trashed, or whose directory structure
  131. is messed up.  For best recovery, you should have a copy of a recent
  132. "ncheck" for each file system, as well as an "ls -liR" for file
  133. ownership and file modes.  Obviously, if you keep those files only on
  134. the file system that was trashed, you will not be able to get at them
  135. easily. 
  136. X
  137. My apologies for initially submitting a buggy program.  I should have
  138. checked it better.  Also, my apologies for those of you in
  139. comp.unix.internals who are tired of hearing about this trivial program
  140. I wrote. :-)
  141. X
  142. I have assumed this program is too trivial to be posted to a source
  143. group.  I figured, if it was generally useful, someone would have
  144. already posted it.  Please e-mail your opinions of this decision.
  145. X
  146. [...]
  147. -- 
  148. Jonathan Kamens                        jik@MIT.Edu
  149. MIT Information Systems/Athena            Moderator, news.answers
  150. X          (Send news.answers-related correspondence
  151. X          to news-answers-request@MIT.Edu.)
  152. SHAR_EOF
  153. chmod 0664 POSTER ||
  154. echo 'restore of POSTER failed'
  155. Wc_c="`wc -c < 'POSTER'`"
  156. test 3618 -eq "$Wc_c" ||
  157.     echo 'POSTER: original size 3618, current size' "$Wc_c"
  158. fi
  159. # ============= fslook.c ==============
  160. if test -f 'fslook.c' -a X"$1" != X"-c"; then
  161.     echo 'x - skipping fslook.c (File already exists)'
  162. else
  163. echo 'x - extracting fslook.c (Text)'
  164. sed 's/^X//' << 'SHAR_EOF' > 'fslook.c' &&
  165. /*************************************************************************
  166. **
  167. ** fslook.c - displays data from a file given it's inode
  168. **    by Bruce Momjian ( root%candle.uucp@ls.com )
  169. **
  170. **************************************************************************/
  171. X
  172. #include <stdio.h>
  173. #include <malloc.h>
  174. #include <unistd.h>
  175. #include <signal.h>
  176. #include <ctype.h>
  177. #include <sys/types.h>
  178. #include <fcntl.h>
  179. #include <sys/fs/s5param.h>        /* for INOPB */
  180. #include <sys/ino.h>            /* for dinode structure */
  181. #include <errno.h>
  182. X
  183. #define USAGE         fprintf(stderr,\
  184. X                            "Usage: %s file_system_device inode_number [start_byte] [length]\n",argv[0]);
  185. X
  186. X                        /* assumes 3 bytes per disk block address in inode */
  187. #define INOBLOCK(b,n)    ( l3block( (b) + (n) * 3 ) ) 
  188. X                        /* assumes 4 bytes per disk block address in inode */
  189. #define INDBLOCK(b,n)    ( *(long *)((b) + (n) * 4) )    
  190. X
  191. #ifndef BSIZE
  192. #define BSIZE     1024    /* block size in bytes */
  193. #endif
  194. X
  195. #ifndef INOPB
  196. #define    INOPB    (BSIZE / sizeof(dinode))
  197. #endif
  198. X
  199. long l3block();
  200. X
  201. int main(argc,argv)
  202. int argc;
  203. char *argv[];
  204. {
  205. X    int curquit(),
  206. X        offset,
  207. X        infd;
  208. X
  209. X    unsigned inode_num;
  210. X
  211. X    unsigned long start,
  212. X         length;
  213. X
  214. X    unsigned char     *buf;
  215. X    char             *badchar;
  216. X
  217. X    struct dinode *ino;
  218. X    
  219. X    if ( argc < 3 || argc > 5 )
  220. X    {
  221. X        USAGE;
  222. X        exit(1);
  223. X    }
  224. X
  225. X    if ( (infd = open(argv[1],O_RDONLY)) == -1)
  226. X    {
  227. X        perror("Can not open device file");
  228. X        exit(1);
  229. X    }
  230. X
  231. X    buf = (unsigned char *) malloc(BSIZE); 
  232. X    if ( buf == NULL)
  233. X    {
  234. X        fputs("No memory\n", stderr);
  235. X        exit(1);
  236. X    }
  237. X
  238. X    inode_num = strtol(argv[2],&badchar, 0);
  239. X    if (*badchar != '\0')
  240. X    {
  241. X        fputs("Invalid inode number.\n", stderr);
  242. X        USAGE;
  243. X        exit(1);
  244. X    }
  245. X
  246. X    if (argc >=4)
  247. X    {
  248. X        start = strtol(argv[3],&badchar, 0);
  249. X        if (*badchar != '\0')
  250. X        {
  251. X            fputs("Invalid start byte.\n", stderr);
  252. X            USAGE;
  253. X            exit(1);
  254. X        }
  255. X    }
  256. X    else
  257. X        start = 0;
  258. X        
  259. X    if (argc >=5)
  260. X    {
  261. X        length = strtol(argv[4],&badchar, 0);
  262. X        if (*badchar != '\0')
  263. X        {
  264. X            fputs("Invalid length byte.\n", stderr);
  265. X            USAGE;
  266. X            exit(1);
  267. X        }
  268. X    }
  269. X    else
  270. X    {
  271. X        get_inode(infd, inode_num, &ino, buf);
  272. X        length = ino->di_size;
  273. X    }        
  274. X    
  275. X    signal(SIGINT, curquit);
  276. X        
  277. X    while (length > 0)
  278. X    {
  279. X        if (start / BSIZE == (start + length - 1) / BSIZE)
  280. X            offset = length;
  281. X        else
  282. X            offset = BSIZE - start % BSIZE;
  283. X        index_block(infd, inode_num, start, buf);
  284. X        print_block(buf, start, offset);
  285. X        length -= offset;
  286. X        start += offset;
  287. X    }
  288. X    return(0);
  289. }
  290. X
  291. X
  292. X
  293. /************************************************************************
  294. **
  295. **    index_block
  296. **
  297. *************************************************************************/
  298. X
  299. index_block(infd, inode_num, start, buf)
  300. int infd;
  301. unsigned inode_num;
  302. unsigned long start;
  303. unsigned char *buf;
  304. {
  305. X    struct dinode *ino;
  306. X    get_inode(infd, inode_num, &ino, buf);
  307. X
  308. X    if (start / BSIZE < 10)        /* 10 DIRECT BLOCKS */
  309. X        get_block(infd, INOBLOCK(ino->di_addr,start / BSIZE), buf);
  310. X    else
  311. X    {
  312. X        start -= BSIZE * 10;
  313. X        if ( start < BSIZE * (BSIZE / 4) )    /* INDIRECT BLOCKS */
  314. X        {
  315. X            get_block(infd, INOBLOCK(ino->di_addr, 10), buf);
  316. X            get_block(infd, INDBLOCK(buf, start / BSIZE), buf);
  317. X        }            
  318. X        else
  319. X        {
  320. X            start -= BSIZE * (BSIZE / 4);
  321. X            if (start < BSIZE * (BSIZE / 4) * (BSIZE / 4) )/* DOUBLE INDIRECT*/
  322. X            {
  323. X                get_block(infd, INOBLOCK(ino->di_addr, 11), buf);
  324. X                get_block(infd, INDBLOCK(buf, start / (BSIZE/4*BSIZE)), buf);
  325. X                start %= BSIZE / 4 * BSIZE;
  326. X                get_block(infd, INDBLOCK(buf, start /  BSIZE), buf);
  327. X            }    
  328. X            else
  329. X            {                                /* TRIPLE INDIRECT */
  330. X                start -= BSIZE * (BSIZE / 4) * ( BSIZE / 4 );
  331. X                get_block(infd, INOBLOCK(ino->di_addr, 12), buf);
  332. X                get_block(infd, INDBLOCK(buf, start / (BSIZE/4*BSIZE/4*BSIZE)),buf);
  333. X                start %= BSIZE / 4 * BSIZE / 4 * BSIZE;
  334. X                get_block(infd, INDBLOCK(buf, start / (BSIZE/4*BSIZE)), buf);
  335. X                start %= BSIZE / 4 * BSIZE;
  336. X                get_block(infd, INDBLOCK(buf, start /  BSIZE), buf);
  337. X
  338. X            }
  339. X        }
  340. X    }
  341. }
  342. X            
  343. /************************************************************************
  344. **
  345. **    get_inode
  346. **
  347. *************************************************************************/
  348. X
  349. get_inode(infd, inode_num, ino, buf )
  350. int infd;
  351. unsigned inode_num;
  352. struct dinode **ino;
  353. unsigned char *buf;
  354. {
  355. X    inode_num--;            /* inodes start at num - 1 */
  356. X    get_block(infd, (daddr_t)(inode_num / INOPB + 2), buf);
  357. X    *ino = (struct dinode *)buf + (inode_num % INOPB);
  358. }
  359. X
  360. /*************************************************************************
  361. **
  362. **     print_block
  363. **
  364. **************************************************************************/
  365. X
  366. print_block( buf, start, offset)
  367. int offset;
  368. unsigned long start;
  369. unsigned char *buf;
  370. {
  371. int cnt = 0;
  372. X
  373. X    while (cnt < offset )
  374. X        printf("%c", buf[start % BSIZE + cnt++]);
  375. }
  376. X
  377. /***************************************************************************
  378. **
  379. **    get_block
  380. **
  381. ****************************************************************************/
  382. get_block(infd, block, buf)
  383. int infd;
  384. long block;
  385. unsigned char *buf;
  386. {
  387. X    int bufsize;    
  388. X    if (lseek(infd, block * BSIZE, SEEK_SET) == -1)
  389. X    {
  390. X        perror("Can not seek in file");
  391. X        exit(1);
  392. X    }
  393. X
  394. X    if( (bufsize = read(infd, buf, BSIZE )) == -1 || bufsize != BSIZE)
  395. X    {
  396. X        perror("Can not read from file");
  397. X        exit(1);
  398. X    }
  399. }
  400. X    
  401. /****************************************************************************
  402. **
  403. **    l3block
  404. **
  405. *****************************************************************************/
  406. long l3block(blockptr)
  407. char *blockptr;
  408. {
  409. X    long ret;
  410. X
  411. X    l3tol(&ret, blockptr, 1);
  412. X    return ret;
  413. }
  414. X
  415. /****************************************************************************
  416. **
  417. **    cur_quit
  418. **
  419. *****************************************************************************/
  420. int curquit()
  421. {
  422. X    exit(0);
  423. }
  424. X
  425. X
  426. X
  427. SHAR_EOF
  428. chmod 0664 fslook.c ||
  429. echo 'restore of fslook.c failed'
  430. Wc_c="`wc -c < 'fslook.c'`"
  431. test 5525 -eq "$Wc_c" ||
  432.     echo 'fslook.c: original size 5525, current size' "$Wc_c"
  433. fi
  434. exit 0
  435.  
  436. -- 
  437. Frank Seitz, Hamburg, 040/7927569, {fs,root,postmaster}@oops.zigzag.hanse.de
  438.