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";
310 $data = pack("iii", $snapdev, $snapno, $snapcount);
312 foreach my $time (sort keys %{$table}) {
313 $data .= pack("Ii", $time, $table->{$time});
317 my $len = length($type);
318 my $cl = length($data);
319 my $add = pack("p", $data);
320 print "type $type (len $len), datalen $datalen ($cl)\n";
321 printf "Addr of data %x\n", $add;
322 my $packed = pack("ipip", length($type), $type, $datalen, $data);
324 my $rc = ioctl(DEV_OBD, &OBD_IOC_ATTACH, $packed);
327 print STDERR "ioctl failed: $!\n";
328 } elsif ($rc eq "0 but true") {
329 print "Finished (success)\n";
331 print "ioctl returned error code $rc.\n";
338 my $file = &readl("enter file name: ");
342 my $table = ReadSnapShotTable($file);
345 PrintSnapShotTable($table);
346 my $action = &readl("Add, Delete or Quit [adq]: ");
347 goto done if ($action =~ "^q.*" );
348 goto add if ($action =~ "^a.*");
349 goto del if ($action =~ "^d.*");
353 my $idx = &readl("enter new index: ");
354 my $time = &readl("enter time (hit RET for \"now\"): ");
355 my $oldtime = SnapFindTimeFromIdx($idx, $table);
356 delete $table->{$oldtime} if defined $oldtime;
357 $time = time unless $time;
358 $table->{$time} = $idx;
362 $didx = &readl("Enter index to delete: ");
363 my $deltime = SnapFindTimeFromIdx($didx, $table);
364 delete $table->{$deltime} if defined $deltime;
368 my $ok = &readl("OK with new table? [Yn]: ");
369 unless ( $ok eq "no" ) {
370 WriteSnapShotTable($file, $table);
374 sub SnapFindTimeFromIdx {
378 foreach my $time ( keys %{$table} ) {
379 if ( $table->{$time} == $idx ) {
386 sub PrintSnapShotTable {
390 foreach $time ( sort keys %{$table} ) {
391 my $stime = localtime($time);
392 printf "Time: %s -- Index %d\n", $stime, $table->{$time};
396 sub ReadSnapShotTable {
403 my ($time, $index) = split ;
404 $table->{$time} = $index;
410 sub WriteSnapShotTable {
415 foreach my $time ( sort keys %{$table} ) {
416 print FH "$time $table->{$time}\n";
425 my $data = pack("III", $::client_id, $srcid, $tgtid);
428 my $packed = pack("ip", $datalen, $data);
429 my $rc = ioctl(DEV_OBD, &OBD_IOC_COPY, $packed);
432 print STDERR "ioctl failed: $!\n";
433 } elsif ($rc eq "0 but true") {
434 print "Finished (success)\n";
436 print "ioctl returned error code $rc.\n";
444 my $data = pack("III", $::client_id, $srcid, $tgtid);
447 my $packed = pack("ip", $datalen, $data);
448 my $rc = ioctl(DEV_OBD, &OBD_IOC_MIGR, $packed);
451 print STDERR "ioctl failed: $!\n";
452 } elsif ($rc eq "0 but true") {
453 print "Finished (success)\n";
455 print "ioctl returned error code $rc.\n";
463 my $data = pack("i", $size);
466 my $packed = pack("ip", $datalen, $data);
467 my $rc = ioctl(DEV_OBD, &OBD_IOC_FORMATOBD, $packed);
470 print STDERR "ioctl failed: $!\n";
471 } elsif ($rc eq "0 but true") {
472 print "Finished (success)\n";
474 print "ioctl returned error code $rc.\n";
482 my $data = pack("ii", $partno, $size);
485 my $packed = pack("ip", $datalen, $data);
486 my $rc = ioctl(DEV_OBD, &OBD_IOC_PARTITION, $packed);
489 print STDERR "ioctl failed: $!\n";
490 } elsif ($rc eq "0 but true") {
491 print "Finished (success)\n";
493 print "ioctl returned error code $rc.\n";
503 $type = "ext2_obd" unless $type;
505 if ( $type eq "ext2_obd" ) {
507 $dev = $::st->rdev() unless $dev;
508 $data = pack("i", $dev);
512 my $packed = pack("ip", $datalen, $data);
513 my $rc = ioctl(DEV_OBD, &OBD_IOC_SETUP, $packed);
516 print STDERR "ioctl failed: $!\n";
517 } elsif ($rc eq "0 but true") {
518 print "Finished (success)\n";
520 print "ioctl returned error code $rc.\n";
526 my $rc = ioctl(DEV_OBD, &OBD_IOC_CLEANUP, $err);
529 print STDERR "ioctl failed: $!\n";
530 } elsif ($rc eq "0 but true") {
531 print "Finished (success)\n";
534 print "ioctl returned error code $rc.\n";
543 $rc = ioctl(DEV_OBD, &OBD_IOC_CONNECT, $packed);
544 $id = unpack("I", $packed);
547 print STDERR "ioctl failed: $!\n";
548 } elsif ($rc eq "0 but true") {
550 print "Client ID : $id\n";
551 print "Finished (success)\n";
553 print "ioctl returned error code $rc.\n";
565 print "syntax: disconnect [client ID]\n";
566 print "When client ID is not given, the last valid client ID to be returned by a\n";
567 print "connect command this session is used; there is no such ID.\n";
571 my $packed = pack("L", $id);
572 my $rc = ioctl(DEV_OBD, &OBD_IOC_DISCONNECT, $packed);
575 print STDERR "ioctl failed: $!\n";
576 } elsif ($rc eq "0 but true") {
577 $::client_id = undef;
578 print "Finished (success)\n";
580 print "ioctl returned error code $rc.\n";
590 if (defined($quiet) && !($quiet eq "quiet")) {
591 print "syntax: create [number of objects [quiet]]\n";
595 my $packed = pack("IL", $::client_id, $prealloc);
596 if (!defined($arg) || scalar($arg) < 2) {
597 print "Creating 1 object...\n";
598 $rc = ioctl(DEV_OBD, &OBD_IOC_CREATE, $packed);
599 if (!defined($quiet)) {
600 my $ino = unpack("L", $packed);
601 print "Created object #$ino.\n";
606 print "Creating " . scalar($arg) . " objects...\n";
607 for ($i = 0; $i < scalar($arg); $i++) {
608 $rc = ioctl(DEV_OBD, &OBD_IOC_CREATE, $packed);
609 my $ino = unpack("L", $packed);
610 if (!($rc eq "0 but true")) {
612 $packed = pack("IL", $::client_id, $prealloc);
613 } elsif (!defined($quiet)) {
614 $packed = pack("IL", $::client_id, $prealloc);
615 print "Created object #$ino.\n";
621 print STDERR "ioctl failed: $!\n";
622 } elsif ($rc eq "0 but true") {
623 print "Finished (success)\n";
625 print "ioctl returned error code $rc.\n";
631 my $rc = ioctl(DEV_OBD, &OBD_IOC_SYNC, $err);
634 print STDERR "ioctl failed: $!\n";
635 } elsif ($rc eq "0 but true") {
636 print "Finished (success)\n";
638 print "ioctl returned error code $rc.\n";
643 if (!defined($::client_id)) {
644 print "You must first ``connect''.\n";
650 if (!defined($arg) || scalar($arg) < 1) {
651 print "destroy requires the object number to destroy.\n";
655 print "Destroying object $arg...\n";
656 my $packed = pack("IL", $::client_id, $arg);
657 my $rc = ioctl(DEV_OBD, &OBD_IOC_DESTROY, $packed);
660 print STDERR "ioctl failed: $!\n";
661 } elsif ($rc eq "0 but true") {
662 print "Finished (success)\n";
664 print "ioctl returned error code $rc.\n";
669 if (!defined($::client_id)) {
670 print "You must first ``connect''.\n";
676 if (!defined($inode) || scalar($inode) < 1) {
677 print "invalid arguments; type \"help getattr\" for a synopsis\n";
682 my $packed = pack("ILsx2lLLLI", $::client_id, $inode, 0, 0, 0, 0, 0, 0, 0,
684 my $rc = ioctl(DEV_OBD, &OBD_IOC_GETATTR, $packed);
687 print STDERR "ioctl failed: $!\n";
688 } elsif ($rc eq "0 but true") {
689 my ($valid, $mode, $uid, $gid, $size, $atime, $mtime, $ctime, $flags);
690 ($valid, $mode, $uid, $gid, $size, $atime, $mtime, $ctime, $flags) =
691 unpack("ISssx2lLLLI", $packed);
693 printf("Inode: %d Mode: %o\n", $inode, $mode);
694 printf("User: %6d Group: %6d Size: %d\n", $uid, $gid, $size);
695 printf("ctime: %08lx -- %s\n", $ctime, scalar(gmtime($ctime)));
696 printf("atime: %08lx -- %s\n", $atime, scalar(gmtime($atime)));
697 printf("mtime: %08lx -- %s\n", $mtime, scalar(gmtime($mtime)));
698 printf("flags: %08x\n", $flags);
699 print "Finished (success)\n";
701 print "ioctl returned error code $rc.\n";
706 if (!defined($::client_id)) {
707 print "You must first ``connect''.\n";
713 my $mode = oct(shift);
727 if (defined($size)) {
728 $valid |= &ATTR_SIZE;
730 if (defined($atime)) {
731 $valid |= &ATTR_ATIME;
733 if (defined($mtime)) {
734 $valid |= &ATTR_MTIME;
736 if (defined($ctime)) {
737 $valid |= &ATTR_CTIME;
739 if (defined($mode)) {
740 $valid |= &ATTR_MODE;
743 if (!defined($inode) || scalar($inode) < 1) {
744 print "invalid arguments; type \"help setattr\" for a synopsis\n";
749 # unsigned int ia_valid; (32)
750 # umode_t ia_mode; (16)
753 # -- 16 bit alignment here! --
754 # off_t ia_size; (32)
755 # time_t ia_atime; (32)
756 # time_t ia_mtime; (32)
757 # time_t ia_ctime; (32)
758 # unsigned int ia_attr_flags; (32)
761 printf "valid is %x, mode is %o\n", $valid, $mode;
762 my $packed = pack("ILLSssx2ILLLL", $::client_id, $inode, $valid, $mode,
763 $uid, $gid, $size, $atime, $mtime, $ctime, 0);
764 my $rc = ioctl(DEV_OBD, &OBD_IOC_SETATTR, $packed);
767 print STDERR "ioctl failed: $!\n";
768 } elsif ($rc eq "0 but true") {
769 print "Finished (success)\n";
771 print "ioctl returned error code $rc.\n";
776 if (!defined($::client_id)) {
777 print "You must first ``connect''.\n";
785 if (!defined($inode) || scalar($inode) < 1 || !defined($count) ||
786 $count < 1 || (defined($offset) && $offset < 0)) {
787 print "invalid arguments; type \"help read\" for a synopsis\n";
791 if (!defined($offset)) {
795 print("Reading $count bytes starting at byte $offset from object " .
798 # "allocate" a large enough buffer
799 my $buf = sprintf("%${count}s", " ");
800 die "suck" if (length($buf) != $count);
802 # the perl we're using doesn't support pack type Q, and offset is 64 bits
803 my $packed = pack("ILpLLL", $::client_id, $inode, $buf, $count, $offset, 0);
805 my $rc = ioctl(DEV_OBD, &OBD_IOC_READ, $packed);
807 $retval = unpack("l", $packed);
810 print STDERR "ioctl failed: $!\n";
811 } elsif ($rc eq "0 but true") {
813 print substr($buf, 0, $retval);
814 print "\nRead $retval of an attempted $count bytes.\n";
815 print "Finished (success)\n";
817 print "Finished (error $retval)\n";
820 print "ioctl returned error code $rc.\n";
825 if (!defined($::client_id)) {
826 print "You must first ``connect''.\n";
834 if (!defined($inode) || scalar($inode) < 1 || !defined($count) ||
835 $count < 1 || (defined($offset) && $offset < 0)) {
836 print "invalid arguments; type \"help read\" for a synopsis\n";
840 if (!defined($offset)) {
844 print("Reading $count bytes starting at byte $offset from object " .
847 # "allocate" a large enough buffer
848 my $buf = sprintf("%${count}s", " ");
849 die "suck" if (length($buf) != $count);
851 # the perl we're using doesn't support pack type Q, and offset is 64 bits
852 my $packed = pack("ILpLLL", $::client_id, $inode, $buf, $count, $offset, 0);
854 my $rc = ioctl(DEV_OBD, &OBD_IOC_READ2, $packed);
856 $retval = unpack("l", $packed);
859 print STDERR "ioctl failed: $!\n";
860 } elsif ($rc eq "0 but true") {
862 print substr($buf, 0, $retval);
863 print "\nRead $retval of an attempted $count bytes.\n";
864 print "Finished (success)\n";
866 print "Finished (error $retval)\n";
869 print "ioctl returned error code $rc.\n";
874 if (!defined($::client_id)) {
875 print "You must first ``connect''.\n";
881 my $text = join(' ', @_);
882 my $count = length($text);
884 if (!defined($inode) || scalar($inode) < 1 || !defined($offset) ||
885 scalar($offset) < 0) {
886 print "invalid arguments; type \"help write\" for a synopsis\n";
890 if (!defined($text)) {
895 print("Writing $count bytes starting at byte $offset to object " .
898 # the perl we're using doesn't support pack type Q
899 my $packed = pack("ILpLLL", $::client_id, $inode, $text, $count, $offset, 0);
900 my $rc = ioctl(DEV_OBD, &OBD_IOC_WRITE, $packed);
902 $retval = unpack("l", $packed);
905 print STDERR "ioctl failed: $!\n";
906 } elsif ($rc eq "0 but true") {
908 print "\nWrote $retval of an attempted $count bytes.\n";
909 print "Finished (success)\n";
911 print "Finished (error $retval)\n";
914 print "ioctl returned error code $rc.\n";
921 if (!defined($::client_id)) {
922 print "You must first ``connect''.\n";
926 if (!defined($arg) || scalar($arg) < 1 || scalar($arg) > 32) {
930 print "Preallocating $arg inodes...\n";
931 my $packed = pack("LLx128", $::client_id, $arg);
932 # client id, alloc, inodes[32]
934 my $rc = ioctl(DEV_OBD, &OBD_IOC_PREALLOCATE, $packed);
937 print STDERR "ioctl failed: $!\n";
938 } elsif ($rc eq "0 but true") {
939 my $alloc = unpack("x4L", $packed);
940 my @inodes = unpack("x8L32", $packed);
943 print "Got $alloc inodes: ";
944 foreach $i (@inodes) {
947 print "\nFinished (success)\n";
949 print "ioctl returned error code $rc.\n";
954 my $rc = ioctl(DEV_OBD, &OBD_IOC_DEC_USE_COUNT, 0);
957 print STDERR "ioctl failed: $!\n";
958 } elsif ($rc eq "0 but true") {
959 print "Finished (success)\n";
961 print "ioctl returned error code $rc.\n";
966 if (!defined($::client_id)) {
967 print "You must first ``connect''.\n";
979 # __kernel_fsid_t f_fsid; (64 bits)
984 my $packed = pack("LLLLLLLIILL6", $::client_id, 0, 0, 0, 0, 0, 0, 0, 0, 0,
987 my $rc = ioctl(DEV_OBD, &OBD_IOC_STATFS, $packed);
990 print STDERR "ioctl failed: $!\n";
991 } elsif ($rc eq "0 but true") {
992 # skip both the conn_id and the fs_type in the buffer
993 my ($bsize, $blocks, $bfree, $bavail, $files, $ffree) =
994 unpack("x4x4LLLLLL", $packed);
995 print("$bsize byte blocks: $blocks, " . ($blocks - $bfree) . " used, " .
996 "$bfree free ($bavail available).\n");
997 print "$files files, " . ($files - $ffree) . " used, $ffree free.\n";
998 print "Finished (success)\n";
1000 print "ioctl returned error code $rc.\n";
1007 if ( !$arg || !$commands{$arg} ) {
1008 print "Comands: ", join( ' ', @jcm_cmd_list), "\n";
1010 print "Usage: " . $commands{$arg}->{doc} . "\n";
1016 print "Disconnecting active session ($::client_id)...";
1017 Disconnect($::client_id);