Changeset 3298ddc in mainline
- Timestamp:
- 2008-03-06T22:33:27Z (17 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- d5d9c53
- Parents:
- 739d00a
- Location:
- uspace
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/libfs/libfs.c
r739d00a r3298ddc 176 176 177 177 /* match the component */ 178 while (tmp && !ops->match( tmp, component))178 while (tmp && !ops->match(cur, tmp, component)) 179 179 tmp = ops->sibling_get(tmp); 180 180 -
uspace/lib/libfs/libfs.h
r739d00a r3298ddc 43 43 44 44 typedef struct { 45 bool (* match)(void *, const char *);45 bool (* match)(void *, void *, const char *); 46 46 void * (* create)(int); 47 47 void (* destroy)(void *); -
uspace/srv/fs/tmpfs/tmpfs.h
r739d00a r3298ddc 48 48 struct tmpfs_dentry *sibling; 49 49 struct tmpfs_dentry *child; 50 char *name;50 hash_table_t names; /**< All names linking to this TMPFS node. */ 51 51 enum { 52 52 TMPFS_NONE, -
uspace/srv/fs/tmpfs/tmpfs_ops.c
r739d00a r3298ddc 57 57 #define DENTRIES_BUCKETS 256 58 58 59 #define NAMES_BUCKETS 4 60 59 61 /* 60 62 * For now, we don't distinguish between different dev_handles/instances. All … … 68 70 69 71 /* Forward declarations of static functions. */ 70 static bool tmpfs_match(void *, const char *);72 static bool tmpfs_match(void *, void *, const char *); 71 73 static void *tmpfs_create_node(int); 72 74 static bool tmpfs_link_node(void *, void *, const char *); … … 141 143 hash_table_t dentries; 142 144 143 /* Implementation of hash table interface . */145 /* Implementation of hash table interface for the dentries hash table. */ 144 146 static hash_index_t dentries_hash(unsigned long *key) 145 147 { … … 168 170 unsigned tmpfs_next_index = 1; 169 171 170 static void tmpfs_dentry_initialize(tmpfs_dentry_t *dentry) 172 typedef struct { 173 char *name; 174 tmpfs_dentry_t *parent; 175 link_t link; 176 } tmpfs_name_t; 177 178 /* Implementation of hash table interface for the names hash table. */ 179 static hash_index_t names_hash(unsigned long *key) 180 { 181 tmpfs_dentry_t *dentry = (tmpfs_dentry_t *) *key; 182 return dentry->index % NAMES_BUCKETS; 183 } 184 185 static int names_compare(unsigned long *key, hash_count_t keys, link_t *item) 186 { 187 tmpfs_dentry_t *dentry = (tmpfs_dentry_t *) *key; 188 tmpfs_name_t *namep = hash_table_get_instance(item, tmpfs_name_t, 189 link); 190 return dentry == namep->parent; 191 } 192 193 static void names_remove_callback(link_t *item) 194 { 195 tmpfs_name_t *namep = hash_table_get_instance(item, tmpfs_name_t, 196 link); 197 free(namep->name); 198 free(namep); 199 } 200 201 /** TMPFS node names hash table operations. */ 202 static hash_table_operations_t names_ops = { 203 .hash = names_hash, 204 .compare = names_compare, 205 .remove_callback = names_remove_callback 206 }; 207 208 static void tmpfs_name_initialize(tmpfs_name_t *namep) 209 { 210 namep->name = NULL; 211 namep->parent = NULL; 212 link_initialize(&namep->link); 213 } 214 215 static bool tmpfs_dentry_initialize(tmpfs_dentry_t *dentry) 171 216 { 172 217 dentry->index = 0; 173 218 dentry->sibling = NULL; 174 219 dentry->child = NULL; 175 dentry->name = NULL;176 220 dentry->type = TMPFS_NONE; 177 221 dentry->lnkcnt = 0; … … 179 223 dentry->data = NULL; 180 224 link_initialize(&dentry->dh_link); 225 return (bool)hash_table_create(&dentry->names, NAMES_BUCKETS, 1, 226 &names_ops); 181 227 } 182 228 … … 186 232 return false; 187 233 root = (tmpfs_dentry_t *) tmpfs_create_node(L_DIRECTORY); 234 if (!root) { 235 hash_table_destroy(&dentries); 236 return false; 237 } 188 238 root->lnkcnt = 1; 189 return root != NULL;239 return true; 190 240 } 191 241 192 242 /** Compare one component of path to a directory entry. 193 243 * 194 * @param nodep Node to compare the path component with. 244 * @param prnt Node from which we descended. 245 * @param chld Node to compare the path component with. 195 246 * @param component Array of characters holding component name. 196 247 * 197 248 * @return True on match, false otherwise. 198 249 */ 199 bool tmpfs_match(void *nodep, const char *component) 200 { 201 tmpfs_dentry_t *dentry = (tmpfs_dentry_t *) nodep; 202 203 return !strcmp(dentry->name, component); 250 bool tmpfs_match(void *prnt, void *chld, const char *component) 251 { 252 tmpfs_dentry_t *parentp = (tmpfs_dentry_t *) prnt; 253 tmpfs_dentry_t *childp = (tmpfs_dentry_t *) chld; 254 255 unsigned long key = (unsigned long) parentp; 256 link_t *hlp = hash_table_find(&childp->names, &key); 257 assert(hlp); 258 tmpfs_name_t *namep = hash_table_get_instance(hlp, tmpfs_name_t, link); 259 260 return !strcmp(namep->name, component); 204 261 } 205 262 … … 212 269 return NULL; 213 270 214 tmpfs_dentry_initialize(node); 271 if (!tmpfs_dentry_initialize(node)) { 272 free(node); 273 return NULL; 274 } 215 275 node->index = tmpfs_next_index++; 216 276 if (lflag & L_DIRECTORY) … … 231 291 assert(parentp->type == TMPFS_DIRECTORY); 232 292 293 tmpfs_name_t *namep = malloc(sizeof(tmpfs_name_t)); 294 if (!namep) 295 return false; 296 tmpfs_name_initialize(namep); 233 297 size_t len = strlen(nm); 234 char *name = malloc(len + 1); 235 if (!name) 298 namep->name = malloc(len + 1); 299 if (!namep->name) { 300 free(namep); 236 301 return false; 302 } 303 strcpy(namep->name, nm); 304 namep->parent = parentp; 237 305 238 306 childp->lnkcnt++; 239 240 strcpy(name, nm);241 childp->name = name;307 308 unsigned long key = (unsigned long) parentp; 309 hash_table_insert(&childp->names, &key, &namep->link); 242 310 243 311 /* Insert the new node into the namespace. */ … … 276 344 childp->sibling = NULL; 277 345 278 free(childp->name);279 childp->name = NULL;346 unsigned long key = (unsigned long) parentp; 347 hash_table_remove(&childp->names, &key, 1); 280 348 281 349 childp->lnkcnt--; … … 294 362 unsigned long index = dentry->index; 295 363 hash_table_remove(&dentries, &index, 1); 364 365 hash_table_destroy(&dentry->names); 296 366 297 367 if (dentry->type == TMPFS_FILE) … … 365 435 } 366 436 367 (void) ipc_data_read_finalize(callid, cur->name, 368 strlen(cur->name) + 1); 437 unsigned long key = (unsigned long) dentry; 438 link_t *hlp = hash_table_find(&cur->names, &key); 439 assert(hlp); 440 tmpfs_name_t *namep = hash_table_get_instance(hlp, tmpfs_name_t, 441 link); 442 443 (void) ipc_data_read_finalize(callid, namep->name, 444 strlen(namep->name) + 1); 369 445 bytes = 1; 370 446 }
Note:
See TracChangeset
for help on using the changeset viewer.