Browse Source

Implement IsoFilesystem to deal with local filesystem.

release-1.5.4.branch
Vreixo Formoso 14 years ago
parent
commit
e034f287bf
  1. 55
      src/fs_local.c
  2. 13
      src/fsource.c
  3. 25
      src/fsource.h

55
src/fs_local.c

@ -238,9 +238,7 @@ int lfs_readdir(IsoFileSource *src, IsoFileSource **child)
/* create the new FileSrc */
ret = iso_file_source_new_lfs(path, child);
if (ret < 0) {
free(path);
}
free(path);
return ret;
}
default:
@ -316,7 +314,7 @@ void lfs_free(IsoFileSource *src)
* @return
* 1 success, < 0 error
*/
int iso_file_source_new_lfs(char *path, IsoFileSource **src)
int iso_file_source_new_lfs(const char *path, IsoFileSource **src)
{
IsoFileSource *lfs_src;
_LocalFsFileSource *data;
@ -337,7 +335,7 @@ int iso_file_source_new_lfs(char *path, IsoFileSource **src)
}
/* fill struct */
data->path = path;
data->path = strdup(path);
data->openned = 0;
lfs_src->refcount = 1;
@ -356,4 +354,51 @@ int iso_file_source_new_lfs(char *path, IsoFileSource **src)
return ISO_SUCCESS;
}
static
int lfs_get_root(IsoFilesystem *fs, IsoFileSource **root)
{
if (fs == NULL || root == NULL) {
return ISO_NULL_POINTER;
}
return iso_file_source_new_lfs("/", root);
}
static
int lfs_get_by_path(IsoFilesystem *fs, const char *path, IsoFileSource **file)
{
if (fs == NULL || path == NULL || file == NULL) {
return ISO_NULL_POINTER;
}
return iso_file_source_new_lfs(path, file);
}
static
void lfs_fs_free(IsoFilesystem *fs)
{
/* nothing to do */
return;
}
int iso_local_filesystem_new(IsoFilesystem **fs)
{
IsoFilesystem *lfs;
if (fs == NULL) {
return ISO_NULL_POINTER;
}
lfs = malloc(sizeof(IsoFilesystem));
if (lfs == NULL) {
return ISO_OUT_OF_MEM;
}
/* fill struct */
lfs->refcount = 1;
lfs->data = NULL; /* we don't need private data */
lfs->get_root = lfs_get_root;
lfs->get_by_path = lfs_get_by_path;
lfs->free = lfs_fs_free;
*fs = lfs;
return ISO_SUCCESS;
}

13
src/fsource.c

@ -21,3 +21,16 @@ void iso_file_source_unref(IsoFileSource *src)
free(src);
}
}
void iso_filesystem_ref(IsoFilesystem *fs)
{
++fs->refcount;
}
void iso_filesystem_unref(IsoFilesystem *fs)
{
if (--fs->refcount == 0) {
fs->free(fs);
free(fs);
}
}

25
src/fsource.h

@ -31,9 +31,19 @@ struct Iso_Filesystem
* @return
* 1 on success, < 0 on error
*/
int (*get_root)(IsoFilesystem *fs, IsoFileSource *root);
int (*get_root)(IsoFilesystem *fs, IsoFileSource **root);
/**
*
*
*/
int (*get_by_path)(IsoFilesystem *fs, const char *path,
IsoFileSource **file);
void (*free)(IsoFilesystem *fs);
int refcount;
void *data;
};
struct Iso_File_Source
@ -177,6 +187,17 @@ void iso_file_source_unref(IsoFileSource *src);
* While this is usually called by corresponding method in IsoFilesystem
* object, for local filesystem it is legal to call this directly.
*/
int iso_file_source_new_lfs(char *path, IsoFileSource **src);
int iso_file_source_new_lfs(const char *path, IsoFileSource **src);
void iso_filesystem_ref(IsoFilesystem *fs);
void iso_filesystem_unref(IsoFilesystem *fs);
/**
* Create a new IsoFilesystem to deal with local filesystem.
*
* @return
* 1 sucess, < 0 error
*/
int iso_local_filesystem_new(IsoFilesystem **fs);
#endif /*LIBISO_FSOURCE_H_*/

Loading…
Cancel
Save