IsoStream version 3 with cmp_ino(),
new API call iso_stream_cmp_ino() for proper comparison of filtered streams
This commit is contained in:
parent
5b073a2f29
commit
8c4682ae92
@ -594,8 +594,13 @@ IsoStream *extf_get_input_stream(IsoStream *stream, int flag)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static
|
||||||
|
int extf_cmp_ino(IsoStream *s1, IsoStream *s2);
|
||||||
|
/* Function is defined after definition of extf_stream_class */
|
||||||
|
|
||||||
|
|
||||||
IsoStreamIface extf_stream_class = {
|
IsoStreamIface extf_stream_class = {
|
||||||
2,
|
3,
|
||||||
"extf",
|
"extf",
|
||||||
extf_stream_open,
|
extf_stream_open,
|
||||||
extf_stream_close,
|
extf_stream_close,
|
||||||
@ -605,10 +610,28 @@ IsoStreamIface extf_stream_class = {
|
|||||||
extf_stream_get_id,
|
extf_stream_get_id,
|
||||||
extf_stream_free,
|
extf_stream_free,
|
||||||
extf_update_size,
|
extf_update_size,
|
||||||
extf_get_input_stream
|
extf_get_input_stream,
|
||||||
|
extf_cmp_ino
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
static
|
||||||
|
int extf_cmp_ino(IsoStream *s1, IsoStream *s2)
|
||||||
|
{
|
||||||
|
ExternalFilterStreamData *data1, *data2;
|
||||||
|
|
||||||
|
if (s1->class != &extf_stream_class || s2->class != &extf_stream_class)
|
||||||
|
return iso_stream_cmp_ino(s1, s2, 1);
|
||||||
|
data1 = (ExternalFilterStreamData*) s1->data;
|
||||||
|
data2 = (ExternalFilterStreamData*) s2->data;
|
||||||
|
if (data1->cmd != data2->cmd)
|
||||||
|
return (data1->cmd < data2->cmd ? -1 : 1);
|
||||||
|
return iso_stream_cmp_ino(data1->orig, data2->orig, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* ------------------------------------------------------------------------- */
|
||||||
|
|
||||||
static
|
static
|
||||||
void extf_filter_free(FilterContext *filter)
|
void extf_filter_free(FilterContext *filter)
|
||||||
{
|
{
|
||||||
|
@ -521,8 +521,12 @@ IsoStream *gzip_get_input_stream(IsoStream *stream, int flag)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static
|
||||||
|
int gzip_cmp_ino(IsoStream *s1, IsoStream *s2);
|
||||||
|
|
||||||
|
|
||||||
IsoStreamIface gzip_stream_compress_class = {
|
IsoStreamIface gzip_stream_compress_class = {
|
||||||
2,
|
3,
|
||||||
"gzip",
|
"gzip",
|
||||||
gzip_stream_open,
|
gzip_stream_open,
|
||||||
gzip_stream_close,
|
gzip_stream_close,
|
||||||
@ -532,12 +536,13 @@ IsoStreamIface gzip_stream_compress_class = {
|
|||||||
gzip_stream_get_id,
|
gzip_stream_get_id,
|
||||||
gzip_stream_free,
|
gzip_stream_free,
|
||||||
gzip_update_size,
|
gzip_update_size,
|
||||||
gzip_get_input_stream
|
gzip_get_input_stream,
|
||||||
|
gzip_cmp_ino
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
IsoStreamIface gzip_stream_uncompress_class = {
|
IsoStreamIface gzip_stream_uncompress_class = {
|
||||||
2,
|
3,
|
||||||
"pizg",
|
"pizg",
|
||||||
gzip_stream_open,
|
gzip_stream_open,
|
||||||
gzip_stream_close,
|
gzip_stream_close,
|
||||||
@ -547,9 +552,24 @@ IsoStreamIface gzip_stream_uncompress_class = {
|
|||||||
gzip_stream_get_id,
|
gzip_stream_get_id,
|
||||||
gzip_stream_free,
|
gzip_stream_free,
|
||||||
gzip_update_size,
|
gzip_update_size,
|
||||||
gzip_get_input_stream
|
gzip_get_input_stream,
|
||||||
|
gzip_cmp_ino
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
static
|
||||||
|
int gzip_cmp_ino(IsoStream *s1, IsoStream *s2)
|
||||||
|
{
|
||||||
|
if (s1->class != s2->class || (s1->class != &gzip_stream_compress_class &&
|
||||||
|
s2->class != &gzip_stream_compress_class))
|
||||||
|
return iso_stream_cmp_ino(s1, s2, 1);
|
||||||
|
return iso_stream_cmp_ino(iso_stream_get_input_stream(s1, 0),
|
||||||
|
iso_stream_get_input_stream(s2, 0), 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* ------------------------------------------------------------------------- */
|
||||||
|
|
||||||
|
|
||||||
static
|
static
|
||||||
void gzip_filter_free(FilterContext *filter)
|
void gzip_filter_free(FilterContext *filter)
|
||||||
|
@ -775,8 +775,12 @@ IsoStream *ziso_get_input_stream(IsoStream *stream, int flag)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static
|
||||||
|
int ziso_cmp_ino(IsoStream *s1, IsoStream *s2);
|
||||||
|
|
||||||
|
|
||||||
IsoStreamIface ziso_stream_compress_class = {
|
IsoStreamIface ziso_stream_compress_class = {
|
||||||
2,
|
3,
|
||||||
"ziso",
|
"ziso",
|
||||||
ziso_stream_open,
|
ziso_stream_open,
|
||||||
ziso_stream_close,
|
ziso_stream_close,
|
||||||
@ -786,12 +790,13 @@ IsoStreamIface ziso_stream_compress_class = {
|
|||||||
ziso_stream_get_id,
|
ziso_stream_get_id,
|
||||||
ziso_stream_free,
|
ziso_stream_free,
|
||||||
ziso_update_size,
|
ziso_update_size,
|
||||||
ziso_get_input_stream
|
ziso_get_input_stream,
|
||||||
|
ziso_cmp_ino
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
IsoStreamIface ziso_stream_uncompress_class = {
|
IsoStreamIface ziso_stream_uncompress_class = {
|
||||||
2,
|
3,
|
||||||
"osiz",
|
"osiz",
|
||||||
ziso_stream_open,
|
ziso_stream_open,
|
||||||
ziso_stream_close,
|
ziso_stream_close,
|
||||||
@ -801,10 +806,25 @@ IsoStreamIface ziso_stream_uncompress_class = {
|
|||||||
ziso_stream_get_id,
|
ziso_stream_get_id,
|
||||||
ziso_stream_free,
|
ziso_stream_free,
|
||||||
ziso_update_size,
|
ziso_update_size,
|
||||||
ziso_get_input_stream
|
ziso_get_input_stream,
|
||||||
|
ziso_cmp_ino
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
static
|
||||||
|
int ziso_cmp_ino(IsoStream *s1, IsoStream *s2)
|
||||||
|
{
|
||||||
|
if (s1->class != s2->class || (s1->class != &ziso_stream_compress_class &&
|
||||||
|
s2->class != &ziso_stream_uncompress_class))
|
||||||
|
iso_stream_cmp_ino(s1, s2, 1);
|
||||||
|
return iso_stream_cmp_ino(iso_stream_get_input_stream(s1, 0),
|
||||||
|
iso_stream_get_input_stream(s2, 0), 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* ------------------------------------------------------------------------- */
|
||||||
|
|
||||||
|
|
||||||
static
|
static
|
||||||
void ziso_filter_free(FilterContext *filter)
|
void ziso_filter_free(FilterContext *filter)
|
||||||
{
|
{
|
||||||
|
@ -759,8 +759,11 @@ typedef struct IsoStream_Iface IsoStreamIface;
|
|||||||
extern ino_t serial_id;
|
extern ino_t serial_id;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Interface definition for IsoStream methods.
|
* Interface definition for IsoStream methods. It is public to allow
|
||||||
*
|
* implementation of own stream types.
|
||||||
|
* The methods defined here typically make use of stream.data which points
|
||||||
|
* to the individual state data of stream instances.
|
||||||
|
*
|
||||||
* @since 0.6.4
|
* @since 0.6.4
|
||||||
*/
|
*/
|
||||||
struct IsoStream_Iface
|
struct IsoStream_Iface
|
||||||
@ -773,6 +776,8 @@ struct IsoStream_Iface
|
|||||||
* update_size() added.
|
* update_size() added.
|
||||||
* Version 2 (since 0.6.18)
|
* Version 2 (since 0.6.18)
|
||||||
* get_input_stream() added. A filter stream must have version 2.
|
* get_input_stream() added. A filter stream must have version 2.
|
||||||
|
* Version 3 (since 0.6.20)
|
||||||
|
* compare() added. A filter stream should have version 3.
|
||||||
*/
|
*/
|
||||||
int version;
|
int version;
|
||||||
|
|
||||||
@ -856,7 +861,6 @@ struct IsoStream_Iface
|
|||||||
void (*free)(IsoStream *stream);
|
void (*free)(IsoStream *stream);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Present if .version is 1 or higher:
|
|
||||||
* Updates the size of the IsoStream with the current size of the
|
* Updates the size of the IsoStream with the current size of the
|
||||||
* underlying source. After calling this, get_size() will return
|
* underlying source. After calling this, get_size() will return
|
||||||
* the new size. This should never be called after
|
* the new size. This should never be called after
|
||||||
@ -869,24 +873,61 @@ struct IsoStream_Iface
|
|||||||
* 1 if ok, < 0 on error (has to be a valid libisofs error code)
|
* 1 if ok, < 0 on error (has to be a valid libisofs error code)
|
||||||
*
|
*
|
||||||
* @since 0.6.8
|
* @since 0.6.8
|
||||||
|
* Present if .version is 1 or higher.
|
||||||
*/
|
*/
|
||||||
int (*update_size)(IsoStream *stream);
|
int (*update_size)(IsoStream *stream);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Present if .version is 2 or higher:
|
|
||||||
* Obtains the eventual input stream of a filter stream.
|
* Obtains the eventual input stream of a filter stream.
|
||||||
|
*
|
||||||
* @param stream
|
* @param stream
|
||||||
* The eventual filter stream to be inquired.
|
* The eventual filter stream to be inquired.
|
||||||
* @param flag
|
* @param flag
|
||||||
* Bitfield for control purposes. Submit 0 for now.
|
* Bitfield for control purposes. Submit 0 for now.
|
||||||
* @return
|
* @return
|
||||||
* The input stream, if one exists. Elsewise NULL.
|
* The input stream, if one exists. Elsewise NULL.
|
||||||
* No extra reference to the stream is taken by this call.
|
* No extra reference to the stream is taken by this call.
|
||||||
*
|
*
|
||||||
* @since 0.6.18
|
* @since 0.6.18
|
||||||
|
* Present if .version is 2 or higher.
|
||||||
*/
|
*/
|
||||||
IsoStream *(*get_input_stream)(IsoStream *stream, int flag);
|
IsoStream *(*get_input_stream)(IsoStream *stream, int flag);
|
||||||
|
|
||||||
|
/* ts A90511 */
|
||||||
|
/**
|
||||||
|
* Compare two streams whether they are based on the same input and will
|
||||||
|
* produce the same output. If in any doubt, then this comparison should
|
||||||
|
* indicate no match. A match might allow hardlinking of IsoFile objects.
|
||||||
|
* This function has to establish an equivalence and order relation:
|
||||||
|
* A = A, if A = B then B = A, if A = B and B = C then A = C,
|
||||||
|
* if A < B then not B < A, if A < B and B < C then A < C
|
||||||
|
*
|
||||||
|
* A function s1.(*cmp_ino)() must only accept stream s2 if function
|
||||||
|
* s2.(*cmp_ino)() would accept s1. Best is to accept only the own stream
|
||||||
|
* type or to have the same function for a family of similar stream types.
|
||||||
|
*
|
||||||
|
* If the function cannot accept one of the given stream types, then
|
||||||
|
* the decision must be delegated to
|
||||||
|
* iso_stream_cmp_ino(s1, s2, 1);
|
||||||
|
* This is also appropriate if one has reason to implement stream.cmp_ino()
|
||||||
|
* without special comparison algorithm.
|
||||||
|
* With filter streams the decision whether the underlying chains of
|
||||||
|
* streams match should be delegated to
|
||||||
|
* iso_stream_cmp_ino(iso_stream_get_input_stream(s1, 0),
|
||||||
|
* iso_stream_get_input_stream(s2, 0), 0);
|
||||||
|
*
|
||||||
|
* @param s1
|
||||||
|
* The first stream to compare. Expect foreign stream types.
|
||||||
|
* @param s2
|
||||||
|
* The second stream to compare. Expect foreign stream types.
|
||||||
|
* @return
|
||||||
|
* -1 if s1 is smaller s2 , 0 if s1 matches s2 , 1 if s1 is larger s2
|
||||||
|
*
|
||||||
|
* @since 0.6.20
|
||||||
|
* Present if .version is 3 or higher.
|
||||||
|
*/
|
||||||
|
int (*cmp_ino)(IsoStream *s1, IsoStream *s2);
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -4162,6 +4203,26 @@ void iso_stream_get_id(IsoStream *stream, unsigned int *fs_id, dev_t *dev_id,
|
|||||||
*/
|
*/
|
||||||
char *iso_stream_get_source_path(IsoStream *stream, int flag);
|
char *iso_stream_get_source_path(IsoStream *stream, int flag);
|
||||||
|
|
||||||
|
/* ts A90502 */
|
||||||
|
/**
|
||||||
|
* Compare two streams whether they are based on the same input and will
|
||||||
|
* produce the same output. If in any doubt, then this comparison will
|
||||||
|
* indicate no match.
|
||||||
|
*
|
||||||
|
* @param s1
|
||||||
|
* The first stream to compare.
|
||||||
|
* @param s2
|
||||||
|
* The second stream to compare.
|
||||||
|
* @return
|
||||||
|
* -1 if s1 is smaller s2 , 0 if s1 matches s2 , 1 if s1 is larger s2
|
||||||
|
* @param flag
|
||||||
|
* bit0= do not use s1->class->compare() even if available
|
||||||
|
* (e.g. because iso_stream_cmp_ino(0 is called as fallback
|
||||||
|
* from said stream->class->compare())
|
||||||
|
*
|
||||||
|
* @since 0.6.20
|
||||||
|
*/
|
||||||
|
int iso_stream_cmp_ino(IsoStream *s1, IsoStream *s2, int flag);
|
||||||
|
|
||||||
/* --------------------------------- AAIP --------------------------------- */
|
/* --------------------------------- AAIP --------------------------------- */
|
||||||
|
|
||||||
|
@ -728,10 +728,11 @@ int iso_stream_set_image_ino(IsoStream *stream, ino_t ino, int flag)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ts A90502 */
|
/* ts A90511 */
|
||||||
/* The former core of iso_file_src_cmp() */
|
/* API */
|
||||||
int iso_stream_cmp_ino(IsoStream *s1, IsoStream *s2, int flag)
|
int iso_stream_cmp_ino(IsoStream *s1, IsoStream *s2, int flag)
|
||||||
{
|
{
|
||||||
|
int ret;
|
||||||
unsigned int fs_id1, fs_id2;
|
unsigned int fs_id1, fs_id2;
|
||||||
dev_t dev_id1, dev_id2;
|
dev_t dev_id1, dev_id2;
|
||||||
ino_t ino_id1, ino_id2;
|
ino_t ino_id1, ino_id2;
|
||||||
@ -741,9 +742,19 @@ int iso_stream_cmp_ino(IsoStream *s1, IsoStream *s2, int flag)
|
|||||||
static int report_counter = 0;
|
static int report_counter = 0;
|
||||||
static int debug = 1;
|
static int debug = 1;
|
||||||
|
|
||||||
if (s1 == s2) {
|
if (s1 == s2)
|
||||||
return 0;
|
return 0;
|
||||||
|
if (s1 == NULL)
|
||||||
|
return -1;
|
||||||
|
if (s2 == NULL)
|
||||||
|
return 1;
|
||||||
|
|
||||||
|
if (s1->class->version >= 3 && !(flag & 1)) {
|
||||||
|
/* Filters may have smarter methods to compare themselves with others */
|
||||||
|
ret = s1->class->cmp_ino(s1, s2);
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
iso_stream_get_id(s1, &fs_id1, &dev_id1, &ino_id1);
|
iso_stream_get_id(s1, &fs_id1, &dev_id1, &ino_id1);
|
||||||
iso_stream_get_id(s2, &fs_id2, &dev_id2, &ino_id2);
|
iso_stream_get_id(s2, &fs_id2, &dev_id2, &ino_id2);
|
||||||
if (fs_id1 < fs_id2) {
|
if (fs_id1 < fs_id2) {
|
||||||
|
@ -82,8 +82,5 @@ int iso_stream_get_src_zf(IsoStream *stream, int *header_size_div4,
|
|||||||
*/
|
*/
|
||||||
int iso_stream_set_image_ino(IsoStream *stream, ino_t ino, int flag);
|
int iso_stream_set_image_ino(IsoStream *stream, ino_t ino, int flag);
|
||||||
|
|
||||||
/* ts A90502 */
|
|
||||||
/* The former core of iso_file_src_cmp() */
|
|
||||||
int iso_stream_cmp_ino(IsoStream *s1, IsoStream *s2, int flag);
|
|
||||||
|
|
||||||
#endif /*STREAM_H_*/
|
#endif /*STREAM_H_*/
|
||||||
|
Loading…
Reference in New Issue
Block a user