__generic_file_write_iter(9)

πŸ“¦ version 7.3.1, in nixpkgs unstable

πŸ’Ύ __generic_file_write_iter(9) β€” like, the Kernel API Manual entry, bestie ✨

Okay so real talk: this is __generic_file_write_iter(9) out of the Kernel API Manual, and it is the function that actually makes "writing data to a file" happen. Yeah. The whole vibe. Let's get into it 🫢


✨ NAME ✨

__generic_file_write_iter β€” write data to a file πŸ’…


🌸 SYNOPSIS 🌸

ssize_t __generic_file_write_iter (struct kiocb *iocb , struct iov_iter
*from );

πŸŽ€ ARGUMENTS πŸŽ€

  • iocb β€” the IO state structure (file, offset, etc.) β€” think of it as the little ✨context✨ everything's working inside of
  • from β€” an iov_iter holding the data we're about to write

πŸ¦‹ DESCRIPTION πŸ¦‹

Bestie. This function does all the work needed to actually write data to a file. All of it. Not me being dramatic β€” that's literally what it says 😭

So what's the rundown? It does all the basic checks, removes SUID from the file, updates modification times, and then calls the proper subroutines depending on whether we're doing direct IO or a standard buffered write. Two paths, one function, main character energy πŸ‘‘

It expects i_rwsem to be grabbed β€” unless we're working on a block device or similar object which does not need locking at all. So like, know your situation before you call it, okay? πŸ™ˆ

⚠️ Real talk though: this function does *not* take care of syncing data in case of an O_SYNC write. A caller has to handle it. And why?? Mainly because we want to avoid syncing under i_rwsem. That's the whole reason, fr fr.

πŸ”₯ RETURN πŸ”₯

  • number of bytes written, even for truncated writes βœ…
  • negative error code if no data has been written at all πŸ’€

πŸ’œ SEE ALSO πŸ’œ

Kernel file ./mm/filemap.c β€” and like, the entire extended friend group:

filemap_remove_folio(9), filemap_fdatawrite_range(9), filemap_flush_range(9), filemap_flush(9), filemap_range_has_page(9), filemap_fdatawait_range(9), filemap_fdatawait_range_keep_errors(9), file_fdatawait_range(9), filemap_fdatawait_keep_errors(9), filemap_write_and_wait_range(9), file_check_and_advance_wb_err(9), file_write_and_wait_range(9), replace_page_cache_folio(9), softleaf_entry_wait_on_locked(9), folio_put_wait_locked(9), folio_unlock(9), folio_end_read(9), folio_end_private_2(9), folio_wait_private_2(9), folio_wait_private_2_killable(9), folio_end_writeback_no_dropbehind(9), folio_end_writeback(9), __folio_lock(9), page_cache_next_miss(9), page_cache_prev_miss(9), __filemap_get_folio_mpol(9), find_get_entries(9), find_lock_entries(9), filemap_get_folios(9), filemap_get_folios_contig(9), filemap_get_folios_tag(9), filemap_get_folios_dirty(9), filemap_read(9), generic_file_read_iter(9), filemap_splice_read(9), mapping_seek_hole_data(9), filemap_fault(9), read_cache_folio(9), mapping_read_folio_gfp(9), read_cache_page_gfp(9), generic_file_write_iter(9), filemap_release_folio(9), filemap_invalidate_inode(9), filemap_cachestat(9)


✨ and that's the whole page, bestie ✨ This one lives in ./mm, dated October 2026, under the __generic_file_write_iter(9) name β€” slay, go write some bytes responsibly πŸ’–πŸŽ€

πŸ“¦ where this page comes from