Skip to content

Commit

Permalink
[rpmextents] Create an internal library to make rpmextents file manip…
Browse files Browse the repository at this point in the history
…ulation easier and less duplicated
  • Loading branch information
chantra committed Feb 9, 2022
1 parent 86776bf commit 0138e4f
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 21 deletions.
3 changes: 2 additions & 1 deletion lib/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ librpm_la_SOURCES = \
rpmscript.h rpmscript.c \
rpmchroot.c rpmchroot.h \
rpmplugins.c rpmplugins.h rpmplugin.h rpmug.c rpmug.h \
rpmtriggers.h rpmtriggers.c rpmvs.c rpmvs.h
rpmtriggers.h rpmtriggers.c rpmvs.c rpmvs.h \
rpmextents_internal.h

librpm_la_LDFLAGS = -version-info $(rpm_version_info)

Expand Down
10 changes: 3 additions & 7 deletions lib/rpmchecksig.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,11 @@
#include "rpmio/rpmio_internal.h" /* fdSetBundle() */
#include "lib/rpmlead.h"
#include "lib/header_internal.h"
#include "lib/rpmextents_internal.h"
#include "lib/rpmvs.h"

#include "debug.h"

/* magic value at end of file (64 bits) that indicates this is a transcoded
* rpm.
*/
#define MAGIC 3472329499408095051

static int doImport(rpmts ts, const char *fn, char *buf, ssize_t blen)
{
char const * const pgpmark = "-----BEGIN PGP ";
Expand Down Expand Up @@ -228,7 +224,7 @@ rpmRC rpmpkgRead(struct rpmvs_s *vs, FD_t fd,
static rpmRC isTranscodedRpm(FD_t fd) {
rpmRC rc = RPMRC_NOTFOUND;
rpm_loff_t current;
uint64_t magic;
extents_magic_t magic;
size_t len;

// If the file is not seekable, we cannot detect whether or not it is transcoded.
Expand All @@ -248,7 +244,7 @@ static rpmRC isTranscodedRpm(FD_t fd) {
rc = RPMRC_FAIL;
goto exit;
}
if (magic != MAGIC) {
if (magic != EXTENTS_MAGIC) {
rpmlog(RPMLOG_DEBUG, _("isTranscodedRpm: not transcoded\n"));
rc = RPMRC_NOTFOUND;
goto exit;
Expand Down
20 changes: 20 additions & 0 deletions lib/rpmextents_internal.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#ifndef _RPMEXTENTS_INTERNAL_H
#define _RPMEXTENTS_INTERNAL_H

#ifdef __cplusplus
extern "C" {
#endif

#include <stdint.h>

/* magic value at end of file (64 bits) that indicates this is a transcoded
* rpm.
*/
#define EXTENTS_MAGIC 3472329499408095051

typedef uint64_t extents_magic_t;

#ifdef __cplusplus
}
#endif
#endif
10 changes: 3 additions & 7 deletions plugins/reflink.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include <rpm/rpmlog.h>
#include "lib/rpmlib.h"
#include "lib/rpmplugin.h"
#include "lib/rpmextents_internal.h"
#include "lib/rpmte_internal.h"
#include <rpm/rpmfileutil.h>
#include "rpmio/rpmio_internal.h"
Expand Down Expand Up @@ -40,11 +41,6 @@

#define BUFFER_SIZE (1024 * 128)

/* magic value at end of file (64 bits) that indicates this is a transcoded
* rpm.
*/
#define MAGIC 3472329499408095051

struct reflink_state_s {
/* Stuff that's used across rpms */
long fundamental_block_size;
Expand Down Expand Up @@ -103,7 +99,7 @@ static rpmRC reflink_psm_pre(rpmPlugin plugin, rpmte te) {
return RPMRC_OK;
}
rpm_loff_t current = Ftell(state->fd);
uint64_t magic;
extents_magic_t magic;
if (Fseek(state->fd, -(sizeof(magic)), SEEK_END) < 0) {
rpmlog(RPMLOG_ERR, _("reflink: failed to seek for magic\n"));
if (Fseek(state->fd, current, SEEK_SET) < 0) {
Expand All @@ -122,7 +118,7 @@ static rpmRC reflink_psm_pre(rpmPlugin plugin, rpmte te) {
}
return RPMRC_FAIL;
}
if (magic != MAGIC) {
if (magic != EXTENTS_MAGIC) {
rpmlog(RPMLOG_DEBUG, _("reflink: not transcoded\n"));
if (Fseek(state->fd, current, SEEK_SET) < 0) {
rpmlog(RPMLOG_ERR,
Expand Down
8 changes: 2 additions & 6 deletions rpm2extents.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include "lib/rpmts.h"
#include "lib/signature.h"
#include "lib/header_internal.h"
#include "lib/rpmextents_internal.h"
#include "rpmio/rpmio_internal.h"

#include <unistd.h>
Expand All @@ -37,11 +38,6 @@
#include "lib/rpmhash.H"
#include "lib/rpmhash.C"

/* magic value at end of file (64 bits) that indicates this is a transcoded
* rpm.
*/
#define MAGIC 3472329499408095051

struct digestoffset {
const unsigned char * digest;
rpm_loff_t pos;
Expand Down Expand Up @@ -402,7 +398,7 @@ static rpmRC process_package(FD_t fdi, FD_t digestori, FD_t validationi)
rc = RPMRC_FAIL;
goto exit;
}
uint64_t magic = MAGIC;
extents_magic_t magic = EXTENTS_MAGIC;
len = sizeof(magic);
if (Fwrite(&magic, len, 1, fdo) != len) {
fprintf(stderr, _("Unable to write magic\n"));
Expand Down

0 comments on commit 0138e4f

Please sign in to comment.