Created
December 3, 2016 17:17
-
-
Save kamawanu/0d8ebeb71de623c316aec4c0446c1b00 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/perl | |
# | |
use strict; | |
no strict (qw(refs)); | |
use Carp; | |
# | |
die "must runs on linux" unless $^O eq "linux"; | |
# | |
my $testmode=0; | |
# | |
{ | |
my($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size, | |
$atime,$mtime,$ctime,$blksize,$blocks) | |
= my(@stat) = stat("/proc/self/fd/0"); | |
####warn join ";",@stat; | |
####die join ";",map { sprintf "%08x",$_ } @stat; | |
$testmode = $dev < 0x100; | |
} | |
# | |
my($nid, $filesys)= split( ";", $ARGV[0] ); | |
# | |
##open RFC, $cachefile; | |
##while(<RFC>){ | |
## my($part,$sig,$vo)=split(/\s/,$_,4); | |
## if( defined $sig && "ID:$sig" eq $nid ){ | |
## my ($sig,$vo) = getvolid($part); # verify | |
## $filesys ||= "vfat,uid=500,noexec"; | |
## mount($part,$filesys) if( defined $sig && "ID:$sig" eq $nid ); | |
## } | |
##} | |
##close RFC; | |
# | |
my @partitions = (); | |
open(PT,"/proc/partitions") || die "no /proc"; | |
my %drives= (); | |
while(<PT>){ | |
$_ =~ s/^\s+|\s+$//; | |
my($major,$minor,$blocks,$name,@other)=split(/\s+/,$_); | |
next if $name =~ /^lvm/; | |
print "major=$major minor=$minor blocks=$blocks name=$name\n" if $^P; | |
next unless $major > 0 && $blocks > 2; | |
####print "#<\n" if $^P; | |
my($main,$bb)=unpack("a3a",$name ); | |
push @partitions, my $info = [ $name, $blocks, $main, $bb ]; | |
$drives{$main} = $info if $bb eq ""; | |
} | |
close PT; | |
my @activepartitions = map { $partitions[$_] } grep { differ($_) } ( 0.. $#partitions ); | |
sub differ($){ | |
my $aa = $partitions[$_]; | |
my $bb = $partitions[$_+1]; | |
#### warn $aa->[2]; warn $bb->[2]; | |
if( $aa->[2] ne $bb->[2] ){ | |
return 1; | |
} | |
if( $aa->[3] eq "" ){ | |
if( $drives{$aa->[2]}->[1] < $bb->[1] ){ | |
return 1; | |
} | |
} else { | |
if( $drives{$aa->[2]}->[1] > $aa->[1] ){ | |
return 1; | |
} | |
} | |
return 0; | |
} | |
#####@activepartitions = @partitions; | |
if( $testmode ){ | |
####die; | |
use Data::Dumper; | |
die Data::Dumper::Dumper( \@activepartitions ); | |
exit; | |
} | |
##open FC, ">${cachefile}.tmp"; | |
foreach my $part (@activepartitions){ | |
my ($sig,$vo) = getvolid($part->[0]); | |
next unless defined $sig; | |
print STDERR "# $part->[0] \"$sig\" \"$vo\"\n"; | |
if( defined $sig && "ID:$sig" eq $nid ){ | |
$filesys ||= "vfat,uid=500,noexec"; | |
mount($part->[0],$filesys); | |
last; | |
} | |
} | |
# | |
sub mount($$) | |
{ | |
my($part,$filesys)=@_; | |
print "-fstype=$filesys,iocharset=euc-jp,check=normal :/dev/$part"; | |
exit; | |
} | |
# | |
sub getvolid($) | |
{ | |
open(RD,"/dev/$_[0]"); | |
binmode(RD); | |
sysread(RD,my $buffer,512)|| return undef; | |
close RD; | |
my $magic = unpack( 'a3', $buffer ); | |
return (undef,undef) unless $magic =~ /^\xEB.\x90/; | |
my $nfat = unpack( 'x22S', $buffer ); | |
# http://hjem.get2net.dk/rune_moeller_barnkob/filesystems/fat32.html | |
# http://www.ntfs.com/fat-partition-sector.htm | |
my $formatmap = [ | |
[ "x67i", "x71A11" ], # fat32 | |
[ "x39i", "x43A11" ], # fat16 | |
]; | |
####croak "$_[0] is unrecognized format($nfat)" unless defined $formatmap->{$nfat}; | |
return ( | |
sprintf("%08x",unpack( $formatmap->[$nfat > 0]->[0], $buffer )), | |
unpack( $formatmap->[$nfat > 0 ]->[1],$buffer) | |
); | |
} | |
# |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/perl | |
# | |
use strict; | |
# | |
my($host,$resourcename)=split(":",shift ); | |
# | |
print "-fstype=smbfs,iocharset=euc-jp,codepage=cp932 ://$host/$resourcename\n"; | |
# |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment