📄 fat_sup.c
字号:
} pathloc->node_access = node; break; case FAT_NAME: node = pathloc->node_access; if ( !node ) set_errno_and_return_minus_one( ENOTDIR ); /* * Only a directory can be decended into. */ if ( node->type != FAT_DIRECTORY ) set_errno_and_return_minus_one( ENOTDIR ); /* * Otherwise find the token name in the present location. */ strlwr(token); node = FAT_find_match_in_dir( token, node ); /* * If there is no node we have found the name of the node we * wish to create. */ if ( ! node ) done = TRUE; else pathloc->node_access = node; break; case FAT_NO_MORE_PATH: set_errno_and_return_minus_one( EEXIST ); break; case FAT_INVALID_TOKEN: set_errno_and_return_minus_one( ENAMETOOLONG ); break; case FAT_CURRENT_DIR: break; } } *name = &path[ i - len ]; /* * We have evaluated the path as far as we can. * Verify there is not any invalid stuff at the end of the name. */ for( ; path[i] != '\0'; i++) { if ( !rtems_filesystem_is_separator( path[ i ] ) ) set_errno_and_return_minus_one( ENOENT ); } /* * Verify we can execute and write to this directory. */ node = pathloc->node_access; result = FAT_Set_handlers( pathloc ); /* * The returned node must be a directory */ if ( node->type != FAT_DIRECTORY ) set_errno_and_return_minus_one( ENOTDIR ); node->reference++; return 0;}/* * FAT_eval_path * * The following routine evaluate path for a node that wishes to be * accessed with mode. pathloc is returned with a pointer to the * node to be accessed. */intFAT_eval_path(pathname,flags,pathloc) const char *pathname; /* IN */ int flags; /* IN */ rtems_filesystem_location_info_t *pathloc; /* IN/OUT */{ int i = 0; int len; FAT_token_types type = FAT_CURRENT_DIR; char token[ 14 ]; rtems_filesystem_location_info_t newloc; FAT_jnode_t *node; int result; /* * This was filled in by the caller and is valid in the * mount table. */ node = pathloc->node_access; /* * Evaluate all tokens until we are done or an error occurs. */ while( (type != FAT_NO_MORE_PATH) && (type != FAT_INVALID_TOKEN) ) { type = FAT_get_token( &pathname[i], token, &len ); i += len; if ( !pathloc->node_access ) set_errno_and_return_minus_one( ENOENT ); node = pathloc->node_access; switch( type ) { case FAT_UP_DIR: /* * Am I at the root of this mounted filesystem? */ if (pathloc->node_access == pathloc->mt_entry->mt_fs_root.node_access) { newloc = pathloc->mt_entry->mt_point_node; *pathloc = newloc; return (*pathloc->ops->evalpath)(&(pathname[i-len]),flags,pathloc); } else { if ( !node->parent ) set_errno_and_return_minus_one( ENOENT ); node = node->parent; pathloc->node_access = node; } pathloc->node_access = node; break; case FAT_NAME: /* * Only a directory can be decended into. */ if ( node->type != FAT_DIRECTORY ) set_errno_and_return_minus_one( ENOTDIR ); /* * Otherwise find the token name in the present location. */ strlwr(token); node = FAT_find_match_in_dir( token, node ); if ( !node ) set_errno_and_return_minus_one( ENOENT ); /* * Set the node access to the point we have found. */ pathloc->node_access = node; break; case FAT_NO_MORE_PATH: case FAT_CURRENT_DIR: break; case FAT_INVALID_TOKEN: set_errno_and_return_minus_one( ENAMETOOLONG ); break; } } result = FAT_Set_handlers( pathloc ); node->reference++; return result;}/* FAT_node_type * Return type of node. It might be FAT_FILE or FAT_DIR */rtems_filesystem_node_types_tFAT_node_type( rtems_filesystem_location_info_t *pathloc ){ FAT_jnode_t *node; node = pathloc->node_access; return node->type;}/* * FAT_mknod * * Routine to create a node in the FAT file system. */intFAT_mknod(token, mode, dev, pathloc) const char *token; /* IN */ mode_t mode; /* IN */ dev_t dev; /* IN */ rtems_filesystem_location_info_t *pathloc; /* IN/OUT */{ FAT_jnode_t *new_node; FAT_jnode_t *node = pathloc->node_access; /* rtems_filesystem_location_info_t tmp_pathloc; */ int result, type; char new_name[ 14 ]; FAT_get_token( token, new_name, &result ); /* * Figure out what type of FAT node this is. */ if ( S_ISDIR(mode) ) { set_errno_and_return_minus_one( EINVAL ); } else if ( S_ISREG(mode) ) { type = FAT_FILE; } else { set_errno_and_return_minus_one( EINVAL ); } /* * Allocate and fill in a FAT jnode */ new_node = calloc(1, sizeof (FAT_jnode_t)); if (!new_node) set_errno_and_return_minus_one( EINVAL ); new_node->geometry = node->geometry; rtems_semaphore_obtain(node->geometry->mutex_id,RTEMS_WAIT,RTEMS_NO_TIMEOUT); new_node->dir_offset = find_free_entry(node); if (new_node->dir_offset < 0) { free(new_node); set_errno_and_return_minus_one( EINVAL ); } new_node->st_ino = search_free_cluster(node->geometry); if (new_node->st_ino < 0) { free(new_node); set_errno_and_return_minus_one( EINVAL ); } new_node->parent = node; new_node->reference = 0; new_node->type = FAT_FILE; new_node->attrib = 0x20; new_node->size = 0; add_node(new_node); update_cluster(new_node->st_ino, 0xffff, node->geometry); strcpy(new_node->name, new_name); update_dir_entry(new_node); save_fat(node->geometry); rtems_semaphore_release(node->geometry->mutex_id); /* result = FAT_Set_handlers( new_node ); */ return 0;}/* * FAT_rmnod */intFAT_rmnod( rtems_filesystem_location_info_t *pathloc){ FAT_jnode_t *node; fat_geom_t *geom; int cluster, next_cluster; node = (FAT_jnode_t *) pathloc->node_access; geom = node->geometry; /* * The file cannot be open to free. */ if ( ( !rtems_libio_is_file_open( node ) ) && (node->type == FAT_FILE) ) { /* * Is rtems_filesystem_current this node? */ if ( rtems_filesystem_current.node_access == pathloc->node_access ) rtems_filesystem_current.node_access = NULL; rtems_semaphore_obtain(geom->mutex_id,RTEMS_WAIT,RTEMS_NO_TIMEOUT); cluster = node->st_ino; do { next_cluster = search_next_cluster(cluster, geom); update_cluster(cluster, 0x0000, geom); cluster = next_cluster; } while (cluster < 0xfff0); /* update_cluster(cluster, 0x0000, geom); */ node->name[0] = 0xe5; node->reference--; update_dir_entry(node); if (node->reference <= 0) del_node(node); /* del_node(node); */ save_fat(geom); rtems_semaphore_release(geom->mutex_id); } else { /* File is opened, so cannot be deleted */ } return 0;}/* * FAT_link. * Actually it is a move function, because fat does not support links */intFAT_link(to_loc, parent_loc, token) rtems_filesystem_location_info_t *to_loc; rtems_filesystem_location_info_t *parent_loc; const char *token;{ FAT_jnode_t *node, *new_parent; char new_name[ 14 ]; int i, new_offset; node = (FAT_jnode_t *) to_loc->node_access; new_parent = (FAT_jnode_t *) parent_loc->node_access; /* * Remove any separators at the end of the string. */ FAT_get_token( token, new_name, &i ); rtems_semaphore_obtain( node->geometry->rw_mutex_id, RTEMS_WAIT,RTEMS_NO_TIMEOUT ); rtems_semaphore_obtain(node->geometry->mutex_id,RTEMS_WAIT,RTEMS_NO_TIMEOUT); new_offset = find_free_entry(new_parent); if (new_offset < 0) { rtems_semaphore_release(node->geometry->mutex_id); rtems_semaphore_release( node->geometry->rw_mutex_id ); set_errno_and_return_minus_one( EINVAL ); } /* Mark current entry as deleted */ node->name[0] = 0xe5; update_dir_entry(node); /* Create new one */ strcpy(node->name,new_name); node->parent->reference--; node->parent = new_parent; node->dir_offset = new_offset; node->parent->reference++; update_dir_entry(node); rtems_semaphore_release( node->geometry->rw_mutex_id ); rtems_semaphore_release(node->geometry->mutex_id); return 0;}/* * FAT_freenodinfo * */intFAT_freenodinfo(rtems_filesystem_location_info_t *pathloc ){ FAT_jnode_t *node; node = pathloc->node_access; node->reference--; del_node(node); return 0;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -