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

Function tmpfs_open

fs/tmpfs/fs_tmpfs.c:1366–1514  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1364 ****************************************************************************/
1365
1366static int tmpfs_open(FAR struct file *filep, FAR const char *relpath,
1367 int oflags, mode_t mode)
1368{
1369 FAR struct inode *inode;
1370 FAR struct tmpfs_s *fs;
1371 FAR struct tmpfs_file_s *tfo;
1372 off_t offset;
1373 int ret;
1374
1375 finfo("filep: %p\n", filep);
1376 DEBUGASSERT(filep->f_priv == NULL);
1377
1378 /* Get the mountpoint inode reference from the file structure and the
1379 * mountpoint private data from the inode structure
1380 */
1381
1382 inode = filep->f_inode;
1383 fs = inode->i_private;
1384
1385 DEBUGASSERT(fs != NULL && fs->tfs_root.tde_object != NULL);
1386
1387 /* Get exclusive access to the file system */
1388
1389 ret = tmpfs_lock(fs);
1390 if (ret < 0)
1391 {
1392 return ret;
1393 }
1394
1395 /* Skip over any leading directory separators (shouldn't be any) */
1396
1397 for (; *relpath == '/'; relpath++);
1398
1399 /* Find the file object associated with this relative path.
1400 * If successful, this action will lock both the parent directory and
1401 * the file object, adding one to the reference count of both.
1402 * In the event that -ENOENT, there will still be a reference and
1403 * lock on the returned directory.
1404 */
1405
1406 ret = tmpfs_find_file(fs, relpath, &tfo, NULL);
1407 if (ret >= 0)
1408 {
1409 /* The file exists. We hold the lock and one reference count
1410 * on the file object.
1411 *
1412 * It would be an error if we are asked to create it exclusively
1413 */
1414
1415 if ((oflags & (O_CREAT | O_EXCL)) == (O_CREAT | O_EXCL))
1416 {
1417 /* Already exists -- can't create it exclusively */
1418
1419 ret = -EEXIST;
1420 goto errout_with_filelock;
1421 }
1422
1423 /* Check if the caller has sufficient privileges to open the file.

Callers

nothing calls this directly

Calls 4

tmpfs_find_fileFunction · 0.85
tmpfs_realloc_fileFunction · 0.85
tmpfs_create_fileFunction · 0.85
tmpfs_release_lockedfileFunction · 0.85

Tested by

no test coverage detected