Lines Matching full:log
18 * LOG FILE structs
29 __le32 sys_page_size; // 0x10: Page size of the system which initialized the log.
30 __le32 page_size; // 0x14: Log page size used for this log file.
53 /* Two copies of these will exist at the beginning of the log file */
55 __le64 current_lsn; // 0x00: Current logical end of log file.
62 __le64 l_size; // 0x18: Usable log file size.
64 __le16 rec_hdr_len; // 0x24: Log page data offset.
65 __le16 data_off; // 0x26: Log page data length.
193 __le32 undo_records; // 0x20: Number of undo log records pending abort
232 /* The following type defines the different log record types. */
236 /* This is used to uniquely identify a client for a particular log file. */
242 /* This is the header that begins every Log Record in the log file. */
248 struct CLIENT_ID client; // 0x1C: Owner of this log record.
262 __le64 last_end_lsn; // 0x08: lsn for the last log record which ends on the page,
279 // Page contains the end of a log record.
290 * END of NTFS LOG structures
341 * Array for log records which require a target attribute.
387 /* Log record length. */
396 struct LFS_RECORD_HDR *lrh; // Log record header of the current lsn.
511 /* Make sure the sequence number bits match the log file size. */ in is_rst_area_valid()
523 /* The log page data offset and record header length must be quad-aligned. */ in is_rst_area_valid()
1079 static inline u32 lsn_to_vbo(struct ntfs_log *log, const u64 lsn) in lsn_to_vbo() argument
1081 u32 vbo = (lsn << log->seq_num_bits) >> (log->seq_num_bits - 3); in lsn_to_vbo()
1086 /* Compute the offset in the log file of the next log page. */
1087 static inline u32 next_page_off(struct ntfs_log *log, u32 off) in next_page_off() argument
1089 off = (off & ~log->sys_page_mask) + log->page_size; in next_page_off()
1090 return off >= log->l_size ? log->first_page : off; in next_page_off()
1093 static inline u32 lsn_to_page_off(struct ntfs_log *log, u64 lsn) in lsn_to_page_off() argument
1095 return (((u32)lsn) << 3) & log->page_mask; in lsn_to_page_off()
1098 static inline u64 vbo_to_lsn(struct ntfs_log *log, u32 off, u64 Seq) in vbo_to_lsn() argument
1100 return (off >> 3) + (Seq << log->file_data_bits); in vbo_to_lsn()
1103 static inline bool is_lsn_in_file(struct ntfs_log *log, u64 lsn) in is_lsn_in_file() argument
1105 return lsn >= log->oldest_lsn && in is_lsn_in_file()
1106 lsn <= le64_to_cpu(log->ra->current_lsn); in is_lsn_in_file()
1109 static inline u32 hdr_file_off(struct ntfs_log *log, in hdr_file_off() argument
1112 if (log->major_ver < 2) in hdr_file_off()
1118 static inline u64 base_lsn(struct ntfs_log *log, in base_lsn() argument
1122 u64 ret = (((h_lsn >> log->file_data_bits) + in base_lsn()
1123 (lsn < (lsn_to_vbo(log, h_lsn) & ~log->page_mask) ? 1 : 0)) in base_lsn()
1124 << log->file_data_bits) + in base_lsn()
1128 log->page_size) + in base_lsn()
1135 static inline bool verify_client_lsn(struct ntfs_log *log, in verify_client_lsn() argument
1139 lsn <= le64_to_cpu(log->ra->current_lsn) && lsn; in verify_client_lsn()
1142 static int read_log_page(struct ntfs_log *log, u32 vbo, in read_log_page() argument
1146 u32 page_idx = vbo >> log->page_bits; in read_log_page()
1147 u32 page_off = vbo & log->page_mask; in read_log_page()
1148 u32 bytes = log->page_size - page_off; in read_log_page()
1150 u32 page_vbo = page_idx << log->page_bits; in read_log_page()
1152 struct ntfs_inode *ni = log->ni; in read_log_page()
1155 if (vbo >= log->l_size) in read_log_page()
1159 to_free = kmalloc(log->page_size, GFP_NOFS); in read_log_page()
1165 page_buf = page_off ? log->one_page_buf : *buffer; in read_log_page()
1168 log->page_size, NULL); in read_log_page()
1203 static int log_read_rst(struct ntfs_log *log, bool first, in log_read_rst() argument
1220 for (; vbo < log->l_size; vbo = 2 * vbo + skip, skip = 0) { in log_read_rst()
1226 if (read_log_page(log, vbo, (struct RECORD_PAGE_HDR **)&r_page, in log_read_rst()
1232 /* Exit if the signature is a log record page. */ in log_read_rst()
1311 * Ilog_init_pg_hdr - Init @log from restart page header.
1313 static void log_init_pg_hdr(struct ntfs_log *log, u16 major_ver, u16 minor_ver) in log_init_pg_hdr() argument
1315 log->sys_page_size = log->page_size; in log_init_pg_hdr()
1316 log->sys_page_mask = log->page_mask; in log_init_pg_hdr()
1318 log->clst_per_page = log->page_size >> log->ni->mi.sbi->cluster_bits; in log_init_pg_hdr()
1319 if (!log->clst_per_page) in log_init_pg_hdr()
1320 log->clst_per_page = 1; in log_init_pg_hdr()
1322 log->first_page = major_ver >= 2 ? 0x22 * log->page_size : in log_init_pg_hdr()
1323 4 * log->page_size; in log_init_pg_hdr()
1324 log->major_ver = major_ver; in log_init_pg_hdr()
1325 log->minor_ver = minor_ver; in log_init_pg_hdr()
1329 * log_create - Init @log in cases when we don't have a restart area to use.
1331 static void log_create(struct ntfs_log *log, const u64 last_lsn, in log_create() argument
1335 log->file_data_bits = blksize_bits(log->l_size) - 3; in log_create()
1336 log->seq_num_mask = (8 << log->file_data_bits) - 1; in log_create()
1337 log->seq_num_bits = sizeof(u64) * 8 - log->file_data_bits; in log_create()
1338 log->seq_num = (last_lsn >> log->file_data_bits) + 2; in log_create()
1339 log->next_page = log->first_page; in log_create()
1340 log->oldest_lsn = log->seq_num << log->file_data_bits; in log_create()
1341 log->oldest_lsn_off = 0; in log_create()
1342 log->last_lsn = log->oldest_lsn; in log_create()
1344 log->l_flags |= NTFSLOG_NO_LAST_LSN | NTFSLOG_NO_OLDEST_LSN; in log_create()
1348 log->l_flags |= NTFSLOG_WRAPPED; in log_create()
1351 log->l_flags |= NTFSLOG_MULTIPLE_PAGE_IO; in log_create()
1353 /* Compute the log page values. */ in log_create()
1354 log->data_off = ALIGN( in log_create()
1356 sizeof(short) * ((log->page_size >> SECTOR_SHIFT) + 1), in log_create()
1358 log->data_size = log->page_size - log->data_off; in log_create()
1359 log->record_header_len = sizeof(struct LFS_RECORD_HDR); in log_create()
1362 log->reserved = log->data_size - log->record_header_len; in log_create()
1365 log->ra_off = ALIGN( in log_create()
1368 ((log->sys_page_size >> SECTOR_SHIFT) + 1), in log_create()
1370 log->restart_size = log->sys_page_size - log->ra_off; in log_create()
1371 log->ra_size = struct_size(log->ra, clients, 1); in log_create()
1372 log->current_openlog_count = open_log_count; in log_create()
1375 * The total available log file space is the number of in log_create()
1376 * log file pages times the space available on each page. in log_create()
1378 log->total_avail_pages = log->l_size - log->first_page; in log_create()
1379 log->total_avail = log->total_avail_pages >> log->page_bits; in log_create()
1386 log->max_current_avail = log->total_avail * log->reserved; in log_create()
1387 log->total_avail = log->total_avail * log->data_size; in log_create()
1388 log->current_avail = log->max_current_avail; in log_create()
1392 * log_create_ra - Fill a restart area from the values stored in @log.
1394 static struct RESTART_AREA *log_create_ra(struct ntfs_log *log) in log_create_ra() argument
1397 struct RESTART_AREA *ra = kzalloc(log->restart_size, GFP_NOFS); in log_create_ra()
1402 ra->current_lsn = cpu_to_le64(log->last_lsn); in log_create_ra()
1405 if (log->l_flags & NTFSLOG_MULTIPLE_PAGE_IO) in log_create_ra()
1407 ra->seq_num_bits = cpu_to_le32(log->seq_num_bits); in log_create_ra()
1408 ra->ra_len = cpu_to_le16(log->ra_size); in log_create_ra()
1410 ra->l_size = cpu_to_le64(log->l_size); in log_create_ra()
1411 ra->rec_hdr_len = cpu_to_le16(log->record_header_len); in log_create_ra()
1412 ra->data_off = cpu_to_le16(log->data_off); in log_create_ra()
1413 ra->open_log_count = cpu_to_le32(log->current_openlog_count + 1); in log_create_ra()
1423 static u32 final_log_off(struct ntfs_log *log, u64 lsn, u32 data_len) in final_log_off() argument
1426 u32 final_log_off = (base_vbo & log->seq_num_mask) & ~log->page_mask; in final_log_off()
1427 u32 page_off = base_vbo & log->page_mask; in final_log_off()
1428 u32 tail = log->page_size - page_off; in final_log_off()
1433 data_len += log->record_header_len; in final_log_off()
1436 * If this lsn is contained this log page we are done. in final_log_off()
1437 * Otherwise we need to walk through several log pages. in final_log_off()
1441 tail = log->data_size; in final_log_off()
1442 page_off = log->data_off - 1; in final_log_off()
1445 final_log_off = next_page_off(log, final_log_off); in final_log_off()
1459 * and then add that value to the file offset of this log page. in final_log_off()
1464 static int next_log_lsn(struct ntfs_log *log, const struct LFS_RECORD_HDR *rh, in next_log_lsn() argument
1469 u32 vbo = lsn_to_vbo(log, this_lsn); in next_log_lsn()
1471 final_log_off(log, this_lsn, le32_to_cpu(rh->client_data_len)); in next_log_lsn()
1472 u32 hdr_off = end & ~log->sys_page_mask; in next_log_lsn()
1473 u64 seq = this_lsn >> log->file_data_bits; in next_log_lsn()
1480 /* Log page header for this page. */ in next_log_lsn()
1481 err = read_log_page(log, hdr_off, &page, NULL); in next_log_lsn()
1493 hdr_off = next_page_off(log, hdr_off); in next_log_lsn()
1494 if (hdr_off == log->first_page) in next_log_lsn()
1497 vbo = hdr_off + log->data_off; in next_log_lsn()
1503 *lsn = vbo_to_lsn(log, vbo, seq); in next_log_lsn()
1509 if (!is_lsn_in_file(log, *lsn)) in next_log_lsn()
1518 * current_log_avail - Calculate the number of bytes available for log records.
1520 static u32 current_log_avail(struct ntfs_log *log) in current_log_avail() argument
1524 if (log->l_flags & NTFSLOG_NO_LAST_LSN) { in current_log_avail()
1526 return log->max_current_avail; in current_log_avail()
1534 oldest_off = (log->l_flags & NTFSLOG_NO_OLDEST_LSN) ? in current_log_avail()
1535 log->first_page : in current_log_avail()
1536 (log->oldest_lsn_off & ~log->sys_page_mask); in current_log_avail()
1539 * We will use the next log page offset to compute the next free page. in current_log_avail()
1543 next_free_off = (log->l_flags & NTFSLOG_REUSE_TAIL) ? in current_log_avail()
1544 log->next_page + log->page_size : in current_log_avail()
1545 log->next_page == log->first_page ? log->l_size : in current_log_avail()
1546 log->next_page; in current_log_avail()
1557 log->total_avail_pages - (next_free_off - oldest_off) : in current_log_avail()
1560 free_bytes >>= log->page_bits; in current_log_avail()
1561 return free_bytes * log->reserved; in current_log_avail()
1564 static bool check_subseq_log_page(struct ntfs_log *log, in check_subseq_log_page() argument
1579 lsn_seq = lsn >> log->file_data_bits; in check_subseq_log_page()
1586 (lsn_seq == seq - 1 && log->first_page == vbo && in check_subseq_log_page()
1587 vbo != (lsn_to_vbo(log, lsn) & ~log->page_mask)); in check_subseq_log_page()
1593 * Walks through the log pages for a file, searching for the
1594 * last log page written to the file.
1596 static int last_log_lsn(struct ntfs_log *log) in last_log_lsn() argument
1601 bool reuse_page = log->l_flags & NTFSLOG_REUSE_TAIL; in last_log_lsn()
1615 u64 last_ok_lsn = reuse_page ? log->last_lsn : 0; in last_log_lsn()
1629 if (log->major_ver >= 2) { in last_log_lsn()
1630 final_off = 0x02 * log->page_size; in last_log_lsn()
1631 second_off = 0x12 * log->page_size; in last_log_lsn()
1634 page_bufs = kmalloc(log->page_size * 0x10, GFP_NOFS); in last_log_lsn()
1638 second_off = log->first_page - log->page_size; in last_log_lsn()
1639 final_off = second_off - log->page_size; in last_log_lsn()
1644 if (read_log_page(log, second_off, &second_tail, &usa_error) || in last_log_lsn()
1651 second_file_off = hdr_file_off(log, second_tail); in last_log_lsn()
1656 if (read_log_page(log, final_off, &first_tail, &usa_error) || in last_log_lsn()
1663 first_file_off = hdr_file_off(log, first_tail); in last_log_lsn()
1667 if (log->major_ver < 2) { in last_log_lsn()
1687 seq_base = (best_page ? lsn2 : lsn1) >> log->file_data_bits; in last_log_lsn()
1691 best_lsn1 = first_tail ? base_lsn(log, first_tail, first_file_off) : 0; in last_log_lsn()
1692 best_lsn2 = second_tail ? base_lsn(log, second_tail, second_file_off) : in last_log_lsn()
1721 seq_base = best_lsn >> log->file_data_bits; in last_log_lsn()
1725 memmove(page_bufs, best_page, log->page_size); in last_log_lsn()
1733 } else if (seq_base == (best_lsn >> log->file_data_bits) && in last_log_lsn()
1734 saved_off + log->page_size == this_off && in last_log_lsn()
1741 saved_off += log->page_size; in last_log_lsn()
1744 memmove(Add2Ptr(page_bufs, tails * log->page_size), best_page, in last_log_lsn()
1745 log->page_size); in last_log_lsn()
1774 final_off += log->page_size; in last_log_lsn()
1775 second_off += log->page_size; in last_log_lsn()
1788 curpage_off = seq_base == log->seq_num ? min(log->next_page, page_off) : in last_log_lsn()
1789 log->next_page; in last_log_lsn()
1792 curpage_off == log->first_page && in last_log_lsn()
1793 !(log->l_flags & (NTFSLOG_NO_LAST_LSN | NTFSLOG_REUSE_TAIL)); in last_log_lsn()
1795 expected_seq = wrapped_file ? (log->seq_num + 1) : log->seq_num; in last_log_lsn()
1801 /* Read the next log page. */ in last_log_lsn()
1802 err = read_log_page(log, curpage_off, &page, &usa_error); in last_log_lsn()
1804 /* Compute the next log page offset the file. */ in last_log_lsn()
1805 nextpage_off = next_page_off(log, curpage_off); in last_log_lsn()
1806 wrapped = nextpage_off == log->first_page; in last_log_lsn()
1845 ((lsn_cur >> log->file_data_bits) + in last_log_lsn()
1847 (lsn_to_vbo(log, lsn_cur) & ~log->page_mask)) ? in last_log_lsn()
1859 log->seq_num = expected_seq; in last_log_lsn()
1860 log->l_flags &= ~NTFSLOG_NO_LAST_LSN; in last_log_lsn()
1861 log->last_lsn = le64_to_cpu(cur_page->record_hdr.last_end_lsn); in last_log_lsn()
1862 log->ra->current_lsn = cur_page->record_hdr.last_end_lsn; in last_log_lsn()
1864 if (log->record_header_len <= in last_log_lsn()
1865 log->page_size - in last_log_lsn()
1867 log->l_flags |= NTFSLOG_REUSE_TAIL; in last_log_lsn()
1868 log->next_page = curpage_off; in last_log_lsn()
1870 log->l_flags &= ~NTFSLOG_REUSE_TAIL; in last_log_lsn()
1871 log->next_page = nextpage_off; in last_log_lsn()
1875 log->l_flags |= NTFSLOG_WRAPPED; in last_log_lsn()
1920 if (expected_seq != (lsn_cur >> log->file_data_bits)) in last_log_lsn()
1944 expected_seq != (lsn_cur >> log->file_data_bits)) { in last_log_lsn()
1993 log->seq_num = expected_seq; in last_log_lsn()
1994 log->last_lsn = le64_to_cpu(page->record_hdr.last_end_lsn); in last_log_lsn()
1995 log->ra->current_lsn = page->record_hdr.last_end_lsn; in last_log_lsn()
1996 log->l_flags &= ~NTFSLOG_NO_LAST_LSN; in last_log_lsn()
2002 if (log->record_header_len <= in last_log_lsn()
2003 log->page_size - in last_log_lsn()
2005 log->l_flags |= NTFSLOG_REUSE_TAIL; in last_log_lsn()
2006 log->next_page = curpage_off; in last_log_lsn()
2008 log->l_flags &= ~NTFSLOG_REUSE_TAIL; in last_log_lsn()
2009 log->next_page = nextpage_off; in last_log_lsn()
2012 /* Remember if we wrapped the log file. */ in last_log_lsn()
2014 log->l_flags |= NTFSLOG_WRAPPED; in last_log_lsn()
2040 log->seq_num = expected_seq; in last_log_lsn()
2041 log->last_lsn = le64_to_cpu(tail_page->record_hdr.last_end_lsn); in last_log_lsn()
2042 log->ra->current_lsn = tail_page->record_hdr.last_end_lsn; in last_log_lsn()
2043 log->l_flags &= ~NTFSLOG_NO_LAST_LSN; in last_log_lsn()
2045 if (log->page_size - in last_log_lsn()
2048 log->record_header_len) { in last_log_lsn()
2049 log->l_flags |= NTFSLOG_REUSE_TAIL; in last_log_lsn()
2050 log->next_page = curpage_off; in last_log_lsn()
2052 log->l_flags &= ~NTFSLOG_REUSE_TAIL; in last_log_lsn()
2053 log->next_page = nextpage_off; in last_log_lsn()
2057 log->l_flags |= NTFSLOG_WRAPPED; in last_log_lsn()
2065 * the sequence number for log records which begon the next page. in last_log_lsn()
2074 if (replace_page || (log->ra->flags & RESTART_SINGLE_PAGE_IO)) { in last_log_lsn()
2083 * If the next page causes us to wrap to the beginning of the log in last_log_lsn()
2098 /* Walk through the file, reading log pages. */ in last_log_lsn()
2099 err = read_log_page(log, nextpage_off, &tst_page, &usa_error); in last_log_lsn()
2116 check_subseq_log_page(log, tst_page, nextpage_off, expected_seq)) { in last_log_lsn()
2126 nextpage_off = next_page_off(log, curpage_off); in last_log_lsn()
2127 wrapped = nextpage_off == log->first_page; in last_log_lsn()
2146 nextpage_off = next_page_off(log, curpage_off); in last_log_lsn()
2147 wrapped = nextpage_off == log->first_page; in last_log_lsn()
2153 /* Call our routine to check this log page. */ in last_log_lsn()
2157 err = read_log_page(log, nextpage_off, &tst_page, &usa_error); in last_log_lsn()
2159 check_subseq_log_page(log, tst_page, nextpage_off, expected_seq)) { in last_log_lsn()
2170 if (sb_rdonly(log->ni->mi.sbi->sb)) { in last_log_lsn()
2177 tails -= (page_off1 - page_off) / log->page_size; in last_log_lsn()
2186 u64 off = hdr_file_off(log, tmp_page); in last_log_lsn()
2189 page = kmalloc(log->page_size, GFP_NOFS); in last_log_lsn()
2200 memcpy(page, tmp_page, log->page_size); in last_log_lsn()
2203 if (log->major_ver < 2) in last_log_lsn()
2210 ntfs_fix_pre_write(&page->rhdr, log->page_size); in last_log_lsn()
2212 err = ntfs_sb_write_run(log->ni->mi.sbi, in last_log_lsn()
2213 &log->ni->file.run, off, page, in last_log_lsn()
2214 log->page_size, 0); in last_log_lsn()
2220 second_off += log->page_size; in last_log_lsn()
2224 tmp_page = Add2Ptr(tmp_page, log->page_size); in last_log_lsn()
2229 if (sb_rdonly(log->ni->mi.sbi->sb)) { in last_log_lsn()
2246 * read_log_rec_buf - Copy a log record from the file to a buffer.
2248 * The log record may span several log pages and may even wrap the file.
2250 static int read_log_rec_buf(struct ntfs_log *log, in read_log_rec_buf() argument
2256 u32 vbo = lsn_to_vbo(log, lsn) & ~log->page_mask; in read_log_rec_buf()
2257 u32 off = lsn_to_page_off(log, lsn) + log->record_header_len; in read_log_rec_buf()
2266 u32 tail = log->page_size - off; in read_log_rec_buf()
2273 err = read_log_page(log, vbo, &ph, &usa_error); in read_log_rec_buf()
2304 vbo = next_page_off(log, vbo); in read_log_rec_buf()
2305 off = log->data_off; in read_log_rec_buf()
2319 static int read_rst_area(struct ntfs_log *log, struct NTFS_RESTART **rst_, in read_rst_area() argument
2325 Add2Ptr(log->ra, le16_to_cpu(log->ra->client_off)); in read_rst_area()
2337 err = read_log_page(log, lsn_to_vbo(log, lsnc), in read_rst_area()
2371 err = read_log_rec_buf(log, rh, rst); in read_rst_area()
2385 static int find_log_rec(struct ntfs_log *log, u64 lsn, struct lcb *lcb) in find_log_rec() argument
2393 err = read_log_page(log, lsn_to_vbo(log, lsn), in find_log_rec()
2402 * If the lsn the log record doesn't match the desired in find_log_rec()
2412 * available space the log file. in find_log_rec()
2414 rec_len = len + log->record_header_len; in find_log_rec()
2415 if (rec_len >= log->total_avail) in find_log_rec()
2419 * If the entire log record is on this log page, in find_log_rec()
2420 * put a pointer to the log record the context block. in find_log_rec()
2432 err = read_log_rec_buf(log, rh, lr); in find_log_rec()
2437 u32 page_off = lsn_to_page_off(log, lsn); in find_log_rec()
2439 if (page_off + len + log->record_header_len > log->page_size) in find_log_rec()
2452 static int read_log_rec_lcb(struct ntfs_log *log, u64 lsn, u32 ctx_mode, in read_log_rec_lcb() argument
2469 cr = Add2Ptr(log->ra, le16_to_cpu(log->ra->client_off)); in read_log_rec_lcb()
2471 if (!verify_client_lsn(log, cr, lsn)) in read_log_rec_lcb()
2477 lcb->client = log->client_id; in read_log_rec_lcb()
2480 /* Find the log record indicated by the given lsn. */ in read_log_rec_lcb()
2481 err = find_log_rec(log, lsn, lcb); in read_log_rec_lcb()
2499 static int find_client_next_lsn(struct ntfs_log *log, struct lcb *lcb, u64 *lsn) in find_client_next_lsn() argument
2515 err = next_log_lsn(log, hdr, ¤t_lsn); in find_client_next_lsn()
2526 err = read_log_page(log, lsn_to_vbo(log, current_lsn), in find_client_next_lsn()
2559 log, Add2Ptr(log->ra, le16_to_cpu(log->ra->client_off)), in find_client_next_lsn()
2564 err = read_log_page(log, lsn_to_vbo(log, next_lsn), in find_client_next_lsn()
2576 static int read_next_log_rec(struct ntfs_log *log, struct lcb *lcb, u64 *lsn) in read_next_log_rec() argument
2580 err = find_client_next_lsn(log, lcb, lsn); in read_next_log_rec()
2595 return find_log_rec(log, *lsn, lcb); in read_next_log_rec()
2968 static struct OpenAttr *find_loaded_attr(struct ntfs_log *log, in find_loaded_attr() argument
2973 while ((oe = enum_rstbl(log->open_attr_tbl, oe))) { in find_loaded_attr()
3035 static int do_action(struct ntfs_log *log, struct OPEN_ATTR_ENRTY *oe, in do_action() argument
3040 struct ntfs_sb_info *sbi = log->ni->mi.sbi; in do_action()
3073 * Process MFT records, as described by the current log record. in do_action()
3160 * Process attributes, as described by the current log record. in do_action()
3255 oa2 = find_loaded_attr(log, attr, rno_base); in do_action()
3322 oa2 = find_loaded_attr(log, attr, rno_base); in do_action()
3362 oa2 = find_loaded_attr(log, attr, rno_base); in do_action()
3381 oa2 = find_loaded_attr(log, attr, rno_base); in do_action()
3725 log->set_dirty = true; in do_action()
3730 * log_replay - Replays log and empties it.
3733 * It replays log and empties it.
3740 struct ntfs_log *log; in log_replay() local
3779 log = kzalloc(sizeof(struct ntfs_log), GFP_NOFS); in log_replay()
3780 if (!log) in log_replay()
3783 log->ni = ni; in log_replay()
3784 log->l_size = log->orig_file_size = ni->vfs_inode.i_size; in log_replay()
3788 log->page_size = norm_file_page(PAGE_SIZE, &log->l_size, true); in log_replay()
3790 log->page_size = norm_file_page(PAGE_SIZE, &log->l_size, false); in log_replay()
3792 if (!log->page_size) { in log_replay()
3797 log->one_page_buf = kmalloc(log->page_size, GFP_NOFS); in log_replay()
3798 if (!log->one_page_buf) { in log_replay()
3803 log->page_mask = log->page_size - 1; in log_replay()
3804 log->page_bits = blksize_bits(log->page_size); in log_replay()
3807 err = log_read_rst(log, true, &log->rst_info); in log_replay()
3812 *initialized = log->rst_info.initialized; in log_replay()
3814 if (!log->rst_info.restart) { in log_replay()
3815 if (log->rst_info.initialized) { in log_replay()
3821 log_init_pg_hdr(log, 1, 1); in log_replay()
3822 log_create(log, 0, get_random_u32(), false, false); in log_replay()
3824 ra = log_create_ra(log); in log_replay()
3829 log->ra = ra; in log_replay()
3830 log->init_ra = true; in log_replay()
3839 if (log->rst_info.vbo) in log_replay()
3842 err = log_read_rst(log, false, &log->rst_info2); in log_replay()
3847 if (!log->rst_info2.restart || in log_replay()
3848 log->rst_info2.last_lsn <= log->rst_info.last_lsn) in log_replay()
3853 if (log->rst_info.chkdsk_was_run && in log_replay()
3854 log->page_size != log->rst_info.vbo) { in log_replay()
3858 if (!read_log_page(log, log->page_size, &sp, &usa_error) && in log_replay()
3866 kfree(log->rst_info.r_page); in log_replay()
3867 memcpy(&log->rst_info, &log->rst_info2, in log_replay()
3869 log->rst_info2.r_page = NULL; in log_replay()
3873 kfree(log->rst_info2.r_page); in log_replay()
3880 log->init_ra = !!log->rst_info.vbo; in log_replay()
3883 ra2 = log->rst_info.valid_page ? in log_replay()
3884 Add2Ptr(log->rst_info.r_page, in log_replay()
3885 le16_to_cpu(log->rst_info.r_page->ra_off)) : in log_replay()
3888 if (log->rst_info.chkdsk_was_run || in log_replay()
3894 /* Do some checks based on whether we have a valid log page. */ in log_replay()
3895 open_log_count = log->rst_info.valid_page ? in log_replay()
3899 log_init_pg_hdr(log, 1, 1); in log_replay()
3901 log_create(log, log->rst_info.last_lsn, open_log_count, wrapped, in log_replay()
3904 ra = log_create_ra(log); in log_replay()
3909 log->ra = ra; in log_replay()
3912 * the log file as required. in log_replay()
3923 * If the log page or the system page sizes have changed, we can't in log_replay()
3924 * use the log file. We must use the system page size instead of the in log_replay()
3927 t32 = le32_to_cpu(log->rst_info.r_page->sys_page_size); in log_replay()
3928 if (log->page_size != t32) { in log_replay()
3929 log->l_size = log->orig_file_size; in log_replay()
3930 log->page_size = norm_file_page(t32, &log->l_size, in log_replay()
3934 if (log->page_size != t32 || in log_replay()
3935 log->page_size != le32_to_cpu(log->rst_info.r_page->page_size)) { in log_replay()
3940 log->page_mask = log->page_size - 1; in log_replay()
3941 log->page_bits = blksize_bits(log->page_size); in log_replay()
3944 if (log->l_size < le64_to_cpu(ra2->l_size)) { in log_replay()
3949 log_init_pg_hdr(log, le16_to_cpu(log->rst_info.r_page->major_ver), in log_replay()
3950 le16_to_cpu(log->rst_info.r_page->minor_ver)); in log_replay()
3952 log->l_size = le64_to_cpu(ra2->l_size); in log_replay()
3953 log->seq_num_bits = le32_to_cpu(ra2->seq_num_bits); in log_replay()
3954 log->file_data_bits = sizeof(u64) * 8 - log->seq_num_bits; in log_replay()
3955 log->seq_num_mask = (8 << log->file_data_bits) - 1; in log_replay()
3956 log->last_lsn = le64_to_cpu(ra2->current_lsn); in log_replay()
3957 log->seq_num = log->last_lsn >> log->file_data_bits; in log_replay()
3958 log->ra_off = le16_to_cpu(log->rst_info.r_page->ra_off); in log_replay()
3959 log->restart_size = log->sys_page_size - log->ra_off; in log_replay()
3960 log->record_header_len = le16_to_cpu(ra2->rec_hdr_len); in log_replay()
3961 log->ra_size = le16_to_cpu(ra2->ra_len); in log_replay()
3962 log->data_off = le16_to_cpu(ra2->data_off); in log_replay()
3963 log->data_size = log->page_size - log->data_off; in log_replay()
3964 log->reserved = log->data_size - log->record_header_len; in log_replay()
3966 vbo = lsn_to_vbo(log, log->last_lsn); in log_replay()
3968 if (vbo < log->first_page) { in log_replay()
3970 log->l_flags |= NTFSLOG_NO_LAST_LSN; in log_replay()
3971 log->next_page = log->first_page; in log_replay()
3975 /* Find the end of this log record. */ in log_replay()
3976 off = final_log_off(log, log->last_lsn, in log_replay()
3981 log->seq_num += 1; in log_replay()
3982 log->l_flags |= NTFSLOG_WRAPPED; in log_replay()
3985 /* Now compute the next log page to use. */ in log_replay()
3986 vbo &= ~log->sys_page_mask; in log_replay()
3987 tail = log->page_size - (off & log->page_mask) - 1; in log_replay()
3990 *If we can fit another log record on the page, in log_replay()
3991 * move back a page the log file. in log_replay()
3993 if (tail >= log->record_header_len) { in log_replay()
3994 log->l_flags |= NTFSLOG_REUSE_TAIL; in log_replay()
3995 log->next_page = vbo; in log_replay()
3997 log->next_page = next_page_off(log, vbo); in log_replay()
4005 log->oldest_lsn = log->last_lsn; in log_replay()
4007 ra2->client_idx[1], &log->oldest_lsn); in log_replay()
4008 log->oldest_lsn_off = lsn_to_vbo(log, log->oldest_lsn); in log_replay()
4010 if (log->oldest_lsn_off < log->first_page) in log_replay()
4011 log->l_flags |= NTFSLOG_NO_OLDEST_LSN; in log_replay()
4014 log->l_flags |= NTFSLOG_WRAPPED | NTFSLOG_MULTIPLE_PAGE_IO; in log_replay()
4016 log->current_openlog_count = le32_to_cpu(ra2->open_log_count); in log_replay()
4017 log->total_avail_pages = log->l_size - log->first_page; in log_replay()
4018 log->total_avail = log->total_avail_pages >> log->page_bits; in log_replay()
4019 log->max_current_avail = log->total_avail * log->reserved; in log_replay()
4020 log->total_avail = log->total_avail * log->data_size; in log_replay()
4022 log->current_avail = current_log_avail(log); in log_replay()
4024 ra = kzalloc(log->restart_size, GFP_NOFS); in log_replay()
4029 log->ra = ra; in log_replay()
4033 memcpy(ra, ra2, log->ra_size); in log_replay()
4039 log->current_openlog_count = get_random_u32(); in log_replay()
4040 ra->open_log_count = cpu_to_le32(log->current_openlog_count); in log_replay()
4041 log->ra_size = offsetof(struct RESTART_AREA, clients) + in log_replay()
4045 ra->ra_len = cpu_to_le16(log->ra_size); in log_replay()
4051 err = last_log_lsn(log); in log_replay()
4055 log->current_avail = current_log_avail(log); in log_replay()
4058 log->init_ra = log->rst_info.vbo; in log_replay()
4061 /* 1.0, 1.1, 2.0 log->major_ver/minor_ver - short values. */ in log_replay()
4062 switch ((log->major_ver << 16) + log->minor_ver) { in log_replay()
4069 log->major_ver, log->minor_ver); in log_replay()
4071 log->set_dirty = true; in log_replay()
4093 cr->oldest_lsn = cpu_to_le64(log->oldest_lsn); in log_replay()
4115 log->client_id.seq_num = cr->seq_num; in log_replay()
4116 log->client_id.client_idx = client; in log_replay()
4118 err = read_rst_area(log, &rst, &checkpt_lsn); in log_replay()
4135 err = read_log_rec_lcb(log, t64, lcb_ctx_prev, &lcb); in log_replay()
4175 err = read_log_rec_lcb(log, t64, lcb_ctx_prev, &lcb); in log_replay()
4227 if (sbi->cluster_size <= log->page_size) in log_replay()
4252 err = read_log_rec_lcb(log, t64, lcb_ctx_prev, &lcb); in log_replay()
4284 err = read_log_rec_lcb(log, t64, lcb_ctx_prev, &lcb); in log_replay()
4314 log->open_attr_tbl = oatbl; in log_replay()
4395 log->open_attr_tbl = oatbl; in log_replay()
4401 err = read_log_rec_lcb(log, checkpt_lsn, lcb_ctx_next, &lcb); in log_replay()
4405 /* Loop to read all subsequent records to the end of the log file. */ in log_replay()
4407 err = read_next_log_rec(log, lcb, &rec_lsn); in log_replay()
4463 * If this is a compensation log record, then change in log_replay()
4469 /* Dispatch to handle log record depending on type. */ in log_replay()
4510 t32 = log->clst_per_page; in log_replay()
4533 * Copy the Lcns from the log record into the Dirty Page Entry. in log_replay()
4552 /* Loop through all of the Lcn ranges this log record. */ in log_replay()
4584 log->open_attr_tbl = oatbl; in log_replay()
4593 log->open_attr_tbl = oatbl; in log_replay()
4599 /* Initialize this entry from the log record. */ in log_replay()
4882 err = read_log_rec_lcb(log, rlsn, lcb_ctx_next, &lcb); in log_replay()
4887 * Now loop to read all of our log records forwards, until in log_replay()
4905 /* Ignore log records that do not update pages. */ in log_replay()
4975 * log record Vcn, after removing this unallocated Vcn. in log_replay()
4980 * If the update described this log record goes beyond in log_replay()
4991 * we can skip this log record. in log_replay()
5001 err = do_action(log, oe, lrh, t16, data, dlen, rec_len, &rec_lsn); in log_replay()
5007 err = read_next_log_rec(log, lcb, &rec_lsn); in log_replay()
5027 log->transaction_id = PtrOffset(trtbl, tr); in log_replay()
5038 err = read_log_rec_lcb(log, undo_next_lsn, lcb_ctx_undo_next, &lcb); in log_replay()
5043 * Now loop to read all of our log records forwards, in log_replay()
5080 vcn &= ~(u64)(log->clst_per_page - 1); in log_replay()
5107 err = do_action(log, oe, lrh, t16, data, dlen, rec_len, NULL); in log_replay()
5114 err = read_next_log_rec(log, lcb, &rec_lsn); in log_replay()
5125 free_rsttbl_idx(trtbl, log->transaction_id); in log_replay()
5127 log->transaction_id = 0; in log_replay()
5143 rh = kzalloc(log->page_size, GFP_NOFS); in log_replay()
5151 t16 = (log->page_size >> SECTOR_SHIFT) + 1; in log_replay()
5153 rh->sys_page_size = cpu_to_le32(log->page_size); in log_replay()
5154 rh->page_size = cpu_to_le32(log->page_size); in log_replay()
5171 ntfs_fix_pre_write(&rh->rhdr, log->page_size); in log_replay()
5173 err = ntfs_sb_write_run(sbi, &ni->file.run, 0, rh, log->page_size, 0); in log_replay()
5175 err = ntfs_sb_write_run(sbi, &log->ni->file.run, log->page_size, in log_replay()
5176 rh, log->page_size, 0); in log_replay()
5219 kfree(log->rst_info.r_page); in log_replay()
5222 kfree(log->one_page_buf); in log_replay()
5229 else if (log->set_dirty) in log_replay()
5232 kfree(log); in log_replay()