MCPcopy Create free account
hub / github.com/RT-Thread/rt-thread / dfs_file_ftruncate

Function dfs_file_ftruncate

components/dfs/dfs_v2/src/dfs_file.c:2211–2245  ·  view source on GitHub ↗

* @brief Truncate or extend a file to the specified length * * This function changes the size of the file referenced by the file descriptor. * If the new size is smaller than current size, the file is truncated. * If larger, the file is extended and the extended area is filled with zeros. * * @param[in] file Pointer to the file structure to truncate * @param[in] length New length of the fil

Source from the content-addressed store, hash-verified

2209 * before truncation to ensure data consistency
2210 */
2211int dfs_file_ftruncate(struct dfs_file *file, off_t length)
2212{
2213 int ret = 0;
2214
2215 if (file)
2216 {
2217 if (file->fops->truncate)
2218 {
2219 if (dfs_is_mounted(file->vnode->mnt) == 0)
2220 {
2221#ifdef RT_USING_PAGECACHE
2222 if (file->vnode->aspace)
2223 {
2224 dfs_aspace_clean(file->vnode->aspace);
2225 }
2226#endif
2227 ret = file->fops->truncate(file, length);
2228 }
2229 else
2230 {
2231 ret = -EINVAL;
2232 }
2233 }
2234 else
2235 {
2236 ret = -ENOSYS;
2237 }
2238 }
2239 else
2240 {
2241 ret = -EBADF;
2242 }
2243
2244 return ret;
2245}
2246
2247/**
2248 * @brief Flush file buffers to storage device

Callers 1

ftruncateFunction · 0.70

Calls 2

dfs_is_mountedFunction · 0.85
dfs_aspace_cleanFunction · 0.85

Tested by

no test coverage detected