summaryrefslogtreecommitdiffstats
path: root/fs/adfs
AgeCommit message (Collapse)AuthorFilesLines
2020-01-25fs/adfs: bigdir: Fix an error code in adfs_fplus_read()Dan Carpenter1-1/+2
This code accidentally returns success, but it should return the -EIO error code from adfs_fplus_validate_header(). Acked-by: Russell King <rmk+kernel@armlinux.org.uk> Fixes: d79288b4f61b ("fs/adfs: bigdir: calculate and validate directory checkbyte") Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com> Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
2020-01-20fs/adfs: mostly divorse inode number from indirect disc addressRussell King3-4/+7
Avoid using the inode number as the indirect disc address, even though these currently have the same value. Signed-off-by: Russell King <rmk+kernel@armlinux.org.uk> Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
2020-01-20fs/adfs: super: add support for E and E+ floppy image formatsRussell King1-1/+17
Add support for ADFS E and E+ floppy image formats, which, unlike their hard disk variants, do not have a filesystem boot block - they have a single map zone, with the map fragment stored at sector 0. Signed-off-by: Russell King <rmk+kernel@armlinux.org.uk> Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
2020-01-20fs/adfs: super: extract filesystem block probeRussell King1-71/+78
Separate the filesystem block probing from the superblock filling so we can support other ADFS filesystem formats, such as the single-zone E and E+ floppy image formats which do not have a boot block. Signed-off-by: Russell King <rmk+kernel@armlinux.org.uk> Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
2020-01-20fs/adfs: dir: remove debug in adfs_dir_update()Russell King1-3/+0
Remove the noisy debug in adfs_dir_update(). Signed-off-by: Russell King <rmk+kernel@armlinux.org.uk> Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
2020-01-20fs/adfs: super: fix inode droppingRussell King1-1/+7
When we have write support enabled, we must not drop inodes before they have been written back, otherwise we lose updates to the filesystem on umount. Keep the inodes around unless we are built in read-only mode, or we are mounted read-only. Signed-off-by: Russell King <rmk+kernel@armlinux.org.uk> Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
2020-01-20fs/adfs: bigdir: implement directory update supportRussell King1-1/+53
Implement big directory entry update support in the same way that we do for new directories. Signed-off-by: Russell King <rmk+kernel@armlinux.org.uk> Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
2020-01-20fs/adfs: bigdir: calculate and validate directory checkbyteRussell King1-0/+38
When reading a big directory, calculate the validate the directory checkbyte to ensure that the directory contents are valid. Signed-off-by: Russell King <rmk+kernel@armlinux.org.uk> Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
2020-01-20fs/adfs: bigdir: directory validation strengtheningRussell King1-1/+28
Strengthen the directory validation by ensuring that the header fields contain sensible values that fit inside the directory, and limit the directory size to 4MB as per RISC OS requirements. Signed-off-by: Russell King <rmk+kernel@armlinux.org.uk> Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
2020-01-20fs/adfs: bigdir: extract directory validationRussell King1-10/+31
Extract the directory validation from the directory reading function as we will want to re-use this code. Signed-off-by: Russell King <rmk+kernel@armlinux.org.uk> Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
2020-01-20fs/adfs: bigdir: factor out directory entry offset calculationRussell King1-6/+11
Factor out the directory entry byte offset calculation. Signed-off-by: Russell King <rmk+kernel@armlinux.org.uk> Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
2020-01-20fs/adfs: newdir: split out directory commit from updateRussell King3-13/+18
After changing a directory, we need to update the sequence numbers and calculate the new check byte before the directory is scheduled to be written back to the media. Since this needs to happen for any change to the directory, move this into a separate method. Signed-off-by: Russell King <rmk+kernel@armlinux.org.uk> Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
2020-01-20fs/adfs: newdir: clean up adfs_f_update()Russell King1-49/+24
__adfs_dir_put() and adfs_dir_find_entry() are only called from adfs_f_update(), so move them into this function, removing some unnecessary entry copying by doing so. Signed-off-by: Russell King <rmk+kernel@armlinux.org.uk> Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
2020-01-20fs/adfs: newdir: merge adfs_dir_read() into adfs_f_read()Russell King1-26/+7
adfs_dir_read() is only called from adfs_f_read(), so merge it into that function. As new directories are always 2048 bytes in size, (which we rely on elsewhere) we can consolidate some of the code. Signed-off-by: Russell King <rmk+kernel@armlinux.org.uk> Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
2020-01-20fs/adfs: newdir: improve directory validationRussell King1-0/+1
Check that the lastmask and reserved fields are all zero, as per the documentation. Signed-off-by: Russell King <rmk+kernel@armlinux.org.uk> Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
2020-01-20fs/adfs: newdir: factor out directory format validationRussell King1-28/+20
We have two locations where we validate the new directory format, so factor this out to a helper. Signed-off-by: Russell King <rmk+kernel@armlinux.org.uk> Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
2020-01-20fs/adfs: dir: use pointers to access directory head/tailsRussell King3-36/+29
Add and use pointers in the adfs_dir structure to access the directory head and tail structures, which will always be contiguous in a buffer. This allows us to avoid memcpy()ing the data in the new directory code, making it slightly more efficient. Signed-off-by: Russell King <rmk+kernel@armlinux.org.uk> Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
2020-01-20fs/adfs: dir: add more efficient iterate() per-format methodRussell King4-14/+42
Rather than using setpos + getnext to iterate through the directory entries, pass iterate() down to the dir format code to populate the dirents. Signed-off-by: Russell King <rmk+kernel@armlinux.org.uk> Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
2020-01-20fs/adfs: dir: switch to iterate_shared methodRussell King1-3/+2
There is nothing in our readdir (aka iterate) method that relies on the directory inode being exclusively locked, so switch to using the iterate_shared() hook rather than iterate(). Signed-off-by: Russell King <rmk+kernel@armlinux.org.uk> Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
2020-01-20fs/adfs: dir: improve compiler coverage in adfs_dir_updateRussell King1-3/+5
Get rid of the ifdef, using IS_ENABLED() instead to detect whether the code should be callable. This allows the compiler to always parse the following code, reducing the chances of errors being missed. Signed-off-by: Russell King <rmk+kernel@armlinux.org.uk> Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
2020-01-20fs/adfs: dir: improve update failure handlingRussell King1-12/+36
When we update a directory, a number of errors may happen. If we failed to find the entry to update, we can just release the directory buffers as normal. However, if we have some other error, we may have partially updated the buffers, resulting in an invalid directory. In this case, we need to discard the buffers to avoid writing the contents back to the media, and later re-read the directory from the media. Signed-off-by: Russell King <rmk+kernel@armlinux.org.uk> Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
2020-01-20fs/adfs: dir: modernise on-disk directory structuresRussell King2-27/+31
Use __u8 and pack the structures for on-disk directories. Signed-off-by: Russell King <rmk+kernel@armlinux.org.uk> Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
2020-01-20fs/adfs: dir: update directory lockingRussell King1-26/+29
Update directory locking such that it covers the validation of the directory, which could fail if another thread is concurrently writing to the same directory. Since we may sleep, we need to use a rwsem rather than a rw spinlock. Signed-off-by: Russell King <rmk+kernel@armlinux.org.uk> Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
2020-01-20fs/adfs: dir: add helper to mark directory buffers dirtyRussell King2-4/+13
Provide a helper for marking directory buffers dirty so they get written back to disk. Signed-off-by: Russell King <rmk+kernel@armlinux.org.uk> Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
2020-01-20fs/adfs: dir: add helper to read directory using inodeRussell King1-10/+22
Add a helper to read a directory using the inode, which we do in two places. Signed-off-by: Russell King <rmk+kernel@armlinux.org.uk> Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
2020-01-20fs/adfs: dir: add generic directory readingRussell King4-77/+74
Both directory formats code the mechanics of fetching the directory buffers using their own implementations. Consolidate these into one implementation. Signed-off-by: Russell King <rmk+kernel@armlinux.org.uk> Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
2020-01-20fs/adfs: dir: add generic copy functionsRussell King4-82/+75
Directories can span multiple buffers, and we currently open-code memcpy access to these buffers, including dealing with entries that are split across multiple buffers. Such code exists in both directory format implementations. Provide common functions to allow data to be copied from/to the directory buffers as if they were a contiguous set of buffers, and use them when accessing directories. Signed-off-by: Russell King <rmk+kernel@armlinux.org.uk> Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
2020-01-20fs/adfs: dir: add common directory sync methodRussell King4-40/+18
adfs_fplus_sync() can be used for both directory formats since we now have a common way to access the buffer heads, so move it into dir.c and appropriately rename it. Remove the directory-format specific implementations. Signed-off-by: Russell King <rmk+kernel@armlinux.org.uk> Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
2020-01-20fs/adfs: dir: add common directory buffer release methodRussell King4-60/+25
With the bhs pointer in place, we have no need for separate per-format free() methods, since a generic version will do. Provide a generic implementation, remove the format specific implementations and the method function pointer. Signed-off-by: Russell King <rmk+kernel@armlinux.org.uk> Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
2020-01-20fs/adfs: dir: add common dir object initialisationRussell King3-12/+13
Initialise the dir object before we pass it down to the directory format specific read handler. This allows us to get rid of the initialisation inside those handlers. Signed-off-by: Russell King <rmk+kernel@armlinux.org.uk> Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
2020-01-20fs/adfs: dir: rename bh_fplus to bhsRussell King2-30/+28
Rename bh_fplus to bhs in preparation to make some of the directory handling code sharable between implementations. Signed-off-by: Russell King <rmk+kernel@armlinux.org.uk> Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
2020-01-20fs/adfs: map: fix map scanningRussell King1-2/+7
When scanning the map for a fragment id, we need to keep track of the free space links, so we don't inadvertently believe that the freespace link is a valid fragment id. Signed-off-by: Russell King <rmk+kernel@armlinux.org.uk> Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
2020-01-20fs/adfs: map: move map-specific sb initialisation to map.cRussell King2-10/+10
Move map specific superblock initialisation to map.c, rather than having it spread into super.c. Signed-off-by: Russell King <rmk+kernel@armlinux.org.uk> Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
2020-01-20fs/adfs: map: use find_next_bit_le() rather than open coding itRussell King1-55/+21
Use find_next_bit_le() to find the end of a fragment in the map rather than open-coding this functionality. Signed-off-by: Russell King <rmk+kernel@armlinux.org.uk> Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
2020-01-20fs/adfs: map: incorporate map offsets into layoutRussell King1-11/+11
lookup_zone() and scan_free_map() cope in different ways with the location of the map data within a zone: 1. lookup_zone() adds a four byte offset to the map data pointer to skip over the check and free link bytes. 2. scan_free_map() needs to use the free link pointer, which is an offset from itself, so we end up adding a 32-bit offset to the end pointer (aka mapsize) which is really confusing. Rename mapsize to endbit as this is really what it is, and incorporate the 32-bit offset into the map layout. This means that both dm_startbit and dm_endbit are now bit offsets from the start of the buffer, rather than four bytes in to the buffer. Signed-off-by: Russell King <rmk+kernel@armlinux.org.uk> Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
2020-01-20fs/adfs: map: factor out map cleanupRussell King3-8/+11
We have several places which deal with releasing the map buffers and freeing the map array. Provide a helper for this. Signed-off-by: Russell King <rmk+kernel@armlinux.org.uk> Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
2020-01-20fs/adfs: map: break up adfs_read_map()Russell King1-21/+59
Split up adfs_read_map() into separate helpers to layout the map, read the map, and release the map buffers. Signed-off-by: Russell King <rmk+kernel@armlinux.org.uk> Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
2020-01-20fs/adfs: map: rename adfs_map_free() to adfs_map_statfs()Russell King3-9/+10
adfs_map_free() is not obvious whether it is freeing the map or returning the number of free blocks on the filesystem. Rename it to the more generic statfs() to make it clear that it's a statistic function. Signed-off-by: Russell King <rmk+kernel@armlinux.org.uk> Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
2020-01-20fs/adfs: map: move map reading and validation to map.cRussell King3-98/+100
Keep all the map code together in map.c, rather than having some in super.c Signed-off-by: Russell King <rmk+kernel@armlinux.org.uk> Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
2020-01-20fs/adfs: inode: fix adfs_mode2atts()Russell King1-9/+9
Fix adfs_mode2atts() to actually update the file permissions on the media rather than using the current inode mode. Note also that directories do not have read/write permissions stored on the media. Signed-off-by: Russell King <rmk+kernel@armlinux.org.uk> Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
2020-01-20fs/adfs: inode: update timestamps to centisecond precisionRussell King2-20/+22
Despite ADFS timestamps having centi-second granularity, and Linux gaining fine-grained timestamp support in v2.5.48, fs/adfs was never updated. Update fs/adfs to centi-second support, and ensure that the inode ctime always reflects what is written in underlying media. Signed-off-by: Russell King <rmk+kernel@armlinux.org.uk> Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
2019-07-19Merge branch 'work.adfs' of ↵Linus Torvalds7-141/+161
git://git.kernel.org/pub/scm/linux/kernel/git/viro/vfs Pull adfs updates from Al Viro: "More ADFS patches from Russell King" * 'work.adfs' of git://git.kernel.org/pub/scm/linux/kernel/git/viro/vfs: fs/adfs: add time stamp and file type helpers fs/adfs: super: limit idlen according to directory type fs/adfs: super: fix use-after-free bug fs/adfs: super: safely update options on remount fs/adfs: super: correct superblock flags fs/adfs: clean up indirect disc addresses and fragment IDs fs/adfs: clean up error message printing fs/adfs: use %pV for error messages fs/adfs: use format_version from disc_record fs/adfs: add helper to get filesystem size fs/adfs: add helper to get discrecord from map fs/adfs: correct disc record structure
2019-06-26fs/adfs: add time stamp and file type helpersRussell King4-27/+27
Add some helpers to check whether the inode has a time stamp and file type, and to parse the file type from the load address. Signed-off-by: Russell King <rmk+kernel@armlinux.org.uk> Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
2019-06-26fs/adfs: super: limit idlen according to directory typeRussell King1-2/+8
Limit idlen according to the directory type, as idlen (the size of a fragment ID) can not be more than 16 with the "new directory" layout. Signed-off-by: Russell King <rmk+kernel@armlinux.org.uk> Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
2019-06-26fs/adfs: super: fix use-after-free bugRussell King1-1/+4
Fix a use-after-free bug during filesystem initialisation, where we access the disc record (which is stored in a buffer) after we have released the buffer. Signed-off-by: Russell King <rmk+kernel@armlinux.org.uk> Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
2019-06-26fs/adfs: super: safely update options on remountRussell King1-4/+13
Only update the options on remount if we successfully parse all options, rather than updating those we've managed to parse. Signed-off-by: Russell King <rmk+kernel@armlinux.org.uk> Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
2019-06-26fs/adfs: super: correct superblock flagsRussell King1-2/+4
We don't support atime updates of any kind, and we ought to set the read-only bit if we are compiled without write support. Signed-off-by: Russell King <rmk+kernel@armlinux.org.uk> Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
2019-06-26fs/adfs: clean up indirect disc addresses and fragment IDsRussell King7-49/+41
We use a variety of different names for the indirect disc address of the current object, use a variety of different types, and print it in a variety of different ways. Bring some consistency to this by naming it "indaddr", use u32 or __u32 as the type since it fits in 32-bits, and always print it with %06x (with no leading hex prefix.) When printing it was a directory identifer, use "dir %06x" otherwise use "object %06x". Do the same for fragment IDs and the parent indirect disc addresses. Signed-off-by: Russell King <rmk+kernel@armlinux.org.uk> Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
2019-06-26fs/adfs: clean up error message printingRussell King3-26/+38
Overhaul our message printing: - provide a consistent way to print messages: - filesystem corruption should be reported via adfs_error() - everything else should use adfs_msg() - clean up the error message printing when mounting a filesystem - fix the messages printed by the big directory format code to only use adfs_error() when there is filesystem corruption, otherwise use adfs_msg(). Signed-off-by: Russell King <rmk+kernel@armlinux.org.uk> Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
2019-06-26fs/adfs: use %pV for error messagesRussell King1-5/+7
Rather than using vsnprintf() with a temporary buffer on the stack, use %pV to print error messages. Signed-off-by: Russell King <rmk+kernel@armlinux.org.uk> Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>