Whamcloud - gitweb
Added code for obdfs to do writes to files and reads of directories and
[fs/lustre-release.git] / lustre / obdclass / obdcontrol
1 #!/usr/bin/perl
2
3 #
4 # This code is issued under the GNU General Public License.
5 # See the file COPYING in this distribution
6 #
7 # Copyright (C) 1998, Stelias Computing
8
9 # Modified for InterMezzo from Gordian's HSM bcache device/jcm module
10 # Copyright (C) 1999, Carnegie Mellon University
11 #
12 # Derived from InterMezzo's incontrol, modified for OBD's
13 # Copyright (C) 1999, Stelias Computing
14 #
15 #
16
17 #use strict;
18 BEGIN { require "asm/errno.ph" };
19 BEGIN { require "asm/ioctl.ph" };
20
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_OBDDEV () { &_IOC(1, ord(\'f\'), 4, 4);}' unless
25   defined(&OBD_IOC_SETUP_OBDDEV);
26 eval 'sub OBD_IOC_CLEANUP_OBDDEV () { &_IOC(0, ord(\'f\'), 5, 0);}' unless
27   defined(&OBD_IOC_CLEANUP_OBDDEV);
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_READ2 () { &_IOC(3, ord(\'f\'), 17, 4);}' unless
41   defined(&OBD_IOC_READ2);
42 eval 'sub OBD_IOC_WRITE () { &_IOC(3, ord(\'f\'), 12, 4);}' unless
43   defined(&OBD_IOC_WRITE);
44 eval 'sub OBD_IOC_CONNECT () { &_IOC(2, ord(\'f\'), 13, 4);}' unless
45   defined(&OBD_IOC_CONNECT);
46 eval 'sub OBD_IOC_DISCONNECT () { &_IOC(1, ord(\'f\'), 14, 4);}' unless
47   defined(&OBD_IOC_DISCONNECT);
48 eval 'sub OBD_IOC_STATFS () { &_IOC(3, ord(\'f\'), 15, 4);}' unless
49   defined(&OBD_IOC_STATFS);
50 eval 'sub OBD_IOC_SYNC () { &_IOC(2, ord(\'f\'), 16, 4);}' unless
51   defined(&OBD_IOC_SYNC);
52
53 eval 'sub ATTR_MODE () {1;}' unless defined(&ATTR_MODE);
54 eval 'sub ATTR_UID () {2;}' unless defined(&ATTR_UID);
55 eval 'sub ATTR_GID () {4;}' unless defined(&ATTR_GID);
56 eval 'sub ATTR_SIZE () {8;}' unless defined(&ATTR_SIZE);
57 eval 'sub ATTR_ATIME () {16;}' unless defined(&ATTR_ATIME);
58 eval 'sub ATTR_MTIME () {32;}' unless defined(&ATTR_MTIME);
59 eval 'sub ATTR_CTIME () {64;}' unless defined(&ATTR_CTIME);
60
61 use Getopt::Long;
62 use File::stat;
63 use Storable;
64 use Carp;
65 use Term::ReadLine;
66 use IO::Handle;
67
68 my ($device, $filesystem);
69 # startup options (I'll replace these when I have some to replace with)
70 GetOptions("device=s" => \$device, "fs=s" => $filesystem) || die "Getoptions";
71
72 # genuine new simulated OBD device
73 $device = "/dev/obd" unless $device;
74 # object store in the ext2 formatted block device
75 $filesystem = "/dev/loop0" unless $filesystem;
76
77 # get a console for the app
78 my $term = new Term::ReadLine 'obdcontrol ';
79 my $attribs = $term->Attribs;
80 $term->ornaments('md,me,,');    # bold face prompt
81
82 # make sure stdout is not buffered
83 STDOUT->autoflush(1);
84
85 my $line;
86 my $command;
87 my $arg;
88
89 my %commands =
90     ('create' => {func => "Create", doc => "create: creates a new inode"},
91      'setup' => {func => "Setup", doc => "setup: link the ext2 partition (default /dev/loop0) to this obddev"},
92      'connect' => {func => "Connect", doc => "connect: allocates client ID for this session"},
93      'disconnect' => {func => "Disconnect", doc => "disconnect [id]: frees client resources"},
94      'sync' => {func => "Sync", doc => "sync: flushes buffers to disk"},
95      'destroy' => {func => "Destroy", doc => "setup: destroys an inode"},
96      'cleanup' => {func => "Cleanup", doc => "cleanup the minor obd device"},
97      'dec_use_count' => {func => "Decusecount", doc => "decreases the module use count so that the module can be removed following an oops"},
98      'read' => {func => "Read", doc => "read <inode> <count> [offset]"},
99      'fsread' => {func => "Read2", doc => "read <inode> <count> [offset]"},
100      'write' => {func => "Write", doc => "write <inode> <offset> <text>"},
101      'setattr' => {func => "Setattr", doc => "setattr <inode> [mode [uid [gid [size [atime [mtime [ctime]]]]]]]"},
102      'getattr' => {func => "Getattr", doc => "getattr <inode>: displays inode object attributes"},
103      'preallocate' => {func => "Preallocate", doc => "preallocate [num]: requests preallocation of num inodes."},
104      'statfs' => {func => "Statfs", doc => "statfs: filesystem status information"},
105      'help' => {func => \&Help,  doc => "help: this message"},
106      'quit' => {func => \&Quit,  doc => "see \"exit\""},
107      'exit' => {func => \&Quit,  doc => "see \"quit\""}
108     );
109
110 #
111 #       setup completion function
112 #
113 my @jcm_cmd_list = keys %commands;
114
115 $attribs->{attempted_completion_function} = \&completeme;
116 #------------------------------------------------------------------------------
117 # Open the device, as we need an FD for the ioctl
118 sysopen(DEV_OBD, $device, 0) || die "Cannot open $device";
119
120 if (!defined($::st = stat($filesystem))) {
121     die "Unable to stat $filesystem.\n";
122 }
123
124 # Get on with the show
125 process_line();
126
127 #------------------------------------------------------------------------------
128 sub completeme {
129     my ($text, $line, $start, $end) = @_;
130     if (substr($line, 0, $start) =~ /^\s*$/) {
131         $attribs->{completion_word} = \@jcm_cmd_list;
132         return $term->completion_matches($text,
133                                          $attribs->{'list_completion_function'});
134     }
135 }
136
137 sub find_command {
138     my $given = shift;
139     my $name;
140     my @completions = completeme($given, $given, 0, length($given));
141     if ($#completions == 0) {
142         $name = shift @completions;
143     }
144
145     return $name;
146 }
147
148 # start making requests
149 sub process_line {
150   foo:
151     $line = $term->readline("obdcontrol > ");
152     execute_line($line);
153     goto foo;
154 }
155
156 sub execute_line {
157     my $line = shift;
158
159     my @arg = split(' ', $line);
160     my $word = shift @arg;
161
162     my $cmd = find_command($word);
163     unless ($cmd) {
164         printf STDERR "$word: No such command, or not unique.\n";
165         return (-1);
166     }
167
168     if ($cmd eq "help" || $cmd eq "exit" || $cmd eq "quit") {
169         return (&{$commands{$cmd}->{func}}(@arg));
170     }
171
172     # Call the function.
173     return (&{$commands{$cmd}->{func}}(@arg));
174 }
175
176 sub Setup {
177     my $err = 0;
178     
179     my $packed = pack("La24", $::st->rdev(), "sim_obd");
180     my $rc = ioctl(DEV_OBD, &OBD_IOC_SETUP_OBDDEV, $packed);
181
182     if (!defined $rc) {
183         print STDERR "ioctl failed: $!\n";
184     } elsif ($rc eq "0 but true") {
185         print "Finished (success)\n";
186     } else {
187         print "ioctl returned error code $rc.\n";
188     }
189 }
190
191 sub Cleanup {
192     my $err = "0";
193     my $rc = ioctl(DEV_OBD, &OBD_IOC_CLEANUP_OBDDEV, $err);
194
195     if (!defined $rc) {
196         print STDERR "ioctl failed: $!\n";
197     } elsif ($rc eq "0 but true") {
198         print "Finished (success)\n";
199     } else {
200         print "ioctl returned error code $rc.\n";
201     }
202 }
203
204
205 sub Connect {
206     my $id = 0;
207     my $ino = 0;
208     my $bs = 0;
209     my $bs_b = 0;
210     my $rc;
211
212     # unsigned int conn_id;
213     # unsigned long conn_ino;
214     # unsigned long conn_blocksize;
215     # unsigned char conn_blocksize_bits;
216
217     my $packed = pack("ILLC", $id, $ino, $bs, $bs_b);
218     $rc = ioctl(DEV_OBD, &OBD_IOC_CONNECT, $packed);
219     ($id, $ino, $bs, $bs_b) = unpack("ILLC", $packed);
220
221     if (!defined $rc) {
222         print STDERR "ioctl failed: $!\n";
223     } elsif ($rc eq "0 but true") {
224         $::client_id = $id;
225         print "Client ID     : $id\n";
226         print "Root inode    : $ino\n";
227         print "Blocksize     : $bs\n";
228         print "Blocksize bits: $bs_b\n";
229         print "Finished (success)\n";
230     } else {
231         print "ioctl returned error code $rc.\n";
232     }
233 }
234
235 sub Disconnect {
236     my $id = shift;
237
238     if (!defined($id)) {
239         $id = $::client_id;
240     }
241
242     if (!defined($id)) {
243         print "syntax: disconnect [client ID]\n";
244         print "When client ID is not given, the last valid client ID to be returned by a\n";
245         print "connect command this session is used; there is no such ID.\n";
246         return;
247     }
248
249     my $packed = pack("L", $id);
250     my $rc = ioctl(DEV_OBD, &OBD_IOC_DISCONNECT, $packed);
251
252     if (!defined $rc) {
253         print STDERR "ioctl failed: $!\n";
254     } elsif ($rc eq "0 but true") {
255         $::client_id = undef;
256         print "Finished (success)\n";
257     } else {
258         print "ioctl returned error code $rc.\n";
259     }
260 }
261
262 sub Create {
263     my $arg = shift;
264     my $quiet = shift;
265     my $rc;
266
267     if (defined($quiet) && !($quiet eq "quiet")) {
268         print "syntax: create [number of objects [quiet]]\n";
269         return;
270     }
271
272     my $packed = pack("I", $::client_id);
273     if (!defined($arg) || scalar($arg) < 2) {
274         print "Creating 1 object...\n";
275         my $packed = pack("I", 0);
276         $rc = ioctl(DEV_OBD, &OBD_IOC_CREATE, $packed);
277         if (!defined($quiet)) {
278             my $ino = unpack("L", $packed);
279             print "Created object #$ino.\n";
280         }
281     } else {
282         my $i;
283
284         print "Creating " . scalar($arg) . " objects...\n";
285         for ($i = 0; $i < scalar($arg); $i++) {
286             $rc = ioctl(DEV_OBD, &OBD_IOC_CREATE, $packed);
287             my $ino = unpack("L", $packed);
288             if (!($rc eq "0 but true") || $packed == 0) {
289                 last;
290             } elsif (!defined($quiet)) {
291                 print "Created object #$ino.\n";
292             }
293         }
294     }
295
296     if (!defined $rc) {
297         print STDERR "ioctl failed: $!\n";
298     } elsif ($rc eq "0 but true") {
299         print "Finished (success)\n";
300     } else {
301         print "ioctl returned error code $rc.\n";
302     }
303 }
304
305 sub Sync {
306     my $err = "0";
307     my $rc = ioctl(DEV_OBD, &OBD_IOC_SYNC, $err);
308
309     if (!defined $rc) {
310         print STDERR "ioctl failed: $!\n";
311     } elsif ($rc eq "0 but true") {
312         print "Finished (success)\n";
313     } else {
314         print "ioctl returned error code $rc.\n";
315     }
316 }
317
318 sub Destroy {
319     if (!defined($::client_id)) {
320         print "You must first ``connect''.\n";
321         return;
322     }
323
324     my $arg = shift;
325
326     if (!defined($arg) || scalar($arg) < 1) {
327         print "destroy requires the object number to destroy.\n";
328         return;
329     }
330
331     print "Destroying object $arg...\n";
332     my $packed = pack("IL", $::client_id, $arg);
333     my $rc = ioctl(DEV_OBD, &OBD_IOC_DESTROY, $packed);
334
335     if (!defined $rc) {
336         print STDERR "ioctl failed: $!\n";
337     } elsif ($rc eq "0 but true") {
338         print "Finished (success)\n";
339     } else {
340         print "ioctl returned error code $rc.\n";
341     }
342 }
343
344 sub Getattr {
345     if (!defined($::client_id)) {
346         print "You must first ``connect''.\n";
347         return;
348     }
349
350     my $inode = shift;
351
352     if (!defined($inode) || scalar($inode) < 1) {
353         print "invalid arguments; type \"help getattr\" for a synopsis\n";
354         return;
355     }
356
357     # see Setattr
358     my $packed = pack("ILsx2lLLLI", $::client_id, $inode, 0, 0, 0, 0, 0, 0, 0,
359                       0);
360     my $rc = ioctl(DEV_OBD, &OBD_IOC_GETATTR, $packed);
361
362     if (!defined $rc) {
363         print STDERR "ioctl failed: $!\n";
364     } elsif ($rc eq "0 but true") {
365         my ($valid, $mode, $uid, $gid, $size, $atime, $mtime, $ctime, $flags);
366         ($valid, $mode, $uid, $gid, $size, $atime, $mtime, $ctime, $flags) =
367           unpack("ISssx2lLLLI", $packed);
368
369         printf("Inode: %d  Mode:  %o\n", $inode, $mode);
370         printf("User: %6d   Group: %6d   Size: %d\n", $uid, $gid, $size);
371         printf("ctime: %08lx -- %s\n", $ctime, scalar(gmtime($ctime)));
372         printf("atime: %08lx -- %s\n", $atime, scalar(gmtime($atime)));
373         printf("mtime: %08lx -- %s\n", $mtime, scalar(gmtime($mtime)));
374         printf("flags: %08x\n", $flags);
375         print "Finished (success)\n";
376     } else {
377         print "ioctl returned error code $rc.\n";
378     }
379 }
380
381 sub Setattr {
382     if (!defined($::client_id)) {
383         print "You must first ``connect''.\n";
384         return;
385     }
386
387     my $inode = shift;
388     my $valid = 0;
389     my $mode = oct(shift);
390     my $uid = shift;
391     my $gid = shift;
392     my $size = shift;
393     my $atime = shift;
394     my $mtime = shift;
395     my $ctime = shift;
396
397     if (defined($uid)) {
398         $valid |= &ATTR_UID;
399     }
400     if (defined($gid)) {
401         $valid |= &ATTR_GID;
402     }
403     if (defined($size)) {
404         $valid |= &ATTR_SIZE;
405     }
406     if (defined($atime)) {
407         $valid |= &ATTR_ATIME;
408     }
409     if (defined($mtime)) {
410         $valid |= &ATTR_MTIME;
411     }
412     if (defined($ctime)) {
413         $valid |= &ATTR_CTIME;
414     }
415     if (defined($mode)) {
416         $valid |= &ATTR_MODE;
417     }
418
419     if (!defined($inode) || scalar($inode) < 1) {
420         print "invalid arguments; type \"help setattr\" for a synopsis\n";
421         return;
422     }
423
424     #struct iattr {
425     #        unsigned int    ia_valid; (32)
426     #        umode_t         ia_mode; (16)
427     #        uid_t           ia_uid; (16)
428     #        gid_t           ia_gid; (16)
429     # -- 16 bit alignment here! --
430     #        off_t           ia_size; (32)
431     #        time_t          ia_atime; (32)
432     #        time_t          ia_mtime; (32)
433     #        time_t          ia_ctime; (32)
434     #        unsigned int    ia_attr_flags; (32)
435     #};
436
437     printf "valid is %x, mode is %o\n", $valid, $mode;
438     my $packed = pack("ILLSssx2ILLLL", $::client_id, $inode, $valid, $mode,
439                       $uid, $gid, $size, $atime, $mtime, $ctime, 0);
440     my $rc = ioctl(DEV_OBD, &OBD_IOC_SETATTR, $packed);
441
442     if (!defined $rc) {
443         print STDERR "ioctl failed: $!\n";
444     } elsif ($rc eq "0 but true") {
445         print "Finished (success)\n";
446     } else {
447         print "ioctl returned error code $rc.\n";
448     }
449 }
450
451 sub Read {
452     if (!defined($::client_id)) {
453         print "You must first ``connect''.\n";
454         return;
455     }
456
457     my $inode = shift;
458     my $count = shift;
459     my $offset = shift;
460   
461     if (!defined($inode) || scalar($inode) < 1 || !defined($count) ||
462         $count < 1 || (defined($offset) && $offset < 0)) {
463         print "invalid arguments; type \"help read\" for a synopsis\n";
464         return;
465     }
466
467     if (!defined($offset)) {
468         $offset = 0;
469     }
470
471     print("Reading $count bytes starting at byte $offset from object " .
472           "$inode...\n");
473
474     # "allocate" a large enough buffer
475     my $buf = sprintf("%${count}s", " ");
476     die "suck" if (length($buf) != $count);
477
478     # the perl we're using doesn't support pack type Q, and offset is 64 bits
479     my $packed = pack("ILpLLL", $::client_id, $inode, $buf, $count, $offset, 0);
480
481     my $rc = ioctl(DEV_OBD, &OBD_IOC_READ, $packed);
482
483     $retval = unpack("l", $packed);
484
485     if (!defined $rc) {
486         print STDERR "ioctl failed: $!\n";
487     } elsif ($rc eq "0 but true") {
488         if ($retval >= 0) {
489                 print substr($buf, 0, $retval);
490                 print "\nRead $retval of an attempted $count bytes.\n";
491                 print "Finished (success)\n";
492         } else {
493                 print "Finished (error $retval)\n";
494         }
495     } else {
496         print "ioctl returned error code $rc.\n";
497     }
498 }
499
500 sub Read2 {
501     if (!defined($::client_id)) {
502         print "You must first ``connect''.\n";
503         return;
504     }
505
506     my $inode = shift;
507     my $count = shift;
508     my $offset = shift;
509   
510     if (!defined($inode) || scalar($inode) < 1 || !defined($count) ||
511         $count < 1 || (defined($offset) && $offset < 0)) {
512         print "invalid arguments; type \"help read\" for a synopsis\n";
513         return;
514     }
515
516     if (!defined($offset)) {
517         $offset = 0;
518     }
519
520     print("Reading $count bytes starting at byte $offset from object " .
521           "$inode...\n");
522
523     # "allocate" a large enough buffer
524     my $buf = sprintf("%${count}s", " ");
525     die "suck" if (length($buf) != $count);
526
527     # the perl we're using doesn't support pack type Q, and offset is 64 bits
528     my $packed = pack("ILpLLL", $::client_id, $inode, $buf, $count, $offset, 0);
529
530     my $rc = ioctl(DEV_OBD, &OBD_IOC_READ2, $packed);
531
532     $retval = unpack("l", $packed);
533
534     if (!defined $rc) {
535         print STDERR "ioctl failed: $!\n";
536     } elsif ($rc eq "0 but true") {
537         if ($retval >= 0) {
538                 print substr($buf, 0, $retval);
539                 print "\nRead $retval of an attempted $count bytes.\n";
540                 print "Finished (success)\n";
541         } else {
542                 print "Finished (error $retval)\n";
543         }
544     } else {
545         print "ioctl returned error code $rc.\n";
546     }
547 }
548
549 sub Write {
550     if (!defined($::client_id)) {
551         print "You must first ``connect''.\n";
552         return;
553     }
554
555     my $inode = shift;
556     my $offset = shift;
557     my $text = join(' ', @_);
558     my $count = length($text);
559
560     if (!defined($inode) || scalar($inode) < 1 || !defined($offset) ||
561         scalar($offset) < 0) {
562         print "invalid arguments; type \"help write\" for a synopsis\n";
563         return;
564     }
565
566     if (!defined($text)) {
567         $text = "";
568         $count = 0;
569     }
570
571     print("Writing $count bytes starting at byte $offset to object " .
572           "$inode...\n");
573
574     # the perl we're using doesn't support pack type Q
575     my $packed = pack("ILpLLL", $::client_id, $inode, $text, $count, $offset, 0);
576     my $rc = ioctl(DEV_OBD, &OBD_IOC_WRITE, $packed);
577
578     $retval = unpack("l", $packed);
579
580     if (!defined $rc) {
581         print STDERR "ioctl failed: $!\n";
582     } elsif ($rc eq "0 but true") {
583         if ($retval >= 0) {
584                 print "\nWrote $retval of an attempted $count bytes.\n";
585                 print "Finished (success)\n";
586         } else {
587                 print "Finished (error $retval)\n";
588         }
589     } else {
590         print "ioctl returned error code $rc.\n";
591     }
592 }
593
594 sub Preallocate {
595     my $arg = shift;
596
597     if (!defined($::client_id)) {
598         print "You must first ``connect''.\n";
599         return;
600     }
601
602     if (!defined($arg) || scalar($arg) < 1 || scalar($arg) > 32) {
603         $arg = 32;
604     }
605
606     print "Preallocating $arg inodes...\n";
607     my $packed = pack("LLx128", $::client_id, $arg);
608     # client id, alloc, inodes[32]
609
610     my $rc = ioctl(DEV_OBD, &OBD_IOC_PREALLOCATE, $packed);
611
612     if (!defined $rc) {
613         print STDERR "ioctl failed: $!\n";
614     } elsif ($rc eq "0 but true") {
615         my $alloc = unpack("x4L", $packed);
616         my @inodes = unpack("x8L32", $packed);
617         my $i;
618
619         print "Got $alloc inodes: ";
620         foreach $i (@inodes) {
621             print $i . " ";
622         }
623         print "\nFinished (success)\n";
624     } else {
625         print "ioctl returned error code $rc.\n";
626     }
627 }
628
629 sub Decusecount {
630     my $rc = ioctl(DEV_OBD, &OBD_IOC_DEC_USE_COUNT, 0);
631
632     if (!defined $rc) {
633         print STDERR "ioctl failed: $!\n";
634     } elsif ($rc eq "0 but true") {
635         print "Finished (success)\n";
636     } else {
637         print "ioctl returned error code $rc.\n";
638     }
639 }
640
641 sub Statfs {
642     if (!defined($::client_id)) {
643         print "You must first ``connect''.\n";
644         return;
645     }
646
647     # struct statfs {
648     #         long f_type;
649     #         long f_bsize;
650     #         long f_blocks;
651     #         long f_bfree;
652     #         long f_bavail;
653     #         long f_files;
654     #         long f_ffree;
655     #         __kernel_fsid_t f_fsid; (64 bits)
656     #         long f_namelen;
657     #         long f_spare[6];
658     # };
659
660     my $packed = pack("LLLLLLLIILL6", $::client_id, 0, 0, 0, 0, 0, 0, 0, 0, 0,
661                       0, 0, 0, 0, 0, 0);
662
663     my $rc = ioctl(DEV_OBD, &OBD_IOC_STATFS, $packed);
664
665     if (!defined $rc) {
666         print STDERR "ioctl failed: $!\n";
667     } elsif ($rc eq "0 but true") {
668         # skip both the conn_id and the fs_type in the buffer
669         my ($bsize, $blocks, $bfree, $bavail, $files, $ffree) =
670             unpack("x4x4LLLLLL", $packed);
671         print("$bsize byte blocks: $blocks, " . ($blocks - $bfree) . " used, " .
672               "$bfree free ($bavail available).\n");
673         print "$files files, " . ($files - $ffree) . " used, $ffree free.\n";
674         print "Finished (success)\n";
675     } else {
676         print "ioctl returned error code $rc.\n";
677     }
678 }
679
680 sub Help {
681     my $arg = shift;
682
683     if ( !$arg || !$commands{$arg} ) {
684         print "Comands: ", join( ' ', @jcm_cmd_list), "\n";
685     } else {
686         print "Usage: " .  $commands{$arg}->{doc} . "\n";
687     }
688 }
689
690 sub Quit {
691     if ($::client_id) {
692         print "Disconnecting active session ($::client_id)...";
693         Disconnect($::client_id);
694     }
695     exit;
696 }