From 9284f0ffa4b19ee5bb0471d0870dfbbf59d3f695 Mon Sep 17 00:00:00 2001 From: Chris Hanson Date: Tue, 23 Apr 1996 20:50:46 +0000 Subject: [PATCH] Add primitive to allow unix systems to detect file-system type. This is particularly useful on systems like Linux which support many file-system types. --- v7/src/microcode/pruxfs.c | 15 +++++- v7/src/microcode/syscall.h | 8 +-- v7/src/microcode/uxfs.c | 102 ++++++++++++++++++++++++++++++++++++- v7/src/microcode/uxtop.c | 6 ++- 4 files changed, 122 insertions(+), 9 deletions(-) diff --git a/v7/src/microcode/pruxfs.c b/v7/src/microcode/pruxfs.c index 59d6bd58b..257346dac 100644 --- a/v7/src/microcode/pruxfs.c +++ b/v7/src/microcode/pruxfs.c @@ -1,8 +1,8 @@ /* -*-C-*- -$Id: pruxfs.c,v 9.51 1993/06/24 07:09:32 gjr Exp $ +$Id: pruxfs.c,v 9.52 1996/04/23 20:50:35 cph Exp $ -Copyright (c) 1987-92 Massachusetts Institute of Technology +Copyright (c) 1987-96 Massachusetts Institute of Technology This material was developed by the Scheme project at the Massachusetts Institute of Technology, Department of Electrical Engineering and @@ -43,6 +43,7 @@ extern int EXFUN (UX_read_file_status, (CONST char * filename, struct stat * s)); extern int EXFUN (UX_read_file_status_indirect, (CONST char * filename, struct stat * s)); +extern CONST char * EXFUN (UX_file_system_type, (CONST char * name)); static SCHEME_OBJECT EXFUN (file_attributes_internal, (struct stat * s)); static void EXFUN (file_mode_string, (struct stat * s, char * a)); @@ -416,3 +417,13 @@ DEFINE_PRIMITIVE ("FILE-EQ?", Prim_file_eq_p, 2, 2, && ((s1 . st_ino) == (s2 . st_ino)))); } } + +DEFINE_PRIMITIVE ("FILE-SYSTEM-TYPE", Prim_file_system_type, 1, 1, 0) +{ + PRIMITIVE_HEADER (1); + { + char * result = (UX_file_system_type (STRING_ARG (1))); + PRIMITIVE_RETURN + (char_pointer_to_string ((result == 0) ? "unknown" : result)); + } +} diff --git a/v7/src/microcode/syscall.h b/v7/src/microcode/syscall.h index 5386402be..43456fde0 100644 --- a/v7/src/microcode/syscall.h +++ b/v7/src/microcode/syscall.h @@ -1,8 +1,8 @@ /* -*-C-*- -$Id: syscall.h,v 1.8 1995/01/06 17:50:54 cph Exp $ +$Id: syscall.h,v 1.9 1996/04/23 20:50:30 cph Exp $ -Copyright (c) 1993-95 Massachusetts Institute of Technology +Copyright (c) 1993-96 Massachusetts Institute of Technology This material was developed by the Scheme project at the Massachusetts Institute of Technology, Department of Electrical Engineering and @@ -107,7 +107,9 @@ enum syscall_names syscall_stat, syscall_lstat, syscall_mktime, - syscall_dld + syscall_dld, + syscall_statfs, + syscall_fstatfs }; enum syserr_names diff --git a/v7/src/microcode/uxfs.c b/v7/src/microcode/uxfs.c index a224acd71..ea023a665 100644 --- a/v7/src/microcode/uxfs.c +++ b/v7/src/microcode/uxfs.c @@ -1,8 +1,8 @@ /* -*-C-*- -$Id: uxfs.c,v 1.11 1996/03/01 09:17:51 cph Exp $ +$Id: uxfs.c,v 1.12 1996/04/23 20:50:46 cph Exp $ -Copyright (c) 1990-95 Massachusetts Institute of Technology +Copyright (c) 1990-96 Massachusetts Institute of Technology This material was developed by the Scheme project at the Massachusetts Institute of Technology, Department of Electrical Engineering and @@ -34,6 +34,33 @@ MIT in each case. */ #include "ux.h" #include "osfs.h" + +#ifdef HAVE_STATFS +#include + +#ifdef __linux +#include +#include +#include +#include +#include +#include +#include +#if 0 /* Broken -- requires __KERNEL__ defined. */ +#include +#endif +#include +#include +#include +#if (LINUX_VERSION_CODE >= 66304) /* 1.3.0 (is this correct?) */ +#include +#if (LINUX_VERSION_CODE >= 66387) /* 1.3.53 */ +#include +#endif +#endif +#endif /* __linux */ + +#endif /* HAVE_STATFS */ int DEFUN (UX_read_file_status, (filename, s), @@ -79,6 +106,77 @@ DEFUN (OS_file_existence_test, (name), CONST char * name) : file_doesnt_exist); } +CONST char * +DEFUN (UX_file_system_type, (name), CONST char * name) +{ +#ifdef HAVE_STATFS + struct statfs s; + while ((UX_statfs (name, (&s))) < 0) + { + if ((errno == ENOENT) || (errno == ENOTDIR)) + return (0); + if (errno != EINTR) + error_system_call (errno, syscall_statfs); + } + +#ifdef __linux + switch (s . f_type) + { +#ifdef COH_SUPER_MAGIC + case COH_SUPER_MAGIC: return ("coherent"); +#endif + case EXT_SUPER_MAGIC: return ("ext"); + case EXT2_SUPER_MAGIC: return ("ext2"); + case HPFS_SUPER_MAGIC: return ("hpfs"); + case ISOFS_SUPER_MAGIC: return ("iso9660"); + case MINIX_SUPER_MAGIC: return ("minix1"); + case MINIX_SUPER_MAGIC2: return ("minix1-30"); +#ifdef MINIX2_SUPER_MAGIC + case MINIX2_SUPER_MAGIC: return ("minix2"); +#endif +#ifdef MINIX2_SUPER_MAGIC2 + case MINIX2_SUPER_MAGIC2: return ("minix2-30"); +#endif + case MSDOS_SUPER_MAGIC: return ("fat"); +#ifdef NCP_SUPER_MAGIC + case NCP_SUPER_MAGIC: return ("ncp"); +#endif +#ifdef NEW_MINIX_SUPER_MAGIC + case NEW_MINIX_SUPER_MAGIC: return ("minix2"); +#endif + case NFS_SUPER_MAGIC: return ("nfs"); +#ifdef PROC_SUPER_MAGIC + case PROC_SUPER_MAGIC: return ("proc"); +#endif +#ifdef SMB_SUPER_MAGIC + case SMB_SUPER_MAGIC: return ("smb"); +#endif +#ifdef SYSV2_SUPER_MAGIC + case SYSV2_SUPER_MAGIC: return ("sysv2"); +#endif +#ifdef SYSV4_SUPER_MAGIC + case SYSV4_SUPER_MAGIC: return ("sysv4"); +#endif +#ifdef XENIX_SUPER_MAGIC + case XENIX_SUPER_MAGIC: return ("xenix"); +#endif + case _XIAFS_SUPER_MAGIC: return ("xiafs"); + } +#endif /* __linux */ + +#ifdef _HPUX + switch ((s . f_fsid) [1]) + { + case MOUNT_UFS: return ("ufs"); + case MOUNT_NFS: return ("nfs"); + case MOUNT_CDFS: return ("iso9660"); + } +#endif /* _HPUX */ +#endif /* HAVE_STATFS */ + + return (0); +} + int DEFUN (OS_file_directory_p, (name), CONST char * name) { diff --git a/v7/src/microcode/uxtop.c b/v7/src/microcode/uxtop.c index 4ece1f0cb..2e2b505d5 100644 --- a/v7/src/microcode/uxtop.c +++ b/v7/src/microcode/uxtop.c @@ -1,6 +1,6 @@ /* -*-C-*- -$Id: uxtop.c,v 1.18 1996/03/04 20:41:28 cph Exp $ +$Id: uxtop.c,v 1.19 1996/04/23 20:50:20 cph Exp $ Copyright (c) 1990-96 Massachusetts Institute of Technology @@ -364,7 +364,9 @@ static char * syscall_names_table [] = "STAT", "LSTAT", "MKTIME", - "DYNAMIC-LOAD" + "DYNAMIC-LOAD", + "STATFS", + "FSTATFS" }; void -- 2.25.1