@@ -56,15 +56,20 @@ ex_status ex_inode_allocate_blocks(struct ex_inode *inode) {
5656
5757 for (size_t i = 0 ; i < EX_DIRECT_BLOCKS ; i ++ ) {
5858
59- inode -> blocks [ i ] = ex_super_allocate_block ();
59+ size_t address = ex_super_allocate_block ();
6060
6161 // we are unable to allocate next block, we should deallocate all
6262 // already allocated blocks
63- if (inode -> blocks [ i ] == EX_BLOCK_INVALID_ADDRESS ) {
63+ if (address == EX_BLOCK_INVALID_ADDRESS ) {
6464 warning ("failing to allocate nth (%lu) block" , i );
6565 ex_inode_deallocate_blocks (inode );
6666 return INODE_BLOCK_ALLOCATION_FAILED ;
6767 }
68+
69+ struct ex_data_block * block = & inode -> blocks [i ];
70+
71+ block -> address = address ;
72+ block -> allocated = 1 ;
6873 }
6974
7075 return OK ;
@@ -74,11 +79,11 @@ void ex_inode_deallocate_blocks(struct ex_inode *inode) {
7479
7580 for (size_t i = 0 ; i < EX_DIRECT_BLOCKS ; i ++ ) {
7681
77- if (inode -> blocks [i ] == EX_BLOCK_INVALID_ADDRESS ) {
82+ if (inode -> blocks [i ]. address == EX_BLOCK_INVALID_ADDRESS ) {
7883 break ;
7984 }
8085
81- ex_super_deallocate_block (inode -> blocks [i ]);
86+ ex_super_deallocate_block (inode -> blocks [i ]. address );
8287 }
8388
8489 ex_super_deallocate_inode_block (inode -> number );
@@ -564,7 +569,12 @@ ssize_t ex_inode_write(struct ex_inode *ino, size_t off, const char *data,
564569 ino -> size += (off + amount ) - ino -> size ;
565570 }
566571
567- block_address addr = ino -> blocks [start_block_idx ];
572+ block_address addr = ino -> blocks [start_block_idx ].address ;
573+ char allocated = ino -> blocks [start_block_idx ].allocated ;
574+
575+ if (!allocated ) {
576+ // XXX: do allocation
577+ }
568578
569579 ex_device_write (ino -> address , (void * )ino , sizeof (struct ex_inode ));
570580 ex_device_write (addr + start_block_off , data , amount );
@@ -582,9 +592,9 @@ ssize_t ex_inode_read(struct ex_inode *ino, size_t off, char *buffer,
582592 return 0 ;
583593 }
584594
585- size_t offset = ino -> blocks [start_block_idx ] + start_block_off ;
595+ size_t offset = ino -> blocks [start_block_idx ]. address + start_block_off ;
586596 ssize_t readed = 0 ;
587-
597+ // XXX: check if block is allocated
588598 // XXX: ignore status for now
589599 (void )ex_device_read_to_buffer (& readed , buffer , offset , amount );
590600
@@ -650,7 +660,7 @@ struct ex_inode_block ex_inode_block_iterate(struct ex_inode *inode,
650660 goto done ;
651661 }
652662
653- block .address = inode -> blocks [it -> block_number ];
663+ block .address = inode -> blocks [it -> block_number ]. address ;
654664 block .data = it -> buffer ;
655665
656666 // XXX: add buffer into ex_block_iterator and use ex_device_read_to_buffer
@@ -713,3 +723,4 @@ int ex_inode_has_perm(struct ex_inode *ino, ex_permission perm, gid_t gid, uid_t
713723
714724 return 0 ;
715725}
726+
0 commit comments