MCPcopy Create free account
hub / github.com/LemonOSProject/LemonOS / CreateDirectory

Method CreateDirectory

Kernel/src/fs/ext2.cpp:1279–1342  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1277 }
1278
1279 int Ext2Volume::CreateDirectory(Ext2Node* node, DirectoryEntry* ent, uint32_t mode){
1280 if(readOnly){
1281 return -EROFS;
1282 }
1283
1284 if((node->flags & FS_NODE_TYPE) != FS_NODE_DIRECTORY) {
1285 Log::Info("[Ext2] Not a directory!");
1286 return -ENOTDIR;
1287 }
1288
1289 if(FindDir(node, ent->name)){
1290 Log::Info("[Ext2] CreateDirectory: Entry %s already exists!", ent->name);
1291 return -EEXIST;
1292 }
1293
1294 Ext2Node* dir = CreateNode();
1295
1296 if(!dir){
1297 Log::Error("[Ext2] Could not create inode!");
1298 return -1;
1299 }
1300
1301 dir->e2inode.mode = EXT2_S_IFDIR;
1302 dir->flags = FS_NODE_DIRECTORY;
1303 dir->e2inode.linkCount = 1;
1304
1305 inodeCache.insert(dir->inode, dir);
1306 ent->node = dir;
1307 ent->inode = dir->inode;
1308 ent->flags = EXT2_FT_DIR;
1309
1310 DirectoryEntry currentEnt;
1311 strcpy(currentEnt.name, ".");
1312 currentEnt.node = dir;
1313 currentEnt.inode = dir->inode;
1314 currentEnt.flags = EXT2_FT_DIR;
1315 dir->e2inode.linkCount++;
1316
1317 DirectoryEntry parentEnt;
1318 strcpy(parentEnt.name, "..");
1319 parentEnt.node = node;
1320 parentEnt.inode = node->inode;
1321 parentEnt.flags = EXT2_FT_DIR;
1322 node->e2inode.linkCount++;
1323
1324 List<DirectoryEntry> entries;
1325 entries.add_back(currentEnt);
1326 entries.add_back(parentEnt);
1327
1328 if(int e = InsertDir(dir, entries)){
1329 return e;
1330 }
1331
1332 if(int e = InsertDir(node, *ent)){
1333 return e;
1334 }
1335
1336 dir->nlink = dir->e2inode.linkCount;

Callers 1

SysMkdirFunction · 0.45

Calls 8

InfoFunction · 0.85
ErrorFunction · 0.85
strcpyFunction · 0.85
AcquireWriteMethod · 0.80
ReleaseWriteMethod · 0.80
FindDirFunction · 0.70
insertMethod · 0.45
add_backMethod · 0.45

Tested by

no test coverage detected