/* * Write buffer cache data */ int iFuseBufferedFsWrite(iFuseFd_t *iFuseFd, const char *buf, off_t off, size_t size) { int status = 0; size_t writtenSize = 0; size_t remain = 0; off_t curOffset = 0; assert(iFuseFd != NULL); assert(buf != NULL); iFuseRodsClientLog(LOG_DEBUG, "iFuseBufferedFsWrite: %s, offset: %lld, size: %lld", iFuseFd->iRodsPath, (long long)off, (long long)size); // write in block level remain = size; curOffset = off; while(remain > 0) { off_t inBlockOffset = getInBlockOffset(curOffset); size_t inBlockAvail = IFUSE_BUFFER_CACHE_BLOCK_SIZE - inBlockOffset; size_t curSize = inBlockAvail > remain ? remain : inBlockAvail; assert(curSize > 0); status = _writeBlock(iFuseFd, buf + writtenSize, curOffset, curSize); if(status < 0) { iFuseRodsClientLogError(LOG_ERROR, status, "iFuseBufferedFsWrite: _writeBlock of %s error, status = %d", iFuseFd->iRodsPath, status); return status; } writtenSize += curSize; remain -= curSize; curOffset += curSize; } return writtenSize; }
int diskManager_writeContents(u32int inodeNumber, char *contents, u32int length, u32int offset) { iNodeDisk inode; _getiNode(inodeNumber, &inode); // log(L_TRACE, "updating contents, %d + %d bytes to inode: %d -> [%d, %d]", offset, length, inodeNumber, inode.data.nextSector, inode.data.nextOffset); // log(L_TRACE,"Contents[MAX: %d, used: %d], reserved blocks = %d", _availableMem(&inode), inode.usedBytes, inode.blocks); if (inode.data.magic != MAGIC_NUMBER) { log(L_ERROR, "Trying to write to a corrupted page!"); errno = E_CORRUPTED_FILE; return -1; } if (offset + length > _availableMem(&inode)) { log(L_TRACE, "%d -> Memory is not enough, have: %d, extending memory to %d bytes", inodeNumber, _availableMem(&inode), offset + length); int extrablocks = _extendMemory(&inode.data, offset + length, FILE_CONTENTS_INITAL_SECTOR, 0); if (extrablocks != -1) { inode.blocks += extrablocks; } else { log(L_ERROR, "There was an error reserving blocks!"); return 0; } } if (offset + length > inode.usedBytes) { inode.usedBytes = offset + length; } int status = _writeBlock(&inode.data, contents, length, offset); if (status == -1) { log(L_ERROR, "\n_writeBlock has failed writing contents...\n"); return -1; } _setiNode(inodeNumber, &inode); return 0; }
Q_LONG KGPGFile::writeBlock(const char *data, Q_ULONG maxlen) { if(!isOpen()) return EOF; if(!isWritable()) return EOF; return _writeBlock(data, maxlen); }
bool KGPGFile::open(int mode, const QString& cmdArgs, bool skipPasswd) { bool useOwnPassphrase = (getenv("GPG_AGENT_INFO") == 0); // qDebug("KGPGFile::open(%d)", mode); m_errmsg.resize(1); if(isOpen()) { // qDebug("File already open"); return false; } // qDebug("check filename empty"); if(m_fn.isEmpty()) return false; // qDebug("setup file structures"); init(); setMode(mode); // qDebug("check valid access mode"); if(!(isReadable() || isWritable())) return false; if(isWritable()) { // qDebug("check recipient count"); if(m_recipient.count() == 0) return false; // qDebug("check access rights"); if(!checkAccess(m_fn, W_OK)) return false; } QStringList args; if(cmdArgs.isEmpty()) { args << "--homedir" << QString("\"%1\"").arg(m_homedir) << "-q" << "--batch"; if(isWritable()) { args << "-ea" << "-z" << "6" << "--comment" << QString("\"%1\"").arg(m_comment) << "--trust-model=always" << "-o" << QString("\"%1\"").arg(m_fn); QValueList<QCString>::Iterator it; for(it = m_recipient.begin(); it != m_recipient.end(); ++it) args << "-r" << QString("\"%1\"").arg(*it); // some versions of GPG had trouble to replace a file // so we delete it first QFile::remove(m_fn); } else { args << "-da"; if(useOwnPassphrase) args << "--passphrase-fd" << "0"; else args << "--use-agent"; args << "--no-default-recipient" << QString("\"%1\"").arg(m_fn); } } else { args = QStringList::split(" ", cmdArgs); } QCString pwd; if(isReadable() && useOwnPassphrase && !skipPasswd) { KPasswordDialog dlg(KPasswordDialog::Password,false,0); dlg.setPrompt(i18n("Enter passphrase")); dlg.addLine(i18n("File"), m_fn); dlg.adjustSize(); if (dlg.exec() == QDialog::Rejected) return false; pwd = QCString(dlg.password()); } // qDebug("starting GPG process"); if(!startProcess(args)) return false; // qDebug("check GPG process running"); if(!m_process) { // if the process is not present anymore, we have to check // if it was a read operation and we might already have data // and the process finished normally. In that case, we // just continue. if(isReadable()) { if(m_ungetchBuffer.isEmpty()) return false; } else return false; } if(isReadable() && useOwnPassphrase && !skipPasswd) { // qDebug("Passphrase is '%s'", pwd.data()); if(_writeBlock(pwd.data(), pwd.length()) == -1) { // qDebug("Sending passphrase failed"); return false; } m_process->closeStdin(); } setState( IO_Open ); ioIndex = 0; // qDebug("File open"); return true; }