fslog.c (fa3cacf544636b2dc48cfb2f277a2071f14d66a2) | fslog.c (195c52bdd5d5ecfdabf5a7c6159efe299e534f84) |
---|---|
1// SPDX-License-Identifier: GPL-2.0 2/* 3 * 4 * Copyright (C) 2019-2021 Paragon Software GmbH, All rights reserved. 5 * 6 */ 7 8#include <linux/blkdev.h> --- 392 unchanged lines hidden (view full) --- 401 u32 ctx_mode; // lcb_ctx_undo_next/lcb_ctx_prev/lcb_ctx_next 402 struct CLIENT_ID client; 403 bool alloc; // if true the we should deallocate 'log_rec' 404}; 405 406static void lcb_put(struct lcb *lcb) 407{ 408 if (lcb->alloc) | 1// SPDX-License-Identifier: GPL-2.0 2/* 3 * 4 * Copyright (C) 2019-2021 Paragon Software GmbH, All rights reserved. 5 * 6 */ 7 8#include <linux/blkdev.h> --- 392 unchanged lines hidden (view full) --- 401 u32 ctx_mode; // lcb_ctx_undo_next/lcb_ctx_prev/lcb_ctx_next 402 struct CLIENT_ID client; 403 bool alloc; // if true the we should deallocate 'log_rec' 404}; 405 406static void lcb_put(struct lcb *lcb) 407{ 408 if (lcb->alloc) |
409 ntfs_free(lcb->log_rec); 410 ntfs_free(lcb->lrh); 411 ntfs_free(lcb); | 409 kfree(lcb->log_rec); 410 kfree(lcb->lrh); 411 kfree(lcb); |
412} 413 414/* 415 * oldest_client_lsn 416 * 417 * find the oldest lsn from active clients. 418 */ 419static inline void oldest_client_lsn(const struct CLIENT_REC *ca, --- 382 unchanged lines hidden (view full) --- 802} 803 804static inline struct RESTART_TABLE *init_rsttbl(u16 esize, u16 used) 805{ 806 __le32 *e, *last_free; 807 u32 off; 808 u32 bytes = esize * used + sizeof(struct RESTART_TABLE); 809 u32 lf = sizeof(struct RESTART_TABLE) + (used - 1) * esize; | 412} 413 414/* 415 * oldest_client_lsn 416 * 417 * find the oldest lsn from active clients. 418 */ 419static inline void oldest_client_lsn(const struct CLIENT_REC *ca, --- 382 unchanged lines hidden (view full) --- 802} 803 804static inline struct RESTART_TABLE *init_rsttbl(u16 esize, u16 used) 805{ 806 __le32 *e, *last_free; 807 u32 off; 808 u32 bytes = esize * used + sizeof(struct RESTART_TABLE); 809 u32 lf = sizeof(struct RESTART_TABLE) + (used - 1) * esize; |
810 struct RESTART_TABLE *t = ntfs_zalloc(bytes); | 810 struct RESTART_TABLE *t = kzalloc(bytes, GFP_NOFS); |
811 812 t->size = cpu_to_le16(esize); 813 t->used = cpu_to_le16(used); 814 t->free_goal = cpu_to_le32(~0u); 815 t->first_free = cpu_to_le32(sizeof(struct RESTART_TABLE)); 816 t->last_free = cpu_to_le32(lf); 817 818 e = (__le32 *)(t + 1); --- 25 unchanged lines hidden (view full) --- 844 rt->first_free = tbl->first_free; 845 *(__le32 *)Add2Ptr(rt, le32_to_cpu(tbl->last_free)) = osize; 846 } else { 847 rt->first_free = osize; 848 } 849 850 rt->total = tbl->total; 851 | 811 812 t->size = cpu_to_le16(esize); 813 t->used = cpu_to_le16(used); 814 t->free_goal = cpu_to_le32(~0u); 815 t->first_free = cpu_to_le32(sizeof(struct RESTART_TABLE)); 816 t->last_free = cpu_to_le32(lf); 817 818 e = (__le32 *)(t + 1); --- 25 unchanged lines hidden (view full) --- 844 rt->first_free = tbl->first_free; 845 *(__le32 *)Add2Ptr(rt, le32_to_cpu(tbl->last_free)) = osize; 846 } else { 847 rt->first_free = osize; 848 } 849 850 rt->total = tbl->total; 851 |
852 ntfs_free(tbl); | 852 kfree(tbl); |
853 return rt; 854} 855 856/* 857 * alloc_rsttbl_idx 858 * 859 * allocates an index from within a previously initialized Restart Table 860 */ --- 268 unchanged lines hidden (view full) --- 1129 struct RECORD_PAGE_HDR *page_buf; 1130 struct ntfs_inode *ni = log->ni; 1131 bool bBAAD; 1132 1133 if (vbo >= log->l_size) 1134 return -EINVAL; 1135 1136 if (!*buffer) { | 853 return rt; 854} 855 856/* 857 * alloc_rsttbl_idx 858 * 859 * allocates an index from within a previously initialized Restart Table 860 */ --- 268 unchanged lines hidden (view full) --- 1129 struct RECORD_PAGE_HDR *page_buf; 1130 struct ntfs_inode *ni = log->ni; 1131 bool bBAAD; 1132 1133 if (vbo >= log->l_size) 1134 return -EINVAL; 1135 1136 if (!*buffer) { |
1137 to_free = ntfs_malloc(bytes); | 1137 to_free = kmalloc(bytes, GFP_NOFS); |
1138 if (!to_free) 1139 return -ENOMEM; 1140 *buffer = to_free; 1141 } 1142 1143 page_buf = page_off ? log->one_page_buf : *buffer; 1144 1145 err = ntfs_read_run_nb(ni->mi.sbi, &ni->file.run, page_vbo, page_buf, --- 13 unchanged lines hidden (view full) --- 1159 *usa_error = bBAAD; 1160 /* Check that the update sequence array for this page is valid */ 1161 /* If we don't allow errors, raise an error status */ 1162 else if (bBAAD) 1163 err = -EINVAL; 1164 1165out: 1166 if (err && to_free) { | 1138 if (!to_free) 1139 return -ENOMEM; 1140 *buffer = to_free; 1141 } 1142 1143 page_buf = page_off ? log->one_page_buf : *buffer; 1144 1145 err = ntfs_read_run_nb(ni->mi.sbi, &ni->file.run, page_vbo, page_buf, --- 13 unchanged lines hidden (view full) --- 1159 *usa_error = bBAAD; 1160 /* Check that the update sequence array for this page is valid */ 1161 /* If we don't allow errors, raise an error status */ 1162 else if (bBAAD) 1163 err = -EINVAL; 1164 1165out: 1166 if (err && to_free) { |
1167 ntfs_free(to_free); | 1167 kfree(to_free); |
1168 *buffer = NULL; 1169 } 1170 1171 return err; 1172} 1173 1174/* 1175 * log_read_rst 1176 * 1177 * it walks through 512 blocks of the file looking for a valid restart page header 1178 * It will stop the first time we find a valid page header 1179 */ 1180static int log_read_rst(struct ntfs_log *log, u32 l_size, bool first, 1181 struct restart_info *info) 1182{ 1183 u32 skip, vbo; | 1168 *buffer = NULL; 1169 } 1170 1171 return err; 1172} 1173 1174/* 1175 * log_read_rst 1176 * 1177 * it walks through 512 blocks of the file looking for a valid restart page header 1178 * It will stop the first time we find a valid page header 1179 */ 1180static int log_read_rst(struct ntfs_log *log, u32 l_size, bool first, 1181 struct restart_info *info) 1182{ 1183 u32 skip, vbo; |
1184 struct RESTART_HDR *r_page = ntfs_malloc(DefaultLogPageSize); | 1184 struct RESTART_HDR *r_page = kmalloc(DefaultLogPageSize, GFP_NOFS); |
1185 1186 if (!r_page) 1187 return -ENOMEM; 1188 1189 memset(info, 0, sizeof(struct restart_info)); 1190 1191 /* Determine which restart area we are looking for */ 1192 if (first) { --- 59 unchanged lines hidden (view full) --- 1252 if (bchk || ra->client_idx[1] == LFS_NO_CLIENT_LE) { 1253 info->valid_page = true; 1254 goto check_result; 1255 } 1256 1257 /* Read the entire restart area */ 1258 sys_page_size = le32_to_cpu(r_page->sys_page_size); 1259 if (DefaultLogPageSize != sys_page_size) { | 1185 1186 if (!r_page) 1187 return -ENOMEM; 1188 1189 memset(info, 0, sizeof(struct restart_info)); 1190 1191 /* Determine which restart area we are looking for */ 1192 if (first) { --- 59 unchanged lines hidden (view full) --- 1252 if (bchk || ra->client_idx[1] == LFS_NO_CLIENT_LE) { 1253 info->valid_page = true; 1254 goto check_result; 1255 } 1256 1257 /* Read the entire restart area */ 1258 sys_page_size = le32_to_cpu(r_page->sys_page_size); 1259 if (DefaultLogPageSize != sys_page_size) { |
1260 ntfs_free(r_page); 1261 r_page = ntfs_zalloc(sys_page_size); | 1260 kfree(r_page); 1261 r_page = kzalloc(sys_page_size, GFP_NOFS); |
1262 if (!r_page) 1263 return -ENOMEM; 1264 1265 if (read_log_page(log, vbo, 1266 (struct RECORD_PAGE_HDR **)&r_page, 1267 &usa_error)) { 1268 /* ignore any errors */ | 1262 if (!r_page) 1263 return -ENOMEM; 1264 1265 if (read_log_page(log, vbo, 1266 (struct RECORD_PAGE_HDR **)&r_page, 1267 &usa_error)) { 1268 /* ignore any errors */ |
1269 ntfs_free(r_page); | 1269 kfree(r_page); |
1270 r_page = NULL; 1271 continue; 1272 } 1273 } 1274 1275 if (is_client_area_valid(r_page, usa_error)) { 1276 info->valid_page = true; 1277 ra = Add2Ptr(r_page, le16_to_cpu(r_page->ra_off)); --- 13 unchanged lines hidden (view full) --- 1291 if (info->valid_page) { 1292 info->last_lsn = le64_to_cpu(ra->current_lsn); 1293 info->restart = true; 1294 info->r_page = r_page; 1295 return 0; 1296 } 1297 } 1298 | 1270 r_page = NULL; 1271 continue; 1272 } 1273 } 1274 1275 if (is_client_area_valid(r_page, usa_error)) { 1276 info->valid_page = true; 1277 ra = Add2Ptr(r_page, le16_to_cpu(r_page->ra_off)); --- 13 unchanged lines hidden (view full) --- 1291 if (info->valid_page) { 1292 info->last_lsn = le64_to_cpu(ra->current_lsn); 1293 info->restart = true; 1294 info->r_page = r_page; 1295 return 0; 1296 } 1297 } 1298 |
1299 ntfs_free(r_page); | 1299 kfree(r_page); |
1300 1301 return 0; 1302} 1303 1304/* 1305 * log_init_pg_hdr 1306 * 1307 * init "log' from restart page header --- 84 unchanged lines hidden (view full) --- 1392/* 1393 * log_create_ra 1394 * 1395 * This routine is called to fill a restart area from the values stored in 'log' 1396 */ 1397static struct RESTART_AREA *log_create_ra(struct ntfs_log *log) 1398{ 1399 struct CLIENT_REC *cr; | 1300 1301 return 0; 1302} 1303 1304/* 1305 * log_init_pg_hdr 1306 * 1307 * init "log' from restart page header --- 84 unchanged lines hidden (view full) --- 1392/* 1393 * log_create_ra 1394 * 1395 * This routine is called to fill a restart area from the values stored in 'log' 1396 */ 1397static struct RESTART_AREA *log_create_ra(struct ntfs_log *log) 1398{ 1399 struct CLIENT_REC *cr; |
1400 struct RESTART_AREA *ra = ntfs_zalloc(log->restart_size); | 1400 struct RESTART_AREA *ra = kzalloc(log->restart_size, GFP_NOFS); |
1401 1402 if (!ra) 1403 return NULL; 1404 1405 ra->current_lsn = cpu_to_le64(log->last_lsn); 1406 ra->log_clients = cpu_to_le16(1); 1407 ra->client_idx[1] = LFS_NO_CLIENT_LE; 1408 if (log->l_flags & NTFSLOG_MULTIPLE_PAGE_IO) --- 95 unchanged lines hidden (view full) --- 1504 1505 /* 1506 * If this lsn is within the legal range for the file, we return true 1507 * Otherwise false indicates that there are no more lsn's 1508 */ 1509 if (!is_lsn_in_file(log, *lsn)) 1510 *lsn = 0; 1511 | 1401 1402 if (!ra) 1403 return NULL; 1404 1405 ra->current_lsn = cpu_to_le64(log->last_lsn); 1406 ra->log_clients = cpu_to_le16(1); 1407 ra->client_idx[1] = LFS_NO_CLIENT_LE; 1408 if (log->l_flags & NTFSLOG_MULTIPLE_PAGE_IO) --- 95 unchanged lines hidden (view full) --- 1504 1505 /* 1506 * If this lsn is within the legal range for the file, we return true 1507 * Otherwise false indicates that there are no more lsn's 1508 */ 1509 if (!is_lsn_in_file(log, *lsn)) 1510 *lsn = 0; 1511 |
1512 ntfs_free(page); | 1512 kfree(page); |
1513 1514 return 0; 1515} 1516 1517/* 1518 * current_log_avail 1519 * 1520 * calculate the number of bytes available for log records --- 108 unchanged lines hidden (view full) --- 1629 struct RECORD_PAGE_HDR *page_bufs = NULL; 1630 struct RECORD_PAGE_HDR *best_page; 1631 1632 if (log->major_ver >= 2) { 1633 final_off = 0x02 * log->page_size; 1634 second_off = 0x12 * log->page_size; 1635 1636 // 0x10 == 0x12 - 0x2 | 1513 1514 return 0; 1515} 1516 1517/* 1518 * current_log_avail 1519 * 1520 * calculate the number of bytes available for log records --- 108 unchanged lines hidden (view full) --- 1629 struct RECORD_PAGE_HDR *page_bufs = NULL; 1630 struct RECORD_PAGE_HDR *best_page; 1631 1632 if (log->major_ver >= 2) { 1633 final_off = 0x02 * log->page_size; 1634 second_off = 0x12 * log->page_size; 1635 1636 // 0x10 == 0x12 - 0x2 |
1637 page_bufs = ntfs_malloc(log->page_size * 0x10); | 1637 page_bufs = kmalloc(log->page_size * 0x10, GFP_NOFS); |
1638 if (!page_bufs) 1639 return -ENOMEM; 1640 } else { 1641 second_off = log->first_page - log->page_size; 1642 final_off = second_off - log->page_size; 1643 } 1644 1645next_tail: 1646 /* Read second tail page (at pos 3/0x12000) */ 1647 if (read_log_page(log, second_off, &second_tail, &usa_error) || 1648 usa_error || second_tail->rhdr.sign != NTFS_RCRD_SIGNATURE) { | 1638 if (!page_bufs) 1639 return -ENOMEM; 1640 } else { 1641 second_off = log->first_page - log->page_size; 1642 final_off = second_off - log->page_size; 1643 } 1644 1645next_tail: 1646 /* Read second tail page (at pos 3/0x12000) */ 1647 if (read_log_page(log, second_off, &second_tail, &usa_error) || 1648 usa_error || second_tail->rhdr.sign != NTFS_RCRD_SIGNATURE) { |
1649 ntfs_free(second_tail); | 1649 kfree(second_tail); |
1650 second_tail = NULL; 1651 second_file_off = 0; 1652 lsn2 = 0; 1653 } else { 1654 second_file_off = hdr_file_off(log, second_tail); 1655 lsn2 = le64_to_cpu(second_tail->record_hdr.last_end_lsn); 1656 } 1657 1658 /* Read first tail page (at pos 2/0x2000 ) */ 1659 if (read_log_page(log, final_off, &first_tail, &usa_error) || 1660 usa_error || first_tail->rhdr.sign != NTFS_RCRD_SIGNATURE) { | 1650 second_tail = NULL; 1651 second_file_off = 0; 1652 lsn2 = 0; 1653 } else { 1654 second_file_off = hdr_file_off(log, second_tail); 1655 lsn2 = le64_to_cpu(second_tail->record_hdr.last_end_lsn); 1656 } 1657 1658 /* Read first tail page (at pos 2/0x2000 ) */ 1659 if (read_log_page(log, final_off, &first_tail, &usa_error) || 1660 usa_error || first_tail->rhdr.sign != NTFS_RCRD_SIGNATURE) { |
1661 ntfs_free(first_tail); | 1661 kfree(first_tail); |
1662 first_tail = NULL; 1663 first_file_off = 0; 1664 lsn1 = 0; 1665 } else { 1666 first_file_off = hdr_file_off(log, first_tail); 1667 lsn1 = le64_to_cpu(first_tail->record_hdr.last_end_lsn); 1668 } 1669 --- 84 unchanged lines hidden (view full) --- 1754 page_pos = best_page_pos; 1755 1756 if (page_cnt > 1) 1757 page_pos += 1; 1758 } else { 1759 page_pos = page_cnt = 1; 1760 } 1761 } else { | 1662 first_tail = NULL; 1663 first_file_off = 0; 1664 lsn1 = 0; 1665 } else { 1666 first_file_off = hdr_file_off(log, first_tail); 1667 lsn1 = le64_to_cpu(first_tail->record_hdr.last_end_lsn); 1668 } 1669 --- 84 unchanged lines hidden (view full) --- 1754 page_pos = best_page_pos; 1755 1756 if (page_cnt > 1) 1757 page_pos += 1; 1758 } else { 1759 page_pos = page_cnt = 1; 1760 } 1761 } else { |
1762 ntfs_free(first_tail); 1763 ntfs_free(second_tail); | 1762 kfree(first_tail); 1763 kfree(second_tail); |
1764 goto tail_read; 1765 } 1766 | 1764 goto tail_read; 1765 } 1766 |
1767 ntfs_free(first_tail_prev); | 1767 kfree(first_tail_prev); |
1768 first_tail_prev = first_tail; 1769 final_off_prev = first_file_off; 1770 first_tail = NULL; 1771 | 1768 first_tail_prev = first_tail; 1769 final_off_prev = first_file_off; 1770 first_tail = NULL; 1771 |
1772 ntfs_free(second_tail_prev); | 1772 kfree(second_tail_prev); |
1773 second_tail_prev = second_tail; 1774 second_off_prev = second_file_off; 1775 second_tail = NULL; 1776 1777 final_off += log->page_size; 1778 second_off += log->page_size; 1779 1780 if (tails < 0x10) --- 244 unchanged lines hidden (view full) --- 2025next_page_1: 2026 2027 if (wrapped) { 2028 expected_seq += 1; 2029 wrapped_file = 1; 2030 } 2031 2032 curpage_off = nextpage_off; | 1773 second_tail_prev = second_tail; 1774 second_off_prev = second_file_off; 1775 second_tail = NULL; 1776 1777 final_off += log->page_size; 1778 second_off += log->page_size; 1779 1780 if (tails < 0x10) --- 244 unchanged lines hidden (view full) --- 2025next_page_1: 2026 2027 if (wrapped) { 2028 expected_seq += 1; 2029 wrapped_file = 1; 2030 } 2031 2032 curpage_off = nextpage_off; |
2033 ntfs_free(page); | 2033 kfree(page); |
2034 page = NULL; 2035 reuse_page = 0; 2036 goto next_page; 2037 2038check_tail: 2039 if (tail_page) { 2040 log->seq_num = expected_seq; 2041 log->last_lsn = le64_to_cpu(tail_page->record_hdr.last_end_lsn); --- 45 unchanged lines hidden (view full) --- 2087 page_cnt = 2; 2088 page_pos = 1; 2089 goto check_valid; 2090 } 2091 2092 cur_pos = 2; 2093 2094next_test_page: | 2034 page = NULL; 2035 reuse_page = 0; 2036 goto next_page; 2037 2038check_tail: 2039 if (tail_page) { 2040 log->seq_num = expected_seq; 2041 log->last_lsn = le64_to_cpu(tail_page->record_hdr.last_end_lsn); --- 45 unchanged lines hidden (view full) --- 2087 page_cnt = 2; 2088 page_pos = 1; 2089 goto check_valid; 2090 } 2091 2092 cur_pos = 2; 2093 2094next_test_page: |
2095 ntfs_free(tst_page); | 2095 kfree(tst_page); |
2096 tst_page = NULL; 2097 2098 /* Walk through the file, reading log pages */ 2099 err = read_log_page(log, nextpage_off, &tst_page, &usa_error); 2100 2101 /* 2102 * If we get a USA error then assume that we correctly found 2103 * the end of the original transfer --- 42 unchanged lines hidden (view full) --- 2146 nextpage_off = next_page_off(log, curpage_off); 2147 wrapped = nextpage_off == log->first_page; 2148 2149 if (wrapped) 2150 expected_seq += 1; 2151 } 2152 2153 /* Call our routine to check this log page */ | 2096 tst_page = NULL; 2097 2098 /* Walk through the file, reading log pages */ 2099 err = read_log_page(log, nextpage_off, &tst_page, &usa_error); 2100 2101 /* 2102 * If we get a USA error then assume that we correctly found 2103 * the end of the original transfer --- 42 unchanged lines hidden (view full) --- 2146 nextpage_off = next_page_off(log, curpage_off); 2147 wrapped = nextpage_off == log->first_page; 2148 2149 if (wrapped) 2150 expected_seq += 1; 2151 } 2152 2153 /* Call our routine to check this log page */ |
2154 ntfs_free(tst_page); | 2154 kfree(tst_page); |
2155 tst_page = NULL; 2156 2157 err = read_log_page(log, nextpage_off, &tst_page, &usa_error); 2158 if (!err && !usa_error && 2159 check_subseq_log_page(log, tst_page, nextpage_off, expected_seq)) { 2160 err = -EINVAL; 2161 goto out; 2162 } --- 18 unchanged lines hidden (view full) --- 2181 tmp_page = tail_page; 2182 tails = 1; 2183 } 2184 2185 while (tails--) { 2186 u64 off = hdr_file_off(log, tmp_page); 2187 2188 if (!page) { | 2155 tst_page = NULL; 2156 2157 err = read_log_page(log, nextpage_off, &tst_page, &usa_error); 2158 if (!err && !usa_error && 2159 check_subseq_log_page(log, tst_page, nextpage_off, expected_seq)) { 2160 err = -EINVAL; 2161 goto out; 2162 } --- 18 unchanged lines hidden (view full) --- 2181 tmp_page = tail_page; 2182 tails = 1; 2183 } 2184 2185 while (tails--) { 2186 u64 off = hdr_file_off(log, tmp_page); 2187 2188 if (!page) { |
2189 page = ntfs_malloc(log->page_size); | 2189 page = kmalloc(log->page_size, GFP_NOFS); |
2190 if (!page) 2191 return -ENOMEM; 2192 } 2193 2194 /* 2195 * Correct page and copy the data from this page 2196 * into it and flush it to disk 2197 */ --- 28 unchanged lines hidden (view full) --- 2226 if (part_io_count) { 2227 if (sb_rdonly(log->ni->mi.sbi->sb)) { 2228 err = -EROFS; 2229 goto out; 2230 } 2231 } 2232 2233out: | 2190 if (!page) 2191 return -ENOMEM; 2192 } 2193 2194 /* 2195 * Correct page and copy the data from this page 2196 * into it and flush it to disk 2197 */ --- 28 unchanged lines hidden (view full) --- 2226 if (part_io_count) { 2227 if (sb_rdonly(log->ni->mi.sbi->sb)) { 2228 err = -EROFS; 2229 goto out; 2230 } 2231 } 2232 2233out: |
2234 ntfs_free(second_tail); 2235 ntfs_free(first_tail); 2236 ntfs_free(page); 2237 ntfs_free(tst_page); 2238 ntfs_free(page_bufs); | 2234 kfree(second_tail); 2235 kfree(first_tail); 2236 kfree(page); 2237 kfree(tst_page); 2238 kfree(page_bufs); |
2239 2240 return err; 2241} 2242 2243/* 2244 * read_log_rec_buf 2245 * 2246 * copies a log record from the file to a buffer --- 59 unchanged lines hidden (view full) --- 2306 /* 2307 * adjust our pointer the user's buffer to transfer 2308 * the next block to 2309 */ 2310 buffer = Add2Ptr(buffer, tail); 2311 } 2312 2313out: | 2239 2240 return err; 2241} 2242 2243/* 2244 * read_log_rec_buf 2245 * 2246 * copies a log record from the file to a buffer --- 59 unchanged lines hidden (view full) --- 2306 /* 2307 * adjust our pointer the user's buffer to transfer 2308 * the next block to 2309 */ 2310 buffer = Add2Ptr(buffer, tail); 2311 } 2312 2313out: |
2314 ntfs_free(ph); | 2314 kfree(ph); |
2315 return err; 2316} 2317 2318static int read_rst_area(struct ntfs_log *log, struct NTFS_RESTART **rst_, 2319 u64 *lsn) 2320{ 2321 int err; 2322 struct LFS_RECORD_HDR *rh = NULL; --- 32 unchanged lines hidden (view full) --- 2355 goto out; 2356 } 2357 2358 if (len < sizeof(struct NTFS_RESTART)) { 2359 err = -EINVAL; 2360 goto out; 2361 } 2362 | 2315 return err; 2316} 2317 2318static int read_rst_area(struct ntfs_log *log, struct NTFS_RESTART **rst_, 2319 u64 *lsn) 2320{ 2321 int err; 2322 struct LFS_RECORD_HDR *rh = NULL; --- 32 unchanged lines hidden (view full) --- 2355 goto out; 2356 } 2357 2358 if (len < sizeof(struct NTFS_RESTART)) { 2359 err = -EINVAL; 2360 goto out; 2361 } 2362 |
2363 rst = ntfs_malloc(len); | 2363 rst = kmalloc(len, GFP_NOFS); |
2364 if (!rst) { 2365 err = -ENOMEM; 2366 goto out; 2367 } 2368 2369 /* Copy the data into the 'rst' buffer */ 2370 err = read_log_rec_buf(log, rh, rst); 2371 if (err) 2372 goto out; 2373 2374 *rst_ = rst; 2375 rst = NULL; 2376 2377out: | 2364 if (!rst) { 2365 err = -ENOMEM; 2366 goto out; 2367 } 2368 2369 /* Copy the data into the 'rst' buffer */ 2370 err = read_log_rec_buf(log, rh, rst); 2371 if (err) 2372 goto out; 2373 2374 *rst_ = rst; 2375 rst = NULL; 2376 2377out: |
2378 ntfs_free(rh); 2379 ntfs_free(rst); | 2378 kfree(rh); 2379 kfree(rst); |
2380 2381 return err; 2382} 2383 2384static int find_log_rec(struct ntfs_log *log, u64 lsn, struct lcb *lcb) 2385{ 2386 int err; 2387 struct LFS_RECORD_HDR *rh = lcb->lrh; --- 26 unchanged lines hidden (view full) --- 2414 if (rec_len >= log->total_avail) 2415 return -EINVAL; 2416 2417 /* 2418 * If the entire log record is on this log page, 2419 * put a pointer to the log record the context block 2420 */ 2421 if (rh->flags & LOG_RECORD_MULTI_PAGE) { | 2380 2381 return err; 2382} 2383 2384static int find_log_rec(struct ntfs_log *log, u64 lsn, struct lcb *lcb) 2385{ 2386 int err; 2387 struct LFS_RECORD_HDR *rh = lcb->lrh; --- 26 unchanged lines hidden (view full) --- 2414 if (rec_len >= log->total_avail) 2415 return -EINVAL; 2416 2417 /* 2418 * If the entire log record is on this log page, 2419 * put a pointer to the log record the context block 2420 */ 2421 if (rh->flags & LOG_RECORD_MULTI_PAGE) { |
2422 void *lr = ntfs_malloc(len); | 2422 void *lr = kmalloc(len, GFP_NOFS); |
2423 2424 if (!lr) 2425 return -ENOMEM; 2426 2427 lcb->log_rec = lr; 2428 lcb->alloc = true; 2429 2430 /* Copy the data into the buffer returned */ --- 36 unchanged lines hidden (view full) --- 2467 } 2468 2469 /* check that the given lsn is the legal range for this client */ 2470 cr = Add2Ptr(log->ra, le16_to_cpu(log->ra->client_off)); 2471 2472 if (!verify_client_lsn(log, cr, lsn)) 2473 return -EINVAL; 2474 | 2423 2424 if (!lr) 2425 return -ENOMEM; 2426 2427 lcb->log_rec = lr; 2428 lcb->alloc = true; 2429 2430 /* Copy the data into the buffer returned */ --- 36 unchanged lines hidden (view full) --- 2467 } 2468 2469 /* check that the given lsn is the legal range for this client */ 2470 cr = Add2Ptr(log->ra, le16_to_cpu(log->ra->client_off)); 2471 2472 if (!verify_client_lsn(log, cr, lsn)) 2473 return -EINVAL; 2474 |
2475 lcb = ntfs_zalloc(sizeof(struct lcb)); | 2475 lcb = kzalloc(sizeof(struct lcb), GFP_NOFS); |
2476 if (!lcb) 2477 return -ENOMEM; 2478 lcb->client = log->client_id; 2479 lcb->ctx_mode = ctx_mode; 2480 2481 /* Find the log record indicated by the given lsn */ 2482 err = find_log_rec(log, lsn, lcb); 2483 if (err) --- 32 unchanged lines hidden (view full) --- 2516 err = next_log_lsn(log, hdr, ¤t_lsn); 2517 if (err) 2518 goto out; 2519 2520 if (!current_lsn) 2521 break; 2522 2523 if (hdr != lcb->lrh) | 2476 if (!lcb) 2477 return -ENOMEM; 2478 lcb->client = log->client_id; 2479 lcb->ctx_mode = ctx_mode; 2480 2481 /* Find the log record indicated by the given lsn */ 2482 err = find_log_rec(log, lsn, lcb); 2483 if (err) --- 32 unchanged lines hidden (view full) --- 2516 err = next_log_lsn(log, hdr, ¤t_lsn); 2517 if (err) 2518 goto out; 2519 2520 if (!current_lsn) 2521 break; 2522 2523 if (hdr != lcb->lrh) |
2524 ntfs_free(hdr); | 2524 kfree(hdr); |
2525 2526 hdr = NULL; 2527 err = read_log_page(log, lsn_to_vbo(log, current_lsn), 2528 (struct RECORD_PAGE_HDR **)&hdr, NULL); 2529 if (err) 2530 goto out; 2531 2532 if (memcmp(&hdr->client, &lcb->client, 2533 sizeof(struct CLIENT_ID))) { 2534 /*err = -EINVAL; */ 2535 } else if (LfsClientRecord == hdr->record_type) { | 2525 2526 hdr = NULL; 2527 err = read_log_page(log, lsn_to_vbo(log, current_lsn), 2528 (struct RECORD_PAGE_HDR **)&hdr, NULL); 2529 if (err) 2530 goto out; 2531 2532 if (memcmp(&hdr->client, &lcb->client, 2533 sizeof(struct CLIENT_ID))) { 2534 /*err = -EINVAL; */ 2535 } else if (LfsClientRecord == hdr->record_type) { |
2536 ntfs_free(lcb->lrh); | 2536 kfree(lcb->lrh); |
2537 lcb->lrh = hdr; 2538 *lsn = current_lsn; 2539 return 0; 2540 } 2541 } 2542 2543out: 2544 if (hdr != lcb->lrh) | 2537 lcb->lrh = hdr; 2538 *lsn = current_lsn; 2539 return 0; 2540 } 2541 } 2542 2543out: 2544 if (hdr != lcb->lrh) |
2545 ntfs_free(hdr); | 2545 kfree(hdr); |
2546 return err; 2547 2548check_undo_next: 2549 if (lcb_ctx_undo_next == lcb->ctx_mode) 2550 next_lsn = le64_to_cpu(hdr->client_undo_next_lsn); 2551 else if (lcb_ctx_prev == lcb->ctx_mode) 2552 next_lsn = le64_to_cpu(hdr->client_prev_lsn); 2553 else --- 7 unchanged lines hidden (view full) --- 2561 next_lsn)) 2562 return 0; 2563 2564 hdr = NULL; 2565 err = read_log_page(log, lsn_to_vbo(log, next_lsn), 2566 (struct RECORD_PAGE_HDR **)&hdr, NULL); 2567 if (err) 2568 return err; | 2546 return err; 2547 2548check_undo_next: 2549 if (lcb_ctx_undo_next == lcb->ctx_mode) 2550 next_lsn = le64_to_cpu(hdr->client_undo_next_lsn); 2551 else if (lcb_ctx_prev == lcb->ctx_mode) 2552 next_lsn = le64_to_cpu(hdr->client_prev_lsn); 2553 else --- 7 unchanged lines hidden (view full) --- 2561 next_lsn)) 2562 return 0; 2563 2564 hdr = NULL; 2565 err = read_log_page(log, lsn_to_vbo(log, next_lsn), 2566 (struct RECORD_PAGE_HDR **)&hdr, NULL); 2567 if (err) 2568 return err; |
2569 ntfs_free(lcb->lrh); | 2569 kfree(lcb->lrh); |
2570 lcb->lrh = hdr; 2571 2572 *lsn = next_lsn; 2573 2574 return 0; 2575} 2576 2577static int read_next_log_rec(struct ntfs_log *log, struct lcb *lcb, u64 *lsn) 2578{ 2579 int err; 2580 2581 err = find_client_next_lsn(log, lcb, lsn); 2582 if (err) 2583 return err; 2584 2585 if (!*lsn) 2586 return 0; 2587 2588 if (lcb->alloc) | 2570 lcb->lrh = hdr; 2571 2572 *lsn = next_lsn; 2573 2574 return 0; 2575} 2576 2577static int read_next_log_rec(struct ntfs_log *log, struct lcb *lcb, u64 *lsn) 2578{ 2579 int err; 2580 2581 err = find_client_next_lsn(log, lcb, lsn); 2582 if (err) 2583 return err; 2584 2585 if (!*lsn) 2586 return 0; 2587 2588 if (lcb->alloc) |
2589 ntfs_free(lcb->log_rec); | 2589 kfree(lcb->log_rec); |
2590 2591 lcb->log_rec = NULL; 2592 lcb->alloc = false; | 2590 2591 lcb->log_rec = NULL; 2592 lcb->alloc = false; |
2593 ntfs_free(lcb->lrh); | 2593 kfree(lcb->lrh); |
2594 lcb->lrh = NULL; 2595 2596 return find_log_rec(log, *lsn, lcb); 2597} 2598 2599static inline bool check_index_header(const struct INDEX_HDR *hdr, size_t bytes) 2600{ 2601 __le16 mask; --- 380 unchanged lines hidden (view full) --- 2982 __le16 flags) 2983{ 2984 struct ATTRIB *attr; 2985 u32 name_size = ALIGN(name_len * sizeof(short), 8); 2986 bool is_ext = flags & (ATTR_FLAG_COMPRESSED | ATTR_FLAG_SPARSED); 2987 u32 asize = name_size + 2988 (is_ext ? SIZEOF_NONRESIDENT_EX : SIZEOF_NONRESIDENT); 2989 | 2594 lcb->lrh = NULL; 2595 2596 return find_log_rec(log, *lsn, lcb); 2597} 2598 2599static inline bool check_index_header(const struct INDEX_HDR *hdr, size_t bytes) 2600{ 2601 __le16 mask; --- 380 unchanged lines hidden (view full) --- 2982 __le16 flags) 2983{ 2984 struct ATTRIB *attr; 2985 u32 name_size = ALIGN(name_len * sizeof(short), 8); 2986 bool is_ext = flags & (ATTR_FLAG_COMPRESSED | ATTR_FLAG_SPARSED); 2987 u32 asize = name_size + 2988 (is_ext ? SIZEOF_NONRESIDENT_EX : SIZEOF_NONRESIDENT); 2989 |
2990 attr = ntfs_zalloc(asize); | 2990 attr = kzalloc(asize, GFP_NOFS); |
2991 if (!attr) 2992 return NULL; 2993 2994 attr->type = type; 2995 attr->size = cpu_to_le32(asize); 2996 attr->flags = flags; 2997 attr->non_res = 1; 2998 attr->name_len = name_len; --- 83 unchanged lines hidden (view full) --- 3082 case UpdateFileNameRoot: 3083 case UpdateRecordDataRoot: 3084 case ZeroEndOfFileRecord: 3085 rno = vbo >> sbi->record_bits; 3086 inode = ilookup(sbi->sb, rno); 3087 if (inode) { 3088 mi = &ntfs_i(inode)->mi; 3089 } else if (op == InitializeFileRecordSegment) { | 2991 if (!attr) 2992 return NULL; 2993 2994 attr->type = type; 2995 attr->size = cpu_to_le32(asize); 2996 attr->flags = flags; 2997 attr->non_res = 1; 2998 attr->name_len = name_len; --- 83 unchanged lines hidden (view full) --- 3082 case UpdateFileNameRoot: 3083 case UpdateRecordDataRoot: 3084 case ZeroEndOfFileRecord: 3085 rno = vbo >> sbi->record_bits; 3086 inode = ilookup(sbi->sb, rno); 3087 if (inode) { 3088 mi = &ntfs_i(inode)->mi; 3089 } else if (op == InitializeFileRecordSegment) { |
3090 mi = ntfs_zalloc(sizeof(struct mft_inode)); | 3090 mi = kzalloc(sizeof(struct mft_inode), GFP_NOFS); |
3091 if (!mi) 3092 return -ENOMEM; 3093 err = mi_format_new(mi, sbi, rno, 0, false); 3094 if (err) 3095 goto out; 3096 } else { 3097 /* read from disk */ 3098 err = mi_get(sbi, rno, &mi); --- 77 unchanged lines hidden (view full) --- 3176 3177 if (!bytes) 3178 bytes = lco - cbo; 3179 3180 bytes += roff; 3181 if (attr->type == ATTR_ALLOC) 3182 bytes = (bytes + 511) & ~511; // align 3183 | 3091 if (!mi) 3092 return -ENOMEM; 3093 err = mi_format_new(mi, sbi, rno, 0, false); 3094 if (err) 3095 goto out; 3096 } else { 3097 /* read from disk */ 3098 err = mi_get(sbi, rno, &mi); --- 77 unchanged lines hidden (view full) --- 3176 3177 if (!bytes) 3178 bytes = lco - cbo; 3179 3180 bytes += roff; 3181 if (attr->type == ATTR_ALLOC) 3182 bytes = (bytes + 511) & ~511; // align 3183 |
3184 buffer_le = ntfs_malloc(bytes); | 3184 buffer_le = kmalloc(bytes, GFP_NOFS); |
3185 if (!buffer_le) 3186 return -ENOMEM; 3187 3188 err = ntfs_read_run_nb(sbi, oa->run1, vbo, buffer_le, bytes, 3189 NULL); 3190 if (err) 3191 goto out; 3192 --- 52 unchanged lines hidden (view full) --- 3245 id2 = le16_to_cpu(attr2->id); 3246 if (id <= id2) 3247 rec->next_attr_id = cpu_to_le16(id2 + 1); 3248 if (is_attr_indexed(attr)) 3249 le16_add_cpu(&rec->hard_links, 1); 3250 3251 oa2 = find_loaded_attr(log, attr, rno_base); 3252 if (oa2) { | 3185 if (!buffer_le) 3186 return -ENOMEM; 3187 3188 err = ntfs_read_run_nb(sbi, oa->run1, vbo, buffer_le, bytes, 3189 NULL); 3190 if (err) 3191 goto out; 3192 --- 52 unchanged lines hidden (view full) --- 3245 id2 = le16_to_cpu(attr2->id); 3246 if (id <= id2) 3247 rec->next_attr_id = cpu_to_le16(id2 + 1); 3248 if (is_attr_indexed(attr)) 3249 le16_add_cpu(&rec->hard_links, 1); 3250 3251 oa2 = find_loaded_attr(log, attr, rno_base); 3252 if (oa2) { |
3253 void *p2 = ntfs_memdup(attr, le32_to_cpu(attr->size)); 3254 | 3253 void *p2 = kmemdup(attr, le32_to_cpu(attr->size), 3254 GFP_NOFS); |
3255 if (p2) { 3256 // run_close(oa2->run1); | 3255 if (p2) { 3256 // run_close(oa2->run1); |
3257 ntfs_free(oa2->attr); | 3257 kfree(oa2->attr); |
3258 oa2->attr = p2; 3259 } 3260 } 3261 3262 mi->dirty = true; 3263 break; 3264 3265 case DeleteAttribute: --- 46 unchanged lines hidden (view full) --- 3312 attr->res.data_size = cpu_to_le32(aoff + dlen - data_off); 3313 3314move_data: 3315 if (data) 3316 memmove(Add2Ptr(attr, aoff), data, dlen); 3317 3318 oa2 = find_loaded_attr(log, attr, rno_base); 3319 if (oa2) { | 3258 oa2->attr = p2; 3259 } 3260 } 3261 3262 mi->dirty = true; 3263 break; 3264 3265 case DeleteAttribute: --- 46 unchanged lines hidden (view full) --- 3312 attr->res.data_size = cpu_to_le32(aoff + dlen - data_off); 3313 3314move_data: 3315 if (data) 3316 memmove(Add2Ptr(attr, aoff), data, dlen); 3317 3318 oa2 = find_loaded_attr(log, attr, rno_base); 3319 if (oa2) { |
3320 void *p2 = ntfs_memdup(attr, le32_to_cpu(attr->size)); 3321 | 3320 void *p2 = kmemdup(attr, le32_to_cpu(attr->size), 3321 GFP_NOFS); |
3322 if (p2) { 3323 // run_close(&oa2->run0); 3324 oa2->run1 = &oa2->run0; | 3322 if (p2) { 3323 // run_close(&oa2->run0); 3324 oa2->run1 = &oa2->run0; |
3325 ntfs_free(oa2->attr); | 3325 kfree(oa2->attr); |
3326 oa2->attr = p2; 3327 } 3328 } 3329 3330 mi->dirty = true; 3331 break; 3332 3333 case UpdateMappingPairs: --- 37 unchanged lines hidden (view full) --- 3371 attr->nres.data_size = new_sz->data_size; 3372 attr->nres.valid_size = new_sz->valid_size; 3373 3374 if (dlen >= sizeof(struct NEW_ATTRIBUTE_SIZES)) 3375 attr->nres.total_size = new_sz->total_size; 3376 3377 oa2 = find_loaded_attr(log, attr, rno_base); 3378 if (oa2) { | 3326 oa2->attr = p2; 3327 } 3328 } 3329 3330 mi->dirty = true; 3331 break; 3332 3333 case UpdateMappingPairs: --- 37 unchanged lines hidden (view full) --- 3371 attr->nres.data_size = new_sz->data_size; 3372 attr->nres.valid_size = new_sz->valid_size; 3373 3374 if (dlen >= sizeof(struct NEW_ATTRIBUTE_SIZES)) 3375 attr->nres.total_size = new_sz->total_size; 3376 3377 oa2 = find_loaded_attr(log, attr, rno_base); 3378 if (oa2) { |
3379 void *p2 = ntfs_memdup(attr, le32_to_cpu(attr->size)); 3380 | 3379 void *p2 = kmemdup(attr, le32_to_cpu(attr->size), 3380 GFP_NOFS); |
3381 if (p2) { | 3381 if (p2) { |
3382 ntfs_free(oa2->attr); | 3382 kfree(oa2->attr); |
3383 oa2->attr = p2; 3384 } 3385 } 3386 mi->dirty = true; 3387 break; 3388 3389 case AddIndexEntryRoot: 3390 e = (struct NTFS_DE *)data; --- 318 unchanged lines hidden (view full) --- 3709 3710out: 3711 3712 if (inode) 3713 iput(inode); 3714 else if (mi != mi2_child) 3715 mi_put(mi); 3716 | 3383 oa2->attr = p2; 3384 } 3385 } 3386 mi->dirty = true; 3387 break; 3388 3389 case AddIndexEntryRoot: 3390 e = (struct NTFS_DE *)data; --- 318 unchanged lines hidden (view full) --- 3709 3710out: 3711 3712 if (inode) 3713 iput(inode); 3714 else if (mi != mi2_child) 3715 mi_put(mi); 3716 |
3717 ntfs_free(buffer_le); | 3717 kfree(buffer_le); |
3718 3719 return err; 3720 3721dirty_vol: 3722 log->set_dirty = true; 3723 goto out; 3724} 3725 --- 52 unchanged lines hidden (view full) --- 3778#if PAGE_SIZE >= DefaultLogPageSize && PAGE_SIZE <= DefaultLogPageSize * 2 3779 page_size = norm_file_page(PAGE_SIZE, &l_size, true); 3780#else 3781 page_size = norm_file_page(PAGE_SIZE, &l_size, false); 3782#endif 3783 if (!page_size) 3784 return -EINVAL; 3785 | 3718 3719 return err; 3720 3721dirty_vol: 3722 log->set_dirty = true; 3723 goto out; 3724} 3725 --- 52 unchanged lines hidden (view full) --- 3778#if PAGE_SIZE >= DefaultLogPageSize && PAGE_SIZE <= DefaultLogPageSize * 2 3779 page_size = norm_file_page(PAGE_SIZE, &l_size, true); 3780#else 3781 page_size = norm_file_page(PAGE_SIZE, &l_size, false); 3782#endif 3783 if (!page_size) 3784 return -EINVAL; 3785 |
3786 log = ntfs_zalloc(sizeof(struct ntfs_log)); | 3786 log = kzalloc(sizeof(struct ntfs_log), GFP_NOFS); |
3787 if (!log) 3788 return -ENOMEM; 3789 3790 log->ni = ni; 3791 log->l_size = l_size; | 3787 if (!log) 3788 return -ENOMEM; 3789 3790 log->ni = ni; 3791 log->l_size = l_size; |
3792 log->one_page_buf = ntfs_malloc(page_size); | 3792 log->one_page_buf = kmalloc(page_size, GFP_NOFS); |
3793 3794 if (!log->one_page_buf) { 3795 err = -ENOMEM; 3796 goto out; 3797 } 3798 3799 log->page_size = page_size; 3800 log->page_mask = page_size - 1; --- 48 unchanged lines hidden (view full) --- 3849 if (rst_info.chkdsk_was_run && page_size != rst_info.vbo) { 3850 struct RECORD_PAGE_HDR *sp = NULL; 3851 bool usa_error; 3852 3853 if (!read_log_page(log, page_size, &sp, &usa_error) && 3854 sp->rhdr.sign == NTFS_CHKD_SIGNATURE) { 3855 use_second_page = false; 3856 } | 3793 3794 if (!log->one_page_buf) { 3795 err = -ENOMEM; 3796 goto out; 3797 } 3798 3799 log->page_size = page_size; 3800 log->page_mask = page_size - 1; --- 48 unchanged lines hidden (view full) --- 3849 if (rst_info.chkdsk_was_run && page_size != rst_info.vbo) { 3850 struct RECORD_PAGE_HDR *sp = NULL; 3851 bool usa_error; 3852 3853 if (!read_log_page(log, page_size, &sp, &usa_error) && 3854 sp->rhdr.sign == NTFS_CHKD_SIGNATURE) { 3855 use_second_page = false; 3856 } |
3857 ntfs_free(sp); | 3857 kfree(sp); |
3858 } 3859 3860 if (use_second_page) { | 3858 } 3859 3860 if (use_second_page) { |
3861 ntfs_free(rst_info.r_page); | 3861 kfree(rst_info.r_page); |
3862 memcpy(&rst_info, &rst_info2, sizeof(struct restart_info)); 3863 rst_info2.r_page = NULL; 3864 } 3865 3866use_first_page: | 3862 memcpy(&rst_info, &rst_info2, sizeof(struct restart_info)); 3863 rst_info2.r_page = NULL; 3864 } 3865 3866use_first_page: |
3867 ntfs_free(rst_info2.r_page); | 3867 kfree(rst_info2.r_page); |
3868 3869check_restart_area: 3870 /* If the restart area is at offset 0, we want to write the second restart area first */ 3871 log->init_ra = !!rst_info.vbo; 3872 3873 /* If we have a valid page then grab a pointer to the restart area */ 3874 ra2 = rst_info.valid_page 3875 ? Add2Ptr(rst_info.r_page, --- 131 unchanged lines hidden (view full) --- 4007 log->current_openlog_count = le32_to_cpu(ra2->open_log_count); 4008 log->total_avail_pages = log->l_size - log->first_page; 4009 log->total_avail = log->total_avail_pages >> log->page_bits; 4010 log->max_current_avail = log->total_avail * log->reserved; 4011 log->total_avail = log->total_avail * log->data_size; 4012 4013 log->current_avail = current_log_avail(log); 4014 | 3868 3869check_restart_area: 3870 /* If the restart area is at offset 0, we want to write the second restart area first */ 3871 log->init_ra = !!rst_info.vbo; 3872 3873 /* If we have a valid page then grab a pointer to the restart area */ 3874 ra2 = rst_info.valid_page 3875 ? Add2Ptr(rst_info.r_page, --- 131 unchanged lines hidden (view full) --- 4007 log->current_openlog_count = le32_to_cpu(ra2->open_log_count); 4008 log->total_avail_pages = log->l_size - log->first_page; 4009 log->total_avail = log->total_avail_pages >> log->page_bits; 4010 log->max_current_avail = log->total_avail * log->reserved; 4011 log->total_avail = log->total_avail * log->data_size; 4012 4013 log->current_avail = current_log_avail(log); 4014 |
4015 ra = ntfs_zalloc(log->restart_size); | 4015 ra = kzalloc(log->restart_size, GFP_NOFS); |
4016 if (!ra) { 4017 err = -ENOMEM; 4018 goto out; 4019 } 4020 log->ra = ra; 4021 4022 t16 = le16_to_cpu(ra2->client_off); 4023 if (t16 == offsetof(struct RESTART_AREA, clients)) { --- 118 unchanged lines hidden (view full) --- 4142 t32 = rec_len - t16; 4143 4144 /* Now check that this is a valid restart table */ 4145 if (!check_rstbl(rt, t32)) { 4146 err = -EINVAL; 4147 goto out; 4148 } 4149 | 4016 if (!ra) { 4017 err = -ENOMEM; 4018 goto out; 4019 } 4020 log->ra = ra; 4021 4022 t16 = le16_to_cpu(ra2->client_off); 4023 if (t16 == offsetof(struct RESTART_AREA, clients)) { --- 118 unchanged lines hidden (view full) --- 4142 t32 = rec_len - t16; 4143 4144 /* Now check that this is a valid restart table */ 4145 if (!check_rstbl(rt, t32)) { 4146 err = -EINVAL; 4147 goto out; 4148 } 4149 |
4150 trtbl = ntfs_memdup(rt, t32); | 4150 trtbl = kmemdup(rt, t32, GFP_NOFS); |
4151 if (!trtbl) { 4152 err = -ENOMEM; 4153 goto out; 4154 } 4155 4156 lcb_put(lcb); 4157 lcb = NULL; 4158 --- 23 unchanged lines hidden (view full) --- 4182 t32 = rec_len - t16; 4183 4184 /* Now check that this is a valid restart table */ 4185 if (!check_rstbl(rt, t32)) { 4186 err = -EINVAL; 4187 goto out; 4188 } 4189 | 4151 if (!trtbl) { 4152 err = -ENOMEM; 4153 goto out; 4154 } 4155 4156 lcb_put(lcb); 4157 lcb = NULL; 4158 --- 23 unchanged lines hidden (view full) --- 4182 t32 = rec_len - t16; 4183 4184 /* Now check that this is a valid restart table */ 4185 if (!check_rstbl(rt, t32)) { 4186 err = -EINVAL; 4187 goto out; 4188 } 4189 |
4190 dptbl = ntfs_memdup(rt, t32); | 4190 dptbl = kmemdup(rt, t32, GFP_NOFS); |
4191 if (!dptbl) { 4192 err = -ENOMEM; 4193 goto out; 4194 } 4195 4196 /* Convert Ra version '0' into version '1' */ 4197 if (rst->major_ver) 4198 goto end_conv_1; --- 50 unchanged lines hidden (view full) --- 4249 bytes_per_attr_entry)) { 4250 err = -EINVAL; 4251 goto out; 4252 } 4253 4254 t32 = lrh_length(lrh); 4255 rec_len -= t32; 4256 | 4191 if (!dptbl) { 4192 err = -ENOMEM; 4193 goto out; 4194 } 4195 4196 /* Convert Ra version '0' into version '1' */ 4197 if (rst->major_ver) 4198 goto end_conv_1; --- 50 unchanged lines hidden (view full) --- 4249 bytes_per_attr_entry)) { 4250 err = -EINVAL; 4251 goto out; 4252 } 4253 4254 t32 = lrh_length(lrh); 4255 rec_len -= t32; 4256 |
4257 attr_names = ntfs_memdup(Add2Ptr(lrh, t32), rec_len); | 4257 attr_names = kmemdup(Add2Ptr(lrh, t32), rec_len, GFP_NOFS); |
4258 4259 lcb_put(lcb); 4260 lcb = NULL; 4261 4262check_attr_table: 4263 /* The next record should be the attribute Table */ 4264 if (!rst->open_attr_len) 4265 goto check_attribute_names2; --- 18 unchanged lines hidden (view full) --- 4284 rt = Add2Ptr(lrh, t16); 4285 t32 = rec_len - t16; 4286 4287 if (!check_rstbl(rt, t32)) { 4288 err = -EINVAL; 4289 goto out; 4290 } 4291 | 4258 4259 lcb_put(lcb); 4260 lcb = NULL; 4261 4262check_attr_table: 4263 /* The next record should be the attribute Table */ 4264 if (!rst->open_attr_len) 4265 goto check_attribute_names2; --- 18 unchanged lines hidden (view full) --- 4284 rt = Add2Ptr(lrh, t16); 4285 t32 = rec_len - t16; 4286 4287 if (!check_rstbl(rt, t32)) { 4288 err = -EINVAL; 4289 goto out; 4290 } 4291 |
4292 oatbl = ntfs_memdup(rt, t32); | 4292 oatbl = kmemdup(rt, t32, GFP_NOFS); |
4293 if (!oatbl) { 4294 err = -ENOMEM; 4295 goto out; 4296 } 4297 4298 log->open_attr_tbl = oatbl; 4299 4300 /* Clear all of the Attr pointers */ --- 166 unchanged lines hidden (view full) --- 4467 * which wrote the checkpoint, possibly creating the table 4468 */ 4469 if (dptbl) { 4470 t32 = (le16_to_cpu(dptbl->size) - 4471 sizeof(struct DIR_PAGE_ENTRY)) / 4472 sizeof(u64); 4473 } else { 4474 t32 = log->clst_per_page; | 4293 if (!oatbl) { 4294 err = -ENOMEM; 4295 goto out; 4296 } 4297 4298 log->open_attr_tbl = oatbl; 4299 4300 /* Clear all of the Attr pointers */ --- 166 unchanged lines hidden (view full) --- 4467 * which wrote the checkpoint, possibly creating the table 4468 */ 4469 if (dptbl) { 4470 t32 = (le16_to_cpu(dptbl->size) - 4471 sizeof(struct DIR_PAGE_ENTRY)) / 4472 sizeof(u64); 4473 } else { 4474 t32 = log->clst_per_page; |
4475 ntfs_free(dptbl); | 4475 kfree(dptbl); |
4476 dptbl = init_rsttbl(struct_size(dp, page_lcns, t32), 4477 32); 4478 if (!dptbl) { 4479 err = -ENOMEM; 4480 goto out; 4481 } 4482 } 4483 --- 86 unchanged lines hidden (view full) --- 4570 oe->ref = oe0->ref; 4571 oe->open_record_lsn = oe0->open_record_lsn; 4572 } else { 4573 memcpy(oe, Add2Ptr(lrh, t16), bytes_per_attr_entry); 4574 } 4575 4576 t16 = le16_to_cpu(lrh->undo_len); 4577 if (t16) { | 4476 dptbl = init_rsttbl(struct_size(dp, page_lcns, t32), 4477 32); 4478 if (!dptbl) { 4479 err = -ENOMEM; 4480 goto out; 4481 } 4482 } 4483 --- 86 unchanged lines hidden (view full) --- 4570 oe->ref = oe0->ref; 4571 oe->open_record_lsn = oe0->open_record_lsn; 4572 } else { 4573 memcpy(oe, Add2Ptr(lrh, t16), bytes_per_attr_entry); 4574 } 4575 4576 t16 = le16_to_cpu(lrh->undo_len); 4577 if (t16) { |
4578 oe->ptr = ntfs_malloc(t16); | 4578 oe->ptr = kmalloc(t16, GFP_NOFS); |
4579 if (!oe->ptr) { 4580 err = -ENOMEM; 4581 goto out; 4582 } 4583 oe->name_len = t16 / sizeof(short); 4584 memcpy(oe->ptr, 4585 Add2Ptr(lrh, le16_to_cpu(lrh->undo_off)), t16); 4586 oe->is_attr_name = 1; --- 88 unchanged lines hidden (view full) --- 4675 4676 oe = enum_rstbl(oatbl, oe); 4677 if (!oe) { 4678 err = 0; 4679 dp = NULL; 4680 goto next_dirty_page; 4681 } 4682 | 4579 if (!oe->ptr) { 4580 err = -ENOMEM; 4581 goto out; 4582 } 4583 oe->name_len = t16 / sizeof(short); 4584 memcpy(oe->ptr, 4585 Add2Ptr(lrh, le16_to_cpu(lrh->undo_off)), t16); 4586 oe->is_attr_name = 1; --- 88 unchanged lines hidden (view full) --- 4675 4676 oe = enum_rstbl(oatbl, oe); 4677 if (!oe) { 4678 err = 0; 4679 dp = NULL; 4680 goto next_dirty_page; 4681 } 4682 |
4683 oa = ntfs_zalloc(sizeof(struct OpenAttr)); | 4683 oa = kzalloc(sizeof(struct OpenAttr), GFP_NOFS); |
4684 if (!oa) { 4685 err = -ENOMEM; 4686 goto out; 4687 } 4688 4689 inode = ntfs_iget5(sbi->sb, &oe->ref, NULL); 4690 if (IS_ERR(inode)) 4691 goto fake_attr; --- 4 unchanged lines hidden (view full) --- 4696 if (oa->ni) { 4697 iput(&oa->ni->vfs_inode); 4698 oa->ni = NULL; 4699 } 4700 4701 attr = attr_create_nonres_log(sbi, oe->type, 0, oe->ptr, 4702 oe->name_len, 0); 4703 if (!attr) { | 4684 if (!oa) { 4685 err = -ENOMEM; 4686 goto out; 4687 } 4688 4689 inode = ntfs_iget5(sbi->sb, &oe->ref, NULL); 4690 if (IS_ERR(inode)) 4691 goto fake_attr; --- 4 unchanged lines hidden (view full) --- 4696 if (oa->ni) { 4697 iput(&oa->ni->vfs_inode); 4698 oa->ni = NULL; 4699 } 4700 4701 attr = attr_create_nonres_log(sbi, oe->type, 0, oe->ptr, 4702 oe->name_len, 0); 4703 if (!attr) { |
4704 ntfs_free(oa); | 4704 kfree(oa); |
4705 err = -ENOMEM; 4706 goto out; 4707 } 4708 oa->attr = attr; 4709 oa->run1 = &oa->run0; 4710 goto final_oe; 4711 } 4712 4713 ni_oe = ntfs_i(inode); 4714 oa->ni = ni_oe; 4715 4716 attr = ni_find_attr(ni_oe, NULL, NULL, oe->type, oe->ptr, oe->name_len, 4717 NULL, NULL); 4718 4719 if (!attr) 4720 goto fake_attr; 4721 4722 t32 = le32_to_cpu(attr->size); | 4705 err = -ENOMEM; 4706 goto out; 4707 } 4708 oa->attr = attr; 4709 oa->run1 = &oa->run0; 4710 goto final_oe; 4711 } 4712 4713 ni_oe = ntfs_i(inode); 4714 oa->ni = ni_oe; 4715 4716 attr = ni_find_attr(ni_oe, NULL, NULL, oe->type, oe->ptr, oe->name_len, 4717 NULL, NULL); 4718 4719 if (!attr) 4720 goto fake_attr; 4721 4722 t32 = le32_to_cpu(attr->size); |
4723 oa->attr = ntfs_memdup(attr, t32); | 4723 oa->attr = kmemdup(attr, t32, GFP_NOFS); |
4724 if (!oa->attr) 4725 goto fake_attr; 4726 4727 if (!S_ISDIR(inode->i_mode)) { 4728 if (attr->type == ATTR_DATA && !attr->name_len) { 4729 oa->run1 = &ni_oe->file.run; 4730 goto final_oe; 4731 } --- 9 unchanged lines hidden (view full) --- 4741 if (attr->non_res) { 4742 u16 roff = le16_to_cpu(attr->nres.run_off); 4743 CLST svcn = le64_to_cpu(attr->nres.svcn); 4744 4745 err = run_unpack(&oa->run0, sbi, inode->i_ino, svcn, 4746 le64_to_cpu(attr->nres.evcn), svcn, 4747 Add2Ptr(attr, roff), t32 - roff); 4748 if (err < 0) { | 4724 if (!oa->attr) 4725 goto fake_attr; 4726 4727 if (!S_ISDIR(inode->i_mode)) { 4728 if (attr->type == ATTR_DATA && !attr->name_len) { 4729 oa->run1 = &ni_oe->file.run; 4730 goto final_oe; 4731 } --- 9 unchanged lines hidden (view full) --- 4741 if (attr->non_res) { 4742 u16 roff = le16_to_cpu(attr->nres.run_off); 4743 CLST svcn = le64_to_cpu(attr->nres.svcn); 4744 4745 err = run_unpack(&oa->run0, sbi, inode->i_ino, svcn, 4746 le64_to_cpu(attr->nres.evcn), svcn, 4747 Add2Ptr(attr, roff), t32 - roff); 4748 if (err < 0) { |
4749 ntfs_free(oa->attr); | 4749 kfree(oa->attr); |
4750 oa->attr = NULL; 4751 goto fake_attr; 4752 } 4753 err = 0; 4754 } 4755 oa->run1 = &oa->run0; 4756 attr = oa->attr; 4757 4758final_oe: 4759 if (oe->is_attr_name == 1) | 4750 oa->attr = NULL; 4751 goto fake_attr; 4752 } 4753 err = 0; 4754 } 4755 oa->run1 = &oa->run0; 4756 attr = oa->attr; 4757 4758final_oe: 4759 if (oe->is_attr_name == 1) |
4760 ntfs_free(oe->ptr); | 4760 kfree(oe->ptr); |
4761 oe->is_attr_name = 0; 4762 oe->ptr = oa; 4763 oe->name_len = attr->name_len; 4764 4765 goto next_open_attribute; 4766 4767 /* 4768 * Now loop through the dirty page table to extract all of the Vcn/Lcn --- 316 unchanged lines hidden (view full) --- 5085 sbi->flags &= ~NTFS_FLAGS_NEED_REPLAY; 5086 5087end_reply: 5088 5089 err = 0; 5090 if (is_ro) 5091 goto out; 5092 | 4761 oe->is_attr_name = 0; 4762 oe->ptr = oa; 4763 oe->name_len = attr->name_len; 4764 4765 goto next_open_attribute; 4766 4767 /* 4768 * Now loop through the dirty page table to extract all of the Vcn/Lcn --- 316 unchanged lines hidden (view full) --- 5085 sbi->flags &= ~NTFS_FLAGS_NEED_REPLAY; 5086 5087end_reply: 5088 5089 err = 0; 5090 if (is_ro) 5091 goto out; 5092 |
5093 rh = ntfs_zalloc(log->page_size); | 5093 rh = kzalloc(log->page_size, GFP_NOFS); |
5094 if (!rh) { 5095 err = -ENOMEM; 5096 goto out; 5097 } 5098 5099 rh->rhdr.sign = NTFS_RSTR_SIGNATURE; 5100 rh->rhdr.fix_off = cpu_to_le16(offsetof(struct RESTART_HDR, fixups)); 5101 t16 = (log->page_size >> SECTOR_SHIFT) + 1; --- 18 unchanged lines hidden (view full) --- 5120 5121 ntfs_fix_pre_write(&rh->rhdr, log->page_size); 5122 5123 err = ntfs_sb_write_run(sbi, &ni->file.run, 0, rh, log->page_size); 5124 if (!err) 5125 err = ntfs_sb_write_run(sbi, &log->ni->file.run, log->page_size, 5126 rh, log->page_size); 5127 | 5094 if (!rh) { 5095 err = -ENOMEM; 5096 goto out; 5097 } 5098 5099 rh->rhdr.sign = NTFS_RSTR_SIGNATURE; 5100 rh->rhdr.fix_off = cpu_to_le16(offsetof(struct RESTART_HDR, fixups)); 5101 t16 = (log->page_size >> SECTOR_SHIFT) + 1; --- 18 unchanged lines hidden (view full) --- 5120 5121 ntfs_fix_pre_write(&rh->rhdr, log->page_size); 5122 5123 err = ntfs_sb_write_run(sbi, &ni->file.run, 0, rh, log->page_size); 5124 if (!err) 5125 err = ntfs_sb_write_run(sbi, &log->ni->file.run, log->page_size, 5126 rh, log->page_size); 5127 |
5128 ntfs_free(rh); | 5128 kfree(rh); |
5129 if (err) 5130 goto out; 5131 5132out: | 5129 if (err) 5130 goto out; 5131 5132out: |
5133 ntfs_free(rst); | 5133 kfree(rst); |
5134 if (lcb) 5135 lcb_put(lcb); 5136 5137 /* Scan the Open Attribute Table to close all of the open attributes */ 5138 oe = NULL; 5139 while ((oe = enum_rstbl(oatbl, oe))) { 5140 rno = ino_get(&oe->ref); 5141 5142 if (oe->is_attr_name == 1) { | 5134 if (lcb) 5135 lcb_put(lcb); 5136 5137 /* Scan the Open Attribute Table to close all of the open attributes */ 5138 oe = NULL; 5139 while ((oe = enum_rstbl(oatbl, oe))) { 5140 rno = ino_get(&oe->ref); 5141 5142 if (oe->is_attr_name == 1) { |
5143 ntfs_free(oe->ptr); | 5143 kfree(oe->ptr); |
5144 oe->ptr = NULL; 5145 continue; 5146 } 5147 5148 if (oe->is_attr_name) 5149 continue; 5150 5151 oa = oe->ptr; 5152 if (!oa) 5153 continue; 5154 5155 run_close(&oa->run0); | 5144 oe->ptr = NULL; 5145 continue; 5146 } 5147 5148 if (oe->is_attr_name) 5149 continue; 5150 5151 oa = oe->ptr; 5152 if (!oa) 5153 continue; 5154 5155 run_close(&oa->run0); |
5156 ntfs_free(oa->attr); | 5156 kfree(oa->attr); |
5157 if (oa->ni) 5158 iput(&oa->ni->vfs_inode); | 5157 if (oa->ni) 5158 iput(&oa->ni->vfs_inode); |
5159 ntfs_free(oa); | 5159 kfree(oa); |
5160 } 5161 | 5160 } 5161 |
5162 ntfs_free(trtbl); 5163 ntfs_free(oatbl); 5164 ntfs_free(dptbl); 5165 ntfs_free(attr_names); 5166 ntfs_free(rst_info.r_page); | 5162 kfree(trtbl); 5163 kfree(oatbl); 5164 kfree(dptbl); 5165 kfree(attr_names); 5166 kfree(rst_info.r_page); |
5167 | 5167 |
5168 ntfs_free(ra); 5169 ntfs_free(log->one_page_buf); | 5168 kfree(ra); 5169 kfree(log->one_page_buf); |
5170 5171 if (err) 5172 sbi->flags |= NTFS_FLAGS_NEED_REPLAY; 5173 5174 if (err == -EROFS) 5175 err = 0; 5176 else if (log->set_dirty) 5177 ntfs_set_state(sbi, NTFS_DIRTY_ERROR); 5178 | 5170 5171 if (err) 5172 sbi->flags |= NTFS_FLAGS_NEED_REPLAY; 5173 5174 if (err == -EROFS) 5175 err = 0; 5176 else if (log->set_dirty) 5177 ntfs_set_state(sbi, NTFS_DIRTY_ERROR); 5178 |
5179 ntfs_free(log); | 5179 kfree(log); |
5180 5181 return err; 5182} | 5180 5181 return err; 5182} |