public void sync() { lock (this) { if (_mywip != null) { lock (REDDY.FSIDList[m_associated_fsid]) { RedFS_Inode inowip = REDDY.FSIDList[m_associated_fsid].get_inode_file_wip("GC"); DEFS.DEBUG("SYNC", "CFile (" + m_inode + ") -mywip.size = " + _mywip.get_filesize()); REDDY.ptrRedFS.sync(_mywip); OPS.Checkin_Wip(inowip, _mywip, m_inode); _mywip.is_dirty = false; REDDY.FSIDList[m_associated_fsid].sync_internal(); REDDY.ptrRedFS.redfs_commit_fsid(REDDY.FSIDList[m_associated_fsid]); } } else { DEFS.DEBUG("FSID", "inserted/unsyncd : " + m_name); } } }
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); }
public int SetEndOfFile(String filename, long length, DokanFileInfo info) { DEFS.DEBUG("DOKAN", "SetEndOfFile(" + filename + "," + length); int midx = REDDY.mountedidx; return(ifs.SetEndOfFile(midx, filename, length, info)); }
/* * Need to look up refcount file/bitmap file. */ private void clean_clog_file_P2(string input, string output) { DEFS.DEBUG("DEDUPE", "Starting clog P2"); Item fp = new fingerprintCLOG(DEDUP_SORT_ORDER.UNDEFINED_PLACEHOLDER); byte[] buffer = new byte[fp.get_size()]; FileStream fsrc = new FileStream(input, FileMode.Open); FileStream fdest = new FileStream(output, FileMode.Create); long count = fsrc.Length / fp.get_size(); int final = 0; for (int i = 0; i < count; i++) { fsrc.Read(buffer, 0, fp.get_size()); fp.parse_bytes(buffer, 0); fingerprintCLOG fpt = (fingerprintCLOG)fp; if (REDDY.ptrRedFS != null && REDDY.ptrRedFS.is_block_free(fpt.dbn)) { continue; } fdest.Write(buffer, 0, fp.get_size()); final++; } fsrc.Close(); fdest.Flush(); fdest.Close(); DEFS.DEBUG("DEDUPE", "Finished clog P2, count = " + count + " to " + final); }
private void clean_fpdb_P1(string input, string output) { DEFS.DEBUG("DEDUPE", "Starting fpdb P1"); Item fp = new fingerprintFPDB(DEDUP_SORT_ORDER.INO_FBN_BASED); byte[] buffer = new byte[fp.get_size()]; FileStream fsrc = new FileStream(input, FileMode.Open); FileStream fdest = new FileStream(output, FileMode.Create); long count = fsrc.Length / fp.get_size(); int final = 0; for (int i = 0; i < count; i++) { fsrc.Read(buffer, 0, fp.get_size()); fp.parse_bytes(buffer, 0); fingerprintFPDB fpt = (fingerprintFPDB)fp; if (REDDY.ptrRedFS != null && REDDY.ptrRedFS.is_block_free(fpt.dbn)) { continue; } fdest.Write(buffer, 0, fp.get_size()); final++; } fsrc.Close(); fdest.Flush(); fdest.Close(); DEFS.DEBUG("DEDUPE", "Finished fpdb P1, count = " + count + " to " + final); }
private void do_fsid_sync_internal(int id) { lock (REDDY.FSIDList[id]) { RedFS_Inode inowip = REDDY.FSIDList[id].get_inode_file_wip("GC1"); REDDY.ptrRedFS.sync(inowip); REDDY.ptrRedFS.flush_cache(inowip, true); REDDY.FSIDList[id].sync_internal(); REDDY.ptrRedFS.redfs_commit_fsid(REDDY.FSIDList[id]); } DEFS.DEBUG("FSIDSYNC", " Calling sync"); REDDY.FSIDList[id].rootdir.sync(); DEFS.DEBUG("FSIDSYNC", "Finished sync, calling gc"); REDDY.FSIDList[id].rootdir.gc(); DEFS.DEBUG("FSIDSYNC", " Finished gc"); if (m_shutdown == true) { ((CInode)REDDY.FSIDList[id].rootdir).unmount(true); } lock (REDDY.FSIDList[id]) { RedFS_Inode inowip = REDDY.FSIDList[id].get_inode_file_wip("GC2"); REDDY.ptrRedFS.sync(inowip); REDDY.ptrRedFS.flush_cache(inowip, true); REDDY.FSIDList[id].sync_internal(); REDDY.ptrRedFS.redfs_commit_fsid(REDDY.FSIDList[id]); } }
private int NEXT_INODE_NUMBER(int fsid) { int ino = find_free_ino_bit(fsid); DEFS.DEBUG("IFSD", "--> Allocated new wip : " + ino + " fsid = " + fsid); return(ino); }
private void init_if_necessary() { for (int i = 0; i < 1024; i++) { if (REDDY.FSIDList[i] != null) { DEFS.ASSERT(REDDY.FSIDList[i].rootdir == null, "Rootdir must be null"); REDDY.FSIDList[i].rootdir = new CDirectory(i, 0, -1, null, null, true); int curr_max_inode = curr_max_inode = REDDY.FSIDList[i].get_start_inonumber(); if (curr_max_inode == 0) { curr_max_inode = 64; DEFS.DEBUG("IFSDMux", "Found current max inode (new) = " + curr_max_inode); } else { DEFS.DEBUG("IFSDMux", "Found current max inode = " + curr_max_inode); DEFS.ASSERT(curr_max_inode >= 64, "Inode number can start only from 64"); } REDDY.FSIDList[i].set_start_inonumber(curr_max_inode); REDDY.ptrRedFS.redfs_commit_fsid(REDDY.FSIDList[i]); } } }
private void prepare_next_chunk(int cid) { int csize = (1024 * 1024) * _item.get_size(); long offset = (long)cid * csize; int bytes = ((inputF.Length - offset) < csize) ? (int)(inputF.Length - offset) : csize; int num_items = bytes / _item.get_size(); inputF.Read(_internal_cache, 0, bytes); if (num_items < 1024 * 1024) { DEFS.DEBUG("SORT", "Processing the last chunk : " + cid); } else { DEFS.DEBUG("SORT", "Processing chunk : " + cid); } for (int i = 0; i < num_items; i++) { sort_input_array[i].parse_bytes(_internal_cache, _item.get_size() * i); //Console.WriteLine(((fingerprint)sort_input_array[i]).dbn); } Array.Sort(sort_input_array, 0, num_items, _item.get_comparator()); for (int i = 0; i < num_items; i++) { sort_input_array[i].get_bytes(_internal_cache, _item.get_size() * i); //Console.WriteLine(((fingerprint)sort_input_array[i]).dbn); } inputF.Seek(cid * (long)csize, SeekOrigin.Begin); inputF.Write(_internal_cache, 0, bytes); }
public void init() { DEFS.DEBUG("WRLdr", "Starting WRLoader"); Thread tc = new Thread(new ThreadStart(tServiceThread)); tc.Start(); m_initialized = true; }
public void get_bytes(byte[] buf) { DEFS.ASSERT(buf.Length == 128 && get_ino() == 0, "get_bytes will not work correctly for non-standard input"); DEFS.DEBUG("FSID", "Copying wip to file data - direct get, ino = " + get_ino()); for (int i = 0; i < 128; i++) { buf[i] = data[i]; } }
public static void dumplistcontents(List <Red_Buffer> list) { DEFS.DEBUGCLR("DIMP", "Dumping list contents"); for (int idx = 0; idx < list.Count; idx++) { Red_Buffer wb = (Red_Buffer)list.ElementAt(idx); DEFS.DEBUG("DUMPLIST", "-> (" + wb.get_level() + ")" + wb.get_ondisk_dbn() + " l=" + wb.get_start_fbn() + " isdirty = " + ((RedBufL0)wb).is_dirty); } }
private void load_mbx(int idx) { if (mbufs[idx] == null) { mbufs[idx] = new MapBuffer(); DEFS.DEBUG("ACTMAP", "Loaded mbx = " + ((long)idx * (256 * 1024))); mfile.Seek((long)idx * (256 * 1024), SeekOrigin.Begin); mfile.Read(mbufs[idx].data, 0, (256 * 1024)); } mbufs[idx].touch_buf(); }
public void shut_down() { DEFS.DEBUG("IFSDMux", "Initiating shutdown call"); m_shutdown = true; while (m_shutdown_done_gc == false) { System.Threading.Thread.Sleep(100); } DEFS.DEBUG("IFSDMux", "Finished shutdown call"); }
public void shut_down() { DEFS.DEBUG("SHUTDOWN", "Calling WRLoader() shut down"); UpdateReqI r = new UpdateReqI(); r.optype = REFCNT_OP.SHUT_DOWN; GLOBALQ.m_reqi_queue.Add(r); while (r.processed == false) { Thread.Sleep(100); } DEFS.DEBUG("SHUTDOWN", "Finishing WRLoader() shut down"); }
public bool shut_down() { DEFS.DEBUG("SHUTDOWN", "Calling REFCntManager() shut down"); m_shutdown = true; m_dbnbitmap.shut_down(); m_wrloader.shut_down(); while (m_wrloader.m_initialized == true) { System.Threading.Thread.Sleep(100); } DEFS.DEBUG("SHUTDOWN", "Finishing REFCntManager() shut down"); return(true); }
public void shut_down() { DEFS.DEBUG("SHUTDOWN", "Calling Map256M() shut down"); sync(); mfile.Flush(); mfile.Close(); xfile.Flush(); xfile.Close(); initialized = false; mfile = null; xfile = null; DEFS.DEBUG("SHUTDOWN", "Finishing Map256M() shut down"); }
void CInode.unmount(bool inshutdown) { long curr = DateTime.Now.ToUniversalTime().Ticks; int seconds = (int)((curr - creation_time) / 10000000); DEFS.DEBUG("UNMOUNT", "CFile (" + m_inode + ") umnount : " + m_name + " inshutdown flag = " + inshutdown + " is _mywip null = " + (_mywip == null) + " secs = " + seconds); if (inshutdown == false && timeoutcheck() == false && m_state == FILE_STATE.FILE_IN_DOKAN_IO) { return; } /* * We cannot unmount a dirty wip directly, it must first be cleaned, so we * dont do this here. The next sync iteration will clean the wip, and then * we are good to unmount. If we are being shutdown, then we sync() here itself. */ if ((inshutdown == false) && ((_mywip == null)))// || _mywip.is_dirty == false)) { DEFS.ASSERT(m_state != FILE_STATE.FILE_IN_DOKAN_IO, "Cannot be dokan io when _mywip = NULL"); return; } /* * _mywip is not null and dirty, or we are shutting down. */ lock (this) { DEFS.ASSERT(m_state != FILE_STATE.FILE_ORPHANED, "We are in sync path can cannot have an orphaned file"); if (_mywip != null) { REDDY.ptrRedFS.sync(_mywip); REDDY.ptrRedFS.flush_cache(_mywip, inshutdown); } lock (REDDY.FSIDList[m_associated_fsid]) { if (_mywip != null) { RedFS_Inode inowipX = REDDY.FSIDList[m_associated_fsid].get_inode_file_wip("Umount file iwp:" + m_name); OPS.Checkin_Wip(inowipX, _mywip, m_inode); DEFS.ASSERT(m_state != FILE_STATE.FILE_DELETED, "Wrong state detected222!"); REDDY.FSIDList[m_associated_fsid].sync_internal(); REDDY.FSIDList[m_associated_fsid].set_dirty(true); _mywip = null; } m_state = FILE_STATE.FILE_UNMOUNTED; } } }
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); }
public static void INIT_LOGGING() { string t = get_time_formatted(); DEFS.DEBUG("IFSD", "Setting INIT_LOGGING()" + t); if (log == null) { string fname = CONFIG.GetBasePath() + "log_" + t + ".txt"; Console.WriteLine("Setting INIT_LOGGING()" + fname); log = new StreamWriter(fname); DEFS.DEBUG("IFSD", "Setting INIT_LOGGING()" + t); } DEFS.DEBUG("IFSD", "Done INIT_LOGGING()"); }
public void W() { DokanOptions opt = new DokanOptions(); opt.DebugMode = true; opt.DriveLetter = m_driveletter; opt.ThreadCount = 1; opt.VolumeLabel = REDDY.FSIDList[REDDY.mountedidx].get_drive_name(); _userlayer = new WUserLayer(_mountedfsid); _userlayer.Init_IFSD(); DokanNet.DokanMain(opt, _userlayer); DEFS.DEBUG("DOKAN", "done with DokanMain() dokan drive: " + m_driveletter); System.Threading.Thread.Sleep(10000); }
public void setfilefsid_on_dirty(int fsid) { int cf = get_int(WIDOffsets.wip_created_from_fsid); if (cf == 0) //new file { set_int(WIDOffsets.wip_created_from_fsid, fsid); } int modfsid = get_int(WIDOffsets.wip_modified_in_fsid); if (modfsid != fsid) { set_int(WIDOffsets.wip_modified_in_fsid, fsid); DEFS.DEBUG("FSID", "Set fsid for inode: " + get_ino() + " from fsid " + modfsid + " to fsid"); } }
public RedFS_Inode get_inode_file_wip(string requester) { if (_ninowip == null) { _ninowip = new RedFS_Inode(WIP_TYPE.PUBLIC_INODE_FILE, 0, -1); for (int i = 0; i < 128; i++) { _ninowip.data[i] = data[CFSvalueoffsets.fsid_inofile_data + i]; } _ninowip.set_wiptype(WIP_TYPE.PUBLIC_INODE_FILE); _ninowip.setfilefsid_on_dirty(m_dbn); } DEFS.DEBUG("FSID", "Giving a inowip to " + requester); return(_ninowip); }
public static CONFIGERROR CheckIfValidFolder(string path) { if (!File.Exists(path + "\\disk2") || !File.Exists(path + "\\RFI2.dat") || !File.Exists(path + "\\allocationmap")) { return(CONFIGERROR.FILE_MISSING); } else { /* * optional files may/maynot exists. * clog, tfile, allocationmap.x, log_* files. */ FileInfo f1 = new FileInfo(path + "\\disk2"); FileInfo f2 = new FileInfo(path + "\\RFI2.dat"); FileInfo f3 = new FileInfo(path + "\\allocationmap"); int blkcnt1 = (int)(f1.Length / 4096); int blkcnt2 = (int)(f2.Length / 8); int blkcnt3 = (int)(f3.Length * 8); //if (blkcnt1 == blkcnt2 && blkcnt2 == blkcnt3) return true; //return false; string final = GetConfigString(path); //DEFS.DEBUGYELLOW("S", final); string configkey = CalculateMD5Hash(final); string savedconfig = ""; try { FileStream fs = new FileStream(path + "\\config.txt", FileMode.Open); StreamReader sr = new StreamReader(fs); savedconfig = sr.ReadLine(); sr.Close(); } catch (Exception e) { DEFS.DEBUG("EXCEPTION", e.Message); } if (savedconfig == configkey) { return(CONFIGERROR.OKAY); } return(CONFIGERROR.HASH_CHECK_FAILED); } }
public void shut_down() { DEFS.DEBUG("SHUTDOWN", "Calling RedFSPersistantStorage() shut down, fpcache_cnt = " + fpcache_cnt); if (initialized == false) { return; } initialized = false; dfile.Flush(); dfile.Close(); flush_clog(); clogfile.Flush(); clogfile.Close(); dfile = null; clogfile = null; DEFS.DEBUG("SHUTDOWN", "Finishing RedfsPersistantStorage() shut down"); }
private void newlun_ok_Click(object sender, EventArgs e) { try { drive_id = Int32.Parse(drive_id_tb.Text); drive_size = Int32.Parse(drive_size_tb.Text); } catch (Exception exx) { DEFS.DEBUG("lun ui", exx.Message); MessageBox.Show("Error in parsing values. Please enter digits only"); drive_id = drive_size = 0; return; } entered = true; this.Close(); }
public bool checkIfKeyValueIsValid(string kstr, string vstr) { if (kstr.Trim() != key) { return(false); } if (vstr == null) { return(true); } if (type == 0) { int vint = 0; try { vint = Int32.Parse(vstr); } catch (Exception e) { DEFS.DEBUG("AFILL", e.Message); return(false); } } return(true); }
public static void dump_inoL0_wips(byte[] buffer) { byte[] buf = new byte[128]; RedFS_Inode wip = new RedFS_Inode(WIP_TYPE.REGULAR_FILE, 0, 0); for (int i = 0; i < 32; i++) { for (int t = 0; t < 128; t++) { buf[t] = buffer[i * 128 + t]; } wip.parse_bytes(buf); if (wip.get_ino() != 0) { DEFS.DEBUG("->", wip.get_string_rep2()); } } }
/* * Long running threads, does GC every 5 seconds approx. */ private void W_GCThreadMux() { DEFS.DEBUG("IFSDMux", "Starting gc/sync thread (Mux)..."); int next_wait = 5000; while (true) { bool shutdownloop = false; TimingCounter tctr = new TimingCounter(); tctr.start_counter(); if (m_shutdown) { shutdownloop = true; } else { Thread.Sleep(next_wait); } for (int i = 0; i < 1024; i++) { if (REDDY.FSIDList[i] == null || REDDY.FSIDList[i].get_dirty_flag() == false) { continue; } do_fsid_sync_internal(i); } if (m_shutdown && shutdownloop) { m_shutdown_done_gc = true; break; } tctr.stop_counter(); next_wait = (m_shutdown)? 0 : (((5000 - tctr.get_millisecs_avg()) < 0) ? 0 : (5000 - tctr.get_millisecs_avg())); } //we are exiting now DEFS.DEBUG("IFSDMux", "Leaving gc/sync thread (Mux)..."); }
private void do_regular_dirORfile_work(UpdateReqI cu, int childcnt) { Red_Buffer wb = allocate_wb(cu.blktype); 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 RF : " + OPS.ChecksumPageWRLoader(buffer)); DEFS.DEBUG("CNTR", "do_regular_dirORfile_work (" + cu.tfbn + ") childcnt =" + childcnt); } wb.data_to_buf(buffer); REDFS_BUFFER_ENCAPSULATED wbe = new REDFS_BUFFER_ENCAPSULATED(wb); BLK_TYPE belowtype = BLK_TYPE.IGNORE; switch (cu.blktype) { case BLK_TYPE.REGULAR_FILE_L1: belowtype = BLK_TYPE.REGULAR_FILE_L0; break; case BLK_TYPE.REGULAR_FILE_L2: belowtype = BLK_TYPE.REGULAR_FILE_L1; break; } for (int i = 0; i < 1024; i++) { int dbnt = wbe.get_child_dbn(i); if (dbnt <= 0) { continue; } apply_update_internal(dbnt, belowtype, childcnt, cu.optype, true); } }