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_inode_load (rtems_rfs_file_system* fs, rtems_rfs_inode_handle* handle) { if (rtems_rfs_trace (RTEMS_RFS_TRACE_INODE_LOAD)) printf ("rtems-rfs: inode-load: ino=%" PRIu32 " loads=%i loaded=%s\n", handle->ino, handle->loads, rtems_rfs_inode_is_loaded (handle) ? "yes" : "no"); /* * An inode does not move so once loaded no need to do again. */ if (!rtems_rfs_inode_is_loaded (handle)) { int rc; rc = rtems_rfs_buffer_handle_request (fs,&handle->buffer, handle->block, true); if (rc > 0) return rc; handle->node = rtems_rfs_buffer_data (&handle->buffer); handle->node += handle->offset; } handle->loads++; return 0; }
int rtems_rfs_inode_delete (rtems_rfs_file_system* fs, rtems_rfs_inode_handle* handle) { int rc = 0; if (rtems_rfs_trace (RTEMS_RFS_TRACE_INODE_DELETE)) printf("rtems-rfs: inode-delete: ino:%" PRIu32 " loaded:%s\n", rtems_rfs_inode_ino (handle), rtems_rfs_inode_is_loaded (handle) ? "yes" : "no"); if (rtems_rfs_inode_is_loaded (handle)) { rtems_rfs_block_map map; /* * Free the ino number. */ rc = rtems_rfs_inode_free (fs, handle->ino); if (rc > 0) return rc; /* * Free the blocks the inode may have attached. */ rc = rtems_rfs_block_map_open (fs, handle, &map); if (rc == 0) { int rrc; rrc = rtems_rfs_block_map_free_all (fs, &map); rc = rtems_rfs_block_map_close (fs, &map); if (rc > 0) rrc = rc; memset (handle->node, 0xff, RTEMS_RFS_INODE_SIZE); rtems_rfs_buffer_mark_dirty (&handle->buffer); /* * Do the release here to avoid the ctime field being set on a * close. Also if there loads is greater then one then other loads * active. Forcing the loads count to 0. */ rc = rtems_rfs_buffer_handle_release (fs, &handle->buffer); handle->loads = 0; handle->node = NULL; } } return rc; }
int rtems_rfs_inode_time_stamp_now (rtems_rfs_inode_handle* handle, bool atime, bool mtime) { time_t now; if (!rtems_rfs_inode_is_loaded (handle)) return ENXIO; now = time (NULL); if (atime) rtems_rfs_inode_set_atime (handle, now); if (mtime) rtems_rfs_inode_set_mtime (handle, now); return 0; }
int rtems_rfs_file_close (rtems_rfs_file_system* fs, rtems_rfs_file_handle* handle) { int rrc; int rc; rrc = 0; if (rtems_rfs_trace (RTEMS_RFS_TRACE_FILE_CLOSE)) printf ("rtems-rfs: file-close: entry: ino=%" PRId32 "\n", handle->shared->inode.ino); if (handle->shared->references > 0) handle->shared->references--; if (handle->shared->references == 0) { if (!rtems_rfs_inode_is_loaded (&handle->shared->inode)) rrc = rtems_rfs_inode_load (fs, &handle->shared->inode); if (rrc == 0) { /* * @todo This could be clever and only update if different. */ rtems_rfs_inode_set_atime (&handle->shared->inode, handle->shared->atime); rtems_rfs_inode_set_mtime (&handle->shared->inode, handle->shared->mtime); rtems_rfs_inode_set_ctime (&handle->shared->inode, handle->shared->ctime); if (!rtems_rfs_block_size_equal (&handle->shared->size, &handle->shared->map.size)) rtems_rfs_block_map_set_size (&handle->shared->map, &handle->shared->size); } rc = rtems_rfs_block_map_close (fs, &handle->shared->map); if (rc > 0) { if (rtems_rfs_trace (RTEMS_RFS_TRACE_FILE_CLOSE)) printf ("rtems-rfs: file-close: map close error: ino=%" PRId32 ": %d: %s\n", handle->shared->inode.ino, rc, strerror (rc)); if (rrc == 0) rrc = rc; } rc = rtems_rfs_inode_close (fs, &handle->shared->inode); if (rc > 0) { if (rtems_rfs_trace (RTEMS_RFS_TRACE_FILE_CLOSE)) printf ("rtems-rfs: file-close: inode close error: ino=%" PRId32 ": %d: %s\n", handle->shared->inode.ino, rc, strerror (rc)); if (rrc == 0) rrc = rc; } rtems_chain_extract (&handle->shared->link); free (handle->shared); } rc = rtems_rfs_buffer_handle_close (fs, &handle->buffer); if ((rrc == 0) && (rc > 0)) rrc = rc; if (rrc > 0) { if (rtems_rfs_trace (RTEMS_RFS_TRACE_FILE_CLOSE)) printf ("rtems-rfs: file-close: result: %d: %s\n", rrc, strerror (rrc)); } free (handle); return rrc; }