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

Method init

fs/subfs.cpp:43–71  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

41 bool ownership = false;
42
43 int init(IFileSystem* _underlayfs, const char* _base_path, bool _ownership)
44 {
45 ownership = _ownership;
46 underlayfs = _underlayfs;
47 underlay_xattrfs = dynamic_cast<IFileSystemXAttr *>(_underlayfs);
48 if (!_base_path || !_base_path[0]) // use default relative path
49 {
50 base_path[0] = '\0';
51 base_path_len = 0;
52 return 0;
53 }
54
55 struct stat st;
56 int ret = underlayfs->stat(_base_path, &st);
57 if (ret < 0 || !S_ISDIR(st.st_mode))
58 LOG_ERROR_RETURN(EINVAL, -1, "the base path '`' of file system [`] must be an directory!",
59 _base_path, _underlayfs);
60
61 base_path_len = (uint)strlen(_base_path);
62 assert(base_path_len > 0);
63 if (base_path_len > LEN(base_path) - 2)
64 LOG_ERROR_RETURN(EINVAL, -1, "the base path '`' is too long!", _base_path);
65
66 memcpy(base_path, _base_path, base_path_len);
67 if (base_path[base_path_len - 1] != '/')
68 base_path[base_path_len++] = '/';
69
70 return 0;
71 }
72 virtual ~SubFileSystem() override
73 {
74 if (ownership)

Callers 1

new_subfsFunction · 0.45

Calls 2

LENFunction · 0.50
statMethod · 0.45

Tested by

no test coverage detected