public int OpenDirectory(int midx, String filename, DokanFileInfo info)
        {
            Inode_Info i = inode_exists_internal(midx, filename, "opendir", false, false);

            if (i != null && i.isfile == false)
            {
                info.IsDirectory = true;
                return(0);
            }
            bool status = open_directory_internal(midx, filename);

            return((status)? 0 : -DokanNet.ERROR_PATH_NOT_FOUND);
        }
        public bool CloneDirectoryTlock(int srcfsid, String sourcedir, int destfsid, String destinationdir)
        {
            string destdirpath = ExtractParentPath(destinationdir);

            if (destdirpath == null)
            {
                return(false);
            }


            Inode_Info destdiri = inode_exists_internal(destfsid, destdirpath, "dclone1", false, false);

            if (destdiri == null)
            {
                return(false);
            }
            Inode_Info destdiri2 = inode_exists_internal(destfsid, destinationdir, "dclone2", false, false);

            if (destdiri2 != null)
            {
                return(false);
            }

            Inode_Info srcdirA = inode_exists_internal(srcfsid, sourcedir, "dclone3", true, false);

            if (srcdirA == null)
            {
                return(false);
            }

            int        count   = srcdirA.nodecount;
            int        pino    = destdiri.ino;
            List <int> inolist = NEXT_N_INODE_NUMBERS(destfsid, count);

            CDirectory newdir = REDDY.FSIDList[srcfsid].rootdir.clone_directory_tlock(sourcedir, destfsid, inolist, pino, destdirpath);

            if (newdir == null)
            {
                return(false);
            }

            newdir.rename_directory(ADFN(destinationdir));
            if (REDDY.FSIDList[destfsid].rootdir.insert_clonedirectory_tlock(destdirpath, newdir) == false)
            {
                //delete the wip.
                newdir.remove_orphan_directory();
                return(false);
            }
            return(true);
        }
