__generic_file_write_iter(9)
πΎ __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 offromβ aniov_iterholding 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 anO_SYNCwrite. A caller has to handle it. And why?? Mainly because we want to avoid syncing underi_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
- nixpkgs unstable: linux-manual 7.3.1
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms