summaryrefslogtreecommitdiffstats
path: root/fs/fs.c
Commit message (Collapse)AuthorAgeFilesLines
* fs: Simplify fd to FILE lookup codeAndrey Smirnov2019-02-271-53/+30
| | | | | | | | | Avoid a bit of repeating code by merging checking fd for correctness and fd to FILE lookup into a single routine and converting the rest of the code to use it. Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* fs: Drop unused code in fstat()Andrey Smirnov2019-02-271-3/+0
| | | | | Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* fs: Drop needless OOM checkAndrey Smirnov2019-02-271-3/+0
| | | | | | | Drop needless OOM check since xzalloc() will never return NULL. Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* Merge branch 'for-next/lseek'Sascha Hauer2019-02-131-20/+20
|\
| * fs: do not call truncate for FILE_SIZE_STREAM sized filesSascha Hauer2019-02-061-0/+3
| | | | | | | | | | | | | | | | | | | | open_and_lseek() increases the file size when the file is opened in write mode and scrolled past the files end. This fails badly on /dev/mem because loff_t which we use for the file size is signed variable, which is used as an unsigned variable in /dev/mem. To catch this case do not try to truncate FILE_SIZE_STREAM sized files. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
| * fs: set errno in ftruncate()Sascha Hauer2019-02-061-1/+3
| | | | | | | | | | | | ftruncate needs to set errno correctly on error. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
| * fs: Simplify new position calculation in lseek()Andrey Smirnov2019-02-041-11/+8
| | | | | | | | | | | | | | | | | | | | | | | | | | | | All these checks are really testing is that resulting position is within [0; f->size] interval. Convert all of the custom checks into a signle one done after the switch statement to simplify the code. Note this change also disables the validity check for f->size == FILE_SIZE_STREAM and whence == SEEK_END, but lseek(stream_fd, offset, SEEK_END) wasn't a meaningful operation to begin with, so this shouldn't be a problem. Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
| * fs: Do not use IS_ERR_VALUE() to validate offset in lseek()Andrey Smirnov2019-02-041-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | On 32-bit systems, checking for IS_ERR_VALUE(pos) is not correct. Expanding that code we get (loff_t cast is added for clarity): (loff_t)pos >= (unsigned long)-MAX_ERRNO given that loff_t is a 64-bit signed value, any perfectly valid seek offset that is greater than 0xffffc000 will result in false positive. Moreso, as a part of fix introduced in e10efc5080 ("fs: fix memory access via /dev/mem for MIPS64") it doesn't really solve the problem completely on on 64-bit platforms, becuase it still leaves out a number of perfectly valid offsets (e.g. "md 0xffffffffffffff00" doesn't work) Undo the original change and convert the check to simply test if offset is negative. Changes neccessary to alllow access to end of 64-bit address space will be implemented in the follow-up patch. Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
| * fs: devfs: Change .lseek callbacks to return 'int'Andrey Smirnov2019-02-041-5/+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>
| * fs: Drop trivial .lseek() implementaitons in FS driversAndrey Smirnov2019-01-291-8/+6
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | There are no FS drivers that do not implement .lseek callback in the codebase, so there doesn't seem to exist a use-case where lseek() would return -ENOSYS due to fsdrv->lseek being NULL. At the same time a large number of FS drivers implement only the most basic "always succeeds" custom .lseek() hook. Change the code of lseek() to treat absense of .lseek() to mean that no special actions needs to be taken by FS driver and seek is always successful and drop all of the trivial .lseek() implementations. 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-0/+2
| | | | | | | | | | | | | | | | | | | | 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>
* | treewide: Introduce MAP_FAILED and replace ad-hoc constants with itAndrey Smirnov2019-01-161-1/+1
|/ | | | | Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* fs: fix possible null pointer dereference of base.Oleksij Rempel2018-11-211-1/+2
| | | | | | | we use base before checking if it is NULL Signed-off-by: Oleksij Rempel <linux@rempel-privat.de> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* fs: closedir: remove uninitialized variable retOleksij Rempel2018-11-211-3/+1
| | | | | Signed-off-by: Oleksij Rempel <linux@rempel-privat.de> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* Merge branch 'for-next/net-switch-mv88e6xxx'Sascha Hauer2018-11-091-1/+1
|\
| * drivers: Introduce dev_set_name()Andrey Smirnov2018-10-181-1/+1
| | | | | | | | | | | | | | | | Introduce dev_set_name() in order to hide implementation details of setting device's name so it'd be easier to change it. Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* | Merge branch 'for-next/missing-prototypes'Sascha Hauer2018-11-091-18/+18
|\ \
| * | fs: Make locally used functions staticSascha Hauer2018-10-191-18/+18
| |/ | | | | | | Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* / fs: implement d_revalidateSascha Hauer2018-10-291-1/+36
|/ | | | | | | d_revalidate is useful when filesystems change under the hood of the fs layer. This can happen with network filesystems or with devfs. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* fs: implement clear_nlink and set_nlinkSascha Hauer2018-10-081-0/+16
| | | | | | | Implement clear_nlink and set_nlink and remove the private versions from UBIFS. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* fs: implement iget_locked and iget_failedSascha Hauer2018-10-081-0/+24
| | | | | | Implement in fs core rather than using a private version in UBIFS. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* fs: implement file_inodeSascha Hauer2018-10-081-0/+1
| | | | | | To ease code porting from Linux Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* fs: stat: Do not forget to set errnoSascha Hauer2018-09-261-0/+3
| | | | | | | | stat() needs to set errno correctly when returning with an error. Fixes: b3fbfad7ae ("fs: dentry cache implementation") Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* fs: open: Do not forget to set errnoSascha Hauer2018-09-261-1/+1
| | | | | | | | | When the initial lookup fails in open we have to go to the error path which sets errno correctly rather than returning directly. Fixes: b3fbfad7ae ("fs: dentry cache implementation") Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* fs: dentry cache implementationSascha Hauer2018-07-111-995/+2191
| | | | | | | | | | | | | | | | | | | | | | | This adds the Linux dentry cache implementation to barebox. Until now every filesystem driver resolves the full path to a file for itself. This leads to code duplication and is error prone since resolving paths is a complicated task. Also it can narrow down the lookup performance since barebox only knows ASCII paths and has no way of caching lookups. With this patch we get the Linux dcache implementation. The path resolving code from fs/namei.c is nearly taken as-is, minus the RCU and locking code. Dcaching is made simple as of now: We simply cache everything and never release any dentries. Although we do reference counting for inodes and dentries it is effectively not used yet. We never free anything until a fs is unmounted in which case we free everything no matter if references are taken or not. This patch also contains a wrapper in fs/legacy.c to support filesystems with the old API. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* fs: fix memory access via /dev/mem for MIPS64Peter Mamonov2018-06-141-2/+2
| | | | | | | | lseek checks for non-negative in-memory offsets (addresses), failing otherwise. However negative address 0xffffffffXXXXXXXX is a valid MIPS64 virtual address. Signed-off-by: Peter Mamonov <pmamonov@gmail.com> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* fs: Fix finding correct directory for mkdir/rmdirSascha Hauer2018-04-061-2/+2
| | | | | | | When there are links in the path mkdir/rmdir are called with then canonicalize_path is needed which resolves the links. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* fs: Cleanup whitespace damageSascha Hauer2018-04-061-13/+13
| | | | | | fs.c has some whitespaces where there should be tabs. Fix it. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* fs: Move mem_write/mem_read to devfs-coreSascha Hauer2018-04-061-66/+0
| | | | | | | fs.c is already heavily filled with code. Move mem_write/mem_read to devfs-core where it fits better. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* fs: check pointer returned by get_fsdevice_by_path before dereferencingGaël PORTAY2018-03-191-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | In __canonicalize_path() we dereference the pointer returned by get_fsdevice_by_path() without checking if the pointer is NULL or not. When the pointer is NULL it leads to an Ooops. Ooops, address error on load or ifetch! $ 0 : 00000000 00000001 a0000026 a0811c10 $ 4 : a0402e60 a0402e48 a0811c00 a0402e58 $ 8 : 00000001 00000000 0000005a 00000023 $12 : 00000000 00000002 00601021 00000000 $16 : a0402e60 a0402e50 a0402e39 a0810000 $20 : a0402e38 a0811420 a0811424 00000000 $24 : 00000000 a080de10 $28 : 87f87d40 a03ffa68 a0810000 a080ce30 Hi : 00000002 Lo : 00000000 epc : a080ce34 ra : a080ce30 Status: 00000006 Cause : 40008010 Config: 80040483 ### ERROR ### Please RESET the board ### Fixes: d79a81736 fs: Don't bother filesystems without link support with additional stat() calls Signed-off-by: Gaël PORTAY <gael.portay@savoirfairelinux.com> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* Merge branch 'for-next/tftp-workaround'Sascha Hauer2018-02-081-0/+22
|\
| * fs: implement is_tftp_fs()Sascha Hauer2018-01-251-0/+22
| | | | | | | | | | | | | | | | | | | | Some commands need files in which they can lseek backwards which is particularly not possible on TFTP. Instead of hiding this behind can_lseek_backward() create a function for it which tests if the file is on TFTP directly rather than using different lseek operations. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* | fs: add support loop mount offsetPhilipp Zabel2018-02-051-3/+9
| | | | | | | | | | | | | | | | When loop mounting, allow to specify an offset into the file, similarly to the losetup offset option. Multiplicative suffixes are supported. Signed-off-by: Philipp Zabel <p.zabel@pengutronix.de> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* | fs: Fix memory leak in mount()Sascha Hauer2018-01-261-0/+2
|/ | | | | | | | "path" is allocated by normalise_path() and thus must be freed. This was done in the error path, but not in the success path. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* Merge branch 'for-next/misc'Sascha Hauer2018-01-221-2/+1
|\
| * move parseopt to lib/Antony Pavlov2018-01-171-2/+1
| | | | | | | | | | Signed-off-by: Antony Pavlov <antonynpavlov@gmail.com> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* | fs: implement ftruncateSascha Hauer2018-01-101-0/+22
|/ | | | Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* fs: Don't bother filesystems without link support with additional stat() callsSascha Hauer2017-09-061-0/+10
| | | | | | | | | | | | | In __canonicalize_path() we only call stat() to know if the path is a link or not. When the filesystem doesn't support links we already know that it's not a link, so we do not need to call stat(). This helps the tftp filesystem since the parent directories of a file to be opened won't be stat()ed anymore, something tftp does not support. Fixes: a602bebc fs: Implement links to directories Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* fs: avoid pathes with '//' in __canonicalize_path()Sascha Hauer2017-09-061-2/+7
| | | | | | | | | In __canonicalize_path pathes beginning with '//' can occur. This is normally not a problem since normalize_path() will clean this up, but it means we cannot call get_fsdevice_by_path() on these pathes in this function, as needed in the next patch. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* fs: Make locally used function canonicalize_dir() staticSascha Hauer2017-06-271-1/+1
| | | | Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* Merge branch 'for-next/misc'Sascha Hauer2017-06-141-4/+32
|\
| * fs: add cdev_create_loop and cdev_remove_loop for loop mount optionPhilipp Zabel2017-06-061-4/+18
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Allow to create a loopback cdev from a file. Signed-off-by: Philipp Zabel <p.zabel@pengutronix.de> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de> Fixed up with: fs: Makefile: Add parseopt to all builds parseopt.h was included to fs.c with commit 9248b, but parseopt.o has a dependency to CONFIG_FS_NFS. Moved parseopt.o to the default build to eliminate build failures. Signed-off-by: Daniel Schultz <d.schultz@phytec.de> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
| * fs: Create automount entries for the default mount pathesSascha Hauer2017-05-101-0/+14
| | | | | | | | | | | | | | | | | | | | 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>
* | fixup! fs: Implement links to directoriesSascha Hauer2017-05-111-2/+2
| |
* | fs: Implement links to directoriesSascha Hauer2017-05-111-118/+169
| | | | | | | | | | | | | | | | | | | | | | | | So far links can only point to files. Implement links to directories. With this all kinds of links are supported: - relative links - absolute links - links including ".." - link loops (are detected, return -EMLINK) Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* | fs: drop path_check_prereq()Sascha Hauer2017-05-111-65/+48
|/ | | | | | | | | | | | | | | | | path_check_prereq() has some bugs: - It's called with S_IFLNK, but this is effectively a no-op because this case is not implemented in the function - It uses lstat, but if stat or lstat should be used depends on the usecase: For opendir() stat() must be used, since we are not interested in the link, but in the target. For readlink() lstat() must be used since we are indeed interested in the link, not the target. It's easier and better understandable to open code the functionality where it's needed, so drop path_check_prereq() and do the right thing where called. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* lseek: tighten error checking and allow negative offsets for SEEK_ENDUwe Kleine-König2017-03-031-2/+4
| | | | | Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* lseek: ensure errno is set on failure and return -1Uwe Kleine-König2017-03-021-1/+7
| | | | | | | | All error paths before calling the driver's lseek callback return -1 and set errno. Do the same if the callback returns an error. Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* fs: Remove O_TRUNC check for devices when open filesTeresa Remmet2017-01-111-1/+1
| | | | | | | | Don't check for the file type here. Devices may have truncate callbacks. Otherwise the caller should check if O_TRUNC is possible. Signed-off-by: Teresa Remmet <t.remmet@phytec.de> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* fs: Check for correct open modeSascha Hauer2016-07-221-1/+11
| | | | | | | Check that readonly openen files is not written to and writeonly files is not read from. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>