示例#3
0
        private void backup_folder(bool firstjob, string oldchecksumfile, string newchecksumfile, ref int curroffset, string sourcedir, string destdir)
        {
            DirectoryInfo srcdi = new DirectoryInfo(sourcedir);
            Inode_Info    di    = REDDY.ptrIFSDMux.GetFileInfoInternalAPI(2, destdir);

            if (srcdi.Exists == false && di == null)
            {
                return;
            }
            else if (srcdi.Exists == false && di != null)
            {
                REDDY.ptrIFSDMux.DeleteDirectory(2, destdir, null);
                return;
            }
            else
            {
                if (srcdi.Exists == true && di == null)
                {
                    /*
                     * Create a new directory and recusively restore directories and files.
                     */
                    REDDY.ptrIFSDMux.CreateDirectory(2, destdir, null);
                }
                else if (srcdi.Exists == true && di != null)
                {
                    /*
                     * Restore directory by directory, if dest subdir does not exist, call this recursviely.
                     * do the same for files.
                     */
                }

                string[] flist = get_file_list(sourcedir, destdir);
                for (int i = 0; i < flist.Length; i++)
                {
                    backup_file(firstjob, oldchecksumfile, newchecksumfile, ref curroffset, sourcedir + "\\" + flist[i], destdir + "\\" + flist[i]);
                    REDDY.FSIDList[2].set_dirty(true);
                }

                string[] dlist = get_dir_list(sourcedir, destdir);
                for (int i = 0; i < dlist.Length; i++)
                {
                    backup_folder(firstjob, oldchecksumfile, newchecksumfile, ref curroffset, sourcedir + "\\" + dlist[i], destdir + "\\" + dlist[i]);
                    REDDY.FSIDList[2].set_dirty(true);
                }
            }
        }
        public int GetFileInformation(int midx, String filename, FileInformation fileinfo, DokanFileInfo info)
        {
            Inode_Info i = inode_exists_internal(midx, filename, "getfinfo", false, false);

            if (i != null)
            {
                fileinfo.Attributes     = i.fa;
                fileinfo.FileName       = i.name;
                fileinfo.CreationTime   = i.CreationTime;
                fileinfo.LastAccessTime = i.LastAccessTime;
                fileinfo.LastWriteTime  = i.LastWriteTime;
                fileinfo.Length         = (i.isfile == true) ? i.size : 0;
                info.IsDirectory        = (i.isfile == true) ? false : true;
                return(0);
            }
            else
            {
                return(-DokanNet.ERROR_PATH_NOT_FOUND);
            }
        }
        /*
         * a. Check that the destination directory exists, and get its inode number
         * b. Allocate a new inode in the destination fsid.
         * c. clone the source file.
         * d. Insert into the destination.
         * e. If failed, do error handling.
         */
        public bool CloneFileTLock(int srcfsid, String sourcefile, int destfsid, String destinationfile)
        {
            string destdirpath = ExtractParentPath(destinationfile);

            if (destdirpath == null)
            {
                DEFS.DEBUG("CLONEF", "couldnot parse parent path");
                return(false);
            }

            Inode_Info destdiri = inode_exists_internal(destfsid, destdirpath, "clone", false, false);

            if (destdiri == null || destdiri.fa == FileAttributes.Normal)
            {
                DEFS.DEBUG("CLONEF", "destdir is absent or is a file");
                return(false);
            }

            int pino   = destdiri.ino;
            int newino = find_free_ino_bit(destfsid);

            CFile newfile = REDDY.FSIDList[srcfsid].rootdir.clone_file_tlock(sourcefile, destfsid, newino, pino, destinationfile);

            if (newfile == null)
            {
                DEFS.DEBUG("CLONEF", "failed to clone file " + sourcefile);
                return(false);
            }

            newfile.rename_file(ADFN(destinationfile));
            if (REDDY.FSIDList[destfsid].rootdir.insert_clonefile_tlock(destdirpath, newfile) == false)
            {
                //delete the wip.
                newfile.remove_ondisk_data2();
                return(false);
            }
            REDDY.FSIDList[destfsid].set_dirty(true);
            return(true);
        }
        /*
         * Below are dokan callback function. Have included here so that
         * we can use locks internally for accsssing _rootdir.
         * midx == mounted idx which is the mounted fsid.
         */
        public int CreateFile(int midx, String filename, FileAccess access, FileShare share,
                              FileMode mode, FileOptions options, DokanFileInfo info)
        {
            Inode_Info i = inode_exists_internal(midx, filename, "createfile", false, false);

            if (i != null)
            {
                if (i.isfile == false)
                {
                    info.IsDirectory = true;
                }
                return(0);// -DokanNet.ERROR_ALREADY_EXISTS;
            }

            if (mode == FileMode.Open)
            {
                return(-1);
            }

            bool status = create_file_internal(midx, filename);

            REDDY.FSIDList[midx].set_dirty(true);
            return((status)? 0 : -DokanNet.DOKAN_ERROR);
        }
