{"id":20079664,"url":"https://github.com/pmq20/libsquash","last_synced_at":"2025-05-05T23:30:36.379Z","repository":{"id":52265948,"uuid":"75185569","full_name":"pmq20/libsquash","owner":"pmq20","description":"Portable, user-land SquashFS that can be easily linked and embedded within your application.","archived":false,"fork":false,"pushed_at":"2021-05-02T16:37:26.000Z","size":1767,"stargazers_count":134,"open_issues_count":3,"forks_count":15,"subscribers_count":7,"default_branch":"master","last_synced_at":"2024-04-10T18:15:10.266Z","etag":null,"topics":["squashfs"],"latest_commit_sha":null,"homepage":"","language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/pmq20.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-11-30T12:38:06.000Z","updated_at":"2024-04-02T03:49:11.000Z","dependencies_parsed_at":"2022-09-12T02:51:20.337Z","dependency_job_id":null,"html_url":"https://github.com/pmq20/libsquash","commit_stats":null,"previous_names":[],"tags_count":8,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pmq20%2Flibsquash","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pmq20%2Flibsquash/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pmq20%2Flibsquash/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pmq20%2Flibsquash/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/pmq20","download_url":"https://codeload.github.com/pmq20/libsquash/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":224472534,"owners_count":17317009,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["squashfs"],"created_at":"2024-11-13T15:24:00.611Z","updated_at":"2024-11-13T15:24:01.304Z","avatar_url":"https://github.com/pmq20.png","language":"C","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Libsquash\n\nPortable, user-land SquashFS that can be easily linked and embedded within your application.\n\n[![Build status: Linux and Darwin](https://travis-ci.org/pmq20/libsquash.svg?branch=master)](https://travis-ci.org/pmq20/libsquash)\n[![Build status: Windows](https://ci.appveyor.com/api/projects/status/f4htq948gag3l2k8/branch/master?svg=true)](https://ci.appveyor.com/project/pmq20/libsquash/branch/master)\n\n## Design\n\nThis project was derived from https://github.com/vasi/squashfuse with the following modifications.\n\n1. __NO FUSE REQUIRED__, so that it can be so portable that even systems without fuse could use it.\n1. Read data from the memory instead of from a file by passing a pointer to an array of bytes,\nwhich could be generated by\nan independently installed [mksquashfs](http://squashfs.sourceforge.net/) tool\nand loaded into memory in advance.\n1. Introduced virtual file descriptor (vfd) as a handle for follow-up libsquash operations.\nThe vfd is generated via `dup(0)` so that it could live together with\nother ordinary file descriptors of the process.\n1. Added new API that mirror the calling style of common system calls;\nalso added is a sample on how to use libsquash in an unobtrusive way by utilizing those API.\n1. Made it compile on 3 platforms simultanesly: Windows, macOS and Linux.\n1. Added [CMake](https://cmake.org/) so that Xcode and Vistual Studio Projects could be easily generated.\n1. Added tests for both the old and new API of the library.\n1. Eliminate dependencies on \u003cstdbool.h\u003e so that Windows XP and Visual C++ 2010 could use this library.\n\n## Building\n\nOn most systems you could build the library using the following commands,\n\n    mkdir build\n    cd build\n    cmake ..\n    cmake --build .\n\nUse `cmake -DBUILD_TESTS=ON ..` to build the tests in addition and use `ctest --verbose` to run them.\n\n## API\n\n### `squash_stat(fs, path, buf)`\n\nObtains information about the file pointed to by `path` of a SquashFS `fs`.\nThe `buf` argument is a pointer to a stat structure as defined by\n`\u003csys/stat.h\u003e` and into which information is placed concerning the file.\nUpon successful completion a value of `0` is returned.\nOtherwise, a value of `-1` is returned and `errno` is set to the reason of the error.\n\n### `squash_lstat(fs, path, buf)`\n\nActs like `squash_stat()` except in the case where the named file is a symbolic link;\n`squash_lstat()` returns information about the link,\nwhile `squash_stat()` returns information about the file the link references.\n\n### `squash_fstat(vfd, buf)`\n\nObtains the same information as `squash_stat()`\nabout an open file known by the virtual file descriptor `vfd`.\n\n### `squash_open(fs, path)`\n\nOpens the file name specified by `path` of a SquashFS `fs` for reading.\nIf successful, `squash_open()` returns a non-negative integer, termed a vfd(virtual file descriptor).\nIt returns `-1` on failure and sets `errno` to the reason of the error.\nThe file pointer (used to mark the current position within the file) is set to the beginning of the file.\nThe returned vfd should later be closed by `squash_close()`.\n\n### `squash_close(vfd)`\n\nDeletes a `vfd`(virtual file descriptor) from the per-process object reference table.\nUpon successful completion, a value of `0` is returned.\nOtherwise, a value of `-1` is returned and `errno` is set to the reason of the error.\n\n### `squash_read(vfd, buf, nbyte)`\n\nAttempts to read `nbyte` bytes of data from the object\nreferenced by `vfs` into the buffer pointed to by `buf`,\nstarting at a position given by the pointer associated with `vfd` (see `squash_lseek`),\nwhich is then incremented by the number of bytes actually read upon return.\nWhen successful it returns the number of bytes actually read and placed in the buffer;\nupon reading end-of-file, zero is returned;\nOtherwise, a value of `-1` is returned and `errno` is set to the reason of the error.\n\n### `squash_lseek(vfd, offset, whence)`\n\nRepositions the offset of `vfs` to the argument `offset`, according to the directive `whence`.\nIf `whence` is `SQUASH_SEEK_SET` then the offset is set to `offset` bytes;\nif `whence` is `SQUASH_SEEK_CUR`, the `offset` is set to its current location plus `offset` bytes;\nif `whence` is `SQUASH_SEEK_END`, the `offset` is set to the size of the file\nand subsequent reads of the data return bytes of zeros.\nThe argument `fildes` must be an open virtual file descriptor.\nUpon successful completion,\nit returns the resulting offset location as measured in bytes from the beginning of the file.\nOtherwise, a value of `-1` is returned and `errno` is set to the reason of the error.\n\n### `squash_readlink(fs, path, buf, bufsize)`\n\nPlaces the contents of the symbolic link `path` of a SquashFS `fs`\nin the buffer `buf`, which has size `bufsize`.\nIt does not append a NUL character to `buf`.\nIf it succeeds the call returns the count of characters placed in the buffer;\notherwise `-1` is returned and `errno` is set to the reason of the error.\n\n### `squash_opendir(fs, filename)`\n\nOpens the directory named by `filename` of a SquashFS `fs`,\nassociates a directory stream with it and returns a pointer\nto be used to identify the directory stream in subsequent operations.\nThe pointer `NULL` is returned if `filename` cannot be accessed,\nor if it cannot allocate enough memory to hold the whole thing,\nand sets `errno` to the reason of the error.\nThe returned resource should later be closed by `squash_closedir()`.\n\n### `squash_closedir(dirp)`\n\nCloses the named directory stream and\nfrees the structure associated with the `dirp` pointer,\nreturning `0` on success.\nOn failure, `-1` is returned and `errno` is set to the reason of the error.\n\n### `squash_readdir(dirp)`\n\nReturns a pointer to the next directory entry.\nIt returns `NULL` upon reaching the end of the directory or on error. \nIn the event of an error, `errno` is set to the reason of the error.\n\n### `squash_telldir(dirp)`\n\nReturns the current location associated with the named directory stream.\n\n### `squash_seekdir(dirp, loc)`\n\nSets the position of the next `squash_readdir()` operation on the directory stream.\nThe new position reverts to the one associated with the directory stream\nwhen the `squash_telldir()` operation was performed.\n\n### `squash_rewinddir(dirp)`\n\nResets the position of the named directory stream to the beginning of the directory.\n\n### `squash_dirfd(dirp)`\n\nReturns the integer Libsquash file descriptor associated with the named directory stream.\nOn failure, `-1` is returned and `errno` is set to the reason of the error.\n\n### `squash_scandir(fs, dirname, namelist, select, compar)`\n\nReads the directory `dirname` of a SquashFS `fs` and\nbuilds an array of pointers to directory entries using `malloc`.\nIf successful it returns the number of entries in the array; \notherwise `-1` is returned and `errno` is set to the reason of the error.\nA pointer to the array of directory entries is stored\nin the location referenced by `namelist` (even if the number of entries is `0`),\nwhich should later be freed via `free()` by freeing each pointer\nin the array and then the array itself.\nThe `select` argument is a pointer to a user supplied subroutine which is\ncalled by `scandir` to select which entries are to be included in the array.\nThe `select` routine is passed a pointer to a directory entry\nand should return a non-zero value if the directory entry\nis to be included in the array.\nIf `select` is `NULL`, then all the directory entries will be included.\nThe `compar` argument is a pointer to a user supplied subroutine\nwhich is passed to `qsort` to sort the completed array.\nIf this pointer is `NULL`, then the array is not sorted.\n\n### `squash_extract(fs, path, ext_name)`\n\nExtracts the file `path` from `fs` to a temporary file inside the temporary folder.\nUpon successful completion the path of the extracted temporary file is returned.\nOtherwise, a value of `NULL` is returned and `errno` is set to the reason of the error.\nThe returned path is referenced by an internal cache and must not be freed.\n\n## To-do\n\n- Test Wide character directories and file names on Windows\n- Benchmark and tweet cache size and block size of libsquash\n- Organize core API's and freeze\n- Make public struct's opaque\n- Seperate headers into private headers and public headers\n- Make intercepting system calls a core functionality instead of in the sample/\n- Test under ARM architecture as well\n- Support Unicode paths\n- Embed mksquashfs logic instead of relying on outside tool\n- Intercept dynamically without compiling via the LD_PRELOAD trick\n\n## Acknowledgment\n\nThank you [Dave Vasilevsky](https://github.com/vasi) for the excellent work of squashfuse!\n\n## See Also\n\n- [Node.js Packer](https://github.com/pmq20/node-packer): Packing your Node.js application into a single executable.\n- [Ruby Packer](https://github.com/pmq20/ruby-packer): Packing your Ruby application into a single executable.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpmq20%2Flibsquash","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpmq20%2Flibsquash","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpmq20%2Flibsquash/lists"}