~ubuntu-branches/ubuntu/quantal/open-vm-tools/quantal-201207201942

« back to all changes in this revision

Viewing changes to tests/testVmblock/manual-blocker.c

  • Committer: Bazaar Package Importer
  • Author(s): Daniel Baumann
  • Date: 2009-10-18 12:28:19 UTC
  • mfrom: (1.1.7 upstream) (2.4.9 squeeze)
  • Revision ID: james.westby@ubuntu.com-20091018122819-00vqew6m0ztpqcqp
Tags: 2009.10.15-201664-1
MergingĀ upstreamĀ versionĀ 2009.10.15-201664.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*********************************************************
 
2
 * Copyright (C) 2008 VMware, Inc. All rights reserved.
 
3
 *
 
4
 * This program is free software; you can redistribute it and/or modify it
 
5
 * under the terms of the GNU Lesser General Public License as published
 
6
 * by the Free Software Foundation version 2.1 and no later version.
 
7
 *
 
8
 * This program is distributed in the hope that it will be useful, but
 
9
 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
 
10
 * or FITNESS FOR A PARTICULAR PURPOSE.  See the Lesser GNU General Public
 
11
 * License for more details.
 
12
 *
 
13
 * You should have received a copy of the GNU Lesser General Public License
 
14
 * along with this program; if not, write to the Free Software Foundation, Inc.,
 
15
 * 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA.
 
16
 *
 
17
 *********************************************************/
 
18
 
 
19
/*
 
20
 * manual-blocker.c --
 
21
 *
 
22
 *      A small test program for manually manipulating vmblock.
 
23
 */
 
24
 
 
25
#include <stdio.h>
 
26
#include <unistd.h>
 
27
#include <stdlib.h>
 
28
#include <errno.h>
 
29
#include <limits.h>
 
30
#include <fcntl.h>
 
31
#include <string.h>
 
32
 
 
33
#include "vmblock_user.h"
 
34
 
 
35
 
 
36
/*
 
37
 *-----------------------------------------------------------------------------
 
38
 *
 
39
 * main --
 
40
 *
 
41
 *      Takes the target file to block as a command line arg. Sits in a loop
 
42
 *      waiting for commands.
 
43
 *
 
44
 * Results:
 
45
 *      Returns 0 on success and nonzero on failure.
 
46
 *
 
47
 * Side effects:
 
48
 *      None/all.
 
49
 *
 
50
 *-----------------------------------------------------------------------------
 
51
 */
 
52
 
 
53
int
 
54
main(int argc,
 
55
     char *argv[])
 
56
{
 
57
   int status;
 
58
   char op;
 
59
 
 
60
   if (argc < 2 ||
 
61
       strcmp(argv[1], "-h") == 0 ||
 
62
       strcmp(argv[1], "--help") == 0) {
 
63
      printf("Usage: %s <path>\n", argv[0]);
 
64
      puts("a to Add a block, d to Delete a block, or l to List blocks (to"
 
65
           " vmblock's log).\n");
 
66
      return 1;
 
67
   }
 
68
 
 
69
   int fd = open(VMBLOCK_DEVICE, VMBLOCK_DEVICE_MODE);
 
70
   if (fd <= 0) {
 
71
      perror("open");
 
72
      return 2;
 
73
   }
 
74
   printf("Opened " VMBLOCK_DEVICE " as fd %d.\n", fd);
 
75
 
 
76
   while (1) {
 
77
      op = getchar();
 
78
      if (op == 'a') {
 
79
         status = VMBLOCK_CONTROL(fd, VMBLOCK_ADD_FILEBLOCK, argv[1]);
 
80
         if (status != 0) {
 
81
            perror(NULL);
 
82
         } else {
 
83
            printf("%s blocked.\n", argv[1]);
 
84
         }
 
85
      } else if (op == 'd') {
 
86
         status = VMBLOCK_CONTROL(fd, VMBLOCK_DEL_FILEBLOCK, argv[1]);
 
87
         if (status != 0) {
 
88
            perror(NULL);
 
89
         } else {
 
90
            printf("%s unblocked.\n", argv[1]);
 
91
         }
 
92
      } else if (op == 'l') {
 
93
         status = VMBLOCK_CONTROL(fd, VMBLOCK_LIST_FILEBLOCKS, argv[1]);
 
94
         if (status != 0) {
 
95
            perror(NULL);
 
96
         } else {
 
97
            printf("Check vmblock's log for list of blocks.\n");
 
98
         }
 
99
      }
 
100
   }
 
101
 
 
102
   return 0;
 
103
}