77 */
88
99#include "hpfs_fn.h"
10+ #include <linux/mpage.h>
1011
1112#define BLOCKS (size ) (((size) + 511) >> 9)
1213
@@ -34,19 +35,28 @@ int hpfs_file_fsync(struct file *file, loff_t start, loff_t end, int datasync)
3435 * so we must ignore such errors.
3536 */
3637
37- static secno hpfs_bmap (struct inode * inode , unsigned file_secno )
38+ static secno hpfs_bmap (struct inode * inode , unsigned file_secno , unsigned * n_secs )
3839{
3940 struct hpfs_inode_info * hpfs_inode = hpfs_i (inode );
4041 unsigned n , disk_secno ;
4142 struct fnode * fnode ;
4243 struct buffer_head * bh ;
4344 if (BLOCKS (hpfs_i (inode )-> mmu_private ) <= file_secno ) return 0 ;
4445 n = file_secno - hpfs_inode -> i_file_sec ;
45- if (n < hpfs_inode -> i_n_secs ) return hpfs_inode -> i_disk_sec + n ;
46+ if (n < hpfs_inode -> i_n_secs ) {
47+ * n_secs = hpfs_inode -> i_n_secs - n ;
48+ return hpfs_inode -> i_disk_sec + n ;
49+ }
4650 if (!(fnode = hpfs_map_fnode (inode -> i_sb , inode -> i_ino , & bh ))) return 0 ;
4751 disk_secno = hpfs_bplus_lookup (inode -> i_sb , inode , & fnode -> btree , file_secno , bh );
4852 if (disk_secno == -1 ) return 0 ;
4953 if (hpfs_chk_sectors (inode -> i_sb , disk_secno , 1 , "bmap" )) return 0 ;
54+ n = file_secno - hpfs_inode -> i_file_sec ;
55+ if (n < hpfs_inode -> i_n_secs ) {
56+ * n_secs = hpfs_inode -> i_n_secs - n ;
57+ return hpfs_inode -> i_disk_sec + n ;
58+ }
59+ * n_secs = 1 ;
5060 return disk_secno ;
5161}
5262
@@ -67,10 +77,14 @@ static int hpfs_get_block(struct inode *inode, sector_t iblock, struct buffer_he
6777{
6878 int r ;
6979 secno s ;
80+ unsigned n_secs ;
7081 hpfs_lock (inode -> i_sb );
71- s = hpfs_bmap (inode , iblock );
82+ s = hpfs_bmap (inode , iblock , & n_secs );
7283 if (s ) {
84+ if (bh_result -> b_size >> 9 < n_secs )
85+ n_secs = bh_result -> b_size >> 9 ;
7386 map_bh (bh_result , inode -> i_sb , s );
87+ bh_result -> b_size = n_secs << 9 ;
7488 goto ret_0 ;
7589 }
7690 if (!create ) goto ret_0 ;
@@ -95,14 +109,26 @@ static int hpfs_get_block(struct inode *inode, sector_t iblock, struct buffer_he
95109 return r ;
96110}
97111
112+ static int hpfs_readpage (struct file * file , struct page * page )
113+ {
114+ return mpage_readpage (page , hpfs_get_block );
115+ }
116+
98117static int hpfs_writepage (struct page * page , struct writeback_control * wbc )
99118{
100- return block_write_full_page (page ,hpfs_get_block , wbc );
119+ return block_write_full_page (page , hpfs_get_block , wbc );
101120}
102121
103- static int hpfs_readpage (struct file * file , struct page * page )
122+ static int hpfs_readpages (struct file * file , struct address_space * mapping ,
123+ struct list_head * pages , unsigned nr_pages )
124+ {
125+ return mpage_readpages (mapping , pages , nr_pages , hpfs_get_block );
126+ }
127+
128+ static int hpfs_writepages (struct address_space * mapping ,
129+ struct writeback_control * wbc )
104130{
105- return block_read_full_page ( page , hpfs_get_block );
131+ return mpage_writepages ( mapping , wbc , hpfs_get_block );
106132}
107133
108134static void hpfs_write_failed (struct address_space * mapping , loff_t to )
@@ -161,6 +187,8 @@ static sector_t _hpfs_bmap(struct address_space *mapping, sector_t block)
161187const struct address_space_operations hpfs_aops = {
162188 .readpage = hpfs_readpage ,
163189 .writepage = hpfs_writepage ,
190+ .readpages = hpfs_readpages ,
191+ .writepages = hpfs_writepages ,
164192 .write_begin = hpfs_write_begin ,
165193 .write_end = hpfs_write_end ,
166194 .bmap = _hpfs_bmap
0 commit comments