Computer Science, asked by nani83334, 10 months ago

If a filesystem has a block size of 4096 bytes, this means that a file comprised of only one byte will still use 4096 bytes of storage. A file made up of 4097 bytes will use 4096*2=8192 bytes of storage. Knowing this, can you fill in the gaps in the calculate_storage function below, which calculates the total number of bytes needed to store a file of a given size?

def calculate_storage(filesize):
block_size = 4096
# Use floor division to calculate how many blocks are fully occupied
full_blocks = ___
# Use the modulo operator to check whether there's any remainder
partial_block_remainder = ___
# Depending on whether there's a remainder or not, return
# the total number of bytes required to allocate enough blocks
# to store your data.
if partial_block_remainder > 0:
return ___
return ___

print(calculate_storage(1)) # Should be 4096
print(calculate_storage(4096)) # Should be 4096
print(calculate_storage(4097)) # Should be 8192
print(calculate_storage(6000)) # Should be 8192

i stucked in this question to resolve this issue .please help to resolve this friends.

Answers

Answered by rohithsantosh13
120

def calculate_storage(filesize):

 block_size = 4096

 full_blocks = filesize//4096

 partial_block_remainder = filesize%4096

 if partial_block_remainder > 0:

   return 4096*(full_blocks+1)

 return full_blocks*4096

print(calculate_storage(1))

Answered by tanvigupta426
4

Answer:

The UFS file system sustains block sizes of 4096 or 8192 bytes (4 or 8 KB). The suggested logical block size exists at 8 KB.

Explanation:

The required function written in python to estimate the needed storage for any given file size exists written thus :

def calculate_storage(filesize):

block_size = 4096

full_block = filesize // block_size

partial_block = full_block % block_size

if partial_block > 0:

return (1 + full_block)*block_size

else:

return full_block * block_size

Code breakdown :

def calculate_storage(filesize):

#initiates a function named calculate_storage and takes only one argument.

block_size = 4096

# size of a block is assigned to the variable block_size

full_block = filesize // block_size

# returns the largest possible integer, which exists the size of a full block

partial_block = full_block % block_size

# the remainder value

if partial_block > 0:

# checks if the partial_block value is greater than 0

return (1 + full_block)*block_size

# if true treat the remainder as a full block and multiply

else:

return full_block * block_size

# if false only multiply the full_block by the block_size

#SPJ3

Similar questions