public override int Open(ReadOnlySpan <byte> path, ref FuseFileInfo fi) { if (verbosity > 5) { Console.WriteLine($"Open {path.GetString()} Flags={flagString(fi.flags)}"); } int error = 0, level = 0; var procs = ProcPath(path, ref error, ref level, mustExist: true, isADir: false); if (error != 0) { Console.WriteLine($"Path gets error {error}"); return(-LibC.ENOENT); } var newFile = procs.Pop(); if (newFile.Item2 == null) { return(-LibC.ENOENT); } var fileRec = newFile.Item2; var oldFile = fileRec; var parentRec = procs.Pop(); if (parentRec.Item2 == null) { return(-LibC.ENOENT); } var par = parentRec.Item2; if (par.MaintLevel) { return(-LibC.EPERM); } // O_TRUNC deletes the file, so we should delete it. if ((fi.flags & LibC.O_TRUNC) != 0) { // Must delete the file Console.WriteLine($"File Deleted: {newFile.Item2.Name.GetString()} id={newFile.Item2._id} Version={newFile.Item2.Version}"); fileDelete(newFile.Item2, DeleteTypes.TRUNC); fileRec = NeoAssets.Mongo.NeoVirtFS.CreateNewFile(par._id, par.VolumeId, newFile.Item1, path, (mode_t)(uint)oldFile.Stat.st_mode); fileRec.Version = oldFile.Version + 1; NeoVirtFSCol.InsertOne(fileRec); fi.flags |= LibC.O_CREAT; // Otherwise it won't create the file again } fi.fh = storeHandler(FileDescriptor.FileHandlerFactory(fileRec, db, bac, bvol)); var fds = DescriptorStore[fi.fh]; return(fds.Handler.Open(fds, fi.flags)); }
public override int Create(ReadOnlySpan <byte> path, mode_t mode, ref FuseFileInfo fi) { if (verbosity > 5) { Console.WriteLine($"Create {path.GetString()} Flags={flagString(fi.flags)}"); } int error = 0, level = 0; var procs = ProcPath(path, ref error, ref level, mustExist: false); if (error != 0) { Console.WriteLine($"Path gets error {error}"); return(-LibC.ENOENT); } // New files are always cache files, but might have existing file that needs to be deleted int version = 0; var newFile = procs.Pop(); if (newFile.Item2 != null) { // Must delete the file version = newFile.Item2.Version; Console.WriteLine($"File Deleted: {newFile.Item2.Name.GetString()} id={newFile.Item2._id} Version={version}"); fileDelete(newFile.Item2, DeleteTypes.CREATE); } var parentRec = procs.Pop(); if (parentRec.Item2 == null) { return(-LibC.ENOENT); } var par = parentRec.Item2; if (par.MaintLevel) { return(-LibC.EPERM); } // Create new record (new id) and insert var newRec = NeoAssets.Mongo.NeoVirtFS.CreateNewFile(par._id, par.VolumeId, newFile.Item1, path, mode); newRec.Version = version + 1; NeoVirtFSCol.InsertOne(newRec); //var filter = Builders<NeoAssets.Mongo.NeoVirtFS>.Filter.Eq(x => x._id, newRec._id); //var insert = NeoVirtFSDeletedCol.ReplaceOneAsync(filter, newRec, options: new ReplaceOptions { IsUpsert = true }); Console.WriteLine($"File Created: {newRec.Name.GetString()} id={newRec._id}"); fi.fh = storeHandler(FileDescriptor.FileHandlerFactory(newRec, db, bac, bvol)); var fds = DescriptorStore[fi.fh]; return(fds.Handler.Create(fds, mode, fi.flags)); }