Problem
I am trying to use sysfs(S) to check for the existence of the S51K filesystem. This fails with a return value of -1 although the same routine used to work in previous releases of the development system. This works with other filesystem types such as HTFS, for example:
#include <sys/fstyp.h>
#include <sys/fsid.h><...>fstyp = sysfs (GETFSIND, "HTFS") ; /* This works */
fstyp = sysfs (GETFSIND, "S51K") ; /* This fails by returning -1 */
<...> Cause
The sysfs() system call is the system interface which allows the
fsinfo[] array to be queried. It is used mainly by high level,
generic filesystem code to find an index for a particular filesystem.
This is a way to incorporate filesystem specific code into the
program: these routine addresses are stored at the same index in
the fstypsw[] array.There is a problem with this routine in SCO OpenServer
Development System Release 5.0. Since the HTFS filesystem
is handled by the same driver as the s51K filesystem, the
routine should work in both cases, however it does not appear
to recognize the S51K filesystem.This has been reported to SCO Engineering.
Solution
The statvfs(S) routine will provide this functionality, as will other routines such as statfs(S), fstatfs(S), fstatvfs(S) and fstyp(ADM).
This example checks two files on an SCO OpenServer 5 system and reports the filesystem type using statvfs(S):
/************************************************************************/#include <stdio.h>
#include <sys/statvfs.h>
#include <sys/types.h>main(argc, argv) int argc; char **argv; { struct statvfs *buffer=NULL; int statvfs_return = 0;
/* Check statvfs */ buffer=(struct statvfs *)malloc(sizeof(struct statvfs)); if ( statvfs ("/.profile", buffer) == -1) { printf("statvfs failed\n"); exit(1); } else printf("filesystem type is %s \n", buffer -> f_basetype);
if ( statvfs ("/unix", buffer) == -1){ printf("statvfs failed\n"); exit(1); } else printf("filesystem type is %s \n", buffer -> f_basetype);
}