4 * (c) 1996 Hans-Joachim Widmaier - Rewritten
6 * (C) 1993 Ray Burr - Modified for Amiga FFS filesystem.
8 * (C) 1992 Eric Youngdale Modified for ISO 9660 filesystem.
10 * (C) 1991 Linus Torvalds - minix filesystem
12 * affs regular file handling primitives
16 #include <asm/div64.h>
17 #include <asm/uaccess.h>
18 #include <asm/system.h>
19 #include <linux/sched.h>
20 #include <linux/affs_fs.h>
21 #include <linux/fcntl.h>
22 #include <linux/kernel.h>
23 #include <linux/errno.h>
24 #include <linux/malloc.h>
25 #include <linux/stat.h>
26 #include <linux/locks.h>
27 #include <linux/smp_lock.h>
28 #include <linux/dirent.h>
30 #include <linux/amigaffs.h>
32 #include <linux/pagemap.h>
34 #define MIN(a,b) (((a)<(b))?(a):(b))
35 #define MAX(a,b) (((a)>(b))?(a):(b))
38 #error PAGE_SIZE must be at least 4096
41 static struct buffer_head
*affs_getblock(struct inode
*inode
, s32 block
);
42 static ssize_t
affs_file_read_ofs(struct file
*filp
, char *buf
, size_t count
, loff_t
*ppos
);
43 static ssize_t
affs_file_write(struct file
*filp
, const char *buf
, size_t count
, loff_t
*ppos
);
44 static ssize_t
affs_file_write_ofs(struct file
*filp
, const char *buf
, size_t cnt
, loff_t
*ppos
);
45 static int alloc_ext_cache(struct inode
*inode
);
47 struct file_operations affs_file_operations
= {
48 read
: generic_file_read
,
49 write
: affs_file_write
,
50 mmap
: generic_file_mmap
,
54 struct inode_operations affs_file_inode_operations
= {
55 truncate
: affs_truncate
,
56 setattr
: affs_notify_change
,
59 struct file_operations affs_file_operations_ofs
= {
60 read
: affs_file_read_ofs
,
61 write
: affs_file_write_ofs
,
65 #define AFFS_ISINDEX(x) ((x < 129) || \
66 (x < 512 && (x & 1) == 0) || \
67 (x < 1024 && (x & 3) == 0) || \
68 (x < 2048 && (x & 15) == 0) || \
69 (x < 4096 && (x & 63) == 0) || \
70 (x < 20480 && (x & 255) == 0) || \
71 (x < 36864 && (x & 511) == 0))
73 /* The keys of the extension blocks are stored in a 512-entry
74 * deep cache. In order to save memory, not every key of later
75 * extension blocks is stored - the larger the file gets, the
76 * bigger the holes in between.
80 seqnum_to_index(int seqnum
)
82 /* All of the first 127 keys are stored */
87 /* Of the next 384 keys, every 2nd is kept */
88 if (seqnum
< (192 * 2))
89 return 128 + (seqnum
>> 1);
92 /* Every 4th of the next 512 */
93 if (seqnum
< (128 * 4))
94 return 128 + 192 + (seqnum
>> 2);
97 /* Every 16th of the next 1024 */
98 if (seqnum
< (64 * 16))
99 return 128 + 192 + 128 + (seqnum
>> 4);
102 /* Every 64th of the next 2048 */
103 if (seqnum
< (32 * 64))
104 return 128 + 192 + 128 + 64 + (seqnum
>> 6);
107 /* Every 256th of the next 16384 */
108 if (seqnum
< (64 * 256))
109 return 128 + 192 + 128 + 64 + 32 + (seqnum
>> 8);
112 /* Every 512th upto 36479 (1.3 GB with 512 byte blocks).
113 * Seeking to positions behind this will get slower
114 * than dead snails nailed to the ground. But if
115 * someone uses files that large with 512-byte blocks,
116 * he or she deserves no better.
119 if (seqnum
> (31 * 512))
121 return 128 + 192 + 128 + 64 + 32 + 64 + (seqnum
>> 9);
124 /* Now the other way round: Calculate the sequence
125 * number of an extension block of a key at the
126 * given index in the cache.
130 index_to_seqnum(int index
)
136 return 128 + (index
<< 1);
139 return 128 + 192 * 2 + (index
<< 2);
142 return 128 + 192 * 2 + 128 * 4 + (index
<< 4);
145 return 128 + 192 * 2 + 128 * 4 + 64 * 16 + (index
<< 6);
148 return 128 + 192 * 2 + 128 * 4 + 64 * 16 + 32 * 64 + (index
<< 8);
150 return 128 + 192 * 2 + 128 * 4 + 64 * 16 + 32 * 64 + 64 * 256 + (index
<< 9);
153 static s32 __inline__
154 calc_key(struct inode
*inode
, int *ext
)
157 struct key_cache
*kc
;
159 for (index
= 0; index
< 4; index
++) {
160 kc
= &inode
->u
.affs_i
.i_ec
->kc
[index
];
161 if (kc
->kc_last
== -1)
162 continue; /* don't look in cache if invalid. */
163 if (*ext
== kc
->kc_this_seq
) {
164 return kc
->kc_this_key
;
165 } else if (*ext
== kc
->kc_this_seq
+ 1) {
167 return kc
->kc_next_key
;
170 return kc
->kc_this_key
;
174 index
= seqnum_to_index(*ext
);
175 if (index
> inode
->u
.affs_i
.i_ec
->max_ext
)
176 index
= inode
->u
.affs_i
.i_ec
->max_ext
;
177 *ext
= index_to_seqnum(index
);
178 return inode
->u
.affs_i
.i_ec
->ec
[index
];
182 affs_bmap(struct inode
*inode
, int block
)
184 struct buffer_head
*bh
;
190 struct key_cache
*kc
;
191 struct key_cache
*tkc
;
196 pr_debug("AFFS: bmap(%lu,%d)\n",inode
->i_ino
,block
);
200 affs_error(inode
->i_sb
,"bmap","Block < 0");
203 if (!inode
->u
.affs_i
.i_ec
) {
204 if (alloc_ext_cache(inode
)) {
209 /* Try to find the requested key in the cache.
210 * In order to speed this up as much as possible,
211 * the cache line lookup is done in a separate
215 for (i
= 0; i
< 4; i
++) {
216 tkc
= &inode
->u
.affs_i
.i_ec
->kc
[i
];
217 /* Look in any cache if the key is there */
218 if (block
<= tkc
->kc_last
&& block
>= tkc
->kc_first
) {
220 return tkc
->kc_keys
[block
- tkc
->kc_first
];
225 for (i
= 0; i
< 4; i
++) {
226 tkc
= &inode
->u
.affs_i
.i_ec
->kc
[i
];
227 if (tkc
->kc_lru_time
.tv_sec
> tv
.tv_sec
)
229 if (tkc
->kc_lru_time
.tv_sec
< tv
.tv_sec
||
230 tkc
->kc_lru_time
.tv_usec
< tv
.tv_usec
) {
232 tv
= tkc
->kc_lru_time
;
235 if (!kc
) /* Really shouldn't happen */
237 kc
->kc_lru_time
= xtime
;
239 kc
->kc_first
= block
;
241 keycount
= AFFS_KCSIZE
;
243 /* Calculate sequence number of the extension block where the
244 * number of the requested block is stored. 0 means it's in
248 ext
= block
/ AFFS_I2HSIZE(inode
);
249 key
= calc_key(inode
,&ext
);
250 block
-= ext
* AFFS_I2HSIZE(inode
);
253 bh
= affs_bread(inode
->i_dev
,key
,AFFS_I2BSIZE(inode
));
257 index
= seqnum_to_index(ext
);
258 if (index
> inode
->u
.affs_i
.i_ec
->max_ext
&&
259 (affs_checksum_block(AFFS_I2BSIZE(inode
),bh
->b_data
,&ptype
,&stype
) ||
260 (ptype
!= T_SHORT
&& ptype
!= T_LIST
) || stype
!= ST_FILE
)) {
264 nkey
= be32_to_cpu(FILE_END(bh
->b_data
,inode
)->extension
);
265 if (block
< AFFS_I2HSIZE(inode
)) {
266 /* Fill cache as much as possible */
268 kc
->kc_first
= ext
* AFFS_I2HSIZE(inode
) + block
;
269 keycount
= keycount
< AFFS_I2HSIZE(inode
) - block
? keycount
:
270 AFFS_I2HSIZE(inode
) - block
;
271 for (i
= 0; i
< keycount
; i
++)
272 kc
->kc_keys
[i
] = be32_to_cpu(AFFS_BLOCK(bh
->b_data
,inode
,block
+ i
));
273 kc
->kc_last
= kc
->kc_first
+ i
- 1;
277 block
-= AFFS_I2HSIZE(inode
);
280 if (index
> inode
->u
.affs_i
.i_ec
->max_ext
&& AFFS_ISINDEX(ext
)) {
281 inode
->u
.affs_i
.i_ec
->ec
[index
] = nkey
;
282 inode
->u
.affs_i
.i_ec
->max_ext
= index
;
286 kc
->kc_this_key
= key
;
287 kc
->kc_this_seq
= ext
;
288 kc
->kc_next_key
= nkey
;
289 key
= be32_to_cpu(AFFS_BLOCK(bh
->b_data
,inode
,block
));
301 static int affs_get_block(struct inode
*inode
, long block
, struct buffer_head
*bh_result
, int create
)
303 int err
, phys
=0, new=0;
306 phys
= affs_bmap(inode
, block
);
308 bh_result
->b_dev
= inode
->i_dev
;
309 bh_result
->b_blocknr
= phys
;
310 bh_result
->b_state
|= (1UL << BH_Mapped
);
320 if (affs_getblock(inode
, block
)==NULL
) {
325 bh_result
->b_dev
= inode
->i_dev
;
326 bh_result
->b_blocknr
= phys
;
327 bh_result
->b_state
|= (1UL << BH_Mapped
);
329 bh_result
->b_state
|= (1UL << BH_New
);
336 affs_error(inode
->i_sb
,"affs_get_block","Block < 0");
341 static int affs_writepage(struct file
*file
, struct page
*page
)
343 return block_write_full_page(page
,affs_get_block
);
345 static int affs_readpage(struct file
*file
, struct page
*page
)
347 return block_read_full_page(page
,affs_get_block
);
349 static int affs_prepare_write(struct file
*file
, struct page
*page
, unsigned from
, unsigned to
)
351 return cont_prepare_write(page
,from
,to
,affs_get_block
,
352 &((struct inode
*)page
->mapping
->host
)->u
.affs_i
.mmu_private
);
354 static int _affs_bmap(struct address_space
*mapping
, long block
)
356 return generic_block_bmap(mapping
,block
,affs_get_block
);
358 struct address_space_operations affs_aops
= {
359 readpage
: affs_readpage
,
360 writepage
: affs_writepage
,
361 sync_page
: block_sync_page
,
362 prepare_write
: affs_prepare_write
,
363 commit_write
: generic_commit_write
,
367 /* With the affs, getting a random block from a file is not
368 * a simple business. Since this fs does not allow holes,
369 * it may be necessary to allocate all the missing blocks
370 * in between, as well as some new extension blocks. The OFS
371 * is even worse: All data blocks contain pointers to the
372 * next ones, so you have to fix [n-1] after allocating [n].
376 static struct buffer_head
* affs_getblock(struct inode
*inode
, s32 block
)
378 struct super_block
*sb
= inode
->i_sb
;
379 int ofs
= sb
->u
.affs_sb
.s_flags
& SF_OFS
;
380 int ext
= block
/ AFFS_I2HSIZE(inode
);
381 struct buffer_head
*bh
, *ebh
, *pbh
= NULL
;
382 struct key_cache
*kc
;
388 pr_debug("AFFS: getblock(%lu,%d)\n",inode
->i_ino
,block
);
390 key
= calc_key(inode
,&ext
);
391 block
-= ext
* AFFS_I2HSIZE(inode
);
392 pt
= ext
? T_LIST
: T_SHORT
;
394 /* Key refers now to the last known extension block,
395 * ext is its sequence number (if 0, key refers to the
396 * header block), and block is the block number relative
397 * to the first block stored in that extension block.
399 for (;;) { /* Loop over header block and extension blocks */
400 struct file_front
*fdp
;
402 bh
= affs_bread(inode
->i_dev
,key
,AFFS_I2BSIZE(inode
));
405 fdp
= (struct file_front
*) bh
->b_data
;
406 err
= affs_checksum_block(AFFS_I2BSIZE(inode
),bh
->b_data
,&cf
,&j
);
407 if (err
|| cf
!= pt
|| j
!= ST_FILE
) {
408 affs_error(sb
, "getblock",
409 "Block %d is not a valid %s", key
,
410 pt
== T_SHORT
? "file header" : "ext block");
413 j
= be32_to_cpu(((struct file_front
*)bh
->b_data
)->block_count
);
414 for (cf
= 0; j
< AFFS_I2HSIZE(inode
) && j
<= block
; j
++) {
415 if (ofs
&& !pbh
&& inode
->u
.affs_i
.i_lastblock
>= 0) {
417 s32 k
= AFFS_BLOCK(bh
->b_data
, inode
, j
- 1);
418 pbh
= affs_bread(inode
->i_dev
,
420 AFFS_I2BSIZE(inode
));
422 pbh
= affs_getblock(inode
,inode
->u
.affs_i
.i_lastblock
);
424 affs_error(sb
,"getblock", "Cannot get last block in file");
428 nkey
= affs_new_data(inode
);
431 inode
->u
.affs_i
.i_lastblock
++;
432 if (AFFS_BLOCK(bh
->b_data
,inode
,j
)) {
433 affs_warning(sb
,"getblock","Block already allocated");
434 affs_free_block(sb
,nkey
);
437 AFFS_BLOCK(bh
->b_data
,inode
,j
) = cpu_to_be32(nkey
);
439 ebh
= affs_bread(inode
->i_dev
,nkey
,AFFS_I2BSIZE(inode
));
441 affs_error(sb
,"getblock", "Cannot get block %d",nkey
);
442 affs_free_block(sb
,nkey
);
443 AFFS_BLOCK(bh
->b_data
,inode
,j
) = 0;
446 DATA_FRONT(ebh
)->primary_type
= cpu_to_be32(T_DATA
);
447 DATA_FRONT(ebh
)->header_key
= cpu_to_be32(inode
->i_ino
);
448 DATA_FRONT(ebh
)->sequence_number
= cpu_to_be32(inode
->u
.affs_i
.i_lastblock
+ 1);
449 affs_fix_checksum(AFFS_I2BSIZE(inode
), ebh
->b_data
, 5);
450 mark_buffer_dirty(ebh
);
452 DATA_FRONT(pbh
)->data_size
= cpu_to_be32(AFFS_I2BSIZE(inode
) - 24);
453 DATA_FRONT(pbh
)->next_data
= cpu_to_be32(nkey
);
454 affs_fix_checksum(AFFS_I2BSIZE(inode
),pbh
->b_data
,5);
455 mark_buffer_dirty(pbh
);
462 /* N.B. May need to release pbh after here */
466 fdp
->first_data
= AFFS_BLOCK(bh
->b_data
,inode
,0);
467 fdp
->block_count
= cpu_to_be32(j
);
468 affs_fix_checksum(AFFS_I2BSIZE(inode
),bh
->b_data
,5);
469 mark_buffer_dirty(bh
);
477 if (j
< AFFS_I2HSIZE(inode
)) {
478 /* N.B. What about pbh here? */
482 block
-= AFFS_I2HSIZE(inode
);
483 key
= be32_to_cpu(FILE_END(bh
->b_data
,inode
)->extension
);
485 key
= affs_new_header(inode
);
488 ebh
= affs_bread(inode
->i_dev
,key
,AFFS_I2BSIZE(inode
));
490 /* N.B. must free bh here */
493 ((struct file_front
*)ebh
->b_data
)->primary_type
= cpu_to_be32(T_LIST
);
494 ((struct file_front
*)ebh
->b_data
)->own_key
= cpu_to_be32(key
);
495 FILE_END(ebh
->b_data
,inode
)->secondary_type
= cpu_to_be32(ST_FILE
);
496 FILE_END(ebh
->b_data
,inode
)->parent
= cpu_to_be32(inode
->i_ino
);
497 affs_fix_checksum(AFFS_I2BSIZE(inode
),ebh
->b_data
,5);
498 mark_buffer_dirty(ebh
);
499 FILE_END(bh
->b_data
,inode
)->extension
= cpu_to_be32(key
);
500 affs_fix_checksum(AFFS_I2BSIZE(inode
),bh
->b_data
,5);
501 mark_buffer_dirty(bh
);
507 index
= seqnum_to_index(ext
);
508 if (index
> inode
->u
.affs_i
.i_ec
->max_ext
&&
510 inode
->u
.affs_i
.i_ec
->ec
[index
] = key
;
511 inode
->u
.affs_i
.i_ec
->max_ext
= index
;
516 /* Invalidate key cache */
517 for (j
= 0; j
< 4; j
++) {
518 kc
= &inode
->u
.affs_i
.i_ec
->kc
[j
];
521 key
= be32_to_cpu(AFFS_BLOCK(bh
->b_data
,inode
,block
));
526 bh
= affs_bread(inode
->i_dev
, key
, AFFS_I2BSIZE(inode
));
530 affs_free_block(sb
, key
);
538 affs_file_read_ofs(struct file
*filp
, char *buf
, size_t count
, loff_t
*ppos
)
540 struct inode
*inode
= filp
->f_dentry
->d_inode
;
542 ssize_t left
, offset
, size
, sector
;
544 struct buffer_head
*bh
;
548 pr_debug("AFFS: file_read_ofs(ino=%lu,pos=%lu,%d)\n",inode
->i_ino
,
549 (unsigned long)*ppos
,count
);
552 affs_error(inode
->i_sb
,"file_read_ofs","Inode = NULL");
555 blocksize
= AFFS_I2BSIZE(inode
) - 24;
556 if (!(S_ISREG(inode
->i_mode
))) {
557 pr_debug("AFFS: file_read: mode = %07o",inode
->i_mode
);
560 if (*ppos
>= inode
->i_size
|| count
<= 0)
565 left
= MIN (inode
->i_size
- *ppos
,count
- (buf
- start
));
569 do_div(tmp
, blocksize
);
570 sector
= affs_bmap(inode
, tmp
);
574 offset
= do_div(tmp
, blocksize
);
575 bh
= affs_bread(inode
->i_dev
,sector
,AFFS_I2BSIZE(inode
));
578 data
= bh
->b_data
+ 24;
579 size
= MIN(blocksize
- offset
,left
);
581 copy_to_user(buf
,data
+ offset
,size
);
591 affs_file_write(struct file
*file
, const char *buf
, size_t count
, loff_t
*ppos
)
595 retval
= generic_file_write (file
, buf
, count
, ppos
);
597 struct inode
*inode
= file
->f_dentry
->d_inode
;
598 inode
->i_ctime
= inode
->i_mtime
= CURRENT_TIME
;
599 mark_inode_dirty(inode
);
605 affs_file_write_ofs(struct file
*file
, const char *buf
, size_t count
, loff_t
*ppos
)
609 retval
= generic_file_write (file
, buf
, count
, ppos
);
611 struct inode
*inode
= file
->f_dentry
->d_inode
;
612 inode
->i_ctime
= inode
->i_mtime
= CURRENT_TIME
;
613 mark_inode_dirty(inode
);
618 /* Free any preallocated blocks. */
621 affs_free_prealloc(struct inode
*inode
)
623 struct super_block
*sb
= inode
->i_sb
;
624 struct affs_zone
*zone
;
627 pr_debug("AFFS: free_prealloc(ino=%lu)\n", inode
->i_ino
);
629 while (inode
->u
.affs_i
.i_pa_cnt
) {
630 block
= inode
->u
.affs_i
.i_data
[inode
->u
.affs_i
.i_pa_next
++];
631 inode
->u
.affs_i
.i_pa_next
&= AFFS_MAX_PREALLOC
- 1;
632 inode
->u
.affs_i
.i_pa_cnt
--;
633 affs_free_block(sb
, block
);
635 if (inode
->u
.affs_i
.i_zone
) {
636 zone
= &sb
->u
.affs_sb
.s_zones
[inode
->u
.affs_i
.i_zone
];
637 if (zone
->z_ino
== inode
->i_ino
)
642 /* Truncate (or enlarge) a file to the requested size. */
645 affs_truncate(struct inode
*inode
)
647 struct buffer_head
*bh
= NULL
;
648 int first
; /* First block to be thrown away */
656 int blocksize
= AFFS_I2BSIZE(inode
);
661 pr_debug("AFFS: truncate(inode=%ld,size=%lu)\n",inode
->i_ino
,inode
->i_size
);
663 net_blocksize
= blocksize
- ((inode
->i_sb
->u
.affs_sb
.s_flags
& SF_OFS
) ? 24 : 0);
664 first
= inode
->i_size
+ net_blocksize
-1;
665 do_div (first
, net_blocksize
);
666 if (inode
->u
.affs_i
.i_lastblock
< first
- 1) {
667 /* There has to be at least one new block to be allocated */
668 if (!inode
->u
.affs_i
.i_ec
&& alloc_ext_cache(inode
)) {
669 /* XXX Fine! No way to indicate an error. */
670 return /* -ENOSPC */;
672 bh
= affs_getblock(inode
,first
- 1);
674 affs_warning(inode
->i_sb
,"truncate","Cannot extend file");
675 inode
->i_size
= net_blocksize
* (inode
->u
.affs_i
.i_lastblock
+ 1);
676 } else if (inode
->i_sb
->u
.affs_sb
.s_flags
& SF_OFS
) {
678 rem
= do_div(tmp
, net_blocksize
);
679 DATA_FRONT(bh
)->data_size
= cpu_to_be32(rem
? rem
: net_blocksize
);
680 affs_fix_checksum(blocksize
,bh
->b_data
,5);
681 mark_buffer_dirty(bh
);
688 /* Free all blocks starting at 'first' and all then-empty
689 * extension blocks. Do not free the header block, though.
692 if (!(bh
= affs_bread(inode
->i_dev
,ekey
,blocksize
))) {
693 affs_error(inode
->i_sb
,"truncate","Cannot read block %d",ekey
);
696 if (affs_checksum_block(blocksize
,bh
->b_data
,&ptype
,&stype
)) {
697 affs_error(inode
->i_sb
,"truncate","Checksum error in header/ext block %d",
701 if (stype
!= ST_FILE
|| (ptype
!= T_SHORT
&& ptype
!= T_LIST
)) {
702 affs_error(inode
->i_sb
,"truncate",
703 "Bad block (key=%d, ptype=%d, stype=%d)",ekey
,ptype
,stype
);
706 /* Do we have to free this extension block after
707 * freeing the data blocks pointed to?
709 freethis
= first
== 0 && ekey
!= inode
->i_ino
;
711 /* Free the data blocks. 'first' is relative to this
712 * extension block and may well lie behind this block.
714 for (block
= first
; block
< AFFS_I2HSIZE(inode
); block
++) {
715 keyp
= &AFFS_BLOCK(bh
->b_data
,inode
,block
);
716 key
= be32_to_cpu(*keyp
);
719 affs_free_block(inode
->i_sb
,key
);
723 keyp
= &GET_END_PTR(struct file_end
,bh
->b_data
,blocksize
)->extension
;
724 key
= be32_to_cpu(*keyp
);
726 /* If 'first' is in this block or is the first
727 * in the next one, this will be the last in
728 * the list, thus we have to adjust the count
729 * and zero the pointer to the next ext block.
731 if (first
<= AFFS_I2HSIZE(inode
)) {
732 ((struct file_front
*)bh
->b_data
)->block_count
= cpu_to_be32(first
);
735 affs_fix_checksum(blocksize
,bh
->b_data
,5);
736 mark_buffer_dirty(bh
);
738 first
-= AFFS_I2HSIZE(inode
);
741 if (freethis
) /* Don't bother fixing checksum */
742 affs_free_block(inode
->i_sb
,ekey
);
745 block
= inode
->i_size
+ net_blocksize
- 1;
746 do_div (block
, net_blocksize
);
748 inode
->u
.affs_i
.i_lastblock
= block
;
750 /* If the file is not truncated to a block boundary,
751 * the partial block after the EOF must be zeroed
752 * so it cannot become accessible again.
756 rem
= do_div(tmp
, net_blocksize
);
758 if ((inode
->i_sb
->u
.affs_sb
.s_flags
& SF_OFS
))
760 pr_debug("AFFS: Zeroing from offset %d in block %d\n",rem
,block
);
761 bh
= affs_getblock(inode
,block
);
763 memset(bh
->b_data
+ rem
,0,blocksize
- rem
);
764 if ((inode
->i_sb
->u
.affs_sb
.s_flags
& SF_OFS
)) {
765 ((struct data_front
*)bh
->b_data
)->data_size
= cpu_to_be32(rem
);
766 ((struct data_front
*)bh
->b_data
)->next_data
= 0;
767 affs_fix_checksum(blocksize
,bh
->b_data
,5);
769 mark_buffer_dirty(bh
);
771 affs_error(inode
->i_sb
,"truncate","Cannot read block %d",block
);
776 /* Invalidate cache */
777 if (inode
->u
.affs_i
.i_ec
) {
778 inode
->u
.affs_i
.i_ec
->max_ext
= 0;
779 for (key
= 0; key
< 4; key
++) {
780 inode
->u
.affs_i
.i_ec
->kc
[key
].kc_next_key
= 0;
781 inode
->u
.affs_i
.i_ec
->kc
[key
].kc_last
= -1;
784 mark_inode_dirty(inode
);
788 * Called only when we need to allocate the extension cache.
792 alloc_ext_cache(struct inode
*inode
)
796 unsigned long cache_page
;
799 pr_debug("AFFS: alloc_ext_cache(ino=%lu)\n",inode
->i_ino
);
801 cache_page
= get_free_page(GFP_KERNEL
);
803 * Check whether somebody else allocated it for us ...
805 if (inode
->u
.affs_i
.i_ec
)
810 inode
->u
.affs_i
.i_ec
= (struct ext_cache
*) cache_page
;
811 /* We only have to initialize non-zero values.
812 * get_free_page() zeroed the page already.
815 inode
->u
.affs_i
.i_ec
->ec
[0] = key
;
816 for (i
= 0; i
< 4; i
++) {
817 inode
->u
.affs_i
.i_ec
->kc
[i
].kc_this_key
= key
;
818 inode
->u
.affs_i
.i_ec
->kc
[i
].kc_last
= -1;
825 free_page(cache_page
);
829 affs_error(inode
->i_sb
,"alloc_ext_cache","Cache allocation failed");