import_iovec(9)

πŸ“¦ version 7.3.1, in nixpkgs unstable

πŸ’– import_iovec β€” the kernel API manual, bestie edition πŸ’–

okay so this one lives in the Kernel API Manual (section 9, kernel developer land 🧚), and it's genuinely one of those functions that looks scary and is actually just doing a very specific lil job. let me walk you through it 🫢


✨ NAME ✨

import_iovec β€” copies an array of &struct iovec from userspace into the kernel, checks that it's valid, and initializes a brand-new &struct iov_iter iterator so you can actually access it. that's the whole vibe. importing iovecs. slay. πŸ’…


🌸 SYNOPSIS 🌸

ssize_t import_iovec (int type , const struct iovec __user *uvec ,
unsigned nr_segs , unsigned fast_segs , struct iovec **iovp , struct
iov_iter *i );

six parameters, one return value, zero chill. let's meet the cast πŸ‘‘


πŸŽ€ ARGUMENTS πŸŽ€

  • type β€” one of READ or WRITE. that's it. pick a lane bestie, there's only two πŸ¦‹
  • uvec β€” pointer to the userspace array. the OG, still living in userspace until we bring it in πŸ’«
  • nr_segs β€” number of elements in the userspace array. like, how many segs are we talking about here πŸ™ˆ
  • fast_segs β€” number of elements in iov. the fast path capacity, iykyk ⭐
  • iovp β€” (input and output parameter!) pointer to a pointer to a kernel array β€” usually a small one chilling on the stack on-stack. it goes in, it comes out, it's giving main character energy 🌈
  • i β€” pointer to the iterator that will get initialized on success. no success, no init, that's the deal πŸ’€

πŸ¦‹ DESCRIPTION πŸ¦‹

okay so here's the tea β˜•:

if the array pointed to by *iov is big enough to hold all nr_segs, then this function places NULL in *iov on return. yep, NULL. that's not a bug, that's the signal ✨

otherwise, a new array gets allocated and the result is placed in *iov. so either way, you're covered.

and the iconic part: this means the caller may call kfree on *iov regardless of whether the small on-stack array was used or not β€” and regardless of whether this function returns an error or not. literally every path, kfree is safe. no cap, that's a genuinely thoughtful API design and i'm obsessed πŸ«ΆπŸ’–

lowkey important: the kfree guarantee holds in all cases β€” small stack array or freshly allocated array, success or error. don't overthink it, just kfree it πŸ”₯

⭐ RETURN ⭐

  • negative error code on error 😭
  • bytes imported on success πŸ‘‘

πŸ’œ SEE ALSO πŸ’œ

go read the whole iov_iter cinematic universe if you have a sec, it's a whole franchise 🌸


that's the page bestie!! πŸŽ€ it ships out of ./lib and it's dated October 2026 β€” so like, from the future, which is very on brand for a kernel girlie πŸ’« mwah, go import some iovecs, you're gonna ate πŸ’…πŸ’–

πŸ“¦ where this page comes from