Home | History | Annotate | Download | only in disk_cache

Lines Matching refs:offset

87 // sent to disk. The buffer can start at any offset, but if we try to write to
88 // anywhere in the first 16KB of the file (kMaxBlockSize), we set the offset to
102 // Returns true if we can handle writing |len| bytes to |offset|.
103 bool PreWrite(int offset, int len);
105 // Truncates the buffer to |offset| bytes.
106 void Truncate(int offset);
108 // Writes |len| bytes from |buf| at the given |offset|.
109 void Write(int offset, net::IOBuffer* buf, int len);
111 // Returns true if we can read |len| bytes from |offset|, given that the
115 bool PreRead(int eof, int offset, int* len);
117 // Read |len| bytes from |buf| at the given |offset|.
118 int Read(int offset, net::IOBuffer* buf, int len);
139 bool EntryImpl::UserBuffer::PreWrite(int offset, int len) {
140 DCHECK_GE(offset, 0);
142 DCHECK_GE(offset + len, 0);
145 if (offset < offset_)
149 if (offset + len <= capacity())
154 if (!Size() && offset > kMaxBlockSize)
157 int required = offset - offset_ + len;
161 void EntryImpl::UserBuffer::Truncate(int offset) {
162 DCHECK_GE(offset, 0);
163 DCHECK_GE(offset, offset_);
164 DVLOG(3) << "Buffer truncate at " << offset << " current " << offset_;
166 offset -= offset_;
167 if (Size() >= offset)
168 buffer_.resize(offset);
171 void EntryImpl::UserBuffer::Write(int offset, net::IOBuffer* buf, int len) {
172 DCHECK_GE(offset, 0);
174 DCHECK_GE(offset + len, 0);
175 DCHECK_GE(offset, offset_);
176 DVLOG(3) << "Buffer write at " << offset << " current " << offset_;
178 if (!Size() && offset > kMaxBlockSize)
179 offset_ = offset;
181 offset -= offset_;
183 if (offset > Size())
184 buffer_.resize(offset);
190 int valid_len = Size() - offset;
193 memcpy(&buffer_[offset], buffer, copy_len);
203 bool EntryImpl::UserBuffer::PreRead(int eof, int offset, int* len) {
204 DCHECK_GE(offset, 0);
207 if (offset < offset_) {
209 if (offset >= eof)
214 *len = std::min(*len, offset_ - offset);
215 *len = std::min(*len, eof - offset);
225 return (offset - offset_ < Size());
228 int EntryImpl::UserBuffer::Read(int offset, net::IOBuffer* buf, int len) {
229 DCHECK_GE(offset, 0);
231 DCHECK(Size() || offset < offset_);
234 if (offset < offset_) {
236 clean_bytes = std::min(offset_ - offset, len);
240 offset = offset_;
244 int start = offset - offset_;
311 int EntryImpl::ReadDataImpl(int index, int offset, net::IOBuffer* buf,
317 new ReadWriteDataParameters(index, offset, buf_len, false)));
320 int result = InternalReadData(index, offset, buf, buf_len, callback);
330 int EntryImpl::WriteDataImpl(int index, int offset, net::IOBuffer* buf,
337 new ReadWriteDataParameters(index, offset, buf_len, truncate)));
340 int result = InternalWriteData(index, offset, buf, buf_len, callback,
351 int EntryImpl::ReadSparseDataImpl(int64 offset, net::IOBuffer* buf, int buf_len,
359 result = sparse_->StartIO(SparseControl::kReadOperation, offset, buf, buf_len,
365 int EntryImpl::WriteSparseDataImpl(int64 offset, net::IOBuffer* buf,
373 result = sparse_->StartIO(SparseControl::kWriteOperation, offset, buf,
379 int EntryImpl::GetAvailableRangeImpl(int64 offset, int len, int64* start) {
384 return sparse_->GetAvailableRange(offset, len, start);
428 size_t offset = 0;
430 offset = address.start_block() * address.BlockSize() + kBlockHeaderSize;
432 if (!key_file || !key_file->Write(key.data(), key.size(), offset)) {
758 size_t offset = 0;
760 offset = address.start_block() * address.BlockSize() + kBlockHeaderSize;
766 if (!offset && key_file->GetLength() != static_cast<size_t>(key_len + 1))
770 !key_file->Read(WriteInto(&key_, key_len + 1), key_len + 1, offset))
793 int EntryImpl::ReadData(int index, int offset, net::IOBuffer* buf, int buf_len,
796 return ReadDataImpl(index, offset, buf, buf_len, callback);
803 if (offset >= entry_size || offset < 0 || !buf_len)
809 backend_->background_queue()->ReadData(this, index, offset, buf, buf_len,
814 int EntryImpl::WriteData(int index, int offset, net::IOBuffer* buf, int buf_len,
817 return WriteDataImpl(index, offset, buf, buf_len, callback, truncate);
823 if (offset < 0 || buf_len < 0)
826 backend_->background_queue()->WriteData(this, index, offset, buf, buf_len,
831 int EntryImpl::ReadSparseData(int64 offset, net::IOBuffer* buf, int buf_len,
834 return ReadSparseDataImpl(offset, buf, buf_len, callback);
836 backend_->background_queue()->ReadSparseData(this, offset, buf, buf_len,
841 int EntryImpl::WriteSparseData(int64 offset, net::IOBuffer* buf, int buf_len,
844 return WriteSparseDataImpl(offset, buf, buf_len, callback);
846 backend_->background_queue()->WriteSparseData(this, offset, buf, buf_len,
851 int EntryImpl::GetAvailableRange(int64 offset, int len, int64* start,
853 backend_->background_queue()->GetAvailableRange(this, offset, len, start,
931 int EntryImpl::InternalReadData(int index, int offset, net::IOBuffer* buf,
934 DVLOG(2) << "Read from " << index << " at " << offset << " : " << buf_len;
939 if (offset >= entry_size || offset < 0 || !buf_len)
947 if (offset + buf_len > entry_size)
948 buf_len = entry_size - offset;
958 user_buffers_[index]->PreRead(eof, offset, &buf_len)) {
960 buf_len = user_buffers_[index]->Read(offset, buf, buf_len);
974 size_t file_offset = offset;
976 DCHECK_LE(offset + buf_len, kMaxBlockSize);
1001 int EntryImpl::InternalWriteData(int index, int offset, net::IOBuffer* buf,
1005 DVLOG(2) << "Write to " << index << " at " << offset << " : " << buf_len;
1009 if (offset < 0 || buf_len < 0)
1014 // offset or buf_len could be negative numbers.
1015 if (offset > max_file_size || buf_len > max_file_size ||
1016 offset + buf_len > max_file_size) {
1017 int size = offset + buf_len;
1028 bool extending = entry_size < offset + buf_len;
1029 truncate = truncate && entry_size > offset + buf_len;
1031 if (!PrepareTarget(index, offset, buf_len, truncate))
1036 UpdateSize(index, entry_size, offset + buf_len);
1045 user_buffers_[index]->Write(offset, buf, buf_len);
1051 if (offset + buf_len == 0) {
1062 size_t file_offset = offset;
1064 DCHECK_LE(offset + buf_len, kMaxBlockSize);
1068 if (!file->SetLength(offset + buf_len))
1199 bool EntryImpl::PrepareTarget(int index, int offset, int buf_len,
1202 return HandleTruncation(index, offset, buf_len);
1204 if (!offset && !buf_len)
1212 if (!user_buffers_[index].get() && offset < kMaxBlockSize) {
1223 return PrepareBuffer(index, offset, buf_len);
1229 bool EntryImpl::HandleTruncation(int index, int offset, int buf_len) {
1233 int new_size = offset + buf_len;
1263 return PrepareBuffer(index, offset, buf_len);
1268 if (offset > user_buffers_[index]->Start())
1283 return ImportSeparateFile(index, offset + buf_len);
1296 int offset = 0;
1299 offset = address.start_block() * address.BlockSize() + kBlockHeaderSize;
1302 !file->Read(user_buffers_[index]->Data(), len, offset, NULL, NULL)) {
1332 bool EntryImpl::PrepareBuffer(int index, int offset, int buf_len) {
1334 if ((user_buffers_[index]->End() && offset > user_buffers_[index]->End()) ||
1335 offset > entry_.Data()->data_size[index]) {
1351 if (!user_buffers_[index]->PreWrite(offset, buf_len)) {
1352 if (!Flush(index, offset + buf_len))
1356 if (offset > user_buffers_[index]->End() ||
1357 !user_buffers_[index]->PreWrite(offset, buf_len)) {
1385 int offset = user_buffers_[index]->Start();
1386 if (!len && !offset)
1391 DCHECK(!offset);
1392 offset = address.start_block() * address.BlockSize() + kBlockHeaderSize;
1399 if (!file->Write(user_buffers_[index]->Data(), len, offset, NULL, NULL))