MCPcopy Create free account
hub / github.com/alibaba/PhotonLibOS / get_inode

Method get_inode

fs/extfs/extfs.cpp:1442–1489  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1440 }
1441
1442 ext2_ino_t get_inode(const char *str, int follow, bool release) {
1443 ext2_ino_t ino = 0;
1444 DEFER(LOG_DEBUG("get_inode ", VALUE(str), VALUE(follow), VALUE(release), VALUE(ino)));
1445
1446 auto func = [&]() -> ext2_ino_t * {
1447 ext2_ino_t *i = new ext2_ino_t;
1448 errcode_t ret = 0;
1449 if (follow) {
1450 ret = ext2fs_namei_follow(fs, EXT2_ROOT_INO, EXT2_ROOT_INO, str, i);
1451 } else {
1452 auto parent = get_parent_dir_ino(fs, str);
1453 if (parent) {
1454 auto filename = get_filename(str);
1455 if (filename)
1456 ret = ext2fs_namei(fs, EXT2_ROOT_INO, parent, filename, i);
1457 else
1458 ret = ext2fs_namei(fs, EXT2_ROOT_INO, EXT2_ROOT_INO, str, i);
1459 } else {
1460 ret = ext2fs_namei(fs, EXT2_ROOT_INO, EXT2_ROOT_INO, str, i);
1461 }
1462 }
1463 if (ret) {
1464 LOG_DEBUG("ext2fs_namei not found ", VALUE(str), VALUE(follow));
1465 errno = -parse_extfs_error(fs, 0, ret);
1466 delete i;
1467 return nullptr;
1468 }
1469 LOG_DEBUG("ext2fs_namei ", VALUE(str), VALUE(follow), VALUE(*i));
1470 return i;
1471 };
1472
1473 if (follow) {
1474 auto b = func();
1475 if (b) ino = *b;
1476
1477 } else {
1478 auto b = ino_cache.borrow(str, func);
1479 if (b) ino = *b;
1480 }
1481
1482 if (release) {
1483 LOG_DEBUG("release ino_cache ", VALUE(str), VALUE(release));
1484 auto b = ino_cache.borrow(str);
1485 b.recycle(true);
1486 }
1487
1488 return ino;
1489 }
1490 int flush_buffer() {
1491 return buffer_file ? buffer_file->fdatasync() : 0;
1492 }

Callers 1

string_to_inodeFunction · 0.80

Calls 3

funcFunction · 0.50
borrowMethod · 0.45
recycleMethod · 0.45

Tested by

no test coverage detected