Пример #1
0
	void TruncateFile(int fd,Uint64 size,bool quick)
	{
		if (FileSize(fd) == size)
			return;

		if (quick)
		{
#ifdef HAVE_FTRUNCATE64
			if (ftruncate64(fd,size) == -1)
#else
			if (ftruncate(fd,size) == -1)
#endif
				throw Error(i18n("Cannot expand file: %1",strerror(errno)));
		}
		else
		{
#ifdef HAVE_POSIX_FALLOCATE64
			if (posix_fallocate64(fd,0,size) != 0)
				throw Error(i18n("Cannot expand file: %1",strerror(errno)));
#elif HAVE_POSIX_FALLOCATE
			if (posix_fallocate(fd,0,size) != 0)
				throw Error(i18n("Cannot expand file: %1",strerror(errno)));
#elif HAVE_FTRUNCATE64
			if (ftruncate64(fd,size) == -1)
				throw Error(i18n("Cannot expand file: %1",strerror(errno)));
#else
			if (ftruncate(fd,size) == -1)
				throw Error(i18n("Cannot expand file: %1",strerror(errno)));
#endif
		}
	}
Пример #2
0
	bool CacheFile::allocateBytes(Uint64 off, Uint64 size)
	{
#ifdef HAVE_POSIX_FALLOCATE64
		return posix_fallocate64(fptr->handle(),off,size) != ENOSPC;
#elif HAVE_POSIX_FALLOCATE
		return posix_fallocate(fptr->handle(),off,size) != ENOSPC;
#else
		return true;
#endif
	}
Пример #3
0
TEST(fcntl, fallocate_EINVAL) {
  TemporaryFile tf;

#if !defined(__GLIBC__)
  errno = 0;
  ASSERT_EQ(-1, fallocate(tf.fd, 0, 0, -1));
  ASSERT_EQ(EINVAL, errno);

  errno = 0;
  ASSERT_EQ(-1, fallocate64(tf.fd, 0, 0, -1));
  ASSERT_EQ(EINVAL, errno);
#endif

  errno = 0;
  ASSERT_EQ(EINVAL, posix_fallocate(tf.fd, 0, -1));
  ASSERT_EQ(0, errno);

  errno = 0;
  ASSERT_EQ(EINVAL, posix_fallocate64(tf.fd, 0, -1));
  ASSERT_EQ(0, errno);
}
Пример #4
0
TEST(fcntl, fallocate) {
  TemporaryFile tf;
  struct stat sb;
  ASSERT_EQ(0, fstat(tf.fd, &sb));
  ASSERT_EQ(0, sb.st_size);

#if !defined(__GLIBC__)
  ASSERT_EQ(0, fallocate(tf.fd, 0, 0, 1));
  ASSERT_EQ(0, fstat(tf.fd, &sb));
  ASSERT_EQ(1, sb.st_size);

  ASSERT_EQ(0, fallocate64(tf.fd, 0, 0, 2));
  ASSERT_EQ(0, fstat(tf.fd, &sb));
  ASSERT_EQ(2, sb.st_size);
#endif

  ASSERT_EQ(0, posix_fallocate(tf.fd, 0, 3));
  ASSERT_EQ(0, fstat(tf.fd, &sb));
  ASSERT_EQ(3, sb.st_size);

  ASSERT_EQ(0, posix_fallocate64(tf.fd, 0, 4));
  ASSERT_EQ(0, fstat(tf.fd, &sb));
  ASSERT_EQ(4, sb.st_size);
}
Пример #5
0
static __inline int _fallocate64(int fd, off64_t offset, off64_t len) {
	return posix_fallocate64(fd, offset, len);
}
Пример #6
0
int posix_fallocate(int fd, off_t offset, off_t len) {
	return posix_fallocate64(fd, offset, len);
}