Problem
How should I use the F_SETBMODE command in fcntl(S)? Why
should I use it in my application? No documentation exists
for this fcntl command in SCO OpenServer Release 5.0.6. Solution
THE F_SETBMODE option is an fcntl command that can be used in any
SCO OpenServer 5 release. An illustrative example of its use is
given below. Essentially, it works around the 2Gb upper
limit on a file offset (as set and maintained by the kernel
in its file table entry for the open file) by allowing its value
to be set and interpreted as 512-byte blocks instead of single
bytes.Three requirements of the operating system environment need to met in order for F_SETBMODE to work properly:
(1) The file must be a valid character or block device
(2) The file device node must reside in a filesystem which supports block mode
(3) The hardware driver accessed through the device node must support block mode
In SCO OpenServer Releases 5.0.0 through 5.0.6, requirement
#2 is met by the HTFS filesystem, but not by the other filesystems
provided by the OS. In SCO OpenServer Release 5.0.0 and 5.0.2,
requirement #3 is met by only the Sdsk (SCSI hard disk) driver;
starting in SCO OpenServer Release 5.0.4, requirement #3 is met by the
Sdsk, Stp (SCSI tape), Srom (SCSI cdrom), and wd (IDE hard disk)
drivers.The following example illustrates the use of the F_SETBMODE option
to fcntl. The program provides two different ways to seek to
the beginning of the superblock of the root filesystem, and then
read some useful information and print this information to the
standard output. When invoked with the -b option, the program
sets F_SETBMODE and seeks to the superblock within /dev/root by
512-byte blocks; when invoked without this option, the program
uses an ordinary byte offset instead.When testing this program please heed the three requirements noted
above. No special compile options are necessary when creating
the executable./***********************begin example**************************/
#include <fcntl.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <errno.h>
#include <sys/types.h>
#include <sys/fs/htfilsys.h>#define BLKSZ 512
#define SUPERBOFF_BLK SUPERBOFF/BLKSZ/**************************************************
HTFS superblock structure--from sys/fs/htfilsys.hstruct filsys {
ulong s_isize; size in blocks of i-list
daddr_t s_fsize; size in blocks of entire volume
short s_nfree; number of addresses in s_free
daddr_t s_free[NICFREE]; free block list
union {
struct s_i16 {
short si16_ninode; number of i-nodes in s_inode
ino16_t si16_inode[NICINOD]; free i-node list
short si16_ffiseg; first free inode segment
} s_i16;
struct s_i32 {
ighdr_t si32_ighdr; number of inode groups
long si32_fill[42];
} s_i32;
} s_u1;
char s_flock; lock during free list manipulation
char s_ilock; lock during i-list manipulation
char s_fmod; super block modified flag
char s_ronly; mounted read-only flag
time_t s_time; last super block update
short s_dinfo[4]; device information
daddr_t s_tfree; total free blocks
ino16_t s_tinode; total free inodes
char s_fname[6]; file system name
char s_fpack[6]; file system pack name
long s_clsize; FFS only
long s_gap; FFS only
long s_firstblk; FFS only
long s_clfree; FFS only
long s_maplist; FFS only
long s_totinode; HTFS only
ino32_t s_logino; i-number of the log file
ulong s_txid; the current transaction ID
long s_fill[3]; adjust to make sizeof filsys
long s_version; file system format version
long s_state; file system state
long s_magic; magic number to indicate new file system
long s_type; type of new file system
};
*********************************************************/struct filsys sb;main( int argc, char **argv ) { char buf[BLKSZ]; int fd, nread;
fd = open("/dev/root", O_RDONLY); if (strcmp(argv[1], "-b") == 0) { if (fcntl(fd, F_SETBMODE, 1) == -1) { fprintf(stderr, "fcntl() failed: %s\n", strerror(errno)); exit(1); } if (lseek(fd, SUPERBOFF_BLK, SEEK_SET) == -1) { fprintf(stderr, "lseek() failed: %s\n", strerror(errno)); exit(1); } printf("Using block mode to seek to superblock\n"); } else if (argc > 1 && (strcmp(argv[1], "-b") != 0)) { fprintf(stderr, "unknown option: %s\n", argv[1]); exit(1); } else { if (lseek(fd, SUPERBOFF, SEEK_SET) == -1) { fprintf(stderr, "lseek() failed: %s\n", strerror(errno)); exit(1); } } if ((nread = read(fd, &sb, BLKSZ)) == -1) { fprintf(stderr, "read() failed: %s\n", strerror(errno)); exit(1); } printf("number of bytes read from superblock: %d\n", nread); printf("size in blocks of i-list: %d\n", sb.s_isize); printf("size in blocks of entire fs: %d\n", sb.s_fsize); printf("total free blocks: %d\n", sb.s_tfree); printf("total free inodes: %d\n", sb.s_tinode); close(fd); exit(0); } /*************************end example**************************/
See also
The fcntl(S) man page for more information on how to use the fcntl system call.