int rtems_rfs_inode_unload (rtems_rfs_file_system* fs, rtems_rfs_inode_handle* handle, bool update_ctime) { int rc = 0; if (rtems_rfs_trace (RTEMS_RFS_TRACE_INODE_UNLOAD)) printf ("rtems-rfs: inode-unload: ino=%" PRIu32 " loads=%i loaded=%s\n", handle->ino, handle->loads, rtems_rfs_inode_is_loaded (handle) ? "yes" : "no"); if (rtems_rfs_inode_is_loaded (handle)) { if (handle->loads == 0) return EIO; handle->loads--; if (handle->loads == 0) { /* * If the buffer is dirty it will be release. Also set the ctime. */ if (rtems_rfs_buffer_dirty (&handle->buffer) && update_ctime) rtems_rfs_inode_set_ctime (handle, time (NULL)); rc = rtems_rfs_buffer_handle_release (fs, &handle->buffer); handle->node = NULL; } } return rc; }
int rtems_rfs_buffer_handle_release (rtems_rfs_file_system* fs, rtems_rfs_buffer_handle* handle) { int rc = 0; if (rtems_rfs_buffer_handle_has_block (handle)) { if (rtems_rfs_trace (RTEMS_RFS_TRACE_BUFFER_HANDLE_RELEASE)) printf ("rtems-rfs: buffer-release: block=%" PRIu32 " %s refs=%d %s\n", rtems_rfs_buffer_bnum (handle), rtems_rfs_buffer_dirty (handle) ? "(dirty)" : "", rtems_rfs_buffer_refs (handle), rtems_rfs_buffer_refs (handle) == 0 ? "BAD REF COUNT" : ""); if (rtems_rfs_buffer_refs (handle) > 0) rtems_rfs_buffer_refs_down (handle); if (rtems_rfs_buffer_refs (handle) == 0) { rtems_chain_extract (rtems_rfs_buffer_link (handle)); fs->buffers_count--; if (rtems_rfs_fs_no_local_cache (fs)) { handle->buffer->user = (void*) 0; rc = rtems_rfs_buffer_io_release (handle->buffer, rtems_rfs_buffer_dirty (handle)); } else { /* * If the total number of held buffers is higher than the configured * value remove a buffer from the queue with the most buffers and * release. The buffers are held on the queues with the newest at the * head. * * This code stops a large series of transactions causing all the * buffers in the cache being held in queues of this file system. */ if ((fs->release_count + fs->release_modified_count) >= fs->max_held_buffers) { rtems_rfs_buffer* buffer; bool modified; if (rtems_rfs_trace (RTEMS_RFS_TRACE_BUFFER_HANDLE_RELEASE)) printf ("rtems-rfs: buffer-release: local cache overflow:" " %" PRIu32 "\n", fs->release_count + fs->release_modified_count); if (fs->release_count > fs->release_modified_count) { buffer = (rtems_rfs_buffer*) rtems_chain_get (&fs->release); fs->release_count--; modified = false; } else { buffer = (rtems_rfs_buffer*) rtems_chain_get (&fs->release_modified); fs->release_modified_count--; modified = true; } buffer->user = (void*) 0; rc = rtems_rfs_buffer_io_release (buffer, modified); } if (rtems_rfs_buffer_dirty (handle)) { rtems_chain_append (&fs->release_modified, rtems_rfs_buffer_link (handle)); fs->release_modified_count++; } else { rtems_chain_append (&fs->release, rtems_rfs_buffer_link (handle)); fs->release_count++; } } } handle->buffer = NULL; } return rc; }