Many hyperlinks are disabled.
Use anonymous login
to enable hyperlinks.
Overview
| SHA1 Hash: | dd959311deedb554593a6663898717b99a9e7468 |
|---|---|
| Date: | 2009-06-15 21:29:14 |
| User: | stephan |
| Comment: | factored out whefs_inode::name. Had to add whefs_file::name, at least temporarily, so whefs_file_name_get() would still work. |
Tags And Properties
- branch=trunk inherited from [d21fde6e87]
- sym-forked_to_google_code added by [3510155b1d] on 2009-06-16 20:12:51
- sym-trunk inherited from [d21fde6e87]
Changes
[hide diffs]Changes to test.c
@@ -232,11 +232,13 @@
whefs_fclose( F2 );
#endif
+#if 1//set this to 0 to test a leak:
whefs_fclose( F );
+#endif
whefs_fs_finalize( fs );
MARKER("ending test\n");
return 0;
}
@@ -567,19 +569,17 @@
WHEFSApp.helpText =
"Basic test/sanity-check program for whefs."
;
int rc = 0;
WHEFSApp_init( argc, argv, WHEFSApp_NoOpen, 0, 0 ); // ignore return.
-
- //whefs_setup_debug_arg( stderr, "hcl" );
ThisApp.fsopts = whefs_fs_options_default;
ThisApp.fsopts.inode_count = 16;
ThisApp.fsopts.block_count = 32;
ThisApp.fsopts.filename_length = 32;
ThisApp.fsopts.block_size = 1024 * 2;
- if(!rc) rc = test_encodings();
- if(!rc) rc = test_hash();
+ //if(!rc) rc = test_encodings();
+ //if(!rc) rc = test_hash();
if(!rc) rc = test_one();
if(!rc) rc = test_ramfs();
if(!rc) rc = test_multiple_files();
if(!rc) rc = test_truncate();
if(!rc) rc = test_caching();
Changes to whdbg.h
@@ -95,21 +95,17 @@
Log error messages.
*/
WHDBG_IO_ERROR = WHDBG_ERROR | 0x02,
/**
- FIXME markers
- */
-WHDBG_FIXME = WHDBG_ERROR | 0x04,
-
-/**
General warning mask.
*/
WHDBG_WARNING = 0x20000000,
WHDBG_NYI = WHDBG_WARNING | 0x01,
WHDBG_INFO = 0x40000000,
+
/**
"For your information..." or "To whom it may concern..."
*/
WHDBG_FYI = WHDBG_INFO,
/**
@@ -120,10 +116,15 @@
/**
Log deallocation events.
*/
WHDBG_DEALLOC = WHDBG_INFO | 0x0002,
+
+/**
+ FIXME markers
+ */
+WHDBG_FIXME = WHDBG_INFO | 0x04,
/**
For apps with a "verbose" flag.
*/
WHDBG_VERBOSE = 0x00010000,
Changes to whefs.h
@@ -1028,15 +1028,18 @@
there is any question at all about its lifetime.
The returned string is guaranteed to be no longer than
whefs_fs_options_get(whefs_file_fs(f))->filename_length
characters (not including the trailing null).
+
+ Maintenance note: f is non-const because of an unsightly
+ implementation detail involving how f's name is stored.
*/
-char const * whefs_file_name_get( whefs_file const * restrict f );
+char const * whefs_file_name_get( whefs_file * restrict f );
/**
- Returns a static string pointing to the whefs home page.
+ Returns a static string with the URL of the whefs home page.
*/
char const * whefs_home_page_url();
/**
Returns a static string containing the file format version
Changes to whefs_details.c
@@ -46,18 +46,18 @@
WHEFS_DBG_F_ALWAYS = WHDBG_ALWAYS,
WHEFS_DBG_F_VERBOSE = WHDBG_VERBOSE,
WHEFS_DBG_F_mymask = 0x0f000000,
WHEFS_DBG_F_LOCK = WHEFS_DBG_F_mymask & 0x01000000,
WHEFS_DBG_F_CACHE = WHEFS_DBG_F_mymask & 0x02000000,
-WHEFS_DBG_F_DEFAULTS_CLIENT = WHEFS_DBG_F_WARNING | WHEFS_DBG_F_ERROR | WHDBG_FIXME | WHDBG_NYI,
-WHEFS_DBG_F_DEFAULTS_HACKER = WHEFS_DBG_F_DEFAULTS_CLIENT | WHEFS_DBG_F_FYI | WHDBG_VERBOSE, // | WHEFS_DBG_F_CACHE, // | WHEFS_DBG_F_LOCK,
+WHEFS_DBG_F_DEFAULTS_CLIENT = WHEFS_DBG_F_WARNING | WHEFS_DBG_F_ERROR | WHDBG_NYI,
+WHEFS_DBG_F_DEFAULTS_HACKER = WHEFS_DBG_F_DEFAULTS_CLIENT | WHDBG_FIXME | WHEFS_DBG_F_FYI | WHDBG_VERBOSE, // | WHEFS_DBG_F_CACHE, // | WHEFS_DBG_F_LOCK,
#if defined(NDEBUG)
-WHEFS_DBG_F_DEFAULT = 0
-//WHEFS_DBG_F_DEFAULTS_CLIENT
+WHEFS_DBG_F_DEFAULT = 0 /* they'll be if(0)'d out in this case, anyway. */
#else
-WHEFS_DBG_F_DEFAULT = WHEFS_DBG_F_DEFAULTS_HACKER
+WHEFS_DBG_F_DEFAULT = WHEFS_DBG_F_DEFAULTS_CLIENT
+//WHEFS_DBG_F_DEFAULTS_HACKER
#endif
};
#define WHEFS_DBG WHDBG(WHEFS_DBG_F_ALWAYS)
#define WHEFS_DBG_ERR WHDBG(WHEFS_DBG_F_ERROR)
@@ -579,10 +579,12 @@
whio_dev * dev;
/**
inode ID.
*/
whefs_id_type inode;
+ /** Unfortunate. Should go away. */
+ whefs_string name;
};
/** Empty initialization object. */
extern const whefs_file whefs_file_init;
/**
Changes to whefs_file.c
@@ -12,11 +12,12 @@
#define WHEFS_FILE_INIT { \
0, /* fs */ \
0, /* flags */ \
0, /* dev */ \
- 0 /* inode */ \
+ 0, /* inode */ \
+ whefs_string_init_m /*name*/ \
}
const whefs_file whefs_file_init = WHEFS_FILE_INIT;
#define WHEFS_FILE_ISOPENED(F) ((F) && ((F)->flags & WHEFS_FLAG_Opened))
#define WHEFS_FILE_ISRO(F) ((F) && ((F)->flags & WHEFS_FLAG_Read))
@@ -53,20 +54,25 @@
whefs_file_alloc_slots.objs[i] = whefs_file_init;
obj = &whefs_file_alloc_slots.objs[i];
break;
}
#endif /* WHIO_USE_STATIC_MALLOC */
- if( ! obj ) obj = (whefs_file *) malloc( sizeof(whefs_file) );
+ if( ! obj )
+ {
+ obj = (whefs_file *) malloc( sizeof(whefs_file) );
+ if( obj ) *obj = whefs_file_init;
+ }
return obj;
}
static void whefs_file_free( whefs_file * restrict obj )
{
#if WHIO_USE_STATIC_MALLOC
if( (obj < &whefs_file_alloc_slots.objs[0]) ||
(obj > &whefs_file_alloc_slots.objs[whefs_file_alloc_count-1]) )
{ /* it does not belong to us */
+ *obj = whefs_file_init;
free(obj);
return;
}
else
{
@@ -74,17 +80,19 @@
whefs_file_alloc_slots.objs[ndx] = whefs_file_init;
whefs_file_alloc_slots.used[ndx] = 0;
return;
}
#else
+ whefs_string_clear( &obj->name, false );
+ *obj = whefs_file_init;
free(obj);
#endif /* WHIO_USE_STATIC_MALLOC */
}
static int whefs_fopen_ro( whefs_file * restrict f, char const * name )
{
- whefs_inode n;
+ whefs_inode n = whefs_inode_init;
int rc = whefs_inode_by_name( f->fs, name, &n );
if( whefs_rc.OK == rc )
{
if( f->dev ) f->dev->api->finalize(f->dev);
f->dev = whefs_dev_for_inode( f->fs, n.id, false );
@@ -104,11 +112,11 @@
static int whefs_fopen_rw( whefs_file * restrict f, char const * name )
{
if( ! f || ! name ) return whefs_rc.ArgError;
if( ! whefs_fs_is_rw(f->fs) ) return whefs_rc.AccessError;
- whefs_inode n;
+ whefs_inode n = whefs_inode_init;
int rc = whefs_inode_by_name( f->fs, name, &n );
if( whefs_rc.OK != rc ) do
{
if(0) WHEFS_DBG("fopen(fs,[%s] found no inode. Trying to create one...",name);
/**
@@ -144,11 +152,11 @@
return rc;
}
whefs_file * whefs_fopen( whefs_fs * fs, char const * name, char const * mode )
{
- if( ! fs || !name || !mode ) return 0;
+ if( ! fs || !name || !*name || !mode ) return 0;
unsigned int flags = 0;
if( 0 && (0 != strchr( mode, 'w' )) )
{ // FIXME: add support for mode 'w' and 'w+'
flags = WHEFS_FLAG_ReadWrite;
}
@@ -163,11 +171,10 @@
WHEFS_DBG_WARN("EFS is opened read-only, so we cannot open files in read/write mode.");
return 0;
}
whefs_file * f = whefs_file_alloc();
if( ! f ) return 0;
- *f = whefs_file_init;
f->fs = fs;
f->flags = flags;
int rc = whefs_rc.IOError;
//WHEFS_DBG_FYI("fopen(fs,[%s],[%s]) flags=0x%08x ISRW=%d", name, mode, flags, WHEFS_FILE_ISRW(f) );
rc = WHEFS_FILE_ISRW(f)
@@ -176,11 +183,16 @@
if( (rc != whefs_rc.OK) || !WHEFS_FILE_ISOPENED(f) || WHEFS_FILE_ISERR(f) )
{
whefs_fclose( f );
f = 0;
}
- //WHEFS_DBG("opened whefs_file [%s]. mode=%s, flags=%08x", name, mode, f->flags );
+ else
+ {
+ WHEFS_FIXME("Get rid of whefs_file::name! file=[%s]. mode=%s, flags=%08x", name, mode, f->flags );
+ whefs_string_copy_cstring( &f->name, name );
+ //WHEFS_DBG_FYI("opened whefs_file [%s]. mode=%s, flags=%08x", name, mode, f->flags );
+ }
return f;
}
whio_dev * whefs_dev_open( whefs_fs * fs, char const * name, bool writeMode )
{
@@ -419,22 +431,27 @@
if( whefs_rc.OK != rc ) return rc;
//whefs_inode_flush( f->fs, ino );
return whefs_rc.OK;
}
-char const * whefs_file_name_get( whefs_file const * restrict f )
+char const * whefs_file_name_get( whefs_file * restrict f )
{
if( ! f ) return 0;
+#if 0
whefs_inode * ino = 0;
int rc = whefs_inode_search_opened( f->fs, f->inode, &ino );
if( whefs_rc.OK != rc )
{
WHEFS_DBG_ERR("This should never ever happen: f appears to be a "
"whefs_file, but we could find no associated opened inode!");
return 0;
}
return ino->name.string;
+#else
+ whefs_inode_name_get( f->fs, f->inode, &f->name );
+ return f->name.string;
+#endif
}
whio_size_t whefs_fsize( whefs_file const * restrict f )
{
#if 1
Changes to whefs_inode.c
@@ -117,11 +117,10 @@
/**
We have to see if we have an existing entry for the given inode ID, so
we can replace its hashvalue in the cache. If we don't do this we end
up with stale/useless entries in the cache.
*/
- whefs_inode * nop = 0;
whefs_hashid * H = 0;
char const * nameCheck = name;
enum { bufSize = WHEFS_MAX_FILENAME_LENGTH + 1 };
char buf[bufSize] = {0};
whefs_string ncheck = whefs_string_init;
@@ -133,16 +132,10 @@
assert( (ncheck.string == buf) && "illegal (re)alloc!");
if( whefs_rc.OK != rc ) return rc;
if( *buf && (0==strcmp(buf,name))) return whefs_rc.OK;
if( *buf ) nameCheck = ncheck.string;
}
-#if 1
- if( whefs_rc.OK == whefs_inode_search_opened( fs, nid, &nop ) )
- { // FIXME: this is unfortunate. TODO: remove whefs_inode::name altogether.
- whefs_string_copy_cstring( &nop->name, name );
- }
-#endif
WHEFS_DBG_CACHE("inode-name-set searching for [old=%s][new=%s][check=%s].",ncheck.string,name,nameCheck);
whefs_id_type ndx = whefs_inode_hash_cache_search_ndx( fs, nameCheck );
if( ndx != whefs_id_type_end )
{
@@ -171,14 +164,10 @@
{
H->hash = fs->cache.hashfunc(name);
//fs->cache.hashes->isSorted = false;
whefs_hashid_list_sort( fs->cache.hashes );
WHEFS_DBG_CACHE("Replacing hashcode for file [%s].",name);
- if( nop )
- {
- rc = whefs_string_copy_cstring( &nop->name, name );
- }
}
if( whefs_rc.OK != rc ) return rc;
whefs_string_cache_set( &fs->cache.strings, nid-1, name );
#endif
return rc;
@@ -255,11 +244,10 @@
if( (whefs_rc.OK == xc) && nop )
{
if( tgt != nop )
{
*tgt = *nop;
- tgt->name = whefs_string_init; // prevent client from cleaning it.
}
//WHEFS_DBG("whefs_inode_id_read() found opened entry #%"WHEFS_ID_TYPE_PFMT" to read.", n->id);
return whefs_rc.OK;
}
}
@@ -515,17 +503,10 @@
{
whefs_inode_list_free(ent);
WHEFS_DBG_ERR("Opening inode #%"WHEFS_ID_TYPE_PFMT" FAILED - whefs_inode_id_read() returned %d", ent->inode.id, rc );
return rc;
}
- rc = whefs_inode_name_get( fs, ent->inode.id, &ent->inode.name );
- if( whefs_rc.OK != rc )
- {
- whefs_inode_list_free(ent);
- WHEFS_DBG_ERR("Opening inode #%"WHEFS_ID_TYPE_PFMT" FAILED - whefs_inode_name_get() returned %d", ent->inode.id, rc );
- return rc;
- }
//WHEFS_DBG("Opened inode #%"WHEFS_ID_TYPE_PFMT" with name [%s]", ent->inode.id, ent->inode.name.string );
x = &ent->inode;
x->writer = writer;
whefs_inode_list * li = fs->opened_nodes;
if( ! li )
@@ -601,11 +582,10 @@
--np->open_count;
if( 0 == np->open_count )
{
if(0) WHEFS_DBG_FYI("REALLY closing inode #%"WHEFS_ID_TYPE_PFMT": Use count=%u, data size=%u",
src->id, src->open_count, src->data_size );
- whefs_string_clear( &np->name, false );
if( li == fs->opened_nodes ) fs->opened_nodes = (li->next ? li->next : li->prev);
if( li->prev ) li->prev->next = li->next;
if( li->next ) li->next->prev = li->prev;
if( np->blocks.list )
{
Changes to whefs_inode.h
@@ -143,11 +143,11 @@
memory. This saves boatloads of i/o for common use cases.
Transient.
*/
whefs_block_list blocks;
/** Transient string used only by opened nodes. */
- whefs_string name;
+ //whefs_string name;
} whefs_inode;
/** Empty inode initialization object. */
#define whefs_inode_init_m { \
0, /* id */ \
@@ -155,12 +155,12 @@
0, /* first_block */ \
0, /* data_size */ \
0, /* mtime */ \
0, /* open_count */ \
0, /* writer */ \
- whefs_block_list_init_m /*blocks */, \
- whefs_string_init_m /* name */ \
+ whefs_block_list_init_m /*blocks */ \
+ /* whefs_string_init_m name */ \
}
/** Empty inode initialization object. */
extern const whefs_inode whefs_inode_init;