Beispiel #1
0
        public int WriteFile(
            String filename,
            Byte[] buffer,
            ref uint writtenBytes,
            long offset,
            DokanFileInfo info)
        {
            Debug("WriteFile {0} bufferLen {1} Offset {2}", filename, buffer.Length, offset);

            string path = GetPath(filename);

            if (path.Contains(":SSHFSProperty.Permission"))
            {
                if (offset == 0)
                {
                    string[] tmp = path.Split(new char[] { ':' });
                    path = tmp[0];
                    int permission = 0;
                    permission = Convert.ToInt32(System.Text.Encoding.ASCII.GetString(buffer), 8);
                    WritePermission(path, permission);
                    writtenBytes = (uint)buffer.Length;
                    return(0);
                }
                else
                {
                    writtenBytes = 0;
                    return(0);
                }
            }

            try
            {
                ChannelSftp channel = GetChannel();
                //GetMonitor monitor = new GetMonitor(buffer.Length);
                Tamir.SharpSsh.java.io.OutputStream stream = channel.put(path, null, 3 /*HACK: 存在しないモード */, offset);
                stream.Write(buffer, 0, buffer.Length);
                stream.Close();
                writtenBytes = (uint)buffer.Length;
                return(0);
            }
            catch (IOException)
            {
                return(0);
            }
            catch (Exception e)
            {
                Debug(e.ToString());
                return(-1);
            }
        }
Beispiel #2
0
        public NtStatus CreateFile(
            string filename,
            DokanNet.FileAccess access,
            FileShare share,
            FileMode mode,
            FileOptions options,
            FileAttributes attributes,
            DokanFileInfo info)
        {
            if (info.IsDirectory)
            {
                switch (mode)
                {
                case FileMode.Open:
                    Debug("OpenDirectory {0}", filename);
                    try
                    {
                        string    path = GetPath(filename);
                        SftpATTRS attr = GetChannel().stat(path);
                        if (attr.isDir())
                        {
                            return(NtStatus.Success);
                        }
                        else
                        {
                            return(NtStatus.ObjectPathNotFound);    // TODO: return not directory?
                        }
                    }
                    catch (SftpException e)
                    {
                        Debug(e.ToString());
                        return(NtStatus.ObjectPathNotFound);
                    }
                    catch (Exception e)
                    {
                        connectionError_ = true;
                        Debug(e.ToString());
                        Reconnect();
                        return(NtStatus.ObjectPathNotFound);
                    }


                case FileMode.CreateNew:
                    Debug("CreateDirectory {0}", filename);
                    try
                    {
                        string      path    = GetPath(filename);
                        ChannelSftp channel = GetChannel();

                        channel.mkdir(path);
                        return(NtStatus.Success);
                    }
                    catch (SftpException e)
                    {
                        Debug(e.ToString());
                        return(NtStatus.Error);
                    }
                    catch (Exception e)
                    {
                        connectionError_ = true;
                        Debug(e.ToString());
                        Reconnect();
                        return(NtStatus.Error);    // TODO: more appropriate error code
                    }

                default:
                    Debug("Error FileMode invalid for directory {0}", mode);
                    return(NtStatus.Error);
                }
            }
            else
            {
                Debug("CreateFile {0}", filename);
                try
                {
                    string      path    = GetPath(filename);
                    ChannelSftp channel = GetChannel();

                    if (CheckAltStream(path))
                    {
                        return(NtStatus.Success);
                    }

                    switch (mode)
                    {
                    case FileMode.Open:
                    {
                        Debug("Open");
                        if (isExist(path, info))
                        {
                            return(NtStatus.Success);
                        }
                        else
                        {
                            return(NtStatus.ObjectNameNotFound);
                        }
                    }

                    case FileMode.CreateNew:
                    {
                        Debug("CreateNew");
                        if (isExist(path, info))
                        {
                            return(NtStatus.ObjectNameCollision);
                        }

                        Debug("CreateNew put 0 byte");
                        Tamir.SharpSsh.java.io.OutputStream stream = channel.put(path);
                        stream.Close();
                        return(NtStatus.Success);
                    }

                    case FileMode.Create:
                    {
                        Debug("Create put 0 byte");
                        Tamir.SharpSsh.java.io.OutputStream stream = channel.put(path);
                        stream.Close();
                        return(NtStatus.Success);
                    }

                    case FileMode.OpenOrCreate:
                    {
                        Debug("OpenOrCreate");

                        if (!isExist(path, info))
                        {
                            Debug("OpenOrCreate put 0 byte");
                            Tamir.SharpSsh.java.io.OutputStream stream = channel.put(path);
                            stream.Close();
                        }
                        return(NtStatus.Success);
                    }

                    case FileMode.Truncate:
                    {
                        Debug("Truncate");

                        if (!isExist(path, info))
                        {
                            return(NtStatus.ObjectNameNotFound);
                        }

                        Debug("Truncate put 0 byte");
                        Tamir.SharpSsh.java.io.OutputStream stream = channel.put(path);
                        stream.Close();
                        return(NtStatus.Success);
                    }

                    case FileMode.Append:
                    {
                        Debug("Append");

                        if (isExist(path, info))
                        {
                            return(NtStatus.Success);
                        }

                        Debug("Append put 0 byte");
                        Tamir.SharpSsh.java.io.OutputStream stream = channel.put(path);
                        stream.Close();
                        return(NtStatus.Success);
                    }

                    default:
                        Debug("Error unknown FileMode {0}", mode);
                        return(NtStatus.Error);
                    }
                }
                catch (SftpException e)
                {
                    Debug(e.ToString());
                    return(NtStatus.ObjectNameNotFound);
                }
                catch (Exception e)
                {
                    connectionError_ = true;
                    Debug(e.ToString());
                    Reconnect();
                    return(NtStatus.ObjectNameNotFound);
                }
            }
        }
