logfile.c (e5451c8f8330e03ad3cfa16048b4daf961af434f) | logfile.c (09cbfeaf1a5a67bfb3201e0c83c810cecb2efa5a) |
---|---|
1/* 2 * logfile.c - NTFS kernel journal handling. Part of the Linux-NTFS project. 3 * 4 * Copyright (c) 2002-2007 Anton Altaparmakov 5 * 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 --- 367 unchanged lines hidden (view full) --- 376 "restart page buffer."); 377 return -ENOMEM; 378 } 379 /* 380 * Read the whole of the restart page into the buffer. If it fits 381 * completely inside @rp, just copy it from there. Otherwise map all 382 * the required pages and copy the data from them. 383 */ | 1/* 2 * logfile.c - NTFS kernel journal handling. Part of the Linux-NTFS project. 3 * 4 * Copyright (c) 2002-2007 Anton Altaparmakov 5 * 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 --- 367 unchanged lines hidden (view full) --- 376 "restart page buffer."); 377 return -ENOMEM; 378 } 379 /* 380 * Read the whole of the restart page into the buffer. If it fits 381 * completely inside @rp, just copy it from there. Otherwise map all 382 * the required pages and copy the data from them. 383 */ |
384 size = PAGE_CACHE_SIZE - (pos & ~PAGE_CACHE_MASK); | 384 size = PAGE_SIZE - (pos & ~PAGE_MASK); |
385 if (size >= le32_to_cpu(rp->system_page_size)) { 386 memcpy(trp, rp, le32_to_cpu(rp->system_page_size)); 387 } else { 388 pgoff_t idx; 389 struct page *page; 390 int have_read, to_read; 391 392 /* First copy what we already have in @rp. */ 393 memcpy(trp, rp, size); 394 /* Copy the remaining data one page at a time. */ 395 have_read = size; 396 to_read = le32_to_cpu(rp->system_page_size) - size; | 385 if (size >= le32_to_cpu(rp->system_page_size)) { 386 memcpy(trp, rp, le32_to_cpu(rp->system_page_size)); 387 } else { 388 pgoff_t idx; 389 struct page *page; 390 int have_read, to_read; 391 392 /* First copy what we already have in @rp. */ 393 memcpy(trp, rp, size); 394 /* Copy the remaining data one page at a time. */ 395 have_read = size; 396 to_read = le32_to_cpu(rp->system_page_size) - size; |
397 idx = (pos + size) >> PAGE_CACHE_SHIFT; 398 BUG_ON((pos + size) & ~PAGE_CACHE_MASK); | 397 idx = (pos + size) >> PAGE_SHIFT; 398 BUG_ON((pos + size) & ~PAGE_MASK); |
399 do { 400 page = ntfs_map_page(vi->i_mapping, idx); 401 if (IS_ERR(page)) { 402 ntfs_error(vi->i_sb, "Error mapping $LogFile " 403 "page (index %lu).", idx); 404 err = PTR_ERR(page); 405 if (err != -EIO && err != -ENOMEM) 406 err = -EIO; 407 goto err_out; 408 } | 399 do { 400 page = ntfs_map_page(vi->i_mapping, idx); 401 if (IS_ERR(page)) { 402 ntfs_error(vi->i_sb, "Error mapping $LogFile " 403 "page (index %lu).", idx); 404 err = PTR_ERR(page); 405 if (err != -EIO && err != -ENOMEM) 406 err = -EIO; 407 goto err_out; 408 } |
409 size = min_t(int, to_read, PAGE_CACHE_SIZE); | 409 size = min_t(int, to_read, PAGE_SIZE); |
410 memcpy((u8*)trp + have_read, page_address(page), size); 411 ntfs_unmap_page(page); 412 have_read += size; 413 to_read -= size; 414 idx++; 415 } while (to_read > 0); 416 } 417 /* --- 86 unchanged lines hidden (view full) --- 504 if (size > MaxLogFileSize) 505 size = MaxLogFileSize; 506 /* 507 * Truncate size to a multiple of the page cache size or the default 508 * log page size if the page cache size is between the default log page 509 * log page size if the page cache size is between the default log page 510 * size and twice that. 511 */ | 410 memcpy((u8*)trp + have_read, page_address(page), size); 411 ntfs_unmap_page(page); 412 have_read += size; 413 to_read -= size; 414 idx++; 415 } while (to_read > 0); 416 } 417 /* --- 86 unchanged lines hidden (view full) --- 504 if (size > MaxLogFileSize) 505 size = MaxLogFileSize; 506 /* 507 * Truncate size to a multiple of the page cache size or the default 508 * log page size if the page cache size is between the default log page 509 * log page size if the page cache size is between the default log page 510 * size and twice that. 511 */ |
512 if (PAGE_CACHE_SIZE >= DefaultLogPageSize && PAGE_CACHE_SIZE <= | 512 if (PAGE_SIZE >= DefaultLogPageSize && PAGE_SIZE <= |
513 DefaultLogPageSize * 2) 514 log_page_size = DefaultLogPageSize; 515 else | 513 DefaultLogPageSize * 2) 514 log_page_size = DefaultLogPageSize; 515 else |
516 log_page_size = PAGE_CACHE_SIZE; | 516 log_page_size = PAGE_SIZE; |
517 log_page_mask = log_page_size - 1; 518 /* 519 * Use ntfs_ffs() instead of ffs() to enable the compiler to 520 * optimize log_page_size and log_page_bits into constants. 521 */ 522 log_page_bits = ntfs_ffs(log_page_size) - 1; 523 size &= ~(s64)(log_page_size - 1); 524 /* --- 9 unchanged lines hidden (view full) --- 534 * Read through the file looking for a restart page. Since the restart 535 * page header is at the beginning of a page we only need to search at 536 * what could be the beginning of a page (for each page size) rather 537 * than scanning the whole file byte by byte. If all potential places 538 * contain empty and uninitialzed records, the log file can be assumed 539 * to be empty. 540 */ 541 for (pos = 0; pos < size; pos <<= 1) { | 517 log_page_mask = log_page_size - 1; 518 /* 519 * Use ntfs_ffs() instead of ffs() to enable the compiler to 520 * optimize log_page_size and log_page_bits into constants. 521 */ 522 log_page_bits = ntfs_ffs(log_page_size) - 1; 523 size &= ~(s64)(log_page_size - 1); 524 /* --- 9 unchanged lines hidden (view full) --- 534 * Read through the file looking for a restart page. Since the restart 535 * page header is at the beginning of a page we only need to search at 536 * what could be the beginning of a page (for each page size) rather 537 * than scanning the whole file byte by byte. If all potential places 538 * contain empty and uninitialzed records, the log file can be assumed 539 * to be empty. 540 */ 541 for (pos = 0; pos < size; pos <<= 1) { |
542 pgoff_t idx = pos >> PAGE_CACHE_SHIFT; | 542 pgoff_t idx = pos >> PAGE_SHIFT; |
543 if (!page || page->index != idx) { 544 if (page) 545 ntfs_unmap_page(page); 546 page = ntfs_map_page(mapping, idx); 547 if (IS_ERR(page)) { 548 ntfs_error(vol->sb, "Error mapping $LogFile " 549 "page (index %lu).", idx); 550 goto err_out; 551 } 552 } | 543 if (!page || page->index != idx) { 544 if (page) 545 ntfs_unmap_page(page); 546 page = ntfs_map_page(mapping, idx); 547 if (IS_ERR(page)) { 548 ntfs_error(vol->sb, "Error mapping $LogFile " 549 "page (index %lu).", idx); 550 goto err_out; 551 } 552 } |
553 kaddr = (u8*)page_address(page) + (pos & ~PAGE_CACHE_MASK); | 553 kaddr = (u8*)page_address(page) + (pos & ~PAGE_MASK); |
554 /* 555 * A non-empty block means the logfile is not empty while an 556 * empty block after a non-empty block has been encountered 557 * means we are done. 558 */ 559 if (!ntfs_is_empty_recordp((le32*)kaddr)) 560 logfile_is_empty = false; 561 else if (!logfile_is_empty) --- 302 unchanged lines hidden --- | 554 /* 555 * A non-empty block means the logfile is not empty while an 556 * empty block after a non-empty block has been encountered 557 * means we are done. 558 */ 559 if (!ntfs_is_empty_recordp((le32*)kaddr)) 560 logfile_is_empty = false; 561 else if (!logfile_is_empty) --- 302 unchanged lines hidden --- |