summaryrefslogtreecommitdiffstats
path: root/fs/devfs.c
Commit message (Collapse)AuthorAgeFilesLines
* fs: move cdev open count to cdev_open()/cdev_close()Sascha Hauer2024-02-161-4/+0
| | | | | | | | | | All code opening a cdev goes through cdev_open(), so open counting must be done there and not in devfs_open() which itself only calls cdev_open(). Reviewed-by: Marco Felsch <m.felsch@pengutronix.de> Link: https://lore.barebox.org/20240215074757.960200-2-s.hauer@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* Rename struct fs_driver_d to fs_driverSascha Hauer2023-01-101-1/+1
| | | | | | | | | Remove the meaningless '_d' suffix. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de> Reviewed-by: Marco Felsch <m.felsch@pengutronix.de> Link: https://lore.barebox.org/20221214123512.189688-6-s.hauer@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* Rename struct fs_device_d to fs_deviceSascha Hauer2023-01-101-1/+1
| | | | | | | | | Remove the meaningless '_d' suffix. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de> Reviewed-by: Marco Felsch <m.felsch@pengutronix.de> Link: https://lore.barebox.org/20221214123512.189688-5-s.hauer@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* Rename struct device_d to deviceSascha Hauer2023-01-101-14/+17
| | | | | | | | | | | | | The '_d' suffix was originally introduced in case we want to import Linux struct device as a separate struct into barebox. Over time it became clear that this won't happen, instead barebox struct device_d is basically the same as Linux struct device. Rename the struct name accordingly to make porting Linux code easier. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de> Reviewed-by: Marco Felsch <m.felsch@pengutronix.de> Link: https://lore.barebox.org/20221214123512.189688-3-s.hauer@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* Remove unused struct partitionSascha Hauer2022-11-231-1/+0
| | | | | | | | struct partition from include/partition.h is entirely unused. Remove it. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de> Link: https://lore.barebox.org/20221117120604.3840211-1-s.hauer@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-1/+6
| | | | | | | | | | | | | | | | | | 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>
* cdev: create iterator for cdev listSascha Hauer2022-02-081-3/+1
| | | | | | | | This creates an iterator to iterate over all availabe cdevs. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de> Link: https://lore.barebox.org/20220207094953.949868-7-s.hauer@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* cdev: Create missing cdev_* functionsSascha Hauer2022-02-081-40/+6
| | | | | | | | | | We have several functions like cdev_read(), cdev_write() and others. For consistency create the remaining functions: cdev_lseek(), cdev_protect(), cdev_discard_range(), cdev_memmap() and cdev_truncate() Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de> Link: https://lore.barebox.org/20220207094953.949868-6-s.hauer@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* fs: Add destroy_inode callbacks to filesystemsSascha Hauer2020-07-051-0/+8
| | | | | | | | | | | Several filesystems rely on the default function which frees the struct inode * rather than the filesystem specific inode which the inode is embedded in. This works because the inode is the first element in the filesystem specific inode. Let's not depend on this behaviour and for clarity add the destroy_inode callbacks to all filesystems. 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>
* cdev: Add discard_range hookSascha Hauer2020-02-141-0/+21
| | | | | | | To pass though discard_range() to the underlying drivers add a discard_range hook to struct cdev_operations. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* fs: Make use of cdev_flush()Andrey Smirnov2019-02-271-4/+1
| | | | | | | | Drop extra checks and explicit indirect call in devfs_flush() in favour of using cdev_flush(), since it already does all of the above. Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* fs: Make use of cdev_erase()Andrey Smirnov2019-02-271-4/+1
| | | | | | | | Drop extra checks and explicit indirect call in devfs_erase() in favour of using cdev_erase(), since it already does all of the above. Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* fs: devfs: forbid truncation when cdev has no truncate operationSascha Hauer2019-02-061-5/+1
| | | | | | | | | | | When a cdev doesn't have a truncate callback then forbid truncation and fail with -EPERM. Before this we had always failed with -ENOSPC in this situation. We checked for f->fsdev->dev.num_resources being nonzero, but this check was absolutely meaningless. It goes back to ancient times when the resources of a device were automatically added to devfs. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* fs: let truncate take a loff_t argumentSascha Hauer2019-02-061-1/+1
| | | | | | | loff_t is the correct type for file sizes. Use it to allow to truncate to sizes bigger than 32bit. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* fs: devfs: Change .lseek callbacks to return 'int'Andrey Smirnov2019-02-041-3/+3
| | | | | | | | | | | Returning requested offset from .lseek() callback doesn't really give us any new information while bringing unnecessary complications. Change all .lseek() types (both in struct struct cdev_operations and in struct fs_driver_d) to return 'int' and adjust the rest of the codebase accordingly. 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-2/+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>
* fs: Update FILE position in lseek()Andrey Smirnov2019-01-291-2/+0
| | | | | | | | | | Instead on relying on driver callbacks to update 'pos' in FILE, do it as a part of lseek() code. This allows us to drop a bit of repeating code as well as making lseek() implementation consistent with write() and read(). Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* devfs: Fix incorrect error check for cdev->ops->lseek()Andrey Smirnov2019-01-291-5/+9
| | | | | | | | | | | | | | | | | | Cdev->ops->lseek() will either return a negative error code on failure or requested position on success. In order to properly check for errors we need to test if the return value is negative, not just that it's not -1. Returning ret - cdev->offset, doesn't appear to be correct either, even if ret is -1, since on failure this will lead us to return (-1 - cdev->offset). Simplify that part by just returning 'pos', which is what we'd end up returning on success in original code as well. Third, make sure to return -ENOSYS, when no .lseek() callback is provided. Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* fs: devfs: Make locally used function staticSascha Hauer2018-11-121-1/+1
| | | | | | devfs_iterate() is only used locally, so make it static. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* fs: devfs: implement d_revalidate hookSascha Hauer2018-10-291-0/+27
| | | | | | | | | | | | | | | | | | | The files in devfs can change withouut the fs layer noticing, so we have to revalidate dentries before using them. A failure could be triggered with: ls /dev/nand0.root.ubi; ubiattach /dev/nand0.root; ls /dev/nand0.root.ubi The first 'ls' would create a dentry for nand0.root.ubi with no inode associated since it does not yet exist. 'ubiattach' then creates that file, but the second 'ls' does not show it since the dentry is not revalidated and thus no inode is added to that dentry. This patch fixes this and also the opposite case when a file is removed (for example with ubidetach). Reported-by: Ladislav Michl <ladis@linux-mips.org> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* fs: devfs: fix r/w permissionsSascha Hauer2018-09-171-1/+6
| | | | | | | | | The real r/w flags were lost in the switch to dentry cache implementation. Restore them. Fixes: 9137c41915 ("fs: devfs: Switch to dentry cache implementation") Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* fs: devfs: Create device files as character devicesSascha Hauer2018-09-171-2/+2
| | | | | | | | | | | | Without this files in /dev/ appear as regular files. copy_file() stumbles upon this as it tries a truncate() on that files which then fails. Create the files as character devices so that copy_file() works as expected. Fixes: 9137c41915 ("fs: devfs: Switch to dentry cache implementation") Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de> Tested-by: Giorgio Dal Molin <giorgio.nicole@arcor.de>
* fs: devfs: Switch to dentry cache implementationSascha Hauer2018-07-111-65/+85
| | | | Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* devfs: Add optional truncate callback for device filesTeresa Remmet2017-01-111-0/+5
| | | | | | | | Not all device files have trivial fix device sizes like static ubi volumes. Here the device file size equals the image size it contains. Signed-off-by: Teresa Remmet <t.remmet@phytec.de> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* mtd: Fix erasing of devices >4GiBSascha Hauer2016-02-091-1/+1
| | | | | | | | | When a device >4GiB is erased, not only the offset can be bigger than 4GiB, but also the size. This happens with the simplest command to erase a device: erase /dev/nand0. Make the size argument a 64bit type to make this work. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* devfs: Add symlink supportSascha Hauer2016-01-081-1/+26
| | | | Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* fs: devfs: Allow mounting only on /dev/Sascha Hauer2015-10-151-0/+7
| | | | | | | We have places in the code where we assume that devfs is mounted on /dev/, so enforce this path to avoid surprises. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* fs: rename inode member of struct filep to privSascha Hauer2015-03-091-10/+10
| | | | | | | Because that's what it is. 'inode' will become confusing once we support real inodes. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* fs: store pointer to fsdev instead of dev in struct filepSascha Hauer2014-10-081-2/+2
| | | | | | | | The struct device_d * in struct filep is never of interest, instead it is always converted to a struct fs_device_d *, so simplify the code by storing the struct fs_device_d * directly. 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>
* fs: fix standard zero, full devicesSascha Hauer2012-07-041-1/+2
| | | | | | | | | | | | | | | | The standard devices are currently broken since they have the size ~0. As now files use loff_t as file size which is a signed type the read implementation gets confused and now returns -1. The current implementation also has the (somewhat theorical) problem that we do not have real streaming devices, so /dev/zero went out of zeroes after reading 4GB (or now LLONG_MAX). This patch introduces a new cdev flag DEVFS_IS_CHARACTER_DEV and a new file size flag FILE_SIZE_STREAM which makes it possible to create real stream devices instead. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* Merge branch 'for-next/resource-size'Sascha Hauer2012-07-021-1/+1
|\ | | | | | | | | | | Conflicts: drivers/base/resource.c fs/fs.c
| * resource: store 'end' instead of 'size' in struct resourceSascha Hauer2012-07-011-1/+1
| | | | | | | | | | | | | | | | | | | | Storing the size instead of the resource end in struct resource was a mistake. 'size' ranges from 0 to UINT[32|64]_MAX + 1 which obviously leads to problems. 'end' on the other hand will never exceed UINT[32|64]_MAX. Also this way we can express a iomem region covering the whole address space. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* | Merge branch 'for-next/misc'Sascha Hauer2012-07-021-0/+6
|\ \
| * | fs/devfs.c: disallow write and erase if a partition is read-onlyJan Luebbe2012-06-301-0/+6
| |/ | | | | | | | | Signed-off-by: Jan Luebbe <jlu@pengutronix.de> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* | make cdev 64bit capableSascha Hauer2012-06-301-2/+2
| | | | | | | | | | | | 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-3/+3
|/ | | | | | | This is a first step for 64bit file support: Make the file sizes/offsets 64bit. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* devfs: don't erase past the end of the partitionJohannes Stezenbach2012-06-071-0/+3
| | | | | | | | "erase /dev/myflash0.mypart 0xf0000+0xf0000" could erase past the end of the partition. Signed-off-by: Johannes Stezenbach <js@sig21.net> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* fs: get fs device using container_ofSascha Hauer2012-02-251-1/+0
| | | | | | This reduces the usage of dev->type_data. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* cdev: pass flags to open functionSascha Hauer2011-12-151-1/+1
| | | | Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* fs: switch to resourceJean-Christophe PLAGNIOL-VILLARD2011-07-301-1/+3
| | | | Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
* devfs: factor out core devfs functionalitySascha Hauer2011-04-111-165/+2
| | | | | | | | | This makes it possible to compile without devfs. devfs_create/devfs_remove is used by drivers and thus must still be present even without devfs support. Also, this patch adds cdev_open/cdev_close/cdev_flush/cdev_ioctl calls to work with devices without using the file api. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* fs: implement flush functionSascha Hauer2011-04-111-0/+11
| | | | | | | Once we have caching in file functions we need a way to sync the the underlying devices. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* devfs: remove unused struct filep* argument from open/closeSascha Hauer2011-04-111-2/+2
| | | | | | | the cdev layer is under the file layer, so it should not use struct filep*. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* fs: remove unused field 'type' from struct fs_driver_dSascha Hauer2011-04-111-1/+0
| | | | Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* devfs: only check for ioctl function when neededSascha Hauer2010-07-051-8/+7
| | | | Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* add partition mtd supportSascha Hauer2010-07-051-0/+31
| | | | Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* rename U-Boot-v2 project to bareboxSascha Hauer2009-12-151-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | This has been done with the following script: find -path ./.git -prune -o -type f -print0 | xargs -0 -r sed -i \ -e 's/u2boot/barebox/g' \ -e 's/U2Boot/barebox/g' \ -e 's/U-boot V2/barebox/g' \ -e 's/u-boot v2/barebox/g' \ -e 's/U-Boot V2/barebox/g' \ -e 's/U-Boot-v2/barebox/g' \ -e 's/U_BOOT/BAREBOX/g' \ -e 's/UBOOT/BAREBOX/g' \ -e 's/uboot/barebox/g' \ -e 's/u-boot/barebox/g' \ -e 's/u_boot/barebox/g' \ -e 's/U-Boot/barebox/g' \ -e 's/U-boot/barebox/g' \ -e 's/U-BOOT/barebox/g' find -path ./.git -prune -o \( -name "*u-boot*" -o -name "*uboot*" -o -name "*u_boot*" \) -print0 | \ xargs -0 -r rename 's/u[-_]?boot/barebox/' It needs some manual fixup following in the next patch Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* devfs: fix return value for lseek in partitionsSascha Hauer2009-09-251-1/+1
| | | | Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>