2 * logfile.c - NTFS kernel journal handling. Part of the Linux-NTFS project.
4 * Copyright (c) 2002-2004 Anton Altaparmakov
6 * This program/include file is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License as published
8 * by the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program/include file is distributed in the hope that it will be
12 * useful, but WITHOUT ANY WARRANTY; without even the implied warranty
13 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program (in the main directory of the Linux-NTFS
18 * distribution in the file COPYING); if not, write to the Free Software
19 * Foundation,Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 #include <linux/types.h>
26 #include <linux/highmem.h>
27 #include <linux/buffer_head.h>
28 #include <linux/bitops.h>
36 * ntfs_check_restart_page_header - check the page header for consistency
37 * @vi: $LogFile inode to which the restart page header belongs
38 * @rp: restart page header to check
39 * @pos: position in @vi at which the restart page header resides
41 * Check the restart page header @rp for consistency and return TRUE if it is
42 * consistent and FALSE otherwise.
44 * This function only needs NTFS_BLOCK_SIZE bytes in @rp, i.e. it does not
45 * require the full restart page.
47 static BOOL
ntfs_check_restart_page_header(struct inode
*vi
,
48 RESTART_PAGE_HEADER
*rp
, s64 pos
)
50 u32 logfile_system_page_size
, logfile_log_page_size
;
51 u16 usa_count
, usa_ofs
, usa_end
, ra_ofs
;
53 ntfs_debug("Entering.");
55 * If the system or log page sizes are smaller than the ntfs block size
56 * or either is not a power of 2 we cannot handle this log file.
58 logfile_system_page_size
= le32_to_cpu(rp
->system_page_size
);
59 logfile_log_page_size
= le32_to_cpu(rp
->log_page_size
);
60 if (logfile_system_page_size
< NTFS_BLOCK_SIZE
||
61 logfile_log_page_size
< NTFS_BLOCK_SIZE
||
62 logfile_system_page_size
&
63 (logfile_system_page_size
- 1) ||
64 logfile_log_page_size
& (logfile_log_page_size
- 1)) {
65 ntfs_error(vi
->i_sb
, "$LogFile uses unsupported page size.");
69 * We must be either at !pos (1st restart page) or at pos = system page
70 * size (2nd restart page).
72 if (pos
&& pos
!= logfile_system_page_size
) {
73 ntfs_error(vi
->i_sb
, "Found restart area in incorrect "
74 "position in $LogFile.");
77 /* We only know how to handle version 1.1. */
78 if (sle16_to_cpu(rp
->major_ver
) != 1 ||
79 sle16_to_cpu(rp
->minor_ver
) != 1) {
80 ntfs_error(vi
->i_sb
, "$LogFile version %i.%i is not "
81 "supported. (This driver supports version "
82 "1.1 only.)", (int)sle16_to_cpu(rp
->major_ver
),
83 (int)sle16_to_cpu(rp
->minor_ver
));
86 /* Verify the size of the update sequence array. */
87 usa_count
= 1 + (logfile_system_page_size
>> NTFS_BLOCK_SIZE_BITS
);
88 if (usa_count
!= le16_to_cpu(rp
->usa_count
)) {
89 ntfs_error(vi
->i_sb
, "$LogFile restart page specifies "
90 "inconsistent update sequence array count.");
93 /* Verify the position of the update sequence array. */
94 usa_ofs
= le16_to_cpu(rp
->usa_ofs
);
95 usa_end
= usa_ofs
+ usa_count
* sizeof(u16
);
96 if (usa_ofs
< sizeof(RESTART_PAGE_HEADER
) ||
97 usa_end
> NTFS_BLOCK_SIZE
- sizeof(u16
)) {
98 ntfs_error(vi
->i_sb
, "$LogFile restart page specifies "
99 "inconsistent update sequence array offset.");
103 * Verify the position of the restart area. It must be:
104 * - aligned to 8-byte boundary,
105 * - after the update sequence array, and
106 * - within the system page size.
108 ra_ofs
= le16_to_cpu(rp
->restart_area_offset
);
109 if (ra_ofs
& 7 || ra_ofs
< usa_end
||
110 ra_ofs
> logfile_system_page_size
) {
111 ntfs_error(vi
->i_sb
, "$LogFile restart page specifies "
112 "inconsistent restart area offset.");
116 * Only restart pages modified by chkdsk are allowed to have chkdsk_lsn
119 if (!ntfs_is_chkd_record(rp
->magic
) && sle64_to_cpu(rp
->chkdsk_lsn
)) {
120 ntfs_error(vi
->i_sb
, "$LogFile restart page is not modified "
121 "chkdsk but a chkdsk LSN is specified.");
129 * ntfs_check_restart_area - check the restart area for consistency
130 * @vi: $LogFile inode to which the restart page belongs
131 * @rp: restart page whose restart area to check
133 * Check the restart area of the restart page @rp for consistency and return
134 * TRUE if it is consistent and FALSE otherwise.
136 * This function assumes that the restart page header has already been
137 * consistency checked.
139 * This function only needs NTFS_BLOCK_SIZE bytes in @rp, i.e. it does not
140 * require the full restart page.
142 static BOOL
ntfs_check_restart_area(struct inode
*vi
, RESTART_PAGE_HEADER
*rp
)
146 u16 ra_ofs
, ra_len
, ca_ofs
;
149 ntfs_debug("Entering.");
150 ra_ofs
= le16_to_cpu(rp
->restart_area_offset
);
151 ra
= (RESTART_AREA
*)((u8
*)rp
+ ra_ofs
);
153 * Everything before ra->file_size must be before the first word
154 * protected by an update sequence number. This ensures that it is
155 * safe to access ra->client_array_offset.
157 if (ra_ofs
+ offsetof(RESTART_AREA
, file_size
) >
158 NTFS_BLOCK_SIZE
- sizeof(u16
)) {
159 ntfs_error(vi
->i_sb
, "$LogFile restart area specifies "
160 "inconsistent file offset.");
164 * Now that we can access ra->client_array_offset, make sure everything
165 * up to the log client array is before the first word protected by an
166 * update sequence number. This ensures we can access all of the
167 * restart area elements safely. Also, the client array offset must be
168 * aligned to an 8-byte boundary.
170 ca_ofs
= le16_to_cpu(ra
->client_array_offset
);
171 if (((ca_ofs
+ 7) & ~7) != ca_ofs
||
172 ra_ofs
+ ca_ofs
> NTFS_BLOCK_SIZE
- sizeof(u16
)) {
173 ntfs_error(vi
->i_sb
, "$LogFile restart area specifies "
174 "inconsistent client array offset.");
178 * The restart area must end within the system page size both when
179 * calculated manually and as specified by ra->restart_area_length.
180 * Also, the calculated length must not exceed the specified length.
182 ra_len
= ca_ofs
+ le16_to_cpu(ra
->log_clients
) *
183 sizeof(LOG_CLIENT_RECORD
);
184 if (ra_ofs
+ ra_len
> le32_to_cpu(rp
->system_page_size
) ||
185 ra_ofs
+ le16_to_cpu(ra
->restart_area_length
) >
186 le32_to_cpu(rp
->system_page_size
) ||
187 ra_len
> le16_to_cpu(ra
->restart_area_length
)) {
188 ntfs_error(vi
->i_sb
, "$LogFile restart area is out of bounds "
189 "of the system page size specified by the "
190 "restart page header and/or the specified "
191 "restart area length is inconsistent.");
195 * The ra->client_free_list and ra->client_in_use_list must be either
196 * LOGFILE_NO_CLIENT or less than ra->log_clients or they are
197 * overflowing the client array.
199 if ((ra
->client_free_list
!= LOGFILE_NO_CLIENT
&&
200 le16_to_cpu(ra
->client_free_list
) >=
201 le16_to_cpu(ra
->log_clients
)) ||
202 (ra
->client_in_use_list
!= LOGFILE_NO_CLIENT
&&
203 le16_to_cpu(ra
->client_in_use_list
) >=
204 le16_to_cpu(ra
->log_clients
))) {
205 ntfs_error(vi
->i_sb
, "$LogFile restart area specifies "
206 "overflowing client free and/or in use lists.");
210 * Check ra->seq_number_bits against ra->file_size for consistency.
211 * We cannot just use ffs() because the file size is not a power of 2.
213 file_size
= (u64
)sle64_to_cpu(ra
->file_size
);
219 if (le32_to_cpu(ra
->seq_number_bits
) != 67 - fs_bits
) {
220 ntfs_error(vi
->i_sb
, "$LogFile restart area specifies "
221 "inconsistent sequence number bits.");
224 /* The log record header length must be a multiple of 8. */
225 if (((le16_to_cpu(ra
->log_record_header_length
) + 7) & ~7) !=
226 le16_to_cpu(ra
->log_record_header_length
)) {
227 ntfs_error(vi
->i_sb
, "$LogFile restart area specifies "
228 "inconsistent log record header length.");
231 /* Dito for the log page data offset. */
232 if (((le16_to_cpu(ra
->log_page_data_offset
) + 7) & ~7) !=
233 le16_to_cpu(ra
->log_page_data_offset
)) {
234 ntfs_error(vi
->i_sb
, "$LogFile restart area specifies "
235 "inconsistent log page data offset.");
243 * ntfs_check_log_client_array - check the log client array for consistency
244 * @vi: $LogFile inode to which the restart page belongs
245 * @rp: restart page whose log client array to check
247 * Check the log client array of the restart page @rp for consistency and
248 * return TRUE if it is consistent and FALSE otherwise.
250 * This function assumes that the restart page header and the restart area have
251 * already been consistency checked.
253 * Unlike ntfs_check_restart_page_header() and ntfs_check_restart_area(), this
254 * function needs @rp->system_page_size bytes in @rp, i.e. it requires the full
255 * restart page and the page must be multi sector transfer deprotected.
257 static BOOL
ntfs_check_log_client_array(struct inode
*vi
,
258 RESTART_PAGE_HEADER
*rp
)
261 LOG_CLIENT_RECORD
*ca
, *cr
;
263 BOOL in_free_list
, idx_is_first
;
265 ntfs_debug("Entering.");
266 ra
= (RESTART_AREA
*)((u8
*)rp
+ le16_to_cpu(rp
->restart_area_offset
));
267 ca
= (LOG_CLIENT_RECORD
*)((u8
*)ra
+
268 le16_to_cpu(ra
->client_array_offset
));
270 * Check the ra->client_free_list first and then check the
271 * ra->client_in_use_list. Check each of the log client records in
272 * each of the lists and check that the array does not overflow the
273 * ra->log_clients value. Also keep track of the number of records
274 * visited as there cannot be more than ra->log_clients records and
275 * that way we detect eventual loops in within a list.
277 nr_clients
= le16_to_cpu(ra
->log_clients
);
278 idx
= le16_to_cpu(ra
->client_free_list
);
281 for (idx_is_first
= TRUE
; idx
!= LOGFILE_NO_CLIENT_CPU
; nr_clients
--,
282 idx
= le16_to_cpu(cr
->next_client
)) {
283 if (!nr_clients
|| idx
>= le16_to_cpu(ra
->log_clients
))
285 /* Set @cr to the current log client record. */
287 /* The first log client record must not have a prev_client. */
289 if (cr
->prev_client
!= LOGFILE_NO_CLIENT
)
291 idx_is_first
= FALSE
;
294 /* Switch to and check the in use list if we just did the free list. */
296 in_free_list
= FALSE
;
297 idx
= le16_to_cpu(ra
->client_in_use_list
);
303 ntfs_error(vi
->i_sb
, "$LogFile log client array is corrupt.");
308 * ntfs_check_and_load_restart_page - check the restart page for consistency
309 * @vi: $LogFile inode to which the restart page belongs
310 * @rp: restart page to check
311 * @pos: position in @vi at which the restart page resides
312 * @wrp: copy of the multi sector transfer deprotected restart page
314 * Check the restart page @rp for consistency and return TRUE if it is
315 * consistent and FALSE otherwise.
317 * This function only needs NTFS_BLOCK_SIZE bytes in @rp, i.e. it does not
318 * require the full restart page.
320 * If @wrp is not NULL, on success, *@wrp will point to a buffer containing a
321 * copy of the complete multi sector transfer deprotected page. On failure,
322 * *@wrp is undefined.
324 static BOOL
ntfs_check_and_load_restart_page(struct inode
*vi
,
325 RESTART_PAGE_HEADER
*rp
, s64 pos
, RESTART_PAGE_HEADER
**wrp
)
328 RESTART_PAGE_HEADER
*trp
;
332 ntfs_debug("Entering.");
333 /* Check the restart page header for consistency. */
334 if (!ntfs_check_restart_page_header(vi
, rp
, pos
)) {
335 /* Error output already done inside the function. */
338 /* Check the restart area for consistency. */
339 if (!ntfs_check_restart_area(vi
, rp
)) {
340 /* Error output already done inside the function. */
343 ra
= (RESTART_AREA
*)((u8
*)rp
+ le16_to_cpu(rp
->restart_area_offset
));
345 * Allocate a buffer to store the whole restart page so we can multi
346 * sector transfer deprotect it.
348 trp
= ntfs_malloc_nofs(le32_to_cpu(rp
->system_page_size
));
350 ntfs_error(vi
->i_sb
, "Failed to allocate memory for $LogFile "
351 "restart page buffer.");
355 * Read the whole of the restart page into the buffer. If it fits
356 * completely inside @rp, just copy it from there. Otherwise map all
357 * the required pages and copy the data from them.
359 size
= PAGE_CACHE_SIZE
- (pos
& ~PAGE_CACHE_MASK
);
360 if (size
>= le32_to_cpu(rp
->system_page_size
)) {
361 memcpy(trp
, rp
, le32_to_cpu(rp
->system_page_size
));
365 int have_read
, to_read
;
367 /* First copy what we already have in @rp. */
368 memcpy(trp
, rp
, size
);
369 /* Copy the remaining data one page at a time. */
371 to_read
= le32_to_cpu(rp
->system_page_size
) - size
;
372 idx
= (pos
+ size
) >> PAGE_CACHE_SHIFT
;
373 BUG_ON((pos
+ size
) & ~PAGE_CACHE_MASK
);
375 page
= ntfs_map_page(vi
->i_mapping
, idx
);
377 ntfs_error(vi
->i_sb
, "Error mapping $LogFile "
378 "page (index %lu).", idx
);
381 size
= min_t(int, to_read
, PAGE_CACHE_SIZE
);
382 memcpy((u8
*)trp
+ have_read
, page_address(page
), size
);
383 ntfs_unmap_page(page
);
387 } while (to_read
> 0);
389 /* Perform the multi sector transfer deprotection on the buffer. */
390 if (post_read_mst_fixup((NTFS_RECORD
*)trp
,
391 le32_to_cpu(rp
->system_page_size
))) {
392 ntfs_error(vi
->i_sb
, "Multi sector transfer error detected in "
393 "$LogFile restart page.");
396 /* Check the log client records for consistency. */
397 ret
= ntfs_check_log_client_array(vi
, trp
);
410 * ntfs_ckeck_logfile - check in the journal if the volume is consistent
411 * @log_vi: struct inode of loaded journal $LogFile to check
413 * Check the $LogFile journal for consistency and return TRUE if it is
414 * consistent and FALSE if not.
416 * At present we only check the two restart pages and ignore the log record
419 * Note that the MstProtected flag is not set on the $LogFile inode and hence
420 * when reading pages they are not deprotected. This is because we do not know
421 * if the $LogFile was created on a system with a different page size to ours
422 * yet and mst deprotection would fail if our page size is smaller.
424 BOOL
ntfs_check_logfile(struct inode
*log_vi
)
426 s64 size
, pos
, rstr1_pos
, rstr2_pos
;
427 ntfs_volume
*vol
= NTFS_SB(log_vi
->i_sb
);
428 struct address_space
*mapping
= log_vi
->i_mapping
;
429 struct page
*page
= NULL
;
431 RESTART_PAGE_HEADER
*rstr1_ph
= NULL
;
432 RESTART_PAGE_HEADER
*rstr2_ph
= NULL
;
433 int log_page_size
, log_page_mask
, ofs
;
434 BOOL logfile_is_empty
= TRUE
;
435 BOOL rstr1_found
= FALSE
;
436 BOOL rstr2_found
= FALSE
;
439 ntfs_debug("Entering.");
440 /* An empty $LogFile must have been clean before it got emptied. */
441 if (NVolLogFileEmpty(vol
))
443 size
= log_vi
->i_size
;
444 /* Make sure the file doesn't exceed the maximum allowed size. */
445 if (size
> MaxLogFileSize
)
446 size
= MaxLogFileSize
;
448 * Truncate size to a multiple of the page cache size or the default
449 * log page size if the page cache size is between the default log page
450 * log page size if the page cache size is between the default log page
451 * size and twice that.
453 if (PAGE_CACHE_SIZE
>= DefaultLogPageSize
&& PAGE_CACHE_SIZE
<=
454 DefaultLogPageSize
* 2)
455 log_page_size
= DefaultLogPageSize
;
457 log_page_size
= PAGE_CACHE_SIZE
;
458 log_page_mask
= log_page_size
- 1;
460 * Use generic_ffs() instead of ffs() to enable the compiler to
461 * optimize log_page_size and log_page_bits into constants.
463 log_page_bits
= generic_ffs(log_page_size
) - 1;
464 size
&= ~(log_page_size
- 1);
466 * Ensure the log file is big enough to store at least the two restart
467 * pages and the minimum number of log record pages.
469 if (size
< log_page_size
* 2 || (size
- log_page_size
* 2) >>
470 log_page_bits
< MinLogRecordPages
) {
471 ntfs_error(vol
->sb
, "$LogFile is too small.");
475 * Read through the file looking for a restart page. Since the restart
476 * page header is at the beginning of a page we only need to search at
477 * what could be the beginning of a page (for each page size) rather
478 * than scanning the whole file byte by byte. If all potential places
479 * contain empty and uninitialzed records, the log file can be assumed
482 for (pos
= 0; pos
< size
; pos
<<= 1) {
483 pgoff_t idx
= pos
>> PAGE_CACHE_SHIFT
;
484 if (!page
|| page
->index
!= idx
) {
486 ntfs_unmap_page(page
);
487 page
= ntfs_map_page(mapping
, idx
);
489 ntfs_error(vol
->sb
, "Error mapping $LogFile "
490 "page (index %lu).", idx
);
494 kaddr
= (u8
*)page_address(page
) + (pos
& ~PAGE_CACHE_MASK
);
496 * A non-empty block means the logfile is not empty while an
497 * empty block after a non-empty block has been encountered
500 if (!ntfs_is_empty_recordp((le32
*)kaddr
))
501 logfile_is_empty
= FALSE
;
502 else if (!logfile_is_empty
)
505 * A log record page means there cannot be a restart page after
506 * this so no need to continue searching.
508 if (ntfs_is_rcrd_recordp((le32
*)kaddr
))
511 * A modified by chkdsk restart page means we cannot handle
514 if (ntfs_is_chkd_recordp((le32
*)kaddr
)) {
515 ntfs_error(vol
->sb
, "$LogFile has been modified by "
516 "chkdsk. Mount this volume in "
520 /* If not a restart page, continue. */
521 if (!ntfs_is_rstr_recordp((le32
*)kaddr
)) {
522 /* Skip to the minimum page size for the next one. */
524 pos
= NTFS_BLOCK_SIZE
>> 1;
527 /* We now know we have a restart page. */
533 ntfs_error(vol
->sb
, "Found more than two "
534 "restart pages in $LogFile.");
541 * Check the restart page for consistency and get a copy of the
542 * complete multi sector transfer deprotected restart page.
544 if (!ntfs_check_and_load_restart_page(log_vi
,
545 (RESTART_PAGE_HEADER
*)kaddr
, pos
,
546 !pos
? &rstr1_ph
: &rstr2_ph
)) {
547 /* Error output already done inside the function. */
551 * We have a valid restart page. The next one must be after
552 * a whole system page size as specified by the valid restart
556 pos
= le32_to_cpu(rstr1_ph
->system_page_size
) >> 1;
559 ntfs_unmap_page(page
);
562 if (logfile_is_empty
) {
563 NVolSetLogFileEmpty(vol
);
565 ntfs_debug("Done. ($LogFile is empty.)");
568 if (!rstr1_found
|| !rstr2_found
) {
569 ntfs_error(vol
->sb
, "Did not find two restart pages in "
574 * The two restart areas must be identical except for the update
577 ofs
= le16_to_cpu(rstr1_ph
->usa_ofs
);
578 if (memcmp(rstr1_ph
, rstr2_ph
, ofs
) || (ofs
+= sizeof(u16
),
579 memcmp((u8
*)rstr1_ph
+ ofs
, (u8
*)rstr2_ph
+ ofs
,
580 le32_to_cpu(rstr1_ph
->system_page_size
) - ofs
))) {
581 ntfs_error(vol
->sb
, "The two restart pages in $LogFile do not "
587 /* All consistency checks passed. */
592 ntfs_unmap_page(page
);
601 * ntfs_is_logfile_clean - check in the journal if the volume is clean
602 * @log_vi: struct inode of loaded journal $LogFile to check
604 * Analyze the $LogFile journal and return TRUE if it indicates the volume was
605 * shutdown cleanly and FALSE if not.
607 * At present we only look at the two restart pages and ignore the log record
608 * pages. This is a little bit crude in that there will be a very small number
609 * of cases where we think that a volume is dirty when in fact it is clean.
610 * This should only affect volumes that have not been shutdown cleanly but did
611 * not have any pending, non-check-pointed i/o, i.e. they were completely idle
612 * at least for the five seconds preceeding the unclean shutdown.
614 * This function assumes that the $LogFile journal has already been consistency
615 * checked by a call to ntfs_check_logfile() and in particular if the $LogFile
616 * is empty this function requires that NVolLogFileEmpty() is true otherwise an
617 * empty volume will be reported as dirty.
619 BOOL
ntfs_is_logfile_clean(struct inode
*log_vi
)
621 ntfs_volume
*vol
= NTFS_SB(log_vi
->i_sb
);
623 RESTART_PAGE_HEADER
*rp
;
626 ntfs_debug("Entering.");
627 /* An empty $LogFile must have been clean before it got emptied. */
628 if (NVolLogFileEmpty(vol
)) {
629 ntfs_debug("Done. ($LogFile is empty.)");
633 * Read the first restart page. It will be possibly incomplete and
634 * will not be multi sector transfer deprotected but we only need the
635 * first NTFS_BLOCK_SIZE bytes so it does not matter.
637 page
= ntfs_map_page(log_vi
->i_mapping
, 0);
639 ntfs_error(vol
->sb
, "Error mapping $LogFile page (index 0).");
642 rp
= (RESTART_PAGE_HEADER
*)page_address(page
);
643 if (!ntfs_is_rstr_record(rp
->magic
)) {
644 ntfs_error(vol
->sb
, "No restart page found at offset zero in "
645 "$LogFile. This is probably a bug in that "
646 "the $LogFile should have been consistency "
647 "checked before calling this function.");
650 ra
= (RESTART_AREA
*)((u8
*)rp
+ le16_to_cpu(rp
->restart_area_offset
));
652 * If the $LogFile has active clients, i.e. it is open, and we do not
653 * have the RESTART_VOLUME_IS_CLEAN bit set in the restart area flags,
654 * we assume there was an unclean shutdown.
656 if (ra
->client_in_use_list
!= LOGFILE_NO_CLIENT
&&
657 !(ra
->flags
& RESTART_VOLUME_IS_CLEAN
)) {
658 ntfs_debug("Done. $LogFile indicates a dirty shutdown.");
661 ntfs_unmap_page(page
);
662 /* $LogFile indicates a clean shutdown. */
663 ntfs_debug("Done. $LogFile indicates a clean shutdown.");
666 ntfs_unmap_page(page
);
671 * ntfs_empty_logfile - empty the contents of the $LogFile journal
672 * @log_vi: struct inode of loaded journal $LogFile to empty
674 * Empty the contents of the $LogFile journal @log_vi and return TRUE on
675 * success and FALSE on error.
677 * This function assumes that the $LogFile journal has already been consistency
678 * checked by a call to ntfs_check_logfile() and that ntfs_is_logfile_clean()
679 * has been used to ensure that the $LogFile is clean.
681 BOOL
ntfs_empty_logfile(struct inode
*log_vi
)
683 ntfs_volume
*vol
= NTFS_SB(log_vi
->i_sb
);
684 struct address_space
*mapping
;
687 ntfs_debug("Entering.");
688 if (NVolLogFileEmpty(vol
))
690 mapping
= log_vi
->i_mapping
;
691 end
= (log_vi
->i_size
+ PAGE_CACHE_SIZE
- 1) >> PAGE_CACHE_SHIFT
;
692 for (idx
= 0; idx
< end
; ++idx
) {
696 /* Find or create the current page. (The page is locked.) */
697 page
= grab_cache_page(mapping
, idx
);
698 if (unlikely(!page
)) {
699 ntfs_error(vol
->sb
, "Insufficient memory to grab "
700 "$LogFile page (index %lu).", idx
);
704 * Set all bytes in the page to 0xff. It doesn't matter if we
705 * go beyond i_size, because ntfs_writepage() will take care of
708 kaddr
= (u8
*)kmap_atomic(page
, KM_USER0
);
709 memset(kaddr
, 0xff, PAGE_CACHE_SIZE
);
710 flush_dcache_page(page
);
711 kunmap_atomic(kaddr
, KM_USER0
);
713 * If the page has buffers, mark them uptodate since buffer
714 * state and not page state is definitive in 2.6 kernels.
716 if (page_has_buffers(page
)) {
717 struct buffer_head
*bh
, *head
;
719 bh
= head
= page_buffers(page
);
721 set_buffer_uptodate(bh
);
722 } while ((bh
= bh
->b_this_page
) != head
);
724 /* Now that buffers are uptodate, set the page uptodate, too. */
725 SetPageUptodate(page
);
727 * Set the page and all its buffers dirty and mark the inode
728 * dirty, too. The VM will write the page later on.
730 set_page_dirty(page
);
731 /* Finally unlock and release the page. */
733 page_cache_release(page
);
735 /* We set the flag so we do not clear the log file again on remount. */
736 NVolSetLogFileEmpty(vol
);