X-Git-Url: http://git.annexia.org/?a=blobdiff_plain;f=daemon%2Ffile.c;h=7854adef9d2b58643df49e60de3cde243a70879f;hb=a3be3a3b877277c1e4b130e1676b9ad307cafa10;hp=ed3221d57a9d85ecaf5f7c509ddfcd672973746d;hpb=84fc760439e82e6b3616abd0d1f9bd7d7eb01ec0;p=libguestfs.git diff --git a/daemon/file.c b/daemon/file.c index ed3221d..7854ade 100644 --- a/daemon/file.c +++ b/daemon/file.c @@ -232,6 +232,23 @@ do_chown (int owner, int group, const char *path) } int +do_lchown (int owner, int group, const char *path) +{ + int r; + + CHROOT_IN; + r = lchown (path, owner, group); + CHROOT_OUT; + + if (r == -1) { + reply_with_perror ("lchown: %s: %d.%d", path, owner, group); + return -1; + } + + return 0; +} + +int do_exists (const char *path) { int r; @@ -352,6 +369,58 @@ do_read_file (const char *path, size_t *size_r) return r; } +char * +do_pread (const char *path, int count, int64_t offset, size_t *size_r) +{ + int fd; + ssize_t r; + char *buf; + + /* The actual limit on messages is smaller than this. This check + * just limits the amount of memory we'll try and allocate in the + * function. If the message is larger than the real limit, that + * will be caught later when we try to serialize the message. + */ + if (count >= GUESTFS_MESSAGE_MAX) { + reply_with_error ("pread: %s: count is too large for the protocol, use smaller reads", path); + return NULL; + } + + CHROOT_IN; + fd = open (path, O_RDONLY); + CHROOT_OUT; + + if (fd == -1) { + reply_with_perror ("open: %s", path); + return NULL; + } + + buf = malloc (count); + if (buf == NULL) { + reply_with_perror ("malloc"); + close (fd); + return NULL; + } + + r = pread (fd, buf, count, offset); + if (r == -1) { + reply_with_perror ("pread: %s", path); + close (fd); + free (buf); + return NULL; + } + + if (close (fd) == -1) { + reply_with_perror ("close: %s", path); + close (fd); + free (buf); + return NULL; + } + + *size_r = r; + return buf; +} + /* This runs the 'file' command. */ char * do_file (const char *path) @@ -361,8 +430,6 @@ do_file (const char *path) char *buf; int len; - REQUIRE_ROOT_OR_RESOLVE_DEVICE (path, return NULL); - if (strncmp (path, "/dev/", 5) == 0) buf = (char *) path; else {