winsoft666 / zoe

C++ File Download Library.
GNU General Public License v3.0
37 stars 12 forks source link

关于文件硬盘预分配 #11

Closed xiaosongmao123 closed 3 days ago

xiaosongmao123 commented 3 years ago

在你的最近一次修改中,已经采用了fallocate 但在我的意识里,mac并不支持fallocate或posix_fallocate linux支持,mac是unix,并不是linux 参见: https://github.com/aria2/aria2/blob/15cad965eb75c8b7f11bc2fc94354d1873bf6261/src/AbstractDiskWriter.cc

 elif defined(__APPLE__) && defined(__MACH__)
  const auto toalloc = offset + length - size();
  fstore_t fstore = {F_ALLOCATECONTIG | F_ALLOCATEALL, F_PEOFPOSMODE, 0,
                     toalloc, 0};
  if (fcntl(fd_, F_PREALLOCATE, &fstore) == -1) {
    // Retry non-contig.
    fstore.fst_flags = F_ALLOCATEALL;
    if (fcntl(fd_, F_PREALLOCATE, &fstore) == -1) {
      int err = errno;
      throw DL_ABORT_EX3(
          err,
          fmt("fcntl(F_PREALLOCATE) of %" PRId64 " failed. cause: %s",
              fstore.fst_length, util::safeStrerror(err).c_str()),
          error_code::FILE_IO_ERROR);
    }
  }
  // This forces the allocation on disk.
  ftruncate(fd_, offset + length);
#  elif HAVE_FALLOCATE

aria2针对mac是使用的fcntl F_PREALLOCATE,在issues7中我也提过 请在macos中实际测试一下,看是否需要进一步修正

winsoft666 commented 3 years ago

待我有空使用虚拟机测试一下

xiaosongmao123 commented 3 years ago

好的,加油!

winsoft666 commented 3 days ago

Fixed