Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 1 Jun 2006 15:04:59 -0500 (CDT)
From:      Jim Pirzyk <pirzyk@FreeBSD.org>
To:        FreeBSD-gnats-submit@FreeBSD.org
Subject:   ports/98307: New port: sysutils/p5-Sys-Filesystem Perl module to acces the fstab and mounted filesystems
Message-ID:  <200606012004.k51K4xsw091501@lilo.ci.uiuc.edu>
Resent-Message-ID: <200606012010.k51KAGap069020@freefall.freebsd.org>

next in thread | raw e-mail | index | archive | help

>Number:         98307
>Category:       ports
>Synopsis:       New port: sysutils/p5-Sys-Filesystem Perl module to acces the fstab and mounted filesystems
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    freebsd-ports-bugs
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:
>Class:          change-request
>Submitter-Id:   current-users
>Arrival-Date:   Thu Jun 01 20:10:15 GMT 2006
>Closed-Date:
>Last-Modified:
>Originator:     Super Jim Pirzyk
>Release:        FreeBSD 6.1-STABLE i386
>Organization:
>Environment:
System: FreeBSD lilo.ci.uiuc.edu 6.1-STABLE FreeBSD 6.1-STABLE #0: Tue May 9 20:02:52 CDT 2006 supirzyk@lilo.ci.uiuc.edu:/services/scratch/usr/src/sys/VMWARE_KERNEL i386


	
>Description:
	
>How-To-Repeat:
	
>Fix:

