public FuserFileHandler GetFileHandler(string filename, ref FuserDefinition.FUSER_FILE_INFO rawHFile) { FuserFileHandler ret = null; if (rawHFile.Context != 0) { int index = (int)rawHFile.Context; // TODO: remove casting lock (this.handlers) { if (index > 0 && index <= this.ListHandlerMaxID) { PVCStoredHandle sh = this.handlers[index]; if (sh != null) { ret = CreateFileHandler(filename, sh.FileHandle, rawHFile); } } } } if (ret == null) { ret = RegisterFileHandler(filename, ref rawHFile); } return(ret); }
public FuserFileHandler RegisterFileHandler(string filename, ref FuserDefinition.FUSER_FILE_INFO rawHFile) { FileHandler fh = new FileHandler(filename); lock (this.handlers) { //int n = this.handlers.Count + 1; bool InsertNewItem = true; if (this.reserve.Count > 0 && this.reserve.Count >= LIMIT_MIN_COUNT_RESERVE) { // try to take an item from the reserve list. PVCStoredHandle sh = this.reserve.Peek(); if (sh == null) { System.Diagnostics.Debugger.Break(); } if (sh.CheckReInsert()) { sh = this.reserve.Dequeue(); int index = sh.GetHandleID; if (this.handlers[index] != null) { return(null); } this.handlers[index] = new PVCStoredHandle(index, fh); if (this.handlers[index].GetHandleID != index) { return(null); } rawHFile.Context = (ulong)index; // TODO: remove casting InsertNewItem = false; } } if (InsertNewItem) { ListHandlerMaxID++; this.handlers.Add(new PVCStoredHandle(ListHandlerMaxID, fh)); if (this.handlers[ListHandlerMaxID].GetHandleID != ListHandlerMaxID) { return(null); } rawHFile.Context = (ulong)ListHandlerMaxID; // TODO: remove casting } } return(CreateFileHandler(filename, fh, rawHFile)); }
public void RemoveFileHandler(ref FuserDefinition.FUSER_FILE_INFO rawHFile) { if (rawHFile.Context != 0) { int index = (int)rawHFile.Context; // TODO: remove casting lock (this.handlers) { rawHFile.Context = 0; // immediately removes the reference if (index > 0 && index <= this.ListHandlerMaxID) { PVCStoredHandle sh = this.handlers[index]; this.handlers[index] = null; // Removes saved handles if (sh != null) { sh.Close(); this.reserve.Enqueue(sh); } } } } }