Commit Graph

54 Commits

Author SHA1 Message Date
Matthew Booth
04ea1375c5 Update FSF address. 2011-11-08 14:43:07 +00:00
Richard W.M. Jones
bb6a1b4cdc New API: write-append
Append content to the end of a file.
2011-07-14 18:18:07 +01:00
Richard W.M. Jones
9ff9941836 daemon: Don't use ../src path to include generator_protocol.h
This file is already hard-linked into the current directory, so
the relative path is not required.
2010-11-03 13:15:19 +00:00
Richard W.M. Jones
7e4bf29fdf New API: pread-device, partial read for devices. 2010-09-27 12:04:44 +01:00
Richard W.M. Jones
e65f521363 pread: Check count and offset parameters are not negative. 2010-09-27 10:51:38 +01:00
Richard W.M. Jones
eeaab2ba84 New API: pwrite-device
This is the same as the existing 'pwrite' API call, but allows you
to write to a device.
2010-09-26 22:21:36 +01:00
Richard W.M. Jones
5a8c8b8bf6 pwrite: Check offset is not negative. 2010-09-26 22:21:36 +01:00
Richard Jones
3a99114360 daemon: Move 'exists', 'is-file' and 'is-dir' to separate file.
This commit is just code movement.
2010-09-09 22:45:22 +01:00
Richard Jones
ba39ced880 file: Fix file command on /dev/VG/LV paths (RHBZ#582484).
Previous commit 4df593496e broke the
"file" command on logical volume paths, since these are symbolic
links.  We *should* follow these (only).

This inadvertantly broke virt-inspector too, which indicates that
we need more regression testing in this area.  Since carrying whole
Fedora images around could make the distribution even larger than
now, I'm not sure at the moment how to do this.

Thanks to Matt Booth for diagnosing this bug.
2010-06-08 16:04:01 +01:00
Richard Jones
4df593496e file: Restrict to regular files (RHBZ#582484).
The file call can hang if called on char devices (because we are
using the file -s option).

This is hard to solve cleanly without adding another file API.

However this restricts file to regular files, unless called explicitly
with a /dev/ path.  For non-regular files, it will now return a
string like "directory".

There is a small semantic change for symbolic links.  Previously
it would not have worked at all on absolute links (or rather, the
results would have been undefined).  It would have treated relative
symlinks to regular files as the regular file itself.  Now it will
return the string "symbolic link" in both cases.

This commit also makes the API safe when called on untrusted
filesystems.  Previously a filesystem might have been set up so
that (eg) /etc/redhat-release was a char device, which would have
caused virt-inspector and virt-v2v to hang.  Now it will not hang.
2010-06-04 15:07:27 +01:00
Richard Jones
74958b0ad4 touch: Restrict touch to regular files only (RHBZ#582484). 2010-06-04 13:53:10 +01:00
Richard Jones
e3befe5a2e daemon: Rearrange code in 'file' command.
path = path to access file (/sysroot/.. or /dev/..)
  display_path = original path, saved so we can display it
  buf = optional buffer which is freed along return codepaths

There should be no change to the semantics of the code.
2010-06-04 11:23:01 +01:00
Richard Jones
9733d47469 daemon: write-file: Check range of size parameter (RHBZ#597135).
This also adds a regression test.
2010-06-02 13:38:00 +01:00
Richard Jones
1214b32162 New API: Implement pwrite system call (partial fix for RHBZ#592883). 2010-05-20 10:30:12 +01:00
Richard Jones
3920ad95f6 New API: write for creating files with fixed content (RHBZ#501889).
The guestfs_write call can be used to create small files with
arbitrary 8 bit content, including \0 bytes.

This replaces and deprecates write-file, which cannot be modified
to use BufferIn because of an unfortunate choice in the ABI: the
size parameter to write-file, if zero, means that the daemon tries
to calculate the length of the buffer using strlen.  However this
fails if we pass a zero-length buffer using BufferIn because then
the daemon tries to do strlen on a (really) zero length buffer, not
even containing a terminating \0 character, thus segfaulting.
2010-05-20 10:30:12 +01:00
Richard Jones
42f59b28f1 daemon: Fix read-file so it fails gracefully for large files (RHBZ#589039).
Pengzhen Cao noticed that read-file would fail for files
larger than the protocol size; this is *not* the bug.  However
it would also lose protocol synchronization after this.

The reason was that functions which return RBufferOut in the
generator must not 'touch' the *size_r parameter along error
return paths.

I fixed read-file and initrd-cat, and I checked that pread was
doing the right thing.

This also adds regression tests for read-file with various categories
of large file.
2010-05-07 15:27:29 +01:00
Richard Jones
61ab83d190 Improved checking, documentation of modes (RHBZ#582901, RHBZ#582929).
chmod: Disallow negative mode, document mode affected by umask.

mkdir-mode: Disallow negative mode, document that filesystems
may interpret the mode in different ways.

mknod: Disallow negative mode, document mode affected by umask.

umask: Check the range of umask mask value carefully.
2010-04-17 13:36:26 +01:00
Richard Jones
e9c3711310 daemon: Don't need to prefix error messages with the command name.
The RPC stubs already prefix the command name to error messages.
The daemon doesn't have to do this.  As a (small) benefit this also
makes the daemon slightly smaller.

Code in the daemon such as:

  if (argv[0] == NULL) {
    reply_with_error ("passed an empty list");
    return NULL;
  }

now results in error messages like this:

  ><fs> command ""
  libguestfs: error: command: passed an empty list

(whereas previously you would have seen ..command: command:..)
2010-02-12 16:49:00 +00:00
Richard Jones
306077ac96 Add 'filesize' call.
Returns the size of a file.  You can already do this with 'stat',
but this call is good for scripting.
2010-01-25 11:37:12 +00:00
Richard Jones
b3035e8d7c daemon: Use gnulib futimens module.
Instead of checking for futimens support and falling back
(incorrectly in one case) to using futimes, use gnulib's
module.

However the gnulib module does not yet support Win32, so
this change is only really useful on platforms like RHEL 5.
2009-11-25 16:28:26 +00:00
Jim Meyering
9a8889e4d0 use STREQ, not strcmp: part 1
git grep -l 'strcmp *([^=]*== *0'|xargs \
  perl -pi -e 's/\bstrcmp( *\(.*?\)) *== *0/STREQ$1/g'
2009-11-09 22:34:16 +01:00
Jim Meyering
3e70b34eed change strncmp() == 0 to STREQLEN()
git grep -l 'strncmp *([^=]*== *0'|xargs \
  perl -pi -e 's/\bstrncmp( *\(.*?\)) *== *0\b/STREQLEN$1/g'
2009-11-09 22:34:16 +01:00
Richard Jones
90cf7fc904 New API call: pread
guestfs_pread lets you do partial file reads from arbitrary
places within a file.  It works like the pread(2) system call.
2009-11-02 17:48:39 +00:00
Richard Jones
2eb19f5261 New API calls: truncate, truncate_size, mkdir_mode, utimens, lchown.
truncate, truncate_size: Used to truncate files to a particular
size, or to zero bytes.

mkdir_mode: Like mkdir but allows you to also specify the
initial permissions for the new directory.

utimens: Set timestamp on a file with nanosecond accuracy.

lchown: Corresponding to lchown(2) syscall (we already have chown).

The implementation is complicated by the fact that we had to
add an Int64 parameter type to the generator.
2009-11-02 16:37:51 +00:00
Jim Meyering
08c2772264 generator.ml: finish adding Dev_or_Path support
* src/generator.ml: Update all rules to handle Dev_or_Path.
(the above changes to generator.ml are mostly mechanical)
Emit a use of REQUIRE_ROOT_OR_RESOLVE_DEVICE.
* daemon/upload.c (do_download): Remove use of
REQUIRE_ROOT_OR_RESOLVE_DEVICE, now that it's automatically done
in calling code.
* daemon/file.c (do_file): Likewise.
2009-08-13 14:45:34 +02:00
Jim Meyering
84fc760439 generator.ml: use new "Pathname" designation
Nearly every file-related function in daemons/*.c is affected:
Remove this pair of statements from each affected do_* function:
-  NEED_ROOT (return -1);
-  ABS_PATH (dir, return -1);
and change the type of the corresponding parameter to "const char *".
* src/generator.ml: Emit NEED_ROOT just once, even when there are two or
more Pathname args.
2009-08-13 14:45:34 +02:00
Jim Meyering
6bda071b5c update all NEED_ROOT uses
run this command:
  git grep -l -w NEED_ROOT|xargs perl -pi -e \
    's/(NEED_ROOT) \((.*?)\)/$1 (return $2)/'
2009-08-13 14:45:34 +02:00
Jim Meyering
fc266e5ab8 s/NEED_ROOT_OR_IS_DEVICE/REQUIRE_ROOT_OR_RESOLVE_DEVICE/ 2009-08-13 14:45:34 +02:00
Jim Meyering
302c18e7d0 manually adjust ABS_PATH uses for new semantics
* daemon/file.c (do_cat): fix an ABS_PATH use
2009-08-13 14:45:34 +02:00
Jim Meyering
0dd6c8c844 update all uses of ABS_PATH
run this command:
  git grep -l -w ABS_PATH|xargs perl -pi -e \
    's/(?:ABS_PATH)( \(.*?,) (.*?)\)/ABS_PATH$1 return $2)/'
2009-08-13 14:45:34 +02:00
Jim Meyering
1997858e90 change almost all uses: s/IS_DEVICE/RESOLVE_DEVICE/
Use this command:
  git grep -l -w IS_DEVICE|xargs perl -pi -e \
    's/\b(?:IS_DEVICE)\b( \(.*?,) (.*?)\)/RESOLVE_DEVICE$1 return $2)/'
2009-08-13 14:45:33 +02:00
Jim Meyering
894d7c6733 daemon/file.c: remove duplicate absolute-path check
* daemon/file.c (do_file): Remove redundant use of ABS_PATH.
It's redundant because the preceding line invokes NEED_ROOT_OR_IS_DEVICE,
which also invokes ABS_PATH.
2009-08-10 10:48:38 +02:00
Jim Meyering
2f1a50d816 Convert all TABs-as-indentation to spaces.
Do it by running this command:
[exempted files are matched via .x-sc_TAB_in_indentation]

  git ls-files \
    | pcregrep -vf .x-sc_TAB_in_indentation \
    | xargs pcregrep -l '^ *\t' \
    | xargs perl -MText::Tabs -ni -le \
      '$m=/^( *\t[ \t]*)(.*)/; print $m ? expand($1) . $2 : $_'
2009-08-03 17:17:57 +02:00
Richard Jones
549bba81e7 Pass '-z' parameter to 'file' command so it looks inside compressed files.
Also we deprecate the old 'zfile' command.
2009-07-28 15:29:23 +01:00
Richard Jones
0f2e9c84e9 Replace shell_quote function with %Q and %R printf specifiers.
%Q => simple shell quoted string
%R => path will be prefixed by /sysroot

eg. snprintf (cmd, sizeof cmd, "cat %R", path); system (cmd);
2009-07-28 10:57:57 +01:00
Richard Jones
26f69f706e Fix typo in error message. 2009-07-22 21:18:01 +01:00
Richard W.M. Jones
e315e0723e Generator: Implement RBufferOut and "read-file" call.
This commit implements the RBufferOut type for returning
arbitrary 8 bit data from calls.

We also implement the guestfs_read_file call to read a
whole file that can contain any 8 bit content, but up to
a limit of ~ 2 MB.
2009-07-21 11:18:34 +01:00
Richard Jones
78029b529a Make /sysroot path configurable.
Currently /sysroot is hard-coded throughout the daemon code.

This patch turns the path into a variable so that we can change
it in future, for example to allow standalone mode to be implemented.

This patch was tested by running all the C API tests successfully.
2009-07-18 10:43:52 +01:00
Richard Jones
7d41d75c1d Implement new 'zfile' command, to show file type inside compressed files. 2009-07-13 18:00:07 +01:00
Jim Meyering
a7b73d4a1e remove trailing blanks 2009-07-03 17:04:21 +02:00
Richard Jones
697f50aea8 Check return value from close() call. 2009-06-22 12:24:14 +01:00
Richard Jones
56bef498f4 In the daemon, change all const char * parameters to char *. 2009-06-10 14:16:47 +01:00
Richard Jones
bb98bbb91c Fix missing futimens bug. 2009-05-06 15:29:01 +01:00
Richard W.M. Jones
6eaa49fadd Use AC_GNU_SOURCE in daemon. Don't need _GNU_SOURCE in C files any more. 2009-04-23 18:51:12 +01:00
Richard Jones
d73a4f097f Implement NEED_ROOT_OR_IS_DEVICE macro. 2009-04-19 12:41:35 +01:00
Richard Jones
05712b2457 'guestfish edit' commands and several bugfixes. 2009-04-15 23:54:51 +01:00
Richard Jones
161018ed1e Fix 'file(1)' command to work on /dev devices. 2009-04-14 13:09:06 +01:00
Richard Jones
4228340388 Added file(1) command. 2009-04-13 23:58:02 +01:00
Richard Jones
b4d2a01828 Added test suite. 2009-04-11 17:04:35 +01:00
Richard Jones
44da812b42 New commands: rm rmdir rm-rf mkdir mkdir-p chmod chown 2009-04-10 12:55:04 +01:00