Beispiel #3
0
        public int CreateFile(
            String filename,
            FileAccess access,
            FileShare share,
            FileMode mode,
            FileOptions options,
            DokanFileInfo info)
        {
            Debug("CreateFile {0}", filename);
            try
            {
                string      path    = GetPath(filename);
                ChannelSftp channel = GetChannel();

                if (CheckAltStream(path))
                {
                    return(0);
                }

                switch (mode)
                {
                case FileMode.Open:
                {
                    Debug("Open");
                    if (isExist(path, info))
                    {
                        return(0);
                    }
                    else
                    {
                        return(-DokanNet.ERROR_FILE_NOT_FOUND);
                    }
                }

                case FileMode.CreateNew:
                {
                    Debug("CreateNew");
                    if (isExist(path, info))
                    {
                        return(-DokanNet.ERROR_ALREADY_EXISTS);
                    }

                    Debug("CreateNew put 0 byte");
                    Tamir.SharpSsh.java.io.OutputStream stream = channel.put(path);
                    stream.Close();
                    return(0);
                }

                case FileMode.Create:
                {
                    Debug("Create put 0 byte");
                    Tamir.SharpSsh.java.io.OutputStream stream = channel.put(path);
                    stream.Close();
                    return(0);
                }

                case FileMode.OpenOrCreate:
                {
                    Debug("OpenOrCreate");

                    if (!isExist(path, info))
                    {
                        Debug("OpenOrCreate put 0 byte");
                        Tamir.SharpSsh.java.io.OutputStream stream = channel.put(path);
                        stream.Close();
                    }
                    return(0);
                }

                case FileMode.Truncate:
                {
                    Debug("Truncate");

                    if (!isExist(path, info))
                    {
                        return(-DokanNet.ERROR_FILE_NOT_FOUND);
                    }

                    Debug("Truncate put 0 byte");
                    Tamir.SharpSsh.java.io.OutputStream stream = channel.put(path);
                    stream.Close();
                    return(0);
                }

                case FileMode.Append:
                {
                    Debug("Append");

                    if (isExist(path, info))
                    {
                        return(0);
                    }

                    Debug("Append put 0 byte");
                    Tamir.SharpSsh.java.io.OutputStream stream = channel.put(path);
                    stream.Close();
                    return(0);
                }

                default:
                    Debug("Error unknown FileMode {0}", mode);
                    return(-1);
                }
            }
            catch (SftpException e)
            {
                Debug(e.ToString());
                return(-DokanNet.ERROR_FILE_NOT_FOUND);
            }
            catch (Exception e)
            {
                connectionError_ = true;
                Debug(e.ToString());
                Reconnect();
                return(-DokanNet.ERROR_FILE_NOT_FOUND);
            }
        }
Beispiel #4
0
        public DokanError CreateFile(
            string filename,
            DokanNet.FileAccess access,
            FileShare share,
            FileMode mode,
            FileOptions options,
            FileAttributes attributes,
            DokanFileInfo info)
        {
            Debug("CreateFile {0}", filename);
            try
            {
                string      path    = GetPath(filename);
                ChannelSftp channel = GetChannel();

                if (CheckAltStream(path))
                {
                    return(DokanError.ErrorSuccess);
                }

                switch (mode)
                {
                case FileMode.Open:
                {
                    Debug("Open");
                    if (isExist(path, info))
                    {
                        return(DokanError.ErrorSuccess);
                    }
                    else
                    {
                        return(DokanError.ErrorFileNotFound);
                    }
                }

                case FileMode.CreateNew:
                {
                    Debug("CreateNew");
                    if (isExist(path, info))
                    {
                        return(DokanError.ErrorAlreadyExists);
                    }

                    Debug("CreateNew put 0 byte");
                    Tamir.SharpSsh.java.io.OutputStream stream = channel.put(path);
                    stream.Close();
                    return(DokanError.ErrorSuccess);
                }

                case FileMode.Create:
                {
                    Debug("Create put 0 byte");
                    Tamir.SharpSsh.java.io.OutputStream stream = channel.put(path);
                    stream.Close();
                    return(DokanError.ErrorSuccess);
                }

                case FileMode.OpenOrCreate:
                {
                    Debug("OpenOrCreate");

                    if (!isExist(path, info))
                    {
                        Debug("OpenOrCreate put 0 byte");
                        Tamir.SharpSsh.java.io.OutputStream stream = channel.put(path);
                        stream.Close();
                    }
                    return(DokanError.ErrorSuccess);
                }

                case FileMode.Truncate:
                {
                    Debug("Truncate");

                    if (!isExist(path, info))
                    {
                        return(DokanError.ErrorFileNotFound);
                    }

                    Debug("Truncate put 0 byte");
                    Tamir.SharpSsh.java.io.OutputStream stream = channel.put(path);
                    stream.Close();
                    return(DokanError.ErrorSuccess);
                }

                case FileMode.Append:
                {
                    Debug("Append");

                    if (isExist(path, info))
                    {
                        return(DokanError.ErrorSuccess);
                    }

                    Debug("Append put 0 byte");
                    Tamir.SharpSsh.java.io.OutputStream stream = channel.put(path);
                    stream.Close();
                    return(DokanError.ErrorSuccess);
                }

                default:
                    Debug("Error unknown FileMode {0}", mode);
                    return(DokanError.ErrorError);
                }
            }
            catch (SftpException e)
            {
                Debug(e.ToString());
                return(DokanError.ErrorFileNotFound);
            }
            catch (Exception e)
            {
                connectionError_ = true;
                Debug(e.ToString());
                Reconnect();
                return(DokanError.ErrorFileNotFound);
            }
        }