summaryrefslogtreecommitdiffstats
path: root/daemon/file.c
Commit message (Collapse)AuthorAgeFilesLines
* daemon: Move 'exists', 'is-file' and 'is-dir' to separate file.Richard Jones2010-10-231-34/+0
| | | | | This commit is just code movement. (cherry picked from commit 3a99114360636806078bbf614c241e89661bcc7f)
* file: Fix file command on /dev/VG/LV paths (RHBZ#582484).Richard Jones2010-06-081-1/+6
| | | | | | | | | | | | | Previous commit 4df593496e116dfb635731c058b7627e81fc179c 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.
* file: Restrict to regular files (RHBZ#582484).Richard Jones2010-06-041-11/+35
| | | | | | | | | | | | | | | | | | | | | | 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.
* touch: Restrict touch to regular files only (RHBZ#582484).Richard Jones2010-06-041-0/+20
|
* daemon: Rearrange code in 'file' command.Richard Jones2010-06-041-16/+15
| | | | | | | | 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.
* daemon: write-file: Check range of size parameter (RHBZ#597135).Richard Jones2010-06-021-1/+22
| | | | This also adds a regression test.
* New API: Implement pwrite system call (partial fix for RHBZ#592883).Richard Jones2010-05-201-0/+31
|
* New API: write for creating files with fixed content (RHBZ#501889).Richard Jones2010-05-201-0/+28
| | | | | | | | | | | | | 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.
* daemon: Fix read-file so it fails gracefully for large files (RHBZ#589039).Richard Jones2010-05-071-4/+10
| | | | | | | | | | | | | | | | 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.
* Improved checking, documentation of modes (RHBZ#582901, RHBZ#582929).Richard Jones2010-04-171-0/+5
| | | | | | | | | | | 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.
* daemon: Don't need to prefix error messages with the command name.Richard Jones2010-02-121-12/+12
| | | | | | | | | | | | | | | | | | | | 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:..)
* Add 'filesize' call.Richard Jones2010-01-251-0/+18
| | | | | Returns the size of a file. You can already do this with 'stat', but this call is good for scripting.
* daemon: Use gnulib futimens module.Richard Jones2009-11-251-4/+0
| | | | | | | | | 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.
* use STREQ, not strcmp: part 1Jim Meyering2009-11-091-2/+2
| | | | | git grep -l 'strcmp *([^=]*== *0'|xargs \ perl -pi -e 's/\bstrcmp( *\(.*?\)) *== *0/STREQ$1/g'
* change strncmp() == 0 to STREQLEN()Jim Meyering2009-11-091-1/+1
| | | | | git grep -l 'strncmp *([^=]*== *0'|xargs \ perl -pi -e 's/\bstrncmp( *\(.*?\)) *== *0\b/STREQLEN$1/g'
* New API call: preadRichard Jones2009-11-021-0/+52
| | | | | guestfs_pread lets you do partial file reads from arbitrary places within a file. It works like the pread(2) system call.
* New API calls: truncate, truncate_size, mkdir_mode, utimens, lchown.Richard Jones2009-11-021-0/+17
| | | | | | | | | | | | | | | 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.
* generator.ml: finish adding Dev_or_Path supportJim Meyering2009-08-131-2/+0
| | | | | | | | | | * 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.
* generator.ml: use new "Pathname" designationJim Meyering2009-08-131-45/+12
| | | | | | | | | | 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.
* update all NEED_ROOT usesJim Meyering2009-08-131-11/+11
| | | | | | run this command: git grep -l -w NEED_ROOT|xargs perl -pi -e \ 's/(NEED_ROOT) \((.*?)\)/$1 (return $2)/'
* s/NEED_ROOT_OR_IS_DEVICE/REQUIRE_ROOT_OR_RESOLVE_DEVICE/Jim Meyering2009-08-131-1/+1
|
* manually adjust ABS_PATH uses for new semanticsJim Meyering2009-08-131-1/+1
| | | | * daemon/file.c (do_cat): fix an ABS_PATH use
* update all uses of ABS_PATHJim Meyering2009-08-131-10/+10
| | | | | | run this command: git grep -l -w ABS_PATH|xargs perl -pi -e \ 's/(?:ABS_PATH)( \(.*?,) (.*?)\)/ABS_PATH$1 return $2)/'
* change almost all uses: s/IS_DEVICE/RESOLVE_DEVICE/Jim Meyering2009-08-131-1/+1
| | | | | | Use this command: git grep -l -w IS_DEVICE|xargs perl -pi -e \ 's/\b(?:IS_DEVICE)\b( \(.*?,) (.*?)\)/RESOLVE_DEVICE$1 return $2)/'
* daemon/file.c: remove duplicate absolute-path checkJim Meyering2009-08-101-1/+0
| | | | | | * 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.
* Convert all TABs-as-indentation to spaces.Jim Meyering2009-08-031-9/+9
| | | | | | | | | | | 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 : $_'
* Pass '-z' parameter to 'file' command so it looks inside compressed files.Richard Jones2009-07-281-1/+1
| | | | Also we deprecate the old 'zfile' command.
* Replace shell_quote function with %Q and %R printf specifiers.Richard Jones2009-07-281-14/+10
| | | | | | | %Q => simple shell quoted string %R => path will be prefixed by /sysroot eg. snprintf (cmd, sizeof cmd, "cat %R", path); system (cmd);
* Fix typo in error message.Richard Jones2009-07-221-1/+1
|
* Generator: Implement RBufferOut and "read-file" call.Richard W.M. Jones2009-07-211-0/+59
| | | | | | | | | 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.
* Make /sysroot path configurable.Richard Jones2009-07-181-6/+6
| | | | | | | | | 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.
* Implement new 'zfile' command, to show file type inside compressed files.Richard Jones2009-07-131-0/+60
|
* remove trailing blanksJim Meyering2009-07-031-1/+1
|
* Check return value from close() call.Richard Jones2009-06-221-1/+5
|
* In the daemon, change all const char * parameters to char *.Richard Jones2009-06-101-10/+10
|
* Fix missing futimens bug.Richard Jones2009-05-061-1/+7
|
* Use AC_GNU_SOURCE in daemon. Don't need _GNU_SOURCE in C files any more.Richard W.M. Jones2009-04-231-2/+0
|
* Implement NEED_ROOT_OR_IS_DEVICE macro.Richard Jones2009-04-191-1/+1
|
* 'guestfish edit' commands and several bugfixes.Richard Jones2009-04-151-2/+2
|
* Fix 'file(1)' command to work on /dev devices.Richard Jones2009-04-141-10/+15
|
* Added file(1) command.Richard Jones2009-04-131-0/+49
|
* Added test suite.Richard Jones2009-04-111-0/+74
|
* New commands: rm rmdir rm-rf mkdir mkdir-p chmod chownRichard Jones2009-04-101-0/+60
|
* Definition and implementation of new guestfs_read_lines API call.Richard Jones2009-04-081-1/+53
|
* Implementations of 'cat', 'ls', and some cleanups.Richard Jones2009-04-061-9/+69
|
* Implement RString and RStringList return types.Richard Jones2009-04-041-0/+7
| | | | | - implement 'll' command. - outlines for 'ls' and 'cat' commands.
* Implemented 'mount' and 'touch' commands.Richard Jones2009-04-031-0/+63