Changes in uspace/srv/fs/fat/fat_ops.c [dfddfcd:2ffaab5] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/fs/fat/fat_ops.c
rdfddfcd r2ffaab5 52 52 #include <adt/list.h> 53 53 #include <assert.h> 54 #include <fibril_sync .h>54 #include <fibril_synch.h> 55 55 #include <sys/mman.h> 56 56 #include <align.h> … … 71 71 static int fat_match(fs_node_t **, fs_node_t *, const char *); 72 72 static int fat_node_get(fs_node_t **, dev_handle_t, fs_index_t); 73 static int fat_node_open(fs_node_t *); 73 74 static int fat_node_put(fs_node_t *); 74 75 static int fat_create_node(fs_node_t **, dev_handle_t, int); … … 83 84 static bool fat_is_directory(fs_node_t *); 84 85 static bool fat_is_file(fs_node_t *node); 86 static dev_handle_t fat_device_get(fs_node_t *node); 85 87 86 88 /* … … 288 290 289 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 /* Check signature of each FAT. */ 329 330 for (fat_no = 0; fat_no < bs->fatcnt; fat_no++) { 331 rc = fat_get_cluster(bs, dev_handle, fat_no, 0, &e0); 332 if (rc != EOK) 333 return EIO; 334 335 rc = fat_get_cluster(bs, dev_handle, fat_no, 1, &e1); 336 if (rc != EOK) 337 return EIO; 338 339 /* Check that first byte of FAT contains the media descriptor. */ 340 if ((e0 & 0xff) != bs->mdesc) 341 return ENOTSUP; 342 343 /* 344 * Check that remaining bits of the first two entries are 345 * set to one. 346 */ 347 if ((e0 >> 8) != 0xff || e1 != 0xffff) 348 return ENOTSUP; 349 } 350 290 351 return EOK; 291 352 } … … 407 468 } 408 469 470 int fat_node_open(fs_node_t *fn) 471 { 472 /* 473 * Opening a file is stateless, nothing 474 * to be done here. 475 */ 476 return EOK; 477 } 478 409 479 int fat_node_put(fs_node_t *fn) 410 480 { … … 867 937 } 868 938 939 dev_handle_t fat_device_get(fs_node_t *node) 940 { 941 return 0; 942 } 943 869 944 /** libfs operations */ 870 945 libfs_ops_t fat_libfs_ops = { … … 872 947 .match = fat_match, 873 948 .node_get = fat_node_get, 949 .node_open = fat_node_open, 874 950 .node_put = fat_node_put, 875 951 .create = fat_create_node, … … 881 957 .size_get = fat_size_get, 882 958 .lnkcnt_get = fat_lnkcnt_get, 883 .plb_get_char = 959 .plb_get_char = fat_plb_get_char, 884 960 .is_directory = fat_is_directory, 885 .is_file = fat_is_file 961 .is_file = fat_is_file, 962 .device_get = fat_device_get 886 963 }; 887 964 … … 957 1034 /* Initialize the block cache */ 958 1035 rc = block_cache_init(dev_handle, bps, 0 /* XXX */, cmode); 1036 if (rc != EOK) { 1037 block_fini(dev_handle); 1038 ipc_answer_0(rid, rc); 1039 return; 1040 } 1041 1042 /* Do some simple sanity checks on the file system. */ 1043 rc = fat_sanity_check(bs, dev_handle); 959 1044 if (rc != EOK) { 960 1045 block_fini(dev_handle);
Note:
See TracChangeset
for help on using the changeset viewer.