[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

Re: [Libguestfs] Proposed new file apis



On 23/08/10 15:00, Matthew Booth wrote:
I've attached a patch to generator.ml for the proposed new file apis.
Note that hread, hpread, hwrite and hpwrite are slightly different to
the apis I proposed previously. I've also added hallocate for good measure.

I forgot hclose and hclose_all.

Matt
--
Matthew Booth, RHCA, RHCSS
Red Hat Engineering, Virtualisation Team

GPG ID:  D33C3490
GPG FPR: 3733 612D 2D05 5458 8A8A 1600 3441 EA19 D33C 3490
diff --git a/src/generator.ml b/src/generator.ml
index e18fa38..1f4d294 100755
--- a/src/generator.ml
+++ b/src/generator.ml
@@ -5336,6 +5336,112 @@ filesystem can be found.
 
 To find the label of a filesystem, use C<guestfs_vfs_label>.");
 
+  ("open_file", (RInt "handle", [Pathname "path"]), 267, [],
+   [],
+   "open a file",
+   "\
+This command opens a file in the guest and returns a handle
+to it. The returned handle is an opaque int which can be passed
+to guestfs_h* calls.
+
+open_file returns -1 on error.");
+
+  ("open_device", (RInt "handle", [Device "device"]), 268, [],
+   [],
+   "open a block device",
+   "\
+This command opens a block device and returns a handle to it.
+It is able to open any block device with a node under /dev,
+including LVM logical volumes. The returned handle is an opaque
+int which can be passed to guestfs_h* calls.
+
+open_device returns -1 on error.");
+
+  ("hclose", (RErr, [Int "handle"]), 269, [],
+   [],
+   "close a file handle",
+   "\
+This command closes C<handle> and releases all resources associated
+with it.");
+
+  ("hclose_all", (RErr, []), 270, [],
+   [],
+   "close all open file handles",
+   "\
+This command closes all file handles which have been opened with
+open_*.");
+
+  ("hread", (RBufferOut "content", [Int "handle"; Int64 "size"]), 271,
+  [ProtocolLimitWarning], [],
+   "read data from an open handle",
+   "\
+This command reads up to C<size> bytes from C<handle> and returns
+the data in C<content>. It will attempt to read exactly C<size>
+bytes, but may return less. Returned C<content> with size 0
+indicates EOF.
+
+hread returns a NULL C<content> on error.");
+
+  ("hpread", (RBufferOut "content", [Int "handle"; Int64 "size";
+                                     Int64 "offset"]), 272,
+  [ProtocolLimitWarning], [],
+   "read data from an open handle at a specific offset",
+   "\
+This command reads up to C<size> bytes from C<handle> starting
+at C<offset> bytes from the beginning of the file. It returns
+the data in C<content>. It will attempt to read exactly C<size>
+bytes, but may return less. Returned C<content> with size 0
+indicates EOF.
+
+hpread returns a NULL C<content> on error.");
+
+  ("hwrite", (RErr, [Int "handle"; BufferIn "content"]), 273,
+   [ProtocolLimitWarning], [],
+   "write data to an open handle",
+   "\
+This command writes all the data in C<content> to C<handle>. It
+returns an error if this fails.");
+
+  ("hpwrite", (RErr, [Int "handle"; BufferIn "content"]), 274,
+   [ProtocolLimitWarning], [],
+   "write data to an open handle at a specific offset",
+   "\
+This command writes all the data in C<content> to C<handle>,
+starting at C<offset> bytes from the beginning of the file. It
+returns an error if this fails.");
+
+  ("hseek", (RInt64 "newoffset", [Int "handle"; Int64 "offset";
+                                  Int "whence"]), 275, [],
+   [],
+   "seek on an open handle",
+   "\
+This command updates the 'current position' in C<handle>. This
+affects the hread and hwrite calls. See L<lseek(3p)> for details
+of C<offset> and C<whence>.
+
+On success, hseek returns the new offset from the beginning of
+the file. It returns an offset of -1 on failure.");
+
+  ("htruncate", (RErr, [Int "handle"; Int64 "size"]), 276, [],
+   [],
+   "truncate a file",
+   "\
+This command sets the size of the file referred to by C<handle>
+to C<size>. If the file was previously larger than C<size>, the
+extra data will be lost. If the file was previously smaller than
+C<size>, the file will be zero-filled. The latter case will
+typically create a sparse file.");
+
+  ("hallocate", (RErr, [Int "handle"; Int64 "offset"; Int64 "length"]), 277, [],
+   [],
+   "reserve space for a file",
+   "\
+This command ensures that C<length> bytes of disk space have been
+allocated, starting at an offset of C<offset> bytes from the
+beginning of the file, for the file referred to by C<handle>.
+This will increase the size of the file if necessary. Any newly
+allocated space will be zero-filled.");
+
 ]
 
 let all_functions = non_daemon_functions @ daemon_functions

[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]