Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int bd_create(const char *pFilename) {
- char bufferFI[BLOCK_SIZE] ;
- ReadBlock(FREE_INODE_BITMAP, bufferFI) ;
- UINT16 idFreeInode = -1 ;
- int i;
- for(i=BASE_BLOCK_INODE ; i<BASE_BLOCK_INODE+N_INODE_ON_DISK ; i++)
- {
- if(bufferFI[i] == 1)
- {
- idFreeInode = i - BASE_BLOCK_INODE ;
- break ;
- }
- }
- if(idFreeInode == -1)
- {
- return -1 ;
- }
- char bufferFB[BLOCK_SIZE] ;
- ReadBlock(FREE_BLOCK_BITMAP, bufferFB) ;
- UINT16 idFreeBlock = -1 ;
- int x;
- for(x=BASE_BLOCK_INODE+N_INODE_ON_DISK; i<N_BLOCK_ON_DISK; i++)
- {
- if(bufferFB[i] == 1)
- {
- idFreeBlock = i;
- break ;
- }
- }
- if(idFreeBlock == -1)
- {
- return -1 ;
- }
- AttachFreeBlock(idFreeBlock);
- AttachFreeInode(idFreeInode + BASE_BLOCK_INODE);
- char dirPath[FILENAME_SIZE*N_INODE_ON_DISK] ;
- char newFileName[FILENAME_SIZE] ;
- GetFilenameFromPath(pFilename, newFileName) ;
- GetDirFromPath(pFilename, dirPath);
- printf("prefix %s , filename %s \n", dirPath, newFileName) ;
- char bufferIno[BLOCK_SIZE];
- inode_path_help(dirPath, bufferIno);
- iNodeEntry* inoE = (iNodeEntry*) bufferIno;
- inoE->iNodeStat.st_size += sizeof(DirEntry) ;
- WriteBlock(inoE->iNodeStat.st_ino+BASE_BLOCK_INODE, (char*) inoE) ;
- char bufferDir[BLOCK_SIZE];
- ReadBlock(inoE->Block[0] , bufferDir) ;
- printiNode(*inoE);
- int numberOfDirs = NumberofDirEntry(inoE->iNodeStat.st_size)-1;
- //DirEntry* dirEntry = malloc((numberOfDirs+1)*sizeof(DirEntry));
- //memcpy(dirEntry, (DirEntry*) bufferDir, numberOfDirs* sizeof(DirEntry));
- DirEntry* dirEntry = (DirEntry*) bufferDir ;
- dirEntry[numberOfDirs].iNode = idFreeInode ;
- strcpy(dirEntry[numberOfDirs].Filename, newFileName);
- WriteBlock(inoE->Block[0], (char*) dirEntry);
- iNodeEntry* newInode = malloc(sizeof(iNodeEntry)) ;
- newInode->Block[0] = idFreeBlock ;
- newInode->iNodeStat.st_size = 0 ;
- newInode->iNodeStat.st_mode =0 ;
- newInode->iNodeStat.st_ino = idFreeInode +BASE_BLOCK_INODE;
- newInode->iNodeStat.st_nlink = 1 ;
- WriteBlock(idFreeInode +BASE_BLOCK_INODE, (char*) newInode) ;
- return 1;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement