📄 ad_fstype.c
字号:
/* -*- Mode: C; c-basic-offset:4 ; -*- *//* * $Id: ad_fstype.c,v 1.30 2002/12/03 23:38:23 David Exp $ * * Copyright (C) 1997 University of Chicago. * See COPYRIGHT notice in top-level directory. *//* This file is quickly becoming the single one, outside the ADIO * implementations, which has "what ADIO components are built in" code in it. */#include "adio.h"#if (defined(HPUX) || defined(SPPUX) || defined(IRIX) || defined(SOLARIS) || defined(AIX) || defined(DEC) || defined(CRAY))#include <sys/statvfs.h>#endif#ifdef LINUX#include <sys/vfs.h>/* #include <linux/nfs_fs.h> this file is broken in newer versions of linux */#define NFS_SUPER_MAGIC 0x6969#endif#ifdef FREEBSD#include <sys/param.h>#include <sys/mount.h>#endif#ifdef PARAGON#include <nx.h>#include <pfs/pfs.h>#include <sys/mount.h>#endif#ifdef SX4#include <sys/stat.h>#endif#ifdef ROMIO_PVFS#include "pvfs_config.h"#include <sys/param.h>#endif#ifdef tflops#include <sys/mount.h>#endif#ifdef HAVE_UNISTD_H/* Needed for readlink */#include <unistd.h>#endif#ifndef ROMIO_NTFSstatic void ADIO_FileSysType_parentdir(char *filename, char **dirnamep);#endifstatic void ADIO_FileSysType_prefix(char *filename, int *fstype, int *error_code);static void ADIO_FileSysType_fncall(char *filename, int *fstype, int *error_code);/* ADIO_FileSysType_parentdir - determines a string pathname for the parent directory of a given filename.Input Parameters:. filename - pointer to file name character arrayOutput Parameters:. dirnamep - pointer to location in which to store a pointer to a string Note that the caller should free the memory located at the pointer returned after the string is no longer needed.*/#ifndef ROMIO_NTFS#ifndef PATH_MAX#define PATH_MAX 65535#endifstatic void ADIO_FileSysType_parentdir(char *filename, char **dirnamep){ int err; char *dir, *slash; struct stat statbuf; err = lstat(filename, &statbuf); if (err || (!S_ISLNK(statbuf.st_mode))) { /* no such file, or file is not a link; these are the "normal" * cases where we can just return the parent directory. */ dir = strdup(filename); } else { /* filename is a symlink. we've presumably already tried * to stat it and found it to be missing (dangling link), * but this code doesn't care if the target is really there * or not. */ char *linkbuf; linkbuf = ADIOI_Malloc(PATH_MAX+1); err = readlink(filename, linkbuf, PATH_MAX+1); if (err) { /* something strange has happened between the time that * we determined that this was a link and the time that * we attempted to read it; punt and use the old name. */ dir = strdup(filename); } else { /* successfully read the link */ dir = strdup(linkbuf); ADIOI_Free(linkbuf); } } slash = strrchr(dir, '/'); if (!slash) strcpy(dir, "."); else { if (slash == dir) *(dir + 1) = 0; else *slash = '\0'; } *dirnamep = dir; return;}#endif /* ROMIO_NTFS *//* ADIO_FileSysType_fncall - determines the file system type for a given file using a system-dependent function callInput Parameters:. filename - pointer to file name character arrayOutput Parameters:. fstype - location in which to store file system type (ADIO_XXX). error_code - location in which to store error code MPI_SUCCESS is stored in the location pointed to by error_code on success. This function is used by MPI_File_open() and MPI_File_delete() to determine file system type. Most other functions use the type which is stored when the file is opened. */static void ADIO_FileSysType_fncall(char *filename, int *fstype, int *error_code){#ifndef ROMIO_NTFS char *dir; int err;#endif#if (defined(HPUX) || defined(SPPUX) || defined(IRIX) || defined(SOLARIS) || defined(AIX) || defined(DEC) || defined(CRAY)) struct statvfs vfsbuf;#endif#if (defined(LINUX) || defined(FREEBSD) || defined(tflops)) struct statfs fsbuf;#endif#ifdef PARAGON struct estatfs ebuf;#endif#ifdef SX4 struct stat sbuf;#endif *error_code = MPI_SUCCESS;#if (defined(HPUX) || defined(SPPUX) || defined(IRIX) || defined(SOLARIS) || defined(AIX) || defined(DEC) || defined(CRAY)) do { err = statvfs(filename, &vfsbuf); } while (err && (errno == ESTALE)); if (err && (errno == ENOENT)) { ADIO_FileSysType_parentdir(filename, &dir); err = statvfs(dir, &vfsbuf); free(dir); } if (err) *error_code = MPI_ERR_UNKNOWN; else { /* FPRINTF(stderr, "%s\n", vfsbuf.f_basetype); */ if (!strncmp(vfsbuf.f_basetype, "nfs", 3)) *fstype = ADIO_NFS; else {# if (defined(HPUX) || defined(SPPUX))# ifdef HFS *fstype = ADIO_HFS;# else *fstype = ADIO_UFS;# endif# else if (!strncmp(vfsbuf.f_basetype, "xfs", 3)) *fstype = ADIO_XFS; else if (!strncmp(vfsbuf.f_basetype, "piofs", 4)) *fstype = ADIO_PIOFS; else *fstype = ADIO_UFS;# endif } }#elif defined(LINUX) do { err = statfs(filename, &fsbuf); } while (err && (errno == ESTALE)); if (err && (errno == ENOENT)) { ADIO_FileSysType_parentdir(filename, &dir); err = statfs(dir, &fsbuf); free(dir); } if (err) *error_code = MPI_ERR_UNKNOWN; else { /* FPRINTF(stderr, "%d\n", fsbuf.f_type);*/ if (fsbuf.f_type == NFS_SUPER_MAGIC) *fstype = ADIO_NFS;# ifdef ROMIO_PVFS else if (fsbuf.f_type == PVFS_SUPER_MAGIC) *fstype = ADIO_PVFS;# endif else *fstype = ADIO_UFS; }#elif (defined(FREEBSD) && defined(HAVE_MOUNT_NFS)) do { err = statfs(filename, &fsbuf); } while (err && (errno == ESTALE)); if (err && (errno == ENOENT)) { ADIO_FileSysType_parentdir(filename, &dir); err = statfs(dir, &fsbuf); free(dir); } if (err) *error_code = MPI_ERR_UNKNOWN; else {# if (__FreeBSD_version>300004) if ( !strncmp("nfs",fsbuf.f_fstypename,3) ) *fstype = ADIO_NFS;# else if (fsbuf.f_type == MOUNT_NFS) *fstype = ADIO_NFS;# endif else *fstype = ADIO_UFS; }#elif defined(PARAGON) do { err = statpfs(filename, &ebuf, 0, 0); } while (err && (errno == ESTALE)); if (err && (errno == ENOENT)) { ADIO_FileSysType_parentdir(filename, &dir); err = statpfs(dir, &ebuf, 0, 0); free(dir); } if (err) *error_code = MPI_ERR_UNKNOWN; else { if (ebuf.f_type == MOUNT_NFS) *fstype = ADIO_NFS; else if (ebuf.f_type == MOUNT_PFS) *fstype = ADIO_PFS; else *fstype = ADIO_UFS; }#elif defined(tflops) do { err = statfs(filename, &fsbuf); } while (err && (errno == ESTALE)); if (err && (errno == ENOENT)) { ADIO_FileSysType_parentdir(filename, &dir); err = statfs(dir, &fsbuf); free(dir); } if (err) *error_code = MPI_ERR_UNKNOWN; else { if (fsbuf.f_type == MOUNT_NFS) *fstype = ADIO_NFS; else if (fsbuf.f_type == MOUNT_PFS) *fstype = ADIO_PFS; else *fstype = ADIO_UFS; }#elif defined(SX4) do { err = stat(filename, &sbuf); } while (err && (errno == ESTALE)); if (err && (errno == ENOENT)) { ADIO_FileSysType_parentdir(filename, &dir); err = stat(dir, &sbuf); free(dir); } if (err) *error_code = MPI_ERR_UNKNOWN; else { if (!strcmp(sbuf.st_fstype, "nfs")) *fstype = ADIO_NFS; else *fstype = ADIO_SFS; }#else /* on other systems, make NFS the default */# ifdef ROMIO_NTFS *fstype = ADIO_NTFS;# else *fstype = ADIO_NFS; # endif *error_code = MPI_SUCCESS;#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -