public FILE_IO_CODE write(byte[] buffer, int bufoffset, int buflen, long fileoffset) { if (m_state == FILE_STATE.FILE_DELETED) { return(FILE_IO_CODE.ERR_FILE_DELETED); } lock (this) { if (_mywip == null) { return(FILE_IO_CODE.ERR_NULL_WIP); } touch(); REDDY.ptrRedFS.redfs_write(_mywip, fileoffset, buffer, bufoffset, buflen); m_size = _mywip.get_filesize(); _mywip.is_dirty = true; m_mtime = DateTime.Now.Ticks; //m_parent.set_dirty(); _mywip.setfilefsid_on_dirty(m_associated_fsid); touch(); return(FILE_IO_CODE.OKAY); } }
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); }
/* * 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); }