Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1 | inode.c: only update the icache for ext2_inode |
| 2 | |
| 3 | We only read the cache when: |
| 4 | |
| 5 | bufsize == sizeof(struct ext2_inode) |
| 6 | |
| 7 | then we should only update the cache in the same condition, otherwise |
| 8 | there would be errors, for example: |
| 9 | |
| 10 | cache[0]: cached ino 14 when bufsize = 128 by ext2fs_write_inode_full() |
| 11 | cache[1]: cached ino 14 when bufsize = 156 by ext2fs_read_inode_full() |
| 12 | |
| 13 | Then update the cache: |
| 14 | cache[0]: cached ino 15 when bufsize = 156 by ext2fs_read_inode_full() |
| 15 | |
| 16 | Then the ino 14 would hit the cache[1] when bufsize = 128 (but it was |
| 17 | cached by bufsize = 156), so there would be errors. |
| 18 | |
| 19 | Upstream-Status: Submitted |
| 20 | |
| 21 | Signed-off-by: Robert Yang <liezhi.yang@windriver.com> |
| 22 | --- |
| 23 | lib/ext2fs/inode.c | 20 ++++++++++++-------- |
| 24 | 1 file changed, 12 insertions(+), 8 deletions(-) |
| 25 | |
| 26 | diff --git a/lib/ext2fs/inode.c b/lib/ext2fs/inode.c |
| 27 | --- a/lib/ext2fs/inode.c |
| 28 | +++ b/lib/ext2fs/inode.c |
| 29 | @@ -612,10 +612,12 @@ errcode_t ext2fs_read_inode_full(ext2_filsys fs, ext2_ino_t ino, |
| 30 | #endif |
| 31 | |
| 32 | /* Update the inode cache */ |
| 33 | - fs->icache->cache_last = (fs->icache->cache_last + 1) % |
| 34 | - fs->icache->cache_size; |
| 35 | - fs->icache->cache[fs->icache->cache_last].ino = ino; |
| 36 | - fs->icache->cache[fs->icache->cache_last].inode = *inode; |
| 37 | + if (bufsize == sizeof(struct ext2_inode)) { |
| 38 | + fs->icache->cache_last = (fs->icache->cache_last + 1) % |
| 39 | + fs->icache->cache_size; |
| 40 | + fs->icache->cache[fs->icache->cache_last].ino = ino; |
| 41 | + fs->icache->cache[fs->icache->cache_last].inode = *inode; |
| 42 | + } |
| 43 | |
| 44 | return 0; |
| 45 | } |
| 46 | @@ -648,10 +650,12 @@ errcode_t ext2fs_write_inode_full(ext2_filsys fs, ext2_ino_t ino, |
| 47 | |
| 48 | /* Check to see if the inode cache needs to be updated */ |
| 49 | if (fs->icache) { |
| 50 | - for (i=0; i < fs->icache->cache_size; i++) { |
| 51 | - if (fs->icache->cache[i].ino == ino) { |
| 52 | - fs->icache->cache[i].inode = *inode; |
| 53 | - break; |
| 54 | + if (bufsize == sizeof(struct ext2_inode)) { |
| 55 | + for (i=0; i < fs->icache->cache_size; i++) { |
| 56 | + if (fs->icache->cache[i].ino == ino) { |
| 57 | + fs->icache->cache[i].inode = *inode; |
| 58 | + break; |
| 59 | + } |
| 60 | } |
| 61 | } |
| 62 | } else { |
| 63 | -- |
| 64 | 1.8.1.2 |
| 65 | |