예제 #1
0
        private void do_inode_refupdate_work(UpdateReqI cu, int childcnt)
        {
            byte[] buffer = new byte[4096];

            lock (tfile0)
            {
                tfile0.Seek((long)cu.tfbn * 4096, SeekOrigin.Begin);
                tfile0.Read(tmpiodatatfileR, 0, 4096);
                CONFIG.Decrypt_Read_WRBuf(tmpiodatatfileR, buffer);
                //DEFS.DEBUG("ENCY", "READ inoLo : " + OPS.ChecksumPageWRLoader(buffer));
                DEFS.DEBUG("CNTR", "do_inode_refupdate_work (" + cu.tfbn + ") childcnt =" + childcnt);
            }

            /*
             * Parent of inowip is always -1.
             */
            RedFS_Inode wip = new RedFS_Inode(WIP_TYPE.REGULAR_FILE, 0, -1);

            byte[] buf = new byte[128];

            for (int i = 0; i < 32; i++)
            {
                for (int t = 0; t < 128; t++)
                {
                    buf[t] = buffer[i * 128 + t];
                }
                wip.parse_bytes(buf);

                BLK_TYPE type   = BLK_TYPE.IGNORE;
                int      numidx = 0;

                switch (wip.get_inode_level())
                {
                case 0:
                    type   = BLK_TYPE.REGULAR_FILE_L0;
                    numidx = OPS.NUML0(wip.get_filesize());
                    break;

                case 1:
                    type   = BLK_TYPE.REGULAR_FILE_L1;
                    numidx = OPS.NUML1(wip.get_filesize());
                    break;

                case 2:
                    type   = BLK_TYPE.REGULAR_FILE_L2;
                    numidx = OPS.NUML2(wip.get_filesize());
                    break;
                }

                for (int x = 0; x < numidx; x++)
                {
                    int dbn = wip.get_child_dbn(x);
                    //if (dbn <= 0) continue;
                    DEFS.DEBUGCLR("^^^^^", "wip[" + x + "] " + dbn + "," + wip.get_wiptype() + "," + childcnt + " fsize = " + wip.get_filesize());
                    DEFS.DEBUGCLR("@@@", wip.get_string_rep2());
                    apply_update_internal(dbn, type, childcnt, cu.optype, true);
                }
            }
            OPS.dump_inoL0_wips(buffer);
        }
예제 #2
0
        public static bool Checkin_Wip(RedFS_Inode inowip, RedFS_Inode mywip, int m_ino)
        {
            DEFS.ASSERT(m_ino == mywip.get_ino(), "Inode numbers dont match, can lead to corruption " + m_ino + "," + mywip.get_ino());
            long fileoffset = m_ino * 128;

            lock (inowip)
            {
                REDDY.ptrRedFS.redfs_write(inowip, fileoffset, mywip.data, 0, 128);
                DEFS.DEBUG("OPS", "CheckIn wip " + mywip.get_ino() + " size = " + mywip.get_filesize());
                inowip.is_dirty = true;
            }
            DEFS.DEBUG("CI_WIP", mywip.get_string_rep2());
            return(true);
        }
예제 #3
0
        public bool read(byte[] buffer, int bufoffset, int buflen, long fileoffset)
        {
            if (m_state == FILE_STATE.FILE_DELETED)
            {
                return(false);
            }
            lock (this)
            {
                if (_mywip == null || (fileoffset >= m_size))
                {
                    OPS.BZERO(buffer);
                    return(false);
                }

                long request_end_offset = fileoffset + buflen;
                if (request_end_offset > m_size)
                {
                    int  old_buflen      = buflen;
                    long true_end_offset = m_size;
                    DEFS.DEBUG("ERROR", "Trying to read beyond EOF = " + m_size + "  (start_offset, end_offset) = " +
                               fileoffset + "," + (fileoffset + buflen));
                    buflen = (int)(true_end_offset - fileoffset);
                    DEFS.ASSERT(old_buflen >= buflen, "Something wrong in calculation");
                    for (int i = (bufoffset + buflen); i < (bufoffset + old_buflen); i++)
                    {
                        buffer[i] = 0;
                    }
                }

                REDDY.ptrRedFS.redfs_read(_mywip, fileoffset, buffer, bufoffset, buflen);

                /*
                 * VLC and office apps tries to read beyond EOF, and we end up growing the file, this happens
                 * with filesize blowing up infinitely.
                 */
                m_size = _mywip.get_filesize();
                touch();
                return(true);
            }
        }
