From f25ca882e4788190b866586686328d0e409d1edf Mon Sep 17 00:00:00 2001 From: Steve Slaven Date: Tue, 28 Jul 2009 16:54:29 -0700 Subject: More fixes to ftruncate to expand a file which was causing the "fake" mmap errors in fsx, fixed loading the right block during write() diff --git a/fusearchive.py b/fusearchive.py index f3567aa..61dc821 100755 --- a/fusearchive.py +++ b/fusearchive.py @@ -666,6 +666,8 @@ class FuseArchive(Fuse): index = int( offset / self.chunk_size ) rest = offset % self.chunk_size + logging.debug( "This chunk falls on index: " + str( index ) + " rest: " + str( rest ) ) + # If index is higher than the number of blocks we current have it's a seek hole, so we need to extend our blocks out # We know these need to essentially be zeroed up to this size since while index > len( self.chunks ): @@ -680,6 +682,8 @@ class FuseArchive(Fuse): self.chunk += "\0" * fill_null self.chunk_modified = True + self._load_chunk( index ) + # Now check if this chunk needs to be extended if len( self.chunk ) < rest: fill_null = rest - len(self.chunk) @@ -844,7 +848,7 @@ class FuseArchive(Fuse): if need_chunks == 0: logging.debug( "Creating 0 chunk file" ) self.chunks = [] - elif need_chunks > curr_chunks: + elif self.size < length: logging.debug( "Need to pad out file, writing/seeking to " + str( length ) ) # Just write out null bytes to the length requested, write will do this for us if we specify the offset @@ -860,25 +864,22 @@ class FuseArchive(Fuse): self.chunks.pop() curr_chunks = len( self.chunks ) - # Now make sure this chunk is the right size, first load the - # last chunk - if len( self.chunks ): - self._load_chunk( len( self.chunks ) - 1 ) - logging.debug( "Loaded final chunk, len: " + str( len( self.chunk ) ) ) - - # Now truncate or extend this item - if len( self.chunk ) < extra_bytes: - remaining = extra_bytes - len(self.chunk) - logging.debug( "Extending final chunk " + str( remaining ) + " bytes" ) - self.chunk += "\0" * remaining - else: - logging.debug( "Truncating final chunk to " + str( extra_bytes ) ) - self.chunk = self.chunk[ :extra_bytes ] + # Now make sure this chunk is the right size, first load the + # last chunk + if len( self.chunks ): + self._load_chunk( len( self.chunks ) - 1 ) + logging.debug( "Loaded final chunk, len: " + str( len( self.chunk ) ) ) + + # Now truncate this item if needed + if len( self.chunk ) > extra_bytes: + logging.debug( "Truncating final chunk to " + str( extra_bytes ) ) + self.chunk = self.chunk[ :extra_bytes ] + self.chunk_dirty = True self.modified = True self.size = length self._load_chunk( 0 ) - # Don't need to mark dirty cache because we're flushing + self._fflush() def lock(self, cmd, owner, **kw): -- cgit v0.10.2