示例#7
0
        private bool backup_file(bool firstjob, string oldchecksumfile, string newchecksumfile, ref int curroffset, string sourcefile, string destfile)
        {
            DEFS.DEBUG("BACKUP", "Entering backup_file ( " + firstjob + "," + oldchecksumfile + "," +
                       newchecksumfile + "," + curroffset + "," + sourcefile + "," + destfile);

            MD5 md5 = System.Security.Cryptography.MD5.Create();
            fingerprintBACKUP fptemp1 = new fingerprintBACKUP();
            fingerprintBACKUP fptemp2 = new fingerprintBACKUP();

            if (firstjob)
            {
                FileInfo srcfi = new FileInfo(sourcefile);
                if (srcfi.Exists == false)
                {
                    REDDY.ptrIFSDMux.DeleteFile(2, destfile, null);
                    return(false);
                }
                else
                {
                    if (REDDY.ptrIFSDMux.CreateFile(2, destfile, FileAccess.ReadWrite, FileShare.ReadWrite, FileMode.Create, FileOptions.None, null) != 0)
                    {
                        MessageBox.Show("failed to create file 1");
                        return(false);
                    }

                    if (REDDY.ptrIFSDMux.SetEndOfFile(2, destfile, srcfi.Length, null) != 0)
                    {
                        MessageBox.Show("failed to seteof 1");
                        return(false);
                    }

                    Inode_Info di = REDDY.ptrIFSDMux.GetFileInfoInternalAPI(2, destfile);
                    REDDY.ptrIFSDMux.SetInternalFlag(2, destfile, 0, curroffset);

                    if (di == null)
                    {
                        MessageBox.Show("failed to get a valid di 1");
                        return(false);
                    }
                    int ino = di.ino;

                    byte[] buffer = new byte[4096];
                    byte[] tmpbuf = new byte[((Item)fptemp1).get_size()];
                    uint   wrote  = 0;

                    int bcount = OPS.NUML0(srcfi.Length);

                    FileStream fs = new FileStream(sourcefile, FileMode.Open);

                    long   outfileoffset = 0;
                    byte[] lastchunkbuf  = null;

                    for (int i = 0; i < bcount; i++)
                    {
                        int size = fs.Read(buffer, 0, 4096);
                        if (size < 4096)
                        {
                            lastchunkbuf = new byte[size];
                            for (int kx = size; kx < 4096; kx++)
                            {
                                buffer[kx] = 0;
                            }
                            for (int kx2 = 0; kx2 < size; kx2++)
                            {
                                lastchunkbuf[kx2] = buffer[kx2];
                            }
                        }
                        byte[] hash = md5.ComputeHash(buffer, 0, 4096);

                        fptemp1.inode = ino;
                        fptemp1.fbn   = i;
                        for (int k = 0; k < 16; k++)
                        {
                            fptemp1.fp[k] = hash[k];
                        }
                        ((Item)fptemp1).get_bytes(tmpbuf, 0);

                        if (REDDY.ptrIFSDMux.WriteFile(2, newchecksumfile, tmpbuf, ref wrote, curroffset, null) != 0)
                        {
                            MessageBox.Show("write failed, wrote = " + wrote);
                            return(false);
                        }
                        if (size > 0)
                        {
                            if (size == 4096)
                            {
                                if (REDDY.ptrIFSDMux.WriteFile(2, destfile, buffer, ref wrote, outfileoffset, null) != 0)
                                {
                                    MessageBox.Show("write failed ee, wrote = " + wrote);
                                    return(false);
                                }
                            }
                            else
                            {
                                if (REDDY.ptrIFSDMux.WriteFile(2, destfile, lastchunkbuf, ref wrote, outfileoffset, null) != 0)
                                {
                                    MessageBox.Show("write failed ee2, wrote = " + wrote);
                                    return(false);
                                }
                            }
                        }
                        newdatacopied += size;
                        outfileoffset += size;

                        curroffset += ((Item)fptemp1).get_size();
                    }
                    //if (REDDY.ptrIFSDMux.SetEndOfFile(2, destfile, srcfi.Length, null) != 0)
                    //{
                    //    MessageBox.Show("failed to seteof 1a");
                    //    return false;
                    //}
                    fs.Close();
                    REDDY.FSIDList[2].set_dirty(true);
                    return(true);
                }
            }
            else
            {
                DEFS.ASSERT(oldchecksumfile != null, "You must pass the oldchecksumfile path");

                FileInfo srcfi = new FileInfo(sourcefile);
                if (srcfi.Exists == false)
                {
                    REDDY.ptrIFSDMux.DeleteFile(2, destfile, null);
                    return(false);
                }
                else
                {
                    if (REDDY.ptrIFSDMux.CreateFile(2, destfile, FileAccess.ReadWrite, FileShare.ReadWrite, FileMode.CreateNew, FileOptions.None, null) != 0)
                    {
                        MessageBox.Show("Createfile has failed");
                        return(false);
                    }
                    if (REDDY.ptrIFSDMux.SetEndOfFile(2, destfile, srcfi.Length, null) != 0)
                    {
                        MessageBox.Show("Set eof has failed!");
                        return(false);
                    }

                    Inode_Info di         = REDDY.ptrIFSDMux.GetFileInfoInternalAPI(2, destfile);
                    int        localoffet = di.backupoffset;

                    REDDY.ptrIFSDMux.SetInternalFlag(2, destfile, 0, curroffset);

                    int ino = di.ino;

                    byte[] buffer = new byte[4096];
                    byte[] tmpbuf = new byte[((Item)fptemp1).get_size()];
                    uint   wrote  = 0;

                    int bcount = OPS.NUML0(srcfi.Length);

                    FileStream fs = new FileStream(sourcefile, FileMode.Open);

                    long   outfileoffset = 0;
                    byte[] lastchunkbuf  = null;

                    DEFS.DEBUG("--------", bcount + ", ArrangeStartingPosition LOOP ");
                    for (int i = 0; i < bcount; i++)
                    {
                        int size = fs.Read(buffer, 0, 4096);
                        if (size < 4096)
                        {
                            lastchunkbuf = new byte[size];
                            for (int kx = size; kx < 4096; kx++)
                            {
                                buffer[kx] = 0;
                            }
                            for (int kx2 = 0; kx2 < size; kx2++)
                            {
                                lastchunkbuf[kx2] = buffer[kx2];
                            }
                        }
                        byte[] hash = md5.ComputeHash(buffer, 0, 4096);
                        fptemp1.inode = ino;
                        fptemp1.fbn   = i;
                        for (int k = 0; k < 16; k++)
                        {
                            fptemp1.fp[k] = hash[k];
                        }

                        byte[] existinghash = new byte[24];
                        uint   readsize     = 0;

                        if (REDDY.ptrIFSDMux.ReadFile(2, oldchecksumfile, existinghash, ref readsize, localoffet, null) != 0)
                        {
                            MessageBox.Show("read failed, " + readsize + ",path = " + oldchecksumfile);
                            return(false);
                        }
                        ((Item)fptemp2).parse_bytes(existinghash, 0);

                        if (!(/* fptemp1.inode == fptemp2.inode &&*/ fptemp1.fbn == fptemp2.fbn &&
                              is_equal(fptemp1.fp, fptemp2.fp)))
                        {
                            if (size > 0)
                            {
                                if (size == 4096)
                                {
                                    if (REDDY.ptrIFSDMux.WriteFile(2, destfile, buffer, ref wrote, outfileoffset, null) != 0)
                                    {
                                        MessageBox.Show("write failed ee, wrote = " + wrote);
                                        return(false);
                                    }
                                }
                                else
                                {
                                    if (REDDY.ptrIFSDMux.WriteFile(2, destfile, lastchunkbuf, ref wrote, outfileoffset, null) != 0)
                                    {
                                        MessageBox.Show("write failed ee2, wrote = " + wrote);
                                        return(false);
                                    }
                                }
                            }
                            newdatacopied += size;
                        }

                        ((Item)fptemp1).get_bytes(tmpbuf, 0);
                        if (REDDY.ptrIFSDMux.WriteFile(2, newchecksumfile, tmpbuf, ref wrote, curroffset, null) != 0)
                        {
                            MessageBox.Show("write failed 22, wrote = " + wrote);
                            return(false);
                        }

                        curroffset    += ((Item)fptemp1).get_size();
                        localoffet    += ((Item)fptemp1).get_size();
                        outfileoffset += size;
                        //DEFS.DEBUG("---", bcount + "," + fs.Position);
                    }

                    fs.Close();

                    if (REDDY.ptrIFSDMux.SetEndOfFile(2, destfile, srcfi.Length, null) != 0)
                    {
                        MessageBox.Show("Set eof has failed! 2");
                        return(false);
                    }

                    DEFS.DEBUG("--------", bcount + ", ArrangeStartingPosition LOOP sdfsfda");
                    REDDY.FSIDList[2].set_dirty(true);
                    return(true);
                }
            }
        }
        public Inode_Info GetFileInfoInternalAPI(int fsid, string filename)
        {
            Inode_Info i = inode_exists_internal(fsid, filename, "getfinfo", false, true);

            return(i);
        }