Advertisement
Guest User

Untitled

a guest
Sep 22nd, 2017
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.71 KB | None | 0 0
  1. void checkDirectories(FILE *image, int inodeNumber) {
  2.     int block, realInodeNumber, pos = 0, i, ii;
  3.     uchar blockBuffer[BLOCK_SIZE], dataBlockBuffer[BLOCK_SIZE];
  4.     uint mode, dblock, inode, singleIndirect, doubleIndirect;
  5.  
  6.     block = (inodeNumber / INODESIZE) + 2;
  7.     realInodeNumber = inodeNumber % INODESIZE;
  8.  
  9.     getBlock(image, block, blockBuffer);
  10.  
  11.     pos = realInodeNumber * INODESIZE;
  12.  
  13.     mode = get4Bytes(blockBuffer + pos);
  14.  
  15.     if (mode == 0)
  16.         return;
  17.  
  18.     if (inodeNumber != 1)
  19.         allInodes.inodes[inodeNumber].nlink++;
  20.  
  21.     if ((mode & IFMT) == IFREG) {
  22.  
  23.     } else if ((mode & IFMT) == IFDIR) {
  24.         pos += 32;
  25.         for (ii = 0; ii < 6; ii++) {
  26.             dblock = get4Bytes(blockBuffer + pos);
  27.             pos += 4;
  28.  
  29.             if (dblock == 0)
  30.                 continue;
  31.  
  32.             if (dblock != 0) {
  33.                 getBlock(image, dblock, dataBlockBuffer);
  34.  
  35.                 for (i = 0; i < DIRPB; i++) {
  36.                     inode = get4Bytes(dataBlockBuffer + (i * INODESIZE));
  37.  
  38.                     if (i <= 1) {
  39.                         allInodes.inodes[inode].nlink++;
  40.                         continue;
  41.                     }
  42.  
  43.                     if (inode == 0)
  44.                         continue;
  45.  
  46.                     checkDirectories(image, inode);
  47.                 }
  48.             }
  49.         }
  50.  
  51.         singleIndirect = get4Bytes(blockBuffer + pos);
  52.         pos += 4;
  53.  
  54.         if (singleIndirect != 0) {
  55.             checkDirectorySingle(image, singleIndirect);
  56.         }
  57.  
  58.         doubleIndirect = get4Bytes(blockBuffer + pos);
  59.  
  60.         if (doubleIndirect != 0) {
  61.             checkDirectoryDouble(image, doubleIndirect);
  62.         }
  63.     }
  64. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement