Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
Block (data storage)
(section)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
{{Short description|Sequence of bits or bytes of a maximum predetermined size}} {{About|the computer input/output technique|the process scheduling concept|Blocking (computing)}} {{Distinguish|Page (computer memory)|Bank (computer memory)}} {{More citations needed|date=April 2014}} {{Use dmy dates|date=March 2020|cs1-dates=y}} In [[computing]] (specifically [[data transmission]] and [[computer storage|data storage]]), a '''block''',<ref name="Buchholz_1962"/> sometimes called a '''physical record''', is a sequence of [[byte]]s or [[bit]]s, usually containing some whole number of [[record (computer science)|record]]s, having a fixed length; a ''block size''.<ref name="CNET14"/> Data thus [[Data structure|structured]] are said to be ''blocked''. The process of putting data into blocks is called ''blocking'', while ''deblocking'' is the process of extracting data from blocks. Blocked data is normally stored in a [[data buffer]], and read or written a whole block at a time. Blocking reduces the [[overhead (computing)|overhead]] and speeds up the handling of the [[data stream]].<ref name="Chang"/> For some devices, such as magnetic tape and [[Count Key Data|CKD disk device]]s, blocking reduces the amount of external storage required for the data. Blocking is almost universally employed when storing data to [[9-track tape|9-track]] [[magnetic tape]], NAND [[flash memory]], and rotating media such as [[floppy disk]]s, [[hard disk]]s, and [[optical disc]]s. Most [[file system]]s are based on a [[block device]], which is a level of [[abstraction (computer science)|abstraction]] for the hardware responsible for storing and retrieving specified blocks of data, though the block size in file systems may be a multiple of the physical block size. This leads to space inefficiency due to [[internal fragmentation]], since file lengths are often not integer multiples of block size, and thus the last block of a file may remain partially empty. This will create [[slack space]]. Some newer file systems, such as [[Btrfs]] and [[FreeBSD]] [[Unix File System|UFS2]], attempt to solve this through techniques called [[block suballocation|block suballocation and tail merging]]. Other file systems such as [[ZFS]] support variable block sizes.<ref name="ZFS1"/><ref name="ZFS2"/> Block storage is normally abstracted by a file system or [[database management system]] (DBMS) for use by applications and end users. The physical or logical volumes accessed via ''block I/O'' may be devices internal to a server, directly attached via [[SCSI]] or [[Fibre Channel]], or distant devices accessed via a [[storage area network]] (SAN) using a protocol such as [[iSCSI]], or [[ATA over Ethernet|AoE]]. DBMSes often use their own block I/O for improved performance and recoverability as compared to layering the DBMS on top of a file system. On Linux the default block size for most file systems is 4096 bytes. The {{Mono|stat}} command part of [[GNU Core Utilities]] can be used to check the block size. In [[Rust (programming language)|Rust]] a block can be read with the {{Code|read_exact}} method.<ref>{{cite web |title=Read in std::io - Rust |url=https://doc.rust-lang.org/std/io/trait.Read.html#method.read_exact |website=doc.rust-lang.org |access-date=2 February 2025}}</ref> <syntaxhighlight lang="rust"> const BLOCK_SIZE: usize = 4096; if let Ok(mut file) = File::open("example.bin") { let mut buf = [0u8; BLOCK_SIZE]; file.read_exact(&mut buf); } </syntaxhighlight> In [[Python (programming language)|Python]] a block can be read with the {{Code|read}} method. <syntaxhighlight lang="python"> BLOCK_SIZE = 4096 with open("example.bin", "rb") as file: block = file.read(BLOCK_SIZE) </syntaxhighlight> In [[C Sharp (programming language)|C#]] a block can be read with the {{Code|FileStream}} class.<ref>{{cite web |title=FileStream.ReadAsync Method (System.IO) |url=https://learn.microsoft.com/en-us/dotnet/api/system.io.filestream.readasync?view=net-9.0 |website=learn.microsoft.com |access-date=2 February 2025 |language=en-us}}</ref> <syntaxhighlight lang="csharp"> const int BLOCK_SIZE = 4096; using FileStream stream = File.Open("example.bin", FileMode.Open); var block = new byte[BLOCK_SIZE]; await stream.ReadAsync(block, 0, BLOCK_SIZE); </syntaxhighlight>
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)