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 ATTR_MODE () {1;}' unless defined(&ATTR_MODE);
70 eval 'sub ATTR_UID () {2;}' unless defined(&ATTR_UID);
71 eval 'sub ATTR_GID () {4;}' unless defined(&ATTR_GID);
72 eval 'sub ATTR_SIZE () {8;}' unless defined(&ATTR_SIZE);
73 eval 'sub ATTR_ATIME () {16;}' unless defined(&ATTR_ATIME);
74 eval 'sub ATTR_MTIME () {32;}' unless defined(&ATTR_MTIME);
75 eval 'sub ATTR_CTIME () {64;}' unless defined(&ATTR_CTIME);
87 GetOptions("f!" => \$file, "device=s" => \$::device, "fs=s" => $::filesystem) || die "Getoptions";
90 # get a console for the app
97 ('device' => {func => "Device", doc => "device <dev>: open another OBD device"},
98 'filesystem' => {func => "Filesystem", doc => "filesystem <dev>: partition for direct OBD device"},
99 'create' => {func => "Create", doc => "create: creates a new inode"},
100 'attach' => {func => "Attach", doc => "attach type [adapter bus tid lun]"},
101 'detach' => {func => "Detach", doc => "detach this device"},
102 'snapattach' => {func => "SnapAttach", doc => "snapattach snapno table"},
103 'snapset' => {func => "SnapSetTable", doc => "snapset tableno file" },
104 'snapprint' => {func => "SnapPrint", doc => "snapprint tableno"},
106 'snaptable' => {func => "SnapShotTable", doc => "snaptable: build a snapshot table (interactive)"},
107 'copy' => {func => "Copy", doc => "copy srcid tgtid"},
108 'migrate' => {func => "Migrate", doc => "migrate srcid tgtid"},
109 'format' => {func => "Format", doc => "format type adapter bus tid lun size"},
110 'partition' => {func => "Partition", doc => "partition type adapter bus tid lun partition size"},
111 'setup' => {func => "Setup", doc => "setup: link the ext2 partition (default /dev/loop0) to this obddev"},
112 'connect' => {func => "Connect", doc => "connect: allocates client ID for this session"},
113 'disconnect' => {func => "Disconnect", doc => "disconnect [id]: frees client resources"},
114 'sync' => {func => "Sync", doc => "sync: flushes buffers to disk"},
115 'destroy' => {func => "Destroy", doc => "setup: destroys an inode"},
116 'cleanup' => {func => "Cleanup", doc => "cleanup the minor obd device"},
117 'dec_use_count' => {func => "Decusecount", doc => "decreases the module use count so that the module can be removed following an oops"},
118 'read' => {func => "Read", doc => "read <inode> <count> [offset]"},
119 'fsread' => {func => "Read2", doc => "read <inode> <count> [offset]"},
120 'write' => {func => "Write", doc => "write <inode> <offset> <text>"},
121 'setattr' => {func => "Setattr", doc => "setattr <inode> [mode [uid [gid [size [atime [mtime [ctime]]]]]]]"},
122 'getattr' => {func => "Getattr", doc => "getattr <inode>: displays inode object attributes"},
123 'preallocate' => {func => "Preallocate", doc => "preallocate [num]: requests preallocation of num inodes."},
124 'statfs' => {func => "Statfs", doc => "statfs: filesystem status information"},
125 'help' => {func => \&Help, doc => "help: this message"},
126 'quit' => {func => \&Quit, doc => "see \"exit\""},
127 'exit' => {func => \&Quit, doc => "see \"quit\""}
131 # setup completion function
133 my @jcm_cmd_list = keys %commands;
141 Filesystem($::filesystem);
149 return $term->readline(@_);
162 $term = new Term::ReadLine 'obdcontrol ';
163 $attribs = $term->Attribs;
164 $attribs->{attempted_completion_function} = \&completeme;
165 $term->ornaments('md,me,,'); # bold face prompt
167 # make sure stdout is not buffered
168 STDOUT->autoflush(1);
171 # Get on with the show
175 #------------------------------------------------------------------------------
177 my ($text, $line, $start, $end) = @_;
178 if (substr($line, 0, $start) =~ /^\s*$/) {
179 $attribs->{completion_word} = \@jcm_cmd_list;
180 return $term->completion_matches($text,
181 $attribs->{'list_completion_function'});
188 my @completions = completeme($given, $given, 0, length($given));
189 if ($#completions == 0) {
190 $name = shift @completions;
196 # start making requests
199 $line = $term->readline("obdcontrol > ");
207 my @arg = split(' ', $line);
208 my $word = shift @arg;
214 $cmd = find_command($word);
217 printf STDERR "$word: No such command, or not unique.\n";
221 if ($cmd eq "help" || $cmd eq "exit" || $cmd eq "quit") {
222 return (&{$commands{$cmd}->{func}}(@arg));
226 return (&{$commands{$cmd}->{func}}(@arg));
229 # set the object store in the ext2 formatted block device
231 my $filesystem = shift;
232 $filesystem = "/dev/loop0" unless $filesystem;
234 $::filesystem = $filesystem;
235 if (!defined($::st = stat($filesystem))) {
236 die "Unable to stat $filesystem.\n";
240 # select the OBD device we talk to
245 $device = "/dev/obd0";
248 # Open the device, as we need an FD for the ioctl
249 sysopen(DEV_OBD, $device, 0) || die "Cannot open $device";
250 print "Device now $device\n";
261 if ($type eq "obdscsi" ) {
266 $data = pack("iiiii", $adapter, $bus, $tid, $lun, $size);
270 my $packed = pack("ipip", length($type), $type, $datalen, $data);
272 my $rc = ioctl(DEV_OBD, &OBD_IOC_ATTACH, $packed);
275 print STDERR "ioctl failed: $!\n";
276 } elsif ($rc eq "0 but true") {
277 print "Finished (success)\n";
279 print "ioctl returned error code $rc.\n";
286 my $rc = ioctl(DEV_OBD, &OBD_IOC_DETACH, $data);
289 print STDERR "ioctl failed: $!\n";
290 } elsif ($rc eq "0 but true") {
291 print "Finished (success)\n";
293 print "ioctl returned error code $rc.\n";
300 my $type = "snap_obd";
301 my $snaptableno = shift;
303 $data = pack("i", $snaptableno);
306 my $len = length($type);
307 my $cl = length($data);
308 my $add = pack("p", $data);
309 print "type $type (len $len), datalen $datalen ($cl)\n";
310 my $packed = pack("ipip", length($type), $type, $datalen, $data);
312 my $rc = ioctl(DEV_OBD, &OBD_SNAP_PRINTTABLE, $packed);
315 print STDERR "ioctl failed: $!\n";
316 } elsif ($rc eq "0 but true") {
317 print "Finished (success)\n";
319 print "ioctl returned error code $rc.\n";
325 my $type = "snap_obd";
326 my $snaptableno = shift;
334 print "No such file $file\n";
337 $table = ReadSnapShotTable($file);
339 $snapcount = keys %{$table};
340 print "Snapcount $snapcount\n";
342 if ( ! defined $table->{0} ) {
343 print "No current snapshot in table! First make one\n";
346 $data = pack("ii", $snaptableno, $snapcount);
348 foreach my $time (sort keys %{$table}) {
349 $data .= pack("Ii", $time, $table->{$time});
353 my $len = length($type);
354 my $cl = length($data);
355 my $add = pack("p", $data);
356 print "type $type (len $len), datalen $datalen ($cl)\n";
357 my $packed = pack("ipip", length($type), $type, $datalen, $data);
359 my $rc = ioctl(DEV_OBD, &OBD_SNAP_SETTABLE, $packed);
362 print STDERR "ioctl failed: $!\n";
363 } elsif ($rc eq "0 but true") {
364 print "Finished (success)\n";
366 print "ioctl returned error code $rc.\n";
373 my $type = "snap_obd";
382 print "No such file $file\n";
385 $table = ReadSnapShotTable($file);
386 $data = pack("iii", $snapdev, $snapno, $tableno);
389 my $len = length($type);
390 my $cl = length($data);
391 my $add = pack("p", $data);
392 print "type $type (len $len), datalen $datalen ($cl)\n";
393 my $packed = pack("ipip", length($type), $type, $datalen, $data);
395 my $rc = ioctl(DEV_OBD, &OBD_IOC_ATTACH, $packed);
398 print STDERR "ioctl failed: $!\n";
399 } elsif ($rc eq "0 but true") {
400 print "Finished (success)\n";
402 print "ioctl returned error code $rc.\n";
409 my $file = &readl("enter file name: ");
413 my $table = ReadSnapShotTable($file);
416 PrintSnapShotTable($table);
417 my $action = &readl("Add, Delete or Quit [adq]: ");
418 goto done if ($action =~ "^q.*" );
419 goto add if ($action =~ "^a.*");
420 goto del if ($action =~ "^d.*");
424 my $idx = &readl("enter index where you want this snapshot: ");
425 my $time = &readl("enter time or 'now' or 'current': ");
426 my $oldtime = SnapFindTimeFromIdx($idx, $table);
427 if (defined $oldtime) {
428 print "This already exists, first clean up\n";
432 if ( $time eq 'now' ) {
434 } elsif ( $time eq 'current' ) {
437 $table->{$time} = $idx;
441 $didx = &readl("Enter index to delete: ");
442 my $deltime = SnapFindTimeFromIdx($didx, $table);
443 delete $table->{$deltime} if defined $deltime;
447 my $ok = &readl("OK with new table? [Yn]: ");
448 unless ( $ok eq "no" ) {
449 WriteSnapShotTable($file, $table);
453 sub SnapFindTimeFromIdx {
457 foreach my $time ( keys %{$table} ) {
458 if ( $table->{$time} == $idx ) {
465 sub PrintSnapShotTable {
469 foreach $time ( sort keys %{$table} ) {
470 my $stime = localtime($time);
474 printf "Time: %s -- Index %d\n", $stime, $table->{$time};
478 sub ReadSnapShotTable {
485 my ($time, $index) = split ;
486 $table->{$time} = $index;
490 PrintSnapShotTable($table);
495 sub WriteSnapShotTable {
500 foreach my $time ( sort keys %{$table} ) {
501 print FH "$time $table->{$time}\n";
510 my $data = pack("III", $::client_id, $srcid, $tgtid);
513 my $packed = pack("ip", $datalen, $data);
514 my $rc = ioctl(DEV_OBD, &OBD_IOC_COPY, $packed);
517 print STDERR "ioctl failed: $!\n";
518 } elsif ($rc eq "0 but true") {
519 print "Finished (success)\n";
521 print "ioctl returned error code $rc.\n";
529 my $data = pack("III", $::client_id, $srcid, $tgtid);
532 my $packed = pack("ip", $datalen, $data);
533 my $rc = ioctl(DEV_OBD, &OBD_IOC_MIGR, $packed);
536 print STDERR "ioctl failed: $!\n";
537 } elsif ($rc eq "0 but true") {
538 print "Finished (success)\n";
540 print "ioctl returned error code $rc.\n";
548 my $data = pack("i", $size);
551 my $packed = pack("ip", $datalen, $data);
552 my $rc = ioctl(DEV_OBD, &OBD_IOC_FORMATOBD, $packed);
555 print STDERR "ioctl failed: $!\n";
556 } elsif ($rc eq "0 but true") {
557 print "Finished (success)\n";
559 print "ioctl returned error code $rc.\n";
567 my $data = pack("ii", $partno, $size);
570 my $packed = pack("ip", $datalen, $data);
571 my $rc = ioctl(DEV_OBD, &OBD_IOC_PARTITION, $packed);
574 print STDERR "ioctl failed: $!\n";
575 } elsif ($rc eq "0 but true") {
576 print "Finished (success)\n";
578 print "ioctl returned error code $rc.\n";
588 $type = "ext2_obd" unless $type;
590 if ( $type eq "ext2_obd" ) {
592 $dev = $::st->rdev() unless $dev;
593 $data = pack("i", $dev);
597 my $packed = pack("ip", $datalen, $data);
598 my $rc = ioctl(DEV_OBD, &OBD_IOC_SETUP, $packed);
601 print STDERR "ioctl failed: $!\n";
602 } elsif ($rc eq "0 but true") {
603 print "Finished (success)\n";
605 print "ioctl returned error code $rc.\n";
611 my $rc = ioctl(DEV_OBD, &OBD_IOC_CLEANUP, $err);
614 print STDERR "ioctl failed: $!\n";
615 } elsif ($rc eq "0 but true") {
616 print "Finished (success)\n";
619 print "ioctl returned error code $rc.\n";
628 $rc = ioctl(DEV_OBD, &OBD_IOC_CONNECT, $packed);
629 $id = unpack("I", $packed);
632 print STDERR "ioctl failed: $!\n";
633 } elsif ($rc eq "0 but true") {
635 print "Client ID : $id\n";
636 print "Finished (success)\n";
638 print "ioctl returned error code $rc.\n";
650 print "syntax: disconnect [client ID]\n";
651 print "When client ID is not given, the last valid client ID to be returned by a\n";
652 print "connect command this session is used; there is no such ID.\n";
656 my $packed = pack("L", $id);
657 my $rc = ioctl(DEV_OBD, &OBD_IOC_DISCONNECT, $packed);
660 print STDERR "ioctl failed: $!\n";
661 } elsif ($rc eq "0 but true") {
662 $::client_id = undef;
663 print "Finished (success)\n";
665 print "ioctl returned error code $rc.\n";
675 if (defined($quiet) && !($quiet eq "quiet")) {
676 print "syntax: create [number of objects [quiet]]\n";
680 my $packed = pack("IL", $::client_id, $prealloc);
681 if (!defined($arg) || scalar($arg) < 2) {
682 print "Creating 1 object...\n";
683 $rc = ioctl(DEV_OBD, &OBD_IOC_CREATE, $packed);
684 if (!defined($quiet)) {
685 my $ino = unpack("L", $packed);
686 print "Created object #$ino.\n";
691 print "Creating " . scalar($arg) . " objects...\n";
692 for ($i = 0; $i < scalar($arg); $i++) {
693 $rc = ioctl(DEV_OBD, &OBD_IOC_CREATE, $packed);
694 my $ino = unpack("L", $packed);
695 if (!($rc eq "0 but true")) {
697 $packed = pack("IL", $::client_id, $prealloc);
698 } elsif (!defined($quiet)) {
699 $packed = pack("IL", $::client_id, $prealloc);
700 print "Created object #$ino.\n";
706 print STDERR "ioctl failed: $!\n";
707 } elsif ($rc eq "0 but true") {
708 print "Finished (success)\n";
710 print "ioctl returned error code $rc.\n";
716 my $rc = ioctl(DEV_OBD, &OBD_IOC_SYNC, $err);
719 print STDERR "ioctl failed: $!\n";
720 } elsif ($rc eq "0 but true") {
721 print "Finished (success)\n";
723 print "ioctl returned error code $rc.\n";
728 if (!defined($::client_id)) {
729 print "You must first ``connect''.\n";
735 if (!defined($arg) || scalar($arg) < 1) {
736 print "destroy requires the object number to destroy.\n";
740 print "Destroying object $arg...\n";
741 my $packed = pack("IL", $::client_id, $arg);
742 my $rc = ioctl(DEV_OBD, &OBD_IOC_DESTROY, $packed);
745 print STDERR "ioctl failed: $!\n";
746 } elsif ($rc eq "0 but true") {
747 print "Finished (success)\n";
749 print "ioctl returned error code $rc.\n";
754 if (!defined($::client_id)) {
755 print "You must first ``connect''.\n";
761 if (!defined($inode) || scalar($inode) < 1) {
762 print "invalid arguments; type \"help getattr\" for a synopsis\n";
767 my $packed = pack("ILsx2lLLLI", $::client_id, $inode, 0, 0, 0, 0, 0, 0, 0,
769 my $rc = ioctl(DEV_OBD, &OBD_IOC_GETATTR, $packed);
772 print STDERR "ioctl failed: $!\n";
773 } elsif ($rc eq "0 but true") {
774 my ($valid, $mode, $uid, $gid, $size, $atime, $mtime, $ctime, $flags);
775 ($valid, $mode, $uid, $gid, $size, $atime, $mtime, $ctime, $flags) =
776 unpack("ISssx2lLLLI", $packed);
778 printf("Inode: %d Mode: %o\n", $inode, $mode);
779 printf("User: %6d Group: %6d Size: %d\n", $uid, $gid, $size);
780 printf("ctime: %08lx -- %s\n", $ctime, scalar(gmtime($ctime)));
781 printf("atime: %08lx -- %s\n", $atime, scalar(gmtime($atime)));
782 printf("mtime: %08lx -- %s\n", $mtime, scalar(gmtime($mtime)));
783 printf("flags: %08x\n", $flags);
784 print "Finished (success)\n";
786 print "ioctl returned error code $rc.\n";
791 if (!defined($::client_id)) {
792 print "You must first ``connect''.\n";
798 my $mode = oct(shift);
812 if (defined($size)) {
813 $valid |= &ATTR_SIZE;
815 if (defined($atime)) {
816 $valid |= &ATTR_ATIME;
818 if (defined($mtime)) {
819 $valid |= &ATTR_MTIME;
821 if (defined($ctime)) {
822 $valid |= &ATTR_CTIME;
824 if (defined($mode)) {
825 $valid |= &ATTR_MODE;
828 if (!defined($inode) || scalar($inode) < 1) {
829 print "invalid arguments; type \"help setattr\" for a synopsis\n";
834 # unsigned int ia_valid; (32)
835 # umode_t ia_mode; (16)
838 # -- 16 bit alignment here! --
839 # off_t ia_size; (32)
840 # time_t ia_atime; (32)
841 # time_t ia_mtime; (32)
842 # time_t ia_ctime; (32)
843 # unsigned int ia_attr_flags; (32)
846 printf "valid is %x, mode is %o\n", $valid, $mode;
847 my $packed = pack("ILLSssx2ILLLL", $::client_id, $inode, $valid, $mode,
848 $uid, $gid, $size, $atime, $mtime, $ctime, 0);
849 my $rc = ioctl(DEV_OBD, &OBD_IOC_SETATTR, $packed);
852 print STDERR "ioctl failed: $!\n";
853 } elsif ($rc eq "0 but true") {
854 print "Finished (success)\n";
856 print "ioctl returned error code $rc.\n";
861 if (!defined($::client_id)) {
862 print "You must first ``connect''.\n";
870 if (!defined($inode) || scalar($inode) < 1 || !defined($count) ||
871 $count < 1 || (defined($offset) && $offset < 0)) {
872 print "invalid arguments; type \"help read\" for a synopsis\n";
876 if (!defined($offset)) {
880 print("Reading $count bytes starting at byte $offset from object " .
883 # "allocate" a large enough buffer
884 my $buf = sprintf("%${count}s", " ");
885 die "suck" if (length($buf) != $count);
887 # the perl we're using doesn't support pack type Q, and offset is 64 bits
888 my $packed = pack("ILpLLL", $::client_id, $inode, $buf, $count, $offset, 0);
890 my $rc = ioctl(DEV_OBD, &OBD_IOC_READ, $packed);
892 $retval = unpack("l", $packed);
895 print STDERR "ioctl failed: $!\n";
896 } elsif ($rc eq "0 but true") {
898 print substr($buf, 0, $retval);
899 print "\nRead $retval of an attempted $count bytes.\n";
900 print "Finished (success)\n";
902 print "Finished (error $retval)\n";
905 print "ioctl returned error code $rc.\n";
910 if (!defined($::client_id)) {
911 print "You must first ``connect''.\n";
919 if (!defined($inode) || scalar($inode) < 1 || !defined($count) ||
920 $count < 1 || (defined($offset) && $offset < 0)) {
921 print "invalid arguments; type \"help read\" for a synopsis\n";
925 if (!defined($offset)) {
929 print("Reading $count bytes starting at byte $offset from object " .
932 # "allocate" a large enough buffer
933 my $buf = sprintf("%${count}s", " ");
934 die "suck" if (length($buf) != $count);
936 # the perl we're using doesn't support pack type Q, and offset is 64 bits
937 my $packed = pack("ILpLLL", $::client_id, $inode, $buf, $count, $offset, 0);
939 my $rc = ioctl(DEV_OBD, &OBD_IOC_READ2, $packed);
941 $retval = unpack("l", $packed);
944 print STDERR "ioctl failed: $!\n";
945 } elsif ($rc eq "0 but true") {
947 print substr($buf, 0, $retval);
948 print "\nRead $retval of an attempted $count bytes.\n";
949 print "Finished (success)\n";
951 print "Finished (error $retval)\n";
954 print "ioctl returned error code $rc.\n";
959 if (!defined($::client_id)) {
960 print "You must first ``connect''.\n";
966 my $text = join(' ', @_);
967 my $count = length($text);
969 if (!defined($inode) || scalar($inode) < 1 || !defined($offset) ||
970 scalar($offset) < 0) {
971 print "invalid arguments; type \"help write\" for a synopsis\n";
975 if (!defined($text)) {
980 print("Writing $count bytes starting at byte $offset to object " .
983 # the perl we're using doesn't support pack type Q
984 my $packed = pack("ILpLLL", $::client_id, $inode, $text, $count, $offset, 0);
985 my $rc = ioctl(DEV_OBD, &OBD_IOC_WRITE, $packed);
987 $retval = unpack("l", $packed);
990 print STDERR "ioctl failed: $!\n";
991 } elsif ($rc eq "0 but true") {
993 print "\nWrote $retval of an attempted $count bytes.\n";
994 print "Finished (success)\n";
996 print "Finished (error $retval)\n";
999 print "ioctl returned error code $rc.\n";
1006 if (!defined($::client_id)) {
1007 print "You must first ``connect''.\n";
1011 if (!defined($arg) || scalar($arg) < 1 || scalar($arg) > 32) {
1015 print "Preallocating $arg inodes...\n";
1016 my $packed = pack("LLx128", $::client_id, $arg);
1017 # client id, alloc, inodes[32]
1019 my $rc = ioctl(DEV_OBD, &OBD_IOC_PREALLOCATE, $packed);
1022 print STDERR "ioctl failed: $!\n";
1023 } elsif ($rc eq "0 but true") {
1024 my $alloc = unpack("x4L", $packed);
1025 my @inodes = unpack("x8L32", $packed);
1028 print "Got $alloc inodes: ";
1029 foreach $i (@inodes) {
1032 print "\nFinished (success)\n";
1034 print "ioctl returned error code $rc.\n";
1039 my $rc = ioctl(DEV_OBD, &OBD_IOC_DEC_USE_COUNT, 0);
1042 print STDERR "ioctl failed: $!\n";
1043 } elsif ($rc eq "0 but true") {
1044 print "Finished (success)\n";
1046 print "ioctl returned error code $rc.\n";
1051 if (!defined($::client_id)) {
1052 print "You must first ``connect''.\n";
1064 # __kernel_fsid_t f_fsid; (64 bits)
1069 my $packed = pack("LLLLLLLIILL6", $::client_id, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1072 my $rc = ioctl(DEV_OBD, &OBD_IOC_STATFS, $packed);
1075 print STDERR "ioctl failed: $!\n";
1076 } elsif ($rc eq "0 but true") {
1077 # skip both the conn_id and the fs_type in the buffer
1078 my ($bsize, $blocks, $bfree, $bavail, $files, $ffree) =
1079 unpack("x4x4LLLLLL", $packed);
1080 print("$bsize byte blocks: $blocks, " . ($blocks - $bfree) . " used, " .
1081 "$bfree free ($bavail available).\n");
1082 print "$files files, " . ($files - $ffree) . " used, $ffree free.\n";
1083 print "Finished (success)\n";
1085 print "ioctl returned error code $rc.\n";
1092 if ( !$arg || !$commands{$arg} ) {
1093 print "Comands: ", join( ' ', @jcm_cmd_list), "\n";
1095 print "Usage: " . $commands{$arg}->{doc} . "\n";
1101 print "Disconnecting active session ($::client_id)...";
1102 Disconnect($::client_id);