aboutsummaryrefslogtreecommitdiffstats
path: root/tools/control/src/org/xenoserver/cmdline/ParsePhysicalList.java
blob: c08a881a26eee41d196308c84225d9f63fd52905 (plain)
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
65
66
67
68
69
70
71
72
73
74
package org.xenoserver.cmdline;

import java.util.Iterator;
import java.util.LinkedList;
import java.util.Map.Entry;

import org.xenoserver.control.CommandFailedException;
import org.xenoserver.control.CommandPhysicalList;
import org.xenoserver.control.Defaults;
import org.xenoserver.control.Extent;
import org.xenoserver.control.Library;
import org.xenoserver.control.Mode;
import org.xenoserver.control.Partition;
import org.xenoserver.control.PartitionManager;
import org.xenoserver.control.Settings;
import org.xenoserver.control.XML;

public class ParsePhysicalList extends CommandParser {

  public void parse(Defaults d, LinkedList args) throws ParseFailedException, CommandFailedException {
    int domain_id = getIntParameter(args, 'n', 0);
    if (domain_id == 0)
      throw new ParseFailedException("Expected -n<domain_id>");

    // Initialise the partition manager
    XML.load_state( PartitionManager.it, Settings.STATE_INPUT_FILE );
    
    CommandPhysicalList list = new CommandPhysicalList( d, domain_id );
    String output = list.execute();
    if ( output != null )
      System.out.println( output );
      
    System.out.println( "maj:min " + "    blocks " + "start sect " +
                        " num sects " + "name    " + "access" );
    Iterator i = list.extents().entrySet().iterator();
    while ( i.hasNext() )
    {
      Entry entry = (Entry) i.next(); 
      Extent e = (Extent) entry.getKey();
      String mode = entry.getValue().toString();
      Partition p = PartitionManager.it.get_partition( e );
      if ( p != null ) {
        System.out.println(Library.format(p.getMajor(),3,0) + ":" + 
          Library.format(p.getMinor(),3,1) + " " +
          Library.format(p.getBlocks(),10,0) + " " +
          Library.format(p.getStartSect(),10,0) + " " +
          Library.format(p.getNumSects(),10,0) + " " +
          Library.format(p.getName(),7,1) + " " +
          Library.format(mode,2,1));   
      } else {
        System.out.println(Library.format(e.getMajor(),3,0) + ":" +
          Library.format(e.getMinor(),3,1) + " " +
          "          " + " " +
          Library.format(e.getOffset(),10,0) + " " +
          Library.format(e.getSize(),10,0) + " " +
          "       " + " " +
          Library.format(mode,2,1));
      }
    }
  }

  public String getName() {
    return "list";
  }

  public String getUsage() {
    return "[-n<domain_id>]";
  }

  public String getHelpText() {
    return "List all physical access which the given domain has been granted.";
  }

}