Пример #1
0
    public void Access(Pfm.MarshallerAccessOp op)
    {
        long openId = op.OpenId();
        int  perr   = 0;

        Pfm.OpenAttribs openAttribs = new Pfm.OpenAttribs();

        if (openId == folderOpenId)
        {
            openAttribs.openId           = folderOpenId;
            openAttribs.openSequence     = 1;
            openAttribs.accessLevel      = Pfm.accessLevelReadData;
            openAttribs.attribs.fileType = Pfm.fileTypeFolder;
            openAttribs.attribs.fileId   = helloRootId;
        }
        else if (openId == fileOpenId)
        {
            openAttribs.openId           = fileOpenId;
            openAttribs.openSequence     = 1;
            openAttribs.accessLevel      = Pfm.accessLevelReadData;
            openAttribs.attribs.fileType = Pfm.fileTypeFile;
            openAttribs.attribs.fileId   = helloFileId;
            openAttribs.attribs.fileSize = helloFileData.Length;
        }
        else
        {
            perr = Pfm.errorNotFound;
        }

        op.Complete(perr, openAttribs, null);
    }
Пример #2
0
    // Pfm.FormatterDispatch.Replace
    // Replace an existing file with a newly created file.
    public void Replace(Pfm.MarshallerReplaceOp op)
    {
        long   targetOpenId       = op.TargetOpenId();
        long   targetParentFileId = op.TargetParentFileId();
        string targetEndName      = op.TargetEndName();
        int    createFileFlags    = op.CreateFileFlags();
        long   writeTime          = op.WriteTime();
        long   newCreateOpenId    = op.NewCreateOpenId();
        int    perr;

        Pfm.OpenAttribs openAttribs = new Pfm.OpenAttribs();
        File            targetFile;
        File            parent;
        File            file;

        perr = FileFindOpenId(targetOpenId, out targetFile);
        if (perr == 0)
        {
            perr = FileFindFileId(targetParentFileId, out parent);
            if (perr == 0)
            {
                file = new File(targetFile.fileType, createFileFlags, writeTime);
                perr = FileNameRemove(parent, writeTime, targetEndName, targetFile);
                if (perr == 0)
                {
                    FileNameAdd(parent, writeTime, targetEndName, file);
                    file.openId = newCreateOpenId;
                    FileOpened(file, ref openAttribs);
                }
            }
        }

        op.Complete(perr, openAttribs, null);
    }
Пример #3
0
    public void Open(Pfm.MarshallerOpenOp op)
    {
        string[] nameParts         = op.NameParts();
        int      createFileType    = op.CreateFileType();
        long     newExistingOpenId = op.NewExistingOpenId();
        int      perr    = 0;
        bool     existed = false;

        Pfm.OpenAttribs openAttribs  = new Pfm.OpenAttribs();
        long            parentFileId = 0;
        string          endName      = null;

        if (nameParts.Length == 0)
        {
            if (folderOpenId == 0)
            {
                folderOpenId = newExistingOpenId;
            }
            existed                      = true;
            openAttribs.openId           = folderOpenId;
            openAttribs.openSequence     = 1;
            openAttribs.accessLevel      = Pfm.accessLevelReadData;
            openAttribs.attribs.fileType = Pfm.fileTypeFolder;
            openAttribs.attribs.fileId   = helloRootId;
        }
        else if (nameParts.Length == 1)
        {
            if (nameParts[0].ToLowerInvariant() != helloFileName.ToLowerInvariant())
            {
                perr = Pfm.errorNotFound;
            }
            else
            {
                if (fileOpenId == 0)
                {
                    fileOpenId = newExistingOpenId;
                }
                existed                      = true;
                openAttribs.openId           = fileOpenId;
                openAttribs.openSequence     = 1;
                openAttribs.accessLevel      = Pfm.accessLevelReadData;
                openAttribs.attribs.fileType = Pfm.fileTypeFile;
                openAttribs.attribs.fileId   = helloFileId;
                openAttribs.attribs.fileSize = helloFileData.Length;
                endName                      = helloFileName;
            }
        }
        else
        {
            perr = Pfm.errorParentNotFound;
        }
        if (perr == Pfm.errorNotFound && createFileType != 0)
        {
            perr = Pfm.errorAccessDenied;
        }

        op.Complete(perr, existed, openAttribs, parentFileId, endName, 0, null, 0, null);
    }
