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);
65 eval 'sub ATTR_MODE () {1;}' unless defined(&ATTR_MODE);
66 eval 'sub ATTR_UID () {2;}' unless defined(&ATTR_UID);
67 eval 'sub ATTR_GID () {4;}' unless defined(&ATTR_GID);
68 eval 'sub ATTR_SIZE () {8;}' unless defined(&ATTR_SIZE);
69 eval 'sub ATTR_ATIME () {16;}' unless defined(&ATTR_ATIME);
70 eval 'sub ATTR_MTIME () {32;}' unless defined(&ATTR_MTIME);
71 eval 'sub ATTR_CTIME () {64;}' unless defined(&ATTR_CTIME);
83 GetOptions("f!" => \$file, "device=s" => \$::device, "fs=s" => $::filesystem) || die "Getoptions";
86 # get a console for the app
93 ('device' => {func => "Device", doc => "device <dev>: open another OBD device"},
94 'filesystem' => {func => "Filesystem", doc => "filesystem <dev>: partition for direct OBD device"},
95 'create' => {func => "Create", doc => "create: creates a new inode"},
96 'attach' => {func => "Attach", doc => "attach type [adapter bus tid lun]"},
97 'detach' => {func => "Detach", doc => "detach this device"},
98 'snapattach' => {func => "SnapAttach", doc => "snapattach snapno snapcount time1 index1 .... timek indexk"},
99 'snaptable' => {func => "SnapShotTable", doc => "snaptable: build a snapshot table (interactive)"},
100 'copy' => {func => "Copy", doc => "copy srcid tgtid"},
101 'migrate' => {func => "Migrate", doc => "migrate srcid tgtid"},
102 'format' => {func => "Format", doc => "format type adapter bus tid lun size"},
103 'partition' => {func => "Partition", doc => "partition type adapter bus tid lun partition size"},
104 'setup' => {func => "Setup", doc => "setup: link the ext2 partition (default /dev/loop0) to this obddev"},
105 'connect' => {func => "Connect", doc => "connect: allocates client ID for this session"},
106 'disconnect' => {func => "Disconnect", doc => "disconnect [id]: frees client resources"},
107 'sync' => {func => "Sync", doc => "sync: flushes buffers to disk"},
108 'destroy' => {func => "Destroy", doc => "setup: destroys an inode"},
109 'cleanup' => {func => "Cleanup", doc => "cleanup the minor obd device"},
110 'dec_use_count' => {func => "Decusecount", doc => "decreases the module use count so that the module can be removed following an oops"},
111 'read' => {func => "Read", doc => "read <inode> <count> [offset]"},
112 'fsread' => {func => "Read2", doc => "read <inode> <count> [offset]"},
113 'write' => {func => "Write", doc => "write <inode> <offset> <text>"},
114 'setattr' => {func => "Setattr", doc => "setattr <inode> [mode [uid [gid [size [atime [mtime [ctime]]]]]]]"},
115 'getattr' => {func => "Getattr", doc => "getattr <inode>: displays inode object attributes"},
116 'preallocate' => {func => "Preallocate", doc => "preallocate [num]: requests preallocation of num inodes."},
117 'statfs' => {func => "Statfs", doc => "statfs: filesystem status information"},
118 'help' => {func => \&Help, doc => "help: this message"},
119 'quit' => {func => \&Quit, doc => "see \"exit\""},
120 'exit' => {func => \&Quit, doc => "see \"quit\""}
124 # setup completion function
126 my @jcm_cmd_list = keys %commands;
134 Filesystem($::filesystem);
142 return $term->readline(@_);
155 $term = new Term::ReadLine 'obdcontrol ';
156 $attribs = $term->Attribs;
157 $attribs->{attempted_completion_function} = \&completeme;
158 $term->ornaments('md,me,,'); # bold face prompt
160 # make sure stdout is not buffered
161 STDOUT->autoflush(1);
164 # Get on with the show
168 #------------------------------------------------------------------------------
170 my ($text, $line, $start, $end) = @_;
171 if (substr($line, 0, $start) =~ /^\s*$/) {
172 $attribs->{completion_word} = \@jcm_cmd_list;
173 return $term->completion_matches($text,
174 $attribs->{'list_completion_function'});
181 my @completions = completeme($given, $given, 0, length($given));
182 if ($#completions == 0) {
183 $name = shift @completions;
189 # start making requests
192 $line = $term->readline("obdcontrol > ");
200 my @arg = split(' ', $line);
201 my $word = shift @arg;
207 $cmd = find_command($word);
210 printf STDERR "$word: No such command, or not unique.\n";
214 if ($cmd eq "help" || $cmd eq "exit" || $cmd eq "quit") {
215 return (&{$commands{$cmd}->{func}}(@arg));
219 return (&{$commands{$cmd}->{func}}(@arg));
222 # set the object store in the ext2 formatted block device
224 my $filesystem = shift;
225 $filesystem = "/dev/loop0" unless $filesystem;
227 $::filesystem = $filesystem;
228 if (!defined($::st = stat($filesystem))) {
229 die "Unable to stat $filesystem.\n";
233 # select the OBD device we talk to
238 $device = "/dev/obd0";
241 # Open the device, as we need an FD for the ioctl
242 sysopen(DEV_OBD, $device, 0) || die "Cannot open $device";
243 print "Device now $device\n";
254 if ($type eq "obdscsi" ) {
259 $data = pack("iiiii", $adapter, $bus, $tid, $lun, $size);
263 my $packed = pack("ipip", length($type), $type, $datalen, $data);
265 my $rc = ioctl(DEV_OBD, &OBD_IOC_ATTACH, $packed);
268 print STDERR "ioctl failed: $!\n";
269 } elsif ($rc eq "0 but true") {
270 print "Finished (success)\n";
272 print "ioctl returned error code $rc.\n";
279 my $rc = ioctl(DEV_OBD, &OBD_IOC_DETACH, $data);
282 print STDERR "ioctl failed: $!\n";
283 } elsif ($rc eq "0 but true") {
284 print "Finished (success)\n";
286 print "ioctl returned error code $rc.\n";
293 my $type = "snap_obd";
303 print "No such file $file\n";
306 $table = ReadSnapShotTable($file);
308 $snapcount = keys %{$table};
309 print "Snapcount $snapcount\n";
311 if ( ! defined $table->{0} ) {
312 print "No current snapshot in table! First make one\n";
315 $data = pack("iii", $snapdev, $snapno, $snapcount);
317 foreach my $time (sort keys %{$table}) {
318 $data .= pack("Ii", $time, $table->{$time});
322 my $len = length($type);
323 my $cl = length($data);
324 my $add = pack("p", $data);
325 print "type $type (len $len), datalen $datalen ($cl)\n";
326 my $packed = pack("ipip", length($type), $type, $datalen, $data);
328 my $rc = ioctl(DEV_OBD, &OBD_IOC_ATTACH, $packed);
331 print STDERR "ioctl failed: $!\n";
332 } elsif ($rc eq "0 but true") {
333 print "Finished (success)\n";
335 print "ioctl returned error code $rc.\n";
342 my $file = &readl("enter file name: ");
346 my $table = ReadSnapShotTable($file);
349 PrintSnapShotTable($table);
350 my $action = &readl("Add, Delete or Quit [adq]: ");
351 goto done if ($action =~ "^q.*" );
352 goto add if ($action =~ "^a.*");
353 goto del if ($action =~ "^d.*");
357 my $idx = &readl("enter index where you want this snapshot: ");
358 my $time = &readl("enter time or 'now' or 'current': ");
359 my $oldtime = SnapFindTimeFromIdx($idx, $table);
360 if (defined $oldtime) {
361 print "This already exists, first clean up\n";
365 if ( $time eq 'now' ) {
367 } elsif ( $time eq 'current' ) {
370 $table->{$time} = $idx;
374 $didx = &readl("Enter index to delete: ");
375 my $deltime = SnapFindTimeFromIdx($didx, $table);
376 delete $table->{$deltime} if defined $deltime;
380 my $ok = &readl("OK with new table? [Yn]: ");
381 unless ( $ok eq "no" ) {
382 WriteSnapShotTable($file, $table);
386 sub SnapFindTimeFromIdx {
390 foreach my $time ( keys %{$table} ) {
391 if ( $table->{$time} == $idx ) {
398 sub PrintSnapShotTable {
402 foreach $time ( sort keys %{$table} ) {
403 my $stime = localtime($time);
407 printf "Time: %s -- Index %d\n", $stime, $table->{$time};
411 sub ReadSnapShotTable {
418 my ($time, $index) = split ;
419 $table->{$time} = $index;
423 PrintSnapShotTable($table);
428 sub WriteSnapShotTable {
433 foreach my $time ( sort keys %{$table} ) {
434 print FH "$time $table->{$time}\n";
443 my $data = pack("III", $::client_id, $srcid, $tgtid);
446 my $packed = pack("ip", $datalen, $data);
447 my $rc = ioctl(DEV_OBD, &OBD_IOC_COPY, $packed);
450 print STDERR "ioctl failed: $!\n";
451 } elsif ($rc eq "0 but true") {
452 print "Finished (success)\n";
454 print "ioctl returned error code $rc.\n";
462 my $data = pack("III", $::client_id, $srcid, $tgtid);
465 my $packed = pack("ip", $datalen, $data);
466 my $rc = ioctl(DEV_OBD, &OBD_IOC_MIGR, $packed);
469 print STDERR "ioctl failed: $!\n";
470 } elsif ($rc eq "0 but true") {
471 print "Finished (success)\n";
473 print "ioctl returned error code $rc.\n";
481 my $data = pack("i", $size);
484 my $packed = pack("ip", $datalen, $data);
485 my $rc = ioctl(DEV_OBD, &OBD_IOC_FORMATOBD, $packed);
488 print STDERR "ioctl failed: $!\n";
489 } elsif ($rc eq "0 but true") {
490 print "Finished (success)\n";
492 print "ioctl returned error code $rc.\n";
500 my $data = pack("ii", $partno, $size);
503 my $packed = pack("ip", $datalen, $data);
504 my $rc = ioctl(DEV_OBD, &OBD_IOC_PARTITION, $packed);
507 print STDERR "ioctl failed: $!\n";
508 } elsif ($rc eq "0 but true") {
509 print "Finished (success)\n";
511 print "ioctl returned error code $rc.\n";
521 $type = "ext2_obd" unless $type;
523 if ( $type eq "ext2_obd" ) {
525 $dev = $::st->rdev() unless $dev;
526 $data = pack("i", $dev);
530 my $packed = pack("ip", $datalen, $data);
531 my $rc = ioctl(DEV_OBD, &OBD_IOC_SETUP, $packed);
534 print STDERR "ioctl failed: $!\n";
535 } elsif ($rc eq "0 but true") {
536 print "Finished (success)\n";
538 print "ioctl returned error code $rc.\n";
544 my $rc = ioctl(DEV_OBD, &OBD_IOC_CLEANUP, $err);
547 print STDERR "ioctl failed: $!\n";
548 } elsif ($rc eq "0 but true") {
549 print "Finished (success)\n";
552 print "ioctl returned error code $rc.\n";
561 $rc = ioctl(DEV_OBD, &OBD_IOC_CONNECT, $packed);
562 $id = unpack("I", $packed);
565 print STDERR "ioctl failed: $!\n";
566 } elsif ($rc eq "0 but true") {
568 print "Client ID : $id\n";
569 print "Finished (success)\n";
571 print "ioctl returned error code $rc.\n";
583 print "syntax: disconnect [client ID]\n";
584 print "When client ID is not given, the last valid client ID to be returned by a\n";
585 print "connect command this session is used; there is no such ID.\n";
589 my $packed = pack("L", $id);
590 my $rc = ioctl(DEV_OBD, &OBD_IOC_DISCONNECT, $packed);
593 print STDERR "ioctl failed: $!\n";
594 } elsif ($rc eq "0 but true") {
595 $::client_id = undef;
596 print "Finished (success)\n";
598 print "ioctl returned error code $rc.\n";
608 if (defined($quiet) && !($quiet eq "quiet")) {
609 print "syntax: create [number of objects [quiet]]\n";
613 my $packed = pack("IL", $::client_id, $prealloc);
614 if (!defined($arg) || scalar($arg) < 2) {
615 print "Creating 1 object...\n";
616 $rc = ioctl(DEV_OBD, &OBD_IOC_CREATE, $packed);
617 if (!defined($quiet)) {
618 my $ino = unpack("L", $packed);
619 print "Created object #$ino.\n";
624 print "Creating " . scalar($arg) . " objects...\n";
625 for ($i = 0; $i < scalar($arg); $i++) {
626 $rc = ioctl(DEV_OBD, &OBD_IOC_CREATE, $packed);
627 my $ino = unpack("L", $packed);
628 if (!($rc eq "0 but true")) {
630 $packed = pack("IL", $::client_id, $prealloc);
631 } elsif (!defined($quiet)) {
632 $packed = pack("IL", $::client_id, $prealloc);
633 print "Created object #$ino.\n";
639 print STDERR "ioctl failed: $!\n";
640 } elsif ($rc eq "0 but true") {
641 print "Finished (success)\n";
643 print "ioctl returned error code $rc.\n";
649 my $rc = ioctl(DEV_OBD, &OBD_IOC_SYNC, $err);
652 print STDERR "ioctl failed: $!\n";
653 } elsif ($rc eq "0 but true") {
654 print "Finished (success)\n";
656 print "ioctl returned error code $rc.\n";
661 if (!defined($::client_id)) {
662 print "You must first ``connect''.\n";
668 if (!defined($arg) || scalar($arg) < 1) {
669 print "destroy requires the object number to destroy.\n";
673 print "Destroying object $arg...\n";
674 my $packed = pack("IL", $::client_id, $arg);
675 my $rc = ioctl(DEV_OBD, &OBD_IOC_DESTROY, $packed);
678 print STDERR "ioctl failed: $!\n";
679 } elsif ($rc eq "0 but true") {
680 print "Finished (success)\n";
682 print "ioctl returned error code $rc.\n";
687 if (!defined($::client_id)) {
688 print "You must first ``connect''.\n";
694 if (!defined($inode) || scalar($inode) < 1) {
695 print "invalid arguments; type \"help getattr\" for a synopsis\n";
700 my $packed = pack("ILsx2lLLLI", $::client_id, $inode, 0, 0, 0, 0, 0, 0, 0,
702 my $rc = ioctl(DEV_OBD, &OBD_IOC_GETATTR, $packed);
705 print STDERR "ioctl failed: $!\n";
706 } elsif ($rc eq "0 but true") {
707 my ($valid, $mode, $uid, $gid, $size, $atime, $mtime, $ctime, $flags);
708 ($valid, $mode, $uid, $gid, $size, $atime, $mtime, $ctime, $flags) =
709 unpack("ISssx2lLLLI", $packed);
711 printf("Inode: %d Mode: %o\n", $inode, $mode);
712 printf("User: %6d Group: %6d Size: %d\n", $uid, $gid, $size);
713 printf("ctime: %08lx -- %s\n", $ctime, scalar(gmtime($ctime)));
714 printf("atime: %08lx -- %s\n", $atime, scalar(gmtime($atime)));
715 printf("mtime: %08lx -- %s\n", $mtime, scalar(gmtime($mtime)));
716 printf("flags: %08x\n", $flags);
717 print "Finished (success)\n";
719 print "ioctl returned error code $rc.\n";
724 if (!defined($::client_id)) {
725 print "You must first ``connect''.\n";
731 my $mode = oct(shift);
745 if (defined($size)) {
746 $valid |= &ATTR_SIZE;
748 if (defined($atime)) {
749 $valid |= &ATTR_ATIME;
751 if (defined($mtime)) {
752 $valid |= &ATTR_MTIME;
754 if (defined($ctime)) {
755 $valid |= &ATTR_CTIME;
757 if (defined($mode)) {
758 $valid |= &ATTR_MODE;
761 if (!defined($inode) || scalar($inode) < 1) {
762 print "invalid arguments; type \"help setattr\" for a synopsis\n";
767 # unsigned int ia_valid; (32)
768 # umode_t ia_mode; (16)
771 # -- 16 bit alignment here! --
772 # off_t ia_size; (32)
773 # time_t ia_atime; (32)
774 # time_t ia_mtime; (32)
775 # time_t ia_ctime; (32)
776 # unsigned int ia_attr_flags; (32)
779 printf "valid is %x, mode is %o\n", $valid, $mode;
780 my $packed = pack("ILLSssx2ILLLL", $::client_id, $inode, $valid, $mode,
781 $uid, $gid, $size, $atime, $mtime, $ctime, 0);
782 my $rc = ioctl(DEV_OBD, &OBD_IOC_SETATTR, $packed);
785 print STDERR "ioctl failed: $!\n";
786 } elsif ($rc eq "0 but true") {
787 print "Finished (success)\n";
789 print "ioctl returned error code $rc.\n";
794 if (!defined($::client_id)) {
795 print "You must first ``connect''.\n";
803 if (!defined($inode) || scalar($inode) < 1 || !defined($count) ||
804 $count < 1 || (defined($offset) && $offset < 0)) {
805 print "invalid arguments; type \"help read\" for a synopsis\n";
809 if (!defined($offset)) {
813 print("Reading $count bytes starting at byte $offset from object " .
816 # "allocate" a large enough buffer
817 my $buf = sprintf("%${count}s", " ");
818 die "suck" if (length($buf) != $count);
820 # the perl we're using doesn't support pack type Q, and offset is 64 bits
821 my $packed = pack("ILpLLL", $::client_id, $inode, $buf, $count, $offset, 0);
823 my $rc = ioctl(DEV_OBD, &OBD_IOC_READ, $packed);
825 $retval = unpack("l", $packed);
828 print STDERR "ioctl failed: $!\n";
829 } elsif ($rc eq "0 but true") {
831 print substr($buf, 0, $retval);
832 print "\nRead $retval of an attempted $count bytes.\n";
833 print "Finished (success)\n";
835 print "Finished (error $retval)\n";
838 print "ioctl returned error code $rc.\n";
843 if (!defined($::client_id)) {
844 print "You must first ``connect''.\n";
852 if (!defined($inode) || scalar($inode) < 1 || !defined($count) ||
853 $count < 1 || (defined($offset) && $offset < 0)) {
854 print "invalid arguments; type \"help read\" for a synopsis\n";
858 if (!defined($offset)) {
862 print("Reading $count bytes starting at byte $offset from object " .
865 # "allocate" a large enough buffer
866 my $buf = sprintf("%${count}s", " ");
867 die "suck" if (length($buf) != $count);
869 # the perl we're using doesn't support pack type Q, and offset is 64 bits
870 my $packed = pack("ILpLLL", $::client_id, $inode, $buf, $count, $offset, 0);
872 my $rc = ioctl(DEV_OBD, &OBD_IOC_READ2, $packed);
874 $retval = unpack("l", $packed);
877 print STDERR "ioctl failed: $!\n";
878 } elsif ($rc eq "0 but true") {
880 print substr($buf, 0, $retval);
881 print "\nRead $retval of an attempted $count bytes.\n";
882 print "Finished (success)\n";
884 print "Finished (error $retval)\n";
887 print "ioctl returned error code $rc.\n";
892 if (!defined($::client_id)) {
893 print "You must first ``connect''.\n";
899 my $text = join(' ', @_);
900 my $count = length($text);
902 if (!defined($inode) || scalar($inode) < 1 || !defined($offset) ||
903 scalar($offset) < 0) {
904 print "invalid arguments; type \"help write\" for a synopsis\n";
908 if (!defined($text)) {
913 print("Writing $count bytes starting at byte $offset to object " .
916 # the perl we're using doesn't support pack type Q
917 my $packed = pack("ILpLLL", $::client_id, $inode, $text, $count, $offset, 0);
918 my $rc = ioctl(DEV_OBD, &OBD_IOC_WRITE, $packed);
920 $retval = unpack("l", $packed);
923 print STDERR "ioctl failed: $!\n";
924 } elsif ($rc eq "0 but true") {
926 print "\nWrote $retval of an attempted $count bytes.\n";
927 print "Finished (success)\n";
929 print "Finished (error $retval)\n";
932 print "ioctl returned error code $rc.\n";
939 if (!defined($::client_id)) {
940 print "You must first ``connect''.\n";
944 if (!defined($arg) || scalar($arg) < 1 || scalar($arg) > 32) {
948 print "Preallocating $arg inodes...\n";
949 my $packed = pack("LLx128", $::client_id, $arg);
950 # client id, alloc, inodes[32]
952 my $rc = ioctl(DEV_OBD, &OBD_IOC_PREALLOCATE, $packed);
955 print STDERR "ioctl failed: $!\n";
956 } elsif ($rc eq "0 but true") {
957 my $alloc = unpack("x4L", $packed);
958 my @inodes = unpack("x8L32", $packed);
961 print "Got $alloc inodes: ";
962 foreach $i (@inodes) {
965 print "\nFinished (success)\n";
967 print "ioctl returned error code $rc.\n";
972 my $rc = ioctl(DEV_OBD, &OBD_IOC_DEC_USE_COUNT, 0);
975 print STDERR "ioctl failed: $!\n";
976 } elsif ($rc eq "0 but true") {
977 print "Finished (success)\n";
979 print "ioctl returned error code $rc.\n";
984 if (!defined($::client_id)) {
985 print "You must first ``connect''.\n";
997 # __kernel_fsid_t f_fsid; (64 bits)
1002 my $packed = pack("LLLLLLLIILL6", $::client_id, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1005 my $rc = ioctl(DEV_OBD, &OBD_IOC_STATFS, $packed);
1008 print STDERR "ioctl failed: $!\n";
1009 } elsif ($rc eq "0 but true") {
1010 # skip both the conn_id and the fs_type in the buffer
1011 my ($bsize, $blocks, $bfree, $bavail, $files, $ffree) =
1012 unpack("x4x4LLLLLL", $packed);
1013 print("$bsize byte blocks: $blocks, " . ($blocks - $bfree) . " used, " .
1014 "$bfree free ($bavail available).\n");
1015 print "$files files, " . ($files - $ffree) . " used, $ffree free.\n";
1016 print "Finished (success)\n";
1018 print "ioctl returned error code $rc.\n";
1025 if ( !$arg || !$commands{$arg} ) {
1026 print "Comands: ", join( ' ', @jcm_cmd_list), "\n";
1028 print "Usage: " . $commands{$arg}->{doc} . "\n";
1034 print "Disconnecting active session ($::client_id)...";
1035 Disconnect($::client_id);