2000-06-10 02:57:23 +08:00
|
|
|
#ifndef H_RPMIO_INTERNAL
|
|
|
|
#define H_RPMIO_INTERNAL
|
|
|
|
|
2000-08-28 02:34:02 +08:00
|
|
|
/** \ingroup rpmio
|
|
|
|
* \file rpmio/rpmio_internal.h
|
|
|
|
*/
|
|
|
|
|
2000-06-20 23:54:48 +08:00
|
|
|
|
2000-06-10 02:57:23 +08:00
|
|
|
#include <rpmio.h>
|
|
|
|
#include <rpmurl.h>
|
|
|
|
|
2000-08-28 09:08:57 +08:00
|
|
|
/** \ingroup rpmio
|
|
|
|
*/
|
2000-06-10 02:57:23 +08:00
|
|
|
typedef struct _FDSTACK_s {
|
2001-06-04 21:55:58 +08:00
|
|
|
FDIO_t io;
|
2000-06-10 02:57:23 +08:00
|
|
|
/*@dependent@*/ void * fp;
|
2001-06-04 21:55:58 +08:00
|
|
|
int fdno;
|
2000-06-10 02:57:23 +08:00
|
|
|
} FDSTACK_t;
|
|
|
|
|
2000-08-28 09:08:57 +08:00
|
|
|
/** \ingroup rpmio
|
|
|
|
* Cumulative statistics for an I/O operation.
|
|
|
|
*/
|
2000-06-10 02:57:23 +08:00
|
|
|
typedef struct {
|
2001-06-04 21:55:58 +08:00
|
|
|
int count; /*!< Number of operations. */
|
|
|
|
off_t bytes; /*!< Number of bytes transferred. */
|
|
|
|
time_t msecs; /*!< Number of milli-seconds. */
|
2000-06-10 02:57:23 +08:00
|
|
|
} OPSTAT_t;
|
|
|
|
|
2000-08-28 09:08:57 +08:00
|
|
|
/** \ingroup rpmio
|
|
|
|
* Identify per-desciptor I/O operation statistics.
|
|
|
|
*/
|
|
|
|
enum FDSTAT_e {
|
2001-06-04 21:55:58 +08:00
|
|
|
FDSTAT_READ = 0, /*!< Read statistics index. */
|
|
|
|
FDSTAT_WRITE = 1, /*!< Write statistics index. */
|
|
|
|
FDSTAT_SEEK = 2, /*!< Seek statistics index. */
|
|
|
|
FDSTAT_CLOSE = 3 /*!< Close statistics. index */
|
2000-08-28 09:08:57 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
/** \ingroup rpmio
|
|
|
|
* Cumulative statistics for a descriptor.
|
|
|
|
*/
|
2000-11-01 00:18:34 +08:00
|
|
|
typedef /*@abstract@*/ struct {
|
2001-06-04 21:55:58 +08:00
|
|
|
struct timeval create; /*!< Structure creation time. */
|
|
|
|
struct timeval begin; /*!< Operation start time. */
|
|
|
|
OPSTAT_t ops[4]; /*!< Cumulative statistics. */
|
2000-11-01 00:18:34 +08:00
|
|
|
} * FDSTAT_t;
|
2000-06-10 02:57:23 +08:00
|
|
|
|
2000-10-24 21:46:51 +08:00
|
|
|
/** \ingroup rpmio
|
2000-11-01 00:18:34 +08:00
|
|
|
* Bit(s) to control digest operation.
|
2000-10-24 21:46:51 +08:00
|
|
|
*/
|
2000-11-01 00:18:34 +08:00
|
|
|
typedef enum rpmDigestFlags_e {
|
|
|
|
RPMDIGEST_MD5 = (1 << 0), /*!< MD5 digest. */
|
2001-09-26 22:45:50 +08:00
|
|
|
RPMDIGEST_SHA1 = (1 << 1) /*!< SHA1 digest. */
|
|
|
|
#ifdef DYING
|
2001-07-22 03:44:22 +08:00
|
|
|
RPMDIGEST_REVERSE = (1 << 16), /*!< Should bytes be reversed? */
|
|
|
|
RPMDIGEST_BCSWAP = (1 << 17), /*!< Should bit count be reversed? */
|
2001-09-26 22:45:50 +08:00
|
|
|
#endif
|
2000-11-01 00:18:34 +08:00
|
|
|
} rpmDigestFlags;
|
2001-09-26 22:45:50 +08:00
|
|
|
#define RPMDIGEST_MASK 0xffff
|
2000-11-01 00:18:34 +08:00
|
|
|
|
2001-10-05 13:10:12 +08:00
|
|
|
/**
|
|
|
|
*/
|
2000-11-01 00:18:34 +08:00
|
|
|
typedef /*@abstract@*/ struct DIGEST_CTX_s * DIGEST_CTX;
|
2000-10-24 21:46:51 +08:00
|
|
|
|
2001-10-06 04:39:50 +08:00
|
|
|
/** \ingroup rpmio
|
|
|
|
* Duplicate a digest context.
|
|
|
|
* @param ctx existing digest context
|
|
|
|
* @return duplicated digest context
|
|
|
|
*/
|
|
|
|
/*@only@*/
|
|
|
|
DIGEST_CTX rpmDigestDup(DIGEST_CTX octx)
|
|
|
|
/*@*/;
|
|
|
|
|
2000-11-01 00:18:34 +08:00
|
|
|
/** \ingroup rpmio
|
|
|
|
* Initialize digest.
|
|
|
|
* Set bit count to 0 and buffer to mysterious initialization constants.
|
|
|
|
* @param flags bit(s) to control digest operation
|
2001-10-06 04:39:50 +08:00
|
|
|
* @return digest context
|
2000-11-01 00:18:34 +08:00
|
|
|
*/
|
2001-10-06 04:39:50 +08:00
|
|
|
/*@only@*/
|
2001-06-04 21:55:58 +08:00
|
|
|
DIGEST_CTX rpmDigestInit(rpmDigestFlags flags)
|
|
|
|
/*@*/;
|
2000-11-01 00:18:34 +08:00
|
|
|
|
|
|
|
/** \ingroup rpmio
|
2001-10-06 04:39:50 +08:00
|
|
|
* Update context with next plain text buffer.
|
|
|
|
* @param ctx digest context
|
2000-11-01 00:18:34 +08:00
|
|
|
* @param data next data buffer
|
|
|
|
* @param len no. bytes of data
|
|
|
|
*/
|
2001-06-04 21:55:58 +08:00
|
|
|
void rpmDigestUpdate(DIGEST_CTX ctx, const void * data, size_t len)
|
|
|
|
/*@modifies ctx @*/;
|
2000-11-01 00:18:34 +08:00
|
|
|
|
|
|
|
/** \ingroup rpmio
|
|
|
|
* Return digest and destroy context.
|
|
|
|
* Final wrapup - pad to 64-byte boundary with the bit pattern
|
|
|
|
* 1 0* (64-bit count of bits processed, MSB-first)
|
|
|
|
*
|
2001-10-06 04:39:50 +08:00
|
|
|
* @param ctx digest context
|
2000-11-01 00:18:34 +08:00
|
|
|
* @retval datap address of returned digest
|
|
|
|
* @retval lenp address of digest length
|
|
|
|
* @param asAscii return digest as ascii string?
|
|
|
|
*/
|
2001-05-04 05:00:18 +08:00
|
|
|
void rpmDigestFinal(/*@only@*/ DIGEST_CTX ctx,
|
|
|
|
/*@null@*/ /*@out@*/ void ** datap,
|
2001-06-04 21:55:58 +08:00
|
|
|
/*@null@*/ /*@out@*/ size_t * lenp, int asAscii)
|
|
|
|
/*@modifies *datap, *lenp @*/;
|
2000-10-24 21:46:51 +08:00
|
|
|
|
2000-08-28 09:08:57 +08:00
|
|
|
/** \ingroup rpmio
|
|
|
|
* The FD_t File Handle data structure.
|
|
|
|
*/
|
2000-06-10 02:57:23 +08:00
|
|
|
struct _FD_s {
|
2001-06-04 21:55:58 +08:00
|
|
|
/*@refs@*/ int nrefs;
|
|
|
|
int flags;
|
2000-06-10 02:57:23 +08:00
|
|
|
#define RPMIO_DEBUG_IO 0x40000000
|
|
|
|
#define RPMIO_DEBUG_REFS 0x20000000
|
2001-06-04 21:55:58 +08:00
|
|
|
int magic;
|
|
|
|
#define FDMAGIC 0x04463138
|
|
|
|
int nfps;
|
|
|
|
FDSTACK_t fps[8];
|
|
|
|
int urlType; /* ufdio: */
|
|
|
|
|
|
|
|
/*@dependent@*/ void * url; /* ufdio: URL info */
|
|
|
|
int rd_timeoutsecs; /* ufdRead: per FD_t timer */
|
|
|
|
ssize_t bytesRemain; /* ufdio: */
|
|
|
|
ssize_t contentLength; /* ufdio: */
|
|
|
|
int persist; /* ufdio: */
|
|
|
|
int wr_chunked; /* ufdio: */
|
|
|
|
|
|
|
|
int syserrno; /* last system errno encountered */
|
2000-06-10 02:57:23 +08:00
|
|
|
/*@observer@*/ const void *errcookie; /* gzdio/bzdio/ufdio: */
|
|
|
|
|
2001-06-04 21:55:58 +08:00
|
|
|
FDSTAT_t stats; /* I/O statistics */
|
|
|
|
/*@owned@*/ /*@null@*/ DIGEST_CTX digest; /* Digest private data */
|
2000-06-10 02:57:23 +08:00
|
|
|
|
2001-06-04 21:55:58 +08:00
|
|
|
int ftpFileDoneNeeded; /* ufdio: (FTP) */
|
|
|
|
unsigned int firstFree; /* fadio: */
|
|
|
|
long int fileSize; /* fadio: */
|
|
|
|
long int fd_cpioPos; /* cpio: */
|
2000-06-10 02:57:23 +08:00
|
|
|
};
|
2000-08-23 21:49:07 +08:00
|
|
|
/*@access FD_t@*/
|
2000-06-10 02:57:23 +08:00
|
|
|
|
|
|
|
#define FDSANE(fd) assert(fd && fd->magic == FDMAGIC)
|
|
|
|
|
2001-06-04 21:55:58 +08:00
|
|
|
/*@-redecl@*/
|
2001-10-15 11:22:10 +08:00
|
|
|
/*@unchecked@*/
|
2000-06-10 05:24:37 +08:00
|
|
|
extern int _rpmio_debug;
|
2001-06-04 21:55:58 +08:00
|
|
|
/*@=redecl@*/
|
2000-06-10 05:24:37 +08:00
|
|
|
|
|
|
|
#define DBG(_f, _m, _x) \
|
|
|
|
if ((_rpmio_debug | ((_f) ? ((FD_t)(_f))->flags : 0)) & (_m)) fprintf _x
|
|
|
|
|
|
|
|
#define DBGIO(_f, _x) DBG((_f), RPMIO_DEBUG_IO, _x)
|
|
|
|
#define DBGREFS(_f, _x) DBG((_f), RPMIO_DEBUG_REFS, _x)
|
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
2001-09-25 05:53:14 +08:00
|
|
|
/** \ingroup rpmio
|
|
|
|
*/
|
2001-06-06 03:26:22 +08:00
|
|
|
int fdFgets(FD_t fd, char * buf, size_t len)
|
2001-10-18 00:43:36 +08:00
|
|
|
/*@globals errno, fileSystem @*/
|
|
|
|
/*@modifies *buf, fd, errno, fileSystem @*/;
|
2000-06-10 05:24:37 +08:00
|
|
|
|
2001-09-25 05:53:14 +08:00
|
|
|
/** \ingroup rpmio
|
|
|
|
*/
|
2000-06-10 05:24:37 +08:00
|
|
|
/*@null@*/ FD_t ftpOpen(const char *url, /*@unused@*/ int flags,
|
2001-06-06 03:26:22 +08:00
|
|
|
/*@unused@*/ mode_t mode, /*@out@*/ urlinfo *uret)
|
2001-10-16 01:53:34 +08:00
|
|
|
/*@globals fileSystem @*/
|
2001-06-06 03:26:22 +08:00
|
|
|
/*@modifies *uret, fileSystem @*/;
|
2001-09-25 05:53:14 +08:00
|
|
|
|
|
|
|
/** \ingroup rpmio
|
|
|
|
*/
|
2001-06-06 03:26:22 +08:00
|
|
|
int ftpReq(FD_t data, const char * ftpCmd, const char * ftpArg)
|
2001-10-16 01:53:34 +08:00
|
|
|
/*@globals fileSystem @*/
|
2001-06-06 03:26:22 +08:00
|
|
|
/*@modifies data, fileSystem @*/;
|
2001-09-25 05:53:14 +08:00
|
|
|
|
|
|
|
/** \ingroup rpmio
|
|
|
|
*/
|
2001-06-06 03:26:22 +08:00
|
|
|
int ftpCmd(const char * cmd, const char * url, const char * arg2)
|
2001-10-16 01:53:34 +08:00
|
|
|
/*@globals fileSystem @*/
|
2001-06-06 03:26:22 +08:00
|
|
|
/*@modifies fileSystem @*/;
|
2000-06-10 05:24:37 +08:00
|
|
|
|
2001-09-25 05:53:14 +08:00
|
|
|
/** \ingroup rpmio
|
|
|
|
*/
|
2001-06-06 03:26:22 +08:00
|
|
|
int ufdClose( /*@only@*/ void * cookie)
|
2001-10-16 01:53:34 +08:00
|
|
|
/*@globals fileSystem @*/
|
2001-10-14 03:35:58 +08:00
|
|
|
/*@modifies cookie, fileSystem @*/;
|
2000-06-10 05:24:37 +08:00
|
|
|
|
2000-08-28 09:08:57 +08:00
|
|
|
/** \ingroup rpmio
|
|
|
|
*/
|
2001-05-04 05:00:18 +08:00
|
|
|
/*@unused@*/ static inline
|
2001-06-04 21:55:58 +08:00
|
|
|
/*@null@*/ const FDIO_t fdGetIo(FD_t fd)
|
|
|
|
/*@*/
|
|
|
|
{
|
2000-06-10 02:57:23 +08:00
|
|
|
FDSANE(fd);
|
|
|
|
return fd->fps[fd->nfps].io;
|
|
|
|
}
|
|
|
|
|
2000-08-28 09:08:57 +08:00
|
|
|
/** \ingroup rpmio
|
|
|
|
*/
|
2001-09-21 23:07:11 +08:00
|
|
|
/*@-nullstate@*/ /* FIX: io may be NULL */
|
2001-05-04 05:00:18 +08:00
|
|
|
/*@unused@*/ static inline
|
2001-06-04 21:55:58 +08:00
|
|
|
void fdSetIo(FD_t fd, /*@kept@*/ /*@null@*/ FDIO_t io)
|
|
|
|
/*@modifies fd @*/
|
|
|
|
{
|
2000-06-10 02:57:23 +08:00
|
|
|
FDSANE(fd);
|
2001-06-06 03:26:22 +08:00
|
|
|
/*@-assignexpose@*/
|
2000-06-10 02:57:23 +08:00
|
|
|
fd->fps[fd->nfps].io = io;
|
2001-06-06 03:26:22 +08:00
|
|
|
/*@=assignexpose@*/
|
2000-06-10 02:57:23 +08:00
|
|
|
}
|
2001-09-21 23:07:11 +08:00
|
|
|
/*@=nullstate@*/
|
2000-06-10 02:57:23 +08:00
|
|
|
|
2000-08-28 09:08:57 +08:00
|
|
|
/** \ingroup rpmio
|
|
|
|
*/
|
2001-05-04 05:00:18 +08:00
|
|
|
/*@unused@*/ static inline
|
2001-09-25 05:53:14 +08:00
|
|
|
/*@exposed@*/ /*@dependent@*/ /*@null@*/ FILE * fdGetFILE(FD_t fd)
|
2001-06-04 21:55:58 +08:00
|
|
|
/*@*/
|
|
|
|
{
|
2000-06-10 02:57:23 +08:00
|
|
|
FDSANE(fd);
|
2001-09-25 05:53:14 +08:00
|
|
|
/*@+voidabstract@*/
|
2000-06-10 02:57:23 +08:00
|
|
|
return ((FILE *)fd->fps[fd->nfps].fp);
|
2001-09-25 05:53:14 +08:00
|
|
|
/*@=voidabstract@*/
|
2000-06-10 02:57:23 +08:00
|
|
|
}
|
|
|
|
|
2000-08-28 09:08:57 +08:00
|
|
|
/** \ingroup rpmio
|
|
|
|
*/
|
2001-05-04 05:00:18 +08:00
|
|
|
/*@unused@*/ static inline
|
2001-09-25 05:53:14 +08:00
|
|
|
/*@exposed@*/ /*@dependent@*/ /*@null@*/ void * fdGetFp(FD_t fd)
|
2001-06-04 21:55:58 +08:00
|
|
|
/*@*/
|
|
|
|
{
|
2000-06-10 02:57:23 +08:00
|
|
|
FDSANE(fd);
|
|
|
|
return fd->fps[fd->nfps].fp;
|
|
|
|
}
|
|
|
|
|
2000-08-28 09:08:57 +08:00
|
|
|
/** \ingroup rpmio
|
|
|
|
*/
|
2001-09-21 23:07:11 +08:00
|
|
|
/*@-nullstate@*/ /* FIX: fp may be NULL */
|
2001-05-04 05:00:18 +08:00
|
|
|
/*@unused@*/ static inline
|
2001-06-04 21:55:58 +08:00
|
|
|
void fdSetFp(FD_t fd, /*@kept@*/ /*@null@*/ void * fp)
|
|
|
|
/*@modifies fd @*/
|
|
|
|
{
|
2000-06-10 02:57:23 +08:00
|
|
|
FDSANE(fd);
|
2001-06-06 03:26:22 +08:00
|
|
|
/*@-assignexpose@*/
|
2000-06-10 02:57:23 +08:00
|
|
|
fd->fps[fd->nfps].fp = fp;
|
2001-06-06 03:26:22 +08:00
|
|
|
/*@=assignexpose@*/
|
2000-06-10 02:57:23 +08:00
|
|
|
}
|
2001-09-21 23:07:11 +08:00
|
|
|
/*@=nullstate@*/
|
2000-06-10 02:57:23 +08:00
|
|
|
|
2000-08-28 09:08:57 +08:00
|
|
|
/** \ingroup rpmio
|
|
|
|
*/
|
2001-05-04 05:00:18 +08:00
|
|
|
/*@unused@*/ static inline
|
2001-06-04 21:55:58 +08:00
|
|
|
int fdGetFdno(FD_t fd)
|
|
|
|
/*@*/
|
|
|
|
{
|
2000-06-10 02:57:23 +08:00
|
|
|
FDSANE(fd);
|
|
|
|
return fd->fps[fd->nfps].fdno;
|
|
|
|
}
|
|
|
|
|
2000-08-28 09:08:57 +08:00
|
|
|
/** \ingroup rpmio
|
|
|
|
*/
|
2001-05-04 05:00:18 +08:00
|
|
|
/*@unused@*/ static inline
|
2001-06-04 21:55:58 +08:00
|
|
|
void fdSetFdno(FD_t fd, int fdno)
|
|
|
|
/*@modifies fd @*/
|
|
|
|
{
|
2000-06-10 02:57:23 +08:00
|
|
|
FDSANE(fd);
|
|
|
|
fd->fps[fd->nfps].fdno = fdno;
|
|
|
|
}
|
|
|
|
|
2000-08-28 09:08:57 +08:00
|
|
|
/** \ingroup rpmio
|
|
|
|
*/
|
2001-05-04 05:00:18 +08:00
|
|
|
/*@unused@*/ static inline
|
|
|
|
void fdSetContentLength(FD_t fd, ssize_t contentLength)
|
2001-06-04 21:55:58 +08:00
|
|
|
/*@modifies fd @*/
|
2000-06-10 02:57:23 +08:00
|
|
|
{
|
|
|
|
FDSANE(fd);
|
|
|
|
fd->contentLength = fd->bytesRemain = contentLength;
|
|
|
|
}
|
|
|
|
|
2000-08-28 09:08:57 +08:00
|
|
|
/** \ingroup rpmio
|
|
|
|
*/
|
2001-05-04 05:00:18 +08:00
|
|
|
/*@unused@*/ static inline
|
|
|
|
void fdPush(FD_t fd, FDIO_t io, void * fp, int fdno)
|
2001-06-04 21:55:58 +08:00
|
|
|
/*@modifies fd @*/
|
2000-07-08 03:46:05 +08:00
|
|
|
{
|
2000-06-10 02:57:23 +08:00
|
|
|
FDSANE(fd);
|
|
|
|
if (fd->nfps >= (sizeof(fd->fps)/sizeof(fd->fps[0]) - 1))
|
|
|
|
return;
|
|
|
|
fd->nfps++;
|
|
|
|
fdSetIo(fd, io);
|
|
|
|
fdSetFp(fd, fp);
|
|
|
|
fdSetFdno(fd, fdno);
|
|
|
|
}
|
|
|
|
|
2000-08-28 09:08:57 +08:00
|
|
|
/** \ingroup rpmio
|
|
|
|
*/
|
2001-06-04 21:55:58 +08:00
|
|
|
/*@unused@*/ static inline void fdPop(FD_t fd)
|
|
|
|
/*@modifies fd @*/
|
|
|
|
{
|
2000-06-10 02:57:23 +08:00
|
|
|
FDSANE(fd);
|
|
|
|
if (fd->nfps < 0) return;
|
|
|
|
fdSetIo(fd, NULL);
|
|
|
|
fdSetFp(fd, NULL);
|
|
|
|
fdSetFdno(fd, -1);
|
|
|
|
fd->nfps--;
|
|
|
|
}
|
|
|
|
|
2000-08-28 09:08:57 +08:00
|
|
|
/** \ingroup rpmio
|
|
|
|
*/
|
2001-05-04 05:00:18 +08:00
|
|
|
/*@unused@*/ static inline void fdstat_enter(/*@null@*/ FD_t fd, int opx)
|
2001-06-04 21:55:58 +08:00
|
|
|
/*@modifies fd @*/
|
2000-06-10 02:57:23 +08:00
|
|
|
{
|
2001-05-04 05:00:18 +08:00
|
|
|
if (fd == NULL || fd->stats == NULL) return;
|
2000-06-10 02:57:23 +08:00
|
|
|
fd->stats->ops[opx].count++;
|
2001-05-01 06:32:22 +08:00
|
|
|
(void) gettimeofday(&fd->stats->begin, NULL);
|
2000-06-10 02:57:23 +08:00
|
|
|
}
|
|
|
|
|
2000-08-28 09:08:57 +08:00
|
|
|
/** \ingroup rpmio
|
|
|
|
*/
|
2001-05-04 05:00:18 +08:00
|
|
|
/*@unused@*/ static inline
|
2001-06-04 21:55:58 +08:00
|
|
|
time_t tvsub(/*@null@*/ const struct timeval * etv,
|
|
|
|
/*@null@*/ const struct timeval * btv)
|
|
|
|
/*@*/
|
|
|
|
{
|
2000-06-10 02:57:23 +08:00
|
|
|
time_t secs, usecs;
|
2001-06-04 21:55:58 +08:00
|
|
|
if (etv == NULL || btv == NULL) return 0;
|
2000-06-10 02:57:23 +08:00
|
|
|
secs = etv->tv_sec - btv->tv_sec;
|
2001-06-04 21:55:58 +08:00
|
|
|
for (usecs = etv->tv_usec - btv->tv_usec; usecs < 0; usecs += 1000000)
|
2000-06-10 02:57:23 +08:00
|
|
|
secs++;
|
|
|
|
return ((secs * 1000) + (usecs/1000));
|
|
|
|
}
|
|
|
|
|
2000-08-28 09:08:57 +08:00
|
|
|
/** \ingroup rpmio
|
|
|
|
*/
|
2001-05-04 05:00:18 +08:00
|
|
|
/*@unused@*/ static inline
|
|
|
|
void fdstat_exit(/*@null@*/ FD_t fd, int opx, ssize_t rc)
|
2001-06-04 21:55:58 +08:00
|
|
|
/*@modifies fd @*/
|
2000-06-10 02:57:23 +08:00
|
|
|
{
|
|
|
|
struct timeval end;
|
2001-05-04 05:00:18 +08:00
|
|
|
if (fd == NULL) return;
|
2000-06-10 02:57:23 +08:00
|
|
|
if (rc == -1) fd->syserrno = errno;
|
|
|
|
if (fd->stats == NULL) return;
|
2001-05-01 06:32:22 +08:00
|
|
|
(void) gettimeofday(&end, NULL);
|
2000-06-10 02:57:23 +08:00
|
|
|
if (rc >= 0) {
|
|
|
|
switch(opx) {
|
|
|
|
case FDSTAT_SEEK:
|
|
|
|
fd->stats->ops[opx].bytes = rc;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
fd->stats->ops[opx].bytes += rc;
|
|
|
|
if (fd->bytesRemain > 0) fd->bytesRemain -= rc;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
fd->stats->ops[opx].msecs += tvsub(&end, &fd->stats->begin);
|
|
|
|
fd->stats->begin = end; /* structure assignment */
|
|
|
|
}
|
|
|
|
|
2000-08-28 09:08:57 +08:00
|
|
|
/** \ingroup rpmio
|
|
|
|
*/
|
2001-05-04 05:00:18 +08:00
|
|
|
/*@unused@*/ static inline
|
2001-06-04 21:55:58 +08:00
|
|
|
void fdstat_print(/*@null@*/ FD_t fd, const char * msg, FILE * fp)
|
2001-10-16 01:53:34 +08:00
|
|
|
/*@globals fileSystem @*/
|
2001-06-06 03:26:22 +08:00
|
|
|
/*@modifies *fp, fileSystem @*/
|
2001-06-04 21:55:58 +08:00
|
|
|
{
|
2000-06-10 02:57:23 +08:00
|
|
|
int opx;
|
2001-05-04 05:00:18 +08:00
|
|
|
if (fd == NULL || fd->stats == NULL) return;
|
2000-06-10 02:57:23 +08:00
|
|
|
for (opx = 0; opx < 4; opx++) {
|
|
|
|
OPSTAT_t *ops = &fd->stats->ops[opx];
|
|
|
|
if (ops->count <= 0) continue;
|
|
|
|
switch (opx) {
|
|
|
|
case FDSTAT_READ:
|
|
|
|
if (msg) fprintf(fp, "%s:", msg);
|
|
|
|
fprintf(fp, "%8d reads, %8ld total bytes in %d.%03d secs\n",
|
|
|
|
ops->count, (long)ops->bytes,
|
|
|
|
(int)(ops->msecs/1000), (int)(ops->msecs%1000));
|
2001-10-14 06:01:38 +08:00
|
|
|
/*@switchbreak@*/ break;
|
2000-06-10 02:57:23 +08:00
|
|
|
case FDSTAT_WRITE:
|
|
|
|
if (msg) fprintf(fp, "%s:", msg);
|
|
|
|
fprintf(fp, "%8d writes, %8ld total bytes in %d.%03d secs\n",
|
|
|
|
ops->count, (long)ops->bytes,
|
|
|
|
(int)(ops->msecs/1000), (int)(ops->msecs%1000));
|
2001-10-14 06:01:38 +08:00
|
|
|
/*@switchbreak@*/ break;
|
2000-06-10 02:57:23 +08:00
|
|
|
case FDSTAT_SEEK:
|
2001-10-14 06:01:38 +08:00
|
|
|
/*@switchbreak@*/ break;
|
2000-06-10 02:57:23 +08:00
|
|
|
case FDSTAT_CLOSE:
|
2001-10-14 06:01:38 +08:00
|
|
|
/*@switchbreak@*/ break;
|
2000-06-10 02:57:23 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-08-28 09:08:57 +08:00
|
|
|
/** \ingroup rpmio
|
|
|
|
*/
|
2001-05-04 05:00:18 +08:00
|
|
|
/*@unused@*/ static inline
|
2001-06-04 21:55:58 +08:00
|
|
|
void fdSetSyserrno(FD_t fd, int syserrno, /*@kept@*/ const void * errcookie)
|
|
|
|
/*@modifies fd @*/
|
|
|
|
{
|
2000-06-10 02:57:23 +08:00
|
|
|
FDSANE(fd);
|
|
|
|
fd->syserrno = syserrno;
|
2001-06-06 03:26:22 +08:00
|
|
|
/*@-assignexpose@*/
|
2000-06-10 02:57:23 +08:00
|
|
|
fd->errcookie = errcookie;
|
2001-06-06 03:26:22 +08:00
|
|
|
/*@=assignexpose@*/
|
2000-06-10 02:57:23 +08:00
|
|
|
}
|
|
|
|
|
2000-08-28 09:08:57 +08:00
|
|
|
/** \ingroup rpmio
|
|
|
|
*/
|
2001-05-04 05:00:18 +08:00
|
|
|
/*@unused@*/ static inline
|
2001-06-04 21:55:58 +08:00
|
|
|
int fdGetRdTimeoutSecs(FD_t fd)
|
|
|
|
/*@*/
|
|
|
|
{
|
2000-06-10 02:57:23 +08:00
|
|
|
FDSANE(fd);
|
|
|
|
return fd->rd_timeoutsecs;
|
|
|
|
}
|
|
|
|
|
2000-08-28 09:08:57 +08:00
|
|
|
/** \ingroup rpmio
|
|
|
|
*/
|
2001-05-04 05:00:18 +08:00
|
|
|
/*@unused@*/ static inline
|
2001-06-04 21:55:58 +08:00
|
|
|
long int fdGetCpioPos(FD_t fd)
|
|
|
|
/*@*/
|
|
|
|
{
|
2000-06-10 02:57:23 +08:00
|
|
|
FDSANE(fd);
|
|
|
|
return fd->fd_cpioPos;
|
|
|
|
}
|
|
|
|
|
2000-08-28 09:08:57 +08:00
|
|
|
/** \ingroup rpmio
|
|
|
|
*/
|
2001-05-04 05:00:18 +08:00
|
|
|
/*@unused@*/ static inline
|
2001-06-04 21:55:58 +08:00
|
|
|
void fdSetCpioPos(FD_t fd, long int cpioPos)
|
|
|
|
/*@modifies fd @*/
|
|
|
|
{
|
2000-06-10 02:57:23 +08:00
|
|
|
FDSANE(fd);
|
|
|
|
fd->fd_cpioPos = cpioPos;
|
|
|
|
}
|
|
|
|
|
2000-08-28 09:08:57 +08:00
|
|
|
/** \ingroup rpmio
|
|
|
|
*/
|
2001-05-04 05:00:18 +08:00
|
|
|
/*@mayexit@*/ /*@unused@*/ static inline
|
2001-06-04 21:55:58 +08:00
|
|
|
FD_t c2f(/*@null@*/ void * cookie)
|
|
|
|
/*@*/
|
|
|
|
{
|
2001-06-06 03:26:22 +08:00
|
|
|
/*@-castexpose@*/
|
2000-06-10 02:57:23 +08:00
|
|
|
FD_t fd = (FD_t) cookie;
|
2001-06-06 03:26:22 +08:00
|
|
|
/*@=castexpose@*/
|
2000-06-10 02:57:23 +08:00
|
|
|
FDSANE(fd);
|
2001-06-06 03:26:22 +08:00
|
|
|
/*@-refcounttrans -retalias@*/ return fd; /*@=refcounttrans =retalias@*/
|
2000-06-10 02:57:23 +08:00
|
|
|
}
|
|
|
|
|
2000-10-24 21:46:51 +08:00
|
|
|
/** \ingroup rpmio
|
|
|
|
*/
|
2001-05-04 05:00:18 +08:00
|
|
|
/*@unused@*/ static inline
|
2001-06-04 21:55:58 +08:00
|
|
|
void fdInitMD5(FD_t fd, int flags)
|
|
|
|
/*@modifies fd @*/
|
|
|
|
{
|
2001-09-26 22:45:50 +08:00
|
|
|
#ifdef DYING
|
2001-07-22 03:44:22 +08:00
|
|
|
if (flags) flags = RPMDIGEST_REVERSE;
|
2001-09-26 22:45:50 +08:00
|
|
|
#endif
|
2000-12-03 05:53:44 +08:00
|
|
|
flags |= RPMDIGEST_MD5;
|
|
|
|
fd->digest = rpmDigestInit(flags);
|
2000-11-01 00:18:34 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/** \ingroup rpmio
|
|
|
|
*/
|
2001-05-04 05:00:18 +08:00
|
|
|
/*@unused@*/ static inline
|
2001-07-22 03:44:22 +08:00
|
|
|
void fdInitSHA1(FD_t fd, int flags)
|
2001-06-04 21:55:58 +08:00
|
|
|
/*@modifies fd @*/
|
|
|
|
{
|
2001-09-26 22:45:50 +08:00
|
|
|
#ifdef DYING
|
2001-07-22 03:44:22 +08:00
|
|
|
if (flags) flags = RPMDIGEST_REVERSE;
|
2001-09-26 22:45:50 +08:00
|
|
|
#endif
|
2001-07-22 03:44:22 +08:00
|
|
|
flags |= RPMDIGEST_SHA1;
|
|
|
|
fd->digest = rpmDigestInit(flags);
|
2000-10-24 21:46:51 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/** \ingroup rpmio
|
|
|
|
*/
|
2001-05-04 05:00:18 +08:00
|
|
|
/*@unused@*/ static inline
|
2001-06-04 21:55:58 +08:00
|
|
|
void fdFiniMD5(FD_t fd,
|
|
|
|
/*@null@*/ /*@out@*/ void ** datap,
|
|
|
|
/*@null@*/ /*@out@*/ size_t * lenp,
|
|
|
|
int asAscii)
|
|
|
|
/*@modifies fd, *datap, *lenp @*/
|
|
|
|
{
|
2000-11-01 00:18:34 +08:00
|
|
|
if (fd->digest == NULL) {
|
2001-01-10 05:46:11 +08:00
|
|
|
if (datap) *datap = NULL;
|
|
|
|
if (lenp) *lenp = 0;
|
2000-11-01 00:18:34 +08:00
|
|
|
return;
|
|
|
|
}
|
2001-04-30 06:43:01 +08:00
|
|
|
/*@-mayaliasunique@*/
|
2000-11-01 00:18:34 +08:00
|
|
|
rpmDigestFinal(fd->digest, datap, lenp, asAscii);
|
2001-04-30 06:43:01 +08:00
|
|
|
/*@=mayaliasunique@*/
|
2000-11-01 00:18:34 +08:00
|
|
|
fd->digest = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/** \ingroup rpmio
|
|
|
|
*/
|
2001-05-04 05:00:18 +08:00
|
|
|
/*@unused@*/ static inline
|
2001-06-04 21:55:58 +08:00
|
|
|
void fdFiniSHA1(FD_t fd,
|
|
|
|
/*@null@*/ /*@out@*/ void ** datap,
|
|
|
|
/*@null@*/ /*@out@*/ size_t * lenp,
|
|
|
|
int asAscii)
|
|
|
|
/*@modifies fd, *datap, *lenp @*/
|
|
|
|
{
|
2000-11-01 00:18:34 +08:00
|
|
|
if (fd->digest == NULL) {
|
2001-01-10 05:46:11 +08:00
|
|
|
if (datap) *datap = NULL;
|
|
|
|
if (lenp) *lenp = 0;
|
2000-10-24 21:46:51 +08:00
|
|
|
return;
|
|
|
|
}
|
2001-04-30 06:43:01 +08:00
|
|
|
/*@-mayaliasunique@*/
|
2000-11-01 00:18:34 +08:00
|
|
|
rpmDigestFinal(fd->digest, datap, lenp, asAscii);
|
2001-04-30 06:43:01 +08:00
|
|
|
/*@=mayaliasunique@*/
|
2000-11-01 00:18:34 +08:00
|
|
|
fd->digest = NULL;
|
2000-10-24 21:46:51 +08:00
|
|
|
}
|
|
|
|
|
2000-08-23 21:49:07 +08:00
|
|
|
/*@-shadow@*/
|
2000-08-28 09:08:57 +08:00
|
|
|
/** \ingroup rpmio
|
|
|
|
*/
|
2001-05-04 05:00:18 +08:00
|
|
|
/*@unused@*/ static inline
|
2001-06-04 21:55:58 +08:00
|
|
|
int fdFileno(/*@null@*/ void * cookie)
|
|
|
|
/*@*/
|
|
|
|
{
|
2000-06-10 02:57:23 +08:00
|
|
|
FD_t fd;
|
|
|
|
if (cookie == NULL) return -2;
|
|
|
|
fd = c2f(cookie);
|
|
|
|
return fd->fps[0].fdno;
|
|
|
|
}
|
2000-08-23 21:49:07 +08:00
|
|
|
/*@=shadow@*/
|
2000-06-10 02:57:23 +08:00
|
|
|
|
2000-06-10 05:24:37 +08:00
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2000-06-10 02:57:23 +08:00
|
|
|
#endif /* H_RPMIO_INTERNAL */
|