Lines Matching refs:len

97 /// fn bytes_add_one(uptr: UserPtr, len: usize) -> Result {
98 /// let (read, mut write) = UserSlice::new(uptr, len).reader_writer();
119 /// fn is_valid(uptr: UserPtr, len: usize) -> Result<bool> {
120 /// let read = UserSlice::new(uptr, len).reader();
129 /// fn get_bytes_if_valid(uptr: UserPtr, len: usize) -> Result<KVec<u8>> {
130 /// if !is_valid(uptr, len)? {
134 /// let read = UserSlice::new(uptr, len).reader();
246 pub fn len(&self) -> usize {
266 let len = out.len();
268 if len > self.length {
271 // SAFETY: `out_ptr` points into a mutable slice of length `len`, so we may write
273 let res = unsafe { bindings::copy_from_user(out_ptr, self.ptr.as_const_ptr(), len) };
277 self.ptr = self.ptr.wrapping_byte_add(len);
278 self.length -= len;
300 let end = offset.saturating_add(self.len()).min(out.len());
307 Ok(dst.len())
329 // OVERFLOW: `offset + read <= data.len() <= isize::MAX <= Offset::MAX`
340 let len = size_of::<T>();
341 if len > self.length {
354 len,
360 self.ptr = self.ptr.wrapping_byte_add(len);
361 self.length -= len;
371 let len = self.length;
372 buf.reserve(len, flags)?;
374 // The call to `reserve` was successful, so the spare capacity is at least `len` bytes long.
375 self.read_raw(&mut buf.spare_capacity_mut()[..len])?;
377 // SAFETY: Since the call to `read_raw` was successful, so the next `len` bytes of the
379 unsafe { buf.inc_len(len) };
402 if dst.len() > self.length {
406 let mut len = raw_strncpy_from_user(dst, self.ptr)?;
407 if len < dst.len() {
409 len += 1;
410 } else if len < buf.len() {
411 // This implies that `len == dst.len() < buf.len()`.
420 // This implies that `len == buf.len()`.
423 // and return it. Unlike the `len < dst.len()` branch, don't modify `len` because it
432 // incremented by `len` or `len-1` in the `len == buf.len()` case.
435 // * If we hit the `len < dst.len()` case, then `raw_strncpy_from_user` guarantees that
439 Ok(unsafe { CStr::from_bytes_with_nul_unchecked(&buf[..len]) })
455 pub fn len(&self) -> usize {
468 /// The caller must ensure that `from` is valid for reads of `len` bytes.
469 unsafe fn write_raw(&mut self, from: *const u8, len: usize) -> Result {
470 if len > self.length {
474 // SAFETY: Caller guarantees `from` is valid for `len` bytes (see this function's
476 let res = unsafe { bindings::copy_to_user(self.ptr.as_mut_ptr(), from.cast(), len) };
480 self.ptr = self.ptr.wrapping_byte_add(len);
481 self.length -= len;
492 // reading `data.len()` bytes.
493 unsafe { self.write_raw(data.as_ptr(), data.len()) }
534 let len = alloc.size();
535 if offset.checked_add(count).ok_or(EOVERFLOW)? > len {
539 if count > self.len() {
544 // guaranteed by the `Coherent` invariants. The check above ensures `offset + count <= len`.
562 let end = offset.saturating_add(self.len()).min(data.len());
569 Ok(src.len())
591 // OVERFLOW: `offset + written <= data.len() <= isize::MAX <= Offset::MAX`
603 let len = size_of::<T>();
604 if len > self.length {
617 len,
623 self.ptr = self.ptr.wrapping_byte_add(len);
624 self.length -= len;
631 /// This reads from userspace until a NUL byte is encountered, or until `dst.len()` bytes have been
634 /// *not* guaranteed to be NUL-terminated when `Ok(dst.len())` is returned.
638 /// When this function returns `Ok(len)`, it is guaranteed that the first `len` bytes of `dst` are
639 /// initialized and non-zero. Furthermore, if `len < dst.len()`, then `dst[len]` is a NUL byte.
643 let len = dst.len() as isize;
645 // SAFETY: `dst` is valid for writing `dst.len()` bytes.
650 len,
659 assert!(res <= len);