Пример #4
0
    // Pfm.FormatterDispatch.Move
    // Open an existing target file, or move a previously opened
    // file to a _new target name if the target does not exist.
    public void Move(Pfm.MarshallerMoveOp op)
    {
        long   sourceOpenId       = op.SourceOpenId();
        long   sourceParentFileId = op.SourceParentFileId();
        string sourceEndName      = op.SourceEndName();

        string[] targetNameParts   = op.TargetNameParts();
        bool     deleteSource      = op.DeleteSource();
        long     writeTime         = op.WriteTime();
        long     newExistingOpenId = op.NewExistingOpenId();
        int      perr;
        bool     existed = false;

        Pfm.OpenAttribs openAttribs  = new Pfm.OpenAttribs();
        long            parentFileId = 0;
        string          endName      = null;
        File            sourceFile;
        File            targetParent;
        File            targetFile;
        File            sourceParent;

        perr = FileFindOpenId(sourceOpenId, out sourceFile);
        if (perr == 0)
        {
            perr = FileFindName(targetNameParts, out targetParent, out targetFile, out endName);
            if (perr == 0)
            {
                existed = true;
                if (targetParent != null)
                {
                    parentFileId = targetParent.fileId;
                }
                if (targetFile.openId == 0)
                {
                    targetFile.openId = newExistingOpenId;
                }
                FileOpened(targetFile, ref openAttribs);
            }
            else if (perr == Pfm.errorNotFound)
            {
                FileNameAdd(targetParent, writeTime, endName, sourceFile);
                perr         = 0;
                parentFileId = targetParent.fileId;
                FileOpened(sourceFile, ref openAttribs);
                if (deleteSource && FileFindFileId(sourceParentFileId, out sourceParent) == 0)
                {
                    FileNameRemove(sourceParent, writeTime, sourceEndName, sourceFile);
                }
            }
        }

        op.Complete(perr, existed, openAttribs, parentFileId, endName, 0, null, 0, null);
    }
Пример #5
0
    // Pfm.FormatterDispatch.Access
    // Read attributes for open file or folder.
    public void Access(Pfm.MarshallerAccessOp op)
    {
        long openId = op.OpenId();
        int  perr   = 0;

        Pfm.OpenAttribs openAttribs = new Pfm.OpenAttribs();
        File            file;

        perr = FileFindOpenId(openId, out file);
        if (perr == 0)
        {
            FileOpened(file, ref openAttribs);
        }

        op.Complete(perr, openAttribs, null);
    }
Пример #6
0
    // Pfm.FormatterDispatch.FlushFile
    public void FlushFile(Pfm.MarshallerFlushFileOp op)
    {
        long openId     = op.OpenId();
        int  flushFlags = op.FlushFlags();
        int  fileFlags  = op.FileFlags();
        long createTime = op.CreateTime();
        long accessTime = op.AccessTime();
        long writeTime  = op.WriteTime();
        long changeTime = op.ChangeTime();
        int  perr       = 0;

        Pfm.OpenAttribs openAttribs = new Pfm.OpenAttribs();
        File            file;

        perr = FileFindOpenId(openId, out file);
        if (perr == 0)
        {
            if (fileFlags != Pfm.fileFlagsInvalid)
            {
                file.fileFlags = fileFlags;
            }
            if (createTime != Pfm.timeInvalid)
            {
                file.createTime = createTime;
            }
            if (accessTime != Pfm.timeInvalid)
            {
                file.accessTime = accessTime;
            }
            if (writeTime != Pfm.timeInvalid)
            {
                file.writeTime = writeTime;
            }
            if (changeTime != Pfm.timeInvalid)
            {
                file.changeTime = changeTime;
            }
            if ((flushFlags & Pfm.flushFlagOpen) != 0)
            {
                FileOpened(file, ref openAttribs);
            }
        }

        op.Complete(perr, openAttribs, null);
    }
Пример #7
0
    // Pfm.FormatterDispatch.Open
    // Open existing file, or create new file.
    public void Open(Pfm.MarshallerOpenOp op)
    {
        string[] nameParts         = op.NameParts();
        int      createFileType    = op.CreateFileType();
        int      createFileFlags   = op.CreateFileFlags();
        long     writeTime         = op.WriteTime();
        long     newCreateOpenId   = op.NewCreateOpenId();
        long     newExistingOpenId = op.NewExistingOpenId();
        int      perr;
        bool     existed = false;

        Pfm.OpenAttribs openAttribs  = new Pfm.OpenAttribs();
        long            parentFileId = 0;
        string          endName      = null;

        File parent;
        File file;

        perr = FileFindName(nameParts, out parent, out file, out endName);
        if (perr == 0)
        {
            existed = true;
            if (parent != null)
            {
                parentFileId = parent.fileId;
            }
            if (file.openId == 0)
            {
                file.openId = newExistingOpenId;
            }
            FileOpened(file, ref openAttribs);
        }
        else if (perr == Pfm.errorNotFound && createFileType != Pfm.fileTypeNone)
        {
            file = new File(createFileType, createFileFlags, writeTime);
            FileNameAdd(parent, writeTime, endName, file);
            file.openId = newCreateOpenId;
            FileOpened(file, ref openAttribs);
            parentFileId = parent.fileId;
            perr         = 0;
        }

        op.Complete(perr, existed, openAttribs, parentFileId, endName, 0, null, 0, null);
    }
