Implement IsoFilesystem to deal with local filesystem.

This commit is contained in:
Vreixo Formoso 2007-11-25 19:54:13 +01:00
parent 1bda81869b
commit e034f287bf
3 changed files with 86 additions and 7 deletions

View File

@ -238,9 +238,7 @@ int lfs_readdir(IsoFileSource *src, IsoFileSource **child)
/* create the new FileSrc */ /* create the new FileSrc */
ret = iso_file_source_new_lfs(path, child); ret = iso_file_source_new_lfs(path, child);
if (ret < 0) {
free(path); free(path);
}
return ret; return ret;
} }
default: default:
@ -316,7 +314,7 @@ void lfs_free(IsoFileSource *src)
* @return * @return
* 1 success, < 0 error * 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; IsoFileSource *lfs_src;
_LocalFsFileSource *data; _LocalFsFileSource *data;
@ -337,7 +335,7 @@ int iso_file_source_new_lfs(char *path, IsoFileSource **src)
} }
/* fill struct */ /* fill struct */
data->path = path; data->path = strdup(path);
data->openned = 0; data->openned = 0;
lfs_src->refcount = 1; lfs_src->refcount = 1;
@ -356,4 +354,51 @@ int iso_file_source_new_lfs(char *path, IsoFileSource **src)
return ISO_SUCCESS; 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;
}

View File

@ -21,3 +21,16 @@ void iso_file_source_unref(IsoFileSource *src)
free(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);
}
}

View File

@ -31,9 +31,19 @@ struct Iso_Filesystem
* @return * @return
* 1 on success, < 0 on error * 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 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 * While this is usually called by corresponding method in IsoFilesystem
* object, for local filesystem it is legal to call this directly. * 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_*/ #endif /*LIBISO_FSOURCE_H_*/