예제 #4
0
        /*
         * We dont expect a write to come before opening because, cdirectory would
         * call a open_file() before inserting into the DIR CACHE. We shouldnt call
         * this with cfile-lock held.
         */
        public bool open_file(bool justcreated)
        {
            if (m_state == FILE_STATE.FILE_DELETED)
            {
                return(false);
            }
            else if (m_state == FILE_STATE.FILE_IN_DOKAN_IO)
            {
                DEFS.ASSERT(_mywip != null, "My wip cannot be null when dokan_io flag is set in open_file");
                return(true);
            }

            touch();
            if (_mywip == null)
            {
                lock (this)
                {
                    if (_mywip != null)
                    {
                        /*
                         * It could be the case that someone already opend it, maybe previous call
                         * that was locked in open_file(), just bail out.
                         */
                        DEFS.ASSERT(m_state != FILE_STATE.FILE_IN_DOKAN_IO, "Suddendly cannot be in dokan io when it was just null");
                        return(true);
                    }

                    lock (REDDY.FSIDList[m_associated_fsid])
                    {
                        _mywip = new RedFS_Inode(WIP_TYPE.REGULAR_FILE, m_inode, m_parent_inode);
                        long oldsize = _mywip.get_filesize();

                        RedFS_Inode inowip = REDDY.FSIDList[m_associated_fsid].get_inode_file_wip("OF:" + m_name);
                        DEFS.DEBUG("F(_mywip)", "Loaded ino= " + m_inode + "wip from disk, size = " + _mywip.get_filesize());

                        bool ret = OPS.Checkout_Wip2(inowip, _mywip, m_inode);

                        if (ret)
                        {
                            DEFS.DEBUG("FILE", "Loaded ino= " + m_inode + "wip from disk, size = " + _mywip.get_filesize());
                        }
                        else
                        {
                            DEFS.DEBUG("FILE", "Loaded ino = " + m_inode + " (new) size = " + _mywip.get_filesize());
                            _mywip.set_ino(m_parent_inode, m_inode);
                        }

                        DEFS.ASSERT(m_size == _mywip.get_filesize(), "File size should match, irrespecitive of weather its " +
                                    " from disk, (=0) then, or inserted from an existing dir load, >= 0 in that case, msize:" + m_size +
                                    " _mywip.size:" + _mywip.get_filesize() + " fname =" + m_name + " ino=" + m_inode + " beforeread size = " +
                                    oldsize + " contents : " + _mywip.get_string_rep2() + " ret = " + ret);

                        if (justcreated)
                        {
                            DEFS.ASSERT(ret == false, "This should be a new file " + _mywip.get_filesize() + " fname =" + m_name +
                                        " ino=" + m_inode + " beforeread size = " + oldsize + " contents : " + _mywip.get_string_rep2());
                            _mywip.setfilefsid_on_dirty(m_associated_fsid);
                            _mywip.is_dirty = true; //this must make it to disk.
                        }
                        REDDY.FSIDList[m_associated_fsid].sync_internal();
                        m_state = FILE_STATE.FILE_DEFAULT;
                    }
                }
            }
            return(true);
        }
예제 #5
0
        public static long ComputeNextStartFbn(RedFS_Inode wip)
        {
            int cnt = NUML0(wip.get_filesize());

            return((long)cnt * 4096);
        }