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
Changes to test.c
| Old (d17fef391a1d7930) | New (d8a4a93d6a765376) | |||
|---|---|---|---|---|
| 1 | /* | 1 | /* | |
| 2 | Test/demo app for libwhefs. | 2 | Test/demo app for libwhefs. | |
| 3 | 3 | |||
| 4 | Author: Stephan Beal (http://wanderinghorse.net/home/stephan/) | 4 | Author: Stephan Beal (http://wanderinghorse.net/home/stephan/) | |
| 5 | 5 | |||
| 226 hidden lines | ||||
| 232 | whefs_fclose( F2 ); | 232 | whefs_fclose( F2 ); | |
| 233 | #endif | 233 | #endif | |
| 234 | 234 | |||
| 235 | 235 | |||
| 236 | 236 | |||
| > | 237 | #if 1//set this to 0 to test a leak: | ||
| 237 | whefs_fclose( F ); | 238 | whefs_fclose( F ); | |
| > | 239 | #endif | ||
| 238 | 240 | |||
| 239 | whefs_fs_finalize( fs ); | 241 | whefs_fs_finalize( fs ); | |
| 240 | MARKER("ending test\n"); | 242 | MARKER("ending test\n"); | |
| 241 | return 0; | 243 | return 0; | |
| 242 | } | 244 | } | |
| 324 hidden lines | ||||
| 567 | WHEFSApp.helpText = | 569 | WHEFSApp.helpText = | |
| 568 | "Basic test/sanity-check program for whefs." | 570 | "Basic test/sanity-check program for whefs." | |
| 569 | ; | 571 | ; | |
| 570 | int rc = 0; | 572 | int rc = 0; | |
| 571 | WHEFSApp_init( argc, argv, WHEFSApp_NoOpen, 0, 0 ); // ignore return. | 573 | WHEFSApp_init( argc, argv, WHEFSApp_NoOpen, 0, 0 ); // ignore return. | |
| 572 | < | |||
| 573 | //whefs_setup_debug_arg( stderr, "hcl" ); | < | ||
| 574 | ThisApp.fsopts = whefs_fs_options_default; | 574 | ThisApp.fsopts = whefs_fs_options_default; | |
| 575 | ThisApp.fsopts.inode_count = 16; | 575 | ThisApp.fsopts.inode_count = 16; | |
| 576 | ThisApp.fsopts.block_count = 32; | 576 | ThisApp.fsopts.block_count = 32; | |
| 577 | ThisApp.fsopts.filename_length = 32; | 577 | ThisApp.fsopts.filename_length = 32; | |
| 578 | ThisApp.fsopts.block_size = 1024 * 2; | 578 | ThisApp.fsopts.block_size = 1024 * 2; | |
| 579 | if(!rc) rc = test_encodings(); | | | 579 | //if(!rc) rc = test_encodings(); |
| 580 | if(!rc) rc = test_hash(); | | | 580 | //if(!rc) rc = test_hash(); |
| 581 | if(!rc) rc = test_one(); | 581 | if(!rc) rc = test_one(); | |
| 582 | if(!rc) rc = test_ramfs(); | 582 | if(!rc) rc = test_ramfs(); | |
| 583 | if(!rc) rc = test_multiple_files(); | 583 | if(!rc) rc = test_multiple_files(); | |
| 584 | if(!rc) rc = test_truncate(); | 584 | if(!rc) rc = test_truncate(); | |
| 585 | if(!rc) rc = test_caching(); | 585 | if(!rc) rc = test_caching(); | |
| 587 | (0==rc) | 587 | (0==rc) | |
| 588 | ? "You win :)" | 588 | ? "You win :)" | |
| 589 | : "You lose :("); | 589 | : "You lose :("); | |
| 590 | return rc; | 590 | return rc; | |
| 591 | } | 591 | } | |
Changes to whdbg.h
| Old (1a80a6d82911e1ba) | New (1b1f2cafdaa02194) | |||
|---|---|---|---|---|
| 1 | #ifndef WANDERINGHORSE_NET_WHDBG_H_INCLUDED | 1 | #ifndef WANDERINGHORSE_NET_WHDBG_H_INCLUDED | |
| 2 | #define WANDERINGHORSE_NET_WHDBG_H_INCLUDED 1 | 2 | #define WANDERINGHORSE_NET_WHDBG_H_INCLUDED 1 | |
| 3 | 3 | |||
| 4 | /** @page whdbg_page_main whdbg: Debugging Library for C | 4 | /** @page whdbg_page_main whdbg: Debugging Library for C | |
| 5 | 5 | |||
| 89 hidden lines | ||||
| 95 | Log error messages. | 95 | Log error messages. | |
| 96 | */ | 96 | */ | |
| 97 | WHDBG_IO_ERROR = WHDBG_ERROR | 0x02, | 97 | WHDBG_IO_ERROR = WHDBG_ERROR | 0x02, | |
| 98 | 98 | |||
| 99 | /** | 99 | /** | |
| 100 | FIXME markers | < | ||
| 101 | */ | < | ||
| 102 | WHDBG_FIXME = WHDBG_ERROR | 0x04, | < | ||
| 103 | < | |||
| 104 | /** | < | ||
| 105 | General warning mask. | 100 | General warning mask. | |
| 106 | */ | 101 | */ | |
| 107 | WHDBG_WARNING = 0x20000000, | 102 | WHDBG_WARNING = 0x20000000, | |
| 108 | WHDBG_NYI = WHDBG_WARNING | 0x01, | 103 | WHDBG_NYI = WHDBG_WARNING | 0x01, | |
| 109 | 104 | |||
| 110 | WHDBG_INFO = 0x40000000, | 105 | WHDBG_INFO = 0x40000000, | |
| > | 106 | |||
| 111 | /** | 107 | /** | |
| 112 | "For your information..." or "To whom it may concern..." | 108 | "For your information..." or "To whom it may concern..." | |
| 113 | */ | 109 | */ | |
| 114 | WHDBG_FYI = WHDBG_INFO, | 110 | WHDBG_FYI = WHDBG_INFO, | |
| 115 | /** | 111 | /** | |
| 4 hidden lines | ||||
| 120 | 116 | |||
| 121 | /** | 117 | /** | |
| 122 | Log deallocation events. | 118 | Log deallocation events. | |
| 123 | */ | 119 | */ | |
| 124 | WHDBG_DEALLOC = WHDBG_INFO | 0x0002, | 120 | WHDBG_DEALLOC = WHDBG_INFO | 0x0002, | |
| > | 121 | |||
| > | 122 | /** | ||
| > | 123 | FIXME markers | ||
| > | 124 | */ | ||
| > | 125 | WHDBG_FIXME = WHDBG_INFO | 0x04, | ||
| 125 | 126 | |||
| 126 | /** | 127 | /** | |
| 127 | For apps with a "verbose" flag. | 128 | For apps with a "verbose" flag. | |
| 128 | */ | 129 | */ | |
| 129 | WHDBG_VERBOSE = 0x00010000, | 130 | WHDBG_VERBOSE = 0x00010000, | |
| 199 hidden lines | ||||
| 329 | #ifdef __cplusplus | 330 | #ifdef __cplusplus | |
| 330 | } /* extern "C" */ | 331 | } /* extern "C" */ | |
| 331 | #endif | 332 | #endif | |
| 332 | 333 | |||
| 333 | #endif /* WANDERINGHORSE_NET_WHDBG_H_INCLUDED */ | 334 | #endif /* WANDERINGHORSE_NET_WHDBG_H_INCLUDED */ | |
Changes to whefs.h
| Old (5d6f203df1cb67fc) | New (c05ff71416f1dce4) | |||
|---|---|---|---|---|
| 1 | #ifndef WANDERINGHORSE_NET_WHEFS_H_INCLUDED | 1 | #ifndef WANDERINGHORSE_NET_WHEFS_H_INCLUDED | |
| 2 | #define WANDERINGHORSE_NET_WHEFS_H_INCLUDED | 2 | #define WANDERINGHORSE_NET_WHEFS_H_INCLUDED | |
| 3 | 3 | |||
| 4 | #include "whefs_config.h" | 4 | #include "whefs_config.h" | |
| 5 | #include <stddef.h> | 5 | #include <stddef.h> | |
| 1022 hidden lines | ||||
| 1028 | there is any question at all about its lifetime. | 1028 | there is any question at all about its lifetime. | |
| 1029 | 1029 | |||
| 1030 | The returned string is guaranteed to be no longer than | 1030 | The returned string is guaranteed to be no longer than | |
| 1031 | whefs_fs_options_get(whefs_file_fs(f))->filename_length | 1031 | whefs_fs_options_get(whefs_file_fs(f))->filename_length | |
| 1032 | characters (not including the trailing null). | 1032 | characters (not including the trailing null). | |
| > | 1033 | |||
| > | 1034 | Maintenance note: f is non-const because of an unsightly | ||
| > | 1035 | implementation detail involving how f's name is stored. | ||
| 1033 | */ | 1036 | */ | |
| 1034 | char const * whefs_file_name_get( whefs_file const * restrict f ); | | | 1037 | char const * whefs_file_name_get( whefs_file * restrict f ); |
| 1035 | 1038 | |||
| 1036 | /** | 1039 | /** | |
| 1037 | Returns a static string pointing to the whefs home page. | | | 1040 | Returns a static string with the URL of the whefs home page. |
| 1038 | */ | 1041 | */ | |
| 1039 | char const * whefs_home_page_url(); | 1042 | char const * whefs_home_page_url(); | |
| 1040 | 1043 | |||
| 1041 | /** | 1044 | /** | |
| 1042 | Returns a static string containing the file format version | 1045 | Returns a static string containing the file format version | |
| 126 hidden lines | ||||
| 1169 | #ifdef __cplusplus | 1172 | #ifdef __cplusplus | |
| 1170 | } /* extern "C" */ | 1173 | } /* extern "C" */ | |
| 1171 | #endif | 1174 | #endif | |
| 1172 | 1175 | |||
| 1173 | #endif /* WANDERINGHORSE_NET_WHEFS_H_INCLUDED */ | 1176 | #endif /* WANDERINGHORSE_NET_WHEFS_H_INCLUDED */ | |
Changes to whefs_details.c
| Old (07b8a5d618bcbcae) | New (1b8a0b71b97054ff) | |||
|---|---|---|---|---|
| 1 | #if !defined(WANDERINGHORSE_NET_WHEFS_DETAILS_C_INCLUDED) | 1 | #if !defined(WANDERINGHORSE_NET_WHEFS_DETAILS_C_INCLUDED) | |
| 2 | #define WANDERINGHORSE_NET_WHEFS_DETAILS_C_INCLUDED 1 | 2 | #define WANDERINGHORSE_NET_WHEFS_DETAILS_C_INCLUDED 1 | |
| 3 | #if ! defined __STDC_FORMAT_MACROS | 3 | #if ! defined __STDC_FORMAT_MACROS | |
| 4 | # define __STDC_FORMAT_MACROS 1 | 4 | # define __STDC_FORMAT_MACROS 1 | |
| 5 | #endif | 5 | #endif | |
| 40 hidden lines | ||||
| 46 | WHEFS_DBG_F_ALWAYS = WHDBG_ALWAYS, | 46 | WHEFS_DBG_F_ALWAYS = WHDBG_ALWAYS, | |
| 47 | WHEFS_DBG_F_VERBOSE = WHDBG_VERBOSE, | 47 | WHEFS_DBG_F_VERBOSE = WHDBG_VERBOSE, | |
| 48 | WHEFS_DBG_F_mymask = 0x0f000000, | 48 | WHEFS_DBG_F_mymask = 0x0f000000, | |
| 49 | WHEFS_DBG_F_LOCK = WHEFS_DBG_F_mymask & 0x01000000, | 49 | WHEFS_DBG_F_LOCK = WHEFS_DBG_F_mymask & 0x01000000, | |
| 50 | WHEFS_DBG_F_CACHE = WHEFS_DBG_F_mymask & 0x02000000, | 50 | WHEFS_DBG_F_CACHE = WHEFS_DBG_F_mymask & 0x02000000, | |
| 51 | WHEFS_DBG_F_DEFAULTS_CLIENT = WHEFS_DBG_F_WARNING | WHEFS_DBG_F_ERROR | WHDBG_FIXME | WHDBG_NYI, | | | 51 | WHEFS_DBG_F_DEFAULTS_CLIENT = WHEFS_DBG_F_WARNING | WHEFS_DBG_F_ERROR | WHDBG_NYI, |
| 52 | WHEFS_DBG_F_DEFAULTS_HACKER = WHEFS_DBG_F_DEFAULTS_CLIENT | WHEFS_DBG_F_FYI | WHDBG_VERBOSE, // | WHEFS_DBG_F_CACHE, // | WHEFS_DBG_F_LOCK, | | | 52 | 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, |
| 53 | 53 | |||
| 54 | #if defined(NDEBUG) | 54 | #if defined(NDEBUG) | |
| 55 | WHEFS_DBG_F_DEFAULT = 0 | | | 55 | WHEFS_DBG_F_DEFAULT = 0 /* they'll be if(0)'d out in this case, anyway. */ |
| 56 | //WHEFS_DBG_F_DEFAULTS_CLIENT | | | ||
| 57 | #else | 56 | #else | |
| 58 | WHEFS_DBG_F_DEFAULT = WHEFS_DBG_F_DEFAULTS_HACKER | | | 57 | WHEFS_DBG_F_DEFAULT = WHEFS_DBG_F_DEFAULTS_CLIENT |
| | | 58 | //WHEFS_DBG_F_DEFAULTS_HACKER | ||
| 59 | #endif | 59 | #endif | |
| 60 | }; | 60 | }; | |
| 61 | 61 | |||
| 62 | #define WHEFS_DBG WHDBG(WHEFS_DBG_F_ALWAYS) | 62 | #define WHEFS_DBG WHDBG(WHEFS_DBG_F_ALWAYS) | |
| 63 | #define WHEFS_DBG_ERR WHDBG(WHEFS_DBG_F_ERROR) | 63 | #define WHEFS_DBG_ERR WHDBG(WHEFS_DBG_F_ERROR) | |
| 515 hidden lines | ||||
| 579 | whio_dev * dev; | 579 | whio_dev * dev; | |
| 580 | /** | 580 | /** | |
| 581 | inode ID. | 581 | inode ID. | |
| 582 | */ | 582 | */ | |
| 583 | whefs_id_type inode; | 583 | whefs_id_type inode; | |
| > | 584 | /** Unfortunate. Should go away. */ | ||
| > | 585 | whefs_string name; | ||
| 584 | }; | 586 | }; | |
| 585 | /** Empty initialization object. */ | 587 | /** Empty initialization object. */ | |
| 586 | extern const whefs_file whefs_file_init; | 588 | extern const whefs_file whefs_file_init; | |
| 587 | 589 | |||
| 588 | /** | 590 | /** | |
| 174 hidden lines | ||||
| 763 | void whefs_inode_hash_cache_sort(whefs_fs * fs ); | 765 | void whefs_inode_hash_cache_sort(whefs_fs * fs ); | |
| 764 | 766 | |||
| 765 | int whefs_fs_cache_name( whefs_fs * fs, whefs_id_type id, char const * n ); | 767 | int whefs_fs_cache_name( whefs_fs * fs, whefs_id_type id, char const * n ); | |
| 766 | 768 | |||
| 767 | #endif /* WANDERINGHORSE_NET_WHEFS_DETAILS_C_INCLUDED */ | 769 | #endif /* WANDERINGHORSE_NET_WHEFS_DETAILS_C_INCLUDED */ | |
Changes to whefs_file.c
| Old (6a0752212fb5e8b9) | New (e4f7cbfe63fc5ff0) | |||
|---|---|---|---|---|
| 1 | /* | 1 | /* | |
| 2 | Implementations for the whefs_file-related API. | 2 | Implementations for the whefs_file-related API. | |
| 3 | 3 | |||
| 4 | Author: Stephan Beal (http://wanderinghorse.net/home/stephan/ | 4 | Author: Stephan Beal (http://wanderinghorse.net/home/stephan/ | |
| 5 | 5 | |||
| 6 hidden lines | ||||
| 12 | 12 | |||
| 13 | #define WHEFS_FILE_INIT { \ | 13 | #define WHEFS_FILE_INIT { \ | |
| 14 | 0, /* fs */ \ | 14 | 0, /* fs */ \ | |
| 15 | 0, /* flags */ \ | 15 | 0, /* flags */ \ | |
| 16 | 0, /* dev */ \ | 16 | 0, /* dev */ \ | |
| 17 | 0 /* inode */ \ | | | 17 | 0, /* inode */ \ |
| | | 18 | whefs_string_init_m /*name*/ \ | ||
| 18 | } | 19 | } | |
| 19 | 20 | |||
| 20 | const whefs_file whefs_file_init = WHEFS_FILE_INIT; | 21 | const whefs_file whefs_file_init = WHEFS_FILE_INIT; | |
| 21 | #define WHEFS_FILE_ISOPENED(F) ((F) && ((F)->flags & WHEFS_FLAG_Opened)) | 22 | #define WHEFS_FILE_ISOPENED(F) ((F) && ((F)->flags & WHEFS_FLAG_Opened)) | |
| 22 | #define WHEFS_FILE_ISRO(F) ((F) && ((F)->flags & WHEFS_FLAG_Read)) | 23 | #define WHEFS_FILE_ISRO(F) ((F) && ((F)->flags & WHEFS_FLAG_Read)) | |
| 30 hidden lines | ||||
| 53 | whefs_file_alloc_slots.objs[i] = whefs_file_init; | 54 | whefs_file_alloc_slots.objs[i] = whefs_file_init; | |
| 54 | obj = &whefs_file_alloc_slots.objs[i]; | 55 | obj = &whefs_file_alloc_slots.objs[i]; | |
| 55 | break; | 56 | break; | |
| 56 | } | 57 | } | |
| 57 | #endif /* WHIO_USE_STATIC_MALLOC */ | 58 | #endif /* WHIO_USE_STATIC_MALLOC */ | |
| 58 | if( ! obj ) obj = (whefs_file *) malloc( sizeof(whefs_file) ); | | | 59 | if( ! obj ) |
| | | 60 | { | ||
| | | 61 | obj = (whefs_file *) malloc( sizeof(whefs_file) ); | ||
| | | 62 | if( obj ) *obj = whefs_file_init; | ||
| | | 63 | } | ||
| 59 | return obj; | 64 | return obj; | |
| 60 | } | 65 | } | |
| 61 | 66 | |||
| 62 | static void whefs_file_free( whefs_file * restrict obj ) | 67 | static void whefs_file_free( whefs_file * restrict obj ) | |
| 63 | { | 68 | { | |
| 64 | #if WHIO_USE_STATIC_MALLOC | 69 | #if WHIO_USE_STATIC_MALLOC | |
| 65 | if( (obj < &whefs_file_alloc_slots.objs[0]) || | 70 | if( (obj < &whefs_file_alloc_slots.objs[0]) || | |
| 66 | (obj > &whefs_file_alloc_slots.objs[whefs_file_alloc_count-1]) ) | 71 | (obj > &whefs_file_alloc_slots.objs[whefs_file_alloc_count-1]) ) | |
| 67 | { /* it does not belong to us */ | 72 | { /* it does not belong to us */ | |
| > | 73 | *obj = whefs_file_init; | ||
| 68 | free(obj); | 74 | free(obj); | |
| 69 | return; | 75 | return; | |
| 70 | } | 76 | } | |
| 71 | else | 77 | else | |
| 72 | { | 78 | { | |
| 74 | whefs_file_alloc_slots.objs[ndx] = whefs_file_init; | 80 | whefs_file_alloc_slots.objs[ndx] = whefs_file_init; | |
| 75 | whefs_file_alloc_slots.used[ndx] = 0; | 81 | whefs_file_alloc_slots.used[ndx] = 0; | |
| 76 | return; | 82 | return; | |
| 77 | } | 83 | } | |
| 78 | #else | 84 | #else | |
| > | 85 | whefs_string_clear( &obj->name, false ); | ||
| > | 86 | *obj = whefs_file_init; | ||
| 79 | free(obj); | 87 | free(obj); | |
| 80 | #endif /* WHIO_USE_STATIC_MALLOC */ | 88 | #endif /* WHIO_USE_STATIC_MALLOC */ | |
| 81 | } | 89 | } | |
| 82 | 90 | |||
| 83 | static int whefs_fopen_ro( whefs_file * restrict f, char const * name ) | 91 | static int whefs_fopen_ro( whefs_file * restrict f, char const * name ) | |
| 84 | { | 92 | { | |
| 85 | whefs_inode n; | | | 93 | whefs_inode n = whefs_inode_init; |
| 86 | int rc = whefs_inode_by_name( f->fs, name, &n ); | 94 | int rc = whefs_inode_by_name( f->fs, name, &n ); | |
| 87 | if( whefs_rc.OK == rc ) | 95 | if( whefs_rc.OK == rc ) | |
| 88 | { | 96 | { | |
| 89 | if( f->dev ) f->dev->api->finalize(f->dev); | 97 | if( f->dev ) f->dev->api->finalize(f->dev); | |
| 90 | f->dev = whefs_dev_for_inode( f->fs, n.id, false ); | 98 | f->dev = whefs_dev_for_inode( f->fs, n.id, false ); | |
| 13 hidden lines | ||||
| 104 | 112 | |||
| 105 | static int whefs_fopen_rw( whefs_file * restrict f, char const * name ) | 113 | static int whefs_fopen_rw( whefs_file * restrict f, char const * name ) | |
| 106 | { | 114 | { | |
| 107 | if( ! f || ! name ) return whefs_rc.ArgError; | 115 | if( ! f || ! name ) return whefs_rc.ArgError; | |
| 108 | if( ! whefs_fs_is_rw(f->fs) ) return whefs_rc.AccessError; | 116 | if( ! whefs_fs_is_rw(f->fs) ) return whefs_rc.AccessError; | |
| 109 | whefs_inode n; | | | 117 | whefs_inode n = whefs_inode_init; |
| 110 | int rc = whefs_inode_by_name( f->fs, name, &n ); | 118 | int rc = whefs_inode_by_name( f->fs, name, &n ); | |
| 111 | if( whefs_rc.OK != rc ) do | 119 | if( whefs_rc.OK != rc ) do | |
| 112 | { | 120 | { | |
| 113 | if(0) WHEFS_DBG("fopen(fs,[%s] found no inode. Trying to create one...",name); | 121 | if(0) WHEFS_DBG("fopen(fs,[%s] found no inode. Trying to create one...",name); | |
| 114 | /** | 122 | /** | |
| 29 hidden lines | ||||
| 144 | return rc; | 152 | return rc; | |
| 145 | } | 153 | } | |
| 146 | 154 | |||
| 147 | whefs_file * whefs_fopen( whefs_fs * fs, char const * name, char const * mode ) | 155 | whefs_file * whefs_fopen( whefs_fs * fs, char const * name, char const * mode ) | |
| 148 | { | 156 | { | |
| 149 | if( ! fs || !name || !mode ) return 0; | | | 157 | if( ! fs || !name || !*name || !mode ) return 0; |
| 150 | unsigned int flags = 0; | 158 | unsigned int flags = 0; | |
| 151 | if( 0 && (0 != strchr( mode, 'w' )) ) | 159 | if( 0 && (0 != strchr( mode, 'w' )) ) | |
| 152 | { // FIXME: add support for mode 'w' and 'w+' | 160 | { // FIXME: add support for mode 'w' and 'w+' | |
| 153 | flags = WHEFS_FLAG_ReadWrite; | 161 | flags = WHEFS_FLAG_ReadWrite; | |
| 154 | } | 162 | } | |
| 8 hidden lines | ||||
| 163 | WHEFS_DBG_WARN("EFS is opened read-only, so we cannot open files in read/write mode."); | 171 | WHEFS_DBG_WARN("EFS is opened read-only, so we cannot open files in read/write mode."); | |
| 164 | return 0; | 172 | return 0; | |
| 165 | } | 173 | } | |
| 166 | whefs_file * f = whefs_file_alloc(); | 174 | whefs_file * f = whefs_file_alloc(); | |
| 167 | if( ! f ) return 0; | 175 | if( ! f ) return 0; | |
| 168 | *f = whefs_file_init; | < | ||
| 169 | f->fs = fs; | 176 | f->fs = fs; | |
| 170 | f->flags = flags; | 177 | f->flags = flags; | |
| 171 | int rc = whefs_rc.IOError; | 178 | int rc = whefs_rc.IOError; | |
| 172 | //WHEFS_DBG_FYI("fopen(fs,[%s],[%s]) flags=0x%08x ISRW=%d", name, mode, flags, WHEFS_FILE_ISRW(f) ); | 179 | //WHEFS_DBG_FYI("fopen(fs,[%s],[%s]) flags=0x%08x ISRW=%d", name, mode, flags, WHEFS_FILE_ISRW(f) ); | |
| 173 | rc = WHEFS_FILE_ISRW(f) | 180 | rc = WHEFS_FILE_ISRW(f) | |
| 2 hidden lines | ||||
| 176 | if( (rc != whefs_rc.OK) || !WHEFS_FILE_ISOPENED(f) || WHEFS_FILE_ISERR(f) ) | 183 | if( (rc != whefs_rc.OK) || !WHEFS_FILE_ISOPENED(f) || WHEFS_FILE_ISERR(f) ) | |
| 177 | { | 184 | { | |
| 178 | whefs_fclose( f ); | 185 | whefs_fclose( f ); | |
| 179 | f = 0; | 186 | f = 0; | |
| 180 | } | 187 | } | |
| 181 | //WHEFS_DBG("opened whefs_file [%s]. mode=%s, flags=%08x", name, mode, f->flags ); | | | 188 | else |
| | | 189 | { | ||
| | | 190 | WHEFS_FIXME("Get rid of whefs_file::name! file=[%s]. mode=%s, flags=%08x", name, mode, f->flags ); | ||
| | | 191 | whefs_string_copy_cstring( &f->name, name ); | ||
| | | 192 | //WHEFS_DBG_FYI("opened whefs_file [%s]. mode=%s, flags=%08x", name, mode, f->flags ); | ||
| | | 193 | } | ||
| 182 | return f; | 194 | return f; | |
| 183 | } | 195 | } | |
| 184 | 196 | |||
| 185 | whio_dev * whefs_dev_open( whefs_fs * fs, char const * name, bool writeMode ) | 197 | whio_dev * whefs_dev_open( whefs_fs * fs, char const * name, bool writeMode ) | |
| 186 | { | 198 | { | |
| 232 hidden lines | ||||
| 419 | if( whefs_rc.OK != rc ) return rc; | 431 | if( whefs_rc.OK != rc ) return rc; | |
| 420 | //whefs_inode_flush( f->fs, ino ); | 432 | //whefs_inode_flush( f->fs, ino ); | |
| 421 | return whefs_rc.OK; | 433 | return whefs_rc.OK; | |
| 422 | } | 434 | } | |
| 423 | 435 | |||
| 424 | char const * whefs_file_name_get( whefs_file const * restrict f ) | | | 436 | char const * whefs_file_name_get( whefs_file * restrict f ) |
| 425 | { | 437 | { | |
| 426 | if( ! f ) return 0; | 438 | if( ! f ) return 0; | |
| > | 439 | #if 0 | ||
| 427 | whefs_inode * ino = 0; | 440 | whefs_inode * ino = 0; | |
| 428 | int rc = whefs_inode_search_opened( f->fs, f->inode, &ino ); | 441 | int rc = whefs_inode_search_opened( f->fs, f->inode, &ino ); | |
| 429 | if( whefs_rc.OK != rc ) | 442 | if( whefs_rc.OK != rc ) | |
| 430 | { | 443 | { | |
| 431 | WHEFS_DBG_ERR("This should never ever happen: f appears to be a " | 444 | WHEFS_DBG_ERR("This should never ever happen: f appears to be a " | |
| 432 | "whefs_file, but we could find no associated opened inode!"); | 445 | "whefs_file, but we could find no associated opened inode!"); | |
| 433 | return 0; | 446 | return 0; | |
| 434 | } | 447 | } | |
| 435 | return ino->name.string; | 448 | return ino->name.string; | |
| > | 449 | #else | ||
| > | 450 | whefs_inode_name_get( f->fs, f->inode, &f->name ); | ||
| > | 451 | return f->name.string; | ||
| > | 452 | #endif | ||
| 436 | } | 453 | } | |
| 437 | 454 | |||
| 438 | whio_size_t whefs_fsize( whefs_file const * restrict f ) | 455 | whio_size_t whefs_fsize( whefs_file const * restrict f ) | |
| 439 | { | 456 | { | |
| 440 | #if 1 | 457 | #if 1 | |
| 7 hidden lines | ||||
| 448 | return (f && f->dev) | 465 | return (f && f->dev) | |
| 449 | ? whio_dev_size( f->dev ) | 466 | ? whio_dev_size( f->dev ) | |
| 450 | : whefs_rc.SizeTError; | 467 | : whefs_rc.SizeTError; | |
| 451 | #endif | 468 | #endif | |
| 452 | } | 469 | } | |
Changes to whefs_inode.c
| Old (ff3760ef7b8e4b23) | New (3ac3cd9cbfe2a82e) | |||
|---|---|---|---|---|
| 1 | /* | 1 | /* | |
| 2 | Implementations for whefs_inode operations. | 2 | Implementations for whefs_inode operations. | |
| 3 | 3 | |||
| 4 | Author: Stephan Beal (http://wanderinghorse.net/home/stephan/) | 4 | Author: Stephan Beal (http://wanderinghorse.net/home/stephan/) | |
| 5 | 5 | |||
| 111 hidden lines | ||||
| 117 | /** | 117 | /** | |
| 118 | We have to see if we have an existing entry for the given inode ID, so | 118 | We have to see if we have an existing entry for the given inode ID, so | |
| 119 | we can replace its hashvalue in the cache. If we don't do this we end | 119 | we can replace its hashvalue in the cache. If we don't do this we end | |
| 120 | up with stale/useless entries in the cache. | 120 | up with stale/useless entries in the cache. | |
| 121 | */ | 121 | */ | |
| 122 | whefs_inode * nop = 0; | < | ||
| 123 | whefs_hashid * H = 0; | 122 | whefs_hashid * H = 0; | |
| 124 | char const * nameCheck = name; | 123 | char const * nameCheck = name; | |
| 125 | enum { bufSize = WHEFS_MAX_FILENAME_LENGTH + 1 }; | 124 | enum { bufSize = WHEFS_MAX_FILENAME_LENGTH + 1 }; | |
| 126 | char buf[bufSize] = {0}; | 125 | char buf[bufSize] = {0}; | |
| 127 | whefs_string ncheck = whefs_string_init; | 126 | whefs_string ncheck = whefs_string_init; | |
| 5 hidden lines | ||||
| 133 | assert( (ncheck.string == buf) && "illegal (re)alloc!"); | 132 | assert( (ncheck.string == buf) && "illegal (re)alloc!"); | |
| 134 | if( whefs_rc.OK != rc ) return rc; | 133 | if( whefs_rc.OK != rc ) return rc; | |
| 135 | if( *buf && (0==strcmp(buf,name))) return whefs_rc.OK; | 134 | if( *buf && (0==strcmp(buf,name))) return whefs_rc.OK; | |
| 136 | if( *buf ) nameCheck = ncheck.string; | 135 | if( *buf ) nameCheck = ncheck.string; | |
| 137 | } | 136 | } | |
| 138 | #if 1 | < | ||
| 139 | if( whefs_rc.OK == whefs_inode_search_opened( fs, nid, &nop ) ) | < | ||
| 140 | { // FIXME: this is unfortunate. TODO: remove whefs_inode::name altogether. | < | ||
| 141 | whefs_string_copy_cstring( &nop->name, name ); | < | ||
| 142 | } | < | ||
| 143 | #endif | < | ||
| 144 | 137 | |||
| 145 | WHEFS_DBG_CACHE("inode-name-set searching for [old=%s][new=%s][check=%s].",ncheck.string,name,nameCheck); | 138 | WHEFS_DBG_CACHE("inode-name-set searching for [old=%s][new=%s][check=%s].",ncheck.string,name,nameCheck); | |
| 146 | whefs_id_type ndx = whefs_inode_hash_cache_search_ndx( fs, nameCheck ); | 139 | whefs_id_type ndx = whefs_inode_hash_cache_search_ndx( fs, nameCheck ); | |
| 147 | if( ndx != whefs_id_type_end ) | 140 | if( ndx != whefs_id_type_end ) | |
| 148 | { | 141 | { | |
| 22 hidden lines | ||||
| 171 | { | 164 | { | |
| 172 | H->hash = fs->cache.hashfunc(name); | 165 | H->hash = fs->cache.hashfunc(name); | |
| 173 | //fs->cache.hashes->isSorted = false; | 166 | //fs->cache.hashes->isSorted = false; | |
| 174 | whefs_hashid_list_sort( fs->cache.hashes ); | 167 | whefs_hashid_list_sort( fs->cache.hashes ); | |
| 175 | WHEFS_DBG_CACHE("Replacing hashcode for file [%s].",name); | 168 | WHEFS_DBG_CACHE("Replacing hashcode for file [%s].",name); | |
| 176 | if( nop ) | < | ||
| 177 | { | < | ||
| 178 | rc = whefs_string_copy_cstring( &nop->name, name ); | < | ||
| 179 | } | < | ||
| 180 | } | 169 | } | |
| 181 | if( whefs_rc.OK != rc ) return rc; | 170 | if( whefs_rc.OK != rc ) return rc; | |
| 182 | whefs_string_cache_set( &fs->cache.strings, nid-1, name ); | 171 | whefs_string_cache_set( &fs->cache.strings, nid-1, name ); | |
| 183 | #endif | 172 | #endif | |
| 184 | return rc; | 173 | return rc; | |
| 70 hidden lines | ||||
| 255 | if( (whefs_rc.OK == xc) && nop ) | 244 | if( (whefs_rc.OK == xc) && nop ) | |
| 256 | { | 245 | { | |
| 257 | if( tgt != nop ) | 246 | if( tgt != nop ) | |
| 258 | { | 247 | { | |
| 259 | *tgt = *nop; | 248 | *tgt = *nop; | |
| 260 | tgt->name = whefs_string_init; // prevent client from cleaning it. | < | ||
| 261 | } | 249 | } | |
| 262 | //WHEFS_DBG("whefs_inode_id_read() found opened entry #%"WHEFS_ID_TYPE_PFMT" to read.", n->id); | 250 | //WHEFS_DBG("whefs_inode_id_read() found opened entry #%"WHEFS_ID_TYPE_PFMT" to read.", n->id); | |
| 263 | return whefs_rc.OK; | 251 | return whefs_rc.OK; | |
| 264 | } | 252 | } | |
| 265 | } | 253 | } | |
| 249 hidden lines | ||||
| 515 | { | 503 | { | |
| 516 | whefs_inode_list_free(ent); | 504 | whefs_inode_list_free(ent); | |
| 517 | WHEFS_DBG_ERR("Opening inode #%"WHEFS_ID_TYPE_PFMT" FAILED - whefs_inode_id_read() returned %d", ent->inode.id, rc ); | 505 | WHEFS_DBG_ERR("Opening inode #%"WHEFS_ID_TYPE_PFMT" FAILED - whefs_inode_id_read() returned %d", ent->inode.id, rc ); | |
| 518 | return rc; | 506 | return rc; | |
| 519 | } | 507 | } | |
| 520 | rc = whefs_inode_name_get( fs, ent->inode.id, &ent->inode.name ); | < | ||
| 521 | if( whefs_rc.OK != rc ) | < | ||
| 522 | { | < | ||
| 523 | whefs_inode_list_free(ent); | < | ||
| 524 | WHEFS_DBG_ERR("Opening inode #%"WHEFS_ID_TYPE_PFMT" FAILED - whefs_inode_name_get() returned %d", ent->inode.id, rc ); | < | ||
| 525 | return rc; | < | ||
| 526 | } | < | ||
| 527 | //WHEFS_DBG("Opened inode #%"WHEFS_ID_TYPE_PFMT" with name [%s]", ent->inode.id, ent->inode.name.string ); | 508 | //WHEFS_DBG("Opened inode #%"WHEFS_ID_TYPE_PFMT" with name [%s]", ent->inode.id, ent->inode.name.string ); | |
| 528 | x = &ent->inode; | 509 | x = &ent->inode; | |
| 529 | x->writer = writer; | 510 | x->writer = writer; | |
| 530 | whefs_inode_list * li = fs->opened_nodes; | 511 | whefs_inode_list * li = fs->opened_nodes; | |
| 531 | if( ! li ) | 512 | if( ! li ) | |
| 69 hidden lines | ||||
| 601 | --np->open_count; | 582 | --np->open_count; | |
| 602 | if( 0 == np->open_count ) | 583 | if( 0 == np->open_count ) | |
| 603 | { | 584 | { | |
| 604 | if(0) WHEFS_DBG_FYI("REALLY closing inode #%"WHEFS_ID_TYPE_PFMT": Use count=%u, data size=%u", | 585 | if(0) WHEFS_DBG_FYI("REALLY closing inode #%"WHEFS_ID_TYPE_PFMT": Use count=%u, data size=%u", | |
| 605 | src->id, src->open_count, src->data_size ); | 586 | src->id, src->open_count, src->data_size ); | |
| 606 | whefs_string_clear( &np->name, false ); | < | ||
| 607 | if( li == fs->opened_nodes ) fs->opened_nodes = (li->next ? li->next : li->prev); | 587 | if( li == fs->opened_nodes ) fs->opened_nodes = (li->next ? li->next : li->prev); | |
| 608 | if( li->prev ) li->prev->next = li->next; | 588 | if( li->prev ) li->prev->next = li->next; | |
| 609 | if( li->next ) li->next->prev = li->prev; | 589 | if( li->next ) li->next->prev = li->prev; | |
| 610 | if( np->blocks.list ) | 590 | if( np->blocks.list ) | |
| 611 | { | 591 | { | |
| 228 hidden lines | ||||
| 840 | x += whefs_sizeof_encoded_uint32; | 820 | x += whefs_sizeof_encoded_uint32; | |
| 841 | rc = whefs_id_decode( x, &dest->first_block ); | 821 | rc = whefs_id_decode( x, &dest->first_block ); | |
| 842 | return rc; | 822 | return rc; | |
| 843 | } | 823 | } | |
| 844 | 824 | |||
Changes to whefs_inode.h
| Old (5d5be8cd2a102fc6) | New (27291146b8c79f6f) | |||
|---|---|---|---|---|
| 1 | #if !defined(WANDERINGHORSE_NET_WHEFS_INODE_H_INCLUDED) | 1 | #if !defined(WANDERINGHORSE_NET_WHEFS_INODE_H_INCLUDED) | |
| 2 | #define WANDERINGHORSE_NET_WHEFS_INODE_H_INCLUDED 1 | 2 | #define WANDERINGHORSE_NET_WHEFS_INODE_H_INCLUDED 1 | |
| 3 | /* | 3 | /* | |
| 4 | Author: Stephan Beal (http://wanderinghorse.net/home/stephan/ | 4 | Author: Stephan Beal (http://wanderinghorse.net/home/stephan/ | |
| 5 | 5 | |||
| 137 hidden lines | ||||
| 143 | memory. This saves boatloads of i/o for common use cases. | 143 | memory. This saves boatloads of i/o for common use cases. | |
| 144 | Transient. | 144 | Transient. | |
| 145 | */ | 145 | */ | |
| 146 | whefs_block_list blocks; | 146 | whefs_block_list blocks; | |
| 147 | /** Transient string used only by opened nodes. */ | 147 | /** Transient string used only by opened nodes. */ | |
| 148 | whefs_string name; | | | 148 | //whefs_string name; |
| 149 | } whefs_inode; | 149 | } whefs_inode; | |
| 150 | 150 | |||
| 151 | /** Empty inode initialization object. */ | 151 | /** Empty inode initialization object. */ | |
| 152 | #define whefs_inode_init_m { \ | 152 | #define whefs_inode_init_m { \ | |
| 153 | 0, /* id */ \ | 153 | 0, /* id */ \ | |
| 155 | 0, /* first_block */ \ | 155 | 0, /* first_block */ \ | |
| 156 | 0, /* data_size */ \ | 156 | 0, /* data_size */ \ | |
| 157 | 0, /* mtime */ \ | 157 | 0, /* mtime */ \ | |
| 158 | 0, /* open_count */ \ | 158 | 0, /* open_count */ \ | |
| 159 | 0, /* writer */ \ | 159 | 0, /* writer */ \ | |
| 160 | whefs_block_list_init_m /*blocks */, \ | | | 160 | whefs_block_list_init_m /*blocks */ \ |
| 161 | whefs_string_init_m /* name */ \ | | | 161 | /* whefs_string_init_m name */ \ |
| 162 | } | 162 | } | |
| 163 | 163 | |||
| 164 | /** Empty inode initialization object. */ | 164 | /** Empty inode initialization object. */ | |
| 165 | extern const whefs_inode whefs_inode_init; | 165 | extern const whefs_inode whefs_inode_init; | |
| 166 | 166 | |||
| 444 hidden lines | ||||
| 611 | } /* extern "C" */ | 611 | } /* extern "C" */ | |
| 612 | #endif | 612 | #endif | |
| 613 | 613 | |||
| 614 | 614 | |||
| 615 | #endif /* WANDERINGHORSE_NET_WHEFS_INODE_H_INCLUDED */ | 615 | #endif /* WANDERINGHORSE_NET_WHEFS_INODE_H_INCLUDED */ | |