file_direct.c (e5451c8f8330e03ad3cfa16048b4daf961af434f) | file_direct.c (09cbfeaf1a5a67bfb3201e0c83c810cecb2efa5a) |
---|---|
1/* 2 * Copyright (c) 2013 3 * Phillip Lougher <phillip@squashfs.org.uk> 4 * 5 * This work is licensed under the terms of the GNU GPL, version 2. See 6 * the COPYING file in the top-level directory. 7 */ 8 --- 16 unchanged lines hidden (view full) --- 25 26/* Read separately compressed datablock directly into page cache */ 27int squashfs_readpage_block(struct page *target_page, u64 block, int bsize) 28 29{ 30 struct inode *inode = target_page->mapping->host; 31 struct squashfs_sb_info *msblk = inode->i_sb->s_fs_info; 32 | 1/* 2 * Copyright (c) 2013 3 * Phillip Lougher <phillip@squashfs.org.uk> 4 * 5 * This work is licensed under the terms of the GNU GPL, version 2. See 6 * the COPYING file in the top-level directory. 7 */ 8 --- 16 unchanged lines hidden (view full) --- 25 26/* Read separately compressed datablock directly into page cache */ 27int squashfs_readpage_block(struct page *target_page, u64 block, int bsize) 28 29{ 30 struct inode *inode = target_page->mapping->host; 31 struct squashfs_sb_info *msblk = inode->i_sb->s_fs_info; 32 |
33 int file_end = (i_size_read(inode) - 1) >> PAGE_CACHE_SHIFT; 34 int mask = (1 << (msblk->block_log - PAGE_CACHE_SHIFT)) - 1; | 33 int file_end = (i_size_read(inode) - 1) >> PAGE_SHIFT; 34 int mask = (1 << (msblk->block_log - PAGE_SHIFT)) - 1; |
35 int start_index = target_page->index & ~mask; 36 int end_index = start_index | mask; 37 int i, n, pages, missing_pages, bytes, res = -ENOMEM; 38 struct page **page; 39 struct squashfs_page_actor *actor; 40 void *pageaddr; 41 42 if (end_index > file_end) --- 20 unchanged lines hidden (view full) --- 63 64 if (page[i] == NULL) { 65 missing_pages++; 66 continue; 67 } 68 69 if (PageUptodate(page[i])) { 70 unlock_page(page[i]); | 35 int start_index = target_page->index & ~mask; 36 int end_index = start_index | mask; 37 int i, n, pages, missing_pages, bytes, res = -ENOMEM; 38 struct page **page; 39 struct squashfs_page_actor *actor; 40 void *pageaddr; 41 42 if (end_index > file_end) --- 20 unchanged lines hidden (view full) --- 63 64 if (page[i] == NULL) { 65 missing_pages++; 66 continue; 67 } 68 69 if (PageUptodate(page[i])) { 70 unlock_page(page[i]); |
71 page_cache_release(page[i]); | 71 put_page(page[i]); |
72 page[i] = NULL; 73 missing_pages++; 74 } 75 } 76 77 if (missing_pages) { 78 /* 79 * Couldn't get one or more pages, this page has either --- 11 unchanged lines hidden (view full) --- 91 } 92 93 /* Decompress directly into the page cache buffers */ 94 res = squashfs_read_data(inode->i_sb, block, bsize, NULL, actor); 95 if (res < 0) 96 goto mark_errored; 97 98 /* Last page may have trailing bytes not filled */ | 72 page[i] = NULL; 73 missing_pages++; 74 } 75 } 76 77 if (missing_pages) { 78 /* 79 * Couldn't get one or more pages, this page has either --- 11 unchanged lines hidden (view full) --- 91 } 92 93 /* Decompress directly into the page cache buffers */ 94 res = squashfs_read_data(inode->i_sb, block, bsize, NULL, actor); 95 if (res < 0) 96 goto mark_errored; 97 98 /* Last page may have trailing bytes not filled */ |
99 bytes = res % PAGE_CACHE_SIZE; | 99 bytes = res % PAGE_SIZE; |
100 if (bytes) { 101 pageaddr = kmap_atomic(page[pages - 1]); | 100 if (bytes) { 101 pageaddr = kmap_atomic(page[pages - 1]); |
102 memset(pageaddr + bytes, 0, PAGE_CACHE_SIZE - bytes); | 102 memset(pageaddr + bytes, 0, PAGE_SIZE - bytes); |
103 kunmap_atomic(pageaddr); 104 } 105 106 /* Mark pages as uptodate, unlock and release */ 107 for (i = 0; i < pages; i++) { 108 flush_dcache_page(page[i]); 109 SetPageUptodate(page[i]); 110 unlock_page(page[i]); 111 if (page[i] != target_page) | 103 kunmap_atomic(pageaddr); 104 } 105 106 /* Mark pages as uptodate, unlock and release */ 107 for (i = 0; i < pages; i++) { 108 flush_dcache_page(page[i]); 109 SetPageUptodate(page[i]); 110 unlock_page(page[i]); 111 if (page[i] != target_page) |
112 page_cache_release(page[i]); | 112 put_page(page[i]); |
113 } 114 115 kfree(actor); 116 kfree(page); 117 118 return 0; 119 120mark_errored: 121 /* Decompression failed, mark pages as errored. Target_page is 122 * dealt with by the caller 123 */ 124 for (i = 0; i < pages; i++) { 125 if (page[i] == NULL || page[i] == target_page) 126 continue; 127 flush_dcache_page(page[i]); 128 SetPageError(page[i]); 129 unlock_page(page[i]); | 113 } 114 115 kfree(actor); 116 kfree(page); 117 118 return 0; 119 120mark_errored: 121 /* Decompression failed, mark pages as errored. Target_page is 122 * dealt with by the caller 123 */ 124 for (i = 0; i < pages; i++) { 125 if (page[i] == NULL || page[i] == target_page) 126 continue; 127 flush_dcache_page(page[i]); 128 SetPageError(page[i]); 129 unlock_page(page[i]); |
130 page_cache_release(page[i]); | 130 put_page(page[i]); |
131 } 132 133out: 134 kfree(actor); 135 kfree(page); 136 return res; 137} 138 --- 9 unchanged lines hidden (view full) --- 148 149 if (res) { 150 ERROR("Unable to read page, block %llx, size %x\n", block, 151 bsize); 152 goto out; 153 } 154 155 for (n = 0; n < pages && bytes > 0; n++, | 131 } 132 133out: 134 kfree(actor); 135 kfree(page); 136 return res; 137} 138 --- 9 unchanged lines hidden (view full) --- 148 149 if (res) { 150 ERROR("Unable to read page, block %llx, size %x\n", block, 151 bsize); 152 goto out; 153 } 154 155 for (n = 0; n < pages && bytes > 0; n++, |
156 bytes -= PAGE_CACHE_SIZE, offset += PAGE_CACHE_SIZE) { 157 int avail = min_t(int, bytes, PAGE_CACHE_SIZE); | 156 bytes -= PAGE_SIZE, offset += PAGE_SIZE) { 157 int avail = min_t(int, bytes, PAGE_SIZE); |
158 159 if (page[n] == NULL) 160 continue; 161 162 pageaddr = kmap_atomic(page[n]); 163 squashfs_copy_data(pageaddr, buffer, offset, avail); | 158 159 if (page[n] == NULL) 160 continue; 161 162 pageaddr = kmap_atomic(page[n]); 163 squashfs_copy_data(pageaddr, buffer, offset, avail); |
164 memset(pageaddr + avail, 0, PAGE_CACHE_SIZE - avail); | 164 memset(pageaddr + avail, 0, PAGE_SIZE - avail); |
165 kunmap_atomic(pageaddr); 166 flush_dcache_page(page[n]); 167 SetPageUptodate(page[n]); 168 unlock_page(page[n]); 169 if (page[n] != target_page) | 165 kunmap_atomic(pageaddr); 166 flush_dcache_page(page[n]); 167 SetPageUptodate(page[n]); 168 unlock_page(page[n]); 169 if (page[n] != target_page) |
170 page_cache_release(page[n]); | 170 put_page(page[n]); |
171 } 172 173out: 174 squashfs_cache_put(buffer); 175 return res; 176} | 171 } 172 173out: 174 squashfs_cache_put(buffer); 175 return res; 176} |