Support for identification of source Streams.
We identify uniquelly a given source Stream by a triple of numbers: the filesystem id, the device id inside the filesystem, and the inode id.
This commit is contained in:
parent
8f7222609e
commit
dd83f85d09
@ -24,6 +24,8 @@
|
|||||||
#include <libgen.h>
|
#include <libgen.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
|
#define ISO_LOCAL_FS_ID 1
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* We can share a local filesystem object, as it has no private atts.
|
* We can share a local filesystem object, as it has no private atts.
|
||||||
*/
|
*/
|
||||||
@ -471,6 +473,12 @@ int lfs_get_by_path(IsoFilesystem *fs, const char *path, IsoFileSource **file)
|
|||||||
return iso_file_source_new_lfs(path, file);
|
return iso_file_source_new_lfs(path, file);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static
|
||||||
|
unsigned int lfs_get_id(IsoFilesystem *fs)
|
||||||
|
{
|
||||||
|
return ISO_LOCAL_FS_ID;
|
||||||
|
}
|
||||||
|
|
||||||
static
|
static
|
||||||
void lfs_fs_free(IsoFilesystem *fs)
|
void lfs_fs_free(IsoFilesystem *fs)
|
||||||
{
|
{
|
||||||
@ -498,6 +506,7 @@ int iso_local_filesystem_new(IsoFilesystem **fs)
|
|||||||
lfs->data = NULL; /* we don't need private data */
|
lfs->data = NULL; /* we don't need private data */
|
||||||
lfs->get_root = lfs_get_root;
|
lfs->get_root = lfs_get_root;
|
||||||
lfs->get_by_path = lfs_get_by_path;
|
lfs->get_by_path = lfs_get_by_path;
|
||||||
|
lfs->get_id = lfs_get_id;
|
||||||
lfs->free = lfs_fs_free;
|
lfs->free = lfs_fs_free;
|
||||||
}
|
}
|
||||||
*fs = lfs;
|
*fs = lfs;
|
||||||
|
@ -9,6 +9,11 @@
|
|||||||
#include "fsource.h"
|
#include "fsource.h"
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Values belong 100 are reserved for out own usage
|
||||||
|
*/
|
||||||
|
unsigned int iso_fs_global_id = 100;
|
||||||
|
|
||||||
void iso_file_source_ref(IsoFileSource *src)
|
void iso_file_source_ref(IsoFileSource *src)
|
||||||
{
|
{
|
||||||
++src->refcount;
|
++src->refcount;
|
||||||
|
@ -23,6 +23,11 @@
|
|||||||
typedef struct Iso_File_Source IsoFileSource;
|
typedef struct Iso_File_Source IsoFileSource;
|
||||||
typedef struct Iso_Filesystem IsoFilesystem;
|
typedef struct Iso_Filesystem IsoFilesystem;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* See IsoFilesystem->get_id() for info about this.
|
||||||
|
*/
|
||||||
|
extern unsigned int iso_fs_global_id;
|
||||||
|
|
||||||
struct Iso_Filesystem
|
struct Iso_Filesystem
|
||||||
{
|
{
|
||||||
|
|
||||||
@ -41,6 +46,21 @@ struct Iso_Filesystem
|
|||||||
int (*get_by_path)(IsoFilesystem *fs, const char *path,
|
int (*get_by_path)(IsoFilesystem *fs, const char *path,
|
||||||
IsoFileSource **file);
|
IsoFileSource **file);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get filesystem identifier.
|
||||||
|
*
|
||||||
|
* If the filesystem is able to generate correct values of the st_dev
|
||||||
|
* and st_ino fields for the struct stat of each file, this should
|
||||||
|
* return an unique number, greater than 0.
|
||||||
|
*
|
||||||
|
* To get a identifier for your filesystem implementation you should
|
||||||
|
* use iso_fs_global_id, incrementing it by one each time.
|
||||||
|
*
|
||||||
|
* Otherwise, if you can't ensure values in the struct stat are valid,
|
||||||
|
* this should return 0.
|
||||||
|
*/
|
||||||
|
unsigned int (*get_id)(IsoFilesystem *fs);
|
||||||
|
|
||||||
void (*free)(IsoFilesystem *fs);
|
void (*free)(IsoFilesystem *fs);
|
||||||
|
|
||||||
/* TODO each file will take a ref to IsoFilesystem, so maybe a 64bits
|
/* TODO each file will take a ref to IsoFilesystem, so maybe a 64bits
|
||||||
|
28
src/stream.c
28
src/stream.c
@ -90,6 +90,33 @@ int fsrc_is_repeatable(IsoStream *stream)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static
|
||||||
|
int fsrc_get_id(IsoStream *stream, unsigned int *fs_id, dev_t *dev_id,
|
||||||
|
ino_t *ino_id)
|
||||||
|
{
|
||||||
|
int result;
|
||||||
|
struct stat info;
|
||||||
|
IsoFileSource *src;
|
||||||
|
IsoFilesystem *fs;
|
||||||
|
|
||||||
|
if (stream == NULL || fs_id == NULL || dev_id == NULL || ino_id == NULL) {
|
||||||
|
return ISO_NULL_POINTER;
|
||||||
|
}
|
||||||
|
src = (IsoFileSource*)stream->data;
|
||||||
|
|
||||||
|
result = src->stat(src, &info);
|
||||||
|
if (result < 0) {
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
fs = src->get_filesystem(src);
|
||||||
|
|
||||||
|
*fs_id = fs->get_id(fs);
|
||||||
|
*dev_id = info.st_dev;
|
||||||
|
*ino_id = info.st_ino;
|
||||||
|
return ISO_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
static
|
static
|
||||||
void fsrc_free(IsoStream *stream)
|
void fsrc_free(IsoStream *stream)
|
||||||
{
|
{
|
||||||
@ -127,6 +154,7 @@ int iso_file_source_stream_new(IsoFileSource *src, IsoStream **stream)
|
|||||||
str->get_size = fsrc_get_size;
|
str->get_size = fsrc_get_size;
|
||||||
str->read = fsrc_read;
|
str->read = fsrc_read;
|
||||||
str->is_repeatable = fsrc_is_repeatable;
|
str->is_repeatable = fsrc_is_repeatable;
|
||||||
|
str->get_id = fsrc_get_id;
|
||||||
str->free = fsrc_free;
|
str->free = fsrc_free;
|
||||||
|
|
||||||
*stream = str;
|
*stream = str;
|
||||||
|
11
src/stream.h
11
src/stream.h
@ -68,6 +68,17 @@ struct Iso_Stream
|
|||||||
*/
|
*/
|
||||||
int (*is_repeatable)(IsoStream *stream);
|
int (*is_repeatable)(IsoStream *stream);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get an unique identifier for the IsoStream. If your implementation
|
||||||
|
* is unable to return a valid identifier, this function should return
|
||||||
|
* 0.
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
* 1 on success, 0 if idenfier is not valid, < 0 error
|
||||||
|
*/
|
||||||
|
int (*get_id)(IsoStream *stream, unsigned int *fs_id, dev_t *dev_id,
|
||||||
|
ino_t *ino_id);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Free implementation specific data. Should never be called by user.
|
* Free implementation specific data. Should never be called by user.
|
||||||
* Use iso_stream_unref() instead.
|
* Use iso_stream_unref() instead.
|
||||||
|
Loading…
Reference in New Issue
Block a user