1 /* libguestfs - the guestfsd daemon
2 * Copyright (C) 2009 Red Hat Inc.
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.
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.
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.
21 #define _GNU_SOURCE /* for futimens(2) */
30 #include "../src/guestfs_protocol.h"
35 do_touch (const char *path)
43 fd = open (path, O_WRONLY | O_CREAT | O_NOCTTY | O_NONBLOCK, 0666);
47 reply_with_perror ("open: %s", path);
51 if (futimens (fd, NULL) == -1) {
52 reply_with_perror ("futimens: %s", path);
62 do_cat (const char *path)
65 int alloc, size, r, max;
72 fd = open (path, O_RDONLY);
76 reply_with_perror ("open: %s", path);
80 /* Read up to GUESTFS_MESSAGE_MAX - <overhead> bytes. If it's
81 * larger than that, we need to return an error instead (for
84 max = GUESTFS_MESSAGE_MAX - 1000;
92 reply_with_error ("cat: %s: file is too large for message buffer",
98 buf2 = realloc (buf, alloc);
100 reply_with_perror ("realloc");
108 r = read (fd, buf + size, alloc - size);
110 reply_with_perror ("read: %s", path);
123 if (close (fd) == -1) {
124 reply_with_perror ("close: %s", path);
129 return buf; /* caller will free */