summaryrefslogtreecommitdiffstats
path: root/fs/fs.c
Commit message (Collapse)AuthorAgeFilesLines
* Merge branch 'for-next/misc'Sascha Hauer2024-03-151-0/+2
|\
| * of: partition: Also add partitions created by addpart to the boot dtbUwe Kleine-König2024-03-131-0/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | A partition added interactively using addpart was added in of_partition_fixup() before commit aec676b568 ("cdev: record whether partition is parsed from OF"). Restore that behaviour. To do that a new flag DEVFS_PARTITION_FOR_FIXUP is created that behaves very similar what DEVFS_PARTITION_FROM_OF did before. The only difference is that addpart makes use of it (and that stat uses a different string to describe it). Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de> Link: https://lore.barebox.org/20240312100918.604105-1-u.kleine-koenig@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* | filetype: have cdev_detect_type take a cdevAhmad Fatoum2024-03-051-3/+11
| | | | | | | | | | | | | | | | | | | | | | cdev_detect_type reads as if it would take a cdev argument, but instead it takes the adev's path. Fix it, so it takes a cdev and change the only user. A new user will be added later that will pass in an already open cdev. Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Link: https://lore.barebox.org/20240304190038.3486881-51-a.fatoum@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* | commands: stat: add option for statatAhmad Fatoum2024-03-051-3/+2
| | | | | | | | | | | | | | | | | | The stat command is a debugging aid for developing the VFS, so it makes sense to add support for dirfd, so they can be tested interactively. Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Link: https://lore.barebox.org/20240304190038.3486881-44-a.fatoum@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* | fs: support opening /Ahmad Fatoum2024-03-051-8/+6
| | | | | | | | | | | | | | | | | | | | | | | | | | With open() on / no longer accessing uninitialized memory, it now always fails with errno == ENOENT. This is because d_lookup only compares children of /, but never / itself. Fix this by comparing the parent and while at it, rework the existing code to be more concise. Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Link: https://lore.barebox.org/20240304190038.3486881-42-a.fatoum@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* | fs: initialize struct nameidata::lastAhmad Fatoum2024-03-051-0/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | The last member is normally written by link_path_walk(), before being read by __lookup_hash, among others. In the special case of calling open() on "/", link_path_walk() will terminate early without setting the last member, leading __d_alloc called by __lookup_hash to read uninitialized memory. Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Link: https://lore.barebox.org/20240304190038.3486881-41-a.fatoum@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* | commands: introduce new findmnt commandAhmad Fatoum2024-03-051-3/+1
| | | | | | | | | | | | | | | | | | | | EFI loader support will need to map barebox VFS paths to fs_device and back. Make development easier by providing a findmnt command to test the mapping. Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Link: https://lore.barebox.org/20240304190038.3486881-40-a.fatoum@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* | fs: implement O_CHROOTAhmad Fatoum2024-03-051-2/+17
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | For use by EFI file system path resolution, implement an O_CHROOT flag that will map / to the root of the file system the dirfd points to instead of the VFS root. If the dirfd points to a mountpoint, it will be followed to the file system inside. This is similar to Linux openat2 with RESOLVE_IN_ROOT. Without this, the EFI protocol would have to do path sanitization itself before passing paths to the barebox VFS implementation. Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Link: https://lore.barebox.org/20240304190038.3486881-39-a.fatoum@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* | fs: support different root directoriesAhmad Fatoum2024-03-051-6/+8
| | | | | | | | | | | | | | | | | | | | | | | | | | | | A root directory is a directory that has itself as the parent. There is only one such directory, but for chroot support we will want to stop path resolution at a non-root directory as well. We do this by giving struct nameidata a d_root field, which serves as a root directory for the lookup. As we initialize it to the global root directory, this introduces no functional change. Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Link: https://lore.barebox.org/20240304190038.3486881-38-a.fatoum@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* | fs: implement O_PATHAhmad Fatoum2024-03-051-24/+34
| | | | | | | | | | | | | | | | | | | | For use with the newly added openat and friends API, add O_PATH file descriptors that are not usable for doing actual I/O, but only for use as dirfd. Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Link: https://lore.barebox.org/20240304190038.3486881-37-a.fatoum@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* | fs: implement openat and friendsAhmad Fatoum2024-03-051-60/+80
| | | | | | | | | | | | | | | | | | | | | | | | The EFI file system API takes as handle an arbitrary file within the volume. Directory iteration should happen relative to that file, which lends itself well to mapping this to openat and friends. Add support for these to barebox in preparation. Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Link: https://lore.barebox.org/20240304190038.3486881-36-a.fatoum@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* | fs: set current working dir directly when mounting rootAhmad Fatoum2024-03-051-5/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | The default current working directory is the root directory, but this can't be initialized statically, because the root directory is only mounted at runtime. Therefore, the get_pwd accessor initializes the current working directory on first access. Instead we could just initialize them when we mount the root directory and simplify the code a tiny bit. Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Link: https://lore.barebox.org/20240304190038.3486881-35-a.fatoum@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* | fs: always check path_init for errorsAhmad Fatoum2024-03-051-0/+4
| | | | | | | | | | | | | | | | | | | | | | We have three calls to path_init, but Only one of them checks the returned pointer value for errors. This didn't hurt so far, because the function always succeeded, but a follow-up commit will cause it to fail in some circumstances, so prepare for that by duly checking the return value. Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Link: https://lore.barebox.org/20240304190038.3486881-34-a.fatoum@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* | fs: remove unused member from struct nameidataAhmad Fatoum2024-03-051-9/+0
| | | | | | | | | | | | | | | | | | A number of members in the struct are either unused or only ever written and never read. Drop them to tidy up the code. Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Link: https://lore.barebox.org/20240304190038.3486881-33-a.fatoum@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* | fs: implement fdopendir and rewinddirAhmad Fatoum2024-03-051-2/+53
| | | | | | | | | | | | | | | | | | | | | | | | We will be using the incoming O_PATH support to implement the EFI file system protocol for when barebox acts as EFI loader. The protocol also requires being able to rewind iteration, so add support for that too. Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Link: https://lore.barebox.org/20240304190038.3486881-32-a.fatoum@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* | fs: factor out opendir iterationAhmad Fatoum2024-03-051-20/+32
| | | | | | | | | | | | | | | | | | In preparation for supporting fdopendir and rewinddir, add an __opendir helper that is reused in a follow-up commit. Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Link: https://lore.barebox.org/20240304190038.3486881-31-a.fatoum@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* | fs: opendir: reference mount point until closedir is calledAhmad Fatoum2024-03-051-2/+2
| | | | | | | | | | | | | | | | | | | | | | | | We currently don't keep the path used for opendir alive beyond the function, because all files are read and added into a linked list at once. If an unmount happens before closedir though, the file names will become invalidated, which shouldn't happen. Keep the path alive for longer to block unmount until directory iteration is over. Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Link: https://lore.barebox.org/20240304190038.3486881-30-a.fatoum@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* | fs: drop unused LOOKUP_ flagsAhmad Fatoum2024-03-051-10/+1
| | | | | | | | | | | | | | | | | | Most flags used during VFS lookup are apparently unused, so let's delete them to make the code easier to reason about. Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Link: https://lore.barebox.org/20240304190038.3486881-29-a.fatoum@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* | fs: turn creat into static inline helperAhmad Fatoum2024-03-051-6/+0
| | | | | | | | | | | | | | | | | | creat is a oneliner that can be inlined at no extra cost, so move it into a header. Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Link: https://lore.barebox.org/20240304190038.3486881-28-a.fatoum@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* | fs: fix unreaddir, so readdir returns unread dirent firstAhmad Fatoum2024-03-051-1/+1
| | | | | | | | | | | | | | | | | | | | unreaddir should return a directory entry at the top of the list, so readdir consumes it again, not at the end. Fixes: 7876018f7333 ("fs: implement unreaddir") Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Link: https://lore.barebox.org/20240304190038.3486881-27-a.fatoum@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* | commands: stat: display bootable partition table bit infoAhmad Fatoum2024-03-051-0/+4
| | | | | | | | | | | | | | | | | | | | There's no common code yet, but board code may iterate over cdevs to handle the boot partition specially. Make writing such code easier by adding the new flags to the stat command's output. Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Link: https://lore.barebox.org/20240304190038.3486881-23-a.fatoum@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* | commands: stat: print DT node for cdevs if availableAhmad Fatoum2024-03-051-0/+5
| | | | | | | | | | | | | | | | | | It may not be directly apparent, what device a cdev spawned from. Have stat report this information for debugging purposes. Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Link: https://lore.barebox.org/20240304190038.3486881-21-a.fatoum@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* | cdev: implement setter/getter for cdev device nodeAhmad Fatoum2024-03-051-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | A cdev has two device tree node pointers, one directly at struct cdev.device_node and another indirectly via cdev.dev->device_node. We may want to remove cdev::device_node in future, but till then to avoid users having to guess, which device_node is the correct one, add a helper to set and get the device tree node. Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Link: https://lore.barebox.org/20240304190038.3486881-19-a.fatoum@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* | treewide: add errno_set helper for returning positive error code in errnoAhmad Fatoum2024-03-051-84/+28
|/ | | | | | | | | | | We have this sequence at multiple places: Check a return value for being below zero and if so, turn it positive and store into errno. Instead of opencoding it everywhere, add a helper to encapsulate this. Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Link: https://lore.barebox.org/20240304190038.3486881-4-a.fatoum@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* fs: add open O_TMPFILE supportAhmad Fatoum2023-12-131-0/+29
| | | | | | | | | | | | | | | | | | | | | | barebox dentry cache is never cleared with the assumption that there should be enough RAM anyway to cache all lookups until boot. When fuzzing barebox however, there is no limit to how many dentries are added to the cache. This is e.g. problematic when fuzzing the FIT parser: FIT images can have compressed payloads. Compressed payloads are passed to uncompress_buf_to_buf, which uses a new random file in ramfs as destination. A fuzzer would thus create a dentry for every iteration, rapidly depleting memory. A general solution for that would be dropping the dentry cache on memory pressure. In the special case of uncompress_buf_to_buf, it would already be enough though to sidestep the dentry cache and create an anonymous file. Linux provides this with the O_TMPFILE option, so let's add the equivalent to barebox. Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Link: https://lore.barebox.org/20231122170323.15175-1-a.fatoum@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* filetype: return error and pass filetype as pointer argumentSascha Hauer2023-08-181-3/+4
| | | | | | | | | | | | | | | | | file_name_detect_type(), file_name_detect_type_offset() and cdev_detect_type() return the filetype. With this all errors from these functions remain undetected and are just returned as filetype_unknown. Explicitly return an error code and pass the filetype as pointer argument so that callers can detect and handle errors. This fixes a bug in the bootm code where the returned filetype was erroneously tested for being smaller than 0. This was never true and so the corresponding error message was never printed. Now with this patch a non existing initrd or device tree file is responded with a meaningful error message. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* Merge branch 'for-next/state'Sascha Hauer2023-06-221-10/+23
|\
| * common: partitions: efi: record type UUID in cdevAhmad Fatoum2023-06-121-0/+2
| | | | | | | | | | | | | | | | | | | | We already record DOS partition type in cdev, so let's do the same for GPT Type UUID. This will be used in a later commit to identify barebox-state partitions. Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Link: https://lore.barebox.org/20230607120714.3083182-19-a.fatoum@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
| * cdev: use cdev::dos_partition_type only if cdev_is_mbr_partitionedAhmad Fatoum2023-06-121-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | dos_partition_type == 0 can mean that either a partition is not a MBR partition or that it indeed has a partition type of 0x00. In preparation for using that field in a union, explicitly check if we have a MBR partition. Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Link: https://lore.barebox.org/20230607120714.3083182-18-a.fatoum@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
| * common: partitions: record whether disk is GPT or MBR partitionedAhmad Fatoum2023-06-121-0/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Currently, the only way to differentiate between a GPT disk and a MBR one is to check whether the cdev's device has a guid (=> GPT) or a nt_signature (=> MBR) device parameter. We already have a flag parameter though, so let's record this info there for easy retrieval. We intentionally don't use the struct cdev::filetype member, because we don't want to change behavior of file_detect_type(). Reviewed-by: Marco Felsch <m.felsch@pengutronix.de> Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Link: https://lore.barebox.org/20230607120714.3083182-14-a.fatoum@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
| * cdev: record whether partition is parsed from OFAhmad Fatoum2023-06-081-0/+2
| | | | | | | | | | | | | | | | | | | | | | | | Later code will make it possible to define an on-disk-described partition in the DT as well. For this reason, we can't assume DEVFS_PARTITION_FROM_TABLE to mean !DT, so let's add a dedicated flag for that. Reviewed-by: Marco Felsch <m.felsch@pengutronix.de> Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Link: https://lore.barebox.org/20230607120714.3083182-11-a.fatoum@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
| * cdev: use more descriptive struct cdev::diskuuid/partuuidAhmad Fatoum2023-06-081-4/+5
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The UUID field has different meanings: For a master cdev: - GPT Header DiskGUID if GPT-formatted - MBR Header NT Disk Signature if MBR-formatted For a partition cdev: - GPT UniquePartitionGUID - MBR Header NT Disk Signature followed by "-${partititon_number}" Later code will add yet another UUID (Partition Type GUID), so let's make existing code more readable by using either diskuuid or partuuid as appropriate. No functional change. Reviewed-by: Marco Felsch <m.felsch@pengutronix.de> Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Link: https://lore.barebox.org/20230607120714.3083182-10-a.fatoum@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
| * commands: stat: remove code duplication for type infoAhmad Fatoum2023-06-081-8/+12
| | | | | | | | | | | | | | | | | | | | | | | | stat prints a line with partitioning/type info for cdevs, but not all cdevs have these, so we want to skip printing when it's empty. Instead of duplicating the check, just utilize printf returning the number of characters written. Reviewed-by: Marco Felsch <m.felsch@pengutronix.de> Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Link: https://lore.barebox.org/20230607120714.3083182-9-a.fatoum@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* | commands: stat: add basic handling for cdev linksAhmad Fatoum2023-06-011-3/+11
| | | | | | | | | | | | | | | | | | | | | | | | | | | | cdev links are not symlinks and cdev_by_name will always resolve them. As the barebox stat command is a convenience for VFS developers, it's useful to have the command identify links, so let's teach it just that. There's no behavior difference between specifying -L and not. This should be rather achieved by removing the concept of cdev links and using symlinks instead, but that's some refactoring for another time. Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Link: https://lore.barebox.org/20230531132331.2152268-2-a.fatoum@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* | commands: stat: print symlink destination when called without -LAhmad Fatoum2023-06-011-2/+15
|/ | | | | | | | This aligns behavior with usual implementations of stat. Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Link: https://lore.barebox.org/20230531132331.2152268-1-a.fatoum@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* fs: fail gracefully in get_mounted_path/get_cdev_by_mountpathAhmad Fatoum2023-05-081-0/+4
| | | | | | | | | | get_fsdevice_by_path will return NULL if no file system was mounted at location. Returned pointer was dereferenced unconditionally, potentially leading to null pointer dereference. Fix this. Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Link: https://lore.barebox.org/20230508074612.3313870-1-a.fatoum@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* commands: stat: fix UUID printAhmad Fatoum2023-03-141-6/+3
| | | | | | cdev->uuid is an already formatted string, not a binary UUID. Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
* Merge branch 'for-next/misc'Sascha Hauer2023-02-231-2/+2
|\
| * fs: remove unused members of struct statAhmad Fatoum2023-02-031-2/+2
| | | | | | | | | | | | | | | | Some members in struct stat are never written, so drop them. Signed-off-by: Ahmad Fatoum <ahmad@a3f.at> Link: https://lore.barebox.org/20230202142512.3551195-1-ahmad@a3f.at Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* | fs: align write return codes with POSIXAhmad Fatoum2023-02-031-0/+2
|/ | | | | | | | | | | | | | | | | | | | | | | | Writing past end of a file results in a cryptic error code: barebox@board:/ cp /dev/zero /dev/mmc0.part write: Operation not permitted cp: Operation not permitted Because the cdev's truncate is not implemented and as such partition can't be increased in size. POSIX specifies EPERM as the correct return code for truncate(2) in such a situation, but for write(2) it is ENOSPC. Thus most truncate callbacks in barebox instead return ENOSPC, when according to POSIX, EPERM would have been the correct error code to propagate. Switching all truncate drivers is a bit more involved, so for now let's treat EPERM and ENOSPC instead when truncate fails to enlarge a file. Reported-by: Marco Felsch <m.felsch@pengutronix.de> Reviewed-by: Marco Felsch <m.felsch@pengutronix.de> Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Link: https://lore.barebox.org/20230202132734.314110-1-a.fatoum@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* Rename struct fs_driver_d to fs_driverSascha Hauer2023-01-101-16/+16
| | | | | | | | | 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-27/+27
| | | | | | | | | 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 driver_d to driverSascha Hauer2023-01-101-3/+3
| | | | | | | | | | | The '_d' suffix was originally meant to distinguish barebox struct names from Linux struct names. struct driver doesn't exist in Linux, so we can rename it and remove the meaningless 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-4-s.hauer@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* Rename struct device_d to deviceSascha Hauer2023-01-101-5/+5
| | | | | | | | | | | | | 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>
* fs: avoid uninitialized var warningSascha Hauer2022-11-081-1/+1
| | | | | | | | | | | | | | | | | | | With gcc-12.2.1-clang-15.0.2-glibc-2.36-binutils-2.39-kernel-6.0.5-sanitized we get a warning about path.dentry being used uninitialized: fs/fs.c:1978:43: warning: 'path.dentry' may be used uninitialized -Wmaybe-uninitialized] I can't see how this can really happen. gcc seems to think that this sequence used in lookup_fast() can result in returning 0: if (IS_ERR(dentry)) return PTR_ERR(dentry); This shouldn't happen. Silence the warning by initializing 'path'. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de> Link: https://lore.barebox.org/20221107102800.3669168-1-s.hauer@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* commands: add new stat commandAhmad Fatoum2022-10-271-1/+104
| | | | | | | | | | | | | We have a couple of commands to help with debugging the VFS: ll, devinfo, devlookup, but we lack a command that can just dump all information we have in a struct stat or struct cdev. Add stat as such a command. For most uses, it's not needed, but it can come in handy for development. The stat_print and cdev_print functions underlying it are exported, so they can called for debugging purposes. Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Link: https://lore.barebox.org/20221026063819.2355568-1-a.fatoum@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* Merge branch 'for-next/selftest'Sascha Hauer2022-10-131-0/+15
|\
| * fs: implement unreaddirAhmad Fatoum2022-10-111-0/+15
| | | | | | | | | | | | | | | | | | | | When iterating over a directory, it can be useful to put back the just read directory entry, so it can be retried at a later time. This will be needed for the EFI loader variable support. Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Link: https://lore.barebox.org/20221010061437.2085412-4-a.fatoum@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* | fs: export file system detection functionalityAhmad Fatoum2022-10-051-2/+2
| | | | | | | | | | | | | | | | | | This will come in handy when using barebox as EFI loader, so give it a more generic name and export it. Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Link: https://lore.barebox.org/20220930154053.752237-1-a.fatoum@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* | fs: implement cdev_mount()Ahmad Fatoum2022-10-041-0/+19
|/ | | | | | | | | | | EFI loaders provide both block device and file system access to software running under it. For file system access, we will just want to get a mount if available and mount at a default location if not. Provide a helper that does just that. Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Link: https://lore.barebox.org/20220930154017.750867-1-a.fatoum@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>