MCPcopy Create free account
hub / github.com/andysworkshop/stm32plus / createFile

Method createFile

lib/src/filesystem/fat/FatFileSystem.cpp:318–362  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

316 */
317
318 bool FatFileSystem::createFile(const char *filename) {
319
320 FatDirectoryIterator *it;
321 bool retval;
322
323 // tokenise the path, must have a component
324
325 TokenisedPathname tp(filename);
326 if(tp.getNumTokens() == 0)
327 return errorProvider.set(ErrorProvider::ERROR_PROVIDER_FILESYSTEM,E_INVALID_PATHNAME);
328
329 // cannot create a file that exists
330
331 if(getDirectoryIteratorPointingToFile(tp,it)) {
332 delete it;
333 return errorProvider.set(ErrorProvider::ERROR_PROVIDER_FILESYSTEM,E_FILE_EXISTS);
334 }
335
336 // limit the range so that we get an iterator on to the parent
337
338 tp.resetRange();
339 tp.setRange(0,tp.getNumTokens() - 2);
340
341 if(!FatDirectoryIterator::getInstance(*this,tp,it))
342 return false;
343
344 // reset the range so that we can see the filename on the end
345
346 tp.resetRange();
347
348 // create the dirents for this new file
349
350 LongNameDirentGenerator lndg(tp.last(),it->getDirectoryEntryIterator(),0,0);
351
352 if(errorProvider.getLast() != 0) {
353 delete it;
354 return false;
355 }
356
357 // write the dirents to the owning directory
358
359 retval=it->getDirectoryEntryIterator().writeDirents(lndg.getDirents(),lndg.getDirentCount());
360 delete it;
361 return retval;
362 }
363
364 /**
365 * Open an existing file.

Callers 4

writeToFileMethod · 0.80
uploadMethod · 0.80
allocateBlocksMethod · 0.80
saveCalibrationMethod · 0.80

Calls 9

getNumTokensMethod · 0.80
resetRangeMethod · 0.80
setRangeMethod · 0.80
lastMethod · 0.80
getLastMethod · 0.80
writeDirentsMethod · 0.80
getDirentsMethod · 0.80
setMethod · 0.45
getDirentCountMethod · 0.45

Tested by

no test coverage detected