build: Remove check for root.
[libguestfs.git] / daemon / ntfs.c
1 /* libguestfs - the guestfsd daemon
2  * Copyright (C) 2009 Red Hat Inc.
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; either version 2 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17  */
18
19 #include <config.h>
20
21 #include <stdio.h>
22 #include <stdlib.h>
23 #include <inttypes.h>
24 #include <string.h>
25 #include <unistd.h>
26
27 #include "daemon.h"
28 #include "actions.h"
29 #include "optgroups.h"
30
31 int
32 optgroup_ntfs3g_available (void)
33 {
34   int r = access ("/bin/ntfs-3g.probe", X_OK);
35   if (r == 0)
36     return 1;
37   /* On Debian: */
38   r = access ("/usr/bin/ntfs-3g.probe", X_OK);
39   return (r == 0);
40 }
41
42 int
43 optgroup_ntfsprogs_available (void)
44 {
45   int r = access ("/usr/sbin/ntfsresize", X_OK);
46   return r == 0;
47 }
48
49 int
50 do_ntfs_3g_probe (int rw, const char *device)
51 {
52   char *err;
53   int r;
54   const char *rw_flag;
55
56   rw_flag = rw ? "-w" : "-r";
57
58   r = commandr (NULL, &err, "ntfs-3g.probe", rw_flag, device, NULL);
59   if (r == -1) {
60     reply_with_error ("%s: %s", device, err);
61     free (err);
62     return -1;
63   }
64
65   return r;
66 }
67
68 int
69 do_ntfsresize (const char *device)
70 {
71   char *err;
72   int r;
73
74   r = command (NULL, &err, "ntfsresize", "-P", device, NULL);
75   if (r == -1) {
76     reply_with_error ("%s: %s", device, err);
77     free (err);
78     return -1;
79   }
80
81   return 0;
82 }
83
84 int
85 do_ntfsresize_size (const char *device, int64_t size)
86 {
87   char *err;
88   int r;
89
90   char buf[32];
91   snprintf (buf, sizeof buf, "%" PRIi64, size);
92
93   r = command (NULL, &err, "ntfsresize", "-P", "--size", buf,
94                device, NULL);
95   if (r == -1) {
96     reply_with_error ("%s: %s", device, err);
97     free (err);
98     return -1;
99   }
100
101   return 0;
102 }