Henry's Notebook
Many strange things
搜索
菜单
导航
首页
最近更改
随机页面
帮助
Henry's Home
个人资料
个人资料
创建账户
登录
消息
目前您没有通知。请访问您的
讨论页
以查看过去消息。
页面工具
内容页面
讨论
查看源代码
历史
首页
»
页面s
查看“Partmount”的源代码
←
Partmount
页面上次由
HenryHu
编辑于13年前
因为以下原因,您没有权限编辑本页:
您所请求的操作仅限于该用户组的用户使用:emailconfirmed
您可以查看与复制此页面的源代码。
[[Category:脚本]] FreeBSD上,在设备插入(例如插了优盘)之后,根据信息自动挂载分区的脚本。 配合[[devd]]使用。 <source lang="perl"> #!/usr/bin/perl sub logmsg { my ($msg) = @_; $msg =~ s/'/"/g; system("logger '[partmount] $msg'"); } sub query_dev { my ($name) = @_; $namelen = 0; $ret = ""; $devs = `gpart list | grep Name`; foreach $i (split(/\n/, $devs)) { $i =~ m/.*?Name: (.*)$/; $dev = $1; $j =`glabel status $dev 2>&1`; if ($? eq 0) { foreach $line (split(/\n/, $j)) { if ($line =~ m/^$name /) { if (substr($line, 0, $namelen) == $name) { # In fact, maybe there are several # devices with the same label... # But what can we do... $ret = $dev; } } elsif ($line =~ m/^( *Name) *Status *Components$/) { $namepart = $1; $namelen = length($namepart); } } } } return $ret; } if (not $ARGV[0] =~ m!(.*)?/(.*)!) { print "Format error."; exit(1); } $parttype = $1; $partname = $2; $devname = query_dev($ARGV[0]); $succ_sound = "/usr/local/share/wesnoth/sounds/arrive.wav"; $err_sound = "/usr/local/share/wesnoth/sounds/bell.wav"; logmsg("$partname inserted, type: $parttype, device: $devname"); if ($devname =~ m/^ad0/) { $result = ""; $retcode = -3; } elsif ($parttype =~ m/ntfs/) { mkdir("/mnt/$partname"); $result = `/usr/local/bin/ntfs-3g -o uid=1001,umask=022,fmask=133 /dev/$parttype/$partname /mnt/$partname 2>&1`; $retcode = $?; } elsif ($parttype =~ m/msdosfs/) { if ($partname =~ m/IPOD/) { $result = ""; $retcode = -2; } else { mkdir("/mnt/$partname"); $result = `/sbin/mount_msdosfs -m 775 -L zh_CN.UTF-8 -u 1001 /dev/$parttype/$partname /mnt/$partname 2>&1`; $retcode = $?; } } if ($retcode == 0) { logmsg("Mount successed."); system("/usr/local/bin/mplayer -really-quiet $succ_sound"); } elsif ($retcode == -3) { logmsg("Local partition found. Ignored.\n"); } elsif ($retcode == -2) { logmsg("Found iPod, ejecting.\n"); system("/sbin/camcontrol eject $devname"); } elsif ($retcode == -1) { logmsg("failed to execute: $!\n"); } elsif ($retcode & 127) { logmsg("Mount failed. child died with signal " . ($retcode & 127) . " , " . (($retcode & 128) ? 'with' : 'without') . " coredump\n"); logmsg("Child output: $result"); system("/usr/local/bin/mplayer -really-quiet $err_sound"); } else { logmsg("child exited with value " . ($retcode >> 8) . "\n"); logmsg("Child output: $result"); system("/usr/local/bin/mplayer -really-quiet $err_sound"); } </source>
返回至
Partmount
。