Changeset b79d450 in mainline for uspace/srv/fs
- Timestamp:
- 2010-01-27T20:35:49Z (16 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- fb6f1a5
- Parents:
- fccc236 (diff), 95e6c4f (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)links above to see all the changes relative to each parent. - Location:
- uspace/srv/fs
- Files:
-
- 6 deleted
- 14 edited
-
devfs/Makefile (modified) (1 diff)
-
devfs/Makefile.build (deleted)
-
devfs/Makefile.common (deleted)
-
devfs/devfs.c (modified) (1 diff)
-
devfs/devfs_ops.c (modified) (1 diff)
-
devfs/devfs_ops.h (modified) (1 diff)
-
fat/Makefile (modified) (1 diff)
-
fat/Makefile.build (deleted)
-
fat/Makefile.common (deleted)
-
fat/fat.c (modified) (1 diff)
-
fat/fat.h (modified) (1 diff)
-
fat/fat_fat.c (modified) (5 diffs)
-
fat/fat_fat.h (modified) (1 diff)
-
fat/fat_ops.c (modified) (3 diffs)
-
tmpfs/Makefile (modified) (1 diff)
-
tmpfs/Makefile.build (deleted)
-
tmpfs/Makefile.common (deleted)
-
tmpfs/tmpfs.c (modified) (1 diff)
-
tmpfs/tmpfs.h (modified) (1 diff)
-
tmpfs/tmpfs_ops.c (modified) (13 diffs)
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/fs/devfs/Makefile
rfccc236 rb79d450 28 28 # 29 29 30 include Makefile.common 30 USPACE_PREFIX = ../../.. 31 LIBS = $(LIBFS_PREFIX)/libfs.a $(LIBC_PREFIX)/libc.a 32 EXTRA_CFLAGS += -I$(LIBFS_PREFIX) 31 33 32 .PHONY: all clean 34 OUTPUT = devfs 33 35 34 all: $(LIBC_PREFIX)/../../../Makefile.config $(LIBC_PREFIX)/../../../config.h $(LIBC_PREFIX)/../../../config.defs $(LIBS) 35 -[ -f $(DEPEND) ] && mv -f $(DEPEND) $(DEPEND_PREV)36 $(MAKE) -f Makefile.build PRECHECK=$(PRECHECK)36 SOURCES = \ 37 devfs.c \ 38 devfs_ops.c 37 39 38 clean: 39 rm -f $(DEPEND) $(DEPEND_PREV) $(JOB) $(OUTPUT) $(OUTPUT).map $(OUTPUT).disasm 40 find . -name '*.o' -follow -exec rm \{\} \; 40 include ../../Makefile.common -
uspace/srv/fs/devfs/devfs.c
rfccc236 rb79d450 75 75 devfs_mount(callid, &call); 76 76 break; 77 case VFS_OUT_UNMOUNTED: 78 devfs_unmounted(callid, &call); 79 break; 80 case VFS_OUT_UNMOUNT: 81 devfs_unmount(callid, &call); 82 break; 77 83 case VFS_OUT_LOOKUP: 78 84 devfs_lookup(callid, &call); -
uspace/srv/fs/devfs/devfs_ops.c
rfccc236 rb79d450 434 434 } 435 435 436 void devfs_unmounted(ipc_callid_t rid, ipc_call_t *request) 437 { 438 ipc_answer_0(rid, ENOTSUP); 439 } 440 441 void devfs_unmount(ipc_callid_t rid, ipc_call_t *request) 442 { 443 libfs_unmount(&devfs_libfs_ops, rid, request); 444 } 445 436 446 void devfs_lookup(ipc_callid_t rid, ipc_call_t *request) 437 447 { -
uspace/srv/fs/devfs/devfs_ops.h
rfccc236 rb79d450 41 41 extern void devfs_mounted(ipc_callid_t, ipc_call_t *); 42 42 extern void devfs_mount(ipc_callid_t, ipc_call_t *); 43 extern void devfs_unmounted(ipc_callid_t, ipc_call_t *); 44 extern void devfs_unmount(ipc_callid_t, ipc_call_t *); 43 45 extern void devfs_lookup(ipc_callid_t, ipc_call_t *); 44 46 extern void devfs_open_node(ipc_callid_t, ipc_call_t *); -
uspace/srv/fs/fat/Makefile
rfccc236 rb79d450 28 28 # 29 29 30 include Makefile.common 30 USPACE_PREFIX = ../../.. 31 LIBS = $(LIBBLOCK_PREFIX)/libblock.a $(LIBFS_PREFIX)/libfs.a $(LIBC_PREFIX)/libc.a 32 EXTRA_CFLAGS += -I$(LIBBLOCK_PREFIX) -I$(LIBFS_PREFIX) 31 33 32 .PHONY: all clean 34 OUTPUT = fat 33 35 34 all: $(LIBC_PREFIX)/../../../Makefile.config $(LIBC_PREFIX)/../../../config.h $(LIBC_PREFIX)/../../../config.defs $(LIBS) 35 -[ -f $(DEPEND) ] && mv -f $(DEPEND) $(DEPEND_PREV) 36 $(MAKE) -f Makefile.build PRECHECK=$(PRECHECK) 36 SOURCES = \ 37 fat.c \ 38 fat_ops.c \ 39 fat_idx.c \ 40 fat_dentry.c \ 41 fat_fat.c 37 42 38 clean: 39 rm -f $(DEPEND) $(DEPEND_PREV) $(JOB) $(OUTPUT) $(OUTPUT).map $(OUTPUT).disasm 40 find . -name '*.o' -follow -exec rm \{\} \; 43 include ../../Makefile.common -
uspace/srv/fs/fat/fat.c
rfccc236 rb79d450 100 100 fat_mount(callid, &call); 101 101 break; 102 case VFS_OUT_UNMOUNTED: 103 fat_unmounted(callid, &call); 104 break; 105 case VFS_OUT_UNMOUNT: 106 fat_unmount(callid, &call); 107 break; 102 108 case VFS_OUT_LOOKUP: 103 109 fat_lookup(callid, &call); -
uspace/srv/fs/fat/fat.h
rfccc236 rb79d450 204 204 extern void fat_mounted(ipc_callid_t, ipc_call_t *); 205 205 extern void fat_mount(ipc_callid_t, ipc_call_t *); 206 extern void fat_unmounted(ipc_callid_t, ipc_call_t *); 207 extern void fat_unmount(ipc_callid_t, ipc_call_t *); 206 208 extern void fat_lookup(ipc_callid_t, ipc_call_t *); 207 209 extern void fat_read(ipc_callid_t, ipc_call_t *); -
uspace/srv/fs/fat/fat_fat.c
rfccc236 rb79d450 247 247 */ 248 248 int 249 fat_get_cluster(fat_bs_t *bs, dev_handle_t dev_handle, fat_cluster_t clst,250 fat_cluster_t *value)249 fat_get_cluster(fat_bs_t *bs, dev_handle_t dev_handle, unsigned fatno, 250 fat_cluster_t clst, fat_cluster_t *value) 251 251 { 252 252 block_t *b; 253 253 uint16_t bps; 254 254 uint16_t rscnt; 255 uint16_t sf; 255 256 fat_cluster_t *cp; 256 257 int rc; … … 258 259 bps = uint16_t_le2host(bs->bps); 259 260 rscnt = uint16_t_le2host(bs->rscnt); 260 261 rc = block_get(&b, dev_handle, rscnt + 261 sf = uint16_t_le2host(bs->sec_per_fat); 262 263 rc = block_get(&b, dev_handle, rscnt + sf * fatno + 262 264 (clst * sizeof(fat_cluster_t)) / bps, BLOCK_FLAGS_NONE); 263 265 if (rc != EOK) … … 398 400 * from the size of the file allocation table. 399 401 */ 400 if ((cl - 2) * bs->spc + ssa >= ts) {402 if ((cl >= 2) && ((cl - 2) * bs->spc + ssa >= ts)) { 401 403 rc = block_put(blk); 402 404 if (rc != EOK) … … 480 482 while (firstc < FAT_CLST_LAST1) { 481 483 assert(firstc >= FAT_CLST_FIRST && firstc < FAT_CLST_BAD); 482 rc = fat_get_cluster(bs, dev_handle, firstc, &nextc);484 rc = fat_get_cluster(bs, dev_handle, FAT1, firstc, &nextc); 483 485 if (rc != EOK) 484 486 return rc; … … 560 562 unsigned fatno; 561 563 562 rc = fat_get_cluster(bs, dev_handle, lastc, &nextc);564 rc = fat_get_cluster(bs, dev_handle, FAT1, lastc, &nextc); 563 565 if (rc != EOK) 564 566 return rc; -
uspace/srv/fs/fat/fat_fat.h
rfccc236 rb79d450 80 80 extern int fat_alloc_shadow_clusters(struct fat_bs *, dev_handle_t, 81 81 fat_cluster_t *, unsigned); 82 extern int fat_get_cluster(struct fat_bs *, dev_handle_t, fat_cluster_t,83 fat_cluster_t *);82 extern int fat_get_cluster(struct fat_bs *, dev_handle_t, unsigned, 83 fat_cluster_t, fat_cluster_t *); 84 84 extern int fat_set_cluster(struct fat_bs *, dev_handle_t, unsigned, 85 85 fat_cluster_t, fat_cluster_t); -
uspace/srv/fs/fat/fat_ops.c
rfccc236 rb79d450 290 290 291 291 *nodepp = nodep; 292 return EOK; 293 } 294 295 /** Perform basic sanity checks on the file system. 296 * 297 * Verify if values of boot sector fields are sane. Also verify media 298 * descriptor. This is used to rule out cases when a device obviously 299 * does not contain a fat file system. 300 */ 301 static int fat_sanity_check(fat_bs_t *bs, dev_handle_t dev_handle) 302 { 303 fat_cluster_t e0, e1; 304 unsigned fat_no; 305 int rc; 306 307 /* Check number of FATs. */ 308 if (bs->fatcnt == 0) 309 return ENOTSUP; 310 311 /* Check total number of sectors. */ 312 313 if (bs->totsec16 == 0 && bs->totsec32 == 0) 314 return ENOTSUP; 315 316 if (bs->totsec16 != 0 && bs->totsec32 != 0 && 317 bs->totsec16 != bs->totsec32) 318 return ENOTSUP; 319 320 /* Check media descriptor. Must be between 0xf0 and 0xff. */ 321 if ((bs->mdesc & 0xf0) != 0xf0) 322 return ENOTSUP; 323 324 /* Check number of sectors per FAT. */ 325 if (bs->sec_per_fat == 0) 326 return ENOTSUP; 327 328 /* 329 * Check that the root directory entries take up whole blocks. 330 * This check is rather strict, but it allows us to treat the root 331 * directory and non-root directories uniformly in some places. 332 * It can be removed provided that functions such as fat_read() are 333 * sanitized to support file systems with this property. 334 */ 335 if ((uint16_t_le2host(bs->root_ent_max) * sizeof(fat_dentry_t)) % 336 uint16_t_le2host(bs->bps) != 0) 337 return ENOTSUP; 338 339 /* Check signature of each FAT. */ 340 341 for (fat_no = 0; fat_no < bs->fatcnt; fat_no++) { 342 rc = fat_get_cluster(bs, dev_handle, fat_no, 0, &e0); 343 if (rc != EOK) 344 return EIO; 345 346 rc = fat_get_cluster(bs, dev_handle, fat_no, 1, &e1); 347 if (rc != EOK) 348 return EIO; 349 350 /* Check that first byte of FAT contains the media descriptor. */ 351 if ((e0 & 0xff) != bs->mdesc) 352 return ENOTSUP; 353 354 /* 355 * Check that remaining bits of the first two entries are 356 * set to one. 357 */ 358 if ((e0 >> 8) != 0xff || e1 != 0xffff) 359 return ENOTSUP; 360 } 361 292 362 return EOK; 293 363 } … … 981 1051 } 982 1052 1053 /* Do some simple sanity checks on the file system. */ 1054 rc = fat_sanity_check(bs, dev_handle); 1055 if (rc != EOK) { 1056 block_fini(dev_handle); 1057 ipc_answer_0(rid, rc); 1058 return; 1059 } 1060 983 1061 rc = fat_idx_init_by_dev_handle(dev_handle); 984 1062 if (rc != EOK) { … … 1037 1115 { 1038 1116 libfs_mount(&fat_libfs_ops, fat_reg.fs_handle, rid, request); 1117 } 1118 1119 void fat_unmounted(ipc_callid_t rid, ipc_call_t *request) 1120 { 1121 ipc_answer_0(rid, ENOTSUP); 1122 } 1123 1124 void fat_unmount(ipc_callid_t rid, ipc_call_t *request) 1125 { 1126 libfs_unmount(&fat_libfs_ops, rid, request); 1039 1127 } 1040 1128 -
uspace/srv/fs/tmpfs/Makefile
rfccc236 rb79d450 28 28 # 29 29 30 include Makefile.common 30 USPACE_PREFIX = ../../.. 31 LIBS = $(LIBBLOCK_PREFIX)/libblock.a $(LIBFS_PREFIX)/libfs.a $(LIBC_PREFIX)/libc.a 32 EXTRA_CFLAGS += -I$(LIBBLOCK_PREFIX) -I$(LIBFS_PREFIX) 31 33 32 .PHONY: all clean 34 OUTPUT = tmpfs 33 35 34 all: $(LIBC_PREFIX)/../../../Makefile.config $(LIBC_PREFIX)/../../../config.h $(LIBC_PREFIX)/../../../config.defs $(LIBS) 35 -[ -f $(DEPEND) ] && mv -f $(DEPEND) $(DEPEND_PREV) 36 $(MAKE) -f Makefile.build PRECHECK=$(PRECHECK) 36 SOURCES = \ 37 tmpfs.c \ 38 tmpfs_ops.c \ 39 tmpfs_dump.c 37 40 38 clean: 39 rm -f $(DEPEND) $(DEPEND_PREV) $(JOB) $(OUTPUT) $(OUTPUT).map $(OUTPUT).disasm 40 find . -name '*.o' -follow -exec rm \{\} \; 41 include ../../Makefile.common -
uspace/srv/fs/tmpfs/tmpfs.c
rfccc236 rb79d450 106 106 tmpfs_mount(callid, &call); 107 107 break; 108 case VFS_OUT_UNMOUNTED: 109 tmpfs_unmounted(callid, &call); 110 break; 111 case VFS_OUT_UNMOUNT: 112 tmpfs_unmount(callid, &call); 113 break; 108 114 case VFS_OUT_LOOKUP: 109 115 tmpfs_lookup(callid, &call); -
uspace/srv/fs/tmpfs/tmpfs.h
rfccc236 rb79d450 83 83 extern void tmpfs_mounted(ipc_callid_t, ipc_call_t *); 84 84 extern void tmpfs_mount(ipc_callid_t, ipc_call_t *); 85 extern void tmpfs_unmounted(ipc_callid_t, ipc_call_t *); 86 extern void tmpfs_unmount(ipc_callid_t, ipc_call_t *); 85 87 extern void tmpfs_lookup(ipc_callid_t, ipc_call_t *); 86 88 extern void tmpfs_read(ipc_callid_t, ipc_call_t *); -
uspace/srv/fs/tmpfs/tmpfs_ops.c
rfccc236 rb79d450 147 147 hash_table_t nodes; 148 148 149 #define NODES_KEY_ INDEX 0150 #define NODES_KEY_ DEV1149 #define NODES_KEY_DEV 0 150 #define NODES_KEY_INDEX 1 151 151 152 152 /* Implementation of hash table interface for the nodes hash table. */ … … 160 160 tmpfs_node_t *nodep = hash_table_get_instance(item, tmpfs_node_t, 161 161 nh_link); 162 return (nodep->index == key[NODES_KEY_INDEX] && 163 nodep->dev_handle == key[NODES_KEY_DEV]); 162 163 switch (keys) { 164 case 1: 165 return (nodep->dev_handle == key[NODES_KEY_DEV]); 166 case 2: 167 return ((nodep->dev_handle == key[NODES_KEY_DEV]) && 168 (nodep->index == key[NODES_KEY_INDEX])); 169 default: 170 abort(); 171 } 164 172 } 165 173 166 174 static void nodes_remove_callback(link_t *item) 167 175 { 176 tmpfs_node_t *nodep = hash_table_get_instance(item, tmpfs_node_t, 177 nh_link); 178 179 while (!list_empty(&nodep->cs_head)) { 180 tmpfs_dentry_t *dentryp = list_get_instance(nodep->cs_head.next, 181 tmpfs_dentry_t, link); 182 183 assert(nodep->type == TMPFS_DIRECTORY); 184 list_remove(&dentryp->link); 185 free(dentryp); 186 } 187 188 if (nodep->data) { 189 assert(nodep->type == TMPFS_FILE); 190 free(nodep->data); 191 } 192 free(nodep->bp); 193 free(nodep); 168 194 } 169 195 … … 215 241 } 216 242 243 static void tmpfs_instance_done(dev_handle_t dev_handle) 244 { 245 unsigned long key[] = { 246 [NODES_KEY_DEV] = dev_handle 247 }; 248 /* 249 * Here we are making use of one special feature of our hash table 250 * implementation, which allows to remove more items based on a partial 251 * key match. In the following, we are going to remove all nodes 252 * matching our device handle. The nodes_remove_callback() function will 253 * take care of resource deallocation. 254 */ 255 hash_table_remove(&nodes, key, 1); 256 } 257 217 258 int tmpfs_match(fs_node_t **rfn, fs_node_t *pfn, const char *component) 218 259 { … … 237 278 { 238 279 unsigned long key[] = { 239 [NODES_KEY_ INDEX] = index,240 [NODES_KEY_ DEV] = dev_handle280 [NODES_KEY_DEV] = dev_handle, 281 [NODES_KEY_INDEX] = index 241 282 }; 242 283 link_t *lnk = hash_table_find(&nodes, key); … … 296 337 /* Insert the new node into the nodes hash table. */ 297 338 unsigned long key[] = { 298 [NODES_KEY_ INDEX] = nodep->index,299 [NODES_KEY_ DEV] = nodep->dev_handle339 [NODES_KEY_DEV] = nodep->dev_handle, 340 [NODES_KEY_INDEX] = nodep->index 300 341 }; 301 342 hash_table_insert(&nodes, key, &nodep->nh_link); … … 312 353 313 354 unsigned long key[] = { 314 [NODES_KEY_ INDEX] = nodep->index,315 [NODES_KEY_ DEV] = nodep->dev_handle355 [NODES_KEY_DEV] = nodep->dev_handle, 356 [NODES_KEY_INDEX] = nodep->index 316 357 }; 317 358 hash_table_remove(&nodes, key, 2); 318 359 319 if (nodep->type == TMPFS_FILE)320 free(nodep->data);321 free(nodep->bp);322 free(nodep);360 /* 361 * The nodes_remove_callback() function takes care of the actual 362 * resource deallocation. 363 */ 323 364 return EOK; 324 365 } … … 424 465 /* Initialize TMPFS instance. */ 425 466 if (!tmpfs_instance_init(dev_handle)) { 467 free(opts); 426 468 ipc_answer_0(rid, ENOMEM); 427 469 return; … … 442 484 rootp->lnkcnt); 443 485 } 486 free(opts); 444 487 } 445 488 … … 447 490 { 448 491 libfs_mount(&tmpfs_libfs_ops, tmpfs_reg.fs_handle, rid, request); 492 } 493 494 void tmpfs_unmounted(ipc_callid_t rid, ipc_call_t *request) 495 { 496 dev_handle_t dev_handle = (dev_handle_t) IPC_GET_ARG1(*request); 497 498 tmpfs_instance_done(dev_handle); 499 ipc_answer_0(rid, EOK); 500 } 501 502 void tmpfs_unmount(ipc_callid_t rid, ipc_call_t *request) 503 { 504 libfs_unmount(&tmpfs_libfs_ops, rid, request); 449 505 } 450 506 … … 465 521 link_t *hlp; 466 522 unsigned long key[] = { 467 [NODES_KEY_INDEX] = index,468 523 [NODES_KEY_DEV] = dev_handle, 524 [NODES_KEY_INDEX] = index 469 525 }; 470 526 hlp = hash_table_find(&nodes, key); … … 539 595 link_t *hlp; 540 596 unsigned long key[] = { 541 [NODES_KEY_ INDEX] = index,542 [NODES_KEY_ DEV] = dev_handle597 [NODES_KEY_DEV] = dev_handle, 598 [NODES_KEY_INDEX] = index 543 599 }; 544 600 hlp = hash_table_find(&nodes, key); … … 603 659 link_t *hlp; 604 660 unsigned long key[] = { 605 [NODES_KEY_ INDEX] = index,606 [NODES_KEY_ DEV] = dev_handle661 [NODES_KEY_DEV] = dev_handle, 662 [NODES_KEY_INDEX] = index 607 663 }; 608 664 hlp = hash_table_find(&nodes, key); … … 646 702 link_t *hlp; 647 703 unsigned long key[] = { 648 [NODES_KEY_ INDEX] = index,649 [NODES_KEY_ DEV] = dev_handle704 [NODES_KEY_DEV] = dev_handle, 705 [NODES_KEY_INDEX] = index 650 706 }; 651 707 hlp = hash_table_find(&nodes, key);
Note:
See TracChangeset
for help on using the changeset viewer.
