summaryrefslogtreecommitdiffstats
path: root/common/block.c
Commit message (Collapse)AuthorAgeFilesLines
* block: record block device typeAhmad Fatoum2024-03-051-0/+24
| | | | | | | | | | Software running under EFI can query the type of a block device. For barebox to be able to report this, start assigning types to all block devices it can create. No functional change yet. Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Link: https://lore.barebox.org/20240304190038.3486881-24-a.fatoum@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* block: define BLOCKSIZE globally in block.hAhmad Fatoum2024-03-051-2/+0
| | | | | | | | | For use by EFI loader code that needs to report block size, export the BLOCKSIZE macro. Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Link: https://lore.barebox.org/20240304190038.3486881-18-a.fatoum@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* block: reparse partition table when necessarySascha Hauer2024-02-161-1/+24
| | | | | | | | | | Call reparse_partition_table() when the partition table may have changed. We detect this by recording if the block device has been written to in the area where the partition table is. Reviewed-by: Marco Felsch <m.felsch@pengutronix.de> Link: https://lore.barebox.org/20240215074757.960200-5-s.hauer@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* Merge branch 'for-next/state'Sascha Hauer2023-06-221-0/+4
|\
| * block: parse partition table on block device registrationAhmad Fatoum2023-06-121-0/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Every instance of block device registration is followed by an attempt to parse the partition table. Thus move partition table parsing into blockdevice_register. We do away with the warning print as it's superfluous: parse_partition_table doesn't return an error if partition table is missing and all other errors already result in an error message. Reviewed-by: Marco Felsch <m.felsch@pengutronix.de> Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Link: https://lore.barebox.org/20230607120714.3083182-13-a.fatoum@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* | file-list: support special 'auto', 'block' specifiersAhmad Fatoum2023-06-121-0/+16
|/ | | | | | | | | | | | | | | | | | | | | | | | | | Best practice is for each board to populate $global.system.partitions or $global.fastboot.partitions with a string exporting its flashable devices in a descriptive manner, e.g. "/dev/mmc0(eMMC),/dev/mmc1(SD)". This often goes into BSPs though, so upstream boards are left without default partitions, making use a bit cumbersome. Make this easier by providing two new magic specifiers: - block: exports all registered block devices (e.g. eMMC and SD) - auto: currently equivalent to "block". May be extended to EEPROMs, raw MTD and UBI in future This makes it easy to export devices on any board: usbgadget -A auto -b or usbgadget -S auto,/tmp/fitimage(fitimage)c Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Link: https://lore.barebox.org/20230609075229.1093397-2-a.fatoum@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* block: refuse registering block devices with absurdly large blocksAhmad Fatoum2023-05-081-0/+5
| | | | | | | | | | | Block layer caching can't work if a block is bigger than BUFSIZE which is used for the caching chunks. Instead of ending up with a rdbufsize of 0, which leads to strange errors on device access, just refuse this outright. Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Link: https://lore.barebox.org/20230508074612.3313870-2-a.fatoum@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* Merge branch 'for-next/misc'Sascha Hauer2022-10-131-1/+1
|\
| * block: have cdev_get_block_device accept const cdevAhmad Fatoum2022-10-111-1/+1
| | | | | | | | | | | | | | | | | | | | Having a non-const cdev parameter for cdev_get_block_device() limits its use as a user may want to just read struct block_device members without change. Allow this by changing parameter to be pointer to const instead. Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Link: https://lore.barebox.org/20221010061122.2084009-2-a.fatoum@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* | block: fix calling cdev_get_block_device with partitionsAhmad Fatoum2022-10-101-1/+1
|/ | | | | | | | | | | | For partitions, cdev->priv references the parent block device. Doing the pointer arithmetic in container_of will result in an out-of-bounds access. Do what the rest of the code does and access cdev->priv instead. Fixes: 84173bf3d0cc ("block: set S_IFBLK for block devices instead of S_IFCHR") Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Link: https://lore.barebox.org/20221010063834.2110400-1-a.fatoum@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* block: set S_IFBLK for block devices instead of S_IFCHRAhmad Fatoum2022-06-101-0/+8
| | | | | | | | | | | | | | | | | | In barebox, block devices are a special case of character devices. Nevertheless, differentiation can be useful to allow scripts iterating over all block devices without accounting for naming, e.g. for dev in /dev/*; do test -b $dev && echo $dev: blockdevice done Add the necessary support. This will break scripts that assume test -c blockdevice to be true, but that's a quite improbable check. Tested-by: Jules Maselbas <jmaselbas@kalray.eu> Signed-off-by: Ahmad Fatoum <ahmad@a3f.at> Link: https://lore.barebox.org/20220602195916.9061-2-a.fatoum@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* block: use 64-bit types for sector offset and count on all platformsAhmad Fatoum2021-02-181-17/+18
| | | | | | | | | | | barebox' use of int for the sector offset puts an upper bound of 1TB on the size of supported block devices, which is already exceeded by common place USB mass storage. Increasing the sizes involved to 64 bit like Linux does won't magically add missing driver support, but it gives us at least a fighting chance. Do so. Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* common: replace license statements with SPDX-License-IdentifiersAhmad Fatoum2020-11-271-10/+1
| | | | | | | | | | | | | For all files in common/ that already have a license text: - Replace with appropriate SPDX-License-Identifier - Remove empty comment lines around replacement - remove comment completely if only thing remaining is name of file without description Reviewed-by: Roland Hieber <rhi@pengutronix.de> Reviewed-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de> Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* treewide: remove references to CREDITSUwe Kleine-König2020-04-271-3/+0
| | | | | | | | The CREDITS file was removed from barebox in 2015 by commit 6570288f2d97 ("Remove the CREDITS file"). Remove references to it from several files. Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* common: fix typos found with codespellYegor Yefremov2020-03-231-1/+1
| | | | | Signed-off-by: Yegor Yefremov <yegorslists@googlemail.com> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* Revert "block: Adjust cache sizes"Ahmad Fatoum2020-03-031-2/+2
| | | | | | | | | | | | | | | | | | | | | | On 12/13/19 2:12 PM, Sascha Hauer wrote: > On Tue, Dec 10, 2019 at 03:44:52PM +0100, Hubert Feurstein wrote: >> With v2015.06.0 the indicated progress of the copy command is very >> smooth. Calling "cp -v /dev/zero /dev/mmc3.root" takes about 80 >> seconds for 256MB. But with v2019.12.0 the progress is very bumpy and >> the copy takes about 280 seconds. >> >> I've tracked this down to this commit which destroys the performance: >> "block: Adjust cache sizes" (b6fef20c1215c6ef0004f6af4a9c4b77af51dc43) > > We could just revert this patch. I can't find any workload that gets > faster with b6fef20c1215. It's rather the other way round. Do this by reverting commit b6fef20c1215c6ef0004f6af4a9c4b77af51dc43. Reported-by: Hubert Feurstein <h.feurstein@gmail.com> Suggested-by: Sascha Hauer <s.hauer@pengutronix.de> Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* block: Implement discard_rangeSascha Hauer2020-02-141-0/+21
| | | | | | | | This implements the discard_range hook. When a range of data is discarded then we do not have to read it from the device and can pass a zeroed buffer instead. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* Merge branch 'for-next/misc'Sascha Hauer2019-02-131-24/+23
|\
| * block: Move shared code in get_chunk() out of if statementAndrey Smirnov2019-01-221-3/+2
| | | | | | | | | | Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
| * block: Do not write past block device boundary during a flushAndrey Smirnov2019-01-221-9/+13
| | | | | | | | | | | | | | | | | | | | | | | | When calling I/O functions of underlying block device driver we always need to make sure that its size is small enough to not go past device's boundary. Not only in get_chunk() and block_cache(), but in writebuffer_flush() as well. Since the same code is used in three different places, move it into a subroutine and adjust all of the calls to ->write()/->read() accordingly. Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
| * block: Replace debug() with dev_dbg()Andrey Smirnov2019-01-181-5/+6
| | | | | | | | | | | | | | | | | | All of the functions using debug() in that file have enough info to use dev_dbg instead. Convert all of the uses of debug() to dev_dbg() in order to get more informative debug output. Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
| * block: Alias block_op_close() to block_op_flush()Andrey Smirnov2019-01-181-7/+2
| | | | | | | | | | | | | | | | | | The two functions are identical, so there's no need to keep two copies of the same code around. Alias block_op_close() to block_op_flush() and drop standalone definition for the former. Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* | devfs: Drop dev_lseek_default()Andrey Smirnov2019-01-291-1/+0
|/ | | | | | | | | | | | | | | | | | | | | Only the following cdevs do not declare an .lseek() operation: - Console devices in common/console.c - Firmware framework in common/firmware.c - JTAG driver in drivers/misc/jtag.c - UBI in drivers/mtd/ubi/barebox.c Of those four, first two are marked DEVFS_IS_CHARACTER_DEV and implement only .write() operation and the last two don't implement anything but .ioctl(). While there's probably no meaningful way to use lseek() against any of those devices, there doesn't seem to be any harm in allowing it either. Change devfs_lseek() to ignore absense of .lseek() callback and drop dev_lseek_default() and all references to it in the codebase. Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* block: Do not ignore error in blk->ops->write()Andrey Smirnov2018-08-311-3/+14
| | | | | | | | | | | Getting a error from blk->ops->write() is not a very unlikely event (happens quite often during new board bringup), so we need to catch and propagate them to upper layers so they can be at least reported properly. Change the code of all of the callers to bail out as soon as blk->ops->write() fails. Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* block: Adjust cache sizesSascha Hauer2018-07-131-2/+2
| | | | | | | | Use four times more cache entries and divide the memory for each entry by four. This lowers the linear read throughput somewhat but increases the access speed for filesystems. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* rename file_operations -> cdev_operationsSascha Hauer2018-04-061-1/+1
| | | | | | | | Linux also has struct file_operations which are something different. Rename our file_operations to cdev_operations which better matches what we have. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* fs: Create automount entries for the default mount pathesSascha Hauer2017-05-101-0/+2
| | | | | | | | | | In barebox the default mount path for a cdev is /mnt/<cdevname> which can be mounted with "mount <cdevname>" without specifying a target path explicitly. Simplify this further by creating automount entries for the default mount pathes which makes a manual mount completely unnecessary. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* block: Add flush callbackSascha Hauer2014-07-141-0/+3
| | | | | | | Some block devices need an explicit callback for flushing written blocks. Add this callback. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* block: Collect block devices on listSascha Hauer2013-09-301-0/+5
| | | | Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* block: shortcut writebuffer_flush if writing is disabledSascha Hauer2013-07-221-0/+3
| | | | | | Saves a few bytes of binary space. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* block: implement block_read/block_write functionsSascha Hauer2013-05-311-0/+22
| | | | | | | | | Some drivers use blk->ops->read/write. This bypasses the caching block layer and was never intended like this. The upper API to the block layer is the cdev layer. This patch adds block_read and block_write functions and uses them where appropriate. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* block: rename file operation functionsSascha Hauer2013-05-311-8/+8
| | | | | | | block_read and block_write collide with a to-be-introduced global function, so rename the file operation functions. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* Treewide: remove address of the Free Software FoundationSascha Hauer2012-09-171-3/+0
| | | | | | | The FSF address has changed in the past. Instead of updating it each time the address changes, just drop it completely treewide. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* Merge branch 'for-next/dma-cache-align'Sascha Hauer2012-07-021-3/+4
|\
| * block: use dma_alloc to allocate buffersSascha Hauer2012-06-301-3/+4
| | | | | | | | | | | | | | Drivers may use dma to transfer blocks, so put them into dma save memory. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* | make cdev 64bit capableSascha Hauer2012-06-301-1/+1
| | | | | | | | | | | | Next step to 64bit support: Make cdev size a 64bit type. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* | use loff_t for file offsetsSascha Hauer2012-06-301-2/+2
|/ | | | | | | This is a first step for 64bit file support: Make the file sizes/offsets 64bit. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* block: Fix printf warningAlexander Shiyan2012-05-311-1/+1
| | | | | Signed-off-by: Alexander Shiyan <shc_work@mail.ru> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* block: do not BUG() on failed block_getSascha Hauer2012-05-301-1/+1
| | | | | | | It does not necessarily means a bug when block_get fails here, this can also be a failure on the underlying device. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* block: propagate error code from block_getSascha Hauer2012-05-301-13/+13
| | | | Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* block: reimplement cachingSascha Hauer2012-02-151-73/+201
| | | | | | | | | | | The current caching layer only has a single buffer for writing and reading. The FAT driver often accesses the fat and then data again, which currently can't be cached. Reimplement this with a list of cached chunks. The number of chunks and their sizes are currently hardcoded, but that could be easily made configurable. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* add block supportSascha Hauer2011-04-111-0/+263
This adds a simple block layer to barebox. Reading and writing to block devices can be painfully slow without caching, so add a simple caching layer here. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>