MCPcopy Create free account
hub / github.com/dmtcp/dmtcp / pathTranslator_VirtualToReal

Function pathTranslator_VirtualToReal

src/plugin_pathtranslator.cpp:126–154  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

124 */
125
126static void
127pathTranslator_VirtualToReal(DmtcpEventData_t *data)
128{
129 pathTranslator_Init();
130 char *virtPath = data->virtualToRealPath.path;
131
132 // Check to see if prefix of virtPath is present in pathMappings.
133 // This is O(n) in the number of mappings. We could make this faster by using
134 // a trie or a hash table.
135 // TODO (kapil): Investigate if we need to match the longest prefix instead of
136 // the first one.
137 for (const auto &mapping : *pathMapping) {
138 const string &oldp = mapping.first;
139 const string &newp = mapping.second;
140 if (Util::strStartsWith(virtPath, oldp.c_str())) {
141 // boundary check: next char must be '/' or end
142 char next = virtPath[oldp.size()];
143 if (next == '/' || next == '\0') {
144 string suffix = &virtPath[oldp.size()];
145 int n = snprintf(data->virtualToRealPath.path,
146 PATH_MAX,
147 "%s%s",
148 newp.c_str(),
149 suffix.c_str());
150 JASSERT(n > 0 && n < PATH_MAX).Text("Translated path exceeds PATH_MAX");
151 }
152 }
153 }
154}
155
156void
157pathTranslator_EventHook(DmtcpEvent_t event, DmtcpEventData_t *data)

Callers 1

pathTranslator_EventHookFunction · 0.85

Calls 2

pathTranslator_InitFunction · 0.85
sizeMethod · 0.45

Tested by

no test coverage detected