File: get_fs_block_size.c

package info (click to toggle)
fis-gtm 6.2-000-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 30,784 kB
  • ctags: 42,554
  • sloc: ansic: 358,483; asm: 4,847; csh: 4,574; sh: 2,261; awk: 200; makefile: 86; sed: 13
file content (52 lines) | stat: -rw-r--r-- 1,795 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
/****************************************************************
 *								*
 *	Copyright 2010, 2013 Fidelity Information Services, Inc	*
 *								*
 *	This source code contains the intellectual property	*
 *	of its copyright holder(s), and is made available	*
 *	under a license.  If you do not know the terms of	*
 *	the license, please stop and do not read further.	*
 *								*
 ****************************************************************/

#include "mdef.h"

#include "have_crit.h"
#include "eintr_wrappers.h"
#include "get_fs_block_size.h"

#ifndef VMS
#include "gtm_statvfs.h"
#endif

uint4	get_fs_block_size(int fd)
{
#	ifndef VMS
	struct statvfs		bufvfs;
	int			status;
#	endif
	uint4			gtm_fs_block_size;
	unsigned long		sys_fs_block_size;

#	if defined(__vms)
	sys_fs_block_size = DISK_BLOCK_SIZE;
#	else
	FSTATVFS(fd, &bufvfs, status);
	assert(-1 != status);
	assert(SIZEOF(sys_fs_block_size) == SIZEOF(bufvfs.f_frsize));
	/* If fstatvfs call fails, we dont know what the underlying filesystem size is.
	 * We found some NFS implementations return bufvfs.f.frsize values that are inappropriate.
	 * Instead of erroring out at this point, we assume a safe value (4K) and continue as much as we can.
	 */
	sys_fs_block_size = ((-1 == status) || (MAX_IO_BLOCK_SIZE < bufvfs.f_frsize)
		|| (DISK_BLOCK_SIZE > bufvfs.f_frsize)) ? 4096 : bufvfs.f_frsize;
#	endif
	/* Fit file system block size in a 4-byte unsigned integer as that is the size in jnl_buffer.
	 * Assert that we never get a block size > what can be held in a 4-byte unsigned integer.
	 */
	gtm_fs_block_size = (uint4)sys_fs_block_size;
	assert(gtm_fs_block_size == sys_fs_block_size);
	assert(MAX_IO_BLOCK_SIZE >= gtm_fs_block_size);
	assert(MAX_IO_BLOCK_SIZE % gtm_fs_block_size == 0);
	return gtm_fs_block_size;
}