summaryrefslogtreecommitdiffstats
path: root/fs/bfs/file.c
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2026-08-19 10:09:22 -0700
committerLinus Torvalds <torvalds@linux-foundation.org>2026-08-19 10:09:22 -0700
commitf4cdf7ca9a1fdcca413157df19753f388a5a224e (patch)
tree60a31895b2446cd7fa27514e8c2843534a0de0da /fs/bfs/file.c
downloadlinux-stable-f4cdf7ca9a1fdcca413157df19753f388a5a224e.tar.gz
linux-stable-f4cdf7ca9a1fdcca413157df19753f388a5a224e.zip
Merge tag 'media/v7.3-1' of git://git.kernel.org/pub/scm/linux/kernel/git/mchehab/linux-mediagrafted
Pull media updates from Mauro Carvalho Chehab: - v4l2-core: added ISP statistics support and per-block validation - v4l2-core: Allow unknown HDR10 white point and luminance - New camera sensors: Sony IMX678 and IMX471m, Himax HM1092 IR sensor - New codec: Milos: VPU v2.0 codec support - isp driver: gained support for Dreamchip RPPX1 ISP framework - vsp1 driver: gained support for RZ/T2H and RZ/N2H - Novalake driver: gained CVS support for new NVL hardware - dvb-core: fix feed leak on failed DMX_ADD_PID - several driver fixes, cleanups and minor improvements * tag 'media/v7.3-1' of git://git.kernel.org/pub/scm/linux/kernel/git/mchehab/linux-media: (308 commits) media: ipu-bridge: check all DMI entries when overriding sensor rotation media: v4l2-async: avoid deleting unlinked ASC entry on link error media: rzg2l-cru: Align bytesperline to hardware DMA stride requirement media: intel/ipu6: fix async notifier cleanup leak on parse error media: staging/ipu7: fix async notifier UAF on probe error path media: amd: isp4: fix self-deadlock in isp4sd_pwron_and_init() error path media: amd: isp4: release partial allocations in isp4if_alloc_fw_gpumem() media: rcar-isp: Fix VSPX reference leaks media: rcar-isp: Release ISPCORE resources media: i2c: imx415: Release runtime PM reference on VBLANK error media: i2c: imx415: Return test pattern write errors media: renesas: vsp1: Declare index variables in for loop statement media: renesas: vsp1: Make reset control optional to support platforms without a reset line media: dt-bindings: media: renesas,vsp1: Document RZ/T2H and RZ/N2H SoCs media: dt-bindings: media: renesas,fcp: Document RZ/T2H and RZ/N2H SoCs media: nxp: imx8-isi: Add additional 32-bit RGB format support media: nxp: imx8-isi: Add 16-bit raw Bayer format support media: nxp: imx8-isi: Implement per-stream reference counting for multiplexed streams media: nxp: imx8-isi: Use BIT_ULL() for 64-bit stream masks media: nxp: imx8-isi: Correct color map between V4L2 and ISI ...
Diffstat (limited to 'fs/bfs/file.c')
-rw-r--r--fs/bfs/file.c203
1 files changed, 203 insertions, 0 deletions
diff --git a/fs/bfs/file.c b/fs/bfs/file.c
new file mode 100644
index 000000000..d33d6bde9
--- /dev/null
+++ b/fs/bfs/file.c
@@ -0,0 +1,203 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * fs/bfs/file.c
+ * BFS file operations.
+ * Copyright (C) 1999-2018 Tigran Aivazian <aivazian.tigran@gmail.com>
+ *
+ * Make the file block allocation algorithm understand the size
+ * of the underlying block device.
+ * Copyright (C) 2007 Dmitri Vorobiev <dmitri.vorobiev@gmail.com>
+ *
+ */
+
+#include <linux/fs.h>
+#include <linux/mpage.h>
+#include <linux/buffer_head.h>
+#include "bfs.h"
+
+#undef DEBUG
+
+#ifdef DEBUG
+#define dprintf(x...) printf(x)
+#else
+#define dprintf(x...)
+#endif
+
+const struct file_operations bfs_file_operations = {
+ .llseek = generic_file_llseek,
+ .read_iter = generic_file_read_iter,
+ .write_iter = generic_file_write_iter,
+ .mmap_prepare = generic_file_mmap_prepare,
+ .splice_read = filemap_splice_read,
+};
+
+static int bfs_move_block(unsigned long from, unsigned long to,
+ struct super_block *sb)
+{
+ struct buffer_head *bh, *new;
+
+ bh = sb_bread(sb, from);
+ if (!bh)
+ return -EIO;
+ new = sb_getblk(sb, to);
+ memcpy(new->b_data, bh->b_data, bh->b_size);
+ mark_buffer_dirty(new);
+ bforget(bh);
+ brelse(new);
+ return 0;
+}
+
+static int bfs_move_blocks(struct super_block *sb, unsigned long start,
+ unsigned long end, unsigned long where)
+{
+ unsigned long i;
+
+ dprintf("%08lx-%08lx->%08lx\n", start, end, where);
+ for (i = start; i <= end; i++)
+ if(bfs_move_block(i, where + i, sb)) {
+ dprintf("failed to move block %08lx -> %08lx\n", i,
+ where + i);
+ return -EIO;
+ }
+ return 0;
+}
+
+static int bfs_get_block(struct inode *inode, sector_t block,
+ struct buffer_head *bh_result, int create)
+{
+ unsigned long phys;
+ int err;
+ struct super_block *sb = inode->i_sb;
+ struct bfs_sb_info *info = BFS_SB(sb);
+ struct bfs_inode_info *bi = BFS_I(inode);
+
+ phys = bi->i_sblock + block;
+ if (!create) {
+ if (phys <= bi->i_eblock) {
+ dprintf("c=%d, b=%08lx, phys=%09lx (granted)\n",
+ create, (unsigned long)block, phys);
+ map_bh(bh_result, sb, phys);
+ }
+ return 0;
+ }
+
+ /*
+ * If the file is not empty and the requested block is within the
+ * range of blocks allocated for this file, we can grant it.
+ */
+ if (bi->i_sblock && (phys <= bi->i_eblock)) {
+ dprintf("c=%d, b=%08lx, phys=%08lx (interim block granted)\n",
+ create, (unsigned long)block, phys);
+ map_bh(bh_result, sb, phys);
+ return 0;
+ }
+
+ /* The file will be extended, so let's see if there is enough space. */
+ if (phys >= info->si_blocks)
+ return -ENOSPC;
+
+ /* The rest has to be protected against itself. */
+ mutex_lock(&info->bfs_lock);
+
+ /*
+ * If the last data block for this file is the last allocated
+ * block, we can extend the file trivially, without moving it
+ * anywhere.
+ */
+ if (bi->i_eblock == info->si_lf_eblk) {
+ dprintf("c=%d, b=%08lx, phys=%08lx (simple extension)\n",
+ create, (unsigned long)block, phys);
+ map_bh(bh_result, sb, phys);
+ info->si_freeb -= phys - bi->i_eblock;
+ info->si_lf_eblk = bi->i_eblock = phys;
+ mark_inode_dirty(inode);
+ err = 0;
+ goto out;
+ }
+
+ /* Ok, we have to move this entire file to the next free block. */
+ phys = info->si_lf_eblk + 1;
+ if (phys + block >= info->si_blocks) {
+ err = -ENOSPC;
+ goto out;
+ }
+
+ if (bi->i_sblock) {
+ err = bfs_move_blocks(inode->i_sb, bi->i_sblock,
+ bi->i_eblock, phys);
+ if (err) {
+ dprintf("failed to move ino=%08lx -> fs corruption\n",
+ inode->i_ino);
+ goto out;
+ }
+ } else
+ err = 0;
+
+ dprintf("c=%d, b=%08lx, phys=%08lx (moved)\n",
+ create, (unsigned long)block, phys);
+ bi->i_sblock = phys;
+ phys += block;
+ info->si_lf_eblk = bi->i_eblock = phys;
+
+ /*
+ * This assumes nothing can write the inode back while we are here
+ * and thus update inode->i_blocks! (XXX)
+ */
+ info->si_freeb -= bi->i_eblock - bi->i_sblock + 1 - inode->i_blocks;
+ mark_inode_dirty(inode);
+ map_bh(bh_result, sb, phys);
+out:
+ mutex_unlock(&info->bfs_lock);
+ return err;
+}
+
+static int bfs_writepages(struct address_space *mapping,
+ struct writeback_control *wbc)
+{
+ return mpage_writepages(mapping, wbc, bfs_get_block);
+}
+
+static int bfs_read_folio(struct file *file, struct folio *folio)
+{
+ return block_read_full_folio(folio, bfs_get_block);
+}
+
+static void bfs_write_failed(struct address_space *mapping, loff_t to)
+{
+ struct inode *inode = mapping->host;
+
+ if (to > inode->i_size)
+ truncate_pagecache(inode, inode->i_size);
+}
+
+static int bfs_write_begin(const struct kiocb *iocb,
+ struct address_space *mapping,
+ loff_t pos, unsigned len,
+ struct folio **foliop, void **fsdata)
+{
+ int ret;
+
+ ret = block_write_begin(mapping, pos, len, foliop, bfs_get_block);
+ if (unlikely(ret))
+ bfs_write_failed(mapping, pos + len);
+
+ return ret;
+}
+
+static sector_t bfs_bmap(struct address_space *mapping, sector_t block)
+{
+ return generic_block_bmap(mapping, block, bfs_get_block);
+}
+
+const struct address_space_operations bfs_aops = {
+ .dirty_folio = block_dirty_folio,
+ .invalidate_folio = block_invalidate_folio,
+ .read_folio = bfs_read_folio,
+ .writepages = bfs_writepages,
+ .write_begin = bfs_write_begin,
+ .write_end = generic_write_end,
+ .migrate_folio = buffer_migrate_folio,
+ .bmap = bfs_bmap,
+};
+
+const struct inode_operations bfs_file_inops;