Allocates a new cluster from the free list or by extending the file.
(&mut self, initial_data: Option<Vec<u8>>)
| 647 | |
| 648 | /// Allocates a new cluster from the free list or by extending the file. |
| 649 | fn get_new_cluster(&mut self, initial_data: Option<Vec<u8>>) -> io::Result<u64> { |
| 650 | if let Some(free_cluster) = self.avail_clusters.pop() { |
| 651 | if free_cluster == 0 { |
| 652 | self.set_corrupt_bit_best_effort(); |
| 653 | return Err(io::Error::from_raw_os_error(EIO)); |
| 654 | } |
| 655 | if let Some(initial_data) = initial_data { |
| 656 | self.raw_file.write_cluster(free_cluster, &initial_data)?; |
| 657 | } else { |
| 658 | self.raw_file.zero_cluster(free_cluster)?; |
| 659 | } |
| 660 | return Ok(free_cluster); |
| 661 | } |
| 662 | |
| 663 | let max_valid = self.refcounts.max_valid_cluster_offset(); |
| 664 | if let Some(new_cluster) = self.raw_file.add_cluster_end(max_valid)? { |
| 665 | if new_cluster == 0 { |
| 666 | self.set_corrupt_bit_best_effort(); |
| 667 | return Err(io::Error::from_raw_os_error(EIO)); |
| 668 | } |
| 669 | if let Some(initial_data) = initial_data { |
| 670 | self.raw_file.write_cluster(new_cluster, &initial_data)?; |
| 671 | } |
| 672 | Ok(new_cluster) |
| 673 | } else { |
| 674 | log::error!("No free clusters in get_new_cluster()"); |
| 675 | Err(io::Error::from_raw_os_error(libc::ENOSPC)) |
| 676 | } |
| 677 | } |
| 678 | |
| 679 | /// Allocates a data cluster and sets its refcount to 1. |
| 680 | fn append_data_cluster(&mut self, initial_data: Option<Vec<u8>>) -> io::Result<u64> { |
no test coverage detected