/// <summary>
        /// Checks whether the specified area has been locked by another file handle.
        /// </summary>
        /// <param name="fileHandle"></param>
        /// <param name="item"></param>
        /// <param name="offset"></param>
        /// <param name="length"></param>
        /// <returns></returns>
        public static bool FileOPLockCheck(FileHandler fileHandle, IFuserFilesystemItem item, long offset, long length)
        {
            try {
                if (fileHandle == null)
                {
                    return(false);
                }
                if (!fileHandle.OPLockActive)
                {
                    return(true); // do not check any locks, according to the filehandle locks are not possible.
                }

                if (item == null)
                {
                    return(false);
                }
                if (offset < 0)
                {
                    return(true);
                }
                if (length <= 0)
                {
                    return(true);
                }


                FileLockManager lockMgr     = item.Filelock;
                FileLockItem[]  locksHandle = null; // list of locks from this handle.
                FileLockItem[]  locksFile   = null; // list of locks from this file.


                lock (fileHandle) {
                    locksHandle = fileHandle.GetFileLockList();
                }

                lock (lockMgr) {
                    locksFile = lockMgr.GetFileLockList();
                }

                if (locksFile == null)
                {
                    return(true);
                }

                List <FileLockItem> locks = new List <FileLockItem>(locksFile);
                if (locksHandle != null)
                {
                    foreach (FileLockItem lItem in locksHandle)
                    {
                        locks.Remove(lItem);
                    }
                }

                foreach (FileLockItem lItem in locks)
                {
                    if (lItem.IsOpLock)
                    {
                        if (!lItem.CheckOPLockRange(offset, length))
                        {
                            return(false);// violation occurred!
                        }
                    }
                }
                return(true);
            } catch {
                return(false);
            }
        }
        /// <summary>
        /// Checks whether the selected item can be deleted. Only the FileLocks are taken into account. Required for Move and Delete
        /// </summary>
        /// <param name="fileHandle"></param>
        /// <param name="item"></param>
        /// <returns></returns>
        public static bool DeletionAllow(FileHandler fileHandle, IFuserFilesystemItem item)
        {
            try {
                if (fileHandle == null)
                {
                    return(false);
                }
                if (item == null)
                {
                    return(false);
                }

                List <FileLockItem> locks;
                FileLockManager     lockMgr          = item.Filelock;
                FileLockItem[]      locksHandle      = null; // list with locks for the current fileHandle
                FileLockItem[]      locksFile        = null; // list with locks for the current file
                FileLockItem[]      locksBlockDelete = null; // list with deletion-locks for the current file

                lock (fileHandle) {
                    locksHandle = fileHandle.GetFileLockList();
                }

                lock (lockMgr) {
                    locksFile        = lockMgr.GetFileLockList();
                    locksBlockDelete = lockMgr.GetBlockDeletePermissionList();
                }

                if (locksFile == null)
                {
                    return(true); // no locks found, file not in use
                }


                // check: deletion block
                if (locksBlockDelete != null)
                {
                    locks = new List <FileLockItem>(locksBlockDelete);
                    if (locksHandle != null)
                    {
                        foreach (FileLockItem lItem in locksHandle)
                        {
                            locks.Remove(lItem);
                        }
                    }
                    if (locks.Count != 0)
                    {
                        return(false);// deletion was blocked
                    }
                }
                // check: deletion block


                locks = new List <FileLockItem>(locksFile);
                if (locksHandle != null)
                {
                    foreach (FileLockItem lItem in locksHandle)
                    {
                        locks.Remove(lItem);
                    }
                }

                bool del = false;
                foreach (FileLockItem lck in locks)
                {
                    if (!lck.Share.HasFlag(FileShare.Delete))
                    {
                        del = true;
                    }
                }

                if (del == false)
                {
                    return(true);
                }
                else
                {
                    return(false);
                }
            } catch {
                return(false);
            }
        }