Advertisement
rnort

copyout

Dec 30th, 2012
360
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.29 KB | None | 0 0
  1. // recursive copy dir tree to extern disk
  2. void RecursiveCopyOut(std::string& externPath, Inode& inode, Directory& dir, std::fstream& file, SuperBlock& sb)
  3. {
  4.     mkdir(externPath.c_str());
  5.  
  6.     for ( int i = 0; i < dir.HEADER.NUMBER; ++i)
  7.     {
  8.         Inode tmpInode = ReadInode(file, dir.ENTRIES[i].INODE_NUMBER);
  9.         if ( dir.ENTRIES[i].ISFILE ==  0 ) // dir
  10.         {
  11.             Directory tmpDir = ReadDirectory( file, tmpInode, sb);
  12.             RecursiveCopyOut( externPath + "\\" + dir.ENTRIES[i].ENTRY_NAME,  tmpInode, tmpDir, file ,sb);
  13.         }
  14.         else
  15.         {
  16.             // copy file
  17.         }
  18.     }
  19. }
  20.  
  21. int CopyOutDirectories(std::string& dirToCopy,  std::string& parentPath, std::string& externPath)
  22. {
  23.     std::string targetPath = parentPath + ( parentPath.back() == '/' ? "" : "/")  + dirToCopy;
  24.     Directory parentDir;
  25.     Inode parentInode;
  26.     GetDirByName( parentPath, parentDir, parentInode);
  27.  
  28.     if ( FindEntryInodeNumber(parentDir, dirToCopy.c_str())  == 0)
  29.     {
  30.         return 1;
  31.     }
  32.     Directory dir;
  33.     Inode  tocopyInode;
  34.     GetDirByName( targetPath, dir, tocopyInode);
  35.  
  36.     std::fstream file("testfile.bin", std::fstream::in |
  37.         std::fstream::binary |
  38.         std::fstream::out );
  39.     SuperBlock sb = ReadSuperBlock(file);
  40.     externPath = externPath + ( externPath.back() == '\\' ? "" : "\\")  + dirToCopy;
  41.     RecursiveCopyOut(externPath, tocopyInode, dir, file, sb);
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement