public int FlushFileBuffers(int midx, String filename, DokanFileInfo info) { CFile ix = get_cfile_internal(midx, filename); if (ix == null) { return(-DokanNet.ERROR_PATH_NOT_FOUND); } ix.open_file(false); ix.sync(); ix.set_dokanio_flag2(false); REDDY.FSIDList[midx].set_dirty(true); return(0); }
/* * This file dups itself into another file, the old version is not deleted. * More like a new reincarnate without loosing old data. The responsibility * of updating path/name is left to CDirectory, as there are only incore data * from the POV of CFile. */ public CFile dup_file(int newfsid, int inode, int pino, string newpath) { if (m_state == FILE_STATE.FILE_DELETED) { return(null); } open_file(false); /* * It is okay to not lock cfnew since nobody actually know that this is * on the system. As nobody else touch this, we can do without locks for the new file. */ lock (this) { if (_mywip == null) { DEFS.ASSERT(m_state == FILE_STATE.FILE_DELETED, "Should be marked deleted, or else some workflow issue"); return(null); } REDDY.ptrRedFS.sync(_mywip); REDDY.ptrRedFS.flush_cache(_mywip, true); //should we write the source inodefile to disk also? CFile cfnew = new CFile(newfsid, inode, pino, m_name, newpath); cfnew.open_file(true); REDDY.ptrRedFS.redfs_dup_file(_mywip, cfnew._mywip); cfnew.m_atime = m_atime; cfnew.m_ctime = m_ctime; cfnew.m_mtime = m_mtime; cfnew.m_size = _mywip.get_filesize(); cfnew.set_ibflag(_mywip.get_ibflag()); cfnew.touch(); //int numblocks = OPS.FSIZETONUMBLOCKS(m_clist[i].get_size()); int numblocks = OPS.NUML0(m_size) + OPS.NUML1(m_size) + OPS.NUML2(m_size); REDDY.FSIDList[newfsid].diff_upadate_logical_data(numblocks * 4096); //not the correct figure per-se REDDY.FSIDList[newfsid].set_dirty(true); DEFS.DEBUGYELLOW("INCRCNT", "Grew fsid usage by " + numblocks + " (file)"); cfnew.sync(); return(cfnew); } }
/* * 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); }