File: getusage.c

package info (click to toggle)
libnjb 2.2.5-4.3
  • links: PTS
  • area: main
  • in suites: squeeze
  • size: 2,528 kB
  • ctags: 1,072
  • sloc: ansic: 11,860; sh: 8,611; makefile: 144
file content (64 lines) | stat: -rw-r--r-- 1,272 bytes parent folder | download | duplicates (8)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#include "common.h"

int main (int argc, char **argv)
{
  njb_t njbs[NJB_MAX_DEVICES];
  njb_t *njb;
  int n, opt, debug;
  extern char *optarg;
  u_int64_t total;
  u_int64_t free;
  
  debug = 0;
  while ( (opt = getopt(argc, argv, "D:")) != -1 ) {
    switch (opt) {
    case 'D':
      debug = atoi(optarg);
      break;
    default:
      fprintf(stderr, "usage: handshake [ -D debuglvl ]\n");
      return 1;
    }
  }
  
  if ( debug ) NJB_Set_Debug(debug);

  if (NJB_Discover(njbs, 0, &n) == -1) {
    fprintf(stderr, "could not locate any jukeboxes\n");
    return 1;
  }

  if ( n == 0 ) {
    fprintf(stderr, "no NJB devices found\n");
    return 0;
  }

  njb = &njbs[0];

  if ( NJB_Open(njb) == -1 ) {
    NJB_Error_Dump(njb,stderr);
    return 1;
  }
  
  if (NJB_Get_Disk_Usage(njb, &total, &free) == -1) {
    NJB_Error_Dump(njb,stderr);
    return 1;
  }
  
#ifdef __WIN32__
  printf("Total bytes on jukebox: %I64u (%I64u MB)\n",
	 total, total/(1024*1024));
  printf("Free bytes on jukebox: %I64u (%I64u MB)\n",
	 free, free/(1024*1024));
#else
  printf("Total bytes on jukebox: %llu (%llu MB)\n",
	 total, total/(1024*1024));
  printf("Free bytes on jukebox: %llu (%llu MB)\n",
	 free, free/(1024*1024));
#endif
  
  NJB_Close(njb);
  
  return 0;
}