libsqsh v1.5.2
Loading...
Searching...
No Matches
sqsh_file.h
Go to the documentation of this file.
1/******************************************************************************
2 * *
3 * Copyright (c) 2023-2024, Enno Boland <g@s01.de> *
4 * *
5 * Redistribution and use in source and binary forms, with or without *
6 * modification, are permitted provided that the following conditions are *
7 * met: *
8 * *
9 * * Redistributions of source code must retain the above copyright notice, *
10 * this list of conditions and the following disclaimer. *
11 * * Redistributions in binary form must reproduce the above copyright *
12 * notice, this list of conditions and the following disclaimer in the *
13 * documentation and/or other materials provided with the distribution. *
14 * *
15 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS *
16 * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, *
17 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR *
18 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR *
19 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, *
20 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, *
21 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR *
22 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF *
23 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING *
24 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS *
25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *
26 * *
27 ******************************************************************************/
28
34#ifndef SQSH_FILE_H
35#define SQSH_FILE_H
36
37#include "sqsh_common.h"
38
39#ifdef __cplusplus
40extern "C" {
41#endif
42
43struct SqshFile;
44struct SqshArchive;
45
46/***************************************
47 * context/file_reader.c
48 */
49
54struct SqshFileReader;
55
65struct SqshFileReader *
66sqsh_file_reader_new(const struct SqshFile *file, int *err);
67
80__attribute__((deprecated(
81 "Since 1.5.0. Use sqsh_file_reader_advance2() instead."))) int
83 struct SqshFileReader *reader, sqsh_index_t offset, size_t size);
84
97 struct SqshFileReader *reader, uint64_t offset, size_t size);
98
107const uint8_t *sqsh_file_reader_data(const struct SqshFileReader *reader);
108
117size_t sqsh_file_reader_size(const struct SqshFileReader *reader);
118
128
129/***************************************
130 * file/file_iterator.c
131 */
132
133struct SqshFileIterator;
134
146sqsh_file_iterator_new(const struct SqshFile *file, int *err);
147
161SQSH_NO_UNUSED bool sqsh_file_iterator_next(
162 struct SqshFileIterator *iterator, size_t desired_size, int *err);
163
173sqsh_file_iterator_is_zero_block(const struct SqshFileIterator *iterator);
174
209__attribute__((
210 deprecated("Since 1.5.0. Use sqsh_file_iterator_skip2() instead.")))
212sqsh_file_iterator_skip(
213 struct SqshFileIterator *iterator, sqsh_index_t *offset,
214 size_t desired_size);
215
249SQSH_NO_UNUSED int sqsh_file_iterator_skip2(
250 struct SqshFileIterator *iterator, uint64_t *offset,
251 size_t desired_size);
252
261SQSH_NO_UNUSED const uint8_t *
262sqsh_file_iterator_data(const struct SqshFileIterator *iterator);
263
272SQSH_NO_UNUSED size_t
273sqsh_file_iterator_block_size(const struct SqshFileIterator *iterator);
274
283SQSH_NO_UNUSED size_t
284sqsh_file_iterator_size(const struct SqshFileIterator *iterator);
285
294int sqsh_file_iterator_free(struct SqshFileIterator *iterator);
295
296/***************************************
297 * file/file.c
298 */
299
303#define SQSH_INODE_NO_FRAGMENT 0xFFFFFFFF
307#define SQSH_INODE_NO_XATTR 0xFFFFFFFF
308
309__attribute__((deprecated(
310 "Since 1.5.0. libsqsh should never return this."))) static const int
311 SQSH_FILE_TYPE_UNKNOWN = -1;
325
337sqsh_open(struct SqshArchive *archive, const char *path, int *err);
338
351sqsh_lopen(struct SqshArchive *archive, const char *path, int *err);
352
364sqsh_open_by_ref(struct SqshArchive *archive, uint64_t inode_ref, int *err);
365
374bool sqsh_file_is_extended(const struct SqshFile *context);
375
384uint32_t sqsh_file_hard_link_count(const struct SqshFile *context);
385
394uint64_t sqsh_file_size(const struct SqshFile *context);
395
404uint16_t sqsh_file_permission(const struct SqshFile *context);
405
414uint32_t sqsh_file_inode(const struct SqshFile *context);
415
424uint32_t sqsh_file_modified_time(const struct SqshFile *context);
425
436uint64_t sqsh_file_blocks_start(const struct SqshFile *context);
437
449__attribute__((deprecated("Since 1.5.0. Use sqsh_file_blockcount2() instead.")))
450uint32_t
451sqsh_file_block_count(const struct SqshFile *context);
452
463uint64_t sqsh_file_block_count2(const struct SqshFile *context);
464
475uint32_t sqsh_file_block_size(const struct SqshFile *context, uint32_t index);
476
486bool
487sqsh_file_block_is_compressed(const struct SqshFile *context, uint32_t index);
488
498uint32_t sqsh_file_fragment_block_index(const struct SqshFile *context);
499
509uint32_t sqsh_file_fragment_block_offset(const struct SqshFile *context);
510
520uint32_t sqsh_file_directory_block_start(const struct SqshFile *context);
521
532__attribute__((
533 deprecated("Since 1.3.0. Use sqsh_file_directory_block_offset2() "
534 "instead."))) uint32_t
536
546uint16_t sqsh_file_directory_block_offset2(const struct SqshFile *context);
547
556uint32_t sqsh_file_directory_parent_inode(const struct SqshFile *context);
557
566bool sqsh_file_has_fragment(const struct SqshFile *context);
567
576enum SqshFileType sqsh_file_type(const struct SqshFile *context);
577
588
600
615const char *sqsh_file_symlink(const struct SqshFile *context);
616
630SQSH_NO_UNUSED char *sqsh_file_symlink_dup(const struct SqshFile *context);
631
641uint32_t sqsh_file_symlink_size(const struct SqshFile *context);
642
652uint32_t sqsh_file_device_id(const struct SqshFile *context);
653
662uint32_t sqsh_file_uid(const struct SqshFile *context);
663
672uint32_t sqsh_file_gid(const struct SqshFile *context);
673
699uint64_t sqsh_file_inode_ref(const struct SqshFile *context);
700
709uint32_t sqsh_file_xattr_index(const struct SqshFile *context);
710
719int sqsh_close(struct SqshFile *file);
720
721#ifdef __cplusplus
722}
723#endif
724#endif /* SQSH_FILE_H */
#define SQSH_NO_UNUSED
Warn if return value is unused.
Definition sqsh_common.h:59
size_t sqsh_index_t
typedef used for indexing
Definition sqsh_common.h:69
SqshFileType
enum that represents the file type.
Definition sqsh_file.h:315
@ SQSH_FILE_TYPE_DIRECTORY
Definition sqsh_file.h:317
@ SQSH_FILE_TYPE_FILE
Definition sqsh_file.h:318
@ SQSH_FILE_TYPE_CHAR
Definition sqsh_file.h:321
@ SQSH_FILE_TYPE_BLOCK
Definition sqsh_file.h:320
@ SQSH_FILE_TYPE_SOCKET
Definition sqsh_file.h:323
@ SQSH_FILE_TYPE_FIFO
Definition sqsh_file.h:322
@ SQSH_FILE_TYPE_SYMLINK
Definition sqsh_file.h:319
An iterator over the contents of a file.
A reader over the contents of a file.
const uint8_t * sqsh_file_reader_data(const struct SqshFileReader *reader)
Gets a pointer to the current data in the file reader.
int sqsh_file_reader_advance2(struct SqshFileReader *reader, uint64_t offset, size_t size)
Advances the file reader by a certain amount of data and presents size bytes of data to the user.
size_t sqsh_file_reader_size(const struct SqshFileReader *reader)
Gets the size of the current data in the file reader.
int sqsh_file_reader_free(struct SqshFileReader *reader)
Cleans up resources used by a SqshFileReader struct.
struct SqshFileReader * sqsh_file_reader_new(const struct SqshFile *file, int *err)
Initializes a SqshFileReader struct.
int sqsh_file_reader_advance(struct SqshFileReader *reader, sqsh_index_t offset, size_t size)
Advances the file reader by a certain amount of data and presents size bytes of data to the user.
The Inode context.
bool sqsh_file_is_extended(const struct SqshFile *context)
returns whether the file is an extended structure.
SQSH_NO_UNUSED struct SqshFile * sqsh_open_by_ref(struct SqshArchive *archive, uint64_t inode_ref, int *err)
Initializes a file context in heap.
uint32_t sqsh_file_modified_time(const struct SqshFile *context)
Getter for the file modification time in seconds since epoch.
uint64_t sqsh_file_size(const struct SqshFile *context)
Getter for the file size. 0 if the file has no size.
uint32_t sqsh_file_hard_link_count(const struct SqshFile *context)
Getter for the inode hard link count.
uint64_t sqsh_file_block_count2(const struct SqshFile *context)
Getter for the amount of blocks of the file content. This is only internally used and will be used wh...
uint64_t sqsh_file_blocks_start(const struct SqshFile *context)
Getter for the start block of the file content. This is only internally used and will be used while r...
uint64_t sqsh_file_inode_ref(const struct SqshFile *context)
returns the inode reference to this file.
uint32_t sqsh_file_uid(const struct SqshFile *context)
returns the owner user id of the file.
SQSH_NO_UNUSED struct SqshFile * sqsh_open(struct SqshArchive *archive, const char *path, int *err)
Initialize the file context from a path.
enum SqshFileType sqsh_file_type(const struct SqshFile *context)
returns the type of the file.
bool sqsh_file_has_fragment(const struct SqshFile *context)
returns true if the file has a fragment block.
uint32_t sqsh_file_inode(const struct SqshFile *context)
Getter for the inode number.
uint32_t sqsh_file_directory_block_offset(const struct SqshFile *context)
retrieve the directory block offset. This is only internally used and will be used while iterating ov...
uint32_t sqsh_file_directory_parent_inode(const struct SqshFile *context)
retrieve the parent inode of the directory.
bool sqsh_file_block_is_compressed(const struct SqshFile *context, uint32_t index)
Checks whether a certain block is compressed.
SQSH_NO_UNUSED char * sqsh_file_symlink_dup(const struct SqshFile *context)
creates a heap allocated copy of the target of a symbolic link.
uint32_t sqsh_file_fragment_block_offset(const struct SqshFile *context)
retrieve the fragment block offset. This is only internally used and will be used while retrieving th...
uint32_t sqsh_file_device_id(const struct SqshFile *context)
returns the device id of the device inode.
uint16_t sqsh_file_directory_block_offset2(const struct SqshFile *context)
retrieve the directory block offset. This is only internally used and will be used while iterating ov...
uint32_t sqsh_file_block_count(const struct SqshFile *context)
Getter for the amount of blocks of the file content. This is only internally used and will be used wh...
uint32_t sqsh_file_block_size(const struct SqshFile *context, uint32_t index)
Getter the size of a block of the file content. This is only internally used and will be used while r...
uint32_t sqsh_file_gid(const struct SqshFile *context)
returns the owner group id of the file.
int sqsh_file_symlink_resolve(struct SqshFile *context)
resolves the symlink target. After calling this function the file is in place changed to the target o...
uint16_t sqsh_file_permission(const struct SqshFile *context)
Getter for the permissions of the file.
const char * sqsh_file_symlink(const struct SqshFile *context)
returns the target of a symbolic link. Be aware that the returned value is not zero terminated.
uint32_t sqsh_file_directory_block_start(const struct SqshFile *context)
retrieve the directory block start. This is only internally used and will be used while iterating ove...
uint32_t sqsh_file_symlink_size(const struct SqshFile *context)
returns the length of the target of a symbolic link in bytes.
uint32_t sqsh_file_fragment_block_index(const struct SqshFile *context)
retrieve the fragment block index. This is only internally used
int sqsh_close(struct SqshFile *file)
cleans up an file context and frees the memory.
uint32_t sqsh_file_xattr_index(const struct SqshFile *context)
returns index of the extended attribute inside of the xattr table.
SQSH_NO_UNUSED struct SqshFile * sqsh_lopen(struct SqshArchive *archive, const char *path, int *err)
Initialize the file context from a path. This function is identical to sqsh_open() but if the path is...
int sqsh_file_symlink_resolve_all(struct SqshFile *context)
resolves all symlink target targets until a file is hit. This function is similar to sqsh_file_symlin...