xref: /OK3568_Linux_fs/kernel/fs/squashfs/file_cache.c (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun // SPDX-License-Identifier: GPL-2.0-only
2*4882a593Smuzhiyun /*
3*4882a593Smuzhiyun  * Copyright (c) 2013
4*4882a593Smuzhiyun  * Phillip Lougher <phillip@squashfs.org.uk>
5*4882a593Smuzhiyun  */
6*4882a593Smuzhiyun 
7*4882a593Smuzhiyun #include <linux/fs.h>
8*4882a593Smuzhiyun #include <linux/vfs.h>
9*4882a593Smuzhiyun #include <linux/kernel.h>
10*4882a593Smuzhiyun #include <linux/slab.h>
11*4882a593Smuzhiyun #include <linux/string.h>
12*4882a593Smuzhiyun #include <linux/pagemap.h>
13*4882a593Smuzhiyun #include <linux/mutex.h>
14*4882a593Smuzhiyun 
15*4882a593Smuzhiyun #include "squashfs_fs.h"
16*4882a593Smuzhiyun #include "squashfs_fs_sb.h"
17*4882a593Smuzhiyun #include "squashfs_fs_i.h"
18*4882a593Smuzhiyun #include "squashfs.h"
19*4882a593Smuzhiyun 
20*4882a593Smuzhiyun /* Read separately compressed datablock and memcopy into page cache */
squashfs_readpage_block(struct page * page,u64 block,int bsize,int expected)21*4882a593Smuzhiyun int squashfs_readpage_block(struct page *page, u64 block, int bsize, int expected)
22*4882a593Smuzhiyun {
23*4882a593Smuzhiyun 	struct inode *i = page->mapping->host;
24*4882a593Smuzhiyun 	struct squashfs_cache_entry *buffer = squashfs_get_datablock(i->i_sb,
25*4882a593Smuzhiyun 		block, bsize);
26*4882a593Smuzhiyun 	int res = buffer->error;
27*4882a593Smuzhiyun 
28*4882a593Smuzhiyun 	if (res)
29*4882a593Smuzhiyun 		ERROR("Unable to read page, block %llx, size %x\n", block,
30*4882a593Smuzhiyun 			bsize);
31*4882a593Smuzhiyun 	else
32*4882a593Smuzhiyun 		squashfs_copy_cache(page, buffer, expected, 0);
33*4882a593Smuzhiyun 
34*4882a593Smuzhiyun 	squashfs_cache_put(buffer);
35*4882a593Smuzhiyun 	return res;
36*4882a593Smuzhiyun }
37