4 # This code is issued under the GNU General Public License.
5 # See the file COPYING in this distribution
7 # Copyright (C) 1998, Stelias Computing
9 # Modified for InterMezzo from Gordian's HSM bcache device/jcm module
10 # Copyright (C) 1999, Carnegie Mellon University
12 # Derived from InterMezzo's incontrol, modified for OBD's
13 # Copyright (C) 1999, Stelias Computing
18 BEGIN { require "asm/errno.ph" };
19 BEGIN { require "asm/ioctl.ph" };
21 # p2ph generated invalid macros for ioctl stuff, so I override some of it here
22 eval 'sub OBD_IOC_CREATE () { &_IOC(2, ord(\'f\'), 3, 4);}' unless
23 defined(&OBD_IOC_CREATE);
24 eval 'sub OBD_IOC_SETUP () { &_IOC(1, ord(\'f\'), 4, 4);}' unless
25 defined(&OBD_IOC_SETUP);
26 eval 'sub OBD_IOC_CLEANUP () { &_IOC(0, ord(\'f\'), 5, 0);}' unless
27 defined(&OBD_IOC_CLEANUP);
28 eval 'sub OBD_IOC_DESTROY () { &_IOC(1, ord(\'f\'), 6, 4);}' unless
29 defined(&OBD_IOC_DESTROY);
30 eval 'sub OBD_IOC_PREALLOCATE () { &_IOC(3, ord(\'f\'), 7, 4);}' unless
31 defined(&OBD_IOC_PREALLOCATE);
32 eval 'sub OBD_IOC_DEC_USE_COUNT () { &_IOC(0, ord(\'f\'), 8, 0);}' unless
33 defined(&OBD_IOC_DEC_USE_COUNT);
34 eval 'sub OBD_IOC_SETATTR () { &_IOC(1, ord(\'f\'), 9, 4);}' unless
35 defined(&OBD_IOC_SETATTR);
36 eval 'sub OBD_IOC_GETATTR () { &_IOC(2, ord(\'f\'), 10, 4);}' unless
37 defined(&OBD_IOC_GETATTR);
38 eval 'sub OBD_IOC_READ () { &_IOC(3, ord(\'f\'), 11, 4);}' unless
39 defined(&OBD_IOC_READ);
40 eval 'sub OBD_IOC_WRITE () { &_IOC(3, ord(\'f\'), 12, 4);}' unless
41 defined(&OBD_IOC_WRITE);
42 eval 'sub OBD_IOC_CONNECT () { &_IOC(2, ord(\'f\'), 13, 4);}' unless
43 defined(&OBD_IOC_CONNECT);
44 eval 'sub OBD_IOC_DISCONNECT () { &_IOC(1, ord(\'f\'), 14, 4);}' unless
45 defined(&OBD_IOC_DISCONNECT);
46 eval 'sub OBD_IOC_STATFS () { &_IOC(3, ord(\'f\'), 15, 4);}' unless
47 defined(&OBD_IOC_STATFS);
48 eval 'sub OBD_IOC_SYNC () { &_IOC(2, ord(\'f\'), 16, 4);}' unless
49 defined(&OBD_IOC_SYNC);
50 eval 'sub OBD_IOC_READ2 () { &_IOC(3, ord(\'f\'), 17, 4);}' unless
51 defined(&OBD_IOC_READ2);
52 eval 'sub OBD_IOC_FORMATOBD () { &_IOC(3, ord(\'f\'), 18, 4);}' unless
53 defined(&OBD_IOC_FORMATOBD);
54 eval 'sub OBD_IOC_PARTITION () { &_IOC(3, ord(\'f\'), 19, 4);}' unless
55 defined(&OBD_IOC_PARTITION);
56 eval 'sub OBD_IOC_ATTACH () { &_IOC(3, ord(\'f\'), 20, 4);}' unless
57 defined(&OBD_IOC_ATTACH);
58 eval 'sub OBD_IOC_DETACH () { &_IOC(3, ord(\'f\'), 21, 4);}' unless
59 defined(&OBD_IOC_DETACH);
60 eval 'sub OBD_IOC_COPY () { &_IOC(3, ord(\'f\'), 22, 4);}' unless
61 defined(&OBD_IOC_COPY);
62 eval 'sub OBD_IOC_MIGR () { &_IOC(3, ord(\'f\'), 23, 4);}' unless
63 defined(&OBD_IOC_MIGR);
64 eval 'sub OBD_SNAP_SETTABLE () { &_IOC(3, ord(\'f\'), 40, 4);}' unless
65 defined(&OBD_SNAP_SETTABLE);
66 eval 'sub OBD_SNAP_PRINTTABLE () { &_IOC(3, ord(\'f\'), 41, 4);}' unless
67 defined(&OBD_SNAP_PRINTTABLE);
69 eval 'sub OBD_EXT2_RUNIT () { &_IOC(3, ord(\'f\'), 61, 4);}' unless
70 defined(&OBD_EXT2_RUNIT);
72 eval 'sub ATTR_MODE () {1;}' unless defined(&ATTR_MODE);
73 eval 'sub ATTR_UID () {2;}' unless defined(&ATTR_UID);
74 eval 'sub ATTR_GID () {4;}' unless defined(&ATTR_GID);
75 eval 'sub ATTR_SIZE () {8;}' unless defined(&ATTR_SIZE);
76 eval 'sub ATTR_ATIME () {16;}' unless defined(&ATTR_ATIME);
77 eval 'sub ATTR_MTIME () {32;}' unless defined(&ATTR_MTIME);
78 eval 'sub ATTR_CTIME () {64;}' unless defined(&ATTR_CTIME);
90 GetOptions("f!" => \$file, "device=s" => \$::device, "fs=s" => $::filesystem) || die "Getoptions";
93 # get a console for the app
100 ('device' => {func => "Device", doc => "device <dev>: open another OBD device"},
101 'filesystem' => {func => "Filesystem", doc => "filesystem <dev>: partition for direct OBD device"},
102 'create' => {func => "Create", doc => "create: creates a new inode"},
103 'attach' => {func => "Attach", doc => "attach type [adapter bus tid lun]"},
104 'detach' => {func => "Detach", doc => "detach this device"},
105 'snapattach' => {func => "SnapAttach", doc => "snapattach snapno table"},
106 'snapset' => {func => "SnapSetTable", doc => "snapset tableno file" },
107 'snapprint' => {func => "SnapPrint", doc => "snapprint tableno"},
109 'testiterator' => {func => "TestIterator", doc => ""},
111 'snaptable' => {func => "SnapShotTable", doc => "snaptable: build a snapshot table (interactive)"},
112 'copy' => {func => "Copy", doc => "copy srcid tgtid"},
113 'migrate' => {func => "Migrate", doc => "migrate srcid tgtid"},
114 'format' => {func => "Format", doc => "format type adapter bus tid lun size"},
115 'partition' => {func => "Partition", doc => "partition type adapter bus tid lun partition size"},
116 'setup' => {func => "Setup", doc => "setup: link the ext2 partition (default /dev/loop0) to this obddev"},
117 'connect' => {func => "Connect", doc => "connect: allocates client ID for this session"},
118 'disconnect' => {func => "Disconnect", doc => "disconnect [id]: frees client resources"},
119 'sync' => {func => "Sync", doc => "sync: flushes buffers to disk"},
120 'destroy' => {func => "Destroy", doc => "setup: destroys an inode"},
121 'cleanup' => {func => "Cleanup", doc => "cleanup the minor obd device"},
122 'dec_use_count' => {func => "Decusecount", doc => "decreases the module use count so that the module can be removed following an oops"},
123 'read' => {func => "Read", doc => "read <inode> <count> [offset]"},
124 'fsread' => {func => "Read2", doc => "read <inode> <count> [offset]"},
125 'write' => {func => "Write", doc => "write <inode> <offset> <text>"},
126 'setattr' => {func => "Setattr", doc => "setattr <inode> [mode [uid [gid [size [atime [mtime [ctime]]]]]]]"},
127 'getattr' => {func => "Getattr", doc => "getattr <inode>: displays inode object attributes"},
128 'preallocate' => {func => "Preallocate", doc => "preallocate [num]: requests preallocation of num inodes."},
129 'statfs' => {func => "Statfs", doc => "statfs: filesystem status information"},
130 'help' => {func => \&Help, doc => "help: this message"},
131 'quit' => {func => \&Quit, doc => "see \"exit\""},
132 'exit' => {func => \&Quit, doc => "see \"quit\""}
136 # setup completion function
138 my @jcm_cmd_list = keys %commands;
146 Filesystem($::filesystem);
154 return $term->readline(@_);
167 $term = new Term::ReadLine 'obdcontrol ';
168 $attribs = $term->Attribs;
169 $attribs->{attempted_completion_function} = \&completeme;
170 $term->ornaments('md,me,,'); # bold face prompt
172 # make sure stdout is not buffered
173 STDOUT->autoflush(1);
176 # Get on with the show
180 #------------------------------------------------------------------------------
182 my ($text, $line, $start, $end) = @_;
183 if (substr($line, 0, $start) =~ /^\s*$/) {
184 $attribs->{completion_word} = \@jcm_cmd_list;
185 return $term->completion_matches($text,
186 $attribs->{'list_completion_function'});
193 my @completions = completeme($given, $given, 0, length($given));
194 if ($#completions == 0) {
195 $name = shift @completions;
201 # start making requests
204 $line = $term->readline("obdcontrol > ");
212 my @arg = split(' ', $line);
213 my $word = shift @arg;
219 $cmd = find_command($word);
222 printf STDERR "$word: No such command, or not unique.\n";
226 if ($cmd eq "help" || $cmd eq "exit" || $cmd eq "quit") {
227 return (&{$commands{$cmd}->{func}}(@arg));
231 return (&{$commands{$cmd}->{func}}(@arg));
234 # set the object store in the ext2 formatted block device
236 my $filesystem = shift;
237 $filesystem = "/dev/loop0" unless $filesystem;
239 $::filesystem = $filesystem;
240 if (!defined($::st = stat($filesystem))) {
241 die "Unable to stat $filesystem.\n";
245 # select the OBD device we talk to
250 $device = "/dev/obd0";
253 # Open the device, as we need an FD for the ioctl
254 sysopen(DEV_OBD, $device, 0) || die "Cannot open $device";
255 print "Device now $device\n";
266 if ($type eq "obdscsi" ) {
271 $data = pack("iiiii", $adapter, $bus, $tid, $lun, $size);
275 my $packed = pack("Lipip", $::client_id, length($type), $type, $datalen, $data);
277 my $rc = ioctl(DEV_OBD, &OBD_IOC_ATTACH, $packed);
280 print STDERR "ioctl failed: $!\n";
281 } elsif ($rc eq "0 but true") {
282 print "Finished (success)\n";
284 print "ioctl returned error code $rc.\n";
291 my $rc = ioctl(DEV_OBD, &OBD_IOC_DETACH, $data);
294 print STDERR "ioctl failed: $!\n";
295 } elsif ($rc eq "0 but true") {
296 print "Finished (success)\n";
298 print "ioctl returned error code $rc.\n";
306 my $type = "ext2_obd";
308 $data = pack("i", 4711);
311 my $len = length($type);
312 my $cl = length($data);
313 my $add = pack("p", $data);
314 print "type $type (len $len), datalen $datalen ($cl)\n";
315 my $packed = pack("Lipip", $::client_id, length($type), $type, $datalen, $data);
317 my $rc = ioctl(DEV_OBD, &OBD_EXT2_RUNIT, $packed);
320 print STDERR "ioctl failed: $!\n";
321 } elsif ($rc eq "0 but true") {
322 print "Finished (success)\n";
324 print "ioctl returned error code $rc.\n";
330 my $type = "snap_obd";
331 my $snaptableno = shift;
333 $data = pack("i", $snaptableno);
336 my $len = length($type);
337 my $cl = length($data);
338 my $add = pack("p", $data);
339 print "type $type (len $len), datalen $datalen ($cl)\n";
340 my $packed = pack("Lipip", $::client_id, length($type), $type, $datalen, $data);
342 my $rc = ioctl(DEV_OBD, &OBD_SNAP_PRINTTABLE, $packed);
345 print STDERR "ioctl failed: $!\n";
346 } elsif ($rc eq "0 but true") {
347 print "Finished (success)\n";
349 print "ioctl returned error code $rc.\n";
355 my $type = "snap_obd";
356 my $snaptableno = shift;
364 print "No such file $file\n";
367 $table = ReadSnapShotTable($file);
369 $snapcount = keys %{$table};
370 print "Snapcount $snapcount\n";
372 if ( ! defined $table->{0} ) {
373 print "No current snapshot in table! First make one\n";
376 $data = pack("ii", $snaptableno, $snapcount);
378 foreach my $time (sort keys %{$table}) {
379 $data .= pack("Ii", $time, $table->{$time});
383 my $len = length($type);
384 my $cl = length($data);
385 my $add = pack("p", $data);
386 print "type $type (len $len), datalen $datalen ($cl)\n";
387 my $packed = pack("Lipip", $::client_id, length($type), $type, $datalen, $data);
389 my $rc = ioctl(DEV_OBD, &OBD_SNAP_SETTABLE, $packed);
392 print STDERR "ioctl failed: $!\n";
393 } elsif ($rc eq "0 but true") {
394 print "Finished (success)\n";
396 print "ioctl returned error code $rc.\n";
403 my $type = "snap_obd";
411 # if ( ! -f $file ) {
412 # print "No such file $file\n";
415 # $table = ReadSnapShotTable($file);
416 $data = pack("iii", $snapdev, $snapno, $tableno);
419 my $len = length($type);
420 my $cl = length($data);
421 my $add = pack("p", $data);
422 print "type $type (len $len), datalen $datalen ($cl)\n";
423 my $packed = pack("Lipip", $::client_id, length($type), $type, $datalen, $data);
425 my $rc = ioctl(DEV_OBD, &OBD_IOC_ATTACH, $packed);
428 print STDERR "ioctl failed: $!\n";
429 } elsif ($rc eq "0 but true") {
430 print "Finished (success)\n";
432 print "ioctl returned error code $rc.\n";
439 my $file = &readl("enter file name: ");
443 my $table = ReadSnapShotTable($file);
446 PrintSnapShotTable($table);
447 my $action = &readl("Add, Delete or Quit [adq]: ");
448 goto done if ($action =~ "^q.*" );
449 goto add if ($action =~ "^a.*");
450 goto del if ($action =~ "^d.*");
454 my $idx = &readl("enter index where you want this snapshot: ");
455 my $time = &readl("enter time or 'now' or 'current': ");
456 my $oldtime = SnapFindTimeFromIdx($idx, $table);
457 if (defined $oldtime) {
458 print "This already exists, first clean up\n";
462 if ( $time eq 'now' ) {
464 } elsif ( $time eq 'current' ) {
467 $table->{$time} = $idx;
471 $didx = &readl("Enter index to delete: ");
472 my $deltime = SnapFindTimeFromIdx($didx, $table);
473 delete $table->{$deltime} if defined $deltime;
477 my $ok = &readl("OK with new table? [Yn]: ");
478 unless ( $ok eq "no" ) {
479 WriteSnapShotTable($file, $table);
483 sub SnapFindTimeFromIdx {
487 foreach my $time ( keys %{$table} ) {
488 if ( $table->{$time} == $idx ) {
495 sub PrintSnapShotTable {
499 foreach $time ( sort keys %{$table} ) {
500 my $stime = localtime($time);
504 printf "Time: %s -- Index %d\n", $stime, $table->{$time};
508 sub ReadSnapShotTable {
515 my ($time, $index) = split ;
516 $table->{$time} = $index;
520 PrintSnapShotTable($table);
525 sub WriteSnapShotTable {
530 foreach my $time ( sort keys %{$table} ) {
531 print FH "$time $table->{$time}\n";
540 my $data = pack("III", $::client_id, $srcid, $tgtid);
543 my $packed = pack("ip", $datalen, $data);
544 my $rc = ioctl(DEV_OBD, &OBD_IOC_COPY, $packed);
547 print STDERR "ioctl failed: $!\n";
548 } elsif ($rc eq "0 but true") {
549 print "Finished (success)\n";
551 print "ioctl returned error code $rc.\n";
559 my $data = pack("III", $::client_id, $srcid, $tgtid);
562 my $packed = pack("ip", $datalen, $data);
563 my $rc = ioctl(DEV_OBD, &OBD_IOC_MIGR, $packed);
566 print STDERR "ioctl failed: $!\n";
567 } elsif ($rc eq "0 but true") {
568 print "Finished (success)\n";
570 print "ioctl returned error code $rc.\n";
578 my $data = pack("i", $size);
581 my $packed = pack("ip", $datalen, $data);
582 my $rc = ioctl(DEV_OBD, &OBD_IOC_FORMATOBD, $packed);
585 print STDERR "ioctl failed: $!\n";
586 } elsif ($rc eq "0 but true") {
587 print "Finished (success)\n";
589 print "ioctl returned error code $rc.\n";
597 my $data = pack("ii", $partno, $size);
600 my $packed = pack("ip", $datalen, $data);
601 my $rc = ioctl(DEV_OBD, &OBD_IOC_PARTITION, $packed);
604 print STDERR "ioctl failed: $!\n";
605 } elsif ($rc eq "0 but true") {
606 print "Finished (success)\n";
608 print "ioctl returned error code $rc.\n";
618 $type = "ext2_obd" unless $type;
620 if ( $type eq "ext2_obd" ) {
622 $dev = $::st->rdev() unless $dev;
623 $data = pack("i", $dev);
627 my $packed = pack("ip", $datalen, $data);
628 my $rc = ioctl(DEV_OBD, &OBD_IOC_SETUP, $packed);
631 print STDERR "ioctl failed: $!\n";
632 } elsif ($rc eq "0 but true") {
633 print "Finished (success)\n";
635 print "ioctl returned error code $rc.\n";
641 my $rc = ioctl(DEV_OBD, &OBD_IOC_CLEANUP, $err);
644 print STDERR "ioctl failed: $!\n";
645 } elsif ($rc eq "0 but true") {
646 print "Finished (success)\n";
649 print "ioctl returned error code $rc.\n";
658 $rc = ioctl(DEV_OBD, &OBD_IOC_CONNECT, $packed);
659 $id = unpack("I", $packed);
662 print STDERR "ioctl failed: $!\n";
663 } elsif ($rc eq "0 but true") {
665 print "Client ID : $id\n";
666 print "Finished (success)\n";
668 print "ioctl returned error code $rc.\n";
680 print "syntax: disconnect [client ID]\n";
681 print "When client ID is not given, the last valid client ID to be returned by a\n";
682 print "connect command this session is used; there is no such ID.\n";
686 my $packed = pack("L", $id);
687 my $rc = ioctl(DEV_OBD, &OBD_IOC_DISCONNECT, $packed);
690 print STDERR "ioctl failed: $!\n";
691 } elsif ($rc eq "0 but true") {
692 $::client_id = undef;
693 print "Finished (success)\n";
695 print "ioctl returned error code $rc.\n";
705 if (defined($quiet) && !($quiet eq "quiet")) {
706 print "syntax: create [number of objects [quiet]]\n";
710 my $packed = pack("IL", $::client_id, $prealloc);
711 if (!defined($arg) || scalar($arg) < 2) {
712 print "Creating 1 object...\n";
713 $rc = ioctl(DEV_OBD, &OBD_IOC_CREATE, $packed);
714 if (!defined($quiet)) {
715 my $ino = unpack("L", $packed);
716 print "Created object #$ino.\n";
721 print "Creating " . scalar($arg) . " objects...\n";
722 for ($i = 0; $i < scalar($arg); $i++) {
723 $rc = ioctl(DEV_OBD, &OBD_IOC_CREATE, $packed);
724 my $ino = unpack("L", $packed);
725 if (!($rc eq "0 but true")) {
727 $packed = pack("IL", $::client_id, $prealloc);
728 } elsif (!defined($quiet)) {
729 $packed = pack("IL", $::client_id, $prealloc);
730 print "Created object #$ino.\n";
736 print STDERR "ioctl failed: $!\n";
737 } elsif ($rc eq "0 but true") {
738 print "Finished (success)\n";
740 print "ioctl returned error code $rc.\n";
746 my $rc = ioctl(DEV_OBD, &OBD_IOC_SYNC, $err);
749 print STDERR "ioctl failed: $!\n";
750 } elsif ($rc eq "0 but true") {
751 print "Finished (success)\n";
753 print "ioctl returned error code $rc.\n";
758 if (!defined($::client_id)) {
759 print "You must first ``connect''.\n";
765 if (!defined($arg) || scalar($arg) < 1) {
766 print "destroy requires the object number to destroy.\n";
770 print "Destroying object $arg...\n";
771 my $packed = pack("IL", $::client_id, $arg);
772 my $rc = ioctl(DEV_OBD, &OBD_IOC_DESTROY, $packed);
775 print STDERR "ioctl failed: $!\n";
776 } elsif ($rc eq "0 but true") {
777 print "Finished (success)\n";
779 print "ioctl returned error code $rc.\n";
784 if (!defined($::client_id)) {
785 print "You must first ``connect''.\n";
791 if (!defined($inode) || scalar($inode) < 1) {
792 print "invalid arguments; type \"help getattr\" for a synopsis\n";
797 my $packed = pack("ILsx2lLLLI", $::client_id, $inode, 0, 0, 0, 0, 0, 0, 0,
799 my $rc = ioctl(DEV_OBD, &OBD_IOC_GETATTR, $packed);
802 print STDERR "ioctl failed: $!\n";
803 } elsif ($rc eq "0 but true") {
804 my ($valid, $mode, $uid, $gid, $size, $atime, $mtime, $ctime, $flags);
805 ($valid, $mode, $uid, $gid, $size, $atime, $mtime, $ctime, $flags) =
806 unpack("ISssx2lLLLI", $packed);
808 printf("Inode: %d Mode: %o\n", $inode, $mode);
809 printf("User: %6d Group: %6d Size: %d\n", $uid, $gid, $size);
810 printf("ctime: %08lx -- %s\n", $ctime, scalar(gmtime($ctime)));
811 printf("atime: %08lx -- %s\n", $atime, scalar(gmtime($atime)));
812 printf("mtime: %08lx -- %s\n", $mtime, scalar(gmtime($mtime)));
813 printf("flags: %08x\n", $flags);
814 print "Finished (success)\n";
816 print "ioctl returned error code $rc.\n";
821 if (!defined($::client_id)) {
822 print "You must first ``connect''.\n";
828 my $mode = oct(shift);
842 if (defined($size)) {
843 $valid |= &ATTR_SIZE;
845 if (defined($atime)) {
846 $valid |= &ATTR_ATIME;
848 if (defined($mtime)) {
849 $valid |= &ATTR_MTIME;
851 if (defined($ctime)) {
852 $valid |= &ATTR_CTIME;
854 if (defined($mode)) {
855 $valid |= &ATTR_MODE;
858 if (!defined($inode) || scalar($inode) < 1) {
859 print "invalid arguments; type \"help setattr\" for a synopsis\n";
864 # unsigned int ia_valid; (32)
865 # umode_t ia_mode; (16)
868 # -- 16 bit alignment here! --
869 # off_t ia_size; (32)
870 # time_t ia_atime; (32)
871 # time_t ia_mtime; (32)
872 # time_t ia_ctime; (32)
873 # unsigned int ia_attr_flags; (32)
876 printf "valid is %x, mode is %o\n", $valid, $mode;
877 my $packed = pack("ILLSssx2ILLLL", $::client_id, $inode, $valid, $mode,
878 $uid, $gid, $size, $atime, $mtime, $ctime, 0);
879 my $rc = ioctl(DEV_OBD, &OBD_IOC_SETATTR, $packed);
882 print STDERR "ioctl failed: $!\n";
883 } elsif ($rc eq "0 but true") {
884 print "Finished (success)\n";
886 print "ioctl returned error code $rc.\n";
891 if (!defined($::client_id)) {
892 print "You must first ``connect''.\n";
900 if (!defined($inode) || scalar($inode) < 1 || !defined($count) ||
901 $count < 1 || (defined($offset) && $offset < 0)) {
902 print "invalid arguments; type \"help read\" for a synopsis\n";
906 if (!defined($offset)) {
910 print("Reading $count bytes starting at byte $offset from object " .
913 # "allocate" a large enough buffer
914 my $buf = sprintf("%${count}s", " ");
915 die "suck" if (length($buf) != $count);
917 # the perl we're using doesn't support pack type Q, and offset is 64 bits
918 my $packed = pack("ILpLLL", $::client_id, $inode, $buf, $count, $offset, 0);
920 my $rc = ioctl(DEV_OBD, &OBD_IOC_READ, $packed);
922 $retval = unpack("l", $packed);
925 print STDERR "ioctl failed: $!\n";
926 } elsif ($rc eq "0 but true") {
928 print substr($buf, 0, $retval);
929 print "\nRead $retval of an attempted $count bytes.\n";
930 print "Finished (success)\n";
932 print "Finished (error $retval)\n";
935 print "ioctl returned error code $rc.\n";
940 if (!defined($::client_id)) {
941 print "You must first ``connect''.\n";
949 if (!defined($inode) || scalar($inode) < 1 || !defined($count) ||
950 $count < 1 || (defined($offset) && $offset < 0)) {
951 print "invalid arguments; type \"help read\" for a synopsis\n";
955 if (!defined($offset)) {
959 print("Reading $count bytes starting at byte $offset from object " .
962 # "allocate" a large enough buffer
963 my $buf = sprintf("%${count}s", " ");
964 die "suck" if (length($buf) != $count);
966 # the perl we're using doesn't support pack type Q, and offset is 64 bits
967 my $packed = pack("ILpLLL", $::client_id, $inode, $buf, $count, $offset, 0);
969 my $rc = ioctl(DEV_OBD, &OBD_IOC_READ2, $packed);
971 $retval = unpack("l", $packed);
974 print STDERR "ioctl failed: $!\n";
975 } elsif ($rc eq "0 but true") {
977 print substr($buf, 0, $retval);
978 print "\nRead $retval of an attempted $count bytes.\n";
979 print "Finished (success)\n";
981 print "Finished (error $retval)\n";
984 print "ioctl returned error code $rc.\n";
989 if (!defined($::client_id)) {
990 print "You must first ``connect''.\n";
996 my $text = join(' ', @_);
997 my $count = length($text);
999 if (!defined($inode) || scalar($inode) < 1 || !defined($offset) ||
1000 scalar($offset) < 0) {
1001 print "invalid arguments; type \"help write\" for a synopsis\n";
1005 if (!defined($text)) {
1010 print("Writing $count bytes starting at byte $offset to object " .
1013 # the perl we're using doesn't support pack type Q
1014 my $packed = pack("ILpLLL", $::client_id, $inode, $text, $count, $offset, 0);
1015 my $rc = ioctl(DEV_OBD, &OBD_IOC_WRITE, $packed);
1017 $retval = unpack("l", $packed);
1020 print STDERR "ioctl failed: $!\n";
1021 } elsif ($rc eq "0 but true") {
1023 print "\nWrote $retval of an attempted $count bytes.\n";
1024 print "Finished (success)\n";
1026 print "Finished (error $retval)\n";
1029 print "ioctl returned error code $rc.\n";
1036 if (!defined($::client_id)) {
1037 print "You must first ``connect''.\n";
1041 if (!defined($arg) || scalar($arg) < 1 || scalar($arg) > 32) {
1045 print "Preallocating $arg inodes...\n";
1046 my $packed = pack("LLx128", $::client_id, $arg);
1047 # client id, alloc, inodes[32]
1049 my $rc = ioctl(DEV_OBD, &OBD_IOC_PREALLOCATE, $packed);
1052 print STDERR "ioctl failed: $!\n";
1053 } elsif ($rc eq "0 but true") {
1054 my $alloc = unpack("x4L", $packed);
1055 my @inodes = unpack("x8L32", $packed);
1058 print "Got $alloc inodes: ";
1059 foreach $i (@inodes) {
1062 print "\nFinished (success)\n";
1064 print "ioctl returned error code $rc.\n";
1069 my $rc = ioctl(DEV_OBD, &OBD_IOC_DEC_USE_COUNT, 0);
1072 print STDERR "ioctl failed: $!\n";
1073 } elsif ($rc eq "0 but true") {
1074 print "Finished (success)\n";
1076 print "ioctl returned error code $rc.\n";
1081 if (!defined($::client_id)) {
1082 print "You must first ``connect''.\n";
1094 # __kernel_fsid_t f_fsid; (64 bits)
1099 my $packed = pack("LLLLLLLIILL6", $::client_id, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1102 my $rc = ioctl(DEV_OBD, &OBD_IOC_STATFS, $packed);
1105 print STDERR "ioctl failed: $!\n";
1106 } elsif ($rc eq "0 but true") {
1107 # skip both the conn_id and the fs_type in the buffer
1108 my ($bsize, $blocks, $bfree, $bavail, $files, $ffree) =
1109 unpack("x4x4LLLLLL", $packed);
1110 print("$bsize byte blocks: $blocks, " . ($blocks - $bfree) . " used, " .
1111 "$bfree free ($bavail available).\n");
1112 print "$files files, " . ($files - $ffree) . " used, $ffree free.\n";
1113 print "Finished (success)\n";
1115 print "ioctl returned error code $rc.\n";
1122 if ( !$arg || !$commands{$arg} ) {
1123 print "Comands: ", join( ' ', @jcm_cmd_list), "\n";
1125 print "Usage: " . $commands{$arg}->{doc} . "\n";
1131 print "Disconnecting active session ($::client_id)...";
1132 Disconnect($::client_id);