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_SNAP_DELETE() { &_IOC(3, ord(\'f\'), 42, 4);}' unless
70 defined(&OBD_SNAP_DELETE);
71 eval 'sub OBD_SNAP_RESTORE() { &_IOC(3, ord(\'f\'), 43, 4);}' unless
72 defined(&OBD_SNAP_RESTORE);
74 eval 'sub OBD_EXT2_RUNIT () { &_IOC(3, ord(\'f\'), 61, 4);}' unless
75 defined(&OBD_EXT2_RUNIT);
77 eval 'sub ATTR_MODE () {1;}' unless defined(&ATTR_MODE);
78 eval 'sub ATTR_UID () {2;}' unless defined(&ATTR_UID);
79 eval 'sub ATTR_GID () {4;}' unless defined(&ATTR_GID);
80 eval 'sub ATTR_SIZE () {8;}' unless defined(&ATTR_SIZE);
81 eval 'sub ATTR_ATIME () {16;}' unless defined(&ATTR_ATIME);
82 eval 'sub ATTR_MTIME () {32;}' unless defined(&ATTR_MTIME);
83 eval 'sub ATTR_CTIME () {64;}' unless defined(&ATTR_CTIME);
95 GetOptions("f!" => \$file, "device=s" => \$::device, "fs=s" => $::filesystem) || die "Getoptions";
98 # get a console for the app
105 ('device' => {func => "Device", doc => "device <dev>: open another OBD device"},
106 'filesystem' => {func => "Filesystem", doc => "filesystem <dev>: partition for direct OBD device"},
107 'create' => {func => "Create", doc => "create: creates a new inode"},
108 'attach' => {func => "Attach", doc => "attach type [adapter bus tid lun]"},
109 'detach' => {func => "Detach", doc => "detach this device"},
110 'snapattach' => {func => "SnapAttach", doc => "snapattach snapno table"},
111 'snapset' => {func => "SnapSetTable", doc => "snapset tableno file" },
112 'snapprint' => {func => "SnapPrint", doc => "snapprint tableno"},
114 'testext2iterator' => {func => "TestExt2Iterator", doc => ""},
115 'snapdelete' => {func => "SnapDelete", doc => "snapdelete: delete connected snap obd"},
116 'snaprestore' => {func => "SnapRestore", doc => "snaprestore: restore connected old snap to current"},
118 'snaptable' => {func => "SnapShotTable", doc => "snaptable: build a snapshot table (interactive)"},
119 'copy' => {func => "Copy", doc => "copy srcid tgtid"},
120 'migrate' => {func => "Migrate", doc => "migrate srcid tgtid"},
121 'format' => {func => "Format", doc => "format type adapter bus tid lun size"},
122 'partition' => {func => "Partition", doc => "partition type adapter bus tid lun partition size"},
123 'setup' => {func => "Setup", doc => "setup: link the ext2 partition (default /dev/loop0) to this obddev"},
124 'connect' => {func => "Connect", doc => "connect: allocates client ID for this session"},
125 'disconnect' => {func => "Disconnect", doc => "disconnect [id]: frees client resources"},
126 'sync' => {func => "Sync", doc => "sync: flushes buffers to disk"},
127 'destroy' => {func => "Destroy", doc => "setup: destroys an inode"},
128 'cleanup' => {func => "Cleanup", doc => "cleanup the minor obd device"},
129 'dec_use_count' => {func => "Decusecount", doc => "decreases the module use count so that the module can be removed following an oops"},
130 'read' => {func => "Read", doc => "read <inode> <count> [offset]"},
131 'fsread' => {func => "Read2", doc => "read <inode> <count> [offset]"},
132 'write' => {func => "Write", doc => "write <inode> <offset> <text>"},
133 'setattr' => {func => "Setattr", doc => "setattr <inode> [mode [uid [gid [size [atime [mtime [ctime]]]]]]]"},
134 'getattr' => {func => "Getattr", doc => "getattr <inode>: displays inode object attributes"},
135 'preallocate' => {func => "Preallocate", doc => "preallocate [num]: requests preallocation of num inodes."},
136 'statfs' => {func => "Statfs", doc => "statfs: filesystem status information"},
137 'help' => {func => \&Help, doc => "help: this message"},
138 'quit' => {func => \&Quit, doc => "see \"exit\""},
139 'exit' => {func => \&Quit, doc => "see \"quit\""}
143 # setup completion function
145 my @jcm_cmd_list = keys %commands;
153 Filesystem($::filesystem);
161 return $term->readline(@_);
174 $term = new Term::ReadLine 'obdcontrol ';
175 $attribs = $term->Attribs;
176 $attribs->{attempted_completion_function} = \&completeme;
177 $term->ornaments('md,me,,'); # bold face prompt
179 # make sure stdout is not buffered
180 STDOUT->autoflush(1);
183 # Get on with the show
187 #------------------------------------------------------------------------------
189 my ($text, $line, $start, $end) = @_;
190 if (substr($line, 0, $start) =~ /^\s*$/) {
191 $attribs->{completion_word} = \@jcm_cmd_list;
192 return $term->completion_matches($text,
193 $attribs->{'list_completion_function'});
200 my @completions = completeme($given, $given, 0, length($given));
201 if ($#completions == 0) {
202 $name = shift @completions;
208 # start making requests
211 $line = $term->readline("obdcontrol > ");
219 my @arg = split(' ', $line);
220 my $word = shift @arg;
226 $cmd = find_command($word);
229 printf STDERR "$word: No such command, or not unique.\n";
233 if ($cmd eq "help" || $cmd eq "exit" || $cmd eq "quit") {
234 return (&{$commands{$cmd}->{func}}(@arg));
238 return (&{$commands{$cmd}->{func}}(@arg));
241 # set the object store in the ext2 formatted block device
243 my $filesystem = shift;
244 $filesystem = "/dev/loop0" unless $filesystem;
246 $::filesystem = $filesystem;
247 if (!defined($::st = stat($filesystem))) {
248 die "Unable to stat $filesystem.\n";
252 # select the OBD device we talk to
257 $device = "/dev/obd0";
260 # Open the device, as we need an FD for the ioctl
261 sysopen(DEV_OBD, $device, 0) || die "Cannot open $device";
262 print "Device now $device\n";
273 if ($type eq "obdscsi" ) {
278 $data = pack("iiiii", $adapter, $bus, $tid, $lun, $size);
282 my $packed = pack("Lipip", $::client_id, length($type), $type, $datalen, $data);
284 my $rc = ioctl(DEV_OBD, &OBD_IOC_ATTACH, $packed);
287 print STDERR "ioctl failed: $!\n";
288 } elsif ($rc eq "0 but true") {
289 print "Finished (success)\n";
291 print "ioctl returned error code $rc.\n";
298 my $rc = ioctl(DEV_OBD, &OBD_IOC_DETACH, $data);
301 print STDERR "ioctl failed: $!\n";
302 } elsif ($rc eq "0 but true") {
303 print "Finished (success)\n";
305 print "ioctl returned error code $rc.\n";
310 sub TestExt2Iterator {
312 my $type = "ext2_obd";
314 $data = pack("i", 4711); # bogus data
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 my $packed = pack("Lipip", $::client_id, length($type), $type, $datalen, $data);
323 my $rc = ioctl(DEV_OBD, &OBD_EXT2_RUNIT, $packed);
326 print STDERR "ioctl failed: $!\n";
327 } elsif ($rc eq "0 but true") {
328 print "Finished (success)\n";
330 print "ioctl returned error code $rc.\n";
337 my $type = "snap_obd";
339 $data = pack("i", 4711); # bogus data
342 my $len = length($type);
343 my $cl = length($data);
344 my $add = pack("p", $data);
345 print "type $type (len $len), datalen $datalen ($cl)\n";
346 my $packed = pack("Lipip", $::client_id, length($type), $type, $datalen, $data);
348 my $rc = ioctl(DEV_OBD, &OBD_SNAP_DELETE, $packed);
351 print STDERR "ioctl failed: $!\n";
352 } elsif ($rc eq "0 but true") {
353 print "Finished (success)\n";
355 print "ioctl returned error code $rc.\n";
362 my $type = "snap_obd";
363 my $prevcurrent = shift;
365 $data = pack("i", $prevcurrent); # where the previous current snapshot now lives
368 my $len = length($type);
369 my $cl = length($data);
370 my $add = pack("p", $data);
371 print "type $type (len $len), datalen $datalen ($cl)\n";
372 my $packed = pack("Lipip", $::client_id, length($type), $type, $datalen, $data);
374 my $rc = ioctl(DEV_OBD, &OBD_SNAP_RESTORE, $packed);
377 print STDERR "ioctl failed: $!\n";
378 } elsif ($rc eq "0 but true") {
379 print "Finished (success)\n";
381 print "ioctl returned error code $rc.\n";
389 my $type = "snap_obd";
390 my $snaptableno = shift;
392 $data = pack("i", $snaptableno);
395 my $len = length($type);
396 my $cl = length($data);
397 my $add = pack("p", $data);
398 print "type $type (len $len), datalen $datalen ($cl)\n";
399 my $packed = pack("Lipip", $::client_id, length($type), $type, $datalen, $data);
401 my $rc = ioctl(DEV_OBD, &OBD_SNAP_PRINTTABLE, $packed);
404 print STDERR "ioctl failed: $!\n";
405 } elsif ($rc eq "0 but true") {
406 print "Finished (success)\n";
408 print "ioctl returned error code $rc.\n";
414 my $type = "snap_obd";
415 my $snaptableno = shift;
423 print "No such file $file\n";
426 $table = ReadSnapShotTable($file);
428 $snapcount = keys %{$table};
429 print "Snapcount $snapcount\n";
431 if ( ! defined $table->{0} ) {
432 print "No current snapshot in table! First make one\n";
435 $data = pack("ii", $snaptableno, $snapcount);
437 foreach my $time (sort keys %{$table}) {
438 $data .= pack("Ii", $time, $table->{$time});
442 my $len = length($type);
443 my $cl = length($data);
444 my $add = pack("p", $data);
445 print "type $type (len $len), datalen $datalen ($cl)\n";
446 my $packed = pack("Lipip", $::client_id, length($type), $type, $datalen, $data);
448 my $rc = ioctl(DEV_OBD, &OBD_SNAP_SETTABLE, $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";
462 my $type = "snap_obd";
470 $data = pack("iii", $snapdev, $snapno, $tableno);
473 my $len = length($type);
474 my $cl = length($data);
475 my $add = pack("p", $data);
476 print "type $type (len $len), datalen $datalen ($cl)\n";
477 my $packed = pack("Lipip", $::client_id, length($type), $type, $datalen, $data);
479 my $rc = ioctl(DEV_OBD, &OBD_IOC_ATTACH, $packed);
482 print STDERR "ioctl failed: $!\n";
483 } elsif ($rc eq "0 but true") {
484 print "Finished (success)\n";
486 print "ioctl returned error code $rc.\n";
493 my $file = &readl("enter file name: ");
497 my $table = ReadSnapShotTable($file);
500 PrintSnapShotTable($table);
501 my $action = &readl("Add, Delete or Quit [adq]: ");
502 goto done if ($action =~ "^q.*" );
503 goto add if ($action =~ "^a.*");
504 goto del if ($action =~ "^d.*");
508 my $idx = &readl("enter index where you want this snapshot: ");
509 my $time = &readl("enter time or 'now' or 'current': ");
510 my $oldtime = SnapFindTimeFromIdx($idx, $table);
511 if (defined $oldtime) {
512 print "This already exists, first clean up\n";
516 if ( $time eq 'now' ) {
518 } elsif ( $time eq 'current' ) {
521 $table->{$time} = $idx;
525 $didx = &readl("Enter index to delete: ");
526 my $deltime = SnapFindTimeFromIdx($didx, $table);
527 delete $table->{$deltime} if defined $deltime;
531 my $ok = &readl("OK with new table? [Yn]: ");
532 unless ( $ok eq "no" ) {
533 WriteSnapShotTable($file, $table);
537 sub SnapFindTimeFromIdx {
541 foreach my $time ( keys %{$table} ) {
542 if ( $table->{$time} == $idx ) {
549 sub PrintSnapShotTable {
553 foreach $time ( sort keys %{$table} ) {
554 my $stime = localtime($time);
558 printf "Time: %s -- Index %d\n", $stime, $table->{$time};
562 sub ReadSnapShotTable {
569 my ($time, $index) = split ;
570 $table->{$time} = $index;
574 PrintSnapShotTable($table);
579 sub WriteSnapShotTable {
584 foreach my $time ( sort keys %{$table} ) {
585 print FH "$time $table->{$time}\n";
594 my $data = pack("III", $::client_id, $srcid, $tgtid);
597 my $packed = pack("ip", $datalen, $data);
598 my $rc = ioctl(DEV_OBD, &OBD_IOC_COPY, $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";
613 my $data = pack("III", $::client_id, $srcid, $tgtid);
616 my $packed = pack("ip", $datalen, $data);
617 my $rc = ioctl(DEV_OBD, &OBD_IOC_MIGR, $packed);
620 print STDERR "ioctl failed: $!\n";
621 } elsif ($rc eq "0 but true") {
622 print "Finished (success)\n";
624 print "ioctl returned error code $rc.\n";
632 my $data = pack("i", $size);
635 my $packed = pack("ip", $datalen, $data);
636 my $rc = ioctl(DEV_OBD, &OBD_IOC_FORMATOBD, $packed);
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";
651 my $data = pack("ii", $partno, $size);
654 my $packed = pack("ip", $datalen, $data);
655 my $rc = ioctl(DEV_OBD, &OBD_IOC_PARTITION, $packed);
658 print STDERR "ioctl failed: $!\n";
659 } elsif ($rc eq "0 but true") {
660 print "Finished (success)\n";
662 print "ioctl returned error code $rc.\n";
672 $type = "ext2_obd" unless $type;
674 if ( $type eq "ext2_obd" ) {
676 $dev = $::st->rdev() unless $dev;
677 $data = pack("i", $dev);
681 my $packed = pack("ip", $datalen, $data);
682 my $rc = ioctl(DEV_OBD, &OBD_IOC_SETUP, $packed);
685 print STDERR "ioctl failed: $!\n";
686 } elsif ($rc eq "0 but true") {
687 print "Finished (success)\n";
689 print "ioctl returned error code $rc.\n";
695 my $rc = ioctl(DEV_OBD, &OBD_IOC_CLEANUP, $err);
698 print STDERR "ioctl failed: $!\n";
699 } elsif ($rc eq "0 but true") {
700 print "Finished (success)\n";
703 print "ioctl returned error code $rc.\n";
712 $rc = ioctl(DEV_OBD, &OBD_IOC_CONNECT, $packed);
713 $id = unpack("I", $packed);
716 print STDERR "ioctl failed: $!\n";
717 } elsif ($rc eq "0 but true") {
719 print "Client ID : $id\n";
720 print "Finished (success)\n";
722 print "ioctl returned error code $rc.\n";
734 print "syntax: disconnect [client ID]\n";
735 print "When client ID is not given, the last valid client ID to be returned by a\n";
736 print "connect command this session is used; there is no such ID.\n";
740 my $packed = pack("L", $id);
741 my $rc = ioctl(DEV_OBD, &OBD_IOC_DISCONNECT, $packed);
744 print STDERR "ioctl failed: $!\n";
745 } elsif ($rc eq "0 but true") {
746 $::client_id = undef;
747 print "Finished (success)\n";
749 print "ioctl returned error code $rc.\n";
759 if (defined($quiet) && !($quiet eq "quiet")) {
760 print "syntax: create [number of objects [quiet]]\n";
764 my $packed = pack("IL", $::client_id, $prealloc);
765 if (!defined($arg) || scalar($arg) < 2) {
766 print "Creating 1 object...\n";
767 $rc = ioctl(DEV_OBD, &OBD_IOC_CREATE, $packed);
768 if (!defined($quiet)) {
769 my $ino = unpack("L", $packed);
770 print "Created object #$ino.\n";
775 print "Creating " . scalar($arg) . " objects...\n";
776 for ($i = 0; $i < scalar($arg); $i++) {
777 $rc = ioctl(DEV_OBD, &OBD_IOC_CREATE, $packed);
778 my $ino = unpack("L", $packed);
779 if (!($rc eq "0 but true")) {
781 $packed = pack("IL", $::client_id, $prealloc);
782 } elsif (!defined($quiet)) {
783 $packed = pack("IL", $::client_id, $prealloc);
784 print "Created object #$ino.\n";
790 print STDERR "ioctl failed: $!\n";
791 } elsif ($rc eq "0 but true") {
792 print "Finished (success)\n";
794 print "ioctl returned error code $rc.\n";
800 my $rc = ioctl(DEV_OBD, &OBD_IOC_SYNC, $err);
803 print STDERR "ioctl failed: $!\n";
804 } elsif ($rc eq "0 but true") {
805 print "Finished (success)\n";
807 print "ioctl returned error code $rc.\n";
812 if (!defined($::client_id)) {
813 print "You must first ``connect''.\n";
819 if (!defined($arg) || scalar($arg) < 1) {
820 print "destroy requires the object number to destroy.\n";
824 print "Destroying object $arg...\n";
825 my $packed = pack("IL", $::client_id, $arg);
826 my $rc = ioctl(DEV_OBD, &OBD_IOC_DESTROY, $packed);
829 print STDERR "ioctl failed: $!\n";
830 } elsif ($rc eq "0 but true") {
831 print "Finished (success)\n";
833 print "ioctl returned error code $rc.\n";
838 if (!defined($::client_id)) {
839 print "You must first ``connect''.\n";
845 if (!defined($inode) || scalar($inode) < 1) {
846 print "invalid arguments; type \"help getattr\" for a synopsis\n";
851 my $packed = pack("ILsx2lLLLI", $::client_id, $inode, 0, 0, 0, 0, 0, 0, 0,
853 my $rc = ioctl(DEV_OBD, &OBD_IOC_GETATTR, $packed);
856 print STDERR "ioctl failed: $!\n";
857 } elsif ($rc eq "0 but true") {
858 my ($valid, $mode, $uid, $gid, $size, $atime, $mtime, $ctime, $flags);
859 ($valid, $mode, $uid, $gid, $size, $atime, $mtime, $ctime, $flags) =
860 unpack("ISssx2lLLLI", $packed);
862 printf("Inode: %d Mode: %o\n", $inode, $mode);
863 printf("User: %6d Group: %6d Size: %d\n", $uid, $gid, $size);
864 printf("ctime: %08lx -- %s\n", $ctime, scalar(gmtime($ctime)));
865 printf("atime: %08lx -- %s\n", $atime, scalar(gmtime($atime)));
866 printf("mtime: %08lx -- %s\n", $mtime, scalar(gmtime($mtime)));
867 printf("flags: %08x\n", $flags);
868 print "Finished (success)\n";
870 print "ioctl returned error code $rc.\n";
875 if (!defined($::client_id)) {
876 print "You must first ``connect''.\n";
882 my $mode = oct(shift);
896 if (defined($size)) {
897 $valid |= &ATTR_SIZE;
899 if (defined($atime)) {
900 $valid |= &ATTR_ATIME;
902 if (defined($mtime)) {
903 $valid |= &ATTR_MTIME;
905 if (defined($ctime)) {
906 $valid |= &ATTR_CTIME;
908 if (defined($mode)) {
909 $valid |= &ATTR_MODE;
912 if (!defined($inode) || scalar($inode) < 1) {
913 print "invalid arguments; type \"help setattr\" for a synopsis\n";
918 # unsigned int ia_valid; (32)
919 # umode_t ia_mode; (16)
922 # -- 16 bit alignment here! --
923 # off_t ia_size; (32)
924 # time_t ia_atime; (32)
925 # time_t ia_mtime; (32)
926 # time_t ia_ctime; (32)
927 # unsigned int ia_attr_flags; (32)
930 printf "valid is %x, mode is %o\n", $valid, $mode;
931 my $packed = pack("ILLSssx2ILLLL", $::client_id, $inode, $valid, $mode,
932 $uid, $gid, $size, $atime, $mtime, $ctime, 0);
933 my $rc = ioctl(DEV_OBD, &OBD_IOC_SETATTR, $packed);
936 print STDERR "ioctl failed: $!\n";
937 } elsif ($rc eq "0 but true") {
938 print "Finished (success)\n";
940 print "ioctl returned error code $rc.\n";
945 if (!defined($::client_id)) {
946 print "You must first ``connect''.\n";
954 if (!defined($inode) || scalar($inode) < 1 || !defined($count) ||
955 $count < 1 || (defined($offset) && $offset < 0)) {
956 print "invalid arguments; type \"help read\" for a synopsis\n";
960 if (!defined($offset)) {
964 print("Reading $count bytes starting at byte $offset from object " .
967 # "allocate" a large enough buffer
968 my $buf = sprintf("%${count}s", " ");
969 die "suck" if (length($buf) != $count);
971 # the perl we're using doesn't support pack type Q, and offset is 64 bits
972 my $packed = pack("ILpLLL", $::client_id, $inode, $buf, $count, $offset, 0);
974 my $rc = ioctl(DEV_OBD, &OBD_IOC_READ, $packed);
976 $retval = unpack("l", $packed);
979 print STDERR "ioctl failed: $!\n";
980 } elsif ($rc eq "0 but true") {
982 print substr($buf, 0, $retval);
983 print "\nRead $retval of an attempted $count bytes.\n";
984 print "Finished (success)\n";
986 print "Finished (error $retval)\n";
989 print "ioctl returned error code $rc.\n";
994 if (!defined($::client_id)) {
995 print "You must first ``connect''.\n";
1003 if (!defined($inode) || scalar($inode) < 1 || !defined($count) ||
1004 $count < 1 || (defined($offset) && $offset < 0)) {
1005 print "invalid arguments; type \"help read\" for a synopsis\n";
1009 if (!defined($offset)) {
1013 print("Reading $count bytes starting at byte $offset from object " .
1016 # "allocate" a large enough buffer
1017 my $buf = sprintf("%${count}s", " ");
1018 die "suck" if (length($buf) != $count);
1020 # the perl we're using doesn't support pack type Q, and offset is 64 bits
1021 my $packed = pack("ILpLLL", $::client_id, $inode, $buf, $count, $offset, 0);
1023 my $rc = ioctl(DEV_OBD, &OBD_IOC_READ2, $packed);
1025 $retval = unpack("l", $packed);
1028 print STDERR "ioctl failed: $!\n";
1029 } elsif ($rc eq "0 but true") {
1031 print substr($buf, 0, $retval);
1032 print "\nRead $retval of an attempted $count bytes.\n";
1033 print "Finished (success)\n";
1035 print "Finished (error $retval)\n";
1038 print "ioctl returned error code $rc.\n";
1043 if (!defined($::client_id)) {
1044 print "You must first ``connect''.\n";
1050 my $text = join(' ', @_);
1051 my $count = length($text);
1053 if (!defined($inode) || scalar($inode) < 1 || !defined($offset) ||
1054 scalar($offset) < 0) {
1055 print "invalid arguments; type \"help write\" for a synopsis\n";
1059 if (!defined($text)) {
1064 print("Writing $count bytes starting at byte $offset to object " .
1067 # the perl we're using doesn't support pack type Q
1068 my $packed = pack("ILpLLL", $::client_id, $inode, $text, $count, $offset, 0);
1069 my $rc = ioctl(DEV_OBD, &OBD_IOC_WRITE, $packed);
1071 $retval = unpack("l", $packed);
1074 print STDERR "ioctl failed: $!\n";
1075 } elsif ($rc eq "0 but true") {
1077 print "\nWrote $retval of an attempted $count bytes.\n";
1078 print "Finished (success)\n";
1080 print "Finished (error $retval)\n";
1083 print "ioctl returned error code $rc.\n";
1090 if (!defined($::client_id)) {
1091 print "You must first ``connect''.\n";
1095 if (!defined($arg) || scalar($arg) < 1 || scalar($arg) > 32) {
1099 print "Preallocating $arg inodes...\n";
1100 my $packed = pack("LLx128", $::client_id, $arg);
1101 # client id, alloc, inodes[32]
1103 my $rc = ioctl(DEV_OBD, &OBD_IOC_PREALLOCATE, $packed);
1106 print STDERR "ioctl failed: $!\n";
1107 } elsif ($rc eq "0 but true") {
1108 my $alloc = unpack("x4L", $packed);
1109 my @inodes = unpack("x8L32", $packed);
1112 print "Got $alloc inodes: ";
1113 foreach $i (@inodes) {
1116 print "\nFinished (success)\n";
1118 print "ioctl returned error code $rc.\n";
1123 my $rc = ioctl(DEV_OBD, &OBD_IOC_DEC_USE_COUNT, 0);
1126 print STDERR "ioctl failed: $!\n";
1127 } elsif ($rc eq "0 but true") {
1128 print "Finished (success)\n";
1130 print "ioctl returned error code $rc.\n";
1135 if (!defined($::client_id)) {
1136 print "You must first ``connect''.\n";
1148 # __kernel_fsid_t f_fsid; (64 bits)
1153 my $packed = pack("LLLLLLLIILL6", $::client_id, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1156 my $rc = ioctl(DEV_OBD, &OBD_IOC_STATFS, $packed);
1159 print STDERR "ioctl failed: $!\n";
1160 } elsif ($rc eq "0 but true") {
1161 # skip both the conn_id and the fs_type in the buffer
1162 my ($bsize, $blocks, $bfree, $bavail, $files, $ffree) =
1163 unpack("x4x4LLLLLL", $packed);
1164 print("$bsize byte blocks: $blocks, " . ($blocks - $bfree) . " used, " .
1165 "$bfree free ($bavail available).\n");
1166 print "$files files, " . ($files - $ffree) . " used, $ffree free.\n";
1167 print "Finished (success)\n";
1169 print "ioctl returned error code $rc.\n";
1176 if ( !$arg || !$commands{$arg} ) {
1177 print "Comands: ", join( ' ', @jcm_cmd_list), "\n";
1179 print "Usage: " . $commands{$arg}->{doc} . "\n";
1185 print "Disconnecting active session ($::client_id)...";
1186 Disconnect($::client_id);