pwrite: Check offset is not negative.
[libguestfs.git] / daemon / file.c
index a55c606..0849456 100644 (file)
@@ -270,40 +270,6 @@ do_lchown (int owner, int group, const char *path)
 }
 
 int
-do_exists (const char *path)
-{
-  int r;
-
-  CHROOT_IN;
-  r = access (path, F_OK);
-  CHROOT_OUT;
-
-  return r == 0;
-}
-
-int
-do_is_file (const char *path)
-{
-  int r;
-  struct stat buf;
-
-  CHROOT_IN;
-  r = lstat (path, &buf);
-  CHROOT_OUT;
-
-  if (r == -1) {
-    if (errno != ENOENT && errno != ENOTDIR) {
-      reply_with_perror ("stat: %s", path);
-      return -1;
-    }
-    else
-      return 0;                        /* Not a file. */
-  }
-
-  return S_ISREG (buf.st_mode);
-}
-
-int
 do_write_file (const char *path, const char *content, int size)
 {
   int fd;
@@ -503,6 +469,11 @@ do_pwrite (const char *path, const char *content, size_t size, int64_t offset)
   int fd;
   ssize_t r;
 
+  if (offset < 0) {
+    reply_with_error ("offset is negative");
+    return -1;
+  }
+
   CHROOT_IN;
   fd = open (path, O_WRONLY);
   CHROOT_OUT;
@@ -581,8 +552,13 @@ do_file (const char *path)
     }
   }
 
+  /* Which flags to use?  For /dev paths, follow links because
+   * /dev/VG/LV is a symbolic link.
+   */
+  const char *flags = is_dev ? "-zbsL" : "-zb";
+
   char *out, *err;
-  int r = command (&out, &err, "file", "-zbs", path, NULL);
+  int r = command (&out, &err, "file", flags, path, NULL);
   free (buf);
 
   if (r == -1) {