defined(&OBD_IOC_COPY);
eval 'sub OBD_IOC_MIGR () { &_IOC(3, ord(\'f\'), 23, 4);}' unless
defined(&OBD_IOC_MIGR);
+eval 'sub OBD_IOC_PUNCH () { &_IOC(3, ord(\'f\'), 24, 4);}' unless
+ defined(&OBD_IOC_PUNCH);
eval 'sub OBD_SNAP_SETTABLE () { &_IOC(3, ord(\'f\'), 40, 4);}' unless
defined(&OBD_SNAP_SETTABLE);
eval 'sub OBD_SNAP_PRINTTABLE () { &_IOC(3, ord(\'f\'), 41, 4);}' unless
my %commands =
('device' => {func => "Device", doc => "device <dev>: open another OBD device"},
'create' => {func => "Create", doc => "create [<num> [<mode> [quiet]]]: create new object(s) (files, unless mode is given)"},
- 'attach' => {func => "Attach", doc => "attach { ext2_obd | snap_obd snapdev snapidx tableno | scsi_obd adapter bus tid lun }: attach this minor device to the specified driver" },
+ 'attach' => {func => "Attach", doc => "attach { obdext2 | obdsnap snapdev snapidx tableno | obdscsi adapter bus tid lun }: attach this minor device to the specified driver" },
'detach' => {func => "Detach", doc => "detach this minor device"},
'testext2iterator' => {func => "TestExt2Iterator", doc => "test ext2 iterator function"},
'snapset' => {func => "SnapSetTable", doc => "snapset <tableno> <file>: set the table (created with snaptable) as table #tableno" },
'migrate' => {func => "Migrate", doc => "migrate <srcid> <tgtid>: migrate data from one object to another"},
'partition' => {func => "Partition", doc => "partition <type> <adapter> <bus> <tid> <lun> <partition> <size>: create a partition"},
'format' => {func => "Format", doc => "format <type> <adapter> <bus> <tid> <lun> <size>: format a partition"},
- 'setup' => {func => "Setup", doc => "setup [type]: link this OBD device to the underlying device (default type ext2_obd)"},
+ 'setup' => {func => "Setup", doc => "setup [type]: link this OBD device to the underlying device (default type obdext2)"},
'connect' => {func => "Connect", doc => "connect: allocates client ID for this session"},
'disconnect' => {func => "Disconnect", doc => "disconnect [id]: frees client resources"},
'sync' => {func => "Sync", doc => "sync: flushes buffers to disk"},
'read' => {func => "Read", doc => "read <id> <count> [offset]: read data from object"},
'fsread' => {func => "Read2", doc => "read <id> <count> [offset]: read data from object"},
'write' => {func => "Write", doc => "write <id> <offset> <text>: write data to object"},
+ 'punch' => {func => "Punch", doc => "punch <id> <start> <count>: punch a hole in object"},
'setattr' => {func => "Setattr", doc => "setattr <id> [mode [uid [gid [size [atime [mtime [ctime]]]]]]]: sets object attributes"},
'getattr' => {func => "Getattr", doc => "getattr <id>: displays object attributes"},
'preallocate' => {func => "Preallocate", doc => "preallocate [num]: requests preallocation of num objects."},
if ( ! $type ) {
print "error: missing type\n";
usage:
- print "usage: attach {ext2_obd | snap_obd | scsi_obd}\n";
+ print "usage: attach {obdext2 | obdsnap | obdscsi}\n";
return;
}
- if ($type eq "scsi_obd" ) {
+ if ($type eq "obdscsi" ) {
my $adapter = shift;
my $bus = shift;
my $tid = shift;
$data = pack("iiii", $adapter, $bus, $tid, $lun);
$datalen = 4 * 4;
- } elsif ($type eq "snap_obd" ) {
+ } elsif ($type eq "obdsnap" ) {
my $snapdev = shift;
my $snapidx = shift;
my $tableno = shift;
$data = pack("iii", $snapdev, $snapidx, $tableno);
$datalen = 3 * 4;
- } elsif ($type eq "ext2_obd") {
+ } elsif ($type eq "obdext2") {
$data = pack("i", 4711); # bogus data
$datalen = 0;
} else {
}
my $err = 0;
- my $type = "ext2_obd";
+ my $type = "obdext2";
$data = pack("i", 4711); # bogus data
$datalen = 4;
}
my $err = 0;
- my $type = "snap_obd";
+ my $type = "obdsnap";
$data = pack("i", 4711); # bogus data
$datalen = 4;
# ready for the ioctl
my $err = 0;
- my $type = "snap_obd";
+ my $type = "obdsnap";
$data = pack("i", $currentindex); # slot of previous current snapshot
$datalen = 4;
sub SnapPrint {
my $err = 0;
- my $type = "snap_obd";
+ my $type = "obdsnap";
my $snaptableno = shift;
$data = pack("i", $snaptableno);
sub SnapSetTable {
my $err = 0;
- my $type = "snap_obd";
+ my $type = "obdsnap";
my $snaptableno = shift;
my $file = shift;
my $snapcount;
$count = 0;
}
- print("Writing $count bytes starting at byte $offset to object " .
- "$id...\n");
+ print("Writing $count bytes starting at byte $offset to object $id...\n");
my $obdo;
$obdo->{id} = $id;
}
}
+sub Punch {
+ if (!defined($::client_id)) {
+ print "You must first ``connect''.\n";
+ return;
+ }
+
+ my $id = shift;
+ my $start = shift;
+ my $count = shift;
+
+ if (!defined($id) || scalar($id) < 1 || !defined($start) ||
+ scalar($start) < 0 || !defined($count) || scalar($count) < 0) {
+ print "invalid arguments; type \"help punch\" for a synopsis\n";
+ return;
+ }
+
+ print("Punching $count bytes starting at byte $start in object $id...\n");
+
+ my $obdo;
+ $obdo->{id} = $id;
+
+ # the perl we're using doesn't support pack type Q
+ my $packed = pack("L", $::client_id) . obdo_pack($obdo) .
+ pack("p LL LL", $buf, $start, $count);
+
+ my $rc = ioctl(DEV_OBD, &OBD_IOC_PUNCH, $packed);
+
+ $retval = unpack("l", $packed);
+
+ if (!defined $rc) {
+ print STDERR "ioctl failed: $!\n";
+ } elsif ($rc eq "0 but true") {
+ if ($retval >= 0) {
+ print "\nPunched $retval of an attempted $count bytes.\n";
+ print "Finished (success)\n";
+ } else {
+ print "Finished (error $retval)\n";
+ }
+ } else {
+ print "ioctl returned error code $rc.\n";
+ }
+}
+
sub Preallocate {
my $num = shift;