Lines Matching +full:multi +full:- +full:function

1 // SPDX-License-Identifier: GPL-2.0-or-later
5 * Copyright (c) 2002-2007 Anton Altaparmakov
15 * ntfs_check_restart_page_header - check the page header for consistency
23 * This function only needs NTFS_BLOCK_SIZE bytes in @rp, i.e. it does not
38 logfile_system_page_size = le32_to_cpu(rp->system_page_size);
39 logfile_log_page_size = le32_to_cpu(rp->log_page_size);
43 (logfile_system_page_size - 1) ||
45 ntfs_error(vi->i_sb, "LogFile uses unsupported page size.");
53 ntfs_error(vi->i_sb, "Found restart area in incorrect position in LogFile.");
57 if (le16_to_cpu(rp->major_ver) != 1 ||
58 le16_to_cpu(rp->minor_ver) != 1) {
59 ntfs_error(vi->i_sb,
61 (int)le16_to_cpu(rp->major_ver),
62 (int)le16_to_cpu(rp->minor_ver));
69 if (ntfs_is_chkd_record(rp->magic) && !le16_to_cpu(rp->usa_count)) {
75 if (usa_count != le16_to_cpu(rp->usa_count)) {
76 ntfs_error(vi->i_sb,
81 usa_ofs = le16_to_cpu(rp->usa_ofs);
84 usa_end > NTFS_BLOCK_SIZE - sizeof(u16)) {
85 ntfs_error(vi->i_sb,
92 * - aligned to 8-byte boundary,
93 * - after the update sequence array, and
94 * - within the system page size.
96 ra_ofs = le16_to_cpu(rp->restart_area_offset);
100 ntfs_error(vi->i_sb,
108 if (!ntfs_is_chkd_record(rp->magic) && le64_to_cpu(rp->chkdsk_lsn)) {
109 ntfs_error(vi->i_sb,
118 * ntfs_check_restart_area - check the restart area for consistency
125 * This function assumes that the restart page header has already been
128 * This function only needs NTFS_BLOCK_SIZE bytes in @rp, i.e. it does not
139 ra_ofs = le16_to_cpu(rp->restart_area_offset);
142 * Everything before ra->file_size must be before the first word
144 * safe to access ra->client_array_offset.
147 NTFS_BLOCK_SIZE - sizeof(u16)) {
148 ntfs_error(vi->i_sb,
153 * Now that we can access ra->client_array_offset, make sure everything
157 * aligned to an 8-byte boundary.
159 ca_ofs = le16_to_cpu(ra->client_array_offset);
161 ra_ofs + ca_ofs > NTFS_BLOCK_SIZE - sizeof(u16)) {
162 ntfs_error(vi->i_sb,
168 * calculated manually and as specified by ra->restart_area_length.
171 ra_len = ca_ofs + le16_to_cpu(ra->log_clients) *
173 if (ra_ofs + ra_len > le32_to_cpu(rp->system_page_size) ||
174 ra_ofs + le16_to_cpu(ra->restart_area_length) >
175 le32_to_cpu(rp->system_page_size) ||
176 ra_len > le16_to_cpu(ra->restart_area_length)) {
177 ntfs_error(vi->i_sb,
182 * The ra->client_free_list and ra->client_in_use_list must be either
183 * LOGFILE_NO_CLIENT or less than ra->log_clients or they are
186 if ((ra->client_free_list != LOGFILE_NO_CLIENT &&
187 le16_to_cpu(ra->client_free_list) >=
188 le16_to_cpu(ra->log_clients)) ||
189 (ra->client_in_use_list != LOGFILE_NO_CLIENT &&
190 le16_to_cpu(ra->client_in_use_list) >=
191 le16_to_cpu(ra->log_clients))) {
192 ntfs_error(vi->i_sb,
197 * Check ra->seq_number_bits against ra->file_size for consistency.
200 file_size = le64_to_cpu(ra->file_size);
206 if (le32_to_cpu(ra->seq_number_bits) != 67 - fs_bits) {
207 ntfs_error(vi->i_sb,
212 if (((le16_to_cpu(ra->log_record_header_length) + 7) & ~7) !=
213 le16_to_cpu(ra->log_record_header_length)) {
214 ntfs_error(vi->i_sb,
219 if (((le16_to_cpu(ra->log_page_data_offset) + 7) & ~7) !=
220 le16_to_cpu(ra->log_page_data_offset)) {
221 ntfs_error(vi->i_sb,
230 * ntfs_check_log_client_array - check the log client array for consistency
237 * This function assumes that the restart page header and the restart area have
241 * function needs @rp->system_page_size bytes in @rp, i.e. it requires the full
242 * restart page and the page must be multi sector transfer deprotected.
253 ra = (struct restart_area *)((u8 *)rp + le16_to_cpu(rp->restart_area_offset));
255 le16_to_cpu(ra->client_array_offset));
257 * Check the ra->client_free_list first and then check the
258 * ra->client_in_use_list. Check each of the log client records in
260 * ra->log_clients value. Also keep track of the number of records
261 * visited as there cannot be more than ra->log_clients records and
264 nr_clients = le16_to_cpu(ra->log_clients);
265 idx = le16_to_cpu(ra->client_free_list);
268 for (idx_is_first = true; idx != LOGFILE_NO_CLIENT_CPU; nr_clients--,
269 idx = le16_to_cpu(cr->next_client)) {
270 if (!nr_clients || idx >= le16_to_cpu(ra->log_clients))
276 if (cr->prev_client != LOGFILE_NO_CLIENT)
284 idx = le16_to_cpu(ra->client_in_use_list);
290 ntfs_error(vi->i_sb, "LogFile log client array is corrupt.");
295 * ntfs_check_and_load_restart_page - check the restart page for consistency
299 * @wrp: [OUT] copy of the multi sector transfer deprotected restart page
303 * and -errno otherwise. The restart page may have been modified by chkdsk in
306 * This function only needs NTFS_BLOCK_SIZE bytes in @rp, i.e. it does not
310 * copy of the complete multi sector transfer deprotected page. On failure,
317 * -EINVAL - The restart page is inconsistent.
318 * -ENOMEM - Not enough memory to load the restart page.
319 * -EIO - Failed to reading from LogFile.
332 /* Error output already done inside the function. */
333 return -EINVAL;
337 /* Error output already done inside the function. */
338 return -EINVAL;
340 ra = (struct restart_area *)((u8 *)rp + le16_to_cpu(rp->restart_area_offset));
342 * Allocate a buffer to store the whole restart page so we can multi
345 trp = kvzalloc(le32_to_cpu(rp->system_page_size), GFP_NOFS);
347 ntfs_error(vi->i_sb, "Failed to allocate memory for LogFile restart page buffer.");
348 return -ENOMEM;
355 size = PAGE_SIZE - (pos & ~PAGE_MASK);
356 if (size >= le32_to_cpu(rp->system_page_size)) {
357 memcpy(trp, rp, le32_to_cpu(rp->system_page_size));
367 to_read = le32_to_cpu(rp->system_page_size) - size;
370 folio = read_mapping_folio(vi->i_mapping, idx, NULL);
372 ntfs_error(vi->i_sb, "Error mapping LogFile page (index %lu).",
375 if (err != -EIO && err != -ENOMEM)
376 err = -EIO;
383 to_read -= size;
388 * Perform the multi sector transfer deprotection on the buffer if the
391 if ((!ntfs_is_chkd_record(trp->magic) || le16_to_cpu(trp->usa_count)) &&
392 post_read_mst_fixup((struct ntfs_record *)trp, le32_to_cpu(rp->system_page_size))) {
394 * A multi sector transfer error was detected. We only need to
395 * abort if the restart page contents exceed the multi sector
398 if (le16_to_cpu(rp->restart_area_offset) +
399 le16_to_cpu(ra->restart_area_length) >
400 NTFS_BLOCK_SIZE - sizeof(u16)) {
401 ntfs_error(vi->i_sb,
402 "Multi sector transfer error detected in LogFile restart page.");
403 err = -EINVAL;
413 if (ntfs_is_rstr_record(rp->magic) &&
414 ra->client_in_use_list != LOGFILE_NO_CLIENT) {
416 err = -EINVAL;
421 if (ntfs_is_rstr_record(rp->magic))
422 *lsn = le64_to_cpu(ra->current_lsn);
423 else /* if (ntfs_is_chkd_record(rp->magic)) */
424 *lsn = le64_to_cpu(rp->chkdsk_lsn);
437 * ntfs_check_logfile - check the journal for consistency
457 struct ntfs_volume *vol = NTFS_SB(log_vi->i_sb);
458 struct address_space *mapping = log_vi->i_mapping;
490 log_page_bits = ntfs_ffs(log_page_size) - 1;
491 size &= ~(s64)(log_page_size - 1);
496 if (size < log_page_size * 2 || (size - log_page_size * 2) >>
498 ntfs_error(vol->sb, "LogFile is too small.");
512 if (!folio || folio->index != idx) {
519 ntfs_error(vol->sb, "Error mapping LogFile page (index %lu).",
526 * A non-empty block means the logfile is not empty while an
527 * empty block after a non-empty block has been encountered
549 * and get a copy of the complete multi sector transfer
572 * Error output already done inside the function. Note, we do
576 if (err != -EINVAL) {
596 ntfs_error(vol->sb,
630 * ntfs_empty_logfile - empty the contents of the LogFile journal
636 * This function assumes that the LogFile journal has already been consistency
644 struct ntfs_volume *vol = log_ni->vol;
645 struct super_block *sb = vol->sb;
667 read_lock_irqsave(&log_ni->size_lock, flags);
668 end_vcn = (log_ni->initialized_size + vol->cluster_size_mask) >>
669 vol->cluster_size_bits;
670 read_unlock_irqrestore(&log_ni->size_lock, flags);
671 truncate_inode_pages(log_vi->i_mapping, 0);
672 down_write(&log_ni->runlist.lock);
673 rl = log_ni->runlist.rl;
674 if (unlikely(!rl || vcn < rl->vcn || !rl->length)) {
678 ntfs_error(sb, "Failed to map runlist fragment (error %d).", -err);
681 rl = log_ni->runlist.rl;
684 while (rl->length && vcn >= rl[1].vcn)
687 err = -ENOMEM;
688 empty_buf = kvzalloc(vol->cluster_size, GFP_NOFS);
692 memset(empty_buf, 0xff, vol->cluster_size);
698 file_ra_state_init(ra, sb->s_bdev->bd_mapping);
708 lcn = rl->lcn;
710 vcn = rl->vcn;
718 if (unlikely(!rl->length || lcn < LCN_HOLE))
724 len = rl->length;
726 len = end_vcn - rl->vcn;
729 page_cache_sync_readahead(sb->s_bdev->bd_mapping, ra, NULL,
730 start >> PAGE_SHIFT, (end - start) >> PAGE_SHIFT);
734 vol->cluster_size);
749 err = filemap_write_and_wait_range(sb->s_bdev->bd_mapping,
750 start, start + vol->cluster_size);
754 start += vol->cluster_size;
756 } while ((++rl)->vcn < end_vcn);
757 up_write(&log_ni->runlist.lock);
760 truncate_inode_pages(log_vi->i_mapping, 0);
772 err = -EIO;
776 up_write(&log_ni->runlist.lock);
778 -err);