# This is a shell archive.  Save it in a file, remove anything before
# this line, and then unpack it by entering "sh file".  Note, it may
# create directories; files and directories will be owned by you and
# have default permissions.
#
# This archive contains:
#
#	p5-Sys-Filesystem
#	p5-Sys-Filesystem/Makefile
#	p5-Sys-Filesystem/distinfo
#	p5-Sys-Filesystem/pkg-descr
#	p5-Sys-Filesystem/pkg-plist
#	p5-Sys-Filesystem/files
#	p5-Sys-Filesystem/files/patch-lib-Sys-Filesystem.pm
#	p5-Sys-Filesystem/files/patch-lib-Sys-Filesystem-Freebsd.pm
#
echo c - p5-Sys-Filesystem
mkdir -p p5-Sys-Filesystem > /dev/null 2>&1
echo x - p5-Sys-Filesystem/Makefile
sed 's/^X//' >p5-Sys-Filesystem/Makefile << 'END-of-p5-Sys-Filesystem/Makefile'
X# New ports collection makefile for:   p5-Sys-Filesystem
X# Date created:                        Thu May 25 21:12:53 CDT 2006
X# Whom:                                        Jim Pirzyk pirzyk@freebsd.org
X#
X# $FreeBSD$
X#
X
XPORTNAME=		Sys-Filesystem
XPORTVERSION=	1.21
XCATEGORIES=	sysutils perl5
XMASTER_SITES=	${MASTER_SITE_PERL_CPAN}
XMASTER_SITE_SUBDIR=	Sys
XPKGNAMEPREFIX=	p5-
X
XMAINTAINER=	pirzyk@FreeBSD.org
XCOMMENT=		Perl module to Retrieve list of filesystems and their properties
X
XPERL_MODBUILD=	yes
X
XMAN3=		Sys::Filesystem::Mswin32.3 \
X			Sys::Filesystem.3 \
X			Sys::Filesystem::Linux.3 \
X			Sys::Filesystem::Darwin.3 \
X			Sys::Filesystem::Cygwin.3 \
X			Sys::Filesystem::Aix.3 \
X			Sys::Filesystem::Unix.3 \
X			Sys::Filesystem::Dummy.3 \
X			Sys::Filesystem::Freebsd.3 \
X			Sys::Filesystem::Solaris.3
X
X.include <bsd.port.pre.mk>
X
X.if ${PERL_LEVEL} < 500600
XIGNORE=		requires perl 5.6.x or later. Install lang/perl5 then try again
X.endif
X
X.include <bsd.port.post.mk>
END-of-p5-Sys-Filesystem/Makefile
echo x - p5-Sys-Filesystem/distinfo
sed 's/^X//' >p5-Sys-Filesystem/distinfo << 'END-of-p5-Sys-Filesystem/distinfo'
XMD5 (Sys-Filesystem-1.21.tar.gz) = 99bdb1a37ed2fde8e6ebede2c36c117e
XSHA256 (Sys-Filesystem-1.21.tar.gz) = 9d5a706f730bbdf013d610c46e32b8c2bb8663382799976df8eb1e6fa17483c5
XSIZE (Sys-Filesystem-1.21.tar.gz) = 18352
END-of-p5-Sys-Filesystem/distinfo
echo x - p5-Sys-Filesystem/pkg-descr
sed 's/^X//' >p5-Sys-Filesystem/pkg-descr << 'END-of-p5-Sys-Filesystem/pkg-descr'
XRetrieve list of filesystems and their properties
X
XSys::Filesystem is intended to be a portable interface to list and query
Xfilesystem names and their properties. At the time of writing there were
Xonly Solaris and Win32 modules available on CPAN to perform this kind of
Xoperation. This module hopes to provide a consistant API to list all,
Xmounted, unmounted and special filesystems on a system, and query as
Xmany properties as possible with common aliases wherever possible.
X
XWWW: http://search.cpan.org/dist/Sys-Filesystem/
END-of-p5-Sys-Filesystem/pkg-descr
echo x - p5-Sys-Filesystem/pkg-plist
sed 's/^X//' >p5-Sys-Filesystem/pkg-plist << 'END-of-p5-Sys-Filesystem/pkg-plist'
X%%SITE_PERL%%/Sys/Filesystem.pm
X%%SITE_PERL%%/Sys/Filesystem/Aix.pm
X%%SITE_PERL%%/Sys/Filesystem/Cygwin.pm
X%%SITE_PERL%%/Sys/Filesystem/Darwin.pm
X%%SITE_PERL%%/Sys/Filesystem/Dummy.pm
X%%SITE_PERL%%/Sys/Filesystem/Freebsd.pm
X%%SITE_PERL%%/Sys/Filesystem/Linux.pm
X%%SITE_PERL%%/Sys/Filesystem/Mswin32.pm
X%%SITE_PERL%%/Sys/Filesystem/Solaris.pm
X%%SITE_PERL%%/Sys/Filesystem/Unix.pm
X@dirrm %%SITE_PERL%%/Sys/Filesystem
X@dirrmtry %%SITE_PERL%%/Sys
END-of-p5-Sys-Filesystem/pkg-plist
echo c - p5-Sys-Filesystem/files
mkdir -p p5-Sys-Filesystem/files > /dev/null 2>&1
echo x - p5-Sys-Filesystem/files/patch-lib-Sys-Filesystem.pm
sed 's/^X//' >p5-Sys-Filesystem/files/patch-lib-Sys-Filesystem.pm << 'END-of-p5-Sys-Filesystem/files/patch-lib-Sys-Filesystem.pm'
X--- lib/Sys/Filesystem.pm.orig	Fri May 26 12:06:39 2006
X+++ lib/Sys/Filesystem.pm	Fri May 26 12:06:40 2006
X@@ -108,7 +108,7 @@
X 	# Invert logic for regular
X 	if (exists $params->{regular}) {
X 		delete $params->{regular};
X-		$params->{regular} = undef;
X+		$params->{special} = undef;
X 	}
X 
X 	my @filesystems = ();
END-of-p5-Sys-Filesystem/files/patch-lib-Sys-Filesystem.pm
echo x - p5-Sys-Filesystem/files/patch-lib-Sys-Filesystem-Freebsd.pm
sed 's/^X//' >p5-Sys-Filesystem/files/patch-lib-Sys-Filesystem-Freebsd.pm << 'END-of-p5-Sys-Filesystem/files/patch-lib-Sys-Filesystem-Freebsd.pm'
X--- ./lib/Sys/Filesystem/Freebsd.pm.orig	Sat Mar 25 14:44:35 2006
X+++ ./lib/Sys/Filesystem/Freebsd.pm	Thu Jun  1 14:55:02 2006
X@@ -26,20 +26,33 @@
X use FileHandle;
X use Carp qw(croak);
X 
X+# For access to the getfsstat system call
X+require 'sys/syscall.ph';
X+require 'sys/mount.ph';
X+
X use vars qw($VERSION);
X $VERSION = '1.05' || sprintf('%d', q$Revision: 364 $ =~ /(\d+)/g);
X 
X+my $sizeof;
X+if ( &STATFS_VERSION == 0x20030518 ) {
X+	$sizeof = 472; # The size in bytes of the statfs structure
X+} else {
X+	croak "The statfs strucuture changed version (" . &STATFS_VERSION . ")\n";
X+}
X+# unpack format, we want the 3rd and the last 3 fields.
X+my $format = 'x8L' . 'x192' . ('A' . &MNAMELEN ) x 3 ;
X+
X sub new {
X 	ref(my $class = shift) && croak 'Class name required';
X 	my %args = @_;
X 	my $self = { };
X 
X 	$args{fstab} ||= '/etc/fstab';
X-	$args{mtab} ||= '/etc/mtab';
X-	$args{xtab} ||= '/etc/lib/nfs/xtab';
X+	# $args{mtab} ||= '/etc/mtab';  # Does not exist on FreeBSD
X+	$args{xtab} ||= '/var/db/mountdtab';
X 
X 	my @keys = qw(fs_spec fs_file fs_vfstype fs_mntops fs_freq fs_passno);
X-	my @special_fs = qw(swap proc devpts tmpfs);
X+	my @special_fs = qw(swap proc devpts devfs tmpfs);
X 
X 	# Read the fstab
X 	my $fstab = new FileHandle;
X@@ -60,24 +73,42 @@
X 		croak "Unable to open fstab file ($args{fstab})\n";
X 	}
X 
X-	# Read the mtab
X-	my $mtab = new FileHandle;
X-	if ($mtab->open($args{mtab})) {
X-		while (<$mtab>) {
X-			next if (/^\s*#/ || /^\s*$/);
X-			my @vals = split(/\s+/, $_);
X-			delete $self->{$vals[1]}->{unmounted} if exists $self->{$vals[1]}->{unmounted};
X-			$self->{$vals[1]}->{mounted} = 1;
X-			$self->{$vals[1]}->{mount_point} = $vals[1];
X-			$self->{$vals[1]}->{device} = $vals[0];
X-			$self->{$vals[1]}->{special} = 1 if grep(/^$vals[2]$/,qw(swap proc devpts tmpfs));
X-			for (my $i = 0; $i < @keys; $i++) {
X-				$self->{$vals[1]}->{$keys[$i]} = $vals[$i];
X-			}
X+	# Get the number of mounted fileystems we have
X+	my $buf = '';
X+	my $cnt = syscall(&SYS_getfsstat, $buf, length $buf, &MNT_NOWAIT);
X+
X+	# Fix a bug on some 5.x systems, the previous syscall may return 0...
X+	$cnt = 20 if ( ! $cnt );
X+
X+	# Preallocate the buffer memory per the syscall() requreiments
X+	$buf = ' ' x ( $sizeof * $cnt );
X+
X+	if ( ($cnt=syscall(&SYS_getfsstat, $buf, length $buf, &MNT_NOWAIT)) ) {
X+		for (my ($i) = 0; $i < $cnt; $i++) {
X+
X+			my $offset = ($i)? 'x' . ($i * $sizeof): '';
X+			my @vals = unpack ( $offset . $format, $buf);
X+
X+			delete $self->{$vals[3]}->{unmounted} if exists $self->{$vals[3]}->{unmounted};
X+			$self->{$vals[3]}->{mounted} = 1;
X+			$self->{$vals[3]}->{mount_point} = $vals[3];
X+			$self->{$vals[3]}->{device} = $vals[2];
X+			$self->{$vals[3]}->{special} = 1 if grep(/^$vals[1]$/,@special_fs);
X+
X+			$self->{$vals[3]}->{fs_spec} = $vals[2];
X+			$self->{$vals[3]}->{fs_file} = $vals[3];
X+			$self->{$vals[3]}->{fs_vfstype} = $vals[1];
X+			$self->{$vals[3]}->{fs_mntops} = 
X+				($vals[0] & &MNT_RDONLY)? 'ro': 'rw';
X+			$self->{$vals[3]}->{fs_mntops} .= ',noexec'
X+				if ($vals[0] & &MNT_NOEXEC);
X+			$self->{$vals[3]}->{fs_mntops} .= ',nosuid'
X+				if ($vals[0] & &MNT_NOSUID);
X+			$self->{$vals[3]}->{fs_mntops} .= ',nodev'
X+				if ($vals[0] & &MNT_NODEV);
X 		}
X-		$mtab->close;
X 	} else {
X-		croak "Unable to open mtab file ($args{mtab})\n";
X+		croak "Unable to retrieve mounted filesystem information\n";
X 	}
X 
X 	# Bless and return
END-of-p5-Sys-Filesystem/files/patch-lib-Sys-Filesystem-Freebsd.pm
exit

>Release-Note:
>Audit-Trail:
>Unformatted:



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200606012004.k51K4xsw091501>