Coder Social home page Coder Social logo

read-qcow2's Introduction

This is a tiny standalone C library for reading qcow2 disk image files.

Unallocated image data is read as all zeros. It does not know about encryption or compression. It can only access the active data, not the snapshots. It cannot make changes to the image file. The qcow2 file's cluster size must be at least the system page size.

But it is small and standalone. You only need the files qcow2.c and qcow2.h to access the content from C.

Open a qcow2 image file

struct qcow2 *qcow2_open(int fd, const char **error_ret);

This function checks that fd is an uncompressed qcow2 image file, and returns a context structure to access it.

The file descriptor fd must not be accessed by the caller afterwards. It will be closed later by qcow2_close().

On error, this function returns NULL, closes the file fd, sets errno and puts an error message in the optional error_ret.

Close the qcow2 image file

void qcow2_close(struct qcow2 *q);

This function closes the file, and frees q.

If q is NULL, this function has no effect.

Query the image's virtual size

uint64_t qcow2_get_size(struct qcow2 *q);

Returns the image's virtual size, in bytes.

Read data from the image

int qcow2_read(struct qcow2 *q, void *dest, size_t len, uint64_t offset);

This function copies to dest at most len bytes of data from the image's virtual content starting at offset. On success, returns the number of bytes copied out to dest. This is the same as len unless the copy would exceed the image size.

On error returns -1 and sets errno. The content of dest is unspecified.

References

read-qcow2's People

Contributors

dleonard0 avatar nigels-com avatar

Stargazers

 avatar

Forkers

jjzhang166

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.