-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpspmount
More file actions
executable file
·143 lines (111 loc) · 3.36 KB
/
pspmount
File metadata and controls
executable file
·143 lines (111 loc) · 3.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
#!/usr/bin/perl -w
# pspmount - PSP mount/umount script
# mounts psp to /mnt/psp by default
# Written by Aaron Blakely <aaron@ephasic.org>
#
# Distributed as part of PSPTools:
# http://github.com/ablakely/psptools
use strict;
use warnings;
my $mountpath = "/mnt/psp";
my $idx = 0;
my $createRestore = 0;
my $restoreMode = 0;
my $cfilePath = "";
my $rfilePath = "";
MODS:
if (not defined $ARGV[$idx]) { goto EXEC; }
if ($ARGV[$idx] eq "-V" || $ARGV[$idx] eq "-h" || $ARGV[$idx] eq "--help" || $ARGV[$idx] eq "--version") {
print "\npspmount v0.5: Automates the mounting process on systems which don't have automounting.\n";
print "Written by Aaron Blakely <aaron\@ephasic.org>\n\n";
print "Usage: $0 [-hp] [path]\n";
print " -h - Displays this message.\n";
print " -p [path] - Changes the mountpoint.\n";
print " -b [file] - Creates a backup image of the PSP.\n";
print " -r [file] - Restores the PSP from a backup image.\n\n";
print "pspmount is distributed as part of the psptools package: http://github.com/ablakely/psptools\n\n";
exit;
}
if ($ARGV[$idx] eq "-b" || $ARGV[$idx] eq "--backup") {
$createRestore = 1;
$cfilePath = $ARGV[++$idx];
unless (system "sync && umount $mountpath && rmdir $mountpath") {
$idx++;
goto MODS;
}
}
if ($ARGV[$idx] eq "-r" || $ARGV[$idx] eq "--restore") {
$restoreMode = 1;
$rfilePath = $ARGV[++$idx];
unless (system "sync && umount $mountpath && rmdir $mountpath") {
$idx++;
goto MODS;
}
}
if ($ARGV[$idx] eq "-p" || $ARGV[$idx] eq "--path") {
$mountpath = $ARGV[++$idx];
$idx++;
goto MODS;
}
EXEC:
if (`whoami` !~ /root/) {
die "This program requires root! Exiting...\n";
}
if (-e "$mountpath") {
unless (system "sync && umount $mountpath && rmdir $mountpath") {
exit;
}
}
my $scsiID;
my $blockDev;
my @partitions;
print "Looking for PSP...\n";
my @pspgrep = `dmesg | grep PSP`;
if ($pspgrep[-1] =~ /scsi (.*)/) {
my @s = split(" ", $1);
$scsiID = $s[0];
$scsiID =~ s/\:$//;
print "\nFOUND! \nADDR: $scsiID\n";
my @bdlookup = `dmesg | grep '$scsiID'`;
foreach my $lookup (@bdlookup) {
if ($lookup =~ /$scsiID: \[(.*)\]/) {
if (-e "/dev/$1") {
print "Block Device: $1\n";
my @pstrs = `dmesg | grep $1:`;
my @pstr = split(" ", $pstrs[-1]);
if (-e "/dev/$1" && !-e "/dev/".$1."1") {
die "Error: PSP found but memory stick is not inserted or formated? Exiting.\n";
}
print "Scanning for /dev/$1 partitions: \n";
for (my $i = 0; $i < scalar @pstr; $i++) {
if (-e "/dev/$pstr[$i]") {
print " Found partition: /dev/$pstr[$i]\n";
push(@partitions, $pstr[$i]);
}
}
print "Attempting to mount first partiton...\n";
if (!-e "$mountpath") {
system "mkdir $mountpath";
}
if (-e "/dev/$partitions[0]") {
unless (system "mount -o rw,noauto,async,user,umask=1000 /dev/$partitions[0] $mountpath") {
print "\nPSP mounted to $mountpath\n";
if ($createRestore == 1) {
print "Creating backup image of PSP: $cfilePath\n";
system "dd if=/dev/$partitions[0] of=$cfilePath";
}
if ($restoreMode == 1) {
print "Restoring PSP from $rfilePath\n";
system "dd if=$rfilePath of=/dev/$partitions[0]";
}
exit;
}
}
} else {
die "Found PSP but it's not mountable! Exiting.\n";
}
}
}
} else {
die "Can't find PSP in dmesg! Exiting.\n";
}