aboutsummaryrefslogtreecommitdiffstats
path: root/tools/control/src/org/xenoserver/cmdline/ParsePhysicalList.java
blob: 85e6e5de1912f145d6f9ce41af898c1c18525986 (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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
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.Partition;
import org.xenoserver.control.PartitionManager;

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

        // Initialise the partition manager
        loadState();

        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.getPartition(e);
            if (p != null) {
                System.out.println(
                    Library.format(p.getMajor(), 3, false)
                        + ":"
                        + Library.format(p.getMinor(), 3, true)
                        + " "
                        + Library.format(p.getBlocks(), 10, false)
                        + " "
                        + Library.format(p.getStartSect(), 10, false)
                        + " "
                        + Library.format(p.getNumSects(), 10, false)
                        + " "
                        + Library.format(p.getName(), 7, true)
                        + " "
                        + Library.format(mode, 2, true));
            } else {
                System.out.println(
                    Library.format(e.getMajor(), 3, false)
                        + ":"
                        + Library.format(
                            e.getMinor() | e.getPartitionNo(),
                            3,
                            true)
                        + " "
                        + "          "
                        + " "
                        + Library.format(e.getOffset(), 10, false)
                        + " "
                        + Library.format(e.getSize(), 10, false)
                        + " "
                        + "       "
                        + " "
                        + Library.format(mode, 2, true));
            }
        }
    }

    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.";
    }

}