MCPcopy Create free account
hub / github.com/apache/nuttx / tmpfs_unlink

Function tmpfs_unlink

fs/tmpfs/fs_tmpfs.c:2351–2454  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2349 ****************************************************************************/
2350
2351static int tmpfs_unlink(FAR struct inode *mountpt, FAR const char *relpath)
2352{
2353 FAR struct tmpfs_s *fs;
2354 FAR struct tmpfs_directory_s *tdo;
2355 FAR struct tmpfs_file_s *tfo = NULL;
2356 FAR const char *name;
2357 int ret;
2358
2359 finfo("mountpt: %p relpath: %s\n", mountpt, relpath);
2360 DEBUGASSERT(mountpt != NULL && relpath != NULL);
2361
2362 /* Get the file system structure from the inode reference. */
2363
2364 fs = mountpt->i_private;
2365 DEBUGASSERT(fs != NULL && fs->tfs_root.tde_object != NULL);
2366
2367 /* Get exclusive access to the file system */
2368
2369 ret = tmpfs_lock(fs);
2370 if (ret < 0)
2371 {
2372 return ret;
2373 }
2374
2375 /* Find the file object and parent directory associated with this relative
2376 * path. If successful, tmpfs_find_file will lock both the file object
2377 * and the parent directory and take one reference count on each.
2378 */
2379
2380 ret = tmpfs_find_file(fs, relpath, &tfo, &tdo);
2381 if (ret < 0)
2382 {
2383 goto errout_with_lock;
2384 }
2385
2386 DEBUGASSERT(tfo != NULL);
2387
2388 /* Get the file name from the relative path */
2389
2390 name = strrchr(relpath, '/');
2391 if (name != NULL)
2392 {
2393 /* Skip over the file '/' character */
2394
2395 name++;
2396 }
2397 else
2398 {
2399 /* The name must lie in the root directory */
2400
2401 name = relpath;
2402 }
2403
2404 /* Remove the file from parent directory */
2405
2406 ret = tmpfs_remove_dirent(tdo, name);
2407 if (ret < 0)
2408 {

Callers

nothing calls this directly

Calls 6

tmpfs_find_fileFunction · 0.85
tmpfs_remove_direntFunction · 0.85
nxrmutex_destroyFunction · 0.85
fs_heap_freeFunction · 0.85
tmpfs_release_lockedfileFunction · 0.85
strrchrFunction · 0.50

Tested by

no test coverage detected