Пример #8
0
    public void FlushFile(Pfm.MarshallerFlushFileOp op)
    {
        long openId     = op.OpenId();
        int  fileFlags  = op.FileFlags();
        int  color      = op.Color();
        long createTime = op.CreateTime();
        long writeTime  = op.WriteTime();
        int  perr       = 0;

        Pfm.OpenAttribs openAttribs = new Pfm.OpenAttribs();

        if (fileFlags != Pfm.fileFlagsInvalid ||
            color != Pfm.colorInvalid ||
            createTime != Pfm.timeInvalid ||
            writeTime != Pfm.timeInvalid)
        {
            perr = Pfm.errorAccessDenied;
        }
        else if (openId == folderOpenId)
        {
            openAttribs.openId           = folderOpenId;
            openAttribs.openSequence     = 1;
            openAttribs.accessLevel      = Pfm.accessLevelReadData;
            openAttribs.attribs.fileType = Pfm.fileTypeFolder;
            openAttribs.attribs.fileId   = helloRootId;
        }
        else if (openId == fileOpenId)
        {
            openAttribs.openId           = fileOpenId;
            openAttribs.openSequence     = 1;
            openAttribs.accessLevel      = Pfm.accessLevelReadData;
            openAttribs.attribs.fileType = Pfm.fileTypeFile;
            openAttribs.attribs.fileId   = helloFileId;
            openAttribs.attribs.fileSize = helloFileData.Length;
        }
        else
        {
            perr = Pfm.errorNotFound;
        }

        op.Complete(perr, openAttribs, null);
    }
Пример #9
0
    void FileOpened(File file, ref Pfm.OpenAttribs openAttribs)
    {
        Debug.Assert(file.openId != 0);
        OpenRef openRef = (OpenRef)(openRefs.Get(file.openId));

        if (openRef == null)
        {
            openRef = new OpenRef(file);
            openRefs.Set(file.openId, openRef);
        }
        openRef.openSequence           = ++lastOpenSequence;
        openAttribs.openId             = file.openId;
        openAttribs.openSequence       = openRef.openSequence;
        openAttribs.accessLevel        = Pfm.accessLevelWriteData;
        openAttribs.attribs.fileType   = file.fileType;
        openAttribs.attribs.fileFlags  = file.fileFlags;
        openAttribs.attribs.fileId     = file.fileId;
        openAttribs.attribs.createTime = file.createTime;
        openAttribs.attribs.accessTime = file.accessTime;
        openAttribs.attribs.writeTime  = file.writeTime;
        openAttribs.attribs.changeTime = file.changeTime;
        openAttribs.attribs.fileSize   = file.fileSize;
    }
Пример #10
0
        public void Access(Pfm.MarshallerAccessOp op)
        {
            long openId = op.OpenId();
            int  err    = 0;

            Pfm.OpenAttribs att = new Pfm.OpenAttribs();
            if (opens.ContainsKey(openId))
            {
                var entry = opens[openId];
                att.accessLevel = Pfm.accessLevelReadData;
                SetAttTime(ref att.attribs, entry);
                att.attribs.fileType = entry.isdir != 0 ? Pfm.fileTypeFolder : Pfm.fileTypeFile;
                att.attribs.fileId   = GetFileId(entry);
                att.attribs.fileSize = entry.size;
                att.openId           = openId;
                att.openSequence     = 1;
            }
            else
            {
                err = Pfm.errorNotFound;
            }
            op.Complete(err, att, null);
        }
Пример #11
0
        public void Open(Pfm.MarshallerOpenOp op)
        {
            int  perr    = 0;
            bool existed = false;

            Pfm.OpenAttribs openAttribs       = new Pfm.OpenAttribs();
            long            parentFileId      = 0;
            string          endName           = null;
            long            newExistingOpenId = op.NewExistingOpenId();

            var names = op.NameParts();

            string des = "open:opennedid:" + opennedid.ToString() + ";names:" + String.Join(";", names);

            Debug.WriteLine(des);

            if (names.Length == 0)
            {
                if (opennedid == 0)
                {
                    opennedid = newExistingOpenId;
                    Entry entry = new Entry();
                    entry.isdir = 1;
                    opens.Add(opennedid, entry);
                }
                existed                      = true;
                openAttribs.openId           = opennedid;
                openAttribs.openSequence     = 1;
                openAttribs.accessLevel      = Pfm.accessLevelReadData;
                openAttribs.attribs.fileId   = GetFileId(opens[opennedid]);
                openAttribs.attribs.fileType = Pfm.fileTypeFolder;
            }
            else// if (names.Length == 1)
            {
                Entry entry = GetEntryByName(names);
                if (entry == null)
                {
                    perr = Pfm.errorNotFound;
                }
                else
                {
                    long id = GetOpenId(entry, newExistingOpenId);
                    existed                      = true;
                    openAttribs.openId           = id;
                    openAttribs.openSequence     = 1;
                    openAttribs.accessLevel      = Pfm.accessLevelReadData;
                    openAttribs.attribs.fileType = entry.isdir != 0 ? Pfm.fileTypeFolder : Pfm.fileTypeFile;
                    openAttribs.attribs.fileId   = GetFileId(entry);
                    openAttribs.attribs.fileSize = entry.size;
                    SetAttTime(ref openAttribs.attribs, entry);

                    endName = entry.server_filename;
                }
            }
            //else
            //{
            //    Debug.WriteLine(string.Format("opendId:{0},names:{1}", opennedid, String.Join(";", names)));
            //    perr = Pfm.errorParentNotFound;
            //}
            op.Complete(perr, existed, openAttribs, parentFileId, endName, 0, null, 0, null);
        }