mirror of
https://github.com/pygos/pkg-utils.git
synced 2024-12-22 09:50:49 +01:00
pkg2sqfs: move some functions to more approrpiate places
Signed-off-by: David Oberhollenzer <goliath@infraroot.at>
This commit is contained in:
parent
025ab1007b
commit
eadeee25d9
6 changed files with 57 additions and 62 deletions
10
sqfs/block.c
10
sqfs/block.c
|
@ -200,13 +200,3 @@ fail_trunc:
|
|||
pkg_reader_get_filename(info->rd));
|
||||
return -1;
|
||||
}
|
||||
|
||||
int sqfs_write_fragment_table(sqfs_info_t *info)
|
||||
{
|
||||
info->super.fragment_entry_count = info->num_fragments;
|
||||
|
||||
return sqfs_write_table(info, info->fragments,
|
||||
sizeof(info->fragments[0]),
|
||||
info->num_fragments,
|
||||
&info->super.fragment_table_start);
|
||||
}
|
||||
|
|
|
@ -294,12 +294,3 @@ fail_tmp:
|
|||
fclose(tmp);
|
||||
return -1;
|
||||
}
|
||||
|
||||
int sqfs_write_ids(sqfs_info_t *info)
|
||||
{
|
||||
info->super.flags |= SQFS_FLAG_UNCOMPRESSED_IDS;
|
||||
|
||||
return sqfs_write_table(info, info->fs.id_tbl,
|
||||
sizeof(info->fs.id_tbl[0]),
|
||||
info->fs.num_ids, &info->super.id_table_start);
|
||||
}
|
||||
|
|
|
@ -99,6 +99,42 @@ static long read_number(const char *name, const char *str, long min, long max)
|
|||
return result;
|
||||
}
|
||||
|
||||
static int sqfs_padd_file(sqfs_info_t *info)
|
||||
{
|
||||
size_t padd_sz = info->super.bytes_used % info->dev_blk_size;
|
||||
uint8_t *buffer;
|
||||
ssize_t ret;
|
||||
off_t off;
|
||||
|
||||
if (padd_sz == 0)
|
||||
return 0;
|
||||
|
||||
off = lseek(info->outfd, 0, SEEK_END);
|
||||
if (off == (off_t)-1) {
|
||||
perror("seek on output file");
|
||||
return -1;
|
||||
}
|
||||
|
||||
padd_sz = info->dev_blk_size - padd_sz;
|
||||
buffer = alloca(padd_sz);
|
||||
memset(buffer, 0, padd_sz);
|
||||
|
||||
ret = write_retry(info->outfd, buffer, padd_sz);
|
||||
|
||||
if (ret < 0) {
|
||||
perror("Error padding squashfs image to page size");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (ret == 0) {
|
||||
fputs("Truncated write trying to padd squashfs image\n",
|
||||
stderr);
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
uint32_t blocksize = SQFS_DEFAULT_BLOCK_SIZE, timestamp = 0;
|
||||
|
|
|
@ -133,9 +133,4 @@ int meta_writer_flush(meta_writer_t *m);
|
|||
|
||||
int meta_writer_append(meta_writer_t *m, const void *data, size_t size);
|
||||
|
||||
int sqfs_write_table(sqfs_info_t *info, const void *data, size_t entsize,
|
||||
size_t count, uint64_t *start);
|
||||
|
||||
int sqfs_padd_file(sqfs_info_t *info);
|
||||
|
||||
#endif /* PKG2SQFS_H */
|
||||
|
|
36
sqfs/super.c
36
sqfs/super.c
|
@ -97,39 +97,3 @@ int sqfs_super_write(sqfs_info_t *info)
|
|||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int sqfs_padd_file(sqfs_info_t *info)
|
||||
{
|
||||
size_t padd_sz = info->super.bytes_used % info->dev_blk_size;
|
||||
uint8_t *buffer;
|
||||
ssize_t ret;
|
||||
off_t off;
|
||||
|
||||
if (padd_sz == 0)
|
||||
return 0;
|
||||
|
||||
off = lseek(info->outfd, 0, SEEK_END);
|
||||
if (off == (off_t)-1) {
|
||||
perror("seek on output file");
|
||||
return -1;
|
||||
}
|
||||
|
||||
padd_sz = info->dev_blk_size - padd_sz;
|
||||
buffer = alloca(padd_sz);
|
||||
memset(buffer, 0, padd_sz);
|
||||
|
||||
ret = write_retry(info->outfd, buffer, padd_sz);
|
||||
|
||||
if (ret < 0) {
|
||||
perror("Error padding squashfs image to page size");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (ret == 0) {
|
||||
fputs("Truncated write trying to padd squashfs image\n",
|
||||
stderr);
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
23
sqfs/table.c
23
sqfs/table.c
|
@ -1,8 +1,8 @@
|
|||
/* SPDX-License-Identifier: ISC */
|
||||
#include "pkg2sqfs.h"
|
||||
|
||||
int sqfs_write_table(sqfs_info_t *info, const void *data, size_t entsize,
|
||||
size_t count, uint64_t *startblock)
|
||||
static int sqfs_write_table(sqfs_info_t *info, const void *data,
|
||||
size_t entsize, size_t count, uint64_t *startblock)
|
||||
{
|
||||
size_t ent_per_blocks = SQFS_META_BLOCK_SIZE / entsize;
|
||||
uint64_t blocks[count / ent_per_blocks + 1];
|
||||
|
@ -56,3 +56,22 @@ fail:
|
|||
meta_writer_destroy(m);
|
||||
return -1;
|
||||
}
|
||||
|
||||
int sqfs_write_fragment_table(sqfs_info_t *info)
|
||||
{
|
||||
info->super.fragment_entry_count = info->num_fragments;
|
||||
|
||||
return sqfs_write_table(info, info->fragments,
|
||||
sizeof(info->fragments[0]),
|
||||
info->num_fragments,
|
||||
&info->super.fragment_table_start);
|
||||
}
|
||||
|
||||
int sqfs_write_ids(sqfs_info_t *info)
|
||||
{
|
||||
info->super.flags |= SQFS_FLAG_UNCOMPRESSED_IDS;
|
||||
|
||||
return sqfs_write_table(info, info->fs.id_tbl,
|
||||
sizeof(info->fs.id_tbl[0]),
|
||||
info->fs.num_ids, &info->super.id_table_start);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue