| 0/0 |
2026/09/17 10:04 |
flow |
patching |
1h50m
Error:
|
| 1/1 |
2026/09/17 10:04 |
action |
base-commit-picker |
0m
Results: map[KernelBranch:master KernelCommit:fd73f4a6659897191fa0d40695fe370925dd3780 KernelRepo:git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git]
|
| 2/1 |
2026/09/17 10:04 |
action |
syz-repro-to-c-repro |
0m
Results: map[SimplifiedCRepro:#define _GNU_SOURCE
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdint.h>
#include <unistd.h>
#include <fcntl.h>
#include <sys/mman.h>
#include <sys/stat.h>
#include <sys/mount.h>
#include <pthread.h>
#include <sys/ioctl.h>
#include <linux/loop.h>
#include <errno.h>
#pragma pack(push, 1)
struct NTFS_BOOT {
uint8_t jump[3];
char system_id[8];
uint16_t bytes_per_sector;
uint8_t sectors_per_clst;
uint16_t reserved_sectors;
uint8_t zero1[3];
uint16_t unused1;
uint8_t media_descriptor;
uint16_t unused2;
uint16_t sectors_per_track;
uint16_t number_of_heads;
uint32_t hidden_sectors;
uint32_t unused3;
uint8_t bios_drive_num;
uint8_t extended_flags;
uint8_t extended_signature;
uint8_t unused4;
uint64_t sectors_per_volume;
uint64_t mft_clst;
uint64_t mft2_clst;
int8_t record_size;
uint8_t unused5[3];
int8_t index_size;
uint8_t unused6[3];
uint64_t serial_number;
uint32_t checksum;
uint8_t boot_code[426];
uint16_t boot_magic;
};
struct MFT_RECORD_HDR {
uint32_t magic;
uint16_t fix_off;
uint16_t fix_num;
uint64_t lsn;
uint16_t seq;
uint16_t hard_links;
uint16_t attr_off;
uint16_t flags;
uint32_t used_bytes;
uint32_t total_bytes;
uint64_t base_ref;
uint16_t next_attr_id;
uint16_t dummy;
uint32_t mft_rec_num;
};
struct ATTR_RESIDENT {
uint32_t type;
uint32_t size;
uint8_t non_res;
uint8_t name_len;
uint16_t name_off;
uint16_t flags;
uint16_t id;
uint32_t data_size;
uint16_t data_off;
uint8_t res_flags;
uint8_t pad;
};
struct ATTR_NON_RESIDENT {
uint32_t type;
uint32_t size;
uint8_t non_res;
uint8_t name_len;
uint16_t name_off;
uint16_t flags;
uint16_t id;
uint64_t svcn;
uint64_t evcn;
uint16_t run_off;
uint16_t comp_unit;
uint32_t pad;
uint64_t alloc_size;
uint64_t data_size;
uint64_t valid_size;
};
struct ATTR_STD_INFO {
uint64_t crtime;
uint64_t mtime;
uint64_t ctime;
uint64_t atime;
uint32_t file_flags;
uint32_t max_ver;
uint32_t ver_num;
uint32_t class_id;
uint32_t owner_id;
uint32_t security_id;
uint64_t quota_charge;
uint64_t usn;
};
struct ATTR_FILE_NAME {
uint64_t parent_ref;
uint64_t crtime;
uint64_t mtime;
uint64_t ctime;
uint64_t atime;
uint64_t alloc_size;
uint64_t data_size;
uint32_t flags;
uint32_t reparse_tag;
uint8_t name_len;
uint8_t name_type;
uint16_t name[];
};
struct ATTR_VOL_INFO_DATA {
uint64_t reserved;
uint8_t major_ver;
uint8_t minor_ver;
uint16_t flags;
};
struct INDEX_HDR {
uint32_t first_entry_off;
uint32_t total_size;
uint32_t alloc_size;
uint8_t flags;
uint8_t pad2[3];
};
struct INDEX_ROOT {
uint32_t type;
uint32_t collation_rule;
uint32_t index_block_size;
uint8_t clusters_per_block;
uint8_t pad[3];
struct INDEX_HDR hdr;
};
struct INDEX_ENTRY {
uint64_t ref;
uint16_t entry_len;
uint16_t key_len;
uint16_t entry_flags;
uint16_t pad;
};
struct ATTR_DEF_ENTRY {
uint16_t name[64];
uint32_t type;
uint32_t display_rule;
uint32_t collation_rule;
uint32_t flags;
uint64_t min_size;
uint64_t max_size;
};
#pragma pack(pop)
static void apply_mft_fixups(uint8_t *rec) {
uint16_t usn = 1;
uint16_t *fix_array = (uint16_t *)(rec + 0x30);
uint16_t *sec0_end = (uint16_t *)(rec + 512 - 2);
uint16_t *sec1_end = (uint16_t *)(rec + 1024 - 2);
fix_array[0] = usn;
fix_array[1] = *sec0_end;
fix_array[2] = *sec1_end;
*sec0_end = usn;
*sec1_end = usn;
}
static int add_attr_std(uint8_t *buf, uint16_t id) {
struct ATTR_RESIDENT *a = (struct ATTR_RESIDENT *)buf;
int asize = sizeof(struct ATTR_RESIDENT) + sizeof(struct ATTR_STD_INFO);
asize = (asize + 7) & ~7;
memset(buf, 0, asize);
a->type = 0x10;
a->size = asize;
a->id = id;
a->data_off = sizeof(struct ATTR_RESIDENT);
a->data_size = sizeof(struct ATTR_STD_INFO);
struct ATTR_STD_INFO *std = (struct ATTR_STD_INFO *)(buf + sizeof(struct ATTR_RESIDENT));
std->file_flags = 0x20;
return asize;
}
static int add_attr_name(uint8_t *buf, uint16_t id, uint64_t pref, const char *name, uint64_t size) {
int nlen = strlen(name);
int datalen = 66 + nlen * 2;
int asize = sizeof(struct ATTR_RESIDENT) + datalen;
asize = (asize + 7) & ~7;
memset(buf, 0, asize);
struct ATTR_RESIDENT *a = (struct ATTR_RESIDENT *)buf;
a->type = 0x30;
a->size = asize;
a->id = id;
a->data_off = sizeof(struct ATTR_RESIDENT);
a->data_size = datalen;
struct ATTR_FILE_NAME *fn = (struct ATTR_FILE_NAME *)(buf + sizeof(struct ATTR_RESIDENT));
fn->parent_ref = pref;
fn->alloc_size = size;
fn->data_size = size;
fn->flags = 0x20;
fn->name_len = nlen;
fn->name_type = 3;
for (int i = 0; i < nlen; i++) fn->name[i] = (uint8_t)name[i];
return asize;
}
static int add_attr_data_res(uint8_t *buf, uint16_t id, const void *data, uint32_t size) {
struct ATTR_RESIDENT *a = (struct ATTR_RESIDENT *)buf;
int asize = sizeof(struct ATTR_RESIDENT) + size;
asize = (asize + 7) & ~7;
memset(buf, 0, asize);
a->type = 0x80;
a->size = asize;
a->id = id;
a->data_off = sizeof(struct ATTR_RESIDENT);
a->data_size = size;
if (size > 0 && data) {
memcpy(buf + sizeof(struct ATTR_RESIDENT), data, size);
}
return asize;
}
static int encode_run(uint8_t *buf, uint64_t clst_count, int64_t lcn) {
buf[0] = 0x22;
buf[1] = clst_count & 0xFF;
buf[2] = (clst_count >> 8) & 0xFF;
buf[3] = lcn & 0xFF;
buf[4] = (lcn >> 8) & 0xFF;
buf[5] = 0x00;
return 6;
}
static void init_record(uint8_t *buf, uint32_t rec_num, uint16_t seq, uint16_t flags) {
memset(buf, 0, 1024);
struct MFT_RECORD_HDR *hdr = (struct MFT_RECORD_HDR *)buf;
hdr->magic = 0x454C4946;
hdr->fix_off = 0x30;
hdr->fix_num = 3;
hdr->seq = seq;
hdr->hard_links = 1;
hdr->attr_off = 0x38;
hdr->flags = flags;
hdr->total_bytes = 1024;
hdr->mft_rec_num = rec_num;
}
int create_ntfs_image(const char *filename) {
FILE *f = fopen(filename, "wb+");
if (!f) return -1;
const uint64_t total_sectors = 204800; // 100MB
const uint32_t clst_size = 4096;
const uint64_t mft_lcn = 4;
const uint64_t mftmirr_lcn = 20;
const uint64_t logfile_lcn = 24;
const uint64_t bitmap_lcn = 74;
const uint64_t upcase_lcn = 75;
const uint64_t mft_bitmap_lcn = 107;
struct NTFS_BOOT boot;
memset(&boot, 0, sizeof(boot));
boot.jump[0] = 0xEB; boot.jump[1] = 0x52; boot.jump[2] = 0x90;
memcpy(boot.system_id, "NTFS ", 8);
boot.bytes_per_sector = 512;
boot.sectors_per_clst = 8;
boot.media_descriptor = 0xF8;
boot.sectors_per_track = 63;
boot.number_of_heads = 255;
boot.bios_drive_num = 0x80;
boot.extended_signature = 0x80;
boot.sectors_per_volume = total_sectors - 1;
boot.mft_clst = mft_lcn;
boot.mft2_clst = mftmirr_lcn;
boot.record_size = -10;
boot.index_size = -12;
boot.serial_number = 0x1234567887654321ULL;
boot.boot_magic = 0xAA55;
fseek(f, 0, SEEK_SET);
fwrite(&boot, sizeof(boot), 1, f);
uint8_t mft_table[32 * 1024];
memset(mft_table, 0, sizeof(mft_table));
/* Record 0: $MFT */
{
uint8_t *rec = mft_table + 0 * 1024;
init_record(rec, 0, 1, 0x01);
int off = 0x38;
off += add_attr_std(rec + off, 1);
off += add_attr_name(rec + off, 2, 5 | (5ULL << 48), "$MFT", 16 * clst_size);
struct ATTR_NON_RESIDENT *a = (struct ATTR_NON_RESIDENT *)(rec + off);
int rlen = encode_run(rec + off + sizeof(*a), 16, mft_lcn);
int asize = (sizeof(*a) + rlen + 7) & ~7;
a->type = 0x80; a->size = asize; a->non_res = 1; a->id = 3;
a->evcn = 15; a->run_off = sizeof(*a);
a->alloc_size = a->data_size = a->valid_size = 16 * clst_size;
off += asize;
struct ATTR_NON_RESIDENT *b = (struct ATTR_NON_RESIDENT *)(rec + off);
int rlen2 = encode_run(rec + off + sizeof(*b), 1, mft_bitmap_lcn);
int bsize = (sizeof(*b) + rlen2 + 7) & ~7;
b->type = 0xB0; b->size = bsize; b->non_res = 1; b->id = 4;
b->evcn = 0; b->run_off = sizeof(*b);
b->alloc_size = clst_size; b->data_size = b->valid_size = 8;
off += bsize;
*(uint32_t *)(rec + off) = 0xFFFFFFFF;
((struct MFT_RECORD_HDR *)rec)->used_bytes = off + 8;
apply_mft_fixups(rec);
}
/* Record 1: $MFTMirr */
{
uint8_t *rec = mft_table + 1 * 1024;
init_record(rec, 1, 1, 0x01);
int off = 0x38;
off += add_attr_std(rec + off, 1);
off += add_attr_name(rec + off, 2, 5 | (5ULL << 48), "$MFTMirr", 4096);
struct ATTR_NON_RESIDENT *a = (struct ATTR_NON_RESIDENT *)(rec + off);
int rlen = encode_run(rec + off + sizeof(*a), 1, mftmirr_lcn);
int asize = (sizeof(*a) + rlen + 7) & ~7;
a->type = 0x80; a->size = asize; a->non_res = 1; a->id = 3;
a->evcn = 0; a->run_off = sizeof(*a);
a->alloc_size = a->data_size = a->valid_size = 4 * 1024;
off += asize;
*(uint32_t *)(rec + off) = 0xFFFFFFFF;
((struct MFT_RECORD_HDR *)rec)->used_bytes = off + 8;
apply_mft_fixups(rec);
}
/* Record 2: $LogFile */
{
uint8_t *rec = mft_table + 2 * 1024;
init_record(rec, 2, 2, 0x01);
int off = 0x38;
off += add_attr_std(rec + off, 1);
off += add_attr_name(rec + off, 2, 5 | (5ULL << 48), "$LogFile", 50 * clst_size);
struct ATTR_NON_RESIDENT *a = (struct ATTR_NON_RESIDENT *)(rec + off);
int rlen = encode_run(rec + off + sizeof(*a), 50, logfile_lcn);
int asize = (sizeof(*a) + rlen + 7) & ~7;
a->type = 0x80; a->size = asize; a->non_res = 1; a->id = 3;
a->evcn = 49; a->run_off = sizeof(*a);
a->alloc_size = a->data_size = a->valid_size = 50 * clst_size;
off += asize;
*(uint32_t *)(rec + off) = 0xFFFFFFFF;
((struct MFT_RECORD_HDR *)rec)->used_bytes = off + 8;
apply_mft_fixups(rec);
}
/* Record 3: $Volume */
{
uint8_t *rec = mft_table + 3 * 1024;
init_record(rec, 3, 3, 0x01);
int off = 0x38;
off += add_attr_std(rec + off, 1);
off += add_attr_name(rec + off, 2, 5 | (5ULL << 48), "$Volume", 0);
struct ATTR_RESIDENT *a = (struct ATTR_RESIDENT *)(rec + off);
int asize = (sizeof(*a) + sizeof(struct ATTR_VOL_INFO_DATA) + 7) & ~7;
a->type = 0x70; a->size = asize; a->id = 3;
a->data_off = sizeof(*a); a->data_size = sizeof(struct ATTR_VOL_INFO_DATA);
struct ATTR_VOL_INFO_DATA *vi = (struct ATTR_VOL_INFO_DATA *)(rec + off + sizeof(*a));
vi->major_ver = 1; vi->minor_ver = 2; // NTFS 1.2 to skip $Secure
off += asize;
off += add_attr_data_res(rec + off, 4, NULL, 0);
*(uint32_t *)(rec + off) = 0xFFFFFFFF;
((struct MFT_RECORD_HDR *)rec)->used_bytes = off + 8;
apply_mft_fixups(rec);
}
/* Record 4: $AttrDef */
{
uint8_t *rec = mft_table + 4 * 1024;
init_record(rec, 4, 4, 0x01);
int off = 0x38;
off += add_attr_std(rec + off, 1);
off += add_attr_name(rec + off, 2, 5 | (5ULL << 48), "$AttrDef", sizeof(struct ATTR_DEF_ENTRY));
struct ATTR_RESIDENT *a = (struct ATTR_RESIDENT *)(rec + off);
int dsize = sizeof(struct ATTR_DEF_ENTRY);
int asize = (sizeof(*a) + dsize + 7) & ~7;
a->type = 0x80; a->size = asize; a->id = 3;
a->data_off = sizeof(*a); a->data_size = dsize;
struct ATTR_DEF_ENTRY *ade = (struct ATTR_DEF_ENTRY *)(rec + off + sizeof(*a));
memset(ade, 0, sizeof(*ade));
ade->type = 0x10;
off += asize;
*(uint32_t *)(rec + off) = 0xFFFFFFFF;
((struct MFT_RECORD_HDR *)rec)->used_bytes = off + 8;
apply_mft_fixups(rec);
}
/* Record 5: Root Directory '.' */
{
uint8_t *rec = mft_table + 5 * 1024;
init_record(rec, 5, 5, 0x03);
int off = 0x38;
off += add_attr_std(rec + off, 1);
off += add_attr_name(rec + off, 2, 5 | (5ULL << 48), ".", 0);
struct ATTR_RESIDENT *a = (struct ATTR_RESIDENT *)(rec + off);
int nlen = 4;
int fn_datalen = 66 + nlen * 2;
int entry1_len = (sizeof(struct INDEX_ENTRY) + fn_datalen + 7) & ~7;
int entry2_len = sizeof(struct INDEX_ENTRY);
int dsize = sizeof(struct INDEX_ROOT) + entry1_len + entry2_len;
int asize = (sizeof(*a) + 8 + dsize + 7) & ~7;
a->type = 0x90; a->size = asize; a->id = 3;
a->name_len = 4; a->name_off = sizeof(*a);
uint16_t *aname = (uint16_t *)(rec + off + sizeof(*a));
aname[0] = '$'; aname[1] = 'I'; aname[2] = '3'; aname[3] = '0';
a->data_off = sizeof(*a) + 8; a->data_size = dsize;
struct INDEX_ROOT *ir = (struct INDEX_ROOT *)(rec + off + sizeof(*a) + 8);
ir->type = 0x30;
ir->collation_rule = 0x01;
ir->index_block_size = 4096;
ir->clusters_per_block = 1;
ir->hdr.first_entry_off = 0x10;
ir->hdr.total_size = 0x10 + entry1_len + entry2_len;
ir->hdr.alloc_size = ir->hdr.total_size;
ir->hdr.flags = 0;
struct INDEX_ENTRY *ie1 = (struct INDEX_ENTRY *)((uint8_t *)ir + sizeof(struct INDEX_ROOT));
memset(ie1, 0, entry1_len);
ie1->ref = 16 | (1ULL << 48);
ie1->entry_len = entry1_len;
ie1->key_len = fn_datalen;
ie1->entry_flags = 0;
struct ATTR_FILE_NAME *fn = (struct ATTR_FILE_NAME *)((uint8_t *)ie1 + sizeof(struct INDEX_ENTRY));
memset(fn, 0, fn_datalen);
fn->parent_ref = 5 | (5ULL << 48);
fn->alloc_size = 5;
fn->data_size = 5;
fn->flags = 0x20;
fn->name_len = nlen;
fn->name_type = 3;
fn->name[0] = 't'; fn->name[1] = 'e'; fn->name[2] = 's'; fn->name[3] = 't';
struct INDEX_ENTRY *ie2 = (struct INDEX_ENTRY *)((uint8_t *)ie1 + entry1_len);
memset(ie2, 0, entry2_len);
ie2->ref = 0;
ie2->entry_len = entry2_len;
ie2->key_len = 0;
ie2->entry_flags = 0x02;
off += asize;
*(uint32_t *)(rec + off) = 0xFFFFFFFF;
((struct MFT_RECORD_HDR *)rec)->used_bytes = off + 8;
apply_mft_fixups(rec);
}
/* Record 6: $Bitmap */
{
uint8_t *rec = mft_table + 6 * 1024;
init_record(rec, 6, 6, 0x01);
int off = 0x38;
off += add_attr_std(rec + off, 1);
off += add_attr_name(rec + off, 2, 5 | (5ULL << 48), "$Bitmap", 3200);
struct ATTR_NON_RESIDENT *a = (struct ATTR_NON_RESIDENT *)(rec + off);
int rlen = encode_run(rec + off + sizeof(*a), 1, bitmap_lcn);
int asize = (sizeof(*a) + rlen + 7) & ~7;
a->type = 0x80; a->size = asize; a->non_res = 1; a->id = 3;
a->evcn = 0; a->run_off = sizeof(*a);
a->alloc_size = clst_size; a->data_size = a->valid_size = 3200;
off += asize;
*(uint32_t *)(rec + off) = 0xFFFFFFFF;
((struct MFT_RECORD_HDR *)rec)->used_bytes = off + 8;
apply_mft_fixups(rec);
}
/* Record 8: $BadClus */
{
uint8_t *rec = mft_table + 8 * 1024;
init_record(rec, 8, 8, 0x01);
int off = 0x38;
off += add_attr_std(rec + off, 1);
off += add_attr_name(rec + off, 2, 5 | (5ULL << 48), "$BadClus", 0);
unsigned char dummy_attr[] = {
0x80, 0x00, 0x00, 0x00, // type = ATTR_DATA
0x48, 0x00, 0x00, 0x00, // size = 72
0x01, // non_res = 1
0x00, // name_len = 0
0x40, 0x00, // name_off = 64
0x00, 0x00, // flags = 0
0x03, 0x00, // id = 3
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // svcn = 0
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // evcn = 0
0x40, 0x00, // run_off = 64
0x00, 0x00, // comp_unit = 0
0x00, 0x00, 0x00, 0x00, // res2 = 0
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // alloc_size = 0
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // data_size = 0
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // valid_size = 0
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 // runlist (empty)
};
memcpy(rec + off, dummy_attr, sizeof(dummy_attr));
off += sizeof(dummy_attr);
*(uint32_t *)(rec + off) = 0xFFFFFFFF;
((struct MFT_RECORD_HDR *)rec)->used_bytes = off + 8;
apply_mft_fixups(rec);
}
/* Record 10: $UpCase */
{
uint8_t *rec = mft_table + 10 * 1024;
init_record(rec, 10, 10, 0x01);
int off = 0x38;
off += add_attr_std(rec + off, 1);
off += add_attr_name(rec + off, 2, 5 | (5ULL << 48), "$UpCase", 131072);
struct ATTR_NON_RESIDENT *a = (struct ATTR_NON_RESIDENT *)(rec + off);
int rlen = encode_run(rec + off + sizeof(*a), 32, upcase_lcn);
int asize = (sizeof(*a) + rlen + 7) & ~7;
a->type = 0x80; a->size = asize; a->non_res = 1; a->id = 3;
a->evcn = 31; a->run_off = sizeof(*a);
a->alloc_size = a->data_size = a->valid_size = 131072;
off += asize;
*(uint32_t *)(rec + off) = 0xFFFFFFFF;
((struct MFT_RECORD_HDR *)rec)->used_bytes = off + 8;
apply_mft_fixups(rec);
}
/* Record 16: "test" */
{
uint8_t *rec = mft_table + 16 * 1024;
init_record(rec, 16, 1, 0x01);
int off = 0x38;
off += add_attr_std(rec + off, 1);
off += add_attr_name(rec + off, 2, 5 | (5ULL << 48), "test", 5);
off += add_attr_data_res(rec + off, 3, "hello", 5);
*(uint32_t *)(rec + off) = 0xFFFFFFFF;
((struct MFT_RECORD_HDR *)rec)->used_bytes = off + 8;
apply_mft_fixups(rec);
}
fseek(f, mft_lcn * clst_size, SEEK_SET);
fwrite(mft_table, 32 * 1024, 1, f);
fseek(f, mftmirr_lcn * clst_size, SEEK_SET);
fwrite(mft_table, 4 * 1024, 1, f);
fseek(f, logfile_lcn * clst_size, SEEK_SET);
uint8_t ff_buf[4096];
memset(ff_buf, 0xFF, sizeof(ff_buf));
for (int i = 0; i < 50; i++) {
fwrite(ff_buf, sizeof(ff_buf), 1, f);
}
fseek(f, bitmap_lcn * clst_size, SEEK_SET);
uint8_t bmp[4096];
memset(bmp, 0, sizeof(bmp));
for (int i = 0; i <= 107; i++) {
bmp[i / 8] |= (1 << (i % 8));
}
fwrite(bmp, sizeof(bmp), 1, f);
fseek(f, upcase_lcn * clst_size, SEEK_SET);
uint16_t upcase_tbl[65536];
for (int i = 0; i < 65536; i++) {
if (i >= 'a' && i <= 'z')
upcase_tbl[i] = i - ('a' - 'A');
else
upcase_tbl[i] = i;
}
fwrite(upcase_tbl, sizeof(upcase_tbl), 1, f);
fseek(f, mft_bitmap_lcn * clst_size, SEEK_SET);
uint8_t mft_bmp[4096];
memset(mft_bmp, 0, sizeof(mft_bmp));
mft_bmp[0] = 0x7F; mft_bmp[1] = 0x05; mft_bmp[2] = 0x01;
fwrite(mft_bmp, sizeof(mft_bmp), 1, f);
fflush(f);
if (ftruncate(fileno(f), total_sectors * 512) < 0) {
fclose(f);
return -1;
}
fclose(f);
return 0;
}
int fd;
volatile int stop = 0;
void *truncate_thread(void *arg) {
while (!stop) {
if (ftruncate(fd, 20) < 0) {}
if (ftruncate(fd, 5) < 0) {}
}
return NULL;
}
void *read_thread(void *arg) {
char *ptr = mmap(NULL, 4096, PROT_READ, MAP_SHARED, fd, 0);
if (ptr == MAP_FAILED) {
perror("mmap");
return NULL;
}
volatile char val;
while (!stop) {
madvise(ptr, 4096, MADV_DONTNEED);
posix_fadvise(fd, 0, 4096, POSIX_FADV_DONTNEED);
val = ptr[0];
}
munmap(ptr, 4096);
return NULL;
}
int main(void) {
umount2("/tmp/mnt", MNT_FORCE | MNT_DETACH);
unlink("/tmp/img.ntfs");
printf("[*] Creating NTFS image...\n");
if (create_ntfs_image("/tmp/img.ntfs") != 0) {
printf("[-] Failed to create NTFS image\n");
exit(1);
}
printf("[+] NTFS image created\n");
int loop_c_fd = open("/dev/loop-control", O_RDWR);
if (loop_c_fd < 0) {
printf("[-] Failed to open /dev/loop-control: %s\n", strerror(errno));
exit(1);
}
int loop_num = ioctl(loop_c_fd, LOOP_CTL_GET_FREE);
if (loop_num < 0) {
printf("[-] Failed to get free loop device: %s\n", strerror(errno));
exit(1);
}
close(loop_c_fd);
char loop_name[64];
sprintf(loop_name, "/dev/loop%d", loop_num);
int loop_fd = open(loop_name, O_RDWR);
if (loop_fd < 0) {
printf("[-] Failed to open %s: %s\n", loop_name, strerror(errno));
exit(1);
}
int file_fd = open("/tmp/img.ntfs", O_RDWR);
if (file_fd < 0) {
printf("[-] Failed to open /tmp/img.ntfs: %s\n", strerror(errno));
exit(1);
}
if (ioctl(loop_fd, LOOP_SET_FD, file_fd) < 0) {
printf("[-] Failed to LOOP_SET_FD: %s\n", strerror(errno));
exit(1);
}
printf("[+] Loop device %s setup\n", loop_name);
close(loop_fd);
close(file_fd);
mkdir("/tmp/mnt", 0777);
usleep(250000);
int retries = 100;
int mount_ret = -1;
while (retries--) {
mount_ret = mount(loop_name, "/tmp/mnt", "ntfs3", 0, "");
if (mount_ret == 0) {
break;
}
if (errno != EBUSY) {
printf("[-] mount failed with unexpected error: %s\n", strerror(errno));
break;
}
usleep(50000);
}
if (mount_ret != 0) {
printf("[-] mount failed after retries\n");
exit(1);
}
printf("[+] Mounted NTFS image\n");
fd = open("/tmp/mnt/test", O_RDWR);
if (fd < 0) {
printf("[-] Failed to open /tmp/mnt/test: %s\n", strerror(errno));
exit(1);
}
printf("[+] Opened /tmp/mnt/test\n");
pthread_t t1;
pthread_t t2[4];
pthread_create(&t1, NULL, truncate_thread, NULL);
for (int i = 0; i < 4; i++) {
pthread_create(&t2[i], NULL, read_thread, NULL);
}
sleep(5);
stop = 1;
pthread_join(t1, NULL);
for (int i = 0; i < 4; i++) {
pthread_join(t2[i], NULL);
}
close(fd);
umount2("/tmp/mnt", MNT_FORCE | MNT_DETACH);
loop_c_fd = open("/dev/loop-control", O_RDWR);
if (loop_c_fd >= 0) {
ioctl(loop_c_fd, LOOP_CTL_REMOVE, loop_num);
close(loop_c_fd);
}
printf("[+] Done\n");
return 0;
}
]
|
| 3/1 |
2026/09/17 10:04 |
action |
kernel-checkouter |
1m
Results: map[KernelSrc:/app/workdir/cache/src/67d11fc48f675838c09d79899c80d8f2ebfe5ae5]
|
| 4/1 |
2026/09/17 10:05 |
action |
kernel-builder |
17m
Results: map[KernelObj:/app/workdir/cache/build/8f886b6cb7d65c3b4ac23f860191087fb82edbf2]
|
| 5/1 |
2026/09/17 10:23 |
action |
crash-reproducer |
1m
Results: map[OtherCrashReports:<nil> ReproducedBugTitle:WARNING in iomap_read_inline_data ReproducedCrashReport:------------[ cut here ]------------
size > iomap->length
WARNING: fs/iomap/buffered-io.c:431 at iomap_read_inline_data+0xa7b/0xc40 fs/iomap/buffered-io.c:431, CPU#0: syz-executor344/5848
Modules linked in:
CPU: 0 UID: 0 PID: 5848 Comm: syz-executor344 Not tainted syzkaller #1 PREEMPT(full)
Hardware name: QEMU Standard PC (Q35 + ICH9, 2009), BIOS 1.16.3-debian-1.16.3-2 04/01/2014
RIP: 0010:iomap_read_inline_data+0xa7b/0xc40 fs/iomap/buffered-io.c:431
Code: 48 83 c4 58 5b 41 5c 41 5d 41 5e 41 5f 5d e9 4c 11 5d 09 cc e8 16 17 59 ff 90 0f 0b 90 bd fb ff ff ff eb da e8 06 17 59 ff 90 <0f> 0b 90 48 bb 00 00 00 00 00 fc ff df 48 8b 44 24 10 80 3c 18 00
RSP: 0000:ffffc9000350f478 EFLAGS: 00010293
RAX: ffffffff826cf42a RBX: ffffc9000350f6d8 RCX: ffff88818e028000
RDX: 0000000000000000 RSI: 0000000000000005 RDI: 0000000000000014
RBP: 0000000000001000 R08: ffffea00045c8547 R09: 1ffffd40008b90a8
R10: dffffc0000000000 R11: fffff940008b90a9 R12: ffffc9000350f680
R13: ffffea00045c8540 R14: 0000000000000005 R15: 1ffff920006a1edb
FS: 00007fad77cec6c0(0000) GS:ffff8881a4c69000(0000) knlGS:0000000000000000
CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033
CR2: 00007fad764e9000 CR3: 0000000114d7f000 CR4: 0000000000352ef0
Call Trace:
<TASK>
iomap_read_folio_iter+0x30d/0xe80 fs/iomap/buffered-io.c:571
iomap_read_folio+0x58b/0x970 fs/iomap/buffered-io.c:676
ntfs_read_folio+0x3f1/0x4b0 fs/ntfs3/inode.c:856
filemap_read_folio+0x12c/0x3a0 mm/filemap.c:2520
filemap_fault+0xd06/0x13b0 mm/filemap.c:3689
__do_fault+0x138/0x2a0 mm/memory.c:5565
do_read_fault mm/memory.c:6000 [inline]
do_fault mm/memory.c:6134 [inline]
do_pte_missing+0x2313/0x3260 mm/memory.c:4700
handle_pte_fault mm/memory.c:6558 [inline]
__handle_mm_fault mm/memory.c:6707 [inline]
handle_mm_fault+0x1a2c/0x3770 mm/memory.c:6876
do_user_addr_fault+0xa4f/0x1340 arch/x86/mm/fault.c:1343
handle_page_fault arch/x86/mm/fault.c:1483 [inline]
exc_page_fault+0x6a/0xc0 arch/x86/mm/fault.c:1536
asm_exc_page_fault+0x26/0x30 arch/x86/include/asm/idtentry.h:595
RIP: 0033:0x7fad78d01f39
Code: 00 ba 04 00 00 00 be 00 10 00 00 48 89 df e8 7e 3e 02 00 8b 3d e0 4b 0c 00 b9 04 00 00 00 31 f6 ba 00 10 00 00 e8 87 34 02 00 <0f> b6 03 88 44 24 0f 8b 05 be 4b 0c 00 85 c0 74 c6 be 00 10 00 00
RSP: 002b:00007fad77cec200 EFLAGS: 00010207
RAX: 0000000000000000 RBX: 00007fad764e9000 RCX: 00007fad78d253ca
RDX: 0000000000000000 RSI: 0000000000000000 RDI: 0000000000000003
RBP: 0000000000000021 R08: 0000000000000003 R09: 0000000000000000
R10: 0000000000000004 R11: 0000000000000246 R12: ffffffffffffffd0
R13: 0000000000000002 R14: 00007ffccf51a930 R15: 00007ffccf51aa18
</TASK>
ReproducedFaultInjection:]
|
| 6/1 |
2026/09/17 10:24 |
action |
codesearch-prepare |
11m
Results: map[Index:codesearch-index]
|
| 7/1 |
2026/09/17 10:36 |
agent |
debugger |
1h18m
Model:
Error:
Instruction:
You are an experienced Linux kernel developer tasked with debugging a kernel crash root cause.
You need to provide a detailed explanation of the root cause for another developer to be
able to write a fix for the bug based on your explanation. Include all relevant details
into the response: function/struct/field/etc names, code snippets, line numbers,
macro/enum values, etc.
Don't make assumptions about the kernel source code (it may be different from what you assume it is).
Extensively use the provided code access tools (codesearch-*, git-*, grepper, etc)
to examine the actual source code, and confirm any assumptions.
Prefer calling several tools at the same time to save round-trips.
Prompt:
The crash is:
------------[ cut here ]------------
size > iomap->length
WARNING: fs/iomap/buffered-io.c:431 at iomap_read_inline_data+0xa7b/0xc40 fs/iomap/buffered-io.c:431, CPU#0: syz-executor344/5848
Modules linked in:
CPU: 0 UID: 0 PID: 5848 Comm: syz-executor344 Not tainted syzkaller #1 PREEMPT(full)
Hardware name: QEMU Standard PC (Q35 + ICH9, 2009), BIOS 1.16.3-debian-1.16.3-2 04/01/2014
RIP: 0010:iomap_read_inline_data+0xa7b/0xc40 fs/iomap/buffered-io.c:431
Code: 48 83 c4 58 5b 41 5c 41 5d 41 5e 41 5f 5d e9 4c 11 5d 09 cc e8 16 17 59 ff 90 0f 0b 90 bd fb ff ff ff eb da e8 06 17 59 ff 90 <0f> 0b 90 48 bb 00 00 00 00 00 fc ff df 48 8b 44 24 10 80 3c 18 00
RSP: 0000:ffffc9000350f478 EFLAGS: 00010293
RAX: ffffffff826cf42a RBX: ffffc9000350f6d8 RCX: ffff88818e028000
RDX: 0000000000000000 RSI: 0000000000000005 RDI: 0000000000000014
RBP: 0000000000001000 R08: ffffea00045c8547 R09: 1ffffd40008b90a8
R10: dffffc0000000000 R11: fffff940008b90a9 R12: ffffc9000350f680
R13: ffffea00045c8540 R14: 0000000000000005 R15: 1ffff920006a1edb
FS: 00007fad77cec6c0(0000) GS:ffff8881a4c69000(0000) knlGS:0000000000000000
CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033
CR2: 00007fad764e9000 CR3: 0000000114d7f000 CR4: 0000000000352ef0
Call Trace:
<TASK>
iomap_read_folio_iter+0x30d/0xe80 fs/iomap/buffered-io.c:571
iomap_read_folio+0x58b/0x970 fs/iomap/buffered-io.c:676
ntfs_read_folio+0x3f1/0x4b0 fs/ntfs3/inode.c:856
filemap_read_folio+0x12c/0x3a0 mm/filemap.c:2520
filemap_fault+0xd06/0x13b0 mm/filemap.c:3689
__do_fault+0x138/0x2a0 mm/memory.c:5565
do_read_fault mm/memory.c:6000 [inline]
do_fault mm/memory.c:6134 [inline]
do_pte_missing+0x2313/0x3260 mm/memory.c:4700
handle_pte_fault mm/memory.c:6558 [inline]
__handle_mm_fault mm/memory.c:6707 [inline]
handle_mm_fault+0x1a2c/0x3770 mm/memory.c:6876
do_user_addr_fault+0xa4f/0x1340 arch/x86/mm/fault.c:1343
handle_page_fault arch/x86/mm/fault.c:1483 [inline]
exc_page_fault+0x6a/0xc0 arch/x86/mm/fault.c:1536
asm_exc_page_fault+0x26/0x30 arch/x86/include/asm/idtentry.h:595
RIP: 0033:0x7fad78d01f39
Code: 00 ba 04 00 00 00 be 00 10 00 00 48 89 df e8 7e 3e 02 00 8b 3d e0 4b 0c 00 b9 04 00 00 00 31 f6 ba 00 10 00 00 e8 87 34 02 00 <0f> b6 03 88 44 24 0f 8b 05 be 4b 0c 00 85 c0 74 c6 be 00 10 00 00
RSP: 002b:00007fad77cec200 EFLAGS: 00010207
RAX: 0000000000000000 RBX: 00007fad764e9000 RCX: 00007fad78d253ca
RDX: 0000000000000000 RSI: 0000000000000000 RDI: 0000000000000003
RBP: 0000000000000021 R08: 0000000000000003 R09: 0000000000000000
R10: 0000000000000004 R11: 0000000000000246 R12: ffffffffffffffd0
R13: 0000000000000002 R14: 00007ffccf51a930 R15: 00007ffccf51aa18
</TASK>
The following C code is a draft of the vulnerable syscall sequence. Keep in mind that
it may lack the precise threading, sandboxing, and some arguments of a working reproducer:
#define _GNU_SOURCE
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdint.h>
#include <unistd.h>
#include <fcntl.h>
#include <sys/mman.h>
#include <sys/stat.h>
#include <sys/mount.h>
#include <pthread.h>
#include <sys/ioctl.h>
#include <linux/loop.h>
#include <errno.h>
#pragma pack(push, 1)
struct NTFS_BOOT {
uint8_t jump[3];
char system_id[8];
uint16_t bytes_per_sector;
uint8_t sectors_per_clst;
uint16_t reserved_sectors;
uint8_t zero1[3];
uint16_t unused1;
uint8_t media_descriptor;
uint16_t unused2;
uint16_t sectors_per_track;
uint16_t number_of_heads;
uint32_t hidden_sectors;
uint32_t unused3;
uint8_t bios_drive_num;
uint8_t extended_flags;
uint8_t extended_signature;
uint8_t unused4;
uint64_t sectors_per_volume;
uint64_t mft_clst;
uint64_t mft2_clst;
int8_t record_size;
uint8_t unused5[3];
int8_t index_size;
uint8_t unused6[3];
uint64_t serial_number;
uint32_t checksum;
uint8_t boot_code[426];
uint16_t boot_magic;
};
struct MFT_RECORD_HDR {
uint32_t magic;
uint16_t fix_off;
uint16_t fix_num;
uint64_t lsn;
uint16_t seq;
uint16_t hard_links;
uint16_t attr_off;
uint16_t flags;
uint32_t used_bytes;
uint32_t total_bytes;
uint64_t base_ref;
uint16_t next_attr_id;
uint16_t dummy;
uint32_t mft_rec_num;
};
struct ATTR_RESIDENT {
uint32_t type;
uint32_t size;
uint8_t non_res;
uint8_t name_len;
uint16_t name_off;
uint16_t flags;
uint16_t id;
uint32_t data_size;
uint16_t data_off;
uint8_t res_flags;
uint8_t pad;
};
struct ATTR_NON_RESIDENT {
uint32_t type;
uint32_t size;
uint8_t non_res;
uint8_t name_len;
uint16_t name_off;
uint16_t flags;
uint16_t id;
uint64_t svcn;
uint64_t evcn;
uint16_t run_off;
uint16_t comp_unit;
uint32_t pad;
uint64_t alloc_size;
uint64_t data_size;
uint64_t valid_size;
};
struct ATTR_STD_INFO {
uint64_t crtime;
uint64_t mtime;
uint64_t ctime;
uint64_t atime;
uint32_t file_flags;
uint32_t max_ver;
uint32_t ver_num;
uint32_t class_id;
uint32_t owner_id;
uint32_t security_id;
uint64_t quota_charge;
uint64_t usn;
};
struct ATTR_FILE_NAME {
uint64_t parent_ref;
uint64_t crtime;
uint64_t mtime;
uint64_t ctime;
uint64_t atime;
uint64_t alloc_size;
uint64_t data_size;
uint32_t flags;
uint32_t reparse_tag;
uint8_t name_len;
uint8_t name_type;
uint16_t name[];
};
struct ATTR_VOL_INFO_DATA {
uint64_t reserved;
uint8_t major_ver;
uint8_t minor_ver;
uint16_t flags;
};
struct INDEX_HDR {
uint32_t first_entry_off;
uint32_t total_size;
uint32_t alloc_size;
uint8_t flags;
uint8_t pad2[3];
};
struct INDEX_ROOT {
uint32_t type;
uint32_t collation_rule;
uint32_t index_block_size;
uint8_t clusters_per_block;
uint8_t pad[3];
struct INDEX_HDR hdr;
};
struct INDEX_ENTRY {
uint64_t ref;
uint16_t entry_len;
uint16_t key_len;
uint16_t entry_flags;
uint16_t pad;
};
struct ATTR_DEF_ENTRY {
uint16_t name[64];
uint32_t type;
uint32_t display_rule;
uint32_t collation_rule;
uint32_t flags;
uint64_t min_size;
uint64_t max_size;
};
#pragma pack(pop)
static void apply_mft_fixups(uint8_t *rec) {
uint16_t usn = 1;
uint16_t *fix_array = (uint16_t *)(rec + 0x30);
uint16_t *sec0_end = (uint16_t *)(rec + 512 - 2);
uint16_t *sec1_end = (uint16_t *)(rec + 1024 - 2);
fix_array[0] = usn;
fix_array[1] = *sec0_end;
fix_array[2] = *sec1_end;
*sec0_end = usn;
*sec1_end = usn;
}
static int add_attr_std(uint8_t *buf, uint16_t id) {
struct ATTR_RESIDENT *a = (struct ATTR_RESIDENT *)buf;
int asize = sizeof(struct ATTR_RESIDENT) + sizeof(struct ATTR_STD_INFO);
asize = (asize + 7) & ~7;
memset(buf, 0, asize);
a->type = 0x10;
a->size = asize;
a->id = id;
a->data_off = sizeof(struct ATTR_RESIDENT);
a->data_size = sizeof(struct ATTR_STD_INFO);
struct ATTR_STD_INFO *std = (struct ATTR_STD_INFO *)(buf + sizeof(struct ATTR_RESIDENT));
std->file_flags = 0x20;
return asize;
}
static int add_attr_name(uint8_t *buf, uint16_t id, uint64_t pref, const char *name, uint64_t size) {
int nlen = strlen(name);
int datalen = 66 + nlen * 2;
int asize = sizeof(struct ATTR_RESIDENT) + datalen;
asize = (asize + 7) & ~7;
memset(buf, 0, asize);
struct ATTR_RESIDENT *a = (struct ATTR_RESIDENT *)buf;
a->type = 0x30;
a->size = asize;
a->id = id;
a->data_off = sizeof(struct ATTR_RESIDENT);
a->data_size = datalen;
struct ATTR_FILE_NAME *fn = (struct ATTR_FILE_NAME *)(buf + sizeof(struct ATTR_RESIDENT));
fn->parent_ref = pref;
fn->alloc_size = size;
fn->data_size = size;
fn->flags = 0x20;
fn->name_len = nlen;
fn->name_type = 3;
for (int i = 0; i < nlen; i++) fn->name[i] = (uint8_t)name[i];
return asize;
}
static int add_attr_data_res(uint8_t *buf, uint16_t id, const void *data, uint32_t size) {
struct ATTR_RESIDENT *a = (struct ATTR_RESIDENT *)buf;
int asize = sizeof(struct ATTR_RESIDENT) + size;
asize = (asize + 7) & ~7;
memset(buf, 0, asize);
a->type = 0x80;
a->size = asize;
a->id = id;
a->data_off = sizeof(struct ATTR_RESIDENT);
a->data_size = size;
if (size > 0 && data) {
memcpy(buf + sizeof(struct ATTR_RESIDENT), data, size);
}
return asize;
}
static int encode_run(uint8_t *buf, uint64_t clst_count, int64_t lcn) {
buf[0] = 0x22;
buf[1] = clst_count & 0xFF;
buf[2] = (clst_count >> 8) & 0xFF;
buf[3] = lcn & 0xFF;
buf[4] = (lcn >> 8) & 0xFF;
buf[5] = 0x00;
return 6;
}
static void init_record(uint8_t *buf, uint32_t rec_num, uint16_t seq, uint16_t flags) {
memset(buf, 0, 1024);
struct MFT_RECORD_HDR *hdr = (struct MFT_RECORD_HDR *)buf;
hdr->magic = 0x454C4946;
hdr->fix_off = 0x30;
hdr->fix_num = 3;
hdr->seq = seq;
hdr->hard_links = 1;
hdr->attr_off = 0x38;
hdr->flags = flags;
hdr->total_bytes = 1024;
hdr->mft_rec_num = rec_num;
}
int create_ntfs_image(const char *filename) {
FILE *f = fopen(filename, "wb+");
if (!f) return -1;
const uint64_t total_sectors = 204800; // 100MB
const uint32_t clst_size = 4096;
const uint64_t mft_lcn = 4;
const uint64_t mftmirr_lcn = 20;
const uint64_t logfile_lcn = 24;
const uint64_t bitmap_lcn = 74;
const uint64_t upcase_lcn = 75;
const uint64_t mft_bitmap_lcn = 107;
struct NTFS_BOOT boot;
memset(&boot, 0, sizeof(boot));
boot.jump[0] = 0xEB; boot.jump[1] = 0x52; boot.jump[2] = 0x90;
memcpy(boot.system_id, "NTFS ", 8);
boot.bytes_per_sector = 512;
boot.sectors_per_clst = 8;
boot.media_descriptor = 0xF8;
boot.sectors_per_track = 63;
boot.number_of_heads = 255;
boot.bios_drive_num = 0x80;
boot.extended_signature = 0x80;
boot.sectors_per_volume = total_sectors - 1;
boot.mft_clst = mft_lcn;
boot.mft2_clst = mftmirr_lcn;
boot.record_size = -10;
boot.index_size = -12;
boot.serial_number = 0x1234567887654321ULL;
boot.boot_magic = 0xAA55;
fseek(f, 0, SEEK_SET);
fwrite(&boot, sizeof(boot), 1, f);
uint8_t mft_table[32 * 1024];
memset(mft_table, 0, sizeof(mft_table));
/* Record 0: $MFT */
{
uint8_t *rec = mft_table + 0 * 1024;
init_record(rec, 0, 1, 0x01);
int off = 0x38;
off += add_attr_std(rec + off, 1);
off += add_attr_name(rec + off, 2, 5 | (5ULL << 48), "$MFT", 16 * clst_size);
struct ATTR_NON_RESIDENT *a = (struct ATTR_NON_RESIDENT *)(rec + off);
int rlen = encode_run(rec + off + sizeof(*a), 16, mft_lcn);
int asize = (sizeof(*a) + rlen + 7) & ~7;
a->type = 0x80; a->size = asize; a->non_res = 1; a->id = 3;
a->evcn = 15; a->run_off = sizeof(*a);
a->alloc_size = a->data_size = a->valid_size = 16 * clst_size;
off += asize;
struct ATTR_NON_RESIDENT *b = (struct ATTR_NON_RESIDENT *)(rec + off);
int rlen2 = encode_run(rec + off + sizeof(*b), 1, mft_bitmap_lcn);
int bsize = (sizeof(*b) + rlen2 + 7) & ~7;
b->type = 0xB0; b->size = bsize; b->non_res = 1; b->id = 4;
b->evcn = 0; b->run_off = sizeof(*b);
b->alloc_size = clst_size; b->data_size = b->valid_size = 8;
off += bsize;
*(uint32_t *)(rec + off) = 0xFFFFFFFF;
((struct MFT_RECORD_HDR *)rec)->used_bytes = off + 8;
apply_mft_fixups(rec);
}
/* Record 1: $MFTMirr */
{
uint8_t *rec = mft_table + 1 * 1024;
init_record(rec, 1, 1, 0x01);
int off = 0x38;
off += add_attr_std(rec + off, 1);
off += add_attr_name(rec + off, 2, 5 | (5ULL << 48), "$MFTMirr", 4096);
struct ATTR_NON_RESIDENT *a = (struct ATTR_NON_RESIDENT *)(rec + off);
int rlen = encode_run(rec + off + sizeof(*a), 1, mftmirr_lcn);
int asize = (sizeof(*a) + rlen + 7) & ~7;
a->type = 0x80; a->size = asize; a->non_res = 1; a->id = 3;
a->evcn = 0; a->run_off = sizeof(*a);
a->alloc_size = a->data_size = a->valid_size = 4 * 1024;
off += asize;
*(uint32_t *)(rec + off) = 0xFFFFFFFF;
((struct MFT_RECORD_HDR *)rec)->used_bytes = off + 8;
apply_mft_fixups(rec);
}
/* Record 2: $LogFile */
{
uint8_t *rec = mft_table + 2 * 1024;
init_record(rec, 2, 2, 0x01);
int off = 0x38;
off += add_attr_std(rec + off, 1);
off += add_attr_name(rec + off, 2, 5 | (5ULL << 48), "$LogFile", 50 * clst_size);
struct ATTR_NON_RESIDENT *a = (struct ATTR_NON_RESIDENT *)(rec + off);
int rlen = encode_run(rec + off + sizeof(*a), 50, logfile_lcn);
int asize = (sizeof(*a) + rlen + 7) & ~7;
a->type = 0x80; a->size = asize; a->non_res = 1; a->id = 3;
a->evcn = 49; a->run_off = sizeof(*a);
a->alloc_size = a->data_size = a->valid_size = 50 * clst_size;
off += asize;
*(uint32_t *)(rec + off) = 0xFFFFFFFF;
((struct MFT_RECORD_HDR *)rec)->used_bytes = off + 8;
apply_mft_fixups(rec);
}
/* Record 3: $Volume */
{
uint8_t *rec = mft_table + 3 * 1024;
init_record(rec, 3, 3, 0x01);
int off = 0x38;
off += add_attr_std(rec + off, 1);
off += add_attr_name(rec + off, 2, 5 | (5ULL << 48), "$Volume", 0);
struct ATTR_RESIDENT *a = (struct ATTR_RESIDENT *)(rec + off);
int asize = (sizeof(*a) + sizeof(struct ATTR_VOL_INFO_DATA) + 7) & ~7;
a->type = 0x70; a->size = asize; a->id = 3;
a->data_off = sizeof(*a); a->data_size = sizeof(struct ATTR_VOL_INFO_DATA);
struct ATTR_VOL_INFO_DATA *vi = (struct ATTR_VOL_INFO_DATA *)(rec + off + sizeof(*a));
vi->major_ver = 1; vi->minor_ver = 2; // NTFS 1.2 to skip $Secure
off += asize;
off += add_attr_data_res(rec + off, 4, NULL, 0);
*(uint32_t *)(rec + off) = 0xFFFFFFFF;
((struct MFT_RECORD_HDR *)rec)->used_bytes = off + 8;
apply_mft_fixups(rec);
}
/* Record 4: $AttrDef */
{
uint8_t *rec = mft_table + 4 * 1024;
init_record(rec, 4, 4, 0x01);
int off = 0x38;
off += add_attr_std(rec + off, 1);
off += add_attr_name(rec + off, 2, 5 | (5ULL << 48), "$AttrDef", sizeof(struct ATTR_DEF_ENTRY));
struct ATTR_RESIDENT *a = (struct ATTR_RESIDENT *)(rec + off);
int dsize = sizeof(struct ATTR_DEF_ENTRY);
int asize = (sizeof(*a) + dsize + 7) & ~7;
a->type = 0x80; a->size = asize; a->id = 3;
a->data_off = sizeof(*a); a->data_size = dsize;
struct ATTR_DEF_ENTRY *ade = (struct ATTR_DEF_ENTRY *)(rec + off + sizeof(*a));
memset(ade, 0, sizeof(*ade));
ade->type = 0x10;
off += asize;
*(uint32_t *)(rec + off) = 0xFFFFFFFF;
((struct MFT_RECORD_HDR *)rec)->used_bytes = off + 8;
apply_mft_fixups(rec);
}
/* Record 5: Root Directory '.' */
{
uint8_t *rec = mft_table + 5 * 1024;
init_record(rec, 5, 5, 0x03);
int off = 0x38;
off += add_attr_std(rec + off, 1);
off += add_attr_name(rec + off, 2, 5 | (5ULL << 48), ".", 0);
struct ATTR_RESIDENT *a = (struct ATTR_RESIDENT *)(rec + off);
int nlen = 4;
int fn_datalen = 66 + nlen * 2;
int entry1_len = (sizeof(struct INDEX_ENTRY) + fn_datalen + 7) & ~7;
int entry2_len = sizeof(struct INDEX_ENTRY);
int dsize = sizeof(struct INDEX_ROOT) + entry1_len + entry2_len;
int asize = (sizeof(*a) + 8 + dsize + 7) & ~7;
a->type = 0x90; a->size = asize; a->id = 3;
a->name_len = 4; a->name_off = sizeof(*a);
uint16_t *aname = (uint16_t *)(rec + off + sizeof(*a));
aname[0] = '$'; aname[1] = 'I'; aname[2] = '3'; aname[3] = '0';
a->data_off = sizeof(*a) + 8; a->data_size = dsize;
struct INDEX_ROOT *ir = (struct INDEX_ROOT *)(rec + off + sizeof(*a) + 8);
ir->type = 0x30;
ir->collation_rule = 0x01;
ir->index_block_size = 4096;
ir->clusters_per_block = 1;
ir->hdr.first_entry_off = 0x10;
ir->hdr.total_size = 0x10 + entry1_len + entry2_len;
ir->hdr.alloc_size = ir->hdr.total_size;
ir->hdr.flags = 0;
struct INDEX_ENTRY *ie1 = (struct INDEX_ENTRY *)((uint8_t *)ir + sizeof(struct INDEX_ROOT));
memset(ie1, 0, entry1_len);
ie1->ref = 16 | (1ULL << 48);
ie1->entry_len = entry1_len;
ie1->key_len = fn_datalen;
ie1->entry_flags = 0;
struct ATTR_FILE_NAME *fn = (struct ATTR_FILE_NAME *)((uint8_t *)ie1 + sizeof(struct INDEX_ENTRY));
memset(fn, 0, fn_datalen);
fn->parent_ref = 5 | (5ULL << 48);
fn->alloc_size = 5;
fn->data_size = 5;
fn->flags = 0x20;
fn->name_len = nlen;
fn->name_type = 3;
fn->name[0] = 't'; fn->name[1] = 'e'; fn->name[2] = 's'; fn->name[3] = 't';
struct INDEX_ENTRY *ie2 = (struct INDEX_ENTRY *)((uint8_t *)ie1 + entry1_len);
memset(ie2, 0, entry2_len);
ie2->ref = 0;
ie2->entry_len = entry2_len;
ie2->key_len = 0;
ie2->entry_flags = 0x02;
off += asize;
*(uint32_t *)(rec + off) = 0xFFFFFFFF;
((struct MFT_RECORD_HDR *)rec)->used_bytes = off + 8;
apply_mft_fixups(rec);
}
/* Record 6: $Bitmap */
{
uint8_t *rec = mft_table + 6 * 1024;
init_record(rec, 6, 6, 0x01);
int off = 0x38;
off += add_attr_std(rec + off, 1);
off += add_attr_name(rec + off, 2, 5 | (5ULL << 48), "$Bitmap", 3200);
struct ATTR_NON_RESIDENT *a = (struct ATTR_NON_RESIDENT *)(rec + off);
int rlen = encode_run(rec + off + sizeof(*a), 1, bitmap_lcn);
int asize = (sizeof(*a) + rlen + 7) & ~7;
a->type = 0x80; a->size = asize; a->non_res = 1; a->id = 3;
a->evcn = 0; a->run_off = sizeof(*a);
a->alloc_size = clst_size; a->data_size = a->valid_size = 3200;
off += asize;
*(uint32_t *)(rec + off) = 0xFFFFFFFF;
((struct MFT_RECORD_HDR *)rec)->used_bytes = off + 8;
apply_mft_fixups(rec);
}
/* Record 8: $BadClus */
{
uint8_t *rec = mft_table + 8 * 1024;
init_record(rec, 8, 8, 0x01);
int off = 0x38;
off += add_attr_std(rec + off, 1);
off += add_attr_name(rec + off, 2, 5 | (5ULL << 48), "$BadClus", 0);
unsigned char dummy_attr[] = {
0x80, 0x00, 0x00, 0x00, // type = ATTR_DATA
0x48, 0x00, 0x00, 0x00, // size = 72
0x01, // non_res = 1
0x00, // name_len = 0
0x40, 0x00, // name_off = 64
0x00, 0x00, // flags = 0
0x03, 0x00, // id = 3
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // svcn = 0
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // evcn = 0
0x40, 0x00, // run_off = 64
0x00, 0x00, // comp_unit = 0
0x00, 0x00, 0x00, 0x00, // res2 = 0
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // alloc_size = 0
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // data_size = 0
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // valid_size = 0
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 // runlist (empty)
};
memcpy(rec + off, dummy_attr, sizeof(dummy_attr));
off += sizeof(dummy_attr);
*(uint32_t *)(rec + off) = 0xFFFFFFFF;
((struct MFT_RECORD_HDR *)rec)->used_bytes = off + 8;
apply_mft_fixups(rec);
}
/* Record 10: $UpCase */
{
uint8_t *rec = mft_table + 10 * 1024;
init_record(rec, 10, 10, 0x01);
int off = 0x38;
off += add_attr_std(rec + off, 1);
off += add_attr_name(rec + off, 2, 5 | (5ULL << 48), "$UpCase", 131072);
struct ATTR_NON_RESIDENT *a = (struct ATTR_NON_RESIDENT *)(rec + off);
int rlen = encode_run(rec + off + sizeof(*a), 32, upcase_lcn);
int asize = (sizeof(*a) + rlen + 7) & ~7;
a->type = 0x80; a->size = asize; a->non_res = 1; a->id = 3;
a->evcn = 31; a->run_off = sizeof(*a);
a->alloc_size = a->data_size = a->valid_size = 131072;
off += asize;
*(uint32_t *)(rec + off) = 0xFFFFFFFF;
((struct MFT_RECORD_HDR *)rec)->used_bytes = off + 8;
apply_mft_fixups(rec);
}
/* Record 16: "test" */
{
uint8_t *rec = mft_table + 16 * 1024;
init_record(rec, 16, 1, 0x01);
int off = 0x38;
off += add_attr_std(rec + off, 1);
off += add_attr_name(rec + off, 2, 5 | (5ULL << 48), "test", 5);
off += add_attr_data_res(rec + off, 3, "hello", 5);
*(uint32_t *)(rec + off) = 0xFFFFFFFF;
((struct MFT_RECORD_HDR *)rec)->used_bytes = off + 8;
apply_mft_fixups(rec);
}
fseek(f, mft_lcn * clst_size, SEEK_SET);
fwrite(mft_table, 32 * 1024, 1, f);
fseek(f, mftmirr_lcn * clst_size, SEEK_SET);
fwrite(mft_table, 4 * 1024, 1, f);
fseek(f, logfile_lcn * clst_size, SEEK_SET);
uint8_t ff_buf[4096];
memset(ff_buf, 0xFF, sizeof(ff_buf));
for (int i = 0; i < 50; i++) {
fwrite(ff_buf, sizeof(ff_buf), 1, f);
}
fseek(f, bitmap_lcn * clst_size, SEEK_SET);
uint8_t bmp[4096];
memset(bmp, 0, sizeof(bmp));
for (int i = 0; i <= 107; i++) {
bmp[i / 8] |= (1 << (i % 8));
}
fwrite(bmp, sizeof(bmp), 1, f);
fseek(f, upcase_lcn * clst_size, SEEK_SET);
uint16_t upcase_tbl[65536];
for (int i = 0; i < 65536; i++) {
if (i >= 'a' && i <= 'z')
upcase_tbl[i] = i - ('a' - 'A');
else
upcase_tbl[i] = i;
}
fwrite(upcase_tbl, sizeof(upcase_tbl), 1, f);
fseek(f, mft_bitmap_lcn * clst_size, SEEK_SET);
uint8_t mft_bmp[4096];
memset(mft_bmp, 0, sizeof(mft_bmp));
mft_bmp[0] = 0x7F; mft_bmp[1] = 0x05; mft_bmp[2] = 0x01;
fwrite(mft_bmp, sizeof(mft_bmp), 1, f);
fflush(f);
if (ftruncate(fileno(f), total_sectors * 512) < 0) {
fclose(f);
return -1;
}
fclose(f);
return 0;
}
int fd;
volatile int stop = 0;
void *truncate_thread(void *arg) {
while (!stop) {
if (ftruncate(fd, 20) < 0) {}
if (ftruncate(fd, 5) < 0) {}
}
return NULL;
}
void *read_thread(void *arg) {
char *ptr = mmap(NULL, 4096, PROT_READ, MAP_SHARED, fd, 0);
if (ptr == MAP_FAILED) {
perror("mmap");
return NULL;
}
volatile char val;
while (!stop) {
madvise(ptr, 4096, MADV_DONTNEED);
posix_fadvise(fd, 0, 4096, POSIX_FADV_DONTNEED);
val = ptr[0];
}
munmap(ptr, 4096);
return NULL;
}
int main(void) {
umount2("/tmp/mnt", MNT_FORCE | MNT_DETACH);
unlink("/tmp/img.ntfs");
printf("[*] Creating NTFS image...\n");
if (create_ntfs_image("/tmp/img.ntfs") != 0) {
printf("[-] Failed to create NTFS image\n");
exit(1);
}
printf("[+] NTFS image created\n");
int loop_c_fd = open("/dev/loop-control", O_RDWR);
if (loop_c_fd < 0) {
printf("[-] Failed to open /dev/loop-control: %s\n", strerror(errno));
exit(1);
}
int loop_num = ioctl(loop_c_fd, LOOP_CTL_GET_FREE);
if (loop_num < 0) {
printf("[-] Failed to get free loop device: %s\n", strerror(errno));
exit(1);
}
close(loop_c_fd);
char loop_name[64];
sprintf(loop_name, "/dev/loop%d", loop_num);
int loop_fd = open(loop_name, O_RDWR);
if (loop_fd < 0) {
printf("[-] Failed to open %s: %s\n", loop_name, strerror(errno));
exit(1);
}
int file_fd = open("/tmp/img.ntfs", O_RDWR);
if (file_fd < 0) {
printf("[-] Failed to open /tmp/img.ntfs: %s\n", strerror(errno));
exit(1);
}
if (ioctl(loop_fd, LOOP_SET_FD, file_fd) < 0) {
printf("[-] Failed to LOOP_SET_FD: %s\n", strerror(errno));
exit(1);
}
printf("[+] Loop device %s setup\n", loop_name);
close(loop_fd);
close(file_fd);
mkdir("/tmp/mnt", 0777);
usleep(250000);
int retries = 100;
int mount_ret = -1;
while (retries--) {
mount_ret = mount(loop_name, "/tmp/mnt", "ntfs3", 0, "");
if (mount_ret == 0) {
break;
}
if (errno != EBUSY) {
printf("[-] mount failed with unexpected error: %s\n", strerror(errno));
break;
}
usleep(50000);
}
if (mount_ret != 0) {
printf("[-] mount failed after retries\n");
exit(1);
}
printf("[+] Mounted NTFS image\n");
fd = open("/tmp/mnt/test", O_RDWR);
if (fd < 0) {
printf("[-] Failed to open /tmp/mnt/test: %s\n", strerror(errno));
exit(1);
}
printf("[+] Opened /tmp/mnt/test\n");
pthread_t t1;
pthread_t t2[4];
pthread_create(&t1, NULL, truncate_thread, NULL);
for (int i = 0; i < 4; i++) {
pthread_create(&t2[i], NULL, read_thread, NULL);
}
sleep(5);
stop = 1;
pthread_join(t1, NULL);
for (int i = 0; i < 4; i++) {
pthread_join(t2[i], NULL);
}
close(fd);
umount2("/tmp/mnt", MNT_FORCE | MNT_DETACH);
loop_c_fd = open("/dev/loop-control", O_RDWR);
if (loop_c_fd >= 0) {
ioctl(loop_c_fd, LOOP_CTL_REMOVE, loop_num);
close(loop_c_fd);
}
printf("[+] Done\n");
return 0;
}
|
| 8/2 |
2026/09/17 10:36 |
llm |
debugger |
0m
Model:
Tokens:
input: 15688
output: 38
thoughts: 310
Thoughts: **Debugging a File System Crash**
Okay, so I've got a crash, and it's happening deep within `iomap_read_inline_data`, specifically in `fs/iomap/buffered-io.c` at line 431. The warning message is pretty clear, `size > iomap->length`. That's not good. I'm reading past the allocated space. Let's see how we got here.
The call trace gives me some clues. It looks like `iomap_read_folio_iter` calls `iomap_read_folio`, which in turn calls `ntfs_read_folio`. The crash originates in `ntfs_read_folio`. Okay, so it seems like there might be an issue with how the NTFS driver is interacting with the I/O mapping layer, which then interacts with the page cache. And `ntfs_read_folio` is using `filemap_read_folio`, so let's check there too.
Now, the reproducer setup is interesting. We're dealing with an NTFS image, a file is opened, and we have two threads doing some pretty aggressive things. The `truncate_thread` is repeatedly calling `ftruncate` β bouncing the file size between 20 and 5 bytes. That's a classic race condition setup. The `read_thread` is then triggering memory pressure with `madvise(DONTNEED)` and `posix_fadvise(DONTNEED)` followed by mmap reads. This indicates the issue has to do with reading from the mmaped file. I need to understand what's happening when the file is truncated and then read from.
I'm going to jump into `fs/iomap/buffered-io.c` around line 431. I need to understand how the I/O map is constructed and whether the size is calculated correctly when the file gets truncated, especially with the NTFS file system. My initial instinct is that the truncation may not be handled properly, creating a race condition between the truncation and the read calls.
|
| 9/2 |
2026/09/17 10:36 |
tool |
grepper |
0m
Args: map[Expression:size > iomap->length PathPrefix:fs/iomap/buffered-io.c]
Results: map[Output:fs/iomap/buffered-io.c=418=static int iomap_read_inline_data(const struct iomap_iter *iter,
--
fs/iomap/buffered-io.c-430-
fs/iomap/buffered-io.c:431: if (WARN_ON_ONCE(size > iomap->length)) {
fs/iomap/buffered-io.c-432- fserror_report_io(iter->inode, FSERR_BUFFERED_READ,
]
|
| 10/2 |
2026/09/17 10:36 |
llm |
debugger |
0m
Model:
Tokens:
input: 16627
output: 39
thoughts: 29
Thoughts: Here's my summary, as though I'm reading and thinking about the code:
**Diving into `iomap_read_inline_data`**
Okay, time to dig into `fs/iomap/buffered-io.c` and take a look at `iomap_read_inline_data`. This function, from the looks of it, is crucial for handling inline data during reads, right? It's the point where we determine how to access the data that might be embedded directly within the inode itself, rather than needing a separate disk block. I need to be sure I've got a good grasp on how this interacts with the rest of the buffered I/O system, particularly when dealing with the possibility of partially filled inline extents or how it is that the data is extracted.
I immediately want to understand how it deals with the various edge cases β what if the requested read crosses the boundary of the inline data? Does it intelligently handle partial reads from the inline portion and then seamlessly transition to disk? Does it check for corrupt data or errors? I'm assuming there's some kind of sanity check on the length of the inline data before it gets processed.
I'm expecting to see a lot of pointer arithmetic and bit manipulation in this function. This is, after all, where we're efficiently pulling data directly from memory. I'm going to pay close attention to the use of any locking mechanisms. Are there any potential race conditions here with concurrent reads or writes to the same inode? Let's hope the locking strategy is well designed. I'll need to remember how the iomap system works with page cache.
I'm curious about the specific error handling and recovery. Where are the `goto` statements leading, and what are the implications of different error scenarios? Is there a clear path for returning an error back to the caller in a clean and controlled way, without leaking resources? I'm assuming that it is robust.
Finally, I'm interested in how it interacts with the underlying block device layer, if at all. Are there specific calls to block device functions within this function, or does it abstract that away? Alright, let's see how they've done it... let's dive in.
|
| 11/2 |
2026/09/17 10:37 |
tool |
read-file |
0m
Args: map[File:fs/iomap/buffered-io.c FirstLine:418 LineCount:50]
Results: map[Contents: 418: static int iomap_read_inline_data(const struct iomap_iter *iter,
419: struct folio *folio)
420: {
421: const struct iomap *iomap = iomap_iter_srcmap(iter);
422: size_t size = i_size_read(iter->inode) - iomap->offset;
423: size_t offset = offset_in_folio(folio, iomap->offset);
424:
425: if (WARN_ON_ONCE(!iomap->inline_data))
426: return -EIO;
427:
428: if (folio_test_uptodate(folio))
429: return 0;
430:
431: if (WARN_ON_ONCE(size > iomap->length)) {
432: fserror_report_io(iter->inode, FSERR_BUFFERED_READ,
433: iomap->offset, size, -EIO, GFP_NOFS);
434: return -EIO;
435: }
436: if (offset > 0)
437: ifs_alloc(iter->inode, folio, iter->flags);
438:
439: folio_fill_tail(folio, offset, iomap->inline_data, size);
440: iomap_set_range_uptodate(folio, offset, folio_size(folio) - offset);
441: return 0;
442: }
443:
444: void iomap_finish_folio_read(struct folio *folio, size_t off, size_t len,
445: int error)
446: {
447: struct iomap_folio_state *ifs = folio->private;
448: bool uptodate = !error;
449: bool finished = true;
450:
451: if (error)
452: fserror_report_io(folio->mapping->host, FSERR_BUFFERED_READ,
453: folio_pos(folio) + off, len, error,
454: GFP_ATOMIC);
455:
456: if (ifs) {
457: unsigned long flags;
458:
459: spin_lock_irqsave(&ifs->state_lock, flags);
460: if (!error)
461: uptodate = ifs_set_range_uptodate(folio, ifs, off, len);
462: ifs->read_bytes_pending -= len;
463: finished = !ifs->read_bytes_pending;
464: spin_unlock_irqrestore(&ifs->state_lock, flags);
465: }
466:
467: if (finished)
]
|
| 12/2 |
2026/09/17 10:37 |
llm |
debugger |
0m
Model:
Tokens:
input: 17989
output: 37
thoughts: 143
Thoughts: **Analyzing a Potential Read Size Inconsistency**
Okay, so I'm looking at this warning that's popping up, and it seems to be flagged when the calculated `size` exceeds `iomap->length`. Digging deeper, it looks like `size` is essentially the difference between the current file size, obtained through `i_size_read(iter->inode)`, and the `iomap->offset`. On the other hand, `iomap->length` represents the length of the inline data.
Aha! Now I see the possible race condition. If the file size is being concurrently modified, say through an `ftruncate` call, the value returned by `i_size_read(iter->inode)` could easily be larger than it was when `iomap->length` was initially set. This explains how the comparison breaks down. `ftruncate` can definitely influence `i_size`.
My next step is to trace how `iomap->length` is actually populated within `ntfs_read_folio`. That's where I need to focus my attention to understand the complete picture and find a potential solution or protection mechanism.
|
| 13/2 |
2026/09/17 10:37 |
tool |
read-file |
0m
Args: map[File:fs/ntfs3/inode.c FirstLine:840 LineCount:50]
Results: map[Contents: 840: return -EIO;
841: }
842:
843: if (ni->i_valid <= vbo) {
844: folio_zero_range(folio, 0, folio_size(folio));
845: folio_mark_uptodate(folio);
846: folio_unlock(folio);
847: return 0;
848: }
849:
850: if (is_compressed(ni)) {
851: /* ni_lock is taken inside ni_read_folio_cmpr after page locks */
852: err = ni_read_folio_cmpr(ni, folio);
853: return err;
854: }
855:
856: iomap_read_folio(&ntfs_iomap_ops, &ctx, NULL);
857: return 0;
858: }
859:
860: static void ntfs_readahead(struct readahead_control *rac)
861: {
862: struct address_space *mapping = rac->mapping;
863: struct inode *inode = mapping->host;
864: struct ntfs_inode *ni = ntfs_i(inode);
865: struct iomap_read_folio_ctx ctx = {
866: .ops = &ntfs_iomap_bio_read_ops,
867: .rac = rac,
868: };
869:
870: if (is_resident(ni)) {
871: /* No readahead for resident. */
872: return;
873: }
874:
875: if (is_compressed(ni)) {
876: /* No readahead for compressed. */
877: return;
878: }
879:
880: iomap_readahead(&ntfs_iomap_ops, &ctx, NULL);
881: }
882:
883: int ntfs_set_size(struct inode *inode, u64 new_size)
884: {
885: struct super_block *sb = inode->i_sb;
886: struct ntfs_sb_info *sbi = sb->s_fs_info;
887: struct ntfs_inode *ni = ntfs_i(inode);
888: int err;
889:
]
|
| 14/2 |
2026/09/17 10:37 |
llm |
debugger |
0m
Model:
Tokens:
input: 19134
output: 26
thoughts: 14
Thoughts: Okay, let's dive into this. Here's my take on those `ntfs_iomap_ops`:
**Diving into ntfs_iomap_ops**
Alright, so we're looking at `ntfs_iomap_ops`. I'm immediately thinking, "Okay, this is how the NTFS file system interacts with the kernel's I/O mapping infrastructure." We're talking about the low-level details of how NTFS handles data access, probably focusing on direct I/O, extent mapping, and addressing within the file system. I need to refresh my memory on the specifics, but I'm guessing this structure defines the methods for mapping logical blocks within an NTFS file to physical blocks on the underlying storage. It'll probably include functions for things like reading, writing, and potentially, managing sparse files or other optimization strategies specific to NTFS. I expect it covers both regular file I/O and perhaps some handling of metadata access, too. Time to delve in and see what's what!
|
| 15/2 |
2026/09/17 10:38 |
tool |
codesearch-find-references |
0m
Args:
Results: map[References:<nil> TruncatedOutput:false]
|
| 16/2 |
2026/09/17 10:38 |
llm |
debugger |
0m
Model:
Tokens:
input: 19408
output: 34
thoughts: 26
Thoughts: Here's my thought process, summarized as you requested:
**Navigating the NTFS Landscape**
Okay, hold on a second. Before I get too deep into this, I need to get my bearings. I'm focusing on the NTFS3 filesystem implementation, and there's a specific data structure or set of operations I need to find the definition of. My initial thought is to zero in on `ntfs_iomap_ops`. That's the key. Now, where would that be located within the kernel sources? My best guess, based on standard kernel organization, is that it'll reside within the `fs/ntfs3/` directory. That's the logical place to start digging. Time to run that search and see what I can unearth.
|
| 17/2 |
2026/09/17 10:38 |
tool |
grepper |
0m
Args: map[Expression:ntfs_iomap_ops PathPrefix:fs/ntfs3/]
Results: map[Output:fs/ntfs3/file.c=301=static int ntfs_extend_initialized_size(struct file *file,
--
fs/ntfs3/file.c-317- err = iomap_zero_range(inode, valid, new_valid - valid, NULL,
fs/ntfs3/file.c:318: &ntfs_iomap_ops, &ntfs_iomap_folio_ops, NULL);
fs/ntfs3/file.c-319- if (err) {
--
fs/ntfs3/file.c=466=static long ntfs_fallocate(struct file *file, int mode, loff_t vbo, loff_t len)
--
fs/ntfs3/file.c-556- err = iomap_zero_range(inode, from, tmp - from, NULL,
fs/ntfs3/file.c:557: &ntfs_iomap_ops,
fs/ntfs3/file.c-558- &ntfs_iomap_folio_ops, NULL);
--
fs/ntfs3/file.c-574- err = iomap_zero_range(inode, end_a, end - end_a, NULL,
fs/ntfs3/file.c:575: &ntfs_iomap_ops,
fs/ntfs3/file.c-576- &ntfs_iomap_folio_ops, NULL);
--
fs/ntfs3/file.c=817=static ssize_t ntfs_file_read_iter(struct kiocb *iocb, struct iov_iter *iter)
--
fs/ntfs3/file.c-892-
fs/ntfs3/file.c:893: ret = iomap_dio_rw(iocb, iter, &ntfs_iomap_ops, NULL, dio_flags,
fs/ntfs3/file.c-894- NULL, 0);
--
fs/ntfs3/file.c=1239=static ssize_t ntfs_file_write_iter(struct kiocb *iocb, struct iov_iter *from)
--
fs/ntfs3/file.c-1307-
fs/ntfs3/file.c:1308: ret = iomap_file_buffered_write(iocb, from, &ntfs_iomap_ops,
fs/ntfs3/file.c-1309- &ntfs_iomap_folio_ops, NULL);
--
fs/ntfs3/file.c-1324-
fs/ntfs3/file.c:1325: ret = iomap_dio_rw(iocb, from, &ntfs_iomap_ops, NULL,
fs/ntfs3/file.c-1326- IOMAP_DIO_FORCE_WAIT, NULL, 0);
--
fs/ntfs3/file.c-1337- iocb->ki_flags &= ~IOCB_DIRECT;
fs/ntfs3/file.c:1338: err = iomap_file_buffered_write(iocb, from, &ntfs_iomap_ops,
fs/ntfs3/file.c-1339- &ntfs_iomap_folio_ops, NULL);
--
fs/ntfs3/file.c=1457=int ntfs_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo,
--
fs/ntfs3/file.c-1487-
fs/ntfs3/file.c:1488: err = iomap_fiemap(inode, fieinfo, start, len, &ntfs_iomap_ops);
fs/ntfs3/file.c-1489-
--
fs/ntfs3/inode.c=763=static sector_t ntfs_bmap(struct address_space *mapping, sector_t block)
--
fs/ntfs3/inode.c-783-
fs/ntfs3/inode.c:784: return iomap_bmap(mapping, block, &ntfs_iomap_ops);
fs/ntfs3/inode.c-785-}
--
fs/ntfs3/inode.c=826=static int ntfs_read_folio(struct file *file, struct folio *folio)
--
fs/ntfs3/inode.c-855-
fs/ntfs3/inode.c:856: iomap_read_folio(&ntfs_iomap_ops, &ctx, NULL);
fs/ntfs3/inode.c-857- return 0;
--
fs/ntfs3/inode.c=860=static void ntfs_readahead(struct readahead_control *rac)
--
fs/ntfs3/inode.c-879-
fs/ntfs3/inode.c:880: iomap_readahead(&ntfs_iomap_ops, &ctx, NULL);
fs/ntfs3/inode.c-881-}
--
fs/ntfs3/inode.c=2319=static DEFINE_IOMAP_ITER_NEXT_END(ntfs_iomap_next, ntfs_iomap_begin,
--
fs/ntfs3/inode.c-2321-
fs/ntfs3/inode.c:2322:const struct iomap_ops ntfs_iomap_ops = {
fs/ntfs3/inode.c-2323- .iomap_next = ntfs_iomap_next,
--
fs/ntfs3/ntfs_fs.h=812=void ntfs_evict_inode(struct inode *inode);
fs/ntfs3/ntfs_fs.h:813:extern const struct iomap_ops ntfs_iomap_ops;
fs/ntfs3/ntfs_fs.h-814-extern const struct iomap_write_ops ntfs_iomap_folio_ops;
]
|
| 18/2 |
2026/09/17 10:38 |
llm |
debugger |
0m
Model:
Tokens:
input: 21179
output: 39
thoughts: 26
Thoughts: Here's my take on those thoughts, tailored for an expert audience:
**Diving into `ntfs_iomap_begin` in `fs/ntfs3/inode.c`**
Okay, time to dig into the `ntfs_iomap_begin` function. Specifically, I need to revisit the implementation within the `ntfs3` filesystem code, focusing on its role with the inodes. Given the context, I'm expecting this function is where the core logic for mapping logical block addresses (LBAs) to physical disk blocks resides. It's the critical entry point for handling read and write operations, and I need to re-familiarize myself with its intricacies. I want to quickly evaluate how it interacts with the NTFS metadata structures. Specifically, I want to refresh my memory on the handling of attribute lists, extents, and the fragment allocation within the NTFS file system. I anticipate that this function is where the details of sparse files, compression, and encryption (if implemented) will be handled. I also need to make sure I understand how it interacts with the journaling mechanisms if any. Essentially, I'm aiming to quickly map the function's responsibility to the broader IO path within the `ntfs3` driver, making sure I understand the complexities.
|
| 19/2 |
2026/09/17 10:38 |
tool |
read-file |
0m
Args: map[File:fs/ntfs3/inode.c FirstLine:2200 LineCount:100]
Results: map[Contents:2200: case IO_REPARSE_TAG_CLOUD_4:
2201: case IO_REPARSE_TAG_CLOUD_5:
2202: case IO_REPARSE_TAG_CLOUD_6:
2203: case IO_REPARSE_TAG_CLOUD_7:
2204: case IO_REPARSE_TAG_CLOUD_8:
2205: case IO_REPARSE_TAG_CLOUD_9:
2206: case IO_REPARSE_TAG_CLOUD_A:
2207: case IO_REPARSE_TAG_CLOUD_B:
2208: case IO_REPARSE_TAG_CLOUD_C:
2209: case IO_REPARSE_TAG_CLOUD_D:
2210: case IO_REPARSE_TAG_CLOUD_E:
2211: case IO_REPARSE_TAG_CLOUD_F:
2212: err = sizeof("OneDrive") - 1;
2213: if (err > buflen)
2214: err = buflen;
2215: memcpy(buffer, "OneDrive", err);
2216: goto out;
2217:
2218: default:
2219: if (IsReparseTagMicrosoft(rp->ReparseTag)) {
2220: /* Unknown Microsoft Tag. */
2221: goto out;
2222: }
2223: if (!IsReparseTagNameSurrogate(rp->ReparseTag) ||
2224: size <= sizeof(struct REPARSE_POINT)) {
2225: goto out;
2226: }
2227:
2228: /* Users tag. */
2229: uname = Add2Ptr(rp, sizeof(struct REPARSE_POINT));
2230: ulen = le16_to_cpu(rp->ReparseDataLength) -
2231: sizeof(struct REPARSE_POINT);
2232: }
2233:
2234: /* Convert nlen from bytes to UNICODE chars. */
2235: ulen >>= 1;
2236:
2237: /* Check that name is available. */
2238: if (!ulen || uname + ulen > (__le16 *)Add2Ptr(rp, size))
2239: goto out;
2240:
2241: /* If name is already zero terminated then truncate it now. */
2242: if (!uname[ulen - 1])
2243: ulen -= 1;
2244:
2245: err = ntfs_utf16_to_nls(sbi, uname, ulen, buffer, buflen);
2246:
2247: if (err < 0)
2248: goto out;
2249:
2250: /* Translate Windows '\' into Linux '/'. */
2251: for (i = 0; i < err; i++) {
2252: if (buffer[i] == '\\')
2253: buffer[i] = '/';
2254: }
2255:
2256: /* Always set last zero. */
2257: buffer[err] = 0;
2258:
2259: /* If this is a junction, translate the link target. */
2260: if (rp->ReparseTag == IO_REPARSE_TAG_MOUNT_POINT)
2261: err = ntfs_translate_junction(sb, link_de, buffer, err, buflen);
2262:
2263: out:
2264: kfree(to_free);
2265: return err;
2266: }
2267:
2268: static const char *ntfs_get_link(struct dentry *de, struct inode *inode,
2269: struct delayed_call *done)
2270: {
2271: int err;
2272: char *ret;
2273:
2274: if (!de)
2275: return ERR_PTR(-ECHILD);
2276:
2277: ret = kmalloc(PAGE_SIZE, GFP_NOFS);
2278: if (!ret)
2279: return ERR_PTR(-ENOMEM);
2280:
2281: err = ntfs_readlink_hlp(de, inode, ret, PAGE_SIZE);
2282: if (err < 0) {
2283: kfree(ret);
2284: return ERR_PTR(err);
2285: }
2286:
2287: set_delayed_call(done, kfree_link, ret);
2288:
2289: return ret;
2290: }
2291:
2292: // clang-format off
2293: const struct inode_operations ntfs_link_inode_operations = {
2294: .get_link = ntfs_get_link,
2295: .setattr = ntfs_setattr,
2296: .listxattr = ntfs_listxattr,
2297: .fileattr_get = ntfs_fileattr_get,
2298: .fileattr_set = ntfs_fileattr_set,
2299: };
]
|
| 20/2 |
2026/09/17 10:38 |
llm |
debugger |
0m
Model:
Tokens:
input: 22978
output: 39
thoughts: 17
Thoughts: Here's my attempt at summarizing the thought process, tailored for an expert audience and written in the first person:
**Navigating the NTFS I/O Landscape**
Okay, so I'm looking at this code, and my initial instinct is that the crucial bit I need β the `ntfs_iomap_begin` function call β isn't right here. It feels like it's a layer down. I'll need to scroll through the file further. I bet the relevant section is nestled deeper, probably within some more granular I/O handling or error-checking sequence. Time to dive deeper and see where that function is actually invoked or defined. This usually indicates how the lower-level functionality is initialized or accessed within the module.
|
| 21/2 |
2026/09/17 10:38 |
tool |
read-file |
0m
Args: map[File:fs/ntfs3/inode.c FirstLine:2300 LineCount:100]
Results: map[Contents:2300:
2301: const struct address_space_operations ntfs_aops = {
2302: .read_folio = ntfs_read_folio,
2303: .readahead = ntfs_readahead,
2304: .writepages = ntfs_writepages,
2305: .bmap = ntfs_bmap,
2306: .dirty_folio = iomap_dirty_folio,
2307: .migrate_folio = filemap_migrate_folio,
2308: .release_folio = iomap_release_folio,
2309: .invalidate_folio = iomap_invalidate_folio,
2310: };
2311:
2312: const struct address_space_operations ntfs_aops_cmpr = {
2313: .read_folio = ntfs_read_folio,
2314: .dirty_folio = iomap_dirty_folio,
2315: .release_folio = iomap_release_folio,
2316: .invalidate_folio = iomap_invalidate_folio,
2317: };
2318:
2319: static DEFINE_IOMAP_ITER_NEXT_END(ntfs_iomap_next, ntfs_iomap_begin,
2320: ntfs_iomap_end);
2321:
2322: const struct iomap_ops ntfs_iomap_ops = {
2323: .iomap_next = ntfs_iomap_next,
2324: };
2325:
2326: const struct iomap_write_ops ntfs_iomap_folio_ops = {
2327: .put_folio = ntfs_iomap_put_folio,
2328: };
2329: // clang-format on
]
|
| 22/2 |
2026/09/17 10:38 |
llm |
debugger |
0m
Model:
Tokens:
input: 23720
output: 26
thoughts: 14
Thoughts: Here's my thought process, as requested:
**Tracing the Source: ntfs_iomap_begin**
Okay, so I'm trying to get a handle on `ntfs_iomap_begin`. My immediate question is, where is this function actually defined? Knowing the definition is fundamental. It's the starting point for understanding its purpose, its parameters, and how it interacts with the rest of the NTFS driver code. I'll need to locate the header file or source file where the declaration lives. From there I can explore the implementation. I'm already anticipating things like the function's return type and any arguments it takes. Once I see the definition, I can begin to reason about its role within the iomap framework. Is it responsible for preparing an iomap operation, setting up data structures, or something else entirely? The definition will give me the first crucial clue.
|
| 23/2 |
2026/09/17 10:39 |
tool |
codesearch-find-references |
0m
Args: map[Name:ntfs_iomap_begin]
Results: map[References:[map[ReferenceKind:takes-address-of ReferencingEntityKind:function ReferencingEntityName:ntfs_iomap_next SourceFile:fs/ntfs3/inode.c SourceLine:2319] map[ReferenceKind:calls ReferencingEntityKind:function ReferencingEntityName:ntfs_writeback_range SourceFile:fs/ntfs3/inode.c SourceLine:1181]] TruncatedOutput:false]
|
| 24/2 |
2026/09/17 10:39 |
llm |
debugger |
0m
Model:
Tokens:
input: 24083
output: 26
thoughts: 26
Thoughts: Here's my take on those thoughts:
**Analyzing `ntfs_iomap_begin` in `fs/ntfs3/inode.c`**
Okay, time to dig into the `ntfs_iomap_begin` function within the NTFS3 filesystem driver. Specifically, it's located in `fs/ntfs3/inode.c`. I'm guessing this function is central to how the NTFS driver handles I/O mapping β figuring out where data physically resides on the disk for a given inode. I need to understand its role in the overall I/O path. I'm hoping this gives me insights into performance bottlenecks or potential areas for optimization within this layer. Let's see how the NTFS driver manages the block mapping. Itβs likely involved in figuring out the on-disk location given the logical offset and size of a file, especially within the context of NTFSβs complex metadata structures and its use of extent-based allocation. It would be a key player for both reads and writes. I'm expecting this function will deal with things like attribute lists, resident data, and the MFT. I'll need to pay close attention to how it handles extent handling, including any potential optimization logic for contiguous extents.
|
| 25/2 |
2026/09/17 10:39 |
tool |
codesearch-definition-source |
0m
Args: map[Name:ntfs_iomap_begin]
Results: map[SourceCode: 921: /*
922: * Function to get mapping vbo -> lbo.
923: * used with:
924: * - iomap_zero_range
925: * - iomap_truncate_page
926: * - iomap_dio_rw
927: * - iomap_file_buffered_write
928: * - iomap_bmap
929: * - iomap_fiemap
930: * - iomap_bio_read_folio
931: * - iomap_bio_readahead
932: */
933: static int ntfs_iomap_begin(struct inode *inode, loff_t offset, loff_t length,
934: unsigned int flags, struct iomap *iomap,
935: struct iomap *srcmap)
936: {
937: struct ntfs_inode *ni = ntfs_i(inode);
938: struct ntfs_sb_info *sbi = ni->mi.sbi;
939: u8 cluster_bits = sbi->cluster_bits;
940: CLST vcn = offset >> cluster_bits;
941: u32 off = offset & sbi->cluster_mask;
942: bool rw = flags & IOMAP_WRITE;
943: loff_t endbyte = offset + length;
944: void *res = NULL;
945: int err;
946: CLST lcn, clen, clen_max = 1;
947: bool new_clst = false;
948: bool no_da;
949: bool zero = false;
950: if (unlikely(ntfs3_forced_shutdown(sbi->sb)))
951: return -EIO;
952:
953: if (flags & IOMAP_REPORT) {
954: if (offset > ntfs_get_maxbytes(ni)) {
955: /* called from fiemap/bmap. */
956: return -EINVAL;
957: }
958:
959: if (offset >= inode->i_size) {
960: /* special code for report. */
961: return -ENOENT;
962: }
963: }
964:
965: if (IOMAP_ZERO == flags && (endbyte & sbi->cluster_mask)) {
966: rw = true;
967: } else if (rw) {
968: clen_max = bytes_to_cluster(sbi, endbyte) - vcn;
969: }
970:
971: /*
972: * Force to allocate clusters if directIO(write) or writeback_range.
973: * NOTE: attr_data_get_block allocates clusters only for sparse file.
974: * Normal file allocates clusters in attr_set_size.
975: */
976: no_da = flags == (IOMAP_DIRECT | IOMAP_WRITE) || srcmap == WB_NO_DA;
977:
978: err = attr_data_get_block(ni, vcn, clen_max, &lcn, &clen,
979: rw ? &new_clst : NULL, zero, &res, no_da);
980:
981: if (err) {
982: return err;
983: }
984:
985: if (lcn == EOF_LCN) {
986: /* request out of file. */
987: if (flags & IOMAP_REPORT) {
988: /* special code for report. */
989: return -ENOENT;
990: }
991:
992: if (rw) {
993: /* should never be here. */
994: return -EINVAL;
995: }
996: lcn = SPARSE_LCN;
997: }
998:
999: iomap->flags = new_clst ? IOMAP_F_NEW : 0;
1000:
1001: if (lcn == RESIDENT_LCN) {
1002: if (offset >= clen) {
1003: if (res)
1004: __free_page(virt_to_page(res));
1005: if (flags & IOMAP_REPORT) {
1006: /* special code for report. */
1007: return -ENOENT;
1008: }
1009: return -EFAULT;
1010: }
1011:
1012: iomap->private = iomap->inline_data = res;
1013: iomap->type = IOMAP_INLINE;
1014: iomap->offset = 0;
1015: iomap->length = clen; /* resident size in bytes. */
1016: return 0;
1017: }
1018:
1019: if (!clen) {
1020: /* broken file? */
1021: return -EINVAL;
1022: }
1023:
1024: iomap->bdev = inode->i_sb->s_bdev;
1025: iomap->offset = offset;
1026: iomap->length = ((loff_t)clen << cluster_bits) - off;
1027:
1028: if (lcn == COMPRESSED_LCN) {
1029: /* should never be here. */
1030: return -EOPNOTSUPP;
1031: }
1032:
1033: if (lcn == DELALLOC_LCN) {
1034: iomap->type = IOMAP_DELALLOC;
1035: iomap->addr = IOMAP_NULL_ADDR;
1036: } else {
1037: /* Translate clusters into bytes. */
1038: iomap->addr = ((loff_t)lcn << cluster_bits) + off;
1039: if (length && iomap->length > length)
1040: iomap->length = length;
1041: else
1042: endbyte = offset + iomap->length;
1043:
1044: if (lcn == SPARSE_LCN) {
1045: iomap->addr = IOMAP_NULL_ADDR;
1046: iomap->type = IOMAP_HOLE;
1047: // if (IOMAP_ZERO == flags && !off) {
1048: // iomap->length = (endbyte - offset) &
1049: // sbi->cluster_mask_inv;
1050: // }
1051: } else if (endbyte <= ni->i_valid) {
1052: iomap->type = IOMAP_MAPPED;
1053: } else if (offset < ni->i_valid) {
1054: iomap->type = IOMAP_MAPPED;
1055: if (flags & IOMAP_REPORT)
1056: iomap->length = ni->i_valid - offset;
1057: } else if (rw || (flags & IOMAP_ZERO)) {
1058: iomap->type = IOMAP_MAPPED;
1059: } else {
1060: iomap->type = IOMAP_UNWRITTEN;
1061: }
1062: }
1063:
1064: if ((flags & IOMAP_ZERO) &&
1065: (iomap->type == IOMAP_MAPPED || iomap->type == IOMAP_DELALLOC)) {
1066: /* Avoid too large requests. */
1067: u32 tail;
1068: u32 off_a = offset & (PAGE_SIZE - 1);
1069: if (off_a)
1070: tail = PAGE_SIZE - off_a;
1071: else
1072: tail = PAGE_SIZE;
1073:
1074: if (iomap->length > tail)
1075: iomap->length = tail;
1076: }
1077:
1078: return 0;
1079: }
SourceFile:fs/ntfs3/inode.c]
|
| 26/2 |
2026/09/17 10:39 |
llm |
debugger |
0m
Model:
Tokens:
input: 26834
output: 25
thoughts: 204
Thoughts: **Analyzing the NTFS I/O Mapping Process**
Okay, so I'm diving into this `ntfs_iomap_begin` function and trying to grasp its logic. The crucial part, it seems, hinges on the `lcn` value. If `lcn` is `RESIDENT_LCN`, that suggests we're dealing with inline data β data stored directly within the attribute itself.
I'm checking the offset and comparing it to `clen`, which, as I recall from previous work with NTFS, is set by the `attr_data_get_block` function. Makes sense; `clen` likely represents the length of the resident data.
If the offset exceeds `clen`, then we have a problem. The code checks if `res` exists, and frees it if it does. If this is a report, then it should report ENOENT. Otherwise, return EFAULT.
However, if offset is within `clen`, we're in a happy path for inline data. `iomap->private` and `iomap->inline_data` are both set to the resident data pointed to by `res`. The `iomap` structure is then configured to indicate an `IOMAP_INLINE` type, with the offset set to zero and the length set to `clen`. Finally, the function returns success. So the basic idea here is efficient inline data handling, which is a key optimization in NTFS, making sure that it can quickly serve requests for attributes that are small enough to be stored in the MFT entry itself.
|
| 27/2 |
2026/09/17 10:39 |
tool |
codesearch-definition-source |
0m
Args: map[Name:attr_data_get_block]
Results: map[SourceCode: 942: /*
943: * attr_data_get_block - Returns 'lcn' and 'len' for given 'vcn'.
944: *
945: * @new == NULL means just to get current mapping for 'vcn'
946: * @new != NULL means allocate real cluster if 'vcn' maps to hole
947: * @zero - zeroout new allocated clusters
948: *
949: * NOTE:
950: * - @new != NULL is called only for sparsed or compressed attributes.
951: * - new allocated clusters are zeroed via blkdev_issue_zeroout.
952: */
953: int attr_data_get_block(struct ntfs_inode *ni, CLST vcn, CLST clen, CLST *lcn,
954: CLST *len, bool *new, bool zero, void **res, bool no_da)
955: {
956: int err;
957:
958: if (new)
959: *new = false;
960: if (res)
961: *res = NULL;
962:
963: /* Try to find in cache. */
964: down_read(&ni->file.run_lock);
965: if (run_lookup_entry_da(&ni->file.run, !no_da ? &ni->file.run_da : NULL,
966: vcn, lcn, len)) {
967: } else {
968: *len = 0;
969: }
970: up_read(&ni->file.run_lock);
971:
972: if (*len && (*lcn != SPARSE_LCN || !new))
973: return 0; /* Fast normal way without allocation. */
974:
975: /* No cluster in cache or we need to allocate cluster in hole. */
976: ni_lock(ni);
977: down_write(&ni->file.run_lock);
978:
979: err = attr_data_get_block_locked(ni, vcn, clen, lcn, len, new, zero,
980: res, no_da);
981:
982: up_write(&ni->file.run_lock);
983: ni_unlock(ni);
984:
985: return err;
986: }
SourceFile:fs/ntfs3/attrib.c]
|
| 28/2 |
2026/09/17 10:39 |
llm |
debugger |
0m
Model:
Tokens:
input: 28121
output: 27
thoughts: 15
Thoughts: Okay, here's my interpretation of that thought process, assuming I'm deep in the weeds of some low-level system code.
**Diving into `attr_data_get_block_locked`**
Alright, so the focus is now on `attr_data_get_block_locked`. That function name alone tells me a lot. We're talking about *attribute data*, which means metadata, descriptors, something tied to a specific object or file system entity. The "get" implies we're retrieving this data. The "block" suggests we're probably dealing with data organized in some kind of block structure, likely on-disk or in a memory-mapped region. And the "locked" part is critical. This means we're in a multithreaded environment, and we're dealing with synchronization primitives. We're likely holding some kind of mutex or spinlock to safely access this critical section. I need to understand this function's exact purpose within the larger data access scheme. I'm going to have to consider potential race conditions, deadlocks, and whether it's optimized for the target hardware. My next step will be to look at the function's definition, the surrounding context, and what it's trying to achieve β is it atomic, transactional, or something more complex? I need to analyze how this function interacts with the underlying storage and other concurrent processes.
|
| 29/2 |
2026/09/17 10:40 |
tool |
codesearch-definition-source |
0m
Args: map[Name:attr_data_get_block_locked]
Results: map[SourceCode: 988: /*
989: * attr_data_get_block_locked - Helper for attr_data_get_block.
990: */
991: int attr_data_get_block_locked(struct ntfs_inode *ni, CLST vcn, CLST clen,
992: CLST *lcn, CLST *len, bool *new, bool zero,
993: void **res, bool no_da)
994: {
995: int err = 0;
996: struct ntfs_sb_info *sbi = ni->mi.sbi;
997: struct runs_tree *run = &ni->file.run;
998: struct runs_tree *run_da = &ni->file.run_da;
999: bool da = sbi->options->delalloc && !no_da;
1000: u8 cluster_bits;
1001: struct ATTRIB *attr, *attr_b;
1002: struct ATTR_LIST_ENTRY *le, *le_b;
1003: struct mft_inode *mi, *mi_b;
1004: CLST hint, svcn, to_alloc, evcn1, next_svcn, asize, end, vcn0;
1005: CLST alloc, evcn;
1006: unsigned fr;
1007: u64 total_size, total_size0;
1008: int step;
1009:
1010: again:
1011: if (run_lookup_entry_da(run, da ? &ni->file.run_da : NULL, vcn, lcn,
1012: len)) {
1013: } else {
1014: *len = 0;
1015: }
1016:
1017: if (*len) {
1018: if (*lcn != SPARSE_LCN || !new)
1019: goto out; /* normal way without allocation. */
1020: if (clen > *len)
1021: clen = *len;
1022: }
1023:
1024: cluster_bits = sbi->cluster_bits;
1025: step = 0;
1026:
1027: le_b = NULL;
1028: attr_b = ni_find_attr(ni, NULL, &le_b, ATTR_DATA, ni->file.ads.name,
1029: ni->file.ads.len, NULL, &mi_b);
1030: if (!attr_b) {
1031: err = -ENOENT;
1032: goto out;
1033: }
1034:
1035: if (!attr_b->non_res) {
1036: u32 data_size = le32_to_cpu(attr_b->res.data_size);
1037: *lcn = RESIDENT_LCN;
1038: *len = data_size;
1039: if (res) {
1040: *res = NULL;
1041: if (data_size) {
1042: struct page *page = alloc_page(GFP_KERNEL);
1043: if (!page) {
1044: err = -ENOMEM;
1045: goto out;
1046: }
1047:
1048: *res = page_address(page);
1049: memcpy(*res, resident_data(attr_b), data_size);
1050: }
1051: }
1052: goto out;
1053: }
1054:
1055: asize = le64_to_cpu(attr_b->nres.alloc_size) >> cluster_bits;
1056: if (vcn >= asize) {
1057: if (new) {
1058: err = -EINVAL;
1059: } else {
1060: *len = 1;
1061: *lcn = EOF_LCN;
1062: }
1063: goto out;
1064: }
1065:
1066: svcn = le64_to_cpu(attr_b->nres.svcn);
1067: evcn1 = le64_to_cpu(attr_b->nres.evcn) + 1;
1068:
1069: attr = attr_b;
1070: le = le_b;
1071: mi = mi_b;
1072:
1073: if (le_b && (vcn < svcn || evcn1 <= vcn)) {
1074: attr = ni_find_attr(ni, attr_b, &le, ATTR_DATA,
1075: ni->file.ads.name, ni->file.ads.len, &vcn,
1076: &mi);
1077: if (!attr) {
1078: err = -EINVAL;
1079: goto out;
1080: }
1081: svcn = le64_to_cpu(attr->nres.svcn);
1082: evcn1 = le64_to_cpu(attr->nres.evcn) + 1;
1083: }
1084:
1085: /* Load in cache actual information. */
1086: err = attr_load_runs(attr, ni, run, NULL);
1087: if (err)
1088: goto out;
1089:
1090: /* Check for compressed frame. */
1091: err = attr_is_frame_compressed(ni, attr_b, vcn >> NTFS_LZNT_CUNIT,
1092: &hint, run);
1093: if (err)
1094: goto out;
1095:
1096: if (hint) {
1097: /* if frame is compressed - don't touch it. */
1098: *lcn = COMPRESSED_LCN;
1099: /* length to the end of frame. */
1100: *len = NTFS_LZNT_CLUSTERS - (vcn & (NTFS_LZNT_CLUSTERS - 1));
1101: err = 0;
1102: goto out;
1103: }
1104:
1105: if (!*len) {
1106: if (run_lookup_entry_da(run, da ? run_da : NULL, vcn, lcn,
1107: len)) {
1108: if (*lcn != SPARSE_LCN || !new)
1109: goto ok; /* Slow normal way without allocation. */
1110:
1111: if (clen > *len)
1112: clen = *len;
1113: } else if (!new) {
1114: /* Here we may return -ENOENT.
1115: * In any case caller gets zero length. */
1116: goto ok;
1117: }
1118: }
1119:
1120: if (!is_attr_ext(attr_b)) {
1121: /* The code below only for sparsed or compressed attributes. */
1122: err = -EINVAL;
1123: goto out;
1124: }
1125:
1126: vcn0 = vcn;
1127: to_alloc = clen;
1128: fr = (sbi->record_size - le32_to_cpu(mi->mrec->used) + 8) / 3 + 1;
1129: /* Allocate frame aligned clusters.
1130: * ntfs.sys usually uses 16 clusters per frame for sparsed or compressed.
1131: * ntfs3 uses 1 cluster per frame for new created sparsed files. */
1132: if (attr_b->nres.c_unit) {
1133: CLST clst_per_frame = 1u << attr_b->nres.c_unit;
1134: CLST cmask = ~(clst_per_frame - 1);
1135:
1136: /* Get frame aligned vcn and to_alloc. */
1137: vcn = vcn0 & cmask;
1138: to_alloc = ((vcn0 + clen + clst_per_frame - 1) & cmask) - vcn;
1139: if (fr < clst_per_frame)
1140: fr = clst_per_frame;
1141: if (vcn != vcn0)
1142: zero = true;
1143:
1144: /* Check if 'vcn' and 'vcn0' in different attribute segments. */
1145: if (vcn < svcn || evcn1 <= vcn) {
1146: struct ATTRIB *attr2;
1147: /* Load runs for truncated vcn. */
1148: attr2 = ni_find_attr(ni, attr_b, &le_b, ATTR_DATA,
1149: ni->file.ads.name,
1150: ni->file.ads.len, &vcn, &mi);
1151: if (!attr2) {
1152: err = -EINVAL;
1153: goto out;
1154: }
1155: evcn1 = le64_to_cpu(attr2->nres.evcn) + 1;
1156: err = attr_load_runs(attr2, ni, run, NULL);
1157: if (err)
1158: goto out;
1159: }
1160:
1161: if (vcn0 < svcn || evcn1 <= vcn0) {
1162: struct ATTRIB *attr2;
1163:
1164: attr2 = ni_find_attr(ni, attr_b, &le_b, ATTR_DATA,
1165: ni->file.ads.name,
1166: ni->file.ads.len, &vcn0, &mi);
1167: if (!attr2) {
1168: err = -EINVAL;
1169: goto out;
1170: }
1171: err = attr_load_runs(attr2, ni, run, NULL);
1172: if (err)
1173: goto out;
1174: }
1175:
1176: da = false; /* no delalloc for compressed file. */
1177: }
1178:
1179: if (vcn + to_alloc > asize)
1180: to_alloc = asize - vcn;
1181:
1182: if (da) {
1183: CLST rlen1, rlen2;
1184: if (!ntfs_check_free_space(sbi, to_alloc, 0, true)) {
1185: err = ni_allocate_da_blocks_locked(ni);
1186: if (err)
1187: goto out;
1188: /* Layout of records may be changed. Start again without 'da'. */
1189: da = false;
1190: goto again;
1191: }
1192:
1193: /* run_add_entry consolidates existed ranges. */
1194: rlen1 = run_len(run_da);
1195: if (!run_add_entry(run_da, vcn, SPARSE_LCN, to_alloc, false)) {
1196: err = -ENOMEM;
1197: goto out;
1198: }
1199: rlen2 = run_len(run_da);
1200:
1201: /* new added delay clusters = rlen2 - rlen1. */
1202: ntfs_add_da(sbi, rlen2 - rlen1);
1203: *len = to_alloc;
1204: *lcn = DELALLOC_LCN;
1205: goto ok;
1206: }
1207:
1208: /* Get the last LCN to allocate from. */
1209: hint = 0;
1210:
1211: if (vcn > evcn1) {
1212: if (!run_add_entry(run, evcn1, SPARSE_LCN, vcn - evcn1,
1213: false)) {
1214: err = -ENOMEM;
1215: goto out;
1216: }
1217: } else if (vcn && !run_lookup_entry(run, vcn - 1, &hint, NULL, NULL)) {
1218: hint = -1;
1219: }
1220:
1221: /* Allocate and zeroout new clusters. */
1222: err = attr_allocate_clusters(sbi, run, run_da, vcn, hint + 1, to_alloc,
1223: NULL,
1224: zero ? ALLOCATE_ZERO : ALLOCATE_ONE_FR,
1225: len, fr, lcn, len);
1226: if (err)
1227: goto out;
1228: *new = true;
1229: step = 1;
1230:
1231: end = vcn + *len;
1232: /* Save 'total_size0' to restore if error. */
1233: total_size0 = le64_to_cpu(attr_b->nres.total_size);
1234: total_size = total_size0 + ((u64)*len << cluster_bits);
1235:
1236: if (vcn != vcn0) {
1237: if (!run_lookup_entry(run, vcn0, lcn, len, NULL)) {
1238: err = -EINVAL;
1239: goto out;
1240: }
1241: if (*lcn == SPARSE_LCN) {
1242: /* Internal error. Should not happened. */
1243: WARN_ON(1);
1244: err = -EINVAL;
1245: goto out;
1246: }
1247: /* Check case when vcn0 + len overlaps new allocated clusters. */
1248: if (vcn0 + *len > end)
1249: *len = end - vcn0;
1250: }
1251:
1252: repack:
1253: err = mi_pack_runs(mi, attr, run, max(end, evcn1) - svcn);
1254: if (err)
1255: goto out;
1256:
1257: attr_b->nres.total_size = cpu_to_le64(total_size);
1258: inode_set_bytes(&ni->vfs_inode, total_size);
1259: ni->ni_flags |= NI_FLAG_UPDATE_PARENT;
1260:
1261: mi_b->dirty = true;
1262: mark_inode_dirty(&ni->vfs_inode);
1263:
1264: /* Stored [vcn : next_svcn) from [vcn : end). */
1265: next_svcn = le64_to_cpu(attr->nres.evcn) + 1;
1266:
1267: if (end <= evcn1) {
1268: if (next_svcn == evcn1) {
1269: /* Normal way. Update attribute and exit. */
1270: goto ok;
1271: }
1272: /* Add new segment [next_svcn : evcn1 - next_svcn). */
1273: if (!ni->attr_list.size) {
1274: err = ni_create_attr_list(ni);
1275: if (err)
1276: goto undo1;
1277: /* Layout of records is changed. */
1278: le_b = NULL;
1279: attr_b = ni_find_attr(ni, NULL, &le_b, ATTR_DATA,
1280: ni->file.ads.name,
1281: ni->file.ads.len, NULL, &mi_b);
1282: if (!attr_b) {
1283: err = -ENOENT;
1284: goto out;
1285: }
1286:
1287: attr = attr_b;
1288: le = le_b;
1289: mi = mi_b;
1290: goto repack;
1291: }
1292: }
1293:
1294: /*
1295: * The code below may require additional cluster (to extend attribute list)
1296: * and / or one MFT record
1297: * It is too complex to undo operations if -ENOSPC occurs deep inside
1298: * in 'ni_insert_nonresident'.
1299: * Return in advance -ENOSPC here if there are no free cluster and no free MFT.
1300: */
1301: if (!ntfs_check_free_space(sbi, 1, 1, false)) {
1302: /* Undo step 1. */
1303: err = -ENOSPC;
1304: goto undo1;
1305: }
1306:
1307: step = 2;
1308: svcn = evcn1;
1309:
1310: /* Estimate next attribute. */
1311: attr = ni_find_attr(ni, attr, &le, ATTR_DATA, ni->file.ads.name,
1312: ni->file.ads.len, &svcn, &mi);
1313:
1314: if (!attr) {
1315: /* Insert new attribute segment. */
1316: goto ins_ext;
1317: }
1318:
1319: /* Try to update existed attribute segment. */
1320: alloc = bytes_to_cluster(sbi, le64_to_cpu(attr_b->nres.alloc_size));
1321: evcn = le64_to_cpu(attr->nres.evcn);
1322:
1323: if (end < next_svcn)
1324: end = next_svcn;
1325: while (end > evcn) {
1326: /* Remove segment [svcn : evcn). */
1327: mi_remove_attr(NULL, mi, attr);
1328:
1329: if (!al_remove_le(ni, le)) {
1330: err = -EINVAL;
1331: goto out;
1332: }
1333:
1334: if (evcn + 1 >= alloc) {
1335: /* Last attribute segment. */
1336: evcn1 = evcn + 1;
1337: goto ins_ext;
1338: }
1339:
1340: if (ni_load_mi(ni, le, &mi)) {
1341: attr = NULL;
1342: goto out;
1343: }
1344:
1345: attr = mi_find_attr(ni, mi, NULL, ATTR_DATA, ni->file.ads.name,
1346: ni->file.ads.len, &le->id);
1347: if (!attr) {
1348: err = -EINVAL;
1349: goto out;
1350: }
1351: svcn = le64_to_cpu(attr->nres.svcn);
1352: evcn = le64_to_cpu(attr->nres.evcn);
1353: }
1354:
1355: if (end < svcn)
1356: end = svcn;
1357:
1358: err = attr_load_runs(attr, ni, run, &end);
1359: if (err)
1360: goto out;
1361:
1362: evcn1 = evcn + 1;
1363: attr->nres.svcn = cpu_to_le64(next_svcn);
1364: err = mi_pack_runs(mi, attr, run, evcn1 - next_svcn);
1365: if (err)
1366: goto out;
1367:
1368: le->vcn = cpu_to_le64(next_svcn);
1369: ni->attr_list.dirty = true;
1370: mi->dirty = true;
1371: next_svcn = le64_to_cpu(attr->nres.evcn) + 1;
1372:
1373: ins_ext:
1374: if (evcn1 > next_svcn) {
1375: err = ni_insert_nonresident(ni, ATTR_DATA, ni->file.ads.name,
1376: ni->file.ads.len, run, next_svcn,
1377: evcn1 - next_svcn, attr_b->flags,
1378: &attr, &mi, NULL);
1379: if (err)
1380: goto out;
1381: }
1382: ok:
1383: run_truncate_around(run, vcn);
1384: out:
1385: if (err && step > 1) {
1386: /* Too complex to restore. */
1387: _ntfs_bad_inode(&ni->vfs_inode);
1388: }
1389:
1390: return err;
1391:
1392: undo1:
1393: /* Undo step1. */
1394: attr_b->nres.total_size = cpu_to_le64(total_size0);
1395: inode_set_bytes(&ni->vfs_inode, total_size0);
1396:
1397: if (run_deallocate_ex(sbi, run, vcn, *len, NULL, false, run_da) ||
1398: !run_add_entry(run, vcn, SPARSE_LCN, *len, false) ||
1399: mi_pack_runs(mi, attr, run, max(end, evcn1) - svcn)) {
1400: _ntfs_bad_inode(&ni->vfs_inode);
1401: }
1402: goto out;
1403: }
SourceFile:fs/ntfs3/attrib.c]
|
| 30/2 |
2026/09/17 10:40 |
llm |
debugger |
0m
Model:
Tokens:
input: 34883
output: 24
thoughts: 888
Thoughts: **Analyzing a Potential Race Condition in NTFS Resident Attribute Handling**
Okay, let's break this down. My initial thought process is centered around a discrepancy I'm seeing with resident attributes in the NTFS file system. Specifically, in the `iomap_read_inline_data` function, a warning is triggered if the size of the data being read (`i_size_read(iter->inode)`) exceeds the expected resident data size (`iomap->length`). The flow goes like this: `attr_data_get_block_locked` determines if an attribute is resident and, if so, sets `iomap->length` (ultimately derived from `data_size`) in `ntfs_iomap_begin`. Then, `iomap_read_inline_data` is called.
The problem is, the reproducer triggers this warning via `ftruncate(fd, 20)` followed by `ftruncate(fd, 5)`. The file's resident, meaning its data is stored directly within the attribute itself. The `ftruncate` calls are key here. I initially thought it was a concurrency issue where `i_size` was altered under the read call, as `ftruncate` takes `inode_lock`. But `read` doesn't take the `inode_lock`. It takes the `folio_lock` and uses `i_size_read`, so there *is* a race. The `inode_lock` protects the `i_size`, but `i_size` is read without the lock by `read` or functions in its stack!
So, the critical question is: how can `i_size_read(iter->inode)` grow to be *larger* than the resident `data_size`? And the answer is the concurrency. The read occurs while `ftruncate` is running, changing the value of `i_size` because it's not protected by the `inode_lock`!
The next step is to examine `ntfs_set_size` or `ntfs_truncate` to better understand the ordering of operations. Specifically, how is `data_size` updated in the resident attribute, and is it updated before or after `i_size` is changed? That will tell me if the `ftruncate` function can alter the `i_size` during a read.
|
| 31/2 |
2026/09/17 10:40 |
tool |
codesearch-definition-source |
0m
Args:
Results: map[SourceCode: 883: int ntfs_set_size(struct inode *inode, u64 new_size)
884: {
885: struct super_block *sb = inode->i_sb;
886: struct ntfs_sb_info *sbi = sb->s_fs_info;
887: struct ntfs_inode *ni = ntfs_i(inode);
888: int err;
889:
890: /* Check for maximum file size. */
891: if (is_sparsed(ni) || is_compressed(ni)) {
892: if (new_size > sbi->maxbytes_sparse) {
893: return -EFBIG;
894: }
895: } else if (new_size > sbi->maxbytes) {
896: return -EFBIG;
897: }
898:
899: /* Mark rw ntfs as dirty. It will be cleared at umount. */
900: ntfs_set_state(sbi, NTFS_DIRTY_DIRTY);
901:
902: ni_lock(ni);
903: down_write(&ni->file.run_lock);
904: if (new_size < ni->i_valid)
905: ni->i_valid = new_size;
906:
907: /* last 'true' means keep preallocated. */
908: err = attr_set_size(ni, ATTR_DATA, ni->file.ads.name, ni->file.ads.len,
909: &ni->file.run, new_size, &ni->i_valid, true);
910:
911: up_write(&ni->file.run_lock);
912: ni_unlock(ni);
913:
914: return err;
915: }
SourceFile:fs/ntfs3/inode.c]
|
| 32/2 |
2026/09/17 10:40 |
llm |
debugger |
0m
Model:
Tokens:
input: 36867
output: 23
thoughts: 11
Thoughts: Okay, here's my interpretation of "Let's see `attr_set_size`", summarized as though it's my own thought process, assuming I'm an expert:
**Investigating `attr_set_size`**
Alright, the code's pointing me at `attr_set_size`. Immediately, my brain kicks into gear. My initial thought is probably, "Okay, `attr_set_size`... that's dealing with the size, the *capacity*, of a set of attributes, right?" I'm mentally picturing the underlying data structure β likely a bitset or a more complex hash table internally, depending on the implementation β and its associated storage requirements.
My next step depends on the *context*. Am I looking at an allocation issue? A performance bottleneck? Or perhaps debugging a memory leak? If it's allocation, I'm thinking, "Is this the *initial* size, or is it the *current* used size, or something else entirely?" If it's performance, I'm asking myself, "Is the size optimal for the expected usage pattern? Are we wasting memory, or are we experiencing frequent re-allocations?"
I need more context. I'm going to quickly reference the documentation, if I have it, to see what this function *actually* does. Specifically, I'll need to know:
* Does this reflect allocated memory (as opposed to used/occupied)?
* Is this exposed to the user, or an internal measure for the library?
* How is this value used elsewhere in the system?
* What is its *type*? Integers? Some bespoke attribute size?
Then, the true thinking begins. It is likely I will be doing some of the following:
* I will have to cross-reference with the other attribute functions.
* I will be looking at this with a critical eye, questioning any assumptions made in the code.
* I will have to check all the possible ways this is called in the code.
* I will consider if there are any race conditions for a multithreaded environment.
Ultimately, my goal is to understand how `attr_set_size` fits into the broader picture and whether it's behaving as expected or, more importantly, *why* it's not. It's a key piece of information, and I need to extract its meaning within this system.
|
| 33/2 |
2026/09/17 10:40 |
tool |
codesearch-definition-source |
0m
Args:
Results: map[SourceCode: 473: static inline int attr_set_size(struct ntfs_inode *ni, enum ATTR_TYPE type,
474: const __le16 *name, u8 name_len,
475: struct runs_tree *run, u64 new_size,
476: const u64 *new_valid, bool keep_prealloc)
477: {
478: return attr_set_size_ex(ni, type, name, name_len, run, new_size,
479: new_valid, keep_prealloc, NULL, false);
480: }
SourceFile:fs/ntfs3/ntfs_fs.h]
|
| 34/2 |
2026/09/17 10:40 |
llm |
debugger |
0m
Model:
Tokens:
input: 37613
output: 25
thoughts: 13
Thoughts: Okay, let's break this down. Here's my perspective on this specific point, tailored for someone who knows their stuff:
**Diving into `attr_set_size_ex`**
Alright, so the focus is on `attr_set_size_ex`. I immediately start thinking about its purpose. From the name itself, I can infer this is probably related to determining the size or capacity of a specific attribute set, and the "ex" suffix probably suggests it's an extended or more detailed version compared to a standard size check. My mind races to the potential implications: Is this a critical piece of memory management? Perhaps it helps optimize storage allocation within a complex data structure? Is there a subtle difference in the information this provides compared to a more basic function that could impact performance if used carelessly? I'm already formulating questions in my head: What specific attributes does this size function consider? Are there any corner cases or potential gotchas that I should immediately consider? And is this particular function going to require careful handling of alignment or data padding to ensure optimal performance? Time to dig into the actual implementation.
|
| 35/2 |
2026/09/17 10:41 |
tool |
codesearch-definition-source |
0m
Args: map[Name:attr_set_size_ex]
Results: map[SourceCode: 421: /*
422: * attr_set_size_ex - Change the size of attribute.
423: *
424: * Extend:
425: * - Sparse/compressed: No allocated clusters.
426: * - Normal: Append allocated and preallocated new clusters.
427: * Shrink:
428: * - No deallocate if @keep_prealloc is set.
429: */
430: int attr_set_size_ex(struct ntfs_inode *ni, enum ATTR_TYPE type,
431: const __le16 *name, u8 name_len, struct runs_tree *run,
432: u64 new_size, const u64 *new_valid, bool keep_prealloc,
433: struct ATTRIB **ret, bool no_da)
434: {
435: int err = 0;
436: struct ntfs_inode *nb = ni->base;
437: struct ntfs_sb_info *sbi = ni->mi.sbi;
438: u8 cluster_bits = sbi->cluster_bits;
439: bool is_mft = ni->mi.rno == MFT_REC_MFT && type == ATTR_DATA &&
440: !name_len;
441: u64 old_valid, old_size, old_alloc, new_alloc_tmp;
442: u64 new_alloc = 0;
443: struct ATTRIB *attr = NULL, *attr_b;
444: struct ATTR_LIST_ENTRY *le, *le_b;
445: struct mft_inode *mi, *mi_b;
446: CLST alen, vcn, lcn, new_alen, old_alen, svcn, evcn;
447: CLST next_svcn, pre_alloc = -1, done = 0;
448: bool is_ext = false, is_bad = false;
449: bool dirty = false;
450: struct runs_tree *run_da = run == &ni->file.run ? &ni->file.run_da :
451: NULL;
452: bool da = !is_mft && sbi->options->delalloc && run_da && !no_da;
453: u32 align;
454: struct MFT_REC *rec;
455:
456: again:
457: alen = 0;
458: le_b = NULL;
459: attr_b = ni_find_attr(ni, NULL, &le_b, type, name, name_len, NULL,
460: &mi_b);
461: if (!attr_b) {
462: err = -ENOENT;
463: goto bad_inode;
464: }
465:
466: if (!attr_b->non_res) {
467: err = attr_set_size_res(ni, attr_b, le_b, mi_b, new_size, run,
468: &attr_b);
469: if (err)
470: return err;
471:
472: /* Return if file is still resident. */
473: if (!attr_b->non_res) {
474: dirty = true;
475: goto ok1;
476: }
477:
478: /* Layout of records may be changed, so do a full search. */
479: goto again;
480: }
481:
482: is_ext = is_attr_ext(attr_b);
483: align = sbi->cluster_size;
484: if (is_ext) {
485: align <<= attr_b->nres.c_unit;
486: keep_prealloc = false;
487: da = false;
488: }
489:
490: old_valid = le64_to_cpu(attr_b->nres.valid_size);
491: old_size = le64_to_cpu(attr_b->nres.data_size);
492: old_alloc = le64_to_cpu(attr_b->nres.alloc_size);
493:
494: again_1:
495: old_alen = old_alloc >> cluster_bits;
496:
497: new_alloc = (new_size + align - 1) & ~(u64)(align - 1);
498: new_alen = new_alloc >> cluster_bits;
499:
500: if (keep_prealloc && new_size < old_size) {
501: attr_b->nres.data_size = cpu_to_le64(new_size);
502: mi_b->dirty = dirty = true;
503: goto ok;
504: }
505:
506: if (da &&
507: (vcn = old_alen + run_len(&ni->file.run_da), new_alen > vcn)) {
508: /* Resize up normal file. Delay new clusters allocation. */
509: alen = new_alen - vcn;
510:
511: if (ntfs_check_free_space(sbi, alen, 0, true)) {
512: if (!run_add_entry(&ni->file.run_da, vcn, SPARSE_LCN,
513: alen, false)) {
514: err = -ENOMEM;
515: goto out;
516: }
517:
518: ntfs_add_da(sbi, alen);
519: goto ok1;
520: }
521: }
522:
523: if (!keep_prealloc && run_da && run_da->count &&
524: (vcn = run_get_max_vcn(run_da), new_alen < vcn)) {
525: /* Shrink delayed clusters. */
526:
527: /* Try to remove fragment from delay allocated run. */
528: if (!run_remove_range(run_da, new_alen, vcn - new_alen,
529: &alen)) {
530: err = -ENOMEM;
531: goto out;
532: }
533:
534: ntfs_sub_da(sbi, alen);
535: }
536:
537: vcn = old_alen - 1;
538:
539: svcn = le64_to_cpu(attr_b->nres.svcn);
540: evcn = le64_to_cpu(attr_b->nres.evcn);
541:
542: if (svcn <= vcn && vcn <= evcn) {
543: attr = attr_b;
544: le = le_b;
545: mi = mi_b;
546: } else if (!le_b) {
547: err = -EINVAL;
548: goto bad_inode;
549: } else {
550: le = le_b;
551: attr = ni_find_attr(ni, attr_b, &le, type, name, name_len, &vcn,
552: &mi);
553: if (!attr) {
554: err = -EINVAL;
555: goto bad_inode;
556: }
557:
558: next_le_1:
559: svcn = le64_to_cpu(attr->nres.svcn);
560: evcn = le64_to_cpu(attr->nres.evcn);
561: }
562: /*
563: * Here we have:
564: * attr,mi,le - last attribute segment (containing 'vcn').
565: * attr_b,mi_b,le_b - base (primary) attribute segment.
566: */
567: next_le:
568: rec = mi->mrec;
569: err = attr_load_runs(attr, ni, run, NULL);
570: if (err)
571: goto out;
572:
573: if (new_size > old_size) {
574: CLST to_allocate;
575: size_t free;
576:
577: if (new_alloc <= old_alloc) {
578: attr_b->nres.data_size = cpu_to_le64(new_size);
579: mi_b->dirty = dirty = true;
580: goto ok;
581: }
582:
583: /*
584: * Add clusters. In simple case we have to:
585: * - allocate space (vcn, lcn, len)
586: * - update packed run in 'mi'
587: * - update attr->nres.evcn
588: * - update attr_b->nres.data_size/attr_b->nres.alloc_size
589: */
590: to_allocate = new_alen - old_alen;
591: add_alloc_in_same_attr_seg:
592: lcn = 0;
593: if (is_mft) {
594: /* MFT allocates clusters from MFT zone. */
595: pre_alloc = 0;
596: } else if (is_ext) {
597: /* No preallocate for sparse/compress. */
598: pre_alloc = 0;
599: } else if (pre_alloc == -1) {
600: pre_alloc = 0;
601: if (type == ATTR_DATA && !name_len &&
602: sbi->options->prealloc) {
603: pre_alloc = bytes_to_cluster(
604: sbi, get_pre_allocated(
605: new_size)) -
606: new_alen;
607: }
608:
609: /* Get the last LCN to allocate from. */
610: if (old_alen &&
611: !run_lookup_entry(run, vcn, &lcn, NULL, NULL)) {
612: lcn = SPARSE_LCN;
613: }
614:
615: if (lcn == SPARSE_LCN)
616: lcn = 0;
617: else if (lcn)
618: lcn += 1;
619:
620: free = wnd_zeroes(&sbi->used.bitmap);
621: if (to_allocate > free) {
622: err = -ENOSPC;
623: goto out;
624: }
625:
626: if (pre_alloc && to_allocate + pre_alloc > free)
627: pre_alloc = 0;
628: }
629:
630: vcn = old_alen;
631:
632: if (is_ext) {
633: if (!run_add_entry(run, vcn, SPARSE_LCN, to_allocate,
634: false)) {
635: err = -ENOMEM;
636: goto out;
637: }
638: alen = to_allocate;
639: } else {
640: /* ~3 bytes per fragment. */
641: err = attr_allocate_clusters(
642: sbi, run, run_da, vcn, lcn, to_allocate,
643: &pre_alloc,
644: is_mft ? ALLOCATE_MFT : ALLOCATE_DEF, &alen,
645: is_mft ? 0 :
646: (sbi->record_size -
647: le32_to_cpu(rec->used) + 8) /
648: 3 +
649: 1,
650: NULL, NULL);
651: if (err)
652: goto out;
653: }
654:
655: done += alen;
656: vcn += alen;
657: if (to_allocate > alen)
658: to_allocate -= alen;
659: else
660: to_allocate = 0;
661:
662: pack_runs:
663: err = mi_pack_runs(mi, attr, run, vcn - svcn);
664: if (err)
665: goto undo_1;
666:
667: next_svcn = le64_to_cpu(attr->nres.evcn) + 1;
668: new_alloc_tmp = (u64)next_svcn << cluster_bits;
669: attr_b->nres.alloc_size = cpu_to_le64(new_alloc_tmp);
670: mi_b->dirty = dirty = true;
671:
672: if (next_svcn >= vcn && !to_allocate) {
673: /* Normal way. Update attribute and exit. */
674: attr_b->nres.data_size = cpu_to_le64(new_size);
675: goto ok;
676: }
677:
678: /* At least two MFT to avoid recursive loop. */
679: if (is_mft && next_svcn == vcn &&
680: ((u64)done << sbi->cluster_bits) >= 2 * sbi->record_size) {
681: new_size = new_alloc_tmp;
682: attr_b->nres.data_size = attr_b->nres.alloc_size;
683: goto ok;
684: }
685:
686: if (le32_to_cpu(rec->used) < sbi->record_size) {
687: old_alen = next_svcn;
688: evcn = old_alen - 1;
689: goto add_alloc_in_same_attr_seg;
690: }
691:
692: attr_b->nres.data_size = attr_b->nres.alloc_size;
693: if (new_alloc_tmp < old_valid)
694: attr_b->nres.valid_size = attr_b->nres.data_size;
695:
696: if (type == ATTR_LIST) {
697: err = ni_expand_list(ni);
698: if (err)
699: goto undo_2;
700: if (next_svcn < vcn)
701: goto pack_runs;
702:
703: /* Layout of records is changed. */
704: goto again;
705: }
706:
707: if (!nb->attr_list.size) {
708: err = ni_create_attr_list(nb);
709: /* In case of error layout of records is not changed. */
710: if (err)
711: goto undo_2;
712: /* Layout of records is changed. */
713: }
714:
715: if (next_svcn >= vcn) {
716: /* This is MFT data, repeat. */
717: goto again;
718: }
719:
720: /* Insert new attribute segment. */
721: err = ni_insert_nonresident(ni, type, name, name_len, run,
722: next_svcn, vcn - next_svcn,
723: attr_b->flags, &attr, &mi, NULL);
724:
725: /*
726: * Layout of records maybe changed.
727: * Find base attribute to update.
728: */
729: le_b = NULL;
730: attr_b = ni_find_attr(ni, NULL, &le_b, type, name, name_len,
731: NULL, &mi_b);
732: if (!attr_b) {
733: err = -EINVAL;
734: goto bad_inode;
735: }
736:
737: if (err) {
738: /* ni_insert_nonresident failed. */
739: attr = NULL;
740: goto undo_2;
741: }
742:
743: /* keep runs for $MFT::$ATTR_DATA and $MFT::$ATTR_BITMAP. */
744: if (ni->mi.rno != MFT_REC_MFT)
745: run_truncate_head(run, evcn + 1);
746:
747: svcn = le64_to_cpu(attr->nres.svcn);
748: evcn = le64_to_cpu(attr->nres.evcn);
749:
750: /*
751: * Attribute is in consistency state.
752: * Save this point to restore to if next steps fail.
753: */
754: old_valid = old_size = old_alloc = (u64)vcn << cluster_bits;
755: attr_b->nres.valid_size = attr_b->nres.data_size =
756: attr_b->nres.alloc_size = cpu_to_le64(old_size);
757: mi_b->dirty = dirty = true;
758: goto again_1;
759: }
760:
761: if (new_size != old_size ||
762: (new_alloc != old_alloc && !keep_prealloc)) {
763: /*
764: * Truncate clusters. In simple case we have to:
765: * - update packed run in 'mi'
766: * - update attr->nres.evcn
767: * - update attr_b->nres.data_size/attr_b->nres.alloc_size
768: * - mark and trim clusters as free (vcn, lcn, len)
769: */
770: CLST dlen = 0;
771:
772: vcn = max(svcn, new_alen);
773: new_alloc_tmp = (u64)vcn << cluster_bits;
774:
775: if (vcn > svcn) {
776: err = mi_pack_runs(mi, attr, run, vcn - svcn);
777: if (err)
778: goto out;
779: } else if (le && le->vcn) {
780: u16 le_sz = le16_to_cpu(le->size);
781:
782: /*
783: * NOTE: List entries for one attribute are always
784: * the same size. We deal with last entry (vcn==0)
785: * and it is not first in entries array
786: * (list entry for std attribute always first).
787: * So it is safe to step back.
788: */
789: mi_remove_attr(NULL, mi, attr);
790:
791: if (!al_remove_le(ni, le)) {
792: err = -EINVAL;
793: goto bad_inode;
794: }
795:
796: le = (struct ATTR_LIST_ENTRY *)((u8 *)le - le_sz);
797: } else {
798: attr->nres.evcn = cpu_to_le64((u64)vcn - 1);
799: mi->dirty = true;
800: }
801:
802: attr_b->nres.alloc_size = cpu_to_le64(new_alloc_tmp);
803:
804: if (vcn == new_alen) {
805: attr_b->nres.data_size = cpu_to_le64(new_size);
806: if (new_size < old_valid)
807: attr_b->nres.valid_size =
808: attr_b->nres.data_size;
809: } else {
810: if (new_alloc_tmp <=
811: le64_to_cpu(attr_b->nres.data_size))
812: attr_b->nres.data_size =
813: attr_b->nres.alloc_size;
814: if (new_alloc_tmp <
815: le64_to_cpu(attr_b->nres.valid_size))
816: attr_b->nres.valid_size =
817: attr_b->nres.alloc_size;
818: }
819: mi_b->dirty = dirty = true;
820:
821: err = run_deallocate_ex(sbi, run, vcn, evcn - vcn + 1, &dlen,
822: true, run_da);
823: if (err)
824: goto out;
825:
826: if (is_ext) {
827: /* dlen - really deallocated clusters. */
828: le64_sub_cpu(&attr_b->nres.total_size,
829: (u64)dlen << cluster_bits);
830: }
831:
832: run_truncate(run, vcn);
833:
834: if (new_alloc_tmp <= new_alloc)
835: goto ok;
836:
837: old_size = new_alloc_tmp;
838: vcn = svcn - 1;
839:
840: if (le == le_b) {
841: attr = attr_b;
842: mi = mi_b;
843: evcn = svcn - 1;
844: svcn = 0;
845: goto next_le;
846: }
847:
848: if (le->type != type || le->name_len != name_len ||
849: memcmp(le_name(le), name, name_len * sizeof(short))) {
850: err = -EINVAL;
851: goto bad_inode;
852: }
853:
854: err = ni_load_mi(ni, le, &mi);
855: if (err)
856: goto out;
857:
858: attr = mi_find_attr(ni, mi, NULL, type, name, name_len,
859: &le->id);
860: if (!attr) {
861: err = -EINVAL;
862: goto bad_inode;
863: }
864: goto next_le_1;
865: }
866:
867: ok:
868: if (new_valid) {
869: __le64 valid = cpu_to_le64(min(*new_valid, new_size));
870:
871: if (attr_b->nres.valid_size != valid) {
872: attr_b->nres.valid_size = valid;
873: mi_b->dirty = true;
874: }
875: }
876:
877: ok1:
878: if (ret)
879: *ret = attr_b;
880:
881: if ((type == ATTR_DATA || (type == ATTR_ALLOC && name == I30_NAME))) {
882: /* Update inode_set_bytes. */
883: if (attr_b->non_res &&
884: inode_get_bytes(&ni->vfs_inode) != new_alloc) {
885: inode_set_bytes(&ni->vfs_inode, new_alloc);
886: dirty = true;
887: }
888:
889: i_size_write(&ni->vfs_inode, new_size);
890:
891: /* Don't forget to update duplicate information in parent. */
892: if (dirty) {
893: ni->ni_flags |= NI_FLAG_UPDATE_PARENT;
894: mark_inode_dirty(&ni->vfs_inode);
895: }
896: }
897:
898: return 0;
899:
900: undo_2:
901: vcn -= alen;
902: attr_b->nres.data_size = cpu_to_le64(old_size);
903: attr_b->nres.valid_size = cpu_to_le64(old_valid);
904: attr_b->nres.alloc_size = cpu_to_le64(old_alloc);
905:
906: /* Restore 'attr' and 'mi'. */
907: if (attr)
908: goto restore_run;
909:
910: if (le64_to_cpu(attr_b->nres.svcn) <= svcn &&
911: svcn <= le64_to_cpu(attr_b->nres.evcn)) {
912: attr = attr_b;
913: le = le_b;
914: mi = mi_b;
915: } else if (!le_b) {
916: err = -EINVAL;
917: goto bad_inode;
918: } else {
919: le = le_b;
920: attr = ni_find_attr(ni, attr_b, &le, type, name, name_len,
921: &svcn, &mi);
922: if (!attr)
923: goto bad_inode;
924: }
925:
926: restore_run:
927: if (mi_pack_runs(mi, attr, run, evcn - svcn + 1))
928: is_bad = true;
929:
930: undo_1:
931: run_deallocate_ex(sbi, run, vcn, alen, NULL, false, run_da);
932:
933: run_truncate(run, vcn);
934: out:
935: if (is_bad) {
936: bad_inode:
937: _ntfs_bad_inode(&ni->vfs_inode);
938: }
939: return err;
940: }
SourceFile:fs/ntfs3/attrib.c]
|
| 36/2 |
2026/09/17 10:41 |
llm |
debugger |
0m
Model:
Tokens:
input: 45841
output: 25
thoughts: 803
Thoughts: **Analyzing Potential Race Conditions in Attribute Size Updates**
Okay, so I'm looking at this `attr_set_size_ex` function, specifically how it handles attribute size changes, particularly for resident attributes. My initial thought is the call to `attr_set_size_res` to update the resident attribute's size, followed by `i_size_write` updating the inode's size. It seems straightforward, but I need to make sure there are no race conditions.
If the size is *increased*, the attribute size will be increased by `attr_set_size_res` first, then `i_size_write` will increase `i_size`. A `read` call by another thread can't possibly have `i_size` smaller than the attribute size.
However, if the size is *decreased*, `attr_set_size_res` will decrease the attribute size *before* `i_size_write` decreases `i_size`. That's where things get interesting. If another thread calls `read` between those two calls, it'll see the *old* (larger) `i_size` but the *new* (smaller) attribute size (`iomap->length`).
This is where the vulnerability lies! The `read` call uses `i_size_read` to calculate a read size. Then there is a check: `size > iomap->length`. If the size is decreased between calls, the old `i_size` used in `read` will result in a larger size, based on the old size, compared to the smaller attribute size. Therefore, this leads to the scenario I want to investigate, where `size > iomap->length` is triggered.
It looks like the discrepancy between the updated attribute size and the `i_size` during a decrease can lead to a race condition. Now I need to dive deeper into `attr_set_size_res` to see exactly how it works, and then investigate the consequences of this discovered race.
|
| 37/2 |
2026/09/17 10:41 |
tool |
codesearch-definition-source |
0m
Args: map[Name:attr_set_size_res]
Results: map[SourceCode: 379: /*
380: * attr_set_size_res - Helper for attr_set_size().
381: */
382: static int attr_set_size_res(struct ntfs_inode *ni, struct ATTRIB *attr,
383: struct ATTR_LIST_ENTRY *le, struct mft_inode *mi,
384: u64 new_size, struct runs_tree *run,
385: struct ATTRIB **ins_attr)
386: {
387: struct ntfs_sb_info *sbi = mi->sbi;
388: struct MFT_REC *rec = mi->mrec;
389: u32 used = le32_to_cpu(rec->used);
390: u32 asize = le32_to_cpu(attr->size);
391: u32 aoff = PtrOffset(rec, attr);
392: u32 rsize = le32_to_cpu(attr->res.data_size);
393: u32 tail = used - aoff - asize;
394: char *next = Add2Ptr(attr, asize);
395: s64 dsize = ALIGN(new_size, 8) - ALIGN(rsize, 8);
396:
397: if (dsize < 0) {
398: memmove(next + dsize, next, tail);
399: } else if (dsize > 0) {
400: if (used + dsize > sbi->max_bytes_per_attr)
401: return attr_make_nonresident(ni, attr, le, mi, new_size,
402: run, ins_attr, NULL);
403:
404: memmove(next + dsize, next, tail);
405: memset(next, 0, dsize);
406: }
407:
408: if (new_size > rsize)
409: memset(Add2Ptr(resident_data(attr), rsize), 0,
410: new_size - rsize);
411:
412: rec->used = cpu_to_le32(used + dsize);
413: attr->size = cpu_to_le32(asize + dsize);
414: attr->res.data_size = cpu_to_le32(new_size);
415: mi->dirty = true;
416: *ins_attr = attr;
417:
418: return 0;
419: }
SourceFile:fs/ntfs3/attrib.c]
|
| 38/2 |
2026/09/17 10:41 |
llm |
debugger |
0m
Model:
Tokens:
input: 47866
output: 24
thoughts: 844
Thoughts: **Analyzing a Potential Race Condition in NTFS File Size Updates**
Okay, so I'm digging into a possible concurrency issue within the NTFS file system code, specifically around file size modifications during truncation. Let's see... I've confirmed that `attr_set_size_res` directly updates `attr->res.data_size`, which is a key piece of information. This function is called within the `attr_set_size` chain, originating from `ntfs_set_size`.
Aha! `i_size_write` is called *after* `attr_set_size_res` within `attr_set_size_ex` at the `ok1:` label. This is important. If a concurrent read happens while these operations are interleaved, then there is an issue.
Now, a concurrent read would be handled through `ntfs_read_folio`, which branches off into `iomap_read_folio`, and eventually `ntfs_iomap_begin`. Inside `ntfs_iomap_begin`, the code reads `attr_b->res.data_size` by way of a call to `attr_data_get_block` and `attr_data_get_block_locked`. This `data_size` becomes the value assigned to `iomap->length`. However, `ntfs_iomap_begin` also reads `i_size_read` later in the function within `iomap_read_inline_data`.
Here's the crux: if a read thread is running between the execution of `attr_set_size_res` and `i_size_write`, it would see the *new* (smaller) `data_size`, but the *old* (larger) `i_size`. Therefore, the calculation `size = i_size - offset` will yield a value larger than `iomap->length`. Bingo! This discrepancy is what triggers the `WARN_ON_ONCE(size > iomap->length)` call.
The question then is, is there any locking to mitigate this race? The `ftruncate` system call calls `ntfs_set_size`. It seems like `ntfs_set_size` holds the `inode_lock`, which is good. Does `ntfs_read_folio` hold the `inode_lock`? No, it looks like `read` (via `filemap_read_folio` -> `ntfs_read_folio`) only holds the folio lock, but not `inode_lock`. Yes, inside `ntfs_set_size`, I see `ni_lock(ni)` which locks `ni->ni_lock`, a mutex. Does `ntfs_read_folio` take `ni_lock`? I need to check `ntfs_read_folio`.
|
| 39/2 |
2026/09/17 10:41 |
tool |
codesearch-definition-source |
0m
Args: map[Name:ntfs_read_folio]
Results: map[SourceCode: 826: static int ntfs_read_folio(struct file *file, struct folio *folio)
827: {
828: int err;
829: struct address_space *mapping = folio->mapping;
830: struct inode *inode = mapping->host;
831: struct ntfs_inode *ni = ntfs_i(inode);
832: loff_t vbo = folio_pos(folio);
833: struct iomap_read_folio_ctx ctx = {
834: .cur_folio = folio,
835: .ops = &ntfs_iomap_bio_read_ops,
836: };
837:
838: if (unlikely(is_bad_ni(ni))) {
839: folio_unlock(folio);
840: return -EIO;
841: }
842:
843: if (ni->i_valid <= vbo) {
844: folio_zero_range(folio, 0, folio_size(folio));
845: folio_mark_uptodate(folio);
846: folio_unlock(folio);
847: return 0;
848: }
849:
850: if (is_compressed(ni)) {
851: /* ni_lock is taken inside ni_read_folio_cmpr after page locks */
852: err = ni_read_folio_cmpr(ni, folio);
853: return err;
854: }
855:
856: iomap_read_folio(&ntfs_iomap_ops, &ctx, NULL);
857: return 0;
858: }
SourceFile:fs/ntfs3/inode.c]
|
| 40/2 |
2026/09/17 10:41 |
llm |
debugger |
0m
Model:
Tokens:
input: 49859
output: 23
thoughts: 1050
Thoughts: **Analyzing Potential Concurrency Issues in NTFS File Size Updates**
Okay, let's break this down. My initial thought was that `ntfs_read_folio` might have a race condition, but it doesn't take `ni_lock` directly. Then I saw that `ntfs_iomap_begin` calls `attr_data_get_block`, which *conditionally* takes `ni_lock`. Specifically, the code does a `run_lookup_entry_da` lookup. If it's a resident attribute (which is key here), that lookup *will* fail, because there are no runs. Therefore, the length will be zero, and *then* `ni_lock` is taken.
The issue arises because `ntfs_set_size`, which is called during file truncation, *also* holds `ni_lock`. So, `attr_data_get_block_locked` and `attr_set_size` are mutually exclusive due to the `ni_lock`. Good, that's reassuring.
Okay, let's step through a hypothetical sequence: if `attr_data_get_block_locked` is called, it *has* `ni_lock`. It reads `attr_b->res.data_size` while holding that lock, then it returns. After `attr_data_get_block` drops `ni_lock`, `ntfs_iomap_begin` returns and then `iomap_read_folio` calls `iomap_read_inline_data`. Importantly, `iomap_read_inline_data` reads `i_size_read`.
Now, if a truncate is occurring, it follows this sequence:
1. Thread 1 (truncate) takes `inode_lock`.
2. It calls `ntfs_setattr` which calls `ntfs_truncate` which in turn calls `ntfs_set_size`.
3. It then takes `ni_lock`.
4. Then `attr_set_size_ex` is called. It updates `attr_b->res.data_size`.
5. It calls `i_size_write(inode, new_size)`.
6. Finally, `ni_lock` is dropped.
Here's the problem I was worried about: If `i_size_write` is called *before* `ni_lock` is dropped, then a concurrent call to `attr_data_get_block_locked` (that needs `ni_lock`) might observe a partially updated state. It would see the new `data_size` but potentially a stale `i_size`. However, the order is crucial here. `attr_set_size_ex` calls `i_size_write` *before* `ntfs_set_size` drops `ni_lock`! That's it!
So, the critical insight: `attr_data_get_block_locked` *cannot* run concurrently *between* when `attr_set_size` updates the resources and when `i_size_write` updates the inode size and then when `ntfs_set_size` drops `ni_lock`. This is because `ni_lock` is held throughout.
Okay, but what if Thread 1 increases the size? If Thread 1 increases the size then `i_size` is increased. Ah, `ftruncate` can *increase* the size - which calls `truncate_setsize` which is called by `ntfs_setattr`. Everything should still be fine.
|
| 41/2 |
2026/09/17 10:42 |
tool |
codesearch-definition-source |
0m
Args:
Results: map[SourceCode: 703: /*
704: * ntfs_setattr - inode_operations::setattr
705: */
706: int ntfs_setattr(struct mnt_idmap *idmap, struct dentry *dentry,
707: struct iattr *attr)
708: {
709: struct inode *inode = d_inode(dentry);
710: struct ntfs_inode *ni = ntfs_i(inode);
711: u32 ia_valid = attr->ia_valid;
712: umode_t mode = inode->i_mode;
713: int err;
714:
715: /* Avoid any operation if inode is bad. */
716: if (unlikely(is_bad_ni(ni)))
717: return -EINVAL;
718:
719: if (unlikely(ntfs3_forced_shutdown(inode->i_sb)))
720: return -EIO;
721:
722: err = setattr_prepare(idmap, dentry, attr);
723: if (err)
724: goto out;
725:
726: if (ia_valid & ATTR_SIZE) {
727: loff_t newsize, oldsize;
728:
729: if (WARN_ON(ni->ni_flags & NI_FLAG_COMPRESSED_MASK)) {
730: /* Should never be here, see ntfs_file_open(). */
731: err = -EOPNOTSUPP;
732: goto out;
733: }
734: inode_dio_wait(inode);
735: oldsize = i_size_read(inode);
736: newsize = attr->ia_size;
737:
738: if (newsize != oldsize) {
739: truncate_setsize(inode, newsize);
740:
741: err = ntfs_set_size(inode, newsize);
742: if (err) {
743: i_size_write(inode, oldsize);
744: goto out;
745: }
746:
747: ni->std_fa |= FILE_ATTRIBUTE_ARCHIVE;
748: ni->ni_flags |= NI_FLAG_UPDATE_PARENT;
749: inode_set_mtime_to_ts(inode,
750: inode_set_ctime_current(inode));
751: }
752: }
753:
754: setattr_copy(idmap, inode, attr);
755:
756: if (!is_ni_base(ni)) {
757: ia_valid &= ~ATTR_SIZE;
758: } else if (mode != inode->i_mode) {
759: err = ntfs_acl_chmod(idmap, dentry);
760: if (err)
761: goto out;
762:
763: /* Linux 'w' -> Windows 'ro'. */
764: if (0222 & inode->i_mode)
765: ni->std_fa &= ~FILE_ATTRIBUTE_READONLY;
766: else
767: ni->std_fa |= FILE_ATTRIBUTE_READONLY;
768: }
769:
770: if (ia_valid & (ATTR_UID | ATTR_GID | ATTR_MODE))
771: ntfs_save_wsl_perm(inode, NULL);
772: mark_inode_dirty(inode);
773: out:
774: return err;
775: }
SourceFile:fs/ntfs3/file.c]
|
| 42/2 |
2026/09/17 10:42 |
llm |
debugger |
0m
Model:
Tokens:
input: 52791
output: 22
thoughts: 57
Thoughts: Okay, here's my take on those thoughts, framed as my own:
**Analyzing `truncate_setsize` and Its Timing**
Right, so I'm seeing this sequence: `truncate_setsize(inode, newsize)` *before* `ntfs_set_size(inode, newsize)`. That's interesting, and important to remember. The key here is that `truncate_setsize` appears to be responsible for modifying `i_size`. That's significant. It means it's handling the core size adjustment, *before* we potentially get into the lower-level NTFS-specific size modifications. Given this ordering, I need to understand *exactly* what `truncate_setsize` is doing to `i_size`, as this could have substantial implications for our overall file size handling strategy in the NTFS context. Time to dive into that function and trace its logic.
|
| 43/2 |
2026/09/17 10:42 |
tool |
codesearch-definition-source |
0m
Args: map[Name:truncate_setsize]
Results: map[SourceCode: 803: /**
804: * truncate_setsize - update inode and pagecache for a new file size
805: * @inode: inode
806: * @newsize: new file size
807: *
808: * truncate_setsize updates i_size and performs pagecache truncation (if
809: * necessary) to @newsize. It will be typically be called from the filesystem's
810: * setattr function when ATTR_SIZE is passed in.
811: *
812: * Must be called with a lock serializing truncates and writes (generally
813: * i_rwsem but e.g. xfs uses a different lock) and before all filesystem
814: * specific block truncation has been performed.
815: */
816: void truncate_setsize(struct inode *inode, loff_t newsize)
817: {
818: loff_t oldsize = inode->i_size;
819:
820: i_size_write(inode, newsize);
821: if (newsize > oldsize)
822: pagecache_isize_extended(inode, oldsize, newsize);
823: truncate_pagecache(inode, newsize);
824: }
SourceFile:mm/truncate.c]
|
| 44/2 |
2026/09/17 10:42 |
llm |
debugger |
0m
Model:
Tokens:
input: 53442
output: 23
thoughts: 1470
Thoughts: **The Race Condition in NTFS Inline Data Truncate**
Okay, I've got it. The `truncate_setsize` function is the key. It calls `i_size_write(inode, newsize)`, which means that the in-memory `i_size` is updated *before* `ntfs_set_size` is called. If I'm increasing the file size, say from 5 to 20, `i_size` immediately becomes 20. Then `ntfs_set_size` gets called, takes `ni_lock`, and updates `attr_b->res.data_size` (the on-disk size) to 20.
The race is this: if a concurrent `read` happens after `truncate_setsize` but before `ntfs_set_size` grabs `ni_lock`...
1. `read` goes through `ntfs_read_folio`.
2. Which goes through `iomap_read_folio`.
3. Then `ntfs_iomap_begin`.
4. `ntfs_iomap_begin` takes `ni_lock`, which is free because `ntfs_set_size` hasn't taken it yet.
5. `ntfs_iomap_begin` reads `attr_b->res.data_size`, which is still the *old* size, 5!
6. `ntfs_iomap_begin` sets `iomap->length = 5`.
7. `ntfs_iomap_begin` drops `ni_lock`.
8. `iomap_read_folio` goes to `iomap_read_inline_data`.
9. `iomap_read_inline_data` reads `i_size_read(iter->inode)`, which is now 20!
10. `size = 20 - 0 = 20`.
11. Now, the check `size > iomap->length` (20 > 5) triggers the `WARN_ON_ONCE`! That's the bug.
So, in essence, I have Thread 1: truncate to 20, and Thread 2: a concurrent read.
I had initially thought that `pagecache_isize_extended` and `truncate_pagecache` would prevent the race, but `pagecache_isize_extended` just zeroes the tail, and `truncate_pagecache` removes pages beyond the new size. But a read *can* allocate a new folio with a call to `filemap_read_folio`, and then `a_ops->read_folio`.
Let me look at `ntfs_setattr`.
I see that `truncate_setsize` updates `i_size` *before* `ntfs_set_size` updates the on-disk metadata. Is this the right order? I'd usually expect that for extending a truncate, `i_size` should be updated *after* blocks are allocated and zeroed, to prevent seeing uninitialized data.
The `truncate_setsize` documentation confirms this, it says "Must be called with a lock serializing truncates and writes (generally i_rwsem... and *before* all filesystem specific block truncation". But, for extending a truncate, `truncate_setsize` *immediately* updates `i_size`.
This means that a concurrent read *without* the `i_rwsem` lock can read the new `i_size` value and attempt to read it before on-disk blocks are allocated and data is available.
`iomap_read_inline_data` is where the error occurs:
```c
size_t size = i_size_read(iter->inode) - iomap->offset;
// ...
if (WARN_ON_ONCE(size > iomap->length)) {
```
If `i_size` is updated before the inline data is expanded, then `size` is larger than `iomap->length`, triggering the warning. Now I need to check how other filesystems, such as ext4, handle extending a truncate with inline data.
|
| 45/2 |
2026/09/17 10:42 |
tool |
codesearch-definition-source |
0m
Args:
Results: map[SourceCode:5985: /*
5986: * ext4_setattr()
5987: *
5988: * Called from notify_change.
5989: *
5990: * We want to trap VFS attempts to truncate the file as soon as
5991: * possible. In particular, we want to make sure that when the VFS
5992: * shrinks i_size, we put the inode on the orphan list and modify
5993: * i_disksize immediately, so that during the subsequent flushing of
5994: * dirty pages and freeing of disk blocks, we can guarantee that any
5995: * commit will leave the blocks being flushed in an unused state on
5996: * disk. (On recovery, the inode will get truncated and the blocks will
5997: * be freed, so we have a strong guarantee that no future commit will
5998: * leave these blocks visible to the user.)
5999: *
6000: * Another thing we have to assure is that if we are in ordered mode
6001: * and inode is still attached to the committing transaction, we must
6002: * we start writeout of all the dirty pages which are being truncated.
6003: * This way we are sure that all the data written in the previous
6004: * transaction are already on disk (truncate waits for pages under
6005: * writeback).
6006: *
6007: * Called with inode->i_rwsem down.
6008: */
6009: int ext4_setattr(struct mnt_idmap *idmap, struct dentry *dentry,
6010: struct iattr *attr)
6011: {
6012: struct inode *inode = d_inode(dentry);
6013: int error, rc = 0;
6014: int orphan = 0;
6015: const unsigned int ia_valid = attr->ia_valid;
6016: bool inc_ivers = true;
6017:
6018: error = ext4_emergency_state(inode->i_sb);
6019: if (unlikely(error))
6020: return error;
6021:
6022: if (unlikely(IS_IMMUTABLE(inode)))
6023: return -EPERM;
6024:
6025: if (unlikely(IS_APPEND(inode) &&
6026: (ia_valid & (ATTR_MODE | ATTR_UID |
6027: ATTR_GID | ATTR_TIMES_SET))))
6028: return -EPERM;
6029:
6030: error = setattr_prepare(idmap, dentry, attr);
6031: if (error)
6032: return error;
6033:
6034: error = fscrypt_prepare_setattr(dentry, attr);
6035: if (error)
6036: return error;
6037:
6038: if (is_quota_modification(idmap, inode, attr)) {
6039: error = dquot_initialize(inode);
6040: if (error)
6041: return error;
6042: }
6043:
6044: if (i_uid_needs_update(idmap, attr, inode) ||
6045: i_gid_needs_update(idmap, attr, inode)) {
6046: handle_t *handle;
6047:
6048: /* (user+group)*(old+new) structure, inode write (sb,
6049: * inode block, ? - but truncate inode update has it) */
6050: handle = ext4_journal_start(inode, EXT4_HT_QUOTA,
6051: (EXT4_MAXQUOTAS_INIT_BLOCKS(inode->i_sb) +
6052: EXT4_MAXQUOTAS_DEL_BLOCKS(inode->i_sb)) + 3);
6053: if (IS_ERR(handle)) {
6054: error = PTR_ERR(handle);
6055: goto err_out;
6056: }
6057:
6058: /* dquot_transfer() calls back ext4_get_inode_usage() which
6059: * counts xattr inode references.
6060: */
6061: down_read(&EXT4_I(inode)->xattr_sem);
6062: error = dquot_transfer(idmap, inode, attr);
6063: up_read(&EXT4_I(inode)->xattr_sem);
6064:
6065: if (error) {
6066: ext4_journal_stop(handle);
6067: return error;
6068: }
6069: /* Update corresponding info in inode so that everything is in
6070: * one transaction */
6071: i_uid_update(idmap, attr, inode);
6072: i_gid_update(idmap, attr, inode);
6073: error = ext4_mark_inode_dirty(handle, inode);
6074: ext4_journal_stop(handle);
6075: if (unlikely(error)) {
6076: return error;
6077: }
6078: }
6079:
6080: if (attr->ia_valid & ATTR_SIZE) {
6081: handle_t *handle;
6082: loff_t oldsize = inode->i_size;
6083: loff_t old_disksize;
6084: int shrink = (attr->ia_size < inode->i_size);
6085:
6086: if (!(ext4_test_inode_flag(inode, EXT4_INODE_EXTENTS))) {
6087: struct ext4_sb_info *sbi = EXT4_SB(inode->i_sb);
6088:
6089: if (attr->ia_size > sbi->s_bitmap_maxbytes) {
6090: return -EFBIG;
6091: }
6092: }
6093: if (!S_ISREG(inode->i_mode)) {
6094: return -EINVAL;
6095: }
6096:
6097: if (attr->ia_size == inode->i_size)
6098: inc_ivers = false;
6099:
6100: /*
6101: * If file has inline data but new size exceeds inline capacity,
6102: * convert to extent-based storage first to prevent inconsistent
6103: * state (inline flag set but size exceeds inline capacity).
6104: */
6105: if (ext4_has_inline_data(inode) &&
6106: attr->ia_size > EXT4_I(inode)->i_inline_size) {
6107: error = ext4_convert_inline_data(inode);
6108: if (error)
6109: goto err_out;
6110: }
6111:
6112: if (shrink) {
6113: if (ext4_should_order_data(inode)) {
6114: error = ext4_begin_ordered_truncate(inode,
6115: attr->ia_size);
6116: if (error)
6117: goto err_out;
6118: }
6119: /*
6120: * Blocks are going to be removed from the inode. Wait
6121: * for dio in flight.
6122: */
6123: inode_dio_wait(inode);
6124: }
6125:
6126: filemap_invalidate_lock(inode->i_mapping);
6127:
6128: rc = ext4_break_layouts(inode);
6129: if (rc) {
6130: filemap_invalidate_unlock(inode->i_mapping);
6131: goto err_out;
6132: }
6133:
6134: if (attr->ia_size != inode->i_size) {
6135: /* attach jbd2 jinode for EOF folio tail zeroing */
6136: if (attr->ia_size & (inode->i_sb->s_blocksize - 1) ||
6137: oldsize & (inode->i_sb->s_blocksize - 1)) {
6138: error = ext4_inode_attach_jinode(inode);
6139: if (error)
6140: goto out_mmap_sem;
6141: }
6142:
6143: /*
6144: * Update c/mtime and tail zero the EOF folio on
6145: * truncate up. ext4_truncate() handles the shrink case
6146: * below.
6147: */
6148: if (!shrink) {
6149: inode_set_mtime_to_ts(inode,
6150: inode_set_ctime_current(inode));
6151: if (oldsize & (inode->i_sb->s_blocksize - 1)) {
6152: error = ext4_block_zero_eof(inode,
6153: oldsize, LLONG_MAX);
6154: if (error)
6155: goto out_mmap_sem;
6156: }
6157: }
6158:
6159: handle = ext4_journal_start(inode, EXT4_HT_INODE, 3);
6160: if (IS_ERR(handle)) {
6161: error = PTR_ERR(handle);
6162: goto out_mmap_sem;
6163: }
6164: if (ext4_handle_valid(handle) && shrink) {
6165: error = ext4_orphan_add(handle, inode);
6166: orphan = 1;
6167: }
6168:
6169: if (shrink)
6170: ext4_fc_track_range(handle, inode,
6171: (attr->ia_size > 0 ? attr->ia_size - 1 : 0) >>
6172: inode->i_sb->s_blocksize_bits,
6173: EXT_MAX_BLOCKS - 1);
6174: else
6175: ext4_fc_track_range(
6176: handle, inode,
6177: (oldsize > 0 ? oldsize - 1 : oldsize) >>
6178: inode->i_sb->s_blocksize_bits,
6179: (attr->ia_size > 0 ? attr->ia_size - 1 : 0) >>
6180: inode->i_sb->s_blocksize_bits);
6181:
6182: down_write(&EXT4_I(inode)->i_data_sem);
6183: old_disksize = EXT4_I(inode)->i_disksize;
6184: EXT4_I(inode)->i_disksize = attr->ia_size;
6185:
6186: /*
6187: * We have to update i_size under i_data_sem together
6188: * with i_disksize to avoid races with writeback code
6189: * running ext4_wb_update_i_disksize().
6190: */
6191: if (!error)
6192: i_size_write(inode, attr->ia_size);
6193: else
6194: EXT4_I(inode)->i_disksize = old_disksize;
6195: up_write(&EXT4_I(inode)->i_data_sem);
6196: rc = ext4_mark_inode_dirty(handle, inode);
6197: if (!error)
6198: error = rc;
6199: ext4_journal_stop(handle);
6200: if (error)
6201: goto out_mmap_sem;
6202: if (!shrink) {
6203: pagecache_isize_extended(inode, oldsize,
6204: inode->i_size);
6205: } else if (ext4_should_journal_data(inode)) {
6206: ext4_wait_for_tail_page_commit(inode);
6207: }
6208: }
6209:
6210: /*
6211: * Truncate pagecache after we've waited for commit
6212: * in data=journal mode to make pages freeable.
6213: */
6214: truncate_pagecache(inode, inode->i_size);
6215: /*
6216: * Call ext4_truncate() even if i_size didn't change to
6217: * truncate possible preallocated blocks.
6218: */
6219: if (attr->ia_size <= oldsize) {
6220: rc = ext4_truncate(inode);
6221: if (rc)
6222: error = rc;
6223: }
6224: out_mmap_sem:
6225: filemap_invalidate_unlock(inode->i_mapping);
6226: }
6227:
6228: if (!error) {
6229: if (inc_ivers)
6230: inode_inc_iversion(inode);
6231: setattr_copy(idmap, inode, attr);
6232: mark_inode_dirty(inode);
6233: }
6234:
6235: /*
6236: * If the call to ext4_truncate failed to get a transaction handle at
6237: * all, we need to clean up the in-core orphan list manually.
6238: */
6239: if (orphan && inode->i_nlink)
6240: ext4_orphan_del(NULL, inode);
6241:
6242: if (!error && (ia_valid & ATTR_MODE))
6243: rc = posix_acl_chmod(idmap, dentry, inode->i_mode);
6244:
6245: err_out:
6246: if (error)
6247: ext4_std_error(inode->i_sb, error);
6248: if (!error)
6249: error = rc;
6250: return error;
6251: }
SourceFile:fs/ext4/inode.c]
|
| 46/2 |
2026/09/17 10:43 |
llm |
debugger |
0m
Model:
Tokens:
input: 59922
output: 24
thoughts: 164
Thoughts: **Ext4 File Size Updates: A Deep Dive**
Okay, so I'm thinking through how ext4 handles file size updates, specifically when the data is inline. My understanding is, if the file has inline data and the new size *exceeds* the inline capacity, the system cleverly converts to extent-based storage *before* it updates `i_size`. That's a good optimization, I see. But if it doesn't exceed the capacity, it goes a different route. It updates `i_size` under the protection of `i_data_sem` and *then* calls `pagecache_isize_extended`.
Wait a minute... I was just remembering something β ext4 doesn't actually use `truncate_setsize`, that's an important detail. It *directly* updates the `i_size` using `i_size_write(inode, attr->ia_size)`. After that, it calls both `pagecache_isize_extended` and `truncate_pagecache`. Got it. That's a key distinction I should have recalled.
And when dealing with inline data specifically, `ext4_read_folio` does *not* utilize `iomap_read_inline_data`. That's interesting, I need to understand that logic better. Let me refresh my memory and check what `ext4_read_folio` is doing in this scenario.
|
| 47/2 |
2026/09/17 10:43 |
tool |
codesearch-definition-source |
0m
Args: map[Name:ext4_read_folio]
Results: map[SourceCode: 321: int ext4_read_folio(struct file *file, struct folio *folio)
322: {
323: struct inode *inode = folio->mapping->host;
324: struct fsverity_info *vi = NULL;
325: int ret;
326:
327: trace_ext4_read_folio(inode, folio);
328:
329: if (ext4_has_inline_data(inode)) {
330: ret = ext4_readpage_inline(inode, folio);
331: if (ret != -EAGAIN)
332: return ret;
333: }
334:
335: if (folio->index < DIV_ROUND_UP(inode->i_size, PAGE_SIZE))
336: vi = fsverity_get_info(inode);
337: if (vi)
338: fsverity_readahead(vi, folio->index, folio_nr_pages(folio));
339: return ext4_mpage_readpages(inode, vi, NULL, folio);
340: }
SourceFile:fs/ext4/readpage.c]
|
| 48/2 |
2026/09/17 10:43 |
llm |
debugger |
0m
Model:
Tokens:
input: 60757
output: 25
thoughts: 26
Thoughts: Here's my take on those thoughts:
**Analyzing `ext4_readpage_inline` in the ext4 Filesystem**
Okay, so I'm thinking about how `ext4` handles reading data, and the first thing that jumps out is that it appears to leverage the `ext4_readpage_inline` function. I know this function is related to inline data, which is where the file data can be stored directly within the inode itself, particularly for smaller files. It's an optimization, obviously. My next step here, as usual, will be to dive into the implementation of `ext4_readpage_inline` to understand exactly how it works. I need to know how it's implemented, its behavior under different conditions (like fragmented inline data), how it interacts with the buffer cache, and how it handles potential errors. I'll need to dissect its interactions with the ext4 journal if journaling is enabled. I need to be sure the function is efficient and handles all corner cases correctly.
|
| 49/2 |
2026/09/17 10:43 |
tool |
codesearch-definition-source |
0m
Args: map[Name:ext4_readpage_inline]
Results: map[SourceCode: 544: int ext4_readpage_inline(struct inode *inode, struct folio *folio)
545: {
546: int ret = 0;
547:
548: down_read(&EXT4_I(inode)->xattr_sem);
549: if (!ext4_has_inline_data(inode)) {
550: up_read(&EXT4_I(inode)->xattr_sem);
551: return -EAGAIN;
552: }
553:
554: /*
555: * Current inline data can only exist in the 1st page,
556: * So for all the other pages, just set them uptodate.
557: */
558: if (!folio->index)
559: ret = ext4_read_inline_folio(inode, folio);
560: else if (!folio_test_uptodate(folio)) {
561: folio_zero_segment(folio, 0, folio_size(folio));
562: folio_mark_uptodate(folio);
563: }
564:
565: up_read(&EXT4_I(inode)->xattr_sem);
566:
567: folio_unlock(folio);
568: return ret >= 0 ? 0 : ret;
569: }
SourceFile:fs/ext4/inline.c]
|
| 50/2 |
2026/09/17 10:43 |
llm |
debugger |
0m
Model:
Tokens:
input: 61440
output: 25
thoughts: 827
Thoughts: **Race Condition in NTFS3 Inode Size Update**
Okay, so I've been digging into this potential race condition I've found in the NTFS3 driver, and it's quite a doozy. It started with looking at how `ext4_readpage_inline` synchronizes with truncate using `xattr_sem`. That made me think about `ntfs_read_folio`, and how it interacts with the `iomap` layer. Specifically, `ntfs_read_folio` calls `ntfs_iomap_begin`, and the key here is the acquisition of `ni_lock`.
Initially, `ntfs_iomap_begin` takes `ni_lock` only if `run_lookup_entry_da` fails. But then it hit me: for resident attributes, `run_lookup_entry_da` *always* fails! That means, it *always* takes `ni_lock`. That has serious implications! If it always takes the lock, then it can't run concurrently with `ntfs_set_size`, which sounds safe.
But then I had to verify my assumption. Let's look at the `ntfs_setattr` function. Here's what's happening. If the new size is different from the old, `truncate_setsize` gets called, which updates `i_size`. *Then* `ntfs_set_size` is called, which also takes `ni_lock`.
The problem? What happens if a `read` operation happens *after* `truncate_setsize` updates `i_size` but *before* `ntfs_set_size` grabs `ni_lock`?
The `read` calls `ntfs_read_folio`, which calls `iomap_read_folio` and then `ntfs_iomap_begin`. `ntfs_iomap_begin` takes `ni_lock`, but *only after* `truncate_setsize` updates `i_size`. Now, `ntfs_iomap_begin` reads `attr_b->res.data_size` and sets `iomap->length`. Importantly, `attr_b->res.data_size` is still the *old* size!
`ntfs_iomap_begin` drops `ni_lock`, and `iomap_read_folio` proceeds to call `iomap_read_inline_data`. Here's where the inconsistency really bites. `iomap_read_inline_data` reads `i_size_read(inode)`, which is now the *new* size, thanks to `truncate_setsize`. Let's say, just for illustration, the new size is 20 and the old size is 5.
So, the read is going to read `size = 20 - 0 = 20`. This calculation is done using a new size, but `iomap->length` is still the old size, 5. So `size > iomap->length`, which is bad, and triggers `WARN_ON_ONCE`. Bang!
So, the race is precisely about `truncate_setsize` updating `i_size` *before* the on-disk metadata (`attr_b->res.data_size`) is updated, even when it is done, under the lock, `ni_lock`. Since the `read` uses `i_size_read(inode)` for the copy, but uses `attr_b->res.data_size` in the calculation to read the correct number of bytes, they're inconsistent, and kaboom.
The fix seems to be that, in `ntfs_setattr`, we probably need to update `i_size` *after* updating the on-disk metadata, or, at a minimum, update it under `ni_lock`. But then, there's the whole issue of `truncate_setsize` having to be called *before* filesystem-specific block truncation for *shrinking* truncates to avoid exposing stale data. For *extending*, updating `i_size` *after* allocating blocks, or even atomically, sounds better. So, wait, what about *extending* truncate?
Let me see how XFS handles this... I should look at `xfs_setattr_size` as a reference.
|
| 51/2 |
2026/09/17 10:44 |
tool |
codesearch-definition-source |
0m
Error:
Args: map[Name:xfs_setattr_size]
Results: map[SourceCode: SourceFile:]
|
| 52/2 |
2026/09/17 10:44 |
llm |
debugger |
0m
Model:
Tokens:
input: 63247
output: 28
thoughts: 18
Thoughts: Here's my thought process, as it went down:
**XFS Investigation: Grepping for `truncate_setsize`**
Okay, so I need to understand how XFS handles setting the file size during truncation. My instinct is to zero in on the relevant code, so let's start with a `grep` for `truncate_setsize` within the `fs/xfs` directory. That's usually the first step for this kind of investigation β quickly locating the key function name or variable and seeing where it's used. Hopefully, this `grep` will turn up the function definition itself, and maybe a few places where itβs called. From there, I can start tracing through the execution flow, looking at how the size is actually modified, any potential locking issues that might arise, and how the underlying blocks are managed. Given the performance-critical nature of XFS, Iβm also going to be keeping an eye out for any optimizations or potential bottlenecks related to this operation. This grep should give me a good initial handle on the code.
|
| 53/2 |
2026/09/17 10:44 |
tool |
grepper |
0m
Args: map[Expression:truncate_setsize PathPrefix:fs/xfs]
Results: map[Output:fs/xfs/xfs_iops.c=905=xfs_vn_setattr_size(
--
fs/xfs/xfs_iops.c-1008- * drop the XFS_MMAP_EXCL lock after the extent manipulations are
fs/xfs/xfs_iops.c:1009: * complete. The truncate_setsize() call also cleans partial EOF page
fs/xfs/xfs_iops.c-1010- * PTEs on extending truncates and hence ensures sub-page block size
--
fs/xfs/xfs_iops.c-1025- */
fs/xfs/xfs_iops.c:1026: truncate_setsize(inode, newsize);
fs/xfs/xfs_iops.c-1027-
]
|
| 54/2 |
2026/09/17 10:44 |
llm |
debugger |
0m
Model:
Tokens:
input: 63736
output: 27
thoughts: 15
Thoughts: Okay, let's dive into this. Here's my take on `xfs_vn_setattr_size`:
**Examining `xfs_vn_setattr_size`**
Alright, so I'm looking at `xfs_vn_setattr_size`. My initial thought is, this is a core XFS function β likely a low-level, critical piece. The name tells me we're dealing with setting the size attribute, specifically within the virtual namespace (vn) layer of XFS. My expert intuition tells me this touches file metadata, probably involving i-nodes. I'm assuming it interacts directly with the on-disk structures and the in-memory representation. I need to understand the implications on data allocation, extent management, and potential fragmentation. I'm already anticipating considerations around journaling and concurrency, particularly if we're dealing with a size change that necessitates a write to the metadata. I'll need to look closely at error handling β what happens if the operation fails mid-way? What are the consistency guarantees provided? And, of course, I'll pay attention to any locking mechanisms utilized to protect against race conditions. I need to consider all the ways it interacts with other functions and system components in the file system.
|
| 55/2 |
2026/09/17 10:44 |
tool |
codesearch-definition-source |
0m
Args: map[Name:xfs_vn_setattr_size]
Results: map[SourceCode: 901: /*
902: * Truncate file. Must have write permission and not be a directory.
903: */
904: int
905: xfs_vn_setattr_size(
906: struct mnt_idmap *idmap,
907: struct dentry *dentry,
908: struct iattr *iattr)
909: {
910: struct inode *inode = d_inode(dentry);
911: struct xfs_inode *ip = XFS_I(inode);
912: struct xfs_mount *mp = ip->i_mount;
913: xfs_off_t oldsize = inode->i_size;
914: xfs_off_t newsize = iattr->ia_size;
915: struct xfs_trans *tp;
916: int error;
917: uint lock_flags = 0;
918: uint resblks = 0;
919: bool did_zeroing = false;
920: struct xfs_zone_alloc_ctx ac = { };
921:
922: xfs_assert_ilocked(ip, XFS_IOLOCK_EXCL | XFS_MMAPLOCK_EXCL);
923: ASSERT(S_ISREG(inode->i_mode));
924: ASSERT((iattr->ia_valid & (ATTR_UID|ATTR_GID|ATTR_ATIME|ATTR_ATIME_SET|
925: ATTR_MTIME_SET|ATTR_TIMES_SET)) == 0);
926:
927: trace_xfs_setattr(ip);
928:
929: error = xfs_vn_change_ok(idmap, dentry, iattr);
930: if (error)
931: return error;
932:
933: /*
934: * Short circuit the truncate case for zero length files.
935: */
936: if (newsize == 0 && oldsize == 0 && ip->i_df.if_nextents == 0) {
937: if (!(iattr->ia_valid & (ATTR_CTIME|ATTR_MTIME)))
938: return 0;
939:
940: /*
941: * Use the regular setattr path to update the timestamps.
942: */
943: iattr->ia_valid &= ~ATTR_SIZE;
944: return xfs_setattr_nonsize(idmap, dentry, ip, iattr);
945: }
946:
947: /*
948: * Make sure that the dquots are attached to the inode.
949: */
950: error = xfs_qm_dqattach(ip);
951: if (error)
952: return error;
953:
954: /*
955: * Wait for all direct I/O to complete.
956: */
957: inode_dio_wait(inode);
958:
959: /*
960: * Normally xfs_zoned_space_reserve is supposed to be called outside the
961: * IOLOCK. For truncate we can't do that since ->setattr is called with
962: * it already held by the VFS. So for now chicken out and try to
963: * allocate space under it.
964: *
965: * To avoid deadlocks this means we can't block waiting for space, which
966: * can lead to spurious -ENOSPC if there are no directly available
967: * blocks. We mitigate this a bit by allowing zeroing to dip into the
968: * reserved pool, but eventually the VFS calling convention needs to
969: * change.
970: */
971: if (xfs_is_zoned_inode(ip)) {
972: error = xfs_zoned_space_reserve(mp, 1,
973: XFS_ZR_NOWAIT | XFS_ZR_RESERVED, &ac);
974: if (error) {
975: if (error == -EAGAIN)
976: return -ENOSPC;
977: return error;
978: }
979: }
980:
981: /*
982: * File data changes must be complete before we start the transaction to
983: * modify the inode. This needs to be done before joining the inode to
984: * the transaction because the inode cannot be unlocked once it is a
985: * part of the transaction.
986: *
987: * Start with zeroing any data beyond EOF that we may expose on file
988: * extension, or zeroing out the rest of the block on a downward
989: * truncate.
990: */
991: if (newsize > oldsize) {
992: trace_xfs_zero_eof(ip, oldsize, newsize - oldsize);
993: error = xfs_zero_range(ip, oldsize, newsize - oldsize,
994: &ac, &did_zeroing);
995: } else {
996: error = xfs_truncate_page(ip, newsize, &ac, &did_zeroing);
997: }
998:
999: if (xfs_is_zoned_inode(ip))
1000: xfs_zoned_space_unreserve(mp, &ac);
1001:
1002: if (error)
1003: return error;
1004:
1005: /*
1006: * We've already locked out new page faults, so now we can safely remove
1007: * pages from the page cache knowing they won't get refaulted until we
1008: * drop the XFS_MMAP_EXCL lock after the extent manipulations are
1009: * complete. The truncate_setsize() call also cleans partial EOF page
1010: * PTEs on extending truncates and hence ensures sub-page block size
1011: * filesystems are correctly handled, too.
1012: *
1013: * We have to do all the page cache truncate work outside the
1014: * transaction context as the "lock" order is page lock->log space
1015: * reservation as defined by extent allocation in the writeback path.
1016: * Hence a truncate can fail with ENOMEM from xfs_trans_alloc(), but
1017: * having already truncated the in-memory version of the file (i.e. made
1018: * user visible changes). There's not much we can do about this, except
1019: * to hope that the caller sees ENOMEM and retries the truncate
1020: * operation.
1021: *
1022: * And we update in-core i_size and truncate page cache beyond newsize
1023: * before writeback the [i_disk_size, newsize] range, so we're
1024: * guaranteed not to write stale data past the new EOF on truncate down.
1025: */
1026: truncate_setsize(inode, newsize);
1027:
1028: /*
1029: * We are going to log the inode size change in this transaction so
1030: * any previous writes that are beyond the on disk EOF and the new
1031: * EOF that have not been written out need to be written here. If we
1032: * do not write the data out, we expose ourselves to the null files
1033: * problem. Note that this includes any block zeroing we did above;
1034: * otherwise those blocks may not be zeroed after a crash.
1035: */
1036: if (did_zeroing ||
1037: (newsize > ip->i_disk_size && oldsize != ip->i_disk_size)) {
1038: error = filemap_write_and_wait_range(VFS_I(ip)->i_mapping,
1039: ip->i_disk_size, newsize - 1);
1040: if (error)
1041: return error;
1042: }
1043:
1044: /*
1045: * For realtime inode with more than one block rtextsize, we need the
1046: * block reservation for bmap btree block allocations/splits that can
1047: * happen since it could split the tail written extent and convert the
1048: * right beyond EOF one to unwritten.
1049: */
1050: if (xfs_inode_has_bigrtalloc(ip))
1051: resblks = XFS_DIOSTRAT_SPACE_RES(mp, 0);
1052:
1053: error = xfs_trans_alloc(mp, &M_RES(mp)->tr_itruncate, resblks,
1054: 0, 0, &tp);
1055: if (error)
1056: return error;
1057:
1058: lock_flags |= XFS_ILOCK_EXCL;
1059: xfs_ilock(ip, XFS_ILOCK_EXCL);
1060: xfs_trans_ijoin(tp, ip, 0);
1061:
1062: /*
1063: * Only change the c/mtime if we are changing the size or we are
1064: * explicitly asked to change it. This handles the semantic difference
1065: * between truncate() and ftruncate() as implemented in the VFS.
1066: *
1067: * The regular truncate() case without ATTR_CTIME and ATTR_MTIME is a
1068: * special case where we need to update the times despite not having
1069: * these flags set. For all other operations the VFS set these flags
1070: * explicitly if it wants a timestamp update.
1071: */
1072: if (newsize != oldsize &&
1073: !(iattr->ia_valid & (ATTR_CTIME | ATTR_MTIME))) {
1074: iattr->ia_ctime = iattr->ia_mtime =
1075: current_time(inode);
1076: iattr->ia_valid |= ATTR_CTIME | ATTR_MTIME;
1077: }
1078:
1079: /*
1080: * The first thing we do is set the size to new_size permanently on
1081: * disk. This way we don't have to worry about anyone ever being able
1082: * to look at the data being freed even in the face of a crash.
1083: * What we're getting around here is the case where we free a block, it
1084: * is allocated to another file, it is written to, and then we crash.
1085: * If the new data gets written to the file but the log buffers
1086: * containing the free and reallocation don't, then we'd end up with
1087: * garbage in the blocks being freed. As long as we make the new size
1088: * permanent before actually freeing any blocks it doesn't matter if
1089: * they get written to.
1090: */
1091: ip->i_disk_size = newsize;
1092: xfs_trans_log_inode(tp, ip, XFS_ILOG_CORE);
1093:
1094: if (newsize <= oldsize) {
1095: error = xfs_itruncate_extents(&tp, ip, XFS_DATA_FORK, newsize);
1096: if (error)
1097: goto out_trans_cancel;
1098:
1099: /*
1100: * Truncated "down", so we're removing references to old data
1101: * here - if we delay flushing for a long time, we expose
1102: * ourselves unduly to the notorious NULL files problem. So,
1103: * we mark this inode and flush it when the file is closed,
1104: * and do not wait the usual (long) time for writeout.
1105: */
1106: xfs_iflags_set(ip, XFS_ITRUNCATED);
1107:
1108: /* A truncate down always removes post-EOF blocks. */
1109: xfs_inode_clear_eofblocks_tag(ip);
1110: }
1111:
1112: setattr_copy(idmap, inode, iattr);
1113: xfs_trans_log_inode(tp, ip, XFS_ILOG_CORE);
1114:
1115: XFS_STATS_INC(mp, xs_ig_attrchg);
1116:
1117: if (xfs_has_wsync(mp))
1118: xfs_trans_set_sync(tp);
1119:
1120: error = xfs_trans_commit(tp);
1121: out_unlock:
1122: if (lock_flags)
1123: xfs_iunlock(ip, lock_flags);
1124: return error;
1125:
1126: out_trans_cancel:
1127: xfs_trans_cancel(tp);
1128: goto out_unlock;
1129: }
SourceFile:fs/xfs/xfs_iops.c]
|
| 56/2 |
2026/09/17 10:44 |
llm |
debugger |
0m
Model:
Tokens:
input: 67848
output: 26
thoughts: 202
Thoughts: **Analyzing File System Concurrency: XFS vs. NTFS3**
Okay, so I'm digging into how different filesystems handle concurrent access during operations like truncation and reading. With XFS, my initial observation is that `truncate_setsize` is getting called *before* `xfs_trans_alloc` and `xfs_ilock`. That's interesting, but I need to understand the complete picture. Wait a minute... XFS has that `xfs_vn_setattr_size` function, and it's holding `XFS_IOLOCK_EXCL | XFS_MMAPLOCK_EXCL` while it's running. Then, I remember that `xfs_file_read_iter` only takes `XFS_IOLOCK_SHARED`. Bingo! It's clear that in XFS, `read` and `truncate` operations are mutually exclusive.
Now, I'm curious about how `ntfs3` does it. Let's see if their implementation has something similar. Does it also hold some lock that excludes reads during truncation? I remember `ntfs_setattr` and its involvement with VFS `notify_change`. Oh yes, it calls `inode_lock(inode)` β which maps to `i_rwsem`, if I remember correctly. So, there's the exclusive lock. The critical question now is whether that inode lock is held by `ntfs_file_read_iter` during reads. I'm going to quickly check `ntfs_file_read_iter`. Need to confirm if it grabs that same `i_rwsem` to see if the two are mutually exclusive.
|
| 57/2 |
2026/09/17 10:45 |
tool |
codesearch-definition-source |
0m
Args: map[Name:ntfs_file_read_iter]
Results: map[SourceCode: 814: /*
815: * ntfs_file_read_iter - file_operations::read_iter
816: */
817: static ssize_t ntfs_file_read_iter(struct kiocb *iocb, struct iov_iter *iter)
818: {
819: struct file *file = iocb->ki_filp;
820: struct inode *inode = file_inode(file);
821: struct ntfs_inode *ni = ntfs_i(inode);
822: size_t bytes = iov_iter_count(iter);
823: loff_t valid, i_size, vbo, end;
824: unsigned int dio_flags;
825: ssize_t ret;
826:
827: ret = check_read_restriction(inode);
828: if (ret)
829: return ret;
830:
831: if (!bytes)
832: return 0; /* skip atime */
833:
834: if (ni->file.ads.len == ARRAY_SIZE(QUERY_STREAMS) &&
835: !memcmp(ni->file.ads.name, QUERY_STREAMS, sizeof(QUERY_STREAMS))) {
836: /* Query ADS. */
837: if (unlikely(iocb->ki_flags & IOCB_DIRECT)) {
838: ntfs_inode_warn(
839: inode,
840: "direct I/O for streams is not supported");
841: return -EOPNOTSUPP;
842: }
843:
844: inode_lock_shared(inode);
845: ret = ni_query_ads(ni, &iocb->ki_pos, iter);
846: inode_unlock_shared(inode);
847: return ret;
848: }
849:
850: if (is_compressed(ni)) {
851: if (iocb->ki_flags & IOCB_DIRECT) {
852: ntfs_inode_warn(
853: inode, "direct i/o + compressed not supported");
854: return -EOPNOTSUPP;
855: }
856: /* Turn off readahead for compressed files. */
857: file->f_ra.ra_pages = 0;
858: }
859:
860: /* Fallback to buffered I/O if the inode does not support direct I/O. */
861: if (!(iocb->ki_flags & IOCB_DIRECT) ||
862: !ntfs_should_use_dio(iocb, iter)) {
863: iocb->ki_flags &= ~IOCB_DIRECT;
864: return generic_file_read_iter(iocb, iter);
865: }
866:
867: if (iocb->ki_flags & IOCB_NOWAIT) {
868: if (!inode_trylock_shared(inode))
869: return -EAGAIN;
870: } else {
871: inode_lock_shared(inode);
872: }
873:
874: vbo = iocb->ki_pos;
875: end = vbo + bytes;
876: dio_flags = 0;
877: valid = ni->i_valid;
878: i_size = inode->i_size;
879:
880: if (vbo < valid) {
881: if (valid < end) {
882: /* read cross 'valid' size. */
883: dio_flags |= IOMAP_DIO_FORCE_WAIT;
884: }
885:
886: if (ni->file.run_da.count) {
887: /* Direct I/O is not compatible with delalloc. */
888: ret = ni_allocate_da_blocks(ni);
889: if (ret)
890: goto out;
891: }
892:
893: ret = iomap_dio_rw(iocb, iter, &ntfs_iomap_ops, NULL, dio_flags,
894: NULL, 0);
895:
896: if (ret <= 0)
897: goto out;
898: end = vbo + ret;
899: if (valid < end) {
900: size_t to_zero = end - valid;
901: /* Fix iter. */
902: iov_iter_revert(iter, to_zero);
903: iov_iter_zero(to_zero, iter);
904: }
905: } else if (vbo < i_size) {
906: if (end > i_size)
907: bytes = i_size - vbo;
908: iov_iter_zero(bytes, iter);
909: iocb->ki_pos += bytes;
910: ret = bytes;
911: }
912:
913: out:
914: inode_unlock_shared(inode);
915: file_accessed(file);
916: return ret;
917: }
SourceFile:fs/ntfs3/file.c]
|
| 58/2 |
2026/09/17 10:45 |
llm |
debugger |
0m
Model:
Tokens:
input: 69996
output: 22
thoughts: 1227
Thoughts: **Analyzing a Concurrency Bug in NTFS3 Truncate and Read Operations**
Okay, so I'm digging into this NTFS3 bug and trying to understand the race condition between file truncation and buffered reads. It seems `ntfs_file_read_iter` kicks things off with `generic_file_read_iter`, which is where the concurrency concern arises. Notably, `generic_file_read_iter` *doesn't* take an `inode_lock_shared(inode)` or the `i_rwsem`, which is standard Linux VFS behavior. Instead, it leans on folio locks. This means buffered reads can happily run concurrently with a `truncate` operation, which is where the problem lies.
Now, `truncate_setsize` uses folio locks only on the folios it's actually truncating (or, for extension, perhaps the last one if partially instantiated). The current `ntfs3` implementation updates `i_size` via `truncate_setsize` *before* the resident attribute size is updated in `attr_set_size_res`. This is where the race happens. A concurrent read, seeing the *new* `i_size` but the *old* resident attribute size, triggers `iomap_read_inline_data` to complain that the size read is larger than `iomap->length`. Bingo!
The fix seems straightforward, update the resident attribute size *before* the `i_size`. But the question is how. I'm looking at how `ext4` manages this, it sets the `i_size` after allocation. The pattern there looks like this:
```c
if (!error)
i_size_write(inode, attr->ia_size);
...
if (!shrink) {
pagecache_isize_extended(inode, oldsize, inode->i_size);
}
```
And `ext4` calls `truncate_pagecache` at the end. Can I do something similar? Let's check `ntfs_setattr`.
In `ntfs_setattr`:
```c
if (newsize != oldsize) {
truncate_setsize(inode, newsize);
err = ntfs_set_size(inode, newsize);
if (err) {
i_size_write(inode, oldsize);
goto out;
}
```
If I change this to update `ntfs_set_size` first:
```c
if (newsize != oldsize) {
inode_dio_wait(inode);
oldsize = i_size_read(inode);
newsize = attr->ia_size;
err = ntfs_set_size(inode, newsize);
if (err)
goto out;
truncate_setsize(inode, newsize);
```
Wait a second, `ntfs_set_size` *already* calls `i_size_write(inode, newsize)` internally! I need to trace into `attr_set_size_ex` to confirm this.
```c
if ((type == ATTR_DATA || (type == ATTR_ALLOC && name == I30_NAME))) {
/* Update inode_set_bytes. */
if (attr_b->non_res &&
inode_get_bytes(&ni->vfs_inode) != new_alloc) {
inode_set_bytes(&ni->vfs_inode, new_alloc);
dirty = true;
}
i_size_write(&ni->vfs_inode, new_size);
```
Yup, there it is. So, why does `ntfs_setattr` call `truncate_setsize` *before* `ntfs_set_size` in the first place? Because `truncate_setsize` also updates `i_size` via `i_size_write` and also calls `truncate_pagecache`. I'd be updating the size twice!
Okay, so I'm thinking if I just move `truncate_setsize` *after* `ntfs_set_size`. But, for shrinking truncates, I have to call `truncate_setsize` (or at least `truncate_pagecache`) *before* freeing the blocks on disk, right? I'm remembering the VFS documentation: `"Must be called with a lock serializing truncates and writes (generally i_rwsem but e.g. xfs uses a different lock) and before all filesystem specific block truncation has been performed."` Because a concurrent read could read into page cache from freed blocks.
Wait, but buffered reads *don't* take
|
| 59/2 |
2026/09/17 10:45 |
tool |
codesearch-definition-source |
0m
Args:
Results: map[SourceCode: 517: int fat_setattr(struct mnt_idmap *idmap, struct dentry *dentry,
518: struct iattr *attr)
519: {
520: struct msdos_sb_info *sbi = MSDOS_SB(dentry->d_sb);
521: struct inode *inode = d_inode(dentry);
522: unsigned int ia_valid;
523: int error;
524:
525: /* Check for setting the inode time. */
526: ia_valid = attr->ia_valid;
527: if (ia_valid & TIMES_SET_FLAGS) {
528: if (fat_allow_set_time(idmap, sbi, inode))
529: attr->ia_valid &= ~TIMES_SET_FLAGS;
530: }
531:
532: error = setattr_prepare(idmap, dentry, attr);
533: attr->ia_valid = ia_valid;
534: if (error) {
535: if (sbi->options.quiet)
536: error = 0;
537: goto out;
538: }
539:
540: /*
541: * Expand the file. Since inode_setattr() updates ->i_size
542: * before calling the ->truncate(), but FAT needs to fill the
543: * hole before it. XXX: this is no longer true with new truncate
544: * sequence.
545: */
546: if (attr->ia_valid & ATTR_SIZE) {
547: inode_dio_wait(inode);
548:
549: if (attr->ia_size > inode->i_size) {
550: error = fat_cont_expand(inode, attr->ia_size);
551: if (error || attr->ia_valid == ATTR_SIZE)
552: goto out;
553: attr->ia_valid &= ~ATTR_SIZE;
554: }
555: }
556:
557: if (((attr->ia_valid & ATTR_UID) &&
558: (!uid_eq(from_vfsuid(idmap, i_user_ns(inode), attr->ia_vfsuid),
559: sbi->options.fs_uid))) ||
560: ((attr->ia_valid & ATTR_GID) &&
561: (!gid_eq(from_vfsgid(idmap, i_user_ns(inode), attr->ia_vfsgid),
562: sbi->options.fs_gid))) ||
563: ((attr->ia_valid & ATTR_MODE) &&
564: (attr->ia_mode & ~FAT_VALID_MODE)))
565: error = -EPERM;
566:
567: if (error) {
568: if (sbi->options.quiet)
569: error = 0;
570: goto out;
571: }
572:
573: /*
574: * We don't return -EPERM here. Yes, strange, but this is too
575: * old behavior.
576: */
577: if (attr->ia_valid & ATTR_MODE) {
578: if (fat_sanitize_mode(sbi, inode, &attr->ia_mode) < 0)
579: attr->ia_valid &= ~ATTR_MODE;
580: }
581:
582: if (attr->ia_valid & ATTR_SIZE) {
583: error = fat_block_truncate_page(inode, attr->ia_size);
584: if (error)
585: goto out;
586: down_write(&MSDOS_I(inode)->truncate_lock);
587: truncate_setsize(inode, attr->ia_size);
588: fat_truncate_blocks(inode, attr->ia_size);
589: up_write(&MSDOS_I(inode)->truncate_lock);
590: }
591:
592: /*
593: * setattr_copy can't truncate these appropriately, so we'll copy them
594: * ourselves. See fat_truncate_time for the c/mtime logic on fat.
595: */
596: if (attr->ia_valid & ATTR_ATIME)
597: fat_truncate_time(inode, &attr->ia_atime, FAT_UPDATE_ATIME);
598: if (attr->ia_valid & ATTR_MTIME)
599: fat_truncate_time(inode, &attr->ia_mtime, FAT_UPDATE_CMTIME);
600: attr->ia_valid &= ~(ATTR_ATIME|ATTR_CTIME|ATTR_MTIME);
601:
602: setattr_copy(idmap, inode, attr);
603: mark_inode_dirty(inode);
604: out:
605: return error;
606: }
SourceFile:fs/fat/file.c]
|
| 60/2 |
2026/09/17 10:45 |
llm |
debugger |
0m
Model:
Tokens:
input: 73754
output: 24
thoughts: 2547
Thoughts: **Analyzing File Size Updates in NTFS**
Alright, let's break this down. I'm looking at how file sizes are changed in the NTFS filesystem, specifically the implications of extending versus shrinking. I'm focusing on ensuring consistency between the in-memory inode size (`i_size`) and the on-disk metadata (`attr_b->res.data_size`).
First, I examined the FAT filesystem as a point of reference. I observed how `fat_cont_expand` is used for extension and how different functions, `truncate_setsize` and then `fat_truncate_blocks` are used for shrinking.
Then, I jumped into `ntfs_setattr`. The core of my analysis revolves around a potential race condition when extending a file. In the initial implementation, `truncate_setsize` modifies `i_size` immediately, but the disk allocation happens later in `ntfs_set_size`. The crucial point is that `ntfs_set_size` indirectly calls `attr_set_size_ex`, which then updates `i_size` as well. The question is, which order of operations is correct.
I realized that if we are extending the file ( `newsize > oldsize`), `truncate_setsize` only calls `pagecache_isize_extended`. This should update the page cache to reflect the new size. `ntfs_set_size`, will call `attr_set_size_ex`, where the `i_size` is updated. However, the update happens *before* the on-disk allocation updates (which are also part of `attr_set_size_ex`). This is where the race condition lies β a concurrent reader could observe the new `i_size` before the disk metadata reflects this change, leading to inconsistencies.
If shrinking, then `truncate_setsize` updates `i_size` and truncates the page cache. `ntfs_set_size` will call `attr_set_size_ex` and the disk blocks will be deallocated.
My proposed change involves handling the shrinking and extending separately:
* **Shrinking:** I'd handle the shrinking and extending differently. For shrinking, it's safe to call `truncate_setsize` first, because that adjusts `i_size` and truncates the page cache. Then, I let `ntfs_set_size` deallocate disk blocks. The key is in handling errors and ensuring atomicity β if `ntfs_set_size` fails during the shrink, I must revert `i_size` back to its original value, so `i_size` never misrepresents the actual on-disk state.
* **Extending:** For extension, my modification defers the explicit `i_size` update via `pagecache_isize_extended` until *after* `ntfs_set_size` completes successfully, which handles the on-disk allocation update. This seems safer, but I need to make sure `ntfs_set_size` itself doesn't depend on a pre-existing `i_size` for its internal calculations. After reviewing the code, it looks like it uses `new_size` directly and that `ntfs_set_size` is safe.
Now, if `ntfs_set_size` fails, `attr_set_size_ex` returns an error, *without* the `i_size` being updated, which is good.
I need to make sure that the `ntfs_set_size` function doesn't rely on `i_size` being up-to-date, and it uses `new_size` directly. It calls `attr_set_size` which, if it succeeds, calls `i_size_write` internally.
To be sure that my approach is safe, I reviewed the behavior of ext4. Ext4 implements file size changes differently and this is useful for comparisons. For shrinking, ext4 updates the `i_size` and `truncate_pagecache` *before* the disk truncation. For extending, it updates `i_size` and does an `ext4_truncate` (which reallocates blocks on disk). Then I also need to verify that what `ntfs3` does matches `ext4`.
In summary: I'm confident my modification addresses the potential race condition by ensuring that the on-disk metadata is updated *before* the new `i_size` is visible to concurrent readers when extending a file. The proposed approach is consistent with the behavior of ext4 when shrinking a file.
|
| 61/2 |
2026/09/17 10:46 |
tool |
codesearch-find-references |
0m
Args:
Results: map[References:[map[ReferenceKind:calls ReferencingEntityKind:function ReferencingEntityName:ntfs_fallocate SourceFile:fs/ntfs3/file.c SourceLine:655] map[ReferenceKind:calls ReferencingEntityKind:function ReferencingEntityName:ntfs_fallocate SourceFile:fs/ntfs3/file.c SourceLine:679] map[ReferenceKind:calls ReferencingEntityKind:function ReferencingEntityName:ntfs_file_write_iter SourceFile:fs/ntfs3/file.c SourceLine:1287] map[ReferenceKind:calls ReferencingEntityKind:function ReferencingEntityName:ntfs_setattr SourceFile:fs/ntfs3/file.c SourceLine:741]] TruncatedOutput:false]
|
| 62/2 |
2026/09/17 10:46 |
llm |
debugger |
0m
Model:
Tokens:
input: 77516
output: 23
thoughts: 212
Thoughts: **Analyzing NTFS Fallocate Implementation**
Okay, so I'm looking at the `ntfs_fallocate` function, and something's bugging me. Specifically, this section:
```c
if (new_size > i_size) {
err = ntfs_set_size(inode, new_size);
if (err)
goto out;
}
```
My initial thought is that it's straightforward; if the requested size (`new_size`) is larger than the current inode size (`i_size`), it calls `ntfs_set_size` to extend the file. Fine, that makes sense. Seems like a typical approach. But then I realized, it *doesn't* appear to use `truncate_setsize` here. That's unusual.
Wait a second... if `ntfs_fallocate` extends the file, it *directly* calls `ntfs_set_size`. And `ntfs_set_size` is the one responsible for updating `i_size`. That's not the normal pattern. `ntfs_fallocate` has a direct impact on the inode size without going through the usual `pagecache_isize_extended` routine. Is that correct?
Thinking back, fallocate with `KEEP_SIZE` shouldn't change the size, but if it's not set, we *do* expect `i_size` to be updated. It feels off. I need to dig deeper into the implementation of `ntfs_fallocate` to confirm my suspicion that the lack of `pagecache_isize_extended` call might be a subtle bug. I'll check it closely.
|
| 63/2 |
2026/09/17 10:46 |
tool |
codesearch-definition-source |
0m
Args:
Results: map[SourceCode: 457: /*
458: * ntfs_fallocate - file_operations::ntfs_fallocate
459: *
460: * Preallocate space for a file. This implements ntfs's fallocate file
461: * operation, which gets called from sys_fallocate system call. User
462: * space requests 'len' bytes at 'vbo'. If FALLOC_FL_KEEP_SIZE is set
463: * we just allocate clusters without zeroing them out. Otherwise we
464: * allocate and zero out clusters via an expanding truncate.
465: */
466: static long ntfs_fallocate(struct file *file, int mode, loff_t vbo, loff_t len)
467: {
468: struct inode *inode = file_inode(file);
469: struct address_space *mapping = inode->i_mapping;
470: struct super_block *sb = inode->i_sb;
471: struct ntfs_sb_info *sbi = sb->s_fs_info;
472: struct ntfs_inode *ni = ntfs_i(inode);
473: loff_t end = vbo + len;
474: loff_t vbo_down = round_down(vbo, max_t(unsigned long,
475: sbi->cluster_size, PAGE_SIZE));
476: bool is_supported_holes = is_sparsed(ni) || is_compressed(ni);
477: loff_t i_size, new_size;
478: bool map_locked;
479: int err;
480:
481: /* No support for dir. */
482: if (!S_ISREG(inode->i_mode))
483: return -EOPNOTSUPP;
484:
485: /*
486: * vfs_fallocate checks all possible combinations of mode.
487: * Do additional checks here before ntfs_set_state(dirty).
488: */
489: if (mode & FALLOC_FL_PUNCH_HOLE) {
490: if (!is_supported_holes)
491: return -EOPNOTSUPP;
492: } else if (mode & FALLOC_FL_COLLAPSE_RANGE) {
493: } else if (mode & FALLOC_FL_INSERT_RANGE) {
494: if (!is_supported_holes)
495: return -EOPNOTSUPP;
496: } else if (mode &
497: ~(FALLOC_FL_KEEP_SIZE | FALLOC_FL_PUNCH_HOLE |
498: FALLOC_FL_COLLAPSE_RANGE | FALLOC_FL_INSERT_RANGE)) {
499: ntfs_inode_warn(inode, "fallocate(0x%x) is not supported",
500: mode);
501: return -EOPNOTSUPP;
502: }
503:
504: ntfs_set_state(sbi, NTFS_DIRTY_DIRTY);
505:
506: inode_lock(inode);
507: i_size = inode->i_size;
508: new_size = max(end, i_size);
509: map_locked = false;
510:
511: if (WARN_ON(ni->ni_flags & NI_FLAG_COMPRESSED_MASK)) {
512: /* Should never be here, see ntfs_file_open. */
513: err = -EOPNOTSUPP;
514: goto out;
515: }
516:
517: if (mode & (FALLOC_FL_PUNCH_HOLE | FALLOC_FL_COLLAPSE_RANGE |
518: FALLOC_FL_INSERT_RANGE)) {
519: inode_dio_wait(inode);
520: filemap_invalidate_lock(mapping);
521: map_locked = true;
522: }
523:
524: if (mode & FALLOC_FL_PUNCH_HOLE) {
525: u32 frame_size;
526: loff_t mask, vbo_a, end_a, tmp, from;
527:
528: err = filemap_write_and_wait_range(mapping, vbo_down,
529: LLONG_MAX);
530: if (err)
531: goto out;
532:
533: truncate_pagecache(inode, vbo_down);
534:
535: ni_lock(ni);
536: err = attr_punch_hole(ni, vbo, len, &frame_size);
537: ni_unlock(ni);
538: if (!err)
539: goto ok;
540:
541: if (err != E_NTFS_NOTALIGNED)
542: goto out;
543:
544: /* Process not aligned punch. */
545: err = 0;
546: if (end > i_size)
547: end = i_size;
548: mask = frame_size - 1;
549: vbo_a = (vbo + mask) & ~mask;
550: end_a = end & ~mask;
551:
552: tmp = min(vbo_a, end);
553: from = min_t(loff_t, ni->i_valid, vbo);
554: /* Zero head of punch. */
555: if (tmp > from) {
556: err = iomap_zero_range(inode, from, tmp - from, NULL,
557: &ntfs_iomap_ops,
558: &ntfs_iomap_folio_ops, NULL);
559: if (err)
560: goto out;
561: }
562:
563: /* Aligned punch_hole. Deallocate clusters. */
564: if (end_a > vbo_a) {
565: ni_lock(ni);
566: err = attr_punch_hole(ni, vbo_a, end_a - vbo_a, NULL);
567: ni_unlock(ni);
568: if (err)
569: goto out;
570: }
571:
572: /* Zero tail of punch. */
573: if (vbo < end_a && end_a < end) {
574: err = iomap_zero_range(inode, end_a, end - end_a, NULL,
575: &ntfs_iomap_ops,
576: &ntfs_iomap_folio_ops, NULL);
577: if (err)
578: goto out;
579: }
580: } else if (mode & FALLOC_FL_COLLAPSE_RANGE) {
581: /*
582: * Write tail of the last page before removed range since
583: * it will get removed from the page cache below.
584: */
585: err = filemap_write_and_wait_range(mapping, vbo_down, vbo);
586: if (err)
587: goto out;
588:
589: /*
590: * Write data that will be shifted to preserve them
591: * when discarding page cache below.
592: */
593: err = filemap_write_and_wait_range(mapping, end, LLONG_MAX);
594: if (err)
595: goto out;
596:
597: truncate_pagecache(inode, vbo_down);
598:
599: ni_lock(ni);
600: err = attr_collapse_range(ni, vbo, len);
601: ni_unlock(ni);
602: if (err)
603: goto out;
604: } else if (mode & FALLOC_FL_INSERT_RANGE) {
605: /* Check new size. */
606: err = inode_newsize_ok(inode, new_size);
607: if (err)
608: goto out;
609:
610: /* Write out all dirty pages. */
611: err = filemap_write_and_wait_range(mapping, vbo_down,
612: LLONG_MAX);
613: if (err)
614: goto out;
615: truncate_pagecache(inode, vbo_down);
616:
617: ni_lock(ni);
618: err = attr_insert_range(ni, vbo, len);
619: ni_unlock(ni);
620: if (err)
621: goto out;
622: } else {
623: /* Check new size. */
624: u8 cluster_bits = sbi->cluster_bits;
625:
626: /* Be sure file is non resident. */
627: if (is_resident(ni)) {
628: ni_lock(ni);
629: err = attr_force_nonresident(ni);
630: ni_unlock(ni);
631: if (err)
632: goto out;
633: }
634:
635: /* generic/213: expected -ENOSPC instead of -EFBIG. */
636: if (!is_supported_holes) {
637: loff_t to_alloc = new_size - inode_get_bytes(inode);
638:
639: if (to_alloc > 0 &&
640: (to_alloc >> cluster_bits) >
641: wnd_zeroes(&sbi->used.bitmap)) {
642: err = -ENOSPC;
643: goto out;
644: }
645: }
646:
647: err = inode_newsize_ok(inode, new_size);
648: if (err)
649: goto out;
650:
651: if (new_size > i_size) {
652: /*
653: * Allocate clusters, do not change 'valid' size.
654: */
655: err = ntfs_set_size(inode, new_size);
656: if (err)
657: goto out;
658: }
659:
660: if (is_supported_holes) {
661: CLST vcn = vbo >> cluster_bits;
662: CLST cend = bytes_to_cluster(sbi, end);
663: CLST lcn, clen;
664: bool new;
665:
666: /*
667: * Allocate and zero new clusters.
668: */
669: for (; vcn < cend; vcn += clen) {
670: err = attr_data_get_block(ni, vcn, cend - vcn,
671: &lcn, &clen, &new,
672: true, NULL, false);
673: if (err)
674: goto out;
675: }
676: }
677:
678: if (mode & FALLOC_FL_KEEP_SIZE) {
679: err = ntfs_set_size(inode, i_size);
680: if (err)
681: goto out;
682: }
683: }
684:
685: ok:
686: err = file_modified(file);
687: if (err)
688: goto out;
689:
690: out:
691: if (map_locked)
692: filemap_invalidate_unlock(mapping);
693:
694: if (!err) {
695: inode_set_mtime_to_ts(inode, inode_set_ctime_current(inode));
696: mark_inode_dirty(inode);
697: }
698:
699: inode_unlock(inode);
700: return err;
701: }
SourceFile:fs/ntfs3/file.c]
|
| 64/2 |
2026/09/17 10:46 |
llm |
debugger-compressor |
0m
Model:
Reply: ### Investigation Summary
#### 1. Crash Overview & Call Stack
* **Kernel Warning**: `WARNING: fs/iomap/buffered-io.c:431 at iomap_read_inline_data+0xa7b/0xc40 fs/iomap/buffered-io.c:431`
* **Warning Condition**: `WARN_ON_ONCE(size > iomap->length)`
* **Stack Trace**:
```text
iomap_read_inline_data fs/iomap/buffered-io.c:431
iomap_read_folio_iter fs/iomap/buffered-io.c:571
iomap_read_folio fs/iomap/buffered-io.c:676
ntfs_read_folio fs/ntfs3/inode.c:856
filemap_read_folio mm/filemap.c:2520
filemap_fault mm/filemap.c:3689
__do_fault mm/memory.c:5565
...
handle_mm_fault / exc_page_fault
```
* **Repro mechanism**: Multithreaded test case bouncing file truncation (`ftruncate(fd, 20)` and `ftruncate(fd, 5)`) on an NTFS file with resident (inline) data, while concurrent threads trigger page faults via mmap reads (`val = ptr[0]` after `madvise(DONTNEED)` and `posix_fadvise(DONTNEED)`).
---
#### 2. Key Code Snippets & File Paths
* **`fs/iomap/buffered-io.c:418-435`** (`iomap_read_inline_data`):
```c
static int iomap_read_inline_data(const struct iomap_iter *iter,
struct folio *folio)
{
const struct iomap *iomap = iomap_iter_srcmap(iter);
size_t size = i_size_read(iter->inode) - iomap->offset;
size_t offset = offset_in_folio(folio, iomap->offset);
if (WARN_ON_ONCE(!iomap->inline_data))
return -EIO;
if (folio_test_uptodate(folio))
return 0;
if (WARN_ON_ONCE(size > iomap->length)) {
fserror_report_io(iter->inode, FSERR_BUFFERED_READ,
iomap->offset, size, -EIO, GFP_NOFS);
return -EIO;
}
...
```
Note: `iomap->offset` for inline data in ntfs3 is 0 (`iomap->offset = 0`), so `size = i_size_read(iter->inode)`. `iomap->length` is set to the resident attribute size `clen` (i.e. `attr_b->res.data_size`).
* **`fs/ntfs3/file.c:706-753`** (`ntfs_setattr`):
```c
int ntfs_setattr(struct mnt_idmap *idmap, struct dentry *dentry,
struct iattr *attr)
{
struct inode *inode = d_inode(dentry);
struct ntfs_inode *ni = ntfs_i(inode);
u32 ia_valid = attr->ia_valid;
...
if (ia_valid & ATTR_SIZE) {
loff_t newsize, oldsize;
...
inode_dio_wait(inode);
oldsize = i_size_read(inode);
newsize = attr->ia_size;
if (newsize != oldsize) {
truncate_setsize(inode, newsize);
err = ntfs_set_size(inode, newsize);
if (err) {
i_size_write(inode, oldsize);
goto out;
}
...
```
* **`mm/truncate.c:816-824`** (`truncate_setsize`):
```c
void truncate_setsize(struct inode *inode, loff_t newsize)
{
loff_t oldsize = inode->i_size;
i_size_write(inode, newsize);
if (newsize > oldsize)
pagecache_isize_extended(inode, oldsize, newsize);
truncate_pagecache(inode, newsize);
}
```
* **`fs/ntfs3/inode.c:883-915`** (`ntfs_set_size`):
```c
int ntfs_set_size(struct inode *inode, u64 new_size)
{
...
ni_lock(ni);
down_write(&ni->file.run_lock);
if (new_size < ni->i_valid)
ni->i_valid = new_size;
/* last 'true' means keep preallocated. */
err = attr_set_size(ni, ATTR_DATA, ni->file.ads.name, ni->file.ads.len,
&ni->file.run, new_size, &ni->i_valid, true);
up_write(&ni->file.run_lock);
ni_unlock(ni);
return err;
}
```
* **`fs/ntfs3/attrib.c:430-897`** (`attr_set_size_ex`):
```c
if (!attr_b->non_res) {
err = attr_set_size_res(ni, attr_b, le_b, mi_b, new_size, run,
&attr_b);
if (err)
return err;
/* Return if file is still resident. */
if (!attr_b->non_res) {
dirty = true;
goto ok1;
}
...
ok1:
...
if ((type == ATTR_DATA || (type == ATTR_ALLOC && name == I30_NAME))) {
...
i_size_write(&ni->vfs_inode, new_size);
...
}
```
* **`fs/ntfs3/inode.c:933-1017`** (`ntfs_iomap_begin`):
```c
err = attr_data_get_block(ni, vcn, clen_max, &lcn, &clen,
rw ? &new_clst : NULL, zero, &res, no_da);
if (err)
return err;
...
if (lcn == RESIDENT_LCN) {
if (offset >= clen) {
if (res)
__free_page(virt_to_page(res));
if (flags & IOMAP_REPORT) {
return -ENOENT;
}
return -EFAULT;
}
iomap->private = iomap->inline_data = res;
iomap->type = IOMAP_INLINE;
iomap->offset = 0;
iomap->length = clen; /* resident size in bytes. */
return 0;
}
```
* **`fs/ntfs3/attrib.c:953-985`** (`attr_data_get_block`):
For resident data, lookup in `run` fails, acquires `ni_lock(ni)`, calls `attr_data_get_block_locked()`, and releases `ni_lock(ni)`.
In `attr_data_get_block_locked()`, `attr_b->res.data_size` is copied into `*len` (which becomes `clen` and `iomap->length`) and a page is allocated and populated with `resident_data(attr_b)` into `*res` (`iomap->inline_data`).
---
#### 3. Root Cause Analysis
1. **Locking Disparity Between Read Faults and Setattr**:
* Page fault / read path: `filemap_fault()` / `filemap_read_folio()` holds the folio lock, but does **not** hold `inode->i_rwsem`.
* Truncate path: `ntfs_setattr()` runs with `inode->i_rwsem` locked.
* `ntfs_iomap_begin()` synchronizes internally via `ni_lock(ni)` when fetching block/resident attributes in `attr_data_get_block()`, but drops `ni_lock(ni)` before returning to `iomap_read_folio()`.
2. **The Race Condition Sequence**:
* **State**: File has size 5 (resident attribute `data_size = 5`, `inode->i_size = 5`).
* **Thread 1 (`ftruncate(fd, 20)`)**:
1. In `ntfs_setattr()`: Calls `truncate_setsize(inode, 20)`.
2. `truncate_setsize()` immediately updates VFS `inode->i_size` to 20 via `i_size_write(inode, 20)`.
3. *Context switch before `ntfs_set_size(inode, 20)` acquires `ni_lock(ni)` or updates `attr_b->res.data_size`.*
* **Thread 2 (page fault read on `ptr[0]`)**:
1. Calls `filemap_fault()` -> `filemap_read_folio()` -> `ntfs_read_folio()` -> `iomap_read_folio()` -> `ntfs_iomap_begin()`.
2. `ntfs_iomap_begin()` acquires `ni_lock(ni)` (since Thread 1 hasn't entered `ntfs_set_size` yet).
3. Calls `attr_data_get_block_locked()`. Resident attribute on disk / in MFT record still has `data_size = 5`.
4. Sets `iomap->offset = 0`, `iomap->length = clen = 5`, `iomap->type = IOMAP_INLINE`, and populates `iomap->inline_data` with 5 bytes.
5. Drops `ni_lock(ni)` and returns to `iomap_read_folio()`.
6. `iomap_read_folio_iter()` calls `iomap_read_inline_data()`.
7. `iomap_read_inline_data()` computes:
`size = i_size_read(iter->inode) - iomap->offset;`
Since `inode->i_size` was already updated to 20 by `truncate_setsize()`, `size = 20 - 0 = 20`.
8. `iomap_read_inline_data()` checks:
`if (WARN_ON_ONCE(size > iomap->length))` -> `20 > 5` evaluates to true!
9. Kernel triggers `WARN_ON_ONCE` and returns `-EIO`.
3. **Secondary / Reverse Race Window**:
Even within `ntfs_set_size()` / `attr_set_size_ex()`, when shrinking or expanding, `i_size_write(&ni->vfs_inode, new_size)` is also duplicated in `attr_set_size_ex` line 889, but `truncate_setsize()` in `ntfs_setattr()` already prematurely changed `inode->i_size` before underlying metadata allocation/extension occurred in `ntfs_set_size()`. Also, between `ntfs_iomap_begin()` releasing `ni_lock(ni)` and `iomap_read_inline_data()` reading `i_size_read()`, `i_size` can change concurrently if read isn't serialized with size modifications.
---
#### 4. Approaches Tried and Dead Ends
* **Examined `iomap_read_inline_data`**: Verified the exact check and warning triggered on line 431.
* **Traced `ntfs_read_folio` -> `ntfs_iomap_begin`**: Confirmed how `iomap->length` is initialized for `RESIDENT_LCN` via `attr_data_get_block()`.
* **Traced `attr_data_get_block` and `attr_data_get_block_locked`**: Verified locking (`ni_lock`) and how `data_size` is read from `attr_b->res.data_size`.
* **Traced `ntfs_set_size` and `attr_set_size_ex`**: Verified how resident attributes are resized and noticed `attr_set_size_ex` updates `i_size_write()`, which led to checking `ntfs_setattr`.
* **Investigated `ntfs_setattr`**: Discovered `truncate_setsize(inode, newsize)` is called before `ntfs_set_size(inode, newsize)`.
* **Compared with `ext4_setattr`**: Ext4 takes special care around inline data conversion (`ext4_convert_inline_data`) and updates `i_size` under `i_data_sem` together with disksize, rather than blindly calling `truncate_setsize` before filesystem block/extent changes.
---
#### 5. Lines of Investigation / Fix Considerations
* For truncate extension (`newsize > oldsize`) in `ntfs_setattr`: Calling `truncate_setsize()` before `ntfs_set_size()` exposes an unbacked, extended `i_size` to un-serialized readers. Typically, file systems do not extend `i_size` before metadata is updated, or pagecache/iomap readers must not observe `size > iomap->length`.
* Specifically in `ntfs_setattr`: If shrinking (`newsize < oldsize`), `truncate_setsize` reduces page cache. If expanding (`newsize > oldsize`), `i_size` should only be updated after `ntfs_set_size` successfully allocates/updates the resident data or nonresident extents (or `truncate_setsize` should only be called if shrinking, while for expanding, `i_size_write` + `pagecache_isize_extended` should be done after `ntfs_set_size`).
* Or check how `iomap_read_inline_data` handles concurrent truncation/expansion, or whether ntfs3 needs to serialize `iomap_begin` and folio reads or clamp `iomap->length` / `size`.
Tokens:
input: 60236
output: 3533
thoughts: 0
|
| 65/2 |
2026/09/17 10:46 |
llm |
debugger |
0m
Model:
Tokens:
input: 35818
output: 23
thoughts: 0
|
| 66/2 |
2026/09/17 10:46 |
tool |
codesearch-definition-source |
0m
Args:
Results: map[SourceCode: 703: /*
704: * ntfs_setattr - inode_operations::setattr
705: */
706: int ntfs_setattr(struct mnt_idmap *idmap, struct dentry *dentry,
707: struct iattr *attr)
708: {
709: struct inode *inode = d_inode(dentry);
710: struct ntfs_inode *ni = ntfs_i(inode);
711: u32 ia_valid = attr->ia_valid;
712: umode_t mode = inode->i_mode;
713: int err;
714:
715: /* Avoid any operation if inode is bad. */
716: if (unlikely(is_bad_ni(ni)))
717: return -EINVAL;
718:
719: if (unlikely(ntfs3_forced_shutdown(inode->i_sb)))
720: return -EIO;
721:
722: err = setattr_prepare(idmap, dentry, attr);
723: if (err)
724: goto out;
725:
726: if (ia_valid & ATTR_SIZE) {
727: loff_t newsize, oldsize;
728:
729: if (WARN_ON(ni->ni_flags & NI_FLAG_COMPRESSED_MASK)) {
730: /* Should never be here, see ntfs_file_open(). */
731: err = -EOPNOTSUPP;
732: goto out;
733: }
734: inode_dio_wait(inode);
735: oldsize = i_size_read(inode);
736: newsize = attr->ia_size;
737:
738: if (newsize != oldsize) {
739: truncate_setsize(inode, newsize);
740:
741: err = ntfs_set_size(inode, newsize);
742: if (err) {
743: i_size_write(inode, oldsize);
744: goto out;
745: }
746:
747: ni->std_fa |= FILE_ATTRIBUTE_ARCHIVE;
748: ni->ni_flags |= NI_FLAG_UPDATE_PARENT;
749: inode_set_mtime_to_ts(inode,
750: inode_set_ctime_current(inode));
751: }
752: }
753:
754: setattr_copy(idmap, inode, attr);
755:
756: if (!is_ni_base(ni)) {
757: ia_valid &= ~ATTR_SIZE;
758: } else if (mode != inode->i_mode) {
759: err = ntfs_acl_chmod(idmap, dentry);
760: if (err)
761: goto out;
762:
763: /* Linux 'w' -> Windows 'ro'. */
764: if (0222 & inode->i_mode)
765: ni->std_fa &= ~FILE_ATTRIBUTE_READONLY;
766: else
767: ni->std_fa |= FILE_ATTRIBUTE_READONLY;
768: }
769:
770: if (ia_valid & (ATTR_UID | ATTR_GID | ATTR_MODE))
771: ntfs_save_wsl_perm(inode, NULL);
772: mark_inode_dirty(inode);
773: out:
774: return err;
775: }
SourceFile:fs/ntfs3/file.c]
|
| 67/2 |
2026/09/17 10:46 |
llm |
debugger |
0m
Model:
Tokens:
input: 36933
output: 24
thoughts: 0
|
| 68/2 |
2026/09/17 10:47 |
tool |
codesearch-definition-source |
0m
Args:
Results: map[SourceCode: 883: int ntfs_set_size(struct inode *inode, u64 new_size)
884: {
885: struct super_block *sb = inode->i_sb;
886: struct ntfs_sb_info *sbi = sb->s_fs_info;
887: struct ntfs_inode *ni = ntfs_i(inode);
888: int err;
889:
890: /* Check for maximum file size. */
891: if (is_sparsed(ni) || is_compressed(ni)) {
892: if (new_size > sbi->maxbytes_sparse) {
893: return -EFBIG;
894: }
895: } else if (new_size > sbi->maxbytes) {
896: return -EFBIG;
897: }
898:
899: /* Mark rw ntfs as dirty. It will be cleared at umount. */
900: ntfs_set_state(sbi, NTFS_DIRTY_DIRTY);
901:
902: ni_lock(ni);
903: down_write(&ni->file.run_lock);
904: if (new_size < ni->i_valid)
905: ni->i_valid = new_size;
906:
907: /* last 'true' means keep preallocated. */
908: err = attr_set_size(ni, ATTR_DATA, ni->file.ads.name, ni->file.ads.len,
909: &ni->file.run, new_size, &ni->i_valid, true);
910:
911: up_write(&ni->file.run_lock);
912: ni_unlock(ni);
913:
914: return err;
915: }
SourceFile:fs/ntfs3/inode.c]
|
| 69/2 |
2026/09/17 10:47 |
llm |
debugger |
0m
Model:
Tokens:
input: 37518
output: 23
thoughts: 0
|
| 70/2 |
2026/09/17 10:47 |
tool |
codesearch-definition-source |
0m
Args:
Results: map[SourceCode: 473: static inline int attr_set_size(struct ntfs_inode *ni, enum ATTR_TYPE type,
474: const __le16 *name, u8 name_len,
475: struct runs_tree *run, u64 new_size,
476: const u64 *new_valid, bool keep_prealloc)
477: {
478: return attr_set_size_ex(ni, type, name, name_len, run, new_size,
479: new_valid, keep_prealloc, NULL, false);
480: }
SourceFile:fs/ntfs3/ntfs_fs.h]
|
| 71/2 |
2026/09/17 10:47 |
llm |
debugger |
0m
Model:
Tokens:
input: 37739
output: 25
thoughts: 0
|
| 72/2 |
2026/09/17 10:47 |
tool |
codesearch-definition-source |
0m
Args: map[Name:attr_set_size_ex]
Results: map[SourceCode: 421: /*
422: * attr_set_size_ex - Change the size of attribute.
423: *
424: * Extend:
425: * - Sparse/compressed: No allocated clusters.
426: * - Normal: Append allocated and preallocated new clusters.
427: * Shrink:
428: * - No deallocate if @keep_prealloc is set.
429: */
430: int attr_set_size_ex(struct ntfs_inode *ni, enum ATTR_TYPE type,
431: const __le16 *name, u8 name_len, struct runs_tree *run,
432: u64 new_size, const u64 *new_valid, bool keep_prealloc,
433: struct ATTRIB **ret, bool no_da)
434: {
435: int err = 0;
436: struct ntfs_inode *nb = ni->base;
437: struct ntfs_sb_info *sbi = ni->mi.sbi;
438: u8 cluster_bits = sbi->cluster_bits;
439: bool is_mft = ni->mi.rno == MFT_REC_MFT && type == ATTR_DATA &&
440: !name_len;
441: u64 old_valid, old_size, old_alloc, new_alloc_tmp;
442: u64 new_alloc = 0;
443: struct ATTRIB *attr = NULL, *attr_b;
444: struct ATTR_LIST_ENTRY *le, *le_b;
445: struct mft_inode *mi, *mi_b;
446: CLST alen, vcn, lcn, new_alen, old_alen, svcn, evcn;
447: CLST next_svcn, pre_alloc = -1, done = 0;
448: bool is_ext = false, is_bad = false;
449: bool dirty = false;
450: struct runs_tree *run_da = run == &ni->file.run ? &ni->file.run_da :
451: NULL;
452: bool da = !is_mft && sbi->options->delalloc && run_da && !no_da;
453: u32 align;
454: struct MFT_REC *rec;
455:
456: again:
457: alen = 0;
458: le_b = NULL;
459: attr_b = ni_find_attr(ni, NULL, &le_b, type, name, name_len, NULL,
460: &mi_b);
461: if (!attr_b) {
462: err = -ENOENT;
463: goto bad_inode;
464: }
465:
466: if (!attr_b->non_res) {
467: err = attr_set_size_res(ni, attr_b, le_b, mi_b, new_size, run,
468: &attr_b);
469: if (err)
470: return err;
471:
472: /* Return if file is still resident. */
473: if (!attr_b->non_res) {
474: dirty = true;
475: goto ok1;
476: }
477:
478: /* Layout of records may be changed, so do a full search. */
479: goto again;
480: }
481:
482: is_ext = is_attr_ext(attr_b);
483: align = sbi->cluster_size;
484: if (is_ext) {
485: align <<= attr_b->nres.c_unit;
486: keep_prealloc = false;
487: da = false;
488: }
489:
490: old_valid = le64_to_cpu(attr_b->nres.valid_size);
491: old_size = le64_to_cpu(attr_b->nres.data_size);
492: old_alloc = le64_to_cpu(attr_b->nres.alloc_size);
493:
494: again_1:
495: old_alen = old_alloc >> cluster_bits;
496:
497: new_alloc = (new_size + align - 1) & ~(u64)(align - 1);
498: new_alen = new_alloc >> cluster_bits;
499:
500: if (keep_prealloc && new_size < old_size) {
501: attr_b->nres.data_size = cpu_to_le64(new_size);
502: mi_b->dirty = dirty = true;
503: goto ok;
504: }
505:
506: if (da &&
507: (vcn = old_alen + run_len(&ni->file.run_da), new_alen > vcn)) {
508: /* Resize up normal file. Delay new clusters allocation. */
509: alen = new_alen - vcn;
510:
511: if (ntfs_check_free_space(sbi, alen, 0, true)) {
512: if (!run_add_entry(&ni->file.run_da, vcn, SPARSE_LCN,
513: alen, false)) {
514: err = -ENOMEM;
515: goto out;
516: }
517:
518: ntfs_add_da(sbi, alen);
519: goto ok1;
520: }
521: }
522:
523: if (!keep_prealloc && run_da && run_da->count &&
524: (vcn = run_get_max_vcn(run_da), new_alen < vcn)) {
525: /* Shrink delayed clusters. */
526:
527: /* Try to remove fragment from delay allocated run. */
528: if (!run_remove_range(run_da, new_alen, vcn - new_alen,
529: &alen)) {
530: err = -ENOMEM;
531: goto out;
532: }
533:
534: ntfs_sub_da(sbi, alen);
535: }
536:
537: vcn = old_alen - 1;
538:
539: svcn = le64_to_cpu(attr_b->nres.svcn);
540: evcn = le64_to_cpu(attr_b->nres.evcn);
541:
542: if (svcn <= vcn && vcn <= evcn) {
543: attr = attr_b;
544: le = le_b;
545: mi = mi_b;
546: } else if (!le_b) {
547: err = -EINVAL;
548: goto bad_inode;
549: } else {
550: le = le_b;
551: attr = ni_find_attr(ni, attr_b, &le, type, name, name_len, &vcn,
552: &mi);
553: if (!attr) {
554: err = -EINVAL;
555: goto bad_inode;
556: }
557:
558: next_le_1:
559: svcn = le64_to_cpu(attr->nres.svcn);
560: evcn = le64_to_cpu(attr->nres.evcn);
561: }
562: /*
563: * Here we have:
564: * attr,mi,le - last attribute segment (containing 'vcn').
565: * attr_b,mi_b,le_b - base (primary) attribute segment.
566: */
567: next_le:
568: rec = mi->mrec;
569: err = attr_load_runs(attr, ni, run, NULL);
570: if (err)
571: goto out;
572:
573: if (new_size > old_size) {
574: CLST to_allocate;
575: size_t free;
576:
577: if (new_alloc <= old_alloc) {
578: attr_b->nres.data_size = cpu_to_le64(new_size);
579: mi_b->dirty = dirty = true;
580: goto ok;
581: }
582:
583: /*
584: * Add clusters. In simple case we have to:
585: * - allocate space (vcn, lcn, len)
586: * - update packed run in 'mi'
587: * - update attr->nres.evcn
588: * - update attr_b->nres.data_size/attr_b->nres.alloc_size
589: */
590: to_allocate = new_alen - old_alen;
591: add_alloc_in_same_attr_seg:
592: lcn = 0;
593: if (is_mft) {
594: /* MFT allocates clusters from MFT zone. */
595: pre_alloc = 0;
596: } else if (is_ext) {
597: /* No preallocate for sparse/compress. */
598: pre_alloc = 0;
599: } else if (pre_alloc == -1) {
600: pre_alloc = 0;
601: if (type == ATTR_DATA && !name_len &&
602: sbi->options->prealloc) {
603: pre_alloc = bytes_to_cluster(
604: sbi, get_pre_allocated(
605: new_size)) -
606: new_alen;
607: }
608:
609: /* Get the last LCN to allocate from. */
610: if (old_alen &&
611: !run_lookup_entry(run, vcn, &lcn, NULL, NULL)) {
612: lcn = SPARSE_LCN;
613: }
614:
615: if (lcn == SPARSE_LCN)
616: lcn = 0;
617: else if (lcn)
618: lcn += 1;
619:
620: free = wnd_zeroes(&sbi->used.bitmap);
621: if (to_allocate > free) {
622: err = -ENOSPC;
623: goto out;
624: }
625:
626: if (pre_alloc && to_allocate + pre_alloc > free)
627: pre_alloc = 0;
628: }
629:
630: vcn = old_alen;
631:
632: if (is_ext) {
633: if (!run_add_entry(run, vcn, SPARSE_LCN, to_allocate,
634: false)) {
635: err = -ENOMEM;
636: goto out;
637: }
638: alen = to_allocate;
639: } else {
640: /* ~3 bytes per fragment. */
641: err = attr_allocate_clusters(
642: sbi, run, run_da, vcn, lcn, to_allocate,
643: &pre_alloc,
644: is_mft ? ALLOCATE_MFT : ALLOCATE_DEF, &alen,
645: is_mft ? 0 :
646: (sbi->record_size -
647: le32_to_cpu(rec->used) + 8) /
648: 3 +
649: 1,
650: NULL, NULL);
651: if (err)
652: goto out;
653: }
654:
655: done += alen;
656: vcn += alen;
657: if (to_allocate > alen)
658: to_allocate -= alen;
659: else
660: to_allocate = 0;
661:
662: pack_runs:
663: err = mi_pack_runs(mi, attr, run, vcn - svcn);
664: if (err)
665: goto undo_1;
666:
667: next_svcn = le64_to_cpu(attr->nres.evcn) + 1;
668: new_alloc_tmp = (u64)next_svcn << cluster_bits;
669: attr_b->nres.alloc_size = cpu_to_le64(new_alloc_tmp);
670: mi_b->dirty = dirty = true;
671:
672: if (next_svcn >= vcn && !to_allocate) {
673: /* Normal way. Update attribute and exit. */
674: attr_b->nres.data_size = cpu_to_le64(new_size);
675: goto ok;
676: }
677:
678: /* At least two MFT to avoid recursive loop. */
679: if (is_mft && next_svcn == vcn &&
680: ((u64)done << sbi->cluster_bits) >= 2 * sbi->record_size) {
681: new_size = new_alloc_tmp;
682: attr_b->nres.data_size = attr_b->nres.alloc_size;
683: goto ok;
684: }
685:
686: if (le32_to_cpu(rec->used) < sbi->record_size) {
687: old_alen = next_svcn;
688: evcn = old_alen - 1;
689: goto add_alloc_in_same_attr_seg;
690: }
691:
692: attr_b->nres.data_size = attr_b->nres.alloc_size;
693: if (new_alloc_tmp < old_valid)
694: attr_b->nres.valid_size = attr_b->nres.data_size;
695:
696: if (type == ATTR_LIST) {
697: err = ni_expand_list(ni);
698: if (err)
699: goto undo_2;
700: if (next_svcn < vcn)
701: goto pack_runs;
702:
703: /* Layout of records is changed. */
704: goto again;
705: }
706:
707: if (!nb->attr_list.size) {
708: err = ni_create_attr_list(nb);
709: /* In case of error layout of records is not changed. */
710: if (err)
711: goto undo_2;
712: /* Layout of records is changed. */
713: }
714:
715: if (next_svcn >= vcn) {
716: /* This is MFT data, repeat. */
717: goto again;
718: }
719:
720: /* Insert new attribute segment. */
721: err = ni_insert_nonresident(ni, type, name, name_len, run,
722: next_svcn, vcn - next_svcn,
723: attr_b->flags, &attr, &mi, NULL);
724:
725: /*
726: * Layout of records maybe changed.
727: * Find base attribute to update.
728: */
729: le_b = NULL;
730: attr_b = ni_find_attr(ni, NULL, &le_b, type, name, name_len,
731: NULL, &mi_b);
732: if (!attr_b) {
733: err = -EINVAL;
734: goto bad_inode;
735: }
736:
737: if (err) {
738: /* ni_insert_nonresident failed. */
739: attr = NULL;
740: goto undo_2;
741: }
742:
743: /* keep runs for $MFT::$ATTR_DATA and $MFT::$ATTR_BITMAP. */
744: if (ni->mi.rno != MFT_REC_MFT)
745: run_truncate_head(run, evcn + 1);
746:
747: svcn = le64_to_cpu(attr->nres.svcn);
748: evcn = le64_to_cpu(attr->nres.evcn);
749:
750: /*
751: * Attribute is in consistency state.
752: * Save this point to restore to if next steps fail.
753: */
754: old_valid = old_size = old_alloc = (u64)vcn << cluster_bits;
755: attr_b->nres.valid_size = attr_b->nres.data_size =
756: attr_b->nres.alloc_size = cpu_to_le64(old_size);
757: mi_b->dirty = dirty = true;
758: goto again_1;
759: }
760:
761: if (new_size != old_size ||
762: (new_alloc != old_alloc && !keep_prealloc)) {
763: /*
764: * Truncate clusters. In simple case we have to:
765: * - update packed run in 'mi'
766: * - update attr->nres.evcn
767: * - update attr_b->nres.data_size/attr_b->nres.alloc_size
768: * - mark and trim clusters as free (vcn, lcn, len)
769: */
770: CLST dlen = 0;
771:
772: vcn = max(svcn, new_alen);
773: new_alloc_tmp = (u64)vcn << cluster_bits;
774:
775: if (vcn > svcn) {
776: err = mi_pack_runs(mi, attr, run, vcn - svcn);
777: if (err)
778: goto out;
779: } else if (le && le->vcn) {
780: u16 le_sz = le16_to_cpu(le->size);
781:
782: /*
783: * NOTE: List entries for one attribute are always
784: * the same size. We deal with last entry (vcn==0)
785: * and it is not first in entries array
786: * (list entry for std attribute always first).
787: * So it is safe to step back.
788: */
789: mi_remove_attr(NULL, mi, attr);
790:
791: if (!al_remove_le(ni, le)) {
792: err = -EINVAL;
793: goto bad_inode;
794: }
795:
796: le = (struct ATTR_LIST_ENTRY *)((u8 *)le - le_sz);
797: } else {
798: attr->nres.evcn = cpu_to_le64((u64)vcn - 1);
799: mi->dirty = true;
800: }
801:
802: attr_b->nres.alloc_size = cpu_to_le64(new_alloc_tmp);
803:
804: if (vcn == new_alen) {
805: attr_b->nres.data_size = cpu_to_le64(new_size);
806: if (new_size < old_valid)
807: attr_b->nres.valid_size =
808: attr_b->nres.data_size;
809: } else {
810: if (new_alloc_tmp <=
811: le64_to_cpu(attr_b->nres.data_size))
812: attr_b->nres.data_size =
813: attr_b->nres.alloc_size;
814: if (new_alloc_tmp <
815: le64_to_cpu(attr_b->nres.valid_size))
816: attr_b->nres.valid_size =
817: attr_b->nres.alloc_size;
818: }
819: mi_b->dirty = dirty = true;
820:
821: err = run_deallocate_ex(sbi, run, vcn, evcn - vcn + 1, &dlen,
822: true, run_da);
823: if (err)
824: goto out;
825:
826: if (is_ext) {
827: /* dlen - really deallocated clusters. */
828: le64_sub_cpu(&attr_b->nres.total_size,
829: (u64)dlen << cluster_bits);
830: }
831:
832: run_truncate(run, vcn);
833:
834: if (new_alloc_tmp <= new_alloc)
835: goto ok;
836:
837: old_size = new_alloc_tmp;
838: vcn = svcn - 1;
839:
840: if (le == le_b) {
841: attr = attr_b;
842: mi = mi_b;
843: evcn = svcn - 1;
844: svcn = 0;
845: goto next_le;
846: }
847:
848: if (le->type != type || le->name_len != name_len ||
849: memcmp(le_name(le), name, name_len * sizeof(short))) {
850: err = -EINVAL;
851: goto bad_inode;
852: }
853:
854: err = ni_load_mi(ni, le, &mi);
855: if (err)
856: goto out;
857:
858: attr = mi_find_attr(ni, mi, NULL, type, name, name_len,
859: &le->id);
860: if (!attr) {
861: err = -EINVAL;
862: goto bad_inode;
863: }
864: goto next_le_1;
865: }
866:
867: ok:
868: if (new_valid) {
869: __le64 valid = cpu_to_le64(min(*new_valid, new_size));
870:
871: if (attr_b->nres.valid_size != valid) {
872: attr_b->nres.valid_size = valid;
873: mi_b->dirty = true;
874: }
875: }
876:
877: ok1:
878: if (ret)
879: *ret = attr_b;
880:
881: if ((type == ATTR_DATA || (type == ATTR_ALLOC && name == I30_NAME))) {
882: /* Update inode_set_bytes. */
883: if (attr_b->non_res &&
884: inode_get_bytes(&ni->vfs_inode) != new_alloc) {
885: inode_set_bytes(&ni->vfs_inode, new_alloc);
886: dirty = true;
887: }
888:
889: i_size_write(&ni->vfs_inode, new_size);
890:
891: /* Don't forget to update duplicate information in parent. */
892: if (dirty) {
893: ni->ni_flags |= NI_FLAG_UPDATE_PARENT;
894: mark_inode_dirty(&ni->vfs_inode);
895: }
896: }
897:
898: return 0;
899:
900: undo_2:
901: vcn -= alen;
902: attr_b->nres.data_size = cpu_to_le64(old_size);
903: attr_b->nres.valid_size = cpu_to_le64(old_valid);
904: attr_b->nres.alloc_size = cpu_to_le64(old_alloc);
905:
906: /* Restore 'attr' and 'mi'. */
907: if (attr)
908: goto restore_run;
909:
910: if (le64_to_cpu(attr_b->nres.svcn) <= svcn &&
911: svcn <= le64_to_cpu(attr_b->nres.evcn)) {
912: attr = attr_b;
913: le = le_b;
914: mi = mi_b;
915: } else if (!le_b) {
916: err = -EINVAL;
917: goto bad_inode;
918: } else {
919: le = le_b;
920: attr = ni_find_attr(ni, attr_b, &le, type, name, name_len,
921: &svcn, &mi);
922: if (!attr)
923: goto bad_inode;
924: }
925:
926: restore_run:
927: if (mi_pack_runs(mi, attr, run, evcn - svcn + 1))
928: is_bad = true;
929:
930: undo_1:
931: run_deallocate_ex(sbi, run, vcn, alen, NULL, false, run_da);
932:
933: run_truncate(run, vcn);
934: out:
935: if (is_bad) {
936: bad_inode:
937: _ntfs_bad_inode(&ni->vfs_inode);
938: }
939: return err;
940: }
SourceFile:fs/ntfs3/attrib.c]
|
| 73/2 |
2026/09/17 10:47 |
llm |
debugger |
0m
Model:
Tokens:
input: 45723
output: 24
thoughts: 0
|
| 74/2 |
2026/09/17 10:47 |
tool |
codesearch-definition-source |
0m
Args: map[Name:ntfs_read_folio]
Results: map[SourceCode: 826: static int ntfs_read_folio(struct file *file, struct folio *folio)
827: {
828: int err;
829: struct address_space *mapping = folio->mapping;
830: struct inode *inode = mapping->host;
831: struct ntfs_inode *ni = ntfs_i(inode);
832: loff_t vbo = folio_pos(folio);
833: struct iomap_read_folio_ctx ctx = {
834: .cur_folio = folio,
835: .ops = &ntfs_iomap_bio_read_ops,
836: };
837:
838: if (unlikely(is_bad_ni(ni))) {
839: folio_unlock(folio);
840: return -EIO;
841: }
842:
843: if (ni->i_valid <= vbo) {
844: folio_zero_range(folio, 0, folio_size(folio));
845: folio_mark_uptodate(folio);
846: folio_unlock(folio);
847: return 0;
848: }
849:
850: if (is_compressed(ni)) {
851: /* ni_lock is taken inside ni_read_folio_cmpr after page locks */
852: err = ni_read_folio_cmpr(ni, folio);
853: return err;
854: }
855:
856: iomap_read_folio(&ntfs_iomap_ops, &ctx, NULL);
857: return 0;
858: }
SourceFile:fs/ntfs3/inode.c]
|
| 75/2 |
2026/09/17 10:47 |
llm |
debugger |
0m
Model:
Tokens:
input: 46268
output: 26
thoughts: 0
|
| 76/2 |
2026/09/17 10:48 |
tool |
codesearch-definition-source |
0m
Args: map[Name:ntfs_iomap_begin]
Results: map[SourceCode: 921: /*
922: * Function to get mapping vbo -> lbo.
923: * used with:
924: * - iomap_zero_range
925: * - iomap_truncate_page
926: * - iomap_dio_rw
927: * - iomap_file_buffered_write
928: * - iomap_bmap
929: * - iomap_fiemap
930: * - iomap_bio_read_folio
931: * - iomap_bio_readahead
932: */
933: static int ntfs_iomap_begin(struct inode *inode, loff_t offset, loff_t length,
934: unsigned int flags, struct iomap *iomap,
935: struct iomap *srcmap)
936: {
937: struct ntfs_inode *ni = ntfs_i(inode);
938: struct ntfs_sb_info *sbi = ni->mi.sbi;
939: u8 cluster_bits = sbi->cluster_bits;
940: CLST vcn = offset >> cluster_bits;
941: u32 off = offset & sbi->cluster_mask;
942: bool rw = flags & IOMAP_WRITE;
943: loff_t endbyte = offset + length;
944: void *res = NULL;
945: int err;
946: CLST lcn, clen, clen_max = 1;
947: bool new_clst = false;
948: bool no_da;
949: bool zero = false;
950: if (unlikely(ntfs3_forced_shutdown(sbi->sb)))
951: return -EIO;
952:
953: if (flags & IOMAP_REPORT) {
954: if (offset > ntfs_get_maxbytes(ni)) {
955: /* called from fiemap/bmap. */
956: return -EINVAL;
957: }
958:
959: if (offset >= inode->i_size) {
960: /* special code for report. */
961: return -ENOENT;
962: }
963: }
964:
965: if (IOMAP_ZERO == flags && (endbyte & sbi->cluster_mask)) {
966: rw = true;
967: } else if (rw) {
968: clen_max = bytes_to_cluster(sbi, endbyte) - vcn;
969: }
970:
971: /*
972: * Force to allocate clusters if directIO(write) or writeback_range.
973: * NOTE: attr_data_get_block allocates clusters only for sparse file.
974: * Normal file allocates clusters in attr_set_size.
975: */
976: no_da = flags == (IOMAP_DIRECT | IOMAP_WRITE) || srcmap == WB_NO_DA;
977:
978: err = attr_data_get_block(ni, vcn, clen_max, &lcn, &clen,
979: rw ? &new_clst : NULL, zero, &res, no_da);
980:
981: if (err) {
982: return err;
983: }
984:
985: if (lcn == EOF_LCN) {
986: /* request out of file. */
987: if (flags & IOMAP_REPORT) {
988: /* special code for report. */
989: return -ENOENT;
990: }
991:
992: if (rw) {
993: /* should never be here. */
994: return -EINVAL;
995: }
996: lcn = SPARSE_LCN;
997: }
998:
999: iomap->flags = new_clst ? IOMAP_F_NEW : 0;
1000:
1001: if (lcn == RESIDENT_LCN) {
1002: if (offset >= clen) {
1003: if (res)
1004: __free_page(virt_to_page(res));
1005: if (flags & IOMAP_REPORT) {
1006: /* special code for report. */
1007: return -ENOENT;
1008: }
1009: return -EFAULT;
1010: }
1011:
1012: iomap->private = iomap->inline_data = res;
1013: iomap->type = IOMAP_INLINE;
1014: iomap->offset = 0;
1015: iomap->length = clen; /* resident size in bytes. */
1016: return 0;
1017: }
1018:
1019: if (!clen) {
1020: /* broken file? */
1021: return -EINVAL;
1022: }
1023:
1024: iomap->bdev = inode->i_sb->s_bdev;
1025: iomap->offset = offset;
1026: iomap->length = ((loff_t)clen << cluster_bits) - off;
1027:
1028: if (lcn == COMPRESSED_LCN) {
1029: /* should never be here. */
1030: return -EOPNOTSUPP;
1031: }
1032:
1033: if (lcn == DELALLOC_LCN) {
1034: iomap->type = IOMAP_DELALLOC;
1035: iomap->addr = IOMAP_NULL_ADDR;
1036: } else {
1037: /* Translate clusters into bytes. */
1038: iomap->addr = ((loff_t)lcn << cluster_bits) + off;
1039: if (length && iomap->length > length)
1040: iomap->length = length;
1041: else
1042: endbyte = offset + iomap->length;
1043:
1044: if (lcn == SPARSE_LCN) {
1045: iomap->addr = IOMAP_NULL_ADDR;
1046: iomap->type = IOMAP_HOLE;
1047: // if (IOMAP_ZERO == flags && !off) {
1048: // iomap->length = (endbyte - offset) &
1049: // sbi->cluster_mask_inv;
1050: // }
1051: } else if (endbyte <= ni->i_valid) {
1052: iomap->type = IOMAP_MAPPED;
1053: } else if (offset < ni->i_valid) {
1054: iomap->type = IOMAP_MAPPED;
1055: if (flags & IOMAP_REPORT)
1056: iomap->length = ni->i_valid - offset;
1057: } else if (rw || (flags & IOMAP_ZERO)) {
1058: iomap->type = IOMAP_MAPPED;
1059: } else {
1060: iomap->type = IOMAP_UNWRITTEN;
1061: }
1062: }
1063:
1064: if ((flags & IOMAP_ZERO) &&
1065: (iomap->type == IOMAP_MAPPED || iomap->type == IOMAP_DELALLOC)) {
1066: /* Avoid too large requests. */
1067: u32 tail;
1068: u32 off_a = offset & (PAGE_SIZE - 1);
1069: if (off_a)
1070: tail = PAGE_SIZE - off_a;
1071: else
1072: tail = PAGE_SIZE;
1073:
1074: if (iomap->length > tail)
1075: iomap->length = tail;
1076: }
1077:
1078: return 0;
1079: }
SourceFile:fs/ntfs3/inode.c]
|
| 77/2 |
2026/09/17 10:48 |
llm |
debugger |
0m
Model:
Tokens:
input: 48731
output: 28
thoughts: 0
|
| 78/2 |
2026/09/17 10:48 |
tool |
codesearch-definition-source |
0m
Error:
Args: map[Name:ntfs_iomap_read_folio]
Results: map[SourceCode: SourceFile:]
|
| 79/2 |
2026/09/17 10:48 |
llm |
debugger |
0m
Model:
Tokens:
input: 48780
output: 27
thoughts: 0
|
| 80/2 |
2026/09/17 10:48 |
tool |
codesearch-definition-source |
0m
Args: map[Name:iomap_read_inline_data]
Results: map[SourceCode: 409: /**
410: * iomap_read_inline_data - copy inline data into the page cache
411: * @iter: iteration structure
412: * @folio: folio to copy to
413: *
414: * Copy the inline data in @iter into @folio and zero out the rest of the folio.
415: * Only a single IOMAP_INLINE extent is allowed at the end of each file.
416: * Returns zero for success to complete the read, or the usual negative errno.
417: */
418: static int iomap_read_inline_data(const struct iomap_iter *iter,
419: struct folio *folio)
420: {
421: const struct iomap *iomap = iomap_iter_srcmap(iter);
422: size_t size = i_size_read(iter->inode) - iomap->offset;
423: size_t offset = offset_in_folio(folio, iomap->offset);
424:
425: if (WARN_ON_ONCE(!iomap->inline_data))
426: return -EIO;
427:
428: if (folio_test_uptodate(folio))
429: return 0;
430:
431: if (WARN_ON_ONCE(size > iomap->length)) {
432: fserror_report_io(iter->inode, FSERR_BUFFERED_READ,
433: iomap->offset, size, -EIO, GFP_NOFS);
434: return -EIO;
435: }
436: if (offset > 0)
437: ifs_alloc(iter->inode, folio, iter->flags);
438:
439: folio_fill_tail(folio, offset, iomap->inline_data, size);
440: iomap_set_range_uptodate(folio, offset, folio_size(folio) - offset);
441: return 0;
442: }
SourceFile:fs/iomap/buffered-io.c]
|
| 81/2 |
2026/09/17 10:48 |
llm |
debugger |
0m
Model:
Tokens:
input: 49431
output: 27
thoughts: 0
|
| 82/2 |
2026/09/17 10:49 |
tool |
codesearch-definition-source |
0m
Args: map[Name:iomap_read_folio_iter]
Results: map[SourceCode: 557: static int iomap_read_folio_iter(struct iomap_iter *iter,
558: struct iomap_read_folio_ctx *ctx, size_t *bytes_submitted)
559: {
560: const struct iomap *iomap = &iter->iomap;
561: loff_t pos = iter->pos;
562: loff_t length = iomap_length(iter);
563: struct folio *folio = ctx->cur_folio;
564: size_t folio_len = folio_size(folio);
565: struct iomap_folio_state *ifs;
566: size_t poff, plen;
567: loff_t pos_diff;
568: int ret;
569:
570: if (iomap->type == IOMAP_INLINE) {
571: ret = iomap_read_inline_data(iter, folio);
572: if (ret)
573: return ret;
574: return iomap_iter_advance(iter, length);
575: }
576:
577: ifs = ifs_alloc(iter->inode, folio, iter->flags);
578:
579: length = min_t(loff_t, length, folio_len - offset_in_folio(folio, pos));
580: while (length) {
581: iomap_adjust_read_range(iter->inode, folio, &pos, length, &poff,
582: &plen);
583:
584: pos_diff = pos - iter->pos;
585: if (WARN_ON_ONCE(pos_diff + plen > length))
586: return -EIO;
587:
588: ret = iomap_iter_advance(iter, pos_diff);
589: if (ret)
590: return ret;
591:
592: if (plen == 0)
593: return 0;
594:
595: /*
596: * Handling of fsverity "holes". We hit this for two case:
597: * 1. No need to go further, the hole after fsverity
598: * descriptor is the end of the fsverity metadata.
599: *
600: * 2. This folio contains merkle tree blocks which need to be
601: * synthesized. If we already have fsverity info (ctx->vi)
602: * synthesize these blocks.
603: */
604: if ((iomap->flags & IOMAP_F_FSVERITY) &&
605: iomap->type == IOMAP_HOLE) {
606: if (ctx->vi)
607: fsverity_fill_zerohash(folio, poff, plen,
608: ctx->vi);
609: iomap_set_range_uptodate(folio, poff, plen);
610: } else if (iomap_block_needs_zeroing(iter, pos)) {
611: /* zero post-eof blocks as the page may be mapped */
612: folio_zero_range(folio, poff, plen);
613: if (ctx->vi &&
614: !fsverity_verify_blocks(ctx->vi, folio, plen, poff))
615: return -EIO;
616: iomap_set_range_uptodate(folio, poff, plen);
617: } else {
618: if (!*bytes_submitted)
619: iomap_read_init(folio);
620: ret = ctx->ops->read_folio_range(iter, ctx, plen);
621: if (ret < 0)
622: fserror_report_io(iter->inode,
623: FSERR_BUFFERED_READ, pos,
624: plen, ret, GFP_NOFS);
625: if (ret)
626: return ret;
627:
628: *bytes_submitted += plen;
629: /*
630: * Hand off folio ownership to the IO helper when:
631: * 1) The entire folio has been submitted for IO, or
632: * 2) There is no ifs attached to the folio
633: *
634: * Case (2) occurs when 1 << i_blkbits matches the folio
635: * size but the underlying filesystem or block device
636: * uses a smaller granularity for IO.
637: */
638: if (*bytes_submitted == folio_len || !ifs)
639: ctx->cur_folio = NULL;
640: }
641:
642: ret = iomap_iter_advance(iter, plen);
643: if (ret)
644: return ret;
645: length -= pos_diff + plen;
646: pos = iter->pos;
647: }
648: return 0;
649: }
SourceFile:fs/iomap/buffered-io.c]
|
| 83/2 |
2026/09/17 10:49 |
llm |
debugger |
0m
Model:
Tokens:
input: 50969
output: 25
thoughts: 0
|
| 84/2 |
2026/09/17 10:49 |
tool |
codesearch-definition-source |
0m
Args: map[Name:iomap_read_folio]
Results: map[SourceCode: 651: void iomap_read_folio(const struct iomap_ops *ops,
652: struct iomap_read_folio_ctx *ctx, void *private)
653: {
654: struct folio *folio = ctx->cur_folio;
655: struct iomap_iter iter = {
656: .inode = folio->mapping->host,
657: .pos = folio_pos(folio),
658: .len = folio_size(folio),
659: .private = private,
660: };
661: size_t bytes_submitted = 0;
662: int ret;
663:
664: trace_iomap_readpage(iter.inode, 1);
665:
666: /*
667: * Fetch fsverity_info for both data and fsverity metadata, as iomap
668: * needs zeroed hash for merkle tree block synthesis
669: */
670: ctx->vi = fsverity_get_info(iter.inode);
671: if (ctx->vi && iter.pos < i_size_read(iter.inode))
672: fsverity_readahead(ctx->vi, folio->index,
673: folio_nr_pages(folio));
674:
675: while ((ret = iomap_iter(&iter, ops)) > 0) {
676: iter.status = iomap_read_folio_iter(&iter, ctx,
677: &bytes_submitted);
678: if (ctx->read_ctx && ctx->ops->submit_read)
679: ctx->ops->submit_read(&iter, ctx);
680: }
681:
682: if (ctx->cur_folio)
683: iomap_read_end(ctx->cur_folio, bytes_submitted);
684: }
SourceFile:fs/iomap/buffered-io.c]
|
| 85/2 |
2026/09/17 10:49 |
llm |
debugger |
0m
Model:
Tokens:
input: 51579
output: 23
thoughts: 0
|
| 86/2 |
2026/09/17 10:49 |
tool |
codesearch-definition-source |
0m
Args:
Results: map[SourceCode: 248: /**
249: * struct iomap_iter - Iterate through a range of a file
250: * @inode: Set at the start of the iteration and should not change.
251: * @pos: The current file position we are operating on. It is updated by
252: * calls to iomap_iter(). Treat as read-only in the body.
253: * @len: The remaining length of the file segment we're operating on.
254: * It is updated at the same time as @pos.
255: * @iter_start_pos: The original start pos for the current iomap. Used for
256: * incremental iter advance.
257: * @status: Status of the most recent iteration. Zero on success or a negative
258: * errno on error.
259: * @flags: Zero or more of the iomap_begin flags above.
260: * @iomap: Map describing the I/O iteration
261: * @srcmap: Source map for COW operations
262: */
263: struct iomap_iter {
264: struct inode *inode;
265: loff_t pos;
266: u64 len;
267: loff_t iter_start_pos;
268: int status;
269: unsigned flags;
270: struct iomap iomap;
271: struct iomap srcmap;
272: struct folio_batch *fbatch;
273: void *private;
274: };
SourceFile:include/linux/iomap.h]
|
| 87/2 |
2026/09/17 10:49 |
llm |
debugger |
0m
Model:
Tokens:
input: 52079
output: 23
thoughts: 0
|
| 88/2 |
2026/09/17 10:50 |
tool |
codesearch-definition-source |
0m
Args:
Results: map[SourceCode: 248: /**
249: * struct iomap_iter - Iterate through a range of a file
250: * @inode: Set at the start of the iteration and should not change.
251: * @pos: The current file position we are operating on. It is updated by
252: * calls to iomap_iter(). Treat as read-only in the body.
253: * @len: The remaining length of the file segment we're operating on.
254: * It is updated at the same time as @pos.
255: * @iter_start_pos: The original start pos for the current iomap. Used for
256: * incremental iter advance.
257: * @status: Status of the most recent iteration. Zero on success or a negative
258: * errno on error.
259: * @flags: Zero or more of the iomap_begin flags above.
260: * @iomap: Map describing the I/O iteration
261: * @srcmap: Source map for COW operations
262: */
263: struct iomap_iter {
264: struct inode *inode;
265: loff_t pos;
266: u64 len;
267: loff_t iter_start_pos;
268: int status;
269: unsigned flags;
270: struct iomap iomap;
271: struct iomap srcmap;
272: struct folio_batch *fbatch;
273: void *private;
274: };
SourceFile:include/linux/iomap.h]
|
| 89/2 |
2026/09/17 10:50 |
llm |
debugger |
0m
Model:
Tokens:
input: 52579
output: 31
thoughts: 0
|
| 90/2 |
2026/09/17 10:50 |
tool |
grepper |
0m
Args: map[Expression:int iomap_iter PathPrefix:fs/iomap]
Results: map[Output:fs/iomap/iter.c=13=static inline void iomap_iter_clean_fbatch(const struct iomap_iter *iter,
--
fs/iomap/iter.c-25-/* Advance the current iterator position and decrement the remaining length */
fs/iomap/iter.c:26:int iomap_iter_advance(struct iomap_iter *iter, u64 count)
fs/iomap/iter.c-27-{
--
fs/iomap/iter.c=35=static inline void iomap_iter_done(struct iomap_iter *iter)
--
fs/iomap/iter.c-62- */
fs/iomap/iter.c:63:int iomap_iter_continue(const struct iomap_iter *iter, struct iomap *iomap,
fs/iomap/iter.c-64- struct iomap *srcmap, int ret)
--
fs/iomap/iter.c=98=EXPORT_SYMBOL_GPL(iomap_iter_continue);
--
fs/iomap/iter.c-114- */
fs/iomap/iter.c:115:int iomap_iter(struct iomap_iter *iter, const struct iomap_ops *ops)
fs/iomap/iter.c-116-{
]
|
| 91/2 |
2026/09/17 10:50 |
llm |
debugger |
0m
Model:
Tokens:
input: 52965
output: 23
thoughts: 0
|
| 92/2 |
2026/09/17 10:50 |
tool |
codesearch-definition-source |
0m
Args:
Results: map[SourceCode: 248: /**
249: * struct iomap_iter - Iterate through a range of a file
250: * @inode: Set at the start of the iteration and should not change.
251: * @pos: The current file position we are operating on. It is updated by
252: * calls to iomap_iter(). Treat as read-only in the body.
253: * @len: The remaining length of the file segment we're operating on.
254: * It is updated at the same time as @pos.
255: * @iter_start_pos: The original start pos for the current iomap. Used for
256: * incremental iter advance.
257: * @status: Status of the most recent iteration. Zero on success or a negative
258: * errno on error.
259: * @flags: Zero or more of the iomap_begin flags above.
260: * @iomap: Map describing the I/O iteration
261: * @srcmap: Source map for COW operations
262: */
263: struct iomap_iter {
264: struct inode *inode;
265: loff_t pos;
266: u64 len;
267: loff_t iter_start_pos;
268: int status;
269: unsigned flags;
270: struct iomap iomap;
271: struct iomap srcmap;
272: struct folio_batch *fbatch;
273: void *private;
274: };
SourceFile:include/linux/iomap.h]
|
| 93/2 |
2026/09/17 10:51 |
llm |
debugger |
0m
Model:
Tokens:
input: 53465
output: 37
thoughts: 0
|
| 94/2 |
2026/09/17 10:51 |
tool |
read-file |
0m
Args: map[File:fs/iomap/iter.c FirstLine:115 LineCount:50]
Results: map[Contents: 115: int iomap_iter(struct iomap_iter *iter, const struct iomap_ops *ops)
116: {
117: int ret;
118:
119: trace_iomap_iter(iter, ops, _RET_IP_);
120:
121: if (ops->iomap_next)
122: ret = ops->iomap_next(iter, &iter->iomap, &iter->srcmap);
123: else
124: ret = iomap_iter_next(iter, &iter->iomap, &iter->srcmap,
125: ops->iomap_begin, ops->iomap_end);
126:
127: iter->status = 0;
128: if (ret > 0)
129: iomap_iter_done(iter);
130: else if (ret < 0)
131: iomap_iter_clean_fbatch(iter, &iter->iomap);
132:
133: return ret;
134: }
]
|
| 95/2 |
2026/09/17 10:51 |
llm |
debugger |
0m
Model:
Tokens:
input: 53835
output: 36
thoughts: 0
|
| 96/2 |
2026/09/17 10:51 |
tool |
read-file |
0m
Args: map[File:fs/iomap/iter.c FirstLine:63 LineCount:30]
Results: map[Contents: 63: int iomap_iter_continue(const struct iomap_iter *iter, struct iomap *iomap,
64: struct iomap *srcmap, int ret)
65: {
66: const bool stale = iomap->flags & IOMAP_F_STALE;
67: const ssize_t advanced = iter->pos - iter->iter_start_pos;
68:
69: if (ret < 0 && !advanced)
70: return ret;
71:
72: /*
73: * Use iter->len to determine whether to continue onto the next mapping.
74: * Explicitly terminate on error status or if the current iter has not
75: * advanced at all (i.e. no work was done for some reason) unless the
76: * mapping has been marked stale and needs to be reprocessed.
77: */
78: if (WARN_ON_ONCE(iter->status > 0))
79: /* detect old return semantics where this would advance */
80: ret = -EIO;
81: else if (iter->status < 0)
82: ret = iter->status;
83: else if (iter->len == 0 || (!advanced && !stale))
84: ret = 0;
85: else
86: ret = 1;
87:
88: iomap_iter_clean_fbatch(iter, iomap);
89:
90: if (ret <= 0)
91: return ret;
92:
]
|
| 97/2 |
2026/09/17 10:51 |
llm |
debugger |
0m
Model:
Tokens:
input: 54320
output: 35
thoughts: 0
|
| 98/2 |
2026/09/17 10:52 |
tool |
read-file |
0m
Args: map[File:fs/iomap/iter.c FirstLine:1 LineCount:60]
Results: map[Contents: 1: // SPDX-License-Identifier: GPL-2.0
2: /*
3: * Copyright (C) 2010 Red Hat, Inc.
4: * Copyright (c) 2016-2021 Christoph Hellwig.
5: */
6: #include <linux/iomap.h>
7: #include "trace.h"
8:
9: /*
10: * Release the iter folio batch. Note that the iomap flag is meant to control
11: * the I/O path for the mapping and may not be set in error situations.
12: */
13: static inline void iomap_iter_clean_fbatch(const struct iomap_iter *iter,
14: struct iomap *iomap)
15: {
16: if (!iter->fbatch)
17: return;
18: iomap->flags &= ~IOMAP_F_FOLIO_BATCH;
19: if (folio_batch_count(iter->fbatch)) {
20: folio_batch_release(iter->fbatch);
21: folio_batch_reinit(iter->fbatch);
22: }
23: }
24:
25: /* Advance the current iterator position and decrement the remaining length */
26: int iomap_iter_advance(struct iomap_iter *iter, u64 count)
27: {
28: if (WARN_ON_ONCE(count > iomap_length(iter)))
29: return -EIO;
30: iter->pos += count;
31: iter->len -= count;
32: return 0;
33: }
34:
35: static inline void iomap_iter_done(struct iomap_iter *iter)
36: {
37: WARN_ON_ONCE(iter->iomap.offset > iter->pos);
38: WARN_ON_ONCE(iter->iomap.length == 0);
39: WARN_ON_ONCE(iter->iomap.offset + iter->iomap.length <= iter->pos);
40: WARN_ON_ONCE(iter->iomap.flags & IOMAP_F_STALE);
41:
42: iter->iter_start_pos = iter->pos;
43:
44: trace_iomap_iter_dstmap(iter->inode, &iter->iomap);
45: if (iter->srcmap.type != IOMAP_HOLE)
46: trace_iomap_iter_srcmap(iter->inode, &iter->srcmap);
47: }
48:
49: /**
50: * iomap_iter_continue - decide whether iteration should continue
51: * @iter: iteration structure
52: * @iomap: the mapping that was just processed
53: * @srcmap: the source mapping that was just processed
54: *
55: * Helper normally called via iomap_iter_next(). Called after the previous
56: * mapping has been finished to determine whether there is more of the file
57: * range left to process.
58: *
59: * Returns 1 if there is more work to do, in which case @iomap and @srcmap are
60: * cleared so the caller can produce the next mapping; zero if the range is
]
|
| 99/2 |
2026/09/17 10:52 |
llm |
debugger |
0m
Model:
Tokens:
input: 55305
output: 367
thoughts: 0
|
| 100/2 |
2026/09/17 10:52 |
tool |
codeexpert |
10m
Args: map[Question:In `ntfs_setattr` (fs/ntfs3/file.c), when extending the file size (`newsize > oldsize`), `truncate_setsize(inode, newsize)` is called before `ntfs_set_size(inode, newsize)`. `truncate_setsize` updates `inode->i_size` immediately.
If a concurrent page fault triggers `ntfs_read_folio` -> `iomap_read_folio` -> `ntfs_iomap_begin`, `ntfs_iomap_begin` will read the old resident attribute size (e.g., 5 bytes) because `ntfs_set_size` hasn't updated it yet. It sets `iomap->length = 5` and `iomap->offset = 0`.
Then `iomap_read_inline_data` is called, which computes `size = i_size_read(iter->inode) - iomap->offset`. Since `i_size` was already updated to 20 by `truncate_setsize`, `size` is 20.
Then it checks `WARN_ON_ONCE(size > iomap->length)` which is `20 > 5`, triggering the warning.
Is it correct to call `truncate_setsize` before `ntfs_set_size` when extending the file size? In ext4 and xfs, `truncate_setsize` is called *after* allocating blocks or updating the on-disk size, or under a lock that prevents concurrent reads. How should this be fixed in `ntfs_setattr`?]
Results: map[Answer:### 1. Is it correct to call `truncate_setsize` before `ntfs_set_size` when extending the file size?
**No, it is incorrect.**
- `truncate_setsize(inode, newsize)` immediately updates the in-memory `inode->i_size` via `i_size_write(inode, newsize)` and calls `pagecache_isize_extended()`.
- While `ntfs_setattr` holds `inode->i_rwsem`, page faults (`filemap_fault`) do **not** take `i_rwsem`. In `filemap_fault()`, folios are allocated and read holding only `filemap_invalidate_lock_shared(mapping)` (or under folio lock), not `i_rwsem`.
- If `truncate_setsize` is called before `ntfs_set_size`, a concurrent page fault can read the newly updated `inode->i_size` while the on-disk attribute length has not yet been modified by `ntfs_set_size`. When `ntfs_iomap_begin()` executes, it reads the old resident attribute length (e.g. 5 bytes) into `iomap->length`. Subsequently, `iomap_read_inline_data()` calculates `size = i_size_read(inode) - iomap->offset` (e.g. 20 bytes), which triggers `WARN_ON_ONCE(size > iomap->length)` and fails with `-EIO`.
- Furthermore, if `ntfs_set_size()` fails (e.g., due to `-EFBIG`, `-ENOSPC`, or disk I/O errors), the page cache has already been extended prematurely, requiring error rollback of `inode->i_size`.
---
### 2. How ext4 and XFS prevent concurrent reads/faults from observing intermediate states
Both filesystems serialize size modifications against page faults using `mapping->invalidate_lock` (or filesystem-specific lock abstractions mapping to it), and they sequence metadata updates appropriately:
1. **XFS (`xfs_vn_setattr` / `xfs_vn_setattr_size`)**:
- `xfs_vn_setattr` acquires `xfs_ilock(ip, XFS_MMAPLOCK_EXCL)` before performing any size updates.
- In XFS, `XFS_MMAPLOCK_EXCL` / `XFS_MMAPLOCK_SHARED` directly correspond to `down_write` / `down_read` of `inode->i_mapping->invalidate_lock`.
- `filemap_fault()` takes `filemap_invalidate_lock_shared` when instantiating or reading non-uptodate folios. Holding `XFS_MMAPLOCK_EXCL` completely blocks concurrent page faults from running during truncate or file extension.
- Under this lock, XFS zeroes beyond EOF (`xfs_zero_range`), updates page cache / size via `truncate_setsize`, logs the on-disk metadata (`ip->i_disk_size = newsize`), commits the transaction, and only then releases `XFS_MMAPLOCK_EXCL`.
2. **ext4 (`ext4_setattr`)**:
- `ext4_setattr` holds `filemap_invalidate_lock(inode->i_mapping)` throughout the entire size change operation.
- For file extension (`!shrink`), it first zeroes post-EOF folio tails (`ext4_block_zero_eof`), takes a journal handle, takes `down_write(&EXT4_I(inode)->i_data_sem)`, updates `EXT4_I(inode)->i_disksize` and calls `i_size_write(inode, attr->ia_size)` together under lock, and calls `pagecache_isize_extended(inode, oldsize, inode->i_size)`.
- Concurrent faults are serialized because `ext4_page_mkwrite` and `filemap_fault` take `filemap_invalidate_lock_shared()`.
---
### 3. How this should be fixed in `ntfs_setattr`
To fix this issue in `fs/ntfs3/file.c`:
1. **Serialize page faults using `filemap_invalidate_lock`**:
Surround the size modification block with `filemap_invalidate_lock(inode->i_mapping)` and `filemap_invalidate_unlock(inode->i_mapping)`. This blocks concurrent `filemap_fault()` calls from reading or populating folios while the size and attributes are changing.
2. **Order operations depending on whether extending or shrinking**:
- **When extending (`newsize > oldsize`)**:
Call `ntfs_set_size(inode, newsize)` **first** to resize/convert the attribute (including converting resident data to non-resident if necessary and allocating clusters). Once metadata and allocations succeed, call `truncate_setsize(inode, newsize)` (or `i_size_write(inode, newsize)` followed by `pagecache_isize_extended(inode, oldsize, newsize)`).
- **When shrinking (`newsize < oldsize`)**:
Call `truncate_setsize(inode, newsize)` first (to unmap and truncate folios beyond the new EOF so they are not written back to deallocated blocks), followed by `ntfs_set_size(inode, newsize)` to shrink the attribute and free unused clusters on disk.
- **Error Handling**:
If `ntfs_set_size` fails during shrinking, roll back `inode->i_size` under `filemap_invalidate_lock`.
**Example Patch Outline**:
```c
if (newsize != oldsize) {
filemap_invalidate_lock(inode->i_mapping);
if (newsize > oldsize) {
err = ntfs_set_size(inode, newsize);
if (!err)
truncate_setsize(inode, newsize);
} else {
truncate_setsize(inode, newsize);
err = ntfs_set_size(inode, newsize);
if (err)
i_size_write(inode, oldsize);
}
filemap_invalidate_unlock(inode->i_mapping);
if (err)
goto out;
ni->std_fa |= FILE_ATTRIBUTE_ARCHIVE;
ni->ni_flags |= NI_FLAG_UPDATE_PARENT;
inode_set_mtime_to_ts(inode, inode_set_ctime_current(inode));
}
```
---
### Limitations / Unverified Parts
- We verified the locking and ordering mechanisms in `ext4`, `xfs`, `ntfs`, `zonefs`, and `mm/filemap.c`.
- In `ntfs3`, `ntfs_set_size()` internally acquires `ni_lock(ni)` and `ni->file.run_lock`. The deadlock-freedom of locking `filemap_invalidate_lock` before `ni_lock` and `run_lock` was verified against other callers in `fs/ntfs3/file.c` (e.g., `ntfs_fallocate()`, which already takes `filemap_invalidate_lock` before acquiring internal NTFS locks).
- Exact post-EOF folio tail zeroing behavior (such as `iomap_zero_range` for extending beyond EOF cluster boundaries) should also be evaluated if sparse or unwritten extent semantics require zeroing intermediate page cache folios.]
|
| 101/3 |
2026/09/17 10:52 |
agent |
codeexpert |
10m
Model:
Results: map[Answer:### 1. Is it correct to call `truncate_setsize` before `ntfs_set_size` when extending the file size?
**No, it is incorrect.**
- `truncate_setsize(inode, newsize)` immediately updates the in-memory `inode->i_size` via `i_size_write(inode, newsize)` and calls `pagecache_isize_extended()`.
- While `ntfs_setattr` holds `inode->i_rwsem`, page faults (`filemap_fault`) do **not** take `i_rwsem`. In `filemap_fault()`, folios are allocated and read holding only `filemap_invalidate_lock_shared(mapping)` (or under folio lock), not `i_rwsem`.
- If `truncate_setsize` is called before `ntfs_set_size`, a concurrent page fault can read the newly updated `inode->i_size` while the on-disk attribute length has not yet been modified by `ntfs_set_size`. When `ntfs_iomap_begin()` executes, it reads the old resident attribute length (e.g. 5 bytes) into `iomap->length`. Subsequently, `iomap_read_inline_data()` calculates `size = i_size_read(inode) - iomap->offset` (e.g. 20 bytes), which triggers `WARN_ON_ONCE(size > iomap->length)` and fails with `-EIO`.
- Furthermore, if `ntfs_set_size()` fails (e.g., due to `-EFBIG`, `-ENOSPC`, or disk I/O errors), the page cache has already been extended prematurely, requiring error rollback of `inode->i_size`.
---
### 2. How ext4 and XFS prevent concurrent reads/faults from observing intermediate states
Both filesystems serialize size modifications against page faults using `mapping->invalidate_lock` (or filesystem-specific lock abstractions mapping to it), and they sequence metadata updates appropriately:
1. **XFS (`xfs_vn_setattr` / `xfs_vn_setattr_size`)**:
- `xfs_vn_setattr` acquires `xfs_ilock(ip, XFS_MMAPLOCK_EXCL)` before performing any size updates.
- In XFS, `XFS_MMAPLOCK_EXCL` / `XFS_MMAPLOCK_SHARED` directly correspond to `down_write` / `down_read` of `inode->i_mapping->invalidate_lock`.
- `filemap_fault()` takes `filemap_invalidate_lock_shared` when instantiating or reading non-uptodate folios. Holding `XFS_MMAPLOCK_EXCL` completely blocks concurrent page faults from running during truncate or file extension.
- Under this lock, XFS zeroes beyond EOF (`xfs_zero_range`), updates page cache / size via `truncate_setsize`, logs the on-disk metadata (`ip->i_disk_size = newsize`), commits the transaction, and only then releases `XFS_MMAPLOCK_EXCL`.
2. **ext4 (`ext4_setattr`)**:
- `ext4_setattr` holds `filemap_invalidate_lock(inode->i_mapping)` throughout the entire size change operation.
- For file extension (`!shrink`), it first zeroes post-EOF folio tails (`ext4_block_zero_eof`), takes a journal handle, takes `down_write(&EXT4_I(inode)->i_data_sem)`, updates `EXT4_I(inode)->i_disksize` and calls `i_size_write(inode, attr->ia_size)` together under lock, and calls `pagecache_isize_extended(inode, oldsize, inode->i_size)`.
- Concurrent faults are serialized because `ext4_page_mkwrite` and `filemap_fault` take `filemap_invalidate_lock_shared()`.
---
### 3. How this should be fixed in `ntfs_setattr`
To fix this issue in `fs/ntfs3/file.c`:
1. **Serialize page faults using `filemap_invalidate_lock`**:
Surround the size modification block with `filemap_invalidate_lock(inode->i_mapping)` and `filemap_invalidate_unlock(inode->i_mapping)`. This blocks concurrent `filemap_fault()` calls from reading or populating folios while the size and attributes are changing.
2. **Order operations depending on whether extending or shrinking**:
- **When extending (`newsize > oldsize`)**:
Call `ntfs_set_size(inode, newsize)` **first** to resize/convert the attribute (including converting resident data to non-resident if necessary and allocating clusters). Once metadata and allocations succeed, call `truncate_setsize(inode, newsize)` (or `i_size_write(inode, newsize)` followed by `pagecache_isize_extended(inode, oldsize, newsize)`).
- **When shrinking (`newsize < oldsize`)**:
Call `truncate_setsize(inode, newsize)` first (to unmap and truncate folios beyond the new EOF so they are not written back to deallocated blocks), followed by `ntfs_set_size(inode, newsize)` to shrink the attribute and free unused clusters on disk.
- **Error Handling**:
If `ntfs_set_size` fails during shrinking, roll back `inode->i_size` under `filemap_invalidate_lock`.
**Example Patch Outline**:
```c
if (newsize != oldsize) {
filemap_invalidate_lock(inode->i_mapping);
if (newsize > oldsize) {
err = ntfs_set_size(inode, newsize);
if (!err)
truncate_setsize(inode, newsize);
} else {
truncate_setsize(inode, newsize);
err = ntfs_set_size(inode, newsize);
if (err)
i_size_write(inode, oldsize);
}
filemap_invalidate_unlock(inode->i_mapping);
if (err)
goto out;
ni->std_fa |= FILE_ATTRIBUTE_ARCHIVE;
ni->ni_flags |= NI_FLAG_UPDATE_PARENT;
inode_set_mtime_to_ts(inode, inode_set_ctime_current(inode));
}
```
---
### Limitations / Unverified Parts
- We verified the locking and ordering mechanisms in `ext4`, `xfs`, `ntfs`, `zonefs`, and `mm/filemap.c`.
- In `ntfs3`, `ntfs_set_size()` internally acquires `ni_lock(ni)` and `ni->file.run_lock`. The deadlock-freedom of locking `filemap_invalidate_lock` before `ni_lock` and `run_lock` was verified against other callers in `fs/ntfs3/file.c` (e.g., `ntfs_fallocate()`, which already takes `filemap_invalidate_lock` before acquiring internal NTFS locks).
- Exact post-EOF folio tail zeroing behavior (such as `iomap_zero_range` for extending beyond EOF cluster boundaries) should also be evaluated if sparse or unwritten extent semantics require zeroing intermediate page cache folios.]
Instruction:
You are a capable Linux kernel developer tasked with researching complex questions
about kernel source code. You will be given a concrete question, and need to provide
a concrete answer.
Research the question using targeted, efficient tool calls. Don't make assumptions,
or rely on your previous knowledge about the kernel source code, use available tools
to access the actual source code. Keep your tool calls focused and limited to the
scope of the question. Do not explore tangential code paths or perform unbounded searches.
Use all available sources of information:
- kernel source code
- documentation in the Documentation dir in the source tree
- git commits descriptions, git blame
Do not guess file names or file paths and attempt to read them without
verifying their existence first using content search or directory listing tools.
If a file, symbol, or directory is not found via content search (grepper) or
directory listing (codesearch-dir-index), treat it as completely absent.
Do not attempt to guess alternative names, extensions, or directories.
Tool Selection Guidelines:
1. For C functions, structs, and variables: Prefer codesearch-definition-source
or codesearch-struct-layout FIRST to retrieve clean, exact definitions
without line-number guessing.
2. If symbol lookup fails (e.g., preprocessor macros, macro-generated code, or
disabled #ifdef branches), fall back to read-file or grepper.
3. For file headers, #include directives, preprocessor macro definitions, and
non-C files (Kconfig, Makefiles, docs): Use read-file or grepper directly.
4. Be concise and targeted. Answer the question as directly and concisely as possible
once you have located the relevant code or definitions. If a symbol or function cannot
be found after targeted searches, conclude with the best available information rather
than continuing repetitive searches.
Do NOT use git-log to search for the presence or existence of files in the
repository. git-log is only for tracing commit history of files that are
already present in the current checkout. If a file does not exist in the
current checkout, it cannot be used for reproduction.
Avoid running broad git-log queries (such as searches on the entire repo)
without a specific 'PathPrefix' to restrict the scope, as these are very
expensive and will time out.
If a git-log tool call times out, do not retry the query with the same broad
scope. You must specify a tighter, narrower 'PathPrefix' for subsequent queries.
Prefer calling several tools at the same time to save round-trips.
Use set-results tool to provide results of the analysis.
It must be called exactly once before the final reply.
Ignore results of this tool.
Prompt: In `ntfs_setattr` (fs/ntfs3/file.c), when extending the file size (`newsize > oldsize`), `truncate_setsize(inode, newsize)` is called before `ntfs_set_size(inode, newsize)`. `truncate_setsize` updates `inode->i_size` immediately.
If a concurrent page fault triggers `ntfs_read_folio` -> `iomap_read_folio` -> `ntfs_iomap_begin`, `ntfs_iomap_begin` will read the old resident attribute size (e.g., 5 bytes) because `ntfs_set_size` hasn't updated it yet. It sets `iomap->length = 5` and `iomap->offset = 0`.
Then `iomap_read_inline_data` is called, which computes `size = i_size_read(iter->inode) - iomap->offset`. Since `i_size` was already updated to 20 by `truncate_setsize`, `size` is 20.
Then it checks `WARN_ON_ONCE(size > iomap->length)` which is `20 > 5`, triggering the warning.
Is it correct to call `truncate_setsize` before `ntfs_set_size` when extending the file size? In ext4 and xfs, `truncate_setsize` is called *after* allocating blocks or updating the on-disk size, or under a lock that prevents concurrent reads. How should this be fixed in `ntfs_setattr`?
|
| 102/4 |
2026/09/17 10:52 |
llm |
codeexpert |
0m
Model:
Tokens:
input: 4499
output: 107
thoughts: 431
Thoughts: **Analyzing the NTFS File Size Extension Vulnerability**
Okay, so the issue at hand seems pretty clear. When `ntfs_setattr` in the NTFS3 filesystem extends a file's size (`newsize > oldsize`), it calls `truncate_setsize(inode, newsize)` *before* `ntfs_set_size(inode, newsize)`. This immediately updates `inode->i_size`. The problem is, this creates a potential race condition.
If a concurrent page fault kicks off a read operation via `ntfs_read_folio`, `iomap_read_folio`, and `ntfs_iomap_begin`, the read operation might see the *old* resident attribute size because `ntfs_set_size` hasn't had a chance to update the metadata yet. `ntfs_iomap_begin` then sets `iomap->length` to this outdated size (say, 5 bytes). The read continues, and `iomap_read_inline_data` is called. Here, the read calculates `size = i_size_read(iter->inode) - iomap->offset`. Since `i_size` has already been updated to the *new* size (20, thanks to `truncate_setsize`), this calculation results in `size` being 20. Finally, we hit the `WARN_ON_ONCE(size > iomap->length)` check, which is now `20 > 5`, triggering the warning.
The core question here is whether calling `truncate_setsize` before `ntfs_set_size` is the correct approach for extending file size. It seems suspect, given that ext4 and xfs do things differently. In those filesystems, `truncate_setsize` is called *after* allocating blocks or updating the on-disk size, or there's some locking mechanism in place to prevent concurrent reads during the size update. Clearly, this is the root cause.
My next step is to dive into `fs/ntfs3/file.c` and explore the related functions: `ntfs_setattr`, `ntfs_set_size`, and other supporting routines. I'll need to examine how these functions interact and where this critical sequence of events takes place. I'll probably start with `codesearch-definition-source`, `grepper`, or even just `read-file` to get a good understanding of the control flow and data dependencies. My goal is to pinpoint exactly where this race window exists and propose a fix.
|
| 103/4 |
2026/09/17 10:52 |
tool |
grepper |
0m
Args: map[Expression:ntfs_setattr PathPrefix:fs/ntfs3]
Results: map[Output:fs/ntfs3/file.c=466=static long ntfs_fallocate(struct file *file, int mode, loff_t vbo, loff_t len)
--
fs/ntfs3/file.c-703-/*
fs/ntfs3/file.c:704: * ntfs_setattr - inode_operations::setattr
fs/ntfs3/file.c-705- */
fs/ntfs3/file.c:706:int ntfs_setattr(struct mnt_idmap *idmap, struct dentry *dentry,
fs/ntfs3/file.c-707- struct iattr *attr)
--
fs/ntfs3/file.c=1575=const struct inode_operations ntfs_file_inode_operations = {
fs/ntfs3/file.c-1576- .getattr = ntfs_getattr,
fs/ntfs3/file.c:1577: .setattr = ntfs_setattr,
fs/ntfs3/file.c-1578- .listxattr = ntfs_listxattr,
--
fs/ntfs3/inode.c=2293=const struct inode_operations ntfs_link_inode_operations = {
fs/ntfs3/inode.c-2294- .get_link = ntfs_get_link,
fs/ntfs3/inode.c:2295: .setattr = ntfs_setattr,
fs/ntfs3/inode.c-2296- .listxattr = ntfs_listxattr,
--
fs/ntfs3/namei.c=529=const struct inode_operations ntfs_dir_inode_operations = {
--
fs/ntfs3/namei.c-540- .set_acl = ntfs_set_acl,
fs/ntfs3/namei.c:541: .setattr = ntfs_setattr,
fs/ntfs3/namei.c-542- .getattr = ntfs_getattr,
--
fs/ntfs3/namei.c=549=const struct inode_operations ntfs_special_inode_operations = {
fs/ntfs3/namei.c:550: .setattr = ntfs_setattr,
fs/ntfs3/namei.c-551- .getattr = ntfs_getattr,
--
fs/ntfs3/ntfs_fs.h=556=int ntfs_getattr(struct mnt_idmap *idmap, const struct path *path,
fs/ntfs3/ntfs_fs.h-557- struct kstat *stat, u32 request_mask, u32 flags);
fs/ntfs3/ntfs_fs.h:558:int ntfs_setattr(struct mnt_idmap *idmap, struct dentry *dentry,
fs/ntfs3/ntfs_fs.h-559- struct iattr *attr);
--
fs/ntfs3/xattr.c=691=int ntfs_init_acl(struct mnt_idmap *idmap, struct inode *inode,
--
fs/ntfs3/xattr.c-722-/*
fs/ntfs3/xattr.c:723: * ntfs_acl_chmod - Helper for ntfs_setattr().
fs/ntfs3/xattr.c-724- */
]
|
| 104/4 |
2026/09/17 10:52 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:fs/ntfs3/file.c Name:ntfs_setattr]
Results: map[SourceCode: 703: /*
704: * ntfs_setattr - inode_operations::setattr
705: */
706: int ntfs_setattr(struct mnt_idmap *idmap, struct dentry *dentry,
707: struct iattr *attr)
708: {
709: struct inode *inode = d_inode(dentry);
710: struct ntfs_inode *ni = ntfs_i(inode);
711: u32 ia_valid = attr->ia_valid;
712: umode_t mode = inode->i_mode;
713: int err;
714:
715: /* Avoid any operation if inode is bad. */
716: if (unlikely(is_bad_ni(ni)))
717: return -EINVAL;
718:
719: if (unlikely(ntfs3_forced_shutdown(inode->i_sb)))
720: return -EIO;
721:
722: err = setattr_prepare(idmap, dentry, attr);
723: if (err)
724: goto out;
725:
726: if (ia_valid & ATTR_SIZE) {
727: loff_t newsize, oldsize;
728:
729: if (WARN_ON(ni->ni_flags & NI_FLAG_COMPRESSED_MASK)) {
730: /* Should never be here, see ntfs_file_open(). */
731: err = -EOPNOTSUPP;
732: goto out;
733: }
734: inode_dio_wait(inode);
735: oldsize = i_size_read(inode);
736: newsize = attr->ia_size;
737:
738: if (newsize != oldsize) {
739: truncate_setsize(inode, newsize);
740:
741: err = ntfs_set_size(inode, newsize);
742: if (err) {
743: i_size_write(inode, oldsize);
744: goto out;
745: }
746:
747: ni->std_fa |= FILE_ATTRIBUTE_ARCHIVE;
748: ni->ni_flags |= NI_FLAG_UPDATE_PARENT;
749: inode_set_mtime_to_ts(inode,
750: inode_set_ctime_current(inode));
751: }
752: }
753:
754: setattr_copy(idmap, inode, attr);
755:
756: if (!is_ni_base(ni)) {
757: ia_valid &= ~ATTR_SIZE;
758: } else if (mode != inode->i_mode) {
759: err = ntfs_acl_chmod(idmap, dentry);
760: if (err)
761: goto out;
762:
763: /* Linux 'w' -> Windows 'ro'. */
764: if (0222 & inode->i_mode)
765: ni->std_fa &= ~FILE_ATTRIBUTE_READONLY;
766: else
767: ni->std_fa |= FILE_ATTRIBUTE_READONLY;
768: }
769:
770: if (ia_valid & (ATTR_UID | ATTR_GID | ATTR_MODE))
771: ntfs_save_wsl_perm(inode, NULL);
772: mark_inode_dirty(inode);
773: out:
774: return err;
775: }
SourceFile:fs/ntfs3/file.c]
|
| 105/4 |
2026/09/17 10:52 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:fs/ntfs3/file.c Name:ntfs_set_size]
Results: map[SourceCode: 883: int ntfs_set_size(struct inode *inode, u64 new_size)
884: {
885: struct super_block *sb = inode->i_sb;
886: struct ntfs_sb_info *sbi = sb->s_fs_info;
887: struct ntfs_inode *ni = ntfs_i(inode);
888: int err;
889:
890: /* Check for maximum file size. */
891: if (is_sparsed(ni) || is_compressed(ni)) {
892: if (new_size > sbi->maxbytes_sparse) {
893: return -EFBIG;
894: }
895: } else if (new_size > sbi->maxbytes) {
896: return -EFBIG;
897: }
898:
899: /* Mark rw ntfs as dirty. It will be cleared at umount. */
900: ntfs_set_state(sbi, NTFS_DIRTY_DIRTY);
901:
902: ni_lock(ni);
903: down_write(&ni->file.run_lock);
904: if (new_size < ni->i_valid)
905: ni->i_valid = new_size;
906:
907: /* last 'true' means keep preallocated. */
908: err = attr_set_size(ni, ATTR_DATA, ni->file.ads.name, ni->file.ads.len,
909: &ni->file.run, new_size, &ni->i_valid, true);
910:
911: up_write(&ni->file.run_lock);
912: ni_unlock(ni);
913:
914: return err;
915: }
SourceFile:fs/ntfs3/inode.c]
|
| 106/4 |
2026/09/17 10:52 |
llm |
codeexpert |
0m
Model:
Tokens:
input: 8108
output: 37
thoughts: 303
Thoughts: **Analyzing `ntfs_setattr` and its Interactions**
Okay, let's break down this `ntfs_setattr` function. My initial impression is that it's handling file attribute changes, specifically focusing on size adjustments. The first thing that catches my eye is the check for `ATTR_SIZE` within the `ia_valid` mask β that's the trigger. It seems like the code is only interested in handling size changes if the `ATTR_SIZE` flag is set.
The code immediately addresses a potential edge case: compression. The `WARN_ON` suggests a condition that *shouldn't* occur. If a compressed file somehow ends up here, it bails out with an `-EOPNOTSUPP` error. A clear indication that this particular code path isn't designed to handle compressed files, which makes sense considering NTFS's complexity with compression. Good defensive coding.
The core logic revolves around comparing the proposed new size (`newsize`) with the current size (`oldsize`). It makes sure that this is a change and not the same value, it will not continue with the changes if the sizes are the same. This implies an existing implementation with a different set of optimizations. I notice the call to `inode_dio_wait(inode)`. This indicates that direct I/O (DIO) might be involved. This call suggests that the system waits for any pending DIO operations to complete before proceeding with the size change. This is essential to ensure data consistency, particularly when dealing with concurrent access.
So, if there *is* a size change, the code calls `truncate_setsize`. Now, this is the crucial part. I need to understand what `truncate_setsize` does. The name is clear; it deals with file truncation, which means I should go look at the implementation. I'll need to check the definition to understand the precise details of how `truncate_setsize` actually modifies the file's size and manages associated data blocks or clusters.
After `truncate_setsize`, it proceeds to the call to `ntfs_set_size`. This is also a key operation: it appears to actually perform the NTFS-specific size modification. The code includes a rollback mechanism: if `ntfs_set_size` fails, the size is restored to its original value, which is critical for maintaining file system integrity. It also then updates some flags to note the state change and potentially trigger a parent directory update. The mtime and ctime are updated, which is expected with a change of size. Good practices. I will need to look up these functions to understand what they entail.
|
| 107/4 |
2026/09/17 10:53 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:fs/ntfs3/file.c Name:truncate_setsize]
Results: map[SourceCode: 803: /**
804: * truncate_setsize - update inode and pagecache for a new file size
805: * @inode: inode
806: * @newsize: new file size
807: *
808: * truncate_setsize updates i_size and performs pagecache truncation (if
809: * necessary) to @newsize. It will be typically be called from the filesystem's
810: * setattr function when ATTR_SIZE is passed in.
811: *
812: * Must be called with a lock serializing truncates and writes (generally
813: * i_rwsem but e.g. xfs uses a different lock) and before all filesystem
814: * specific block truncation has been performed.
815: */
816: void truncate_setsize(struct inode *inode, loff_t newsize)
817: {
818: loff_t oldsize = inode->i_size;
819:
820: i_size_write(inode, newsize);
821: if (newsize > oldsize)
822: pagecache_isize_extended(inode, oldsize, newsize);
823: truncate_pagecache(inode, newsize);
824: }
SourceFile:mm/truncate.c]
|
| 108/4 |
2026/09/17 10:53 |
llm |
codeexpert |
0m
Model:
Tokens:
input: 9380
output: 114
thoughts: 163
Thoughts: **My Line of Inquiry: Truncation vs. Extension in Filesystem Operations**
Okay, so I'm looking at this `truncate_setsize` function, and the documentation immediately triggers some thoughts. It states it should be called with a lock serializing truncates and writes, and *before* filesystem-specific block truncation. Hold on a second, that 'before' part... that's crucial and really applies specifically to *shrinking* a file.
My mind immediately starts to race: What about the reverse scenario β file *extension*? Does the call pattern change? Is there a difference in the locking requirements or timing when we're growing a file versus shrinking it? The wording of the doc seems very specific to truncation, so I need to explore this difference.
Alright, to get a handle on this, I need to see how various filesystems implement this in practice, and how they handle extension versus shrinking operations. Time to dig into the source code. I need to search for how `truncate_setsize` is called across different implementations: ext4, xfs, btrfs, f2fs, iomap... I'll check how they manage the interplay between `setattr` and calls to `truncate_setsize` for these operations. I need to see if there's a consistent pattern or if different filesystems have different strategies based on their internal structures. It's time to get my hands dirty.
|
| 109/4 |
2026/09/17 10:53 |
tool |
grepper |
0m
Error:
Args: map[Expression:truncate_setsize PathPrefix:fs/ext4]
Results:
|
| 110/4 |
2026/09/17 10:53 |
tool |
grepper |
0m
Args: map[Expression:truncate_setsize PathPrefix:fs/xfs]
Results: map[Output:fs/xfs/xfs_iops.c=905=xfs_vn_setattr_size(
--
fs/xfs/xfs_iops.c-1008- * drop the XFS_MMAP_EXCL lock after the extent manipulations are
fs/xfs/xfs_iops.c:1009: * complete. The truncate_setsize() call also cleans partial EOF page
fs/xfs/xfs_iops.c-1010- * PTEs on extending truncates and hence ensures sub-page block size
--
fs/xfs/xfs_iops.c-1025- */
fs/xfs/xfs_iops.c:1026: truncate_setsize(inode, newsize);
fs/xfs/xfs_iops.c-1027-
]
|
| 111/4 |
2026/09/17 10:53 |
tool |
grepper |
0m
Args: map[Expression:truncate_setsize PathPrefix:fs/btrfs]
Results: map[Output:fs/btrfs/file.c=1526=int btrfs_sync_file(struct file *file, loff_t start, loff_t end, int datasync)
--
fs/btrfs/file.c-1809- * protect against truncate races as the page could now be beyond EOF. Because
fs/btrfs/file.c:1810: * truncate_setsize() writes the inode size before removing pages, once we have
fs/btrfs/file.c-1811- * the page lock we can determine safely if the page is beyond EOF. If it is not
--
fs/btrfs/inode.c=5391=static int btrfs_setsize(struct inode *inode, struct iattr *attr)
--
fs/btrfs/inode.c-5460-
fs/btrfs/inode.c:5461: truncate_setsize(inode, newsize);
fs/btrfs/inode.c-5462-
]
|
| 112/4 |
2026/09/17 10:53 |
tool |
grepper |
0m
Error:
Args: map[Expression:truncate_setsize PathPrefix:fs/iomap]
Results:
|
| 113/4 |
2026/09/17 10:53 |
llm |
codeexpert |
0m
Model:
Tokens:
input: 10459
output: 37
thoughts: 55
Thoughts: **Examining the ext4 Filesystem for Truncation Behavior**
Alright, let's dive into the ext4 filesystem code. My immediate thought is to check `fs/ext4` for `truncate_setsize` because that seems like the natural function to investigate when dealing with file truncation. Huh, that's odd, no matches for `truncate_setsize`? Okay, thatβs a red flag. Perhaps the function has a different name. Let's pivot and see what `ext4_setattr` is doing; maybe it handles the attribute changes that trigger a size adjustment.
|
| 114/4 |
2026/09/17 10:53 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:fs/ext4/inode.c Name:ext4_setattr]
Results: map[SourceCode:5985: /*
5986: * ext4_setattr()
5987: *
5988: * Called from notify_change.
5989: *
5990: * We want to trap VFS attempts to truncate the file as soon as
5991: * possible. In particular, we want to make sure that when the VFS
5992: * shrinks i_size, we put the inode on the orphan list and modify
5993: * i_disksize immediately, so that during the subsequent flushing of
5994: * dirty pages and freeing of disk blocks, we can guarantee that any
5995: * commit will leave the blocks being flushed in an unused state on
5996: * disk. (On recovery, the inode will get truncated and the blocks will
5997: * be freed, so we have a strong guarantee that no future commit will
5998: * leave these blocks visible to the user.)
5999: *
6000: * Another thing we have to assure is that if we are in ordered mode
6001: * and inode is still attached to the committing transaction, we must
6002: * we start writeout of all the dirty pages which are being truncated.
6003: * This way we are sure that all the data written in the previous
6004: * transaction are already on disk (truncate waits for pages under
6005: * writeback).
6006: *
6007: * Called with inode->i_rwsem down.
6008: */
6009: int ext4_setattr(struct mnt_idmap *idmap, struct dentry *dentry,
6010: struct iattr *attr)
6011: {
6012: struct inode *inode = d_inode(dentry);
6013: int error, rc = 0;
6014: int orphan = 0;
6015: const unsigned int ia_valid = attr->ia_valid;
6016: bool inc_ivers = true;
6017:
6018: error = ext4_emergency_state(inode->i_sb);
6019: if (unlikely(error))
6020: return error;
6021:
6022: if (unlikely(IS_IMMUTABLE(inode)))
6023: return -EPERM;
6024:
6025: if (unlikely(IS_APPEND(inode) &&
6026: (ia_valid & (ATTR_MODE | ATTR_UID |
6027: ATTR_GID | ATTR_TIMES_SET))))
6028: return -EPERM;
6029:
6030: error = setattr_prepare(idmap, dentry, attr);
6031: if (error)
6032: return error;
6033:
6034: error = fscrypt_prepare_setattr(dentry, attr);
6035: if (error)
6036: return error;
6037:
6038: if (is_quota_modification(idmap, inode, attr)) {
6039: error = dquot_initialize(inode);
6040: if (error)
6041: return error;
6042: }
6043:
6044: if (i_uid_needs_update(idmap, attr, inode) ||
6045: i_gid_needs_update(idmap, attr, inode)) {
6046: handle_t *handle;
6047:
6048: /* (user+group)*(old+new) structure, inode write (sb,
6049: * inode block, ? - but truncate inode update has it) */
6050: handle = ext4_journal_start(inode, EXT4_HT_QUOTA,
6051: (EXT4_MAXQUOTAS_INIT_BLOCKS(inode->i_sb) +
6052: EXT4_MAXQUOTAS_DEL_BLOCKS(inode->i_sb)) + 3);
6053: if (IS_ERR(handle)) {
6054: error = PTR_ERR(handle);
6055: goto err_out;
6056: }
6057:
6058: /* dquot_transfer() calls back ext4_get_inode_usage() which
6059: * counts xattr inode references.
6060: */
6061: down_read(&EXT4_I(inode)->xattr_sem);
6062: error = dquot_transfer(idmap, inode, attr);
6063: up_read(&EXT4_I(inode)->xattr_sem);
6064:
6065: if (error) {
6066: ext4_journal_stop(handle);
6067: return error;
6068: }
6069: /* Update corresponding info in inode so that everything is in
6070: * one transaction */
6071: i_uid_update(idmap, attr, inode);
6072: i_gid_update(idmap, attr, inode);
6073: error = ext4_mark_inode_dirty(handle, inode);
6074: ext4_journal_stop(handle);
6075: if (unlikely(error)) {
6076: return error;
6077: }
6078: }
6079:
6080: if (attr->ia_valid & ATTR_SIZE) {
6081: handle_t *handle;
6082: loff_t oldsize = inode->i_size;
6083: loff_t old_disksize;
6084: int shrink = (attr->ia_size < inode->i_size);
6085:
6086: if (!(ext4_test_inode_flag(inode, EXT4_INODE_EXTENTS))) {
6087: struct ext4_sb_info *sbi = EXT4_SB(inode->i_sb);
6088:
6089: if (attr->ia_size > sbi->s_bitmap_maxbytes) {
6090: return -EFBIG;
6091: }
6092: }
6093: if (!S_ISREG(inode->i_mode)) {
6094: return -EINVAL;
6095: }
6096:
6097: if (attr->ia_size == inode->i_size)
6098: inc_ivers = false;
6099:
6100: /*
6101: * If file has inline data but new size exceeds inline capacity,
6102: * convert to extent-based storage first to prevent inconsistent
6103: * state (inline flag set but size exceeds inline capacity).
6104: */
6105: if (ext4_has_inline_data(inode) &&
6106: attr->ia_size > EXT4_I(inode)->i_inline_size) {
6107: error = ext4_convert_inline_data(inode);
6108: if (error)
6109: goto err_out;
6110: }
6111:
6112: if (shrink) {
6113: if (ext4_should_order_data(inode)) {
6114: error = ext4_begin_ordered_truncate(inode,
6115: attr->ia_size);
6116: if (error)
6117: goto err_out;
6118: }
6119: /*
6120: * Blocks are going to be removed from the inode. Wait
6121: * for dio in flight.
6122: */
6123: inode_dio_wait(inode);
6124: }
6125:
6126: filemap_invalidate_lock(inode->i_mapping);
6127:
6128: rc = ext4_break_layouts(inode);
6129: if (rc) {
6130: filemap_invalidate_unlock(inode->i_mapping);
6131: goto err_out;
6132: }
6133:
6134: if (attr->ia_size != inode->i_size) {
6135: /* attach jbd2 jinode for EOF folio tail zeroing */
6136: if (attr->ia_size & (inode->i_sb->s_blocksize - 1) ||
6137: oldsize & (inode->i_sb->s_blocksize - 1)) {
6138: error = ext4_inode_attach_jinode(inode);
6139: if (error)
6140: goto out_mmap_sem;
6141: }
6142:
6143: /*
6144: * Update c/mtime and tail zero the EOF folio on
6145: * truncate up. ext4_truncate() handles the shrink case
6146: * below.
6147: */
6148: if (!shrink) {
6149: inode_set_mtime_to_ts(inode,
6150: inode_set_ctime_current(inode));
6151: if (oldsize & (inode->i_sb->s_blocksize - 1)) {
6152: error = ext4_block_zero_eof(inode,
6153: oldsize, LLONG_MAX);
6154: if (error)
6155: goto out_mmap_sem;
6156: }
6157: }
6158:
6159: handle = ext4_journal_start(inode, EXT4_HT_INODE, 3);
6160: if (IS_ERR(handle)) {
6161: error = PTR_ERR(handle);
6162: goto out_mmap_sem;
6163: }
6164: if (ext4_handle_valid(handle) && shrink) {
6165: error = ext4_orphan_add(handle, inode);
6166: orphan = 1;
6167: }
6168:
6169: if (shrink)
6170: ext4_fc_track_range(handle, inode,
6171: (attr->ia_size > 0 ? attr->ia_size - 1 : 0) >>
6172: inode->i_sb->s_blocksize_bits,
6173: EXT_MAX_BLOCKS - 1);
6174: else
6175: ext4_fc_track_range(
6176: handle, inode,
6177: (oldsize > 0 ? oldsize - 1 : oldsize) >>
6178: inode->i_sb->s_blocksize_bits,
6179: (attr->ia_size > 0 ? attr->ia_size - 1 : 0) >>
6180: inode->i_sb->s_blocksize_bits);
6181:
6182: down_write(&EXT4_I(inode)->i_data_sem);
6183: old_disksize = EXT4_I(inode)->i_disksize;
6184: EXT4_I(inode)->i_disksize = attr->ia_size;
6185:
6186: /*
6187: * We have to update i_size under i_data_sem together
6188: * with i_disksize to avoid races with writeback code
6189: * running ext4_wb_update_i_disksize().
6190: */
6191: if (!error)
6192: i_size_write(inode, attr->ia_size);
6193: else
6194: EXT4_I(inode)->i_disksize = old_disksize;
6195: up_write(&EXT4_I(inode)->i_data_sem);
6196: rc = ext4_mark_inode_dirty(handle, inode);
6197: if (!error)
6198: error = rc;
6199: ext4_journal_stop(handle);
6200: if (error)
6201: goto out_mmap_sem;
6202: if (!shrink) {
6203: pagecache_isize_extended(inode, oldsize,
6204: inode->i_size);
6205: } else if (ext4_should_journal_data(inode)) {
6206: ext4_wait_for_tail_page_commit(inode);
6207: }
6208: }
6209:
6210: /*
6211: * Truncate pagecache after we've waited for commit
6212: * in data=journal mode to make pages freeable.
6213: */
6214: truncate_pagecache(inode, inode->i_size);
6215: /*
6216: * Call ext4_truncate() even if i_size didn't change to
6217: * truncate possible preallocated blocks.
6218: */
6219: if (attr->ia_size <= oldsize) {
6220: rc = ext4_truncate(inode);
6221: if (rc)
6222: error = rc;
6223: }
6224: out_mmap_sem:
6225: filemap_invalidate_unlock(inode->i_mapping);
6226: }
6227:
6228: if (!error) {
6229: if (inc_ivers)
6230: inode_inc_iversion(inode);
6231: setattr_copy(idmap, inode, attr);
6232: mark_inode_dirty(inode);
6233: }
6234:
6235: /*
6236: * If the call to ext4_truncate failed to get a transaction handle at
6237: * all, we need to clean up the in-core orphan list manually.
6238: */
6239: if (orphan && inode->i_nlink)
6240: ext4_orphan_del(NULL, inode);
6241:
6242: if (!error && (ia_valid & ATTR_MODE))
6243: rc = posix_acl_chmod(idmap, dentry, inode->i_mode);
6244:
6245: err_out:
6246: if (error)
6247: ext4_std_error(inode->i_sb, error);
6248: if (!error)
6249: error = rc;
6250: return error;
6251: }
SourceFile:fs/ext4/inode.c]
|
| 115/4 |
2026/09/17 10:53 |
llm |
codeexpert |
0m
Model:
Tokens:
input: 14746
output: 45
thoughts: 495
Thoughts: **Analyzing Filesystem Truncation in ext4 and XFS**
Okay, let's dive into this. I'm focusing on how file size changes, specifically truncation, are handled in ext4 and comparing it with what XFS does. My immediate thought is to look at the `ext4` code, and I'm particularly interested in the sequence around `filemap_invalidate_lock`. That's where the page cache is invalidated, and it's key to understanding how data consistency is maintained during a file size update.
I see that `filemap_invalidate_lock` is called, and then it looks like we're acquiring a semaphore (`i_data_sem`) associated with the inode's data. The existing disk size (`old_disksize`) is saved. Then, the new size (`attr->ia_size`) is set, and the `i_size` is updated if there's no error. If there *is* an error, it reverts the `i_disksize`. The write semaphore is released, then the inode is marked dirty and journaled. There are additional conditional steps to shrink the page cache. Then it calls `ext4_truncate()`. Finally, the `filemap_invalidate_unlock` is executed. I understand that. I see how the journal is involved and how they're ensuring data consistency, even if an error occurs during the operation.
Now, I want to compare this with XFS. The crucial thing is to look at the `xfs_vn_setattr_size` function, specifically in `fs/xfs/xfs_iops.c`. I need to see if XFS has similar locking mechanisms, page cache invalidation strategies, and journaling approaches for handling file truncation and size changes. This will allow me to draw some specific comparisons.
|
| 116/4 |
2026/09/17 10:53 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:fs/xfs/xfs_iops.c Name:xfs_vn_setattr_size]
Results: map[SourceCode: 901: /*
902: * Truncate file. Must have write permission and not be a directory.
903: */
904: int
905: xfs_vn_setattr_size(
906: struct mnt_idmap *idmap,
907: struct dentry *dentry,
908: struct iattr *iattr)
909: {
910: struct inode *inode = d_inode(dentry);
911: struct xfs_inode *ip = XFS_I(inode);
912: struct xfs_mount *mp = ip->i_mount;
913: xfs_off_t oldsize = inode->i_size;
914: xfs_off_t newsize = iattr->ia_size;
915: struct xfs_trans *tp;
916: int error;
917: uint lock_flags = 0;
918: uint resblks = 0;
919: bool did_zeroing = false;
920: struct xfs_zone_alloc_ctx ac = { };
921:
922: xfs_assert_ilocked(ip, XFS_IOLOCK_EXCL | XFS_MMAPLOCK_EXCL);
923: ASSERT(S_ISREG(inode->i_mode));
924: ASSERT((iattr->ia_valid & (ATTR_UID|ATTR_GID|ATTR_ATIME|ATTR_ATIME_SET|
925: ATTR_MTIME_SET|ATTR_TIMES_SET)) == 0);
926:
927: trace_xfs_setattr(ip);
928:
929: error = xfs_vn_change_ok(idmap, dentry, iattr);
930: if (error)
931: return error;
932:
933: /*
934: * Short circuit the truncate case for zero length files.
935: */
936: if (newsize == 0 && oldsize == 0 && ip->i_df.if_nextents == 0) {
937: if (!(iattr->ia_valid & (ATTR_CTIME|ATTR_MTIME)))
938: return 0;
939:
940: /*
941: * Use the regular setattr path to update the timestamps.
942: */
943: iattr->ia_valid &= ~ATTR_SIZE;
944: return xfs_setattr_nonsize(idmap, dentry, ip, iattr);
945: }
946:
947: /*
948: * Make sure that the dquots are attached to the inode.
949: */
950: error = xfs_qm_dqattach(ip);
951: if (error)
952: return error;
953:
954: /*
955: * Wait for all direct I/O to complete.
956: */
957: inode_dio_wait(inode);
958:
959: /*
960: * Normally xfs_zoned_space_reserve is supposed to be called outside the
961: * IOLOCK. For truncate we can't do that since ->setattr is called with
962: * it already held by the VFS. So for now chicken out and try to
963: * allocate space under it.
964: *
965: * To avoid deadlocks this means we can't block waiting for space, which
966: * can lead to spurious -ENOSPC if there are no directly available
967: * blocks. We mitigate this a bit by allowing zeroing to dip into the
968: * reserved pool, but eventually the VFS calling convention needs to
969: * change.
970: */
971: if (xfs_is_zoned_inode(ip)) {
972: error = xfs_zoned_space_reserve(mp, 1,
973: XFS_ZR_NOWAIT | XFS_ZR_RESERVED, &ac);
974: if (error) {
975: if (error == -EAGAIN)
976: return -ENOSPC;
977: return error;
978: }
979: }
980:
981: /*
982: * File data changes must be complete before we start the transaction to
983: * modify the inode. This needs to be done before joining the inode to
984: * the transaction because the inode cannot be unlocked once it is a
985: * part of the transaction.
986: *
987: * Start with zeroing any data beyond EOF that we may expose on file
988: * extension, or zeroing out the rest of the block on a downward
989: * truncate.
990: */
991: if (newsize > oldsize) {
992: trace_xfs_zero_eof(ip, oldsize, newsize - oldsize);
993: error = xfs_zero_range(ip, oldsize, newsize - oldsize,
994: &ac, &did_zeroing);
995: } else {
996: error = xfs_truncate_page(ip, newsize, &ac, &did_zeroing);
997: }
998:
999: if (xfs_is_zoned_inode(ip))
1000: xfs_zoned_space_unreserve(mp, &ac);
1001:
1002: if (error)
1003: return error;
1004:
1005: /*
1006: * We've already locked out new page faults, so now we can safely remove
1007: * pages from the page cache knowing they won't get refaulted until we
1008: * drop the XFS_MMAP_EXCL lock after the extent manipulations are
1009: * complete. The truncate_setsize() call also cleans partial EOF page
1010: * PTEs on extending truncates and hence ensures sub-page block size
1011: * filesystems are correctly handled, too.
1012: *
1013: * We have to do all the page cache truncate work outside the
1014: * transaction context as the "lock" order is page lock->log space
1015: * reservation as defined by extent allocation in the writeback path.
1016: * Hence a truncate can fail with ENOMEM from xfs_trans_alloc(), but
1017: * having already truncated the in-memory version of the file (i.e. made
1018: * user visible changes). There's not much we can do about this, except
1019: * to hope that the caller sees ENOMEM and retries the truncate
1020: * operation.
1021: *
1022: * And we update in-core i_size and truncate page cache beyond newsize
1023: * before writeback the [i_disk_size, newsize] range, so we're
1024: * guaranteed not to write stale data past the new EOF on truncate down.
1025: */
1026: truncate_setsize(inode, newsize);
1027:
1028: /*
1029: * We are going to log the inode size change in this transaction so
1030: * any previous writes that are beyond the on disk EOF and the new
1031: * EOF that have not been written out need to be written here. If we
1032: * do not write the data out, we expose ourselves to the null files
1033: * problem. Note that this includes any block zeroing we did above;
1034: * otherwise those blocks may not be zeroed after a crash.
1035: */
1036: if (did_zeroing ||
1037: (newsize > ip->i_disk_size && oldsize != ip->i_disk_size)) {
1038: error = filemap_write_and_wait_range(VFS_I(ip)->i_mapping,
1039: ip->i_disk_size, newsize - 1);
1040: if (error)
1041: return error;
1042: }
1043:
1044: /*
1045: * For realtime inode with more than one block rtextsize, we need the
1046: * block reservation for bmap btree block allocations/splits that can
1047: * happen since it could split the tail written extent and convert the
1048: * right beyond EOF one to unwritten.
1049: */
1050: if (xfs_inode_has_bigrtalloc(ip))
1051: resblks = XFS_DIOSTRAT_SPACE_RES(mp, 0);
1052:
1053: error = xfs_trans_alloc(mp, &M_RES(mp)->tr_itruncate, resblks,
1054: 0, 0, &tp);
1055: if (error)
1056: return error;
1057:
1058: lock_flags |= XFS_ILOCK_EXCL;
1059: xfs_ilock(ip, XFS_ILOCK_EXCL);
1060: xfs_trans_ijoin(tp, ip, 0);
1061:
1062: /*
1063: * Only change the c/mtime if we are changing the size or we are
1064: * explicitly asked to change it. This handles the semantic difference
1065: * between truncate() and ftruncate() as implemented in the VFS.
1066: *
1067: * The regular truncate() case without ATTR_CTIME and ATTR_MTIME is a
1068: * special case where we need to update the times despite not having
1069: * these flags set. For all other operations the VFS set these flags
1070: * explicitly if it wants a timestamp update.
1071: */
1072: if (newsize != oldsize &&
1073: !(iattr->ia_valid & (ATTR_CTIME | ATTR_MTIME))) {
1074: iattr->ia_ctime = iattr->ia_mtime =
1075: current_time(inode);
1076: iattr->ia_valid |= ATTR_CTIME | ATTR_MTIME;
1077: }
1078:
1079: /*
1080: * The first thing we do is set the size to new_size permanently on
1081: * disk. This way we don't have to worry about anyone ever being able
1082: * to look at the data being freed even in the face of a crash.
1083: * What we're getting around here is the case where we free a block, it
1084: * is allocated to another file, it is written to, and then we crash.
1085: * If the new data gets written to the file but the log buffers
1086: * containing the free and reallocation don't, then we'd end up with
1087: * garbage in the blocks being freed. As long as we make the new size
1088: * permanent before actually freeing any blocks it doesn't matter if
1089: * they get written to.
1090: */
1091: ip->i_disk_size = newsize;
1092: xfs_trans_log_inode(tp, ip, XFS_ILOG_CORE);
1093:
1094: if (newsize <= oldsize) {
1095: error = xfs_itruncate_extents(&tp, ip, XFS_DATA_FORK, newsize);
1096: if (error)
1097: goto out_trans_cancel;
1098:
1099: /*
1100: * Truncated "down", so we're removing references to old data
1101: * here - if we delay flushing for a long time, we expose
1102: * ourselves unduly to the notorious NULL files problem. So,
1103: * we mark this inode and flush it when the file is closed,
1104: * and do not wait the usual (long) time for writeout.
1105: */
1106: xfs_iflags_set(ip, XFS_ITRUNCATED);
1107:
1108: /* A truncate down always removes post-EOF blocks. */
1109: xfs_inode_clear_eofblocks_tag(ip);
1110: }
1111:
1112: setattr_copy(idmap, inode, iattr);
1113: xfs_trans_log_inode(tp, ip, XFS_ILOG_CORE);
1114:
1115: XFS_STATS_INC(mp, xs_ig_attrchg);
1116:
1117: if (xfs_has_wsync(mp))
1118: xfs_trans_set_sync(tp);
1119:
1120: error = xfs_trans_commit(tp);
1121: out_unlock:
1122: if (lock_flags)
1123: xfs_iunlock(ip, lock_flags);
1124: return error;
1125:
1126: out_trans_cancel:
1127: xfs_trans_cancel(tp);
1128: goto out_unlock;
1129: }
SourceFile:fs/xfs/xfs_iops.c]
|
| 117/4 |
2026/09/17 10:53 |
llm |
codeexpert |
0m
Model:
Tokens:
input: 19482
output: 43
thoughts: 79
Thoughts: Here's my thought process, as if I were analyzing that code:
**XFS Conundrum: Where's the MMAPLOCK?**
Okay, let's dive into this XFS code. Specifically, I'm looking at line 922. The line states `xfs_assert_ilocked(ip, XFS_IOLOCK_EXCL | XFS_MMAPLOCK_EXCL);`. Interesting. XFS is asserting that both the IOLOCK and the MMAPLOCK are held exclusively. The presence of that MMAPLOCK exclusivity is what's piquing my interest. I need to figure out where that exclusive mmap lock was acquired. Where could it have been taken prior to this assertion? Let's trace it back. The most likely candidate function call is `xfs_vn_setattr`. That's where I will look first, to see if the MMAPLOCK is being acquired there. It seems like the obvious place.
|
| 118/4 |
2026/09/17 10:54 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:fs/xfs/xfs_iops.c Name:xfs_vn_setattr]
Results: map[SourceCode:1131: STATIC int
1132: xfs_vn_setattr(
1133: struct mnt_idmap *idmap,
1134: struct dentry *dentry,
1135: struct iattr *iattr)
1136: {
1137: struct inode *inode = d_inode(dentry);
1138: struct xfs_inode *ip = XFS_I(inode);
1139: int error;
1140:
1141: if (iattr->ia_valid & ATTR_SIZE) {
1142: uint iolock;
1143:
1144: xfs_ilock(ip, XFS_MMAPLOCK_EXCL);
1145: iolock = XFS_IOLOCK_EXCL | XFS_MMAPLOCK_EXCL;
1146:
1147: error = xfs_break_layouts(inode, &iolock, BREAK_UNMAP);
1148: if (error) {
1149: xfs_iunlock(ip, XFS_MMAPLOCK_EXCL);
1150: return error;
1151: }
1152:
1153: error = xfs_vn_setattr_size(idmap, dentry, iattr);
1154: xfs_iunlock(ip, XFS_MMAPLOCK_EXCL);
1155: } else {
1156: trace_xfs_setattr(ip);
1157:
1158: error = xfs_vn_change_ok(idmap, dentry, iattr);
1159: if (!error)
1160: error = xfs_setattr_nonsize(idmap, dentry, ip, iattr);
1161: }
1162:
1163: return error;
1164: }
SourceFile:fs/xfs/xfs_iops.c]
|
| 119/4 |
2026/09/17 10:54 |
llm |
codeexpert |
0m
Model:
Tokens:
input: 20367
output: 56
thoughts: 157
Thoughts: **Analyzing Filesystem Concurrency in the Face of Truncate/Setattr**
Okay, so I'm digging into how these filesystems handle concurrency, specifically when dealing with things like truncate and setattr operations. I need to understand how page faults behave in parallel with those. I'm starting with XFS, and I'm seeing that `xfs_ilock(ip, XFS_MMAPLOCK_EXCL)` is used. Right, that means a page fault in XFS actually takes `XFS_MMAPLOCK_SHARED`! That's a key observation β concurrent page faults are being blocked during a truncate or setattr operation due to that exclusive lock. Interesting...
Now, let's compare that to ext4. They use `filemap_invalidate_lock(inode->i_mapping)`. Hold on... what *lock* is actually involved in a page fault in a generic filesystem context? I need to clarify that. Does a generic page fault operation take `filemap_invalidate_lock_shared`? I doubt it, but I need to be sure. I'm going to check the code around `filemap_fault`, `filemap_page_mkwrite`, and maybe even jump over to something like `ntfs_read_folio` just to see the differences. I also need to verify that `filemap_invalidate_lock` isn't involved in page faults directly. I think I'm on to something here. Gotta compare these locking strategies to get a clear picture!
|
| 120/4 |
2026/09/17 10:54 |
tool |
grepper |
0m
Args: map[Expression:filemap_invalidate_lock PathPrefix:mm/]
Results: map[Output:mm/filemap.c=1021=EXPORT_SYMBOL(filemap_alloc_folio_noprof);
--
mm/filemap.c-1024-/*
mm/filemap.c:1025: * filemap_invalidate_lock_two - lock invalidate_lock for two mappings
mm/filemap.c-1026- *
--
mm/filemap.c-1031- */
mm/filemap.c:1032:void filemap_invalidate_lock_two(struct address_space *mapping1,
mm/filemap.c-1033- struct address_space *mapping2)
--
mm/filemap.c-1041-}
mm/filemap.c:1042:EXPORT_SYMBOL(filemap_invalidate_lock_two);
mm/filemap.c-1043-
--
mm/filemap.c=2563=static int filemap_update_page(struct kiocb *iocb,
--
mm/filemap.c-2572- } else {
mm/filemap.c:2573: filemap_invalidate_lock_shared(mapping);
mm/filemap.c-2574- }
--
mm/filemap.c=2619=static int filemap_create_folio(struct kiocb *iocb, struct folio_batch *fbatch)
--
mm/filemap.c-2648- */
mm/filemap.c:2649: filemap_invalidate_lock_shared(mapping);
mm/filemap.c-2650- index = (iocb->ki_pos >> (PAGE_SHIFT + min_order)) << min_order;
--
mm/filemap.c=3555=vm_fault_t filemap_fault(struct vm_fault *vmf)
--
mm/filemap.c-3584- if (unlikely(!folio_test_uptodate(folio))) {
mm/filemap.c:3585: filemap_invalidate_lock_shared(mapping);
mm/filemap.c-3586- mapping_locked = true;
--
mm/filemap.c-3603- if (!mapping_locked) {
mm/filemap.c:3604: filemap_invalidate_lock_shared(mapping);
mm/filemap.c-3605- mapping_locked = true;
--
mm/filemap.c=4572=int filemap_invalidate_inode(struct inode *inode, bool flush,
--
mm/filemap.c-4583- /* Prevent new folios from being added to the inode. */
mm/filemap.c:4584: filemap_invalidate_lock(mapping);
mm/filemap.c-4585-
--
mm/readahead.c=326=static void do_page_cache_ra(struct readahead_control *ractl,
--
mm/readahead.c-346-
mm/readahead.c:347: filemap_invalidate_lock_shared(mapping);
mm/readahead.c-348- page_cache_ra_unbounded(ractl, nr_to_read, lookahead_size);
--
mm/readahead.c=481=void page_cache_ra_order(struct readahead_control *ractl,
--
mm/readahead.c-516- nofs = memalloc_nofs_save();
mm/readahead.c:517: filemap_invalidate_lock_shared(mapping);
mm/readahead.c-518- /*
--
mm/secretmem.c=110=static vm_fault_t secretmem_fault(struct vm_fault *vmf)
--
mm/secretmem.c-124-
mm/secretmem.c:125: filemap_invalidate_lock_shared(mapping);
mm/secretmem.c-126-
--
mm/secretmem.c=241=static int secretmem_setattr(struct mnt_idmap *idmap,
--
mm/secretmem.c-248-
mm/secretmem.c:249: filemap_invalidate_lock(mapping);
mm/secretmem.c-250-
]
|
| 121/4 |
2026/09/17 10:54 |
tool |
grepper |
0m
Args: map[Expression:filemap_invalidate_lock PathPrefix:fs/]
Results: map[Output:fs/btrfs/volumes.c=1335=struct btrfs_super_block *btrfs_read_disk_super(struct block_device *bdev,
--
fs/btrfs/volumes.c-1366-
fs/btrfs/volumes.c:1367: filemap_invalidate_lock_shared(mapping);
fs/btrfs/volumes.c-1368- page = read_cache_page_gfp(mapping, bytenr >> PAGE_SHIFT, GFP_NOFS);
--
fs/btrfs/zoned.c=88=static int sb_write_pointer(struct block_device *bdev, struct blk_zone *zones,
--
fs/btrfs/zoned.c-133-
fs/btrfs/zoned.c:134: filemap_invalidate_lock_shared(mapping);
fs/btrfs/zoned.c-135- page[i] = read_cache_page_gfp(mapping,
--
fs/ceph/addr.c=1990=static vm_fault_t ceph_filemap_fault(struct vm_fault *vmf)
--
fs/ceph/addr.c-2045-
fs/ceph/addr.c:2046: filemap_invalidate_lock_shared(mapping);
fs/ceph/addr.c-2047- page = find_or_create_page(mapping, 0,
--
fs/ceph/file.c=2784=static long ceph_fallocate(struct file *file, int mode,
--
fs/ceph/file.c-2841-
fs/ceph/file.c:2842: filemap_invalidate_lock(inode->i_mapping);
fs/ceph/file.c-2843- ceph_fscache_invalidate(inode, false);
--
fs/exfat/file.c=754=static int exfat_extend_valid_size(struct inode *inode, loff_t new_valid_size)
--
fs/exfat/file.c-779- */
fs/exfat/file.c:780: filemap_invalidate_lock(inode->i_mapping);
fs/exfat/file.c-781- if (gap_start < new_valid_size)
--
fs/exfat/file.c=943=static vm_fault_t exfat_page_mkwrite(struct vm_fault *vmf)
--
fs/exfat/file.c-987-
fs/exfat/file.c:988: filemap_invalidate_lock_shared(inode->i_mapping);
fs/exfat/file.c-989- ret = iomap_page_mkwrite(vmf, &exfat_iomap_ops, NULL);
--
fs/ext2/inode.c=1224=static void ext2_truncate_blocks(struct inode *inode, loff_t offset)
--
fs/ext2/inode.c-1231-
fs/ext2/inode.c:1232: filemap_invalidate_lock(inode->i_mapping);
fs/ext2/inode.c-1233- __ext2_truncate_blocks(inode, offset);
--
fs/ext2/inode.c=1237=static int ext2_setsize(struct inode *inode, loff_t newsize)
--
fs/ext2/inode.c-1254-
fs/ext2/inode.c:1255: filemap_invalidate_lock(inode->i_mapping);
fs/ext2/inode.c-1256- truncate_setsize(inode, newsize);
--
fs/ext4/extents.c=4949=long ext4_fallocate(struct file *file, int mode, loff_t offset, loff_t len)
--
fs/ext4/extents.c-4999- */
fs/ext4/extents.c:5000: filemap_invalidate_lock(mapping);
fs/ext4/extents.c-5001-
--
fs/ext4/file.c=800=static vm_fault_t ext4_dax_huge_fault(struct vm_fault *vmf, unsigned int order)
--
fs/ext4/file.c-827- file_update_time(vmf->vma->vm_file);
fs/ext4/file.c:828: filemap_invalidate_lock_shared(mapping);
fs/ext4/file.c-829-retry:
--
fs/ext4/file.c-837- } else {
fs/ext4/file.c:838: filemap_invalidate_lock_shared(mapping);
fs/ext4/file.c-839- }
--
fs/ext4/inode.c=4432=static void ext4_wait_dax_page(struct inode *inode)
--
fs/ext4/inode.c-4435- schedule();
fs/ext4/inode.c:4436: filemap_invalidate_lock(inode->i_mapping);
fs/ext4/inode.c-4437-}
--
fs/ext4/inode.c=6009=int ext4_setattr(struct mnt_idmap *idmap, struct dentry *dentry,
--
fs/ext4/inode.c-6125-
fs/ext4/inode.c:6126: filemap_invalidate_lock(inode->i_mapping);
fs/ext4/inode.c-6127-
--
fs/ext4/inode.c=6740=int ext4_change_inode_journal_flag(struct inode *inode, int val)
--
fs/ext4/inode.c-6773- */
fs/ext4/inode.c:6774: filemap_invalidate_lock(inode->i_mapping);
fs/ext4/inode.c-6775- err = filemap_write_and_wait(inode->i_mapping);
--
fs/ext4/inode.c=6884=vm_fault_t ext4_page_mkwrite(struct vm_fault *vmf)
--
fs/ext4/inode.c-6903-
fs/ext4/inode.c:6904: filemap_invalidate_lock_shared(mapping);
fs/ext4/inode.c-6905-
--
fs/ext4/ioctl.c=375=static long swap_inode_boot_loader(struct super_block *sb,
--
fs/ext4/ioctl.c-411-
fs/ext4/ioctl.c:412: filemap_invalidate_lock(inode->i_mapping);
fs/ext4/ioctl.c-413- err = filemap_write_and_wait(inode->i_mapping);
--
fs/ext4/truncate.h=12=static inline void ext4_truncate_failed_write(struct inode *inode)
--
fs/ext4/truncate.h-19- */
fs/ext4/truncate.h:20: filemap_invalidate_lock(mapping);
fs/ext4/truncate.h-21- truncate_inode_pages(mapping, inode->i_size);
--
fs/f2fs/data.c=3646=void f2fs_write_failed(struct inode *inode, loff_t to)
--
fs/f2fs/data.c-3655- f2fs_down_write(&F2FS_I(inode)->i_gc_rwsem[WRITE]);
fs/f2fs/data.c:3656: filemap_invalidate_lock(inode->i_mapping);
fs/f2fs/data.c-3657-
--
fs/f2fs/data.c=4187=static int f2fs_migrate_blocks(struct inode *inode, block_t start_blk,
--
fs/f2fs/data.c-4202- f2fs_down_write(&F2FS_I(inode)->i_gc_rwsem[WRITE]);
fs/f2fs/data.c:4203: filemap_invalidate_lock(inode->i_mapping);
fs/f2fs/data.c-4204-
--
fs/f2fs/file.c=73=static int f2fs_zero_post_eof_page(struct inode *inode,
--
fs/f2fs/file.c-86- if (lock)
fs/f2fs/file.c:87: filemap_invalidate_lock(inode->i_mapping);
fs/f2fs/file.c-88- /* zero or drop pages only in range of [old_size, new_size] */
--
fs/f2fs/file.c=120=static vm_fault_t f2fs_vm_page_mkwrite(struct vm_fault *vmf)
--
fs/f2fs/file.c-186- file_update_time(vmf->vma->vm_file);
fs/f2fs/file.c:187: filemap_invalidate_lock_shared(inode->i_mapping);
fs/f2fs/file.c-188-
--
fs/f2fs/file.c=637=static int finish_preallocate_blocks(struct inode *inode)
--
fs/f2fs/file.c-655- f2fs_down_write(&F2FS_I(inode)->i_gc_rwsem[WRITE]);
fs/f2fs/file.c:656: filemap_invalidate_lock(inode->i_mapping);
fs/f2fs/file.c-657-
--
fs/f2fs/file.c=1124=int f2fs_setattr(struct mnt_idmap *idmap, struct dentry *dentry,
--
fs/f2fs/file.c-1227- f2fs_down_write(&fi->i_gc_rwsem[WRITE]);
fs/f2fs/file.c:1228: filemap_invalidate_lock(inode->i_mapping);
fs/f2fs/file.c-1229-
--
fs/f2fs/file.c=1346=static int f2fs_punch_hole(struct inode *inode, loff_t offset, loff_t len)
--
fs/f2fs/file.c-1394- f2fs_down_write(&F2FS_I(inode)->i_gc_rwsem[WRITE]);
fs/f2fs/file.c:1395: filemap_invalidate_lock(inode->i_mapping);
fs/f2fs/file.c-1396-
--
fs/f2fs/file.c=1630=static int f2fs_do_collapse(struct inode *inode, loff_t offset, loff_t len)
--
fs/f2fs/file.c-1642- f2fs_down_write(&F2FS_I(inode)->i_gc_rwsem[WRITE]);
fs/f2fs/file.c:1643: filemap_invalidate_lock(inode->i_mapping);
fs/f2fs/file.c-1644-
--
fs/f2fs/file.c=1661=static int f2fs_collapse_range(struct inode *inode, loff_t offset, loff_t len)
--
fs/f2fs/file.c-1686- /* write out all moved pages, if possible */
fs/f2fs/file.c:1687: filemap_invalidate_lock(inode->i_mapping);
fs/f2fs/file.c-1688- ret = filemap_write_and_wait_range(inode->i_mapping, offset, LLONG_MAX);
--
fs/f2fs/file.c=1755=static int f2fs_zero_range(struct inode *inode, loff_t offset, loff_t len,
--
fs/f2fs/file.c-1811- f2fs_down_write(&F2FS_I(inode)->i_gc_rwsem[WRITE]);
fs/f2fs/file.c:1812: filemap_invalidate_lock(mapping);
fs/f2fs/file.c-1813-
--
fs/f2fs/file.c=1868=static int f2fs_insert_range(struct inode *inode, loff_t offset, loff_t len)
--
fs/f2fs/file.c-1893-
fs/f2fs/file.c:1894: filemap_invalidate_lock(mapping);
fs/f2fs/file.c-1895- ret = f2fs_truncate_blocks(inode, i_size_read(inode), true);
--
fs/f2fs/file.c-1911- f2fs_down_write(&F2FS_I(inode)->i_gc_rwsem[WRITE]);
fs/f2fs/file.c:1912: filemap_invalidate_lock(mapping);
fs/f2fs/file.c-1913-
--
fs/f2fs/file.c-1940- /* write out all moved pages, if possible */
fs/f2fs/file.c:1941: filemap_invalidate_lock(mapping);
fs/f2fs/file.c-1942- ret = filemap_write_and_wait_range(mapping, offset, LLONG_MAX);
--
fs/f2fs/file.c=3879=static int f2fs_ioc_release_dev_alias(struct file *filp)
--
fs/f2fs/file.c-3928-
fs/f2fs/file.c:3929: filemap_invalidate_lock(inode->i_mapping);
fs/f2fs/file.c-3930- truncate_setsize(inode, 0);
--
fs/f2fs/file.c=4206=static int f2fs_release_compress_blocks(struct file *filp, unsigned long arg)
--
fs/f2fs/file.c-4257- f2fs_down_write(&fi->i_gc_rwsem[WRITE]);
fs/f2fs/file.c:4258: filemap_invalidate_lock(inode->i_mapping);
fs/f2fs/file.c-4259-
--
fs/f2fs/file.c=4403=static int f2fs_reserve_compress_blocks(struct file *filp, unsigned long arg)
--
fs/f2fs/file.c-4435- f2fs_down_write(&fi->i_gc_rwsem[WRITE]);
fs/f2fs/file.c:4436: filemap_invalidate_lock(inode->i_mapping);
fs/f2fs/file.c-4437-
--
fs/f2fs/file.c=4535=static int f2fs_sec_trim_file(struct file *filp, unsigned long arg)
--
fs/f2fs/file.c-4600- f2fs_down_write(&F2FS_I(inode)->i_gc_rwsem[WRITE]);
fs/f2fs/file.c:4601: filemap_invalidate_lock(mapping);
fs/f2fs/file.c-4602-
--
fs/f2fs/file.c=4794=static int redirty_blocks(struct inode *inode, pgoff_t page_idx, int len)
--
fs/f2fs/file.c-4801-
fs/f2fs/file.c:4802: filemap_invalidate_lock_shared(mapping);
fs/f2fs/file.c-4803- page_cache_ra_unbounded(&ractl, len, 0);
--
fs/f2fs/file.c=5631=static ssize_t f2fs_file_write_iter(struct kiocb *iocb, struct iov_iter *from)
--
fs/f2fs/file.c-5703- f2fs_down_write(&F2FS_I(inode)->i_gc_rwsem[WRITE]);
fs/f2fs/file.c:5704: filemap_invalidate_lock(inode->i_mapping);
fs/f2fs/file.c-5705- if (!f2fs_truncate(inode))
--
fs/fuse/dax.c=663=static void fuse_wait_dax_page(struct inode *inode)
--
fs/fuse/dax.c-666- schedule();
fs/fuse/dax.c:667: filemap_invalidate_lock(inode->i_mapping);
fs/fuse/dax.c-668-}
--
fs/fuse/dax.c=755=static vm_fault_t __fuse_dax_fault(struct vm_fault *vmf, unsigned int order,
--
fs/fuse/dax.c-778- */
fs/fuse/dax.c:779: filemap_invalidate_lock_shared(inode->i_mapping);
fs/fuse/dax.c-780- ret = dax_iomap_fault(vmf, order, &pfn, &error, &fuse_iomap_ops);
--
fs/fuse/dax.c=914=inode_inline_reclaim_one_dmap(struct fuse_conn_dax *fcd, struct inode *inode,
--
fs/fuse/dax.c-923-
fs/fuse/dax.c:924: filemap_invalidate_lock(inode->i_mapping);
fs/fuse/dax.c-925-
--
fs/fuse/dax.c=1076=static int lookup_and_reclaim_dmap(struct fuse_conn_dax *fcd,
--
fs/fuse/dax.c-1085-
fs/fuse/dax.c:1086: filemap_invalidate_lock(inode->i_mapping);
fs/fuse/dax.c-1087- ret = fuse_dax_break_layouts(inode, dmap_start, dmap_end);
--
fs/fuse/dir.c=2145=int fuse_do_setattr(struct mnt_idmap *idmap, struct dentry *dentry,
--
fs/fuse/dir.c-2177- if (FUSE_IS_DAX(inode) && is_truncate) {
fs/fuse/dir.c:2178: filemap_invalidate_lock(mapping);
fs/fuse/dir.c-2179- fault_blocked = true;
--
fs/fuse/file.c=250=static int fuse_open(struct inode *inode, struct file *file)
--
fs/fuse/file.c-271- if (dax_truncate) {
fs/fuse/file.c:272: filemap_invalidate_lock(inode->i_mapping);
fs/fuse/file.c-273- err = fuse_dax_break_layouts(inode, 0, -1);
--
fs/fuse/file.c=2832=static long fuse_file_fallocate(struct file *file, int mode, loff_t offset,
--
fs/fuse/file.c-2859- if (block_faults) {
fs/fuse/file.c:2860: filemap_invalidate_lock(inode->i_mapping);
fs/fuse/file.c-2861- err = fuse_dax_break_layouts(inode, 0, -1);
--
fs/ntfs/file.c=254=static int ntfs_setattr_size(struct inode *vi, struct iattr *attr)
--
fs/ntfs/file.c-278- */
fs/ntfs/file.c:279: filemap_invalidate_lock(vi->i_mapping);
fs/ntfs/file.c-280- if (attr->ia_size > old_size) {
--
fs/ntfs/file.c=676=static vm_fault_t ntfs_filemap_page_mkwrite(struct vm_fault *vmf)
--
fs/ntfs/file.c-691- */
fs/ntfs/file.c:692: filemap_invalidate_lock_shared(mapping);
fs/ntfs/file.c-693- ret = iomap_page_mkwrite(vmf, &ntfs_page_mkwrite_iomap_ops, NULL);
--
fs/ntfs/file.c=1127=static long ntfs_fallocate(struct file *file, int mode, loff_t offset, loff_t len)
--
fs/ntfs/file.c-1170- /* Take invalidate_lock for all fallocate operations to prevent races */
fs/ntfs/file.c:1171: filemap_invalidate_lock(vi->i_mapping);
fs/ntfs/file.c-1172-
--
fs/ntfs3/file.c=466=static long ntfs_fallocate(struct file *file, int mode, loff_t vbo, loff_t len)
--
fs/ntfs3/file.c-519- inode_dio_wait(inode);
fs/ntfs3/file.c:520: filemap_invalidate_lock(mapping);
fs/ntfs3/file.c-521- map_locked = true;
--
fs/smb/client/file.c=993=static int cifs_do_truncate(const unsigned int xid, struct dentry *dentry)
--
fs/smb/client/file.c-1005-
fs/smb/client/file.c:1006: filemap_invalidate_lock(inode->i_mapping);
fs/smb/client/file.c-1007-
--
fs/smb/client/smb2ops.c=3508=static long smb3_zero_range(struct file *file, struct cifs_tcon *tcon,
--
fs/smb/client/smb2ops.c-3531-
fs/smb/client/smb2ops.c:3532: filemap_invalidate_lock(inode->i_mapping);
fs/smb/client/smb2ops.c-3533-
--
fs/smb/client/smb2ops.c=3592=static long smb3_punch_hole(struct file *file, struct cifs_tcon *tcon,
--
fs/smb/client/smb2ops.c-3610-
fs/smb/client/smb2ops.c:3611: filemap_invalidate_lock(inode->i_mapping);
fs/smb/client/smb2ops.c-3612- /*
--
fs/smb/client/smb2ops.c=4014=static long smb3_collapse_range(struct file *file, struct cifs_tcon *tcon,
--
fs/smb/client/smb2ops.c-4032-
fs/smb/client/smb2ops.c:4033: filemap_invalidate_lock(inode->i_mapping);
fs/smb/client/smb2ops.c-4034- rc = filemap_write_and_wait_range(inode->i_mapping,
--
fs/smb/client/smb2ops.c=4078=static long smb3_insert_range(struct file *file, struct cifs_tcon *tcon,
--
fs/smb/client/smb2ops.c-4108-
fs/smb/client/smb2ops.c:4109: filemap_invalidate_lock(inode->i_mapping);
fs/smb/client/smb2ops.c-4110- rc = filemap_write_and_wait_range(inode->i_mapping,
--
fs/udf/file.c=38=static vm_fault_t udf_page_mkwrite(struct vm_fault *vmf)
--
fs/udf/file.c-50- file_update_time(vma->vm_file);
fs/udf/file.c:51: filemap_invalidate_lock_shared(mapping);
fs/udf/file.c-52- folio_lock(folio);
--
fs/udf/file.c=89=static ssize_t udf_file_write_iter(struct kiocb *iocb, struct iov_iter *from)
--
fs/udf/file.c-104- iocb->ki_pos + iov_iter_count(from))) {
fs/udf/file.c:105: filemap_invalidate_lock(inode->i_mapping);
fs/udf/file.c-106- retval = udf_expand_file_adinicb(inode);
--
fs/udf/file.c=215=static int udf_setattr(struct mnt_idmap *idmap, struct dentry *dentry,
--
fs/udf/file.c-236- attr->ia_size != i_size_read(inode)) {
fs/udf/file.c:237: filemap_invalidate_lock(inode->i_mapping);
fs/udf/file.c-238- error = udf_setsize(inode, attr->ia_size);
--
fs/verity/read_metadata.c=16=static int fsverity_read_merkle_tree(struct inode *inode,
--
fs/verity/read_metadata.c-38- if (inode->i_sb->s_vop->readahead_merkle_tree) {
fs/verity/read_metadata.c:39: filemap_invalidate_lock_shared(inode->i_mapping);
fs/verity/read_metadata.c-40- inode->i_sb->s_vop->readahead_merkle_tree(
--
fs/xfs/xfs_bmap_util.c=1537=xfs_swap_extents(
--
fs/xfs/xfs_bmap_util.c-1558- lock_two_nondirectories(VFS_I(ip), VFS_I(tip));
fs/xfs/xfs_bmap_util.c:1559: filemap_invalidate_lock_two(VFS_I(ip)->i_mapping,
fs/xfs/xfs_bmap_util.c-1560- VFS_I(tip)->i_mapping);
--
fs/xfs/xfs_inode.c=2792=xfs_ilock2_io_mmap(
--
fs/xfs/xfs_inode.c-2810- } else
fs/xfs/xfs_inode.c:2811: filemap_invalidate_lock_two(VFS_I(ip1)->i_mapping,
fs/xfs/xfs_inode.c-2812- VFS_I(ip2)->i_mapping);
--
fs/xfs/xfs_iomap.c=2134=xfs_buffered_write_iomap_end(
--
fs/xfs/xfs_iomap.c-2167- } else {
fs/xfs/xfs_iomap.c:2168: filemap_invalidate_lock(inode->i_mapping);
fs/xfs/xfs_iomap.c-2169- iomap_write_delalloc_release(inode, start_byte, end_byte, flags,
--
fs/zonefs/file.c=203=int zonefs_file_truncate(struct inode *inode, loff_t isize)
--
fs/zonefs/file.c-228- /* Serialize against page faults */
fs/zonefs/file.c:229: filemap_invalidate_lock(inode->i_mapping);
fs/zonefs/file.c-230-
--
fs/zonefs/file.c=297=static vm_fault_t zonefs_filemap_page_mkwrite(struct vm_fault *vmf)
--
fs/zonefs/file.c-315- /* Serialize against truncates */
fs/zonefs/file.c:316: filemap_invalidate_lock_shared(inode->i_mapping);
fs/zonefs/file.c-317- ret = iomap_page_mkwrite(vmf, &zonefs_write_iomap_ops, NULL);
]
|
| 122/4 |
2026/09/17 10:54 |
llm |
codeexpert |
0m
Model:
Tokens:
input: 29291
output: 37
thoughts: 45
Thoughts: Here's my take on those instructions, as if I'm the one thinking them:
**Diving into NTFS3 File Allocation**
Okay, time to get my hands dirty with this `ntfs3` code. Let's see... I need to refresh my memory on the file allocation implementation. Right, let's start by zeroing in on `fs/ntfs3/file.c`. Specifically, I want to jump over to line 520. That should give me a good jumping-off point to understand the core structures being used.
Then, I need to understand the details of `ntfs_fallocate` in `fs/ntfs3/file.c`. This is where the real work of file pre-allocation and sparse file management happens. I want to trace the code path and see how it interacts with the underlying disk structures and metadata. Knowing this function is crucial to understanding the details of how `ntfs3` handles space on the volume! Let's get to it!
|
| 123/4 |
2026/09/17 10:54 |
tool |
read-file |
0m
Args: map[File:fs/ntfs3/file.c FirstLine:515 LineCount:50]
Results: map[Contents: 515: }
516:
517: if (mode & (FALLOC_FL_PUNCH_HOLE | FALLOC_FL_COLLAPSE_RANGE |
518: FALLOC_FL_INSERT_RANGE)) {
519: inode_dio_wait(inode);
520: filemap_invalidate_lock(mapping);
521: map_locked = true;
522: }
523:
524: if (mode & FALLOC_FL_PUNCH_HOLE) {
525: u32 frame_size;
526: loff_t mask, vbo_a, end_a, tmp, from;
527:
528: err = filemap_write_and_wait_range(mapping, vbo_down,
529: LLONG_MAX);
530: if (err)
531: goto out;
532:
533: truncate_pagecache(inode, vbo_down);
534:
535: ni_lock(ni);
536: err = attr_punch_hole(ni, vbo, len, &frame_size);
537: ni_unlock(ni);
538: if (!err)
539: goto ok;
540:
541: if (err != E_NTFS_NOTALIGNED)
542: goto out;
543:
544: /* Process not aligned punch. */
545: err = 0;
546: if (end > i_size)
547: end = i_size;
548: mask = frame_size - 1;
549: vbo_a = (vbo + mask) & ~mask;
550: end_a = end & ~mask;
551:
552: tmp = min(vbo_a, end);
553: from = min_t(loff_t, ni->i_valid, vbo);
554: /* Zero head of punch. */
555: if (tmp > from) {
556: err = iomap_zero_range(inode, from, tmp - from, NULL,
557: &ntfs_iomap_ops,
558: &ntfs_iomap_folio_ops, NULL);
559: if (err)
560: goto out;
561: }
562:
563: /* Aligned punch_hole. Deallocate clusters. */
564: if (end_a > vbo_a) {
]
|
| 124/4 |
2026/09/17 10:54 |
llm |
codeexpert |
0m
Model:
Tokens:
input: 30335
output: 36
thoughts: 80
Thoughts: Here's my take on the thought process, as requested:
**Diving into `ntfs_setattr_size`**
Okay, so I need to understand how file size attributes are handled within the NTFS filesystem, specifically in the legacy implementation, or whatever they're calling it these days. The goal is to see exactly what `fs/ntfs/file.c` does in relation to the function `ntfs_setattr_size`. I know that function is the key to managing file size updates, and I'm itching to dig into the guts of how it works at line 254. Let's see how that handles the `iattr` struct and modifies the inode.
|
| 125/4 |
2026/09/17 10:55 |
tool |
read-file |
0m
Args: map[File:fs/ntfs/file.c FirstLine:254 LineCount:50]
Results: map[Contents: 254: static int ntfs_setattr_size(struct inode *vi, struct iattr *attr)
255: {
256: struct ntfs_inode *ni = NTFS_I(vi);
257: int err;
258: loff_t old_size = vi->i_size;
259:
260: if (NInoCompressed(ni) || NInoEncrypted(ni) || NInoWofCompressed(ni)) {
261: ntfs_warning(
262: vi->i_sb,
263: "Changes in inode size are not supported yet for %s files.",
264: NInoEncrypted(ni) ? "encrypted" : "compressed");
265: return -EOPNOTSUPP;
266: }
267:
268: err = inode_newsize_ok(vi, attr->ia_size);
269: if (err)
270: return err;
271:
272: inode_dio_wait(vi);
273:
274: /*
275: * Serialize with page faults and pagecache instantiation so that
276: * readers cannot observe the size change until the attribute
277: * updates below have completed.
278: */
279: filemap_invalidate_lock(vi->i_mapping);
280: if (attr->ia_size > old_size) {
281: truncate_pagecache(vi, old_size);
282: i_size_write(vi, attr->ia_size);
283: pagecache_isize_extended(vi, old_size, attr->ia_size);
284: } else {
285: truncate_setsize(vi, attr->ia_size);
286: }
287:
288: err = ntfs_truncate_vfs(vi, attr->ia_size, old_size);
289: if (err)
290: i_size_write(vi, old_size);
291: filemap_invalidate_unlock(vi->i_mapping);
292:
293: return err;
294: }
295:
296: /*
297: * ntfs_setattr
298: *
299: * Called from notify_change() when an attribute is being changed.
300: *
301: * NOTE: Changes in inode size are not supported yet for compressed or
302: * encrypted files.
303: */
]
|
| 126/4 |
2026/09/17 10:55 |
llm |
codeexpert |
0m
Model:
Tokens:
input: 31339
output: 36
thoughts: 68
Thoughts: **Investigating a Recent NTFS File System Behavior**
Okay, so I'm diving into this `fs/ntfs/file.c` file again, specifically lines 274 to 291. Something there is catching my eye β maybe a performance anomaly, or potentially a subtle bug I need to understand better. But hold on, I need some context. When was this particular section of code introduced? What commit touched these lines?
Time to use the tools. I'll reach for `git blame` or `git log` and pinpoint the exact commit that brought that code into `fs/ntfs/file.c` at line 274. That'll provide the crucial history and hopefully the rationale behind the change. Understanding the "why" will allow me to assess the "what" with much more accuracy.
|
| 127/4 |
2026/09/17 10:55 |
tool |
git-blame |
0m
Args: map[End:292 File:fs/ntfs/file.c Start:274]
Results: map[Output:^fd73f4a66598 274) /*
^fd73f4a66598 275) * Serialize with page faults and pagecache instantiation so that
^fd73f4a66598 276) * readers cannot observe the size change until the attribute
^fd73f4a66598 277) * updates below have completed.
^fd73f4a66598 278) */
^fd73f4a66598 279) filemap_invalidate_lock(vi->i_mapping);
^fd73f4a66598 280) if (attr->ia_size > old_size) {
^fd73f4a66598 281) truncate_pagecache(vi, old_size);
^fd73f4a66598 282) i_size_write(vi, attr->ia_size);
^fd73f4a66598 283) pagecache_isize_extended(vi, old_size, attr->ia_size);
^fd73f4a66598 284) } else {
^fd73f4a66598 285) truncate_setsize(vi, attr->ia_size);
^fd73f4a66598 286) }
^fd73f4a66598 287)
^fd73f4a66598 288) err = ntfs_truncate_vfs(vi, attr->ia_size, old_size);
^fd73f4a66598 289) if (err)
^fd73f4a66598 290) i_size_write(vi, old_size);
^fd73f4a66598 291) filemap_invalidate_unlock(vi->i_mapping);
^fd73f4a66598 292)
]
|
| 128/4 |
2026/09/17 10:55 |
llm |
codeexpert |
0m
Model:
Tokens:
input: 32178
output: 30
thoughts: 50
Thoughts: Okay, here's my interpretation of that thought process, assuming I'm deep in the weeds of kernel development:
**Initial Confusion and Investigation**
Wait a minute, `fs/ntfs/file.c`? That's... unexpected. I could have sworn we were on `ntfs3` and I haven't heard about another NTFS implementation. Is this a completely new driver? Or is this a subtle refactor, perhaps a backport, or maybe even a rename in a different branch? Time to dig deeper. I need context. Let's see what's changed around that file with that commit ID: `fd73f4a66598`. That should give me the crucial details.
|
| 129/4 |
2026/09/17 10:55 |
tool |
git-show |
0m
Args: map[Commit:fd73f4a66598 Stat:true]
Results: map[Output:commit fd73f4a6659897191fa0d40695fe370925dd3780
Author: Linus Torvalds <torvalds@linux-foundation.org>
Date: Sun Sep 13 14:38:02 2026 -0700
Linux 7.3-rc3
.clang-format | 808 +
.clippy.toml | 21 +
.cocciconfig | 3 +
.editorconfig | 27 +
.get_maintainer.ignore | 9 +
.gitattributes | 5 +
.gitignore | 196 +
.mailmap | 996 +
.pylintrc | 2 +
.rustfmt.toml | 12 +
COPYING | 20 +
CREDITS | 4651 +
Documentation/.gitignore | 3 +
Documentation/.renames.txt | 1185 +
Documentation/ABI/README | 98 +
.../ABI/obsolete/automount-tracefs-debugfs | 20 +
Documentation/ABI/obsolete/o2cb | 11 +
Documentation/ABI/obsolete/procfs-i8k | 10 +
Documentation/ABI/obsolete/sysfs-bus-iio | 174 +
Documentation/ABI/obsolete/sysfs-bus-usb | 31 +
Documentation/ABI/obsolete/sysfs-class-typec | 48 +
Documentation/ABI/obsolete/sysfs-cpuidle | 9 +
.../ABI/obsolete/sysfs-driver-hid-roccat-arvo | 53 +
.../ABI/obsolete/sysfs-driver-hid-roccat-isku | 153 +
.../ABI/obsolete/sysfs-driver-hid-roccat-koneplus | 145 +
.../ABI/obsolete/sysfs-driver-hid-roccat-konepure | 105 +
.../ABI/obsolete/sysfs-driver-hid-roccat-kovaplus | 116 +
.../ABI/obsolete/sysfs-driver-hid-roccat-lua | 7 +
.../ABI/obsolete/sysfs-driver-hid-roccat-pyra | 126 +
.../ABI/obsolete/sysfs-driver-hid-roccat-ryos | 178 +
.../ABI/obsolete/sysfs-driver-hid-roccat-savu | 77 +
.../ABI/obsolete/sysfs-driver-intel_pmc_bxt | 22 +
Documentation/ABI/obsolete/sysfs-driver-ivpu | 30 +
.../ABI/obsolete/sysfs-driver-samsung-laptop | 10 +
Documentation/ABI/obsolete/sysfs-firmware-acpi | 8 +
Documentation/ABI/obsolete/sysfs-gpio | 40 +
.../ABI/obsolete/sysfs-kernel-fadump_enabled | 9 +
.../ABI/obsolete/sysfs-kernel-fadump_registered | 10 +
.../ABI/obsolete/sysfs-kernel-fadump_release_mem | 10 +
.../ABI/obsolete/sysfs-kernel-kexec-kdump | 71 +
.../ABI/obsolete/sysfs-platform-ideapad-laptop | 8 +
Documentation/ABI/removed/devfs | 13 +
Documentation/ABI/removed/dv1394 | 14 +
Documentation/ABI/removed/ip_queue | 9 +
Documentation/ABI/removed/net_dma | 8 +
Documentation/ABI/removed/o2cb | 10 +
Documentation/ABI/removed/raw1394 | 16 +
Documentation/ABI/removed/sysfs-bus-nfit | 17 +
Documentation/ABI/removed/sysfs-class-cxl | 272 +
Documentation/ABI/removed/sysfs-class-rfkill | 13 +
Documentation/ABI/removed/sysfs-firmware-efi-vars | 12 +
.../removed/sysfs-kernel-fadump_release_opalcore | 9 +
Documentation/ABI/removed/sysfs-kernel-uids | 14 +
Documentation/ABI/removed/sysfs-mce | 37 +
.../ABI/removed/sysfs-selinux-checkreqprot | 26 +
Documentation/ABI/removed/sysfs-selinux-disable | 29 +
Documentation/ABI/removed/sysfs-selinux-user | 12 +
Documentation/ABI/removed/video1394 | 17 +
Documentation/ABI/stable/configfs-nvmet | 352 +
Documentation/ABI/stable/firewire-cdev | 111 +
Documentation/ABI/stable/o2cb | 10 +
Documentation/ABI/stable/procfs-audit_loginuid | 27 +
Documentation/ABI/stable/syscalls | 10 +
Documentation/ABI/stable/sysfs-acpi-pmprofile | 28 +
Documentation/ABI/stable/sysfs-block | 941 +
Documentation/ABI/stable/sysfs-bus-firewire | 136 +
Documentation/ABI/stable/sysfs-bus-fsl-mc | 19 +
Documentation/ABI/stable/sysfs-bus-mhi | 44 +
Documentation/ABI/stable/sysfs-bus-nvmem | 50 +
Documentation/ABI/stable/sysfs-bus-usb | 142 +
Documentation/ABI/stable/sysfs-bus-vmbus | 187 +
Documentation/ABI/stable/sysfs-bus-w1 | 12 +
Documentation/ABI/stable/sysfs-bus-xen-backend | 84 +
Documentation/ABI/stable/sysfs-class-backlight | 63 +
Documentation/ABI/stable/sysfs-class-bluetooth | 9 +
Documentation/ABI/stable/sysfs-class-infiniband | 784 +
Documentation/ABI/stable/sysfs-class-rfkill | 93 +
Documentation/ABI/stable/sysfs-class-tpm | 210 +
Documentation/ABI/stable/sysfs-class-ubi | 221 +
Documentation/ABI/stable/sysfs-class-udc | 93 +
Documentation/ABI/stable/sysfs-devices | 32 +
Documentation/ABI/stable/sysfs-devices-node | 238 +
Documentation/ABI/stable/sysfs-devices-system-cpu | 117 +
.../ABI/stable/sysfs-devices-system-xen_memory | 86 +
Documentation/ABI/stable/sysfs-driver-aspeed-vuart | 24 +
Documentation/ABI/stable/sysfs-driver-dma-idxd | 376 +
Documentation/ABI/stable/sysfs-driver-dma-ioatdma | 30 +
.../ABI/stable/sysfs-driver-firmware-zynqmp | 256 +
Documentation/ABI/stable/sysfs-driver-ib_srp | 192 +
Documentation/ABI/stable/sysfs-driver-misc-cp500 | 25 +
Documentation/ABI/stable/sysfs-driver-mlxreg-io | 815 +
Documentation/ABI/stable/sysfs-driver-qaic | 19 +
Documentation/ABI/stable/sysfs-driver-qla2xxx | 8 +
Documentation/ABI/stable/sysfs-driver-speakup | 394 +
Documentation/ABI/stable/sysfs-driver-usb-usbtmc | 27 +
Documentation/ABI/stable/sysfs-driver-w1_ds2438 | 13 +
Documentation/ABI/stable/sysfs-driver-w1_ds28e04 | 15 +
Documentation/ABI/stable/sysfs-driver-w1_ds28ea00 | 6 +
Documentation/ABI/stable/sysfs-firmware-opal-dump | 46 +
Documentation/ABI/stable/sysfs-firmware-opal-elog | 62 +
Documentation/ABI/stable/sysfs-fs-orangefs | 87 +
Documentation/ABI/stable/sysfs-hypervisor-xen | 135 +
Documentation/ABI/stable/sysfs-kernel-notes | 5 +
.../ABI/stable/sysfs-kernel-time-aux-clocks | 5 +
Documentation/ABI/stable/sysfs-module | 47 +
Documentation/ABI/stable/sysfs-nvme | 453 +
Documentation/ABI/stable/sysfs-platform-wmi-bmof | 7 +
Documentation/ABI/stable/sysfs-transport-srp | 58 +
Documentation/ABI/stable/thermal-notification | 4 +
Documentation/ABI/stable/vdso | 37 +
Documentation/ABI/testing/amdpmf-interface | 73 +
Documentation/ABI/testing/configfs-acpi | 52 +
Documentation/ABI/testing/configfs-iio | 34 +
Documentation/ABI/testing/configfs-most | 241 +
Documentation/ABI/testing/configfs-rdma_cm | 34 +
.../ABI/testing/configfs-spear-pcie-gadget | 33 +
Documentation/ABI/testing/configfs-stp-policy | 48 +
.../ABI/testing/configfs-stp-policy-p_sys-t | 41 +
.../ABI/testing/configfs-thunderbolt_stream | 98 +
Documentation/ABI/testing/configfs-tsm-report | 161 +
Documentation/ABI/testing/configfs-usb-gadget | 158 +
Documentation/ABI/testing/configfs-usb-gadget-acm | 15 +
Documentation/ABI/testing/configfs-usb-gadget-ecm | 20 +
Documentation/ABI/testing/configfs-usb-gadget-eem | 16 +
Documentation/ABI/testing/configfs-usb-gadget-ffs | 17 +
Documentation/ABI/testing/configfs-usb-gadget-hid | 13 +
.../ABI/testing/configfs-usb-gadget-loopback | 10 +
.../ABI/testing/configfs-usb-gadget-mass-storage | 41 +
Documentation/ABI/testing/configfs-usb-gadget-midi | 15 +
.../ABI/testing/configfs-usb-gadget-midi2 | 54 +
Documentation/ABI/testing/configfs-usb-gadget-ncm | 15 +
Documentation/ABI/testing/configfs-usb-gadget-obex | 9 +
.../ABI/testing/configfs-usb-gadget-phonet | 8 +
.../ABI/testing/configfs-usb-gadget-printer | 11 +
.../ABI/testing/configfs-usb-gadget-rndis | 19 +
.../ABI/testing/configfs-usb-gadget-serial | 9 +
.../ABI/testing/configfs-usb-gadget-sourcesink | 16 +
.../ABI/testing/configfs-usb-gadget-subset | 16 +
Documentation/ABI/testing/configfs-usb-gadget-tcm | 6 +
Documentation/ABI/testing/configfs-usb-gadget-uac1 | 41 +
.../ABI/testing/configfs-usb-gadget-uac1_legacy | 9 +
Documentation/ABI/testing/configfs-usb-gadget-uac2 | 51 +
Documentation/ABI/testing/configfs-usb-gadget-uvc | 438 +
Documentation/ABI/testing/debugfs-alienware-wmi | 64 +
Documentation/ABI/testing/debugfs-amd-iommu | 131 +
Documentation/ABI/testing/debugfs-cdns-pcie | 5 +
Documentation/ABI/testing/debugfs-cec-error-inj | 40 +
Documentation/ABI/testing/debugfs-cros-ec | 78 +
Documentation/ABI/testing/debugfs-cxl | 157 +
Documentation/ABI/testing/debugfs-dell-wmi-ddv | 34 +
Documentation/ABI/testing/debugfs-driver-dcc | 127 +
Documentation/ABI/testing/debugfs-driver-genwqe | 91 +
.../ABI/testing/debugfs-driver-habanalabs | 323 +
Documentation/ABI/testing/debugfs-driver-qat | 109 +
.../ABI/testing/debugfs-driver-qat_telemetry | 259 +
Documentation/ABI/testing/debugfs-dwc-pcie | 157 +
Documentation/ABI/testing/debugfs-ec | 21 +
Documentation/ABI/testing/debugfs-hisi-hpre | 200 +
Documentation/ABI/testing/debugfs-hisi-migration | 25 +
Documentation/ABI/testing/debugfs-hisi-sec | 173 +
Documentation/ABI/testing/debugfs-hisi-zip | 174 +
Documentation/ABI/testing/debugfs-hyperv | 23 +
Documentation/ABI/testing/debugfs-ideapad | 19 +
Documentation/ABI/testing/debugfs-iio-ad9467 | 39 +
Documentation/ABI/testing/debugfs-iio-backend | 20 +
Documentation/ABI/testing/debugfs-intel-iommu | 276 +
Documentation/ABI/testing/debugfs-moxtet | 35 +
Documentation/ABI/testing/debugfs-msi-wmi-platform | 14 +
Documentation/ABI/testing/debugfs-olpc | 16 +
Documentation/ABI/testing/debugfs-pcie-ptm | 70 +
Documentation/ABI/testing/debugfs-pfo-nx-crypto | 45 +
Documentation/ABI/testing/debugfs-scmi | 70 +
Documentation/ABI/testing/debugfs-scmi-raw | 208 +
Documentation/ABI/testing/debugfs-tpmi | 40 +
Documentation/ABI/testing/debugfs-vfio | 57 +
Documentation/ABI/testing/debugfs-wilco-ec | 45 +
Documentation/ABI/testing/dell-smbios-wmi | 41 +
Documentation/ABI/testing/dev-kmsg | 127 +
Documentation/ABI/testing/devlink-resource-mlxsw | 33 +
Documentation/ABI/testing/evm | 109 +
Documentation/ABI/testing/gpio-cdev | 28 +
Documentation/ABI/testing/ima_policy | 196 +
Documentation/ABI/testing/ppc-memtrace | 46 +
Documentation/ABI/testing/procfs-attr-current | 20 +
Documentation/ABI/testing/procfs-attr-exec | 20 +
Documentation/ABI/testing/procfs-attr-prev | 19 +
Documentation/ABI/testing/procfs-diskstats | 43 +
.../ABI/testing/procfs-nfsd-reply_cache_stats | 38 +
Documentation/ABI/testing/procfs-smaps_rollup | 42 +
Documentation/ABI/testing/pstore | 47 +
Documentation/ABI/testing/rtc-cdev | 50 +
Documentation/ABI/testing/securityfs-secrets-coco | 51 +
Documentation/ABI/testing/sysfs-amd-pmc | 13 +
Documentation/ABI/testing/sysfs-amd-pmf | 13 +
Documentation/ABI/testing/sysfs-ata | 140 +
.../ABI/testing/sysfs-auxdisplay-linedisp | 90 +
Documentation/ABI/testing/sysfs-block-aoe | 45 +
Documentation/ABI/testing/sysfs-block-bcache | 149 +
Documentation/ABI/testing/sysfs-block-device | 119 +
Documentation/ABI/testing/sysfs-block-dm | 47 +
Documentation/ABI/testing/sysfs-block-loop | 50 +
Documentation/ABI/testing/sysfs-block-rnbd | 64 +
Documentation/ABI/testing/sysfs-block-rssd | 5 +
Documentation/ABI/testing/sysfs-block-zram | 166 +
Documentation/ABI/testing/sysfs-bus-acpi | 98 +
Documentation/ABI/testing/sysfs-bus-amba | 20 +
Documentation/ABI/testing/sysfs-bus-auxiliary | 9 +
Documentation/ABI/testing/sysfs-bus-bcma | 31 +
Documentation/ABI/testing/sysfs-bus-cdx | 121 +
Documentation/ABI/testing/sysfs-bus-coreboot | 45 +
.../ABI/testing/sysfs-bus-coresight-devices-cti | 247 +
.../sysfs-bus-coresight-devices-dummy-source | 21 +
.../ABI/testing/sysfs-bus-coresight-devices-etb10 | 88 +
.../ABI/testing/sysfs-bus-coresight-devices-etm3x | 328 +
.../ABI/testing/sysfs-bus-coresight-devices-etm4x | 532 +
.../ABI/testing/sysfs-bus-coresight-devices-funnel | 18 +
.../ABI/testing/sysfs-bus-coresight-devices-stm | 59 +
.../ABI/testing/sysfs-bus-coresight-devices-tmc | 115 +
.../ABI/testing/sysfs-bus-coresight-devices-tpda | 69 +
.../ABI/testing/sysfs-bus-coresight-devices-tpdm | 290 +
.../ABI/testing/sysfs-bus-coresight-devices-trbe | 20 +
.../testing/sysfs-bus-coresight-devices-ultra_smb | 31 +
Documentation/ABI/testing/sysfs-bus-counter | 477 +
Documentation/ABI/testing/sysfs-bus-css | 56 +
Documentation/ABI/testing/sysfs-bus-cxl | 646 +
Documentation/ABI/testing/sysfs-bus-dax | 177 +
Documentation/ABI/testing/sysfs-bus-dfl | 17 +
.../ABI/testing/sysfs-bus-dfl-devices-emif | 25 +
.../ABI/testing/sysfs-bus-dfl-devices-n3000-nios | 47 +
.../ABI/testing/sysfs-bus-event_source-devices | 24 +
.../testing/sysfs-bus-event_source-devices-caps | 24 +
.../testing/sysfs-bus-event_source-devices-dfl_fme | 104 +
.../ABI/testing/sysfs-bus-event_source-devices-dsa | 30 +
.../testing/sysfs-bus-event_source-devices-events | 102 +
.../testing/sysfs-bus-event_source-devices-format | 21 +
.../sysfs-bus-event_source-devices-hisi_ptt | 113 +
.../testing/sysfs-bus-event_source-devices-hv_24x7 | 98 +
.../testing/sysfs-bus-event_source-devices-hv_gpci | 242 +
.../testing/sysfs-bus-event_source-devices-iommu | 37 +
.../testing/sysfs-bus-event_source-devices-rdpmc | 44 +
.../testing/sysfs-bus-event_source-devices-uncore | 13 +
.../testing/sysfs-bus-event_source-devices-vpa-dtl | 25 +
.../testing/sysfs-bus-event_source-devices-vpa-pmu | 25 +
Documentation/ABI/testing/sysfs-bus-fcoe | 138 +
Documentation/ABI/testing/sysfs-bus-fsi | 46 +
.../ABI/testing/sysfs-bus-fsi-devices-sbefifo | 10 +
Documentation/ABI/testing/sysfs-bus-fsl-mc | 25 +
Documentation/ABI/testing/sysfs-bus-hsi | 19 +
.../ABI/testing/sysfs-bus-i2c-devices-bq32k | 7 +
.../ABI/testing/sysfs-bus-i2c-devices-fsa9480 | 27 +
.../ABI/testing/sysfs-bus-i2c-devices-hm6352 | 21 +
.../ABI/testing/sysfs-bus-i2c-devices-lm3533 | 15 +
.../ABI/testing/sysfs-bus-i2c-devices-m24lr | 100 +
.../ABI/testing/sysfs-bus-i2c-devices-pca954x | 23 +
.../testing/sysfs-bus-i2c-devices-turris-omnia-mcu | 113 +
Documentation/ABI/testing/sysfs-bus-i3c | 194 +
Documentation/ABI/testing/sysfs-bus-iio | 2511 +
.../ABI/testing/sysfs-bus-iio-accel-adxl372 | 7 +
.../ABI/testing/sysfs-bus-iio-accel-bmc150 | 7 +
Documentation/ABI/testing/sysfs-bus-iio-ad9739a | 19 +
.../ABI/testing/sysfs-bus-iio-adc-ad-sigma-delta | 23 +
Documentation/ABI/testing/sysfs-bus-iio-adc-ad4130 | 20 +
Documentation/ABI/testing/sysfs-bus-iio-adc-ad7192 | 27 +
.../ABI/testing/sysfs-bus-iio-adc-ad7280a | 13 +
.../testing/sysfs-bus-iio-adc-envelope-detector | 39 +
Documentation/ABI/testing/sysfs-bus-iio-adc-hi8435 | 48 +
.../ABI/testing/sysfs-bus-iio-adc-max11410 | 13 +
.../ABI/testing/sysfs-bus-iio-adc-mcp3564 | 53 +
Documentation/ABI/testing/sysfs-bus-iio-adc-mt6360 | 78 +
.../ABI/testing/sysfs-bus-iio-adc-pac1934 | 9 +
Documentation/ABI/testing/sysfs-bus-iio-adc-stm32 | 21 +
Documentation/ABI/testing/sysfs-bus-iio-bno055 | 81 +
Documentation/ABI/testing/sysfs-bus-iio-cdc-ad7746 | 11 +
.../ABI/testing/sysfs-bus-iio-chemical-sgp40 | 17 +
.../ABI/testing/sysfs-bus-iio-chemical-sunrise-co2 | 38 +
.../ABI/testing/sysfs-bus-iio-chemical-vz89x | 7 +
Documentation/ABI/testing/sysfs-bus-iio-cros-ec | 21 +
Documentation/ABI/testing/sysfs-bus-iio-dac | 61 +
Documentation/ABI/testing/sysfs-bus-iio-dac-ad5766 | 31 +
.../ABI/testing/sysfs-bus-iio-dac-dpot-dac | 8 +
.../ABI/testing/sysfs-bus-iio-dac-ltc2688 | 55 +
.../ABI/testing/sysfs-bus-iio-dfsdm-adc-stm32 | 22 +
.../ABI/testing/sysfs-bus-iio-distance-srf08 | 17 +
Documentation/ABI/testing/sysfs-bus-iio-dma-buffer | 19 +
.../ABI/testing/sysfs-bus-iio-filter-admv8818 | 18 +
Documentation/ABI/testing/sysfs-bus-iio-flow | 21 +
Documentation/ABI/testing/sysfs-bus-iio-frequency | 11 +
.../ABI/testing/sysfs-bus-iio-frequency-ad9523 | 31 +
.../ABI/testing/sysfs-bus-iio-frequency-adf4350 | 11 +
.../ABI/testing/sysfs-bus-iio-frequency-adf4371 | 11 +
.../ABI/testing/sysfs-bus-iio-frequency-admv1013 | 38 +
.../ABI/testing/sysfs-bus-iio-frequency-admv1014 | 23 +
.../ABI/testing/sysfs-bus-iio-gyro-bmg160 | 7 +
.../ABI/testing/sysfs-bus-iio-health-afe440x | 39 +
Documentation/ABI/testing/sysfs-bus-iio-humidity | 10 +
.../sysfs-bus-iio-impedance-analyzer-ad5933 | 35 +
Documentation/ABI/testing/sysfs-bus-iio-ina2xx-adc | 15 +
.../ABI/testing/sysfs-bus-iio-inv_icm42600 | 18 +
Documentation/ABI/testing/sysfs-bus-iio-isl29501 | 47 +
.../ABI/testing/sysfs-bus-iio-light-isl29018 | 21 +
.../ABI/testing/sysfs-bus-iio-light-lm3533-als | 56 +
.../ABI/testing/sysfs-bus-iio-light-si1133 | 22 +
.../ABI/testing/sysfs-bus-iio-light-tsl2583 | 20 +
.../ABI/testing/sysfs-bus-iio-light-tsl2772 | 13 +
.../ABI/testing/sysfs-bus-iio-magnetometer-hmc5843 | 20 +
Documentation/ABI/testing/sysfs-bus-iio-meas-spec | 7 +
Documentation/ABI/testing/sysfs-bus-iio-mpu6050 | 13 +
.../testing/sysfs-bus-iio-potentiometer-mcp4531 | 8 +
Documentation/ABI/testing/sysfs-bus-iio-proximity | 24 +
.../ABI/testing/sysfs-bus-iio-proximity-as3935 | 15 +
.../ABI/testing/sysfs-bus-iio-resolver-ad2s1210 | 27 +
Documentation/ABI/testing/sysfs-bus-iio-sps30 | 28 +
Documentation/ABI/testing/sysfs-bus-iio-sx9310 | 10 +
Documentation/ABI/testing/sysfs-bus-iio-sx9324 | 29 +
.../ABI/testing/sysfs-bus-iio-thermocouple | 18 +
.../ABI/testing/sysfs-bus-iio-timer-stm32 | 143 +
.../ABI/testing/sysfs-bus-iio-trigger-sysfs | 42 +
Documentation/ABI/testing/sysfs-bus-iio-vf610 | 16 +
.../ABI/testing/sysfs-bus-intel_th-devices-gth | 52 +
.../ABI/testing/sysfs-bus-intel_th-devices-msc | 54 +
.../ABI/testing/sysfs-bus-intel_th-devices-pti | 24 +
.../ABI/testing/sysfs-bus-intel_th-output-devices | 15 +
Documentation/ABI/testing/sysfs-bus-mcb | 29 +
Documentation/ABI/testing/sysfs-bus-mdio | 72 +
Documentation/ABI/testing/sysfs-bus-media | 6 +
Documentation/ABI/testing/sysfs-bus-mei | 56 +
Documentation/ABI/testing/sysfs-bus-mmc | 4 +
Documentation/ABI/testing/sysfs-bus-most | 299 +
Documentation/ABI/testing/sysfs-bus-moxtet-devices | 17 +
Documentation/ABI/testing/sysfs-bus-nfit | 233 +
Documentation/ABI/testing/sysfs-bus-nvdimm | 60 +
Documentation/ABI/testing/sysfs-bus-optee-devices | 17 +
Documentation/ABI/testing/sysfs-bus-papr-pmem | 75 +
Documentation/ABI/testing/sysfs-bus-pci | 704 +
.../ABI/testing/sysfs-bus-pci-devices-aer | 163 +
.../ABI/testing/sysfs-bus-pci-devices-avs | 8 +
.../ABI/testing/sysfs-bus-pci-devices-catpt | 17 +
.../ABI/testing/sysfs-bus-pci-devices-cciss | 80 +
.../ABI/testing/sysfs-bus-pci-devices-pvpanic | 26 +
.../ABI/testing/sysfs-bus-pci-drivers-btintel_pcie | 15 +
.../ABI/testing/sysfs-bus-pci-drivers-ehci_hcd | 46 +
.../ABI/testing/sysfs-bus-pci-drivers-janz-cmodio | 8 +
.../ABI/testing/sysfs-bus-pci-drivers-xhci_hcd | 129 +
Documentation/ABI/testing/sysfs-bus-peci | 16 +
Documentation/ABI/testing/sysfs-bus-platform | 56 +
.../sysfs-bus-platform-devices-ampere-smpro | 325 +
.../testing/sysfs-bus-platform-devices-occ-hwmon | 13 +
.../sysfs-bus-platform-drivers-amd_x3d_vcache | 12 +
.../ABI/testing/sysfs-bus-platform-onboard-usb-dev | 9 +
Documentation/ABI/testing/sysfs-bus-rapidio | 201 +
Documentation/ABI/testing/sysfs-bus-rbd | 173 +
Documentation/ABI/testing/sysfs-bus-rpmsg | 95 +
Documentation/ABI/testing/sysfs-bus-siox | 90 +
.../ABI/testing/sysfs-bus-soundwire-master | 23 +
.../ABI/testing/sysfs-bus-soundwire-slave | 109 +
.../ABI/testing/sysfs-bus-spi-devices-spi-nor | 40 +
.../testing/sysfs-bus-surface_aggregator-tabletsw | 57 +
Documentation/ABI/testing/sysfs-bus-thunderbolt | 370 +
Documentation/ABI/testing/sysfs-bus-typec | 51 +
Documentation/ABI/testing/sysfs-bus-usb | 607 +
.../ABI/testing/sysfs-bus-usb-devices-usbsevseg | 46 +
Documentation/ABI/testing/sysfs-bus-usb-lvstest | 60 +
Documentation/ABI/testing/sysfs-bus-vdpa | 57 +
Documentation/ABI/testing/sysfs-bus-vfio-mdev | 113 +
Documentation/ABI/testing/sysfs-bus-vmbus | 21 +
Documentation/ABI/testing/sysfs-bus-wmi | 81 +
Documentation/ABI/testing/sysfs-c2port | 81 +
Documentation/ABI/testing/sysfs-cfq-target-latency | 8 +
Documentation/ABI/testing/sysfs-class | 16 +
Documentation/ABI/testing/sysfs-class-backlight | 186 +
.../testing/sysfs-class-backlight-driver-lm3533 | 54 +
.../ABI/testing/sysfs-class-backlight-lm3639 | 11 +
Documentation/ABI/testing/sysfs-class-bdi | 134 +
Documentation/ABI/testing/sysfs-class-bsr | 25 +
Documentation/ABI/testing/sysfs-class-chromeos | 53 +
.../sysfs-class-chromeos-driver-cros-ec-lightbar | 74 +
.../sysfs-class-chromeos-driver-cros-ec-vbc | 6 +
Documentation/ABI/testing/sysfs-class-devfreq | 143 +
.../ABI/testing/sysfs-class-devfreq-event | 25 +
Documentation/ABI/testing/sysfs-class-devlink | 130 +
Documentation/ABI/testing/sysfs-class-drm | 8 +
Documentation/ABI/testing/sysfs-class-extcon | 101 +
Documentation/ABI/testing/sysfs-class-fc | 27 +
Documentation/ABI/testing/sysfs-class-fc_host | 23 +
.../ABI/testing/sysfs-class-fc_remote_ports | 23 +
Documentation/ABI/testing/sysfs-class-firmware | 77 +
.../ABI/testing/sysfs-class-firmware-attributes | 494 +
Documentation/ABI/testing/sysfs-class-fpga-bridge | 11 +
Documentation/ABI/testing/sysfs-class-fpga-manager | 60 +
Documentation/ABI/testing/sysfs-class-fpga-region | 9 +
Documentation/ABI/testing/sysfs-class-gnss | 17 +
Documentation/ABI/testing/sysfs-class-hwmon | 1089 +
.../ABI/testing/sysfs-class-ieee80211-rtw89 | 24 +
Documentation/ABI/testing/sysfs-class-intel_pmt | 119 +
.../ABI/testing/sysfs-class-intel_pmt-features | 134 +
Documentation/ABI/testing/sysfs-class-iommu | 17 +
.../ABI/testing/sysfs-class-iommu-amd-iommu | 14 +
.../ABI/testing/sysfs-class-iommu-intel-iommu | 32 +
Documentation/ABI/testing/sysfs-class-issei | 73 +
Documentation/ABI/testing/sysfs-class-lcd | 23 +
Documentation/ABI/testing/sysfs-class-led | 89 +
.../ABI/testing/sysfs-class-led-driver-aw200xx | 5 +
.../ABI/testing/sysfs-class-led-driver-lm3533 | 73 +
.../testing/sysfs-class-led-driver-turris-omnia | 28 +
Documentation/ABI/testing/sysfs-class-led-flash | 89 +
.../ABI/testing/sysfs-class-led-multicolor | 37 +
.../ABI/testing/sysfs-class-led-trigger-netdev | 192 +
.../ABI/testing/sysfs-class-led-trigger-oneshot | 36 +
.../ABI/testing/sysfs-class-led-trigger-pattern | 50 +
.../ABI/testing/sysfs-class-led-trigger-tty | 62 +
.../ABI/testing/sysfs-class-led-trigger-usbport | 13 +
Documentation/ABI/testing/sysfs-class-leds-gt683r | 18 +
Documentation/ABI/testing/sysfs-class-mei | 105 +
Documentation/ABI/testing/sysfs-class-mic | 178 +
Documentation/ABI/testing/sysfs-class-mtd | 242 +
Documentation/ABI/testing/sysfs-class-mux | 16 +
Documentation/ABI/testing/sysfs-class-net | 354 +
Documentation/ABI/testing/sysfs-class-net-cdc_ncm | 168 +
Documentation/ABI/testing/sysfs-class-net-dsa | 14 +
Documentation/ABI/testing/sysfs-class-net-grcan | 35 +
.../ABI/testing/sysfs-class-net-janz-ican3 | 19 +
Documentation/ABI/testing/sysfs-class-net-peak_usb | 19 +
Documentation/ABI/testing/sysfs-class-net-phydev | 75 +
Documentation/ABI/testing/sysfs-class-net-qmi | 76 +
Documentation/ABI/testing/sysfs-class-net-queues | 121 +
.../ABI/testing/sysfs-class-net-statistics | 217 +
Documentation/ABI/testing/sysfs-class-ocxl | 51 +
.../ABI/testing/sysfs-class-platform-profile | 50 +
Documentation/ABI/testing/sysfs-class-power | 906 +
.../ABI/testing/sysfs-class-power-bd71828 | 13 +
Documentation/ABI/testing/sysfs-class-power-gaokun | 27 +
.../ABI/testing/sysfs-class-power-ltc4162l | 82 +
.../ABI/testing/sysfs-class-power-max1720x | 32 +
Documentation/ABI/testing/sysfs-class-power-mp2629 | 9 +
Documentation/ABI/testing/sysfs-class-power-rt9467 | 19 +
Documentation/ABI/testing/sysfs-class-power-rt9471 | 32 +
Documentation/ABI/testing/sysfs-class-power-rt9756 | 30 +
.../ABI/testing/sysfs-class-power-surface | 15 +
.../ABI/testing/sysfs-class-power-twl4030 | 33 +
Documentation/ABI/testing/sysfs-class-power-wilco | 40 +
Documentation/ABI/testing/sysfs-class-powercap | 152 +
Documentation/ABI/testing/sysfs-class-pwm | 88 +
Documentation/ABI/testing/sysfs-class-rapidio | 59 +
Documentation/ABI/testing/sysfs-class-rc | 137 +
Documentation/ABI/testing/sysfs-class-rc-nuvoton | 15 +
.../testing/sysfs-class-reboot-mode-reboot_modes | 39 +
Documentation/ABI/testing/sysfs-class-regulator | 453 +
Documentation/ABI/testing/sysfs-class-remoteproc | 104 +
Documentation/ABI/testing/sysfs-class-rnbd-client | 133 +
Documentation/ABI/testing/sysfs-class-rnbd-server | 58 +
Documentation/ABI/testing/sysfs-class-rtc | 91 +
.../sysfs-class-rtc-rtc0-device-rtc_calibration | 14 +
Documentation/ABI/testing/sysfs-class-rtrs-client | 146 +
Documentation/ABI/testing/sysfs-class-rtrs-server | 53 +
Documentation/ABI/testing/sysfs-class-scsi_host | 119 +
Documentation/ABI/testing/sysfs-class-scsi_tape | 109 +
Documentation/ABI/testing/sysfs-class-spi-eeprom | 30 +
Documentation/ABI/testing/sysfs-class-spi-master | 34 +
Documentation/ABI/testing/sysfs-class-stm | 24 +
Documentation/ABI/testing/sysfs-class-stm_source | 11 +
Documentation/ABI/testing/sysfs-class-switchtec | 96 +
Documentation/ABI/testing/sysfs-class-tee | 25 +
Documentation/ABI/testing/sysfs-class-thermal | 259 +
Documentation/ABI/testing/sysfs-class-tsm | 9 +
Documentation/ABI/testing/sysfs-class-typec | 386 +
.../ABI/testing/sysfs-class-usb_power_delivery | 284 +
Documentation/ABI/testing/sysfs-class-usb_role | 27 +
Documentation/ABI/testing/sysfs-class-vduse | 33 +
Documentation/ABI/testing/sysfs-class-wakeup | 76 +
Documentation/ABI/testing/sysfs-class-watchdog | 129 +
Documentation/ABI/testing/sysfs-class-zram | 24 +
Documentation/ABI/testing/sysfs-dev | 21 +
Documentation/ABI/testing/sysfs-devices | 25 +
Documentation/ABI/testing/sysfs-devices-consumer | 9 +
Documentation/ABI/testing/sysfs-devices-coredump | 10 +
Documentation/ABI/testing/sysfs-devices-edac | 157 +
.../ABI/testing/sysfs-devices-faux-tdx-host | 26 +
.../ABI/testing/sysfs-devices-firmware_node | 17 +
Documentation/ABI/testing/sysfs-devices-lpss_ltr | 44 +
Documentation/ABI/testing/sysfs-devices-mapping | 62 +
Documentation/ABI/testing/sysfs-devices-memory | 120 +
Documentation/ABI/testing/sysfs-devices-mmc | 21 +
Documentation/ABI/testing/sysfs-devices-online | 20 +
.../ABI/testing/sysfs-devices-pci-host-bridge | 45 +
.../ABI/testing/sysfs-devices-physical_location | 42 +
.../ABI/testing/sysfs-devices-platform-ACPI-TAD | 117 +
.../testing/sysfs-devices-platform-_UDC_-gadget | 23 +
.../ABI/testing/sysfs-devices-platform-docg3 | 40 +
.../ABI/testing/sysfs-devices-platform-dock | 39 +
.../ABI/testing/sysfs-devices-platform-ipmi | 242 +
.../testing/sysfs-devices-platform-kunpeng_hccs | 126 +
.../sysfs-devices-platform-sh_mobile_lcdc_fb | 44 +
.../ABI/testing/sysfs-devices-platform-soc-ipa | 114 +
.../testing/sysfs-devices-platform-stratix10-rsu | 232 +
.../ABI/testing/sysfs-devices-platform-trackpoint | 115 +
Documentation/ABI/testing/sysfs-devices-power | 307 +
.../ABI/testing/sysfs-devices-power_resources_D0 | 13 +
.../ABI/testing/sysfs-devices-power_resources_D1 | 14 +
.../ABI/testing/sysfs-devices-power_resources_D2 | 14 +
.../testing/sysfs-devices-power_resources_D3hot | 14 +
.../testing/sysfs-devices-power_resources_wakeup | 13 +
.../ABI/testing/sysfs-devices-power_state | 20 +
.../ABI/testing/sysfs-devices-real_power_state | 23 +
Documentation/ABI/testing/sysfs-devices-removable | 20 +
.../ABI/testing/sysfs-devices-resource_in_use | 12 +
Documentation/ABI/testing/sysfs-devices-soc | 95 +
.../ABI/testing/sysfs-devices-software_node | 10 +
.../ABI/testing/sysfs-devices-state_synced | 29 +
Documentation/ABI/testing/sysfs-devices-sun | 14 +
Documentation/ABI/testing/sysfs-devices-supplier | 9 +
Documentation/ABI/testing/sysfs-devices-system-cpu | 808 +
.../ABI/testing/sysfs-devices-system-ibm-rtl | 24 +
.../ABI/testing/sysfs-devices-system-xen_cpu | 20 +
Documentation/ABI/testing/sysfs-devices-vfio-dev | 8 +
.../testing/sysfs-devices-virtual-misc-tdx_guest | 63 +
.../ABI/testing/sysfs-devices-waiting_for_supplier | 17 +
Documentation/ABI/testing/sysfs-devices-xenbus | 41 +
Documentation/ABI/testing/sysfs-driver-altera-cvp | 8 +
Documentation/ABI/testing/sysfs-driver-amd-sfh | 13 +
.../ABI/testing/sysfs-driver-aspeed-uart-routing | 27 +
.../ABI/testing/sysfs-driver-bd9571mwv-regulator | 31 +
Documentation/ABI/testing/sysfs-driver-ccp | 120 +
.../ABI/testing/sysfs-driver-chromeos-acpi | 152 +
.../ABI/testing/sysfs-driver-dell-dw5826e-reset | 9 +
Documentation/ABI/testing/sysfs-driver-eud | 9 +
.../ABI/testing/sysfs-driver-framer-pef2256 | 8 +
.../ABI/testing/sysfs-driver-fsi-master-gpio | 10 +
Documentation/ABI/testing/sysfs-driver-ge-achc | 15 +
Documentation/ABI/testing/sysfs-driver-genwqe | 78 +
Documentation/ABI/testing/sysfs-driver-habanalabs | 265 +
Documentation/ABI/testing/sysfs-driver-hid | 20 +
.../ABI/testing/sysfs-driver-hid-appletb-kbd | 13 +
Documentation/ABI/testing/sysfs-driver-hid-corsair | 15 +
.../ABI/testing/sysfs-driver-hid-corsair-void | 38 +
Documentation/ABI/testing/sysfs-driver-hid-lenovo | 60 +
.../ABI/testing/sysfs-driver-hid-lenovo-go | 724 +
.../ABI/testing/sysfs-driver-hid-lenovo-go-s | 304 +
.../ABI/testing/sysfs-driver-hid-logitech-hidpp | 19 +
.../ABI/testing/sysfs-driver-hid-logitech-lg4ff | 75 +
.../ABI/testing/sysfs-driver-hid-multitouch | 9 +
Documentation/ABI/testing/sysfs-driver-hid-ntrig | 73 +
Documentation/ABI/testing/sysfs-driver-hid-picolcd | 43 +
.../ABI/testing/sysfs-driver-hid-prodikeys | 29 +
.../ABI/testing/sysfs-driver-hid-roccat-kone | 125 +
Documentation/ABI/testing/sysfs-driver-hid-srws1 | 21 +
Documentation/ABI/testing/sysfs-driver-hid-wiimote | 85 +
.../ABI/testing/sysfs-driver-input-axp-pek | 11 +
.../ABI/testing/sysfs-driver-input-cros-ec-keyb | 6 +
.../ABI/testing/sysfs-driver-input-exc3000 | 26 +
Documentation/ABI/testing/sysfs-driver-intc_sar | 54 +
.../ABI/testing/sysfs-driver-intel-i915-hwmon | 93 +
.../ABI/testing/sysfs-driver-intel-m10-bmc | 36 +
.../testing/sysfs-driver-intel-m10-bmc-sec-update | 61 +
.../ABI/testing/sysfs-driver-intel-rapid-start | 21 +
.../ABI/testing/sysfs-driver-intel-xe-hwmon | 315 +
.../ABI/testing/sysfs-driver-intel-xe-ras | 30 +
.../ABI/testing/sysfs-driver-intel-xe-sriov | 190 +
Documentation/ABI/testing/sysfs-driver-intel_sdsi | 90 +
Documentation/ABI/testing/sysfs-driver-ivpu | 65 +
.../ABI/testing/sysfs-driver-jz4780-efuse | 20 +
.../ABI/testing/sysfs-driver-lenovo-yb9-kbdock | 19 +
.../ABI/testing/sysfs-driver-panfrost-profiling | 10 +
.../ABI/testing/sysfs-driver-panthor-profiling | 10 +
Documentation/ABI/testing/sysfs-driver-pciback | 28 +
Documentation/ABI/testing/sysfs-driver-ppi | 75 +
Documentation/ABI/testing/sysfs-driver-qaic | 18 +
Documentation/ABI/testing/sysfs-driver-qat | 167 +
Documentation/ABI/testing/sysfs-driver-qat_kpt | 97 +
Documentation/ABI/testing/sysfs-driver-qat_ras | 41 +
Documentation/ABI/testing/sysfs-driver-qat_rl | 226 +
Documentation/ABI/testing/sysfs-driver-qat_svn | 114 +
.../ABI/testing/sysfs-driver-samsung-laptop | 37 +
Documentation/ABI/testing/sysfs-driver-spi-intel | 20 +
Documentation/ABI/testing/sysfs-driver-st | 12 +
Documentation/ABI/testing/sysfs-driver-tegra-fuse | 11 +
.../ABI/testing/sysfs-driver-toshiba_acpi | 223 +
.../ABI/testing/sysfs-driver-toshiba_haps | 22 +
.../ABI/testing/sysfs-driver-typec-displayport | 74 +
Documentation/ABI/testing/sysfs-driver-uacce | 57 +
Documentation/ABI/testing/sysfs-driver-ucsi-ccg | 6 +
Documentation/ABI/testing/sysfs-driver-ufs | 1793 +
.../ABI/testing/sysfs-driver-uio_pci_sva-pasid | 29 +
.../ABI/testing/sysfs-driver-uniwill-laptop | 105 +
Documentation/ABI/testing/sysfs-driver-w1_ds28e17 | 24 +
Documentation/ABI/testing/sysfs-driver-w1_therm | 190 +
Documentation/ABI/testing/sysfs-driver-wacom | 105 +
Documentation/ABI/testing/sysfs-driver-xdata | 49 +
Documentation/ABI/testing/sysfs-driver-xen-blkback | 46 +
.../ABI/testing/sysfs-driver-xen-blkfront | 19 +
.../ABI/testing/sysfs-driver-xilinx-tmr-manager | 16 +
Documentation/ABI/testing/sysfs-driver-zynqmp-fpga | 73 +
Documentation/ABI/testing/sysfs-edac-ecs | 74 +
Documentation/ABI/testing/sysfs-edac-memory-repair | 206 +
Documentation/ABI/testing/sysfs-edac-scrub | 85 +
Documentation/ABI/testing/sysfs-firmware-acpi | 277 +
.../ABI/testing/sysfs-firmware-dmi-entries | 114 +
.../ABI/testing/sysfs-firmware-dmi-tables | 22 +
Documentation/ABI/testing/sysfs-firmware-efi | 45 +
Documentation/ABI/testing/sysfs-firmware-efi-esrt | 87 +
.../ABI/testing/sysfs-firmware-efi-runtime-map | 36 +
Documentation/ABI/testing/sysfs-firmware-gsmi | 58 +
Documentation/ABI/testing/sysfs-firmware-initrd | 8 +
.../ABI/testing/sysfs-firmware-lefi-boardinfo | 35 +
Documentation/ABI/testing/sysfs-firmware-log | 7 +
Documentation/ABI/testing/sysfs-firmware-memmap | 75 +
Documentation/ABI/testing/sysfs-firmware-ofw | 52 +
.../ABI/testing/sysfs-firmware-opal-powercap | 31 +
Documentation/ABI/testing/sysfs-firmware-opal-psr | 18 +
.../ABI/testing/sysfs-firmware-opal-sensor-groups | 21 +
.../testing/sysfs-firmware-papr-energy-scale-info | 29 +
Documentation/ABI/testing/sysfs-firmware-plpks | 58 +
.../ABI/testing/sysfs-firmware-qemu_fw_cfg | 103 +
.../ABI/testing/sysfs-firmware-sev-vulnerabilities | 19 +
Documentation/ABI/testing/sysfs-firmware-sgi_uv | 159 +
.../ABI/testing/sysfs-firmware-turris-mox-rwtm | 28 +
Documentation/ABI/testing/sysfs-fs-erofs | 49 +
Documentation/ABI/testing/sysfs-fs-ext4 | 118 +
Documentation/ABI/testing/sysfs-fs-f2fs | 1022 +
Documentation/ABI/testing/sysfs-fs-nilfs2 | 269 +
Documentation/ABI/testing/sysfs-fs-ubifs | 35 +
Documentation/ABI/testing/sysfs-fs-virtiofs | 11 +
Documentation/ABI/testing/sysfs-fs-xfs | 37 +
Documentation/ABI/testing/sysfs-hypervisor-xen | 46 +
Documentation/ABI/testing/sysfs-ibft | 33 +
.../ABI/testing/sysfs-kernel-address_bits | 10 +
Documentation/ABI/testing/sysfs-kernel-boot_params | 39 +
Documentation/ABI/testing/sysfs-kernel-btf | 25 +
.../ABI/testing/sysfs-kernel-cpu_byteorder | 12 +
Documentation/ABI/testing/sysfs-kernel-fadump | 59 +
Documentation/ABI/testing/sysfs-kernel-fscaps | 8 +
.../ABI/testing/sysfs-kernel-hardlockup_count | 7 +
.../ABI/testing/sysfs-kernel-iommu_groups | 64 +
Documentation/ABI/testing/sysfs-kernel-irq | 60 +
Documentation/ABI/testing/sysfs-kernel-kexec-kdump | 61 +
Documentation/ABI/testing/sysfs-kernel-livepatch | 95 +
Documentation/ABI/testing/sysfs-kernel-mm | 6 +
Documentation/ABI/testing/sysfs-kernel-mm-cma | 44 +
Documentation/ABI/testing/sysfs-kernel-mm-damon | 664 +
.../ABI/testing/sysfs-kernel-mm-hugepages | 17 +
Documentation/ABI/testing/sysfs-kernel-mm-ksm | 61 +
.../ABI/testing/sysfs-kernel-mm-memory-tiers | 25 +
.../ABI/testing/sysfs-kernel-mm-mempolicy | 4 +
.../sysfs-kernel-mm-mempolicy-weighted-interleave | 54 +
Documentation/ABI/testing/sysfs-kernel-mm-numa | 28 +
Documentation/ABI/testing/sysfs-kernel-mm-swap | 16 +
.../testing/sysfs-kernel-mm-transparent-hugepage | 18 +
Documentation/ABI/testing/sysfs-kernel-oops_count | 6 +
.../ABI/testing/sysfs-kernel-rcu_stall_count | 6 +
Documentation/ABI/testing/sysfs-kernel-reboot | 40 +
Documentation/ABI/testing/sysfs-kernel-slab | 526 +
.../ABI/testing/sysfs-kernel-softlockup_count | 7 +
Documentation/ABI/testing/sysfs-kernel-vmcoreinfo | 14 +
Documentation/ABI/testing/sysfs-kernel-warn_count | 6 +
Documentation/ABI/testing/sysfs-mce | 97 +
.../ABI/testing/sysfs-memory-page-offline | 44 +
Documentation/ABI/testing/sysfs-module | 84 +
Documentation/ABI/testing/sysfs-nvmem-cells | 21 +
Documentation/ABI/testing/sysfs-ocfs2 | 89 +
.../ABI/testing/sysfs-platform-alienware-wmi | 14 +
.../ABI/testing/sysfs-platform-asus-laptop | 71 +
Documentation/ABI/testing/sysfs-platform-asus-wmi | 240 +
Documentation/ABI/testing/sysfs-platform-at91 | 27 +
Documentation/ABI/testing/sysfs-platform-ayaneo-ec | 19 +
.../ABI/testing/sysfs-platform-brcmstb-gisb-arb | 8 +
.../ABI/testing/sysfs-platform-brcmstb-memc | 15 +
.../ABI/testing/sysfs-platform-chipidea-usb-otg | 56 +
.../ABI/testing/sysfs-platform-chipidea-usb2 | 9 +
.../ABI/testing/sysfs-platform-dell-laptop | 73 +
.../ABI/testing/sysfs-platform-dell-privacy-wmi | 71 +
.../ABI/testing/sysfs-platform-dell-smbios | 21 +
.../ABI/testing/sysfs-platform-dell-wmi-ddv | 9 +
Documentation/ABI/testing/sysfs-platform-dfl-fme | 246 +
Documentation/ABI/testing/sysfs-platform-dfl-port | 101 +
Documentation/ABI/testing/sysfs-platform-dptf | 157 +
.../ABI/testing/sysfs-platform-eeepc-laptop | 56 +
Documentation/ABI/testing/sysfs-platform-hidma | 9 +
.../ABI/testing/sysfs-platform-hidma-mgmt | 97 +
.../ABI/testing/sysfs-platform-i2c-demux-pinctrl | 18 +
.../ABI/testing/sysfs-platform-ideapad-laptop | 52 +
Documentation/ABI/testing/sysfs-platform-intel-ifs | 52 +
Documentation/ABI/testing/sysfs-platform-intel-pmc | 22 +
.../testing/sysfs-platform-intel-wmi-sbl-fw-update | 13 +
.../testing/sysfs-platform-intel-wmi-thunderbolt | 12 +
Documentation/ABI/testing/sysfs-platform-kim | 49 +
Documentation/ABI/testing/sysfs-platform-lg-laptop | 36 +
.../ABI/testing/sysfs-platform-mellanox-bootctl | 162 +
.../ABI/testing/sysfs-platform-mellanox-pmc | 64 +
.../ABI/testing/sysfs-platform-msi-laptop | 83 +
Documentation/ABI/testing/sysfs-platform-oxp | 25 +
.../ABI/testing/sysfs-platform-phy-rcar-gen3-usb2 | 17 +
.../ABI/testing/sysfs-platform-power-on-reason | 12 +
.../ABI/testing/sysfs-platform-renesas_usb3 | 17 +
Documentation/ABI/testing/sysfs-platform-silicom | 30 +
Documentation/ABI/testing/sysfs-platform-sst-atom | 26 +
Documentation/ABI/testing/sysfs-platform-tahvo-usb | 16 +
Documentation/ABI/testing/sysfs-platform-ts5500 | 54 +
.../ABI/testing/sysfs-platform-twl4030-usb | 8 +
.../ABI/testing/sysfs-platform-usbip-vudc | 38 +
Documentation/ABI/testing/sysfs-platform-wilco-ec | 58 +
Documentation/ABI/testing/sysfs-platform_profile | 40 +
Documentation/ABI/testing/sysfs-power | 472 +
Documentation/ABI/testing/sysfs-pps | 73 +
Documentation/ABI/testing/sysfs-pps-gen | 43 +
Documentation/ABI/testing/sysfs-pps-gen-tio | 6 +
Documentation/ABI/testing/sysfs-profiling | 13 +
Documentation/ABI/testing/sysfs-ptp | 142 +
Documentation/ABI/testing/sysfs-secvar | 65 +
Documentation/ABI/testing/sysfs-timecard | 293 +
Documentation/ABI/testing/sysfs-tty | 166 +
Documentation/ABI/testing/sysfs-uevent | 51 +
Documentation/ABI/testing/usb-charger-uevent | 54 +
Documentation/ABI/testing/usb-uevent | 27 +
Documentation/Changes | 1 +
Documentation/CodingStyle | 1 +
Documentation/Kconfig | 28 +
Documentation/Makefile | 115 +
Documentation/PCI/acpi-info.rst | 192 +
Documentation/PCI/boot-interrupts.rst | 159 +
Documentation/PCI/controller/index.rst | 11 +
.../PCI/controller/pci-controller-drivers.rst | 402 +
.../PCI/controller/rcar-pcie-firmware.rst | 32 +
.../PCI/endpoint/function/binding/pci-ntb.rst | 38 +
.../PCI/endpoint/function/binding/pci-test.rst | 26 +
Documentation/PCI/endpoint/index.rst | 21 +
Documentation/PCI/endpoint/pci-endpoint-cfs.rst | 138 +
Documentation/PCI/endpoint/pci-endpoint.rst | 283 +
Documentation/PCI/endpoint/pci-ntb-function.rst | 348 +
Documentation/PCI/endpoint/pci-ntb-howto.rst | 158 +
Documentation/PCI/endpoint/pci-nvme-function.rst | 13 +
Documentation/PCI/endpoint/pci-test-function.rst | 103 +
Documentation/PCI/endpoint/pci-test-howto.rst | 239 +
Documentation/PCI/endpoint/pci-vntb-function.rst | 129 +
Documentation/PCI/endpoint/pci-vntb-howto.rst | 169 +
Documentation/PCI/index.rst | 22 +
Documentation/PCI/msi-howto.rst | 300 +
Documentation/PCI/pci-error-recovery.rst | 471 +
Documentation/PCI/pci-iov-howto.rst | 171 +
Documentation/PCI/pci.rst | 578 +
Documentation/PCI/pcieaer-howto.rst | 267 +
Documentation/PCI/pciebus-howto.rst | 228 +
Documentation/PCI/sysfs-pci.rst | 138 +
Documentation/PCI/tph.rst | 132 +
.../Design/Data-Structures/BigTreeClassicRCU.svg | 474 +
.../BigTreePreemptRCUBHdyntickCB.svg | 662 +
.../RCU/Design/Data-Structures/Data-Structures.rst | 1196 +
.../Design/Data-Structures/HugeTreeClassicRCU.svg | 939 +
.../RCU/Design/Data-Structures/TreeLevel.svg | 828 +
.../RCU/Design/Data-Structures/TreeMapping.svg | 305 +
.../Design/Data-Structures/TreeMappingLevel.svg | 380 +
.../RCU/Design/Data-Structures/blkd_task.svg | 631 +
.../RCU/Design/Data-Structures/nxtlist.svg | 386 +
.../Design/Expedited-Grace-Periods/ExpRCUFlow.svg | 830 +
.../Expedited-Grace-Periods/ExpSchedFlow.svg | 830 +
.../Expedited-Grace-Periods.rst | 521 +
.../RCU/Design/Expedited-Grace-Periods/Funnel0.svg | 275 +
.../RCU/Design/Expedited-Grace-Periods/Funnel1.svg | 275 +
.../RCU/Design/Expedited-Grace-Periods/Funnel2.svg | 287 +
.../RCU/Design/Expedited-Grace-Periods/Funnel3.svg | 323 +
.../RCU/Design/Expedited-Grace-Periods/Funnel4.svg | 323 +
.../RCU/Design/Expedited-Grace-Periods/Funnel5.svg | 335 +
.../RCU/Design/Expedited-Grace-Periods/Funnel6.svg | 335 +
.../RCU/Design/Expedited-Grace-Periods/Funnel7.svg | 347 +
.../RCU/Design/Expedited-Grace-Periods/Funnel8.svg | 311 +
.../Memory-Ordering/Tree-RCU-Memory-Ordering.rst | 648 +
.../TreeRCU-callback-invocation.svg | 486 +
.../Memory-Ordering/TreeRCU-callback-registry.svg | 646 +
.../RCU/Design/Memory-Ordering/TreeRCU-dyntick.svg | 700 +
.../Design/Memory-Ordering/TreeRCU-gp-cleanup.svg | 1133 +
.../RCU/Design/Memory-Ordering/TreeRCU-gp-fqs.svg | 1309 +
.../Design/Memory-Ordering/TreeRCU-gp-init-1.svg | 658 +
.../Design/Memory-Ordering/TreeRCU-gp-init-2.svg | 656 +
.../Design/Memory-Ordering/TreeRCU-gp-init-3.svg | 636 +
.../RCU/Design/Memory-Ordering/TreeRCU-gp.svg | 5135 +
.../RCU/Design/Memory-Ordering/TreeRCU-hotplug.svg | 775 +
.../RCU/Design/Memory-Ordering/TreeRCU-qs.svg | 1095 +
.../RCU/Design/Memory-Ordering/rcu_node-lock.svg | 229 +
.../Design/Requirements/GPpartitionReaders1.svg | 374 +
.../Design/Requirements/ReadersPartitionGP1.svg | 639 +
.../RCU/Design/Requirements/Requirements.rst | 2873 +
Documentation/RCU/NMI-RCU.rst | 123 +
Documentation/RCU/RTFP.txt | 2812 +
Documentation/RCU/UP.rst | 152 +
Documentation/RCU/checklist.rst | 556 +
Documentation/RCU/index.rst | 30 +
Documentation/RCU/listRCU.rst | 511 +
Documentation/RCU/lockdep-splat.rst | 115 +
Documentation/RCU/lockdep.rst | 119 +
Documentation/RCU/rcu.rst | 93 +
Documentation/RCU/rcu_dereference.rst | 502 +
Documentation/RCU/rcubarrier.rst | 377 +
Documentation/RCU/rculist_nulls.rst | 215 +
Documentation/RCU/rcuref.rst | 158 +
Documentation/RCU/stallwarn.rst | 491 +
Documentation/RCU/torture.rst | 374 +
Documentation/RCU/whatisRCU.rst | 1415 +
Documentation/SubmittingPatches | 1 +
Documentation/accel/amdxdna/amdnpu.rst | 306 +
Documentation/accel/amdxdna/index.rst | 11 +
Documentation/accel/index.rst | 13 +
Documentation/accel/introduction.rst | 110 +
Documentation/accel/qaic/aic080.rst | 14 +
Documentation/accel/qaic/aic100.rst | 538 +
Documentation/accel/qaic/index.rst | 14 +
Documentation/accel/qaic/qaic.rst | 209 +
Documentation/accel/rocket/index.rst | 19 +
Documentation/accounting/cgroupstats.rst | 31 +
Documentation/accounting/delay-accounting.rst | 214 +
Documentation/accounting/index.rst | 14 +
Documentation/accounting/psi.rst | 188 +
Documentation/accounting/taskstats-struct.rst | 199 +
Documentation/accounting/taskstats.rst | 182 +
Documentation/admin-guide/LSM/LoadPin.rst | 31 +
Documentation/admin-guide/LSM/SELinux.rst | 44 +
Documentation/admin-guide/LSM/SafeSetID.rst | 118 +
Documentation/admin-guide/LSM/Smack.rst | 871 +
Documentation/admin-guide/LSM/Yama.rst | 75 +
Documentation/admin-guide/LSM/apparmor.rst | 54 +
Documentation/admin-guide/LSM/index.rst | 51 +
Documentation/admin-guide/LSM/ipe.rst | 835 +
Documentation/admin-guide/LSM/landlock.rst | 298 +
Documentation/admin-guide/LSM/tomoyo.rst | 52 +
.../admin-guide/RAS/address-translation.rst | 24 +
Documentation/admin-guide/RAS/error-decoding.rst | 21 +
Documentation/admin-guide/RAS/index.rst | 7 +
Documentation/admin-guide/RAS/main.rst | 1087 +
Documentation/admin-guide/README.rst | 360 +
Documentation/admin-guide/abi-obsolete-files.rst | 7 +
Documentation/admin-guide/abi-obsolete.rst | 13 +
Documentation/admin-guide/abi-removed-files.rst | 7 +
Documentation/admin-guide/abi-removed.rst | 7 +
Documentation/admin-guide/abi-stable-files.rst | 7 +
Documentation/admin-guide/abi-stable.rst | 16 +
Documentation/admin-guide/abi-testing-files.rst | 7 +
Documentation/admin-guide/abi-testing.rst | 22 +
Documentation/admin-guide/abi.rst | 29 +
Documentation/admin-guide/acpi/cppc_sysfs.rst | 78 +
.../admin-guide/acpi/fan_performance_states.rst | 90 +
Documentation/admin-guide/acpi/index.rst | 14 +
.../admin-guide/acpi/initrd_table_override.rst | 115 +
Documentation/admin-guide/acpi/ssdt-overlays.rst | 181 +
Documentation/admin-guide/aoe/aoe.rst | 150 +
Documentation/admin-guide/aoe/autoload.sh | 17 +
Documentation/admin-guide/aoe/examples.rst | 23 +
Documentation/admin-guide/aoe/index.rst | 10 +
Documentation/admin-guide/aoe/status.sh | 30 +
Documentation/admin-guide/aoe/todo.rst | 17 +
Documentation/admin-guide/aoe/udev-install.sh | 33 +
Documentation/admin-guide/aoe/udev.txt | 26 +
.../admin-guide/auxdisplay/cfag12864b.rst | 98 +
Documentation/admin-guide/auxdisplay/index.rst | 9 +
Documentation/admin-guide/auxdisplay/ks0108.rst | 50 +
Documentation/admin-guide/bcache.rst | 644 +
Documentation/admin-guide/binderfs.rst | 87 +
Documentation/admin-guide/binfmt-misc.rst | 391 +
.../blockdev/drbd/DRBD-8.3-data-packets.svg | 588 +
.../blockdev/drbd/DRBD-data-packets.svg | 459 +
.../admin-guide/blockdev/drbd/conn-states-8.dot | 18 +
.../blockdev/drbd/data-structure-v9.rst | 42 +
.../admin-guide/blockdev/drbd/disk-states-8.dot | 16 +
.../drbd/drbd-connection-state-overview.dot | 85 +
.../admin-guide/blockdev/drbd/figures.rst | 30 +
Documentation/admin-guide/blockdev/drbd/index.rst | 19 +
.../admin-guide/blockdev/drbd/peer-states-8.dot | 8 +
Documentation/admin-guide/blockdev/floppy.rst | 255 +
Documentation/admin-guide/blockdev/index.rst | 17 +
Documentation/admin-guide/blockdev/nbd.rst | 31 +
Documentation/admin-guide/blockdev/paride.rst | 207 +
Documentation/admin-guide/blockdev/ramdisk.rst | 153 +
Documentation/admin-guide/blockdev/zoned_loop.rst | 191 +
Documentation/admin-guide/blockdev/zram.rst | 610 +
Documentation/admin-guide/bootconfig.rst | 416 +
Documentation/admin-guide/braille-console.rst | 38 +
Documentation/admin-guide/btmrvl.rst | 124 +
Documentation/admin-guide/bug-bisect.rst | 165 +
Documentation/admin-guide/bug-hunting.rst | 370 +
.../admin-guide/cgroup-v1/blkio-controller.rst | 301 +
Documentation/admin-guide/cgroup-v1/cgroups.rst | 697 +
Documentation/admin-guide/cgroup-v1/cpuacct.rst | 50 +
Documentation/admin-guide/cgroup-v1/cpusets.rst | 874 +
Documentation/admin-guide/cgroup-v1/devices.rst | 132 +
.../admin-guide/cgroup-v1/freezer-subsystem.rst | 131 +
Documentation/admin-guide/cgroup-v1/hugetlb.rst | 139 +
Documentation/admin-guide/cgroup-v1/index.rst | 24 +
Documentation/admin-guide/cgroup-v1/memcg_test.rst | 342 +
Documentation/admin-guide/cgroup-v1/memory.rst | 926 +
Documentation/admin-guide/cgroup-v1/misc.rst | 4 +
Documentation/admin-guide/cgroup-v1/net_cls.rst | 44 +
Documentation/admin-guide/cgroup-v1/net_prio.rst | 57 +
Documentation/admin-guide/cgroup-v1/pids.rst | 93 +
Documentation/admin-guide/cgroup-v1/rdma.rst | 191 +
Documentation/admin-guide/cgroup-v2.rst | 3581 +
Documentation/admin-guide/cifs/authors.rst | 69 +
Documentation/admin-guide/cifs/changes.rst | 9 +
Documentation/admin-guide/cifs/index.rst | 14 +
Documentation/admin-guide/cifs/introduction.rst | 53 +
Documentation/admin-guide/cifs/todo.rst | 133 +
Documentation/admin-guide/cifs/usage.rst | 864 +
Documentation/admin-guide/cifs/winucase_convert.pl | 62 +
Documentation/admin-guide/clearing-warn-once.rst | 9 +
Documentation/admin-guide/cpu-isolation.rst | 357 +
Documentation/admin-guide/cpu-load.rst | 117 +
Documentation/admin-guide/cputopology.rst | 101 +
Documentation/admin-guide/dell_rbu.rst | 128 +
.../admin-guide/device-mapper/cache-policies.rst | 131 +
Documentation/admin-guide/device-mapper/cache.rst | 337 +
Documentation/admin-guide/device-mapper/delay.rst | 54 +
.../admin-guide/device-mapper/dm-clone.rst | 333 +
.../admin-guide/device-mapper/dm-crypt.rst | 212 +
.../admin-guide/device-mapper/dm-dust.rst | 305 +
Documentation/admin-guide/device-mapper/dm-ebs.rst | 51 +
.../admin-guide/device-mapper/dm-flakey.rst | 88 +
Documentation/admin-guide/device-mapper/dm-ima.rst | 718 +
.../admin-guide/device-mapper/dm-init.rst | 133 +
.../admin-guide/device-mapper/dm-inlinecrypt.rst | 129 +
.../admin-guide/device-mapper/dm-integrity.rst | 321 +
Documentation/admin-guide/device-mapper/dm-io.rst | 75 +
Documentation/admin-guide/device-mapper/dm-log.rst | 57 +
.../admin-guide/device-mapper/dm-pcache.rst | 202 +
.../admin-guide/device-mapper/dm-queue-length.rst | 48 +
.../admin-guide/device-mapper/dm-raid.rst | 489 +
.../admin-guide/device-mapper/dm-service-time.rst | 101 +
.../admin-guide/device-mapper/dm-uevent.rst | 110 +
.../admin-guide/device-mapper/dm-zoned.rst | 194 +
Documentation/admin-guide/device-mapper/era.rst | 116 +
Documentation/admin-guide/device-mapper/index.rst | 43 +
Documentation/admin-guide/device-mapper/kcopyd.rst | 47 +
Documentation/admin-guide/device-mapper/linear.rst | 63 +
.../admin-guide/device-mapper/log-writes.rst | 145 +
.../admin-guide/device-mapper/persistent-data.rst | 88 +
.../admin-guide/device-mapper/snapshot.rst | 196 +
.../admin-guide/device-mapper/statistics.rst | 225 +
.../admin-guide/device-mapper/striped.rst | 61 +
Documentation/admin-guide/device-mapper/switch.rst | 141 +
.../device-mapper/thin-provisioning.rst | 427 +
.../admin-guide/device-mapper/unstriped.rst | 135 +
.../admin-guide/device-mapper/vdo-design.rst | 633 +
Documentation/admin-guide/device-mapper/vdo.rst | 413 +
Documentation/admin-guide/device-mapper/verity.rst | 349 +
.../admin-guide/device-mapper/writecache.rst | 114 +
Documentation/admin-guide/device-mapper/zero.rst | 37 +
Documentation/admin-guide/devices.rst | 270 +
Documentation/admin-guide/devices.txt | 3081 +
Documentation/admin-guide/dynamic-debug-howto.rst | 392 +
Documentation/admin-guide/edid.rst | 27 +
Documentation/admin-guide/efi-stub.rst | 103 +
Documentation/admin-guide/ext4.rst | 611 +
Documentation/admin-guide/features.rst | 3 +
.../admin-guide/filesystem-monitoring.rst | 78 +
Documentation/admin-guide/gpio/gpio-aggregator.rst | 218 +
Documentation/admin-guide/gpio/gpio-mockup.rst | 59 +
Documentation/admin-guide/gpio/gpio-sim.rst | 137 +
Documentation/admin-guide/gpio/gpio-virtuser.rst | 177 +
Documentation/admin-guide/gpio/index.rst | 14 +
Documentation/admin-guide/gpio/obsolete.rst | 13 +
.../admin-guide/hw-vuln/attack_vector_controls.rst | 236 +
.../admin-guide/hw-vuln/core-scheduling.rst | 226 +
.../admin-guide/hw-vuln/cross-thread-rsb.rst | 91 +
.../admin-guide/hw-vuln/gather_data_sampling.rst | 109 +
Documentation/admin-guide/hw-vuln/index.rst | 29 +
.../hw-vuln/indirect-target-selection.rst | 168 +
Documentation/admin-guide/hw-vuln/l1d_flush.rst | 69 +
Documentation/admin-guide/hw-vuln/l1tf.rst | 615 +
Documentation/admin-guide/hw-vuln/mds.rst | 303 +
Documentation/admin-guide/hw-vuln/multihit.rst | 167 +
.../admin-guide/hw-vuln/old_microcode.rst | 21 +
.../hw-vuln/processor_mmio_stale_data.rst | 269 +
.../admin-guide/hw-vuln/reg-file-data-sampling.rst | 96 +
Documentation/admin-guide/hw-vuln/rsb.rst | 268 +
.../special-register-buffer-data-sampling.rst | 150 +
Documentation/admin-guide/hw-vuln/spectre.rst | 725 +
Documentation/admin-guide/hw-vuln/srso.rst | 242 +
.../admin-guide/hw-vuln/tsx_async_abort.rst | 270 +
Documentation/admin-guide/hw-vuln/vmscape.rst | 110 +
Documentation/admin-guide/hw_random.rst | 104 +
Documentation/admin-guide/index.rst | 192 +
Documentation/admin-guide/init.rst | 48 +
Documentation/admin-guide/initrd.rst | 383 +
Documentation/admin-guide/iostats.rst | 187 +
Documentation/admin-guide/java.rst | 423 +
Documentation/admin-guide/jfs.rst | 66 +
Documentation/admin-guide/kdump/gdbmacros.txt | 323 +
Documentation/admin-guide/kdump/index.rst | 13 +
Documentation/admin-guide/kdump/kdump.rst | 612 +
Documentation/admin-guide/kdump/vmcoreinfo.rst | 596 +
Documentation/admin-guide/kernel-parameters.rst | 135 +
Documentation/admin-guide/kernel-parameters.txt | 8709 +
.../admin-guide/kernel-per-CPU-kthreads.rst | 325 +
.../admin-guide/laptops/alienware-wmi.rst | 127 +
Documentation/admin-guide/laptops/asus-laptop.rst | 271 +
.../admin-guide/laptops/disk-shock-protection.rst | 151 +
Documentation/admin-guide/laptops/index.rst | 19 +
Documentation/admin-guide/laptops/lg-laptop.rst | 82 +
.../admin-guide/laptops/samsung-galaxybook.rst | 174 +
Documentation/admin-guide/laptops/sony-laptop.rst | 174 +
[Output truncated: showing 1000 of 96042 lines]]
|
| 130/4 |
2026/09/17 10:56 |
llm |
codeexpert |
0m
Model:
Tokens:
input: 54242
output: 22
thoughts: 49
Thoughts: Okay, let's break this down.
**Investigating the `fs/ntfs` Directory**
Hmm, I'm trying to figure something out, probably related to the file system, but where did `fs/ntfs` come up in the git history or the project structure? I need to quickly see what's *actually* in the `fs/ntfs` directory. My usual approach would be to dive into the codebase, but I'll skip that. Let's see if `codesearch-dir-index` has a faster answer for me. That should give me a good overview of what's present in that directory without having to parse all the source code myself.
|
| 131/4 |
2026/09/17 10:56 |
tool |
codesearch-dir-index |
0m
Args:
Results: map[Files:[aops.c attrib.c attrib.h attrlist.c attrlist.h bdev-io.c bitmap.c bitmap.h collate.c collate.h compress.c debug.c debug.h dir.c dir.h ea.c ea.h file.c index.c index.h inode.c inode.h iomap.c iomap.h layout.h lcnalloc.c lcnalloc.h logfile.c logfile.h malloc.h mft.c mft.h mst.c namei.c ntfs.h ntfs_codec.h object_id.c object_id.h reparse.c reparse.h runlist.c runlist.h super.c sysctl.c sysctl.h time.h unistr.c upcase.c volume.h wof.c] Subdirs:[lib]]
|
| 132/4 |
2026/09/17 10:56 |
llm |
codeexpert |
0m
Model:
Tokens:
input: 54815
output: 23
thoughts: 33
Thoughts: Okay, here's my take on those thoughts, framed as my own:
**Analyzing the NTFS3 Implementation**
Alright, time to dig into `fs/ntfs3`. My first step, as always, is to get a lay of the land. I'm going to leverage my existing knowledge and experience, so let's use `codesearch-dir-index` to get a quick overview of how the filesystem interacts with our broader kernel code base. This search should help me rapidly identify key areas and potential integration points I should be aware of. I'm expecting to find references related to the inode management, the data structures used, and the low-level disk access. It's the standard first step - establish the current state.
|
| 133/4 |
2026/09/17 10:56 |
tool |
codesearch-dir-index |
0m
Args:
Results: map[Files:[attrib.c attrlist.c bitfunc.c bitmap.c debug.h dir.c file.c frecord.c fslog.c fsntfs.c index.c inode.c lznt.c namei.c ntfs.h ntfs_fs.h record.c run.c super.c upcase.c xattr.c] Subdirs:[lib]]
|
| 134/4 |
2026/09/17 10:56 |
llm |
codeexpert |
0m
Model:
Tokens:
input: 55186
output: 28
thoughts: 67
Thoughts: Here's my take on this β a quick scan and assessment, as I see it.
**Quick NTFS File System Investigation**
Okay, so I need to dive into this. Based on what's been flagged, I'm thinking the likely culprit lies within the NTFS file system code. I'll need to double-check a few key functions: `ntfs_read_folio`, `ntfs_iomap_begin`, and the `iomap_read_inline_data` routines. Seems like a read operation issue somewhere. The question is, where exactly is the hiccup?
My first step is to locate those functions within the file system code, specifically within the `fs/ntfs3` directory. That will give me a point of departure, and I can start tracing through the execution flow to see where the problem is originating. From there, I can begin to assess how the data is being read and identify any potential bottlenecks or logical errors.
|
| 135/4 |
2026/09/17 10:57 |
tool |
grepper |
0m
Args: map[Expression:read_folio PathPrefix:fs/ntfs3]
Results: map[Output:fs/ntfs3/frecord.c=1896=static struct folio *ntfs_lock_new_page(struct address_space *mapping,
--
fs/ntfs3/frecord.c-1923-/*
fs/ntfs3/frecord.c:1924: * ni_read_folio_cmpr
fs/ntfs3/frecord.c-1925- *
--
fs/ntfs3/frecord.c-1928- */
fs/ntfs3/frecord.c:1929:int ni_read_folio_cmpr(struct ntfs_inode *ni, struct folio *folio)
fs/ntfs3/frecord.c-1930-{
--
fs/ntfs3/inode.c=813=static void ntfs_iomap_bio_submit_read(const struct iomap_iter *iter,
fs/ntfs3/inode.c:814: struct iomap_read_folio_ctx *ctx)
fs/ntfs3/inode.c-815-{
--
fs/ntfs3/inode.c=820=static const struct iomap_read_ops ntfs_iomap_bio_read_ops = {
fs/ntfs3/inode.c:821: .read_folio_range = iomap_bio_read_folio_range,
fs/ntfs3/inode.c-822- .submit_read = ntfs_iomap_bio_submit_read,
--
fs/ntfs3/inode.c-825-
fs/ntfs3/inode.c:826:static int ntfs_read_folio(struct file *file, struct folio *folio)
fs/ntfs3/inode.c-827-{
--
fs/ntfs3/inode.c-832- loff_t vbo = folio_pos(folio);
fs/ntfs3/inode.c:833: struct iomap_read_folio_ctx ctx = {
fs/ntfs3/inode.c-834- .cur_folio = folio,
--
fs/ntfs3/inode.c-850- if (is_compressed(ni)) {
fs/ntfs3/inode.c:851: /* ni_lock is taken inside ni_read_folio_cmpr after page locks */
fs/ntfs3/inode.c:852: err = ni_read_folio_cmpr(ni, folio);
fs/ntfs3/inode.c-853- return err;
--
fs/ntfs3/inode.c-855-
fs/ntfs3/inode.c:856: iomap_read_folio(&ntfs_iomap_ops, &ctx, NULL);
fs/ntfs3/inode.c-857- return 0;
--
fs/ntfs3/inode.c=860=static void ntfs_readahead(struct readahead_control *rac)
--
fs/ntfs3/inode.c-864- struct ntfs_inode *ni = ntfs_i(inode);
fs/ntfs3/inode.c:865: struct iomap_read_folio_ctx ctx = {
fs/ntfs3/inode.c-866- .ops = &ntfs_iomap_bio_read_ops,
--
fs/ntfs3/inode.c=883=int ntfs_set_size(struct inode *inode, u64 new_size)
--
fs/ntfs3/inode.c-929- * - iomap_fiemap
fs/ntfs3/inode.c:930: * - iomap_bio_read_folio
fs/ntfs3/inode.c-931- * - iomap_bio_readahead
--
fs/ntfs3/inode.c=2301=const struct address_space_operations ntfs_aops = {
fs/ntfs3/inode.c:2302: .read_folio = ntfs_read_folio,
fs/ntfs3/inode.c-2303- .readahead = ntfs_readahead,
--
fs/ntfs3/inode.c=2312=const struct address_space_operations ntfs_aops_cmpr = {
fs/ntfs3/inode.c:2313: .read_folio = ntfs_read_folio,
fs/ntfs3/inode.c-2314- .dirty_folio = iomap_dirty_folio,
--
fs/ntfs3/ntfs_fs.h=616=int ni_write_inode(struct inode *inode, int sync, const char *hint);
fs/ntfs3/ntfs_fs.h-617-#define _ni_write_inode(i, w) ni_write_inode(i, w, __func__)
fs/ntfs3/ntfs_fs.h:618:int ni_read_folio_cmpr(struct ntfs_inode *ni, struct folio *folio);
fs/ntfs3/ntfs_fs.h-619-int ni_decompress_file(struct ntfs_inode *ni);
]
|
| 136/4 |
2026/09/17 10:57 |
llm |
codeexpert |
0m
Model:
Tokens:
input: 56795
output: 37
thoughts: 24
Thoughts: Here's a summary of my thought process, as if I were the one thinking it:
**Diving into the NTFS Read Function**
Okay, time to get my hands dirty. Let's start by digging into the `ntfs_read_folio` function. I need to understand exactly how NTFS3 handles folio reads, specifically within the `fs/ntfs3/inode.c` context. I'm assuming there's some interesting logic here related to how the file system interacts with the underlying storage and caches data. I'm keen to see how the implementation deals with block sizes, extent mapping, and any potential optimizations they've put in place for read performance. Perhaps I'll find some insights that could be leveraged elsewhere, or maybe even identify some subtle issues that might be worth investigating more deeply. It's time to become intimate with the code.
|
| 137/4 |
2026/09/17 10:57 |
tool |
read-file |
0m
Args: map[File:fs/ntfs3/inode.c FirstLine:825 LineCount:35]
Results: map[Contents: 825:
826: static int ntfs_read_folio(struct file *file, struct folio *folio)
827: {
828: int err;
829: struct address_space *mapping = folio->mapping;
830: struct inode *inode = mapping->host;
831: struct ntfs_inode *ni = ntfs_i(inode);
832: loff_t vbo = folio_pos(folio);
833: struct iomap_read_folio_ctx ctx = {
834: .cur_folio = folio,
835: .ops = &ntfs_iomap_bio_read_ops,
836: };
837:
838: if (unlikely(is_bad_ni(ni))) {
839: folio_unlock(folio);
840: return -EIO;
841: }
842:
843: if (ni->i_valid <= vbo) {
844: folio_zero_range(folio, 0, folio_size(folio));
845: folio_mark_uptodate(folio);
846: folio_unlock(folio);
847: return 0;
848: }
849:
850: if (is_compressed(ni)) {
851: /* ni_lock is taken inside ni_read_folio_cmpr after page locks */
852: err = ni_read_folio_cmpr(ni, folio);
853: return err;
854: }
855:
856: iomap_read_folio(&ntfs_iomap_ops, &ctx, NULL);
857: return 0;
858: }
859:
]
|
| 138/4 |
2026/09/17 10:57 |
llm |
codeexpert |
0m
Model:
Tokens:
input: 57554
output: 41
thoughts: 27
Thoughts: Okay, here's my interpretation of that thought process, assuming I'm already deep in kernel development and familiar with the NTFS3 filesystem:
**Diving into `ntfs_iomap_begin`**
Alright, time to get my hands dirty. I need to take a look at the `ntfs_iomap_begin` function. I know this is a core component for handling I/O mapping within the NTFS3 filesystem, and it's located right where it should be: `fs/ntfs3/inode.c`. I need to figure out how this function interacts with the rest of the file system and how it plays with data mapping. This is probably where the magic happens and I will need to delve into the details to understand it's role.
|
| 139/4 |
2026/09/17 10:57 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:fs/ntfs3/inode.c Name:ntfs_iomap_begin]
Results: map[SourceCode: 921: /*
922: * Function to get mapping vbo -> lbo.
923: * used with:
924: * - iomap_zero_range
925: * - iomap_truncate_page
926: * - iomap_dio_rw
927: * - iomap_file_buffered_write
928: * - iomap_bmap
929: * - iomap_fiemap
930: * - iomap_bio_read_folio
931: * - iomap_bio_readahead
932: */
933: static int ntfs_iomap_begin(struct inode *inode, loff_t offset, loff_t length,
934: unsigned int flags, struct iomap *iomap,
935: struct iomap *srcmap)
936: {
937: struct ntfs_inode *ni = ntfs_i(inode);
938: struct ntfs_sb_info *sbi = ni->mi.sbi;
939: u8 cluster_bits = sbi->cluster_bits;
940: CLST vcn = offset >> cluster_bits;
941: u32 off = offset & sbi->cluster_mask;
942: bool rw = flags & IOMAP_WRITE;
943: loff_t endbyte = offset + length;
944: void *res = NULL;
945: int err;
946: CLST lcn, clen, clen_max = 1;
947: bool new_clst = false;
948: bool no_da;
949: bool zero = false;
950: if (unlikely(ntfs3_forced_shutdown(sbi->sb)))
951: return -EIO;
952:
953: if (flags & IOMAP_REPORT) {
954: if (offset > ntfs_get_maxbytes(ni)) {
955: /* called from fiemap/bmap. */
956: return -EINVAL;
957: }
958:
959: if (offset >= inode->i_size) {
960: /* special code for report. */
961: return -ENOENT;
962: }
963: }
964:
965: if (IOMAP_ZERO == flags && (endbyte & sbi->cluster_mask)) {
966: rw = true;
967: } else if (rw) {
968: clen_max = bytes_to_cluster(sbi, endbyte) - vcn;
969: }
970:
971: /*
972: * Force to allocate clusters if directIO(write) or writeback_range.
973: * NOTE: attr_data_get_block allocates clusters only for sparse file.
974: * Normal file allocates clusters in attr_set_size.
975: */
976: no_da = flags == (IOMAP_DIRECT | IOMAP_WRITE) || srcmap == WB_NO_DA;
977:
978: err = attr_data_get_block(ni, vcn, clen_max, &lcn, &clen,
979: rw ? &new_clst : NULL, zero, &res, no_da);
980:
981: if (err) {
982: return err;
983: }
984:
985: if (lcn == EOF_LCN) {
986: /* request out of file. */
987: if (flags & IOMAP_REPORT) {
988: /* special code for report. */
989: return -ENOENT;
990: }
991:
992: if (rw) {
993: /* should never be here. */
994: return -EINVAL;
995: }
996: lcn = SPARSE_LCN;
997: }
998:
999: iomap->flags = new_clst ? IOMAP_F_NEW : 0;
1000:
1001: if (lcn == RESIDENT_LCN) {
1002: if (offset >= clen) {
1003: if (res)
1004: __free_page(virt_to_page(res));
1005: if (flags & IOMAP_REPORT) {
1006: /* special code for report. */
1007: return -ENOENT;
1008: }
1009: return -EFAULT;
1010: }
1011:
1012: iomap->private = iomap->inline_data = res;
1013: iomap->type = IOMAP_INLINE;
1014: iomap->offset = 0;
1015: iomap->length = clen; /* resident size in bytes. */
1016: return 0;
1017: }
1018:
1019: if (!clen) {
1020: /* broken file? */
1021: return -EINVAL;
1022: }
1023:
1024: iomap->bdev = inode->i_sb->s_bdev;
1025: iomap->offset = offset;
1026: iomap->length = ((loff_t)clen << cluster_bits) - off;
1027:
1028: if (lcn == COMPRESSED_LCN) {
1029: /* should never be here. */
1030: return -EOPNOTSUPP;
1031: }
1032:
1033: if (lcn == DELALLOC_LCN) {
1034: iomap->type = IOMAP_DELALLOC;
1035: iomap->addr = IOMAP_NULL_ADDR;
1036: } else {
1037: /* Translate clusters into bytes. */
1038: iomap->addr = ((loff_t)lcn << cluster_bits) + off;
1039: if (length && iomap->length > length)
1040: iomap->length = length;
1041: else
1042: endbyte = offset + iomap->length;
1043:
1044: if (lcn == SPARSE_LCN) {
1045: iomap->addr = IOMAP_NULL_ADDR;
1046: iomap->type = IOMAP_HOLE;
1047: // if (IOMAP_ZERO == flags && !off) {
1048: // iomap->length = (endbyte - offset) &
1049: // sbi->cluster_mask_inv;
1050: // }
1051: } else if (endbyte <= ni->i_valid) {
1052: iomap->type = IOMAP_MAPPED;
1053: } else if (offset < ni->i_valid) {
1054: iomap->type = IOMAP_MAPPED;
1055: if (flags & IOMAP_REPORT)
1056: iomap->length = ni->i_valid - offset;
1057: } else if (rw || (flags & IOMAP_ZERO)) {
1058: iomap->type = IOMAP_MAPPED;
1059: } else {
1060: iomap->type = IOMAP_UNWRITTEN;
1061: }
1062: }
1063:
1064: if ((flags & IOMAP_ZERO) &&
1065: (iomap->type == IOMAP_MAPPED || iomap->type == IOMAP_DELALLOC)) {
1066: /* Avoid too large requests. */
1067: u32 tail;
1068: u32 off_a = offset & (PAGE_SIZE - 1);
1069: if (off_a)
1070: tail = PAGE_SIZE - off_a;
1071: else
1072: tail = PAGE_SIZE;
1073:
1074: if (iomap->length > tail)
1075: iomap->length = tail;
1076: }
1077:
1078: return 0;
1079: }
SourceFile:fs/ntfs3/inode.c]
|
| 140/4 |
2026/09/17 10:57 |
llm |
codeexpert |
0m
Model:
Tokens:
input: 60223
output: 34
thoughts: 208
Thoughts: **Analyzing NTFS Inline Data Handling**
Okay, let's break this down. I'm looking at the `ntfs_iomap_begin` function first. Specifically, I'm examining the scenario where `lcn` (logical cluster number) is equal to `RESIDENT_LCN`. This tells me we're dealing with inline data β data stored directly within the file's metadata.
The first check is crucial: `if (offset >= clen)`. If the requested `offset` into the data is beyond the resident `clen` (content length, in bytes), we have a problem. If we have a `res` variable, meaning resident data, we free the associated page. Then, the logic splits. If the call has `IOMAP_REPORT` set, it's an error report. We return `-ENOENT`. Otherwise, we return `-EFAULT` because this means data requested exceeds what is resident.
If that check passes, we're in the happy path of accessing the inline data. The function sets `iomap->private` and `iomap->inline_data` to `res`. This means we're pointing to the resident data. The iomap's `type` is set to `IOMAP_INLINE`, and the offset and length are also set to correctly describe the inline data. This seems straightforward β we're essentially creating a data descriptor for the inline data.
Now, I need to see how that inline data is actually read. That means turning to `iomap_read_inline_data` in `fs/iomap/buffered-io.c`. I expect to see how this `iomap` structure is used to retrieve the data. This will be the key to understanding how inline data is handled in the buffered I/O path.
|
| 141/4 |
2026/09/17 10:58 |
tool |
grepper |
0m
Args: map[Expression:iomap_read_inline_data PathPrefix:fs/iomap]
Results: map[Output:fs/iomap/buffered-io.c=382=static inline bool iomap_block_needs_zeroing(const struct iomap_iter *iter,
--
fs/iomap/buffered-io.c-409-/**
fs/iomap/buffered-io.c:410: * iomap_read_inline_data - copy inline data into the page cache
fs/iomap/buffered-io.c-411- * @iter: iteration structure
--
fs/iomap/buffered-io.c-417- */
fs/iomap/buffered-io.c:418:static int iomap_read_inline_data(const struct iomap_iter *iter,
fs/iomap/buffered-io.c-419- struct folio *folio)
--
fs/iomap/buffered-io.c=557=static int iomap_read_folio_iter(struct iomap_iter *iter,
--
fs/iomap/buffered-io.c-570- if (iomap->type == IOMAP_INLINE) {
fs/iomap/buffered-io.c:571: ret = iomap_read_inline_data(iter, folio);
fs/iomap/buffered-io.c-572- if (ret)
--
fs/iomap/buffered-io.c=1019=static int iomap_write_begin_inline(const struct iomap_iter *iter,
--
fs/iomap/buffered-io.c-1024- return -EIO;
fs/iomap/buffered-io.c:1025: return iomap_read_inline_data(iter, folio);
fs/iomap/buffered-io.c-1026-}
]
|
| 142/4 |
2026/09/17 10:58 |
llm |
codeexpert |
0m
Model:
Tokens:
input: 61320
output: 44
thoughts: 15
Thoughts: Okay, let's dive into `iomap_read_inline_data`. This function's name alone hints at a key optimization related to how we handle data directly within the inode or file system metadata, specifically during a read operation. It's about pulling data "inline," as opposed to having to fetch it from a separate block on disk. This likely means we're dealing with small files or very fragmented files where the data is small enough to fit within the inode itself or a closely associated data structure.
I need to understand the conditions triggering this path. When do we *choose* to read data in this way? What's the criteria? Is it file size, fragmentation, specific flags set on the inode, or perhaps a combination of these factors? I suspect there are thresholds involved.
Next, I'll need to look at what data structures are accessed and how they are handled. Is the data copied directly to the user's buffer, or are there intermediate buffers involved? Are we bypassing the standard page cache here or still using it in some fashion? I'll have to see if there's any cache invalidation or update logic.
I need to scrutinize any error handling. What happens if the data is corrupted or if there's a problem accessing the metadata? Does it fall back to a slower, more general read path? Are there any security considerations or potential race conditions that need careful examination, especially with concurrent reads?
Finally, how does this interact with other file system features? What about extended attributes or ACLs? Are there any performance implications when the "inline" data grows too large, requiring the file system to shift to a different data placement strategy? I'm expecting this to be an optimization for small files, but I need to fully understand its impact. Let's start reading...
|
| 143/4 |
2026/09/17 10:58 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:fs/iomap/buffered-io.c Name:iomap_read_inline_data]
Results: map[SourceCode: 409: /**
410: * iomap_read_inline_data - copy inline data into the page cache
411: * @iter: iteration structure
412: * @folio: folio to copy to
413: *
414: * Copy the inline data in @iter into @folio and zero out the rest of the folio.
415: * Only a single IOMAP_INLINE extent is allowed at the end of each file.
416: * Returns zero for success to complete the read, or the usual negative errno.
417: */
418: static int iomap_read_inline_data(const struct iomap_iter *iter,
419: struct folio *folio)
420: {
421: const struct iomap *iomap = iomap_iter_srcmap(iter);
422: size_t size = i_size_read(iter->inode) - iomap->offset;
423: size_t offset = offset_in_folio(folio, iomap->offset);
424:
425: if (WARN_ON_ONCE(!iomap->inline_data))
426: return -EIO;
427:
428: if (folio_test_uptodate(folio))
429: return 0;
430:
431: if (WARN_ON_ONCE(size > iomap->length)) {
432: fserror_report_io(iter->inode, FSERR_BUFFERED_READ,
433: iomap->offset, size, -EIO, GFP_NOFS);
434: return -EIO;
435: }
436: if (offset > 0)
437: ifs_alloc(iter->inode, folio, iter->flags);
438:
439: folio_fill_tail(folio, offset, iomap->inline_data, size);
440: iomap_set_range_uptodate(folio, offset, folio_size(folio) - offset);
441: return 0;
442: }
SourceFile:fs/iomap/buffered-io.c]
|
| 144/4 |
2026/09/17 10:58 |
llm |
codeexpert |
0m
Model:
Tokens:
input: 62380
output: 34
thoughts: 729
Thoughts: **Analyzing a Potential Race Condition in NTFS File Extension**
Okay, so this is an interesting one. It appears we've got a potential race condition when extending an NTFS file's size in `ntfs_setattr`. The core issue, as I understand it, stems from the order of operations: `truncate_setsize` is called *before* the on-disk size is updated via `ntfs_set_size`. This timing opens a window for a concurrent page fault to cause a read of stale data.
Let me break down my understanding. `iomap_read_inline_data` is being called, and it's detecting an inconsistency: the file size reported by the inode (`i_size_read`) is greater than the expected inline data length. This discrepancy triggers a warning. The sequence is as follows: `truncate_setsize` increases the inode's `i_size`. A concurrent page fault then occurs, triggering a read that, via the iomap logic, checks the inline data. Because the on-disk size hasn't been updated yet via `ntfs_set_size`, we read the *old* value, resulting in `iomap->length` being smaller than the updated `i_size`.
The crucial question is, of course, whether the existing order of operations in `ntfs_setattr` is correct. The warning hints that it might not be, and the comparison to ext4 and xfs confirms this suspicion. Those filesystems either allocate blocks or update the on-disk size *before* calling `truncate_setsize`, or they use a lock to prevent concurrent reads. This suggests that the current NTFS approach is vulnerable.
Now, my line of inquiry is clear: First, I need to get a really good handle on what `truncate_setsize` actually does, and specifically, what the expected sequence of actions should be when extending (and shrinking) file size. I also need to find out *how* file size operations are supposed to be protected in general. The question explicitly mentions locking. That requires me to understand what locks are held during `setattr` and page faulting. I need to understand what locks `filemap_fault` takes, and whether that is relevant here.
The potential solutions are:
1. **Reorder `truncate_setsize` and `ntfs_set_size`**: The simplest fix might be to call `ntfs_set_size` *before* `truncate_setsize`, ensuring the on-disk size is updated before the inode's `i_size` is increased. This is the simplest fix, but I need to make sure this doesn't create other issues.
2. **Add a Lock**: Add a lock around the operations in `ntfs_setattr` to prevent concurrent reads during the file size extension. This is more robust, but introduces more overhead.
3. **Refactor the Logic**: The underlying issue seems related to how we handle inline data and IOMAP in the context of file extension. Maybe the process of calling these methods can be reworked.
I need to dig into the relevant code, specifically the `filemap_fault` function, to confirm the locking assumptions and understand if there's an existing mechanism to prevent this race condition.
|
| 145/4 |
2026/09/17 10:59 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:mm/filemap.c Name:filemap_fault]
Results: map[SourceCode:3532: /**
3533: * filemap_fault - read in file data for page fault handling
3534: * @vmf: struct vm_fault containing details of the fault
3535: *
3536: * filemap_fault() is invoked via the vma operations vector for a
3537: * mapped memory region to read in file data during a page fault.
3538: *
3539: * The goto's are kind of ugly, but this streamlines the normal case of having
3540: * it in the page cache, and handles the special cases reasonably without
3541: * having a lot of duplicated code.
3542: *
3543: * vma->vm_mm->mmap_lock must be held on entry.
3544: *
3545: * If our return value has VM_FAULT_RETRY set, it's because the mmap_lock
3546: * may be dropped before doing I/O or by lock_folio_maybe_drop_mmap().
3547: *
3548: * If our return value does not have VM_FAULT_RETRY set, the mmap_lock
3549: * has not been released.
3550: *
3551: * We never return with VM_FAULT_RETRY and a bit from VM_FAULT_ERROR set.
3552: *
3553: * Return: bitwise-OR of %VM_FAULT_ codes.
3554: */
3555: vm_fault_t filemap_fault(struct vm_fault *vmf)
3556: {
3557: int error;
3558: struct file *file = vmf->vma->vm_file;
3559: struct file *fpin = NULL;
3560: struct address_space *mapping = file->f_mapping;
3561: struct inode *inode = mapping->host;
3562: pgoff_t max_idx, index = vmf->pgoff;
3563: struct folio *folio;
3564: vm_fault_t ret = 0;
3565: bool mapping_locked = false;
3566:
3567: max_idx = DIV_ROUND_UP(i_size_read(inode), PAGE_SIZE);
3568: if (unlikely(index >= max_idx))
3569: return VM_FAULT_SIGBUS;
3570:
3571: trace_mm_filemap_fault(mapping, index);
3572:
3573: /*
3574: * Do we have something in the page cache already?
3575: */
3576: folio = filemap_get_folio(mapping, index);
3577: if (likely(!IS_ERR(folio))) {
3578: /*
3579: * We found the page, so try async readahead before waiting for
3580: * the lock.
3581: */
3582: if (!(vmf->flags & FAULT_FLAG_TRIED))
3583: fpin = do_async_mmap_readahead(vmf, folio);
3584: if (unlikely(!folio_test_uptodate(folio))) {
3585: filemap_invalidate_lock_shared(mapping);
3586: mapping_locked = true;
3587: }
3588: } else {
3589: ret = filemap_fault_recheck_pte_none(vmf);
3590: if (unlikely(ret))
3591: return ret;
3592:
3593: /* No page in the page cache at all */
3594: count_vm_event(PGMAJFAULT);
3595: count_memcg_event_mm(vmf->vma->vm_mm, PGMAJFAULT);
3596: ret = VM_FAULT_MAJOR;
3597: fpin = do_sync_mmap_readahead(vmf);
3598: retry_find:
3599: /*
3600: * See comment in filemap_create_folio() why we need
3601: * invalidate_lock
3602: */
3603: if (!mapping_locked) {
3604: filemap_invalidate_lock_shared(mapping);
3605: mapping_locked = true;
3606: }
3607: folio = __filemap_get_folio(mapping, index,
3608: FGP_CREAT|FGP_FOR_MMAP,
3609: vmf->gfp_mask);
3610: if (IS_ERR(folio)) {
3611: if (fpin)
3612: goto out_retry;
3613: filemap_invalidate_unlock_shared(mapping);
3614: return VM_FAULT_OOM;
3615: }
3616: }
3617:
3618: if (!lock_folio_maybe_drop_mmap(vmf, folio, &fpin))
3619: goto out_retry;
3620:
3621: /* Did it get truncated? */
3622: if (unlikely(folio->mapping != mapping)) {
3623: folio_unlock(folio);
3624: folio_put(folio);
3625: goto retry_find;
3626: }
3627: VM_BUG_ON_FOLIO(!folio_contains(folio, index), folio);
3628:
3629: /*
3630: * We have a locked folio in the page cache, now we need to check
3631: * that it's up-to-date. If not, it is going to be due to an error,
3632: * or because readahead was otherwise unable to retrieve it.
3633: */
3634: if (unlikely(!folio_test_uptodate(folio))) {
3635: /*
3636: * If the invalidate lock is not held, the folio was in cache
3637: * and uptodate and now it is not. Strange but possible since we
3638: * didn't hold the page lock all the time. Let's drop
3639: * everything, get the invalidate lock and try again.
3640: */
3641: if (!mapping_locked) {
3642: folio_unlock(folio);
3643: folio_put(folio);
3644: goto retry_find;
3645: }
3646:
3647: /*
3648: * OK, the folio is really not uptodate. This can be because the
3649: * VMA has the VM_RAND_READ flag set, or because an error
3650: * arose. Let's read it in directly.
3651: */
3652: goto page_not_uptodate;
3653: }
3654:
3655: /*
3656: * We've made it this far and we had to drop our mmap_lock, now is the
3657: * time to return to the upper layer and have it re-find the vma and
3658: * redo the fault.
3659: */
3660: if (fpin) {
3661: folio_unlock(folio);
3662: goto out_retry;
3663: }
3664: if (mapping_locked)
3665: filemap_invalidate_unlock_shared(mapping);
3666:
3667: /*
3668: * Found the page and have a reference on it.
3669: * We must recheck i_size under page lock.
3670: */
3671: max_idx = DIV_ROUND_UP(i_size_read(inode), PAGE_SIZE);
3672: if (unlikely(index >= max_idx)) {
3673: folio_unlock(folio);
3674: folio_put(folio);
3675: return VM_FAULT_SIGBUS;
3676: }
3677:
3678: vmf->page = folio_file_page(folio, index);
3679: return ret | VM_FAULT_LOCKED;
3680:
3681: page_not_uptodate:
3682: /*
3683: * Umm, take care of errors if the page isn't up-to-date.
3684: * Try to re-read it _once_. We do this synchronously,
3685: * because there really aren't any performance issues here
3686: * and we need to check for errors.
3687: */
3688: fpin = maybe_unlock_mmap_for_io(vmf, fpin);
3689: error = filemap_read_folio(file, mapping->a_ops->read_folio, folio);
3690: if (fpin)
3691: goto out_retry;
3692: folio_put(folio);
3693:
3694: if (!error || error == AOP_TRUNCATED_PAGE)
3695: goto retry_find;
3696: filemap_invalidate_unlock_shared(mapping);
3697:
3698: return VM_FAULT_SIGBUS;
3699:
3700: out_retry:
3701: /*
3702: * We dropped the mmap_lock, we need to return to the fault handler to
3703: * re-find the vma and come back and find our hopefully still populated
3704: * page.
3705: */
3706: if (!IS_ERR(folio))
3707: folio_put(folio);
3708: if (mapping_locked)
3709: filemap_invalidate_unlock_shared(mapping);
3710: if (fpin)
3711: fput(fpin);
3712: return ret | VM_FAULT_RETRY;
3713: }
SourceFile:mm/filemap.c]
|
| 146/4 |
2026/09/17 10:59 |
llm |
codeexpert |
0m
Model:
Tokens:
input: 66624
output: 30
thoughts: 297
Thoughts: **Analyzing `filemap_fault` and Invalidation Locks**
Okay, let's dive into this `filemap_fault` function. I see it handles situations where a folio isn't in the page cache or is out-of-date. Specifically, I'm focusing on this bit where `!mapping_locked` triggers `filemap_invalidate_lock_shared(mapping)`. That's a key observation.
Now, looking at `page_not_uptodate`, it seems that `mapping_locked` becomes `TRUE` by the time `filemap_read_folio` is called. That makes sense, because `filemap_invalidate_lock_shared(mapping)` is held while calling `read_folio` during the fault handling process. So, `filemap_read_folio` is protected by the shared lock. Good, good.
But wait a minute... what about `filemap_invalidate_lock(mapping)`? I'm thinking about its use in `setattr`. If someone calls `filemap_invalidate_lock(mapping)` in `setattr`, doesn't that mean `filemap_fault` will block on `filemap_invalidate_lock_shared(mapping)`? Yes, it seems so. This potential for contention is a critical point to consider.
Now, the question is, does `filemap_invalidate_lock` also cover truncate or extension operations? That's what I need to understand completely. The locking implications are potentially quite broad. I'll need to dig into the documentation and see how `filemap_invalidate_lock` is *actually* used. Comments, specifically, are what I need to be searching for.
|
| 147/4 |
2026/09/17 10:59 |
tool |
grepper |
0m
Args: map[Expression:invalidate_lock PathPrefix:include/linux/fs.h]
Results: map[Output:include/linux/fs.h=446=struct mapping_metadata_bhs {
--
include/linux/fs.h-455- * @i_pages: Cached pages.
include/linux/fs.h:456: * @invalidate_lock: Guards coherency between page cache contents and
include/linux/fs.h-457- * file offset->disk block mappings in the filesystem during invalidates.
--
include/linux/fs.h=471=struct address_space {
--
include/linux/fs.h-473- struct xarray i_pages;
include/linux/fs.h:474: struct rw_semaphore invalidate_lock;
include/linux/fs.h-475- gfp_t gfp_mask;
--
include/linux/fs.h=1072=static inline void inode_lock_shared_nested(struct inode *inode, unsigned subclass)
--
include/linux/fs.h-1076-
include/linux/fs.h:1077:static inline void filemap_invalidate_lock(struct address_space *mapping)
include/linux/fs.h-1078-{
include/linux/fs.h:1079: down_write(&mapping->invalidate_lock);
include/linux/fs.h-1080-}
--
include/linux/fs.h=1082=static inline void filemap_invalidate_unlock(struct address_space *mapping)
include/linux/fs.h-1083-{
include/linux/fs.h:1084: up_write(&mapping->invalidate_lock);
include/linux/fs.h-1085-}
include/linux/fs.h-1086-
include/linux/fs.h:1087:static inline void filemap_invalidate_lock_shared(struct address_space *mapping)
include/linux/fs.h-1088-{
include/linux/fs.h:1089: down_read(&mapping->invalidate_lock);
include/linux/fs.h-1090-}
--
include/linux/fs.h=1092=static inline int filemap_invalidate_trylock_shared(
--
include/linux/fs.h-1094-{
include/linux/fs.h:1095: return down_read_trylock(&mapping->invalidate_lock);
include/linux/fs.h-1096-}
--
include/linux/fs.h=1098=static inline void filemap_invalidate_unlock_shared(
--
include/linux/fs.h-1100-{
include/linux/fs.h:1101: up_read(&mapping->invalidate_lock);
include/linux/fs.h-1102-}
--
include/linux/fs.h=1105=void unlock_two_nondirectories(struct inode *, struct inode*);
include/linux/fs.h-1106-
include/linux/fs.h:1107:void filemap_invalidate_lock_two(struct address_space *mapping1,
include/linux/fs.h-1108- struct address_space *mapping2);
--
include/linux/fs.h=2285=struct file_system_type {
--
include/linux/fs.h-2313- struct lock_class_key i_mutex_key;
include/linux/fs.h:2314: struct lock_class_key invalidate_lock_key;
include/linux/fs.h-2315- struct lock_class_key i_mutex_dir_key;
]
|
| 148/4 |
2026/09/17 10:59 |
llm |
codeexpert-compressor |
0m
Model:
Reply: ### Workspace & Investigation State Summary
#### 1. Core Problem Statement & Context
- **Issue**: In `fs/ntfs3/file.c` within `ntfs_setattr`, when extending file size (`newsize > oldsize`), `truncate_setsize(inode, newsize)` is invoked *before* `ntfs_set_size(inode, newsize)`.
- `truncate_setsize()` updates `inode->i_size` immediately via `i_size_write(inode, newsize)`.
- A concurrent page fault path (`ntfs_read_folio` -> `iomap_read_folio` -> `ntfs_iomap_begin`) reads the old resident attribute size from disk metadata (e.g. 5 bytes) because `ntfs_set_size` has not yet updated it, setting `iomap->length = 5` and `iomap->offset = 0`.
- Subsequently, `iomap_read_inline_data` evaluates `size = i_size_read(iter->inode) - iomap->offset` which reads the newly updated `i_size` (20 bytes).
- This results in `size > iomap->length` (20 > 5), triggering the kernel warning:
`WARN_ON_ONCE(size > iomap->length)`.
- **Questions Asked**:
1. Is it correct to call `truncate_setsize` before `ntfs_set_size` when extending the file size?
2. In ext4 and xfs, how do they order size updates and locking to prevent concurrent reads/faults from observing intermediate states?
3. How should this be fixed in `ntfs_setattr`?
---
#### 2. Code Snippets & Key Findings
##### A. `fs/ntfs3/file.c`: `ntfs_setattr()` (lines 726-752)
```c
if (ia_valid & ATTR_SIZE) {
loff_t newsize, oldsize;
if (WARN_ON(ni->ni_flags & NI_FLAG_COMPRESSED_MASK)) {
/* Should never be here, see ntfs_file_open(). */
err = -EOPNOTSUPP;
goto out;
}
inode_dio_wait(inode);
oldsize = i_size_read(inode);
newsize = attr->ia_size;
if (newsize != oldsize) {
truncate_setsize(inode, newsize);
err = ntfs_set_size(inode, newsize);
if (err) {
i_size_write(inode, oldsize);
goto out;
}
ni->std_fa |= FILE_ATTRIBUTE_ARCHIVE;
ni->ni_flags |= NI_FLAG_UPDATE_PARENT;
inode_set_mtime_to_ts(inode,
inode_set_ctime_current(inode));
}
}
```
##### B. `fs/ntfs3/inode.c`: `ntfs_set_size()` (lines 883-915)
```c
int ntfs_set_size(struct inode *inode, u64 new_size)
{
struct super_block *sb = inode->i_sb;
struct ntfs_sb_info *sbi = sb->s_fs_info;
struct ntfs_inode *ni = ntfs_i(inode);
int err;
/* Check for maximum file size. */
if (is_sparsed(ni) || is_compressed(ni)) {
if (new_size > sbi->maxbytes_sparse) {
return -EFBIG;
}
} else if (new_size > sbi->maxbytes) {
return -EFBIG;
}
/* Mark rw ntfs as dirty. It will be cleared at umount. */
ntfs_set_state(sbi, NTFS_DIRTY_DIRTY);
ni_lock(ni);
down_write(&ni->file.run_lock);
if (new_size < ni->i_valid)
ni->i_valid = new_size;
/* last 'true' means keep preallocated. */
err = attr_set_size(ni, ATTR_DATA, ni->file.ads.name, ni->file.ads.len,
&ni->file.run, new_size, &ni->i_valid, true);
up_write(&ni->file.run_lock);
ni_unlock(ni);
return err;
}
```
##### C. `mm/truncate.c`: `truncate_setsize()` (lines 816-824)
```c
void truncate_setsize(struct inode *inode, loff_t newsize)
{
loff_t oldsize = inode->i_size;
i_size_write(inode, newsize);
if (newsize > oldsize)
pagecache_isize_extended(inode, oldsize, newsize);
truncate_pagecache(inode, newsize);
}
```
*Note from comment:*
`Must be called with a lock serializing truncates and writes (generally i_rwsem but e.g. xfs uses a different lock) and before all filesystem specific block truncation has been performed.`
##### D. Reference Patterns from Other Filesystems
1. **`fs/ext4/inode.c` (`ext4_setattr`)**:
- Holds `filemap_invalidate_lock(inode->i_mapping)`.
- If shrinking (`shrink`): waits for DIO, takes `down_write(&EXT4_I(inode)->i_data_sem)`, updates disk size and `i_size_write(inode, attr->ia_size)`.
- If extending (`!shrink`): calls `ext4_block_zero_eof()`, updates disk size and `i_size_write()`, calls `pagecache_isize_extended(inode, oldsize, inode->i_size)`, then `truncate_pagecache(inode, inode->i_size)`.
- In both cases, pagecache invalidation / faults are blocked by `filemap_invalidate_lock()`, and `i_size` is only written when `i_disksize` is safely updated under locks.
2. **`fs/xfs/xfs_iops.c` (`xfs_vn_setattr` / `xfs_vn_setattr_size`)**:
- Acquires `xfs_ilock(ip, XFS_MMAPLOCK_EXCL)` in `xfs_vn_setattr()` before calling `xfs_vn_setattr_size()`.
- Serializes out any concurrent faults (`filemap_fault` / mmap faults take `MMAPLOCK_SHARED` or `filemap_invalidate_lock_shared`).
- Does zeroing of range on extension (`xfs_zero_range`), then calls `truncate_setsize(inode, newsize)`, writes on-disk metadata (`ip->i_disk_size = newsize`), commits transaction, and finally unlocks `XFS_MMAPLOCK_EXCL`.
3. **`fs/ntfs/file.c` (`ntfs_setattr_size`)**:
- Explicitly serializes:
```c
filemap_invalidate_lock(vi->i_mapping);
if (attr->ia_size > old_size) {
truncate_pagecache(vi, old_size);
i_size_write(vi, attr->ia_size);
pagecache_isize_extended(vi, old_size, attr->ia_size);
} else {
truncate_setsize(vi, attr->ia_size);
}
err = ntfs_truncate_vfs(vi, attr->ia_size, old_size);
if (err)
i_size_write(vi, old_size);
filemap_invalidate_unlock(vi->i_mapping);
```
4. **`fs/ntfs3/file.c` (`ntfs_fallocate`)**:
- Already uses `filemap_invalidate_lock(mapping)` for punch/collapse/insert range operations to serialize page faults and page cache operations.
---
#### 3. Investigation Approaches & Dead-Ends
- Grepped `truncate_setsize` across `fs/ext4` (found no direct calls; ext4 manually open-codes `i_size_write`, `pagecache_isize_extended`, and `truncate_pagecache` protected by `filemap_invalidate_lock` and `i_data_sem`).
- Grepped and reviewed `truncate_setsize` in `fs/xfs` (found `xfs_vn_setattr_size` uses `truncate_setsize`, protected by `XFS_MMAPLOCK_EXCL` which serializes page faults).
- Checked `filemap_invalidate_lock` usages across mm and fs:
- `filemap_fault()` takes `filemap_invalidate_lock_shared(mapping)` when instantiating or checking non-uptodate folios.
- `ntfs_setattr` currently does NOT take `filemap_invalidate_lock(inode->i_mapping)` around size modification.
- Checked commit `fd73f4a66598` on `fs/ntfs/file.c` (git blame revealed commit was simply a base commit / kernel release import; broad git-show dumped large diff of release tag - avoid full git-show on release tags).
---
#### 4. Hypotheses & Proposed Solutions to Evaluate
##### Why calling `truncate_setsize` before `ntfs_set_size` on file extension is problematic:
1. **Ordering issue**:
- For truncation down (`newsize < oldsize`), `truncate_setsize()` is typically called before block freeing so that userspace cannot read past EOF or see unallocated blocks.
- For file extension (`newsize > oldsize`), updating `i_size` in pagecache *before* metadata and disk allocation (or resident-to-nonresident transformation) causes concurrent readers/faults to observe inconsistent state where `i_size` > allocated size / attribute length.
2. **Missing Serialization / Locking**:
- `i_rwsem` protects against concurrent writes/truncates, but `filemap_fault()` only takes `filemap_invalidate_lock_shared(inode->i_mapping)`. It does NOT hold `i_rwsem`.
- Without `filemap_invalidate_lock(inode->i_mapping)` in `ntfs_setattr`, page faults can run concurrently with `ntfs_setattr`.
3. **Fix Strategy**:
- **Option A (Ordering & Locking)**:
- Wrap the size modification under `filemap_invalidate_lock(inode->i_mapping)` and `filemap_invalidate_unlock(inode->i_mapping)`.
- When `newsize > oldsize`: call `ntfs_set_size(inode, newsize)` *first* to update the resident/nonresident attributes and allocate backing space. Once metadata is updated, update `i_size` via `truncate_setsize(inode, newsize)` (or `i_size_write` + `pagecache_isize_extended`).
- When `newsize < oldsize`: `truncate_setsize(inode, newsize)` is called before `ntfs_set_size(inode, newsize)` to unmap/truncate page cache before deallocating clusters/shrinking attribute.
- Check how other iomap-based filesystems structure this and verify exact error rollback handling if `ntfs_set_size` fails.
Tokens:
input: 53502
output: 2680
thoughts: 0
|
| 149/4 |
2026/09/17 10:59 |
llm |
codeexpert |
0m
Model:
Tokens:
input: 19713
output: 37
thoughts: 0
|
| 150/4 |
2026/09/17 10:59 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:fs/ext4/inode.c Name:ext4_setattr]
Results: map[SourceCode:5985: /*
5986: * ext4_setattr()
5987: *
5988: * Called from notify_change.
5989: *
5990: * We want to trap VFS attempts to truncate the file as soon as
5991: * possible. In particular, we want to make sure that when the VFS
5992: * shrinks i_size, we put the inode on the orphan list and modify
5993: * i_disksize immediately, so that during the subsequent flushing of
5994: * dirty pages and freeing of disk blocks, we can guarantee that any
5995: * commit will leave the blocks being flushed in an unused state on
5996: * disk. (On recovery, the inode will get truncated and the blocks will
5997: * be freed, so we have a strong guarantee that no future commit will
5998: * leave these blocks visible to the user.)
5999: *
6000: * Another thing we have to assure is that if we are in ordered mode
6001: * and inode is still attached to the committing transaction, we must
6002: * we start writeout of all the dirty pages which are being truncated.
6003: * This way we are sure that all the data written in the previous
6004: * transaction are already on disk (truncate waits for pages under
6005: * writeback).
6006: *
6007: * Called with inode->i_rwsem down.
6008: */
6009: int ext4_setattr(struct mnt_idmap *idmap, struct dentry *dentry,
6010: struct iattr *attr)
6011: {
6012: struct inode *inode = d_inode(dentry);
6013: int error, rc = 0;
6014: int orphan = 0;
6015: const unsigned int ia_valid = attr->ia_valid;
6016: bool inc_ivers = true;
6017:
6018: error = ext4_emergency_state(inode->i_sb);
6019: if (unlikely(error))
6020: return error;
6021:
6022: if (unlikely(IS_IMMUTABLE(inode)))
6023: return -EPERM;
6024:
6025: if (unlikely(IS_APPEND(inode) &&
6026: (ia_valid & (ATTR_MODE | ATTR_UID |
6027: ATTR_GID | ATTR_TIMES_SET))))
6028: return -EPERM;
6029:
6030: error = setattr_prepare(idmap, dentry, attr);
6031: if (error)
6032: return error;
6033:
6034: error = fscrypt_prepare_setattr(dentry, attr);
6035: if (error)
6036: return error;
6037:
6038: if (is_quota_modification(idmap, inode, attr)) {
6039: error = dquot_initialize(inode);
6040: if (error)
6041: return error;
6042: }
6043:
6044: if (i_uid_needs_update(idmap, attr, inode) ||
6045: i_gid_needs_update(idmap, attr, inode)) {
6046: handle_t *handle;
6047:
6048: /* (user+group)*(old+new) structure, inode write (sb,
6049: * inode block, ? - but truncate inode update has it) */
6050: handle = ext4_journal_start(inode, EXT4_HT_QUOTA,
6051: (EXT4_MAXQUOTAS_INIT_BLOCKS(inode->i_sb) +
6052: EXT4_MAXQUOTAS_DEL_BLOCKS(inode->i_sb)) + 3);
6053: if (IS_ERR(handle)) {
6054: error = PTR_ERR(handle);
6055: goto err_out;
6056: }
6057:
6058: /* dquot_transfer() calls back ext4_get_inode_usage() which
6059: * counts xattr inode references.
6060: */
6061: down_read(&EXT4_I(inode)->xattr_sem);
6062: error = dquot_transfer(idmap, inode, attr);
6063: up_read(&EXT4_I(inode)->xattr_sem);
6064:
6065: if (error) {
6066: ext4_journal_stop(handle);
6067: return error;
6068: }
6069: /* Update corresponding info in inode so that everything is in
6070: * one transaction */
6071: i_uid_update(idmap, attr, inode);
6072: i_gid_update(idmap, attr, inode);
6073: error = ext4_mark_inode_dirty(handle, inode);
6074: ext4_journal_stop(handle);
6075: if (unlikely(error)) {
6076: return error;
6077: }
6078: }
6079:
6080: if (attr->ia_valid & ATTR_SIZE) {
6081: handle_t *handle;
6082: loff_t oldsize = inode->i_size;
6083: loff_t old_disksize;
6084: int shrink = (attr->ia_size < inode->i_size);
6085:
6086: if (!(ext4_test_inode_flag(inode, EXT4_INODE_EXTENTS))) {
6087: struct ext4_sb_info *sbi = EXT4_SB(inode->i_sb);
6088:
6089: if (attr->ia_size > sbi->s_bitmap_maxbytes) {
6090: return -EFBIG;
6091: }
6092: }
6093: if (!S_ISREG(inode->i_mode)) {
6094: return -EINVAL;
6095: }
6096:
6097: if (attr->ia_size == inode->i_size)
6098: inc_ivers = false;
6099:
6100: /*
6101: * If file has inline data but new size exceeds inline capacity,
6102: * convert to extent-based storage first to prevent inconsistent
6103: * state (inline flag set but size exceeds inline capacity).
6104: */
6105: if (ext4_has_inline_data(inode) &&
6106: attr->ia_size > EXT4_I(inode)->i_inline_size) {
6107: error = ext4_convert_inline_data(inode);
6108: if (error)
6109: goto err_out;
6110: }
6111:
6112: if (shrink) {
6113: if (ext4_should_order_data(inode)) {
6114: error = ext4_begin_ordered_truncate(inode,
6115: attr->ia_size);
6116: if (error)
6117: goto err_out;
6118: }
6119: /*
6120: * Blocks are going to be removed from the inode. Wait
6121: * for dio in flight.
6122: */
6123: inode_dio_wait(inode);
6124: }
6125:
6126: filemap_invalidate_lock(inode->i_mapping);
6127:
6128: rc = ext4_break_layouts(inode);
6129: if (rc) {
6130: filemap_invalidate_unlock(inode->i_mapping);
6131: goto err_out;
6132: }
6133:
6134: if (attr->ia_size != inode->i_size) {
6135: /* attach jbd2 jinode for EOF folio tail zeroing */
6136: if (attr->ia_size & (inode->i_sb->s_blocksize - 1) ||
6137: oldsize & (inode->i_sb->s_blocksize - 1)) {
6138: error = ext4_inode_attach_jinode(inode);
6139: if (error)
6140: goto out_mmap_sem;
6141: }
6142:
6143: /*
6144: * Update c/mtime and tail zero the EOF folio on
6145: * truncate up. ext4_truncate() handles the shrink case
6146: * below.
6147: */
6148: if (!shrink) {
6149: inode_set_mtime_to_ts(inode,
6150: inode_set_ctime_current(inode));
6151: if (oldsize & (inode->i_sb->s_blocksize - 1)) {
6152: error = ext4_block_zero_eof(inode,
6153: oldsize, LLONG_MAX);
6154: if (error)
6155: goto out_mmap_sem;
6156: }
6157: }
6158:
6159: handle = ext4_journal_start(inode, EXT4_HT_INODE, 3);
6160: if (IS_ERR(handle)) {
6161: error = PTR_ERR(handle);
6162: goto out_mmap_sem;
6163: }
6164: if (ext4_handle_valid(handle) && shrink) {
6165: error = ext4_orphan_add(handle, inode);
6166: orphan = 1;
6167: }
6168:
6169: if (shrink)
6170: ext4_fc_track_range(handle, inode,
6171: (attr->ia_size > 0 ? attr->ia_size - 1 : 0) >>
6172: inode->i_sb->s_blocksize_bits,
6173: EXT_MAX_BLOCKS - 1);
6174: else
6175: ext4_fc_track_range(
6176: handle, inode,
6177: (oldsize > 0 ? oldsize - 1 : oldsize) >>
6178: inode->i_sb->s_blocksize_bits,
6179: (attr->ia_size > 0 ? attr->ia_size - 1 : 0) >>
6180: inode->i_sb->s_blocksize_bits);
6181:
6182: down_write(&EXT4_I(inode)->i_data_sem);
6183: old_disksize = EXT4_I(inode)->i_disksize;
6184: EXT4_I(inode)->i_disksize = attr->ia_size;
6185:
6186: /*
6187: * We have to update i_size under i_data_sem together
6188: * with i_disksize to avoid races with writeback code
6189: * running ext4_wb_update_i_disksize().
6190: */
6191: if (!error)
6192: i_size_write(inode, attr->ia_size);
6193: else
6194: EXT4_I(inode)->i_disksize = old_disksize;
6195: up_write(&EXT4_I(inode)->i_data_sem);
6196: rc = ext4_mark_inode_dirty(handle, inode);
6197: if (!error)
6198: error = rc;
6199: ext4_journal_stop(handle);
6200: if (error)
6201: goto out_mmap_sem;
6202: if (!shrink) {
6203: pagecache_isize_extended(inode, oldsize,
6204: inode->i_size);
6205: } else if (ext4_should_journal_data(inode)) {
6206: ext4_wait_for_tail_page_commit(inode);
6207: }
6208: }
6209:
6210: /*
6211: * Truncate pagecache after we've waited for commit
6212: * in data=journal mode to make pages freeable.
6213: */
6214: truncate_pagecache(inode, inode->i_size);
6215: /*
6216: * Call ext4_truncate() even if i_size didn't change to
6217: * truncate possible preallocated blocks.
6218: */
6219: if (attr->ia_size <= oldsize) {
6220: rc = ext4_truncate(inode);
6221: if (rc)
6222: error = rc;
6223: }
6224: out_mmap_sem:
6225: filemap_invalidate_unlock(inode->i_mapping);
6226: }
6227:
6228: if (!error) {
6229: if (inc_ivers)
6230: inode_inc_iversion(inode);
6231: setattr_copy(idmap, inode, attr);
6232: mark_inode_dirty(inode);
6233: }
6234:
6235: /*
6236: * If the call to ext4_truncate failed to get a transaction handle at
6237: * all, we need to clean up the in-core orphan list manually.
6238: */
6239: if (orphan && inode->i_nlink)
6240: ext4_orphan_del(NULL, inode);
6241:
6242: if (!error && (ia_valid & ATTR_MODE))
6243: rc = posix_acl_chmod(idmap, dentry, inode->i_mode);
6244:
6245: err_out:
6246: if (error)
6247: ext4_std_error(inode->i_sb, error);
6248: if (!error)
6249: error = rc;
6250: return error;
6251: }
SourceFile:fs/ext4/inode.c]
|
| 151/4 |
2026/09/17 10:59 |
llm |
codeexpert |
0m
Model:
Tokens:
input: 23819
output: 45
thoughts: 0
|
| 152/4 |
2026/09/17 11:00 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:fs/xfs/xfs_iops.c Name:xfs_vn_setattr_size]
Results: map[SourceCode: 901: /*
902: * Truncate file. Must have write permission and not be a directory.
903: */
904: int
905: xfs_vn_setattr_size(
906: struct mnt_idmap *idmap,
907: struct dentry *dentry,
908: struct iattr *iattr)
909: {
910: struct inode *inode = d_inode(dentry);
911: struct xfs_inode *ip = XFS_I(inode);
912: struct xfs_mount *mp = ip->i_mount;
913: xfs_off_t oldsize = inode->i_size;
914: xfs_off_t newsize = iattr->ia_size;
915: struct xfs_trans *tp;
916: int error;
917: uint lock_flags = 0;
918: uint resblks = 0;
919: bool did_zeroing = false;
920: struct xfs_zone_alloc_ctx ac = { };
921:
922: xfs_assert_ilocked(ip, XFS_IOLOCK_EXCL | XFS_MMAPLOCK_EXCL);
923: ASSERT(S_ISREG(inode->i_mode));
924: ASSERT((iattr->ia_valid & (ATTR_UID|ATTR_GID|ATTR_ATIME|ATTR_ATIME_SET|
925: ATTR_MTIME_SET|ATTR_TIMES_SET)) == 0);
926:
927: trace_xfs_setattr(ip);
928:
929: error = xfs_vn_change_ok(idmap, dentry, iattr);
930: if (error)
931: return error;
932:
933: /*
934: * Short circuit the truncate case for zero length files.
935: */
936: if (newsize == 0 && oldsize == 0 && ip->i_df.if_nextents == 0) {
937: if (!(iattr->ia_valid & (ATTR_CTIME|ATTR_MTIME)))
938: return 0;
939:
940: /*
941: * Use the regular setattr path to update the timestamps.
942: */
943: iattr->ia_valid &= ~ATTR_SIZE;
944: return xfs_setattr_nonsize(idmap, dentry, ip, iattr);
945: }
946:
947: /*
948: * Make sure that the dquots are attached to the inode.
949: */
950: error = xfs_qm_dqattach(ip);
951: if (error)
952: return error;
953:
954: /*
955: * Wait for all direct I/O to complete.
956: */
957: inode_dio_wait(inode);
958:
959: /*
960: * Normally xfs_zoned_space_reserve is supposed to be called outside the
961: * IOLOCK. For truncate we can't do that since ->setattr is called with
962: * it already held by the VFS. So for now chicken out and try to
963: * allocate space under it.
964: *
965: * To avoid deadlocks this means we can't block waiting for space, which
966: * can lead to spurious -ENOSPC if there are no directly available
967: * blocks. We mitigate this a bit by allowing zeroing to dip into the
968: * reserved pool, but eventually the VFS calling convention needs to
969: * change.
970: */
971: if (xfs_is_zoned_inode(ip)) {
972: error = xfs_zoned_space_reserve(mp, 1,
973: XFS_ZR_NOWAIT | XFS_ZR_RESERVED, &ac);
974: if (error) {
975: if (error == -EAGAIN)
976: return -ENOSPC;
977: return error;
978: }
979: }
980:
981: /*
982: * File data changes must be complete before we start the transaction to
983: * modify the inode. This needs to be done before joining the inode to
984: * the transaction because the inode cannot be unlocked once it is a
985: * part of the transaction.
986: *
987: * Start with zeroing any data beyond EOF that we may expose on file
988: * extension, or zeroing out the rest of the block on a downward
989: * truncate.
990: */
991: if (newsize > oldsize) {
992: trace_xfs_zero_eof(ip, oldsize, newsize - oldsize);
993: error = xfs_zero_range(ip, oldsize, newsize - oldsize,
994: &ac, &did_zeroing);
995: } else {
996: error = xfs_truncate_page(ip, newsize, &ac, &did_zeroing);
997: }
998:
999: if (xfs_is_zoned_inode(ip))
1000: xfs_zoned_space_unreserve(mp, &ac);
1001:
1002: if (error)
1003: return error;
1004:
1005: /*
1006: * We've already locked out new page faults, so now we can safely remove
1007: * pages from the page cache knowing they won't get refaulted until we
1008: * drop the XFS_MMAP_EXCL lock after the extent manipulations are
1009: * complete. The truncate_setsize() call also cleans partial EOF page
1010: * PTEs on extending truncates and hence ensures sub-page block size
1011: * filesystems are correctly handled, too.
1012: *
1013: * We have to do all the page cache truncate work outside the
1014: * transaction context as the "lock" order is page lock->log space
1015: * reservation as defined by extent allocation in the writeback path.
1016: * Hence a truncate can fail with ENOMEM from xfs_trans_alloc(), but
1017: * having already truncated the in-memory version of the file (i.e. made
1018: * user visible changes). There's not much we can do about this, except
1019: * to hope that the caller sees ENOMEM and retries the truncate
1020: * operation.
1021: *
1022: * And we update in-core i_size and truncate page cache beyond newsize
1023: * before writeback the [i_disk_size, newsize] range, so we're
1024: * guaranteed not to write stale data past the new EOF on truncate down.
1025: */
1026: truncate_setsize(inode, newsize);
1027:
1028: /*
1029: * We are going to log the inode size change in this transaction so
1030: * any previous writes that are beyond the on disk EOF and the new
1031: * EOF that have not been written out need to be written here. If we
1032: * do not write the data out, we expose ourselves to the null files
1033: * problem. Note that this includes any block zeroing we did above;
1034: * otherwise those blocks may not be zeroed after a crash.
1035: */
1036: if (did_zeroing ||
1037: (newsize > ip->i_disk_size && oldsize != ip->i_disk_size)) {
1038: error = filemap_write_and_wait_range(VFS_I(ip)->i_mapping,
1039: ip->i_disk_size, newsize - 1);
1040: if (error)
1041: return error;
1042: }
1043:
1044: /*
1045: * For realtime inode with more than one block rtextsize, we need the
1046: * block reservation for bmap btree block allocations/splits that can
1047: * happen since it could split the tail written extent and convert the
1048: * right beyond EOF one to unwritten.
1049: */
1050: if (xfs_inode_has_bigrtalloc(ip))
1051: resblks = XFS_DIOSTRAT_SPACE_RES(mp, 0);
1052:
1053: error = xfs_trans_alloc(mp, &M_RES(mp)->tr_itruncate, resblks,
1054: 0, 0, &tp);
1055: if (error)
1056: return error;
1057:
1058: lock_flags |= XFS_ILOCK_EXCL;
1059: xfs_ilock(ip, XFS_ILOCK_EXCL);
1060: xfs_trans_ijoin(tp, ip, 0);
1061:
1062: /*
1063: * Only change the c/mtime if we are changing the size or we are
1064: * explicitly asked to change it. This handles the semantic difference
1065: * between truncate() and ftruncate() as implemented in the VFS.
1066: *
1067: * The regular truncate() case without ATTR_CTIME and ATTR_MTIME is a
1068: * special case where we need to update the times despite not having
1069: * these flags set. For all other operations the VFS set these flags
1070: * explicitly if it wants a timestamp update.
1071: */
1072: if (newsize != oldsize &&
1073: !(iattr->ia_valid & (ATTR_CTIME | ATTR_MTIME))) {
1074: iattr->ia_ctime = iattr->ia_mtime =
1075: current_time(inode);
1076: iattr->ia_valid |= ATTR_CTIME | ATTR_MTIME;
1077: }
1078:
1079: /*
1080: * The first thing we do is set the size to new_size permanently on
1081: * disk. This way we don't have to worry about anyone ever being able
1082: * to look at the data being freed even in the face of a crash.
1083: * What we're getting around here is the case where we free a block, it
1084: * is allocated to another file, it is written to, and then we crash.
1085: * If the new data gets written to the file but the log buffers
1086: * containing the free and reallocation don't, then we'd end up with
1087: * garbage in the blocks being freed. As long as we make the new size
1088: * permanent before actually freeing any blocks it doesn't matter if
1089: * they get written to.
1090: */
1091: ip->i_disk_size = newsize;
1092: xfs_trans_log_inode(tp, ip, XFS_ILOG_CORE);
1093:
1094: if (newsize <= oldsize) {
1095: error = xfs_itruncate_extents(&tp, ip, XFS_DATA_FORK, newsize);
1096: if (error)
1097: goto out_trans_cancel;
1098:
1099: /*
1100: * Truncated "down", so we're removing references to old data
1101: * here - if we delay flushing for a long time, we expose
1102: * ourselves unduly to the notorious NULL files problem. So,
1103: * we mark this inode and flush it when the file is closed,
1104: * and do not wait the usual (long) time for writeout.
1105: */
1106: xfs_iflags_set(ip, XFS_ITRUNCATED);
1107:
1108: /* A truncate down always removes post-EOF blocks. */
1109: xfs_inode_clear_eofblocks_tag(ip);
1110: }
1111:
1112: setattr_copy(idmap, inode, iattr);
1113: xfs_trans_log_inode(tp, ip, XFS_ILOG_CORE);
1114:
1115: XFS_STATS_INC(mp, xs_ig_attrchg);
1116:
1117: if (xfs_has_wsync(mp))
1118: xfs_trans_set_sync(tp);
1119:
1120: error = xfs_trans_commit(tp);
1121: out_unlock:
1122: if (lock_flags)
1123: xfs_iunlock(ip, lock_flags);
1124: return error;
1125:
1126: out_trans_cancel:
1127: xfs_trans_cancel(tp);
1128: goto out_unlock;
1129: }
SourceFile:fs/xfs/xfs_iops.c]
|
| 153/4 |
2026/09/17 11:00 |
llm |
codeexpert |
0m
Model:
Tokens:
input: 27671
output: 43
thoughts: 0
|
| 154/4 |
2026/09/17 11:00 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:fs/xfs/xfs_iops.c Name:xfs_vn_setattr]
Results: map[SourceCode:1131: STATIC int
1132: xfs_vn_setattr(
1133: struct mnt_idmap *idmap,
1134: struct dentry *dentry,
1135: struct iattr *iattr)
1136: {
1137: struct inode *inode = d_inode(dentry);
1138: struct xfs_inode *ip = XFS_I(inode);
1139: int error;
1140:
1141: if (iattr->ia_valid & ATTR_SIZE) {
1142: uint iolock;
1143:
1144: xfs_ilock(ip, XFS_MMAPLOCK_EXCL);
1145: iolock = XFS_IOLOCK_EXCL | XFS_MMAPLOCK_EXCL;
1146:
1147: error = xfs_break_layouts(inode, &iolock, BREAK_UNMAP);
1148: if (error) {
1149: xfs_iunlock(ip, XFS_MMAPLOCK_EXCL);
1150: return error;
1151: }
1152:
1153: error = xfs_vn_setattr_size(idmap, dentry, iattr);
1154: xfs_iunlock(ip, XFS_MMAPLOCK_EXCL);
1155: } else {
1156: trace_xfs_setattr(ip);
1157:
1158: error = xfs_vn_change_ok(idmap, dentry, iattr);
1159: if (!error)
1160: error = xfs_setattr_nonsize(idmap, dentry, ip, iattr);
1161: }
1162:
1163: return error;
1164: }
SourceFile:fs/xfs/xfs_iops.c]
|
| 155/4 |
2026/09/17 11:00 |
llm |
codeexpert |
0m
Model:
Tokens:
input: 28269
output: 42
thoughts: 0
|
| 156/4 |
2026/09/17 11:00 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:fs/xfs/xfs_file.c Name:xfs_filemap_fault]
Results: map[SourceCode:2076: static vm_fault_t
2077: xfs_filemap_fault(
2078: struct vm_fault *vmf)
2079: {
2080: struct inode *inode = file_inode(vmf->vma->vm_file);
2081:
2082: /* DAX can shortcut the normal fault path on write faults! */
2083: if (IS_DAX(inode)) {
2084: if (xfs_is_write_fault(vmf))
2085: return xfs_write_fault(vmf, 0);
2086: return xfs_dax_read_fault(vmf, 0);
2087: }
2088:
2089: trace_xfs_read_fault(XFS_I(inode), 0);
2090: return filemap_fault(vmf);
2091: }
SourceFile:fs/xfs/xfs_file.c]
|
| 157/4 |
2026/09/17 11:00 |
llm |
codeexpert |
0m
Model:
Tokens:
input: 28600
output: 45
thoughts: 0
|
| 158/4 |
2026/09/17 11:00 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:fs/xfs/xfs_file.c Name:xfs_filemap_page_mkwrite]
Results: map[SourceCode:2107: static vm_fault_t
2108: xfs_filemap_page_mkwrite(
2109: struct vm_fault *vmf)
2110: {
2111: return xfs_write_fault(vmf, 0);
2112: }
SourceFile:fs/xfs/xfs_file.c]
|
| 159/4 |
2026/09/17 11:01 |
llm |
codeexpert |
0m
Model:
Tokens:
input: 28763
output: 41
thoughts: 0
|
| 160/4 |
2026/09/17 11:01 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:fs/xfs/xfs_file.c Name:xfs_write_fault]
Results: map[SourceCode:2058: static vm_fault_t
2059: xfs_write_fault(
2060: struct vm_fault *vmf,
2061: unsigned int order)
2062: {
2063: if (xfs_is_zoned_inode(XFS_I(file_inode(vmf->vma->vm_file))))
2064: return xfs_write_fault_zoned(vmf, order);
2065: return __xfs_write_fault(vmf, order, NULL);
2066: }
SourceFile:fs/xfs/xfs_file.c]
|
| 161/4 |
2026/09/17 11:01 |
llm |
codeexpert |
0m
Model:
Tokens:
input: 28991
output: 42
thoughts: 0
|
| 162/4 |
2026/09/17 11:01 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:fs/xfs/xfs_file.c Name:__xfs_write_fault]
Results: map[SourceCode:1983: /*
1984: * Locking for serialisation of IO during page faults. This results in a lock
1985: * ordering of:
1986: *
1987: * mmap_lock (MM)
1988: * sb_start_pagefault(vfs, freeze)
1989: * invalidate_lock (vfs/XFS_MMAPLOCK - truncate serialisation)
1990: * page_lock (MM)
1991: * i_lock (XFS - extent map serialisation)
1992: */
1993: static vm_fault_t
1994: __xfs_write_fault(
1995: struct vm_fault *vmf,
1996: unsigned int order,
1997: struct xfs_zone_alloc_ctx *ac)
1998: {
1999: struct inode *inode = file_inode(vmf->vma->vm_file);
2000: struct xfs_inode *ip = XFS_I(inode);
2001: unsigned int lock_mode = XFS_MMAPLOCK_SHARED;
2002: vm_fault_t ret;
2003:
2004: trace_xfs_write_fault(ip, order);
2005:
2006: sb_start_pagefault(inode->i_sb);
2007: file_update_time(vmf->vma->vm_file);
2008:
2009: /*
2010: * Normally we only need the shared mmaplock, but if a reflink remap is
2011: * in progress we take the exclusive lock to wait for the remap to
2012: * finish before taking a write fault.
2013: */
2014: xfs_ilock(ip, XFS_MMAPLOCK_SHARED);
2015: if (xfs_iflags_test(ip, XFS_IREMAPPING)) {
2016: xfs_iunlock(ip, XFS_MMAPLOCK_SHARED);
2017: xfs_ilock(ip, XFS_MMAPLOCK_EXCL);
2018: lock_mode = XFS_MMAPLOCK_EXCL;
2019: }
2020:
2021: if (IS_DAX(inode))
2022: ret = xfs_dax_fault_locked(vmf, order, true);
2023: else
2024: ret = iomap_page_mkwrite(vmf, &xfs_buffered_write_iomap_ops,
2025: ac);
2026: xfs_iunlock(ip, lock_mode);
2027:
2028: sb_end_pagefault(inode->i_sb);
2029: return ret;
2030: }
SourceFile:fs/xfs/xfs_file.c]
|
| 163/4 |
2026/09/17 11:01 |
llm |
codeexpert |
0m
Model:
Tokens:
input: 29852
output: 30
thoughts: 0
|
| 164/4 |
2026/09/17 11:02 |
tool |
grepper |
0m
Args: map[Expression:XFS_MMAPLOCK PathPrefix:fs/xfs]
Results: map[Output:fs/xfs/scrub/bmap.c=34=xchk_setup_inode_bmap(
--
fs/xfs/scrub/bmap.c-57-
fs/xfs/scrub/bmap.c:58: xchk_ilock(sc, XFS_MMAPLOCK_EXCL);
fs/xfs/scrub/bmap.c-59-
--
fs/xfs/scrub/quotacheck.c=392=xqcheck_collect_inode(
--
fs/xfs/scrub/quotacheck.c-417- if (isreg)
fs/xfs/scrub/quotacheck.c:418: xfs_ilock(ip, XFS_MMAPLOCK_SHARED);
fs/xfs/scrub/quotacheck.c-419- if (XFS_IS_REALTIME_INODE(ip)) {
--
fs/xfs/scrub/quotacheck.c-478- if (isreg)
fs/xfs/scrub/quotacheck.c:479: xfs_iunlock(ip, XFS_MMAPLOCK_SHARED);
fs/xfs/scrub/quotacheck.c-480- xfs_iunlock(ip, XFS_IOLOCK_SHARED);
--
fs/xfs/xfs_bmap_util.c=1015=xfs_collapse_file_space(
--
fs/xfs/xfs_bmap_util.c-1027-
fs/xfs/xfs_bmap_util.c:1028: xfs_assert_ilocked(ip, XFS_IOLOCK_EXCL | XFS_MMAPLOCK_EXCL);
fs/xfs/xfs_bmap_util.c-1029-
--
fs/xfs/xfs_bmap_util.c=1084=xfs_insert_file_space(
--
fs/xfs/xfs_bmap_util.c-1096-
fs/xfs/xfs_bmap_util.c:1097: xfs_assert_ilocked(ip, XFS_IOLOCK_EXCL | XFS_MMAPLOCK_EXCL);
fs/xfs/xfs_bmap_util.c-1098-
--
fs/xfs/xfs_exchrange.c=844=xfs_ioc_start_commit(
--
fs/xfs/xfs_exchrange.c-854- const unsigned int lockflags = XFS_IOLOCK_SHARED |
fs/xfs/xfs_exchrange.c:855: XFS_MMAPLOCK_SHARED |
fs/xfs/xfs_exchrange.c-856- XFS_ILOCK_SHARED;
--
fs/xfs/xfs_file.c=372=xfs_file_write_zero_eof(
--
fs/xfs/xfs_file.c-430-
fs/xfs/xfs_file.c:431: xfs_ilock(ip, XFS_MMAPLOCK_EXCL);
fs/xfs/xfs_file.c-432- error = xfs_zero_range(ip, isize, iocb->ki_pos - isize, ac, NULL);
fs/xfs/xfs_file.c:433: xfs_iunlock(ip, XFS_MMAPLOCK_EXCL);
fs/xfs/xfs_file.c-434-
--
fs/xfs/xfs_file.c=1546=__xfs_file_fallocate(
--
fs/xfs/xfs_file.c-1555- long error;
fs/xfs/xfs_file.c:1556: uint iolock = XFS_IOLOCK_EXCL | XFS_MMAPLOCK_EXCL;
fs/xfs/xfs_file.c-1557-
--
fs/xfs/xfs_file.c=1967=xfs_dax_read_fault(
--
fs/xfs/xfs_file.c-1975-
fs/xfs/xfs_file.c:1976: xfs_ilock(ip, XFS_MMAPLOCK_SHARED);
fs/xfs/xfs_file.c-1977- ret = xfs_dax_fault_locked(vmf, order, false);
fs/xfs/xfs_file.c:1978: xfs_iunlock(ip, XFS_MMAPLOCK_SHARED);
fs/xfs/xfs_file.c-1979-
--
fs/xfs/xfs_file.c-1988- * sb_start_pagefault(vfs, freeze)
fs/xfs/xfs_file.c:1989: * invalidate_lock (vfs/XFS_MMAPLOCK - truncate serialisation)
fs/xfs/xfs_file.c-1990- * page_lock (MM)
--
fs/xfs/xfs_file.c=1994=__xfs_write_fault(
--
fs/xfs/xfs_file.c-2000- struct xfs_inode *ip = XFS_I(inode);
fs/xfs/xfs_file.c:2001: unsigned int lock_mode = XFS_MMAPLOCK_SHARED;
fs/xfs/xfs_file.c-2002- vm_fault_t ret;
--
fs/xfs/xfs_file.c-2013- */
fs/xfs/xfs_file.c:2014: xfs_ilock(ip, XFS_MMAPLOCK_SHARED);
fs/xfs/xfs_file.c-2015- if (xfs_iflags_test(ip, XFS_IREMAPPING)) {
fs/xfs/xfs_file.c:2016: xfs_iunlock(ip, XFS_MMAPLOCK_SHARED);
fs/xfs/xfs_file.c:2017: xfs_ilock(ip, XFS_MMAPLOCK_EXCL);
fs/xfs/xfs_file.c:2018: lock_mode = XFS_MMAPLOCK_EXCL;
fs/xfs/xfs_file.c-2019- }
--
fs/xfs/xfs_icache.c=1398=xfs_inode_free_cowblocks(
--
fs/xfs/xfs_icache.c-1428-
fs/xfs/xfs_icache.c:1429: if (!xfs_ilock_nowait(ip, XFS_MMAPLOCK_EXCL)) {
fs/xfs/xfs_icache.c-1430- if (wait)
--
fs/xfs/xfs_icache.c-1433- }
fs/xfs/xfs_icache.c:1434: *lockflags |= XFS_MMAPLOCK_EXCL;
fs/xfs/xfs_icache.c-1435-
--
fs/xfs/xfs_inode.c=78=xfs_ilock_attr_map_shared(
--
fs/xfs/xfs_inode.c-90- * You can't set both SHARED and EXCL for the same lock,
fs/xfs/xfs_inode.c:91: * and only XFS_IOLOCK_SHARED, XFS_IOLOCK_EXCL, XFS_MMAPLOCK_SHARED,
fs/xfs/xfs_inode.c:92: * XFS_MMAPLOCK_EXCL, XFS_ILOCK_SHARED, XFS_ILOCK_EXCL are valid values
fs/xfs/xfs_inode.c-93- * to set in lock_flags.
--
fs/xfs/xfs_inode.c=96=xfs_lock_flags_assert(
--
fs/xfs/xfs_inode.c-100- (XFS_IOLOCK_SHARED | XFS_IOLOCK_EXCL));
fs/xfs/xfs_inode.c:101: ASSERT((lock_flags & (XFS_MMAPLOCK_SHARED | XFS_MMAPLOCK_EXCL)) !=
fs/xfs/xfs_inode.c:102: (XFS_MMAPLOCK_SHARED | XFS_MMAPLOCK_EXCL));
fs/xfs/xfs_inode.c-103- ASSERT((lock_flags & (XFS_ILOCK_SHARED | XFS_ILOCK_EXCL)) !=
--
fs/xfs/xfs_inode.c=140=xfs_ilock(
--
fs/xfs/xfs_inode.c-155-
fs/xfs/xfs_inode.c:156: if (lock_flags & XFS_MMAPLOCK_EXCL) {
fs/xfs/xfs_inode.c-157- down_write_nested(&VFS_I(ip)->i_mapping->invalidate_lock,
fs/xfs/xfs_inode.c:158: XFS_MMAPLOCK_DEP(lock_flags));
fs/xfs/xfs_inode.c:159: } else if (lock_flags & XFS_MMAPLOCK_SHARED) {
fs/xfs/xfs_inode.c-160- down_read_nested(&VFS_I(ip)->i_mapping->invalidate_lock,
fs/xfs/xfs_inode.c:161: XFS_MMAPLOCK_DEP(lock_flags));
fs/xfs/xfs_inode.c-162- }
--
fs/xfs/xfs_inode.c=183=xfs_ilock_nowait(
--
fs/xfs/xfs_inode.c-198-
fs/xfs/xfs_inode.c:199: if (lock_flags & XFS_MMAPLOCK_EXCL) {
fs/xfs/xfs_inode.c-200- if (!down_write_trylock(&VFS_I(ip)->i_mapping->invalidate_lock))
fs/xfs/xfs_inode.c-201- goto out_undo_iolock;
fs/xfs/xfs_inode.c:202: } else if (lock_flags & XFS_MMAPLOCK_SHARED) {
fs/xfs/xfs_inode.c-203- if (!down_read_trylock(&VFS_I(ip)->i_mapping->invalidate_lock))
--
fs/xfs/xfs_inode.c-216-out_undo_mmaplock:
fs/xfs/xfs_inode.c:217: if (lock_flags & XFS_MMAPLOCK_EXCL)
fs/xfs/xfs_inode.c-218- up_write(&VFS_I(ip)->i_mapping->invalidate_lock);
fs/xfs/xfs_inode.c:219: else if (lock_flags & XFS_MMAPLOCK_SHARED)
fs/xfs/xfs_inode.c-220- up_read(&VFS_I(ip)->i_mapping->invalidate_lock);
--
fs/xfs/xfs_inode.c=243=xfs_iunlock(
--
fs/xfs/xfs_inode.c-253-
fs/xfs/xfs_inode.c:254: if (lock_flags & XFS_MMAPLOCK_EXCL)
fs/xfs/xfs_inode.c-255- up_write(&VFS_I(ip)->i_mapping->invalidate_lock);
fs/xfs/xfs_inode.c:256: else if (lock_flags & XFS_MMAPLOCK_SHARED)
fs/xfs/xfs_inode.c-257- up_read(&VFS_I(ip)->i_mapping->invalidate_lock);
--
fs/xfs/xfs_inode.c=272=xfs_ilock_demote(
--
fs/xfs/xfs_inode.c-275-{
fs/xfs/xfs_inode.c:276: ASSERT(lock_flags & (XFS_IOLOCK_EXCL|XFS_MMAPLOCK_EXCL|XFS_ILOCK_EXCL));
fs/xfs/xfs_inode.c-277- ASSERT((lock_flags &
fs/xfs/xfs_inode.c:278: ~(XFS_IOLOCK_EXCL|XFS_MMAPLOCK_EXCL|XFS_ILOCK_EXCL)) == 0);
fs/xfs/xfs_inode.c-279-
--
fs/xfs/xfs_inode.c-281- downgrade_write(&ip->i_lock);
fs/xfs/xfs_inode.c:282: if (lock_flags & XFS_MMAPLOCK_EXCL)
fs/xfs/xfs_inode.c-283- downgrade_write(&VFS_I(ip)->i_mapping->invalidate_lock);
--
fs/xfs/xfs_inode.c=291=xfs_assert_ilocked(
--
fs/xfs/xfs_inode.c-303-
fs/xfs/xfs_inode.c:304: if (lock_flags & XFS_MMAPLOCK_SHARED)
fs/xfs/xfs_inode.c-305- rwsem_assert_held(&VFS_I(ip)->i_mapping->invalidate_lock);
fs/xfs/xfs_inode.c:306: else if (lock_flags & XFS_MMAPLOCK_EXCL)
fs/xfs/xfs_inode.c-307- rwsem_assert_held_write(&VFS_I(ip)->i_mapping->invalidate_lock);
--
fs/xfs/xfs_inode.c=339=xfs_lock_inumorder(
--
fs/xfs/xfs_inode.c-352-
fs/xfs/xfs_inode.c:353: if (lock_mode & (XFS_MMAPLOCK_SHARED|XFS_MMAPLOCK_EXCL)) {
fs/xfs/xfs_inode.c:354: ASSERT(subclass <= XFS_MMAPLOCK_MAX_SUBCLASS);
fs/xfs/xfs_inode.c:355: class += subclass << XFS_MMAPLOCK_SHIFT;
fs/xfs/xfs_inode.c-356- }
--
fs/xfs/xfs_inode.c=382=xfs_lock_inodes(
--
fs/xfs/xfs_inode.c-400- ASSERT(ips && inodes >= 2 && inodes <= 5);
fs/xfs/xfs_inode.c:401: ASSERT(lock_mode & (XFS_IOLOCK_EXCL | XFS_MMAPLOCK_EXCL |
fs/xfs/xfs_inode.c-402- XFS_ILOCK_EXCL));
fs/xfs/xfs_inode.c:403: ASSERT(!(lock_mode & (XFS_IOLOCK_SHARED | XFS_MMAPLOCK_SHARED |
fs/xfs/xfs_inode.c-404- XFS_ILOCK_SHARED)));
fs/xfs/xfs_inode.c:405: ASSERT(!(lock_mode & XFS_MMAPLOCK_EXCL) ||
fs/xfs/xfs_inode.c:406: inodes <= XFS_MMAPLOCK_MAX_SUBCLASS + 1);
fs/xfs/xfs_inode.c-407- ASSERT(!(lock_mode & XFS_ILOCK_EXCL) ||
--
fs/xfs/xfs_inode.c-410- if (lock_mode & XFS_IOLOCK_EXCL) {
fs/xfs/xfs_inode.c:411: ASSERT(!(lock_mode & (XFS_MMAPLOCK_EXCL | XFS_ILOCK_EXCL)));
fs/xfs/xfs_inode.c:412: } else if (lock_mode & XFS_MMAPLOCK_EXCL)
fs/xfs/xfs_inode.c-413- ASSERT(!(lock_mode & XFS_ILOCK_EXCL));
--
fs/xfs/xfs_inode.c=483=xfs_lock_two_inodes(
--
fs/xfs/xfs_inode.c-495- ASSERT(!(ip1_mode & (XFS_IOLOCK_SHARED|XFS_IOLOCK_EXCL)));
fs/xfs/xfs_inode.c:496: ASSERT(!(ip0_mode & (XFS_MMAPLOCK_SHARED|XFS_MMAPLOCK_EXCL)));
fs/xfs/xfs_inode.c:497: ASSERT(!(ip1_mode & (XFS_MMAPLOCK_SHARED|XFS_MMAPLOCK_EXCL)));
fs/xfs/xfs_inode.c-498- ASSERT(I_INO(ip0) != I_INO(ip1));
--
fs/xfs/xfs_inode.c=2749=xfs_mmaplock_two_inodes_and_break_dax_layout(
--
fs/xfs/xfs_inode.c-2759- /* Lock the first inode */
fs/xfs/xfs_inode.c:2760: xfs_ilock(ip1, XFS_MMAPLOCK_EXCL);
fs/xfs/xfs_inode.c-2761- error = xfs_break_dax_layouts(VFS_I(ip1));
fs/xfs/xfs_inode.c-2762- if (error) {
fs/xfs/xfs_inode.c:2763: xfs_iunlock(ip1, XFS_MMAPLOCK_EXCL);
fs/xfs/xfs_inode.c-2764- return error;
--
fs/xfs/xfs_inode.c-2770- /* Nested lock the second inode */
fs/xfs/xfs_inode.c:2771: xfs_ilock(ip2, xfs_lock_inumorder(XFS_MMAPLOCK_EXCL, 1));
fs/xfs/xfs_inode.c-2772- /*
fs/xfs/xfs_inode.c-2773- * We cannot use xfs_break_dax_layouts() directly here because it may
fs/xfs/xfs_inode.c:2774: * need to unlock & lock the XFS_MMAPLOCK_EXCL which is not suitable
fs/xfs/xfs_inode.c-2775- * for this nested lock case.
--
fs/xfs/xfs_inode.c-2778- if (error) {
fs/xfs/xfs_inode.c:2779: xfs_iunlock(ip2, XFS_MMAPLOCK_EXCL);
fs/xfs/xfs_inode.c:2780: xfs_iunlock(ip1, XFS_MMAPLOCK_EXCL);
fs/xfs/xfs_inode.c-2781- goto again;
--
fs/xfs/xfs_inode.c=2819=xfs_iunlock2_io_mmap(
--
fs/xfs/xfs_inode.c-2823- if (IS_DAX(VFS_I(ip1)) && IS_DAX(VFS_I(ip2))) {
fs/xfs/xfs_inode.c:2824: xfs_iunlock(ip2, XFS_MMAPLOCK_EXCL);
fs/xfs/xfs_inode.c-2825- if (ip1 != ip2)
fs/xfs/xfs_inode.c:2826: xfs_iunlock(ip1, XFS_MMAPLOCK_EXCL);
fs/xfs/xfs_inode.c-2827- } else
--
fs/xfs/xfs_inode.c=2838=xfs_iunlock2_remapping(
--
fs/xfs/xfs_inode.c-2844- if (ip1 != ip2)
fs/xfs/xfs_inode.c:2845: xfs_iunlock(ip1, XFS_MMAPLOCK_SHARED);
fs/xfs/xfs_inode.c:2846: xfs_iunlock(ip2, XFS_MMAPLOCK_EXCL);
fs/xfs/xfs_inode.c-2847-
--
fs/xfs/xfs_inode.c=3007=xfs_wait_dax_page(
--
fs/xfs/xfs_inode.c-3011-
fs/xfs/xfs_inode.c:3012: xfs_iunlock(ip, XFS_MMAPLOCK_EXCL);
fs/xfs/xfs_inode.c-3013- schedule();
fs/xfs/xfs_inode.c:3014: xfs_ilock(ip, XFS_MMAPLOCK_EXCL);
fs/xfs/xfs_inode.c-3015-}
--
fs/xfs/xfs_inode.c=3018=xfs_break_dax_layouts(
--
fs/xfs/xfs_inode.c-3020-{
fs/xfs/xfs_inode.c:3021: xfs_assert_ilocked(XFS_I(inode), XFS_MMAPLOCK_EXCL);
fs/xfs/xfs_inode.c-3022-
--
fs/xfs/xfs_inode.h=371=static inline bool xfs_inode_can_sw_atomic_write(const struct xfs_inode *ip)
--
fs/xfs/xfs_inode.h-446-#define XFS_ILOCK_SHARED (1u << 3)
fs/xfs/xfs_inode.h:447:#define XFS_MMAPLOCK_EXCL (1u << 4)
fs/xfs/xfs_inode.h:448:#define XFS_MMAPLOCK_SHARED (1u << 5)
fs/xfs/xfs_inode.h-449-
--
fs/xfs/xfs_inode.h-451- | XFS_ILOCK_EXCL | XFS_ILOCK_SHARED \
fs/xfs/xfs_inode.h:452: | XFS_MMAPLOCK_EXCL | XFS_MMAPLOCK_SHARED)
fs/xfs/xfs_inode.h-453-
--
fs/xfs/xfs_inode.h-458- { XFS_ILOCK_SHARED, "ILOCK_SHARED" }, \
fs/xfs/xfs_inode.h:459: { XFS_MMAPLOCK_EXCL, "MMAPLOCK_EXCL" }, \
fs/xfs/xfs_inode.h:460: { XFS_MMAPLOCK_SHARED, "MMAPLOCK_SHARED" }
fs/xfs/xfs_inode.h-461-
--
fs/xfs/xfs_inode.h-491- * 16-19 XFS_IOLOCK_SHIFT dependencies
fs/xfs/xfs_inode.h:492: * 20-23 XFS_MMAPLOCK_SHIFT dependencies
fs/xfs/xfs_inode.h-493- * 24-31 XFS_ILOCK_SHIFT dependencies
--
fs/xfs/xfs_inode.h-515-
fs/xfs/xfs_inode.h:516:#define XFS_MMAPLOCK_SHIFT 20
fs/xfs/xfs_inode.h:517:#define XFS_MMAPLOCK_NUMORDER 0
fs/xfs/xfs_inode.h:518:#define XFS_MMAPLOCK_MAX_SUBCLASS 3
fs/xfs/xfs_inode.h:519:#define XFS_MMAPLOCK_DEP_MASK 0x00f00000u
fs/xfs/xfs_inode.h-520-
--
fs/xfs/xfs_inode.h-527-#define XFS_LOCK_SUBCLASS_MASK (XFS_IOLOCK_DEP_MASK | \
fs/xfs/xfs_inode.h:528: XFS_MMAPLOCK_DEP_MASK | \
fs/xfs/xfs_inode.h-529- XFS_ILOCK_DEP_MASK)
--
fs/xfs/xfs_inode.h-532- >> XFS_IOLOCK_SHIFT)
fs/xfs/xfs_inode.h:533:#define XFS_MMAPLOCK_DEP(flags) (((flags) & XFS_MMAPLOCK_DEP_MASK) \
fs/xfs/xfs_inode.h:534: >> XFS_MMAPLOCK_SHIFT)
fs/xfs/xfs_inode.h-535-#define XFS_ILOCK_DEP(flags) (((flags) & XFS_ILOCK_DEP_MASK) \
--
fs/xfs/xfs_iomap.c=2371=xfs_zero_range(
--
fs/xfs/xfs_iomap.c-2379-
fs/xfs/xfs_iomap.c:2380: xfs_assert_ilocked(ip, XFS_IOLOCK_EXCL | XFS_MMAPLOCK_EXCL);
fs/xfs/xfs_iomap.c-2381-
--
fs/xfs/xfs_iops.c=905=xfs_vn_setattr_size(
--
fs/xfs/xfs_iops.c-921-
fs/xfs/xfs_iops.c:922: xfs_assert_ilocked(ip, XFS_IOLOCK_EXCL | XFS_MMAPLOCK_EXCL);
fs/xfs/xfs_iops.c-923- ASSERT(S_ISREG(inode->i_mode));
--
fs/xfs/xfs_iops.c=1132=xfs_vn_setattr(
--
fs/xfs/xfs_iops.c-1143-
fs/xfs/xfs_iops.c:1144: xfs_ilock(ip, XFS_MMAPLOCK_EXCL);
fs/xfs/xfs_iops.c:1145: iolock = XFS_IOLOCK_EXCL | XFS_MMAPLOCK_EXCL;
fs/xfs/xfs_iops.c-1146-
--
fs/xfs/xfs_iops.c-1148- if (error) {
fs/xfs/xfs_iops.c:1149: xfs_iunlock(ip, XFS_MMAPLOCK_EXCL);
fs/xfs/xfs_iops.c-1150- return error;
--
fs/xfs/xfs_iops.c-1153- error = xfs_vn_setattr_size(idmap, dentry, iattr);
fs/xfs/xfs_iops.c:1154: xfs_iunlock(ip, XFS_MMAPLOCK_EXCL);
fs/xfs/xfs_iops.c-1155- } else {
--
fs/xfs/xfs_reflink.c=1688=xfs_reflink_remap_prep(
--
fs/xfs/xfs_reflink.c-1759- if (inode_in != inode_out)
fs/xfs/xfs_reflink.c:1760: xfs_ilock_demote(src, XFS_IOLOCK_EXCL | XFS_MMAPLOCK_EXCL);
fs/xfs/xfs_reflink.c-1761-
--
fs/xfs/xfs_zone_gc.c=884=xfs_zone_gc_finish_chunk(
--
fs/xfs/xfs_zone_gc.c-886-{
fs/xfs/xfs_zone_gc.c:887: uint iolock = XFS_IOLOCK_EXCL | XFS_MMAPLOCK_EXCL;
fs/xfs/xfs_zone_gc.c-888- struct xfs_zone_gc_data *data = chunk->data;
]
|
| 165/4 |
2026/09/17 11:02 |
llm |
codeexpert |
0m
Model:
Tokens:
input: 37245
output: 27
thoughts: 188
Thoughts: **XFS's MMAPLOCK and VFS Integration**
Okay, so I'm digging into XFS's inode code, specifically lines 156-162 in `fs/xfs/xfs_inode.c`. And it's pretty clear - the `XFS_MMAPLOCK` is *directly* the VFS's `i_mapping->invalidate_lock`. `XFS_MMAPLOCK_EXCL` is just a `down_write_nested` on that lock, and `XFS_MMAPLOCK_SHARED` is a `down_read_nested` on it. That's actually quite elegant. It confirms what I suspected, the XFS team leveraged the existing VFS infrastructure for their locking mechanism around memory mapping.
Now, I need to understand how this interacts with truncate/setattr and other operations. I need to refresh my understanding of how other filesystems manage this. Let me pivot and compare XFS's approach to how generic filesystems and other iomap-based filesystems like btrfs, f2fs, zonefs, gfs2 handle the `truncate_setsize` and `filemap_invalidate_lock`. Specifically, the interplay between those and the memory mapping. Knowing those details should give me a more complete picture of XFS's design choices here.
|
| 166/4 |
2026/09/17 11:02 |
tool |
grepper |
0m
Args: map[Expression:filemap_invalidate_lock PathPrefix:fs]
Results: map[Output:fs/btrfs/volumes.c=1335=struct btrfs_super_block *btrfs_read_disk_super(struct block_device *bdev,
--
fs/btrfs/volumes.c-1366-
fs/btrfs/volumes.c:1367: filemap_invalidate_lock_shared(mapping);
fs/btrfs/volumes.c-1368- page = read_cache_page_gfp(mapping, bytenr >> PAGE_SHIFT, GFP_NOFS);
--
fs/btrfs/zoned.c=88=static int sb_write_pointer(struct block_device *bdev, struct blk_zone *zones,
--
fs/btrfs/zoned.c-133-
fs/btrfs/zoned.c:134: filemap_invalidate_lock_shared(mapping);
fs/btrfs/zoned.c-135- page[i] = read_cache_page_gfp(mapping,
--
fs/ceph/addr.c=1990=static vm_fault_t ceph_filemap_fault(struct vm_fault *vmf)
--
fs/ceph/addr.c-2045-
fs/ceph/addr.c:2046: filemap_invalidate_lock_shared(mapping);
fs/ceph/addr.c-2047- page = find_or_create_page(mapping, 0,
--
fs/ceph/file.c=2784=static long ceph_fallocate(struct file *file, int mode,
--
fs/ceph/file.c-2841-
fs/ceph/file.c:2842: filemap_invalidate_lock(inode->i_mapping);
fs/ceph/file.c-2843- ceph_fscache_invalidate(inode, false);
--
fs/exfat/file.c=754=static int exfat_extend_valid_size(struct inode *inode, loff_t new_valid_size)
--
fs/exfat/file.c-779- */
fs/exfat/file.c:780: filemap_invalidate_lock(inode->i_mapping);
fs/exfat/file.c-781- if (gap_start < new_valid_size)
--
fs/exfat/file.c=943=static vm_fault_t exfat_page_mkwrite(struct vm_fault *vmf)
--
fs/exfat/file.c-987-
fs/exfat/file.c:988: filemap_invalidate_lock_shared(inode->i_mapping);
fs/exfat/file.c-989- ret = iomap_page_mkwrite(vmf, &exfat_iomap_ops, NULL);
--
fs/ext2/inode.c=1224=static void ext2_truncate_blocks(struct inode *inode, loff_t offset)
--
fs/ext2/inode.c-1231-
fs/ext2/inode.c:1232: filemap_invalidate_lock(inode->i_mapping);
fs/ext2/inode.c-1233- __ext2_truncate_blocks(inode, offset);
--
fs/ext2/inode.c=1237=static int ext2_setsize(struct inode *inode, loff_t newsize)
--
fs/ext2/inode.c-1254-
fs/ext2/inode.c:1255: filemap_invalidate_lock(inode->i_mapping);
fs/ext2/inode.c-1256- truncate_setsize(inode, newsize);
--
fs/ext4/extents.c=4949=long ext4_fallocate(struct file *file, int mode, loff_t offset, loff_t len)
--
fs/ext4/extents.c-4999- */
fs/ext4/extents.c:5000: filemap_invalidate_lock(mapping);
fs/ext4/extents.c-5001-
--
fs/ext4/file.c=800=static vm_fault_t ext4_dax_huge_fault(struct vm_fault *vmf, unsigned int order)
--
fs/ext4/file.c-827- file_update_time(vmf->vma->vm_file);
fs/ext4/file.c:828: filemap_invalidate_lock_shared(mapping);
fs/ext4/file.c-829-retry:
--
fs/ext4/file.c-837- } else {
fs/ext4/file.c:838: filemap_invalidate_lock_shared(mapping);
fs/ext4/file.c-839- }
--
fs/ext4/inode.c=4432=static void ext4_wait_dax_page(struct inode *inode)
--
fs/ext4/inode.c-4435- schedule();
fs/ext4/inode.c:4436: filemap_invalidate_lock(inode->i_mapping);
fs/ext4/inode.c-4437-}
--
fs/ext4/inode.c=6009=int ext4_setattr(struct mnt_idmap *idmap, struct dentry *dentry,
--
fs/ext4/inode.c-6125-
fs/ext4/inode.c:6126: filemap_invalidate_lock(inode->i_mapping);
fs/ext4/inode.c-6127-
--
fs/ext4/inode.c=6740=int ext4_change_inode_journal_flag(struct inode *inode, int val)
--
fs/ext4/inode.c-6773- */
fs/ext4/inode.c:6774: filemap_invalidate_lock(inode->i_mapping);
fs/ext4/inode.c-6775- err = filemap_write_and_wait(inode->i_mapping);
--
fs/ext4/inode.c=6884=vm_fault_t ext4_page_mkwrite(struct vm_fault *vmf)
--
fs/ext4/inode.c-6903-
fs/ext4/inode.c:6904: filemap_invalidate_lock_shared(mapping);
fs/ext4/inode.c-6905-
--
fs/ext4/ioctl.c=375=static long swap_inode_boot_loader(struct super_block *sb,
--
fs/ext4/ioctl.c-411-
fs/ext4/ioctl.c:412: filemap_invalidate_lock(inode->i_mapping);
fs/ext4/ioctl.c-413- err = filemap_write_and_wait(inode->i_mapping);
--
fs/ext4/truncate.h=12=static inline void ext4_truncate_failed_write(struct inode *inode)
--
fs/ext4/truncate.h-19- */
fs/ext4/truncate.h:20: filemap_invalidate_lock(mapping);
fs/ext4/truncate.h-21- truncate_inode_pages(mapping, inode->i_size);
--
fs/f2fs/data.c=3646=void f2fs_write_failed(struct inode *inode, loff_t to)
--
fs/f2fs/data.c-3655- f2fs_down_write(&F2FS_I(inode)->i_gc_rwsem[WRITE]);
fs/f2fs/data.c:3656: filemap_invalidate_lock(inode->i_mapping);
fs/f2fs/data.c-3657-
--
fs/f2fs/data.c=4187=static int f2fs_migrate_blocks(struct inode *inode, block_t start_blk,
--
fs/f2fs/data.c-4202- f2fs_down_write(&F2FS_I(inode)->i_gc_rwsem[WRITE]);
fs/f2fs/data.c:4203: filemap_invalidate_lock(inode->i_mapping);
fs/f2fs/data.c-4204-
--
fs/f2fs/file.c=73=static int f2fs_zero_post_eof_page(struct inode *inode,
--
fs/f2fs/file.c-86- if (lock)
fs/f2fs/file.c:87: filemap_invalidate_lock(inode->i_mapping);
fs/f2fs/file.c-88- /* zero or drop pages only in range of [old_size, new_size] */
--
fs/f2fs/file.c=120=static vm_fault_t f2fs_vm_page_mkwrite(struct vm_fault *vmf)
--
fs/f2fs/file.c-186- file_update_time(vmf->vma->vm_file);
fs/f2fs/file.c:187: filemap_invalidate_lock_shared(inode->i_mapping);
fs/f2fs/file.c-188-
--
fs/f2fs/file.c=637=static int finish_preallocate_blocks(struct inode *inode)
--
fs/f2fs/file.c-655- f2fs_down_write(&F2FS_I(inode)->i_gc_rwsem[WRITE]);
fs/f2fs/file.c:656: filemap_invalidate_lock(inode->i_mapping);
fs/f2fs/file.c-657-
--
fs/f2fs/file.c=1124=int f2fs_setattr(struct mnt_idmap *idmap, struct dentry *dentry,
--
fs/f2fs/file.c-1227- f2fs_down_write(&fi->i_gc_rwsem[WRITE]);
fs/f2fs/file.c:1228: filemap_invalidate_lock(inode->i_mapping);
fs/f2fs/file.c-1229-
--
fs/f2fs/file.c=1346=static int f2fs_punch_hole(struct inode *inode, loff_t offset, loff_t len)
--
fs/f2fs/file.c-1394- f2fs_down_write(&F2FS_I(inode)->i_gc_rwsem[WRITE]);
fs/f2fs/file.c:1395: filemap_invalidate_lock(inode->i_mapping);
fs/f2fs/file.c-1396-
--
fs/f2fs/file.c=1630=static int f2fs_do_collapse(struct inode *inode, loff_t offset, loff_t len)
--
fs/f2fs/file.c-1642- f2fs_down_write(&F2FS_I(inode)->i_gc_rwsem[WRITE]);
fs/f2fs/file.c:1643: filemap_invalidate_lock(inode->i_mapping);
fs/f2fs/file.c-1644-
--
fs/f2fs/file.c=1661=static int f2fs_collapse_range(struct inode *inode, loff_t offset, loff_t len)
--
fs/f2fs/file.c-1686- /* write out all moved pages, if possible */
fs/f2fs/file.c:1687: filemap_invalidate_lock(inode->i_mapping);
fs/f2fs/file.c-1688- ret = filemap_write_and_wait_range(inode->i_mapping, offset, LLONG_MAX);
--
fs/f2fs/file.c=1755=static int f2fs_zero_range(struct inode *inode, loff_t offset, loff_t len,
--
fs/f2fs/file.c-1811- f2fs_down_write(&F2FS_I(inode)->i_gc_rwsem[WRITE]);
fs/f2fs/file.c:1812: filemap_invalidate_lock(mapping);
fs/f2fs/file.c-1813-
--
fs/f2fs/file.c=1868=static int f2fs_insert_range(struct inode *inode, loff_t offset, loff_t len)
--
fs/f2fs/file.c-1893-
fs/f2fs/file.c:1894: filemap_invalidate_lock(mapping);
fs/f2fs/file.c-1895- ret = f2fs_truncate_blocks(inode, i_size_read(inode), true);
--
fs/f2fs/file.c-1911- f2fs_down_write(&F2FS_I(inode)->i_gc_rwsem[WRITE]);
fs/f2fs/file.c:1912: filemap_invalidate_lock(mapping);
fs/f2fs/file.c-1913-
--
fs/f2fs/file.c-1940- /* write out all moved pages, if possible */
fs/f2fs/file.c:1941: filemap_invalidate_lock(mapping);
fs/f2fs/file.c-1942- ret = filemap_write_and_wait_range(mapping, offset, LLONG_MAX);
--
fs/f2fs/file.c=3879=static int f2fs_ioc_release_dev_alias(struct file *filp)
--
fs/f2fs/file.c-3928-
fs/f2fs/file.c:3929: filemap_invalidate_lock(inode->i_mapping);
fs/f2fs/file.c-3930- truncate_setsize(inode, 0);
--
fs/f2fs/file.c=4206=static int f2fs_release_compress_blocks(struct file *filp, unsigned long arg)
--
fs/f2fs/file.c-4257- f2fs_down_write(&fi->i_gc_rwsem[WRITE]);
fs/f2fs/file.c:4258: filemap_invalidate_lock(inode->i_mapping);
fs/f2fs/file.c-4259-
--
fs/f2fs/file.c=4403=static int f2fs_reserve_compress_blocks(struct file *filp, unsigned long arg)
--
fs/f2fs/file.c-4435- f2fs_down_write(&fi->i_gc_rwsem[WRITE]);
fs/f2fs/file.c:4436: filemap_invalidate_lock(inode->i_mapping);
fs/f2fs/file.c-4437-
--
fs/f2fs/file.c=4535=static int f2fs_sec_trim_file(struct file *filp, unsigned long arg)
--
fs/f2fs/file.c-4600- f2fs_down_write(&F2FS_I(inode)->i_gc_rwsem[WRITE]);
fs/f2fs/file.c:4601: filemap_invalidate_lock(mapping);
fs/f2fs/file.c-4602-
--
fs/f2fs/file.c=4794=static int redirty_blocks(struct inode *inode, pgoff_t page_idx, int len)
--
fs/f2fs/file.c-4801-
fs/f2fs/file.c:4802: filemap_invalidate_lock_shared(mapping);
fs/f2fs/file.c-4803- page_cache_ra_unbounded(&ractl, len, 0);
--
fs/f2fs/file.c=5631=static ssize_t f2fs_file_write_iter(struct kiocb *iocb, struct iov_iter *from)
--
fs/f2fs/file.c-5703- f2fs_down_write(&F2FS_I(inode)->i_gc_rwsem[WRITE]);
fs/f2fs/file.c:5704: filemap_invalidate_lock(inode->i_mapping);
fs/f2fs/file.c-5705- if (!f2fs_truncate(inode))
--
fs/fuse/dax.c=663=static void fuse_wait_dax_page(struct inode *inode)
--
fs/fuse/dax.c-666- schedule();
fs/fuse/dax.c:667: filemap_invalidate_lock(inode->i_mapping);
fs/fuse/dax.c-668-}
--
fs/fuse/dax.c=755=static vm_fault_t __fuse_dax_fault(struct vm_fault *vmf, unsigned int order,
--
fs/fuse/dax.c-778- */
fs/fuse/dax.c:779: filemap_invalidate_lock_shared(inode->i_mapping);
fs/fuse/dax.c-780- ret = dax_iomap_fault(vmf, order, &pfn, &error, &fuse_iomap_ops);
--
fs/fuse/dax.c=914=inode_inline_reclaim_one_dmap(struct fuse_conn_dax *fcd, struct inode *inode,
--
fs/fuse/dax.c-923-
fs/fuse/dax.c:924: filemap_invalidate_lock(inode->i_mapping);
fs/fuse/dax.c-925-
--
fs/fuse/dax.c=1076=static int lookup_and_reclaim_dmap(struct fuse_conn_dax *fcd,
--
fs/fuse/dax.c-1085-
fs/fuse/dax.c:1086: filemap_invalidate_lock(inode->i_mapping);
fs/fuse/dax.c-1087- ret = fuse_dax_break_layouts(inode, dmap_start, dmap_end);
--
fs/fuse/dir.c=2145=int fuse_do_setattr(struct mnt_idmap *idmap, struct dentry *dentry,
--
fs/fuse/dir.c-2177- if (FUSE_IS_DAX(inode) && is_truncate) {
fs/fuse/dir.c:2178: filemap_invalidate_lock(mapping);
fs/fuse/dir.c-2179- fault_blocked = true;
--
fs/fuse/file.c=250=static int fuse_open(struct inode *inode, struct file *file)
--
fs/fuse/file.c-271- if (dax_truncate) {
fs/fuse/file.c:272: filemap_invalidate_lock(inode->i_mapping);
fs/fuse/file.c-273- err = fuse_dax_break_layouts(inode, 0, -1);
--
fs/fuse/file.c=2832=static long fuse_file_fallocate(struct file *file, int mode, loff_t offset,
--
fs/fuse/file.c-2859- if (block_faults) {
fs/fuse/file.c:2860: filemap_invalidate_lock(inode->i_mapping);
fs/fuse/file.c-2861- err = fuse_dax_break_layouts(inode, 0, -1);
--
fs/ntfs/file.c=254=static int ntfs_setattr_size(struct inode *vi, struct iattr *attr)
--
fs/ntfs/file.c-278- */
fs/ntfs/file.c:279: filemap_invalidate_lock(vi->i_mapping);
fs/ntfs/file.c-280- if (attr->ia_size > old_size) {
--
fs/ntfs/file.c=676=static vm_fault_t ntfs_filemap_page_mkwrite(struct vm_fault *vmf)
--
fs/ntfs/file.c-691- */
fs/ntfs/file.c:692: filemap_invalidate_lock_shared(mapping);
fs/ntfs/file.c-693- ret = iomap_page_mkwrite(vmf, &ntfs_page_mkwrite_iomap_ops, NULL);
--
fs/ntfs/file.c=1127=static long ntfs_fallocate(struct file *file, int mode, loff_t offset, loff_t len)
--
fs/ntfs/file.c-1170- /* Take invalidate_lock for all fallocate operations to prevent races */
fs/ntfs/file.c:1171: filemap_invalidate_lock(vi->i_mapping);
fs/ntfs/file.c-1172-
--
fs/ntfs3/file.c=466=static long ntfs_fallocate(struct file *file, int mode, loff_t vbo, loff_t len)
--
fs/ntfs3/file.c-519- inode_dio_wait(inode);
fs/ntfs3/file.c:520: filemap_invalidate_lock(mapping);
fs/ntfs3/file.c-521- map_locked = true;
--
fs/smb/client/file.c=993=static int cifs_do_truncate(const unsigned int xid, struct dentry *dentry)
--
fs/smb/client/file.c-1005-
fs/smb/client/file.c:1006: filemap_invalidate_lock(inode->i_mapping);
fs/smb/client/file.c-1007-
--
fs/smb/client/smb2ops.c=3508=static long smb3_zero_range(struct file *file, struct cifs_tcon *tcon,
--
fs/smb/client/smb2ops.c-3531-
fs/smb/client/smb2ops.c:3532: filemap_invalidate_lock(inode->i_mapping);
fs/smb/client/smb2ops.c-3533-
--
fs/smb/client/smb2ops.c=3592=static long smb3_punch_hole(struct file *file, struct cifs_tcon *tcon,
--
fs/smb/client/smb2ops.c-3610-
fs/smb/client/smb2ops.c:3611: filemap_invalidate_lock(inode->i_mapping);
fs/smb/client/smb2ops.c-3612- /*
--
fs/smb/client/smb2ops.c=4014=static long smb3_collapse_range(struct file *file, struct cifs_tcon *tcon,
--
fs/smb/client/smb2ops.c-4032-
fs/smb/client/smb2ops.c:4033: filemap_invalidate_lock(inode->i_mapping);
fs/smb/client/smb2ops.c-4034- rc = filemap_write_and_wait_range(inode->i_mapping,
--
fs/smb/client/smb2ops.c=4078=static long smb3_insert_range(struct file *file, struct cifs_tcon *tcon,
--
fs/smb/client/smb2ops.c-4108-
fs/smb/client/smb2ops.c:4109: filemap_invalidate_lock(inode->i_mapping);
fs/smb/client/smb2ops.c-4110- rc = filemap_write_and_wait_range(inode->i_mapping,
--
fs/udf/file.c=38=static vm_fault_t udf_page_mkwrite(struct vm_fault *vmf)
--
fs/udf/file.c-50- file_update_time(vma->vm_file);
fs/udf/file.c:51: filemap_invalidate_lock_shared(mapping);
fs/udf/file.c-52- folio_lock(folio);
--
fs/udf/file.c=89=static ssize_t udf_file_write_iter(struct kiocb *iocb, struct iov_iter *from)
--
fs/udf/file.c-104- iocb->ki_pos + iov_iter_count(from))) {
fs/udf/file.c:105: filemap_invalidate_lock(inode->i_mapping);
fs/udf/file.c-106- retval = udf_expand_file_adinicb(inode);
--
fs/udf/file.c=215=static int udf_setattr(struct mnt_idmap *idmap, struct dentry *dentry,
--
fs/udf/file.c-236- attr->ia_size != i_size_read(inode)) {
fs/udf/file.c:237: filemap_invalidate_lock(inode->i_mapping);
fs/udf/file.c-238- error = udf_setsize(inode, attr->ia_size);
--
fs/verity/read_metadata.c=16=static int fsverity_read_merkle_tree(struct inode *inode,
--
fs/verity/read_metadata.c-38- if (inode->i_sb->s_vop->readahead_merkle_tree) {
fs/verity/read_metadata.c:39: filemap_invalidate_lock_shared(inode->i_mapping);
fs/verity/read_metadata.c-40- inode->i_sb->s_vop->readahead_merkle_tree(
--
fs/xfs/xfs_bmap_util.c=1537=xfs_swap_extents(
--
fs/xfs/xfs_bmap_util.c-1558- lock_two_nondirectories(VFS_I(ip), VFS_I(tip));
fs/xfs/xfs_bmap_util.c:1559: filemap_invalidate_lock_two(VFS_I(ip)->i_mapping,
fs/xfs/xfs_bmap_util.c-1560- VFS_I(tip)->i_mapping);
--
fs/xfs/xfs_inode.c=2792=xfs_ilock2_io_mmap(
--
fs/xfs/xfs_inode.c-2810- } else
fs/xfs/xfs_inode.c:2811: filemap_invalidate_lock_two(VFS_I(ip1)->i_mapping,
fs/xfs/xfs_inode.c-2812- VFS_I(ip2)->i_mapping);
--
fs/xfs/xfs_iomap.c=2134=xfs_buffered_write_iomap_end(
--
fs/xfs/xfs_iomap.c-2167- } else {
fs/xfs/xfs_iomap.c:2168: filemap_invalidate_lock(inode->i_mapping);
fs/xfs/xfs_iomap.c-2169- iomap_write_delalloc_release(inode, start_byte, end_byte, flags,
--
fs/zonefs/file.c=203=int zonefs_file_truncate(struct inode *inode, loff_t isize)
--
fs/zonefs/file.c-228- /* Serialize against page faults */
fs/zonefs/file.c:229: filemap_invalidate_lock(inode->i_mapping);
fs/zonefs/file.c-230-
--
fs/zonefs/file.c=297=static vm_fault_t zonefs_filemap_page_mkwrite(struct vm_fault *vmf)
--
fs/zonefs/file.c-315- /* Serialize against truncates */
fs/zonefs/file.c:316: filemap_invalidate_lock_shared(inode->i_mapping);
fs/zonefs/file.c-317- ret = iomap_page_mkwrite(vmf, &zonefs_write_iomap_ops, NULL);
]
|
| 167/4 |
2026/09/17 11:02 |
llm |
codeexpert |
0m
Model:
Tokens:
input: 45065
output: 38
thoughts: 35
Thoughts: Okay, here's my take on those thoughts, tailored for an expert audience:
**Examining Truncate/SetSize Implementation**
Right, time to dig into the nitty-gritty. I want to see how the kernel handles `truncate` and `setsize` operations at the filesystem level, and the best way to do that is to look at some well-established, potentially different implementations. I'm thinking specifically about `fs/zonefs/file.c` and `fs/udf/file.c`. ZoneFS is interesting because of its block-oriented nature and inherent limitations with random access which could have an impact on these operations. UDF is a good contrast, given that it's a more traditional filesystem, it is interesting to see the trade-offs implemented. Seeing how both filesystems implement the same operations will give me a better understanding of the trade-offs made, and hopefully, I'll identify some best practices or potential areas for optimization across the board, or perhaps highlight subtle differences in design considerations. Let's see how they manage block allocation/deallocation, inode updates, and any potential locking strategies they employ. Analyzing these files will give me a clear picture of how they're handling these fundamental file operations.
|
| 168/4 |
2026/09/17 11:02 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:fs/zonefs/file.c Name:zonefs_file_truncate]
Results: map[SourceCode: 203: int zonefs_file_truncate(struct inode *inode, loff_t isize)
204: {
205: struct zonefs_inode_info *zi = ZONEFS_I(inode);
206: struct zonefs_zone *z = zonefs_inode_zone(inode);
207: loff_t old_isize;
208: enum req_op op;
209: int ret = 0;
210:
211: /*
212: * Only sequential zone files can be truncated and truncation is allowed
213: * only down to a 0 size, which is equivalent to a zone reset, and to
214: * the maximum file size, which is equivalent to a zone finish.
215: */
216: if (!zonefs_zone_is_seq(z))
217: return -EPERM;
218:
219: if (!isize)
220: op = REQ_OP_ZONE_RESET;
221: else if (isize == z->z_capacity)
222: op = REQ_OP_ZONE_FINISH;
223: else
224: return -EPERM;
225:
226: inode_dio_wait(inode);
227:
228: /* Serialize against page faults */
229: filemap_invalidate_lock(inode->i_mapping);
230:
231: /* Serialize against zonefs_iomap_begin() */
232: mutex_lock(&zi->i_truncate_mutex);
233:
234: old_isize = i_size_read(inode);
235: if (isize == old_isize)
236: goto unlock;
237:
238: ret = zonefs_inode_zone_mgmt(inode, op);
239: if (ret)
240: goto unlock;
241:
242: /*
243: * If the mount option ZONEFS_MNTOPT_EXPLICIT_OPEN is set,
244: * take care of open zones.
245: */
246: if (z->z_flags & ZONEFS_ZONE_OPEN) {
247: /*
248: * Truncating a zone to EMPTY or FULL is the equivalent of
249: * closing the zone. For a truncation to 0, we need to
250: * re-open the zone to ensure new writes can be processed.
251: * For a truncation to the maximum file size, the zone is
252: * closed and writes cannot be accepted anymore, so clear
253: * the open flag.
254: */
255: if (!isize)
256: ret = zonefs_inode_zone_mgmt(inode, REQ_OP_ZONE_OPEN);
257: else
258: z->z_flags &= ~ZONEFS_ZONE_OPEN;
259: }
260:
261: zonefs_update_stats(inode, isize);
262: truncate_setsize(inode, isize);
263: z->z_wpoffset = isize;
264: zonefs_inode_account_active(inode);
265:
266: unlock:
267: mutex_unlock(&zi->i_truncate_mutex);
268: filemap_invalidate_unlock(inode->i_mapping);
269:
270: return ret;
271: }
SourceFile:fs/zonefs/file.c]
|
| 169/4 |
2026/09/17 11:02 |
llm |
codeexpert |
0m
Model:
Tokens:
input: 46552
output: 1680
thoughts: 1319
Thoughts: **Summary of `ntfs_setattr` Size Change Handling**
Okay, here's my understanding of this issue and proposed fix, keeping in mind I need to use the information I've gathered so far. No additional research is possible.
First, it is absolutely incorrect to call `truncate_setsize` *before* `ntfs_set_size` when extending a file. This creates a critical window. Essentially, `truncate_setsize` immediately updates `inode->i_size` and signals the page cache about the change. However, `ntfs_set_size` is responsible for updating the *actual* on-disk metadata (file size in the MFT entry, possibly allocating clusters, or converting a resident attribute to non-resident). Since `ntfs_setattr` only holds `inode->i_rwsem`, concurrent page faults that run under `mmap_lock` are *not* blocked and can happen simultaneously. So, if a page fault happens *after* `i_size` has been extended but *before* the filesystem metadata has been updated, it can lead to inconsistent reads. The `iomap` length might be an old size, while the `i_size` (from `inode->i_size`) is the new larger size. This triggers an `EIO` error due to an inconsistent size comparison. Also, if `ntfs_set_size` fails, the inconsistency remains and needs rollback.
Now, let's look at how other filesystems deal with this. XFS uses `XFS_MMAPLOCK` which blocks any concurrent access. `xfs_vn_setattr` acquires this exclusive lock, and `filemap_fault` uses a shared lock. This guarantees no intermediate state is observable during the entire truncate or extend operation. Ext4 does something similar with `filemap_invalidate_lock`. In `ext4_setattr`, the entire size modification code is protected by this lock. For file extension, Ext4 first zeroes EOF folios, acquires the inode's data semaphore, updates on-disk and in-core size atomically under that semaphore, marks the inode dirty, calls `pagecache_isize_extended()`, calls `truncate_pagecache()`, and finally unlocks the invalidate lock. `ext4_page_mkwrite` and `filemap_fault` also hold this same lock in shared mode.
So, the fix for `ntfs_setattr` is clear. The key is to serialize with page faults.
Here's my proposed fix:
1. **Locking**: `ntfs_setattr` *must* hold `filemap_invalidate_lock(inode->i_mapping)` across the *entire* size change operation. This is critical to prevent the race condition seen in the existing code. This parallels how other file systems and even the ntfs3 `ntfs_fallocate` implementation handle the same scenario.
2. **Ordering**:
* **File Extension (`newsize > oldsize`)**: First, call `ntfs_set_size(inode, newsize)` *before* updating `inode->i_size`. This step handles the on-disk metadata updates β allocating clusters or converting attributes. Then, *after* that, update the page cache and `i_size`: call `truncate_setsize(inode, newsize)` (or possibly `i_size_write(inode, newsize)` and `pagecache_isize_extended(inode, oldsize, newsize)`). This way, by the time `i_size` is visible, the attribute length and mappings reflect the new file size and eliminates the `size > iomap->length` issue.
* **File Shrink (`newsize < oldsize`)**: Call `truncate_setsize(inode, newsize)` *first* (while holding the invalidate lock). This ensures any pages beyond the new EOF are discarded before calling `ntfs_set_size(inode, newsize)` to free up disk clusters or update attribute sizes.
3. **Caveat / Verification**: We *must* explicitly note which parts of this fix are verified against the kernel source (ext4, XFS, etc.) and highlight any implementation specifics or nuances (like the preference between `truncate_setsize` vs `i_size_write` + `pagecache_isize_extended`, and ensuring that error paths restore the original `i_size` *under* the `filemap_invalidate_lock`).
That's my complete understanding based on the information provided, and the best-effort approach I can take with current restrictions.
|
| 170/4 |
2026/09/17 11:03 |
tool |
set-results |
0m
Args: map[Answer:### 1. Is it correct to call `truncate_setsize` before `ntfs_set_size` when extending the file size?
**No, it is incorrect.**
- `truncate_setsize(inode, newsize)` immediately updates the in-memory `inode->i_size` via `i_size_write(inode, newsize)` and calls `pagecache_isize_extended()`.
- While `ntfs_setattr` holds `inode->i_rwsem`, page faults (`filemap_fault`) do **not** take `i_rwsem`. In `filemap_fault()`, folios are allocated and read holding only `filemap_invalidate_lock_shared(mapping)` (or under folio lock), not `i_rwsem`.
- If `truncate_setsize` is called before `ntfs_set_size`, a concurrent page fault can read the newly updated `inode->i_size` while the on-disk attribute length has not yet been modified by `ntfs_set_size`. When `ntfs_iomap_begin()` executes, it reads the old resident attribute length (e.g. 5 bytes) into `iomap->length`. Subsequently, `iomap_read_inline_data()` calculates `size = i_size_read(inode) - iomap->offset` (e.g. 20 bytes), which triggers `WARN_ON_ONCE(size > iomap->length)` and fails with `-EIO`.
- Furthermore, if `ntfs_set_size()` fails (e.g., due to `-EFBIG`, `-ENOSPC`, or disk I/O errors), the page cache has already been extended prematurely, requiring error rollback of `inode->i_size`.
---
### 2. How ext4 and XFS prevent concurrent reads/faults from observing intermediate states
Both filesystems serialize size modifications against page faults using `mapping->invalidate_lock` (or filesystem-specific lock abstractions mapping to it), and they sequence metadata updates appropriately:
1. **XFS (`xfs_vn_setattr` / `xfs_vn_setattr_size`)**:
- `xfs_vn_setattr` acquires `xfs_ilock(ip, XFS_MMAPLOCK_EXCL)` before performing any size updates.
- In XFS, `XFS_MMAPLOCK_EXCL` / `XFS_MMAPLOCK_SHARED` directly correspond to `down_write` / `down_read` of `inode->i_mapping->invalidate_lock`.
- `filemap_fault()` takes `filemap_invalidate_lock_shared` when instantiating or reading non-uptodate folios. Holding `XFS_MMAPLOCK_EXCL` completely blocks concurrent page faults from running during truncate or file extension.
- Under this lock, XFS zeroes beyond EOF (`xfs_zero_range`), updates page cache / size via `truncate_setsize`, logs the on-disk metadata (`ip->i_disk_size = newsize`), commits the transaction, and only then releases `XFS_MMAPLOCK_EXCL`.
2. **ext4 (`ext4_setattr`)**:
- `ext4_setattr` holds `filemap_invalidate_lock(inode->i_mapping)` throughout the entire size change operation.
- For file extension (`!shrink`), it first zeroes post-EOF folio tails (`ext4_block_zero_eof`), takes a journal handle, takes `down_write(&EXT4_I(inode)->i_data_sem)`, updates `EXT4_I(inode)->i_disksize` and calls `i_size_write(inode, attr->ia_size)` together under lock, and calls `pagecache_isize_extended(inode, oldsize, inode->i_size)`.
- Concurrent faults are serialized because `ext4_page_mkwrite` and `filemap_fault` take `filemap_invalidate_lock_shared()`.
---
### 3. How this should be fixed in `ntfs_setattr`
To fix this issue in `fs/ntfs3/file.c`:
1. **Serialize page faults using `filemap_invalidate_lock`**:
Surround the size modification block with `filemap_invalidate_lock(inode->i_mapping)` and `filemap_invalidate_unlock(inode->i_mapping)`. This blocks concurrent `filemap_fault()` calls from reading or populating folios while the size and attributes are changing.
2. **Order operations depending on whether extending or shrinking**:
- **When extending (`newsize > oldsize`)**:
Call `ntfs_set_size(inode, newsize)` **first** to resize/convert the attribute (including converting resident data to non-resident if necessary and allocating clusters). Once metadata and allocations succeed, call `truncate_setsize(inode, newsize)` (or `i_size_write(inode, newsize)` followed by `pagecache_isize_extended(inode, oldsize, newsize)`).
- **When shrinking (`newsize < oldsize`)**:
Call `truncate_setsize(inode, newsize)` first (to unmap and truncate folios beyond the new EOF so they are not written back to deallocated blocks), followed by `ntfs_set_size(inode, newsize)` to shrink the attribute and free unused clusters on disk.
- **Error Handling**:
If `ntfs_set_size` fails during shrinking, roll back `inode->i_size` under `filemap_invalidate_lock`.
**Example Patch Outline**:
```c
if (newsize != oldsize) {
filemap_invalidate_lock(inode->i_mapping);
if (newsize > oldsize) {
err = ntfs_set_size(inode, newsize);
if (!err)
truncate_setsize(inode, newsize);
} else {
truncate_setsize(inode, newsize);
err = ntfs_set_size(inode, newsize);
if (err)
i_size_write(inode, oldsize);
}
filemap_invalidate_unlock(inode->i_mapping);
if (err)
goto out;
ni->std_fa |= FILE_ATTRIBUTE_ARCHIVE;
ni->ni_flags |= NI_FLAG_UPDATE_PARENT;
inode_set_mtime_to_ts(inode, inode_set_ctime_current(inode));
}
```
---
### Limitations / Unverified Parts
- We verified the locking and ordering mechanisms in `ext4`, `xfs`, `ntfs`, `zonefs`, and `mm/filemap.c`.
- In `ntfs3`, `ntfs_set_size()` internally acquires `ni_lock(ni)` and `ni->file.run_lock`. The deadlock-freedom of locking `filemap_invalidate_lock` before `ni_lock` and `run_lock` was verified against other callers in `fs/ntfs3/file.c` (e.g., `ntfs_fallocate()`, which already takes `filemap_invalidate_lock` before acquiring internal NTFS locks).
- Exact post-EOF folio tail zeroing behavior (such as `iomap_zero_range` for extending beyond EOF cluster boundaries) should also be evaluated if sparse or unwritten extent semantics require zeroing intermediate page cache folios.]
Results: map[Answer:### 1. Is it correct to call `truncate_setsize` before `ntfs_set_size` when extending the file size?
**No, it is incorrect.**
- `truncate_setsize(inode, newsize)` immediately updates the in-memory `inode->i_size` via `i_size_write(inode, newsize)` and calls `pagecache_isize_extended()`.
- While `ntfs_setattr` holds `inode->i_rwsem`, page faults (`filemap_fault`) do **not** take `i_rwsem`. In `filemap_fault()`, folios are allocated and read holding only `filemap_invalidate_lock_shared(mapping)` (or under folio lock), not `i_rwsem`.
- If `truncate_setsize` is called before `ntfs_set_size`, a concurrent page fault can read the newly updated `inode->i_size` while the on-disk attribute length has not yet been modified by `ntfs_set_size`. When `ntfs_iomap_begin()` executes, it reads the old resident attribute length (e.g. 5 bytes) into `iomap->length`. Subsequently, `iomap_read_inline_data()` calculates `size = i_size_read(inode) - iomap->offset` (e.g. 20 bytes), which triggers `WARN_ON_ONCE(size > iomap->length)` and fails with `-EIO`.
- Furthermore, if `ntfs_set_size()` fails (e.g., due to `-EFBIG`, `-ENOSPC`, or disk I/O errors), the page cache has already been extended prematurely, requiring error rollback of `inode->i_size`.
---
### 2. How ext4 and XFS prevent concurrent reads/faults from observing intermediate states
Both filesystems serialize size modifications against page faults using `mapping->invalidate_lock` (or filesystem-specific lock abstractions mapping to it), and they sequence metadata updates appropriately:
1. **XFS (`xfs_vn_setattr` / `xfs_vn_setattr_size`)**:
- `xfs_vn_setattr` acquires `xfs_ilock(ip, XFS_MMAPLOCK_EXCL)` before performing any size updates.
- In XFS, `XFS_MMAPLOCK_EXCL` / `XFS_MMAPLOCK_SHARED` directly correspond to `down_write` / `down_read` of `inode->i_mapping->invalidate_lock`.
- `filemap_fault()` takes `filemap_invalidate_lock_shared` when instantiating or reading non-uptodate folios. Holding `XFS_MMAPLOCK_EXCL` completely blocks concurrent page faults from running during truncate or file extension.
- Under this lock, XFS zeroes beyond EOF (`xfs_zero_range`), updates page cache / size via `truncate_setsize`, logs the on-disk metadata (`ip->i_disk_size = newsize`), commits the transaction, and only then releases `XFS_MMAPLOCK_EXCL`.
2. **ext4 (`ext4_setattr`)**:
- `ext4_setattr` holds `filemap_invalidate_lock(inode->i_mapping)` throughout the entire size change operation.
- For file extension (`!shrink`), it first zeroes post-EOF folio tails (`ext4_block_zero_eof`), takes a journal handle, takes `down_write(&EXT4_I(inode)->i_data_sem)`, updates `EXT4_I(inode)->i_disksize` and calls `i_size_write(inode, attr->ia_size)` together under lock, and calls `pagecache_isize_extended(inode, oldsize, inode->i_size)`.
- Concurrent faults are serialized because `ext4_page_mkwrite` and `filemap_fault` take `filemap_invalidate_lock_shared()`.
---
### 3. How this should be fixed in `ntfs_setattr`
To fix this issue in `fs/ntfs3/file.c`:
1. **Serialize page faults using `filemap_invalidate_lock`**:
Surround the size modification block with `filemap_invalidate_lock(inode->i_mapping)` and `filemap_invalidate_unlock(inode->i_mapping)`. This blocks concurrent `filemap_fault()` calls from reading or populating folios while the size and attributes are changing.
2. **Order operations depending on whether extending or shrinking**:
- **When extending (`newsize > oldsize`)**:
Call `ntfs_set_size(inode, newsize)` **first** to resize/convert the attribute (including converting resident data to non-resident if necessary and allocating clusters). Once metadata and allocations succeed, call `truncate_setsize(inode, newsize)` (or `i_size_write(inode, newsize)` followed by `pagecache_isize_extended(inode, oldsize, newsize)`).
- **When shrinking (`newsize < oldsize`)**:
Call `truncate_setsize(inode, newsize)` first (to unmap and truncate folios beyond the new EOF so they are not written back to deallocated blocks), followed by `ntfs_set_size(inode, newsize)` to shrink the attribute and free unused clusters on disk.
- **Error Handling**:
If `ntfs_set_size` fails during shrinking, roll back `inode->i_size` under `filemap_invalidate_lock`.
**Example Patch Outline**:
```c
if (newsize != oldsize) {
filemap_invalidate_lock(inode->i_mapping);
if (newsize > oldsize) {
err = ntfs_set_size(inode, newsize);
if (!err)
truncate_setsize(inode, newsize);
} else {
truncate_setsize(inode, newsize);
err = ntfs_set_size(inode, newsize);
if (err)
i_size_write(inode, oldsize);
}
filemap_invalidate_unlock(inode->i_mapping);
if (err)
goto out;
ni->std_fa |= FILE_ATTRIBUTE_ARCHIVE;
ni->ni_flags |= NI_FLAG_UPDATE_PARENT;
inode_set_mtime_to_ts(inode, inode_set_ctime_current(inode));
}
```
---
### Limitations / Unverified Parts
- We verified the locking and ordering mechanisms in `ext4`, `xfs`, `ntfs`, `zonefs`, and `mm/filemap.c`.
- In `ntfs3`, `ntfs_set_size()` internally acquires `ni_lock(ni)` and `ni->file.run_lock`. The deadlock-freedom of locking `filemap_invalidate_lock` before `ni_lock` and `run_lock` was verified against other callers in `fs/ntfs3/file.c` (e.g., `ntfs_fallocate()`, which already takes `filemap_invalidate_lock` before acquiring internal NTFS locks).
- Exact post-EOF folio tail zeroing behavior (such as `iomap_zero_range` for extending beyond EOF cluster boundaries) should also be evaluated if sparse or unwritten extent semantics require zeroing intermediate page cache folios.]
|
| 171/2 |
2026/09/17 11:03 |
llm |
debugger |
0m
Model:
Tokens:
input: 57349
output: 23
thoughts: 0
|
| 172/2 |
2026/09/17 11:03 |
tool |
codesearch-definition-source |
0m
Args:
Results: map[SourceCode: 457: /*
458: * ntfs_fallocate - file_operations::ntfs_fallocate
459: *
460: * Preallocate space for a file. This implements ntfs's fallocate file
461: * operation, which gets called from sys_fallocate system call. User
462: * space requests 'len' bytes at 'vbo'. If FALLOC_FL_KEEP_SIZE is set
463: * we just allocate clusters without zeroing them out. Otherwise we
464: * allocate and zero out clusters via an expanding truncate.
465: */
466: static long ntfs_fallocate(struct file *file, int mode, loff_t vbo, loff_t len)
467: {
468: struct inode *inode = file_inode(file);
469: struct address_space *mapping = inode->i_mapping;
470: struct super_block *sb = inode->i_sb;
471: struct ntfs_sb_info *sbi = sb->s_fs_info;
472: struct ntfs_inode *ni = ntfs_i(inode);
473: loff_t end = vbo + len;
474: loff_t vbo_down = round_down(vbo, max_t(unsigned long,
475: sbi->cluster_size, PAGE_SIZE));
476: bool is_supported_holes = is_sparsed(ni) || is_compressed(ni);
477: loff_t i_size, new_size;
478: bool map_locked;
479: int err;
480:
481: /* No support for dir. */
482: if (!S_ISREG(inode->i_mode))
483: return -EOPNOTSUPP;
484:
485: /*
486: * vfs_fallocate checks all possible combinations of mode.
487: * Do additional checks here before ntfs_set_state(dirty).
488: */
489: if (mode & FALLOC_FL_PUNCH_HOLE) {
490: if (!is_supported_holes)
491: return -EOPNOTSUPP;
492: } else if (mode & FALLOC_FL_COLLAPSE_RANGE) {
493: } else if (mode & FALLOC_FL_INSERT_RANGE) {
494: if (!is_supported_holes)
495: return -EOPNOTSUPP;
496: } else if (mode &
497: ~(FALLOC_FL_KEEP_SIZE | FALLOC_FL_PUNCH_HOLE |
498: FALLOC_FL_COLLAPSE_RANGE | FALLOC_FL_INSERT_RANGE)) {
499: ntfs_inode_warn(inode, "fallocate(0x%x) is not supported",
500: mode);
501: return -EOPNOTSUPP;
502: }
503:
504: ntfs_set_state(sbi, NTFS_DIRTY_DIRTY);
505:
506: inode_lock(inode);
507: i_size = inode->i_size;
508: new_size = max(end, i_size);
509: map_locked = false;
510:
511: if (WARN_ON(ni->ni_flags & NI_FLAG_COMPRESSED_MASK)) {
512: /* Should never be here, see ntfs_file_open. */
513: err = -EOPNOTSUPP;
514: goto out;
515: }
516:
517: if (mode & (FALLOC_FL_PUNCH_HOLE | FALLOC_FL_COLLAPSE_RANGE |
518: FALLOC_FL_INSERT_RANGE)) {
519: inode_dio_wait(inode);
520: filemap_invalidate_lock(mapping);
521: map_locked = true;
522: }
523:
524: if (mode & FALLOC_FL_PUNCH_HOLE) {
525: u32 frame_size;
526: loff_t mask, vbo_a, end_a, tmp, from;
527:
528: err = filemap_write_and_wait_range(mapping, vbo_down,
529: LLONG_MAX);
530: if (err)
531: goto out;
532:
533: truncate_pagecache(inode, vbo_down);
534:
535: ni_lock(ni);
536: err = attr_punch_hole(ni, vbo, len, &frame_size);
537: ni_unlock(ni);
538: if (!err)
539: goto ok;
540:
541: if (err != E_NTFS_NOTALIGNED)
542: goto out;
543:
544: /* Process not aligned punch. */
545: err = 0;
546: if (end > i_size)
547: end = i_size;
548: mask = frame_size - 1;
549: vbo_a = (vbo + mask) & ~mask;
550: end_a = end & ~mask;
551:
552: tmp = min(vbo_a, end);
553: from = min_t(loff_t, ni->i_valid, vbo);
554: /* Zero head of punch. */
555: if (tmp > from) {
556: err = iomap_zero_range(inode, from, tmp - from, NULL,
557: &ntfs_iomap_ops,
558: &ntfs_iomap_folio_ops, NULL);
559: if (err)
560: goto out;
561: }
562:
563: /* Aligned punch_hole. Deallocate clusters. */
564: if (end_a > vbo_a) {
565: ni_lock(ni);
566: err = attr_punch_hole(ni, vbo_a, end_a - vbo_a, NULL);
567: ni_unlock(ni);
568: if (err)
569: goto out;
570: }
571:
572: /* Zero tail of punch. */
573: if (vbo < end_a && end_a < end) {
574: err = iomap_zero_range(inode, end_a, end - end_a, NULL,
575: &ntfs_iomap_ops,
576: &ntfs_iomap_folio_ops, NULL);
577: if (err)
578: goto out;
579: }
580: } else if (mode & FALLOC_FL_COLLAPSE_RANGE) {
581: /*
582: * Write tail of the last page before removed range since
583: * it will get removed from the page cache below.
584: */
585: err = filemap_write_and_wait_range(mapping, vbo_down, vbo);
586: if (err)
587: goto out;
588:
589: /*
590: * Write data that will be shifted to preserve them
591: * when discarding page cache below.
592: */
593: err = filemap_write_and_wait_range(mapping, end, LLONG_MAX);
594: if (err)
595: goto out;
596:
597: truncate_pagecache(inode, vbo_down);
598:
599: ni_lock(ni);
600: err = attr_collapse_range(ni, vbo, len);
601: ni_unlock(ni);
602: if (err)
603: goto out;
604: } else if (mode & FALLOC_FL_INSERT_RANGE) {
605: /* Check new size. */
606: err = inode_newsize_ok(inode, new_size);
607: if (err)
608: goto out;
609:
610: /* Write out all dirty pages. */
611: err = filemap_write_and_wait_range(mapping, vbo_down,
612: LLONG_MAX);
613: if (err)
614: goto out;
615: truncate_pagecache(inode, vbo_down);
616:
617: ni_lock(ni);
618: err = attr_insert_range(ni, vbo, len);
619: ni_unlock(ni);
620: if (err)
621: goto out;
622: } else {
623: /* Check new size. */
624: u8 cluster_bits = sbi->cluster_bits;
625:
626: /* Be sure file is non resident. */
627: if (is_resident(ni)) {
628: ni_lock(ni);
629: err = attr_force_nonresident(ni);
630: ni_unlock(ni);
631: if (err)
632: goto out;
633: }
634:
635: /* generic/213: expected -ENOSPC instead of -EFBIG. */
636: if (!is_supported_holes) {
637: loff_t to_alloc = new_size - inode_get_bytes(inode);
638:
639: if (to_alloc > 0 &&
640: (to_alloc >> cluster_bits) >
641: wnd_zeroes(&sbi->used.bitmap)) {
642: err = -ENOSPC;
643: goto out;
644: }
645: }
646:
647: err = inode_newsize_ok(inode, new_size);
648: if (err)
649: goto out;
650:
651: if (new_size > i_size) {
652: /*
653: * Allocate clusters, do not change 'valid' size.
654: */
655: err = ntfs_set_size(inode, new_size);
656: if (err)
657: goto out;
658: }
659:
660: if (is_supported_holes) {
661: CLST vcn = vbo >> cluster_bits;
662: CLST cend = bytes_to_cluster(sbi, end);
663: CLST lcn, clen;
664: bool new;
665:
666: /*
667: * Allocate and zero new clusters.
668: */
669: for (; vcn < cend; vcn += clen) {
670: err = attr_data_get_block(ni, vcn, cend - vcn,
671: &lcn, &clen, &new,
672: true, NULL, false);
673: if (err)
674: goto out;
675: }
676: }
677:
678: if (mode & FALLOC_FL_KEEP_SIZE) {
679: err = ntfs_set_size(inode, i_size);
680: if (err)
681: goto out;
682: }
683: }
684:
685: ok:
686: err = file_modified(file);
687: if (err)
688: goto out;
689:
690: out:
691: if (map_locked)
692: filemap_invalidate_unlock(mapping);
693:
694: if (!err) {
695: inode_set_mtime_to_ts(inode, inode_set_ctime_current(inode));
696: mark_inode_dirty(inode);
697: }
698:
699: inode_unlock(inode);
700: return err;
701: }
SourceFile:fs/ntfs3/file.c]
|
| 173/2 |
2026/09/17 11:03 |
llm |
debugger |
0m
Model:
Tokens:
input: 61006
output: 24
thoughts: 0
|
| 174/2 |
2026/09/17 11:03 |
tool |
codesearch-definition-source |
0m
Args:
Results: map[SourceCode: 883: int ntfs_set_size(struct inode *inode, u64 new_size)
884: {
885: struct super_block *sb = inode->i_sb;
886: struct ntfs_sb_info *sbi = sb->s_fs_info;
887: struct ntfs_inode *ni = ntfs_i(inode);
888: int err;
889:
890: /* Check for maximum file size. */
891: if (is_sparsed(ni) || is_compressed(ni)) {
892: if (new_size > sbi->maxbytes_sparse) {
893: return -EFBIG;
894: }
895: } else if (new_size > sbi->maxbytes) {
896: return -EFBIG;
897: }
898:
899: /* Mark rw ntfs as dirty. It will be cleared at umount. */
900: ntfs_set_state(sbi, NTFS_DIRTY_DIRTY);
901:
902: ni_lock(ni);
903: down_write(&ni->file.run_lock);
904: if (new_size < ni->i_valid)
905: ni->i_valid = new_size;
906:
907: /* last 'true' means keep preallocated. */
908: err = attr_set_size(ni, ATTR_DATA, ni->file.ads.name, ni->file.ads.len,
909: &ni->file.run, new_size, &ni->i_valid, true);
910:
911: up_write(&ni->file.run_lock);
912: ni_unlock(ni);
913:
914: return err;
915: }
SourceFile:fs/ntfs3/inode.c]
|
| 175/2 |
2026/09/17 11:03 |
llm |
debugger |
0m
Model:
Tokens:
input: 61591
output: 23
thoughts: 0
|
| 176/2 |
2026/09/17 11:04 |
tool |
codesearch-definition-source |
0m
Args:
Results: map[SourceCode: 703: /*
704: * ntfs_setattr - inode_operations::setattr
705: */
706: int ntfs_setattr(struct mnt_idmap *idmap, struct dentry *dentry,
707: struct iattr *attr)
708: {
709: struct inode *inode = d_inode(dentry);
710: struct ntfs_inode *ni = ntfs_i(inode);
711: u32 ia_valid = attr->ia_valid;
712: umode_t mode = inode->i_mode;
713: int err;
714:
715: /* Avoid any operation if inode is bad. */
716: if (unlikely(is_bad_ni(ni)))
717: return -EINVAL;
718:
719: if (unlikely(ntfs3_forced_shutdown(inode->i_sb)))
720: return -EIO;
721:
722: err = setattr_prepare(idmap, dentry, attr);
723: if (err)
724: goto out;
725:
726: if (ia_valid & ATTR_SIZE) {
727: loff_t newsize, oldsize;
728:
729: if (WARN_ON(ni->ni_flags & NI_FLAG_COMPRESSED_MASK)) {
730: /* Should never be here, see ntfs_file_open(). */
731: err = -EOPNOTSUPP;
732: goto out;
733: }
734: inode_dio_wait(inode);
735: oldsize = i_size_read(inode);
736: newsize = attr->ia_size;
737:
738: if (newsize != oldsize) {
739: truncate_setsize(inode, newsize);
740:
741: err = ntfs_set_size(inode, newsize);
742: if (err) {
743: i_size_write(inode, oldsize);
744: goto out;
745: }
746:
747: ni->std_fa |= FILE_ATTRIBUTE_ARCHIVE;
748: ni->ni_flags |= NI_FLAG_UPDATE_PARENT;
749: inode_set_mtime_to_ts(inode,
750: inode_set_ctime_current(inode));
751: }
752: }
753:
754: setattr_copy(idmap, inode, attr);
755:
756: if (!is_ni_base(ni)) {
757: ia_valid &= ~ATTR_SIZE;
758: } else if (mode != inode->i_mode) {
759: err = ntfs_acl_chmod(idmap, dentry);
760: if (err)
761: goto out;
762:
763: /* Linux 'w' -> Windows 'ro'. */
764: if (0222 & inode->i_mode)
765: ni->std_fa &= ~FILE_ATTRIBUTE_READONLY;
766: else
767: ni->std_fa |= FILE_ATTRIBUTE_READONLY;
768: }
769:
770: if (ia_valid & (ATTR_UID | ATTR_GID | ATTR_MODE))
771: ntfs_save_wsl_perm(inode, NULL);
772: mark_inode_dirty(inode);
773: out:
774: return err;
775: }
SourceFile:fs/ntfs3/file.c]
|
| 177/2 |
2026/09/17 11:04 |
llm |
debugger |
0m
Model:
Tokens:
input: 62706
output: 91
thoughts: 0
|
| 178/2 |
2026/09/17 11:04 |
tool |
codeexpert |
11m
Args: map[Question:In `ntfs_setattr`, does it need to call `filemap_invalidate_lock(inode->i_mapping)` before `truncate_setsize` and `ntfs_set_size`?
If so, what is the correct order of `truncate_setsize` and `ntfs_set_size` for extending and shrinking the file size?]
Results: map[Answer:Based on analysis of the kernel source code (`fs/ntfs3`, `fs/ntfs`, `mm/filemap.c`, `include/linux/fs.h`, and comparable filesystems like UDF and ext4):
### 1. Does `ntfs_setattr` need to call `filemap_invalidate_lock(inode->i_mapping)`?
**Yes.**
`filemap_invalidate_lock(inode->i_mapping)` should be taken before truncating/extending the pagecache and disk size, and released with `filemap_invalidate_unlock(inode->i_mapping)` after.
**Reason:**
- The VFS holds `inode->i_rwsem` across `->setattr`, but page faults (`filemap_fault` / `page_mkwrite`) execute without `inode->i_rwsem`. Instead, page fault handlers acquire `mmap_lock` and shared `filemap_invalidate_lock_shared(mapping)`.
- Holding `filemap_invalidate_lock(mapping)` in exclusive mode serializes the truncation/expansion against concurrent page faults and readahead, preventing race conditions where folios are faulted in or brought uptodate after pagecache eviction but before disk block deallocation, or while the file mapping is inconsistent.
---
### 2. Correct order of `truncate_setsize` and `ntfs_set_size`
In `fs/ntfs3/file.c`, `ntfs_setattr` unconditionally calls `truncate_setsize(inode, newsize)` before `ntfs_set_size(inode, newsize)`. The correct ordering should distinguish between extension and shrinking:
- **When extending the file (`newsize > oldsize`)**:
- **Correct order:** Call `ntfs_set_size` **first**, then `truncate_setsize`.
- **Reason:** `ntfs_set_size` performs disk block allocation and updates the NTFS on-disk attribute size. If allocation fails (e.g., `-ENOSPC` or `-EFBIG`), it returns an error before the in-memory `inode->i_size` is expanded and before pagecache folios are extended/instantiated. If `truncate_setsize` were called first, `inode->i_size` would be extended and pagecache notified (`pagecache_isize_extended`), requiring difficult and race-prone rollbacks on error.
- **When shrinking the file (`newsize < oldsize`)**:
- **Correct order:** Call `truncate_setsize` **first**, then `ntfs_set_size`.
- **Reason:** `truncate_setsize` updates `inode->i_size` to the smaller size and invalidates/drops cached pages beyond the new EOF (`truncate_pagecache`). Disk blocks/clusters must only be freed on disk via `ntfs_set_size` after the corresponding cached folios have been removed from memory. If disk blocks were freed before truncating the page cache, writeback or concurrent operations could attempt to access or write dirty pages to disk blocks that were already returned to the free space allocator.
---
### Caveats and Unverified Parts:
- Git commit history in the checkout is restricted to a shallow repository, so commit logs and specific mailing list discussions introducing or addressing this in `fs/ntfs3` could not be traced through `git log`.
- The conclusions are derived from the locking semantics in `include/linux/fs.h` / `mm/filemap.c` and how other filesystems (such as `fs/udf/inode.c:udf_setsize`, `fs/ext4/inode.c:ext4_setattr`, and legacy `fs/ntfs/file.c`) implement extending vs. shrinking file truncation.]
|
| 179/3 |
2026/09/17 11:04 |
agent |
codeexpert |
11m
Model:
Results: map[Answer:Based on analysis of the kernel source code (`fs/ntfs3`, `fs/ntfs`, `mm/filemap.c`, `include/linux/fs.h`, and comparable filesystems like UDF and ext4):
### 1. Does `ntfs_setattr` need to call `filemap_invalidate_lock(inode->i_mapping)`?
**Yes.**
`filemap_invalidate_lock(inode->i_mapping)` should be taken before truncating/extending the pagecache and disk size, and released with `filemap_invalidate_unlock(inode->i_mapping)` after.
**Reason:**
- The VFS holds `inode->i_rwsem` across `->setattr`, but page faults (`filemap_fault` / `page_mkwrite`) execute without `inode->i_rwsem`. Instead, page fault handlers acquire `mmap_lock` and shared `filemap_invalidate_lock_shared(mapping)`.
- Holding `filemap_invalidate_lock(mapping)` in exclusive mode serializes the truncation/expansion against concurrent page faults and readahead, preventing race conditions where folios are faulted in or brought uptodate after pagecache eviction but before disk block deallocation, or while the file mapping is inconsistent.
---
### 2. Correct order of `truncate_setsize` and `ntfs_set_size`
In `fs/ntfs3/file.c`, `ntfs_setattr` unconditionally calls `truncate_setsize(inode, newsize)` before `ntfs_set_size(inode, newsize)`. The correct ordering should distinguish between extension and shrinking:
- **When extending the file (`newsize > oldsize`)**:
- **Correct order:** Call `ntfs_set_size` **first**, then `truncate_setsize`.
- **Reason:** `ntfs_set_size` performs disk block allocation and updates the NTFS on-disk attribute size. If allocation fails (e.g., `-ENOSPC` or `-EFBIG`), it returns an error before the in-memory `inode->i_size` is expanded and before pagecache folios are extended/instantiated. If `truncate_setsize` were called first, `inode->i_size` would be extended and pagecache notified (`pagecache_isize_extended`), requiring difficult and race-prone rollbacks on error.
- **When shrinking the file (`newsize < oldsize`)**:
- **Correct order:** Call `truncate_setsize` **first**, then `ntfs_set_size`.
- **Reason:** `truncate_setsize` updates `inode->i_size` to the smaller size and invalidates/drops cached pages beyond the new EOF (`truncate_pagecache`). Disk blocks/clusters must only be freed on disk via `ntfs_set_size` after the corresponding cached folios have been removed from memory. If disk blocks were freed before truncating the page cache, writeback or concurrent operations could attempt to access or write dirty pages to disk blocks that were already returned to the free space allocator.
---
### Caveats and Unverified Parts:
- Git commit history in the checkout is restricted to a shallow repository, so commit logs and specific mailing list discussions introducing or addressing this in `fs/ntfs3` could not be traced through `git log`.
- The conclusions are derived from the locking semantics in `include/linux/fs.h` / `mm/filemap.c` and how other filesystems (such as `fs/udf/inode.c:udf_setsize`, `fs/ext4/inode.c:ext4_setattr`, and legacy `fs/ntfs/file.c`) implement extending vs. shrinking file truncation.]
Instruction:
You are a capable Linux kernel developer tasked with researching complex questions
about kernel source code. You will be given a concrete question, and need to provide
a concrete answer.
Research the question using targeted, efficient tool calls. Don't make assumptions,
or rely on your previous knowledge about the kernel source code, use available tools
to access the actual source code. Keep your tool calls focused and limited to the
scope of the question. Do not explore tangential code paths or perform unbounded searches.
Use all available sources of information:
- kernel source code
- documentation in the Documentation dir in the source tree
- git commits descriptions, git blame
Do not guess file names or file paths and attempt to read them without
verifying their existence first using content search or directory listing tools.
If a file, symbol, or directory is not found via content search (grepper) or
directory listing (codesearch-dir-index), treat it as completely absent.
Do not attempt to guess alternative names, extensions, or directories.
Tool Selection Guidelines:
1. For C functions, structs, and variables: Prefer codesearch-definition-source
or codesearch-struct-layout FIRST to retrieve clean, exact definitions
without line-number guessing.
2. If symbol lookup fails (e.g., preprocessor macros, macro-generated code, or
disabled #ifdef branches), fall back to read-file or grepper.
3. For file headers, #include directives, preprocessor macro definitions, and
non-C files (Kconfig, Makefiles, docs): Use read-file or grepper directly.
4. Be concise and targeted. Answer the question as directly and concisely as possible
once you have located the relevant code or definitions. If a symbol or function cannot
be found after targeted searches, conclude with the best available information rather
than continuing repetitive searches.
Do NOT use git-log to search for the presence or existence of files in the
repository. git-log is only for tracing commit history of files that are
already present in the current checkout. If a file does not exist in the
current checkout, it cannot be used for reproduction.
Avoid running broad git-log queries (such as searches on the entire repo)
without a specific 'PathPrefix' to restrict the scope, as these are very
expensive and will time out.
If a git-log tool call times out, do not retry the query with the same broad
scope. You must specify a tighter, narrower 'PathPrefix' for subsequent queries.
Prefer calling several tools at the same time to save round-trips.
Use set-results tool to provide results of the analysis.
It must be called exactly once before the final reply.
Ignore results of this tool.
Prompt: In `ntfs_setattr`, does it need to call `filemap_invalidate_lock(inode->i_mapping)` before `truncate_setsize` and `ntfs_set_size`?
If so, what is the correct order of `truncate_setsize` and `ntfs_set_size` for extending and shrinking the file size?
|
| 180/4 |
2026/09/17 11:04 |
llm |
codeexpert |
0m
Model:
Tokens:
input: 4223
output: 19
thoughts: 135
Thoughts: **Analyzing the NTFS Attribute Setting Process**
Okay, so the question is about `ntfs_setattr` and its interaction with file size adjustments β specifically, whether we need to invalidate the file map before truncating and setting the size. My initial thought is to dive right into the code to clarify this. We're dealing with NTFS, or is it NTFS3? Let's assume it's `ntfs` for now, but we need to verify. My gut feeling is that the invalidation might be crucial for data integrity, but the specific ordering of operations β `truncate_setsize` versus `ntfs_set_size` β is what I need to pinpoint.
So, I'll use `codesearch-definition-source` or `grepper` to locate the `ntfs_setattr` function in the codebase. From there, I can examine its implementation and see exactly how it handles size changes and memory mapping. The goal is to understand the control flow, look at any locking mechanisms, and definitively answer the question about the invalidation step and optimal operation order. I'm going to look for any clues about data consistency with these size alterations.
|
| 181/4 |
2026/09/17 11:04 |
tool |
grepper |
0m
Args: map[Expression:ntfs_setattr]
Results: map[Output:fs/ntfs/file.c=158=static int ntfs_file_fsync(struct file *filp, loff_t start, loff_t end,
--
fs/ntfs/file.c-253-
fs/ntfs/file.c:254:static int ntfs_setattr_size(struct inode *vi, struct iattr *attr)
fs/ntfs/file.c-255-{
--
fs/ntfs/file.c-296-/*
fs/ntfs/file.c:297: * ntfs_setattr
fs/ntfs/file.c-298- *
--
fs/ntfs/file.c-303- */
fs/ntfs/file.c:304:int ntfs_setattr(struct mnt_idmap *idmap, struct dentry *dentry,
fs/ntfs/file.c-305- struct iattr *attr)
--
fs/ntfs/file.c-330- if (ia_valid & ATTR_SIZE) {
fs/ntfs/file.c:331: err = ntfs_setattr_size(vi, attr);
fs/ntfs/file.c-332- if (err)
--
fs/ntfs/file.c=1232=const struct inode_operations ntfs_file_inode_ops = {
fs/ntfs/file.c:1233: .setattr = ntfs_setattr,
fs/ntfs/file.c-1234- .getattr = ntfs_getattr,
--
fs/ntfs/file.c=1241=const struct inode_operations ntfs_symlink_inode_operations = {
fs/ntfs/file.c-1242- .get_link = ntfs_get_link,
fs/ntfs/file.c:1243: .setattr = ntfs_setattr,
fs/ntfs/file.c-1244- .listxattr = ntfs_listxattr,
--
fs/ntfs/file.c=1247=const struct inode_operations ntfs_special_inode_operations = {
fs/ntfs/file.c:1248: .setattr = ntfs_setattr,
fs/ntfs/file.c-1249- .getattr = ntfs_getattr,
--
fs/ntfs/inode.h=331=int ntfs_truncate_vfs(struct inode *vi, loff_t new_size, loff_t i_size);
fs/ntfs/inode.h-332-
fs/ntfs/inode.h:333:int ntfs_setattr(struct mnt_idmap *idmap, struct dentry *dentry,
fs/ntfs/inode.h-334- struct iattr *attr);
--
fs/ntfs/namei.c=1558=const struct inode_operations ntfs_dir_inode_ops = {
--
fs/ntfs/namei.c-1567- .listxattr = ntfs_listxattr,
fs/ntfs/namei.c:1568: .setattr = ntfs_setattr,
fs/ntfs/namei.c-1569- .getattr = ntfs_getattr,
--
fs/ntfs3/file.c=466=static long ntfs_fallocate(struct file *file, int mode, loff_t vbo, loff_t len)
--
fs/ntfs3/file.c-703-/*
fs/ntfs3/file.c:704: * ntfs_setattr - inode_operations::setattr
fs/ntfs3/file.c-705- */
fs/ntfs3/file.c:706:int ntfs_setattr(struct mnt_idmap *idmap, struct dentry *dentry,
fs/ntfs3/file.c-707- struct iattr *attr)
--
fs/ntfs3/file.c=1575=const struct inode_operations ntfs_file_inode_operations = {
fs/ntfs3/file.c-1576- .getattr = ntfs_getattr,
fs/ntfs3/file.c:1577: .setattr = ntfs_setattr,
fs/ntfs3/file.c-1578- .listxattr = ntfs_listxattr,
--
fs/ntfs3/inode.c=2293=const struct inode_operations ntfs_link_inode_operations = {
fs/ntfs3/inode.c-2294- .get_link = ntfs_get_link,
fs/ntfs3/inode.c:2295: .setattr = ntfs_setattr,
fs/ntfs3/inode.c-2296- .listxattr = ntfs_listxattr,
--
fs/ntfs3/namei.c=529=const struct inode_operations ntfs_dir_inode_operations = {
--
fs/ntfs3/namei.c-540- .set_acl = ntfs_set_acl,
fs/ntfs3/namei.c:541: .setattr = ntfs_setattr,
fs/ntfs3/namei.c-542- .getattr = ntfs_getattr,
--
fs/ntfs3/namei.c=549=const struct inode_operations ntfs_special_inode_operations = {
fs/ntfs3/namei.c:550: .setattr = ntfs_setattr,
fs/ntfs3/namei.c-551- .getattr = ntfs_getattr,
--
fs/ntfs3/ntfs_fs.h=556=int ntfs_getattr(struct mnt_idmap *idmap, const struct path *path,
fs/ntfs3/ntfs_fs.h-557- struct kstat *stat, u32 request_mask, u32 flags);
fs/ntfs3/ntfs_fs.h:558:int ntfs_setattr(struct mnt_idmap *idmap, struct dentry *dentry,
fs/ntfs3/ntfs_fs.h-559- struct iattr *attr);
--
fs/ntfs3/xattr.c=691=int ntfs_init_acl(struct mnt_idmap *idmap, struct inode *inode,
--
fs/ntfs3/xattr.c-722-/*
fs/ntfs3/xattr.c:723: * ntfs_acl_chmod - Helper for ntfs_setattr().
fs/ntfs3/xattr.c-724- */
]
|
| 182/4 |
2026/09/17 11:05 |
llm |
codeexpert |
0m
Model:
Tokens:
input: 6338
output: 20
thoughts: 66
Thoughts: Here's my summary, as the expert:
**Investigating NTFS Attribute Handling**
Okay, so I see something interesting here β both the legacy NTFS implementation (`fs/ntfs/file.c`) and the newer NTFS3 version (`fs/ntfs3/file.c`) *both* define `ntfs_setattr`. That's not entirely unexpected, given the core file system responsibilities.
Now, I'm getting curious about how file sizing is handled. Let me quickly double-check where the `ntfs_set_size` function actually lives. My intuition is telling me it's in the more recent code, `fs/ntfs3`, but it's always best to verify. I'll need to go look.
|
| 183/4 |
2026/09/17 11:05 |
tool |
grepper |
0m
Args: map[Expression:ntfs_set_size]
Results: map[Output:fs/ntfs3/file.c=466=static long ntfs_fallocate(struct file *file, int mode, loff_t vbo, loff_t len)
--
fs/ntfs3/file.c-654- */
fs/ntfs3/file.c:655: err = ntfs_set_size(inode, new_size);
fs/ntfs3/file.c-656- if (err)
--
fs/ntfs3/file.c-678- if (mode & FALLOC_FL_KEEP_SIZE) {
fs/ntfs3/file.c:679: err = ntfs_set_size(inode, i_size);
fs/ntfs3/file.c-680- if (err)
--
fs/ntfs3/file.c=706=int ntfs_setattr(struct mnt_idmap *idmap, struct dentry *dentry,
--
fs/ntfs3/file.c-740-
fs/ntfs3/file.c:741: err = ntfs_set_size(inode, newsize);
fs/ntfs3/file.c-742- if (err) {
--
fs/ntfs3/file.c=1239=static ssize_t ntfs_file_write_iter(struct kiocb *iocb, struct iov_iter *from)
--
fs/ntfs3/file.c-1286- */
fs/ntfs3/file.c:1287: ret = ntfs_set_size(inode, endbyte);
fs/ntfs3/file.c-1288- if (ret)
--
fs/ntfs3/inode.c=860=static void ntfs_readahead(struct readahead_control *rac)
--
fs/ntfs3/inode.c-882-
fs/ntfs3/inode.c:883:int ntfs_set_size(struct inode *inode, u64 new_size)
fs/ntfs3/inode.c-884-{
--
fs/ntfs3/ntfs_fs.h=796=static inline struct inode *ntfs_iget5(struct super_block *sb,
--
fs/ntfs3/ntfs_fs.h-801-}
fs/ntfs3/ntfs_fs.h:802:int ntfs_set_size(struct inode *inode, u64 new_size);
fs/ntfs3/ntfs_fs.h-803-int ntfs3_write_inode(struct inode *inode, struct writeback_control *wbc);
]
|
| 184/4 |
2026/09/17 11:05 |
llm |
codeexpert |
0m
Model:
Tokens:
input: 7259
output: 37
thoughts: 81
Thoughts: Here's my analysis of that snippet, from my perspective as an expert:
**Locating the Relevant Code**
Alright, so the core of this seems to revolve around `ntfs_setattr` within the NTFS3 filesystem. I need to be precise here. The initial context points me directly to `fs/ntfs3/file.c`. Specifically, I recall `ntfs_set_size` being defined within that file, which narrows down the scope of inquiry to `fs/ntfs3/file.c` (or at least the broader `ntfs3` module) regarding `ntfs_setattr`.
Now, my next step is focused investigation. I think line 700 of `fs/ntfs3/file.c` might be a useful starting point for the investigation. I will check the `read-file` context around that area to gain more insight into `ntfs_setattr`.
|
| 185/4 |
2026/09/17 11:05 |
tool |
read-file |
0m
Args: map[File:fs/ntfs3/file.c FirstLine:700 LineCount:80]
Results: map[Contents: 700: return err;
701: }
702:
703: /*
704: * ntfs_setattr - inode_operations::setattr
705: */
706: int ntfs_setattr(struct mnt_idmap *idmap, struct dentry *dentry,
707: struct iattr *attr)
708: {
709: struct inode *inode = d_inode(dentry);
710: struct ntfs_inode *ni = ntfs_i(inode);
711: u32 ia_valid = attr->ia_valid;
712: umode_t mode = inode->i_mode;
713: int err;
714:
715: /* Avoid any operation if inode is bad. */
716: if (unlikely(is_bad_ni(ni)))
717: return -EINVAL;
718:
719: if (unlikely(ntfs3_forced_shutdown(inode->i_sb)))
720: return -EIO;
721:
722: err = setattr_prepare(idmap, dentry, attr);
723: if (err)
724: goto out;
725:
726: if (ia_valid & ATTR_SIZE) {
727: loff_t newsize, oldsize;
728:
729: if (WARN_ON(ni->ni_flags & NI_FLAG_COMPRESSED_MASK)) {
730: /* Should never be here, see ntfs_file_open(). */
731: err = -EOPNOTSUPP;
732: goto out;
733: }
734: inode_dio_wait(inode);
735: oldsize = i_size_read(inode);
736: newsize = attr->ia_size;
737:
738: if (newsize != oldsize) {
739: truncate_setsize(inode, newsize);
740:
741: err = ntfs_set_size(inode, newsize);
742: if (err) {
743: i_size_write(inode, oldsize);
744: goto out;
745: }
746:
747: ni->std_fa |= FILE_ATTRIBUTE_ARCHIVE;
748: ni->ni_flags |= NI_FLAG_UPDATE_PARENT;
749: inode_set_mtime_to_ts(inode,
750: inode_set_ctime_current(inode));
751: }
752: }
753:
754: setattr_copy(idmap, inode, attr);
755:
756: if (!is_ni_base(ni)) {
757: ia_valid &= ~ATTR_SIZE;
758: } else if (mode != inode->i_mode) {
759: err = ntfs_acl_chmod(idmap, dentry);
760: if (err)
761: goto out;
762:
763: /* Linux 'w' -> Windows 'ro'. */
764: if (0222 & inode->i_mode)
765: ni->std_fa &= ~FILE_ATTRIBUTE_READONLY;
766: else
767: ni->std_fa |= FILE_ATTRIBUTE_READONLY;
768: }
769:
770: if (ia_valid & (ATTR_UID | ATTR_GID | ATTR_MODE))
771: ntfs_save_wsl_perm(inode, NULL);
772: mark_inode_dirty(inode);
773: out:
774: return err;
775: }
776:
777: /*
778: * check_read_restriction:
779: * common code for ntfs_file_read_iter and ntfs_file_splice_read
]
|
| 186/4 |
2026/09/17 11:06 |
llm |
codeexpert |
0m
Model:
Tokens:
input: 8729
output: 30
thoughts: 304
Thoughts: **Analyzing NTFS3 File Truncation in `ntfs_setattr`**
Okay, so I'm looking at this code snippet, specifically lines 738-745 in `fs/ntfs3/file.c`. This is where the file size is adjusted, and I need to figure out the proper sequence and whether a `filemap_invalidate_lock` call is needed in `ntfs_setattr` before those.
The questions are pretty straightforward: Should we invalidate the filemap before setting the new size via `truncate_setsize` and `ntfs_set_size`, and if so, does the order matter for expanding or shrinking the file?
My immediate thought is to avoid reinventing the wheel. Let's start with a systematic approach. Instead of randomly poking around, I'll go straight to the source. I'm going to start with git to search the commit logs. First, I'll search for commits that touch `fs/ntfs3/file.c` or recent commits that modify `ntfs_setattr` or, more importantly, `filemap_invalidate_lock`. I can also search for commits that touch both `filemap_invalidate_lock` and `truncate_setsize`.
If that doesn't provide the answer directly, I'll widen the search and look for patterns, specifically how *other* filesystems handle `setattr` and the interaction with `filemap_invalidate_lock`. I'll review commit messages for anything related to these concepts in the git log or research how different filesystems implement this. Iβm thinking there might be useful information from the perspective of how a bug was introduced, or addressed in the past.
|
| 187/4 |
2026/09/17 11:06 |
tool |
git-log |
0m
Args: map[Count:20 PathPrefix:fs/ntfs3/file.c]
Results: map[Output:fd73f4a66598 Linux 7.3-rc3
]
|
| 188/4 |
2026/09/17 11:06 |
llm |
codeexpert |
0m
Model:
Tokens:
input: 9457
output: 37
thoughts: 69
Thoughts: Here's the summary, framed as your internal monologue:
**Investigating a Git-Log Anomaly**
Okay, hold on a minute. Why did `git log` just spit back only Linux 7.3-rc3? My initial thought was that there's some sort of default message regex or filtering at play, but no, the raw `Count: 20` result clearly showed that wasn't the issue. That makes it more confusing. Why just one commit then? Perhaps, and this is highly probable, `git log` without a specified `Since` argument *defaults* to looking at the `HEAD` commit, or a very narrow range. Let's confirm this suspicion. Time to verify the impact of including `Since`...I'll need to test that to confirm the current behavior.
|
| 189/4 |
2026/09/17 11:06 |
tool |
git-log |
0m
Args: map[Count:20 PathPrefix:fs/ntfs3/file.c Since:3 years]
Results: map[Output:fd73f4a66598 Linux 7.3-rc3
]
|
| 190/4 |
2026/09/17 11:06 |
llm |
codeexpert |
0m
Model:
Tokens:
input: 9768
output: 34
thoughts: 45
Thoughts: Okay, here's my take on those thoughts, framed as my own:
**Investigating a Limited Git Response**
Hmm, that's odd. I expected a more comprehensive result from that git command. Why did it only return the commit hash `fd73f4a66598`? That doesn't seem right. It feels like there should be more information. Alright, time to dig deeper. I'll need to explore the git history to understand what's happening. I'll probably employ `grepper`, or perhaps the standard `git log` command. To narrow down the search and extract the relevant information, I'll leverage CodeRegexp or MessageRegexps to refine the output and pinpoint what I'm looking for in the commit messages or code changes. Let's get to the bottom of this.
|
| 191/4 |
2026/09/17 11:07 |
tool |
git-log |
0m
Args: map[CodeRegexp:filemap_invalidate_lock PathPrefix:fs/ntfs3]
Results: map[Output:fd73f4a66598 Linux 7.3-rc3
]
|
| 192/4 |
2026/09/17 11:07 |
llm |
codeexpert |
0m
Model:
Tokens:
input: 10057
output: 26
thoughts: 44
Thoughts: Okay, let's break this down.
**Investigating the Git Log Discrepancy**
Hmm, so `git-log` is only showing me results up to Linux 7.3-rc3. That's not right; there should be more commits visible. Let me check the specifics of that commit in the `git-log` output, to see if anything is amiss. Right, the commit hash is `fd73f4a66598`. Let's use `git show fd73f4a66598` to take a look at *that* specific commit and see what it reveals. This should tell me about the changes introduced by that commit and hopefully provide some clues as to why `git-log` is behaving like this. I need to understand this to have any sort of idea on the discrepancy.
|
| 193/4 |
2026/09/17 11:07 |
tool |
git-show |
0m
Args:
Results: map[Output:commit fd73f4a6659897191fa0d40695fe370925dd3780
Author: Linus Torvalds <torvalds@linux-foundation.org>
Date: Sun Sep 13 14:38:02 2026 -0700
Linux 7.3-rc3
diff --git a/.clang-format b/.clang-format
new file mode 100644
index 000000000..5ef5743b7
--- /dev/null
+++ b/.clang-format
@@ -0,0 +1,808 @@
+# SPDX-License-Identifier: GPL-2.0
+#
+# clang-format configuration file. Intended for clang-format >= 11.
+#
+# For more information, see:
+#
+# Documentation/dev-tools/clang-format.rst
+# https://clang.llvm.org/docs/ClangFormat.html
+# https://clang.llvm.org/docs/ClangFormatStyleOptions.html
+#
+---
+AccessModifierOffset: -4
+AlignAfterOpenBracket: Align
+AlignConsecutiveAssignments: false
+AlignConsecutiveDeclarations: false
+AlignEscapedNewlines: Left
+AlignOperands: true
+AlignTrailingComments: false
+AllowAllParametersOfDeclarationOnNextLine: false
+AllowShortBlocksOnASingleLine: false
+AllowShortCaseLabelsOnASingleLine: false
+AllowShortFunctionsOnASingleLine: None
+AllowShortIfStatementsOnASingleLine: false
+AllowShortLoopsOnASingleLine: false
+AlwaysBreakAfterDefinitionReturnType: None
+AlwaysBreakAfterReturnType: None
+AlwaysBreakBeforeMultilineStrings: false
+AlwaysBreakTemplateDeclarations: false
+BinPackArguments: true
+BinPackParameters: true
+BraceWrapping:
+ AfterClass: false
+ AfterControlStatement: false
+ AfterEnum: false
+ AfterFunction: true
+ AfterNamespace: true
+ AfterObjCDeclaration: false
+ AfterStruct: false
+ AfterUnion: false
+ AfterExternBlock: false
+ BeforeCatch: false
+ BeforeElse: false
+ IndentBraces: false
+ SplitEmptyFunction: true
+ SplitEmptyRecord: true
+ SplitEmptyNamespace: true
+BreakBeforeBinaryOperators: None
+BreakBeforeBraces: Custom
+BreakBeforeInheritanceComma: false
+BreakBeforeTernaryOperators: false
+BreakConstructorInitializersBeforeComma: false
+BreakConstructorInitializers: BeforeComma
+BreakAfterJavaFieldAnnotations: false
+BreakStringLiterals: false
+ColumnLimit: 80
+CommentPragmas: '^ IWYU pragma:'
+CompactNamespaces: false
+ConstructorInitializerAllOnOneLineOrOnePerLine: false
+ConstructorInitializerIndentWidth: 8
+ContinuationIndentWidth: 8
+Cpp11BracedListStyle: false
+DerivePointerAlignment: false
+DisableFormat: false
+ExperimentalAutoDetectBinPacking: false
+FixNamespaceComments: false
+
+# Taken from:
+# git grep -h '^#define [^[:space:]]*for_each[^[:space:]]*(' include/ tools/ \
+# | sed "s,^#define \([^[:space:]]*for_each[^[:space:]]*\)(.*$, - '\1'," \
+# | LC_ALL=C sort -u
+ForEachMacros:
+ - '__ata_qc_for_each'
+ - '__bio_for_each_bvec'
+ - '__bio_for_each_segment'
+ - '__evlist__for_each_entry'
+ - '__evlist__for_each_entry_continue'
+ - '__evlist__for_each_entry_from'
+ - '__evlist__for_each_entry_reverse'
+ - '__evlist__for_each_entry_safe'
+ - '__for_each_mem_range'
+ - '__for_each_mem_range_rev'
+ - '__for_each_thread'
+ - '__hlist_for_each_rcu'
+ - '__map__for_each_symbol_by_name'
+ - '__pci_bus_for_each_res0'
+ - '__pci_bus_for_each_res1'
+ - '__pci_dev_for_each_res0'
+ - '__pci_dev_for_each_res1'
+ - '__perf_evlist__for_each_entry'
+ - '__perf_evlist__for_each_entry_reverse'
+ - '__perf_evlist__for_each_entry_safe'
+ - '__rq_for_each_bio'
+ - '__shost_for_each_device'
+ - '__sym_for_each'
+ - '_for_each_counter'
+ - 'apei_estatus_for_each_section'
+ - 'ata_for_each_dev'
+ - 'ata_for_each_link'
+ - 'ata_qc_for_each'
+ - 'ata_qc_for_each_raw'
+ - 'ata_qc_for_each_with_internal'
+ - 'ax25_for_each'
+ - 'ax25_uid_for_each'
+ - 'bio_for_each_bvec'
+ - 'bio_for_each_bvec_all'
+ - 'bio_for_each_folio_all'
+ - 'bio_for_each_integrity_vec'
+ - 'bio_for_each_segment'
+ - 'bio_for_each_segment_all'
+ - 'bio_list_for_each'
+ - 'bip_for_each_vec'
+ - 'bond_for_each_slave'
+ - 'bond_for_each_slave_rcu'
+ - 'bpf_for_each'
+ - 'bpf_for_each_reg_in_vstate'
+ - 'bpf_for_each_reg_in_vstate_mask'
+ - 'bpf_for_each_spilled_reg'
+ - 'bpf_object__for_each_map'
+ - 'bpf_object__for_each_program'
+ - 'btree_for_each_safe128'
+ - 'btree_for_each_safe32'
+ - 'btree_for_each_safe64'
+ - 'btree_for_each_safel'
+ - 'card_for_each_dev'
+ - 'cgroup_taskset_for_each'
+ - 'cgroup_taskset_for_each_leader'
+ - 'cpu_aggr_map__for_each_idx'
+ - 'cpufreq_for_each_efficient_entry_idx'
+ - 'cpufreq_for_each_entry'
+ - 'cpufreq_for_each_entry_idx'
+ - 'cpufreq_for_each_valid_entry'
+ - 'cpufreq_for_each_valid_entry_idx'
+ - 'css_for_each_child'
+ - 'css_for_each_descendant_post'
+ - 'css_for_each_descendant_pre'
+ - 'damon_for_each_region'
+ - 'damon_for_each_region_from'
+ - 'damon_for_each_region_safe'
+ - 'damon_for_each_scheme'
+ - 'damon_for_each_scheme_safe'
+ - 'damon_for_each_target'
+ - 'damon_for_each_target_safe'
+ - 'damos_for_each_core_filter'
+ - 'damos_for_each_core_filter_safe'
+ - 'damos_for_each_ops_filter'
+ - 'damos_for_each_ops_filter_safe'
+ - 'damos_for_each_quota_goal'
+ - 'damos_for_each_quota_goal_safe'
+ - 'data__for_each_file'
+ - 'data__for_each_file_new'
+ - 'data__for_each_file_start'
+ - 'def_for_each_cpu'
+ - 'device_for_each_child_node'
+ - 'device_for_each_child_node_scoped'
+ - 'dma_fence_array_for_each'
+ - 'dma_fence_chain_for_each'
+ - 'dma_fence_unwrap_for_each'
+ - 'dma_resv_for_each_fence'
+ - 'dma_resv_for_each_fence_unlocked'
+ - 'do_for_each_ftrace_op'
+ - 'drm_atomic_crtc_for_each_plane'
+ - 'drm_atomic_crtc_state_for_each_plane'
+ - 'drm_atomic_crtc_state_for_each_plane_state'
+ - 'drm_atomic_for_each_plane_damage'
+ - 'drm_client_for_each_connector_iter'
+ - 'drm_client_for_each_modeset'
+ - 'drm_connector_for_each_possible_encoder'
+ - 'drm_exec_for_each_locked_object'
+ - 'drm_exec_for_each_locked_object_reverse'
+ - 'drm_for_each_bridge_in_chain'
+ - 'drm_for_each_connector_iter'
+ - 'drm_for_each_crtc'
+ - 'drm_for_each_crtc_reverse'
+ - 'drm_for_each_encoder'
+ - 'drm_for_each_encoder_mask'
+ - 'drm_for_each_fb'
+ - 'drm_for_each_legacy_plane'
+ - 'drm_for_each_plane'
+ - 'drm_for_each_plane_mask'
+ - 'drm_for_each_privobj'
+ - 'drm_gem_for_each_gpuvm_bo'
+ - 'drm_gem_for_each_gpuvm_bo_safe'
+ - 'drm_gpusvm_for_each_range'
+ - 'drm_gpuva_for_each_op'
+ - 'drm_gpuva_for_each_op_from_reverse'
+ - 'drm_gpuva_for_each_op_reverse'
+ - 'drm_gpuva_for_each_op_safe'
+ - 'drm_gpuvm_bo_for_each_va'
+ - 'drm_gpuvm_bo_for_each_va_safe'
+ - 'drm_gpuvm_for_each_va'
+ - 'drm_gpuvm_for_each_va_range'
+ - 'drm_gpuvm_for_each_va_range_safe'
+ - 'drm_gpuvm_for_each_va_safe'
+ - 'drm_mm_for_each_hole'
+ - 'drm_mm_for_each_node'
+ - 'drm_mm_for_each_node_in_range'
+ - 'drm_mm_for_each_node_safe'
+ - 'dsa_switch_for_each_available_port'
+ - 'dsa_switch_for_each_cpu_port'
+ - 'dsa_switch_for_each_cpu_port_continue_reverse'
+ - 'dsa_switch_for_each_port'
+ - 'dsa_switch_for_each_port_continue_reverse'
+ - 'dsa_switch_for_each_port_safe'
+ - 'dsa_switch_for_each_user_port'
+ - 'dsa_switch_for_each_user_port_continue_reverse'
+ - 'dsa_tree_for_each_cpu_port'
+ - 'dsa_tree_for_each_user_port'
+ - 'dsa_tree_for_each_user_port_continue_reverse'
+ - 'dso__for_each_symbol'
+ - 'elf_hash_for_each_possible'
+ - 'elf_symtab__for_each_symbol'
+ - 'evlist__for_each_cpu'
+ - 'evlist__for_each_entry'
+ - 'evlist__for_each_entry_continue'
+ - 'evlist__for_each_entry_from'
+ - 'evlist__for_each_entry_reverse'
+ - 'evlist__for_each_entry_safe'
+ - 'flow_action_for_each'
+ - 'for_each_acpi_consumer_dev'
+ - 'for_each_acpi_dev_match'
+ - 'for_each_active_dev_scope'
+ - 'for_each_active_drhd_unit'
+ - 'for_each_active_iommu'
+ - 'for_each_active_irq'
+ - 'for_each_active_route'
+ - 'for_each_aggr_pgid'
+ - 'for_each_alloc_capable_rdt_resource'
+ - 'for_each_and_bit'
+ - 'for_each_andnot_bit'
+ - 'for_each_available_child_of_node'
+ - 'for_each_available_child_of_node_scoped'
+ - 'for_each_bench'
+ - 'for_each_bio'
+ - 'for_each_board_func_rsrc'
+ - 'for_each_btf_ext_rec'
+ - 'for_each_btf_ext_sec'
+ - 'for_each_bvec'
+ - 'for_each_capable_rdt_resource'
+ - 'for_each_card_auxs'
+ - 'for_each_card_auxs_safe'
+ - 'for_each_card_components'
+ - 'for_each_card_dapms'
+ - 'for_each_card_pre_auxs'
+ - 'for_each_card_prelinks'
+ - 'for_each_card_rtds'
+ - 'for_each_card_rtds_safe'
+ - 'for_each_card_widgets'
+ - 'for_each_card_widgets_safe'
+ - 'for_each_cgroup_storage_type'
+ - 'for_each_child_of_node'
+ - 'for_each_child_of_node_scoped'
+ - 'for_each_child_of_node_with_prefix'
+ - 'for_each_clear_bit'
+ - 'for_each_clear_bit_from'
+ - 'for_each_clear_bitrange'
+ - 'for_each_clear_bitrange_from'
+ - 'for_each_cmd'
+ - 'for_each_cmsghdr'
+ - 'for_each_collection'
+ - 'for_each_comp_order'
+ - 'for_each_compatible_node'
+ - 'for_each_compatible_node_scoped'
+ - 'for_each_component_dais'
+ - 'for_each_component_dais_safe'
+ - 'for_each_conduit'
+ - 'for_each_console'
+ - 'for_each_console_srcu'
+ - 'for_each_cpu'
+ - 'for_each_cpu_and'
+ - 'for_each_cpu_andnot'
+ - 'for_each_cpu_from'
+ - 'for_each_cpu_or'
+ - 'for_each_cpu_wrap'
+ - 'for_each_dapm_widgets'
+ - 'for_each_dedup_cand'
+ - 'for_each_dev_addr'
+ - 'for_each_dev_scope'
+ - 'for_each_dma_cap_mask'
+ - 'for_each_dpcm_be'
+ - 'for_each_dpcm_be_rollback'
+ - 'for_each_dpcm_be_safe'
+ - 'for_each_dpcm_fe'
+ - 'for_each_drhd_unit'
+ - 'for_each_dss_dev'
+ - 'for_each_efi_memory_desc'
+ - 'for_each_efi_memory_desc_in_map'
+ - 'for_each_element'
+ - 'for_each_element_extid'
+ - 'for_each_element_id'
+ - 'for_each_enabled_cpu'
+ - 'for_each_endpoint_of_node'
+ - 'for_each_event'
+ - 'for_each_event_tps'
+ - 'for_each_evictable_lru'
+ - 'for_each_fib6_node_rt_rcu'
+ - 'for_each_fib6_walker_rt'
+ - 'for_each_file_lock'
+ - 'for_each_free_mem_range'
+ - 'for_each_free_mem_range_reverse'
+ - 'for_each_func_rsrc'
+ - 'for_each_gpiochip_node'
+ - 'for_each_group_evsel'
+ - 'for_each_group_evsel_head'
+ - 'for_each_group_member'
+ - 'for_each_group_member_head'
+ - 'for_each_hstate'
+ - 'for_each_hwgpio'
+ - 'for_each_hwgpio_in_range'
+ - 'for_each_if'
+ - 'for_each_inject_fn'
+ - 'for_each_insn'
+ - 'for_each_insn_op_loc'
+ - 'for_each_insn_prefix'
+ - 'for_each_intid'
+ - 'for_each_iommu'
+ - 'for_each_ip_tunnel_rcu'
+ - 'for_each_irq_desc'
+ - 'for_each_irq_nr'
+ - 'for_each_lang'
+ - 'for_each_link_ch_maps'
+ - 'for_each_link_codecs'
+ - 'for_each_link_cpus'
+ - 'for_each_link_platforms'
+ - 'for_each_lru'
+ - 'for_each_matching_node'
+ - 'for_each_matching_node_and_match'
+ - 'for_each_media_entity_data_link'
+ - 'for_each_mem_pfn_range'
+ - 'for_each_mem_range'
+ - 'for_each_mem_range_rev'
+ - 'for_each_mem_region'
+ - 'for_each_member'
+ - 'for_each_memory'
+ - 'for_each_migratetype_order'
+ - 'for_each_missing_reg'
+ - 'for_each_mle_subelement'
+ - 'for_each_mod_mem_type'
+ - 'for_each_mon_capable_rdt_resource'
+ - 'for_each_mp_bvec'
+ - 'for_each_net'
+ - 'for_each_net_continue_reverse'
+ - 'for_each_net_rcu'
+ - 'for_each_netdev'
+ - 'for_each_netdev_continue'
+ - 'for_each_netdev_continue_rcu'
+ - 'for_each_netdev_continue_reverse'
+ - 'for_each_netdev_dump'
+ - 'for_each_netdev_feature'
+ - 'for_each_netdev_in_bond_rcu'
+ - 'for_each_netdev_rcu'
+ - 'for_each_netdev_reverse'
+ - 'for_each_netdev_safe'
+ - 'for_each_new_connector_in_state'
+ - 'for_each_new_crtc_in_state'
+ - 'for_each_new_mst_mgr_in_state'
+ - 'for_each_new_plane_in_state'
+ - 'for_each_new_plane_in_state_reverse'
+ - 'for_each_new_private_obj_in_state'
+ - 'for_each_new_reg'
+ - 'for_each_nhlt_endpoint'
+ - 'for_each_nhlt_endpoint_fmtcfg'
+ - 'for_each_nhlt_fmtcfg'
+ - 'for_each_node'
+ - 'for_each_node_by_name'
+ - 'for_each_node_by_type'
+ - 'for_each_node_mask'
+ - 'for_each_node_numadist'
+ - 'for_each_node_state'
+ - 'for_each_node_with_cpus'
+ - 'for_each_node_with_property'
+ - 'for_each_nonreserved_multicast_dest_pgid'
+ - 'for_each_numa_hop_mask'
+ - 'for_each_of_allnodes'
+ - 'for_each_of_allnodes_from'
+ - 'for_each_of_cpu_node'
+ - 'for_each_of_graph_port'
+ - 'for_each_of_graph_port_endpoint'
+ - 'for_each_of_pci_range'
+ - 'for_each_old_connector_in_state'
+ - 'for_each_old_crtc_in_state'
+ - 'for_each_old_mst_mgr_in_state'
+ - 'for_each_old_plane_in_state'
+ - 'for_each_old_private_obj_in_state'
+ - 'for_each_oldnew_connector_in_state'
+ - 'for_each_oldnew_crtc_in_state'
+ - 'for_each_oldnew_mst_mgr_in_state'
+ - 'for_each_oldnew_plane_in_state'
+ - 'for_each_oldnew_plane_in_state_reverse'
+ - 'for_each_oldnew_private_obj_in_state'
+ - 'for_each_online_cpu'
+ - 'for_each_online_cpu_wrap'
+ - 'for_each_online_node'
+ - 'for_each_online_pgdat'
+ - 'for_each_or_bit'
+ - 'for_each_page_ext'
+ - 'for_each_path'
+ - 'for_each_pci_bridge'
+ - 'for_each_pci_dev'
+ - 'for_each_pcm_streams'
+ - 'for_each_physmem_range'
+ - 'for_each_populated_zone'
+ - 'for_each_possible_cpu'
+ - 'for_each_possible_cpu_wrap'
+ - 'for_each_present_blessed_reg'
+ - 'for_each_present_cpu'
+ - 'for_each_present_section_nr'
+ - 'for_each_prime_number'
+ - 'for_each_prime_number_from'
+ - 'for_each_probe_cache_entry'
+ - 'for_each_process'
+ - 'for_each_process_thread'
+ - 'for_each_prop_codec_conf'
+ - 'for_each_prop_dai_codec'
+ - 'for_each_prop_dai_cpu'
+ - 'for_each_prop_dlc_codecs'
+ - 'for_each_prop_dlc_cpus'
+ - 'for_each_prop_dlc_platforms'
+ - 'for_each_property_of_node'
+ - 'for_each_pt_level_entry'
+ - 'for_each_rdt_resource'
+ - 'for_each_reg'
+ - 'for_each_reg_filtered'
+ - 'for_each_reloc'
+ - 'for_each_reloc_from'
+ - 'for_each_requested_gpio'
+ - 'for_each_requested_gpio_in_range'
+ - 'for_each_reserved_child_of_node'
+ - 'for_each_reserved_mem_range'
+ - 'for_each_reserved_mem_region'
+ - 'for_each_rtd_ch_maps'
+ - 'for_each_rtd_codec_dais'
+ - 'for_each_rtd_components'
+ - 'for_each_rtd_cpu_dais'
+ - 'for_each_rtd_dais'
+ - 'for_each_rtd_dais_reverse'
+ - 'for_each_sband_iftype_data'
+ - 'for_each_script'
+ - 'for_each_sec'
+ - 'for_each_set_bit'
+ - 'for_each_set_bit_from'
+ - 'for_each_set_bit_wrap'
+ - 'for_each_set_bitrange'
+ - 'for_each_set_bitrange_from'
+ - 'for_each_set_clump8'
+ - 'for_each_sg'
+ - 'for_each_sg_dma_page'
+ - 'for_each_sg_page'
+ - 'for_each_sgtable_dma_page'
+ - 'for_each_sgtable_dma_sg'
+ - 'for_each_sgtable_page'
+ - 'for_each_sgtable_sg'
+ - 'for_each_sibling_event'
+ - 'for_each_sta_active_link'
+ - 'for_each_subelement'
+ - 'for_each_subelement_extid'
+ - 'for_each_subelement_id'
+ - 'for_each_sublist'
+ - 'for_each_subsystem'
+ - 'for_each_suite'
+ - 'for_each_supported_activate_fn'
+ - 'for_each_supported_inject_fn'
+ - 'for_each_sym'
+ - 'for_each_thread'
+ - 'for_each_token'
+ - 'for_each_unicast_dest_pgid'
+ - 'for_each_valid_link'
+ - 'for_each_vif_active_link'
+ - 'for_each_vma'
+ - 'for_each_vma_range'
+ - 'for_each_vsi'
+ - 'for_each_wakeup_source'
+ - 'for_each_zone'
+ - 'for_each_zone_zonelist'
+ - 'for_each_zone_zonelist_nodemask'
+ - 'func_for_each_insn'
+ - 'fwnode_for_each_available_child_node'
+ - 'fwnode_for_each_child_node'
+ - 'fwnode_for_each_parent_node'
+ - 'fwnode_graph_for_each_endpoint'
+ - 'gadget_for_each_ep'
+ - 'genradix_for_each'
+ - 'genradix_for_each_from'
+ - 'genradix_for_each_reverse'
+ - 'guard'
+ - 'hash_for_each'
+ - 'hash_for_each_possible'
+ - 'hash_for_each_possible_rcu'
+ - 'hash_for_each_possible_rcu_notrace'
+ - 'hash_for_each_possible_safe'
+ - 'hash_for_each_rcu'
+ - 'hash_for_each_safe'
+ - 'hashmap__for_each_entry'
+ - 'hashmap__for_each_entry_safe'
+ - 'hashmap__for_each_key_entry'
+ - 'hashmap__for_each_key_entry_safe'
+ - 'hctx_for_each_ctx'
+ - 'hists__for_each_format'
+ - 'hists__for_each_sort_list'
+ - 'hlist_bl_for_each_entry'
+ - 'hlist_bl_for_each_entry_rcu'
+ - 'hlist_bl_for_each_entry_safe'
+ - 'hlist_for_each'
+ - 'hlist_for_each_entry'
+ - 'hlist_for_each_entry_continue'
+ - 'hlist_for_each_entry_continue_rcu'
+ - 'hlist_for_each_entry_continue_rcu_bh'
+ - 'hlist_for_each_entry_from'
+ - 'hlist_for_each_entry_from_rcu'
+ - 'hlist_for_each_entry_rcu'
+ - 'hlist_for_each_entry_rcu_bh'
+ - 'hlist_for_each_entry_rcu_notrace'
+ - 'hlist_for_each_entry_safe'
+ - 'hlist_for_each_entry_srcu'
+ - 'hlist_for_each_safe'
+ - 'hlist_nulls_for_each_entry'
+ - 'hlist_nulls_for_each_entry_from'
+ - 'hlist_nulls_for_each_entry_rcu'
+ - 'hlist_nulls_for_each_entry_safe'
+ - 'i3c_bus_for_each_i2cdev'
+ - 'i3c_bus_for_each_i3cdev'
+ - 'idr_for_each_entry'
+ - 'idr_for_each_entry_continue'
+ - 'idr_for_each_entry_continue_ul'
+ - 'idr_for_each_entry_ul'
+ - 'iio_for_each_active_channel'
+ - 'in_dev_for_each_ifa_rcu'
+ - 'in_dev_for_each_ifa_rtnl'
+ - 'in_dev_for_each_ifa_rtnl_net'
+ - 'inet_bind_bucket_for_each'
+ - 'interval_tree_for_each_span'
+ - 'intlist__for_each_entry'
+ - 'intlist__for_each_entry_safe'
+ - 'kcore_copy__for_each_phdr'
+ - 'key_for_each'
+ - 'key_for_each_safe'
+ - 'klp_for_each_func'
+ - 'klp_for_each_func_safe'
+ - 'klp_for_each_func_static'
+ - 'klp_for_each_object'
+ - 'klp_for_each_object_safe'
+ - 'klp_for_each_object_static'
+ - 'kunit_suite_for_each_test_case'
+ - 'kvm_for_each_memslot'
+ - 'kvm_for_each_memslot_in_gfn_range'
+ - 'kvm_for_each_vcpu'
+ - 'libbpf_nla_for_each_attr'
+ - 'list_for_each'
+ - 'list_for_each_codec'
+ - 'list_for_each_codec_safe'
+ - 'list_for_each_continue'
+ - 'list_for_each_entry'
+ - 'list_for_each_entry_continue'
+ - 'list_for_each_entry_continue_rcu'
+ - 'list_for_each_entry_continue_reverse'
+ - 'list_for_each_entry_from'
+ - 'list_for_each_entry_from_rcu'
+ - 'list_for_each_entry_from_reverse'
+ - 'list_for_each_entry_lockless'
+ - 'list_for_each_entry_rcu'
+ - 'list_for_each_entry_reverse'
+ - 'list_for_each_entry_safe'
+ - 'list_for_each_entry_safe_continue'
+ - 'list_for_each_entry_safe_from'
+ - 'list_for_each_entry_safe_reverse'
+ - 'list_for_each_entry_srcu'
+ - 'list_for_each_from'
+ - 'list_for_each_prev'
+ - 'list_for_each_prev_safe'
+ - 'list_for_each_rcu'
+ - 'list_for_each_safe'
+ - 'llist_for_each'
+ - 'llist_for_each_entry'
+ - 'llist_for_each_entry_safe'
+ - 'llist_for_each_safe'
+ - 'lwq_for_each_safe'
+ - 'map__for_each_symbol'
+ - 'map__for_each_symbol_by_name'
+ - 'mas_for_each'
+ - 'mas_for_each_rev'
+ - 'mci_for_each_dimm'
+ - 'media_device_for_each_entity'
+ - 'media_device_for_each_intf'
+ - 'media_device_for_each_link'
+ - 'media_device_for_each_pad'
+ - 'media_entity_for_each_pad'
+ - 'media_pipeline_for_each_entity'
+ - 'media_pipeline_for_each_pad'
+ - 'mlx5_lag_for_each_peer_mdev'
+ - 'mptcp_for_each_subflow'
+ - 'msi_domain_for_each_desc'
+ - 'msi_for_each_desc'
+ - 'mt_for_each'
+ - 'nanddev_io_for_each_block'
+ - 'nanddev_io_for_each_page'
+ - 'neigh_for_each_in_bucket'
+ - 'neigh_for_each_in_bucket_rcu'
+ - 'neigh_for_each_in_bucket_safe'
+ - 'netdev_for_each_lower_dev'
+ - 'netdev_for_each_lower_private'
+ - 'netdev_for_each_lower_private_rcu'
+ - 'netdev_for_each_mc_addr'
+ - 'netdev_for_each_synced_mc_addr'
+ - 'netdev_for_each_synced_uc_addr'
+ - 'netdev_for_each_uc_addr'
+ - 'netdev_for_each_upper_dev_rcu'
+ - 'netdev_hw_addr_list_for_each'
+ - 'nft_rule_for_each_expr'
+ - 'nla_for_each_attr'
+ - 'nla_for_each_attr_type'
+ - 'nla_for_each_nested'
+ - 'nla_for_each_nested_type'
+ - 'nlmsg_for_each_attr'
+ - 'nlmsg_for_each_msg'
+ - 'nr_neigh_for_each'
+ - 'nr_neigh_for_each_safe'
+ - 'nr_node_for_each'
+ - 'nr_node_for_each_safe'
+ - 'of_for_each_phandle'
+ - 'of_property_for_each_string'
+ - 'of_property_for_each_u32'
+ - 'pci_bus_for_each_resource'
+ - 'pci_dev_for_each_resource'
+ - 'pcl_for_each_chunk'
+ - 'pcl_for_each_segment'
+ - 'pcm_for_each_format'
+ - 'perf_config_items__for_each_entry'
+ - 'perf_config_sections__for_each_entry'
+ - 'perf_config_set__for_each_entry'
+ - 'perf_cpu_map__for_each_cpu'
+ - 'perf_cpu_map__for_each_cpu_skip_any'
+ - 'perf_cpu_map__for_each_idx'
+ - 'perf_evlist__for_each_entry'
+ - 'perf_evlist__for_each_entry_reverse'
+ - 'perf_evlist__for_each_entry_safe'
+ - 'perf_evlist__for_each_evsel'
+ - 'perf_evlist__for_each_mmap'
+ - 'perf_evsel_for_each_per_thread_period_safe'
+ - 'perf_hpp_list__for_each_format'
+ - 'perf_hpp_list__for_each_format_safe'
+ - 'perf_hpp_list__for_each_sort_list'
+ - 'perf_hpp_list__for_each_sort_list_safe'
+ - 'plist_for_each'
+ - 'plist_for_each_continue'
+ - 'plist_for_each_entry'
+ - 'plist_for_each_entry_continue'
+ - 'plist_for_each_entry_safe'
+ - 'plist_for_each_safe'
+ - 'pnp_for_each_card'
+ - 'pnp_for_each_dev'
+ - 'protocol_for_each_card'
+ - 'protocol_for_each_dev'
+ - 'queue_for_each_hw_ctx'
+ - 'radix_tree_for_each_slot'
+ - 'radix_tree_for_each_tagged'
+ - 'rb_for_each'
+ - 'rbtree_postorder_for_each_entry_safe'
+ - 'rdma_for_each_block'
+ - 'rdma_for_each_port'
+ - 'rdma_umem_for_each_dma_block'
+ - 'resource_list_for_each_entry'
+ - 'resource_list_for_each_entry_safe'
+ - 'rhl_for_each_entry_rcu'
+ - 'rhl_for_each_rcu'
+ - 'rht_for_each'
+ - 'rht_for_each_entry'
+ - 'rht_for_each_entry_from'
+ - 'rht_for_each_entry_rcu'
+ - 'rht_for_each_entry_rcu_from'
+ - 'rht_for_each_entry_safe'
+ - 'rht_for_each_from'
+ - 'rht_for_each_rcu'
+ - 'rht_for_each_rcu_from'
+ - 'rq_for_each_bvec'
+ - 'rq_for_each_segment'
+ - 'rq_list_for_each'
+ - 'rq_list_for_each_safe'
+ - 'sample_read_group__for_each'
+ - 'scoped_guard'
+ - 'scsi_for_each_prot_sg'
+ - 'scsi_for_each_sg'
+ - 'sctp_for_each_hentry'
+ - 'sctp_skb_for_each'
+ - 'sec_for_each_insn'
+ - 'sec_for_each_insn_continue'
+ - 'sec_for_each_insn_from'
+ - 'sec_for_each_sym'
+ - 'shdma_for_each_chan'
+ - 'shost_for_each_device'
+ - 'sk_for_each'
+ - 'sk_for_each_bound'
+ - 'sk_for_each_bound_safe'
+ - 'sk_for_each_entry_offset_rcu'
+ - 'sk_for_each_from'
+ - 'sk_for_each_rcu'
+ - 'sk_for_each_safe'
+ - 'sk_nulls_for_each'
+ - 'sk_nulls_for_each_from'
+ - 'sk_nulls_for_each_rcu'
+ - 'snd_array_for_each'
+ - 'snd_pcm_group_for_each_entry'
+ - 'snd_soc_dapm_widget_for_each_path'
+ - 'snd_soc_dapm_widget_for_each_path_safe'
+ - 'snd_soc_dapm_widget_for_each_sink_path'
+ - 'snd_soc_dapm_widget_for_each_source_path'
+ - 'sparsebit_for_each_set_range'
+ - 'strlist__for_each_entry'
+ - 'strlist__for_each_entry_safe'
+ - 'sym_for_each_insn'
+ - 'sym_for_each_insn_continue_reverse'
+ - 'symbols__for_each_entry'
+ - 'tb_property_for_each'
+ - 'tcf_act_for_each_action'
+ - 'tcf_exts_for_each_action'
+ - 'test_suite__for_each_test_case'
+ - 'tool_pmu__for_each_event'
+ - 'ttm_bo_lru_for_each_reserved_guarded'
+ - 'ttm_resource_manager_for_each_res'
+ - 'udp_lrpa_for_each_entry_rcu'
+ - 'udp_portaddr_for_each_entry'
+ - 'udp_portaddr_for_each_entry_rcu'
+ - 'usb_hub_for_each_child'
+ - 'v4l2_device_for_each_subdev'
+ - 'v4l2_m2m_for_each_dst_buf'
+ - 'v4l2_m2m_for_each_dst_buf_safe'
+ - 'v4l2_m2m_for_each_src_buf'
+ - 'v4l2_m2m_for_each_src_buf_safe'
+ - 'virtio_device_for_each_vq'
+ - 'vkms_config_for_each_connector'
+ - 'vkms_config_for_each_crtc'
+ - 'vkms_config_for_each_encoder'
+ - 'vkms_config_for_each_plane'
+ - 'vkms_config_connector_for_each_possible_encoder'
+ - 'vkms_config_encoder_for_each_possible_crtc'
+ - 'vkms_config_plane_for_each_possible_crtc'
+ - 'while_for_each_ftrace_op'
+ - 'workloads__for_each'
+ - 'xa_for_each'
+ - 'xa_for_each_marked'
+ - 'xa_for_each_range'
+ - 'xa_for_each_start'
+ - 'xas_for_each'
+ - 'xas_for_each_conflict'
+ - 'xas_for_each_marked'
+ - 'xbc_array_for_each_value'
+ - 'xbc_for_each_key_value'
+ - 'xbc_node_for_each_array_value'
+ - 'xbc_node_for_each_child'
+ - 'xbc_node_for_each_key_value'
+ - 'xbc_node_for_each_subkey'
+ - 'ynl_attr_for_each'
+ - 'ynl_attr_for_each_nested'
+ - 'ynl_attr_for_each_payload'
+ - 'zorro_for_each_dev'
+ - 'zpci_bus_for_each'
+
+IncludeBlocks: Preserve
+IncludeCategories:
+ - Regex: '.*'
+ Priority: 1
+IncludeIsMainRegex: '(Test)?$'
+IndentCaseLabels: false
+IndentGotoLabels: false
+IndentPPDirectives: None
+IndentWidth: 8
+IndentWrappedFunctionNames: false
+JavaScriptQuotes: Leave
+JavaScriptWrapImports: true
+KeepEmptyLinesAtTheStartOfBlocks: false
+MacroBlockBegin: ''
+MacroBlockEnd: ''
+MaxEmptyLinesToKeep: 1
+NamespaceIndentation: None
+ObjCBinPackProtocolList: Auto
+ObjCBlockIndentWidth: 8
+ObjCSpaceAfterProperty: true
+ObjCSpaceBeforeProtocolList: true
+
+# Taken from git's rules
+PenaltyBreakAssignment: 10
+PenaltyBreakBeforeFirstCallParameter: 30
+PenaltyBreakComment: 10
+PenaltyBreakFirstLessLess: 0
+PenaltyBreakString: 10
+PenaltyExcessCharacter: 100
+PenaltyReturnTypeOnItsOwnLine: 60
+
+PointerAlignment: Right
+ReflowComments: false
+SortIncludes: false
+SortUsingDeclarations: false
+SpaceAfterCStyleCast: false
+SpaceAfterTemplateKeyword: true
+SpaceBeforeAssignmentOperators: true
+SpaceBeforeCtorInitializerColon: true
+SpaceBeforeInheritanceColon: true
+SpaceBeforeParens: ControlStatementsExceptForEachMacros
+SpaceBeforeRangeBasedForLoopColon: true
+SpaceInEmptyParentheses: false
+SpacesBeforeTrailingComments: 1
+SpacesInAngles: false
+SpacesInContainerLiterals: false
+SpacesInCStyleCastParentheses: false
+SpacesInParentheses: false
+SpacesInSquareBrackets: false
+Standard: Cpp03
+TabWidth: 8
+UseTab: Always
+...
diff --git a/.clippy.toml b/.clippy.toml
new file mode 100644
index 000000000..b0a78cc8b
--- /dev/null
+++ b/.clippy.toml
@@ -0,0 +1,21 @@
+# SPDX-License-Identifier: GPL-2.0
+
+msrv = "1.85.0"
+
+check-private-items = true
+
+disallowed-macros = [
+ # The `clippy::dbg_macro` lint only works with `std::dbg!`, thus we simulate
+ # it here, see: https://github.com/rust-lang/rust-clippy/issues/11303.
+ { path = "kernel::dbg", reason = "the `dbg!` macro is intended as a debugging tool", allow-invalid = true },
+]
+
+[[disallowed-methods]]
+path = "core::ffi::CStr::as_ptr"
+replacement = "kernel::prelude::CStrExt::as_char_ptr"
+reason = "kernel's `char` is always unsigned, use `as_char_ptr` instead"
+
+[[disallowed-methods]]
+path = "core::ffi::CStr::from_ptr"
+replacement = "kernel::prelude::CStrExt::from_char_ptr"
+reason = "kernel's `char` is always unsigned, use `from_char_ptr` instead"
diff --git a/.cocciconfig b/.cocciconfig
new file mode 100644
index 000000000..43967c6b2
--- /dev/null
+++ b/.cocciconfig
@@ -0,0 +1,3 @@
+[spatch]
+ options = --timeout 200
+ options = --use-gitgrep
diff --git a/.editorconfig b/.editorconfig
new file mode 100644
index 000000000..69718ac91
--- /dev/null
+++ b/.editorconfig
@@ -0,0 +1,27 @@
+# SPDX-License-Identifier: GPL-2.0-only
+
+[{*.{awk,c,dts,dtsi,dtso,h,mk,rst,s,S},Kconfig,Makefile,Makefile.*}]
+charset = utf-8
+end_of_line = lf
+insert_final_newline = true
+indent_style = tab
+indent_size = 8
+
+[*.{json,py,rs}]
+charset = utf-8
+end_of_line = lf
+insert_final_newline = true
+indent_style = space
+indent_size = 4
+
+# this must be below the general *.py to overwrite it
+[tools/{perf,power,rcu,testing/kunit}/**.py,]
+indent_style = tab
+indent_size = 8
+
+[*.yaml]
+charset = utf-8
+end_of_line = lf
+insert_final_newline = true
+indent_style = space
+indent_size = 2
diff --git a/.get_maintainer.ignore b/.get_maintainer.ignore
new file mode 100644
index 000000000..5ad082b4d
--- /dev/null
+++ b/.get_maintainer.ignore
@@ -0,0 +1,9 @@
+Alan Cox <alan@lxorguk.ukuu.org.uk>
+Alan Cox <root@hraefn.swansea.linux.org.uk>
+Alyssa Rosenzweig <alyssa@rosenzweig.io>
+Askar Safin <safinaskar@gmail.com>
+Christoph Hellwig <hch@lst.de>
+Jeff Kirsher <jeffrey.t.kirsher@intel.com>
+Marc Gonzalez <marc.w.gonzalez@free.fr>
+Nathan Chancellor <nathan@kernel.org>
+Ralf Baechle <ralf@linux-mips.org>
diff --git a/.gitattributes b/.gitattributes
new file mode 100644
index 000000000..2325c529e
--- /dev/null
+++ b/.gitattributes
@@ -0,0 +1,5 @@
+# SPDX-License-Identifier: GPL-2.0-only
+*.[ch] diff=cpp
+*.dts diff=dts
+*.dts[io] diff=dts
+*.rs diff=rust
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 000000000..9875120ea
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,196 @@
+# SPDX-License-Identifier: GPL-2.0-only
+#
+# NOTE! Don't add files that are generated in specific
+# subdirectories here. Add them in the ".gitignore" file
+# in that subdirectory instead.
+#
+# NOTE! Please use 'git ls-files -i -c --exclude-per-directory=.gitignore'
+# command after changing this file, to see if there are
+# any tracked files which get ignored after the change.
+#
+# Normal rules (sorted alphabetically)
+#
+.*
+*.a
+*.asn1.[ch]
+*.bc
+*.bin
+*.bz2
+*.c.[012]*.*
+*.dt.yaml
+*.dtb
+*.dtbo
+*.dtb.S
+*.dtbo.S
+*.dwo
+*.dylib
+*.elf
+*.gcno
+*.gcda
+*.gz
+*.i
+*.ko
+*.lex.c
+*.ll
+*.lst
+*.lz4
+*.lzma
+*.lzo
+*.mod
+*.mod.c
+*.o
+*.o.*
+*.patch
+*.pyc
+*.rlib
+*.rmeta
+*.rpm
+*.rsi
+*.s
+*.so
+*.so.dbg
+*.spdx.json
+*.su
+*.symtypes
+*.tab.[ch]
+*.tar
+*.xz
+*.zst
+Module.symvers
+dtbs-list
+builtin.order
+modules.order
+
+#
+# Top-level generic files
+#
+/linux
+/modules-only.symvers
+/vmlinux
+/vmlinux.32
+/vmlinux.map
+/vmlinux.symvers
+/vmlinux.thinlto-index
+/vmlinux.unstripped
+/vmlinux-gdb.py
+/vmlinuz
+/System.map
+/Module.markers
+/modules.builtin
[Output truncated: showing 1000 of 44398434 lines]]
|
| 194/4 |
2026/09/17 11:07 |
llm |
codeexpert |
0m
Model:
Tokens:
input: 23776
output: 27
thoughts: 196
Thoughts: **Analyzing the NTFS Attribute Setting Process**
Okay, so this git repository is either brand new or a very shallow clone, basically just one commit. That means all the code I need is right here in the working tree β good to know. Now, letβs dig into these questions. The core of it all is about `ntfs_setattr` and whether `filemap_invalidate_lock(inode->i_mapping)` needs to be called *before* `truncate_setsize` and `ntfs_set_size`. And, if so, we need to know the correct sequence for file size extension or reduction.
Given the code is all available, my next step is clear: I'm going to search the kernel tree. I'll need to understand how `filemap_invalidate_lock` is being used within similar functions in other filesystems in the context of `setattr` and `truncate`. Let's get to the grep command; I'll search for `filemap_invalidate_lock` within the `fs/` directory. That should give me a solid view on patterns and best practices, and help me confidently answer those questions.
|
| 195/4 |
2026/09/17 11:07 |
tool |
grepper |
0m
Args: map[Expression:filemap_invalidate_lock PathPrefix:fs]
Results: map[Output:fs/btrfs/volumes.c=1335=struct btrfs_super_block *btrfs_read_disk_super(struct block_device *bdev,
--
fs/btrfs/volumes.c-1366-
fs/btrfs/volumes.c:1367: filemap_invalidate_lock_shared(mapping);
fs/btrfs/volumes.c-1368- page = read_cache_page_gfp(mapping, bytenr >> PAGE_SHIFT, GFP_NOFS);
--
fs/btrfs/zoned.c=88=static int sb_write_pointer(struct block_device *bdev, struct blk_zone *zones,
--
fs/btrfs/zoned.c-133-
fs/btrfs/zoned.c:134: filemap_invalidate_lock_shared(mapping);
fs/btrfs/zoned.c-135- page[i] = read_cache_page_gfp(mapping,
--
fs/ceph/addr.c=1990=static vm_fault_t ceph_filemap_fault(struct vm_fault *vmf)
--
fs/ceph/addr.c-2045-
fs/ceph/addr.c:2046: filemap_invalidate_lock_shared(mapping);
fs/ceph/addr.c-2047- page = find_or_create_page(mapping, 0,
--
fs/ceph/file.c=2784=static long ceph_fallocate(struct file *file, int mode,
--
fs/ceph/file.c-2841-
fs/ceph/file.c:2842: filemap_invalidate_lock(inode->i_mapping);
fs/ceph/file.c-2843- ceph_fscache_invalidate(inode, false);
--
fs/exfat/file.c=754=static int exfat_extend_valid_size(struct inode *inode, loff_t new_valid_size)
--
fs/exfat/file.c-779- */
fs/exfat/file.c:780: filemap_invalidate_lock(inode->i_mapping);
fs/exfat/file.c-781- if (gap_start < new_valid_size)
--
fs/exfat/file.c=943=static vm_fault_t exfat_page_mkwrite(struct vm_fault *vmf)
--
fs/exfat/file.c-987-
fs/exfat/file.c:988: filemap_invalidate_lock_shared(inode->i_mapping);
fs/exfat/file.c-989- ret = iomap_page_mkwrite(vmf, &exfat_iomap_ops, NULL);
--
fs/ext2/inode.c=1224=static void ext2_truncate_blocks(struct inode *inode, loff_t offset)
--
fs/ext2/inode.c-1231-
fs/ext2/inode.c:1232: filemap_invalidate_lock(inode->i_mapping);
fs/ext2/inode.c-1233- __ext2_truncate_blocks(inode, offset);
--
fs/ext2/inode.c=1237=static int ext2_setsize(struct inode *inode, loff_t newsize)
--
fs/ext2/inode.c-1254-
fs/ext2/inode.c:1255: filemap_invalidate_lock(inode->i_mapping);
fs/ext2/inode.c-1256- truncate_setsize(inode, newsize);
--
fs/ext4/extents.c=4949=long ext4_fallocate(struct file *file, int mode, loff_t offset, loff_t len)
--
fs/ext4/extents.c-4999- */
fs/ext4/extents.c:5000: filemap_invalidate_lock(mapping);
fs/ext4/extents.c-5001-
--
fs/ext4/file.c=800=static vm_fault_t ext4_dax_huge_fault(struct vm_fault *vmf, unsigned int order)
--
fs/ext4/file.c-827- file_update_time(vmf->vma->vm_file);
fs/ext4/file.c:828: filemap_invalidate_lock_shared(mapping);
fs/ext4/file.c-829-retry:
--
fs/ext4/file.c-837- } else {
fs/ext4/file.c:838: filemap_invalidate_lock_shared(mapping);
fs/ext4/file.c-839- }
--
fs/ext4/inode.c=4432=static void ext4_wait_dax_page(struct inode *inode)
--
fs/ext4/inode.c-4435- schedule();
fs/ext4/inode.c:4436: filemap_invalidate_lock(inode->i_mapping);
fs/ext4/inode.c-4437-}
--
fs/ext4/inode.c=6009=int ext4_setattr(struct mnt_idmap *idmap, struct dentry *dentry,
--
fs/ext4/inode.c-6125-
fs/ext4/inode.c:6126: filemap_invalidate_lock(inode->i_mapping);
fs/ext4/inode.c-6127-
--
fs/ext4/inode.c=6740=int ext4_change_inode_journal_flag(struct inode *inode, int val)
--
fs/ext4/inode.c-6773- */
fs/ext4/inode.c:6774: filemap_invalidate_lock(inode->i_mapping);
fs/ext4/inode.c-6775- err = filemap_write_and_wait(inode->i_mapping);
--
fs/ext4/inode.c=6884=vm_fault_t ext4_page_mkwrite(struct vm_fault *vmf)
--
fs/ext4/inode.c-6903-
fs/ext4/inode.c:6904: filemap_invalidate_lock_shared(mapping);
fs/ext4/inode.c-6905-
--
fs/ext4/ioctl.c=375=static long swap_inode_boot_loader(struct super_block *sb,
--
fs/ext4/ioctl.c-411-
fs/ext4/ioctl.c:412: filemap_invalidate_lock(inode->i_mapping);
fs/ext4/ioctl.c-413- err = filemap_write_and_wait(inode->i_mapping);
--
fs/ext4/truncate.h=12=static inline void ext4_truncate_failed_write(struct inode *inode)
--
fs/ext4/truncate.h-19- */
fs/ext4/truncate.h:20: filemap_invalidate_lock(mapping);
fs/ext4/truncate.h-21- truncate_inode_pages(mapping, inode->i_size);
--
fs/f2fs/data.c=3646=void f2fs_write_failed(struct inode *inode, loff_t to)
--
fs/f2fs/data.c-3655- f2fs_down_write(&F2FS_I(inode)->i_gc_rwsem[WRITE]);
fs/f2fs/data.c:3656: filemap_invalidate_lock(inode->i_mapping);
fs/f2fs/data.c-3657-
--
fs/f2fs/data.c=4187=static int f2fs_migrate_blocks(struct inode *inode, block_t start_blk,
--
fs/f2fs/data.c-4202- f2fs_down_write(&F2FS_I(inode)->i_gc_rwsem[WRITE]);
fs/f2fs/data.c:4203: filemap_invalidate_lock(inode->i_mapping);
fs/f2fs/data.c-4204-
--
fs/f2fs/file.c=73=static int f2fs_zero_post_eof_page(struct inode *inode,
--
fs/f2fs/file.c-86- if (lock)
fs/f2fs/file.c:87: filemap_invalidate_lock(inode->i_mapping);
fs/f2fs/file.c-88- /* zero or drop pages only in range of [old_size, new_size] */
--
fs/f2fs/file.c=120=static vm_fault_t f2fs_vm_page_mkwrite(struct vm_fault *vmf)
--
fs/f2fs/file.c-186- file_update_time(vmf->vma->vm_file);
fs/f2fs/file.c:187: filemap_invalidate_lock_shared(inode->i_mapping);
fs/f2fs/file.c-188-
--
fs/f2fs/file.c=637=static int finish_preallocate_blocks(struct inode *inode)
--
fs/f2fs/file.c-655- f2fs_down_write(&F2FS_I(inode)->i_gc_rwsem[WRITE]);
fs/f2fs/file.c:656: filemap_invalidate_lock(inode->i_mapping);
fs/f2fs/file.c-657-
--
fs/f2fs/file.c=1124=int f2fs_setattr(struct mnt_idmap *idmap, struct dentry *dentry,
--
fs/f2fs/file.c-1227- f2fs_down_write(&fi->i_gc_rwsem[WRITE]);
fs/f2fs/file.c:1228: filemap_invalidate_lock(inode->i_mapping);
fs/f2fs/file.c-1229-
--
fs/f2fs/file.c=1346=static int f2fs_punch_hole(struct inode *inode, loff_t offset, loff_t len)
--
fs/f2fs/file.c-1394- f2fs_down_write(&F2FS_I(inode)->i_gc_rwsem[WRITE]);
fs/f2fs/file.c:1395: filemap_invalidate_lock(inode->i_mapping);
fs/f2fs/file.c-1396-
--
fs/f2fs/file.c=1630=static int f2fs_do_collapse(struct inode *inode, loff_t offset, loff_t len)
--
fs/f2fs/file.c-1642- f2fs_down_write(&F2FS_I(inode)->i_gc_rwsem[WRITE]);
fs/f2fs/file.c:1643: filemap_invalidate_lock(inode->i_mapping);
fs/f2fs/file.c-1644-
--
fs/f2fs/file.c=1661=static int f2fs_collapse_range(struct inode *inode, loff_t offset, loff_t len)
--
fs/f2fs/file.c-1686- /* write out all moved pages, if possible */
fs/f2fs/file.c:1687: filemap_invalidate_lock(inode->i_mapping);
fs/f2fs/file.c-1688- ret = filemap_write_and_wait_range(inode->i_mapping, offset, LLONG_MAX);
--
fs/f2fs/file.c=1755=static int f2fs_zero_range(struct inode *inode, loff_t offset, loff_t len,
--
fs/f2fs/file.c-1811- f2fs_down_write(&F2FS_I(inode)->i_gc_rwsem[WRITE]);
fs/f2fs/file.c:1812: filemap_invalidate_lock(mapping);
fs/f2fs/file.c-1813-
--
fs/f2fs/file.c=1868=static int f2fs_insert_range(struct inode *inode, loff_t offset, loff_t len)
--
fs/f2fs/file.c-1893-
fs/f2fs/file.c:1894: filemap_invalidate_lock(mapping);
fs/f2fs/file.c-1895- ret = f2fs_truncate_blocks(inode, i_size_read(inode), true);
--
fs/f2fs/file.c-1911- f2fs_down_write(&F2FS_I(inode)->i_gc_rwsem[WRITE]);
fs/f2fs/file.c:1912: filemap_invalidate_lock(mapping);
fs/f2fs/file.c-1913-
--
fs/f2fs/file.c-1940- /* write out all moved pages, if possible */
fs/f2fs/file.c:1941: filemap_invalidate_lock(mapping);
fs/f2fs/file.c-1942- ret = filemap_write_and_wait_range(mapping, offset, LLONG_MAX);
--
fs/f2fs/file.c=3879=static int f2fs_ioc_release_dev_alias(struct file *filp)
--
fs/f2fs/file.c-3928-
fs/f2fs/file.c:3929: filemap_invalidate_lock(inode->i_mapping);
fs/f2fs/file.c-3930- truncate_setsize(inode, 0);
--
fs/f2fs/file.c=4206=static int f2fs_release_compress_blocks(struct file *filp, unsigned long arg)
--
fs/f2fs/file.c-4257- f2fs_down_write(&fi->i_gc_rwsem[WRITE]);
fs/f2fs/file.c:4258: filemap_invalidate_lock(inode->i_mapping);
fs/f2fs/file.c-4259-
--
fs/f2fs/file.c=4403=static int f2fs_reserve_compress_blocks(struct file *filp, unsigned long arg)
--
fs/f2fs/file.c-4435- f2fs_down_write(&fi->i_gc_rwsem[WRITE]);
fs/f2fs/file.c:4436: filemap_invalidate_lock(inode->i_mapping);
fs/f2fs/file.c-4437-
--
fs/f2fs/file.c=4535=static int f2fs_sec_trim_file(struct file *filp, unsigned long arg)
--
fs/f2fs/file.c-4600- f2fs_down_write(&F2FS_I(inode)->i_gc_rwsem[WRITE]);
fs/f2fs/file.c:4601: filemap_invalidate_lock(mapping);
fs/f2fs/file.c-4602-
--
fs/f2fs/file.c=4794=static int redirty_blocks(struct inode *inode, pgoff_t page_idx, int len)
--
fs/f2fs/file.c-4801-
fs/f2fs/file.c:4802: filemap_invalidate_lock_shared(mapping);
fs/f2fs/file.c-4803- page_cache_ra_unbounded(&ractl, len, 0);
--
fs/f2fs/file.c=5631=static ssize_t f2fs_file_write_iter(struct kiocb *iocb, struct iov_iter *from)
--
fs/f2fs/file.c-5703- f2fs_down_write(&F2FS_I(inode)->i_gc_rwsem[WRITE]);
fs/f2fs/file.c:5704: filemap_invalidate_lock(inode->i_mapping);
fs/f2fs/file.c-5705- if (!f2fs_truncate(inode))
--
fs/fuse/dax.c=663=static void fuse_wait_dax_page(struct inode *inode)
--
fs/fuse/dax.c-666- schedule();
fs/fuse/dax.c:667: filemap_invalidate_lock(inode->i_mapping);
fs/fuse/dax.c-668-}
--
fs/fuse/dax.c=755=static vm_fault_t __fuse_dax_fault(struct vm_fault *vmf, unsigned int order,
--
fs/fuse/dax.c-778- */
fs/fuse/dax.c:779: filemap_invalidate_lock_shared(inode->i_mapping);
fs/fuse/dax.c-780- ret = dax_iomap_fault(vmf, order, &pfn, &error, &fuse_iomap_ops);
--
fs/fuse/dax.c=914=inode_inline_reclaim_one_dmap(struct fuse_conn_dax *fcd, struct inode *inode,
--
fs/fuse/dax.c-923-
fs/fuse/dax.c:924: filemap_invalidate_lock(inode->i_mapping);
fs/fuse/dax.c-925-
--
fs/fuse/dax.c=1076=static int lookup_and_reclaim_dmap(struct fuse_conn_dax *fcd,
--
fs/fuse/dax.c-1085-
fs/fuse/dax.c:1086: filemap_invalidate_lock(inode->i_mapping);
fs/fuse/dax.c-1087- ret = fuse_dax_break_layouts(inode, dmap_start, dmap_end);
--
fs/fuse/dir.c=2145=int fuse_do_setattr(struct mnt_idmap *idmap, struct dentry *dentry,
--
fs/fuse/dir.c-2177- if (FUSE_IS_DAX(inode) && is_truncate) {
fs/fuse/dir.c:2178: filemap_invalidate_lock(mapping);
fs/fuse/dir.c-2179- fault_blocked = true;
--
fs/fuse/file.c=250=static int fuse_open(struct inode *inode, struct file *file)
--
fs/fuse/file.c-271- if (dax_truncate) {
fs/fuse/file.c:272: filemap_invalidate_lock(inode->i_mapping);
fs/fuse/file.c-273- err = fuse_dax_break_layouts(inode, 0, -1);
--
fs/fuse/file.c=2832=static long fuse_file_fallocate(struct file *file, int mode, loff_t offset,
--
fs/fuse/file.c-2859- if (block_faults) {
fs/fuse/file.c:2860: filemap_invalidate_lock(inode->i_mapping);
fs/fuse/file.c-2861- err = fuse_dax_break_layouts(inode, 0, -1);
--
fs/ntfs/file.c=254=static int ntfs_setattr_size(struct inode *vi, struct iattr *attr)
--
fs/ntfs/file.c-278- */
fs/ntfs/file.c:279: filemap_invalidate_lock(vi->i_mapping);
fs/ntfs/file.c-280- if (attr->ia_size > old_size) {
--
fs/ntfs/file.c=676=static vm_fault_t ntfs_filemap_page_mkwrite(struct vm_fault *vmf)
--
fs/ntfs/file.c-691- */
fs/ntfs/file.c:692: filemap_invalidate_lock_shared(mapping);
fs/ntfs/file.c-693- ret = iomap_page_mkwrite(vmf, &ntfs_page_mkwrite_iomap_ops, NULL);
--
fs/ntfs/file.c=1127=static long ntfs_fallocate(struct file *file, int mode, loff_t offset, loff_t len)
--
fs/ntfs/file.c-1170- /* Take invalidate_lock for all fallocate operations to prevent races */
fs/ntfs/file.c:1171: filemap_invalidate_lock(vi->i_mapping);
fs/ntfs/file.c-1172-
--
fs/ntfs3/file.c=466=static long ntfs_fallocate(struct file *file, int mode, loff_t vbo, loff_t len)
--
fs/ntfs3/file.c-519- inode_dio_wait(inode);
fs/ntfs3/file.c:520: filemap_invalidate_lock(mapping);
fs/ntfs3/file.c-521- map_locked = true;
--
fs/smb/client/file.c=993=static int cifs_do_truncate(const unsigned int xid, struct dentry *dentry)
--
fs/smb/client/file.c-1005-
fs/smb/client/file.c:1006: filemap_invalidate_lock(inode->i_mapping);
fs/smb/client/file.c-1007-
--
fs/smb/client/smb2ops.c=3508=static long smb3_zero_range(struct file *file, struct cifs_tcon *tcon,
--
fs/smb/client/smb2ops.c-3531-
fs/smb/client/smb2ops.c:3532: filemap_invalidate_lock(inode->i_mapping);
fs/smb/client/smb2ops.c-3533-
--
fs/smb/client/smb2ops.c=3592=static long smb3_punch_hole(struct file *file, struct cifs_tcon *tcon,
--
fs/smb/client/smb2ops.c-3610-
fs/smb/client/smb2ops.c:3611: filemap_invalidate_lock(inode->i_mapping);
fs/smb/client/smb2ops.c-3612- /*
--
fs/smb/client/smb2ops.c=4014=static long smb3_collapse_range(struct file *file, struct cifs_tcon *tcon,
--
fs/smb/client/smb2ops.c-4032-
fs/smb/client/smb2ops.c:4033: filemap_invalidate_lock(inode->i_mapping);
fs/smb/client/smb2ops.c-4034- rc = filemap_write_and_wait_range(inode->i_mapping,
--
fs/smb/client/smb2ops.c=4078=static long smb3_insert_range(struct file *file, struct cifs_tcon *tcon,
--
fs/smb/client/smb2ops.c-4108-
fs/smb/client/smb2ops.c:4109: filemap_invalidate_lock(inode->i_mapping);
fs/smb/client/smb2ops.c-4110- rc = filemap_write_and_wait_range(inode->i_mapping,
--
fs/udf/file.c=38=static vm_fault_t udf_page_mkwrite(struct vm_fault *vmf)
--
fs/udf/file.c-50- file_update_time(vma->vm_file);
fs/udf/file.c:51: filemap_invalidate_lock_shared(mapping);
fs/udf/file.c-52- folio_lock(folio);
--
fs/udf/file.c=89=static ssize_t udf_file_write_iter(struct kiocb *iocb, struct iov_iter *from)
--
fs/udf/file.c-104- iocb->ki_pos + iov_iter_count(from))) {
fs/udf/file.c:105: filemap_invalidate_lock(inode->i_mapping);
fs/udf/file.c-106- retval = udf_expand_file_adinicb(inode);
--
fs/udf/file.c=215=static int udf_setattr(struct mnt_idmap *idmap, struct dentry *dentry,
--
fs/udf/file.c-236- attr->ia_size != i_size_read(inode)) {
fs/udf/file.c:237: filemap_invalidate_lock(inode->i_mapping);
fs/udf/file.c-238- error = udf_setsize(inode, attr->ia_size);
--
fs/verity/read_metadata.c=16=static int fsverity_read_merkle_tree(struct inode *inode,
--
fs/verity/read_metadata.c-38- if (inode->i_sb->s_vop->readahead_merkle_tree) {
fs/verity/read_metadata.c:39: filemap_invalidate_lock_shared(inode->i_mapping);
fs/verity/read_metadata.c-40- inode->i_sb->s_vop->readahead_merkle_tree(
--
fs/xfs/xfs_bmap_util.c=1537=xfs_swap_extents(
--
fs/xfs/xfs_bmap_util.c-1558- lock_two_nondirectories(VFS_I(ip), VFS_I(tip));
fs/xfs/xfs_bmap_util.c:1559: filemap_invalidate_lock_two(VFS_I(ip)->i_mapping,
fs/xfs/xfs_bmap_util.c-1560- VFS_I(tip)->i_mapping);
--
fs/xfs/xfs_inode.c=2792=xfs_ilock2_io_mmap(
--
fs/xfs/xfs_inode.c-2810- } else
fs/xfs/xfs_inode.c:2811: filemap_invalidate_lock_two(VFS_I(ip1)->i_mapping,
fs/xfs/xfs_inode.c-2812- VFS_I(ip2)->i_mapping);
--
fs/xfs/xfs_iomap.c=2134=xfs_buffered_write_iomap_end(
--
fs/xfs/xfs_iomap.c-2167- } else {
fs/xfs/xfs_iomap.c:2168: filemap_invalidate_lock(inode->i_mapping);
fs/xfs/xfs_iomap.c-2169- iomap_write_delalloc_release(inode, start_byte, end_byte, flags,
--
fs/zonefs/file.c=203=int zonefs_file_truncate(struct inode *inode, loff_t isize)
--
fs/zonefs/file.c-228- /* Serialize against page faults */
fs/zonefs/file.c:229: filemap_invalidate_lock(inode->i_mapping);
fs/zonefs/file.c-230-
--
fs/zonefs/file.c=297=static vm_fault_t zonefs_filemap_page_mkwrite(struct vm_fault *vmf)
--
fs/zonefs/file.c-315- /* Serialize against truncates */
fs/zonefs/file.c:316: filemap_invalidate_lock_shared(inode->i_mapping);
fs/zonefs/file.c-317- ret = iomap_page_mkwrite(vmf, &zonefs_write_iomap_ops, NULL);
]
|
| 196/4 |
2026/09/17 11:08 |
llm |
codeexpert |
0m
Model:
Tokens:
input: 31561
output: 36
thoughts: 104
Thoughts: **Diving Deep into the NTFS Implementation**
Okay, here we go. My initial thought is to compare the older NTFS implementation, `fs/ntfs/file.c`, with the newer `fs/ntfs3/file.c`. I have a feeling there are some interesting architectural changes, or perhaps optimizations, that need to be understood.
Wait a second, before I get carried away with the broad strokes, I want to zero in on a specific section. Let's start by examining lines 254 through 290 of `fs/ntfs/file.c` and how it is implemented in the newer `fs/ntfs3/file.c`. Then compare how it's implemented.
Actually, to get a better understanding of that functionality, let's take a look at a slightly larger section, lines 250 through 295 of `fs/ntfs/file.c` instead. This should give me enough context. I need to understand this functionality fully before proceeding.
|
| 197/4 |
2026/09/17 11:08 |
tool |
read-file |
0m
Args: map[File:fs/ntfs/file.c FirstLine:250 LineCount:45]
Results: map[Contents: 250: blkdev_issue_flush(vi->i_sb->s_bdev);
251: return ret;
252: }
253:
254: static int ntfs_setattr_size(struct inode *vi, struct iattr *attr)
255: {
256: struct ntfs_inode *ni = NTFS_I(vi);
257: int err;
258: loff_t old_size = vi->i_size;
259:
260: if (NInoCompressed(ni) || NInoEncrypted(ni) || NInoWofCompressed(ni)) {
261: ntfs_warning(
262: vi->i_sb,
263: "Changes in inode size are not supported yet for %s files.",
264: NInoEncrypted(ni) ? "encrypted" : "compressed");
265: return -EOPNOTSUPP;
266: }
267:
268: err = inode_newsize_ok(vi, attr->ia_size);
269: if (err)
270: return err;
271:
272: inode_dio_wait(vi);
273:
274: /*
275: * Serialize with page faults and pagecache instantiation so that
276: * readers cannot observe the size change until the attribute
277: * updates below have completed.
278: */
279: filemap_invalidate_lock(vi->i_mapping);
280: if (attr->ia_size > old_size) {
281: truncate_pagecache(vi, old_size);
282: i_size_write(vi, attr->ia_size);
283: pagecache_isize_extended(vi, old_size, attr->ia_size);
284: } else {
285: truncate_setsize(vi, attr->ia_size);
286: }
287:
288: err = ntfs_truncate_vfs(vi, attr->ia_size, old_size);
289: if (err)
290: i_size_write(vi, old_size);
291: filemap_invalidate_unlock(vi->i_mapping);
292:
293: return err;
294: }
]
|
| 198/4 |
2026/09/17 11:08 |
llm |
codeexpert |
0m
Model:
Tokens:
input: 32602
output: 37
thoughts: 568
Thoughts: **Analyzing NTFS Truncation and Attribute Setting**
Okay, here's what's running through my mind. This question about `ntfs_setattr` and the call order of `filemap_invalidate_lock`, `truncate_setsize`, and `ntfs_set_size` is intriguing. The critical question: when setting file attributes, is `filemap_invalidate_lock` necessary before adjusting the file size?
First, I need to understand the existing implementation to make a good determination. I started by looking at `fs/ntfs/file.c` to see how it handles truncation because that's what the question references. Ah, yes, it calls `ntfs_truncate_vfs`, good to know. Now, let's turn to `fs/ntfs3/file.c` which, I assume, is a newer implementation.
Bingo! The question specifically mentions `ntfs_set_size` along with `truncate_setsize`. Let's examine `fs/ntfs3/file.c`'s implementation of `ntfs_setattr`. Examining the code reveals this snippet:
```c
if (ia_valid & ATTR_SIZE) {
loff_t newsize, oldsize;
if (WARN_ON(ni->ni_flags & NI_FLAG_COMPRESSED_MASK)) {
/* Should never be here, see ntfs_file_open(). */
err = -EOPNOTSUPP;
goto out;
}
inode_dio_wait(inode);
oldsize = i_size_read(inode);
newsize = attr->ia_size;
if (newsize != oldsize) {
truncate_setsize(inode, newsize);
err = ntfs_set_size(inode, newsize);
if (err) {
i_size_write(inode, oldsize);
goto out;
}
ni->std_fa |= FILE_ATTRIBUTE_ARCHIVE;
ni->ni_flags |= NI_FLAG_UPDATE_PARENT;
inode_set_mtime_to_ts(inode,
inode_set_ctime_current(inode));
}
}
```
Wait a minute, where's the call to `filemap_invalidate_lock`? That's the core of the question! It looks like `ntfs3` doesn't include it. This is a potential red flag, or perhaps an optimization. I need to understand the rationale here.
Okay, time to widen the scope. I'll need to check how other filesystems handle this, and see if there are common patterns or explanations for the placement of `filemap_invalidate_lock`. Let's look at `fs/ext4/inode.c`, the `ext4_setattr` function. A comparative analysis should reveal more about the correct approach.
|
| 199/4 |
2026/09/17 11:08 |
tool |
read-file |
0m
Args: map[File:fs/ext4/inode.c FirstLine:6120 LineCount:40]
Results: map[Contents:6120: * Blocks are going to be removed from the inode. Wait
6121: * for dio in flight.
6122: */
6123: inode_dio_wait(inode);
6124: }
6125:
6126: filemap_invalidate_lock(inode->i_mapping);
6127:
6128: rc = ext4_break_layouts(inode);
6129: if (rc) {
6130: filemap_invalidate_unlock(inode->i_mapping);
6131: goto err_out;
6132: }
6133:
6134: if (attr->ia_size != inode->i_size) {
6135: /* attach jbd2 jinode for EOF folio tail zeroing */
6136: if (attr->ia_size & (inode->i_sb->s_blocksize - 1) ||
6137: oldsize & (inode->i_sb->s_blocksize - 1)) {
6138: error = ext4_inode_attach_jinode(inode);
6139: if (error)
6140: goto out_mmap_sem;
6141: }
6142:
6143: /*
6144: * Update c/mtime and tail zero the EOF folio on
6145: * truncate up. ext4_truncate() handles the shrink case
6146: * below.
6147: */
6148: if (!shrink) {
6149: inode_set_mtime_to_ts(inode,
6150: inode_set_ctime_current(inode));
6151: if (oldsize & (inode->i_sb->s_blocksize - 1)) {
6152: error = ext4_block_zero_eof(inode,
6153: oldsize, LLONG_MAX);
6154: if (error)
6155: goto out_mmap_sem;
6156: }
6157: }
6158:
6159: handle = ext4_journal_start(inode, EXT4_HT_INODE, 3);
]
|
| 200/4 |
2026/09/17 11:08 |
llm |
codeexpert |
0m
Model:
Tokens:
input: 34453
output: 37
thoughts: 15
Thoughts: Okay, here's my interpretation of those thoughts, crafted with the understanding that I'm speaking to a fellow expert:
**Diving Deeper into ext4_setattr**
Right, so we're focusing on `ext4_setattr`, and naturally, my mind immediately jumps to the surrounding context. It's like, "Where *else* in the code can we see this being implemented or referenced?" I want to trace the implications of that function call, understand its place in the broader file system design. "Let's also see further down in `ext4_setattr`." This means that I'm planning to scan the code, looking at the implementations of this functions, and how they relate to related objects. I know `ext4_setattr` is a key component, but I need to fully understand all of its interactions. This goes beyond a surface-level understanding; I'm trying to map the relationships between `ext4_setattr` and its surrounding components.
|
| 201/4 |
2026/09/17 11:09 |
tool |
read-file |
0m
Args: map[File:fs/ext4/inode.c FirstLine:6160 LineCount:50]
Results: map[Contents:6160: if (IS_ERR(handle)) {
6161: error = PTR_ERR(handle);
6162: goto out_mmap_sem;
6163: }
6164: if (ext4_handle_valid(handle) && shrink) {
6165: error = ext4_orphan_add(handle, inode);
6166: orphan = 1;
6167: }
6168:
6169: if (shrink)
6170: ext4_fc_track_range(handle, inode,
6171: (attr->ia_size > 0 ? attr->ia_size - 1 : 0) >>
6172: inode->i_sb->s_blocksize_bits,
6173: EXT_MAX_BLOCKS - 1);
6174: else
6175: ext4_fc_track_range(
6176: handle, inode,
6177: (oldsize > 0 ? oldsize - 1 : oldsize) >>
6178: inode->i_sb->s_blocksize_bits,
6179: (attr->ia_size > 0 ? attr->ia_size - 1 : 0) >>
6180: inode->i_sb->s_blocksize_bits);
6181:
6182: down_write(&EXT4_I(inode)->i_data_sem);
6183: old_disksize = EXT4_I(inode)->i_disksize;
6184: EXT4_I(inode)->i_disksize = attr->ia_size;
6185:
6186: /*
6187: * We have to update i_size under i_data_sem together
6188: * with i_disksize to avoid races with writeback code
6189: * running ext4_wb_update_i_disksize().
6190: */
6191: if (!error)
6192: i_size_write(inode, attr->ia_size);
6193: else
6194: EXT4_I(inode)->i_disksize = old_disksize;
6195: up_write(&EXT4_I(inode)->i_data_sem);
6196: rc = ext4_mark_inode_dirty(handle, inode);
6197: if (!error)
6198: error = rc;
6199: ext4_journal_stop(handle);
6200: if (error)
6201: goto out_mmap_sem;
6202: if (!shrink) {
6203: pagecache_isize_extended(inode, oldsize,
6204: inode->i_size);
6205: } else if (ext4_should_journal_data(inode)) {
6206: ext4_wait_for_tail_page_commit(inode);
6207: }
6208: }
6209:
]
|
| 202/4 |
2026/09/17 11:09 |
llm |
codeexpert |
0m
Model:
Tokens:
input: 35531
output: 37
thoughts: 26
Thoughts: Okay, here's my summary, taking on the persona you requested:
**Ext4 Shrink Investigation: Delving into `ext4_setattr`**
Alright, time to get to work. I need to understand what's happening with shrinking in ext4. First, let me navigate to `ext4_setattr` and see what that function does. It seems like it's the place to start digging for details. I need to see if the shrinking logic is called inside the function `ext4_setattr`.
|
| 203/4 |
2026/09/17 11:09 |
tool |
read-file |
0m
Args: map[File:fs/ext4/inode.c FirstLine:6210 LineCount:40]
Results: map[Contents:6210: /*
6211: * Truncate pagecache after we've waited for commit
6212: * in data=journal mode to make pages freeable.
6213: */
6214: truncate_pagecache(inode, inode->i_size);
6215: /*
6216: * Call ext4_truncate() even if i_size didn't change to
6217: * truncate possible preallocated blocks.
6218: */
6219: if (attr->ia_size <= oldsize) {
6220: rc = ext4_truncate(inode);
6221: if (rc)
6222: error = rc;
6223: }
6224: out_mmap_sem:
6225: filemap_invalidate_unlock(inode->i_mapping);
6226: }
6227:
6228: if (!error) {
6229: if (inc_ivers)
6230: inode_inc_iversion(inode);
6231: setattr_copy(idmap, inode, attr);
6232: mark_inode_dirty(inode);
6233: }
6234:
6235: /*
6236: * If the call to ext4_truncate failed to get a transaction handle at
6237: * all, we need to clean up the in-core orphan list manually.
6238: */
6239: if (orphan && inode->i_nlink)
6240: ext4_orphan_del(NULL, inode);
6241:
6242: if (!error && (ia_valid & ATTR_MODE))
6243: rc = posix_acl_chmod(idmap, dentry, inode->i_mode);
6244:
6245: err_out:
6246: if (error)
6247: ext4_std_error(inode->i_sb, error);
6248: if (!error)
6249: error = rc;
]
|
| 204/4 |
2026/09/17 11:09 |
llm |
codeexpert |
0m
Model:
Tokens:
input: 36280
output: 37
thoughts: 41
Thoughts: Here's my thinking process:
**Diving Deeper into `truncate_setsize`**
Okay, before I proceed further, I need to make absolutely sure I have a solid understanding of how `truncate_setsize` functions. Let's not just assume I remember it correctly. I'll take a quick scan for implementations and related comments in *other* filesystems, to broaden my context and see if there are any subtle nuances or caveats I'm missing. The goal is to solidify the definition and clarify any potential gotchas. I need to refresh the definition and any accompanying documentation regarding `truncate_setsize`.
|
| 205/4 |
2026/09/17 11:09 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:fs/ntfs3/file.c Name:truncate_setsize]
Results: map[SourceCode: 803: /**
804: * truncate_setsize - update inode and pagecache for a new file size
805: * @inode: inode
806: * @newsize: new file size
807: *
808: * truncate_setsize updates i_size and performs pagecache truncation (if
809: * necessary) to @newsize. It will be typically be called from the filesystem's
810: * setattr function when ATTR_SIZE is passed in.
811: *
812: * Must be called with a lock serializing truncates and writes (generally
813: * i_rwsem but e.g. xfs uses a different lock) and before all filesystem
814: * specific block truncation has been performed.
815: */
816: void truncate_setsize(struct inode *inode, loff_t newsize)
817: {
818: loff_t oldsize = inode->i_size;
819:
820: i_size_write(inode, newsize);
821: if (newsize > oldsize)
822: pagecache_isize_extended(inode, oldsize, newsize);
823: truncate_pagecache(inode, newsize);
824: }
SourceFile:mm/truncate.c]
|
| 206/4 |
2026/09/17 11:09 |
llm |
codeexpert |
0m
Model:
Tokens:
input: 36872
output: 39
thoughts: 111
Thoughts: **Analyzing Filesystem Truncation in NTFS3**
Okay, so I'm looking at this `truncate_setsize` function, and the comment is pretty specific. It's reminding me that this needs to be called with a lock that serializes both truncates *and* writes. It even throws in that little note about different filesystems potentially using different locks β like XFS, for example. Good to keep that in mind. But now, my mind's wandering and I'm wondering about the NTFS3 implementation. Specifically, what's `ntfs_set_size` doing over there in `fs/ntfs3`? I need to check the `ntfs_set_size` definition in `fs/ntfs3/inode.c`. That's where I should find the answer to my question.
|
| 207/4 |
2026/09/17 11:10 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:fs/ntfs3/inode.c Name:ntfs_set_size]
Results: map[SourceCode: 883: int ntfs_set_size(struct inode *inode, u64 new_size)
884: {
885: struct super_block *sb = inode->i_sb;
886: struct ntfs_sb_info *sbi = sb->s_fs_info;
887: struct ntfs_inode *ni = ntfs_i(inode);
888: int err;
889:
890: /* Check for maximum file size. */
891: if (is_sparsed(ni) || is_compressed(ni)) {
892: if (new_size > sbi->maxbytes_sparse) {
893: return -EFBIG;
894: }
895: } else if (new_size > sbi->maxbytes) {
896: return -EFBIG;
897: }
898:
899: /* Mark rw ntfs as dirty. It will be cleared at umount. */
900: ntfs_set_state(sbi, NTFS_DIRTY_DIRTY);
901:
902: ni_lock(ni);
903: down_write(&ni->file.run_lock);
904: if (new_size < ni->i_valid)
905: ni->i_valid = new_size;
906:
907: /* last 'true' means keep preallocated. */
908: err = attr_set_size(ni, ATTR_DATA, ni->file.ads.name, ni->file.ads.len,
909: &ni->file.run, new_size, &ni->i_valid, true);
910:
911: up_write(&ni->file.run_lock);
912: ni_unlock(ni);
913:
914: return err;
915: }
SourceFile:fs/ntfs3/inode.c]
|
| 208/4 |
2026/09/17 11:10 |
llm |
codeexpert |
0m
Model:
Tokens:
input: 37758
output: 25
thoughts: 495
Thoughts: **Analyzing File Size Modification in NTFS**
Okay, so I'm diving into this `ntfs_setattr` question, specifically the interplay between `filemap_invalidate_lock`, `truncate_setsize`, and `ntfs_set_size`. The core of the issue seems to be the order and potential race conditions when modifying a file's size, both extending and shrinking it.
My first thought is to understand the core functions involved. `ntfs_set_size` is the key function that calls `attr_set_size`, which, crucially, performs the actual on-disk block allocation or truncation, this happens by calling `truncate_setsize` which call `i_size_write` and also deals with the page cache. So, it looks like `ntfs_set_size` is responsible for the actual *physical* on-disk changes, while `truncate_setsize` handles the *logical* inode size update and page cache management.
The initial question is whether `filemap_invalidate_lock` is needed and, if so, the correct order of these calls when *extending* or *shrinking* the file. The key here is to think about the consequences of each operation.
If we extend the file, and `ntfs_set_size` fails (say, due to -ENOSPC), what if `truncate_setsize` was called first? That's the critical piece. The `inode->i_size` might be updated, and pages could be faulted in or zeroed prematurely, which is a major concern.
Therefore, I need to check how these operations are handled in other filesystems, to get a broader view of common practices, I'll need to check how `truncate_setsize` is implemented in, for example, ext4, xfs, btrfs, f2fs, zonefs, udf, ocfs2, and others. I need to grep for `truncate_setsize` across `fs/` to figure out best practices. The goal is to identify common patterns, particularly in the order of operations and the safeguards employed. The best way to understand this is a direct comparison across the main file systems.
|
| 209/4 |
2026/09/17 11:10 |
tool |
grepper |
0m
Args: map[Expression:truncate_setsize PathPrefix:fs]
Results: map[Output:fs/9p/vfs_inode.c=1017=static int v9fs_vfs_setattr(struct mnt_idmap *idmap,
--
fs/9p/vfs_inode.c-1081- iattr->ia_size != i_size_read(inode)) {
fs/9p/vfs_inode.c:1082: truncate_setsize(inode, iattr->ia_size);
fs/9p/vfs_inode.c-1083- netfs_resize_file(netfs_inode(inode), iattr->ia_size, true);
--
fs/9p/vfs_inode_dotl.c=511=int v9fs_vfs_setattr_dotl(struct mnt_idmap *idmap,
--
fs/9p/vfs_inode_dotl.c-576- i_size_read(inode)) {
fs/9p/vfs_inode_dotl.c:577: truncate_setsize(inode, iattr->ia_size);
fs/9p/vfs_inode_dotl.c-578- netfs_resize_file(netfs_inode(inode), iattr->ia_size, true);
--
fs/adfs/inode.c=302=adfs_setattr(struct mnt_idmap *idmap, struct dentry *dentry, struct iattr *attr)
--
fs/adfs/inode.c-323- if (ia_valid & ATTR_SIZE)
fs/adfs/inode.c:324: truncate_setsize(inode, attr->ia_size);
fs/adfs/inode.c-325-
--
fs/affs/inode.c=216=affs_setattr(struct mnt_idmap *idmap, struct dentry *dentry, struct iattr *attr)
--
fs/affs/inode.c-244-
fs/affs/inode.c:245: truncate_setsize(inode, attr->ia_size);
fs/affs/inode.c-246- affs_truncate(inode);
--
fs/afs/inode.c=762=int afs_setattr(struct mnt_idmap *idmap, struct dentry *dentry,
--
fs/afs/inode.c-816- attr->ia_size > netfs_read_remote_i_size(inode)) {
fs/afs/inode.c:817: truncate_setsize(inode, attr->ia_size);
fs/afs/inode.c-818- netfs_resize_file(&vnode->netfs, size, false);
--
fs/aio.c=360=static void put_aio_ring_file(struct kioctx *ctx)
--
fs/aio.c-366-
fs/aio.c:367: truncate_setsize(inode, 0);
fs/aio.c-368-
--
fs/btrfs/file.c=1526=int btrfs_sync_file(struct file *file, loff_t start, loff_t end, int datasync)
--
fs/btrfs/file.c-1809- * protect against truncate races as the page could now be beyond EOF. Because
fs/btrfs/file.c:1810: * truncate_setsize() writes the inode size before removing pages, once we have
fs/btrfs/file.c-1811- * the page lock we can determine safely if the page is beyond EOF. If it is not
--
fs/btrfs/inode.c=5391=static int btrfs_setsize(struct inode *inode, struct iattr *attr)
--
fs/btrfs/inode.c-5460-
fs/btrfs/inode.c:5461: truncate_setsize(inode, newsize);
fs/btrfs/inode.c-5462-
--
fs/ecryptfs/inode.c=733=static int __ecryptfs_truncate(struct dentry *dentry, const struct iattr *ia)
--
fs/ecryptfs/inode.c-784- if (!(crypt_stat->flags & ECRYPTFS_ENCRYPTED)) {
fs/ecryptfs/inode.c:785: truncate_setsize(inode, ia->ia_size);
fs/ecryptfs/inode.c-786- lower_ia.ia_size = ia->ia_size;
--
fs/ecryptfs/inode.c-804- }
fs/ecryptfs/inode.c:805: truncate_setsize(inode, ia->ia_size);
fs/ecryptfs/inode.c-806- rc = ecryptfs_write_inode_size_to_metadata(inode);
--
fs/exfat/file.c=350=int exfat_setattr(struct mnt_idmap *idmap, struct dentry *dentry,
--
fs/exfat/file.c-415- inode_dio_wait(inode);
fs/exfat/file.c:416: truncate_setsize(inode, attr->ia_size);
fs/exfat/file.c-417-
--
fs/exfat/file.c=754=static int exfat_extend_valid_size(struct inode *inode, loff_t new_valid_size)
--
fs/exfat/file.c-786- if (ret) {
fs/exfat/file.c:787: truncate_setsize(inode, old_valid_size);
fs/exfat/file.c-788- exfat_truncate(inode);
--
fs/ext2/inode.c=1237=static int ext2_setsize(struct inode *inode, loff_t newsize)
--
fs/ext2/inode.c-1255- filemap_invalidate_lock(inode->i_mapping);
fs/ext2/inode.c:1256: truncate_setsize(inode, newsize);
fs/ext2/inode.c-1257- __ext2_truncate_blocks(inode, newsize);
--
fs/f2fs/file.c=637=static int finish_preallocate_blocks(struct inode *inode)
--
fs/f2fs/file.c-657-
fs/f2fs/file.c:658: truncate_setsize(inode, i_size_read(inode));
fs/f2fs/file.c-659- ret = f2fs_truncate(inode);
--
fs/f2fs/file.c=1124=int f2fs_setattr(struct mnt_idmap *idmap, struct dentry *dentry,
--
fs/f2fs/file.c-1235- }
fs/f2fs/file.c:1236: truncate_setsize(inode, attr->ia_size);
fs/f2fs/file.c-1237-
--
fs/f2fs/file.c=3879=static int f2fs_ioc_release_dev_alias(struct file *filp)
--
fs/f2fs/file.c-3929- filemap_invalidate_lock(inode->i_mapping);
fs/f2fs/file.c:3930: truncate_setsize(inode, 0);
fs/f2fs/file.c-3931-
--
fs/fat/file.c=517=int fat_setattr(struct mnt_idmap *idmap, struct dentry *dentry,
--
fs/fat/file.c-586- down_write(&MSDOS_I(inode)->truncate_lock);
fs/fat/file.c:587: truncate_setsize(inode, attr->ia_size);
fs/fat/file.c-588- fat_truncate_blocks(inode, attr->ia_size);
--
fs/gfs2/bmap.c=2095=static int do_grow(struct inode *inode, u64 size)
--
fs/gfs2/bmap.c-2138-
fs/gfs2/bmap.c:2139: truncate_setsize(inode, size);
fs/gfs2/bmap.c-2140- inode_set_mtime_to_ts(&ip->i_inode, inode_set_ctime_current(&ip->i_inode));
--
fs/hfs/inode.c=646=int hfs_inode_setattr(struct mnt_idmap *idmap, struct dentry *dentry,
--
fs/hfs/inode.c-686-
fs/hfs/inode.c:687: truncate_setsize(inode, attr->ia_size);
fs/hfs/inode.c-688- hfs_file_truncate(inode);
--
fs/hfsplus/inode.c=308=static int hfsplus_setattr(struct mnt_idmap *idmap,
--
fs/hfsplus/inode.c-326- }
fs/hfsplus/inode.c:327: truncate_setsize(inode, attr->ia_size);
fs/hfsplus/inode.c-328- hfsplus_file_truncate(inode);
--
fs/hostfs/hostfs_kern.c=804=static int hostfs_setattr(struct mnt_idmap *idmap,
--
fs/hostfs/hostfs_kern.c-868- attr->ia_size != i_size_read(inode))
fs/hostfs/hostfs_kern.c:869: truncate_setsize(inode, attr->ia_size);
fs/hostfs/hostfs_kern.c-870-
--
fs/hpfs/inode.c=260=int hpfs_setattr(struct mnt_idmap *idmap, struct dentry *dentry,
--
fs/hpfs/inode.c-287-
fs/hpfs/inode.c:288: truncate_setsize(inode, attr->ia_size);
fs/hpfs/inode.c-289- hpfs_truncate(inode);
--
fs/jffs2/fs.c=32=int jffs2_do_setattr (struct inode *inode, struct iattr *iattr)
--
fs/jffs2/fs.c-179-
fs/jffs2/fs.c:180: /* We have to do the truncate_setsize() without f->sem held, since
fs/jffs2/fs.c-181- some pages may be locked and waiting for it in read_folio().
--
fs/jffs2/fs.c-185- if (ivalid & ATTR_SIZE && inode->i_size > iattr->ia_size) {
fs/jffs2/fs.c:186: truncate_setsize(inode, iattr->ia_size);
fs/jffs2/fs.c-187- inode->i_blocks = (inode->i_size + 511) >> 9;
--
fs/jfs/file.c=92=int jfs_setattr(struct mnt_idmap *idmap, struct dentry *dentry,
--
fs/jfs/file.c-121-
fs/jfs/file.c:122: truncate_setsize(inode, iattr->ia_size);
fs/jfs/file.c-123- jfs_truncate(inode);
--
fs/libfs.c=916=int simple_setattr(struct mnt_idmap *idmap, struct dentry *dentry,
--
fs/libfs.c-926- if (iattr->ia_valid & ATTR_SIZE)
fs/libfs.c:927: truncate_setsize(inode, iattr->ia_size);
fs/libfs.c-928- setattr_copy(idmap, inode, iattr);
--
fs/minix/file.c=26=static int minix_setattr(struct mnt_idmap *idmap,
--
fs/minix/file.c-41-
fs/minix/file.c:42: truncate_setsize(inode, attr->ia_size);
fs/minix/file.c-43- minix_truncate(inode);
--
fs/nilfs2/inode.c=907=int nilfs_setattr(struct mnt_idmap *idmap, struct dentry *dentry,
--
fs/nilfs2/inode.c-925- inode_dio_wait(inode);
fs/nilfs2/inode.c:926: truncate_setsize(inode, iattr->ia_size);
fs/nilfs2/inode.c-927- nilfs_truncate(inode);
--
fs/ntfs/file.c=254=static int ntfs_setattr_size(struct inode *vi, struct iattr *attr)
--
fs/ntfs/file.c-284- } else {
fs/ntfs/file.c:285: truncate_setsize(vi, attr->ia_size);
fs/ntfs/file.c-286- }
--
fs/ntfs/file.c=579=static ssize_t ntfs_file_write_iter(struct kiocb *iocb, struct iov_iter *from)
--
fs/ntfs/file.c-664- if (ni->data_size != old_data_size) {
fs/ntfs/file.c:665: truncate_setsize(vi, old_data_size);
fs/ntfs/file.c-666- ntfs_attr_truncate(ni, old_data_size);
--
fs/ntfs/inode.c=375=int ntfs_drop_big_inode(struct inode *inode)
--
fs/ntfs/inode.c-390-
fs/ntfs/inode.c:391: truncate_setsize(VFS_I(ni), 0);
fs/ntfs/inode.c-392- ntfs_truncate_vfs(VFS_I(ni), 0, 1);
--
fs/ntfs/inode.c=2410=int ntfs_extend_initialized_size(struct inode *vi, const loff_t offset,
--
fs/ntfs/inode.c-2444- if (err)
fs/ntfs/inode.c:2445: truncate_setsize(vi, old_init_size);
fs/ntfs/inode.c-2446- return err;
--
fs/ntfs3/attrib.c=2009=int attr_collapse_range(struct ntfs_inode *ni, u64 vbo, u64 bytes)
--
fs/ntfs3/attrib.c-2057- /* Simple truncate file at 'vbo'. */
fs/ntfs3/attrib.c:2058: truncate_setsize(&ni->vfs_inode, vbo);
fs/ntfs3/attrib.c-2059- err = attr_set_size(ni, ATTR_DATA, ni->file.ads.name,
--
fs/ntfs3/file.c=706=int ntfs_setattr(struct mnt_idmap *idmap, struct dentry *dentry,
--
fs/ntfs3/file.c-738- if (newsize != oldsize) {
fs/ntfs3/file.c:739: truncate_setsize(inode, newsize);
fs/ntfs3/file.c-740-
--
fs/omfs/file.c=341=static int omfs_setattr(struct mnt_idmap *idmap,
--
fs/omfs/file.c-355- return error;
fs/omfs/file.c:356: truncate_setsize(inode, attr->ia_size);
fs/omfs/file.c-357- omfs_truncate(inode);
--
fs/orangefs/inode.c=697=static int orangefs_setattr_size(struct inode *inode, struct iattr *iattr)
--
fs/orangefs/inode.c-722-
fs/orangefs/inode.c:723: /* This is truncate_setsize in a different order. */
fs/orangefs/inode.c-724- truncate_pagecache(inode, iattr->ia_size);
--
fs/ramfs/file-nommu.c=135=static int ramfs_nommu_resize(struct inode *inode, loff_t newsize, loff_t size)
--
fs/ramfs/file-nommu.c-154-
fs/ramfs/file-nommu.c:155: truncate_setsize(inode, newsize);
fs/ramfs/file-nommu.c-156- return 0;
--
fs/smb/client/cifsfs.c=1519=ssize_t cifs_file_copychunk_range(unsigned int xid,
--
fs/smb/client/cifsfs.c-1596- if (rc > 0 && destoff + rc > i_size_read(target_inode)) {
fs/smb/client/cifsfs.c:1597: truncate_setsize(target_inode, destoff + rc);
fs/smb/client/cifsfs.c-1598- netfs_resize_file(&target_cifsi->netfs,
--
fs/smb/client/smb2ops.c=3508=static long smb3_zero_range(struct file *file, struct cifs_tcon *tcon,
--
fs/smb/client/smb2ops.c-3568- if (rc >= 0) {
fs/smb/client/smb2ops.c:3569: truncate_setsize(inode, new_size);
fs/smb/client/smb2ops.c-3570- spin_lock(&inode->i_lock);
--
fs/smb/client/smb2ops.c=4014=static long smb3_collapse_range(struct file *file, struct cifs_tcon *tcon,
--
fs/smb/client/smb2ops.c-4064-
fs/smb/client/smb2ops.c:4065: truncate_setsize(inode, new_eof);
fs/smb/client/smb2ops.c-4066- spin_lock(&inode->i_lock);
--
fs/smb/client/smb2ops.c=4078=static long smb3_insert_range(struct file *file, struct cifs_tcon *tcon,
--
fs/smb/client/smb2ops.c-4127-
fs/smb/client/smb2ops.c:4128: truncate_setsize(inode, new_eof);
fs/smb/client/smb2ops.c-4129- spin_lock(&inode->i_lock);
--
fs/ubifs/file.c=883=static int do_writepage(struct folio *folio, size_t len)
--
fs/ubifs/file.c-958- * same time. And the problematic one is truncation to smaller size, from where
fs/ubifs/file.c:959: * we have to call 'truncate_setsize()', which first changes @inode->i_size,
fs/ubifs/file.c-960- * then drops the truncated pages. And while dropping the pages, it takes the
fs/ubifs/file.c:961: * page lock. This means that 'do_truncation()' cannot call 'truncate_setsize()'
fs/ubifs/file.c-962- * with @ui_mutex locked, because it would deadlock with 'ubifs_writepage()'.
--
fs/ubifs/file.c-965- * XXX(truncate): with the new truncate sequence this is not true anymore,
fs/ubifs/file.c:966: * and the calls to truncate_setsize can be move around freely. They should
fs/ubifs/file.c-967- * be moved to the very end of the truncate sequence.
--
fs/ubifs/file.c=1100=static int do_truncation(struct ubifs_info *c, struct inode *inode,
--
fs/ubifs/file.c-1133-
fs/ubifs/file.c:1134: truncate_setsize(inode, new_size);
fs/ubifs/file.c-1135-
--
fs/ubifs/file.c=1208=static int do_setattr(struct ubifs_info *c, struct inode *inode,
--
fs/ubifs/file.c-1222- dbg_gen("size %lld -> %lld", inode->i_size, new_size);
fs/ubifs/file.c:1223: truncate_setsize(inode, new_size);
fs/ubifs/file.c-1224- }
--
fs/ubifs/file.c-1229- inode_set_mtime_to_ts(inode, inode_set_ctime_current(inode));
fs/ubifs/file.c:1230: /* 'truncate_setsize()' changed @i_size, update @ui_size */
fs/ubifs/file.c-1231- ui->ui_size = inode->i_size;
--
fs/ubifs/ubifs.h=334=struct ubifs_gced_idx_leb {
--
fs/ubifs/ubifs.h-393- * make sure @inode->i_size is always changed under @ui_mutex, because it
fs/ubifs/ubifs.h:394: * cannot call 'truncate_setsize()' with @ui_mutex locked, because it would
fs/ubifs/ubifs.h-395- * deadlock with 'ubifs_writepage()' (see file.c). All the other inode fields
--
fs/udf/inode.c=1280=int udf_setsize(struct inode *inode, loff_t newsize)
--
fs/udf/inode.c-1307-set_size:
fs/udf/inode.c:1308: truncate_setsize(inode, newsize);
fs/udf/inode.c-1309- } else {
--
fs/udf/inode.c-1316- iinfo->i_lenAlloc = newsize;
fs/udf/inode.c:1317: truncate_setsize(inode, newsize);
fs/udf/inode.c-1318- up_write(&iinfo->i_data_sem);
--
fs/udf/inode.c-1324- return err;
fs/udf/inode.c:1325: truncate_setsize(inode, newsize);
fs/udf/inode.c-1326- down_write(&iinfo->i_data_sem);
--
fs/ufs/inode.c=1167=static int ufs_truncate(struct inode *inode, loff_t size)
--
fs/ufs/inode.c-1187-
fs/ufs/inode.c:1188: truncate_setsize(inode, size);
fs/ufs/inode.c-1189-
--
fs/xfs/xfs_iops.c=905=xfs_vn_setattr_size(
--
fs/xfs/xfs_iops.c-1008- * drop the XFS_MMAP_EXCL lock after the extent manipulations are
fs/xfs/xfs_iops.c:1009: * complete. The truncate_setsize() call also cleans partial EOF page
fs/xfs/xfs_iops.c-1010- * PTEs on extending truncates and hence ensures sub-page block size
--
fs/xfs/xfs_iops.c-1025- */
fs/xfs/xfs_iops.c:1026: truncate_setsize(inode, newsize);
fs/xfs/xfs_iops.c-1027-
--
fs/zonefs/file.c=203=int zonefs_file_truncate(struct inode *inode, loff_t isize)
--
fs/zonefs/file.c-261- zonefs_update_stats(inode, isize);
fs/zonefs/file.c:262: truncate_setsize(inode, isize);
fs/zonefs/file.c-263- z->z_wpoffset = isize;
]
|
| 210/4 |
2026/09/17 11:10 |
llm |
codeexpert |
0m
Model:
Tokens:
input: 45037
output: 37
thoughts: 41
Thoughts: Here's my summary, as though I'm thinking through this process:
**Diving into the UDF Filesystem's Size Setting**
Okay, so I need to understand how the UDF filesystem handles setting file sizes. Let's see... a quick mental search brings me to the potential function: `udf_setsize`. That seems like the right place to start. Now, where is that in the kernel source? Ah, it's in `fs/udf/inode.c`. Alright, let's navigate there. I'll open up that file and jump to around line 1280. That's usually a good starting point for a function definition. I'll take a look at the code there and see how it works. I'll be looking for things like how it interacts with the underlying block device, any potential error conditions, and how it handles the metadata updates. Let's get to it!
|
| 211/4 |
2026/09/17 11:10 |
tool |
read-file |
0m
Args: map[File:fs/udf/inode.c FirstLine:1280 LineCount:55]
Results: map[Contents:1280: int udf_setsize(struct inode *inode, loff_t newsize)
1281: {
1282: int err = 0;
1283: struct udf_inode_info *iinfo;
1284: unsigned int bsize = i_blocksize(inode);
1285:
1286: if (!(S_ISREG(inode->i_mode) || S_ISDIR(inode->i_mode) ||
1287: S_ISLNK(inode->i_mode)))
1288: return -EINVAL;
1289:
1290: iinfo = UDF_I(inode);
1291: if (newsize > inode->i_size) {
1292: if (iinfo->i_alloc_type == ICBTAG_FLAG_AD_IN_ICB) {
1293: if (bsize >=
1294: (udf_file_entry_alloc_offset(inode) + newsize)) {
1295: down_write(&iinfo->i_data_sem);
1296: iinfo->i_lenAlloc = newsize;
1297: up_write(&iinfo->i_data_sem);
1298: goto set_size;
1299: }
1300: err = udf_expand_file_adinicb(inode);
1301: if (err)
1302: return err;
1303: }
1304: err = udf_extend_file(inode, newsize);
1305: if (err)
1306: return err;
1307: set_size:
1308: truncate_setsize(inode, newsize);
1309: } else {
1310: if (iinfo->i_alloc_type == ICBTAG_FLAG_AD_IN_ICB) {
1311: down_write(&iinfo->i_data_sem);
1312: udf_clear_extent_cache(inode);
1313: memset(iinfo->i_data + iinfo->i_lenEAttr + newsize,
1314: 0x00, bsize - newsize -
1315: udf_file_entry_alloc_offset(inode));
1316: iinfo->i_lenAlloc = newsize;
1317: truncate_setsize(inode, newsize);
1318: up_write(&iinfo->i_data_sem);
1319: goto update_time;
1320: }
1321: err = block_truncate_page(inode->i_mapping, newsize,
1322: udf_get_block);
1323: if (err)
1324: return err;
1325: truncate_setsize(inode, newsize);
1326: down_write(&iinfo->i_data_sem);
1327: udf_clear_extent_cache(inode);
1328: err = udf_truncate_extents(inode);
1329: up_write(&iinfo->i_data_sem);
1330: if (err)
1331: return err;
1332: }
1333: update_time:
1334: inode_set_mtime_to_ts(inode, inode_set_ctime_current(inode));
]
|
| 212/4 |
2026/09/17 11:10 |
llm |
codeexpert |
0m
Model:
Tokens:
input: 46239
output: 25
thoughts: 299
Thoughts: **My Analysis of the UDF Filesystem Truncate Logic**
Okay, so I'm looking at this code snippet in `fs/udf/inode.c`, specifically the `if (newsize > inode->i_size)` block. Interesting. It's essentially handling file extension and shrinking within the UDF filesystem, and the order of operations here is actually quite clever.
When I'm *extending* the file (`newsize > inode->i_size`), it first calls `udf_extend_file(inode, newsize)`. This makes perfect sense; allocate or extend the disk space *before* updating the file size with `truncate_setsize(inode, newsize)`. This way, if the disk allocation fails, the file size remains unchanged β a critical consistency measure. We don't want partial writes or inconsistent metadata, right?
But *shrinking* is handled differently. Here, it calls `truncate_setsize(inode, newsize)` *first*, and then `udf_truncate_extents(inode)`. This makes equally good sense! I suspect this is because `truncate_setsize` modifies the pagecache and the `i_size`. We want to ensure that readers or mmap'd regions don't see or write beyond the new, truncated size. So that has to happen *before* we actually trim the on-disk blocks, reducing the file size. Protect the data!
Now, I'm getting curious. Is this *just* a UDF thing, or is this a general VFS/Linux filesystem rule? I really need to check other filesystems and the documentation for this. Let me quickly scan through `Documentation/filesystems/` and run a quick `grep` for `truncate_setsize` across the documentation. This could be a crucial best practice, or a pattern I can apply in my own work... let's dig deeper!
|
| 213/4 |
2026/09/17 11:11 |
tool |
grepper |
0m
Args: map[Expression:truncate_setsize PathPrefix:Documentation]
Results: map[Output:Documentation/filesystems/iomap/operations.rst=297=operation.
Documentation/filesystems/iomap/operations.rst:298:``truncate_setsize`` or ``truncate_pagecache`` will take care of
Documentation/filesystems/iomap/operations.rst-299-everything after the EOF block.
]
|
| 214/4 |
2026/09/17 11:11 |
llm |
codeexpert |
0m
Model:
Tokens:
input: 47059
output: 27
thoughts: 20
Thoughts: Here's my thought process, summarized as you requested:
**Navigating the Filesystem Documentation**
Okay, so I need to understand how `filemap_invalidate_lock` works. Given my background, I immediately think, "Where would I find the most authoritative and detailed information?" Naturally, the kernel documentation is the first port of call. Specifically, for filesystem-related details, the logical place to look is the `Documentation/filesystems/` directory within the kernel source. That seems like the most likely place to either find a full explanation of the function, or at least a reference to the relevant section that would explain its purpose, use, and interaction with other components. Let's start there.
|
| 215/4 |
2026/09/17 11:11 |
tool |
grepper |
0m
Error:
Args: map[Expression:filemap_invalidate_lock PathPrefix:Documentation]
Results:
|
| 216/4 |
2026/09/17 11:11 |
llm |
codeexpert |
0m
Model:
Tokens:
input: 47267
output: 27
thoughts: 24
Thoughts: Here's my summary, as if I were thinking these thoughts:
**Investigating `filemap_invalidate_lock`**
Okay, so I need to understand this `filemap_invalidate_lock` function a bit better. Instead of guessing, let's cut straight to the source. Time to open up the `include/` directory and use `grep` to quickly locate the documentation comment for this thing. Hopefully, there's a good explanation in there that will shed some light on its purpose and usage. No point in wasting time digging through unrelated code when I can find the definitive answer directly within the header file itself. Let's see what we can find.
|
| 217/4 |
2026/09/17 11:11 |
tool |
grepper |
0m
Args: map[Expression:filemap_invalidate_lock PathPrefix:include]
Results: map[Output:include/linux/fs.h=1072=static inline void inode_lock_shared_nested(struct inode *inode, unsigned subclass)
--
include/linux/fs.h-1076-
include/linux/fs.h:1077:static inline void filemap_invalidate_lock(struct address_space *mapping)
include/linux/fs.h-1078-{
--
include/linux/fs.h=1082=static inline void filemap_invalidate_unlock(struct address_space *mapping)
--
include/linux/fs.h-1086-
include/linux/fs.h:1087:static inline void filemap_invalidate_lock_shared(struct address_space *mapping)
include/linux/fs.h-1088-{
--
include/linux/fs.h=1105=void unlock_two_nondirectories(struct inode *, struct inode*);
include/linux/fs.h-1106-
include/linux/fs.h:1107:void filemap_invalidate_lock_two(struct address_space *mapping1,
include/linux/fs.h-1108- struct address_space *mapping2);
]
|
| 218/4 |
2026/09/17 11:11 |
llm |
codeexpert |
0m
Model:
Tokens:
input: 47763
output: 36
thoughts: 21
Thoughts: Here's a summary of my thought process, as requested:
**Diving into the Filesystem Structure**
Alright, I need to get a better handle on how this filesystem is structured. I'm going to jump into the `include/linux/fs.h` header file. Specifically, I'm aiming for around line 1070. That's usually where the core data structures for file system operations, like `struct file_operations` are defined or referenced, along with things like `struct inode` and `struct super_block`. I'm hoping to refresh my understanding of where the low-level functions tie into the virtual filesystem layer, or maybe I'm looking to track down a specific VFS call. Let's see what we can find there.
|
| 219/4 |
2026/09/17 11:11 |
tool |
read-file |
0m
Args: map[File:include/linux/fs.h FirstLine:1050 LineCount:50]
Results: map[Contents:1050: }
1051:
1052: static inline int inode_trylock(struct inode *inode)
1053: {
1054: return down_write_trylock(&inode->i_rwsem);
1055: }
1056:
1057: static inline int inode_trylock_shared(struct inode *inode)
1058: {
1059: return down_read_trylock(&inode->i_rwsem);
1060: }
1061:
1062: static inline int inode_is_locked(struct inode *inode)
1063: {
1064: return rwsem_is_locked(&inode->i_rwsem);
1065: }
1066:
1067: static inline void inode_lock_nested(struct inode *inode, unsigned subclass)
1068: {
1069: down_write_nested(&inode->i_rwsem, subclass);
1070: }
1071:
1072: static inline void inode_lock_shared_nested(struct inode *inode, unsigned subclass)
1073: {
1074: down_read_nested(&inode->i_rwsem, subclass);
1075: }
1076:
1077: static inline void filemap_invalidate_lock(struct address_space *mapping)
1078: {
1079: down_write(&mapping->invalidate_lock);
1080: }
1081:
1082: static inline void filemap_invalidate_unlock(struct address_space *mapping)
1083: {
1084: up_write(&mapping->invalidate_lock);
1085: }
1086:
1087: static inline void filemap_invalidate_lock_shared(struct address_space *mapping)
1088: {
1089: down_read(&mapping->invalidate_lock);
1090: }
1091:
1092: static inline int filemap_invalidate_trylock_shared(
1093: struct address_space *mapping)
1094: {
1095: return down_read_trylock(&mapping->invalidate_lock);
1096: }
1097:
1098: static inline void filemap_invalidate_unlock_shared(
1099: struct address_space *mapping)
]
|
| 220/4 |
2026/09/17 11:11 |
llm |
codeexpert |
0m
Model:
Tokens:
input: 48655
output: 30
thoughts: 41
Thoughts: **Investigating the `invalidate_lock` within `address_space`**
Okay, so I'm trying to figure out where `mapping->invalidate_lock` is actually defined, which is something I need to understand for this particular problem I'm tackling. Since it's part of the `address_space` structure, the logical first step is to dig into the `struct address_space` definition. Then, I need to pinpoint the `invalidate_lock` field.
I'll start by searching the relevant headers, so I will start with `include/linux/fs.h`. That's where a lot of the fundamental filesystem structures are typically defined, and `address_space` is almost certainly there. I'll search that file for anything related to `invalidate_lock` to find its type and context within the `address_space` definition.
|
| 221/4 |
2026/09/17 11:12 |
tool |
grepper |
0m
Args: map[Expression:invalidate_lock PathPrefix:include/linux/fs.h]
Results: map[Output:include/linux/fs.h=446=struct mapping_metadata_bhs {
--
include/linux/fs.h-455- * @i_pages: Cached pages.
include/linux/fs.h:456: * @invalidate_lock: Guards coherency between page cache contents and
include/linux/fs.h-457- * file offset->disk block mappings in the filesystem during invalidates.
--
include/linux/fs.h=471=struct address_space {
--
include/linux/fs.h-473- struct xarray i_pages;
include/linux/fs.h:474: struct rw_semaphore invalidate_lock;
include/linux/fs.h-475- gfp_t gfp_mask;
--
include/linux/fs.h=1072=static inline void inode_lock_shared_nested(struct inode *inode, unsigned subclass)
--
include/linux/fs.h-1076-
include/linux/fs.h:1077:static inline void filemap_invalidate_lock(struct address_space *mapping)
include/linux/fs.h-1078-{
include/linux/fs.h:1079: down_write(&mapping->invalidate_lock);
include/linux/fs.h-1080-}
--
include/linux/fs.h=1082=static inline void filemap_invalidate_unlock(struct address_space *mapping)
include/linux/fs.h-1083-{
include/linux/fs.h:1084: up_write(&mapping->invalidate_lock);
include/linux/fs.h-1085-}
include/linux/fs.h-1086-
include/linux/fs.h:1087:static inline void filemap_invalidate_lock_shared(struct address_space *mapping)
include/linux/fs.h-1088-{
include/linux/fs.h:1089: down_read(&mapping->invalidate_lock);
include/linux/fs.h-1090-}
--
include/linux/fs.h=1092=static inline int filemap_invalidate_trylock_shared(
--
include/linux/fs.h-1094-{
include/linux/fs.h:1095: return down_read_trylock(&mapping->invalidate_lock);
include/linux/fs.h-1096-}
--
include/linux/fs.h=1098=static inline void filemap_invalidate_unlock_shared(
--
include/linux/fs.h-1100-{
include/linux/fs.h:1101: up_read(&mapping->invalidate_lock);
include/linux/fs.h-1102-}
--
include/linux/fs.h=1105=void unlock_two_nondirectories(struct inode *, struct inode*);
include/linux/fs.h-1106-
include/linux/fs.h:1107:void filemap_invalidate_lock_two(struct address_space *mapping1,
include/linux/fs.h-1108- struct address_space *mapping2);
--
include/linux/fs.h=2285=struct file_system_type {
--
include/linux/fs.h-2313- struct lock_class_key i_mutex_key;
include/linux/fs.h:2314: struct lock_class_key invalidate_lock_key;
include/linux/fs.h-2315- struct lock_class_key i_mutex_dir_key;
]
|
| 222/4 |
2026/09/17 11:12 |
llm |
codeexpert |
0m
Model:
Tokens:
input: 49813
output: 29
thoughts: 91
Thoughts: Here's my thought process, as it stands:
**Examining File System Coherency**
Okay, so I'm looking at this definition in `include/linux/fs.h`, specifically `@invalidate_lock`. It's pretty clear: this lock is all about ensuring the page cache and the file offset-to-disk block mappings stay consistent, especially during invalidation processes. That's key for data integrity, right? I want to dig deeper into a specific file system and see how this actually plays out in practice.
Since I'm interested in how it's implemented, I'll go straight to `fs/ntfs3`. My aim here is to see where and how `invalidate_lock` is being used, or if a similar function is being used. A quick grep for both `invalidate_lock` and `filemap_invalidate` should give me a good picture of its role within the NTFS3 implementation. I want to understand the mechanics here to assess any performance impacts or potential areas of concern. Let's see what comes up...
|
| 223/4 |
2026/09/17 11:12 |
tool |
grepper |
0m
Args: map[Expression:filemap_invalidate PathPrefix:fs/ntfs3]
Results: map[Output:fs/ntfs3/file.c=466=static long ntfs_fallocate(struct file *file, int mode, loff_t vbo, loff_t len)
--
fs/ntfs3/file.c-519- inode_dio_wait(inode);
fs/ntfs3/file.c:520: filemap_invalidate_lock(mapping);
fs/ntfs3/file.c-521- map_locked = true;
--
fs/ntfs3/file.c-691- if (map_locked)
fs/ntfs3/file.c:692: filemap_invalidate_unlock(mapping);
fs/ntfs3/file.c-693-
]
|
| 224/4 |
2026/09/17 11:12 |
llm |
codeexpert |
0m
Model:
Tokens:
input: 50350
output: 29
thoughts: 20
Thoughts: Here's my thought process, as if I were considering this issue:
**Investigating `page_mkwrite` in NTFS3**
Okay, so we're diving into the `fs/ntfs3` code, and I need to see how the writeback process interacts with page faults. My immediate thought is to look for any instances of `page_mkwrite` within that directory. This function is the key to understanding how the file system handles creating writable pages from read-only ones, so it's a critical point for understanding write paths, potential copy-on-write behavior, and synchronization. Grepping for this within `fs/ntfs3` is a good starting point to quickly identify how NTFS3's write handling functions. It'll give me a list of entry points to investigate further. Let's see what that yields!
|
| 225/4 |
2026/09/17 11:13 |
tool |
grepper |
0m
Args: map[Expression:page_mkwrite PathPrefix:fs/ntfs3]
Results: map[Output:fs/ntfs3/file.c=371=static const struct vm_operations_struct ntfs_file_vm_ops = {
--
fs/ntfs3/file.c-374- .map_pages = filemap_map_pages,
fs/ntfs3/file.c:375: .page_mkwrite = filemap_page_mkwrite,
fs/ntfs3/file.c-376-};
]
|
| 226/4 |
2026/09/17 11:13 |
llm |
codeexpert |
0m
Model:
Tokens:
input: 50699
output: 40
thoughts: 57
Thoughts: Okay, here's my take on those thoughts, framed as an expert's internal monologue:
**Investigating the NTFS File Write Operations**
Alright, let's see... *ntfs\_file\_vm\_ops* is pointing to *.page\_mkwrite = filemap\_page\_mkwrite*. Ah, that's interesting, but not entirely unexpected. Now, I need to jog my memory (or confirm my assumptions) about what *filemap\_page\_mkwrite* actually *does* in this context. It's the key to understanding the file write operation at that level of the VFS interface for NTFS, so let's quickly check what's going on behind that function call. I need to refresh my understanding of the data flow.
|
| 227/4 |
2026/09/17 11:13 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:fs/ntfs3/file.c Name:filemap_page_mkwrite]
Results: map[SourceCode:4006: vm_fault_t filemap_page_mkwrite(struct vm_fault *vmf)
4007: {
4008: struct address_space *mapping = vmf->vma->vm_file->f_mapping;
4009: struct folio *folio = page_folio(vmf->page);
4010: vm_fault_t ret = VM_FAULT_LOCKED;
4011:
4012: sb_start_pagefault(mapping->host->i_sb);
4013: file_update_time(vmf->vma->vm_file);
4014: folio_lock(folio);
4015: if (folio->mapping != mapping) {
4016: folio_unlock(folio);
4017: ret = VM_FAULT_NOPAGE;
4018: goto out;
4019: }
4020: /*
4021: * We mark the folio dirty already here so that when freeze is in
4022: * progress, we are guaranteed that writeback during freezing will
4023: * see the dirty folio and writeprotect it again.
4024: */
4025: folio_mark_dirty(folio);
4026: folio_wait_stable(folio);
4027: out:
4028: sb_end_pagefault(mapping->host->i_sb);
4029: return ret;
4030: }
SourceFile:mm/filemap.c]
|
| 228/4 |
2026/09/17 11:13 |
llm |
codeexpert |
0m
Model:
Tokens:
input: 51372
output: 37
thoughts: 40
Thoughts: Okay, here's my interpretation of that thought process, from an expert's perspective:
**Diving into the NTFS Filesystem Implementation**
Hmm, `ntfs_file_fault`... I need to refresh my memory on that. Specifically, I'm trying to understand the nitty-gritty of what happens when a file fault occurs in the NTFS3 filesystem. Okay, I know where to start looking. Let's go straight to the source. Time to crack open `fs/ntfs3/file.c` and specifically, I'll be looking at the `ntfs_file_vm_ops` structure. Thatβs the most logical place to find the relevant function pointer, or better yet the function itself, responsible for handling that specific virtual memory operation. I know that's where the critical file operations are registered, and that should give me the context I need.
|
| 229/4 |
2026/09/17 11:13 |
tool |
read-file |
0m
Args: map[File:fs/ntfs3/file.c FirstLine:365 LineCount:25]
Results: map[Contents: 365: mark_inode_dirty(inode);
366: }
367: ntfs_zero_tail(inode->i_mapping, ni->i_valid);
368: }
369:
370: /* Copy of generic_file_vm_ops. */
371: static const struct vm_operations_struct ntfs_file_vm_ops = {
372: .close = ntfs_filemap_close,
373: .fault = filemap_fault,
374: .map_pages = filemap_map_pages,
375: .page_mkwrite = filemap_page_mkwrite,
376: };
377:
378: /*
379: * ntfs_file_mmap_prepare - file_operations::mmap_prepare
380: */
381: static int ntfs_file_mmap_prepare(struct vm_area_desc *desc)
382: {
383: struct file *file = desc->file;
384: struct inode *inode = file_inode(file);
385: struct ntfs_inode *ni = ntfs_i(inode);
386: const bool rw = vma_desc_test(desc, VMA_WRITE_BIT);
387: int err;
388:
389: /* Avoid any operation if inode is bad. */
]
|
| 230/4 |
2026/09/17 11:13 |
llm |
codeexpert |
0m
Model:
Tokens:
input: 52041
output: 37
thoughts: 31
Thoughts: Okay, here's my take on those thoughts, framed as an expert's internal monologue:
**Investigating a Potential Locking Issue in the Filemap Code**
Hmm, now that I'm looking at this code, a question pops into my head. I'm wondering if `filemap_fault` actually acquires the `filemap_invalidate_lock_shared` lock. It's a key detail to understand the locking behavior here, and I need to be absolutely sure about that. The implications are significant if there's a missed lock. Time to jump straight into the code for `filemap_fault` and verify. Gotta check that function call and its interaction with the lock. Let's see...
|
| 231/4 |
2026/09/17 11:14 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:fs/ntfs3/file.c Name:filemap_fault]
Results: map[SourceCode:3532: /**
3533: * filemap_fault - read in file data for page fault handling
3534: * @vmf: struct vm_fault containing details of the fault
3535: *
3536: * filemap_fault() is invoked via the vma operations vector for a
3537: * mapped memory region to read in file data during a page fault.
3538: *
3539: * The goto's are kind of ugly, but this streamlines the normal case of having
3540: * it in the page cache, and handles the special cases reasonably without
3541: * having a lot of duplicated code.
3542: *
3543: * vma->vm_mm->mmap_lock must be held on entry.
3544: *
3545: * If our return value has VM_FAULT_RETRY set, it's because the mmap_lock
3546: * may be dropped before doing I/O or by lock_folio_maybe_drop_mmap().
3547: *
3548: * If our return value does not have VM_FAULT_RETRY set, the mmap_lock
3549: * has not been released.
3550: *
3551: * We never return with VM_FAULT_RETRY and a bit from VM_FAULT_ERROR set.
3552: *
3553: * Return: bitwise-OR of %VM_FAULT_ codes.
3554: */
3555: vm_fault_t filemap_fault(struct vm_fault *vmf)
3556: {
3557: int error;
3558: struct file *file = vmf->vma->vm_file;
3559: struct file *fpin = NULL;
3560: struct address_space *mapping = file->f_mapping;
3561: struct inode *inode = mapping->host;
3562: pgoff_t max_idx, index = vmf->pgoff;
3563: struct folio *folio;
3564: vm_fault_t ret = 0;
3565: bool mapping_locked = false;
3566:
3567: max_idx = DIV_ROUND_UP(i_size_read(inode), PAGE_SIZE);
3568: if (unlikely(index >= max_idx))
3569: return VM_FAULT_SIGBUS;
3570:
3571: trace_mm_filemap_fault(mapping, index);
3572:
3573: /*
3574: * Do we have something in the page cache already?
3575: */
3576: folio = filemap_get_folio(mapping, index);
3577: if (likely(!IS_ERR(folio))) {
3578: /*
3579: * We found the page, so try async readahead before waiting for
3580: * the lock.
3581: */
3582: if (!(vmf->flags & FAULT_FLAG_TRIED))
3583: fpin = do_async_mmap_readahead(vmf, folio);
3584: if (unlikely(!folio_test_uptodate(folio))) {
3585: filemap_invalidate_lock_shared(mapping);
3586: mapping_locked = true;
3587: }
3588: } else {
3589: ret = filemap_fault_recheck_pte_none(vmf);
3590: if (unlikely(ret))
3591: return ret;
3592:
3593: /* No page in the page cache at all */
3594: count_vm_event(PGMAJFAULT);
3595: count_memcg_event_mm(vmf->vma->vm_mm, PGMAJFAULT);
3596: ret = VM_FAULT_MAJOR;
3597: fpin = do_sync_mmap_readahead(vmf);
3598: retry_find:
3599: /*
3600: * See comment in filemap_create_folio() why we need
3601: * invalidate_lock
3602: */
3603: if (!mapping_locked) {
3604: filemap_invalidate_lock_shared(mapping);
3605: mapping_locked = true;
3606: }
3607: folio = __filemap_get_folio(mapping, index,
3608: FGP_CREAT|FGP_FOR_MMAP,
3609: vmf->gfp_mask);
3610: if (IS_ERR(folio)) {
3611: if (fpin)
3612: goto out_retry;
3613: filemap_invalidate_unlock_shared(mapping);
3614: return VM_FAULT_OOM;
3615: }
3616: }
3617:
3618: if (!lock_folio_maybe_drop_mmap(vmf, folio, &fpin))
3619: goto out_retry;
3620:
3621: /* Did it get truncated? */
3622: if (unlikely(folio->mapping != mapping)) {
3623: folio_unlock(folio);
3624: folio_put(folio);
3625: goto retry_find;
3626: }
3627: VM_BUG_ON_FOLIO(!folio_contains(folio, index), folio);
3628:
3629: /*
3630: * We have a locked folio in the page cache, now we need to check
3631: * that it's up-to-date. If not, it is going to be due to an error,
3632: * or because readahead was otherwise unable to retrieve it.
3633: */
3634: if (unlikely(!folio_test_uptodate(folio))) {
3635: /*
3636: * If the invalidate lock is not held, the folio was in cache
3637: * and uptodate and now it is not. Strange but possible since we
3638: * didn't hold the page lock all the time. Let's drop
3639: * everything, get the invalidate lock and try again.
3640: */
3641: if (!mapping_locked) {
3642: folio_unlock(folio);
3643: folio_put(folio);
3644: goto retry_find;
3645: }
3646:
3647: /*
3648: * OK, the folio is really not uptodate. This can be because the
3649: * VMA has the VM_RAND_READ flag set, or because an error
3650: * arose. Let's read it in directly.
3651: */
3652: goto page_not_uptodate;
3653: }
3654:
3655: /*
3656: * We've made it this far and we had to drop our mmap_lock, now is the
3657: * time to return to the upper layer and have it re-find the vma and
3658: * redo the fault.
3659: */
3660: if (fpin) {
3661: folio_unlock(folio);
3662: goto out_retry;
3663: }
3664: if (mapping_locked)
3665: filemap_invalidate_unlock_shared(mapping);
3666:
3667: /*
3668: * Found the page and have a reference on it.
3669: * We must recheck i_size under page lock.
3670: */
3671: max_idx = DIV_ROUND_UP(i_size_read(inode), PAGE_SIZE);
3672: if (unlikely(index >= max_idx)) {
3673: folio_unlock(folio);
3674: folio_put(folio);
3675: return VM_FAULT_SIGBUS;
3676: }
3677:
3678: vmf->page = folio_file_page(folio, index);
3679: return ret | VM_FAULT_LOCKED;
3680:
3681: page_not_uptodate:
3682: /*
3683: * Umm, take care of errors if the page isn't up-to-date.
3684: * Try to re-read it _once_. We do this synchronously,
3685: * because there really aren't any performance issues here
3686: * and we need to check for errors.
3687: */
3688: fpin = maybe_unlock_mmap_for_io(vmf, fpin);
3689: error = filemap_read_folio(file, mapping->a_ops->read_folio, folio);
3690: if (fpin)
3691: goto out_retry;
3692: folio_put(folio);
3693:
3694: if (!error || error == AOP_TRUNCATED_PAGE)
3695: goto retry_find;
3696: filemap_invalidate_unlock_shared(mapping);
3697:
3698: return VM_FAULT_SIGBUS;
3699:
3700: out_retry:
3701: /*
3702: * We dropped the mmap_lock, we need to return to the fault handler to
3703: * re-find the vma and come back and find our hopefully still populated
3704: * page.
3705: */
3706: if (!IS_ERR(folio))
3707: folio_put(folio);
3708: if (mapping_locked)
3709: filemap_invalidate_unlock_shared(mapping);
3710: if (fpin)
3711: fput(fpin);
3712: return ret | VM_FAULT_RETRY;
3713: }
SourceFile:mm/filemap.c]
|
| 232/4 |
2026/09/17 11:14 |
llm |
codeexpert |
0m
Model:
Tokens:
input: 55049
output: 36
thoughts: 119
Thoughts: **Analyzing `filemap_fault` and `filemap_invalidate_lock_shared`**
Okay, so I'm looking at `filemap_fault` and I see it acquires `filemap_invalidate_lock_shared(mapping)`. Standard stuff, but let's dig a bit deeper. Specifically, I'm focusing on lines 3600-3606.
Ah, there it is! They're explicitly checking if the mapping is already locked. If not, they call `filemap_invalidate_lock_shared(mapping)` and set `mapping_locked` to true. This feels familiar, this pattern of locking. The comment they've included is interesting, it mentions something about why they need `invalidate_lock`. That's where the real detail lives, let's go read the comment in `filemap_create_folio()` to jog my memory, I suspect it is about memory management in a multi-threaded system. I need the full picture here. I can tell you're very familiar with these methods, so I won't patronize you with details you already know. Let's see what the fine print says.
|
| 233/4 |
2026/09/17 11:14 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:mm/filemap.c Name:filemap_create_folio]
Results: map[SourceCode:2619: static int filemap_create_folio(struct kiocb *iocb, struct folio_batch *fbatch)
2620: {
2621: struct address_space *mapping = iocb->ki_filp->f_mapping;
2622: struct folio *folio;
2623: int error;
2624: unsigned int min_order = mapping_min_folio_order(mapping);
2625: pgoff_t index;
2626:
2627: if (iocb->ki_flags & (IOCB_NOWAIT | IOCB_WAITQ))
2628: return -EAGAIN;
2629:
2630: folio = filemap_alloc_folio(mapping_gfp_mask(mapping), min_order, NULL);
2631: if (!folio)
2632: return -ENOMEM;
2633: if (iocb->ki_flags & IOCB_DONTCACHE)
2634: __folio_set_dropbehind(folio);
2635:
2636: /*
2637: * Protect against truncate / hole punch. Grabbing invalidate_lock
2638: * here assures we cannot instantiate and bring uptodate new
2639: * pagecache folios after evicting page cache during truncate
2640: * and before actually freeing blocks. Note that we could
2641: * release invalidate_lock after inserting the folio into
2642: * the page cache as the locked folio would then be enough to
2643: * synchronize with hole punching. But there are code paths
2644: * such as filemap_update_page() filling in partially uptodate
2645: * pages or ->readahead() that need to hold invalidate_lock
2646: * while mapping blocks for IO so let's hold the lock here as
2647: * well to keep locking rules simple.
2648: */
2649: filemap_invalidate_lock_shared(mapping);
2650: index = (iocb->ki_pos >> (PAGE_SHIFT + min_order)) << min_order;
2651: error = filemap_add_folio(mapping, folio, index,
2652: mapping_gfp_constraint(mapping, GFP_KERNEL));
2653: if (error == -EEXIST)
2654: error = AOP_TRUNCATED_PAGE;
2655: if (error)
2656: goto error;
2657:
2658: error = filemap_read_folio(iocb->ki_filp, mapping->a_ops->read_folio,
2659: folio);
2660: if (error)
2661: goto error;
2662:
2663: filemap_invalidate_unlock_shared(mapping);
2664: folio_batch_add(fbatch, folio);
2665: return 0;
2666: error:
2667: filemap_invalidate_unlock_shared(mapping);
2668: folio_put(folio);
2669: return error;
2670: }
SourceFile:mm/filemap.c]
|
| 234/4 |
2026/09/17 11:14 |
llm |
codeexpert |
0m
Model:
Tokens:
input: 56323
output: 37
thoughts: 503
Thoughts: **Analyzing NTFS Truncation and Fallocate Implementation**
Okay, so I'm digging into how NTFS handles file truncation and allocation, specifically looking at potential synchronization issues and lock usage. My initial focus was on the general approach, and I had a specific section in `fs/ntfs/file.c` in mind to examine the implications of `filemap_invalidate_lock()` and the related size updates. The text in the earlier `fs/ntfs` code clearly outlines the need to serialize with page faults and pagecache instantiation, as well as the actions taken with `truncate_pagecache`, `i_size_write`, and `pagecache_isize_extended`.
The comment in that first code block about protecting against truncate/hole punch and the use of `invalidate_lock` is key here to synchronize page cache eviction during truncation before freeing blocks. It suggests that while the lock could technically be released earlier, it's held throughout to simplify the locking rules, which makes perfect sense given the other operations.
But then, a thought struck me: let's not assume it's the same across all NTFS implementations. I needed to cross-reference to the updated NTFS3 filesystem. I had to investigate to see if any similar comments, history, discussions or commit messages exist in that newer version of the code.
I'm now checking `fs/ntfs3/file.c`, specifically `ntfs_fallocate` and the relevant section, lines 510-530. I want to see how these operations interact. Perhaps there's a difference in how it's handled there, or maybe a more refined approach that provides more insight. This is where the real nuance lies, so I'm going to carefully read this section and try to determine whether there are any differences, improvements, or subtle shifts in logic that I can learn from.
|
| 235/4 |
2026/09/17 11:14 |
tool |
read-file |
0m
Args: map[File:fs/ntfs3/file.c FirstLine:510 LineCount:40]
Results: map[Contents: 510:
511: if (WARN_ON(ni->ni_flags & NI_FLAG_COMPRESSED_MASK)) {
512: /* Should never be here, see ntfs_file_open. */
513: err = -EOPNOTSUPP;
514: goto out;
515: }
516:
517: if (mode & (FALLOC_FL_PUNCH_HOLE | FALLOC_FL_COLLAPSE_RANGE |
518: FALLOC_FL_INSERT_RANGE)) {
519: inode_dio_wait(inode);
520: filemap_invalidate_lock(mapping);
521: map_locked = true;
522: }
523:
524: if (mode & FALLOC_FL_PUNCH_HOLE) {
525: u32 frame_size;
526: loff_t mask, vbo_a, end_a, tmp, from;
527:
528: err = filemap_write_and_wait_range(mapping, vbo_down,
529: LLONG_MAX);
530: if (err)
531: goto out;
532:
533: truncate_pagecache(inode, vbo_down);
534:
535: ni_lock(ni);
536: err = attr_punch_hole(ni, vbo, len, &frame_size);
537: ni_unlock(ni);
538: if (!err)
539: goto ok;
540:
541: if (err != E_NTFS_NOTALIGNED)
542: goto out;
543:
544: /* Process not aligned punch. */
545: err = 0;
546: if (end > i_size)
547: end = i_size;
548: mask = frame_size - 1;
549: vbo_a = (vbo + mask) & ~mask;
]
|
| 236/4 |
2026/09/17 11:14 |
llm |
codeexpert |
0m
Model:
Tokens:
input: 57850
output: 37
thoughts: 26
Thoughts: Here's my take on the `ntfs_fallocate` function, pulling from what I'm seeing in `fs/ntfs3/file.c`:
**Dissecting `ntfs_fallocate` in `fs/ntfs3/file.c`**
Alright, let's dive into the rest of `ntfs_fallocate`. I'm already anticipating the typical challenges here: how the NTFS file system handles this operation, especially with its specific metadata structures and allocation strategies. I need to understand how they're handling sparse files, how they're updating the attribute list if we're extending or pre-allocating clusters, and what locking mechanisms are in place to ensure consistency during this process. I'll need to pay close attention to the error handling and how they manage potential disk I/O failures during allocation or metadata updates. Is there any fragmentation avoidance strategy in place, or any checks to determine if the allocation is contiguous? And, of course, I want to see how they integrate with the underlying block device layer. I expect to find some interesting logic related to extent mapping, and how they interact with the journal to maintain integrity. There may be some optimizations related to how they handle zeroing data.
|
| 237/4 |
2026/09/17 11:15 |
tool |
read-file |
0m
Args: map[File:fs/ntfs3/file.c FirstLine:645 LineCount:55]
Results: map[Contents: 645: }
646:
647: err = inode_newsize_ok(inode, new_size);
648: if (err)
649: goto out;
650:
651: if (new_size > i_size) {
652: /*
653: * Allocate clusters, do not change 'valid' size.
654: */
655: err = ntfs_set_size(inode, new_size);
656: if (err)
657: goto out;
658: }
659:
660: if (is_supported_holes) {
661: CLST vcn = vbo >> cluster_bits;
662: CLST cend = bytes_to_cluster(sbi, end);
663: CLST lcn, clen;
664: bool new;
665:
666: /*
667: * Allocate and zero new clusters.
668: */
669: for (; vcn < cend; vcn += clen) {
670: err = attr_data_get_block(ni, vcn, cend - vcn,
671: &lcn, &clen, &new,
672: true, NULL, false);
673: if (err)
674: goto out;
675: }
676: }
677:
678: if (mode & FALLOC_FL_KEEP_SIZE) {
679: err = ntfs_set_size(inode, i_size);
680: if (err)
681: goto out;
682: }
683: }
684:
685: ok:
686: err = file_modified(file);
687: if (err)
688: goto out;
689:
690: out:
691: if (map_locked)
692: filemap_invalidate_unlock(mapping);
693:
694: if (!err) {
695: inode_set_mtime_to_ts(inode, inode_set_ctime_current(inode));
696: mark_inode_dirty(inode);
697: }
698:
699: inode_unlock(inode);
]
|
| 238/4 |
2026/09/17 11:15 |
llm |
codeexpert |
0m
Model:
Tokens:
input: 58872
output: 38
thoughts: 2749
Thoughts: **Analyzing NTFS File Size Management and Concurrency**
Okay, here's the breakdown of my thought process. I need to figure out the correct order and potential race conditions when resizing files in NTFS, specifically within the `ntfs_setattr` function. My initial focus is on `fs/ntfs3/file.c` and how it handles file truncation and size extension.
First, I see the core code block in `ntfs_setattr` that deals with changing the file size. I note the use of `truncate_setsize` and `ntfs_set_size`. The `inode_lock` is held, but I need to understand if this is enough to protect against all potential races. This is where my questions start to form: Does `ntfs_setattr` need to call `filemap_invalidate_lock` before these operations? And if so, how does that influence the order of `truncate_setsize` and `ntfs_set_size`?
The absence of `filemap_invalidate_lock` is immediately a red flag. I know from experience that this lock guards against races with page faults and write operations on the page cache. Truncating a file, whether shrinking or extending, has to deal with the page cache.
I'm thinking about the implications of the page cache. If I shrink a file, I need to make sure that the page cache is truncated *before* deallocating the disk blocks to avoid concurrent access to freed blocks. Conversely, when extending, if I increase the `i_size` *before* allocating the disk space, page faults could happen in the unallocated range. A failure in `ntfs_set_size` then leaves me with an inconsistent state: `i_size` is too big but no data on the disk.
This leads me to the critical question: What's the correct order for extending and shrinking file sizes? I have to analyze the page cache eviction and allocation logic. Specifically, `filemap_fault` acquires `invalidate_lock_shared` and not `inode_lock`, highlighting the potential race. What is `filemap_create_folio` doing in terms of truncate and hole punch? I have to check the comment. I remember the comment says it needs `invalidate_lock` to protect the filesystem after evicting the pagecache, because a concurrent truncate process might be in action.
Now, I'm forming a hypothesis, that I need to call `filemap_invalidate_lock` to protect from a page fault. Then the correct order of operations will be different for extending and shrinking the file.
I go back and re-read the code for `truncate_setsize`. It calls `pagecache_isize_extended` if the file is being extended and `truncate_pagecache`.
Next, I need to verify what `ntfs_set_size` actually does. My concern is that while `truncate_setsize` modifies `i_size`, `ntfs_set_size` might not be modifying it, and there might be a race. I check the implementation of `ntfs_set_size`, specifically how it interacts with the inode size and the disk. It turns out that `ntfs_set_size` *doesn't* directly modify `inode->i_size`. It updates on-disk metadata and a separate internal `ni->i_valid` value. Crucially, the NTFS on-disk size and its internal view of the valid data are managed separately from `inode->i_size`. `ntfs_set_size` does not directly modify `inode->i_size`.
This means the sequence and how the pagecache eviction should happen is key.
My conclusion is:
* **Shrinking:** Call `truncate_setsize` *before* calling `ntfs_set_size`. This truncates the page cache *before* freeing disk blocks, preventing data corruption.
* **Extending:** Call `ntfs_set_size` *before* calling `truncate_setsize`. This allocates disk space first. If allocation fails, no inconsistent state is created because we haven't touched `inode->i_size`.
This rule should be verified by checking the call sites of `ntfs_set_size`.
|
| 239/4 |
2026/09/17 11:15 |
tool |
read-file |
0m
Args: map[File:fs/ntfs3/file.c FirstLine:1270 LineCount:40]
Results: map[Contents:1270: goto out;
1271: }
1272:
1273: if (WARN_ON(ni->ni_flags & NI_FLAG_COMPRESSED_MASK)) {
1274: /* Should never be here, see ntfs_file_open(). */
1275: ret = -EOPNOTSUPP;
1276: goto out;
1277: }
1278:
1279: vbo = iocb->ki_pos;
1280: endbyte = vbo + ret;
1281:
1282: if (endbyte > inode->i_size) {
1283: /*
1284: * Normal files: increase file size, allocate space.
1285: * Sparse/Compressed: increase file size. No space allocated.
1286: */
1287: ret = ntfs_set_size(inode, endbyte);
1288: if (ret)
1289: goto out;
1290: }
1291:
1292: if (is_compressed(ni)) {
1293: ret = ntfs_compress_write(iocb, from);
1294: goto out;
1295: }
1296:
1297: if (vbo > ni->i_valid) {
1298: ret = ntfs_extend_initialized_size(file, ni, vbo);
1299: if (ret)
1300: goto out;
1301: }
1302:
1303: /* Fallback to buffered I/O if the inode does not support direct I/O. */
1304: if (!(iocb->ki_flags & IOCB_DIRECT) ||
1305: !ntfs_should_use_dio(iocb, from)) {
1306: iocb->ki_flags &= ~IOCB_DIRECT;
1307:
1308: ret = iomap_file_buffered_write(iocb, from, &ntfs_iomap_ops,
1309: &ntfs_iomap_folio_ops, NULL);
]
|
| 240/4 |
2026/09/17 11:15 |
llm |
codeexpert |
0m
Model:
Tokens:
input: 63271
output: 830
thoughts: 1396
Thoughts: **Analysis of `ntfs_setattr` and File Size Manipulation**
Okay, here's the deal, based on my understanding and the information at hand. I've got a pretty good grasp on this, but I'm operating with the limitations of the current data availability. I haven't done any external research to check myself.
First, regarding the need for `filemap_invalidate_lock(inode->i_mapping)` in `ntfs_setattr`: it's clear to me that it's *absolutely* necessary. Right now, it's missing from `fs/ntfs3/file.c` (`ntfs_setattr`), unlike other filesystems I've looked at (and `ntfs_fallocate`, or the legacy `fs/ntfs/file.c:ntfs_setattr_size`). Why? Because that `invalidate_lock` is what serializes the invalidation and truncation of the page cache against page faults and readahead operations. Without it, we risk races. Concurrent page faults could bring data into the cache in regions that are *about* to be deallocated, or worse, have already been freed on disk. This is a potential recipe for corruption. `inode_lock` alone isn't enough; page faults get by with just `mmap_lock` and `filemap_invalidate_lock_shared`. We need the write mode.
Next, the order of `truncate_setsize` and `ntfs_set_size` is crucial. The current code in `ntfs_setattr` doesn't differentiate by the direction of size change, which is a problem. Let's break it down:
* **Extending the file (newsize > oldsize)**: `ntfs_set_size` *must* come before `truncate_setsize`. This is essential because `ntfs_set_size` is responsible for allocating and committing disk space/extents. If we run into an error like `-ENOSPC` or `-EFBIG` during allocation, we want the operation to fail cleanly *before* the in-memory inode size (`i_size`) and the page cache get changed. If `truncate_setsize` were called first and then allocation failed, we'd have an inconsistent state with the inode size increased, the page cache potentially extended, and no backing storage. It's a mess.
* **Shrinking the file (newsize < oldsize)**: `truncate_setsize` *must* be called *before* `ntfs_set_size`. Here, `truncate_setsize` updates the inode's size and, more importantly, invalidates and frees cached pages beyond the new EOF. Disk blocks/clusters should only be deallocated *after* the page cache folios beyond the new EOF have been discarded. If we freed disk blocks first, then the subsequent page cache truncation could try to write to freed blocks, which leads to corruption or data loss.
**Caveats:**
* My analysis is based on code inspection of `ntfs3/file.c` (`ntfs_setattr`, `ntfs_fallocate`), `ntfs3/inode.c` (`ntfs_set_size`), `mm/filemap.c`, and comparison to `udf_setsize`, `ext4_setattr`, and the legacy ntfs code.
* The Git commit history is limited because of the shallow repository. I couldn't verify specifics about past discussions or patches related to this missing lock in `ntfs_setattr`.
I'm ready to call the `set-results` tool now.
|
| 241/4 |
2026/09/17 11:15 |
tool |
set-results |
0m
Args: map[Answer:Based on analysis of the kernel source code (`fs/ntfs3`, `fs/ntfs`, `mm/filemap.c`, `include/linux/fs.h`, and comparable filesystems like UDF and ext4):
### 1. Does `ntfs_setattr` need to call `filemap_invalidate_lock(inode->i_mapping)`?
**Yes.**
`filemap_invalidate_lock(inode->i_mapping)` should be taken before truncating/extending the pagecache and disk size, and released with `filemap_invalidate_unlock(inode->i_mapping)` after.
**Reason:**
- The VFS holds `inode->i_rwsem` across `->setattr`, but page faults (`filemap_fault` / `page_mkwrite`) execute without `inode->i_rwsem`. Instead, page fault handlers acquire `mmap_lock` and shared `filemap_invalidate_lock_shared(mapping)`.
- Holding `filemap_invalidate_lock(mapping)` in exclusive mode serializes the truncation/expansion against concurrent page faults and readahead, preventing race conditions where folios are faulted in or brought uptodate after pagecache eviction but before disk block deallocation, or while the file mapping is inconsistent.
---
### 2. Correct order of `truncate_setsize` and `ntfs_set_size`
In `fs/ntfs3/file.c`, `ntfs_setattr` unconditionally calls `truncate_setsize(inode, newsize)` before `ntfs_set_size(inode, newsize)`. The correct ordering should distinguish between extension and shrinking:
- **When extending the file (`newsize > oldsize`)**:
- **Correct order:** Call `ntfs_set_size` **first**, then `truncate_setsize`.
- **Reason:** `ntfs_set_size` performs disk block allocation and updates the NTFS on-disk attribute size. If allocation fails (e.g., `-ENOSPC` or `-EFBIG`), it returns an error before the in-memory `inode->i_size` is expanded and before pagecache folios are extended/instantiated. If `truncate_setsize` were called first, `inode->i_size` would be extended and pagecache notified (`pagecache_isize_extended`), requiring difficult and race-prone rollbacks on error.
- **When shrinking the file (`newsize < oldsize`)**:
- **Correct order:** Call `truncate_setsize` **first**, then `ntfs_set_size`.
- **Reason:** `truncate_setsize` updates `inode->i_size` to the smaller size and invalidates/drops cached pages beyond the new EOF (`truncate_pagecache`). Disk blocks/clusters must only be freed on disk via `ntfs_set_size` after the corresponding cached folios have been removed from memory. If disk blocks were freed before truncating the page cache, writeback or concurrent operations could attempt to access or write dirty pages to disk blocks that were already returned to the free space allocator.
---
### Caveats and Unverified Parts:
- Git commit history in the checkout is restricted to a shallow repository, so commit logs and specific mailing list discussions introducing or addressing this in `fs/ntfs3` could not be traced through `git log`.
- The conclusions are derived from the locking semantics in `include/linux/fs.h` / `mm/filemap.c` and how other filesystems (such as `fs/udf/inode.c:udf_setsize`, `fs/ext4/inode.c:ext4_setattr`, and legacy `fs/ntfs/file.c`) implement extending vs. shrinking file truncation.]
Results: map[Answer:Based on analysis of the kernel source code (`fs/ntfs3`, `fs/ntfs`, `mm/filemap.c`, `include/linux/fs.h`, and comparable filesystems like UDF and ext4):
### 1. Does `ntfs_setattr` need to call `filemap_invalidate_lock(inode->i_mapping)`?
**Yes.**
`filemap_invalidate_lock(inode->i_mapping)` should be taken before truncating/extending the pagecache and disk size, and released with `filemap_invalidate_unlock(inode->i_mapping)` after.
**Reason:**
- The VFS holds `inode->i_rwsem` across `->setattr`, but page faults (`filemap_fault` / `page_mkwrite`) execute without `inode->i_rwsem`. Instead, page fault handlers acquire `mmap_lock` and shared `filemap_invalidate_lock_shared(mapping)`.
- Holding `filemap_invalidate_lock(mapping)` in exclusive mode serializes the truncation/expansion against concurrent page faults and readahead, preventing race conditions where folios are faulted in or brought uptodate after pagecache eviction but before disk block deallocation, or while the file mapping is inconsistent.
---
### 2. Correct order of `truncate_setsize` and `ntfs_set_size`
In `fs/ntfs3/file.c`, `ntfs_setattr` unconditionally calls `truncate_setsize(inode, newsize)` before `ntfs_set_size(inode, newsize)`. The correct ordering should distinguish between extension and shrinking:
- **When extending the file (`newsize > oldsize`)**:
- **Correct order:** Call `ntfs_set_size` **first**, then `truncate_setsize`.
- **Reason:** `ntfs_set_size` performs disk block allocation and updates the NTFS on-disk attribute size. If allocation fails (e.g., `-ENOSPC` or `-EFBIG`), it returns an error before the in-memory `inode->i_size` is expanded and before pagecache folios are extended/instantiated. If `truncate_setsize` were called first, `inode->i_size` would be extended and pagecache notified (`pagecache_isize_extended`), requiring difficult and race-prone rollbacks on error.
- **When shrinking the file (`newsize < oldsize`)**:
- **Correct order:** Call `truncate_setsize` **first**, then `ntfs_set_size`.
- **Reason:** `truncate_setsize` updates `inode->i_size` to the smaller size and invalidates/drops cached pages beyond the new EOF (`truncate_pagecache`). Disk blocks/clusters must only be freed on disk via `ntfs_set_size` after the corresponding cached folios have been removed from memory. If disk blocks were freed before truncating the page cache, writeback or concurrent operations could attempt to access or write dirty pages to disk blocks that were already returned to the free space allocator.
---
### Caveats and Unverified Parts:
- Git commit history in the checkout is restricted to a shallow repository, so commit logs and specific mailing list discussions introducing or addressing this in `fs/ntfs3` could not be traced through `git log`.
- The conclusions are derived from the locking semantics in `include/linux/fs.h` / `mm/filemap.c` and how other filesystems (such as `fs/udf/inode.c:udf_setsize`, `fs/ext4/inode.c:ext4_setattr`, and legacy `fs/ntfs/file.c`) implement extending vs. shrinking file truncation.]
|
| 242/2 |
2026/09/17 11:15 |
llm |
debugger |
0m
Model:
Tokens:
input: 63624
output: 23
thoughts: 0
|
| 243/2 |
2026/09/17 11:16 |
tool |
codesearch-definition-source |
0m
Args:
Results: map[SourceCode: 703: /*
704: * ntfs_setattr - inode_operations::setattr
705: */
706: int ntfs_setattr(struct mnt_idmap *idmap, struct dentry *dentry,
707: struct iattr *attr)
708: {
709: struct inode *inode = d_inode(dentry);
710: struct ntfs_inode *ni = ntfs_i(inode);
711: u32 ia_valid = attr->ia_valid;
712: umode_t mode = inode->i_mode;
713: int err;
714:
715: /* Avoid any operation if inode is bad. */
716: if (unlikely(is_bad_ni(ni)))
717: return -EINVAL;
718:
719: if (unlikely(ntfs3_forced_shutdown(inode->i_sb)))
720: return -EIO;
721:
722: err = setattr_prepare(idmap, dentry, attr);
723: if (err)
724: goto out;
725:
726: if (ia_valid & ATTR_SIZE) {
727: loff_t newsize, oldsize;
728:
729: if (WARN_ON(ni->ni_flags & NI_FLAG_COMPRESSED_MASK)) {
730: /* Should never be here, see ntfs_file_open(). */
731: err = -EOPNOTSUPP;
732: goto out;
733: }
734: inode_dio_wait(inode);
735: oldsize = i_size_read(inode);
736: newsize = attr->ia_size;
737:
738: if (newsize != oldsize) {
739: truncate_setsize(inode, newsize);
740:
741: err = ntfs_set_size(inode, newsize);
742: if (err) {
743: i_size_write(inode, oldsize);
744: goto out;
745: }
746:
747: ni->std_fa |= FILE_ATTRIBUTE_ARCHIVE;
748: ni->ni_flags |= NI_FLAG_UPDATE_PARENT;
749: inode_set_mtime_to_ts(inode,
750: inode_set_ctime_current(inode));
751: }
752: }
753:
754: setattr_copy(idmap, inode, attr);
755:
756: if (!is_ni_base(ni)) {
757: ia_valid &= ~ATTR_SIZE;
758: } else if (mode != inode->i_mode) {
759: err = ntfs_acl_chmod(idmap, dentry);
760: if (err)
761: goto out;
762:
763: /* Linux 'w' -> Windows 'ro'. */
764: if (0222 & inode->i_mode)
765: ni->std_fa &= ~FILE_ATTRIBUTE_READONLY;
766: else
767: ni->std_fa |= FILE_ATTRIBUTE_READONLY;
768: }
769:
770: if (ia_valid & (ATTR_UID | ATTR_GID | ATTR_MODE))
771: ntfs_save_wsl_perm(inode, NULL);
772: mark_inode_dirty(inode);
773: out:
774: return err;
775: }
SourceFile:fs/ntfs3/file.c]
|
| 244/2 |
2026/09/17 11:16 |
llm |
debugger |
0m
Model:
Tokens:
input: 64739
output: 23
thoughts: 0
|
| 245/2 |
2026/09/17 11:16 |
tool |
codesearch-definition-source |
0m
Args:
Results: map[SourceCode: 457: /*
458: * ntfs_fallocate - file_operations::ntfs_fallocate
459: *
460: * Preallocate space for a file. This implements ntfs's fallocate file
461: * operation, which gets called from sys_fallocate system call. User
462: * space requests 'len' bytes at 'vbo'. If FALLOC_FL_KEEP_SIZE is set
463: * we just allocate clusters without zeroing them out. Otherwise we
464: * allocate and zero out clusters via an expanding truncate.
465: */
466: static long ntfs_fallocate(struct file *file, int mode, loff_t vbo, loff_t len)
467: {
468: struct inode *inode = file_inode(file);
469: struct address_space *mapping = inode->i_mapping;
470: struct super_block *sb = inode->i_sb;
471: struct ntfs_sb_info *sbi = sb->s_fs_info;
472: struct ntfs_inode *ni = ntfs_i(inode);
473: loff_t end = vbo + len;
474: loff_t vbo_down = round_down(vbo, max_t(unsigned long,
475: sbi->cluster_size, PAGE_SIZE));
476: bool is_supported_holes = is_sparsed(ni) || is_compressed(ni);
477: loff_t i_size, new_size;
478: bool map_locked;
479: int err;
480:
481: /* No support for dir. */
482: if (!S_ISREG(inode->i_mode))
483: return -EOPNOTSUPP;
484:
485: /*
486: * vfs_fallocate checks all possible combinations of mode.
487: * Do additional checks here before ntfs_set_state(dirty).
488: */
489: if (mode & FALLOC_FL_PUNCH_HOLE) {
490: if (!is_supported_holes)
491: return -EOPNOTSUPP;
492: } else if (mode & FALLOC_FL_COLLAPSE_RANGE) {
493: } else if (mode & FALLOC_FL_INSERT_RANGE) {
494: if (!is_supported_holes)
495: return -EOPNOTSUPP;
496: } else if (mode &
497: ~(FALLOC_FL_KEEP_SIZE | FALLOC_FL_PUNCH_HOLE |
498: FALLOC_FL_COLLAPSE_RANGE | FALLOC_FL_INSERT_RANGE)) {
499: ntfs_inode_warn(inode, "fallocate(0x%x) is not supported",
500: mode);
501: return -EOPNOTSUPP;
502: }
503:
504: ntfs_set_state(sbi, NTFS_DIRTY_DIRTY);
505:
506: inode_lock(inode);
507: i_size = inode->i_size;
508: new_size = max(end, i_size);
509: map_locked = false;
510:
511: if (WARN_ON(ni->ni_flags & NI_FLAG_COMPRESSED_MASK)) {
512: /* Should never be here, see ntfs_file_open. */
513: err = -EOPNOTSUPP;
514: goto out;
515: }
516:
517: if (mode & (FALLOC_FL_PUNCH_HOLE | FALLOC_FL_COLLAPSE_RANGE |
518: FALLOC_FL_INSERT_RANGE)) {
519: inode_dio_wait(inode);
520: filemap_invalidate_lock(mapping);
521: map_locked = true;
522: }
523:
524: if (mode & FALLOC_FL_PUNCH_HOLE) {
525: u32 frame_size;
526: loff_t mask, vbo_a, end_a, tmp, from;
527:
528: err = filemap_write_and_wait_range(mapping, vbo_down,
529: LLONG_MAX);
530: if (err)
531: goto out;
532:
533: truncate_pagecache(inode, vbo_down);
534:
535: ni_lock(ni);
536: err = attr_punch_hole(ni, vbo, len, &frame_size);
537: ni_unlock(ni);
538: if (!err)
539: goto ok;
540:
541: if (err != E_NTFS_NOTALIGNED)
542: goto out;
543:
544: /* Process not aligned punch. */
545: err = 0;
546: if (end > i_size)
547: end = i_size;
548: mask = frame_size - 1;
549: vbo_a = (vbo + mask) & ~mask;
550: end_a = end & ~mask;
551:
552: tmp = min(vbo_a, end);
553: from = min_t(loff_t, ni->i_valid, vbo);
554: /* Zero head of punch. */
555: if (tmp > from) {
556: err = iomap_zero_range(inode, from, tmp - from, NULL,
557: &ntfs_iomap_ops,
558: &ntfs_iomap_folio_ops, NULL);
559: if (err)
560: goto out;
561: }
562:
563: /* Aligned punch_hole. Deallocate clusters. */
564: if (end_a > vbo_a) {
565: ni_lock(ni);
566: err = attr_punch_hole(ni, vbo_a, end_a - vbo_a, NULL);
567: ni_unlock(ni);
568: if (err)
569: goto out;
570: }
571:
572: /* Zero tail of punch. */
573: if (vbo < end_a && end_a < end) {
574: err = iomap_zero_range(inode, end_a, end - end_a, NULL,
575: &ntfs_iomap_ops,
576: &ntfs_iomap_folio_ops, NULL);
577: if (err)
578: goto out;
579: }
580: } else if (mode & FALLOC_FL_COLLAPSE_RANGE) {
581: /*
582: * Write tail of the last page before removed range since
583: * it will get removed from the page cache below.
584: */
585: err = filemap_write_and_wait_range(mapping, vbo_down, vbo);
586: if (err)
587: goto out;
588:
589: /*
590: * Write data that will be shifted to preserve them
591: * when discarding page cache below.
592: */
593: err = filemap_write_and_wait_range(mapping, end, LLONG_MAX);
594: if (err)
595: goto out;
596:
597: truncate_pagecache(inode, vbo_down);
598:
599: ni_lock(ni);
600: err = attr_collapse_range(ni, vbo, len);
601: ni_unlock(ni);
602: if (err)
603: goto out;
604: } else if (mode & FALLOC_FL_INSERT_RANGE) {
605: /* Check new size. */
606: err = inode_newsize_ok(inode, new_size);
607: if (err)
608: goto out;
609:
610: /* Write out all dirty pages. */
611: err = filemap_write_and_wait_range(mapping, vbo_down,
612: LLONG_MAX);
613: if (err)
614: goto out;
615: truncate_pagecache(inode, vbo_down);
616:
617: ni_lock(ni);
618: err = attr_insert_range(ni, vbo, len);
619: ni_unlock(ni);
620: if (err)
621: goto out;
622: } else {
623: /* Check new size. */
624: u8 cluster_bits = sbi->cluster_bits;
625:
626: /* Be sure file is non resident. */
627: if (is_resident(ni)) {
628: ni_lock(ni);
629: err = attr_force_nonresident(ni);
630: ni_unlock(ni);
631: if (err)
632: goto out;
633: }
634:
635: /* generic/213: expected -ENOSPC instead of -EFBIG. */
636: if (!is_supported_holes) {
637: loff_t to_alloc = new_size - inode_get_bytes(inode);
638:
639: if (to_alloc > 0 &&
640: (to_alloc >> cluster_bits) >
641: wnd_zeroes(&sbi->used.bitmap)) {
642: err = -ENOSPC;
643: goto out;
644: }
645: }
646:
647: err = inode_newsize_ok(inode, new_size);
648: if (err)
649: goto out;
650:
651: if (new_size > i_size) {
652: /*
653: * Allocate clusters, do not change 'valid' size.
654: */
655: err = ntfs_set_size(inode, new_size);
656: if (err)
657: goto out;
658: }
659:
660: if (is_supported_holes) {
661: CLST vcn = vbo >> cluster_bits;
662: CLST cend = bytes_to_cluster(sbi, end);
663: CLST lcn, clen;
664: bool new;
665:
666: /*
667: * Allocate and zero new clusters.
668: */
669: for (; vcn < cend; vcn += clen) {
670: err = attr_data_get_block(ni, vcn, cend - vcn,
671: &lcn, &clen, &new,
672: true, NULL, false);
673: if (err)
674: goto out;
675: }
676: }
677:
678: if (mode & FALLOC_FL_KEEP_SIZE) {
679: err = ntfs_set_size(inode, i_size);
680: if (err)
681: goto out;
682: }
683: }
684:
685: ok:
686: err = file_modified(file);
687: if (err)
688: goto out;
689:
690: out:
691: if (map_locked)
692: filemap_invalidate_unlock(mapping);
693:
694: if (!err) {
695: inode_set_mtime_to_ts(inode, inode_set_ctime_current(inode));
696: mark_inode_dirty(inode);
697: }
698:
699: inode_unlock(inode);
700: return err;
701: }
SourceFile:fs/ntfs3/file.c]
|
| 246/2 |
2026/09/17 11:16 |
llm |
debugger |
0m
Model:
Tokens:
input: 68396
output: 94
thoughts: 0
|
| 247/2 |
2026/09/17 11:17 |
tool |
codeexpert |
11m
Args: map[Question:Write a patch for `ntfs_setattr` in `fs/ntfs3/file.c` to fix the race condition between `truncate_setsize` and `ntfs_set_size` by using `filemap_invalidate_lock(inode->i_mapping)` and reordering `truncate_setsize` and `ntfs_set_size` correctly.]
Results: map[Answer:To fix the race condition between `truncate_setsize` and `ntfs_set_size`, `ntfs_setattr` must:
1. Acquire `filemap_invalidate_lock(inode->i_mapping)` to protect against concurrent page faults and page cache invalidation/filling during truncation.
2. Call `ntfs_set_size(inode, newsize)` first so that underlying on-disk attribute and allocation changes are performed before mutating in-memory `i_size` and discarding page cache pages. If `ntfs_set_size` fails, the error can be returned without having corrupted the page cache or needing to roll back `i_size` with `i_size_write(inode, oldsize)`.
3. Call `truncate_setsize(inode, newsize)` only upon success of `ntfs_set_size`, while still holding `filemap_invalidate_lock(inode->i_mapping)`.
4. Release `filemap_invalidate_unlock(inode->i_mapping)`.
### Patch
```diff
--- a/fs/ntfs3/file.c
+++ b/fs/ntfs3/file.c
@@ -736,13 +736,14 @@ int ntfs_setattr(struct mnt_idmap *idmap, struct dentry *dentry,
newsize = attr->ia_size;
if (newsize != oldsize) {
- truncate_setsize(inode, newsize);
-
+ filemap_invalidate_lock(inode->i_mapping);
err = ntfs_set_size(inode, newsize);
- if (err) {
- i_size_write(inode, oldsize);
+ if (!err)
+ truncate_setsize(inode, newsize);
+ filemap_invalidate_unlock(inode->i_mapping);
+
+ if (err)
goto out;
- }
ni->std_fa |= FILE_ATTRIBUTE_ARCHIVE;
ni->ni_flags |= NI_FLAG_UPDATE_PARENT;
```
### Caveats and Unverified Aspects
- The local git repository history contains only a single commit (HEAD at Linux 7.3-rc3), so earlier commit messages, developer discussion, or mailing list revisions for this exact bug fix could not be verified against the git log.
- Testing the patch via kernel compilation and running ntfs3 xfstests was not performed since dynamic execution tools are not available.]
|
| 248/3 |
2026/09/17 11:17 |
agent |
codeexpert |
11m
Model:
Results: map[Answer:To fix the race condition between `truncate_setsize` and `ntfs_set_size`, `ntfs_setattr` must:
1. Acquire `filemap_invalidate_lock(inode->i_mapping)` to protect against concurrent page faults and page cache invalidation/filling during truncation.
2. Call `ntfs_set_size(inode, newsize)` first so that underlying on-disk attribute and allocation changes are performed before mutating in-memory `i_size` and discarding page cache pages. If `ntfs_set_size` fails, the error can be returned without having corrupted the page cache or needing to roll back `i_size` with `i_size_write(inode, oldsize)`.
3. Call `truncate_setsize(inode, newsize)` only upon success of `ntfs_set_size`, while still holding `filemap_invalidate_lock(inode->i_mapping)`.
4. Release `filemap_invalidate_unlock(inode->i_mapping)`.
### Patch
```diff
--- a/fs/ntfs3/file.c
+++ b/fs/ntfs3/file.c
@@ -736,13 +736,14 @@ int ntfs_setattr(struct mnt_idmap *idmap, struct dentry *dentry,
newsize = attr->ia_size;
if (newsize != oldsize) {
- truncate_setsize(inode, newsize);
-
+ filemap_invalidate_lock(inode->i_mapping);
err = ntfs_set_size(inode, newsize);
- if (err) {
- i_size_write(inode, oldsize);
+ if (!err)
+ truncate_setsize(inode, newsize);
+ filemap_invalidate_unlock(inode->i_mapping);
+
+ if (err)
goto out;
- }
ni->std_fa |= FILE_ATTRIBUTE_ARCHIVE;
ni->ni_flags |= NI_FLAG_UPDATE_PARENT;
```
### Caveats and Unverified Aspects
- The local git repository history contains only a single commit (HEAD at Linux 7.3-rc3), so earlier commit messages, developer discussion, or mailing list revisions for this exact bug fix could not be verified against the git log.
- Testing the patch via kernel compilation and running ntfs3 xfstests was not performed since dynamic execution tools are not available.]
Instruction:
You are a capable Linux kernel developer tasked with researching complex questions
about kernel source code. You will be given a concrete question, and need to provide
a concrete answer.
Research the question using targeted, efficient tool calls. Don't make assumptions,
or rely on your previous knowledge about the kernel source code, use available tools
to access the actual source code. Keep your tool calls focused and limited to the
scope of the question. Do not explore tangential code paths or perform unbounded searches.
Use all available sources of information:
- kernel source code
- documentation in the Documentation dir in the source tree
- git commits descriptions, git blame
Do not guess file names or file paths and attempt to read them without
verifying their existence first using content search or directory listing tools.
If a file, symbol, or directory is not found via content search (grepper) or
directory listing (codesearch-dir-index), treat it as completely absent.
Do not attempt to guess alternative names, extensions, or directories.
Tool Selection Guidelines:
1. For C functions, structs, and variables: Prefer codesearch-definition-source
or codesearch-struct-layout FIRST to retrieve clean, exact definitions
without line-number guessing.
2. If symbol lookup fails (e.g., preprocessor macros, macro-generated code, or
disabled #ifdef branches), fall back to read-file or grepper.
3. For file headers, #include directives, preprocessor macro definitions, and
non-C files (Kconfig, Makefiles, docs): Use read-file or grepper directly.
4. Be concise and targeted. Answer the question as directly and concisely as possible
once you have located the relevant code or definitions. If a symbol or function cannot
be found after targeted searches, conclude with the best available information rather
than continuing repetitive searches.
Do NOT use git-log to search for the presence or existence of files in the
repository. git-log is only for tracing commit history of files that are
already present in the current checkout. If a file does not exist in the
current checkout, it cannot be used for reproduction.
Avoid running broad git-log queries (such as searches on the entire repo)
without a specific 'PathPrefix' to restrict the scope, as these are very
expensive and will time out.
If a git-log tool call times out, do not retry the query with the same broad
scope. You must specify a tighter, narrower 'PathPrefix' for subsequent queries.
Prefer calling several tools at the same time to save round-trips.
Use set-results tool to provide results of the analysis.
It must be called exactly once before the final reply.
Ignore results of this tool.
Prompt: Write a patch for `ntfs_setattr` in `fs/ntfs3/file.c` to fix the race condition between `truncate_setsize` and `ntfs_set_size` by using `filemap_invalidate_lock(inode->i_mapping)` and reordering `truncate_setsize` and `ntfs_set_size` correctly.
|
| 249/4 |
2026/09/17 11:17 |
llm |
codeexpert |
0m
Model:
Tokens:
input: 4226
output: 38
thoughts: 134
Thoughts: **Analyzing the NTFS Attribute Setting Race Condition**
Okay, so I need to address this race condition in `ntfs_setattr` within `fs/ntfs3/file.c`. The goal is to synchronize `truncate_setsize` and `ntfs_set_size` properly. Right, the current implementation seems to be vulnerable, and we need a reliable fix. The suggested approach involves `filemap_invalidate_lock(inode->i_mapping)` β which makes sense; a good way to ensure a clean slate, particularly around file size changes β and then reordering the calls to those functions.
My immediate action will be to delve into `fs/ntfs3/file.c` and specifically examine `ntfs_setattr`. I'll want to trace the code path and understand the exact sequence in question. I'll probably start with a quick search for the function definition using `codesearch-definition-source` or maybe `read-file` to get a good overview of the function and its calls. And if that's not enough, `grepper` should reveal all the relevant calls and interactions. I'll need to clearly pinpoint where the race exists and then verify the proposed solution will effectively eliminate it, ensuring data integrity and consistency. This sounds like it should be a pretty straightforward modification.
|
| 250/4 |
2026/09/17 11:17 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:fs/ntfs3/file.c Name:ntfs_setattr]
Results: map[SourceCode: 703: /*
704: * ntfs_setattr - inode_operations::setattr
705: */
706: int ntfs_setattr(struct mnt_idmap *idmap, struct dentry *dentry,
707: struct iattr *attr)
708: {
709: struct inode *inode = d_inode(dentry);
710: struct ntfs_inode *ni = ntfs_i(inode);
711: u32 ia_valid = attr->ia_valid;
712: umode_t mode = inode->i_mode;
713: int err;
714:
715: /* Avoid any operation if inode is bad. */
716: if (unlikely(is_bad_ni(ni)))
717: return -EINVAL;
718:
719: if (unlikely(ntfs3_forced_shutdown(inode->i_sb)))
720: return -EIO;
721:
722: err = setattr_prepare(idmap, dentry, attr);
723: if (err)
724: goto out;
725:
726: if (ia_valid & ATTR_SIZE) {
727: loff_t newsize, oldsize;
728:
729: if (WARN_ON(ni->ni_flags & NI_FLAG_COMPRESSED_MASK)) {
730: /* Should never be here, see ntfs_file_open(). */
731: err = -EOPNOTSUPP;
732: goto out;
733: }
734: inode_dio_wait(inode);
735: oldsize = i_size_read(inode);
736: newsize = attr->ia_size;
737:
738: if (newsize != oldsize) {
739: truncate_setsize(inode, newsize);
740:
741: err = ntfs_set_size(inode, newsize);
742: if (err) {
743: i_size_write(inode, oldsize);
744: goto out;
745: }
746:
747: ni->std_fa |= FILE_ATTRIBUTE_ARCHIVE;
748: ni->ni_flags |= NI_FLAG_UPDATE_PARENT;
749: inode_set_mtime_to_ts(inode,
750: inode_set_ctime_current(inode));
751: }
752: }
753:
754: setattr_copy(idmap, inode, attr);
755:
756: if (!is_ni_base(ni)) {
757: ia_valid &= ~ATTR_SIZE;
758: } else if (mode != inode->i_mode) {
759: err = ntfs_acl_chmod(idmap, dentry);
760: if (err)
761: goto out;
762:
763: /* Linux 'w' -> Windows 'ro'. */
764: if (0222 & inode->i_mode)
765: ni->std_fa &= ~FILE_ATTRIBUTE_READONLY;
766: else
767: ni->std_fa |= FILE_ATTRIBUTE_READONLY;
768: }
769:
770: if (ia_valid & (ATTR_UID | ATTR_GID | ATTR_MODE))
771: ntfs_save_wsl_perm(inode, NULL);
772: mark_inode_dirty(inode);
773: out:
774: return err;
775: }
SourceFile:fs/ntfs3/file.c]
|
| 251/4 |
2026/09/17 11:17 |
llm |
codeexpert |
0m
Model:
Tokens:
input: 5766
output: 32
thoughts: 380
Thoughts: **My Analysis of the `ntfs_setattr` Implementation**
Okay, let's break this down. My initial thought is about how `ntfs_setattr` handles size changes, specifically the truncation aspect. The code snippet flags a concern when dealing with compressed files, which is interesting - that's a good place to start digging. The critical part is around the `truncate_setsize` and `ntfs_set_size` calls. I'm immediately wondering about the interaction with the filemap, and how this relates to cache coherency and data consistency.
Given my experience, I'm thinking about typical practices across different filesystems. I need to understand how other filesystems, like ext4, xfs, btrfs, f2fs, and even zonefs, handle similar `setattr` operations. I need to compare their strategies for handling `truncate_setsize` (or its equivalents) and what impact this has on the filemap.
The question of how they utilize `filemap_invalidate_lock` is key, I'll need to figure out when and how it's used during truncation. Are they using it *before* truncation to synchronize or *after* to invalidate? And most importantly, is this the right strategy for NTFS?
My next step is to dive into git history, both within the `fs/ntfs3/` directory and in other filesystems, searching for occurrences of `filemap_invalidate_lock` and `truncate_setsize`. I'll analyze how other filesystems perform this work and compare their methods to what's happening here. That should give me a good sense of whether this is the best approach, or if there might be opportunities for improvement or optimization.
|
| 252/4 |
2026/09/17 11:17 |
tool |
grepper |
0m
Args: map[Expression:filemap_invalidate_lock.*i_mapping PathPrefix:fs/]
Results: map[Output:fs/ceph/file.c=2784=static long ceph_fallocate(struct file *file, int mode,
--
fs/ceph/file.c-2841-
fs/ceph/file.c:2842: filemap_invalidate_lock(inode->i_mapping);
fs/ceph/file.c-2843- ceph_fscache_invalidate(inode, false);
--
fs/exfat/file.c=754=static int exfat_extend_valid_size(struct inode *inode, loff_t new_valid_size)
--
fs/exfat/file.c-779- */
fs/exfat/file.c:780: filemap_invalidate_lock(inode->i_mapping);
fs/exfat/file.c-781- if (gap_start < new_valid_size)
--
fs/exfat/file.c=943=static vm_fault_t exfat_page_mkwrite(struct vm_fault *vmf)
--
fs/exfat/file.c-987-
fs/exfat/file.c:988: filemap_invalidate_lock_shared(inode->i_mapping);
fs/exfat/file.c-989- ret = iomap_page_mkwrite(vmf, &exfat_iomap_ops, NULL);
--
fs/ext2/inode.c=1224=static void ext2_truncate_blocks(struct inode *inode, loff_t offset)
--
fs/ext2/inode.c-1231-
fs/ext2/inode.c:1232: filemap_invalidate_lock(inode->i_mapping);
fs/ext2/inode.c-1233- __ext2_truncate_blocks(inode, offset);
--
fs/ext2/inode.c=1237=static int ext2_setsize(struct inode *inode, loff_t newsize)
--
fs/ext2/inode.c-1254-
fs/ext2/inode.c:1255: filemap_invalidate_lock(inode->i_mapping);
fs/ext2/inode.c-1256- truncate_setsize(inode, newsize);
--
fs/ext4/inode.c=4432=static void ext4_wait_dax_page(struct inode *inode)
--
fs/ext4/inode.c-4435- schedule();
fs/ext4/inode.c:4436: filemap_invalidate_lock(inode->i_mapping);
fs/ext4/inode.c-4437-}
--
fs/ext4/inode.c=6009=int ext4_setattr(struct mnt_idmap *idmap, struct dentry *dentry,
--
fs/ext4/inode.c-6125-
fs/ext4/inode.c:6126: filemap_invalidate_lock(inode->i_mapping);
fs/ext4/inode.c-6127-
--
fs/ext4/inode.c=6740=int ext4_change_inode_journal_flag(struct inode *inode, int val)
--
fs/ext4/inode.c-6773- */
fs/ext4/inode.c:6774: filemap_invalidate_lock(inode->i_mapping);
fs/ext4/inode.c-6775- err = filemap_write_and_wait(inode->i_mapping);
--
fs/ext4/ioctl.c=375=static long swap_inode_boot_loader(struct super_block *sb,
--
fs/ext4/ioctl.c-411-
fs/ext4/ioctl.c:412: filemap_invalidate_lock(inode->i_mapping);
fs/ext4/ioctl.c-413- err = filemap_write_and_wait(inode->i_mapping);
--
fs/f2fs/data.c=3646=void f2fs_write_failed(struct inode *inode, loff_t to)
--
fs/f2fs/data.c-3655- f2fs_down_write(&F2FS_I(inode)->i_gc_rwsem[WRITE]);
fs/f2fs/data.c:3656: filemap_invalidate_lock(inode->i_mapping);
fs/f2fs/data.c-3657-
--
fs/f2fs/data.c=4187=static int f2fs_migrate_blocks(struct inode *inode, block_t start_blk,
--
fs/f2fs/data.c-4202- f2fs_down_write(&F2FS_I(inode)->i_gc_rwsem[WRITE]);
fs/f2fs/data.c:4203: filemap_invalidate_lock(inode->i_mapping);
fs/f2fs/data.c-4204-
--
fs/f2fs/file.c=73=static int f2fs_zero_post_eof_page(struct inode *inode,
--
fs/f2fs/file.c-86- if (lock)
fs/f2fs/file.c:87: filemap_invalidate_lock(inode->i_mapping);
fs/f2fs/file.c-88- /* zero or drop pages only in range of [old_size, new_size] */
--
fs/f2fs/file.c=120=static vm_fault_t f2fs_vm_page_mkwrite(struct vm_fault *vmf)
--
fs/f2fs/file.c-186- file_update_time(vmf->vma->vm_file);
fs/f2fs/file.c:187: filemap_invalidate_lock_shared(inode->i_mapping);
fs/f2fs/file.c-188-
--
fs/f2fs/file.c=637=static int finish_preallocate_blocks(struct inode *inode)
--
fs/f2fs/file.c-655- f2fs_down_write(&F2FS_I(inode)->i_gc_rwsem[WRITE]);
fs/f2fs/file.c:656: filemap_invalidate_lock(inode->i_mapping);
fs/f2fs/file.c-657-
--
fs/f2fs/file.c=1124=int f2fs_setattr(struct mnt_idmap *idmap, struct dentry *dentry,
--
fs/f2fs/file.c-1227- f2fs_down_write(&fi->i_gc_rwsem[WRITE]);
fs/f2fs/file.c:1228: filemap_invalidate_lock(inode->i_mapping);
fs/f2fs/file.c-1229-
--
fs/f2fs/file.c=1346=static int f2fs_punch_hole(struct inode *inode, loff_t offset, loff_t len)
--
fs/f2fs/file.c-1394- f2fs_down_write(&F2FS_I(inode)->i_gc_rwsem[WRITE]);
fs/f2fs/file.c:1395: filemap_invalidate_lock(inode->i_mapping);
fs/f2fs/file.c-1396-
--
fs/f2fs/file.c=1630=static int f2fs_do_collapse(struct inode *inode, loff_t offset, loff_t len)
--
fs/f2fs/file.c-1642- f2fs_down_write(&F2FS_I(inode)->i_gc_rwsem[WRITE]);
fs/f2fs/file.c:1643: filemap_invalidate_lock(inode->i_mapping);
fs/f2fs/file.c-1644-
--
fs/f2fs/file.c=1661=static int f2fs_collapse_range(struct inode *inode, loff_t offset, loff_t len)
--
fs/f2fs/file.c-1686- /* write out all moved pages, if possible */
fs/f2fs/file.c:1687: filemap_invalidate_lock(inode->i_mapping);
fs/f2fs/file.c-1688- ret = filemap_write_and_wait_range(inode->i_mapping, offset, LLONG_MAX);
--
fs/f2fs/file.c=3879=static int f2fs_ioc_release_dev_alias(struct file *filp)
--
fs/f2fs/file.c-3928-
fs/f2fs/file.c:3929: filemap_invalidate_lock(inode->i_mapping);
fs/f2fs/file.c-3930- truncate_setsize(inode, 0);
--
fs/f2fs/file.c=4206=static int f2fs_release_compress_blocks(struct file *filp, unsigned long arg)
--
fs/f2fs/file.c-4257- f2fs_down_write(&fi->i_gc_rwsem[WRITE]);
fs/f2fs/file.c:4258: filemap_invalidate_lock(inode->i_mapping);
fs/f2fs/file.c-4259-
--
fs/f2fs/file.c=4403=static int f2fs_reserve_compress_blocks(struct file *filp, unsigned long arg)
--
fs/f2fs/file.c-4435- f2fs_down_write(&fi->i_gc_rwsem[WRITE]);
fs/f2fs/file.c:4436: filemap_invalidate_lock(inode->i_mapping);
fs/f2fs/file.c-4437-
--
fs/f2fs/file.c=5631=static ssize_t f2fs_file_write_iter(struct kiocb *iocb, struct iov_iter *from)
--
fs/f2fs/file.c-5703- f2fs_down_write(&F2FS_I(inode)->i_gc_rwsem[WRITE]);
fs/f2fs/file.c:5704: filemap_invalidate_lock(inode->i_mapping);
fs/f2fs/file.c-5705- if (!f2fs_truncate(inode))
--
fs/fuse/dax.c=663=static void fuse_wait_dax_page(struct inode *inode)
--
fs/fuse/dax.c-666- schedule();
fs/fuse/dax.c:667: filemap_invalidate_lock(inode->i_mapping);
fs/fuse/dax.c-668-}
--
fs/fuse/dax.c=755=static vm_fault_t __fuse_dax_fault(struct vm_fault *vmf, unsigned int order,
--
fs/fuse/dax.c-778- */
fs/fuse/dax.c:779: filemap_invalidate_lock_shared(inode->i_mapping);
fs/fuse/dax.c-780- ret = dax_iomap_fault(vmf, order, &pfn, &error, &fuse_iomap_ops);
--
fs/fuse/dax.c=914=inode_inline_reclaim_one_dmap(struct fuse_conn_dax *fcd, struct inode *inode,
--
fs/fuse/dax.c-923-
fs/fuse/dax.c:924: filemap_invalidate_lock(inode->i_mapping);
fs/fuse/dax.c-925-
--
fs/fuse/dax.c=1076=static int lookup_and_reclaim_dmap(struct fuse_conn_dax *fcd,
--
fs/fuse/dax.c-1085-
fs/fuse/dax.c:1086: filemap_invalidate_lock(inode->i_mapping);
fs/fuse/dax.c-1087- ret = fuse_dax_break_layouts(inode, dmap_start, dmap_end);
--
fs/fuse/file.c=250=static int fuse_open(struct inode *inode, struct file *file)
--
fs/fuse/file.c-271- if (dax_truncate) {
fs/fuse/file.c:272: filemap_invalidate_lock(inode->i_mapping);
fs/fuse/file.c-273- err = fuse_dax_break_layouts(inode, 0, -1);
--
fs/fuse/file.c=2832=static long fuse_file_fallocate(struct file *file, int mode, loff_t offset,
--
fs/fuse/file.c-2859- if (block_faults) {
fs/fuse/file.c:2860: filemap_invalidate_lock(inode->i_mapping);
fs/fuse/file.c-2861- err = fuse_dax_break_layouts(inode, 0, -1);
--
fs/ntfs/file.c=254=static int ntfs_setattr_size(struct inode *vi, struct iattr *attr)
--
fs/ntfs/file.c-278- */
fs/ntfs/file.c:279: filemap_invalidate_lock(vi->i_mapping);
fs/ntfs/file.c-280- if (attr->ia_size > old_size) {
--
fs/ntfs/file.c=1127=static long ntfs_fallocate(struct file *file, int mode, loff_t offset, loff_t len)
--
fs/ntfs/file.c-1170- /* Take invalidate_lock for all fallocate operations to prevent races */
fs/ntfs/file.c:1171: filemap_invalidate_lock(vi->i_mapping);
fs/ntfs/file.c-1172-
--
fs/smb/client/file.c=993=static int cifs_do_truncate(const unsigned int xid, struct dentry *dentry)
--
fs/smb/client/file.c-1005-
fs/smb/client/file.c:1006: filemap_invalidate_lock(inode->i_mapping);
fs/smb/client/file.c-1007-
--
fs/smb/client/smb2ops.c=3508=static long smb3_zero_range(struct file *file, struct cifs_tcon *tcon,
--
fs/smb/client/smb2ops.c-3531-
fs/smb/client/smb2ops.c:3532: filemap_invalidate_lock(inode->i_mapping);
fs/smb/client/smb2ops.c-3533-
--
fs/smb/client/smb2ops.c=3592=static long smb3_punch_hole(struct file *file, struct cifs_tcon *tcon,
--
fs/smb/client/smb2ops.c-3610-
fs/smb/client/smb2ops.c:3611: filemap_invalidate_lock(inode->i_mapping);
fs/smb/client/smb2ops.c-3612- /*
--
fs/smb/client/smb2ops.c=4014=static long smb3_collapse_range(struct file *file, struct cifs_tcon *tcon,
--
fs/smb/client/smb2ops.c-4032-
fs/smb/client/smb2ops.c:4033: filemap_invalidate_lock(inode->i_mapping);
fs/smb/client/smb2ops.c-4034- rc = filemap_write_and_wait_range(inode->i_mapping,
--
fs/smb/client/smb2ops.c=4078=static long smb3_insert_range(struct file *file, struct cifs_tcon *tcon,
--
fs/smb/client/smb2ops.c-4108-
fs/smb/client/smb2ops.c:4109: filemap_invalidate_lock(inode->i_mapping);
fs/smb/client/smb2ops.c-4110- rc = filemap_write_and_wait_range(inode->i_mapping,
--
fs/udf/file.c=89=static ssize_t udf_file_write_iter(struct kiocb *iocb, struct iov_iter *from)
--
fs/udf/file.c-104- iocb->ki_pos + iov_iter_count(from))) {
fs/udf/file.c:105: filemap_invalidate_lock(inode->i_mapping);
fs/udf/file.c-106- retval = udf_expand_file_adinicb(inode);
--
fs/udf/file.c=215=static int udf_setattr(struct mnt_idmap *idmap, struct dentry *dentry,
--
fs/udf/file.c-236- attr->ia_size != i_size_read(inode)) {
fs/udf/file.c:237: filemap_invalidate_lock(inode->i_mapping);
fs/udf/file.c-238- error = udf_setsize(inode, attr->ia_size);
--
fs/verity/read_metadata.c=16=static int fsverity_read_merkle_tree(struct inode *inode,
--
fs/verity/read_metadata.c-38- if (inode->i_sb->s_vop->readahead_merkle_tree) {
fs/verity/read_metadata.c:39: filemap_invalidate_lock_shared(inode->i_mapping);
fs/verity/read_metadata.c-40- inode->i_sb->s_vop->readahead_merkle_tree(
--
fs/xfs/xfs_bmap_util.c=1537=xfs_swap_extents(
--
fs/xfs/xfs_bmap_util.c-1558- lock_two_nondirectories(VFS_I(ip), VFS_I(tip));
fs/xfs/xfs_bmap_util.c:1559: filemap_invalidate_lock_two(VFS_I(ip)->i_mapping,
fs/xfs/xfs_bmap_util.c-1560- VFS_I(tip)->i_mapping);
--
fs/xfs/xfs_inode.c=2792=xfs_ilock2_io_mmap(
--
fs/xfs/xfs_inode.c-2810- } else
fs/xfs/xfs_inode.c:2811: filemap_invalidate_lock_two(VFS_I(ip1)->i_mapping,
fs/xfs/xfs_inode.c-2812- VFS_I(ip2)->i_mapping);
--
fs/xfs/xfs_iomap.c=2134=xfs_buffered_write_iomap_end(
--
fs/xfs/xfs_iomap.c-2167- } else {
fs/xfs/xfs_iomap.c:2168: filemap_invalidate_lock(inode->i_mapping);
fs/xfs/xfs_iomap.c-2169- iomap_write_delalloc_release(inode, start_byte, end_byte, flags,
--
fs/zonefs/file.c=203=int zonefs_file_truncate(struct inode *inode, loff_t isize)
--
fs/zonefs/file.c-228- /* Serialize against page faults */
fs/zonefs/file.c:229: filemap_invalidate_lock(inode->i_mapping);
fs/zonefs/file.c-230-
--
fs/zonefs/file.c=297=static vm_fault_t zonefs_filemap_page_mkwrite(struct vm_fault *vmf)
--
fs/zonefs/file.c-315- /* Serialize against truncates */
fs/zonefs/file.c:316: filemap_invalidate_lock_shared(inode->i_mapping);
fs/zonefs/file.c-317- ret = iomap_page_mkwrite(vmf, &zonefs_write_iomap_ops, NULL);
]
|
| 253/4 |
2026/09/17 11:17 |
llm |
codeexpert |
0m
Model:
Tokens:
input: 11848
output: 32
thoughts: 100
Thoughts: **Investigating NTFS3 File Size Invalidation**
Okay, so I need to figure out the right approach for handling file size invalidation in this NTFS3 context. My initial instinct was to check out the existing practices in `fs/ntfs/file.c` or perhaps other filesystems as a general reference, but actually, `fs/ntfs3` is *the* place to focus.
Now, the crucial question is, how does `fs/ntfs3` currently interact with the `filemap_invalidate_lock` mechanism, if at all? I'm also curious about the behavior of `ntfs_set_size` within that module, as it likely plays a pivotal role.
My next step is to perform a targeted grep search within `fs/ntfs3`. I'll look specifically for instances of `filemap_invalidate_lock` and, more broadly, `invalidate_lock` to quickly identify relevant code sections and understand the existing implementation details. This should provide the key insights needed to proceed.
|
| 254/4 |
2026/09/17 11:17 |
tool |
grepper |
0m
Args: map[Expression:filemap_invalidate_.*lock PathPrefix:fs/ntfs3]
Results: map[Output:fs/ntfs3/file.c=466=static long ntfs_fallocate(struct file *file, int mode, loff_t vbo, loff_t len)
--
fs/ntfs3/file.c-519- inode_dio_wait(inode);
fs/ntfs3/file.c:520: filemap_invalidate_lock(mapping);
fs/ntfs3/file.c-521- map_locked = true;
--
fs/ntfs3/file.c-691- if (map_locked)
fs/ntfs3/file.c:692: filemap_invalidate_unlock(mapping);
fs/ntfs3/file.c-693-
]
|
| 255/4 |
2026/09/17 11:18 |
llm |
codeexpert |
0m
Model:
Tokens:
input: 12389
output: 37
thoughts: 54
Thoughts: Okay, here's my take on those thoughts, tailored for an expert audience:
**Analyzing `ntfs_fallocate` in `fs/ntfs3/file.c`**
Alright, let's dive into `ntfs_fallocate` within the NTFS3 implementation. My initial focus is going to be on the regions around lines 510-530 and then again around 680-700 within `file.c`. I'm expecting to see the core logic for how fallocate is handled, specifically within this specific filesystem. I want to see what steps are taken to pre-allocate blocks, potentially extending the file size, and the error handling for what can go wrong during this process. I'm also interested to see how it potentially interacts with the metadata of the NTFS file system, particularly the MFT. I'll need to observe any interactions with the journal or other concurrency control. I'm hoping to quickly identify any potential performance bottlenecks or edge cases.
|
| 256/4 |
2026/09/17 11:18 |
tool |
read-file |
0m
Args: map[File:fs/ntfs3/file.c FirstLine:500 LineCount:40]
Results: map[Contents: 500: mode);
501: return -EOPNOTSUPP;
502: }
503:
504: ntfs_set_state(sbi, NTFS_DIRTY_DIRTY);
505:
506: inode_lock(inode);
507: i_size = inode->i_size;
508: new_size = max(end, i_size);
509: map_locked = false;
510:
511: if (WARN_ON(ni->ni_flags & NI_FLAG_COMPRESSED_MASK)) {
512: /* Should never be here, see ntfs_file_open. */
513: err = -EOPNOTSUPP;
514: goto out;
515: }
516:
517: if (mode & (FALLOC_FL_PUNCH_HOLE | FALLOC_FL_COLLAPSE_RANGE |
518: FALLOC_FL_INSERT_RANGE)) {
519: inode_dio_wait(inode);
520: filemap_invalidate_lock(mapping);
521: map_locked = true;
522: }
523:
524: if (mode & FALLOC_FL_PUNCH_HOLE) {
525: u32 frame_size;
526: loff_t mask, vbo_a, end_a, tmp, from;
527:
528: err = filemap_write_and_wait_range(mapping, vbo_down,
529: LLONG_MAX);
530: if (err)
531: goto out;
532:
533: truncate_pagecache(inode, vbo_down);
534:
535: ni_lock(ni);
536: err = attr_punch_hole(ni, vbo, len, &frame_size);
537: ni_unlock(ni);
538: if (!err)
539: goto ok;
]
|
| 257/4 |
2026/09/17 11:18 |
llm |
codeexpert |
0m
Model:
Tokens:
input: 13285
output: 37
thoughts: 25
Thoughts: Okay, here's my summary, taking on the persona you requested:
**Peeking into `ntfs_fallocate`'s Inner Workings**
Alright, let's dive back into `ntfs_fallocate`. Specifically, I'm going to revisit lines 680 to 705 to refresh my memory on the critical operations in this function. I'm especially interested in how it handles space allocation and deallocation within the NTFS file system. I need to keep the high-level picture in my head as I review the code.
|
| 258/4 |
2026/09/17 11:18 |
tool |
read-file |
0m
Args: map[File:fs/ntfs3/file.c FirstLine:680 LineCount:35]
Results: map[Contents: 680: if (err)
681: goto out;
682: }
683: }
684:
685: ok:
686: err = file_modified(file);
687: if (err)
688: goto out;
689:
690: out:
691: if (map_locked)
692: filemap_invalidate_unlock(mapping);
693:
694: if (!err) {
695: inode_set_mtime_to_ts(inode, inode_set_ctime_current(inode));
696: mark_inode_dirty(inode);
697: }
698:
699: inode_unlock(inode);
700: return err;
701: }
702:
703: /*
704: * ntfs_setattr - inode_operations::setattr
705: */
706: int ntfs_setattr(struct mnt_idmap *idmap, struct dentry *dentry,
707: struct iattr *attr)
708: {
709: struct inode *inode = d_inode(dentry);
710: struct ntfs_inode *ni = ntfs_i(inode);
711: u32 ia_valid = attr->ia_valid;
712: umode_t mode = inode->i_mode;
713: int err;
714:
]
|
| 259/4 |
2026/09/17 11:18 |
llm |
codeexpert |
0m
Model:
Tokens:
input: 13914
output: 39
thoughts: 28
Thoughts: Here's my analysis of the provided context, expressed as a first-person expert summary:
**Diving into `ntfs_set_size` and Related Functionality**
Okay, so we're focusing in on `ntfs_set_size`. My initial thought is that we need to examine this function, its implementation, and most importantly, *all* of its call sites. As a seasoned professional, I know that just looking at the function in isolation is rarely enough. I need to understand the larger context. Are we talking about resizing the volume itself? Adjusting file sizes within the NTFS file system? What are the potential impacts of this size adjustment? Is this a core NTFS function, or is it abstracted by layers of code?
I need to understand what other functions interact with `ntfs_set_size` and why, so I can see what its implications are in a variety of situations. I want to see if there are any potential race conditions or locking issues involved when making the changes. Are there any error handling subtleties that require my scrutiny? What edge cases might not be covered, causing unexpected behavior? Essentially, I need a holistic view of its usage and consequences within the larger NTFS ecosystem.
|
| 260/4 |
2026/09/17 11:18 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:fs/ntfs3/file.c Name:ntfs_set_size]
Results: map[SourceCode: 883: int ntfs_set_size(struct inode *inode, u64 new_size)
884: {
885: struct super_block *sb = inode->i_sb;
886: struct ntfs_sb_info *sbi = sb->s_fs_info;
887: struct ntfs_inode *ni = ntfs_i(inode);
888: int err;
889:
890: /* Check for maximum file size. */
891: if (is_sparsed(ni) || is_compressed(ni)) {
892: if (new_size > sbi->maxbytes_sparse) {
893: return -EFBIG;
894: }
895: } else if (new_size > sbi->maxbytes) {
896: return -EFBIG;
897: }
898:
899: /* Mark rw ntfs as dirty. It will be cleared at umount. */
900: ntfs_set_state(sbi, NTFS_DIRTY_DIRTY);
901:
902: ni_lock(ni);
903: down_write(&ni->file.run_lock);
904: if (new_size < ni->i_valid)
905: ni->i_valid = new_size;
906:
907: /* last 'true' means keep preallocated. */
908: err = attr_set_size(ni, ATTR_DATA, ni->file.ads.name, ni->file.ads.len,
909: &ni->file.run, new_size, &ni->i_valid, true);
910:
911: up_write(&ni->file.run_lock);
912: ni_unlock(ni);
913:
914: return err;
915: }
SourceFile:fs/ntfs3/inode.c]
|
| 261/4 |
2026/09/17 11:18 |
llm |
codeexpert |
0m
Model:
Tokens:
input: 14793
output: 30
thoughts: 92
Thoughts: Okay, here's my thought process on this, distilled into a first-person summary as you requested, presented for a fellow expert:
**Investigating `ntfs_set_size` Functionality**
Right, let's break this down. My understanding is `ntfs_set_size` is responsible for setting the attribute size on disk within the NTFS filesystem, handling the underlying metadata changes. But before I dive deeper, I always try to see if there's been any prior art or similar issues handled in the codebase. Let me quickly check the history: I should search git commits, specifically in `fs/ntfs3` or maybe even other filesystems as a comparison to see how similar functions have been handled in the past. Specifically, I'll be looking for patches touching `ntfs_setattr`, `truncate_setsize`, or even `filemap_invalidate_lock`. That could give me some clues about potential concurrency issues, edge cases, or optimizations that have already been considered. To focus it a bit more, I should generate a list of the commits that relate to the file. I will use `git log` with the file path `fs/ntfs3/file.c` to see what changes have been made to this file and if there is any interesting information related to size. That should be a good starting point to build a mental model of the relevant code.
|
| 262/4 |
2026/09/17 11:19 |
tool |
git-log |
0m
Args: map[Count:20 PathPrefix:fs/ntfs3/file.c]
Results: map[Output:fd73f4a66598 Linux 7.3-rc3
]
|
| 263/4 |
2026/09/17 11:19 |
llm |
codeexpert |
0m
Model:
Tokens:
input: 15239
output: 22
thoughts: 36
Thoughts: Okay, here's my interpretation of those thoughts, presented as my own mental process, given my expertise:
**Debugging a Git History Snag**
Hmm, that's odd. `git-log` is only showing me Linux 7.3-rc3? That's definitely not the full picture. My gut tells me something is limiting the output. Is the command using a `Count` parameter thatβs artificially truncating the history? Or, even worse, has the history been shallowly cloned, meaning I don't have the entire repository history locally?
Let's start by ruling out the obvious. I need to re-run the `git-log` command, but this time, I'll strip out any `Count` argument that might be in play. That's the first test. I need to make sure I'm getting the complete history.
If that doesn't fix it, and I still get a limited result, I can try running it without `MessageRegexps` to see if there is some filter interfering.
|
| 264/4 |
2026/09/17 11:19 |
tool |
git-log |
0m
Args: map[MessageRegexps:[ntfs_setattr]]
Results:
|
| 265/4 |
2026/09/17 11:19 |
llm |
codeexpert |
0m
Model:
Tokens:
input: 15532
output: 31
thoughts: 39
Thoughts: Okay, here's my interpretation of those thoughts, framed as a first-person summary, keeping in mind my expertise:
**Investigating Potential Issues in NTFS File Truncation**
Right, let's dive in. I need to get a handle on the history related to potential problems around `truncate_setsize` and `filemap_invalidate_lock`, specifically within the NTFS filesystem's file handling. I'm thinking a deep dive into the `git log` is the best starting point. I'll focus my query on commits that touched `fs/ntfs/file.c` or other files that would be closely related to file truncation logic. The goal here is to identify recent changes, potential regressions, or any significant modifications that might have introduced or exacerbated whatever issue I'm investigating. I'll be looking for changes that might have subtly altered the behavior of those specific functions, or how they interact. A targeted `git log` search is the most efficient way to isolate those specific commits from the whole codebase and start to build a chronology of potential culprits.
|
| 266/4 |
2026/09/17 11:19 |
tool |
git-log |
0m
Args: map[CodeRegexp:filemap_invalidate_lock PathPrefix:fs/]
Results: map[Output:fd73f4a66598 Linux 7.3-rc3
]
|
| 267/4 |
2026/09/17 11:19 |
llm |
codeexpert |
0m
Model:
Tokens:
input: 15858
output: 20
thoughts: 35
Thoughts: Here's my take:
**Investigating a Git HEAD Mystery**
Okay, so HEAD is pointing at Linux 7.3-rc3, but is this a full repository, or is it a shallow clone, or maybe even just a single commit? I need to figure this out quickly. I can't start work on this until I understand the scope of the clone. Let's start by running `git show` on HEAD. That should give me the information I need: the commit details, but also hopefully some clues about its origin and whether this is a full repository or a partial one.
|
| 268/4 |
2026/09/17 11:19 |
tool |
git-show |
0m
Args: map[Commit:HEAD Stat:true]
Results: map[Output:commit fd73f4a6659897191fa0d40695fe370925dd3780
Author: Linus Torvalds <torvalds@linux-foundation.org>
Date: Sun Sep 13 14:38:02 2026 -0700
Linux 7.3-rc3
.clang-format | 808 +
.clippy.toml | 21 +
.cocciconfig | 3 +
.editorconfig | 27 +
.get_maintainer.ignore | 9 +
.gitattributes | 5 +
.gitignore | 196 +
.mailmap | 996 +
.pylintrc | 2 +
.rustfmt.toml | 12 +
COPYING | 20 +
CREDITS | 4651 +
Documentation/.gitignore | 3 +
Documentation/.renames.txt | 1185 +
Documentation/ABI/README | 98 +
.../ABI/obsolete/automount-tracefs-debugfs | 20 +
Documentation/ABI/obsolete/o2cb | 11 +
Documentation/ABI/obsolete/procfs-i8k | 10 +
Documentation/ABI/obsolete/sysfs-bus-iio | 174 +
Documentation/ABI/obsolete/sysfs-bus-usb | 31 +
Documentation/ABI/obsolete/sysfs-class-typec | 48 +
Documentation/ABI/obsolete/sysfs-cpuidle | 9 +
.../ABI/obsolete/sysfs-driver-hid-roccat-arvo | 53 +
.../ABI/obsolete/sysfs-driver-hid-roccat-isku | 153 +
.../ABI/obsolete/sysfs-driver-hid-roccat-koneplus | 145 +
.../ABI/obsolete/sysfs-driver-hid-roccat-konepure | 105 +
.../ABI/obsolete/sysfs-driver-hid-roccat-kovaplus | 116 +
.../ABI/obsolete/sysfs-driver-hid-roccat-lua | 7 +
.../ABI/obsolete/sysfs-driver-hid-roccat-pyra | 126 +
.../ABI/obsolete/sysfs-driver-hid-roccat-ryos | 178 +
.../ABI/obsolete/sysfs-driver-hid-roccat-savu | 77 +
.../ABI/obsolete/sysfs-driver-intel_pmc_bxt | 22 +
Documentation/ABI/obsolete/sysfs-driver-ivpu | 30 +
.../ABI/obsolete/sysfs-driver-samsung-laptop | 10 +
Documentation/ABI/obsolete/sysfs-firmware-acpi | 8 +
Documentation/ABI/obsolete/sysfs-gpio | 40 +
.../ABI/obsolete/sysfs-kernel-fadump_enabled | 9 +
.../ABI/obsolete/sysfs-kernel-fadump_registered | 10 +
.../ABI/obsolete/sysfs-kernel-fadump_release_mem | 10 +
.../ABI/obsolete/sysfs-kernel-kexec-kdump | 71 +
.../ABI/obsolete/sysfs-platform-ideapad-laptop | 8 +
Documentation/ABI/removed/devfs | 13 +
Documentation/ABI/removed/dv1394 | 14 +
Documentation/ABI/removed/ip_queue | 9 +
Documentation/ABI/removed/net_dma | 8 +
Documentation/ABI/removed/o2cb | 10 +
Documentation/ABI/removed/raw1394 | 16 +
Documentation/ABI/removed/sysfs-bus-nfit | 17 +
Documentation/ABI/removed/sysfs-class-cxl | 272 +
Documentation/ABI/removed/sysfs-class-rfkill | 13 +
Documentation/ABI/removed/sysfs-firmware-efi-vars | 12 +
.../removed/sysfs-kernel-fadump_release_opalcore | 9 +
Documentation/ABI/removed/sysfs-kernel-uids | 14 +
Documentation/ABI/removed/sysfs-mce | 37 +
.../ABI/removed/sysfs-selinux-checkreqprot | 26 +
Documentation/ABI/removed/sysfs-selinux-disable | 29 +
Documentation/ABI/removed/sysfs-selinux-user | 12 +
Documentation/ABI/removed/video1394 | 17 +
Documentation/ABI/stable/configfs-nvmet | 352 +
Documentation/ABI/stable/firewire-cdev | 111 +
Documentation/ABI/stable/o2cb | 10 +
Documentation/ABI/stable/procfs-audit_loginuid | 27 +
Documentation/ABI/stable/syscalls | 10 +
Documentation/ABI/stable/sysfs-acpi-pmprofile | 28 +
Documentation/ABI/stable/sysfs-block | 941 +
Documentation/ABI/stable/sysfs-bus-firewire | 136 +
Documentation/ABI/stable/sysfs-bus-fsl-mc | 19 +
Documentation/ABI/stable/sysfs-bus-mhi | 44 +
Documentation/ABI/stable/sysfs-bus-nvmem | 50 +
Documentation/ABI/stable/sysfs-bus-usb | 142 +
Documentation/ABI/stable/sysfs-bus-vmbus | 187 +
Documentation/ABI/stable/sysfs-bus-w1 | 12 +
Documentation/ABI/stable/sysfs-bus-xen-backend | 84 +
Documentation/ABI/stable/sysfs-class-backlight | 63 +
Documentation/ABI/stable/sysfs-class-bluetooth | 9 +
Documentation/ABI/stable/sysfs-class-infiniband | 784 +
Documentation/ABI/stable/sysfs-class-rfkill | 93 +
Documentation/ABI/stable/sysfs-class-tpm | 210 +
Documentation/ABI/stable/sysfs-class-ubi | 221 +
Documentation/ABI/stable/sysfs-class-udc | 93 +
Documentation/ABI/stable/sysfs-devices | 32 +
Documentation/ABI/stable/sysfs-devices-node | 238 +
Documentation/ABI/stable/sysfs-devices-system-cpu | 117 +
.../ABI/stable/sysfs-devices-system-xen_memory | 86 +
Documentation/ABI/stable/sysfs-driver-aspeed-vuart | 24 +
Documentation/ABI/stable/sysfs-driver-dma-idxd | 376 +
Documentation/ABI/stable/sysfs-driver-dma-ioatdma | 30 +
.../ABI/stable/sysfs-driver-firmware-zynqmp | 256 +
Documentation/ABI/stable/sysfs-driver-ib_srp | 192 +
Documentation/ABI/stable/sysfs-driver-misc-cp500 | 25 +
Documentation/ABI/stable/sysfs-driver-mlxreg-io | 815 +
Documentation/ABI/stable/sysfs-driver-qaic | 19 +
Documentation/ABI/stable/sysfs-driver-qla2xxx | 8 +
Documentation/ABI/stable/sysfs-driver-speakup | 394 +
Documentation/ABI/stable/sysfs-driver-usb-usbtmc | 27 +
Documentation/ABI/stable/sysfs-driver-w1_ds2438 | 13 +
Documentation/ABI/stable/sysfs-driver-w1_ds28e04 | 15 +
Documentation/ABI/stable/sysfs-driver-w1_ds28ea00 | 6 +
Documentation/ABI/stable/sysfs-firmware-opal-dump | 46 +
Documentation/ABI/stable/sysfs-firmware-opal-elog | 62 +
Documentation/ABI/stable/sysfs-fs-orangefs | 87 +
Documentation/ABI/stable/sysfs-hypervisor-xen | 135 +
Documentation/ABI/stable/sysfs-kernel-notes | 5 +
.../ABI/stable/sysfs-kernel-time-aux-clocks | 5 +
Documentation/ABI/stable/sysfs-module | 47 +
Documentation/ABI/stable/sysfs-nvme | 453 +
Documentation/ABI/stable/sysfs-platform-wmi-bmof | 7 +
Documentation/ABI/stable/sysfs-transport-srp | 58 +
Documentation/ABI/stable/thermal-notification | 4 +
Documentation/ABI/stable/vdso | 37 +
Documentation/ABI/testing/amdpmf-interface | 73 +
Documentation/ABI/testing/configfs-acpi | 52 +
Documentation/ABI/testing/configfs-iio | 34 +
Documentation/ABI/testing/configfs-most | 241 +
Documentation/ABI/testing/configfs-rdma_cm | 34 +
.../ABI/testing/configfs-spear-pcie-gadget | 33 +
Documentation/ABI/testing/configfs-stp-policy | 48 +
.../ABI/testing/configfs-stp-policy-p_sys-t | 41 +
.../ABI/testing/configfs-thunderbolt_stream | 98 +
Documentation/ABI/testing/configfs-tsm-report | 161 +
Documentation/ABI/testing/configfs-usb-gadget | 158 +
Documentation/ABI/testing/configfs-usb-gadget-acm | 15 +
Documentation/ABI/testing/configfs-usb-gadget-ecm | 20 +
Documentation/ABI/testing/configfs-usb-gadget-eem | 16 +
Documentation/ABI/testing/configfs-usb-gadget-ffs | 17 +
Documentation/ABI/testing/configfs-usb-gadget-hid | 13 +
.../ABI/testing/configfs-usb-gadget-loopback | 10 +
.../ABI/testing/configfs-usb-gadget-mass-storage | 41 +
Documentation/ABI/testing/configfs-usb-gadget-midi | 15 +
.../ABI/testing/configfs-usb-gadget-midi2 | 54 +
Documentation/ABI/testing/configfs-usb-gadget-ncm | 15 +
Documentation/ABI/testing/configfs-usb-gadget-obex | 9 +
.../ABI/testing/configfs-usb-gadget-phonet | 8 +
.../ABI/testing/configfs-usb-gadget-printer | 11 +
.../ABI/testing/configfs-usb-gadget-rndis | 19 +
.../ABI/testing/configfs-usb-gadget-serial | 9 +
.../ABI/testing/configfs-usb-gadget-sourcesink | 16 +
.../ABI/testing/configfs-usb-gadget-subset | 16 +
Documentation/ABI/testing/configfs-usb-gadget-tcm | 6 +
Documentation/ABI/testing/configfs-usb-gadget-uac1 | 41 +
.../ABI/testing/configfs-usb-gadget-uac1_legacy | 9 +
Documentation/ABI/testing/configfs-usb-gadget-uac2 | 51 +
Documentation/ABI/testing/configfs-usb-gadget-uvc | 438 +
Documentation/ABI/testing/debugfs-alienware-wmi | 64 +
Documentation/ABI/testing/debugfs-amd-iommu | 131 +
Documentation/ABI/testing/debugfs-cdns-pcie | 5 +
Documentation/ABI/testing/debugfs-cec-error-inj | 40 +
Documentation/ABI/testing/debugfs-cros-ec | 78 +
Documentation/ABI/testing/debugfs-cxl | 157 +
Documentation/ABI/testing/debugfs-dell-wmi-ddv | 34 +
Documentation/ABI/testing/debugfs-driver-dcc | 127 +
Documentation/ABI/testing/debugfs-driver-genwqe | 91 +
.../ABI/testing/debugfs-driver-habanalabs | 323 +
Documentation/ABI/testing/debugfs-driver-qat | 109 +
.../ABI/testing/debugfs-driver-qat_telemetry | 259 +
Documentation/ABI/testing/debugfs-dwc-pcie | 157 +
Documentation/ABI/testing/debugfs-ec | 21 +
Documentation/ABI/testing/debugfs-hisi-hpre | 200 +
Documentation/ABI/testing/debugfs-hisi-migration | 25 +
Documentation/ABI/testing/debugfs-hisi-sec | 173 +
Documentation/ABI/testing/debugfs-hisi-zip | 174 +
Documentation/ABI/testing/debugfs-hyperv | 23 +
Documentation/ABI/testing/debugfs-ideapad | 19 +
Documentation/ABI/testing/debugfs-iio-ad9467 | 39 +
Documentation/ABI/testing/debugfs-iio-backend | 20 +
Documentation/ABI/testing/debugfs-intel-iommu | 276 +
Documentation/ABI/testing/debugfs-moxtet | 35 +
Documentation/ABI/testing/debugfs-msi-wmi-platform | 14 +
Documentation/ABI/testing/debugfs-olpc | 16 +
Documentation/ABI/testing/debugfs-pcie-ptm | 70 +
Documentation/ABI/testing/debugfs-pfo-nx-crypto | 45 +
Documentation/ABI/testing/debugfs-scmi | 70 +
Documentation/ABI/testing/debugfs-scmi-raw | 208 +
Documentation/ABI/testing/debugfs-tpmi | 40 +
Documentation/ABI/testing/debugfs-vfio | 57 +
Documentation/ABI/testing/debugfs-wilco-ec | 45 +
Documentation/ABI/testing/dell-smbios-wmi | 41 +
Documentation/ABI/testing/dev-kmsg | 127 +
Documentation/ABI/testing/devlink-resource-mlxsw | 33 +
Documentation/ABI/testing/evm | 109 +
Documentation/ABI/testing/gpio-cdev | 28 +
Documentation/ABI/testing/ima_policy | 196 +
Documentation/ABI/testing/ppc-memtrace | 46 +
Documentation/ABI/testing/procfs-attr-current | 20 +
Documentation/ABI/testing/procfs-attr-exec | 20 +
Documentation/ABI/testing/procfs-attr-prev | 19 +
Documentation/ABI/testing/procfs-diskstats | 43 +
.../ABI/testing/procfs-nfsd-reply_cache_stats | 38 +
Documentation/ABI/testing/procfs-smaps_rollup | 42 +
Documentation/ABI/testing/pstore | 47 +
Documentation/ABI/testing/rtc-cdev | 50 +
Documentation/ABI/testing/securityfs-secrets-coco | 51 +
Documentation/ABI/testing/sysfs-amd-pmc | 13 +
Documentation/ABI/testing/sysfs-amd-pmf | 13 +
Documentation/ABI/testing/sysfs-ata | 140 +
.../ABI/testing/sysfs-auxdisplay-linedisp | 90 +
Documentation/ABI/testing/sysfs-block-aoe | 45 +
Documentation/ABI/testing/sysfs-block-bcache | 149 +
Documentation/ABI/testing/sysfs-block-device | 119 +
Documentation/ABI/testing/sysfs-block-dm | 47 +
Documentation/ABI/testing/sysfs-block-loop | 50 +
Documentation/ABI/testing/sysfs-block-rnbd | 64 +
Documentation/ABI/testing/sysfs-block-rssd | 5 +
Documentation/ABI/testing/sysfs-block-zram | 166 +
Documentation/ABI/testing/sysfs-bus-acpi | 98 +
Documentation/ABI/testing/sysfs-bus-amba | 20 +
Documentation/ABI/testing/sysfs-bus-auxiliary | 9 +
Documentation/ABI/testing/sysfs-bus-bcma | 31 +
Documentation/ABI/testing/sysfs-bus-cdx | 121 +
Documentation/ABI/testing/sysfs-bus-coreboot | 45 +
.../ABI/testing/sysfs-bus-coresight-devices-cti | 247 +
.../sysfs-bus-coresight-devices-dummy-source | 21 +
.../ABI/testing/sysfs-bus-coresight-devices-etb10 | 88 +
.../ABI/testing/sysfs-bus-coresight-devices-etm3x | 328 +
.../ABI/testing/sysfs-bus-coresight-devices-etm4x | 532 +
.../ABI/testing/sysfs-bus-coresight-devices-funnel | 18 +
.../ABI/testing/sysfs-bus-coresight-devices-stm | 59 +
.../ABI/testing/sysfs-bus-coresight-devices-tmc | 115 +
.../ABI/testing/sysfs-bus-coresight-devices-tpda | 69 +
.../ABI/testing/sysfs-bus-coresight-devices-tpdm | 290 +
.../ABI/testing/sysfs-bus-coresight-devices-trbe | 20 +
.../testing/sysfs-bus-coresight-devices-ultra_smb | 31 +
Documentation/ABI/testing/sysfs-bus-counter | 477 +
Documentation/ABI/testing/sysfs-bus-css | 56 +
Documentation/ABI/testing/sysfs-bus-cxl | 646 +
Documentation/ABI/testing/sysfs-bus-dax | 177 +
Documentation/ABI/testing/sysfs-bus-dfl | 17 +
.../ABI/testing/sysfs-bus-dfl-devices-emif | 25 +
.../ABI/testing/sysfs-bus-dfl-devices-n3000-nios | 47 +
.../ABI/testing/sysfs-bus-event_source-devices | 24 +
.../testing/sysfs-bus-event_source-devices-caps | 24 +
.../testing/sysfs-bus-event_source-devices-dfl_fme | 104 +
.../ABI/testing/sysfs-bus-event_source-devices-dsa | 30 +
.../testing/sysfs-bus-event_source-devices-events | 102 +
.../testing/sysfs-bus-event_source-devices-format | 21 +
.../sysfs-bus-event_source-devices-hisi_ptt | 113 +
.../testing/sysfs-bus-event_source-devices-hv_24x7 | 98 +
.../testing/sysfs-bus-event_source-devices-hv_gpci | 242 +
.../testing/sysfs-bus-event_source-devices-iommu | 37 +
.../testing/sysfs-bus-event_source-devices-rdpmc | 44 +
.../testing/sysfs-bus-event_source-devices-uncore | 13 +
.../testing/sysfs-bus-event_source-devices-vpa-dtl | 25 +
.../testing/sysfs-bus-event_source-devices-vpa-pmu | 25 +
Documentation/ABI/testing/sysfs-bus-fcoe | 138 +
Documentation/ABI/testing/sysfs-bus-fsi | 46 +
.../ABI/testing/sysfs-bus-fsi-devices-sbefifo | 10 +
Documentation/ABI/testing/sysfs-bus-fsl-mc | 25 +
Documentation/ABI/testing/sysfs-bus-hsi | 19 +
.../ABI/testing/sysfs-bus-i2c-devices-bq32k | 7 +
.../ABI/testing/sysfs-bus-i2c-devices-fsa9480 | 27 +
.../ABI/testing/sysfs-bus-i2c-devices-hm6352 | 21 +
.../ABI/testing/sysfs-bus-i2c-devices-lm3533 | 15 +
.../ABI/testing/sysfs-bus-i2c-devices-m24lr | 100 +
.../ABI/testing/sysfs-bus-i2c-devices-pca954x | 23 +
.../testing/sysfs-bus-i2c-devices-turris-omnia-mcu | 113 +
Documentation/ABI/testing/sysfs-bus-i3c | 194 +
Documentation/ABI/testing/sysfs-bus-iio | 2511 +
.../ABI/testing/sysfs-bus-iio-accel-adxl372 | 7 +
.../ABI/testing/sysfs-bus-iio-accel-bmc150 | 7 +
Documentation/ABI/testing/sysfs-bus-iio-ad9739a | 19 +
.../ABI/testing/sysfs-bus-iio-adc-ad-sigma-delta | 23 +
Documentation/ABI/testing/sysfs-bus-iio-adc-ad4130 | 20 +
Documentation/ABI/testing/sysfs-bus-iio-adc-ad7192 | 27 +
.../ABI/testing/sysfs-bus-iio-adc-ad7280a | 13 +
.../testing/sysfs-bus-iio-adc-envelope-detector | 39 +
Documentation/ABI/testing/sysfs-bus-iio-adc-hi8435 | 48 +
.../ABI/testing/sysfs-bus-iio-adc-max11410 | 13 +
.../ABI/testing/sysfs-bus-iio-adc-mcp3564 | 53 +
Documentation/ABI/testing/sysfs-bus-iio-adc-mt6360 | 78 +
.../ABI/testing/sysfs-bus-iio-adc-pac1934 | 9 +
Documentation/ABI/testing/sysfs-bus-iio-adc-stm32 | 21 +
Documentation/ABI/testing/sysfs-bus-iio-bno055 | 81 +
Documentation/ABI/testing/sysfs-bus-iio-cdc-ad7746 | 11 +
.../ABI/testing/sysfs-bus-iio-chemical-sgp40 | 17 +
.../ABI/testing/sysfs-bus-iio-chemical-sunrise-co2 | 38 +
.../ABI/testing/sysfs-bus-iio-chemical-vz89x | 7 +
Documentation/ABI/testing/sysfs-bus-iio-cros-ec | 21 +
Documentation/ABI/testing/sysfs-bus-iio-dac | 61 +
Documentation/ABI/testing/sysfs-bus-iio-dac-ad5766 | 31 +
.../ABI/testing/sysfs-bus-iio-dac-dpot-dac | 8 +
.../ABI/testing/sysfs-bus-iio-dac-ltc2688 | 55 +
.../ABI/testing/sysfs-bus-iio-dfsdm-adc-stm32 | 22 +
.../ABI/testing/sysfs-bus-iio-distance-srf08 | 17 +
Documentation/ABI/testing/sysfs-bus-iio-dma-buffer | 19 +
.../ABI/testing/sysfs-bus-iio-filter-admv8818 | 18 +
Documentation/ABI/testing/sysfs-bus-iio-flow | 21 +
Documentation/ABI/testing/sysfs-bus-iio-frequency | 11 +
.../ABI/testing/sysfs-bus-iio-frequency-ad9523 | 31 +
.../ABI/testing/sysfs-bus-iio-frequency-adf4350 | 11 +
.../ABI/testing/sysfs-bus-iio-frequency-adf4371 | 11 +
.../ABI/testing/sysfs-bus-iio-frequency-admv1013 | 38 +
.../ABI/testing/sysfs-bus-iio-frequency-admv1014 | 23 +
.../ABI/testing/sysfs-bus-iio-gyro-bmg160 | 7 +
.../ABI/testing/sysfs-bus-iio-health-afe440x | 39 +
Documentation/ABI/testing/sysfs-bus-iio-humidity | 10 +
.../sysfs-bus-iio-impedance-analyzer-ad5933 | 35 +
Documentation/ABI/testing/sysfs-bus-iio-ina2xx-adc | 15 +
.../ABI/testing/sysfs-bus-iio-inv_icm42600 | 18 +
Documentation/ABI/testing/sysfs-bus-iio-isl29501 | 47 +
.../ABI/testing/sysfs-bus-iio-light-isl29018 | 21 +
.../ABI/testing/sysfs-bus-iio-light-lm3533-als | 56 +
.../ABI/testing/sysfs-bus-iio-light-si1133 | 22 +
.../ABI/testing/sysfs-bus-iio-light-tsl2583 | 20 +
.../ABI/testing/sysfs-bus-iio-light-tsl2772 | 13 +
.../ABI/testing/sysfs-bus-iio-magnetometer-hmc5843 | 20 +
Documentation/ABI/testing/sysfs-bus-iio-meas-spec | 7 +
Documentation/ABI/testing/sysfs-bus-iio-mpu6050 | 13 +
.../testing/sysfs-bus-iio-potentiometer-mcp4531 | 8 +
Documentation/ABI/testing/sysfs-bus-iio-proximity | 24 +
.../ABI/testing/sysfs-bus-iio-proximity-as3935 | 15 +
.../ABI/testing/sysfs-bus-iio-resolver-ad2s1210 | 27 +
Documentation/ABI/testing/sysfs-bus-iio-sps30 | 28 +
Documentation/ABI/testing/sysfs-bus-iio-sx9310 | 10 +
Documentation/ABI/testing/sysfs-bus-iio-sx9324 | 29 +
.../ABI/testing/sysfs-bus-iio-thermocouple | 18 +
.../ABI/testing/sysfs-bus-iio-timer-stm32 | 143 +
.../ABI/testing/sysfs-bus-iio-trigger-sysfs | 42 +
Documentation/ABI/testing/sysfs-bus-iio-vf610 | 16 +
.../ABI/testing/sysfs-bus-intel_th-devices-gth | 52 +
.../ABI/testing/sysfs-bus-intel_th-devices-msc | 54 +
.../ABI/testing/sysfs-bus-intel_th-devices-pti | 24 +
.../ABI/testing/sysfs-bus-intel_th-output-devices | 15 +
Documentation/ABI/testing/sysfs-bus-mcb | 29 +
Documentation/ABI/testing/sysfs-bus-mdio | 72 +
Documentation/ABI/testing/sysfs-bus-media | 6 +
Documentation/ABI/testing/sysfs-bus-mei | 56 +
Documentation/ABI/testing/sysfs-bus-mmc | 4 +
Documentation/ABI/testing/sysfs-bus-most | 299 +
Documentation/ABI/testing/sysfs-bus-moxtet-devices | 17 +
Documentation/ABI/testing/sysfs-bus-nfit | 233 +
Documentation/ABI/testing/sysfs-bus-nvdimm | 60 +
Documentation/ABI/testing/sysfs-bus-optee-devices | 17 +
Documentation/ABI/testing/sysfs-bus-papr-pmem | 75 +
Documentation/ABI/testing/sysfs-bus-pci | 704 +
.../ABI/testing/sysfs-bus-pci-devices-aer | 163 +
.../ABI/testing/sysfs-bus-pci-devices-avs | 8 +
.../ABI/testing/sysfs-bus-pci-devices-catpt | 17 +
.../ABI/testing/sysfs-bus-pci-devices-cciss | 80 +
.../ABI/testing/sysfs-bus-pci-devices-pvpanic | 26 +
.../ABI/testing/sysfs-bus-pci-drivers-btintel_pcie | 15 +
.../ABI/testing/sysfs-bus-pci-drivers-ehci_hcd | 46 +
.../ABI/testing/sysfs-bus-pci-drivers-janz-cmodio | 8 +
.../ABI/testing/sysfs-bus-pci-drivers-xhci_hcd | 129 +
Documentation/ABI/testing/sysfs-bus-peci | 16 +
Documentation/ABI/testing/sysfs-bus-platform | 56 +
.../sysfs-bus-platform-devices-ampere-smpro | 325 +
.../testing/sysfs-bus-platform-devices-occ-hwmon | 13 +
.../sysfs-bus-platform-drivers-amd_x3d_vcache | 12 +
.../ABI/testing/sysfs-bus-platform-onboard-usb-dev | 9 +
Documentation/ABI/testing/sysfs-bus-rapidio | 201 +
Documentation/ABI/testing/sysfs-bus-rbd | 173 +
Documentation/ABI/testing/sysfs-bus-rpmsg | 95 +
Documentation/ABI/testing/sysfs-bus-siox | 90 +
.../ABI/testing/sysfs-bus-soundwire-master | 23 +
.../ABI/testing/sysfs-bus-soundwire-slave | 109 +
.../ABI/testing/sysfs-bus-spi-devices-spi-nor | 40 +
.../testing/sysfs-bus-surface_aggregator-tabletsw | 57 +
Documentation/ABI/testing/sysfs-bus-thunderbolt | 370 +
Documentation/ABI/testing/sysfs-bus-typec | 51 +
Documentation/ABI/testing/sysfs-bus-usb | 607 +
.../ABI/testing/sysfs-bus-usb-devices-usbsevseg | 46 +
Documentation/ABI/testing/sysfs-bus-usb-lvstest | 60 +
Documentation/ABI/testing/sysfs-bus-vdpa | 57 +
Documentation/ABI/testing/sysfs-bus-vfio-mdev | 113 +
Documentation/ABI/testing/sysfs-bus-vmbus | 21 +
Documentation/ABI/testing/sysfs-bus-wmi | 81 +
Documentation/ABI/testing/sysfs-c2port | 81 +
Documentation/ABI/testing/sysfs-cfq-target-latency | 8 +
Documentation/ABI/testing/sysfs-class | 16 +
Documentation/ABI/testing/sysfs-class-backlight | 186 +
.../testing/sysfs-class-backlight-driver-lm3533 | 54 +
.../ABI/testing/sysfs-class-backlight-lm3639 | 11 +
Documentation/ABI/testing/sysfs-class-bdi | 134 +
Documentation/ABI/testing/sysfs-class-bsr | 25 +
Documentation/ABI/testing/sysfs-class-chromeos | 53 +
.../sysfs-class-chromeos-driver-cros-ec-lightbar | 74 +
.../sysfs-class-chromeos-driver-cros-ec-vbc | 6 +
Documentation/ABI/testing/sysfs-class-devfreq | 143 +
.../ABI/testing/sysfs-class-devfreq-event | 25 +
Documentation/ABI/testing/sysfs-class-devlink | 130 +
Documentation/ABI/testing/sysfs-class-drm | 8 +
Documentation/ABI/testing/sysfs-class-extcon | 101 +
Documentation/ABI/testing/sysfs-class-fc | 27 +
Documentation/ABI/testing/sysfs-class-fc_host | 23 +
.../ABI/testing/sysfs-class-fc_remote_ports | 23 +
Documentation/ABI/testing/sysfs-class-firmware | 77 +
.../ABI/testing/sysfs-class-firmware-attributes | 494 +
Documentation/ABI/testing/sysfs-class-fpga-bridge | 11 +
Documentation/ABI/testing/sysfs-class-fpga-manager | 60 +
Documentation/ABI/testing/sysfs-class-fpga-region | 9 +
Documentation/ABI/testing/sysfs-class-gnss | 17 +
Documentation/ABI/testing/sysfs-class-hwmon | 1089 +
.../ABI/testing/sysfs-class-ieee80211-rtw89 | 24 +
Documentation/ABI/testing/sysfs-class-intel_pmt | 119 +
.../ABI/testing/sysfs-class-intel_pmt-features | 134 +
Documentation/ABI/testing/sysfs-class-iommu | 17 +
.../ABI/testing/sysfs-class-iommu-amd-iommu | 14 +
.../ABI/testing/sysfs-class-iommu-intel-iommu | 32 +
Documentation/ABI/testing/sysfs-class-issei | 73 +
Documentation/ABI/testing/sysfs-class-lcd | 23 +
Documentation/ABI/testing/sysfs-class-led | 89 +
.../ABI/testing/sysfs-class-led-driver-aw200xx | 5 +
.../ABI/testing/sysfs-class-led-driver-lm3533 | 73 +
.../testing/sysfs-class-led-driver-turris-omnia | 28 +
Documentation/ABI/testing/sysfs-class-led-flash | 89 +
.../ABI/testing/sysfs-class-led-multicolor | 37 +
.../ABI/testing/sysfs-class-led-trigger-netdev | 192 +
.../ABI/testing/sysfs-class-led-trigger-oneshot | 36 +
.../ABI/testing/sysfs-class-led-trigger-pattern | 50 +
.../ABI/testing/sysfs-class-led-trigger-tty | 62 +
.../ABI/testing/sysfs-class-led-trigger-usbport | 13 +
Documentation/ABI/testing/sysfs-class-leds-gt683r | 18 +
Documentation/ABI/testing/sysfs-class-mei | 105 +
Documentation/ABI/testing/sysfs-class-mic | 178 +
Documentation/ABI/testing/sysfs-class-mtd | 242 +
Documentation/ABI/testing/sysfs-class-mux | 16 +
Documentation/ABI/testing/sysfs-class-net | 354 +
Documentation/ABI/testing/sysfs-class-net-cdc_ncm | 168 +
Documentation/ABI/testing/sysfs-class-net-dsa | 14 +
Documentation/ABI/testing/sysfs-class-net-grcan | 35 +
.../ABI/testing/sysfs-class-net-janz-ican3 | 19 +
Documentation/ABI/testing/sysfs-class-net-peak_usb | 19 +
Documentation/ABI/testing/sysfs-class-net-phydev | 75 +
Documentation/ABI/testing/sysfs-class-net-qmi | 76 +
Documentation/ABI/testing/sysfs-class-net-queues | 121 +
.../ABI/testing/sysfs-class-net-statistics | 217 +
Documentation/ABI/testing/sysfs-class-ocxl | 51 +
.../ABI/testing/sysfs-class-platform-profile | 50 +
Documentation/ABI/testing/sysfs-class-power | 906 +
.../ABI/testing/sysfs-class-power-bd71828 | 13 +
Documentation/ABI/testing/sysfs-class-power-gaokun | 27 +
.../ABI/testing/sysfs-class-power-ltc4162l | 82 +
.../ABI/testing/sysfs-class-power-max1720x | 32 +
Documentation/ABI/testing/sysfs-class-power-mp2629 | 9 +
Documentation/ABI/testing/sysfs-class-power-rt9467 | 19 +
Documentation/ABI/testing/sysfs-class-power-rt9471 | 32 +
Documentation/ABI/testing/sysfs-class-power-rt9756 | 30 +
.../ABI/testing/sysfs-class-power-surface | 15 +
.../ABI/testing/sysfs-class-power-twl4030 | 33 +
Documentation/ABI/testing/sysfs-class-power-wilco | 40 +
Documentation/ABI/testing/sysfs-class-powercap | 152 +
Documentation/ABI/testing/sysfs-class-pwm | 88 +
Documentation/ABI/testing/sysfs-class-rapidio | 59 +
Documentation/ABI/testing/sysfs-class-rc | 137 +
Documentation/ABI/testing/sysfs-class-rc-nuvoton | 15 +
.../testing/sysfs-class-reboot-mode-reboot_modes | 39 +
Documentation/ABI/testing/sysfs-class-regulator | 453 +
Documentation/ABI/testing/sysfs-class-remoteproc | 104 +
Documentation/ABI/testing/sysfs-class-rnbd-client | 133 +
Documentation/ABI/testing/sysfs-class-rnbd-server | 58 +
Documentation/ABI/testing/sysfs-class-rtc | 91 +
.../sysfs-class-rtc-rtc0-device-rtc_calibration | 14 +
Documentation/ABI/testing/sysfs-class-rtrs-client | 146 +
Documentation/ABI/testing/sysfs-class-rtrs-server | 53 +
Documentation/ABI/testing/sysfs-class-scsi_host | 119 +
Documentation/ABI/testing/sysfs-class-scsi_tape | 109 +
Documentation/ABI/testing/sysfs-class-spi-eeprom | 30 +
Documentation/ABI/testing/sysfs-class-spi-master | 34 +
Documentation/ABI/testing/sysfs-class-stm | 24 +
Documentation/ABI/testing/sysfs-class-stm_source | 11 +
Documentation/ABI/testing/sysfs-class-switchtec | 96 +
Documentation/ABI/testing/sysfs-class-tee | 25 +
Documentation/ABI/testing/sysfs-class-thermal | 259 +
Documentation/ABI/testing/sysfs-class-tsm | 9 +
Documentation/ABI/testing/sysfs-class-typec | 386 +
.../ABI/testing/sysfs-class-usb_power_delivery | 284 +
Documentation/ABI/testing/sysfs-class-usb_role | 27 +
Documentation/ABI/testing/sysfs-class-vduse | 33 +
Documentation/ABI/testing/sysfs-class-wakeup | 76 +
Documentation/ABI/testing/sysfs-class-watchdog | 129 +
Documentation/ABI/testing/sysfs-class-zram | 24 +
Documentation/ABI/testing/sysfs-dev | 21 +
Documentation/ABI/testing/sysfs-devices | 25 +
Documentation/ABI/testing/sysfs-devices-consumer | 9 +
Documentation/ABI/testing/sysfs-devices-coredump | 10 +
Documentation/ABI/testing/sysfs-devices-edac | 157 +
.../ABI/testing/sysfs-devices-faux-tdx-host | 26 +
.../ABI/testing/sysfs-devices-firmware_node | 17 +
Documentation/ABI/testing/sysfs-devices-lpss_ltr | 44 +
Documentation/ABI/testing/sysfs-devices-mapping | 62 +
Documentation/ABI/testing/sysfs-devices-memory | 120 +
Documentation/ABI/testing/sysfs-devices-mmc | 21 +
Documentation/ABI/testing/sysfs-devices-online | 20 +
.../ABI/testing/sysfs-devices-pci-host-bridge | 45 +
.../ABI/testing/sysfs-devices-physical_location | 42 +
.../ABI/testing/sysfs-devices-platform-ACPI-TAD | 117 +
.../testing/sysfs-devices-platform-_UDC_-gadget | 23 +
.../ABI/testing/sysfs-devices-platform-docg3 | 40 +
.../ABI/testing/sysfs-devices-platform-dock | 39 +
.../ABI/testing/sysfs-devices-platform-ipmi | 242 +
.../testing/sysfs-devices-platform-kunpeng_hccs | 126 +
.../sysfs-devices-platform-sh_mobile_lcdc_fb | 44 +
.../ABI/testing/sysfs-devices-platform-soc-ipa | 114 +
.../testing/sysfs-devices-platform-stratix10-rsu | 232 +
.../ABI/testing/sysfs-devices-platform-trackpoint | 115 +
Documentation/ABI/testing/sysfs-devices-power | 307 +
.../ABI/testing/sysfs-devices-power_resources_D0 | 13 +
.../ABI/testing/sysfs-devices-power_resources_D1 | 14 +
.../ABI/testing/sysfs-devices-power_resources_D2 | 14 +
.../testing/sysfs-devices-power_resources_D3hot | 14 +
.../testing/sysfs-devices-power_resources_wakeup | 13 +
.../ABI/testing/sysfs-devices-power_state | 20 +
.../ABI/testing/sysfs-devices-real_power_state | 23 +
Documentation/ABI/testing/sysfs-devices-removable | 20 +
.../ABI/testing/sysfs-devices-resource_in_use | 12 +
Documentation/ABI/testing/sysfs-devices-soc | 95 +
.../ABI/testing/sysfs-devices-software_node | 10 +
.../ABI/testing/sysfs-devices-state_synced | 29 +
Documentation/ABI/testing/sysfs-devices-sun | 14 +
Documentation/ABI/testing/sysfs-devices-supplier | 9 +
Documentation/ABI/testing/sysfs-devices-system-cpu | 808 +
.../ABI/testing/sysfs-devices-system-ibm-rtl | 24 +
.../ABI/testing/sysfs-devices-system-xen_cpu | 20 +
Documentation/ABI/testing/sysfs-devices-vfio-dev | 8 +
.../testing/sysfs-devices-virtual-misc-tdx_guest | 63 +
.../ABI/testing/sysfs-devices-waiting_for_supplier | 17 +
Documentation/ABI/testing/sysfs-devices-xenbus | 41 +
Documentation/ABI/testing/sysfs-driver-altera-cvp | 8 +
Documentation/ABI/testing/sysfs-driver-amd-sfh | 13 +
.../ABI/testing/sysfs-driver-aspeed-uart-routing | 27 +
.../ABI/testing/sysfs-driver-bd9571mwv-regulator | 31 +
Documentation/ABI/testing/sysfs-driver-ccp | 120 +
.../ABI/testing/sysfs-driver-chromeos-acpi | 152 +
.../ABI/testing/sysfs-driver-dell-dw5826e-reset | 9 +
Documentation/ABI/testing/sysfs-driver-eud | 9 +
.../ABI/testing/sysfs-driver-framer-pef2256 | 8 +
.../ABI/testing/sysfs-driver-fsi-master-gpio | 10 +
Documentation/ABI/testing/sysfs-driver-ge-achc | 15 +
Documentation/ABI/testing/sysfs-driver-genwqe | 78 +
Documentation/ABI/testing/sysfs-driver-habanalabs | 265 +
Documentation/ABI/testing/sysfs-driver-hid | 20 +
.../ABI/testing/sysfs-driver-hid-appletb-kbd | 13 +
Documentation/ABI/testing/sysfs-driver-hid-corsair | 15 +
.../ABI/testing/sysfs-driver-hid-corsair-void | 38 +
Documentation/ABI/testing/sysfs-driver-hid-lenovo | 60 +
.../ABI/testing/sysfs-driver-hid-lenovo-go | 724 +
.../ABI/testing/sysfs-driver-hid-lenovo-go-s | 304 +
.../ABI/testing/sysfs-driver-hid-logitech-hidpp | 19 +
.../ABI/testing/sysfs-driver-hid-logitech-lg4ff | 75 +
.../ABI/testing/sysfs-driver-hid-multitouch | 9 +
Documentation/ABI/testing/sysfs-driver-hid-ntrig | 73 +
Documentation/ABI/testing/sysfs-driver-hid-picolcd | 43 +
.../ABI/testing/sysfs-driver-hid-prodikeys | 29 +
.../ABI/testing/sysfs-driver-hid-roccat-kone | 125 +
Documentation/ABI/testing/sysfs-driver-hid-srws1 | 21 +
Documentation/ABI/testing/sysfs-driver-hid-wiimote | 85 +
.../ABI/testing/sysfs-driver-input-axp-pek | 11 +
.../ABI/testing/sysfs-driver-input-cros-ec-keyb | 6 +
.../ABI/testing/sysfs-driver-input-exc3000 | 26 +
Documentation/ABI/testing/sysfs-driver-intc_sar | 54 +
.../ABI/testing/sysfs-driver-intel-i915-hwmon | 93 +
.../ABI/testing/sysfs-driver-intel-m10-bmc | 36 +
.../testing/sysfs-driver-intel-m10-bmc-sec-update | 61 +
.../ABI/testing/sysfs-driver-intel-rapid-start | 21 +
.../ABI/testing/sysfs-driver-intel-xe-hwmon | 315 +
.../ABI/testing/sysfs-driver-intel-xe-ras | 30 +
.../ABI/testing/sysfs-driver-intel-xe-sriov | 190 +
Documentation/ABI/testing/sysfs-driver-intel_sdsi | 90 +
Documentation/ABI/testing/sysfs-driver-ivpu | 65 +
.../ABI/testing/sysfs-driver-jz4780-efuse | 20 +
.../ABI/testing/sysfs-driver-lenovo-yb9-kbdock | 19 +
.../ABI/testing/sysfs-driver-panfrost-profiling | 10 +
.../ABI/testing/sysfs-driver-panthor-profiling | 10 +
Documentation/ABI/testing/sysfs-driver-pciback | 28 +
Documentation/ABI/testing/sysfs-driver-ppi | 75 +
Documentation/ABI/testing/sysfs-driver-qaic | 18 +
Documentation/ABI/testing/sysfs-driver-qat | 167 +
Documentation/ABI/testing/sysfs-driver-qat_kpt | 97 +
Documentation/ABI/testing/sysfs-driver-qat_ras | 41 +
Documentation/ABI/testing/sysfs-driver-qat_rl | 226 +
Documentation/ABI/testing/sysfs-driver-qat_svn | 114 +
.../ABI/testing/sysfs-driver-samsung-laptop | 37 +
Documentation/ABI/testing/sysfs-driver-spi-intel | 20 +
Documentation/ABI/testing/sysfs-driver-st | 12 +
Documentation/ABI/testing/sysfs-driver-tegra-fuse | 11 +
.../ABI/testing/sysfs-driver-toshiba_acpi | 223 +
.../ABI/testing/sysfs-driver-toshiba_haps | 22 +
.../ABI/testing/sysfs-driver-typec-displayport | 74 +
Documentation/ABI/testing/sysfs-driver-uacce | 57 +
Documentation/ABI/testing/sysfs-driver-ucsi-ccg | 6 +
Documentation/ABI/testing/sysfs-driver-ufs | 1793 +
.../ABI/testing/sysfs-driver-uio_pci_sva-pasid | 29 +
.../ABI/testing/sysfs-driver-uniwill-laptop | 105 +
Documentation/ABI/testing/sysfs-driver-w1_ds28e17 | 24 +
Documentation/ABI/testing/sysfs-driver-w1_therm | 190 +
Documentation/ABI/testing/sysfs-driver-wacom | 105 +
Documentation/ABI/testing/sysfs-driver-xdata | 49 +
Documentation/ABI/testing/sysfs-driver-xen-blkback | 46 +
.../ABI/testing/sysfs-driver-xen-blkfront | 19 +
.../ABI/testing/sysfs-driver-xilinx-tmr-manager | 16 +
Documentation/ABI/testing/sysfs-driver-zynqmp-fpga | 73 +
Documentation/ABI/testing/sysfs-edac-ecs | 74 +
Documentation/ABI/testing/sysfs-edac-memory-repair | 206 +
Documentation/ABI/testing/sysfs-edac-scrub | 85 +
Documentation/ABI/testing/sysfs-firmware-acpi | 277 +
.../ABI/testing/sysfs-firmware-dmi-entries | 114 +
.../ABI/testing/sysfs-firmware-dmi-tables | 22 +
Documentation/ABI/testing/sysfs-firmware-efi | 45 +
Documentation/ABI/testing/sysfs-firmware-efi-esrt | 87 +
.../ABI/testing/sysfs-firmware-efi-runtime-map | 36 +
Documentation/ABI/testing/sysfs-firmware-gsmi | 58 +
Documentation/ABI/testing/sysfs-firmware-initrd | 8 +
.../ABI/testing/sysfs-firmware-lefi-boardinfo | 35 +
Documentation/ABI/testing/sysfs-firmware-log | 7 +
Documentation/ABI/testing/sysfs-firmware-memmap | 75 +
Documentation/ABI/testing/sysfs-firmware-ofw | 52 +
.../ABI/testing/sysfs-firmware-opal-powercap | 31 +
Documentation/ABI/testing/sysfs-firmware-opal-psr | 18 +
.../ABI/testing/sysfs-firmware-opal-sensor-groups | 21 +
.../testing/sysfs-firmware-papr-energy-scale-info | 29 +
Documentation/ABI/testing/sysfs-firmware-plpks | 58 +
.../ABI/testing/sysfs-firmware-qemu_fw_cfg | 103 +
.../ABI/testing/sysfs-firmware-sev-vulnerabilities | 19 +
Documentation/ABI/testing/sysfs-firmware-sgi_uv | 159 +
.../ABI/testing/sysfs-firmware-turris-mox-rwtm | 28 +
Documentation/ABI/testing/sysfs-fs-erofs | 49 +
Documentation/ABI/testing/sysfs-fs-ext4 | 118 +
Documentation/ABI/testing/sysfs-fs-f2fs | 1022 +
Documentation/ABI/testing/sysfs-fs-nilfs2 | 269 +
Documentation/ABI/testing/sysfs-fs-ubifs | 35 +
Documentation/ABI/testing/sysfs-fs-virtiofs | 11 +
Documentation/ABI/testing/sysfs-fs-xfs | 37 +
Documentation/ABI/testing/sysfs-hypervisor-xen | 46 +
Documentation/ABI/testing/sysfs-ibft | 33 +
.../ABI/testing/sysfs-kernel-address_bits | 10 +
Documentation/ABI/testing/sysfs-kernel-boot_params | 39 +
Documentation/ABI/testing/sysfs-kernel-btf | 25 +
.../ABI/testing/sysfs-kernel-cpu_byteorder | 12 +
Documentation/ABI/testing/sysfs-kernel-fadump | 59 +
Documentation/ABI/testing/sysfs-kernel-fscaps | 8 +
.../ABI/testing/sysfs-kernel-hardlockup_count | 7 +
.../ABI/testing/sysfs-kernel-iommu_groups | 64 +
Documentation/ABI/testing/sysfs-kernel-irq | 60 +
Documentation/ABI/testing/sysfs-kernel-kexec-kdump | 61 +
Documentation/ABI/testing/sysfs-kernel-livepatch | 95 +
Documentation/ABI/testing/sysfs-kernel-mm | 6 +
Documentation/ABI/testing/sysfs-kernel-mm-cma | 44 +
Documentation/ABI/testing/sysfs-kernel-mm-damon | 664 +
.../ABI/testing/sysfs-kernel-mm-hugepages | 17 +
Documentation/ABI/testing/sysfs-kernel-mm-ksm | 61 +
.../ABI/testing/sysfs-kernel-mm-memory-tiers | 25 +
.../ABI/testing/sysfs-kernel-mm-mempolicy | 4 +
.../sysfs-kernel-mm-mempolicy-weighted-interleave | 54 +
Documentation/ABI/testing/sysfs-kernel-mm-numa | 28 +
Documentation/ABI/testing/sysfs-kernel-mm-swap | 16 +
.../testing/sysfs-kernel-mm-transparent-hugepage | 18 +
Documentation/ABI/testing/sysfs-kernel-oops_count | 6 +
.../ABI/testing/sysfs-kernel-rcu_stall_count | 6 +
Documentation/ABI/testing/sysfs-kernel-reboot | 40 +
Documentation/ABI/testing/sysfs-kernel-slab | 526 +
.../ABI/testing/sysfs-kernel-softlockup_count | 7 +
Documentation/ABI/testing/sysfs-kernel-vmcoreinfo | 14 +
Documentation/ABI/testing/sysfs-kernel-warn_count | 6 +
Documentation/ABI/testing/sysfs-mce | 97 +
.../ABI/testing/sysfs-memory-page-offline | 44 +
Documentation/ABI/testing/sysfs-module | 84 +
Documentation/ABI/testing/sysfs-nvmem-cells | 21 +
Documentation/ABI/testing/sysfs-ocfs2 | 89 +
.../ABI/testing/sysfs-platform-alienware-wmi | 14 +
.../ABI/testing/sysfs-platform-asus-laptop | 71 +
Documentation/ABI/testing/sysfs-platform-asus-wmi | 240 +
Documentation/ABI/testing/sysfs-platform-at91 | 27 +
Documentation/ABI/testing/sysfs-platform-ayaneo-ec | 19 +
.../ABI/testing/sysfs-platform-brcmstb-gisb-arb | 8 +
.../ABI/testing/sysfs-platform-brcmstb-memc | 15 +
.../ABI/testing/sysfs-platform-chipidea-usb-otg | 56 +
.../ABI/testing/sysfs-platform-chipidea-usb2 | 9 +
.../ABI/testing/sysfs-platform-dell-laptop | 73 +
.../ABI/testing/sysfs-platform-dell-privacy-wmi | 71 +
.../ABI/testing/sysfs-platform-dell-smbios | 21 +
.../ABI/testing/sysfs-platform-dell-wmi-ddv | 9 +
Documentation/ABI/testing/sysfs-platform-dfl-fme | 246 +
Documentation/ABI/testing/sysfs-platform-dfl-port | 101 +
Documentation/ABI/testing/sysfs-platform-dptf | 157 +
.../ABI/testing/sysfs-platform-eeepc-laptop | 56 +
Documentation/ABI/testing/sysfs-platform-hidma | 9 +
.../ABI/testing/sysfs-platform-hidma-mgmt | 97 +
.../ABI/testing/sysfs-platform-i2c-demux-pinctrl | 18 +
.../ABI/testing/sysfs-platform-ideapad-laptop | 52 +
Documentation/ABI/testing/sysfs-platform-intel-ifs | 52 +
Documentation/ABI/testing/sysfs-platform-intel-pmc | 22 +
.../testing/sysfs-platform-intel-wmi-sbl-fw-update | 13 +
.../testing/sysfs-platform-intel-wmi-thunderbolt | 12 +
Documentation/ABI/testing/sysfs-platform-kim | 49 +
Documentation/ABI/testing/sysfs-platform-lg-laptop | 36 +
.../ABI/testing/sysfs-platform-mellanox-bootctl | 162 +
.../ABI/testing/sysfs-platform-mellanox-pmc | 64 +
.../ABI/testing/sysfs-platform-msi-laptop | 83 +
Documentation/ABI/testing/sysfs-platform-oxp | 25 +
.../ABI/testing/sysfs-platform-phy-rcar-gen3-usb2 | 17 +
.../ABI/testing/sysfs-platform-power-on-reason | 12 +
.../ABI/testing/sysfs-platform-renesas_usb3 | 17 +
Documentation/ABI/testing/sysfs-platform-silicom | 30 +
Documentation/ABI/testing/sysfs-platform-sst-atom | 26 +
Documentation/ABI/testing/sysfs-platform-tahvo-usb | 16 +
Documentation/ABI/testing/sysfs-platform-ts5500 | 54 +
.../ABI/testing/sysfs-platform-twl4030-usb | 8 +
.../ABI/testing/sysfs-platform-usbip-vudc | 38 +
Documentation/ABI/testing/sysfs-platform-wilco-ec | 58 +
Documentation/ABI/testing/sysfs-platform_profile | 40 +
Documentation/ABI/testing/sysfs-power | 472 +
Documentation/ABI/testing/sysfs-pps | 73 +
Documentation/ABI/testing/sysfs-pps-gen | 43 +
Documentation/ABI/testing/sysfs-pps-gen-tio | 6 +
Documentation/ABI/testing/sysfs-profiling | 13 +
Documentation/ABI/testing/sysfs-ptp | 142 +
Documentation/ABI/testing/sysfs-secvar | 65 +
Documentation/ABI/testing/sysfs-timecard | 293 +
Documentation/ABI/testing/sysfs-tty | 166 +
Documentation/ABI/testing/sysfs-uevent | 51 +
Documentation/ABI/testing/usb-charger-uevent | 54 +
Documentation/ABI/testing/usb-uevent | 27 +
Documentation/Changes | 1 +
Documentation/CodingStyle | 1 +
Documentation/Kconfig | 28 +
Documentation/Makefile | 115 +
Documentation/PCI/acpi-info.rst | 192 +
Documentation/PCI/boot-interrupts.rst | 159 +
Documentation/PCI/controller/index.rst | 11 +
.../PCI/controller/pci-controller-drivers.rst | 402 +
.../PCI/controller/rcar-pcie-firmware.rst | 32 +
.../PCI/endpoint/function/binding/pci-ntb.rst | 38 +
.../PCI/endpoint/function/binding/pci-test.rst | 26 +
Documentation/PCI/endpoint/index.rst | 21 +
Documentation/PCI/endpoint/pci-endpoint-cfs.rst | 138 +
Documentation/PCI/endpoint/pci-endpoint.rst | 283 +
Documentation/PCI/endpoint/pci-ntb-function.rst | 348 +
Documentation/PCI/endpoint/pci-ntb-howto.rst | 158 +
Documentation/PCI/endpoint/pci-nvme-function.rst | 13 +
Documentation/PCI/endpoint/pci-test-function.rst | 103 +
Documentation/PCI/endpoint/pci-test-howto.rst | 239 +
Documentation/PCI/endpoint/pci-vntb-function.rst | 129 +
Documentation/PCI/endpoint/pci-vntb-howto.rst | 169 +
Documentation/PCI/index.rst | 22 +
Documentation/PCI/msi-howto.rst | 300 +
Documentation/PCI/pci-error-recovery.rst | 471 +
Documentation/PCI/pci-iov-howto.rst | 171 +
Documentation/PCI/pci.rst | 578 +
Documentation/PCI/pcieaer-howto.rst | 267 +
Documentation/PCI/pciebus-howto.rst | 228 +
Documentation/PCI/sysfs-pci.rst | 138 +
Documentation/PCI/tph.rst | 132 +
.../Design/Data-Structures/BigTreeClassicRCU.svg | 474 +
.../BigTreePreemptRCUBHdyntickCB.svg | 662 +
.../RCU/Design/Data-Structures/Data-Structures.rst | 1196 +
.../Design/Data-Structures/HugeTreeClassicRCU.svg | 939 +
.../RCU/Design/Data-Structures/TreeLevel.svg | 828 +
.../RCU/Design/Data-Structures/TreeMapping.svg | 305 +
.../Design/Data-Structures/TreeMappingLevel.svg | 380 +
.../RCU/Design/Data-Structures/blkd_task.svg | 631 +
.../RCU/Design/Data-Structures/nxtlist.svg | 386 +
.../Design/Expedited-Grace-Periods/ExpRCUFlow.svg | 830 +
.../Expedited-Grace-Periods/ExpSchedFlow.svg | 830 +
.../Expedited-Grace-Periods.rst | 521 +
.../RCU/Design/Expedited-Grace-Periods/Funnel0.svg | 275 +
.../RCU/Design/Expedited-Grace-Periods/Funnel1.svg | 275 +
.../RCU/Design/Expedited-Grace-Periods/Funnel2.svg | 287 +
.../RCU/Design/Expedited-Grace-Periods/Funnel3.svg | 323 +
.../RCU/Design/Expedited-Grace-Periods/Funnel4.svg | 323 +
.../RCU/Design/Expedited-Grace-Periods/Funnel5.svg | 335 +
.../RCU/Design/Expedited-Grace-Periods/Funnel6.svg | 335 +
.../RCU/Design/Expedited-Grace-Periods/Funnel7.svg | 347 +
.../RCU/Design/Expedited-Grace-Periods/Funnel8.svg | 311 +
.../Memory-Ordering/Tree-RCU-Memory-Ordering.rst | 648 +
.../TreeRCU-callback-invocation.svg | 486 +
.../Memory-Ordering/TreeRCU-callback-registry.svg | 646 +
.../RCU/Design/Memory-Ordering/TreeRCU-dyntick.svg | 700 +
.../Design/Memory-Ordering/TreeRCU-gp-cleanup.svg | 1133 +
.../RCU/Design/Memory-Ordering/TreeRCU-gp-fqs.svg | 1309 +
.../Design/Memory-Ordering/TreeRCU-gp-init-1.svg | 658 +
.../Design/Memory-Ordering/TreeRCU-gp-init-2.svg | 656 +
.../Design/Memory-Ordering/TreeRCU-gp-init-3.svg | 636 +
.../RCU/Design/Memory-Ordering/TreeRCU-gp.svg | 5135 +
.../RCU/Design/Memory-Ordering/TreeRCU-hotplug.svg | 775 +
.../RCU/Design/Memory-Ordering/TreeRCU-qs.svg | 1095 +
.../RCU/Design/Memory-Ordering/rcu_node-lock.svg | 229 +
.../Design/Requirements/GPpartitionReaders1.svg | 374 +
.../Design/Requirements/ReadersPartitionGP1.svg | 639 +
.../RCU/Design/Requirements/Requirements.rst | 2873 +
Documentation/RCU/NMI-RCU.rst | 123 +
Documentation/RCU/RTFP.txt | 2812 +
Documentation/RCU/UP.rst | 152 +
Documentation/RCU/checklist.rst | 556 +
Documentation/RCU/index.rst | 30 +
Documentation/RCU/listRCU.rst | 511 +
Documentation/RCU/lockdep-splat.rst | 115 +
Documentation/RCU/lockdep.rst | 119 +
Documentation/RCU/rcu.rst | 93 +
Documentation/RCU/rcu_dereference.rst | 502 +
Documentation/RCU/rcubarrier.rst | 377 +
Documentation/RCU/rculist_nulls.rst | 215 +
Documentation/RCU/rcuref.rst | 158 +
Documentation/RCU/stallwarn.rst | 491 +
Documentation/RCU/torture.rst | 374 +
Documentation/RCU/whatisRCU.rst | 1415 +
Documentation/SubmittingPatches | 1 +
Documentation/accel/amdxdna/amdnpu.rst | 306 +
Documentation/accel/amdxdna/index.rst | 11 +
Documentation/accel/index.rst | 13 +
Documentation/accel/introduction.rst | 110 +
Documentation/accel/qaic/aic080.rst | 14 +
Documentation/accel/qaic/aic100.rst | 538 +
Documentation/accel/qaic/index.rst | 14 +
Documentation/accel/qaic/qaic.rst | 209 +
Documentation/accel/rocket/index.rst | 19 +
Documentation/accounting/cgroupstats.rst | 31 +
Documentation/accounting/delay-accounting.rst | 214 +
Documentation/accounting/index.rst | 14 +
Documentation/accounting/psi.rst | 188 +
Documentation/accounting/taskstats-struct.rst | 199 +
Documentation/accounting/taskstats.rst | 182 +
Documentation/admin-guide/LSM/LoadPin.rst | 31 +
Documentation/admin-guide/LSM/SELinux.rst | 44 +
Documentation/admin-guide/LSM/SafeSetID.rst | 118 +
Documentation/admin-guide/LSM/Smack.rst | 871 +
Documentation/admin-guide/LSM/Yama.rst | 75 +
Documentation/admin-guide/LSM/apparmor.rst | 54 +
Documentation/admin-guide/LSM/index.rst | 51 +
Documentation/admin-guide/LSM/ipe.rst | 835 +
Documentation/admin-guide/LSM/landlock.rst | 298 +
Documentation/admin-guide/LSM/tomoyo.rst | 52 +
.../admin-guide/RAS/address-translation.rst | 24 +
Documentation/admin-guide/RAS/error-decoding.rst | 21 +
Documentation/admin-guide/RAS/index.rst | 7 +
Documentation/admin-guide/RAS/main.rst | 1087 +
Documentation/admin-guide/README.rst | 360 +
Documentation/admin-guide/abi-obsolete-files.rst | 7 +
Documentation/admin-guide/abi-obsolete.rst | 13 +
Documentation/admin-guide/abi-removed-files.rst | 7 +
Documentation/admin-guide/abi-removed.rst | 7 +
Documentation/admin-guide/abi-stable-files.rst | 7 +
Documentation/admin-guide/abi-stable.rst | 16 +
Documentation/admin-guide/abi-testing-files.rst | 7 +
Documentation/admin-guide/abi-testing.rst | 22 +
Documentation/admin-guide/abi.rst | 29 +
Documentation/admin-guide/acpi/cppc_sysfs.rst | 78 +
.../admin-guide/acpi/fan_performance_states.rst | 90 +
Documentation/admin-guide/acpi/index.rst | 14 +
.../admin-guide/acpi/initrd_table_override.rst | 115 +
Documentation/admin-guide/acpi/ssdt-overlays.rst | 181 +
Documentation/admin-guide/aoe/aoe.rst | 150 +
Documentation/admin-guide/aoe/autoload.sh | 17 +
Documentation/admin-guide/aoe/examples.rst | 23 +
Documentation/admin-guide/aoe/index.rst | 10 +
Documentation/admin-guide/aoe/status.sh | 30 +
Documentation/admin-guide/aoe/todo.rst | 17 +
Documentation/admin-guide/aoe/udev-install.sh | 33 +
Documentation/admin-guide/aoe/udev.txt | 26 +
.../admin-guide/auxdisplay/cfag12864b.rst | 98 +
Documentation/admin-guide/auxdisplay/index.rst | 9 +
Documentation/admin-guide/auxdisplay/ks0108.rst | 50 +
Documentation/admin-guide/bcache.rst | 644 +
Documentation/admin-guide/binderfs.rst | 87 +
Documentation/admin-guide/binfmt-misc.rst | 391 +
.../blockdev/drbd/DRBD-8.3-data-packets.svg | 588 +
.../blockdev/drbd/DRBD-data-packets.svg | 459 +
.../admin-guide/blockdev/drbd/conn-states-8.dot | 18 +
.../blockdev/drbd/data-structure-v9.rst | 42 +
.../admin-guide/blockdev/drbd/disk-states-8.dot | 16 +
.../drbd/drbd-connection-state-overview.dot | 85 +
.../admin-guide/blockdev/drbd/figures.rst | 30 +
Documentation/admin-guide/blockdev/drbd/index.rst | 19 +
.../admin-guide/blockdev/drbd/peer-states-8.dot | 8 +
Documentation/admin-guide/blockdev/floppy.rst | 255 +
Documentation/admin-guide/blockdev/index.rst | 17 +
Documentation/admin-guide/blockdev/nbd.rst | 31 +
Documentation/admin-guide/blockdev/paride.rst | 207 +
Documentation/admin-guide/blockdev/ramdisk.rst | 153 +
Documentation/admin-guide/blockdev/zoned_loop.rst | 191 +
Documentation/admin-guide/blockdev/zram.rst | 610 +
Documentation/admin-guide/bootconfig.rst | 416 +
Documentation/admin-guide/braille-console.rst | 38 +
Documentation/admin-guide/btmrvl.rst | 124 +
Documentation/admin-guide/bug-bisect.rst | 165 +
Documentation/admin-guide/bug-hunting.rst | 370 +
.../admin-guide/cgroup-v1/blkio-controller.rst | 301 +
Documentation/admin-guide/cgroup-v1/cgroups.rst | 697 +
Documentation/admin-guide/cgroup-v1/cpuacct.rst | 50 +
Documentation/admin-guide/cgroup-v1/cpusets.rst | 874 +
Documentation/admin-guide/cgroup-v1/devices.rst | 132 +
.../admin-guide/cgroup-v1/freezer-subsystem.rst | 131 +
Documentation/admin-guide/cgroup-v1/hugetlb.rst | 139 +
Documentation/admin-guide/cgroup-v1/index.rst | 24 +
Documentation/admin-guide/cgroup-v1/memcg_test.rst | 342 +
Documentation/admin-guide/cgroup-v1/memory.rst | 926 +
Documentation/admin-guide/cgroup-v1/misc.rst | 4 +
Documentation/admin-guide/cgroup-v1/net_cls.rst | 44 +
Documentation/admin-guide/cgroup-v1/net_prio.rst | 57 +
Documentation/admin-guide/cgroup-v1/pids.rst | 93 +
Documentation/admin-guide/cgroup-v1/rdma.rst | 191 +
Documentation/admin-guide/cgroup-v2.rst | 3581 +
Documentation/admin-guide/cifs/authors.rst | 69 +
Documentation/admin-guide/cifs/changes.rst | 9 +
Documentation/admin-guide/cifs/index.rst | 14 +
Documentation/admin-guide/cifs/introduction.rst | 53 +
Documentation/admin-guide/cifs/todo.rst | 133 +
Documentation/admin-guide/cifs/usage.rst | 864 +
Documentation/admin-guide/cifs/winucase_convert.pl | 62 +
Documentation/admin-guide/clearing-warn-once.rst | 9 +
Documentation/admin-guide/cpu-isolation.rst | 357 +
Documentation/admin-guide/cpu-load.rst | 117 +
Documentation/admin-guide/cputopology.rst | 101 +
Documentation/admin-guide/dell_rbu.rst | 128 +
.../admin-guide/device-mapper/cache-policies.rst | 131 +
Documentation/admin-guide/device-mapper/cache.rst | 337 +
Documentation/admin-guide/device-mapper/delay.rst | 54 +
.../admin-guide/device-mapper/dm-clone.rst | 333 +
.../admin-guide/device-mapper/dm-crypt.rst | 212 +
.../admin-guide/device-mapper/dm-dust.rst | 305 +
Documentation/admin-guide/device-mapper/dm-ebs.rst | 51 +
.../admin-guide/device-mapper/dm-flakey.rst | 88 +
Documentation/admin-guide/device-mapper/dm-ima.rst | 718 +
.../admin-guide/device-mapper/dm-init.rst | 133 +
.../admin-guide/device-mapper/dm-inlinecrypt.rst | 129 +
.../admin-guide/device-mapper/dm-integrity.rst | 321 +
Documentation/admin-guide/device-mapper/dm-io.rst | 75 +
Documentation/admin-guide/device-mapper/dm-log.rst | 57 +
.../admin-guide/device-mapper/dm-pcache.rst | 202 +
.../admin-guide/device-mapper/dm-queue-length.rst | 48 +
.../admin-guide/device-mapper/dm-raid.rst | 489 +
.../admin-guide/device-mapper/dm-service-time.rst | 101 +
.../admin-guide/device-mapper/dm-uevent.rst | 110 +
.../admin-guide/device-mapper/dm-zoned.rst | 194 +
Documentation/admin-guide/device-mapper/era.rst | 116 +
Documentation/admin-guide/device-mapper/index.rst | 43 +
Documentation/admin-guide/device-mapper/kcopyd.rst | 47 +
Documentation/admin-guide/device-mapper/linear.rst | 63 +
.../admin-guide/device-mapper/log-writes.rst | 145 +
.../admin-guide/device-mapper/persistent-data.rst | 88 +
.../admin-guide/device-mapper/snapshot.rst | 196 +
.../admin-guide/device-mapper/statistics.rst | 225 +
.../admin-guide/device-mapper/striped.rst | 61 +
Documentation/admin-guide/device-mapper/switch.rst | 141 +
.../device-mapper/thin-provisioning.rst | 427 +
.../admin-guide/device-mapper/unstriped.rst | 135 +
.../admin-guide/device-mapper/vdo-design.rst | 633 +
Documentation/admin-guide/device-mapper/vdo.rst | 413 +
Documentation/admin-guide/device-mapper/verity.rst | 349 +
.../admin-guide/device-mapper/writecache.rst | 114 +
Documentation/admin-guide/device-mapper/zero.rst | 37 +
Documentation/admin-guide/devices.rst | 270 +
Documentation/admin-guide/devices.txt | 3081 +
Documentation/admin-guide/dynamic-debug-howto.rst | 392 +
Documentation/admin-guide/edid.rst | 27 +
Documentation/admin-guide/efi-stub.rst | 103 +
Documentation/admin-guide/ext4.rst | 611 +
Documentation/admin-guide/features.rst | 3 +
.../admin-guide/filesystem-monitoring.rst | 78 +
Documentation/admin-guide/gpio/gpio-aggregator.rst | 218 +
Documentation/admin-guide/gpio/gpio-mockup.rst | 59 +
Documentation/admin-guide/gpio/gpio-sim.rst | 137 +
Documentation/admin-guide/gpio/gpio-virtuser.rst | 177 +
Documentation/admin-guide/gpio/index.rst | 14 +
Documentation/admin-guide/gpio/obsolete.rst | 13 +
.../admin-guide/hw-vuln/attack_vector_controls.rst | 236 +
.../admin-guide/hw-vuln/core-scheduling.rst | 226 +
.../admin-guide/hw-vuln/cross-thread-rsb.rst | 91 +
.../admin-guide/hw-vuln/gather_data_sampling.rst | 109 +
Documentation/admin-guide/hw-vuln/index.rst | 29 +
.../hw-vuln/indirect-target-selection.rst | 168 +
Documentation/admin-guide/hw-vuln/l1d_flush.rst | 69 +
Documentation/admin-guide/hw-vuln/l1tf.rst | 615 +
Documentation/admin-guide/hw-vuln/mds.rst | 303 +
Documentation/admin-guide/hw-vuln/multihit.rst | 167 +
.../admin-guide/hw-vuln/old_microcode.rst | 21 +
.../hw-vuln/processor_mmio_stale_data.rst | 269 +
.../admin-guide/hw-vuln/reg-file-data-sampling.rst | 96 +
Documentation/admin-guide/hw-vuln/rsb.rst | 268 +
.../special-register-buffer-data-sampling.rst | 150 +
Documentation/admin-guide/hw-vuln/spectre.rst | 725 +
Documentation/admin-guide/hw-vuln/srso.rst | 242 +
.../admin-guide/hw-vuln/tsx_async_abort.rst | 270 +
Documentation/admin-guide/hw-vuln/vmscape.rst | 110 +
Documentation/admin-guide/hw_random.rst | 104 +
Documentation/admin-guide/index.rst | 192 +
Documentation/admin-guide/init.rst | 48 +
Documentation/admin-guide/initrd.rst | 383 +
Documentation/admin-guide/iostats.rst | 187 +
Documentation/admin-guide/java.rst | 423 +
Documentation/admin-guide/jfs.rst | 66 +
Documentation/admin-guide/kdump/gdbmacros.txt | 323 +
Documentation/admin-guide/kdump/index.rst | 13 +
Documentation/admin-guide/kdump/kdump.rst | 612 +
Documentation/admin-guide/kdump/vmcoreinfo.rst | 596 +
Documentation/admin-guide/kernel-parameters.rst | 135 +
Documentation/admin-guide/kernel-parameters.txt | 8709 +
.../admin-guide/kernel-per-CPU-kthreads.rst | 325 +
.../admin-guide/laptops/alienware-wmi.rst | 127 +
Documentation/admin-guide/laptops/asus-laptop.rst | 271 +
.../admin-guide/laptops/disk-shock-protection.rst | 151 +
Documentation/admin-guide/laptops/index.rst | 19 +
Documentation/admin-guide/laptops/lg-laptop.rst | 82 +
.../admin-guide/laptops/samsung-galaxybook.rst | 174 +
Documentation/admin-guide/laptops/sony-laptop.rst | 174 +
[Output truncated: showing 1000 of 96042 lines]]
|
| 269/4 |
2026/09/17 11:20 |
llm |
codeexpert |
0m
Model:
Tokens:
input: 37870
output: 37
thoughts: 137
Thoughts: **Analyzing the NTFS3 File Attribute Update Race Condition**
Okay, so the repository only has a single commit, which is completely expected for this situation. No need to dig further into the history. Now, let's get down to the core of the problem the user is outlining. They want a patch for `ntfs_setattr` within `fs/ntfs3/file.c` to resolve a race condition between `truncate_setsize` and `ntfs_set_size`. The proposed solution involves using `filemap_invalidate_lock(inode->i_mapping)` and reordering those two functions. Got it. So, my next step is clear: I need to go read the `fs/ntfs3/file.c` file and specifically focus on the `ntfs_setattr` function, and see how these components currently interact within the code. Let's see what's what.
|
| 270/4 |
2026/09/17 11:20 |
tool |
read-file |
0m
Args: map[File:fs/ntfs3/file.c FirstLine:700 LineCount:80]
Results: map[Contents: 700: return err;
701: }
702:
703: /*
704: * ntfs_setattr - inode_operations::setattr
705: */
706: int ntfs_setattr(struct mnt_idmap *idmap, struct dentry *dentry,
707: struct iattr *attr)
708: {
709: struct inode *inode = d_inode(dentry);
710: struct ntfs_inode *ni = ntfs_i(inode);
711: u32 ia_valid = attr->ia_valid;
712: umode_t mode = inode->i_mode;
713: int err;
714:
715: /* Avoid any operation if inode is bad. */
716: if (unlikely(is_bad_ni(ni)))
717: return -EINVAL;
718:
719: if (unlikely(ntfs3_forced_shutdown(inode->i_sb)))
720: return -EIO;
721:
722: err = setattr_prepare(idmap, dentry, attr);
723: if (err)
724: goto out;
725:
726: if (ia_valid & ATTR_SIZE) {
727: loff_t newsize, oldsize;
728:
729: if (WARN_ON(ni->ni_flags & NI_FLAG_COMPRESSED_MASK)) {
730: /* Should never be here, see ntfs_file_open(). */
731: err = -EOPNOTSUPP;
732: goto out;
733: }
734: inode_dio_wait(inode);
735: oldsize = i_size_read(inode);
736: newsize = attr->ia_size;
737:
738: if (newsize != oldsize) {
739: truncate_setsize(inode, newsize);
740:
741: err = ntfs_set_size(inode, newsize);
742: if (err) {
743: i_size_write(inode, oldsize);
744: goto out;
745: }
746:
747: ni->std_fa |= FILE_ATTRIBUTE_ARCHIVE;
748: ni->ni_flags |= NI_FLAG_UPDATE_PARENT;
749: inode_set_mtime_to_ts(inode,
750: inode_set_ctime_current(inode));
751: }
752: }
753:
754: setattr_copy(idmap, inode, attr);
755:
756: if (!is_ni_base(ni)) {
757: ia_valid &= ~ATTR_SIZE;
758: } else if (mode != inode->i_mode) {
759: err = ntfs_acl_chmod(idmap, dentry);
760: if (err)
761: goto out;
762:
763: /* Linux 'w' -> Windows 'ro'. */
764: if (0222 & inode->i_mode)
765: ni->std_fa &= ~FILE_ATTRIBUTE_READONLY;
766: else
767: ni->std_fa |= FILE_ATTRIBUTE_READONLY;
768: }
769:
770: if (ia_valid & (ATTR_UID | ATTR_GID | ATTR_MODE))
771: ntfs_save_wsl_perm(inode, NULL);
772: mark_inode_dirty(inode);
773: out:
774: return err;
775: }
776:
777: /*
778: * check_read_restriction:
779: * common code for ntfs_file_read_iter and ntfs_file_splice_read
]
|
| 271/4 |
2026/09/17 11:20 |
llm |
codeexpert |
0m
Model:
Tokens:
input: 39392
output: 36
thoughts: 451
Thoughts: **Analyzing the NTFS Attribute Setting Process**
Okay, let's break this down. I'm looking at `ntfs_setattr` in the new `ntfs3` driver, specifically the section dealing with size changes. My immediate thought is, "Huh, this looks familiar; let's see where the potential race condition might be." The code checks for `ATTR_SIZE` in `ia_valid`, handles what seems to be a compressed file (though it shouldn't be here), and then gets to the core logic. I see we have `oldsize` and `newsize`, and if they differ, the code calls `truncate_setsize` followed by `ntfs_set_size`.
But wait, the prompt mentions a race condition between these two functions! That's the key. My brain's already starting to churn. They're asking to fix the race condition in `ntfs_setattr` by using `filemap_invalidate_lock(inode->i_mapping)` and reordering `truncate_setsize` and `ntfs_set_size` correctly. Okay, so we likely have a scenario where the file metadata might be inconsistent if a concurrent operation interferes between the truncation and the NTFS-specific size update.
Right, let me step back and think. What's the standard VFS behavior here? How do other filesystems, both *natively* or NTFS, deal with truncating or extending a file? Is there a standard pattern for invalidating the page cache or taking a lock to ensure data consistency? My instincts tell me there is. I need to understand if the current order of execution is the right way to do it. Should the filesystem-specific size update happen before or after the VFS level truncate operation that invalidates the pages?
Alright, let's explore how other filesystems deal with this issue, and compare their solution, the old NTFS implementation or common VFS patterns. I'll read and analyze `fs/ntfs/file.c` around line 279 in the old driver, as well as several other filesystems. That should illuminate the correct approach for `ntfs3`. This looks like a classic race, and I have to be sure I choose the right tools for the job!
|
| 272/4 |
2026/09/17 11:21 |
tool |
read-file |
0m
Args: map[File:fs/ntfs/file.c FirstLine:265 LineCount:50]
Results: map[Contents: 265: return -EOPNOTSUPP;
266: }
267:
268: err = inode_newsize_ok(vi, attr->ia_size);
269: if (err)
270: return err;
271:
272: inode_dio_wait(vi);
273:
274: /*
275: * Serialize with page faults and pagecache instantiation so that
276: * readers cannot observe the size change until the attribute
277: * updates below have completed.
278: */
279: filemap_invalidate_lock(vi->i_mapping);
280: if (attr->ia_size > old_size) {
281: truncate_pagecache(vi, old_size);
282: i_size_write(vi, attr->ia_size);
283: pagecache_isize_extended(vi, old_size, attr->ia_size);
284: } else {
285: truncate_setsize(vi, attr->ia_size);
286: }
287:
288: err = ntfs_truncate_vfs(vi, attr->ia_size, old_size);
289: if (err)
290: i_size_write(vi, old_size);
291: filemap_invalidate_unlock(vi->i_mapping);
292:
293: return err;
294: }
295:
296: /*
297: * ntfs_setattr
298: *
299: * Called from notify_change() when an attribute is being changed.
300: *
301: * NOTE: Changes in inode size are not supported yet for compressed or
302: * encrypted files.
303: */
304: int ntfs_setattr(struct mnt_idmap *idmap, struct dentry *dentry,
305: struct iattr *attr)
306: {
307: struct inode *vi = d_inode(dentry);
308: int err;
309: unsigned int ia_valid = attr->ia_valid;
310: struct ntfs_inode *ni = NTFS_I(vi);
311: struct ntfs_volume *vol = ni->vol;
312:
313: if (NVolShutdown(vol))
314: return -EIO;
]
|
| 273/4 |
2026/09/17 11:21 |
llm |
codeexpert |
0m
Model:
Tokens:
input: 41070
output: 37
thoughts: 227
Thoughts: **Analyzing the NTFS Race Condition Patch**
Okay, hold on a second. Before I dive *too* deep into this `ntfs_setattr` fix, I need to take a step back and get a broader perspective. Let me see how other filesystems handle the interplay between `truncate_setsize` and block allocation/truncation during attribute setting. It's easy to get tunnel vision. I've been down that road before.
Right, let me double-check the exact requirements. The prompt wants me to fix a race in `ntfs_setattr` within `fs/ntfs3/file.c`. Specifically, it instructs me to address a race between `truncate_setsize` and `ntfs_set_size` using `filemap_invalidate_lock(inode->i_mapping)` *and* to correctly reorder those two functions. Got it. The wording is precise: *using* the lock and *reordering*. No ambiguity there, which is good.
So, let's look at some examples to understand common patterns. I'm going to quickly scan through implementations like `ext4_setattr`, `f2fs_setattr`, `ext2_setsize`, `udf_setsize`, `btrfs`, and `xfs`. Seeing a range of designs will give me a better understanding of how others approach this issue. First up, let's take a closer look at `ext4_setattr`. I'll start there. That's a solid place to begin for comparison.
|
| 274/4 |
2026/09/17 11:21 |
tool |
read-file |
0m
Args: map[File:fs/ext4/inode.c FirstLine:6120 LineCount:50]
Results: map[Contents:6120: * Blocks are going to be removed from the inode. Wait
6121: * for dio in flight.
6122: */
6123: inode_dio_wait(inode);
6124: }
6125:
6126: filemap_invalidate_lock(inode->i_mapping);
6127:
6128: rc = ext4_break_layouts(inode);
6129: if (rc) {
6130: filemap_invalidate_unlock(inode->i_mapping);
6131: goto err_out;
6132: }
6133:
6134: if (attr->ia_size != inode->i_size) {
6135: /* attach jbd2 jinode for EOF folio tail zeroing */
6136: if (attr->ia_size & (inode->i_sb->s_blocksize - 1) ||
6137: oldsize & (inode->i_sb->s_blocksize - 1)) {
6138: error = ext4_inode_attach_jinode(inode);
6139: if (error)
6140: goto out_mmap_sem;
6141: }
6142:
6143: /*
6144: * Update c/mtime and tail zero the EOF folio on
6145: * truncate up. ext4_truncate() handles the shrink case
6146: * below.
6147: */
6148: if (!shrink) {
6149: inode_set_mtime_to_ts(inode,
6150: inode_set_ctime_current(inode));
6151: if (oldsize & (inode->i_sb->s_blocksize - 1)) {
6152: error = ext4_block_zero_eof(inode,
6153: oldsize, LLONG_MAX);
6154: if (error)
6155: goto out_mmap_sem;
6156: }
6157: }
6158:
6159: handle = ext4_journal_start(inode, EXT4_HT_INODE, 3);
6160: if (IS_ERR(handle)) {
6161: error = PTR_ERR(handle);
6162: goto out_mmap_sem;
6163: }
6164: if (ext4_handle_valid(handle) && shrink) {
6165: error = ext4_orphan_add(handle, inode);
6166: orphan = 1;
6167: }
6168:
6169: if (shrink)
]
|
| 275/4 |
2026/09/17 11:21 |
llm |
codeexpert |
0m
Model:
Tokens:
input: 42402
output: 37
thoughts: 24
Thoughts: Here's my attempt at summarizing the thought process, tailored for an expert audience:
**Diving into ext4_setattr Implementation**
Alright, let's zoom in on the `ext4_setattr` function, specifically the section spanning from roughly line 6170 to 6210. I need to refresh my memory on how this code handles the intricacies of setting file attributes in ext4. I'm particularly interested in the details of that specific block of code as it will give me an insight as to how attributes such as timestamps are set, how the inode is updated, and how any potential errors are handled. I'll be looking for any potential race conditions or locking issues that I may have overlooked previously. This should provide some insight.
|
| 276/4 |
2026/09/17 11:21 |
tool |
read-file |
0m
Args: map[File:fs/ext4/inode.c FirstLine:6170 LineCount:40]
Results: map[Contents:6170: ext4_fc_track_range(handle, inode,
6171: (attr->ia_size > 0 ? attr->ia_size - 1 : 0) >>
6172: inode->i_sb->s_blocksize_bits,
6173: EXT_MAX_BLOCKS - 1);
6174: else
6175: ext4_fc_track_range(
6176: handle, inode,
6177: (oldsize > 0 ? oldsize - 1 : oldsize) >>
6178: inode->i_sb->s_blocksize_bits,
6179: (attr->ia_size > 0 ? attr->ia_size - 1 : 0) >>
6180: inode->i_sb->s_blocksize_bits);
6181:
6182: down_write(&EXT4_I(inode)->i_data_sem);
6183: old_disksize = EXT4_I(inode)->i_disksize;
6184: EXT4_I(inode)->i_disksize = attr->ia_size;
6185:
6186: /*
6187: * We have to update i_size under i_data_sem together
6188: * with i_disksize to avoid races with writeback code
6189: * running ext4_wb_update_i_disksize().
6190: */
6191: if (!error)
6192: i_size_write(inode, attr->ia_size);
6193: else
6194: EXT4_I(inode)->i_disksize = old_disksize;
6195: up_write(&EXT4_I(inode)->i_data_sem);
6196: rc = ext4_mark_inode_dirty(handle, inode);
6197: if (!error)
6198: error = rc;
6199: ext4_journal_stop(handle);
6200: if (error)
6201: goto out_mmap_sem;
6202: if (!shrink) {
6203: pagecache_isize_extended(inode, oldsize,
6204: inode->i_size);
6205: } else if (ext4_should_journal_data(inode)) {
6206: ext4_wait_for_tail_page_commit(inode);
6207: }
6208: }
6209:
]
|
| 277/4 |
2026/09/17 11:21 |
llm |
codeexpert |
0m
Model:
Tokens:
input: 43305
output: 36
thoughts: 32
Thoughts: Here's my take:
**Examining File System Implementations**
Okay, I need to zoom in on how this file system interaction is happening. Before I go too deep down a rabbit hole, let's step back and consider how file operations are managed. I think the best place to start is to look at some well-defined file system implementations. I'm thinking of files like `fs/zonefs/file.c` or perhaps `fs/udf/file.c`. These are likely to provide good examples of how they handle file-specific structures and operations. I need to understand how the lower layers are implemented before I go too much further. I'm expecting to find insights into how different file systems manage file metadata, permissions, and the actual data blocks, because that will allow me to contextualize this situation.
|
| 278/4 |
2026/09/17 11:22 |
tool |
read-file |
0m
Args: map[File:fs/udf/file.c FirstLine:230 LineCount:40]
Results: map[Contents: 230: if ((attr->ia_valid & ATTR_GID) &&
231: UDF_QUERY_FLAG(sb, UDF_FLAG_GID_SET) &&
232: !gid_eq(attr->ia_gid, UDF_SB(sb)->s_gid))
233: return -EPERM;
234:
235: if ((attr->ia_valid & ATTR_SIZE) &&
236: attr->ia_size != i_size_read(inode)) {
237: filemap_invalidate_lock(inode->i_mapping);
238: error = udf_setsize(inode, attr->ia_size);
239: filemap_invalidate_unlock(inode->i_mapping);
240: if (error)
241: return error;
242: }
243:
244: if (attr->ia_valid & ATTR_MODE)
245: udf_update_extra_perms(inode, attr->ia_mode);
246:
247: setattr_copy(&nop_mnt_idmap, inode, attr);
248: mark_inode_dirty(inode);
249: if (IS_SYNC(inode))
250: sync_inode_metadata(inode, 1);
251: return 0;
252: }
253:
254: const struct inode_operations udf_file_inode_operations = {
255: .setattr = udf_setattr,
256: };
]
|
| 279/4 |
2026/09/17 11:22 |
llm |
codeexpert |
0m
Model:
Tokens:
input: 43994
output: 37
thoughts: 32
Thoughts: Here's my take on the thought process, as if it were my own:
**Diving into the UDF Filesystem**
Okay, time to get my hands dirty with this UDF filesystem code. I need to understand how file sizes are handled, particularly how they're *set*. Let's zero in on `fs/udf/file.c`. That seems like the logical place to start digging. Right, I remember that `udf_setsize` function... Let's check out how exactly `udf_setsize` functions.
|
| 280/4 |
2026/09/17 11:22 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:fs/udf/file.c Name:udf_setsize]
Results: map[SourceCode:1280: int udf_setsize(struct inode *inode, loff_t newsize)
1281: {
1282: int err = 0;
1283: struct udf_inode_info *iinfo;
1284: unsigned int bsize = i_blocksize(inode);
1285:
1286: if (!(S_ISREG(inode->i_mode) || S_ISDIR(inode->i_mode) ||
1287: S_ISLNK(inode->i_mode)))
1288: return -EINVAL;
1289:
1290: iinfo = UDF_I(inode);
1291: if (newsize > inode->i_size) {
1292: if (iinfo->i_alloc_type == ICBTAG_FLAG_AD_IN_ICB) {
1293: if (bsize >=
1294: (udf_file_entry_alloc_offset(inode) + newsize)) {
1295: down_write(&iinfo->i_data_sem);
1296: iinfo->i_lenAlloc = newsize;
1297: up_write(&iinfo->i_data_sem);
1298: goto set_size;
1299: }
1300: err = udf_expand_file_adinicb(inode);
1301: if (err)
1302: return err;
1303: }
1304: err = udf_extend_file(inode, newsize);
1305: if (err)
1306: return err;
1307: set_size:
1308: truncate_setsize(inode, newsize);
1309: } else {
1310: if (iinfo->i_alloc_type == ICBTAG_FLAG_AD_IN_ICB) {
1311: down_write(&iinfo->i_data_sem);
1312: udf_clear_extent_cache(inode);
1313: memset(iinfo->i_data + iinfo->i_lenEAttr + newsize,
1314: 0x00, bsize - newsize -
1315: udf_file_entry_alloc_offset(inode));
1316: iinfo->i_lenAlloc = newsize;
1317: truncate_setsize(inode, newsize);
1318: up_write(&iinfo->i_data_sem);
1319: goto update_time;
1320: }
1321: err = block_truncate_page(inode->i_mapping, newsize,
1322: udf_get_block);
1323: if (err)
1324: return err;
1325: truncate_setsize(inode, newsize);
1326: down_write(&iinfo->i_data_sem);
1327: udf_clear_extent_cache(inode);
1328: err = udf_truncate_extents(inode);
1329: up_write(&iinfo->i_data_sem);
1330: if (err)
1331: return err;
1332: }
1333: update_time:
1334: inode_set_mtime_to_ts(inode, inode_set_ctime_current(inode));
1335: mark_inode_dirty(inode);
1336: return err;
1337: }
SourceFile:fs/udf/inode.c]
|
| 281/4 |
2026/09/17 11:22 |
llm |
codeexpert |
0m
Model:
Tokens:
input: 45157
output: 33
thoughts: 162
Thoughts: **Analyzing File Size Management in UDF and Beyond**
Okay, hold on a second! I need to really understand the sequence of operations within `udf_setsize`. The order is critical here. When the desired `newsize` is *larger* than the current `inode->i_size`, we extend the file first with `udf_extend_file` and *then* truncate it using `truncate_setsize`. But... what happens when `newsize` is *smaller*? It looks like we call `truncate_setsize` *first*, and then we handle extent truncation with `udf_truncate_extents`.
Hmm, this order discrepancy is making me a little uneasy. I need to get a better handle on the underlying rationale and possible pitfalls. I'm wondering if there are any subtle race conditions at play between these two operations. Maybe this is similar to handling size changes in `ntfs_set_size`.
I should probably broaden my scope. Let me see how other filesystems handle the implications of truncating up versus down. I need to be sure I'm not overlooking a common pattern or a potential vulnerability.
Right, time to dig deeper. I'm going to jump into `truncate_setsize` in mm/truncate.c. I bet it has some valuable insights.
|
| 282/4 |
2026/09/17 11:22 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:mm/truncate.c Name:truncate_setsize]
Results: map[SourceCode: 803: /**
804: * truncate_setsize - update inode and pagecache for a new file size
805: * @inode: inode
806: * @newsize: new file size
807: *
808: * truncate_setsize updates i_size and performs pagecache truncation (if
809: * necessary) to @newsize. It will be typically be called from the filesystem's
810: * setattr function when ATTR_SIZE is passed in.
811: *
812: * Must be called with a lock serializing truncates and writes (generally
813: * i_rwsem but e.g. xfs uses a different lock) and before all filesystem
814: * specific block truncation has been performed.
815: */
816: void truncate_setsize(struct inode *inode, loff_t newsize)
817: {
818: loff_t oldsize = inode->i_size;
819:
820: i_size_write(inode, newsize);
821: if (newsize > oldsize)
822: pagecache_isize_extended(inode, oldsize, newsize);
823: truncate_pagecache(inode, newsize);
824: }
SourceFile:mm/truncate.c]
|
| 283/4 |
2026/09/17 11:22 |
llm |
codeexpert |
0m
Model:
Tokens:
input: 46012
output: 26
thoughts: 598
Thoughts: **Analyzing Filesystem Truncation and Extension Logic**
Okay, so I'm looking at this `truncate_setsize` function, and it seems pretty central to how filesystems handle size changes. The comment mentions it updates `i_size` and manages pagecache truncation, typically triggered during a file's `setattr` operation when the size attribute changes. The crucial part is the lock requirement; it needs to serialize truncates and writes, generally with `i_rwsem`, though some filesystems might use their own lock.
My main concern is distinguishing the behavior when the file is shrinking versus when it's growing. I need to be *very* careful about the order of operations. Let's dig in deeper...
Looking at the code, in `truncate_setsize` itself, it updates `i_size` to the `newsize`, then conditionally extends the pagecache if `newsize > oldsize` using `pagecache_isize_extended`, and *then* does the truncation with `truncate_pagecache`.
Aha! Now I see the problem if we're extending. If `truncate_setsize` is called *before* `ntfs_set_size` (the filesystem-specific function), a reader could slip in between `i_size` being updated, but before the disk metadata is allocated and written! That would be a race condition, and a potential file corruption! Or, what if `ntfs_set_size` *fails*? We'd have `i_size` updated, but the underlying blocks wouldn't be allocated.
The current `ntfs3` code, thankfully, seems to handle this: it calls `truncate_setsize` *after* `ntfs_set_size`, which is exactly what I'm concerned about. We need to be able to make sure `ntfs_set_size` *must* be called first when we are growing the file. If extending, we *must* call `ntfs_set_size` before `truncate_setsize`.
However, the logic seems correct when shrinking. If the file is shrunk, the page cache truncation (done by `truncate_setsize`) MUST happen *before* the filesystem block truncation (done by `ntfs_set_size`). This makes sense: unmap and discard the pages *before* freeing the corresponding disk blocks.
Okay, so the order is CRITICAL when extending. But is it always the *same* order, regardless of extension or shrinking? To be sure, I need to check how other filesystems manage this. Let me search the kernel source and look for patterns around the use of `truncate_setsize` to see what practices they follow for both extending and shrinking. This will allow me to ensure we are following best practices, and can ensure the safety and reliability of the implementation.
|
| 284/4 |
2026/09/17 11:23 |
tool |
grepper |
0m
Args: map[Expression:truncate_setsize PathPrefix:fs/]
Results: map[Output:fs/9p/vfs_inode.c=1017=static int v9fs_vfs_setattr(struct mnt_idmap *idmap,
--
fs/9p/vfs_inode.c-1081- iattr->ia_size != i_size_read(inode)) {
fs/9p/vfs_inode.c:1082: truncate_setsize(inode, iattr->ia_size);
fs/9p/vfs_inode.c-1083- netfs_resize_file(netfs_inode(inode), iattr->ia_size, true);
--
fs/9p/vfs_inode_dotl.c=511=int v9fs_vfs_setattr_dotl(struct mnt_idmap *idmap,
--
fs/9p/vfs_inode_dotl.c-576- i_size_read(inode)) {
fs/9p/vfs_inode_dotl.c:577: truncate_setsize(inode, iattr->ia_size);
fs/9p/vfs_inode_dotl.c-578- netfs_resize_file(netfs_inode(inode), iattr->ia_size, true);
--
fs/adfs/inode.c=302=adfs_setattr(struct mnt_idmap *idmap, struct dentry *dentry, struct iattr *attr)
--
fs/adfs/inode.c-323- if (ia_valid & ATTR_SIZE)
fs/adfs/inode.c:324: truncate_setsize(inode, attr->ia_size);
fs/adfs/inode.c-325-
--
fs/affs/inode.c=216=affs_setattr(struct mnt_idmap *idmap, struct dentry *dentry, struct iattr *attr)
--
fs/affs/inode.c-244-
fs/affs/inode.c:245: truncate_setsize(inode, attr->ia_size);
fs/affs/inode.c-246- affs_truncate(inode);
--
fs/afs/inode.c=762=int afs_setattr(struct mnt_idmap *idmap, struct dentry *dentry,
--
fs/afs/inode.c-816- attr->ia_size > netfs_read_remote_i_size(inode)) {
fs/afs/inode.c:817: truncate_setsize(inode, attr->ia_size);
fs/afs/inode.c-818- netfs_resize_file(&vnode->netfs, size, false);
--
fs/aio.c=360=static void put_aio_ring_file(struct kioctx *ctx)
--
fs/aio.c-366-
fs/aio.c:367: truncate_setsize(inode, 0);
fs/aio.c-368-
--
fs/btrfs/file.c=1526=int btrfs_sync_file(struct file *file, loff_t start, loff_t end, int datasync)
--
fs/btrfs/file.c-1809- * protect against truncate races as the page could now be beyond EOF. Because
fs/btrfs/file.c:1810: * truncate_setsize() writes the inode size before removing pages, once we have
fs/btrfs/file.c-1811- * the page lock we can determine safely if the page is beyond EOF. If it is not
--
fs/btrfs/inode.c=5391=static int btrfs_setsize(struct inode *inode, struct iattr *attr)
--
fs/btrfs/inode.c-5460-
fs/btrfs/inode.c:5461: truncate_setsize(inode, newsize);
fs/btrfs/inode.c-5462-
--
fs/ecryptfs/inode.c=733=static int __ecryptfs_truncate(struct dentry *dentry, const struct iattr *ia)
--
fs/ecryptfs/inode.c-784- if (!(crypt_stat->flags & ECRYPTFS_ENCRYPTED)) {
fs/ecryptfs/inode.c:785: truncate_setsize(inode, ia->ia_size);
fs/ecryptfs/inode.c-786- lower_ia.ia_size = ia->ia_size;
--
fs/ecryptfs/inode.c-804- }
fs/ecryptfs/inode.c:805: truncate_setsize(inode, ia->ia_size);
fs/ecryptfs/inode.c-806- rc = ecryptfs_write_inode_size_to_metadata(inode);
--
fs/exfat/file.c=350=int exfat_setattr(struct mnt_idmap *idmap, struct dentry *dentry,
--
fs/exfat/file.c-415- inode_dio_wait(inode);
fs/exfat/file.c:416: truncate_setsize(inode, attr->ia_size);
fs/exfat/file.c-417-
--
fs/exfat/file.c=754=static int exfat_extend_valid_size(struct inode *inode, loff_t new_valid_size)
--
fs/exfat/file.c-786- if (ret) {
fs/exfat/file.c:787: truncate_setsize(inode, old_valid_size);
fs/exfat/file.c-788- exfat_truncate(inode);
--
fs/ext2/inode.c=1237=static int ext2_setsize(struct inode *inode, loff_t newsize)
--
fs/ext2/inode.c-1255- filemap_invalidate_lock(inode->i_mapping);
fs/ext2/inode.c:1256: truncate_setsize(inode, newsize);
fs/ext2/inode.c-1257- __ext2_truncate_blocks(inode, newsize);
--
fs/f2fs/file.c=637=static int finish_preallocate_blocks(struct inode *inode)
--
fs/f2fs/file.c-657-
fs/f2fs/file.c:658: truncate_setsize(inode, i_size_read(inode));
fs/f2fs/file.c-659- ret = f2fs_truncate(inode);
--
fs/f2fs/file.c=1124=int f2fs_setattr(struct mnt_idmap *idmap, struct dentry *dentry,
--
fs/f2fs/file.c-1235- }
fs/f2fs/file.c:1236: truncate_setsize(inode, attr->ia_size);
fs/f2fs/file.c-1237-
--
fs/f2fs/file.c=3879=static int f2fs_ioc_release_dev_alias(struct file *filp)
--
fs/f2fs/file.c-3929- filemap_invalidate_lock(inode->i_mapping);
fs/f2fs/file.c:3930: truncate_setsize(inode, 0);
fs/f2fs/file.c-3931-
--
fs/fat/file.c=517=int fat_setattr(struct mnt_idmap *idmap, struct dentry *dentry,
--
fs/fat/file.c-586- down_write(&MSDOS_I(inode)->truncate_lock);
fs/fat/file.c:587: truncate_setsize(inode, attr->ia_size);
fs/fat/file.c-588- fat_truncate_blocks(inode, attr->ia_size);
--
fs/gfs2/bmap.c=2095=static int do_grow(struct inode *inode, u64 size)
--
fs/gfs2/bmap.c-2138-
fs/gfs2/bmap.c:2139: truncate_setsize(inode, size);
fs/gfs2/bmap.c-2140- inode_set_mtime_to_ts(&ip->i_inode, inode_set_ctime_current(&ip->i_inode));
--
fs/hfs/inode.c=646=int hfs_inode_setattr(struct mnt_idmap *idmap, struct dentry *dentry,
--
fs/hfs/inode.c-686-
fs/hfs/inode.c:687: truncate_setsize(inode, attr->ia_size);
fs/hfs/inode.c-688- hfs_file_truncate(inode);
--
fs/hfsplus/inode.c=308=static int hfsplus_setattr(struct mnt_idmap *idmap,
--
fs/hfsplus/inode.c-326- }
fs/hfsplus/inode.c:327: truncate_setsize(inode, attr->ia_size);
fs/hfsplus/inode.c-328- hfsplus_file_truncate(inode);
--
fs/hostfs/hostfs_kern.c=804=static int hostfs_setattr(struct mnt_idmap *idmap,
--
fs/hostfs/hostfs_kern.c-868- attr->ia_size != i_size_read(inode))
fs/hostfs/hostfs_kern.c:869: truncate_setsize(inode, attr->ia_size);
fs/hostfs/hostfs_kern.c-870-
--
fs/hpfs/inode.c=260=int hpfs_setattr(struct mnt_idmap *idmap, struct dentry *dentry,
--
fs/hpfs/inode.c-287-
fs/hpfs/inode.c:288: truncate_setsize(inode, attr->ia_size);
fs/hpfs/inode.c-289- hpfs_truncate(inode);
--
fs/jffs2/fs.c=32=int jffs2_do_setattr (struct inode *inode, struct iattr *iattr)
--
fs/jffs2/fs.c-179-
fs/jffs2/fs.c:180: /* We have to do the truncate_setsize() without f->sem held, since
fs/jffs2/fs.c-181- some pages may be locked and waiting for it in read_folio().
--
fs/jffs2/fs.c-185- if (ivalid & ATTR_SIZE && inode->i_size > iattr->ia_size) {
fs/jffs2/fs.c:186: truncate_setsize(inode, iattr->ia_size);
fs/jffs2/fs.c-187- inode->i_blocks = (inode->i_size + 511) >> 9;
--
fs/jfs/file.c=92=int jfs_setattr(struct mnt_idmap *idmap, struct dentry *dentry,
--
fs/jfs/file.c-121-
fs/jfs/file.c:122: truncate_setsize(inode, iattr->ia_size);
fs/jfs/file.c-123- jfs_truncate(inode);
--
fs/libfs.c=916=int simple_setattr(struct mnt_idmap *idmap, struct dentry *dentry,
--
fs/libfs.c-926- if (iattr->ia_valid & ATTR_SIZE)
fs/libfs.c:927: truncate_setsize(inode, iattr->ia_size);
fs/libfs.c-928- setattr_copy(idmap, inode, iattr);
--
fs/minix/file.c=26=static int minix_setattr(struct mnt_idmap *idmap,
--
fs/minix/file.c-41-
fs/minix/file.c:42: truncate_setsize(inode, attr->ia_size);
fs/minix/file.c-43- minix_truncate(inode);
--
fs/nilfs2/inode.c=907=int nilfs_setattr(struct mnt_idmap *idmap, struct dentry *dentry,
--
fs/nilfs2/inode.c-925- inode_dio_wait(inode);
fs/nilfs2/inode.c:926: truncate_setsize(inode, iattr->ia_size);
fs/nilfs2/inode.c-927- nilfs_truncate(inode);
--
fs/ntfs/file.c=254=static int ntfs_setattr_size(struct inode *vi, struct iattr *attr)
--
fs/ntfs/file.c-284- } else {
fs/ntfs/file.c:285: truncate_setsize(vi, attr->ia_size);
fs/ntfs/file.c-286- }
--
fs/ntfs/file.c=579=static ssize_t ntfs_file_write_iter(struct kiocb *iocb, struct iov_iter *from)
--
fs/ntfs/file.c-664- if (ni->data_size != old_data_size) {
fs/ntfs/file.c:665: truncate_setsize(vi, old_data_size);
fs/ntfs/file.c-666- ntfs_attr_truncate(ni, old_data_size);
--
fs/ntfs/inode.c=375=int ntfs_drop_big_inode(struct inode *inode)
--
fs/ntfs/inode.c-390-
fs/ntfs/inode.c:391: truncate_setsize(VFS_I(ni), 0);
fs/ntfs/inode.c-392- ntfs_truncate_vfs(VFS_I(ni), 0, 1);
--
fs/ntfs/inode.c=2410=int ntfs_extend_initialized_size(struct inode *vi, const loff_t offset,
--
fs/ntfs/inode.c-2444- if (err)
fs/ntfs/inode.c:2445: truncate_setsize(vi, old_init_size);
fs/ntfs/inode.c-2446- return err;
--
fs/ntfs3/attrib.c=2009=int attr_collapse_range(struct ntfs_inode *ni, u64 vbo, u64 bytes)
--
fs/ntfs3/attrib.c-2057- /* Simple truncate file at 'vbo'. */
fs/ntfs3/attrib.c:2058: truncate_setsize(&ni->vfs_inode, vbo);
fs/ntfs3/attrib.c-2059- err = attr_set_size(ni, ATTR_DATA, ni->file.ads.name,
--
fs/ntfs3/file.c=706=int ntfs_setattr(struct mnt_idmap *idmap, struct dentry *dentry,
--
fs/ntfs3/file.c-738- if (newsize != oldsize) {
fs/ntfs3/file.c:739: truncate_setsize(inode, newsize);
fs/ntfs3/file.c-740-
--
fs/omfs/file.c=341=static int omfs_setattr(struct mnt_idmap *idmap,
--
fs/omfs/file.c-355- return error;
fs/omfs/file.c:356: truncate_setsize(inode, attr->ia_size);
fs/omfs/file.c-357- omfs_truncate(inode);
--
fs/orangefs/inode.c=697=static int orangefs_setattr_size(struct inode *inode, struct iattr *iattr)
--
fs/orangefs/inode.c-722-
fs/orangefs/inode.c:723: /* This is truncate_setsize in a different order. */
fs/orangefs/inode.c-724- truncate_pagecache(inode, iattr->ia_size);
--
fs/ramfs/file-nommu.c=135=static int ramfs_nommu_resize(struct inode *inode, loff_t newsize, loff_t size)
--
fs/ramfs/file-nommu.c-154-
fs/ramfs/file-nommu.c:155: truncate_setsize(inode, newsize);
fs/ramfs/file-nommu.c-156- return 0;
--
fs/smb/client/cifsfs.c=1519=ssize_t cifs_file_copychunk_range(unsigned int xid,
--
fs/smb/client/cifsfs.c-1596- if (rc > 0 && destoff + rc > i_size_read(target_inode)) {
fs/smb/client/cifsfs.c:1597: truncate_setsize(target_inode, destoff + rc);
fs/smb/client/cifsfs.c-1598- netfs_resize_file(&target_cifsi->netfs,
--
fs/smb/client/smb2ops.c=3508=static long smb3_zero_range(struct file *file, struct cifs_tcon *tcon,
--
fs/smb/client/smb2ops.c-3568- if (rc >= 0) {
fs/smb/client/smb2ops.c:3569: truncate_setsize(inode, new_size);
fs/smb/client/smb2ops.c-3570- spin_lock(&inode->i_lock);
--
fs/smb/client/smb2ops.c=4014=static long smb3_collapse_range(struct file *file, struct cifs_tcon *tcon,
--
fs/smb/client/smb2ops.c-4064-
fs/smb/client/smb2ops.c:4065: truncate_setsize(inode, new_eof);
fs/smb/client/smb2ops.c-4066- spin_lock(&inode->i_lock);
--
fs/smb/client/smb2ops.c=4078=static long smb3_insert_range(struct file *file, struct cifs_tcon *tcon,
--
fs/smb/client/smb2ops.c-4127-
fs/smb/client/smb2ops.c:4128: truncate_setsize(inode, new_eof);
fs/smb/client/smb2ops.c-4129- spin_lock(&inode->i_lock);
--
fs/ubifs/file.c=883=static int do_writepage(struct folio *folio, size_t len)
--
fs/ubifs/file.c-958- * same time. And the problematic one is truncation to smaller size, from where
fs/ubifs/file.c:959: * we have to call 'truncate_setsize()', which first changes @inode->i_size,
fs/ubifs/file.c-960- * then drops the truncated pages. And while dropping the pages, it takes the
fs/ubifs/file.c:961: * page lock. This means that 'do_truncation()' cannot call 'truncate_setsize()'
fs/ubifs/file.c-962- * with @ui_mutex locked, because it would deadlock with 'ubifs_writepage()'.
--
fs/ubifs/file.c-965- * XXX(truncate): with the new truncate sequence this is not true anymore,
fs/ubifs/file.c:966: * and the calls to truncate_setsize can be move around freely. They should
fs/ubifs/file.c-967- * be moved to the very end of the truncate sequence.
--
fs/ubifs/file.c=1100=static int do_truncation(struct ubifs_info *c, struct inode *inode,
--
fs/ubifs/file.c-1133-
fs/ubifs/file.c:1134: truncate_setsize(inode, new_size);
fs/ubifs/file.c-1135-
--
fs/ubifs/file.c=1208=static int do_setattr(struct ubifs_info *c, struct inode *inode,
--
fs/ubifs/file.c-1222- dbg_gen("size %lld -> %lld", inode->i_size, new_size);
fs/ubifs/file.c:1223: truncate_setsize(inode, new_size);
fs/ubifs/file.c-1224- }
--
fs/ubifs/file.c-1229- inode_set_mtime_to_ts(inode, inode_set_ctime_current(inode));
fs/ubifs/file.c:1230: /* 'truncate_setsize()' changed @i_size, update @ui_size */
fs/ubifs/file.c-1231- ui->ui_size = inode->i_size;
--
fs/ubifs/ubifs.h=334=struct ubifs_gced_idx_leb {
--
fs/ubifs/ubifs.h-393- * make sure @inode->i_size is always changed under @ui_mutex, because it
fs/ubifs/ubifs.h:394: * cannot call 'truncate_setsize()' with @ui_mutex locked, because it would
fs/ubifs/ubifs.h-395- * deadlock with 'ubifs_writepage()' (see file.c). All the other inode fields
--
fs/udf/inode.c=1280=int udf_setsize(struct inode *inode, loff_t newsize)
--
fs/udf/inode.c-1307-set_size:
fs/udf/inode.c:1308: truncate_setsize(inode, newsize);
fs/udf/inode.c-1309- } else {
--
fs/udf/inode.c-1316- iinfo->i_lenAlloc = newsize;
fs/udf/inode.c:1317: truncate_setsize(inode, newsize);
fs/udf/inode.c-1318- up_write(&iinfo->i_data_sem);
--
fs/udf/inode.c-1324- return err;
fs/udf/inode.c:1325: truncate_setsize(inode, newsize);
fs/udf/inode.c-1326- down_write(&iinfo->i_data_sem);
--
fs/ufs/inode.c=1167=static int ufs_truncate(struct inode *inode, loff_t size)
--
fs/ufs/inode.c-1187-
fs/ufs/inode.c:1188: truncate_setsize(inode, size);
fs/ufs/inode.c-1189-
--
fs/xfs/xfs_iops.c=905=xfs_vn_setattr_size(
--
fs/xfs/xfs_iops.c-1008- * drop the XFS_MMAP_EXCL lock after the extent manipulations are
fs/xfs/xfs_iops.c:1009: * complete. The truncate_setsize() call also cleans partial EOF page
fs/xfs/xfs_iops.c-1010- * PTEs on extending truncates and hence ensures sub-page block size
--
fs/xfs/xfs_iops.c-1025- */
fs/xfs/xfs_iops.c:1026: truncate_setsize(inode, newsize);
fs/xfs/xfs_iops.c-1027-
--
fs/zonefs/file.c=203=int zonefs_file_truncate(struct inode *inode, loff_t isize)
--
fs/zonefs/file.c-261- zonefs_update_stats(inode, isize);
fs/zonefs/file.c:262: truncate_setsize(inode, isize);
fs/zonefs/file.c-263- z->z_wpoffset = isize;
]
|
| 285/4 |
2026/09/17 11:23 |
llm |
codeexpert |
0m
Model:
Tokens:
input: 53533
output: 40
thoughts: 43
Thoughts: Here's my take on those thoughts:
**Analyzing `xfs_vn_setattr_size` in the XFS Filesystem**
Okay, time to dive into that `xfs_vn_setattr_size` function again. I need to refresh my understanding of how XFS handles attribute size adjustments. Specifically, I should probably focus on how this function impacts block allocation and metadata updates. It's crucial for understanding how XFS deals with file growth and truncation. Let's head over to the `fs/xfs/xfs_iops.c` file β that's usually the place to find the nitty-gritty details on i/o operations and attribute setting. I think the code I'm most interested in will be in the region of lines 980 to 1040, give or take, that's where I'd expect to see the core logic for the size setting function. I'll be looking for interaction with the inode's on-disk metadata and the allocation structures. My goal is to solidify how `xfs_vn_setattr_size` fits into the broader picture of XFS performance and reliability.
|
| 286/4 |
2026/09/17 11:23 |
tool |
read-file |
0m
Args: map[File:fs/xfs/xfs_iops.c FirstLine:980 LineCount:55]
Results: map[Contents: 980:
981: /*
982: * File data changes must be complete before we start the transaction to
983: * modify the inode. This needs to be done before joining the inode to
984: * the transaction because the inode cannot be unlocked once it is a
985: * part of the transaction.
986: *
987: * Start with zeroing any data beyond EOF that we may expose on file
988: * extension, or zeroing out the rest of the block on a downward
989: * truncate.
990: */
991: if (newsize > oldsize) {
992: trace_xfs_zero_eof(ip, oldsize, newsize - oldsize);
993: error = xfs_zero_range(ip, oldsize, newsize - oldsize,
994: &ac, &did_zeroing);
995: } else {
996: error = xfs_truncate_page(ip, newsize, &ac, &did_zeroing);
997: }
998:
999: if (xfs_is_zoned_inode(ip))
1000: xfs_zoned_space_unreserve(mp, &ac);
1001:
1002: if (error)
1003: return error;
1004:
1005: /*
1006: * We've already locked out new page faults, so now we can safely remove
1007: * pages from the page cache knowing they won't get refaulted until we
1008: * drop the XFS_MMAP_EXCL lock after the extent manipulations are
1009: * complete. The truncate_setsize() call also cleans partial EOF page
1010: * PTEs on extending truncates and hence ensures sub-page block size
1011: * filesystems are correctly handled, too.
1012: *
1013: * We have to do all the page cache truncate work outside the
1014: * transaction context as the "lock" order is page lock->log space
1015: * reservation as defined by extent allocation in the writeback path.
1016: * Hence a truncate can fail with ENOMEM from xfs_trans_alloc(), but
1017: * having already truncated the in-memory version of the file (i.e. made
1018: * user visible changes). There's not much we can do about this, except
1019: * to hope that the caller sees ENOMEM and retries the truncate
1020: * operation.
1021: *
1022: * And we update in-core i_size and truncate page cache beyond newsize
1023: * before writeback the [i_disk_size, newsize] range, so we're
1024: * guaranteed not to write stale data past the new EOF on truncate down.
1025: */
1026: truncate_setsize(inode, newsize);
1027:
1028: /*
1029: * We are going to log the inode size change in this transaction so
1030: * any previous writes that are beyond the on disk EOF and the new
1031: * EOF that have not been written out need to be written here. If we
1032: * do not write the data out, we expose ourselves to the null files
1033: * problem. Note that this includes any block zeroing we did above;
1034: * otherwise those blocks may not be zeroed after a crash.
]
|
| 287/4 |
2026/09/17 11:23 |
llm |
codeexpert |
0m
Model:
Tokens:
input: 54826
output: 40
thoughts: 56
Thoughts: **Analyzing `xfs_vn_setattr_size` and its Filemap Interaction**
Okay, let's dive into `xfs_vn_setattr_size`. My focus is on understanding its interaction with the filemap, specifically where it's calling `filemap_invalidate_lock`. That's the critical bit I need to pin down. Let's see...I'll need to go to `fs/xfs/xfs_iops.c` and zero in on lines 905 through 979. Those lines should contain the core logic I'm interested in, based on the function name. I anticipate this will be a relatively straightforward analysis, but it's important to be meticulous in these matters. Time to get to it.
|
| 288/4 |
2026/09/17 11:23 |
tool |
read-file |
0m
Args: map[File:fs/xfs/xfs_iops.c FirstLine:905 LineCount:70]
Results: map[Contents: 905: xfs_vn_setattr_size(
906: struct mnt_idmap *idmap,
907: struct dentry *dentry,
908: struct iattr *iattr)
909: {
910: struct inode *inode = d_inode(dentry);
911: struct xfs_inode *ip = XFS_I(inode);
912: struct xfs_mount *mp = ip->i_mount;
913: xfs_off_t oldsize = inode->i_size;
914: xfs_off_t newsize = iattr->ia_size;
915: struct xfs_trans *tp;
916: int error;
917: uint lock_flags = 0;
918: uint resblks = 0;
919: bool did_zeroing = false;
920: struct xfs_zone_alloc_ctx ac = { };
921:
922: xfs_assert_ilocked(ip, XFS_IOLOCK_EXCL | XFS_MMAPLOCK_EXCL);
923: ASSERT(S_ISREG(inode->i_mode));
924: ASSERT((iattr->ia_valid & (ATTR_UID|ATTR_GID|ATTR_ATIME|ATTR_ATIME_SET|
925: ATTR_MTIME_SET|ATTR_TIMES_SET)) == 0);
926:
927: trace_xfs_setattr(ip);
928:
929: error = xfs_vn_change_ok(idmap, dentry, iattr);
930: if (error)
931: return error;
932:
933: /*
934: * Short circuit the truncate case for zero length files.
935: */
936: if (newsize == 0 && oldsize == 0 && ip->i_df.if_nextents == 0) {
937: if (!(iattr->ia_valid & (ATTR_CTIME|ATTR_MTIME)))
938: return 0;
939:
940: /*
941: * Use the regular setattr path to update the timestamps.
942: */
943: iattr->ia_valid &= ~ATTR_SIZE;
944: return xfs_setattr_nonsize(idmap, dentry, ip, iattr);
945: }
946:
947: /*
948: * Make sure that the dquots are attached to the inode.
949: */
950: error = xfs_qm_dqattach(ip);
951: if (error)
952: return error;
953:
954: /*
955: * Wait for all direct I/O to complete.
956: */
957: inode_dio_wait(inode);
958:
959: /*
960: * Normally xfs_zoned_space_reserve is supposed to be called outside the
961: * IOLOCK. For truncate we can't do that since ->setattr is called with
962: * it already held by the VFS. So for now chicken out and try to
963: * allocate space under it.
964: *
965: * To avoid deadlocks this means we can't block waiting for space, which
966: * can lead to spurious -ENOSPC if there are no directly available
967: * blocks. We mitigate this a bit by allowing zeroing to dip into the
968: * reserved pool, but eventually the VFS calling convention needs to
969: * change.
970: */
971: if (xfs_is_zoned_inode(ip)) {
972: error = xfs_zoned_space_reserve(mp, 1,
973: XFS_ZR_NOWAIT | XFS_ZR_RESERVED, &ac);
974: if (error) {
]
|
| 289/4 |
2026/09/17 11:23 |
llm |
codeexpert |
0m
Model:
Tokens:
input: 56240
output: 38
thoughts: 576
Thoughts: **Analyzing the `ntfs_setattr` Race Condition**
Okay, let's break this down. The prompt wants me to patch `ntfs_setattr` in `fs/ntfs3/file.c` to fix a race condition between `truncate_setsize` and `ntfs_set_size`. The solution involves `filemap_invalidate_lock(inode->i_mapping)` and, crucially, reordering these two functions. But *why*? I need to understand the underlying issue before crafting a solution.
Let's look at the current code snippet provided. We have this:
```c
if (ia_valid & ATTR_SIZE) {
loff_t newsize, oldsize;
if (WARN_ON(ni->ni_flags & NI_FLAG_COMPRESSED_MASK)) {
/* Should never be here, see ntfs_file_open(). */
err = -EOPNOTSUPP;
goto out;
}
inode_dio_wait(inode);
oldsize = i_size_read(inode);
newsize = attr->ia_size;
if (newsize != oldsize) {
truncate_setsize(inode, newsize);
err = ntfs_set_size(inode, newsize);
if (err) {
i_size_write(inode, oldsize);
goto out;
}
ni->std_fa |= FILE_ATTRIBUTE_ARCHIVE;
ni->ni_flags |= NI_FLAG_UPDATE_PARENT;
inode_set_mtime_to_ts(inode,
inode_set_ctime_current(inode));
}
}
```
Okay, the code first checks if the `ATTR_SIZE` attribute is valid. Then, it compares the current file size (`oldsize`) with the new size (`newsize`). If they differ, the code calls `truncate_setsize` followed by `ntfs_set_size`. The critical question is *when* does the order of these two operations matter?
Is it determined by whether the new size is less than or equal to, or greater than, the old size? Does the reordering depend on whether we are shrinking or extending the file? Perhaps `ntfs_set_size` is intended to happen first when extending and second when shrinking? Or the order of operations depends on the file size change direction, i.e. `newsize <= oldsize` or `newsize > oldsize`?
I need to dig deeper. I need to understand how these functions interact at a low level, and how they handle concurrent access. I should check `attr_collapse_range` in `fs/ntfs3/attrib.c` and other functions to get a clearer picture of the file size manipulation in this driver. Let me look at line 2055-2070 in `fs/ntfs3/attrib.c`.
|
| 290/4 |
2026/09/17 11:24 |
tool |
read-file |
0m
Args: map[File:fs/ntfs3/attrib.c FirstLine:2055 LineCount:20]
Results: map[Contents:2055: valid_size = min(ni->i_valid, vbo);
2056:
2057: /* Simple truncate file at 'vbo'. */
2058: truncate_setsize(&ni->vfs_inode, vbo);
2059: err = attr_set_size(ni, ATTR_DATA, ni->file.ads.name,
2060: ni->file.ads.len, &ni->file.run, vbo,
2061: &valid_size, true);
2062:
2063: if (!err && valid_size < ni->i_valid)
2064: ni->i_valid = valid_size;
2065:
2066: goto out;
2067: }
2068:
2069: vcn = vbo >> sbi->cluster_bits;
2070: len = bytes >> sbi->cluster_bits;
2071: end = vcn + len;
2072: dealloc = 0;
2073: done = 0;
2074:
]
|
| 291/4 |
2026/09/17 11:24 |
llm |
codeexpert |
0m
Model:
Tokens:
input: 57816
output: 14
thoughts: 158
Thoughts: **Investigating the NTFS Filesystem Issue**
Okay, so I've hit a snag and need to dig deeper. My first instinct is to see what kind of chatter already exists β are there discussions, commits, or mailing list patches on this specific issue? I should start broad. Hold on, let's refine this a bit, let's focus the search! I'm going to hit LKML and the git logs directly. The terms that seem most relevant are: "ntfs_setattr" coupled with "truncate_setsize," or perhaps "ntfs_set_size" with "truncate_setsize," and let's throw in "filemap_invalidate_lock" with "ntfs3". Also let's try "ntfs_setattr" with "filemap_invalidate_lock"
Wait, I need to check my work. I might as well search the whole repository, including documentation, for those terms. It's possible the earlier git-log didn't capture everything because the tree was younger? Hold on...why did `git log` only show a single commit? That can't be right. Let's try `git log -n 5` without a path prefix to ensure I get the full picture. I need a more complete view of what's been happening.
|
| 292/4 |
2026/09/17 11:24 |
tool |
git-log |
0m
Error:
Args:
Results:
|
| 293/4 |
2026/09/17 11:24 |
llm |
codeexpert |
0m
Model:
Tokens:
input: 58299
output: 20
thoughts: 21
Thoughts: Here's my summary, as though I were thinking through the process:
**Reviewing the Git History**
Okay, so I need to dig into the Git history. Let's start with a sanity check. I'm going to use `git log` to get a comprehensive view. The crucial thing here is the `PathPrefix`. I need to ensure I'm looking at the root of the repository. So, I'm explicitly setting `PathPrefix` to an empty string. That should give me the entire commit history, unrestricted by any path filters. This is my baseline. From this, I can begin to filter and hone in on more specific aspects of the repo, but right now, I need the complete picture to assess anything further.
|
| 294/4 |
2026/09/17 11:24 |
tool |
git-log |
0m
Error:
Args:
Results:
|
| 295/4 |
2026/09/17 11:24 |
llm |
codeexpert |
0m
Model:
Tokens:
input: 58530
output: 21
thoughts: 24
Thoughts: Okay, here's my interpretation of that thought process, summarized as you requested:
**Debugging a Path Prefix Issue**
Alright, so the `PathPrefix` variable was coming up as an empty string. That's a classic gotcha, because it evaluates to "falsy" in most of these contexts. Meaning the code probably thought there was *no* path specified, when I actually wanted it to consider the current directory. So, to fix that, I'll explicitly set `PathPrefix` to `"."`. That should ensure it correctly interprets the intended relative path to the current working directory, and hopefully resolves the underlying issue I'm seeing. This should get everything working as expected.
|
| 296/4 |
2026/09/17 11:25 |
tool |
git-log |
0m
Args: map[Count:5 PathPrefix:.]
Results: map[Output:fd73f4a66598 Linux 7.3-rc3
]
|
| 297/4 |
2026/09/17 11:25 |
llm |
codeexpert |
0m
Model:
Tokens:
input: 58753
output: 19
thoughts: 82
Thoughts: Okay, here's my take on those thoughts, framed as my own:
**Investigating a Potential Race Condition**
Alright, so the repository I'm looking at is a shallow clone, with just a single commit, `fd73f4a66598`. No problem there, that's perfectly acceptable for this initial investigation. The task at hand is to pinpoint any potential race conditions, and it seems like the best starting point is to examine how `truncate_setsize` and `filemap_invalidate_lock` interact, considering the context of those functions.
My strategy is clear: I'm going to leverage the power of `grep` to quickly scan the kernel source tree. I'll search for occurrences of both `truncate_setsize` and `filemap_invalidate_lock`, and I'll include 'race' to expand the search. This should allow me to focus in on any comments or code that explicitly addresses potential concurrency issues or synchronization around these key functions and locking. This should narrow down the search to areas with high probability of having an impact.
|
| 298/4 |
2026/09/17 11:25 |
tool |
grepper |
0m
Args: map[Expression:invalidate_lock.*truncate]
Results: map[Output:Documentation/filesystems/locking.rst=325=returns zero on success. The filesystem must exclusively acquire
Documentation/filesystems/locking.rst:326:invalidate_lock before invalidating page cache in truncate / hole punch
Documentation/filesystems/locking.rst-327-path (and thus calling into ->invalidate_folio) to block races between page
--
Documentation/mm/process_addrs.rst=440=There is also a file-system specific lock ordering comment located at the top of
--
Documentation/mm/process_addrs.rst-450- ->i_rwsem
Documentation/mm/process_addrs.rst:451: ->invalidate_lock (acquired by fs in truncate path)
Documentation/mm/process_addrs.rst-452- ->i_mmap_rwsem (truncate->unmap_mapping_range)
--
fs/xfs/xfs_file.c=1967=xfs_dax_read_fault(
--
fs/xfs/xfs_file.c-1988- * sb_start_pagefault(vfs, freeze)
fs/xfs/xfs_file.c:1989: * invalidate_lock (vfs/XFS_MMAPLOCK - truncate serialisation)
fs/xfs/xfs_file.c-1990- * page_lock (MM)
--
fs/zonefs/zonefs.h=87=struct zonefs_inode_info {
--
fs/zonefs/zonefs.h-100- * i_truncate_mutex. Only zonefs_seq_file_truncate() takes both lock
fs/zonefs/zonefs.h:101: * (invalidate_lock first, i_truncate_mutex second).
fs/zonefs/zonefs.h-102- */
--
mm/filemap.c-88- * ->i_rwsem
mm/filemap.c:89: * ->invalidate_lock (acquired by fs in truncate path)
mm/filemap.c-90- * ->i_mmap_rwsem (truncate->unmap_mapping_range)
]
|
| 299/4 |
2026/09/17 11:25 |
llm |
codeexpert |
0m
Model:
Tokens:
input: 59616
output: 36
thoughts: 38
Thoughts: Here's my take on the thought process, as requested:
**Diving into Filesystem Locking in the Kernel**
Okay, so I'm thinking I need a refresher on some of the nuances of filesystem locking within the kernel. I remember seeing a pretty detailed explanation somewhere in the documentation. Right, that's it - I should consult the documentation. Specifically, it's probably going to be in `Documentation/filesystems/locking.rst`. I'll open that up right away. Let's start with a focused read. Hmm, let me skip ahead to lines 320 through 345. I'm expecting those lines to deal with a specific locking mechanism, or perhaps a particular locking scenario that I need to be aware of to solve the issue I'm dealing with. Let's see what gems are there.
|
| 300/4 |
2026/09/17 11:25 |
tool |
read-file |
0m
Args: map[File:Documentation/filesystems/locking.rst FirstLine:320 LineCount:35]
Results: map[Contents: 320: filesystems and by the swapper. The latter will eventually go away. Please,
321: keep it that way and don't breed new callers.
322:
323: ->invalidate_folio() is called when the filesystem must attempt to drop
324: some or all of the buffers from the page when it is being truncated. It
325: returns zero on success. The filesystem must exclusively acquire
326: invalidate_lock before invalidating page cache in truncate / hole punch
327: path (and thus calling into ->invalidate_folio) to block races between page
328: cache invalidation and page cache filling functions (fault, read, ...).
329:
330: ->release_folio() is called when the MM wants to make a change to the
331: folio that would invalidate the filesystem's private data. For example,
332: it may be about to be removed from the address_space or split. The folio
333: is locked and not under writeback. It may be dirty. The gfp parameter
334: is not usually used for allocation, but rather to indicate what the
335: filesystem may do to attempt to free the private data. The filesystem may
336: return false to indicate that the folio's private data cannot be freed.
337: If it returns true, it should have already removed the private data from
338: the folio. If a filesystem does not provide a ->release_folio method,
339: the pagecache will assume that private data is buffer_heads and call
340: try_to_free_buffers().
341:
342: ->free_folio() is called when the kernel has dropped the folio
343: from the page cache.
344:
345: ->launder_folio() may be called prior to releasing a folio if
346: it is still found to be dirty. It returns zero if the folio was successfully
347: cleaned, or an error value if not. Note that in order to prevent the folio
348: getting mapped back in and redirtied, it needs to be kept locked
349: across the entire operation.
350:
351: ->swap_activate() will be called to prepare the given file for swap. It
352: should perform any validation and preparation necessary to ensure that
353: writes can be performed with minimal memory allocation. It should call
354: add_swap_extent(), or the helper iomap_swapfile_activate(), and return
]
|
| 301/4 |
2026/09/17 11:25 |
llm |
codeexpert |
0m
Model:
Tokens:
input: 60553
output: 30
thoughts: 23
Thoughts: Here's my take on those thoughts:
**Locking and Filesystem Operations - Let's Dig In**
Okay, so I need to refresh my memory on the interactions between file locking and the `setattr` and `truncate` operations within the filesystem. It's crucial, obviously, to ensure data integrity and avoid race conditions, especially when dealing with concurrent access. I'm thinking the best place to start is the official documentation, specifically `Documentation/filesystems/locking.rst`. That document usually has the authoritative definitions of locking semantics in the kernel. I'll need to pay close attention to how `setattr` and `truncate` are handled in relation to different locking mechanisms, like advisory locks and mandatory locks. Are there specific lock types required, and how do they interact? Are there any potential gotchas or edge cases, like signal handling, that the documentation highlights? This will provide the foundation for understanding how my code should interact with these operations when implementing... well, whatever I'm working on! Understanding these fundamentals is key.
|
| 302/4 |
2026/09/17 11:26 |
tool |
grepper |
0m
Args: map[Expression:setattr PathPrefix:Documentation/filesystems/locking.rst]
Results: map[Output:Documentation/filesystems/locking.rst=62=prototypes::
--
Documentation/filesystems/locking.rst-78- struct posix_acl * (*get_inode_acl)(struct inode *, int, bool);
Documentation/filesystems/locking.rst:79: int (*setattr) (struct mnt_idmap *, struct dentry *, struct iattr *);
Documentation/filesystems/locking.rst-80- int (*getattr) (struct mnt_idmap *, const struct path *, struct kstat *, u32, unsigned int);
--
Documentation/filesystems/locking.rst=113=get_link: no
Documentation/filesystems/locking.rst:114:setattr: exclusive
Documentation/filesystems/locking.rst-115-permission: no (may not block if called in rcu-walk mode)
]
|
| 303/4 |
2026/09/17 11:26 |
llm |
codeexpert |
0m
Model:
Tokens:
input: 61035
output: 31
thoughts: 2014
Thoughts: **Analyzing the NTFS Truncate Race Condition**
Okay, let's break this down systematically. I'm revisiting `fs/ntfs3/file.c` and specifically `ntfs_setattr`. The task is to fix a race condition between `truncate_setsize` and `ntfs_set_size` using `filemap_invalidate_lock` and, crucially, reordering the calls.
First, I need to clearly understand *why* there's a race and which order is problematic. Right now, the code calls `truncate_setsize` *before* `ntfs_set_size`. The comment says something about this not applying to compressed files, so let's check that we aren't handling any compressed files. The code currently does the following:
1. Checks if it's a valid inode and handles some shutdown cases.
2. Prepares the setting of attributes via `setattr_prepare()`.
3. If `ATTR_SIZE` is set:
* Calculates new and old size.
* Warns about compressed files (which should *never* be here.)
* Waits on `inode_dio_wait()`.
* Calls `truncate_setsize(inode, newsize)`.
* Calls `ntfs_set_size(inode, newsize)`.
* Handles errors by writing the old size back and exiting.
* Sets archive flag and update parent flag.
* Sets modified/changed timestamps.
4. Finally calls `setattr_copy()` to copy the attributes.
Now I need to understand what's happening if `newsize` is different from `oldsize`. If `newsize` is less than `oldsize`, it's a truncate/shrink. If `newsize` is greater, it's an extension. This is important to understand which call is likely to fail in which case.
The key is realizing that `ntfs_set_size` *can* fail, returning `-EFBIG` or `-ENOSPC`, or other disk errors. That's a critical point! If `truncate_setsize` is called *first*, and *then* `ntfs_set_size` fails, the page cache has *already* been truncated by `truncate_pagecache()` and the `i_size` has been set, but the underlying NTFS metadata might not reflect the change, leading to inconsistencies. That's why the current code has `i_size_write(inode, oldsize)` in the error path. If ntfs_set_size fails, then `i_size` needs to be set back to its old value!
But wait... What happens if `ntfs_set_size` is called *first*? Importantly, I've checked the definition of `ntfs_set_size` in `fs/ntfs3/inode.c`, and it **doesn't** directly touch `inode->i_size`. It updates internal NTFS structures (`ni->i_valid`), and `attr_set_size()` updates the file size in the underlying NTFS structures. `truncate_setsize` *is* the one that updates `inode->i_size`! So, if `ntfs_set_size` fails, we haven't touched the page cache *or* the `i_size`. That is, we can simply return the error without any cleanup, as there is *nothing* to clean up.
This strongly suggests that reordering to call `ntfs_set_size` *before* `truncate_setsize` might solve the problem. Let me look at other filesystems to see how they handle size changes to confirm. I should also see if there are other places where `truncate_setsize` or `attr_set_size` or `ntfs_set_size` are called, which may expose similar patterns.
Now, I need to figure out *where* to put `filemap_invalidate_lock(inode->i_mapping)`. Based on my understanding, it must be inserted *before* `ntfs_set_size` (now the first call) to ensure the cache is invalidated *before* modifying the underlying NTFS data, protecting against the race. This needs to be checked against other filesystems. The next step is to write a patch to accomplish this.
|
| 304/4 |
2026/09/17 11:26 |
tool |
grepper |
0m
Args: map[Expression:ntfs_set_size PathPrefix:fs/ntfs3]
Results: map[Output:fs/ntfs3/file.c=466=static long ntfs_fallocate(struct file *file, int mode, loff_t vbo, loff_t len)
--
fs/ntfs3/file.c-654- */
fs/ntfs3/file.c:655: err = ntfs_set_size(inode, new_size);
fs/ntfs3/file.c-656- if (err)
--
fs/ntfs3/file.c-678- if (mode & FALLOC_FL_KEEP_SIZE) {
fs/ntfs3/file.c:679: err = ntfs_set_size(inode, i_size);
fs/ntfs3/file.c-680- if (err)
--
fs/ntfs3/file.c=706=int ntfs_setattr(struct mnt_idmap *idmap, struct dentry *dentry,
--
fs/ntfs3/file.c-740-
fs/ntfs3/file.c:741: err = ntfs_set_size(inode, newsize);
fs/ntfs3/file.c-742- if (err) {
--
fs/ntfs3/file.c=1239=static ssize_t ntfs_file_write_iter(struct kiocb *iocb, struct iov_iter *from)
--
fs/ntfs3/file.c-1286- */
fs/ntfs3/file.c:1287: ret = ntfs_set_size(inode, endbyte);
fs/ntfs3/file.c-1288- if (ret)
--
fs/ntfs3/inode.c=860=static void ntfs_readahead(struct readahead_control *rac)
--
fs/ntfs3/inode.c-882-
fs/ntfs3/inode.c:883:int ntfs_set_size(struct inode *inode, u64 new_size)
fs/ntfs3/inode.c-884-{
--
fs/ntfs3/ntfs_fs.h=796=static inline struct inode *ntfs_iget5(struct super_block *sb,
--
fs/ntfs3/ntfs_fs.h-801-}
fs/ntfs3/ntfs_fs.h:802:int ntfs_set_size(struct inode *inode, u64 new_size);
fs/ntfs3/ntfs_fs.h-803-int ntfs3_write_inode(struct inode *inode, struct writeback_control *wbc);
]
|
| 305/4 |
2026/09/17 11:26 |
llm |
codeexpert |
0m
Model:
Tokens:
input: 64692
output: 37
thoughts: 54
Thoughts: **Diving into the NTFS Fallocate Implementation**
Okay, so I need to understand how `fallocate` is implemented within the NTFS3 filesystem. The code has to be complex, so let's start with a focused look. Let's head over to the `fs/ntfs3/file.c` file and specifically examine the `ntfs_fallocate` function. I think the critical area I want to understand is lines 650 to 670, but it will be better to look at a slightly larger context, so I will scope out lines 645-685. Reading that should give me a good handle on the core of the `fallocate` functionality in this part of the filesystem.
|
| 306/4 |
2026/09/17 11:26 |
tool |
read-file |
0m
Args: map[File:fs/ntfs3/file.c FirstLine:645 LineCount:40]
Results: map[Contents: 645: }
646:
647: err = inode_newsize_ok(inode, new_size);
648: if (err)
649: goto out;
650:
651: if (new_size > i_size) {
652: /*
653: * Allocate clusters, do not change 'valid' size.
654: */
655: err = ntfs_set_size(inode, new_size);
656: if (err)
657: goto out;
658: }
659:
660: if (is_supported_holes) {
661: CLST vcn = vbo >> cluster_bits;
662: CLST cend = bytes_to_cluster(sbi, end);
663: CLST lcn, clen;
664: bool new;
665:
666: /*
667: * Allocate and zero new clusters.
668: */
669: for (; vcn < cend; vcn += clen) {
670: err = attr_data_get_block(ni, vcn, cend - vcn,
671: &lcn, &clen, &new,
672: true, NULL, false);
673: if (err)
674: goto out;
675: }
676: }
677:
678: if (mode & FALLOC_FL_KEEP_SIZE) {
679: err = ntfs_set_size(inode, i_size);
680: if (err)
681: goto out;
682: }
683: }
684:
]
|
| 307/4 |
2026/09/17 11:26 |
llm |
codeexpert-compressor |
0m
Model:
Reply: ### 1. Approaches Tried and Results
- **Examined `ntfs_setattr` in `fs/ntfs3/file.c`**:
- Found definition at lines 706β775.
- In `ia_valid & ATTR_SIZE` block (lines 726β752):
```c
if (ia_valid & ATTR_SIZE) {
loff_t newsize, oldsize;
if (WARN_ON(ni->ni_flags & NI_FLAG_COMPRESSED_MASK)) {
err = -EOPNOTSUPP;
goto out;
}
inode_dio_wait(inode);
oldsize = i_size_read(inode);
newsize = attr->ia_size;
if (newsize != oldsize) {
truncate_setsize(inode, newsize);
err = ntfs_set_size(inode, newsize);
if (err) {
i_size_write(inode, oldsize);
goto out;
}
...
}
}
```
- Identified problem: `truncate_setsize(inode, newsize)` happens before `ntfs_set_size(inode, newsize)` without holding `filemap_invalidate_lock(inode->i_mapping)`.
- In failure cases (`ntfs_set_size` fails), `truncate_setsize` has already updated `i_size` and invalidated page cache, then rolls back with `i_size_write(inode, oldsize)`, but cache state is damaged/inconsistent. Moreover, during extension/truncation, readers/mmap can race with metadata changes.
- **Examined `filemap_invalidate_lock` usage across filesystems**:
- Grepped `filemap_invalidate_lock.*i_mapping` across `fs/`:
- `fs/ntfs3/file.c`: Used in `ntfs_fallocate` around lines 520, 692.
- `fs/ntfs/file.c`: In `ntfs_setattr_size`, wraps `filemap_invalidate_lock(vi->i_mapping)` around pagecache/i_size changes and `ntfs_truncate_vfs`.
- `fs/udf/file.c` and `fs/udf/inode.c`: In `udf_setattr`, wraps `filemap_invalidate_lock(inode->i_mapping)` around size change. In `udf_setsize`, on expansion calls `udf_extend_file` (or `udf_expand_file_adinicb`) *first*, then `truncate_setsize`.
- `fs/ext2/inode.c`: `ext2_setsize` locks `filemap_invalidate_lock`, calls `truncate_setsize`, then `ext2_truncate_blocks` (or vice versa depending on shrink/grow).
- **Examined `ntfs_fallocate` in `fs/ntfs3/file.c`**:
- Found locking pattern:
```c
inode_dio_wait(inode);
filemap_invalidate_lock(mapping);
map_locked = true;
...
if (map_locked)
filemap_invalidate_unlock(mapping);
```
- **Examined `ntfs_set_size` in `fs/ntfs3/inode.c`**:
- Found definition at lines 883β915:
- Checks maxbytes bounds (`maxbytes_sparse` or `maxbytes`).
- Sets dirty state (`NTFS_DIRTY_DIRTY`).
- Takes `ni_lock(ni)` and `down_write(&ni->file.run_lock)`.
- If `new_size < ni->i_valid`, sets `ni->i_valid = new_size`.
- Calls `attr_set_size(...)`.
- Unlocks `ni->file.run_lock` and `ni_lock`.
- Returns error code.
- **Git history check**:
- Repository is a shallow/single-commit clone (`fd73f4a66598 Linux 7.3-rc3`), commit history for previous commits on `ntfs_setattr` is unavailable.
---
### 2. Hypotheses, Theories, and Active Lines of Investigation
- **The exact race and ordering problem**:
- The prompt specifies: "fix the race condition between `truncate_setsize` and `ntfs_set_size` by using `filemap_invalidate_lock(inode->i_mapping)` and reordering `truncate_setsize` and `ntfs_set_size` correctly."
- When extending vs shrinking:
- Or specifically: why reorder `truncate_setsize` and `ntfs_set_size`?
- If `ntfs_set_size(inode, newsize)` is called first: disk space / attributes are allocated/checked before `truncate_setsize(inode, newsize)` updates `i_size` and truncates page cache. If `ntfs_set_size` fails (e.g. -ENOSPC, -EFBIG, I/O error), `i_size` has not been modified yet by `truncate_setsize`, eliminating the need to rollback `i_size_write(inode, oldsize)` and avoiding corrupted pagecache states.
- Alternatively, check how `ntfs_truncate` or other drivers order `truncate_setsize` vs disk allocation. In standard VFS truncation or other filesystems:
- If shrinking: page cache truncate vs block freeing. But `ntfs_set_size` handles both shrink and grow (allocates blocks on expand or frees/sets non-resident attribute size).
- If `ntfs_set_size` is run first before `truncate_setsize`: `err = ntfs_set_size(inode, newsize); if (err) goto ...; truncate_setsize(inode, newsize);`.
- What about `filemap_invalidate_lock`:
Must hold `filemap_invalidate_lock(inode->i_mapping)` while performing the size change operations (`ntfs_set_size` and `truncate_setsize`), and `filemap_invalidate_unlock(inode->i_mapping)` afterwards.
- Need to verify whether `filemap_invalidate_lock` should surround the size change block or if there's any other place in `ntfs_setattr` where it unlocks.
- Need to check if `inode->i_mapping` is already available as a local variable or `inode->i_mapping`.
- Check error paths: if `ntfs_set_size` returns error, must unlock `filemap_invalidate_unlock(inode->i_mapping)` before returning / jumping out.
---
### 3. Key File Paths, Structs, and Relevant Code Snippets
- **File**: `fs/ntfs3/file.c`
- Function: `ntfs_setattr` (lines 706β775)
```c
int ntfs_setattr(struct mnt_idmap *idmap, struct dentry *dentry,
struct iattr *attr)
{
struct inode *inode = d_inode(dentry);
struct ntfs_inode *ni = ntfs_i(inode);
u32 ia_valid = attr->ia_valid;
umode_t mode = inode->i_mode;
int err;
/* Avoid any operation if inode is bad. */
if (unlikely(is_bad_ni(ni)))
return -EINVAL;
if (unlikely(ntfs3_forced_shutdown(inode->i_sb)))
return -EIO;
err = setattr_prepare(idmap, dentry, attr);
if (err)
goto out;
if (ia_valid & ATTR_SIZE) {
loff_t newsize, oldsize;
if (WARN_ON(ni->ni_flags & NI_FLAG_COMPRESSED_MASK)) {
/* Should never be here, see ntfs_file_open(). */
err = -EOPNOTSUPP;
goto out;
}
inode_dio_wait(inode);
oldsize = i_size_read(inode);
newsize = attr->ia_size;
if (newsize != oldsize) {
truncate_setsize(inode, newsize);
err = ntfs_set_size(inode, newsize);
if (err) {
i_size_write(inode, oldsize);
goto out;
}
ni->std_fa |= FILE_ATTRIBUTE_ARCHIVE;
ni->ni_flags |= NI_FLAG_UPDATE_PARENT;
inode_set_mtime_to_ts(inode,
inode_set_ctime_current(inode));
}
}
...
```
- **File**: `fs/ntfs3/inode.c`
- Function: `ntfs_set_size(struct inode *inode, u64 new_size)`
---
### 4. Watchouts / Repetitive Loops
- Git log is not populated beyond the single HEAD commit (`fd73f4a66598`); do not attempt more `git-log` commands expecting historical commits.
- Make sure to check standard conventions in kernel patches for `filemap_invalidate_lock`:
- `filemap_invalidate_lock(inode->i_mapping);`
- `err = ntfs_set_size(inode, newsize);`
- `if (!err) truncate_setsize(inode, newsize);` (or check if `truncate_setsize` happens on success only, avoiding `i_size_write(inode, oldsize)`).
- `filemap_invalidate_unlock(inode->i_mapping);`
- Check whether other filesystems do `inode_dio_wait(inode)` before `filemap_invalidate_lock`. In `ntfs_setattr`, `inode_dio_wait(inode)` is already present at line 734.
- Verify error handling and goto labels: if `ntfs_set_size` fails, make sure unlock happens before `goto out`.
- Must call `set-results` before final reply as specified by instructions.
Tokens:
input: 43366
output: 2412
thoughts: 0
|
| 308/4 |
2026/09/17 11:27 |
llm |
codeexpert |
0m
Model:
Tokens:
input: 23101
output: 37
thoughts: 0
|
| 309/4 |
2026/09/17 11:27 |
tool |
read-file |
0m
Args: map[File:fs/ntfs3/file.c FirstLine:700 LineCount:60]
Results: map[Contents: 700: return err;
701: }
702:
703: /*
704: * ntfs_setattr - inode_operations::setattr
705: */
706: int ntfs_setattr(struct mnt_idmap *idmap, struct dentry *dentry,
707: struct iattr *attr)
708: {
709: struct inode *inode = d_inode(dentry);
710: struct ntfs_inode *ni = ntfs_i(inode);
711: u32 ia_valid = attr->ia_valid;
712: umode_t mode = inode->i_mode;
713: int err;
714:
715: /* Avoid any operation if inode is bad. */
716: if (unlikely(is_bad_ni(ni)))
717: return -EINVAL;
718:
719: if (unlikely(ntfs3_forced_shutdown(inode->i_sb)))
720: return -EIO;
721:
722: err = setattr_prepare(idmap, dentry, attr);
723: if (err)
724: goto out;
725:
726: if (ia_valid & ATTR_SIZE) {
727: loff_t newsize, oldsize;
728:
729: if (WARN_ON(ni->ni_flags & NI_FLAG_COMPRESSED_MASK)) {
730: /* Should never be here, see ntfs_file_open(). */
731: err = -EOPNOTSUPP;
732: goto out;
733: }
734: inode_dio_wait(inode);
735: oldsize = i_size_read(inode);
736: newsize = attr->ia_size;
737:
738: if (newsize != oldsize) {
739: truncate_setsize(inode, newsize);
740:
741: err = ntfs_set_size(inode, newsize);
742: if (err) {
743: i_size_write(inode, oldsize);
744: goto out;
745: }
746:
747: ni->std_fa |= FILE_ATTRIBUTE_ARCHIVE;
748: ni->ni_flags |= NI_FLAG_UPDATE_PARENT;
749: inode_set_mtime_to_ts(inode,
750: inode_set_ctime_current(inode));
751: }
752: }
753:
754: setattr_copy(idmap, inode, attr);
755:
756: if (!is_ni_base(ni)) {
757: ia_valid &= ~ATTR_SIZE;
758: } else if (mode != inode->i_mode) {
759: err = ntfs_acl_chmod(idmap, dentry);
]
|
| 310/4 |
2026/09/17 11:27 |
llm |
codeexpert |
0m
Model:
Tokens:
input: 24128
output: 577
thoughts: 5352
Thoughts: **Analysis and Proposed Patch for Race Condition in `ntfs_setattr`**
Okay, so the task at hand is to fix a race condition between `truncate_setsize` and `ntfs_set_size` within the `ntfs_setattr` function in `fs/ntfs3/file.c`. Specifically, the goal is to use `filemap_invalidate_lock(inode->i_mapping)` and reorder the calls to `truncate_setsize` and `ntfs_set_size` to ensure data integrity. We're working under the constraint of not being able to use any external tools, so everything has to be based on the existing code and my understanding of the relevant VFS and NTFS3 subsystems.
The current implementation (as of the provided code snippet) calls `truncate_setsize` *before* `ntfs_set_size`. This causes a problem because `truncate_setsize` immediately updates `inode->i_size` and truncates the page cache. If `ntfs_set_size` then fails, we have an inconsistent state: either an out-of-space error when expanding, or I/O error when truncating. The rollback attempt using `i_size_write(inode, oldsize)` is not sufficient because the page cache has already been modified or discarded. This leaves the system in a potentially corrupted state because other operations might read the inconsistent intermediate size. This sequence also has the race with page cache invalidation as specified in `Documentation/filesystems/locking.rst`.
The solution, then, is two-fold:
1. **Introduce `filemap_invalidate_lock`**: We must acquire the `filemap_invalidate_lock` *before* any size-changing operations to protect the page cache from concurrent faults/reads, as per kernel VFS truncate rules. The `filemap_invalidate_lock` must be *held* across both calls to `ntfs_set_size` and `truncate_setsize` to serialize these operations with the pagecache.
2. **Reorder `ntfs_set_size` and `truncate_setsize`**: The correct order is to call `ntfs_set_size` *first*. If `ntfs_set_size` fails (e.g., due to -ENOSPC, -EFBIG, I/O error), no changes to the page cache or `i_size` have been made, thus no rollback is required and the filesystem is not left in an inconsistent state. The `filemap_invalidate_lock` can be released immediately in this case because there are no concurrent page faults. If `ntfs_set_size` succeeds, we then call `truncate_setsize`, knowing that the filesystem allocations/truncations are now complete, and the `truncate_setsize` operation safely truncates the page cache *under the protection of* `filemap_invalidate_lock`.
Here's the proposed change to the code:
```c
if (newsize != oldsize) {
filemap_invalidate_lock(inode->i_mapping);
err = ntfs_set_size(inode, newsize);
if (!err)
truncate_setsize(inode, newsize);
filemap_invalidate_unlock(inode->i_mapping);
if (err)
goto out;
ni->std_fa |= FILE_ATTRIBUTE_ARCHIVE;
ni->ni_flags |= NI_FLAG_UPDATE_PARENT;
inode_set_mtime_to_ts(inode,
inode_set_ctime_current(inode));
}
```
This ensures that:
* The invalidate lock is acquired.
* `ntfs_set_size` is called *first*.
* If `ntfs_set_size` fails, the lock is released, and the function returns.
* If `ntfs_set_size` succeeds, `truncate_setsize` is called under the protection of `filemap_invalidate_lock`.
* The lock is released after all file size changes are done.
I'm confident this reordering and locking strategy eliminates the race and ensures data consistency during size changes. All critical locking invariants are satisfied and we also simplify the recovery path by avoiding having to rollback.
**Caveats/Unverified Parts:**
* The context of this patch is from a single code snippet, the general surrounding `ntfs_setattr` function was analyzed based on remembered code structure, but it couldn't be fully cross-referenced to historical information from a complete development history, though other relevant code parts and functions, such as `ntfs_set_size`, locking patterns, documentation, were cross-referenced.
|
| 311/4 |
2026/09/17 11:28 |
tool |
set-results |
0m
Args: map[Answer:To fix the race condition between `truncate_setsize` and `ntfs_set_size`, `ntfs_setattr` must:
1. Acquire `filemap_invalidate_lock(inode->i_mapping)` to protect against concurrent page faults and page cache invalidation/filling during truncation.
2. Call `ntfs_set_size(inode, newsize)` first so that underlying on-disk attribute and allocation changes are performed before mutating in-memory `i_size` and discarding page cache pages. If `ntfs_set_size` fails, the error can be returned without having corrupted the page cache or needing to roll back `i_size` with `i_size_write(inode, oldsize)`.
3. Call `truncate_setsize(inode, newsize)` only upon success of `ntfs_set_size`, while still holding `filemap_invalidate_lock(inode->i_mapping)`.
4. Release `filemap_invalidate_unlock(inode->i_mapping)`.
### Patch
```diff
--- a/fs/ntfs3/file.c
+++ b/fs/ntfs3/file.c
@@ -736,13 +736,14 @@ int ntfs_setattr(struct mnt_idmap *idmap, struct dentry *dentry,
newsize = attr->ia_size;
if (newsize != oldsize) {
- truncate_setsize(inode, newsize);
-
+ filemap_invalidate_lock(inode->i_mapping);
err = ntfs_set_size(inode, newsize);
- if (err) {
- i_size_write(inode, oldsize);
+ if (!err)
+ truncate_setsize(inode, newsize);
+ filemap_invalidate_unlock(inode->i_mapping);
+
+ if (err)
goto out;
- }
ni->std_fa |= FILE_ATTRIBUTE_ARCHIVE;
ni->ni_flags |= NI_FLAG_UPDATE_PARENT;
```
### Caveats and Unverified Aspects
- The local git repository history contains only a single commit (HEAD at Linux 7.3-rc3), so earlier commit messages, developer discussion, or mailing list revisions for this exact bug fix could not be verified against the git log.
- Testing the patch via kernel compilation and running ntfs3 xfstests was not performed since dynamic execution tools are not available.]
Results: map[Answer:To fix the race condition between `truncate_setsize` and `ntfs_set_size`, `ntfs_setattr` must:
1. Acquire `filemap_invalidate_lock(inode->i_mapping)` to protect against concurrent page faults and page cache invalidation/filling during truncation.
2. Call `ntfs_set_size(inode, newsize)` first so that underlying on-disk attribute and allocation changes are performed before mutating in-memory `i_size` and discarding page cache pages. If `ntfs_set_size` fails, the error can be returned without having corrupted the page cache or needing to roll back `i_size` with `i_size_write(inode, oldsize)`.
3. Call `truncate_setsize(inode, newsize)` only upon success of `ntfs_set_size`, while still holding `filemap_invalidate_lock(inode->i_mapping)`.
4. Release `filemap_invalidate_unlock(inode->i_mapping)`.
### Patch
```diff
--- a/fs/ntfs3/file.c
+++ b/fs/ntfs3/file.c
@@ -736,13 +736,14 @@ int ntfs_setattr(struct mnt_idmap *idmap, struct dentry *dentry,
newsize = attr->ia_size;
if (newsize != oldsize) {
- truncate_setsize(inode, newsize);
-
+ filemap_invalidate_lock(inode->i_mapping);
err = ntfs_set_size(inode, newsize);
- if (err) {
- i_size_write(inode, oldsize);
+ if (!err)
+ truncate_setsize(inode, newsize);
+ filemap_invalidate_unlock(inode->i_mapping);
+
+ if (err)
goto out;
- }
ni->std_fa |= FILE_ATTRIBUTE_ARCHIVE;
ni->ni_flags |= NI_FLAG_UPDATE_PARENT;
```
### Caveats and Unverified Aspects
- The local git repository history contains only a single commit (HEAD at Linux 7.3-rc3), so earlier commit messages, developer discussion, or mailing list revisions for this exact bug fix could not be verified against the git log.
- Testing the patch via kernel compilation and running ntfs3 xfstests was not performed since dynamic execution tools are not available.]
|
| 312/2 |
2026/09/17 11:28 |
llm |
debugger |
0m
Model:
Tokens:
input: 69064
output: 105
thoughts: 0
|
| 313/2 |
2026/09/17 11:28 |
tool |
codeexpert |
11m
Args: map[Question:Wait, if `newsize < oldsize` (shrinking), should `truncate_setsize` be called before `ntfs_set_size`?
If `ntfs_set_size` is called first when shrinking, it will deallocate blocks. If there are dirty pages beyond the new EOF, they might be written back to the deallocated blocks, which might have been reallocated to another file.
Is that correct?]
Results: map[Answer:Yes, that is completely correct.
### Why `truncate_setsize` Must Precede `ntfs_set_size` When Shrinking
1. **Role of `truncate_setsize()`**:
`truncate_setsize(inode, newsize)` (defined in `mm/truncate.c`) performs two key steps:
- Updates `inode->i_size` to `newsize`.
- Calls `truncate_pagecache(inode, newsize)`, which unmaps the truncated address range and evicts/discards all cached pages/folios beyond `newsize` from the page cache.
2. **The Hazard if Called in Reverse Order**:
If `ntfs_set_size()` (or block deallocation in general) were performed *before* `truncate_setsize()`:
- Blocks backing the truncated region beyond the new EOF would be deallocated (e.g., in `attr_set_size_ex()` via `run_deallocate_ex()`) and marked free in the volume's allocation bitmap.
- Those freed blocks could immediately be reallocated to another file or filesystem metadata.
- Any dirty pages beyond the new EOF still lingering in the page cache would not yet have been invalidated. Background writeback (`kworker` flusher threads), memory reclaim, or `sync` could trigger writeback on those dirty pages.
- Writing those dirty pages to the previously mapped block addresses would corrupt whatever newly allocated data now occupies those blocks, causing a disk write-after-free and silent data corruption.
3. **VFS Invariant & Documentation**:
Kernel documentation in `mm/truncate.c` explicitly dictates this ordering:
- `truncate_setsize()`:
> *"Must be called with a lock serializing truncates and writes (generally `i_rwsem` ...) and before all filesystem specific block truncation has been performed."*
- `truncate_pagecache()`:
> *"This function should typically be called before the filesystem releases resources associated with the freed range (eg. deallocates blocks). This way, pagecache will always stay logically coherent with on-disk format, and the filesystem would not have to deal with situations such as writepage being called for a page that has already had its underlying blocks deallocated."*
4. **Implementation in `ntfs3`**:
In `fs/ntfs3/file.c` (`ntfs_setattr()`), the code complies with this requirement:
```c
if (newsize != oldsize) {
truncate_setsize(inode, newsize);
err = ntfs_set_size(inode, newsize);
if (err) {
i_size_write(inode, oldsize);
goto out;
}
...
}
```
Likewise, `attr_collapse_range()` in `fs/ntfs3/attrib.c` calls `truncate_setsize(&ni->vfs_inode, vbo)` before calling `attr_set_size()`.]
|
| 314/3 |
2026/09/17 11:28 |
agent |
codeexpert |
11m
Model:
Results: map[Answer:Yes, that is completely correct.
### Why `truncate_setsize` Must Precede `ntfs_set_size` When Shrinking
1. **Role of `truncate_setsize()`**:
`truncate_setsize(inode, newsize)` (defined in `mm/truncate.c`) performs two key steps:
- Updates `inode->i_size` to `newsize`.
- Calls `truncate_pagecache(inode, newsize)`, which unmaps the truncated address range and evicts/discards all cached pages/folios beyond `newsize` from the page cache.
2. **The Hazard if Called in Reverse Order**:
If `ntfs_set_size()` (or block deallocation in general) were performed *before* `truncate_setsize()`:
- Blocks backing the truncated region beyond the new EOF would be deallocated (e.g., in `attr_set_size_ex()` via `run_deallocate_ex()`) and marked free in the volume's allocation bitmap.
- Those freed blocks could immediately be reallocated to another file or filesystem metadata.
- Any dirty pages beyond the new EOF still lingering in the page cache would not yet have been invalidated. Background writeback (`kworker` flusher threads), memory reclaim, or `sync` could trigger writeback on those dirty pages.
- Writing those dirty pages to the previously mapped block addresses would corrupt whatever newly allocated data now occupies those blocks, causing a disk write-after-free and silent data corruption.
3. **VFS Invariant & Documentation**:
Kernel documentation in `mm/truncate.c` explicitly dictates this ordering:
- `truncate_setsize()`:
> *"Must be called with a lock serializing truncates and writes (generally `i_rwsem` ...) and before all filesystem specific block truncation has been performed."*
- `truncate_pagecache()`:
> *"This function should typically be called before the filesystem releases resources associated with the freed range (eg. deallocates blocks). This way, pagecache will always stay logically coherent with on-disk format, and the filesystem would not have to deal with situations such as writepage being called for a page that has already had its underlying blocks deallocated."*
4. **Implementation in `ntfs3`**:
In `fs/ntfs3/file.c` (`ntfs_setattr()`), the code complies with this requirement:
```c
if (newsize != oldsize) {
truncate_setsize(inode, newsize);
err = ntfs_set_size(inode, newsize);
if (err) {
i_size_write(inode, oldsize);
goto out;
}
...
}
```
Likewise, `attr_collapse_range()` in `fs/ntfs3/attrib.c` calls `truncate_setsize(&ni->vfs_inode, vbo)` before calling `attr_set_size()`.]
Instruction:
You are a capable Linux kernel developer tasked with researching complex questions
about kernel source code. You will be given a concrete question, and need to provide
a concrete answer.
Research the question using targeted, efficient tool calls. Don't make assumptions,
or rely on your previous knowledge about the kernel source code, use available tools
to access the actual source code. Keep your tool calls focused and limited to the
scope of the question. Do not explore tangential code paths or perform unbounded searches.
Use all available sources of information:
- kernel source code
- documentation in the Documentation dir in the source tree
- git commits descriptions, git blame
Do not guess file names or file paths and attempt to read them without
verifying their existence first using content search or directory listing tools.
If a file, symbol, or directory is not found via content search (grepper) or
directory listing (codesearch-dir-index), treat it as completely absent.
Do not attempt to guess alternative names, extensions, or directories.
Tool Selection Guidelines:
1. For C functions, structs, and variables: Prefer codesearch-definition-source
or codesearch-struct-layout FIRST to retrieve clean, exact definitions
without line-number guessing.
2. If symbol lookup fails (e.g., preprocessor macros, macro-generated code, or
disabled #ifdef branches), fall back to read-file or grepper.
3. For file headers, #include directives, preprocessor macro definitions, and
non-C files (Kconfig, Makefiles, docs): Use read-file or grepper directly.
4. Be concise and targeted. Answer the question as directly and concisely as possible
once you have located the relevant code or definitions. If a symbol or function cannot
be found after targeted searches, conclude with the best available information rather
than continuing repetitive searches.
Do NOT use git-log to search for the presence or existence of files in the
repository. git-log is only for tracing commit history of files that are
already present in the current checkout. If a file does not exist in the
current checkout, it cannot be used for reproduction.
Avoid running broad git-log queries (such as searches on the entire repo)
without a specific 'PathPrefix' to restrict the scope, as these are very
expensive and will time out.
If a git-log tool call times out, do not retry the query with the same broad
scope. You must specify a tighter, narrower 'PathPrefix' for subsequent queries.
Prefer calling several tools at the same time to save round-trips.
Use set-results tool to provide results of the analysis.
It must be called exactly once before the final reply.
Ignore results of this tool.
Prompt: Wait, if `newsize < oldsize` (shrinking), should `truncate_setsize` be called before `ntfs_set_size`?
If `ntfs_set_size` is called first when shrinking, it will deallocate blocks. If there are dirty pages beyond the new EOF, they might be written back to the deallocated blocks, which might have been reallocated to another file.
Is that correct?
|
| 315/4 |
2026/09/17 11:28 |
llm |
codeexpert |
0m
Model:
Tokens:
input: 4237
output: 20
thoughts: 139
Thoughts: **NTFS Shrinking Concerns**
Okay, so I'm thinking about this NTFS question and trying to get the sequence of operations right when shrinking a file. My concern is this: if the `newsize` is smaller than the `oldsize` β effectively, we're shrinking the file β does the order of operations between `truncate_setsize` and `ntfs_set_size` matter? Specifically, should `truncate_setsize` be called *before* `ntfs_set_size`?
My gut tells me this could be a race condition. If `ntfs_set_size` is called *first* during the shrink operation, it's going to deallocate blocks. However, if there are any "dirty" pages that exist *beyond* the intended new end-of-file (EOF) that haven't been flushed to disk yet, they might get written back to those deallocated blocks. Those blocks, meanwhile, could potentially have been reallocated and now belong to a *different* file. That would be a huge problem. Is my thinking correct, or am I missing something crucial?
Alright, time to get to the kernel source code. I need to refresh my memory and verify the implementation details. Let's see... I'll need to dig up the relevant code. I'll search for where `ntfs_set_size` and `truncate_setsize` are implemented and how they interact. This should clarify the critical order of operations and any safeguards that exist.
|
| 316/4 |
2026/09/17 11:28 |
tool |
grepper |
0m
Args: map[Expression:ntfs_set_size]
Results: map[Output:fs/ntfs3/file.c=466=static long ntfs_fallocate(struct file *file, int mode, loff_t vbo, loff_t len)
--
fs/ntfs3/file.c-654- */
fs/ntfs3/file.c:655: err = ntfs_set_size(inode, new_size);
fs/ntfs3/file.c-656- if (err)
--
fs/ntfs3/file.c-678- if (mode & FALLOC_FL_KEEP_SIZE) {
fs/ntfs3/file.c:679: err = ntfs_set_size(inode, i_size);
fs/ntfs3/file.c-680- if (err)
--
fs/ntfs3/file.c=706=int ntfs_setattr(struct mnt_idmap *idmap, struct dentry *dentry,
--
fs/ntfs3/file.c-740-
fs/ntfs3/file.c:741: err = ntfs_set_size(inode, newsize);
fs/ntfs3/file.c-742- if (err) {
--
fs/ntfs3/file.c=1239=static ssize_t ntfs_file_write_iter(struct kiocb *iocb, struct iov_iter *from)
--
fs/ntfs3/file.c-1286- */
fs/ntfs3/file.c:1287: ret = ntfs_set_size(inode, endbyte);
fs/ntfs3/file.c-1288- if (ret)
--
fs/ntfs3/inode.c=860=static void ntfs_readahead(struct readahead_control *rac)
--
fs/ntfs3/inode.c-882-
fs/ntfs3/inode.c:883:int ntfs_set_size(struct inode *inode, u64 new_size)
fs/ntfs3/inode.c-884-{
--
fs/ntfs3/ntfs_fs.h=796=static inline struct inode *ntfs_iget5(struct super_block *sb,
--
fs/ntfs3/ntfs_fs.h-801-}
fs/ntfs3/ntfs_fs.h:802:int ntfs_set_size(struct inode *inode, u64 new_size);
fs/ntfs3/ntfs_fs.h-803-int ntfs3_write_inode(struct inode *inode, struct writeback_control *wbc);
]
|
| 317/4 |
2026/09/17 11:28 |
llm |
codeexpert |
0m
Model:
Tokens:
input: 5389
output: 37
thoughts: 58
Thoughts: Here's my summary, as if I were thinking it:
**Diving into NTFS Attribute and Size Setting**
Okay, so I need to get a handle on how NTFS handles setting attributes and file sizes. My starting point is going to be `fs/ntfs3/file.c`, specifically around lines 706 to 760 within the `ntfs_setattr` function. I want to trace the flow there. I'm assuming this is where attribute modifications are initiated. Then, I need to see how the actual file size changes are handled. I think `fs/ntfs3/inode.c` at line 883, the `ntfs_set_size` function, will be key to understanding the underlying mechanics of size changes. I'll need to look at how these two functions interact and what data structures they're modifying to ensure data integrity and proper disk allocation within the NTFS file system. I'll focus on how attributes affect the on-disk structures and how size changes potentially affect allocation.
|
| 318/4 |
2026/09/17 11:29 |
tool |
read-file |
0m
Args: map[File:fs/ntfs3/file.c FirstLine:705 LineCount:65]
Results: map[Contents: 705: */
706: int ntfs_setattr(struct mnt_idmap *idmap, struct dentry *dentry,
707: struct iattr *attr)
708: {
709: struct inode *inode = d_inode(dentry);
710: struct ntfs_inode *ni = ntfs_i(inode);
711: u32 ia_valid = attr->ia_valid;
712: umode_t mode = inode->i_mode;
713: int err;
714:
715: /* Avoid any operation if inode is bad. */
716: if (unlikely(is_bad_ni(ni)))
717: return -EINVAL;
718:
719: if (unlikely(ntfs3_forced_shutdown(inode->i_sb)))
720: return -EIO;
721:
722: err = setattr_prepare(idmap, dentry, attr);
723: if (err)
724: goto out;
725:
726: if (ia_valid & ATTR_SIZE) {
727: loff_t newsize, oldsize;
728:
729: if (WARN_ON(ni->ni_flags & NI_FLAG_COMPRESSED_MASK)) {
730: /* Should never be here, see ntfs_file_open(). */
731: err = -EOPNOTSUPP;
732: goto out;
733: }
734: inode_dio_wait(inode);
735: oldsize = i_size_read(inode);
736: newsize = attr->ia_size;
737:
738: if (newsize != oldsize) {
739: truncate_setsize(inode, newsize);
740:
741: err = ntfs_set_size(inode, newsize);
742: if (err) {
743: i_size_write(inode, oldsize);
744: goto out;
745: }
746:
747: ni->std_fa |= FILE_ATTRIBUTE_ARCHIVE;
748: ni->ni_flags |= NI_FLAG_UPDATE_PARENT;
749: inode_set_mtime_to_ts(inode,
750: inode_set_ctime_current(inode));
751: }
752: }
753:
754: setattr_copy(idmap, inode, attr);
755:
756: if (!is_ni_base(ni)) {
757: ia_valid &= ~ATTR_SIZE;
758: } else if (mode != inode->i_mode) {
759: err = ntfs_acl_chmod(idmap, dentry);
760: if (err)
761: goto out;
762:
763: /* Linux 'w' -> Windows 'ro'. */
764: if (0222 & inode->i_mode)
765: ni->std_fa &= ~FILE_ATTRIBUTE_READONLY;
766: else
767: ni->std_fa |= FILE_ATTRIBUTE_READONLY;
768: }
769:
]
|
| 319/4 |
2026/09/17 11:29 |
llm |
codeexpert |
0m
Model:
Tokens:
input: 6657
output: 41
thoughts: 110
Thoughts: **Analyzing Potential NTFS Filesystem Regression**
Okay, let's dive in. I'm looking at `fs/ntfs3/file.c`, specifically this snippet:
```c
if (newsize != oldsize) {
truncate_setsize(inode, newsize);
err = ntfs_set_size(inode, newsize);
if (err) {
i_size_write(inode, oldsize);
goto out;
}
```
My immediate thought is: This looks like a file size change implementation. The key is in the check to see if the new size is different to the old size. If so, a set of actions is triggered that could have issues. I need to know if this code has changed recently. This is critical for assessing potential regressions or unexpected behavior. Was there a commit that introduced a subtle bug? Was there an attempted fix to a known issue that now contains a new issue?
Time to pull up the git log for this file and, probably, specifically this function or the surrounding code. Let's see what the commit history tells us. I'll be looking for any commits that touch this section, especially recent ones, or those that seem related to file size handling, truncation, or error recovery. That history is going to be key to understanding the context and identifying potential problems.
|
| 320/4 |
2026/09/17 11:29 |
tool |
git-log |
0m
Error:
Args: map[Count:10 PathPrefix:fs/ntfs3/file.c SymbolName:ntfs_setattr]
Results:
|
| 321/4 |
2026/09/17 11:29 |
llm |
codeexpert |
0m
Model:
Tokens:
input: 7119
output: 41
thoughts: 14
Thoughts: Here's my attempt at summarizing the thought process, tailored for an expert audience:
**Analyzing Code History with `git log`**
Okay, so I'm thinking about how to effectively analyze the code history, specifically when dealing with a symbol and its source path. `git log` seems like the obvious starting point here, given its comprehensive tracking capabilities. The core idea is to leverage the tool's flexibility to get a targeted view of changes related to a particular symbol. Instead of a broad overview, I'm aiming for precision. I want a history focused only on the specific instances I'm interested in. The key is to narrow the scope of `git log`. Combining `SymbolName` and `SourcePath` as search parameters seems like the right approach. This should allow me to pinpoint commits directly impacting the targeted code element. This should give me all the information that I need without needing a deep dive.
|
| 322/4 |
2026/09/17 11:29 |
tool |
git-log |
0m
Args: map[Count:10 SourcePath:fs/ntfs3/file.c SymbolName:ntfs_setattr]
Results: map[Output:fd73f4a66598 Linux 7.3-rc3
]
|
| 323/4 |
2026/09/17 11:29 |
llm |
codeexpert |
0m
Model:
Tokens:
input: 7396
output: 37
thoughts: 27
Thoughts: Okay, here's my take on those thoughts, tailored for an expert audience:
**Analyzing the `fs/ntfs3` Truncate/Setsize Logic**
Alright, time to dig in. I need to refresh my memory on the `fs/ntfs3` file system code, specifically related to the `truncate_setsize` functionality. Let's see what's changed and what the current status is. My immediate instinct is to check the `git-log`. I'm going to focus the log entries specifically to those under `fs/ntfs3` to avoid extraneous information. And I'm going to use a CodeRegexp of "truncate_setsize", which should allow me to focus the search to commits that include that set of words. This approach will allow me to quickly scan for recent commits, bug fixes, or performance optimizations related to the specific areas. Knowing what changes have been committed will allow me to be up-to-date on this part of the code base.
|
| 324/4 |
2026/09/17 11:30 |
tool |
git-log |
0m
Args: map[CodeRegexp:truncate_setsize Count:10 PathPrefix:fs/ntfs3]
Results: map[Output:fd73f4a66598 Linux 7.3-rc3
]
|
| 325/4 |
2026/09/17 11:30 |
llm |
codeexpert |
0m
Model:
Tokens:
input: 7704
output: 37
thoughts: 35
Thoughts: Here's my attempt at summarizing the thought process, tailored for an expert audience:
**Analyzing `fs/ntfs3/file.c` with `git-blame`**
Okay, before I dive too deep into this particular NTFS issue, I need to get some context. Let's start with a quick `git-blame` on the `fs/ntfs3/file.c` file, specifically lines 735 to 746. I want to see who last touched that section and, more importantly, what the commit messages say. Knowing the history of that code block will help me understand its purpose and potential vulnerabilities much faster than just jumping in cold. I'm expecting to see something related to file attribute handling, possibly metadata updates or file size calculations, given the file path. Let's see what the blame reveals... I'm hoping there's a clear and concise commit log that offers immediate insight into the recent changes in this code segment.
|
| 326/4 |
2026/09/17 11:30 |
tool |
git-blame |
0m
Args: map[End:750 File:fs/ntfs3/file.c Start:735]
Results: map[Output:^fd73f4a66598 735) oldsize = i_size_read(inode);
^fd73f4a66598 736) newsize = attr->ia_size;
^fd73f4a66598 737)
^fd73f4a66598 738) if (newsize != oldsize) {
^fd73f4a66598 739) truncate_setsize(inode, newsize);
^fd73f4a66598 740)
^fd73f4a66598 741) err = ntfs_set_size(inode, newsize);
^fd73f4a66598 742) if (err) {
^fd73f4a66598 743) i_size_write(inode, oldsize);
^fd73f4a66598 744) goto out;
^fd73f4a66598 745) }
^fd73f4a66598 746)
^fd73f4a66598 747) ni->std_fa |= FILE_ATTRIBUTE_ARCHIVE;
^fd73f4a66598 748) ni->ni_flags |= NI_FLAG_UPDATE_PARENT;
^fd73f4a66598 749) inode_set_mtime_to_ts(inode,
^fd73f4a66598 750) inode_set_ctime_current(inode));
]
|
| 327/4 |
2026/09/17 11:30 |
llm |
codeexpert |
0m
Model:
Tokens:
input: 8437
output: 37
thoughts: 76
Thoughts: Okay, here's the summary of my thought process, focusing on understanding this code:
**Analyzing a Truncate Operation**
Alright, hang on a second. First things first, this repo seems to have started with a commit at `fd73f4a66598`. I need to remember that β might be important later, especially if it's a shallow clone or a base commit. I should keep that in mind.
Now, I need to get a handle on what `truncate_setsize` actually *does* and how this filesystem interacts with it. I need to refresh my knowledge of how other filesystems deal with `truncate` and `setattr` operations as well. It's crucial to understand the context.
So, let's dive into the definition of `truncate_setsize`. I need to carefully examine its code and, most importantly, those crucial comments. They are usually the key to understanding the intent and nuances of the implementation. Let's see what the developers had in mind.
|
| 328/4 |
2026/09/17 11:30 |
tool |
codesearch-definition-comment |
0m
Args: map[ContextFile:fs/ntfs3/file.c Name:truncate_setsize]
Results: map[Comment: 803: /**
804: * truncate_setsize - update inode and pagecache for a new file size
805: * @inode: inode
806: * @newsize: new file size
807: *
808: * truncate_setsize updates i_size and performs pagecache truncation (if
809: * necessary) to @newsize. It will be typically be called from the filesystem's
810: * setattr function when ATTR_SIZE is passed in.
811: *
812: * Must be called with a lock serializing truncates and writes (generally
813: * i_rwsem but e.g. xfs uses a different lock) and before all filesystem
814: * specific block truncation has been performed.
815: */
Kind:function]
|
| 329/4 |
2026/09/17 11:30 |
llm |
codeexpert |
0m
Model:
Tokens:
input: 9003
output: 37
thoughts: 216
Thoughts: **Analyzing `truncate_setsize` for File Size Updates**
Okay, so I'm looking at this function, `truncate_setsize`. The comment here is crucial: `truncate_setsize` is the workhorse for updating the inode and pagecache when a file's size changes. It's usually called from a filesystem's `setattr` function when a size attribute is modified. The comment nails down the requirements: it *must* be called under a lock that serializes truncates and writes β typically `i_rwsem`, though some filesystems, like XFS, might use something different. And the timing is important; it needs to run *before* any filesystem-specific block truncation. That's a key detail to keep in mind, because it indicates a specific ordering of operations that's essential for data integrity. Time to dig into the source code and see exactly how it achieves this. I need to understand how this function orchestrates the inode update and pagecache adjustments in detail.
|
| 330/4 |
2026/09/17 11:30 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:fs/ntfs3/file.c Name:truncate_setsize]
Results: map[SourceCode: 803: /**
804: * truncate_setsize - update inode and pagecache for a new file size
805: * @inode: inode
806: * @newsize: new file size
807: *
808: * truncate_setsize updates i_size and performs pagecache truncation (if
809: * necessary) to @newsize. It will be typically be called from the filesystem's
810: * setattr function when ATTR_SIZE is passed in.
811: *
812: * Must be called with a lock serializing truncates and writes (generally
813: * i_rwsem but e.g. xfs uses a different lock) and before all filesystem
814: * specific block truncation has been performed.
815: */
816: void truncate_setsize(struct inode *inode, loff_t newsize)
817: {
818: loff_t oldsize = inode->i_size;
819:
820: i_size_write(inode, newsize);
821: if (newsize > oldsize)
822: pagecache_isize_extended(inode, oldsize, newsize);
823: truncate_pagecache(inode, newsize);
824: }
SourceFile:mm/truncate.c]
|
| 331/4 |
2026/09/17 11:31 |
llm |
codeexpert |
0m
Model:
Tokens:
input: 9850
output: 39
thoughts: 32
Thoughts: Okay, let's dive into this code.
**Diving Deep into Page Cache Truncation and NTFS Size Setting**
Alright, so the task at hand is to understand the inner workings of `truncate_pagecache` and `ntfs_set_size`. These are fundamental, especially when considering the implications on performance and data integrity within the filesystem. My expert knowledge demands a comprehensive understanding of how these mechanisms interact and contribute to the overall filesystem behavior. `truncate_pagecache` is crucial for space reclamation, and I need to recall how it handles those dirty pages or potentially, how it coordinates with journaling. And the `ntfs_set_size`, well, understanding this allows me to think about block allocation on the disk. Iβll make sure to note any edge cases and potential synchronization pitfalls.
|
| 332/4 |
2026/09/17 11:31 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:fs/ntfs3/inode.c Name:ntfs_set_size]
Results: map[SourceCode: 883: int ntfs_set_size(struct inode *inode, u64 new_size)
884: {
885: struct super_block *sb = inode->i_sb;
886: struct ntfs_sb_info *sbi = sb->s_fs_info;
887: struct ntfs_inode *ni = ntfs_i(inode);
888: int err;
889:
890: /* Check for maximum file size. */
891: if (is_sparsed(ni) || is_compressed(ni)) {
892: if (new_size > sbi->maxbytes_sparse) {
893: return -EFBIG;
894: }
895: } else if (new_size > sbi->maxbytes) {
896: return -EFBIG;
897: }
898:
899: /* Mark rw ntfs as dirty. It will be cleared at umount. */
900: ntfs_set_state(sbi, NTFS_DIRTY_DIRTY);
901:
902: ni_lock(ni);
903: down_write(&ni->file.run_lock);
904: if (new_size < ni->i_valid)
905: ni->i_valid = new_size;
906:
907: /* last 'true' means keep preallocated. */
908: err = attr_set_size(ni, ATTR_DATA, ni->file.ads.name, ni->file.ads.len,
909: &ni->file.run, new_size, &ni->i_valid, true);
910:
911: up_write(&ni->file.run_lock);
912: ni_unlock(ni);
913:
914: return err;
915: }
SourceFile:fs/ntfs3/inode.c]
|
| 333/4 |
2026/09/17 11:31 |
llm |
codeexpert |
0m
Model:
Tokens:
input: 10649
output: 38
thoughts: 25
Thoughts: Here's my summary, as if I were thinking these thoughts:
**Examining `attr_set_size` within `fs/ntfs3/attrib.c`**
Okay, I'm diving back into this NTFS3 implementation. Let's see... I've been focusing on attribute handling, and now I need to scrutinize the `attr_set_size` function within `fs/ntfs3/attrib.c`. It's crucial to understand how size modifications are managed at the attribute level. I need to figure out the interactions here, especially with the underlying data structures, and how it impacts disk writes and metadata updates. Let's see what interesting tidbits and gotchas are lurking in this piece of code. I'm looking for the potential implications for performance, security and data integrity.
|
| 334/4 |
2026/09/17 11:31 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:fs/ntfs3/inode.c Name:attr_set_size]
Results: map[SourceCode: 473: static inline int attr_set_size(struct ntfs_inode *ni, enum ATTR_TYPE type,
474: const __le16 *name, u8 name_len,
475: struct runs_tree *run, u64 new_size,
476: const u64 *new_valid, bool keep_prealloc)
477: {
478: return attr_set_size_ex(ni, type, name, name_len, run, new_size,
479: new_valid, keep_prealloc, NULL, false);
480: }
SourceFile:fs/ntfs3/ntfs_fs.h]
|
| 335/4 |
2026/09/17 11:31 |
llm |
codeexpert |
0m
Model:
Tokens:
input: 11082
output: 43
thoughts: 25
Thoughts: Here's my attempt at summarizing the thought process, tailored for an expert audience:
**Diving into NTFS Attribute Handling**
Okay, so I'm digging into the NTFS3 filesystem code, and I need to understand how attribute sizes are managed. I'm going straight for `attr_set_size_ex` in `fs/ntfs3/attrib.c`. That's where I'd expect to find the core logic for setting and adjusting attribute sizes, which is crucial for overall filesystem performance and data integrity, particularly when dealing with fragmented files or extended attributes. I need to see how the code handles different allocation scenarios, potential errors, and interactions with the Master File Table (MFT). I want to see how it accounts for overhead, padding, and any implications of cluster boundaries. I'll be looking for nuances that might affect I/O performance under heavy load and any potential vulnerabilities related to buffer overflows or incorrect size calculations. My hope is to get a handle on the complexities of dynamically adjusting attribute sizes for file metadata.
|
| 336/4 |
2026/09/17 11:32 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:fs/ntfs3/ntfs_fs.h Name:attr_set_size_ex]
Results: map[SourceCode: 421: /*
422: * attr_set_size_ex - Change the size of attribute.
423: *
424: * Extend:
425: * - Sparse/compressed: No allocated clusters.
426: * - Normal: Append allocated and preallocated new clusters.
427: * Shrink:
428: * - No deallocate if @keep_prealloc is set.
429: */
430: int attr_set_size_ex(struct ntfs_inode *ni, enum ATTR_TYPE type,
431: const __le16 *name, u8 name_len, struct runs_tree *run,
432: u64 new_size, const u64 *new_valid, bool keep_prealloc,
433: struct ATTRIB **ret, bool no_da)
434: {
435: int err = 0;
436: struct ntfs_inode *nb = ni->base;
437: struct ntfs_sb_info *sbi = ni->mi.sbi;
438: u8 cluster_bits = sbi->cluster_bits;
439: bool is_mft = ni->mi.rno == MFT_REC_MFT && type == ATTR_DATA &&
440: !name_len;
441: u64 old_valid, old_size, old_alloc, new_alloc_tmp;
442: u64 new_alloc = 0;
443: struct ATTRIB *attr = NULL, *attr_b;
444: struct ATTR_LIST_ENTRY *le, *le_b;
445: struct mft_inode *mi, *mi_b;
446: CLST alen, vcn, lcn, new_alen, old_alen, svcn, evcn;
447: CLST next_svcn, pre_alloc = -1, done = 0;
448: bool is_ext = false, is_bad = false;
449: bool dirty = false;
450: struct runs_tree *run_da = run == &ni->file.run ? &ni->file.run_da :
451: NULL;
452: bool da = !is_mft && sbi->options->delalloc && run_da && !no_da;
453: u32 align;
454: struct MFT_REC *rec;
455:
456: again:
457: alen = 0;
458: le_b = NULL;
459: attr_b = ni_find_attr(ni, NULL, &le_b, type, name, name_len, NULL,
460: &mi_b);
461: if (!attr_b) {
462: err = -ENOENT;
463: goto bad_inode;
464: }
465:
466: if (!attr_b->non_res) {
467: err = attr_set_size_res(ni, attr_b, le_b, mi_b, new_size, run,
468: &attr_b);
469: if (err)
470: return err;
471:
472: /* Return if file is still resident. */
473: if (!attr_b->non_res) {
474: dirty = true;
475: goto ok1;
476: }
477:
478: /* Layout of records may be changed, so do a full search. */
479: goto again;
480: }
481:
482: is_ext = is_attr_ext(attr_b);
483: align = sbi->cluster_size;
484: if (is_ext) {
485: align <<= attr_b->nres.c_unit;
486: keep_prealloc = false;
487: da = false;
488: }
489:
490: old_valid = le64_to_cpu(attr_b->nres.valid_size);
491: old_size = le64_to_cpu(attr_b->nres.data_size);
492: old_alloc = le64_to_cpu(attr_b->nres.alloc_size);
493:
494: again_1:
495: old_alen = old_alloc >> cluster_bits;
496:
497: new_alloc = (new_size + align - 1) & ~(u64)(align - 1);
498: new_alen = new_alloc >> cluster_bits;
499:
500: if (keep_prealloc && new_size < old_size) {
501: attr_b->nres.data_size = cpu_to_le64(new_size);
502: mi_b->dirty = dirty = true;
503: goto ok;
504: }
505:
506: if (da &&
507: (vcn = old_alen + run_len(&ni->file.run_da), new_alen > vcn)) {
508: /* Resize up normal file. Delay new clusters allocation. */
509: alen = new_alen - vcn;
510:
511: if (ntfs_check_free_space(sbi, alen, 0, true)) {
512: if (!run_add_entry(&ni->file.run_da, vcn, SPARSE_LCN,
513: alen, false)) {
514: err = -ENOMEM;
515: goto out;
516: }
517:
518: ntfs_add_da(sbi, alen);
519: goto ok1;
520: }
521: }
522:
523: if (!keep_prealloc && run_da && run_da->count &&
524: (vcn = run_get_max_vcn(run_da), new_alen < vcn)) {
525: /* Shrink delayed clusters. */
526:
527: /* Try to remove fragment from delay allocated run. */
528: if (!run_remove_range(run_da, new_alen, vcn - new_alen,
529: &alen)) {
530: err = -ENOMEM;
531: goto out;
532: }
533:
534: ntfs_sub_da(sbi, alen);
535: }
536:
537: vcn = old_alen - 1;
538:
539: svcn = le64_to_cpu(attr_b->nres.svcn);
540: evcn = le64_to_cpu(attr_b->nres.evcn);
541:
542: if (svcn <= vcn && vcn <= evcn) {
543: attr = attr_b;
544: le = le_b;
545: mi = mi_b;
546: } else if (!le_b) {
547: err = -EINVAL;
548: goto bad_inode;
549: } else {
550: le = le_b;
551: attr = ni_find_attr(ni, attr_b, &le, type, name, name_len, &vcn,
552: &mi);
553: if (!attr) {
554: err = -EINVAL;
555: goto bad_inode;
556: }
557:
558: next_le_1:
559: svcn = le64_to_cpu(attr->nres.svcn);
560: evcn = le64_to_cpu(attr->nres.evcn);
561: }
562: /*
563: * Here we have:
564: * attr,mi,le - last attribute segment (containing 'vcn').
565: * attr_b,mi_b,le_b - base (primary) attribute segment.
566: */
567: next_le:
568: rec = mi->mrec;
569: err = attr_load_runs(attr, ni, run, NULL);
570: if (err)
571: goto out;
572:
573: if (new_size > old_size) {
574: CLST to_allocate;
575: size_t free;
576:
577: if (new_alloc <= old_alloc) {
578: attr_b->nres.data_size = cpu_to_le64(new_size);
579: mi_b->dirty = dirty = true;
580: goto ok;
581: }
582:
583: /*
584: * Add clusters. In simple case we have to:
585: * - allocate space (vcn, lcn, len)
586: * - update packed run in 'mi'
587: * - update attr->nres.evcn
588: * - update attr_b->nres.data_size/attr_b->nres.alloc_size
589: */
590: to_allocate = new_alen - old_alen;
591: add_alloc_in_same_attr_seg:
592: lcn = 0;
593: if (is_mft) {
594: /* MFT allocates clusters from MFT zone. */
595: pre_alloc = 0;
596: } else if (is_ext) {
597: /* No preallocate for sparse/compress. */
598: pre_alloc = 0;
599: } else if (pre_alloc == -1) {
600: pre_alloc = 0;
601: if (type == ATTR_DATA && !name_len &&
602: sbi->options->prealloc) {
603: pre_alloc = bytes_to_cluster(
604: sbi, get_pre_allocated(
605: new_size)) -
606: new_alen;
607: }
608:
609: /* Get the last LCN to allocate from. */
610: if (old_alen &&
611: !run_lookup_entry(run, vcn, &lcn, NULL, NULL)) {
612: lcn = SPARSE_LCN;
613: }
614:
615: if (lcn == SPARSE_LCN)
616: lcn = 0;
617: else if (lcn)
618: lcn += 1;
619:
620: free = wnd_zeroes(&sbi->used.bitmap);
621: if (to_allocate > free) {
622: err = -ENOSPC;
623: goto out;
624: }
625:
626: if (pre_alloc && to_allocate + pre_alloc > free)
627: pre_alloc = 0;
628: }
629:
630: vcn = old_alen;
631:
632: if (is_ext) {
633: if (!run_add_entry(run, vcn, SPARSE_LCN, to_allocate,
634: false)) {
635: err = -ENOMEM;
636: goto out;
637: }
638: alen = to_allocate;
639: } else {
640: /* ~3 bytes per fragment. */
641: err = attr_allocate_clusters(
642: sbi, run, run_da, vcn, lcn, to_allocate,
643: &pre_alloc,
644: is_mft ? ALLOCATE_MFT : ALLOCATE_DEF, &alen,
645: is_mft ? 0 :
646: (sbi->record_size -
647: le32_to_cpu(rec->used) + 8) /
648: 3 +
649: 1,
650: NULL, NULL);
651: if (err)
652: goto out;
653: }
654:
655: done += alen;
656: vcn += alen;
657: if (to_allocate > alen)
658: to_allocate -= alen;
659: else
660: to_allocate = 0;
661:
662: pack_runs:
663: err = mi_pack_runs(mi, attr, run, vcn - svcn);
664: if (err)
665: goto undo_1;
666:
667: next_svcn = le64_to_cpu(attr->nres.evcn) + 1;
668: new_alloc_tmp = (u64)next_svcn << cluster_bits;
669: attr_b->nres.alloc_size = cpu_to_le64(new_alloc_tmp);
670: mi_b->dirty = dirty = true;
671:
672: if (next_svcn >= vcn && !to_allocate) {
673: /* Normal way. Update attribute and exit. */
674: attr_b->nres.data_size = cpu_to_le64(new_size);
675: goto ok;
676: }
677:
678: /* At least two MFT to avoid recursive loop. */
679: if (is_mft && next_svcn == vcn &&
680: ((u64)done << sbi->cluster_bits) >= 2 * sbi->record_size) {
681: new_size = new_alloc_tmp;
682: attr_b->nres.data_size = attr_b->nres.alloc_size;
683: goto ok;
684: }
685:
686: if (le32_to_cpu(rec->used) < sbi->record_size) {
687: old_alen = next_svcn;
688: evcn = old_alen - 1;
689: goto add_alloc_in_same_attr_seg;
690: }
691:
692: attr_b->nres.data_size = attr_b->nres.alloc_size;
693: if (new_alloc_tmp < old_valid)
694: attr_b->nres.valid_size = attr_b->nres.data_size;
695:
696: if (type == ATTR_LIST) {
697: err = ni_expand_list(ni);
698: if (err)
699: goto undo_2;
700: if (next_svcn < vcn)
701: goto pack_runs;
702:
703: /* Layout of records is changed. */
704: goto again;
705: }
706:
707: if (!nb->attr_list.size) {
708: err = ni_create_attr_list(nb);
709: /* In case of error layout of records is not changed. */
710: if (err)
711: goto undo_2;
712: /* Layout of records is changed. */
713: }
714:
715: if (next_svcn >= vcn) {
716: /* This is MFT data, repeat. */
717: goto again;
718: }
719:
720: /* Insert new attribute segment. */
721: err = ni_insert_nonresident(ni, type, name, name_len, run,
722: next_svcn, vcn - next_svcn,
723: attr_b->flags, &attr, &mi, NULL);
724:
725: /*
726: * Layout of records maybe changed.
727: * Find base attribute to update.
728: */
729: le_b = NULL;
730: attr_b = ni_find_attr(ni, NULL, &le_b, type, name, name_len,
731: NULL, &mi_b);
732: if (!attr_b) {
733: err = -EINVAL;
734: goto bad_inode;
735: }
736:
737: if (err) {
738: /* ni_insert_nonresident failed. */
739: attr = NULL;
740: goto undo_2;
741: }
742:
743: /* keep runs for $MFT::$ATTR_DATA and $MFT::$ATTR_BITMAP. */
744: if (ni->mi.rno != MFT_REC_MFT)
745: run_truncate_head(run, evcn + 1);
746:
747: svcn = le64_to_cpu(attr->nres.svcn);
748: evcn = le64_to_cpu(attr->nres.evcn);
749:
750: /*
751: * Attribute is in consistency state.
752: * Save this point to restore to if next steps fail.
753: */
754: old_valid = old_size = old_alloc = (u64)vcn << cluster_bits;
755: attr_b->nres.valid_size = attr_b->nres.data_size =
756: attr_b->nres.alloc_size = cpu_to_le64(old_size);
757: mi_b->dirty = dirty = true;
758: goto again_1;
759: }
760:
761: if (new_size != old_size ||
762: (new_alloc != old_alloc && !keep_prealloc)) {
763: /*
764: * Truncate clusters. In simple case we have to:
765: * - update packed run in 'mi'
766: * - update attr->nres.evcn
767: * - update attr_b->nres.data_size/attr_b->nres.alloc_size
768: * - mark and trim clusters as free (vcn, lcn, len)
769: */
770: CLST dlen = 0;
771:
772: vcn = max(svcn, new_alen);
773: new_alloc_tmp = (u64)vcn << cluster_bits;
774:
775: if (vcn > svcn) {
776: err = mi_pack_runs(mi, attr, run, vcn - svcn);
777: if (err)
778: goto out;
779: } else if (le && le->vcn) {
780: u16 le_sz = le16_to_cpu(le->size);
781:
782: /*
783: * NOTE: List entries for one attribute are always
784: * the same size. We deal with last entry (vcn==0)
785: * and it is not first in entries array
786: * (list entry for std attribute always first).
787: * So it is safe to step back.
788: */
789: mi_remove_attr(NULL, mi, attr);
790:
791: if (!al_remove_le(ni, le)) {
792: err = -EINVAL;
793: goto bad_inode;
794: }
795:
796: le = (struct ATTR_LIST_ENTRY *)((u8 *)le - le_sz);
797: } else {
798: attr->nres.evcn = cpu_to_le64((u64)vcn - 1);
799: mi->dirty = true;
800: }
801:
802: attr_b->nres.alloc_size = cpu_to_le64(new_alloc_tmp);
803:
804: if (vcn == new_alen) {
805: attr_b->nres.data_size = cpu_to_le64(new_size);
806: if (new_size < old_valid)
807: attr_b->nres.valid_size =
808: attr_b->nres.data_size;
809: } else {
810: if (new_alloc_tmp <=
811: le64_to_cpu(attr_b->nres.data_size))
812: attr_b->nres.data_size =
813: attr_b->nres.alloc_size;
814: if (new_alloc_tmp <
815: le64_to_cpu(attr_b->nres.valid_size))
816: attr_b->nres.valid_size =
817: attr_b->nres.alloc_size;
818: }
819: mi_b->dirty = dirty = true;
820:
821: err = run_deallocate_ex(sbi, run, vcn, evcn - vcn + 1, &dlen,
822: true, run_da);
823: if (err)
824: goto out;
825:
826: if (is_ext) {
827: /* dlen - really deallocated clusters. */
828: le64_sub_cpu(&attr_b->nres.total_size,
829: (u64)dlen << cluster_bits);
830: }
831:
832: run_truncate(run, vcn);
833:
834: if (new_alloc_tmp <= new_alloc)
835: goto ok;
836:
837: old_size = new_alloc_tmp;
838: vcn = svcn - 1;
839:
840: if (le == le_b) {
841: attr = attr_b;
842: mi = mi_b;
843: evcn = svcn - 1;
844: svcn = 0;
845: goto next_le;
846: }
847:
848: if (le->type != type || le->name_len != name_len ||
849: memcmp(le_name(le), name, name_len * sizeof(short))) {
850: err = -EINVAL;
851: goto bad_inode;
852: }
853:
854: err = ni_load_mi(ni, le, &mi);
855: if (err)
856: goto out;
857:
858: attr = mi_find_attr(ni, mi, NULL, type, name, name_len,
859: &le->id);
860: if (!attr) {
861: err = -EINVAL;
862: goto bad_inode;
863: }
864: goto next_le_1;
865: }
866:
867: ok:
868: if (new_valid) {
869: __le64 valid = cpu_to_le64(min(*new_valid, new_size));
870:
871: if (attr_b->nres.valid_size != valid) {
872: attr_b->nres.valid_size = valid;
873: mi_b->dirty = true;
874: }
875: }
876:
877: ok1:
878: if (ret)
879: *ret = attr_b;
880:
881: if ((type == ATTR_DATA || (type == ATTR_ALLOC && name == I30_NAME))) {
882: /* Update inode_set_bytes. */
883: if (attr_b->non_res &&
884: inode_get_bytes(&ni->vfs_inode) != new_alloc) {
885: inode_set_bytes(&ni->vfs_inode, new_alloc);
886: dirty = true;
887: }
888:
889: i_size_write(&ni->vfs_inode, new_size);
890:
891: /* Don't forget to update duplicate information in parent. */
892: if (dirty) {
893: ni->ni_flags |= NI_FLAG_UPDATE_PARENT;
894: mark_inode_dirty(&ni->vfs_inode);
895: }
896: }
897:
898: return 0;
899:
900: undo_2:
901: vcn -= alen;
902: attr_b->nres.data_size = cpu_to_le64(old_size);
903: attr_b->nres.valid_size = cpu_to_le64(old_valid);
904: attr_b->nres.alloc_size = cpu_to_le64(old_alloc);
905:
906: /* Restore 'attr' and 'mi'. */
907: if (attr)
908: goto restore_run;
909:
910: if (le64_to_cpu(attr_b->nres.svcn) <= svcn &&
911: svcn <= le64_to_cpu(attr_b->nres.evcn)) {
912: attr = attr_b;
913: le = le_b;
914: mi = mi_b;
915: } else if (!le_b) {
916: err = -EINVAL;
917: goto bad_inode;
918: } else {
919: le = le_b;
920: attr = ni_find_attr(ni, attr_b, &le, type, name, name_len,
921: &svcn, &mi);
922: if (!attr)
923: goto bad_inode;
924: }
925:
926: restore_run:
927: if (mi_pack_runs(mi, attr, run, evcn - svcn + 1))
928: is_bad = true;
929:
930: undo_1:
931: run_deallocate_ex(sbi, run, vcn, alen, NULL, false, run_da);
932:
933: run_truncate(run, vcn);
934: out:
935: if (is_bad) {
936: bad_inode:
937: _ntfs_bad_inode(&ni->vfs_inode);
938: }
939: return err;
940: }
SourceFile:fs/ntfs3/attrib.c]
|
| 337/4 |
2026/09/17 11:32 |
llm |
codeexpert |
0m
Model:
Tokens:
input: 19324
output: 28
thoughts: 1129
Thoughts: **Analyzing NTFS File Shrinking Logic**
Okay, let's break this down. The core question revolves around the correct order of operations when shrinking an NTFS file: should `truncate_setsize` be called before or after `ntfs_set_size`? My initial thought is to confirm the potential issue of deallocating blocks and dirty pages being written back to newly allocated space.
I need to confirm the sequence. The question raises a valid concern: if `ntfs_set_size` deallocates blocks *before* the dirty pages beyond the new EOF are flushed, there's a risk of data corruption. The deallocated blocks could be re-allocated to a different file, and those "dirty" pages, when eventually written back, would corrupt the data of the new owner.
To investigate, I first want to see how other filesystems handle this. It would also be good to check VFS documentation/conventions.
Then, I'll go straight to the code. Specifically, the `fs/ntfs3/file.c` file. Looking at the existing implementation, I see that, currently, `truncate_setsize` *is* called *before* `ntfs_set_size`. But is that always true, or are there other call sites or paths within the code? I need to know.
I need to dig into `ntfs_set_size` itself. I need to know if it does indeed deallocate blocks during a shrink operation. I see the critical `keep_prealloc` flag used in `ntfs_set_size`. The comment says "last 'true' means keep preallocated." Digging deeper, it calls `attr_set_size`.
Aha! Now I see the crucial conditional in `fs/ntfs3/attrib.c`: if `keep_prealloc` is true when shrinking, no deallocation occurs. The size is simply updated in the metadata. This is important: the block deallocation *only* happens if `keep_prealloc` is false.
I need to confirm that `ntfs_set_size` does indeed pass `keep_prealloc = true`. Yes, the code explicitly passes `true`. So, if that code path is followed, no block deallocation happens.
But... are there other cases? What about sparse or compressed files? I see the code checking if the attribute is extended, and setting `keep_prealloc` to false in that case. That's a critical path to remember: *if* the file is extended (e.g., compressed or sparse), then block deallocation could occur *before* the dirty data is flushed.
I need to ask myself, is this the whole picture, and why is this being raised? Are there subtleties I'm missing? I should investigate the commit logs and mailing lists. Is there existing discussion or prior issues related to this specific ordering or `keep_prealloc` behavior? I'll search for "truncate_setsize" in the git log to see if there's any relevant history.
|
| 338/4 |
2026/09/17 11:32 |
tool |
git-log |
0m
Args: map[CodeRegexp:truncate_setsize.*ntfs_set_size]
Results:
|
| 339/4 |
2026/09/17 11:32 |
llm |
codeexpert |
0m
Model:
Tokens:
input: 21137
output: 37
thoughts: 25
Thoughts: Here's my thought process, summarized as you requested:
**Investigating Potential Data Truncation**
Okay, so I need to dig into potential issues related to data truncation, specifically within the context of `setsize` operations. My first instinct is to cast a wide net. I'm going to leverage the power of the version control system, in this case, likely Git, to explore the commit history. I'll search for every instance of the term `truncate_setsize`. That should give me a good overview of where this function or related concepts have been discussed, implemented, and potentially modified. Given the context, I should focus on the file system layers. I'll start with the entire repository and, depending on the results, narrow the search to `fs/ntfs3`. This focused search within the NTFS3 module might provide quicker results. Let's see what the search uncovers!
|
| 340/4 |
2026/09/17 11:33 |
tool |
git-log |
0m
Args: map[Count:20 MessageRegexps:[truncate_setsize] PathPrefix:fs/ntfs3]
Results:
|
| 341/4 |
2026/09/17 11:33 |
llm |
codeexpert |
0m
Model:
Tokens:
input: 21401
output: 30
thoughts: 32
Thoughts: Okay, here's my take on those thoughts, framed as my own:
**Investigating Potential Data Corruption Scenarios**
Alright, before I dive too deep into this specific issue, let's take a step back and adopt a broader view. I need to be absolutely sure I'm not missing something subtle here. My initial focus might be too narrow. Let's start with a thorough search. I'm going to leverage my knowledge of the codebase and its history. I want to search across *every single commit message* for mentions of keywords that are relevant to this particular type of problem. Think terms like `truncate_setsize`, which sounds like it could be related to resizing or modifying data structures, which is a key potential problem. Beyond that, let's include anything related to "shrinking" β as shrinking could lead to data loss. Also, I'm thinking about related areas, like `truncate_pagecache`, because the cache interacts with all data and could be implicated. The goal is to see if any historical changes, fixes, or discussions have happened that can provide a clue to this issue. It's time to gather all related context.
|
| 342/4 |
2026/09/17 11:33 |
tool |
git-log |
0m
Args: map[Count:20 MessageRegexps:[truncate_setsize shrink]]
Results:
|
| 343/4 |
2026/09/17 11:33 |
llm |
codeexpert |
0m
Model:
Tokens:
input: 21718
output: 26
thoughts: 23
Thoughts: Here's my take on those thoughts, tailored for an expert like yourself:
**Analyzing the Git History with Precision**
Okay, so I'm thinking I need to delve into a Git repository's history, but I want to be *very* specific about what I'm looking for. The core command I'm starting with is `git log`. That's my go-to for examining commits.
The key to this investigation is the `MessageRegexps` directive. I need to filter the commit messages using regular expressions, and the specific regexp I've selected, `"truncate_setsize"`, tells me precisely what I'm hunting for. My hypothesis is that I'm trying to identify commits that deal with a truncated set size, meaning I'm looking for commits containing a message that includes the phrase "truncate_setsize". This likely suggests a particular area of code and I'm very interested to see where those changes might have occurred. Essentially, I'm performing focused pattern matching across the commit log.
|
| 344/4 |
2026/09/17 11:34 |
tool |
git-log |
0m
Args: map[Count:10 MessageRegexps:[truncate_setsize]]
Results:
|
| 345/4 |
2026/09/17 11:34 |
llm |
codeexpert |
0m
Model:
Tokens:
input: 21995
output: 30
thoughts: 63
Thoughts: **Investigating a Git Log Mystery**
Okay, so `git log` came back empty. That's strange, I know I've been making commits. Wait a minute⦠could this be a shallow clone issue? I'll bet the repository only has commit `fd73f4a66598` or something similar, because it was cloned with a depth of 1. Right, that makes sense.
To confirm this, I need to check the contents of that specific commit. Let's fire up `git show` and see what's what with `fd73f4a66598`. That should give me the information I need to confirm my theory and get a handle on the repository's history.
|
| 346/4 |
2026/09/17 11:34 |
tool |
git-show |
0m
Args: map[Commit:fd73f4a66598 Stat:true]
Results: map[Output:commit fd73f4a6659897191fa0d40695fe370925dd3780
Author: Linus Torvalds <torvalds@linux-foundation.org>
Date: Sun Sep 13 14:38:02 2026 -0700
Linux 7.3-rc3
.clang-format | 808 +
.clippy.toml | 21 +
.cocciconfig | 3 +
.editorconfig | 27 +
.get_maintainer.ignore | 9 +
.gitattributes | 5 +
.gitignore | 196 +
.mailmap | 996 +
.pylintrc | 2 +
.rustfmt.toml | 12 +
COPYING | 20 +
CREDITS | 4651 +
Documentation/.gitignore | 3 +
Documentation/.renames.txt | 1185 +
Documentation/ABI/README | 98 +
.../ABI/obsolete/automount-tracefs-debugfs | 20 +
Documentation/ABI/obsolete/o2cb | 11 +
Documentation/ABI/obsolete/procfs-i8k | 10 +
Documentation/ABI/obsolete/sysfs-bus-iio | 174 +
Documentation/ABI/obsolete/sysfs-bus-usb | 31 +
Documentation/ABI/obsolete/sysfs-class-typec | 48 +
Documentation/ABI/obsolete/sysfs-cpuidle | 9 +
.../ABI/obsolete/sysfs-driver-hid-roccat-arvo | 53 +
.../ABI/obsolete/sysfs-driver-hid-roccat-isku | 153 +
.../ABI/obsolete/sysfs-driver-hid-roccat-koneplus | 145 +
.../ABI/obsolete/sysfs-driver-hid-roccat-konepure | 105 +
.../ABI/obsolete/sysfs-driver-hid-roccat-kovaplus | 116 +
.../ABI/obsolete/sysfs-driver-hid-roccat-lua | 7 +
.../ABI/obsolete/sysfs-driver-hid-roccat-pyra | 126 +
.../ABI/obsolete/sysfs-driver-hid-roccat-ryos | 178 +
.../ABI/obsolete/sysfs-driver-hid-roccat-savu | 77 +
.../ABI/obsolete/sysfs-driver-intel_pmc_bxt | 22 +
Documentation/ABI/obsolete/sysfs-driver-ivpu | 30 +
.../ABI/obsolete/sysfs-driver-samsung-laptop | 10 +
Documentation/ABI/obsolete/sysfs-firmware-acpi | 8 +
Documentation/ABI/obsolete/sysfs-gpio | 40 +
.../ABI/obsolete/sysfs-kernel-fadump_enabled | 9 +
.../ABI/obsolete/sysfs-kernel-fadump_registered | 10 +
.../ABI/obsolete/sysfs-kernel-fadump_release_mem | 10 +
.../ABI/obsolete/sysfs-kernel-kexec-kdump | 71 +
.../ABI/obsolete/sysfs-platform-ideapad-laptop | 8 +
Documentation/ABI/removed/devfs | 13 +
Documentation/ABI/removed/dv1394 | 14 +
Documentation/ABI/removed/ip_queue | 9 +
Documentation/ABI/removed/net_dma | 8 +
Documentation/ABI/removed/o2cb | 10 +
Documentation/ABI/removed/raw1394 | 16 +
Documentation/ABI/removed/sysfs-bus-nfit | 17 +
Documentation/ABI/removed/sysfs-class-cxl | 272 +
Documentation/ABI/removed/sysfs-class-rfkill | 13 +
Documentation/ABI/removed/sysfs-firmware-efi-vars | 12 +
.../removed/sysfs-kernel-fadump_release_opalcore | 9 +
Documentation/ABI/removed/sysfs-kernel-uids | 14 +
Documentation/ABI/removed/sysfs-mce | 37 +
.../ABI/removed/sysfs-selinux-checkreqprot | 26 +
Documentation/ABI/removed/sysfs-selinux-disable | 29 +
Documentation/ABI/removed/sysfs-selinux-user | 12 +
Documentation/ABI/removed/video1394 | 17 +
Documentation/ABI/stable/configfs-nvmet | 352 +
Documentation/ABI/stable/firewire-cdev | 111 +
Documentation/ABI/stable/o2cb | 10 +
Documentation/ABI/stable/procfs-audit_loginuid | 27 +
Documentation/ABI/stable/syscalls | 10 +
Documentation/ABI/stable/sysfs-acpi-pmprofile | 28 +
Documentation/ABI/stable/sysfs-block | 941 +
Documentation/ABI/stable/sysfs-bus-firewire | 136 +
Documentation/ABI/stable/sysfs-bus-fsl-mc | 19 +
Documentation/ABI/stable/sysfs-bus-mhi | 44 +
Documentation/ABI/stable/sysfs-bus-nvmem | 50 +
Documentation/ABI/stable/sysfs-bus-usb | 142 +
Documentation/ABI/stable/sysfs-bus-vmbus | 187 +
Documentation/ABI/stable/sysfs-bus-w1 | 12 +
Documentation/ABI/stable/sysfs-bus-xen-backend | 84 +
Documentation/ABI/stable/sysfs-class-backlight | 63 +
Documentation/ABI/stable/sysfs-class-bluetooth | 9 +
Documentation/ABI/stable/sysfs-class-infiniband | 784 +
Documentation/ABI/stable/sysfs-class-rfkill | 93 +
Documentation/ABI/stable/sysfs-class-tpm | 210 +
Documentation/ABI/stable/sysfs-class-ubi | 221 +
Documentation/ABI/stable/sysfs-class-udc | 93 +
Documentation/ABI/stable/sysfs-devices | 32 +
Documentation/ABI/stable/sysfs-devices-node | 238 +
Documentation/ABI/stable/sysfs-devices-system-cpu | 117 +
.../ABI/stable/sysfs-devices-system-xen_memory | 86 +
Documentation/ABI/stable/sysfs-driver-aspeed-vuart | 24 +
Documentation/ABI/stable/sysfs-driver-dma-idxd | 376 +
Documentation/ABI/stable/sysfs-driver-dma-ioatdma | 30 +
.../ABI/stable/sysfs-driver-firmware-zynqmp | 256 +
Documentation/ABI/stable/sysfs-driver-ib_srp | 192 +
Documentation/ABI/stable/sysfs-driver-misc-cp500 | 25 +
Documentation/ABI/stable/sysfs-driver-mlxreg-io | 815 +
Documentation/ABI/stable/sysfs-driver-qaic | 19 +
Documentation/ABI/stable/sysfs-driver-qla2xxx | 8 +
Documentation/ABI/stable/sysfs-driver-speakup | 394 +
Documentation/ABI/stable/sysfs-driver-usb-usbtmc | 27 +
Documentation/ABI/stable/sysfs-driver-w1_ds2438 | 13 +
Documentation/ABI/stable/sysfs-driver-w1_ds28e04 | 15 +
Documentation/ABI/stable/sysfs-driver-w1_ds28ea00 | 6 +
Documentation/ABI/stable/sysfs-firmware-opal-dump | 46 +
Documentation/ABI/stable/sysfs-firmware-opal-elog | 62 +
Documentation/ABI/stable/sysfs-fs-orangefs | 87 +
Documentation/ABI/stable/sysfs-hypervisor-xen | 135 +
Documentation/ABI/stable/sysfs-kernel-notes | 5 +
.../ABI/stable/sysfs-kernel-time-aux-clocks | 5 +
Documentation/ABI/stable/sysfs-module | 47 +
Documentation/ABI/stable/sysfs-nvme | 453 +
Documentation/ABI/stable/sysfs-platform-wmi-bmof | 7 +
Documentation/ABI/stable/sysfs-transport-srp | 58 +
Documentation/ABI/stable/thermal-notification | 4 +
Documentation/ABI/stable/vdso | 37 +
Documentation/ABI/testing/amdpmf-interface | 73 +
Documentation/ABI/testing/configfs-acpi | 52 +
Documentation/ABI/testing/configfs-iio | 34 +
Documentation/ABI/testing/configfs-most | 241 +
Documentation/ABI/testing/configfs-rdma_cm | 34 +
.../ABI/testing/configfs-spear-pcie-gadget | 33 +
Documentation/ABI/testing/configfs-stp-policy | 48 +
.../ABI/testing/configfs-stp-policy-p_sys-t | 41 +
.../ABI/testing/configfs-thunderbolt_stream | 98 +
Documentation/ABI/testing/configfs-tsm-report | 161 +
Documentation/ABI/testing/configfs-usb-gadget | 158 +
Documentation/ABI/testing/configfs-usb-gadget-acm | 15 +
Documentation/ABI/testing/configfs-usb-gadget-ecm | 20 +
Documentation/ABI/testing/configfs-usb-gadget-eem | 16 +
Documentation/ABI/testing/configfs-usb-gadget-ffs | 17 +
Documentation/ABI/testing/configfs-usb-gadget-hid | 13 +
.../ABI/testing/configfs-usb-gadget-loopback | 10 +
.../ABI/testing/configfs-usb-gadget-mass-storage | 41 +
Documentation/ABI/testing/configfs-usb-gadget-midi | 15 +
.../ABI/testing/configfs-usb-gadget-midi2 | 54 +
Documentation/ABI/testing/configfs-usb-gadget-ncm | 15 +
Documentation/ABI/testing/configfs-usb-gadget-obex | 9 +
.../ABI/testing/configfs-usb-gadget-phonet | 8 +
.../ABI/testing/configfs-usb-gadget-printer | 11 +
.../ABI/testing/configfs-usb-gadget-rndis | 19 +
.../ABI/testing/configfs-usb-gadget-serial | 9 +
.../ABI/testing/configfs-usb-gadget-sourcesink | 16 +
.../ABI/testing/configfs-usb-gadget-subset | 16 +
Documentation/ABI/testing/configfs-usb-gadget-tcm | 6 +
Documentation/ABI/testing/configfs-usb-gadget-uac1 | 41 +
.../ABI/testing/configfs-usb-gadget-uac1_legacy | 9 +
Documentation/ABI/testing/configfs-usb-gadget-uac2 | 51 +
Documentation/ABI/testing/configfs-usb-gadget-uvc | 438 +
Documentation/ABI/testing/debugfs-alienware-wmi | 64 +
Documentation/ABI/testing/debugfs-amd-iommu | 131 +
Documentation/ABI/testing/debugfs-cdns-pcie | 5 +
Documentation/ABI/testing/debugfs-cec-error-inj | 40 +
Documentation/ABI/testing/debugfs-cros-ec | 78 +
Documentation/ABI/testing/debugfs-cxl | 157 +
Documentation/ABI/testing/debugfs-dell-wmi-ddv | 34 +
Documentation/ABI/testing/debugfs-driver-dcc | 127 +
Documentation/ABI/testing/debugfs-driver-genwqe | 91 +
.../ABI/testing/debugfs-driver-habanalabs | 323 +
Documentation/ABI/testing/debugfs-driver-qat | 109 +
.../ABI/testing/debugfs-driver-qat_telemetry | 259 +
Documentation/ABI/testing/debugfs-dwc-pcie | 157 +
Documentation/ABI/testing/debugfs-ec | 21 +
Documentation/ABI/testing/debugfs-hisi-hpre | 200 +
Documentation/ABI/testing/debugfs-hisi-migration | 25 +
Documentation/ABI/testing/debugfs-hisi-sec | 173 +
Documentation/ABI/testing/debugfs-hisi-zip | 174 +
Documentation/ABI/testing/debugfs-hyperv | 23 +
Documentation/ABI/testing/debugfs-ideapad | 19 +
Documentation/ABI/testing/debugfs-iio-ad9467 | 39 +
Documentation/ABI/testing/debugfs-iio-backend | 20 +
Documentation/ABI/testing/debugfs-intel-iommu | 276 +
Documentation/ABI/testing/debugfs-moxtet | 35 +
Documentation/ABI/testing/debugfs-msi-wmi-platform | 14 +
Documentation/ABI/testing/debugfs-olpc | 16 +
Documentation/ABI/testing/debugfs-pcie-ptm | 70 +
Documentation/ABI/testing/debugfs-pfo-nx-crypto | 45 +
Documentation/ABI/testing/debugfs-scmi | 70 +
Documentation/ABI/testing/debugfs-scmi-raw | 208 +
Documentation/ABI/testing/debugfs-tpmi | 40 +
Documentation/ABI/testing/debugfs-vfio | 57 +
Documentation/ABI/testing/debugfs-wilco-ec | 45 +
Documentation/ABI/testing/dell-smbios-wmi | 41 +
Documentation/ABI/testing/dev-kmsg | 127 +
Documentation/ABI/testing/devlink-resource-mlxsw | 33 +
Documentation/ABI/testing/evm | 109 +
Documentation/ABI/testing/gpio-cdev | 28 +
Documentation/ABI/testing/ima_policy | 196 +
Documentation/ABI/testing/ppc-memtrace | 46 +
Documentation/ABI/testing/procfs-attr-current | 20 +
Documentation/ABI/testing/procfs-attr-exec | 20 +
Documentation/ABI/testing/procfs-attr-prev | 19 +
Documentation/ABI/testing/procfs-diskstats | 43 +
.../ABI/testing/procfs-nfsd-reply_cache_stats | 38 +
Documentation/ABI/testing/procfs-smaps_rollup | 42 +
Documentation/ABI/testing/pstore | 47 +
Documentation/ABI/testing/rtc-cdev | 50 +
Documentation/ABI/testing/securityfs-secrets-coco | 51 +
Documentation/ABI/testing/sysfs-amd-pmc | 13 +
Documentation/ABI/testing/sysfs-amd-pmf | 13 +
Documentation/ABI/testing/sysfs-ata | 140 +
.../ABI/testing/sysfs-auxdisplay-linedisp | 90 +
Documentation/ABI/testing/sysfs-block-aoe | 45 +
Documentation/ABI/testing/sysfs-block-bcache | 149 +
Documentation/ABI/testing/sysfs-block-device | 119 +
Documentation/ABI/testing/sysfs-block-dm | 47 +
Documentation/ABI/testing/sysfs-block-loop | 50 +
Documentation/ABI/testing/sysfs-block-rnbd | 64 +
Documentation/ABI/testing/sysfs-block-rssd | 5 +
Documentation/ABI/testing/sysfs-block-zram | 166 +
Documentation/ABI/testing/sysfs-bus-acpi | 98 +
Documentation/ABI/testing/sysfs-bus-amba | 20 +
Documentation/ABI/testing/sysfs-bus-auxiliary | 9 +
Documentation/ABI/testing/sysfs-bus-bcma | 31 +
Documentation/ABI/testing/sysfs-bus-cdx | 121 +
Documentation/ABI/testing/sysfs-bus-coreboot | 45 +
.../ABI/testing/sysfs-bus-coresight-devices-cti | 247 +
.../sysfs-bus-coresight-devices-dummy-source | 21 +
.../ABI/testing/sysfs-bus-coresight-devices-etb10 | 88 +
.../ABI/testing/sysfs-bus-coresight-devices-etm3x | 328 +
.../ABI/testing/sysfs-bus-coresight-devices-etm4x | 532 +
.../ABI/testing/sysfs-bus-coresight-devices-funnel | 18 +
.../ABI/testing/sysfs-bus-coresight-devices-stm | 59 +
.../ABI/testing/sysfs-bus-coresight-devices-tmc | 115 +
.../ABI/testing/sysfs-bus-coresight-devices-tpda | 69 +
.../ABI/testing/sysfs-bus-coresight-devices-tpdm | 290 +
.../ABI/testing/sysfs-bus-coresight-devices-trbe | 20 +
.../testing/sysfs-bus-coresight-devices-ultra_smb | 31 +
Documentation/ABI/testing/sysfs-bus-counter | 477 +
Documentation/ABI/testing/sysfs-bus-css | 56 +
Documentation/ABI/testing/sysfs-bus-cxl | 646 +
Documentation/ABI/testing/sysfs-bus-dax | 177 +
Documentation/ABI/testing/sysfs-bus-dfl | 17 +
.../ABI/testing/sysfs-bus-dfl-devices-emif | 25 +
.../ABI/testing/sysfs-bus-dfl-devices-n3000-nios | 47 +
.../ABI/testing/sysfs-bus-event_source-devices | 24 +
.../testing/sysfs-bus-event_source-devices-caps | 24 +
.../testing/sysfs-bus-event_source-devices-dfl_fme | 104 +
.../ABI/testing/sysfs-bus-event_source-devices-dsa | 30 +
.../testing/sysfs-bus-event_source-devices-events | 102 +
.../testing/sysfs-bus-event_source-devices-format | 21 +
.../sysfs-bus-event_source-devices-hisi_ptt | 113 +
.../testing/sysfs-bus-event_source-devices-hv_24x7 | 98 +
.../testing/sysfs-bus-event_source-devices-hv_gpci | 242 +
.../testing/sysfs-bus-event_source-devices-iommu | 37 +
.../testing/sysfs-bus-event_source-devices-rdpmc | 44 +
.../testing/sysfs-bus-event_source-devices-uncore | 13 +
.../testing/sysfs-bus-event_source-devices-vpa-dtl | 25 +
.../testing/sysfs-bus-event_source-devices-vpa-pmu | 25 +
Documentation/ABI/testing/sysfs-bus-fcoe | 138 +
Documentation/ABI/testing/sysfs-bus-fsi | 46 +
.../ABI/testing/sysfs-bus-fsi-devices-sbefifo | 10 +
Documentation/ABI/testing/sysfs-bus-fsl-mc | 25 +
Documentation/ABI/testing/sysfs-bus-hsi | 19 +
.../ABI/testing/sysfs-bus-i2c-devices-bq32k | 7 +
.../ABI/testing/sysfs-bus-i2c-devices-fsa9480 | 27 +
.../ABI/testing/sysfs-bus-i2c-devices-hm6352 | 21 +
.../ABI/testing/sysfs-bus-i2c-devices-lm3533 | 15 +
.../ABI/testing/sysfs-bus-i2c-devices-m24lr | 100 +
.../ABI/testing/sysfs-bus-i2c-devices-pca954x | 23 +
.../testing/sysfs-bus-i2c-devices-turris-omnia-mcu | 113 +
Documentation/ABI/testing/sysfs-bus-i3c | 194 +
Documentation/ABI/testing/sysfs-bus-iio | 2511 +
.../ABI/testing/sysfs-bus-iio-accel-adxl372 | 7 +
.../ABI/testing/sysfs-bus-iio-accel-bmc150 | 7 +
Documentation/ABI/testing/sysfs-bus-iio-ad9739a | 19 +
.../ABI/testing/sysfs-bus-iio-adc-ad-sigma-delta | 23 +
Documentation/ABI/testing/sysfs-bus-iio-adc-ad4130 | 20 +
Documentation/ABI/testing/sysfs-bus-iio-adc-ad7192 | 27 +
.../ABI/testing/sysfs-bus-iio-adc-ad7280a | 13 +
.../testing/sysfs-bus-iio-adc-envelope-detector | 39 +
Documentation/ABI/testing/sysfs-bus-iio-adc-hi8435 | 48 +
.../ABI/testing/sysfs-bus-iio-adc-max11410 | 13 +
.../ABI/testing/sysfs-bus-iio-adc-mcp3564 | 53 +
Documentation/ABI/testing/sysfs-bus-iio-adc-mt6360 | 78 +
.../ABI/testing/sysfs-bus-iio-adc-pac1934 | 9 +
Documentation/ABI/testing/sysfs-bus-iio-adc-stm32 | 21 +
Documentation/ABI/testing/sysfs-bus-iio-bno055 | 81 +
Documentation/ABI/testing/sysfs-bus-iio-cdc-ad7746 | 11 +
.../ABI/testing/sysfs-bus-iio-chemical-sgp40 | 17 +
.../ABI/testing/sysfs-bus-iio-chemical-sunrise-co2 | 38 +
.../ABI/testing/sysfs-bus-iio-chemical-vz89x | 7 +
Documentation/ABI/testing/sysfs-bus-iio-cros-ec | 21 +
Documentation/ABI/testing/sysfs-bus-iio-dac | 61 +
Documentation/ABI/testing/sysfs-bus-iio-dac-ad5766 | 31 +
.../ABI/testing/sysfs-bus-iio-dac-dpot-dac | 8 +
.../ABI/testing/sysfs-bus-iio-dac-ltc2688 | 55 +
.../ABI/testing/sysfs-bus-iio-dfsdm-adc-stm32 | 22 +
.../ABI/testing/sysfs-bus-iio-distance-srf08 | 17 +
Documentation/ABI/testing/sysfs-bus-iio-dma-buffer | 19 +
.../ABI/testing/sysfs-bus-iio-filter-admv8818 | 18 +
Documentation/ABI/testing/sysfs-bus-iio-flow | 21 +
Documentation/ABI/testing/sysfs-bus-iio-frequency | 11 +
.../ABI/testing/sysfs-bus-iio-frequency-ad9523 | 31 +
.../ABI/testing/sysfs-bus-iio-frequency-adf4350 | 11 +
.../ABI/testing/sysfs-bus-iio-frequency-adf4371 | 11 +
.../ABI/testing/sysfs-bus-iio-frequency-admv1013 | 38 +
.../ABI/testing/sysfs-bus-iio-frequency-admv1014 | 23 +
.../ABI/testing/sysfs-bus-iio-gyro-bmg160 | 7 +
.../ABI/testing/sysfs-bus-iio-health-afe440x | 39 +
Documentation/ABI/testing/sysfs-bus-iio-humidity | 10 +
.../sysfs-bus-iio-impedance-analyzer-ad5933 | 35 +
Documentation/ABI/testing/sysfs-bus-iio-ina2xx-adc | 15 +
.../ABI/testing/sysfs-bus-iio-inv_icm42600 | 18 +
Documentation/ABI/testing/sysfs-bus-iio-isl29501 | 47 +
.../ABI/testing/sysfs-bus-iio-light-isl29018 | 21 +
.../ABI/testing/sysfs-bus-iio-light-lm3533-als | 56 +
.../ABI/testing/sysfs-bus-iio-light-si1133 | 22 +
.../ABI/testing/sysfs-bus-iio-light-tsl2583 | 20 +
.../ABI/testing/sysfs-bus-iio-light-tsl2772 | 13 +
.../ABI/testing/sysfs-bus-iio-magnetometer-hmc5843 | 20 +
Documentation/ABI/testing/sysfs-bus-iio-meas-spec | 7 +
Documentation/ABI/testing/sysfs-bus-iio-mpu6050 | 13 +
.../testing/sysfs-bus-iio-potentiometer-mcp4531 | 8 +
Documentation/ABI/testing/sysfs-bus-iio-proximity | 24 +
.../ABI/testing/sysfs-bus-iio-proximity-as3935 | 15 +
.../ABI/testing/sysfs-bus-iio-resolver-ad2s1210 | 27 +
Documentation/ABI/testing/sysfs-bus-iio-sps30 | 28 +
Documentation/ABI/testing/sysfs-bus-iio-sx9310 | 10 +
Documentation/ABI/testing/sysfs-bus-iio-sx9324 | 29 +
.../ABI/testing/sysfs-bus-iio-thermocouple | 18 +
.../ABI/testing/sysfs-bus-iio-timer-stm32 | 143 +
.../ABI/testing/sysfs-bus-iio-trigger-sysfs | 42 +
Documentation/ABI/testing/sysfs-bus-iio-vf610 | 16 +
.../ABI/testing/sysfs-bus-intel_th-devices-gth | 52 +
.../ABI/testing/sysfs-bus-intel_th-devices-msc | 54 +
.../ABI/testing/sysfs-bus-intel_th-devices-pti | 24 +
.../ABI/testing/sysfs-bus-intel_th-output-devices | 15 +
Documentation/ABI/testing/sysfs-bus-mcb | 29 +
Documentation/ABI/testing/sysfs-bus-mdio | 72 +
Documentation/ABI/testing/sysfs-bus-media | 6 +
Documentation/ABI/testing/sysfs-bus-mei | 56 +
Documentation/ABI/testing/sysfs-bus-mmc | 4 +
Documentation/ABI/testing/sysfs-bus-most | 299 +
Documentation/ABI/testing/sysfs-bus-moxtet-devices | 17 +
Documentation/ABI/testing/sysfs-bus-nfit | 233 +
Documentation/ABI/testing/sysfs-bus-nvdimm | 60 +
Documentation/ABI/testing/sysfs-bus-optee-devices | 17 +
Documentation/ABI/testing/sysfs-bus-papr-pmem | 75 +
Documentation/ABI/testing/sysfs-bus-pci | 704 +
.../ABI/testing/sysfs-bus-pci-devices-aer | 163 +
.../ABI/testing/sysfs-bus-pci-devices-avs | 8 +
.../ABI/testing/sysfs-bus-pci-devices-catpt | 17 +
.../ABI/testing/sysfs-bus-pci-devices-cciss | 80 +
.../ABI/testing/sysfs-bus-pci-devices-pvpanic | 26 +
.../ABI/testing/sysfs-bus-pci-drivers-btintel_pcie | 15 +
.../ABI/testing/sysfs-bus-pci-drivers-ehci_hcd | 46 +
.../ABI/testing/sysfs-bus-pci-drivers-janz-cmodio | 8 +
.../ABI/testing/sysfs-bus-pci-drivers-xhci_hcd | 129 +
Documentation/ABI/testing/sysfs-bus-peci | 16 +
Documentation/ABI/testing/sysfs-bus-platform | 56 +
.../sysfs-bus-platform-devices-ampere-smpro | 325 +
.../testing/sysfs-bus-platform-devices-occ-hwmon | 13 +
.../sysfs-bus-platform-drivers-amd_x3d_vcache | 12 +
.../ABI/testing/sysfs-bus-platform-onboard-usb-dev | 9 +
Documentation/ABI/testing/sysfs-bus-rapidio | 201 +
Documentation/ABI/testing/sysfs-bus-rbd | 173 +
Documentation/ABI/testing/sysfs-bus-rpmsg | 95 +
Documentation/ABI/testing/sysfs-bus-siox | 90 +
.../ABI/testing/sysfs-bus-soundwire-master | 23 +
.../ABI/testing/sysfs-bus-soundwire-slave | 109 +
.../ABI/testing/sysfs-bus-spi-devices-spi-nor | 40 +
.../testing/sysfs-bus-surface_aggregator-tabletsw | 57 +
Documentation/ABI/testing/sysfs-bus-thunderbolt | 370 +
Documentation/ABI/testing/sysfs-bus-typec | 51 +
Documentation/ABI/testing/sysfs-bus-usb | 607 +
.../ABI/testing/sysfs-bus-usb-devices-usbsevseg | 46 +
Documentation/ABI/testing/sysfs-bus-usb-lvstest | 60 +
Documentation/ABI/testing/sysfs-bus-vdpa | 57 +
Documentation/ABI/testing/sysfs-bus-vfio-mdev | 113 +
Documentation/ABI/testing/sysfs-bus-vmbus | 21 +
Documentation/ABI/testing/sysfs-bus-wmi | 81 +
Documentation/ABI/testing/sysfs-c2port | 81 +
Documentation/ABI/testing/sysfs-cfq-target-latency | 8 +
Documentation/ABI/testing/sysfs-class | 16 +
Documentation/ABI/testing/sysfs-class-backlight | 186 +
.../testing/sysfs-class-backlight-driver-lm3533 | 54 +
.../ABI/testing/sysfs-class-backlight-lm3639 | 11 +
Documentation/ABI/testing/sysfs-class-bdi | 134 +
Documentation/ABI/testing/sysfs-class-bsr | 25 +
Documentation/ABI/testing/sysfs-class-chromeos | 53 +
.../sysfs-class-chromeos-driver-cros-ec-lightbar | 74 +
.../sysfs-class-chromeos-driver-cros-ec-vbc | 6 +
Documentation/ABI/testing/sysfs-class-devfreq | 143 +
.../ABI/testing/sysfs-class-devfreq-event | 25 +
Documentation/ABI/testing/sysfs-class-devlink | 130 +
Documentation/ABI/testing/sysfs-class-drm | 8 +
Documentation/ABI/testing/sysfs-class-extcon | 101 +
Documentation/ABI/testing/sysfs-class-fc | 27 +
Documentation/ABI/testing/sysfs-class-fc_host | 23 +
.../ABI/testing/sysfs-class-fc_remote_ports | 23 +
Documentation/ABI/testing/sysfs-class-firmware | 77 +
.../ABI/testing/sysfs-class-firmware-attributes | 494 +
Documentation/ABI/testing/sysfs-class-fpga-bridge | 11 +
Documentation/ABI/testing/sysfs-class-fpga-manager | 60 +
Documentation/ABI/testing/sysfs-class-fpga-region | 9 +
Documentation/ABI/testing/sysfs-class-gnss | 17 +
Documentation/ABI/testing/sysfs-class-hwmon | 1089 +
.../ABI/testing/sysfs-class-ieee80211-rtw89 | 24 +
Documentation/ABI/testing/sysfs-class-intel_pmt | 119 +
.../ABI/testing/sysfs-class-intel_pmt-features | 134 +
Documentation/ABI/testing/sysfs-class-iommu | 17 +
.../ABI/testing/sysfs-class-iommu-amd-iommu | 14 +
.../ABI/testing/sysfs-class-iommu-intel-iommu | 32 +
Documentation/ABI/testing/sysfs-class-issei | 73 +
Documentation/ABI/testing/sysfs-class-lcd | 23 +
Documentation/ABI/testing/sysfs-class-led | 89 +
.../ABI/testing/sysfs-class-led-driver-aw200xx | 5 +
.../ABI/testing/sysfs-class-led-driver-lm3533 | 73 +
.../testing/sysfs-class-led-driver-turris-omnia | 28 +
Documentation/ABI/testing/sysfs-class-led-flash | 89 +
.../ABI/testing/sysfs-class-led-multicolor | 37 +
.../ABI/testing/sysfs-class-led-trigger-netdev | 192 +
.../ABI/testing/sysfs-class-led-trigger-oneshot | 36 +
.../ABI/testing/sysfs-class-led-trigger-pattern | 50 +
.../ABI/testing/sysfs-class-led-trigger-tty | 62 +
.../ABI/testing/sysfs-class-led-trigger-usbport | 13 +
Documentation/ABI/testing/sysfs-class-leds-gt683r | 18 +
Documentation/ABI/testing/sysfs-class-mei | 105 +
Documentation/ABI/testing/sysfs-class-mic | 178 +
Documentation/ABI/testing/sysfs-class-mtd | 242 +
Documentation/ABI/testing/sysfs-class-mux | 16 +
Documentation/ABI/testing/sysfs-class-net | 354 +
Documentation/ABI/testing/sysfs-class-net-cdc_ncm | 168 +
Documentation/ABI/testing/sysfs-class-net-dsa | 14 +
Documentation/ABI/testing/sysfs-class-net-grcan | 35 +
.../ABI/testing/sysfs-class-net-janz-ican3 | 19 +
Documentation/ABI/testing/sysfs-class-net-peak_usb | 19 +
Documentation/ABI/testing/sysfs-class-net-phydev | 75 +
Documentation/ABI/testing/sysfs-class-net-qmi | 76 +
Documentation/ABI/testing/sysfs-class-net-queues | 121 +
.../ABI/testing/sysfs-class-net-statistics | 217 +
Documentation/ABI/testing/sysfs-class-ocxl | 51 +
.../ABI/testing/sysfs-class-platform-profile | 50 +
Documentation/ABI/testing/sysfs-class-power | 906 +
.../ABI/testing/sysfs-class-power-bd71828 | 13 +
Documentation/ABI/testing/sysfs-class-power-gaokun | 27 +
.../ABI/testing/sysfs-class-power-ltc4162l | 82 +
.../ABI/testing/sysfs-class-power-max1720x | 32 +
Documentation/ABI/testing/sysfs-class-power-mp2629 | 9 +
Documentation/ABI/testing/sysfs-class-power-rt9467 | 19 +
Documentation/ABI/testing/sysfs-class-power-rt9471 | 32 +
Documentation/ABI/testing/sysfs-class-power-rt9756 | 30 +
.../ABI/testing/sysfs-class-power-surface | 15 +
.../ABI/testing/sysfs-class-power-twl4030 | 33 +
Documentation/ABI/testing/sysfs-class-power-wilco | 40 +
Documentation/ABI/testing/sysfs-class-powercap | 152 +
Documentation/ABI/testing/sysfs-class-pwm | 88 +
Documentation/ABI/testing/sysfs-class-rapidio | 59 +
Documentation/ABI/testing/sysfs-class-rc | 137 +
Documentation/ABI/testing/sysfs-class-rc-nuvoton | 15 +
.../testing/sysfs-class-reboot-mode-reboot_modes | 39 +
Documentation/ABI/testing/sysfs-class-regulator | 453 +
Documentation/ABI/testing/sysfs-class-remoteproc | 104 +
Documentation/ABI/testing/sysfs-class-rnbd-client | 133 +
Documentation/ABI/testing/sysfs-class-rnbd-server | 58 +
Documentation/ABI/testing/sysfs-class-rtc | 91 +
.../sysfs-class-rtc-rtc0-device-rtc_calibration | 14 +
Documentation/ABI/testing/sysfs-class-rtrs-client | 146 +
Documentation/ABI/testing/sysfs-class-rtrs-server | 53 +
Documentation/ABI/testing/sysfs-class-scsi_host | 119 +
Documentation/ABI/testing/sysfs-class-scsi_tape | 109 +
Documentation/ABI/testing/sysfs-class-spi-eeprom | 30 +
Documentation/ABI/testing/sysfs-class-spi-master | 34 +
Documentation/ABI/testing/sysfs-class-stm | 24 +
Documentation/ABI/testing/sysfs-class-stm_source | 11 +
Documentation/ABI/testing/sysfs-class-switchtec | 96 +
Documentation/ABI/testing/sysfs-class-tee | 25 +
Documentation/ABI/testing/sysfs-class-thermal | 259 +
Documentation/ABI/testing/sysfs-class-tsm | 9 +
Documentation/ABI/testing/sysfs-class-typec | 386 +
.../ABI/testing/sysfs-class-usb_power_delivery | 284 +
Documentation/ABI/testing/sysfs-class-usb_role | 27 +
Documentation/ABI/testing/sysfs-class-vduse | 33 +
Documentation/ABI/testing/sysfs-class-wakeup | 76 +
Documentation/ABI/testing/sysfs-class-watchdog | 129 +
Documentation/ABI/testing/sysfs-class-zram | 24 +
Documentation/ABI/testing/sysfs-dev | 21 +
Documentation/ABI/testing/sysfs-devices | 25 +
Documentation/ABI/testing/sysfs-devices-consumer | 9 +
Documentation/ABI/testing/sysfs-devices-coredump | 10 +
Documentation/ABI/testing/sysfs-devices-edac | 157 +
.../ABI/testing/sysfs-devices-faux-tdx-host | 26 +
.../ABI/testing/sysfs-devices-firmware_node | 17 +
Documentation/ABI/testing/sysfs-devices-lpss_ltr | 44 +
Documentation/ABI/testing/sysfs-devices-mapping | 62 +
Documentation/ABI/testing/sysfs-devices-memory | 120 +
Documentation/ABI/testing/sysfs-devices-mmc | 21 +
Documentation/ABI/testing/sysfs-devices-online | 20 +
.../ABI/testing/sysfs-devices-pci-host-bridge | 45 +
.../ABI/testing/sysfs-devices-physical_location | 42 +
.../ABI/testing/sysfs-devices-platform-ACPI-TAD | 117 +
.../testing/sysfs-devices-platform-_UDC_-gadget | 23 +
.../ABI/testing/sysfs-devices-platform-docg3 | 40 +
.../ABI/testing/sysfs-devices-platform-dock | 39 +
.../ABI/testing/sysfs-devices-platform-ipmi | 242 +
.../testing/sysfs-devices-platform-kunpeng_hccs | 126 +
.../sysfs-devices-platform-sh_mobile_lcdc_fb | 44 +
.../ABI/testing/sysfs-devices-platform-soc-ipa | 114 +
.../testing/sysfs-devices-platform-stratix10-rsu | 232 +
.../ABI/testing/sysfs-devices-platform-trackpoint | 115 +
Documentation/ABI/testing/sysfs-devices-power | 307 +
.../ABI/testing/sysfs-devices-power_resources_D0 | 13 +
.../ABI/testing/sysfs-devices-power_resources_D1 | 14 +
.../ABI/testing/sysfs-devices-power_resources_D2 | 14 +
.../testing/sysfs-devices-power_resources_D3hot | 14 +
.../testing/sysfs-devices-power_resources_wakeup | 13 +
.../ABI/testing/sysfs-devices-power_state | 20 +
.../ABI/testing/sysfs-devices-real_power_state | 23 +
Documentation/ABI/testing/sysfs-devices-removable | 20 +
.../ABI/testing/sysfs-devices-resource_in_use | 12 +
Documentation/ABI/testing/sysfs-devices-soc | 95 +
.../ABI/testing/sysfs-devices-software_node | 10 +
.../ABI/testing/sysfs-devices-state_synced | 29 +
Documentation/ABI/testing/sysfs-devices-sun | 14 +
Documentation/ABI/testing/sysfs-devices-supplier | 9 +
Documentation/ABI/testing/sysfs-devices-system-cpu | 808 +
.../ABI/testing/sysfs-devices-system-ibm-rtl | 24 +
.../ABI/testing/sysfs-devices-system-xen_cpu | 20 +
Documentation/ABI/testing/sysfs-devices-vfio-dev | 8 +
.../testing/sysfs-devices-virtual-misc-tdx_guest | 63 +
.../ABI/testing/sysfs-devices-waiting_for_supplier | 17 +
Documentation/ABI/testing/sysfs-devices-xenbus | 41 +
Documentation/ABI/testing/sysfs-driver-altera-cvp | 8 +
Documentation/ABI/testing/sysfs-driver-amd-sfh | 13 +
.../ABI/testing/sysfs-driver-aspeed-uart-routing | 27 +
.../ABI/testing/sysfs-driver-bd9571mwv-regulator | 31 +
Documentation/ABI/testing/sysfs-driver-ccp | 120 +
.../ABI/testing/sysfs-driver-chromeos-acpi | 152 +
.../ABI/testing/sysfs-driver-dell-dw5826e-reset | 9 +
Documentation/ABI/testing/sysfs-driver-eud | 9 +
.../ABI/testing/sysfs-driver-framer-pef2256 | 8 +
.../ABI/testing/sysfs-driver-fsi-master-gpio | 10 +
Documentation/ABI/testing/sysfs-driver-ge-achc | 15 +
Documentation/ABI/testing/sysfs-driver-genwqe | 78 +
Documentation/ABI/testing/sysfs-driver-habanalabs | 265 +
Documentation/ABI/testing/sysfs-driver-hid | 20 +
.../ABI/testing/sysfs-driver-hid-appletb-kbd | 13 +
Documentation/ABI/testing/sysfs-driver-hid-corsair | 15 +
.../ABI/testing/sysfs-driver-hid-corsair-void | 38 +
Documentation/ABI/testing/sysfs-driver-hid-lenovo | 60 +
.../ABI/testing/sysfs-driver-hid-lenovo-go | 724 +
.../ABI/testing/sysfs-driver-hid-lenovo-go-s | 304 +
.../ABI/testing/sysfs-driver-hid-logitech-hidpp | 19 +
.../ABI/testing/sysfs-driver-hid-logitech-lg4ff | 75 +
.../ABI/testing/sysfs-driver-hid-multitouch | 9 +
Documentation/ABI/testing/sysfs-driver-hid-ntrig | 73 +
Documentation/ABI/testing/sysfs-driver-hid-picolcd | 43 +
.../ABI/testing/sysfs-driver-hid-prodikeys | 29 +
.../ABI/testing/sysfs-driver-hid-roccat-kone | 125 +
Documentation/ABI/testing/sysfs-driver-hid-srws1 | 21 +
Documentation/ABI/testing/sysfs-driver-hid-wiimote | 85 +
.../ABI/testing/sysfs-driver-input-axp-pek | 11 +
.../ABI/testing/sysfs-driver-input-cros-ec-keyb | 6 +
.../ABI/testing/sysfs-driver-input-exc3000 | 26 +
Documentation/ABI/testing/sysfs-driver-intc_sar | 54 +
.../ABI/testing/sysfs-driver-intel-i915-hwmon | 93 +
.../ABI/testing/sysfs-driver-intel-m10-bmc | 36 +
.../testing/sysfs-driver-intel-m10-bmc-sec-update | 61 +
.../ABI/testing/sysfs-driver-intel-rapid-start | 21 +
.../ABI/testing/sysfs-driver-intel-xe-hwmon | 315 +
.../ABI/testing/sysfs-driver-intel-xe-ras | 30 +
.../ABI/testing/sysfs-driver-intel-xe-sriov | 190 +
Documentation/ABI/testing/sysfs-driver-intel_sdsi | 90 +
Documentation/ABI/testing/sysfs-driver-ivpu | 65 +
.../ABI/testing/sysfs-driver-jz4780-efuse | 20 +
.../ABI/testing/sysfs-driver-lenovo-yb9-kbdock | 19 +
.../ABI/testing/sysfs-driver-panfrost-profiling | 10 +
.../ABI/testing/sysfs-driver-panthor-profiling | 10 +
Documentation/ABI/testing/sysfs-driver-pciback | 28 +
Documentation/ABI/testing/sysfs-driver-ppi | 75 +
Documentation/ABI/testing/sysfs-driver-qaic | 18 +
Documentation/ABI/testing/sysfs-driver-qat | 167 +
Documentation/ABI/testing/sysfs-driver-qat_kpt | 97 +
Documentation/ABI/testing/sysfs-driver-qat_ras | 41 +
Documentation/ABI/testing/sysfs-driver-qat_rl | 226 +
Documentation/ABI/testing/sysfs-driver-qat_svn | 114 +
.../ABI/testing/sysfs-driver-samsung-laptop | 37 +
Documentation/ABI/testing/sysfs-driver-spi-intel | 20 +
Documentation/ABI/testing/sysfs-driver-st | 12 +
Documentation/ABI/testing/sysfs-driver-tegra-fuse | 11 +
.../ABI/testing/sysfs-driver-toshiba_acpi | 223 +
.../ABI/testing/sysfs-driver-toshiba_haps | 22 +
.../ABI/testing/sysfs-driver-typec-displayport | 74 +
Documentation/ABI/testing/sysfs-driver-uacce | 57 +
Documentation/ABI/testing/sysfs-driver-ucsi-ccg | 6 +
Documentation/ABI/testing/sysfs-driver-ufs | 1793 +
.../ABI/testing/sysfs-driver-uio_pci_sva-pasid | 29 +
.../ABI/testing/sysfs-driver-uniwill-laptop | 105 +
Documentation/ABI/testing/sysfs-driver-w1_ds28e17 | 24 +
Documentation/ABI/testing/sysfs-driver-w1_therm | 190 +
Documentation/ABI/testing/sysfs-driver-wacom | 105 +
Documentation/ABI/testing/sysfs-driver-xdata | 49 +
Documentation/ABI/testing/sysfs-driver-xen-blkback | 46 +
.../ABI/testing/sysfs-driver-xen-blkfront | 19 +
.../ABI/testing/sysfs-driver-xilinx-tmr-manager | 16 +
Documentation/ABI/testing/sysfs-driver-zynqmp-fpga | 73 +
Documentation/ABI/testing/sysfs-edac-ecs | 74 +
Documentation/ABI/testing/sysfs-edac-memory-repair | 206 +
Documentation/ABI/testing/sysfs-edac-scrub | 85 +
Documentation/ABI/testing/sysfs-firmware-acpi | 277 +
.../ABI/testing/sysfs-firmware-dmi-entries | 114 +
.../ABI/testing/sysfs-firmware-dmi-tables | 22 +
Documentation/ABI/testing/sysfs-firmware-efi | 45 +
Documentation/ABI/testing/sysfs-firmware-efi-esrt | 87 +
.../ABI/testing/sysfs-firmware-efi-runtime-map | 36 +
Documentation/ABI/testing/sysfs-firmware-gsmi | 58 +
Documentation/ABI/testing/sysfs-firmware-initrd | 8 +
.../ABI/testing/sysfs-firmware-lefi-boardinfo | 35 +
Documentation/ABI/testing/sysfs-firmware-log | 7 +
Documentation/ABI/testing/sysfs-firmware-memmap | 75 +
Documentation/ABI/testing/sysfs-firmware-ofw | 52 +
.../ABI/testing/sysfs-firmware-opal-powercap | 31 +
Documentation/ABI/testing/sysfs-firmware-opal-psr | 18 +
.../ABI/testing/sysfs-firmware-opal-sensor-groups | 21 +
.../testing/sysfs-firmware-papr-energy-scale-info | 29 +
Documentation/ABI/testing/sysfs-firmware-plpks | 58 +
.../ABI/testing/sysfs-firmware-qemu_fw_cfg | 103 +
.../ABI/testing/sysfs-firmware-sev-vulnerabilities | 19 +
Documentation/ABI/testing/sysfs-firmware-sgi_uv | 159 +
.../ABI/testing/sysfs-firmware-turris-mox-rwtm | 28 +
Documentation/ABI/testing/sysfs-fs-erofs | 49 +
Documentation/ABI/testing/sysfs-fs-ext4 | 118 +
Documentation/ABI/testing/sysfs-fs-f2fs | 1022 +
Documentation/ABI/testing/sysfs-fs-nilfs2 | 269 +
Documentation/ABI/testing/sysfs-fs-ubifs | 35 +
Documentation/ABI/testing/sysfs-fs-virtiofs | 11 +
Documentation/ABI/testing/sysfs-fs-xfs | 37 +
Documentation/ABI/testing/sysfs-hypervisor-xen | 46 +
Documentation/ABI/testing/sysfs-ibft | 33 +
.../ABI/testing/sysfs-kernel-address_bits | 10 +
Documentation/ABI/testing/sysfs-kernel-boot_params | 39 +
Documentation/ABI/testing/sysfs-kernel-btf | 25 +
.../ABI/testing/sysfs-kernel-cpu_byteorder | 12 +
Documentation/ABI/testing/sysfs-kernel-fadump | 59 +
Documentation/ABI/testing/sysfs-kernel-fscaps | 8 +
.../ABI/testing/sysfs-kernel-hardlockup_count | 7 +
.../ABI/testing/sysfs-kernel-iommu_groups | 64 +
Documentation/ABI/testing/sysfs-kernel-irq | 60 +
Documentation/ABI/testing/sysfs-kernel-kexec-kdump | 61 +
Documentation/ABI/testing/sysfs-kernel-livepatch | 95 +
Documentation/ABI/testing/sysfs-kernel-mm | 6 +
Documentation/ABI/testing/sysfs-kernel-mm-cma | 44 +
Documentation/ABI/testing/sysfs-kernel-mm-damon | 664 +
.../ABI/testing/sysfs-kernel-mm-hugepages | 17 +
Documentation/ABI/testing/sysfs-kernel-mm-ksm | 61 +
.../ABI/testing/sysfs-kernel-mm-memory-tiers | 25 +
.../ABI/testing/sysfs-kernel-mm-mempolicy | 4 +
.../sysfs-kernel-mm-mempolicy-weighted-interleave | 54 +
Documentation/ABI/testing/sysfs-kernel-mm-numa | 28 +
Documentation/ABI/testing/sysfs-kernel-mm-swap | 16 +
.../testing/sysfs-kernel-mm-transparent-hugepage | 18 +
Documentation/ABI/testing/sysfs-kernel-oops_count | 6 +
.../ABI/testing/sysfs-kernel-rcu_stall_count | 6 +
Documentation/ABI/testing/sysfs-kernel-reboot | 40 +
Documentation/ABI/testing/sysfs-kernel-slab | 526 +
.../ABI/testing/sysfs-kernel-softlockup_count | 7 +
Documentation/ABI/testing/sysfs-kernel-vmcoreinfo | 14 +
Documentation/ABI/testing/sysfs-kernel-warn_count | 6 +
Documentation/ABI/testing/sysfs-mce | 97 +
.../ABI/testing/sysfs-memory-page-offline | 44 +
Documentation/ABI/testing/sysfs-module | 84 +
Documentation/ABI/testing/sysfs-nvmem-cells | 21 +
Documentation/ABI/testing/sysfs-ocfs2 | 89 +
.../ABI/testing/sysfs-platform-alienware-wmi | 14 +
.../ABI/testing/sysfs-platform-asus-laptop | 71 +
Documentation/ABI/testing/sysfs-platform-asus-wmi | 240 +
Documentation/ABI/testing/sysfs-platform-at91 | 27 +
Documentation/ABI/testing/sysfs-platform-ayaneo-ec | 19 +
.../ABI/testing/sysfs-platform-brcmstb-gisb-arb | 8 +
.../ABI/testing/sysfs-platform-brcmstb-memc | 15 +
.../ABI/testing/sysfs-platform-chipidea-usb-otg | 56 +
.../ABI/testing/sysfs-platform-chipidea-usb2 | 9 +
.../ABI/testing/sysfs-platform-dell-laptop | 73 +
.../ABI/testing/sysfs-platform-dell-privacy-wmi | 71 +
.../ABI/testing/sysfs-platform-dell-smbios | 21 +
.../ABI/testing/sysfs-platform-dell-wmi-ddv | 9 +
Documentation/ABI/testing/sysfs-platform-dfl-fme | 246 +
Documentation/ABI/testing/sysfs-platform-dfl-port | 101 +
Documentation/ABI/testing/sysfs-platform-dptf | 157 +
.../ABI/testing/sysfs-platform-eeepc-laptop | 56 +
Documentation/ABI/testing/sysfs-platform-hidma | 9 +
.../ABI/testing/sysfs-platform-hidma-mgmt | 97 +
.../ABI/testing/sysfs-platform-i2c-demux-pinctrl | 18 +
.../ABI/testing/sysfs-platform-ideapad-laptop | 52 +
Documentation/ABI/testing/sysfs-platform-intel-ifs | 52 +
Documentation/ABI/testing/sysfs-platform-intel-pmc | 22 +
.../testing/sysfs-platform-intel-wmi-sbl-fw-update | 13 +
.../testing/sysfs-platform-intel-wmi-thunderbolt | 12 +
Documentation/ABI/testing/sysfs-platform-kim | 49 +
Documentation/ABI/testing/sysfs-platform-lg-laptop | 36 +
.../ABI/testing/sysfs-platform-mellanox-bootctl | 162 +
.../ABI/testing/sysfs-platform-mellanox-pmc | 64 +
.../ABI/testing/sysfs-platform-msi-laptop | 83 +
Documentation/ABI/testing/sysfs-platform-oxp | 25 +
.../ABI/testing/sysfs-platform-phy-rcar-gen3-usb2 | 17 +
.../ABI/testing/sysfs-platform-power-on-reason | 12 +
.../ABI/testing/sysfs-platform-renesas_usb3 | 17 +
Documentation/ABI/testing/sysfs-platform-silicom | 30 +
Documentation/ABI/testing/sysfs-platform-sst-atom | 26 +
Documentation/ABI/testing/sysfs-platform-tahvo-usb | 16 +
Documentation/ABI/testing/sysfs-platform-ts5500 | 54 +
.../ABI/testing/sysfs-platform-twl4030-usb | 8 +
.../ABI/testing/sysfs-platform-usbip-vudc | 38 +
Documentation/ABI/testing/sysfs-platform-wilco-ec | 58 +
Documentation/ABI/testing/sysfs-platform_profile | 40 +
Documentation/ABI/testing/sysfs-power | 472 +
Documentation/ABI/testing/sysfs-pps | 73 +
Documentation/ABI/testing/sysfs-pps-gen | 43 +
Documentation/ABI/testing/sysfs-pps-gen-tio | 6 +
Documentation/ABI/testing/sysfs-profiling | 13 +
Documentation/ABI/testing/sysfs-ptp | 142 +
Documentation/ABI/testing/sysfs-secvar | 65 +
Documentation/ABI/testing/sysfs-timecard | 293 +
Documentation/ABI/testing/sysfs-tty | 166 +
Documentation/ABI/testing/sysfs-uevent | 51 +
Documentation/ABI/testing/usb-charger-uevent | 54 +
Documentation/ABI/testing/usb-uevent | 27 +
Documentation/Changes | 1 +
Documentation/CodingStyle | 1 +
Documentation/Kconfig | 28 +
Documentation/Makefile | 115 +
Documentation/PCI/acpi-info.rst | 192 +
Documentation/PCI/boot-interrupts.rst | 159 +
Documentation/PCI/controller/index.rst | 11 +
.../PCI/controller/pci-controller-drivers.rst | 402 +
.../PCI/controller/rcar-pcie-firmware.rst | 32 +
.../PCI/endpoint/function/binding/pci-ntb.rst | 38 +
.../PCI/endpoint/function/binding/pci-test.rst | 26 +
Documentation/PCI/endpoint/index.rst | 21 +
Documentation/PCI/endpoint/pci-endpoint-cfs.rst | 138 +
Documentation/PCI/endpoint/pci-endpoint.rst | 283 +
Documentation/PCI/endpoint/pci-ntb-function.rst | 348 +
Documentation/PCI/endpoint/pci-ntb-howto.rst | 158 +
Documentation/PCI/endpoint/pci-nvme-function.rst | 13 +
Documentation/PCI/endpoint/pci-test-function.rst | 103 +
Documentation/PCI/endpoint/pci-test-howto.rst | 239 +
Documentation/PCI/endpoint/pci-vntb-function.rst | 129 +
Documentation/PCI/endpoint/pci-vntb-howto.rst | 169 +
Documentation/PCI/index.rst | 22 +
Documentation/PCI/msi-howto.rst | 300 +
Documentation/PCI/pci-error-recovery.rst | 471 +
Documentation/PCI/pci-iov-howto.rst | 171 +
Documentation/PCI/pci.rst | 578 +
Documentation/PCI/pcieaer-howto.rst | 267 +
Documentation/PCI/pciebus-howto.rst | 228 +
Documentation/PCI/sysfs-pci.rst | 138 +
Documentation/PCI/tph.rst | 132 +
.../Design/Data-Structures/BigTreeClassicRCU.svg | 474 +
.../BigTreePreemptRCUBHdyntickCB.svg | 662 +
.../RCU/Design/Data-Structures/Data-Structures.rst | 1196 +
.../Design/Data-Structures/HugeTreeClassicRCU.svg | 939 +
.../RCU/Design/Data-Structures/TreeLevel.svg | 828 +
.../RCU/Design/Data-Structures/TreeMapping.svg | 305 +
.../Design/Data-Structures/TreeMappingLevel.svg | 380 +
.../RCU/Design/Data-Structures/blkd_task.svg | 631 +
.../RCU/Design/Data-Structures/nxtlist.svg | 386 +
.../Design/Expedited-Grace-Periods/ExpRCUFlow.svg | 830 +
.../Expedited-Grace-Periods/ExpSchedFlow.svg | 830 +
.../Expedited-Grace-Periods.rst | 521 +
.../RCU/Design/Expedited-Grace-Periods/Funnel0.svg | 275 +
.../RCU/Design/Expedited-Grace-Periods/Funnel1.svg | 275 +
.../RCU/Design/Expedited-Grace-Periods/Funnel2.svg | 287 +
.../RCU/Design/Expedited-Grace-Periods/Funnel3.svg | 323 +
.../RCU/Design/Expedited-Grace-Periods/Funnel4.svg | 323 +
.../RCU/Design/Expedited-Grace-Periods/Funnel5.svg | 335 +
.../RCU/Design/Expedited-Grace-Periods/Funnel6.svg | 335 +
.../RCU/Design/Expedited-Grace-Periods/Funnel7.svg | 347 +
.../RCU/Design/Expedited-Grace-Periods/Funnel8.svg | 311 +
.../Memory-Ordering/Tree-RCU-Memory-Ordering.rst | 648 +
.../TreeRCU-callback-invocation.svg | 486 +
.../Memory-Ordering/TreeRCU-callback-registry.svg | 646 +
.../RCU/Design/Memory-Ordering/TreeRCU-dyntick.svg | 700 +
.../Design/Memory-Ordering/TreeRCU-gp-cleanup.svg | 1133 +
.../RCU/Design/Memory-Ordering/TreeRCU-gp-fqs.svg | 1309 +
.../Design/Memory-Ordering/TreeRCU-gp-init-1.svg | 658 +
.../Design/Memory-Ordering/TreeRCU-gp-init-2.svg | 656 +
.../Design/Memory-Ordering/TreeRCU-gp-init-3.svg | 636 +
.../RCU/Design/Memory-Ordering/TreeRCU-gp.svg | 5135 +
.../RCU/Design/Memory-Ordering/TreeRCU-hotplug.svg | 775 +
.../RCU/Design/Memory-Ordering/TreeRCU-qs.svg | 1095 +
.../RCU/Design/Memory-Ordering/rcu_node-lock.svg | 229 +
.../Design/Requirements/GPpartitionReaders1.svg | 374 +
.../Design/Requirements/ReadersPartitionGP1.svg | 639 +
.../RCU/Design/Requirements/Requirements.rst | 2873 +
Documentation/RCU/NMI-RCU.rst | 123 +
Documentation/RCU/RTFP.txt | 2812 +
Documentation/RCU/UP.rst | 152 +
Documentation/RCU/checklist.rst | 556 +
Documentation/RCU/index.rst | 30 +
Documentation/RCU/listRCU.rst | 511 +
Documentation/RCU/lockdep-splat.rst | 115 +
Documentation/RCU/lockdep.rst | 119 +
Documentation/RCU/rcu.rst | 93 +
Documentation/RCU/rcu_dereference.rst | 502 +
Documentation/RCU/rcubarrier.rst | 377 +
Documentation/RCU/rculist_nulls.rst | 215 +
Documentation/RCU/rcuref.rst | 158 +
Documentation/RCU/stallwarn.rst | 491 +
Documentation/RCU/torture.rst | 374 +
Documentation/RCU/whatisRCU.rst | 1415 +
Documentation/SubmittingPatches | 1 +
Documentation/accel/amdxdna/amdnpu.rst | 306 +
Documentation/accel/amdxdna/index.rst | 11 +
Documentation/accel/index.rst | 13 +
Documentation/accel/introduction.rst | 110 +
Documentation/accel/qaic/aic080.rst | 14 +
Documentation/accel/qaic/aic100.rst | 538 +
Documentation/accel/qaic/index.rst | 14 +
Documentation/accel/qaic/qaic.rst | 209 +
Documentation/accel/rocket/index.rst | 19 +
Documentation/accounting/cgroupstats.rst | 31 +
Documentation/accounting/delay-accounting.rst | 214 +
Documentation/accounting/index.rst | 14 +
Documentation/accounting/psi.rst | 188 +
Documentation/accounting/taskstats-struct.rst | 199 +
Documentation/accounting/taskstats.rst | 182 +
Documentation/admin-guide/LSM/LoadPin.rst | 31 +
Documentation/admin-guide/LSM/SELinux.rst | 44 +
Documentation/admin-guide/LSM/SafeSetID.rst | 118 +
Documentation/admin-guide/LSM/Smack.rst | 871 +
Documentation/admin-guide/LSM/Yama.rst | 75 +
Documentation/admin-guide/LSM/apparmor.rst | 54 +
Documentation/admin-guide/LSM/index.rst | 51 +
Documentation/admin-guide/LSM/ipe.rst | 835 +
Documentation/admin-guide/LSM/landlock.rst | 298 +
Documentation/admin-guide/LSM/tomoyo.rst | 52 +
.../admin-guide/RAS/address-translation.rst | 24 +
Documentation/admin-guide/RAS/error-decoding.rst | 21 +
Documentation/admin-guide/RAS/index.rst | 7 +
Documentation/admin-guide/RAS/main.rst | 1087 +
Documentation/admin-guide/README.rst | 360 +
Documentation/admin-guide/abi-obsolete-files.rst | 7 +
Documentation/admin-guide/abi-obsolete.rst | 13 +
Documentation/admin-guide/abi-removed-files.rst | 7 +
Documentation/admin-guide/abi-removed.rst | 7 +
Documentation/admin-guide/abi-stable-files.rst | 7 +
Documentation/admin-guide/abi-stable.rst | 16 +
Documentation/admin-guide/abi-testing-files.rst | 7 +
Documentation/admin-guide/abi-testing.rst | 22 +
Documentation/admin-guide/abi.rst | 29 +
Documentation/admin-guide/acpi/cppc_sysfs.rst | 78 +
.../admin-guide/acpi/fan_performance_states.rst | 90 +
Documentation/admin-guide/acpi/index.rst | 14 +
.../admin-guide/acpi/initrd_table_override.rst | 115 +
Documentation/admin-guide/acpi/ssdt-overlays.rst | 181 +
Documentation/admin-guide/aoe/aoe.rst | 150 +
Documentation/admin-guide/aoe/autoload.sh | 17 +
Documentation/admin-guide/aoe/examples.rst | 23 +
Documentation/admin-guide/aoe/index.rst | 10 +
Documentation/admin-guide/aoe/status.sh | 30 +
Documentation/admin-guide/aoe/todo.rst | 17 +
Documentation/admin-guide/aoe/udev-install.sh | 33 +
Documentation/admin-guide/aoe/udev.txt | 26 +
.../admin-guide/auxdisplay/cfag12864b.rst | 98 +
Documentation/admin-guide/auxdisplay/index.rst | 9 +
Documentation/admin-guide/auxdisplay/ks0108.rst | 50 +
Documentation/admin-guide/bcache.rst | 644 +
Documentation/admin-guide/binderfs.rst | 87 +
Documentation/admin-guide/binfmt-misc.rst | 391 +
.../blockdev/drbd/DRBD-8.3-data-packets.svg | 588 +
.../blockdev/drbd/DRBD-data-packets.svg | 459 +
.../admin-guide/blockdev/drbd/conn-states-8.dot | 18 +
.../blockdev/drbd/data-structure-v9.rst | 42 +
.../admin-guide/blockdev/drbd/disk-states-8.dot | 16 +
.../drbd/drbd-connection-state-overview.dot | 85 +
.../admin-guide/blockdev/drbd/figures.rst | 30 +
Documentation/admin-guide/blockdev/drbd/index.rst | 19 +
.../admin-guide/blockdev/drbd/peer-states-8.dot | 8 +
Documentation/admin-guide/blockdev/floppy.rst | 255 +
Documentation/admin-guide/blockdev/index.rst | 17 +
Documentation/admin-guide/blockdev/nbd.rst | 31 +
Documentation/admin-guide/blockdev/paride.rst | 207 +
Documentation/admin-guide/blockdev/ramdisk.rst | 153 +
Documentation/admin-guide/blockdev/zoned_loop.rst | 191 +
Documentation/admin-guide/blockdev/zram.rst | 610 +
Documentation/admin-guide/bootconfig.rst | 416 +
Documentation/admin-guide/braille-console.rst | 38 +
Documentation/admin-guide/btmrvl.rst | 124 +
Documentation/admin-guide/bug-bisect.rst | 165 +
Documentation/admin-guide/bug-hunting.rst | 370 +
.../admin-guide/cgroup-v1/blkio-controller.rst | 301 +
Documentation/admin-guide/cgroup-v1/cgroups.rst | 697 +
Documentation/admin-guide/cgroup-v1/cpuacct.rst | 50 +
Documentation/admin-guide/cgroup-v1/cpusets.rst | 874 +
Documentation/admin-guide/cgroup-v1/devices.rst | 132 +
.../admin-guide/cgroup-v1/freezer-subsystem.rst | 131 +
Documentation/admin-guide/cgroup-v1/hugetlb.rst | 139 +
Documentation/admin-guide/cgroup-v1/index.rst | 24 +
Documentation/admin-guide/cgroup-v1/memcg_test.rst | 342 +
Documentation/admin-guide/cgroup-v1/memory.rst | 926 +
Documentation/admin-guide/cgroup-v1/misc.rst | 4 +
Documentation/admin-guide/cgroup-v1/net_cls.rst | 44 +
Documentation/admin-guide/cgroup-v1/net_prio.rst | 57 +
Documentation/admin-guide/cgroup-v1/pids.rst | 93 +
Documentation/admin-guide/cgroup-v1/rdma.rst | 191 +
Documentation/admin-guide/cgroup-v2.rst | 3581 +
Documentation/admin-guide/cifs/authors.rst | 69 +
Documentation/admin-guide/cifs/changes.rst | 9 +
Documentation/admin-guide/cifs/index.rst | 14 +
Documentation/admin-guide/cifs/introduction.rst | 53 +
Documentation/admin-guide/cifs/todo.rst | 133 +
Documentation/admin-guide/cifs/usage.rst | 864 +
Documentation/admin-guide/cifs/winucase_convert.pl | 62 +
Documentation/admin-guide/clearing-warn-once.rst | 9 +
Documentation/admin-guide/cpu-isolation.rst | 357 +
Documentation/admin-guide/cpu-load.rst | 117 +
Documentation/admin-guide/cputopology.rst | 101 +
Documentation/admin-guide/dell_rbu.rst | 128 +
.../admin-guide/device-mapper/cache-policies.rst | 131 +
Documentation/admin-guide/device-mapper/cache.rst | 337 +
Documentation/admin-guide/device-mapper/delay.rst | 54 +
.../admin-guide/device-mapper/dm-clone.rst | 333 +
.../admin-guide/device-mapper/dm-crypt.rst | 212 +
.../admin-guide/device-mapper/dm-dust.rst | 305 +
Documentation/admin-guide/device-mapper/dm-ebs.rst | 51 +
.../admin-guide/device-mapper/dm-flakey.rst | 88 +
Documentation/admin-guide/device-mapper/dm-ima.rst | 718 +
.../admin-guide/device-mapper/dm-init.rst | 133 +
.../admin-guide/device-mapper/dm-inlinecrypt.rst | 129 +
.../admin-guide/device-mapper/dm-integrity.rst | 321 +
Documentation/admin-guide/device-mapper/dm-io.rst | 75 +
Documentation/admin-guide/device-mapper/dm-log.rst | 57 +
.../admin-guide/device-mapper/dm-pcache.rst | 202 +
.../admin-guide/device-mapper/dm-queue-length.rst | 48 +
.../admin-guide/device-mapper/dm-raid.rst | 489 +
.../admin-guide/device-mapper/dm-service-time.rst | 101 +
.../admin-guide/device-mapper/dm-uevent.rst | 110 +
.../admin-guide/device-mapper/dm-zoned.rst | 194 +
Documentation/admin-guide/device-mapper/era.rst | 116 +
Documentation/admin-guide/device-mapper/index.rst | 43 +
Documentation/admin-guide/device-mapper/kcopyd.rst | 47 +
Documentation/admin-guide/device-mapper/linear.rst | 63 +
.../admin-guide/device-mapper/log-writes.rst | 145 +
.../admin-guide/device-mapper/persistent-data.rst | 88 +
.../admin-guide/device-mapper/snapshot.rst | 196 +
.../admin-guide/device-mapper/statistics.rst | 225 +
.../admin-guide/device-mapper/striped.rst | 61 +
Documentation/admin-guide/device-mapper/switch.rst | 141 +
.../device-mapper/thin-provisioning.rst | 427 +
.../admin-guide/device-mapper/unstriped.rst | 135 +
.../admin-guide/device-mapper/vdo-design.rst | 633 +
Documentation/admin-guide/device-mapper/vdo.rst | 413 +
Documentation/admin-guide/device-mapper/verity.rst | 349 +
.../admin-guide/device-mapper/writecache.rst | 114 +
Documentation/admin-guide/device-mapper/zero.rst | 37 +
Documentation/admin-guide/devices.rst | 270 +
Documentation/admin-guide/devices.txt | 3081 +
Documentation/admin-guide/dynamic-debug-howto.rst | 392 +
Documentation/admin-guide/edid.rst | 27 +
Documentation/admin-guide/efi-stub.rst | 103 +
Documentation/admin-guide/ext4.rst | 611 +
Documentation/admin-guide/features.rst | 3 +
.../admin-guide/filesystem-monitoring.rst | 78 +
Documentation/admin-guide/gpio/gpio-aggregator.rst | 218 +
Documentation/admin-guide/gpio/gpio-mockup.rst | 59 +
Documentation/admin-guide/gpio/gpio-sim.rst | 137 +
Documentation/admin-guide/gpio/gpio-virtuser.rst | 177 +
Documentation/admin-guide/gpio/index.rst | 14 +
Documentation/admin-guide/gpio/obsolete.rst | 13 +
.../admin-guide/hw-vuln/attack_vector_controls.rst | 236 +
.../admin-guide/hw-vuln/core-scheduling.rst | 226 +
.../admin-guide/hw-vuln/cross-thread-rsb.rst | 91 +
.../admin-guide/hw-vuln/gather_data_sampling.rst | 109 +
Documentation/admin-guide/hw-vuln/index.rst | 29 +
.../hw-vuln/indirect-target-selection.rst | 168 +
Documentation/admin-guide/hw-vuln/l1d_flush.rst | 69 +
Documentation/admin-guide/hw-vuln/l1tf.rst | 615 +
Documentation/admin-guide/hw-vuln/mds.rst | 303 +
Documentation/admin-guide/hw-vuln/multihit.rst | 167 +
.../admin-guide/hw-vuln/old_microcode.rst | 21 +
.../hw-vuln/processor_mmio_stale_data.rst | 269 +
.../admin-guide/hw-vuln/reg-file-data-sampling.rst | 96 +
Documentation/admin-guide/hw-vuln/rsb.rst | 268 +
.../special-register-buffer-data-sampling.rst | 150 +
Documentation/admin-guide/hw-vuln/spectre.rst | 725 +
Documentation/admin-guide/hw-vuln/srso.rst | 242 +
.../admin-guide/hw-vuln/tsx_async_abort.rst | 270 +
Documentation/admin-guide/hw-vuln/vmscape.rst | 110 +
Documentation/admin-guide/hw_random.rst | 104 +
Documentation/admin-guide/index.rst | 192 +
Documentation/admin-guide/init.rst | 48 +
Documentation/admin-guide/initrd.rst | 383 +
Documentation/admin-guide/iostats.rst | 187 +
Documentation/admin-guide/java.rst | 423 +
Documentation/admin-guide/jfs.rst | 66 +
Documentation/admin-guide/kdump/gdbmacros.txt | 323 +
Documentation/admin-guide/kdump/index.rst | 13 +
Documentation/admin-guide/kdump/kdump.rst | 612 +
Documentation/admin-guide/kdump/vmcoreinfo.rst | 596 +
Documentation/admin-guide/kernel-parameters.rst | 135 +
Documentation/admin-guide/kernel-parameters.txt | 8709 +
.../admin-guide/kernel-per-CPU-kthreads.rst | 325 +
.../admin-guide/laptops/alienware-wmi.rst | 127 +
Documentation/admin-guide/laptops/asus-laptop.rst | 271 +
.../admin-guide/laptops/disk-shock-protection.rst | 151 +
Documentation/admin-guide/laptops/index.rst | 19 +
Documentation/admin-guide/laptops/lg-laptop.rst | 82 +
.../admin-guide/laptops/samsung-galaxybook.rst | 174 +
Documentation/admin-guide/laptops/sony-laptop.rst | 174 +
[Output truncated: showing 1000 of 96042 lines]]
|
| 347/4 |
2026/09/17 11:34 |
llm |
codeexpert |
0m
Model:
Tokens:
input: 44077
output: 25
thoughts: 524
Thoughts: **Analyzing the Truncate Order Question**
Okay, here's the deal. I've got this checkout, and `git log` only shows one commit, fd73f4a66598. So, I need to dive into the kernel sources using codesearch and grepper.
Now, let's break down this question. I need to make sure I'm getting the core concept. The question is centered around whether `truncate_setsize` should be called before `ntfs_set_size` when we're shrinking a file (`newsize < oldsize`). The crux of it is this: if `ntfs_set_size` deallocates blocks *before* page cache handling, we could have a nasty data corruption scenario.
Let me think this through methodically:
1. **The Core Question:** Should `truncate_setsize` be called *before* the filesystem does its block deallocation (the `ntfs_set_size` bit)?
2. **The Reasoning:** If `ntfs_set_size` runs first, it'll deallocate disk blocks. Then, what happens with dirty pages that are *beyond* the new end-of-file (EOF)?
The risk, as I understand it, is that those dirty pages, being written back to disk from the page cache (either through background writeback, direct reclaim, or a sync), could end up writing to blocks that have already been deallocated. Those blocks might even be reallocated to a *different* file. Bang! Data corruption! This is a classic write-after-free issue, but with file data.
So, is the reasoning correct? Yes, it is!
Specifically:
* Shrinking a file (`newsize < oldsize`) means we need to deallocate blocks.
* Before deallocating, we need to handle the page cache.
* `truncate_setsize` updates `i_size` and truncates the page cache (using `truncate_pagecache(inode, newsize)`), which in turn unmaps pages.
* If we deallocate blocks before that page cache truncation, dirty pages could be written back to those freed blocks, now potentially belonging to another file. This could corrupt data.
* Therefore, the page cache has to be truncated first, to ensure no writes happen to the blocks *after* they've been deallocated.
Okay, this feels solid. However, just to be absolutely sure, I'm going to consult the documentation. I need to check `Documentation/filesystems/`, `Documentation/`, or the VFS documentation for `truncate`. Let me search for `truncate_setsize` or "block truncation" or "truncate order" to make sure there's not something I'm missing!
|
| 348/4 |
2026/09/17 11:35 |
tool |
grepper |
0m
Args: map[Expression:truncate_setsize PathPrefix:Documentation]
Results: map[Output:Documentation/filesystems/iomap/operations.rst=297=operation.
Documentation/filesystems/iomap/operations.rst:298:``truncate_setsize`` or ``truncate_pagecache`` will take care of
Documentation/filesystems/iomap/operations.rst-299-everything after the EOF block.
]
|
| 349/4 |
2026/09/17 11:35 |
llm |
codeexpert |
0m
Model:
Tokens:
input: 45319
output: 40
thoughts: 25
Thoughts: Here's my attempt at summarizing the thought process, tailored for an expert audience:
**Diving into iomap Operations**
Okay, so I need to refresh my memory on the specifics of the `iomap` implementation. Right, let's pull up that documentation file, specifically `Documentation/filesystems/iomap/operations.rst`. I recall it has a pretty good overview, and I think the section around line 297 is where the core `iomap` operations are discussed in detail. Time to get the details fresh in my head! Let's see what's what.
|
| 350/4 |
2026/09/17 11:35 |
tool |
read-file |
0m
Args: map[File:Documentation/filesystems/iomap/operations.rst FirstLine:285 LineCount:40]
Results: map[Contents: 285: storage with another file to preemptively copy the shared data to newly
286: allocate storage.
287: ``IOMAP_WRITE | IOMAP_UNSHARE`` will be passed as the ``flags`` argument
288: to ``->iomap_begin``.
289: Callers typically hold ``i_rwsem`` and ``invalidate_lock`` in exclusive
290: mode before calling this function.
291:
292: Truncation
293: ----------
294:
295: Filesystems can call ``iomap_truncate_page`` to zero the bytes in the
296: pagecache from EOF to the end of the fsblock during a file truncation
297: operation.
298: ``truncate_setsize`` or ``truncate_pagecache`` will take care of
299: everything after the EOF block.
300: ``IOMAP_ZERO`` will be passed as the ``flags`` argument to
301: ``->iomap_begin``.
302: Callers typically hold ``i_rwsem`` and ``invalidate_lock`` in exclusive
303: mode before calling this function.
304:
305: Pagecache Writeback
306: -------------------
307:
308: Filesystems can call ``iomap_writepages`` to respond to a request to
309: write dirty pagecache folios to disk.
310: The ``mapping`` and ``wbc`` parameters should be passed unchanged.
311: The ``wpc`` pointer should be allocated by the filesystem and must
312: be initialized to zero.
313:
314: The pagecache will lock each folio before trying to schedule it for
315: writeback.
316: It does not lock ``i_rwsem`` or ``invalidate_lock``.
317:
318: The dirty bit will be cleared for all folios run through the
319: ``->writeback_range`` machinery described below even if the writeback fails.
320: This is to prevent dirty folio clots when storage devices fail; an
321: ``-EIO`` is recorded for userspace to collect via ``fsync``.
322:
323: The ``ops`` structure must be specified and is as follows:
324:
]
|
| 351/4 |
2026/09/17 11:35 |
llm |
codeexpert |
0m
Model:
Tokens:
input: 46162
output: 28
thoughts: 306
Thoughts: **Analyzing `truncate_setsize` and Its Role in Filesystem Operations**
Okay, let's revisit that comment for `truncate_setsize`. It's crucial, especially since I'm trying to grok the interaction between the VFS and the filesystem's specific implementation. So, here's what I'm seeing:
This function, `truncate_setsize`, is specifically designed to handle the update of the inode's size and to manage pagecache truncation when a file's size is being modified to `newsize`. The comment makes it clear that this function is typically called from the filesystem's `setattr` function, specifically when `ATTR_SIZE` is involved.
The comment clearly indicates a critical constraint on its execution. Line 813 makes the point really clear: "and before all filesystem specific block truncation has been performed". This suggests a particular order of operations. The VFS level handling (i.e. `truncate_setsize` and friends) *must* happen before any filesystem-specific block truncation is done. This points to a layering where the VFS sets the stage for the filesystem to do its low-level stuff. It helps me understand where the responsibility for each aspect of this change is clearly divided, which is vital for any filesystem interaction.
Now, I really need to double-check the documentation β `Documentation/filesystems/vfs.rst` or any relevant VFS documentation. I'm going to look to understand the precise interaction between `truncate_setsize` and the overall `setattr` flow. I need to clarify what the VFS expects from the filesystem's `setattr` implementation in terms of pre- and post-conditions. It's a common area for subtle bugs and filesystem-specific deviations if not handled correctly.
|
| 352/4 |
2026/09/17 11:36 |
tool |
grepper |
0m
Args: map[Expression:truncate_setsize PathPrefix:Documentation/filesystems]
Results: map[Output:Documentation/filesystems/iomap/operations.rst=297=operation.
Documentation/filesystems/iomap/operations.rst:298:``truncate_setsize`` or ``truncate_pagecache`` will take care of
Documentation/filesystems/iomap/operations.rst-299-everything after the EOF block.
]
|
| 353/4 |
2026/09/17 11:36 |
llm |
codeexpert |
0m
Model:
Tokens:
input: 46964
output: 30
thoughts: 14
Thoughts: Here's my attempt at summarizing the thought process, tailored for an expert audience:
**Diving into the Filesystem Locking Documentation**
Okay, time to get to the heart of the matter. My initial thought is to dive straight into the documentation on filesystem locking, specifically the `Documentation/filesystems/locking.rst` file. It's usually the best place to start when I need to refresh my knowledge or troubleshoot lock-related issues within a filesystem context. I'm hoping to get a clear overview of the concepts and mechanisms described there. Perhaps itβll have the relevant sections on advisory versus mandatory locking, different locking implementations, or some nuanced aspects around interactions with various POSIX interfaces. I anticipate some detailed explanations of the locking primitives and synchronization techniques. Iβm especially keen to see if it covers any recent additions or changes in locking strategies with newer kernel releases, or if any common pitfalls or best practices are outlined. That document is usually pretty comprehensive, so I'm expecting a good foundation to work from. Let's see what gems are waiting there!
|
| 354/4 |
2026/09/17 11:36 |
tool |
grepper |
0m
Args: map[Expression:setattr PathPrefix:Documentation/filesystems/locking.rst]
Results: map[Output:Documentation/filesystems/locking.rst=62=prototypes::
--
Documentation/filesystems/locking.rst-78- struct posix_acl * (*get_inode_acl)(struct inode *, int, bool);
Documentation/filesystems/locking.rst:79: int (*setattr) (struct mnt_idmap *, struct dentry *, struct iattr *);
Documentation/filesystems/locking.rst-80- int (*getattr) (struct mnt_idmap *, const struct path *, struct kstat *, u32, unsigned int);
--
Documentation/filesystems/locking.rst=113=get_link: no
Documentation/filesystems/locking.rst:114:setattr: exclusive
Documentation/filesystems/locking.rst-115-permission: no (may not block if called in rcu-walk mode)
]
|
| 355/4 |
2026/09/17 11:36 |
llm |
codeexpert |
0m
Model:
Tokens:
input: 47440
output: 26
thoughts: 67
Thoughts: **Investigating Filesystem `truncate_setsize` Usage**
Alright, let's dive into this `truncate_setsize` function and see where it's actually making an appearance in the kernel's filesystem landscape. My initial hunch is that it's probably pretty fundamental, and thus, I anticipate it's utilized by quite a few filesystems. I'm thinking specifically about ext4, xfs, btrfs, f2fs, and those NTFS implementations β both the older and newer ones, like ntfs and ntfs3.
The quickest way to get a handle on this is to just run a quick `grep` operation. I'll focus that search within the `fs/` directory, since that's where I expect all the filesystem-related code to live. This should give me a good overview of where `truncate_setsize` is being called and, ideally, a sense of how it's being used in each of these filesystems. This kind of overview will quickly help me understand if there are any filesystem-specific quirks to consider.
|
| 356/4 |
2026/09/17 11:37 |
tool |
grepper |
0m
Args: map[Expression:truncate_setsize PathPrefix:fs/]
Results: map[Output:fs/9p/vfs_inode.c=1017=static int v9fs_vfs_setattr(struct mnt_idmap *idmap,
--
fs/9p/vfs_inode.c-1081- iattr->ia_size != i_size_read(inode)) {
fs/9p/vfs_inode.c:1082: truncate_setsize(inode, iattr->ia_size);
fs/9p/vfs_inode.c-1083- netfs_resize_file(netfs_inode(inode), iattr->ia_size, true);
--
fs/9p/vfs_inode_dotl.c=511=int v9fs_vfs_setattr_dotl(struct mnt_idmap *idmap,
--
fs/9p/vfs_inode_dotl.c-576- i_size_read(inode)) {
fs/9p/vfs_inode_dotl.c:577: truncate_setsize(inode, iattr->ia_size);
fs/9p/vfs_inode_dotl.c-578- netfs_resize_file(netfs_inode(inode), iattr->ia_size, true);
--
fs/adfs/inode.c=302=adfs_setattr(struct mnt_idmap *idmap, struct dentry *dentry, struct iattr *attr)
--
fs/adfs/inode.c-323- if (ia_valid & ATTR_SIZE)
fs/adfs/inode.c:324: truncate_setsize(inode, attr->ia_size);
fs/adfs/inode.c-325-
--
fs/affs/inode.c=216=affs_setattr(struct mnt_idmap *idmap, struct dentry *dentry, struct iattr *attr)
--
fs/affs/inode.c-244-
fs/affs/inode.c:245: truncate_setsize(inode, attr->ia_size);
fs/affs/inode.c-246- affs_truncate(inode);
--
fs/afs/inode.c=762=int afs_setattr(struct mnt_idmap *idmap, struct dentry *dentry,
--
fs/afs/inode.c-816- attr->ia_size > netfs_read_remote_i_size(inode)) {
fs/afs/inode.c:817: truncate_setsize(inode, attr->ia_size);
fs/afs/inode.c-818- netfs_resize_file(&vnode->netfs, size, false);
--
fs/aio.c=360=static void put_aio_ring_file(struct kioctx *ctx)
--
fs/aio.c-366-
fs/aio.c:367: truncate_setsize(inode, 0);
fs/aio.c-368-
--
fs/btrfs/file.c=1526=int btrfs_sync_file(struct file *file, loff_t start, loff_t end, int datasync)
--
fs/btrfs/file.c-1809- * protect against truncate races as the page could now be beyond EOF. Because
fs/btrfs/file.c:1810: * truncate_setsize() writes the inode size before removing pages, once we have
fs/btrfs/file.c-1811- * the page lock we can determine safely if the page is beyond EOF. If it is not
--
fs/btrfs/inode.c=5391=static int btrfs_setsize(struct inode *inode, struct iattr *attr)
--
fs/btrfs/inode.c-5460-
fs/btrfs/inode.c:5461: truncate_setsize(inode, newsize);
fs/btrfs/inode.c-5462-
--
fs/ecryptfs/inode.c=733=static int __ecryptfs_truncate(struct dentry *dentry, const struct iattr *ia)
--
fs/ecryptfs/inode.c-784- if (!(crypt_stat->flags & ECRYPTFS_ENCRYPTED)) {
fs/ecryptfs/inode.c:785: truncate_setsize(inode, ia->ia_size);
fs/ecryptfs/inode.c-786- lower_ia.ia_size = ia->ia_size;
--
fs/ecryptfs/inode.c-804- }
fs/ecryptfs/inode.c:805: truncate_setsize(inode, ia->ia_size);
fs/ecryptfs/inode.c-806- rc = ecryptfs_write_inode_size_to_metadata(inode);
--
fs/exfat/file.c=350=int exfat_setattr(struct mnt_idmap *idmap, struct dentry *dentry,
--
fs/exfat/file.c-415- inode_dio_wait(inode);
fs/exfat/file.c:416: truncate_setsize(inode, attr->ia_size);
fs/exfat/file.c-417-
--
fs/exfat/file.c=754=static int exfat_extend_valid_size(struct inode *inode, loff_t new_valid_size)
--
fs/exfat/file.c-786- if (ret) {
fs/exfat/file.c:787: truncate_setsize(inode, old_valid_size);
fs/exfat/file.c-788- exfat_truncate(inode);
--
fs/ext2/inode.c=1237=static int ext2_setsize(struct inode *inode, loff_t newsize)
--
fs/ext2/inode.c-1255- filemap_invalidate_lock(inode->i_mapping);
fs/ext2/inode.c:1256: truncate_setsize(inode, newsize);
fs/ext2/inode.c-1257- __ext2_truncate_blocks(inode, newsize);
--
fs/f2fs/file.c=637=static int finish_preallocate_blocks(struct inode *inode)
--
fs/f2fs/file.c-657-
fs/f2fs/file.c:658: truncate_setsize(inode, i_size_read(inode));
fs/f2fs/file.c-659- ret = f2fs_truncate(inode);
--
fs/f2fs/file.c=1124=int f2fs_setattr(struct mnt_idmap *idmap, struct dentry *dentry,
--
fs/f2fs/file.c-1235- }
fs/f2fs/file.c:1236: truncate_setsize(inode, attr->ia_size);
fs/f2fs/file.c-1237-
--
fs/f2fs/file.c=3879=static int f2fs_ioc_release_dev_alias(struct file *filp)
--
fs/f2fs/file.c-3929- filemap_invalidate_lock(inode->i_mapping);
fs/f2fs/file.c:3930: truncate_setsize(inode, 0);
fs/f2fs/file.c-3931-
--
fs/fat/file.c=517=int fat_setattr(struct mnt_idmap *idmap, struct dentry *dentry,
--
fs/fat/file.c-586- down_write(&MSDOS_I(inode)->truncate_lock);
fs/fat/file.c:587: truncate_setsize(inode, attr->ia_size);
fs/fat/file.c-588- fat_truncate_blocks(inode, attr->ia_size);
--
fs/gfs2/bmap.c=2095=static int do_grow(struct inode *inode, u64 size)
--
fs/gfs2/bmap.c-2138-
fs/gfs2/bmap.c:2139: truncate_setsize(inode, size);
fs/gfs2/bmap.c-2140- inode_set_mtime_to_ts(&ip->i_inode, inode_set_ctime_current(&ip->i_inode));
--
fs/hfs/inode.c=646=int hfs_inode_setattr(struct mnt_idmap *idmap, struct dentry *dentry,
--
fs/hfs/inode.c-686-
fs/hfs/inode.c:687: truncate_setsize(inode, attr->ia_size);
fs/hfs/inode.c-688- hfs_file_truncate(inode);
--
fs/hfsplus/inode.c=308=static int hfsplus_setattr(struct mnt_idmap *idmap,
--
fs/hfsplus/inode.c-326- }
fs/hfsplus/inode.c:327: truncate_setsize(inode, attr->ia_size);
fs/hfsplus/inode.c-328- hfsplus_file_truncate(inode);
--
fs/hostfs/hostfs_kern.c=804=static int hostfs_setattr(struct mnt_idmap *idmap,
--
fs/hostfs/hostfs_kern.c-868- attr->ia_size != i_size_read(inode))
fs/hostfs/hostfs_kern.c:869: truncate_setsize(inode, attr->ia_size);
fs/hostfs/hostfs_kern.c-870-
--
fs/hpfs/inode.c=260=int hpfs_setattr(struct mnt_idmap *idmap, struct dentry *dentry,
--
fs/hpfs/inode.c-287-
fs/hpfs/inode.c:288: truncate_setsize(inode, attr->ia_size);
fs/hpfs/inode.c-289- hpfs_truncate(inode);
--
fs/jffs2/fs.c=32=int jffs2_do_setattr (struct inode *inode, struct iattr *iattr)
--
fs/jffs2/fs.c-179-
fs/jffs2/fs.c:180: /* We have to do the truncate_setsize() without f->sem held, since
fs/jffs2/fs.c-181- some pages may be locked and waiting for it in read_folio().
--
fs/jffs2/fs.c-185- if (ivalid & ATTR_SIZE && inode->i_size > iattr->ia_size) {
fs/jffs2/fs.c:186: truncate_setsize(inode, iattr->ia_size);
fs/jffs2/fs.c-187- inode->i_blocks = (inode->i_size + 511) >> 9;
--
fs/jfs/file.c=92=int jfs_setattr(struct mnt_idmap *idmap, struct dentry *dentry,
--
fs/jfs/file.c-121-
fs/jfs/file.c:122: truncate_setsize(inode, iattr->ia_size);
fs/jfs/file.c-123- jfs_truncate(inode);
--
fs/libfs.c=916=int simple_setattr(struct mnt_idmap *idmap, struct dentry *dentry,
--
fs/libfs.c-926- if (iattr->ia_valid & ATTR_SIZE)
fs/libfs.c:927: truncate_setsize(inode, iattr->ia_size);
fs/libfs.c-928- setattr_copy(idmap, inode, iattr);
--
fs/minix/file.c=26=static int minix_setattr(struct mnt_idmap *idmap,
--
fs/minix/file.c-41-
fs/minix/file.c:42: truncate_setsize(inode, attr->ia_size);
fs/minix/file.c-43- minix_truncate(inode);
--
fs/nilfs2/inode.c=907=int nilfs_setattr(struct mnt_idmap *idmap, struct dentry *dentry,
--
fs/nilfs2/inode.c-925- inode_dio_wait(inode);
fs/nilfs2/inode.c:926: truncate_setsize(inode, iattr->ia_size);
fs/nilfs2/inode.c-927- nilfs_truncate(inode);
--
fs/ntfs/file.c=254=static int ntfs_setattr_size(struct inode *vi, struct iattr *attr)
--
fs/ntfs/file.c-284- } else {
fs/ntfs/file.c:285: truncate_setsize(vi, attr->ia_size);
fs/ntfs/file.c-286- }
--
fs/ntfs/file.c=579=static ssize_t ntfs_file_write_iter(struct kiocb *iocb, struct iov_iter *from)
--
fs/ntfs/file.c-664- if (ni->data_size != old_data_size) {
fs/ntfs/file.c:665: truncate_setsize(vi, old_data_size);
fs/ntfs/file.c-666- ntfs_attr_truncate(ni, old_data_size);
--
fs/ntfs/inode.c=375=int ntfs_drop_big_inode(struct inode *inode)
--
fs/ntfs/inode.c-390-
fs/ntfs/inode.c:391: truncate_setsize(VFS_I(ni), 0);
fs/ntfs/inode.c-392- ntfs_truncate_vfs(VFS_I(ni), 0, 1);
--
fs/ntfs/inode.c=2410=int ntfs_extend_initialized_size(struct inode *vi, const loff_t offset,
--
fs/ntfs/inode.c-2444- if (err)
fs/ntfs/inode.c:2445: truncate_setsize(vi, old_init_size);
fs/ntfs/inode.c-2446- return err;
--
fs/ntfs3/attrib.c=2009=int attr_collapse_range(struct ntfs_inode *ni, u64 vbo, u64 bytes)
--
fs/ntfs3/attrib.c-2057- /* Simple truncate file at 'vbo'. */
fs/ntfs3/attrib.c:2058: truncate_setsize(&ni->vfs_inode, vbo);
fs/ntfs3/attrib.c-2059- err = attr_set_size(ni, ATTR_DATA, ni->file.ads.name,
--
fs/ntfs3/file.c=706=int ntfs_setattr(struct mnt_idmap *idmap, struct dentry *dentry,
--
fs/ntfs3/file.c-738- if (newsize != oldsize) {
fs/ntfs3/file.c:739: truncate_setsize(inode, newsize);
fs/ntfs3/file.c-740-
--
fs/omfs/file.c=341=static int omfs_setattr(struct mnt_idmap *idmap,
--
fs/omfs/file.c-355- return error;
fs/omfs/file.c:356: truncate_setsize(inode, attr->ia_size);
fs/omfs/file.c-357- omfs_truncate(inode);
--
fs/orangefs/inode.c=697=static int orangefs_setattr_size(struct inode *inode, struct iattr *iattr)
--
fs/orangefs/inode.c-722-
fs/orangefs/inode.c:723: /* This is truncate_setsize in a different order. */
fs/orangefs/inode.c-724- truncate_pagecache(inode, iattr->ia_size);
--
fs/ramfs/file-nommu.c=135=static int ramfs_nommu_resize(struct inode *inode, loff_t newsize, loff_t size)
--
fs/ramfs/file-nommu.c-154-
fs/ramfs/file-nommu.c:155: truncate_setsize(inode, newsize);
fs/ramfs/file-nommu.c-156- return 0;
--
fs/smb/client/cifsfs.c=1519=ssize_t cifs_file_copychunk_range(unsigned int xid,
--
fs/smb/client/cifsfs.c-1596- if (rc > 0 && destoff + rc > i_size_read(target_inode)) {
fs/smb/client/cifsfs.c:1597: truncate_setsize(target_inode, destoff + rc);
fs/smb/client/cifsfs.c-1598- netfs_resize_file(&target_cifsi->netfs,
--
fs/smb/client/smb2ops.c=3508=static long smb3_zero_range(struct file *file, struct cifs_tcon *tcon,
--
fs/smb/client/smb2ops.c-3568- if (rc >= 0) {
fs/smb/client/smb2ops.c:3569: truncate_setsize(inode, new_size);
fs/smb/client/smb2ops.c-3570- spin_lock(&inode->i_lock);
--
fs/smb/client/smb2ops.c=4014=static long smb3_collapse_range(struct file *file, struct cifs_tcon *tcon,
--
fs/smb/client/smb2ops.c-4064-
fs/smb/client/smb2ops.c:4065: truncate_setsize(inode, new_eof);
fs/smb/client/smb2ops.c-4066- spin_lock(&inode->i_lock);
--
fs/smb/client/smb2ops.c=4078=static long smb3_insert_range(struct file *file, struct cifs_tcon *tcon,
--
fs/smb/client/smb2ops.c-4127-
fs/smb/client/smb2ops.c:4128: truncate_setsize(inode, new_eof);
fs/smb/client/smb2ops.c-4129- spin_lock(&inode->i_lock);
--
fs/ubifs/file.c=883=static int do_writepage(struct folio *folio, size_t len)
--
fs/ubifs/file.c-958- * same time. And the problematic one is truncation to smaller size, from where
fs/ubifs/file.c:959: * we have to call 'truncate_setsize()', which first changes @inode->i_size,
fs/ubifs/file.c-960- * then drops the truncated pages. And while dropping the pages, it takes the
fs/ubifs/file.c:961: * page lock. This means that 'do_truncation()' cannot call 'truncate_setsize()'
fs/ubifs/file.c-962- * with @ui_mutex locked, because it would deadlock with 'ubifs_writepage()'.
--
fs/ubifs/file.c-965- * XXX(truncate): with the new truncate sequence this is not true anymore,
fs/ubifs/file.c:966: * and the calls to truncate_setsize can be move around freely. They should
fs/ubifs/file.c-967- * be moved to the very end of the truncate sequence.
--
fs/ubifs/file.c=1100=static int do_truncation(struct ubifs_info *c, struct inode *inode,
--
fs/ubifs/file.c-1133-
fs/ubifs/file.c:1134: truncate_setsize(inode, new_size);
fs/ubifs/file.c-1135-
--
fs/ubifs/file.c=1208=static int do_setattr(struct ubifs_info *c, struct inode *inode,
--
fs/ubifs/file.c-1222- dbg_gen("size %lld -> %lld", inode->i_size, new_size);
fs/ubifs/file.c:1223: truncate_setsize(inode, new_size);
fs/ubifs/file.c-1224- }
--
fs/ubifs/file.c-1229- inode_set_mtime_to_ts(inode, inode_set_ctime_current(inode));
fs/ubifs/file.c:1230: /* 'truncate_setsize()' changed @i_size, update @ui_size */
fs/ubifs/file.c-1231- ui->ui_size = inode->i_size;
--
fs/ubifs/ubifs.h=334=struct ubifs_gced_idx_leb {
--
fs/ubifs/ubifs.h-393- * make sure @inode->i_size is always changed under @ui_mutex, because it
fs/ubifs/ubifs.h:394: * cannot call 'truncate_setsize()' with @ui_mutex locked, because it would
fs/ubifs/ubifs.h-395- * deadlock with 'ubifs_writepage()' (see file.c). All the other inode fields
--
fs/udf/inode.c=1280=int udf_setsize(struct inode *inode, loff_t newsize)
--
fs/udf/inode.c-1307-set_size:
fs/udf/inode.c:1308: truncate_setsize(inode, newsize);
fs/udf/inode.c-1309- } else {
--
fs/udf/inode.c-1316- iinfo->i_lenAlloc = newsize;
fs/udf/inode.c:1317: truncate_setsize(inode, newsize);
fs/udf/inode.c-1318- up_write(&iinfo->i_data_sem);
--
fs/udf/inode.c-1324- return err;
fs/udf/inode.c:1325: truncate_setsize(inode, newsize);
fs/udf/inode.c-1326- down_write(&iinfo->i_data_sem);
--
fs/ufs/inode.c=1167=static int ufs_truncate(struct inode *inode, loff_t size)
--
fs/ufs/inode.c-1187-
fs/ufs/inode.c:1188: truncate_setsize(inode, size);
fs/ufs/inode.c-1189-
--
fs/xfs/xfs_iops.c=905=xfs_vn_setattr_size(
--
fs/xfs/xfs_iops.c-1008- * drop the XFS_MMAP_EXCL lock after the extent manipulations are
fs/xfs/xfs_iops.c:1009: * complete. The truncate_setsize() call also cleans partial EOF page
fs/xfs/xfs_iops.c-1010- * PTEs on extending truncates and hence ensures sub-page block size
--
fs/xfs/xfs_iops.c-1025- */
fs/xfs/xfs_iops.c:1026: truncate_setsize(inode, newsize);
fs/xfs/xfs_iops.c-1027-
--
fs/zonefs/file.c=203=int zonefs_file_truncate(struct inode *inode, loff_t isize)
--
fs/zonefs/file.c-261- zonefs_update_stats(inode, isize);
fs/zonefs/file.c:262: truncate_setsize(inode, isize);
fs/zonefs/file.c-263- z->z_wpoffset = isize;
]
|
| 357/4 |
2026/09/17 11:37 |
llm |
codeexpert |
0m
Model:
Tokens:
input: 54056
output: 41
thoughts: 69
Thoughts: **Diving into Filesystem IOPS Implementation**
Okay, so I need to refresh my memory on how different filesystems handle IOPS. I recall some key areas I've looked at before. Let's start by digging into `fs/xfs/xfs_iops.c`, specifically around lines 1000 to 1040. That's a good place to start my investigation into XFS's implementation. I can use this as a reference point for comparing and contrasting approaches, and what insights I can find there. I'll also glance at `fs/ext4/inode.c`, too, just to get a different perspective. This should give me a broader view of common practices and how specific filesystems tackle this fundamental problem.
|
| 358/4 |
2026/09/17 11:37 |
tool |
read-file |
0m
Args: map[File:fs/xfs/xfs_iops.c FirstLine:1000 LineCount:40]
Results: map[Contents:1000: xfs_zoned_space_unreserve(mp, &ac);
1001:
1002: if (error)
1003: return error;
1004:
1005: /*
1006: * We've already locked out new page faults, so now we can safely remove
1007: * pages from the page cache knowing they won't get refaulted until we
1008: * drop the XFS_MMAP_EXCL lock after the extent manipulations are
1009: * complete. The truncate_setsize() call also cleans partial EOF page
1010: * PTEs on extending truncates and hence ensures sub-page block size
1011: * filesystems are correctly handled, too.
1012: *
1013: * We have to do all the page cache truncate work outside the
1014: * transaction context as the "lock" order is page lock->log space
1015: * reservation as defined by extent allocation in the writeback path.
1016: * Hence a truncate can fail with ENOMEM from xfs_trans_alloc(), but
1017: * having already truncated the in-memory version of the file (i.e. made
1018: * user visible changes). There's not much we can do about this, except
1019: * to hope that the caller sees ENOMEM and retries the truncate
1020: * operation.
1021: *
1022: * And we update in-core i_size and truncate page cache beyond newsize
1023: * before writeback the [i_disk_size, newsize] range, so we're
1024: * guaranteed not to write stale data past the new EOF on truncate down.
1025: */
1026: truncate_setsize(inode, newsize);
1027:
1028: /*
1029: * We are going to log the inode size change in this transaction so
1030: * any previous writes that are beyond the on disk EOF and the new
1031: * EOF that have not been written out need to be written here. If we
1032: * do not write the data out, we expose ourselves to the null files
1033: * problem. Note that this includes any block zeroing we did above;
1034: * otherwise those blocks may not be zeroed after a crash.
1035: */
1036: if (did_zeroing ||
1037: (newsize > ip->i_disk_size && oldsize != ip->i_disk_size)) {
1038: error = filemap_write_and_wait_range(VFS_I(ip)->i_mapping,
1039: ip->i_disk_size, newsize - 1);
]
|
| 359/4 |
2026/09/17 11:37 |
llm |
codeexpert |
0m
Model:
Tokens:
input: 55073
output: 33
thoughts: 105
Thoughts: **Examining File Truncation and Data Integrity**
Alright, let's dive into this. I'm seeing this comment in the XFS code, specifically concerning how they handle file truncation. It's highlighting a key strategy: updating the in-core `i_size` and truncating the page cache *before* writing the data back to disk in the range between the old and new file size. The reasoning is solid β we want to prevent writing any stale, old data past the new end-of-file after a "truncate down" operation. This guarantees that any writeback process won't accidentally extend the file with remnants of the previous data. This looks like a solid safeguard for data integrity.
Now, how does this compare to a different filesystem's approach? Let's take a look at how `ext4` handles a similar operation, specifically related to `setattr` which often entails changes in file size. Let's see how they manage their own truncation and attribute setting to accomplish the same end goal! I should investigate the `ext4_setattr` function in their source.
|
| 360/4 |
2026/09/17 11:37 |
tool |
grepper |
0m
Args: map[Expression:truncate_setsize|ext4_truncate PathPrefix:fs/ext4]
Results: map[Output:fs/ext4/ext4.h=1048=struct ext4_inode_info {
--
fs/ext4/ext4.h-1132- * in memory. During truncate, i_size is set to the new size by
fs/ext4/ext4.h:1133: * the VFS prior to calling ext4_truncate(), but the filesystem won't
fs/ext4/ext4.h-1134- * set i_disksize to 0 until the truncate is actually under way.
--
fs/ext4/ext4.h-1142- * a truncate is in progress. The only things which change i_disksize
fs/ext4/ext4.h:1143: * are ext4_get_block (growth) and ext4_truncate (shrinkth).
fs/ext4/ext4.h-1144- */
--
fs/ext4/ext4.h-1147- /*
fs/ext4/ext4.h:1148: * i_data_sem is for serialising ext4_truncate() against
fs/ext4/ext4.h-1149- * ext4_getblock(). In the 2.4 ext2 design, great chunks of inode's
--
fs/ext4/ext4.h=3198=extern int ext4_can_truncate(struct inode *inode);
fs/ext4/ext4.h:3199:extern int ext4_truncate(struct inode *);
fs/ext4/ext4.h-3200-extern int ext4_break_layouts(struct inode *);
fs/ext4/ext4.h:3201:extern int ext4_truncate_page_cache_block_range(struct inode *inode,
fs/ext4/ext4.h-3202- loff_t start, loff_t end);
--
fs/ext4/extents.c=4780=static long ext4_zero_range(struct file *file, loff_t offset,
--
fs/ext4/extents.c-4825- /* Now release the pages and zero block aligned part of pages */
fs/ext4/extents.c:4826: ret = ext4_truncate_page_cache_block_range(inode, offset, end);
fs/ext4/extents.c-4827- if (ret)
--
fs/ext4/file.c=392=static void ext4_inode_extension_cleanup(struct inode *inode, bool need_trunc)
--
fs/ext4/file.c-395- if (need_trunc) {
fs/ext4/file.c:396: ext4_truncate_failed_write(inode);
fs/ext4/file.c-397- /*
--
fs/ext4/indirect.c=530=int ext4_ind_map_blocks(handle_t *handle, struct inode *inode,
--
fs/ext4/indirect.c-632- /*
fs/ext4/indirect.c:633: * Block out ext4_truncate while we alter the tree
fs/ext4/indirect.c-634- */
--
fs/ext4/indirect.c=754=static inline int all_zeroes(__le32 *p, __le32 *q)
--
fs/ext4/indirect.c-769- *
fs/ext4/indirect.c:770: * This is a helper function used by ext4_truncate().
fs/ext4/indirect.c-771- *
--
fs/ext4/indirect.c-777- * with everything to the right of the path. Since no allocation
fs/ext4/indirect.c:778: * past the truncation point is possible until ext4_truncate()
fs/ext4/indirect.c-779- * finishes, we may safely do the latter, but top of branch may
--
fs/ext4/inline.c=571=static int ext4_convert_inline_data_to_extent(struct address_space *mapping,
--
fs/ext4/inline.c-656- handle = NULL;
fs/ext4/inline.c:657: ext4_truncate_failed_write(inode);
fs/ext4/inline.c-658- /*
--
fs/ext4/inline.c=793=int ext4_write_inline_data_end(struct inode *inode, loff_t pos, unsigned len,
--
fs/ext4/inline.c-874- if (pos + len > inode->i_size) {
fs/ext4/inline.c:875: ext4_truncate_failed_write(inode);
fs/ext4/inline.c-876- /*
--
fs/ext4/inline.c=896=static int ext4_da_convert_inline_data_to_extent(struct address_space *mapping,
--
fs/ext4/inline.c-926- folio_put(folio);
fs/ext4/inline.c:927: ext4_truncate_failed_write(inode);
fs/ext4/inline.c-928- return ret;
--
fs/ext4/inode.c=169=void ext4_evict_inode(struct inode *inode)
--
fs/ext4/inode.c-258- /*
fs/ext4/inode.c:259: * Set inode->i_size to 0 before calling ext4_truncate(). We need
fs/ext4/inode.c-260- * special handling of symlinks here because i_size is used to
--
fs/ext4/inode.c-275- if (inode->i_blocks) {
fs/ext4/inode.c:276: err = ext4_truncate(inode);
fs/ext4/inode.c-277- if (err) {
--
fs/ext4/inode.c-297- /*
fs/ext4/inode.c:298: * Kill off the orphan record which ext4_truncate created.
fs/ext4/inode.c-299- * AKPM: I think this can be inside the above `if'.
--
fs/ext4/inode.c-301- * deletion of a non-existent orphan - this is because we don't
fs/ext4/inode.c:302: * know if ext4_truncate() actually created an orphan record.
fs/ext4/inode.c-303- * (Well, we could do this if we need to, but heck - it works)
--
fs/ext4/inode.c=1277=static int ext4_write_begin(const struct kiocb *iocb,
--
fs/ext4/inode.c-1390- if (extended) {
fs/ext4/inode.c:1391: ext4_truncate_failed_write(inode);
fs/ext4/inode.c-1392- /*
--
fs/ext4/inode.c=1432=static int ext4_write_end(const struct kiocb *iocb,
--
fs/ext4/inode.c-1486- if (pos + len > inode->i_size && !verity) {
fs/ext4/inode.c:1487: ext4_truncate_failed_write(inode);
fs/ext4/inode.c-1488- /*
--
fs/ext4/inode.c=1535=static int ext4_journalled_write_end(const struct kiocb *iocb,
--
fs/ext4/inode.c-1599- if (pos + len > inode->i_size && !verity) {
fs/ext4/inode.c:1600: ext4_truncate_failed_write(inode);
fs/ext4/inode.c-1601- /*
--
fs/ext4/inode.c=3124=static int ext4_da_write_begin(const struct kiocb *iocb,
--
fs/ext4/inode.c-3177- if (pos + len > inode->i_size)
fs/ext4/inode.c:3178: ext4_truncate_failed_write(inode);
fs/ext4/inode.c-3179-
--
fs/ext4/inode.c=4343=int ext4_update_disksize_before_punch(struct inode *inode, loff_t offset,
--
fs/ext4/inode.c-4369-
fs/ext4/inode.c:4370:static inline void ext4_truncate_folio(struct inode *inode,
fs/ext4/inode.c-4371- loff_t start, loff_t end)
--
fs/ext4/inode.c-4389-
fs/ext4/inode.c:4390:int ext4_truncate_page_cache_block_range(struct inode *inode,
fs/ext4/inode.c-4391- loff_t start, loff_t end)
--
fs/ext4/inode.c-4420-
fs/ext4/inode.c:4421: ext4_truncate_folio(inode, start, min(page_boundary, end));
fs/ext4/inode.c-4422- if (end > page_boundary)
fs/ext4/inode.c:4423: ext4_truncate_folio(inode,
fs/ext4/inode.c-4424- round_down(end, PAGE_SIZE), end);
--
fs/ext4/inode.c=4458=int ext4_punch_hole(struct file *file, loff_t offset, loff_t length)
--
fs/ext4/inode.c-4498- /* Now release the pages and zero block aligned part of pages*/
fs/ext4/inode.c:4499: ret = ext4_truncate_page_cache_block_range(inode, offset, end);
fs/ext4/inode.c-4500- if (ret)
--
fs/ext4/inode.c=4567=int ext4_inode_attach_jinode(struct inode *inode)
--
fs/ext4/inode.c-4597-/*
fs/ext4/inode.c:4598: * ext4_truncate()
fs/ext4/inode.c-4599- *
fs/ext4/inode.c-4600- * We block out ext4_get_block() block instantiations across the entire
fs/ext4/inode.c:4601: * transaction, and VFS/VM ensures that ext4_truncate() cannot run
fs/ext4/inode.c-4602- * simultaneously on behalf of the same inode.
--
fs/ext4/inode.c-4619- * that this inode's truncate did not complete and it will again call
fs/ext4/inode.c:4620: * ext4_truncate() to have another go. So there will be instantiated blocks
fs/ext4/inode.c-4621- * to the right of the truncation point in a crashed ext4 filesystem. But
fs/ext4/inode.c-4622- * that's fine - as long as they are linked from the inode, the post-crash
fs/ext4/inode.c:4623: * ext4_truncate() run will find them and release them.
fs/ext4/inode.c-4624- */
fs/ext4/inode.c:4625:int ext4_truncate(struct inode *inode)
fs/ext4/inode.c-4626-{
--
fs/ext4/inode.c-4638- WARN_ON(!inode_is_locked(inode));
fs/ext4/inode.c:4639: trace_ext4_truncate_enter(inode);
fs/ext4/inode.c-4640-
--
fs/ext4/inode.c-4726-out_trace:
fs/ext4/inode.c:4727: trace_ext4_truncate_exit(inode);
fs/ext4/inode.c-4728- return err;
--
fs/ext4/inode.c=6009=int ext4_setattr(struct mnt_idmap *idmap, struct dentry *dentry,
--
fs/ext4/inode.c-6144- * Update c/mtime and tail zero the EOF folio on
fs/ext4/inode.c:6145: * truncate up. ext4_truncate() handles the shrink case
fs/ext4/inode.c-6146- * below.
--
fs/ext4/inode.c-6215- /*
fs/ext4/inode.c:6216: * Call ext4_truncate() even if i_size didn't change to
fs/ext4/inode.c-6217- * truncate possible preallocated blocks.
--
fs/ext4/inode.c-6219- if (attr->ia_size <= oldsize) {
fs/ext4/inode.c:6220: rc = ext4_truncate(inode);
fs/ext4/inode.c-6221- if (rc)
--
fs/ext4/inode.c-6235- /*
fs/ext4/inode.c:6236: * If the call to ext4_truncate failed to get a transaction handle at
fs/ext4/inode.c-6237- * all, we need to clean up the in-core orphan list manually.
--
fs/ext4/orphan.c=322=static void ext4_process_orphan(struct inode *inode,
--
fs/ext4/orphan.c-337- truncate_inode_pages(inode->i_mapping, inode->i_size);
fs/ext4/orphan.c:338: ret = ext4_truncate(inode);
fs/ext4/orphan.c-339- if (ret) {
--
fs/ext4/orphan.c-341- * We need to clean up the in-core orphan list
fs/ext4/orphan.c:342: * manually if ext4_truncate() failed to get a
fs/ext4/orphan.c-343- * transaction handle.
--
fs/ext4/truncate.h-11- */
fs/ext4/truncate.h:12:static inline void ext4_truncate_failed_write(struct inode *inode)
fs/ext4/truncate.h-13-{
--
fs/ext4/truncate.h-21- truncate_inode_pages(mapping, inode->i_size);
fs/ext4/truncate.h:22: ext4_truncate(inode);
fs/ext4/truncate.h-23- filemap_invalidate_unlock(mapping);
--
fs/ext4/verity.c=102=static int ext4_begin_enable_verity(struct file *filp)
--
fs/ext4/verity.c-142- */
fs/ext4/verity.c:143: err = ext4_truncate(inode);
fs/ext4/verity.c-144- if (err)
--
fs/ext4/verity.c=191=static int ext4_end_enable_verity(struct file *filp, const void *desc,
--
fs/ext4/verity.c-264- truncate_inode_pages(inode->i_mapping, inode->i_size);
fs/ext4/verity.c:265: ext4_truncate(inode);
fs/ext4/verity.c-266- ext4_orphan_del(NULL, inode);
]
|
| 361/4 |
2026/09/17 11:37 |
llm |
codeexpert |
0m
Model:
Tokens:
input: 59436
output: 37
thoughts: 24
Thoughts: Here's my attempt at summarizing the thought process, tailored for an expert audience:
**Diving into `ext4_setattr`**
Okay, time to get my hands dirty and jump into the `ext4_setattr` function, specifically focusing on the code around lines 6140-6225. I'm zeroing in on this section because I suspect there's something interesting happening regarding attribute modifications and potential performance implications, or maybe even a subtle bug lurking. I'm betting this region probably handles the meat of the permission checks, file size updates (including handling of blocks or inodes), atime/ctime/mtime updates and various other related attributes. I'm keen to see the interaction between the VFS layer and the ext4-specific implementation here, specifically looking for any potential synchronization issues or unexpected locking order in this key path. I should also check how the code interacts with journaling and extent-based block allocation, since thatβs always a crucial performance bottleneck. I wonder if there are any potential race conditions between metadata updates and data blocks being written. Iβll keep a sharp eye for subtle interactions with error handling and recovery as well. Let's see what gems we can find.
|
| 362/4 |
2026/09/17 11:38 |
tool |
read-file |
0m
Args: map[File:fs/ext4/inode.c FirstLine:6180 LineCount:50]
Results: map[Contents:6180: inode->i_sb->s_blocksize_bits);
6181:
6182: down_write(&EXT4_I(inode)->i_data_sem);
6183: old_disksize = EXT4_I(inode)->i_disksize;
6184: EXT4_I(inode)->i_disksize = attr->ia_size;
6185:
6186: /*
6187: * We have to update i_size under i_data_sem together
6188: * with i_disksize to avoid races with writeback code
6189: * running ext4_wb_update_i_disksize().
6190: */
6191: if (!error)
6192: i_size_write(inode, attr->ia_size);
6193: else
6194: EXT4_I(inode)->i_disksize = old_disksize;
6195: up_write(&EXT4_I(inode)->i_data_sem);
6196: rc = ext4_mark_inode_dirty(handle, inode);
6197: if (!error)
6198: error = rc;
6199: ext4_journal_stop(handle);
6200: if (error)
6201: goto out_mmap_sem;
6202: if (!shrink) {
6203: pagecache_isize_extended(inode, oldsize,
6204: inode->i_size);
6205: } else if (ext4_should_journal_data(inode)) {
6206: ext4_wait_for_tail_page_commit(inode);
6207: }
6208: }
6209:
6210: /*
6211: * Truncate pagecache after we've waited for commit
6212: * in data=journal mode to make pages freeable.
6213: */
6214: truncate_pagecache(inode, inode->i_size);
6215: /*
6216: * Call ext4_truncate() even if i_size didn't change to
6217: * truncate possible preallocated blocks.
6218: */
6219: if (attr->ia_size <= oldsize) {
6220: rc = ext4_truncate(inode);
6221: if (rc)
6222: error = rc;
6223: }
6224: out_mmap_sem:
6225: filemap_invalidate_unlock(inode->i_mapping);
6226: }
6227:
6228: if (!error) {
6229: if (inc_ivers)
]
|
| 363/4 |
2026/09/17 11:38 |
llm |
codeexpert |
0m
Model:
Tokens:
input: 60507
output: 36
thoughts: 1197
Thoughts: **Analyzing Filesystem Truncation Order and Potential Data Corruption**
Okay, let's break this down. My initial observation is about the order of operations during file truncation, specifically in the context of `ext4`, where `truncate_pagecache` is called *before* `ext4_truncate`, which handles block deallocation. I see this pattern repeated across several filesystems: `affs`, `btrfs`, `exfat`, `ext2`, `f2fs`, `fat`, `hfs`, `hpfs`, `jfs`, `minix`, `nilfs2`, `ntfs (old)`, and `ntfs3`. They all seem to use `truncate_setsize` followed by the filesystem-specific truncate function.
The question then becomes: *why*?
My immediate thought is to revisit the comment for `truncate_setsize` itself. It explicitly states that this function "Must be called ... before all filesystem specific block truncation has been performed." Bingo! That confirms the observed ordering is deliberate and likely for a very specific reason.
Now, let's re-examine the user's prompt carefully, especially the shrinking scenario. If we're reducing the file size (`newsize < oldsize`) and `ntfs_set_size` (or block deallocation in general) is called *first*, then what happens with the page cache? Potentially, dirty pages "beyond" the new end-of-file (EOF) might still exist. If these are written back, they could end up on blocks that have been deallocated and *possibly* reallocated to another file, leading to catastrophic data corruption. That's a serious concern!
The prompt's hypothesis seems spot-on. If `ntfs_set_size` is called *first* when shrinking, it's a huge potential vulnerability for data corruption. `truncate_setsize` is essential to adjust the inode's size and to also truncate the page cache before blocks are deallocated, ensuring that any writes don't go astray.
But what about the other case - file expansion? Let me look at what happens when `newsize > oldsize` within `truncate_setsize`. `truncate_setsize` sets the new size and then:
* It calls `pagecache_isize_extended`. Let's see what that does.
This all points to ensuring there are no race conditions with the page cache.
|
| 364/4 |
2026/09/17 11:38 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:mm/truncate.c Name:pagecache_isize_extended]
Results: map[SourceCode: 827: /**
828: * pagecache_isize_extended - update pagecache after extension of i_size
829: * @inode: inode for which i_size was extended
830: * @from: original inode size
831: * @to: new inode size
832: *
833: * Handle extension of inode size either caused by extending truncate or
834: * by write starting after current i_size. We mark the page straddling
835: * current i_size RO so that page_mkwrite() is called on the first
836: * write access to the page. The filesystem will update its per-block
837: * information before user writes to the page via mmap after the i_size
838: * has been changed.
839: *
840: * The function must be called after i_size is updated so that page fault
841: * coming after we unlock the folio will already see the new i_size.
842: * The function must be called while we still hold i_rwsem - this not only
843: * makes sure i_size is stable but also that userspace cannot observe new
844: * i_size value before we are prepared to store mmap writes at new inode size.
845: */
846: void pagecache_isize_extended(struct inode *inode, loff_t from, loff_t to)
847: {
848: int bsize = i_blocksize(inode);
849: loff_t rounded_from;
850: struct folio *folio;
851:
852: WARN_ON(to > inode->i_size);
853:
854: if (from >= to || bsize >= PAGE_SIZE)
855: return;
856: /* Page straddling @from will not have any hole block created? */
857: rounded_from = round_up(from, bsize);
858: if (to <= rounded_from || !(rounded_from & (PAGE_SIZE - 1)))
859: return;
860:
861: folio = filemap_lock_folio(inode->i_mapping, from / PAGE_SIZE);
862: /* Folio not cached? Nothing to do */
863: if (IS_ERR(folio))
864: return;
865: /*
866: * See folio_clear_dirty_for_io() for details why folio_mark_dirty()
867: * is needed.
868: */
869: if (folio_mkclean(folio))
870: folio_mark_dirty(folio);
871:
872: /*
873: * The post-eof range of the folio must be zeroed before it is exposed
874: * to the file. Writeback normally does this, but since i_size has been
875: * increased we handle it here.
876: */
877: if (folio_test_dirty(folio)) {
878: unsigned int offset, end;
879:
880: offset = from - folio_pos(folio);
881: end = min_t(unsigned int, to - folio_pos(folio),
882: folio_size(folio));
883: folio_zero_segment(folio, offset, end);
884: }
885:
886: folio_unlock(folio);
887: folio_put(folio);
888: }
SourceFile:mm/truncate.c]
|
| 365/4 |
2026/09/17 11:38 |
llm |
codeexpert |
0m
Model:
Tokens:
input: 63270
output: 33
thoughts: 227
Thoughts: **Investigating the NTFS Size Adjustment**
Okay, so I'm looking at this `ntfs_set_size` function, and I'm wondering about the error handling, specifically if `ntfs_set_size` fails. The code is in `fs/ntfs3/file.c`, and I see this sequence:
```c
oldsize = i_size_read(inode);
newsize = attr->ia_size;
if (newsize != oldsize) {
truncate_setsize(inode, newsize);
err = ntfs_set_size(inode, newsize);
if (err) {
i_size_write(inode, oldsize);
goto out;
}
```
So, it's pretty clear: if the new size is different from the old size, it calls `truncate_setsize` before trying to set the size with `ntfs_set_size`. Then, if `ntfs_set_size` errors out, it resets the size back to the old value. Makes sense.
But wait a minute... `truncate_setsize` does a few things. First, it calls `i_size_write(inode, newsize);` and then `truncate_pagecache(inode, newsize);`. Hmm, it *writes* the new size first *before* actually setting the size. I need to understand that. And I definitely need to see what `truncate_pagecache` actually *does*.
Looks like `truncate_pagecache` is responsible for removing all pages beyond the `newsize` from the `mapping`. That's important. It discards dirty data beyond that size and also unmaps the user page tables that map those pages. That's a critical detail because if `ntfs_set_size` fails, then all that data, and the page table mappings, might have been lost. So this could lead to issues. I need to understand the implications of discarding that data, especially if `ntfs_set_size` fails after this sequence. Time to dig deeper into `truncate_pagecache` and its interaction with the rest of the file system.
|
| 366/4 |
2026/09/17 11:38 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:mm/truncate.c Name:truncate_pagecache]
Results: map[SourceCode: 768: /**
769: * truncate_pagecache - unmap and remove pagecache that has been truncated
770: * @inode: inode
771: * @newsize: new file size
772: *
773: * inode's new i_size must already be written before truncate_pagecache
774: * is called.
775: *
776: * This function should typically be called before the filesystem
777: * releases resources associated with the freed range (eg. deallocates
778: * blocks). This way, pagecache will always stay logically coherent
779: * with on-disk format, and the filesystem would not have to deal with
780: * situations such as writepage being called for a page that has already
781: * had its underlying blocks deallocated.
782: */
783: void truncate_pagecache(struct inode *inode, loff_t newsize)
784: {
785: struct address_space *mapping = inode->i_mapping;
786: loff_t holebegin = round_up(newsize, PAGE_SIZE);
787:
788: /*
789: * unmap_mapping_range is called twice, first simply for
790: * efficiency so that truncate_inode_pages does fewer
791: * single-page unmaps. However after this first call, and
792: * before truncate_inode_pages finishes, it is possible for
793: * private pages to be COWed, which remain after
794: * truncate_inode_pages finishes, hence the second
795: * unmap_mapping_range call must be made for correctness.
796: */
797: unmap_mapping_range(mapping, holebegin, 0, 1);
798: truncate_inode_pages(mapping, newsize);
799: unmap_mapping_range(mapping, holebegin, 0, 1);
800: }
SourceFile:mm/truncate.c]
|
| 367/4 |
2026/09/17 11:38 |
llm |
codeexpert |
0m
Model:
Tokens:
input: 64574
output: 30
thoughts: 1507
Thoughts: **Analyzing File Truncation in NTFS and Pagecache Interactions**
Okay, so I'm looking at this `truncate_pagecache` function, and the comment is pretty explicit. It confirms my initial hypothesis: this needs to happen *before* the filesystem starts deallocating blocks. It explicitly states that this ordering keeps the pagecache logically consistent with the on-disk format. Avoiding scenarios like `writepage` being called on deallocated blocks is crucial.
I've got the user's question clear in my mind now: If shrinking a file (`newsize < oldsize`), should `truncate_setsize` be called *before* `ntfs_set_size`? Absolutely, yes, this is the correct order of operations! Otherwise, `ntfs_set_size` would deallocate blocks, and we risk dirty pages that are *beyond* the new EOF being written back to those deallocated blocks. That would be a complete disaster, potentially overwriting data from other files, or causing I/O errors and data corruption.
Let's break down the process step by step, precisely how the code would play out:
1. `truncate_setsize(inode, newsize)`: The first step is to update `inode->i_size` to `newsize`. This establishes the file's new boundary. Then, it calls `truncate_pagecache(inode, newsize)`. This function is responsible for unmapping page table entries using `unmap_mapping_range` and removing the truncated pages/folios from the page cache using `truncate_inode_pages`. The dirty pages that are *beyond* `newsize` are essentially discarded and dropped from the writeback queue. If `newsize > oldsize`, it calls `pagecache_isize_extended`.
2. Now comes the crucial part: Why must the pagecache truncation happen *before* the filesystem's block deallocation (in this case `ntfs_set_size`)? Because if the blocks are freed first, the underlying disk space is returned to the free space allocator. Meanwhile, the pagecache *still* contains potentially dirty pages that are now *beyond* the new file size and writeback can continue asynchronously. If the writeback happens, it will lead to either of the following bad scenarios: a) The writeback routine tries to write to the old block numbers which now are part of another file, leading to data corruption and potential overwrites. b) if the extent is removed from the inode, writeback may fail. To prevent this, `truncate_setsize` comes first to ensure the following:
* `i_size` gets updated so writeback routines know the new EOF and won't write beyond it.
* `truncate_inode_pages` purges and invalidates all folios beyond `newsize`, discarding dirty pages.
* Sub-block / partial page at new EOF has its tail zeroed.
Once the pagecache beyond the new EOF is truncated and unmapped, it is perfectly safe to deallocate the physical blocks on disk, so you're not writing to the wrong location, or a deallocated block.
Now, let's circle back to `ntfs_set_size`. I want to confirm if it deallocates blocks when shrinking. The code in `fs/ntfs3/inode.c` shows that it calls `attr_set_size`. Crucially, there's a `keep_prealloc` flag passed to `attr_set_size`, and the documentation uses `true` for this parameter. Let's dig deeper: in `attr_set_size_ex`, if `keep_prealloc` is true and `new_size < old_size` the size attribute's data size (`attr_b->nres.data_size`) is updated to the new size but the blocks *aren't* deallocated, the code just goes to `ok`.
But, wait a minute! There is an exception to that! The code checks `is_ext` if the attribute is compressed or sparse, `keep_prealloc` is set to `false`. In that case, the clusters *are* deallocated with `run_deallocate_ex`. So, if the file is *not* sparse or compressed, the blocks aren't deallocated! So, I need to check when `attr_set_size` is called with `keep_prealloc = false`.
I'll check where `attr_set_size` is called with `keep_prealloc = false` to be certain. And does `ntfs_fallocate` deallocate blocks as well?
|
| 368/4 |
2026/09/17 11:39 |
tool |
grepper |
0m
Args: map[Expression:attr_set_size PathPrefix:fs/ntfs3]
Results: map[Output:fs/ntfs3/attrib.c-5- *
fs/ntfs3/attrib.c:6: * TODO: Merge attr_set_size/attr_data_get_block/attr_allocate_frame?
fs/ntfs3/attrib.c-7- */
--
fs/ntfs3/attrib.c=254=int attr_make_nonresident(struct ntfs_inode *ni, struct ATTRIB *attr,
--
fs/ntfs3/attrib.c-379-/*
fs/ntfs3/attrib.c:380: * attr_set_size_res - Helper for attr_set_size().
fs/ntfs3/attrib.c-381- */
fs/ntfs3/attrib.c:382:static int attr_set_size_res(struct ntfs_inode *ni, struct ATTRIB *attr,
fs/ntfs3/attrib.c-383- struct ATTR_LIST_ENTRY *le, struct mft_inode *mi,
--
fs/ntfs3/attrib.c-421-/*
fs/ntfs3/attrib.c:422: * attr_set_size_ex - Change the size of attribute.
fs/ntfs3/attrib.c-423- *
--
fs/ntfs3/attrib.c-429- */
fs/ntfs3/attrib.c:430:int attr_set_size_ex(struct ntfs_inode *ni, enum ATTR_TYPE type,
fs/ntfs3/attrib.c-431- const __le16 *name, u8 name_len, struct runs_tree *run,
--
fs/ntfs3/attrib.c-466- if (!attr_b->non_res) {
fs/ntfs3/attrib.c:467: err = attr_set_size_res(ni, attr_b, le_b, mi_b, new_size, run,
fs/ntfs3/attrib.c-468- &attr_b);
--
fs/ntfs3/attrib.c=2009=int attr_collapse_range(struct ntfs_inode *ni, u64 vbo, u64 bytes)
--
fs/ntfs3/attrib.c-2058- truncate_setsize(&ni->vfs_inode, vbo);
fs/ntfs3/attrib.c:2059: err = attr_set_size(ni, ATTR_DATA, ni->file.ads.name,
fs/ntfs3/attrib.c-2060- ni->file.ads.len, &ni->file.run, vbo,
--
fs/ntfs3/attrib.c-2083- */
fs/ntfs3/attrib.c:2084: err = attr_set_size_ex(ni, ATTR_DATA, ni->file.ads.name,
fs/ntfs3/attrib.c-2085- ni->file.ads.len, run,
--
fs/ntfs3/attrib.c=2527=int attr_insert_range(struct ntfs_inode *ni, u64 vbo, u64 bytes)
--
fs/ntfs3/attrib.c-2591- if (!attr_b->non_res) {
fs/ntfs3/attrib.c:2592: err = attr_set_size(ni, ATTR_DATA, ni->file.ads.name,
fs/ntfs3/attrib.c-2593- ni->file.ads.len, run, data_size + bytes,
--
fs/ntfs3/attrlist.c=300=int al_add_le(struct ntfs_inode *ni, enum ATTR_TYPE type, const __le16 *name,
--
fs/ntfs3/attrlist.c-353-
fs/ntfs3/attrlist.c:354: err = attr_set_size_ex(ni, ATTR_LIST, NULL, 0, &al->run, new_size,
fs/ntfs3/attrlist.c-355- &new_size, true, &attr, false);
--
fs/ntfs3/attrlist.c=402=int al_update(struct ntfs_inode *ni, int sync)
--
fs/ntfs3/attrlist.c-417- */
fs/ntfs3/attrlist.c:418: err = attr_set_size_ex(ni, ATTR_LIST, NULL, 0, &al->run, al->size, NULL,
fs/ntfs3/attrlist.c-419- false, &attr, false);
--
fs/ntfs3/file.c=1418=static int ntfs_file_release(struct inode *inode, struct file *file)
--
fs/ntfs3/file.c-1441- /* Deallocate preallocated. */
fs/ntfs3/file.c:1442: err = attr_set_size_ex(ni, ATTR_DATA, ni->file.ads.name,
fs/ntfs3/file.c-1443- ni->file.ads.len, &ni->file.run,
--
fs/ntfs3/frecord.c=424=ni_ins_new_attr(struct ntfs_inode *ni, struct mft_inode *mi,
--
fs/ntfs3/frecord.c-446- /*
fs/ntfs3/frecord.c:447: * al_add_le -> attr_set_size (list) -> ni_expand_list
fs/ntfs3/frecord.c-448- * which moves some attributes out of primary record
--
fs/ntfs3/frecord.c=3341=int ni_allocate_da_blocks_locked(struct ntfs_inode *ni)
--
fs/ntfs3/frecord.c-3368- /*
fs/ntfs3/frecord.c:3369: * Normal file allocates clusters in 'attr_set_size'
fs/ntfs3/frecord.c-3370- */
fs/ntfs3/frecord.c:3371: err = attr_set_size_ex(ni, ATTR_DATA, ni->file.ads.name,
fs/ntfs3/frecord.c-3372- ni->file.ads.len, &ni->file.run,
--
fs/ntfs3/fsntfs.c=458=bool ntfs_check_free_space(struct ntfs_sb_info *sbi, CLST clen, CLST mlen,
--
fs/ntfs3/fsntfs.c-516- * ntfs_extend_mft ->
fs/ntfs3/fsntfs.c:517: * attr_set_size ->
fs/ntfs3/fsntfs.c-518- * ni_insert_nonresident ->
--
fs/ntfs3/fsntfs.c=527=static int ntfs_extend_mft(struct ntfs_sb_info *sbi)
--
fs/ntfs3/fsntfs.c-540- down_write(&ni->file.run_lock);
fs/ntfs3/fsntfs.c:541: err = attr_set_size_ex(ni, ATTR_DATA, NULL, 0, &ni->file.run,
fs/ntfs3/fsntfs.c-542- new_mft_bytes, NULL, false, &attr, false);
--
fs/ntfs3/fsntfs.c-555-
fs/ntfs3/fsntfs.c:556: err = attr_set_size(ni, ATTR_BITMAP, NULL, 0, &sbi->mft.bitmap.run,
fs/ntfs3/fsntfs.c-557- new_bitmap_bytes, &new_bitmap_bytes, true);
--
fs/ntfs3/fsntfs.c=2089=int ntfs_insert_security(struct ntfs_sb_info *sbi,
--
fs/ntfs3/fsntfs.c-2222- if (new_sds_size > ni->vfs_inode.i_size) {
fs/ntfs3/fsntfs.c:2223: err = attr_set_size(ni, ATTR_DATA, SDS_NAME,
fs/ntfs3/fsntfs.c-2224- ARRAY_SIZE(SDS_NAME), &ni->file.run,
--
fs/ntfs3/index.c=1532=static int indx_add_allocate(struct ntfs_index *indx, struct ntfs_inode *ni,
--
fs/ntfs3/index.c-1574- /* Increase bitmap. */
fs/ntfs3/index.c:1575: err = attr_set_size(ni, ATTR_BITMAP, in->name, in->name_len,
fs/ntfs3/index.c-1576- &indx->bitmap_run,
--
fs/ntfs3/index.c-1596- /* Increase allocation. */
fs/ntfs3/index.c:1597: err = attr_set_size(ni, ATTR_ALLOC, in->name, in->name_len,
fs/ntfs3/index.c-1598- &indx->alloc_run, data_size, &data_size, true);
--
fs/ntfs3/index.c-1614- /* Ops. No space? */
fs/ntfs3/index.c:1615: attr_set_size(ni, ATTR_BITMAP, in->name, in->name_len,
fs/ntfs3/index.c-1616- &indx->bitmap_run, bmp_size, &bmp_size_v, false);
--
fs/ntfs3/index.c=2152=static int indx_shrink(struct ntfs_index *indx, struct ntfs_inode *ni,
--
fs/ntfs3/index.c-2197-
fs/ntfs3/index.c:2198: err = attr_set_size(ni, ATTR_ALLOC, in->name, in->name_len,
fs/ntfs3/index.c-2199- &indx->alloc_run, new_data, &new_data, false);
--
fs/ntfs3/index.c-2209-
fs/ntfs3/index.c:2210: err = attr_set_size(ni, ATTR_BITMAP, in->name, in->name_len,
fs/ntfs3/index.c-2211- &indx->bitmap_run, bpb, &bpb, false);
--
fs/ntfs3/index.c=2369=int indx_delete_entry(struct ntfs_index *indx, struct ntfs_inode *ni,
--
fs/ntfs3/index.c-2702-
fs/ntfs3/index.c:2703: err = attr_set_size(ni, ATTR_ALLOC, in->name, in->name_len,
fs/ntfs3/index.c-2704- &indx->alloc_run, 0, NULL, false);
--
fs/ntfs3/index.c-2711-
fs/ntfs3/index.c:2712: err = attr_set_size(ni, ATTR_BITMAP, in->name, in->name_len,
fs/ntfs3/index.c-2713- &indx->bitmap_run, 0, NULL, false);
--
fs/ntfs3/inode.c=883=int ntfs_set_size(struct inode *inode, u64 new_size)
--
fs/ntfs3/inode.c-907- /* last 'true' means keep preallocated. */
fs/ntfs3/inode.c:908: err = attr_set_size(ni, ATTR_DATA, ni->file.ads.name, ni->file.ads.len,
fs/ntfs3/inode.c-909- &ni->file.run, new_size, &ni->i_valid, true);
--
fs/ntfs3/inode.c=933=static int ntfs_iomap_begin(struct inode *inode, loff_t offset, loff_t length,
--
fs/ntfs3/inode.c-973- * NOTE: attr_data_get_block allocates clusters only for sparse file.
fs/ntfs3/inode.c:974: * Normal file allocates clusters in attr_set_size.
fs/ntfs3/inode.c-975- */
--
fs/ntfs3/inode.c=1384=int ntfs_create_inode(struct mnt_idmap *idmap, struct inode *dir,
--
fs/ntfs3/inode.c-1892- run_init(&run);
fs/ntfs3/inode.c:1893: attr_set_size(ni, ATTR_EA, NULL, 0, &run, 0, NULL, false);
fs/ntfs3/inode.c-1894- run_close(&run);
--
fs/ntfs3/ntfs_fs.h=465=int attr_make_nonresident(struct ntfs_inode *ni, struct ATTRIB *attr,
--
fs/ntfs3/ntfs_fs.h-468- struct ATTRIB **ins_attr, struct page *page);
fs/ntfs3/ntfs_fs.h:469:int attr_set_size_ex(struct ntfs_inode *ni, enum ATTR_TYPE type,
fs/ntfs3/ntfs_fs.h-470- const __le16 *name, u8 name_len, struct runs_tree *run,
--
fs/ntfs3/ntfs_fs.h-472- struct ATTRIB **ret, bool no_da);
fs/ntfs3/ntfs_fs.h:473:static inline int attr_set_size(struct ntfs_inode *ni, enum ATTR_TYPE type,
fs/ntfs3/ntfs_fs.h-474- const __le16 *name, u8 name_len,
--
fs/ntfs3/ntfs_fs.h-477-{
fs/ntfs3/ntfs_fs.h:478: return attr_set_size_ex(ni, type, name, name_len, run, new_size,
fs/ntfs3/ntfs_fs.h-479- new_valid, keep_prealloc, NULL, false);
--
fs/ntfs3/xattr.c=316=static noinline int ntfs_set_ea(struct inode *inode, const char *name,
--
fs/ntfs3/xattr.c-464- new_sz = size;
fs/ntfs3/xattr.c:465: err = attr_set_size(ni, ATTR_EA, NULL, 0, &ea_run, new_sz, &new_sz,
fs/ntfs3/xattr.c-466- false);
]
|
| 369/4 |
2026/09/17 11:39 |
llm |
codeexpert-compressor |
0m
Model:
Reply: ### 1. Approaches Tried and Results
- **Grep for `ntfs_set_size`**:
- Found callers in `fs/ntfs3/file.c` (`ntfs_fallocate`, `ntfs_setattr`, `ntfs_file_write_iter`), definition in `fs/ntfs3/inode.c`, header in `fs/ntfs3/ntfs_fs.h`.
- **Inspected `ntfs_setattr` in `fs/ntfs3/file.c`**:
- Examined lines 705β769.
- In `ntfs_setattr()`:
```c
if (newsize != oldsize) {
truncate_setsize(inode, newsize);
err = ntfs_set_size(inode, newsize);
if (err) {
i_size_write(inode, oldsize);
goto out;
}
...
}
```
- Confirmed current order in `ntfs_setattr()` is indeed `truncate_setsize(inode, newsize)` called *before* `ntfs_set_size(inode, newsize)`.
- **Examined git history**:
- Attempted `git-log` queries to find commit history related to `truncate_setsize` in `fs/ntfs3`.
- Repository is a shallow/single-commit clone rooted at `fd73f4a66598` ("Linux 7.3-rc3"), so git commit logs prior to this commit are unavailable.
- **Inspected `truncate_setsize` definition and comments in `mm/truncate.c`**:
- Definition in `mm/truncate.c:816`:
```c
/**
* truncate_setsize - update inode and pagecache for a new file size
* ...
* Must be called with a lock serializing truncates and writes (generally
* i_rwsem but e.g. xfs uses a different lock) and before all filesystem
* specific block truncation has been performed.
*/
void truncate_setsize(struct inode *inode, loff_t newsize)
{
loff_t oldsize = inode->i_size;
i_size_write(inode, newsize);
if (newsize > oldsize)
pagecache_isize_extended(inode, oldsize, newsize);
truncate_pagecache(inode, newsize);
}
```
- Explicitly states: *Must be called ... before all filesystem specific block truncation has been performed.*
- **Inspected `ntfs_set_size` in `fs/ntfs3/inode.c`**:
- Lines 883β915:
```c
int ntfs_set_size(struct inode *inode, u64 new_size)
{
...
ni_lock(ni);
down_write(&ni->file.run_lock);
if (new_size < ni->i_valid)
ni->i_valid = new_size;
/* last 'true' means keep preallocated. */
err = attr_set_size(ni, ATTR_DATA, ni->file.ads.name, ni->file.ads.len,
&ni->file.run, new_size, &ni->i_valid, true);
up_write(&ni->file.run_lock);
ni_unlock(ni);
return err;
}
```
- Calls `attr_set_size(..., keep_prealloc = true)`.
- **Inspected `attr_set_size_ex` in `fs/ntfs3/attrib.c`**:
- Examined how shrinking is handled:
- If `keep_prealloc && new_size < old_size` (lines 500β504): updates `data_size`, does not deallocate clusters.
- However, if `is_ext` (sparse or compressed file, lines 484β488), `keep_prealloc` is forced to `false` (`keep_prealloc = false`).
- When `keep_prealloc` is `false` or when clusters are truncated (lines 761β835), `run_deallocate_ex()` actually frees clusters on disk.
- Also, other callers or shrinking operations deallocate blocks.
### 2. Current Hypotheses and Analysis Regarding the User's Question
The user asked:
> Wait, if `newsize < oldsize` (shrinking), should `truncate_setsize` be called before `ntfs_set_size`?
> If `ntfs_set_size` is called first when shrinking, it will deallocate blocks. If there are dirty pages beyond the new EOF, they might be written back to the deallocated blocks, which might have been reallocated to another file.
> Is that correct?
Analysis:
1. **The user's assertion is correct**:
- Calling `truncate_setsize` before filesystem block truncation/deallocation is the standard VFS requirement and rule across Linux filesystems.
- `truncate_setsize` does two things:
1. Updates `inode->i_size` to `newsize`.
2. Calls `truncate_pagecache(inode, newsize)`, which unmaps and discards (invalidates) all cached pages / folios beyond `newsize` from the page cache, preventing writeback of stale dirty pages past EOF.
- If block truncation (deallocation) were performed *before* `truncate_setsize`:
- Blocks backing the truncated region could be freed and placed back into the filesystem free list (or block allocator bitmap).
- These freed blocks could immediately be allocated to another file or metadata structure.
- Any dirty pages remaining in the page cache past the new EOF that haven't been discarded yet could be written back to disk by background flusher threads (`wb_workfn`), `sync`, or memory reclaim, overwriting the freed/reallocated blocks and causing silent data corruption (write-after-free).
2. **Standard VFS contract**:
- The kerneldoc for `truncate_setsize` in `mm/truncate.c` explicitly mandates this ordering:
*"Must be called with a lock serializing truncates and writes (generally i_rwsem ...) and before all filesystem specific block truncation has been performed."*
3. **In `fs/ntfs3` specifically**:
- `ntfs_setattr()` already follows this rule:
```c
truncate_setsize(inode, newsize);
err = ntfs_set_size(inode, newsize);
```
- If `ntfs_set_size` were called before `truncate_setsize` during a shrink operation where blocks are freed (e.g. sparse/compressed files or general block deallocation), the race condition described by the user would indeed occur.
### 3. Key Files and Code References
- **`mm/truncate.c:803-824`**:
- `truncate_setsize()` implementation and doc comment requiring it to be called *before* filesystem-specific block truncation.
- **`fs/ntfs3/file.c:706-752`**:
- `ntfs_setattr()` showing `truncate_setsize(inode, newsize)` called before `ntfs_set_size(inode, newsize)`.
- **`fs/ntfs3/inode.c:883-915`**:
- `ntfs_set_size()` calling `attr_set_size(..., keep_prealloc=true)`.
- **`fs/ntfs3/attrib.c:421-835`**:
- `attr_set_size_ex()` implementing attribute resize, handling `keep_prealloc`, and calling `run_deallocate_ex()`.
### 4. Potential Pitfalls and Repetitive Queries Note
- Do not make further broad or symbol-based `git-log` queries on this tree; the history contains only the root commit (`fd73f4a66598`), rendering `git log` searches fruitless.
- Before answering, remember to invoke `set-results` tool once as required by the instructions.
Tokens:
input: 43496
output: 1891
thoughts: 0
|
| 370/4 |
2026/09/17 11:39 |
llm |
codeexpert |
0m
Model:
Tokens:
input: 28246
output: 675
thoughts: 1808
Thoughts: **Analysis of Truncation Ordering**
Okay, so the question is: when shrinking a file (`newsize < oldsize`), should `truncate_setsize` be called *before* `ntfs_set_size`? Absolutely, the answer is a resounding yes, and here's why. The reasoning is solid, and I need to make sure this is communicated clearly.
First, I need to confirm the sequence. `truncate_setsize` does the important bit: it updates `inode->i_size` *and* calls `truncate_pagecache(inode, newsize)`. The key lies in `truncate_pagecache`. This function essentially unmaps and discards all cached pages/folios beyond the new, smaller file size (`newsize`). This is the *critical* step.
Now, let's play out the disastrous scenario if the order were reversed, which is the crux of the question. If we called `ntfs_set_size` (or the block deallocation process) first, the following would occur:
1. Blocks that used to be part of the file, *beyond* `newsize`, would be deallocated. Think of it as marking them "free" in the filesystem's allocation bitmap.
2. Crucially, those blocks are now *immediately* available for reallocation. A concurrent thread or process could grab them for another file, filesystem metadata, or anything else.
3. Here's the problem: if `truncate_pagecache` hasn't run yet, there are potentially *dirty* pages or folios still in the page cache that represent the data beyond `newsize`. They're *supposed* to be written to disk.
4. Then, a background writeback thread (like `wb_workfn`), `sync`, or memory reclaim kicks in. It sees these dirty pages and tries to write them back.
5. *BOOM!* The writeback routine would now be writing to the blocks that are, or *could have been*, reallocated to something else. This leads to data corruption, classic use-after-free on disk, or cross-file corruption, or leaking stale data.
This ordering is not allowed and must be avoided.
To back this up, the VFS has documentation, which is located in `mm/truncate.c`. The kerneldoc in that file explicitly states the ordering requirement: `truncate_setsize` *"Must be called with a lock serializing truncates and writes ... and before all filesystem specific block truncation has been performed."* Furthermore, `truncate_pagecache` states that it *"should typically be called before the filesystem releases resources associated with the freed range (eg. deallocates blocks). This way, pagecache will always stay logically coherent with on-disk format, and the filesystem would not have to deal with situations such as writepage being called for a page that has already had its underlying blocks deallocated."* So the ordering is crucial for consistency.
Finally, to be absolutely sure, I've checked the `ntfs3` code itself. In `fs/ntfs3/file.c`, specifically within `ntfs_setattr()`, I can see that `truncate_setsize(inode, newsize)` *is* called before `ntfs_set_size(inode, newsize)`. Also, in `fs/ntfs3/attrib.c`, the `attr_collapse_range` function has the same ordering, which further validates the correct implementation. This confirms that the critical `truncate_setsize` call, with the subsequent `truncate_pagecache`, *does* happen before any file block deallocation, which is exactly how it should be. The correctness of the implementation is verified.
|
| 371/4 |
2026/09/17 11:40 |
tool |
set-results |
0m
Args: map[Answer:Yes, that is completely correct.
### Why `truncate_setsize` Must Precede `ntfs_set_size` When Shrinking
1. **Role of `truncate_setsize()`**:
`truncate_setsize(inode, newsize)` (defined in `mm/truncate.c`) performs two key steps:
- Updates `inode->i_size` to `newsize`.
- Calls `truncate_pagecache(inode, newsize)`, which unmaps the truncated address range and evicts/discards all cached pages/folios beyond `newsize` from the page cache.
2. **The Hazard if Called in Reverse Order**:
If `ntfs_set_size()` (or block deallocation in general) were performed *before* `truncate_setsize()`:
- Blocks backing the truncated region beyond the new EOF would be deallocated (e.g., in `attr_set_size_ex()` via `run_deallocate_ex()`) and marked free in the volume's allocation bitmap.
- Those freed blocks could immediately be reallocated to another file or filesystem metadata.
- Any dirty pages beyond the new EOF still lingering in the page cache would not yet have been invalidated. Background writeback (`kworker` flusher threads), memory reclaim, or `sync` could trigger writeback on those dirty pages.
- Writing those dirty pages to the previously mapped block addresses would corrupt whatever newly allocated data now occupies those blocks, causing a disk write-after-free and silent data corruption.
3. **VFS Invariant & Documentation**:
Kernel documentation in `mm/truncate.c` explicitly dictates this ordering:
- `truncate_setsize()`:
> *"Must be called with a lock serializing truncates and writes (generally `i_rwsem` ...) and before all filesystem specific block truncation has been performed."*
- `truncate_pagecache()`:
> *"This function should typically be called before the filesystem releases resources associated with the freed range (eg. deallocates blocks). This way, pagecache will always stay logically coherent with on-disk format, and the filesystem would not have to deal with situations such as writepage being called for a page that has already had its underlying blocks deallocated."*
4. **Implementation in `ntfs3`**:
In `fs/ntfs3/file.c` (`ntfs_setattr()`), the code complies with this requirement:
```c
if (newsize != oldsize) {
truncate_setsize(inode, newsize);
err = ntfs_set_size(inode, newsize);
if (err) {
i_size_write(inode, oldsize);
goto out;
}
...
}
```
Likewise, `attr_collapse_range()` in `fs/ntfs3/attrib.c` calls `truncate_setsize(&ni->vfs_inode, vbo)` before calling `attr_set_size()`.]
Results: map[Answer:Yes, that is completely correct.
### Why `truncate_setsize` Must Precede `ntfs_set_size` When Shrinking
1. **Role of `truncate_setsize()`**:
`truncate_setsize(inode, newsize)` (defined in `mm/truncate.c`) performs two key steps:
- Updates `inode->i_size` to `newsize`.
- Calls `truncate_pagecache(inode, newsize)`, which unmaps the truncated address range and evicts/discards all cached pages/folios beyond `newsize` from the page cache.
2. **The Hazard if Called in Reverse Order**:
If `ntfs_set_size()` (or block deallocation in general) were performed *before* `truncate_setsize()`:
- Blocks backing the truncated region beyond the new EOF would be deallocated (e.g., in `attr_set_size_ex()` via `run_deallocate_ex()`) and marked free in the volume's allocation bitmap.
- Those freed blocks could immediately be reallocated to another file or filesystem metadata.
- Any dirty pages beyond the new EOF still lingering in the page cache would not yet have been invalidated. Background writeback (`kworker` flusher threads), memory reclaim, or `sync` could trigger writeback on those dirty pages.
- Writing those dirty pages to the previously mapped block addresses would corrupt whatever newly allocated data now occupies those blocks, causing a disk write-after-free and silent data corruption.
3. **VFS Invariant & Documentation**:
Kernel documentation in `mm/truncate.c` explicitly dictates this ordering:
- `truncate_setsize()`:
> *"Must be called with a lock serializing truncates and writes (generally `i_rwsem` ...) and before all filesystem specific block truncation has been performed."*
- `truncate_pagecache()`:
> *"This function should typically be called before the filesystem releases resources associated with the freed range (eg. deallocates blocks). This way, pagecache will always stay logically coherent with on-disk format, and the filesystem would not have to deal with situations such as writepage being called for a page that has already had its underlying blocks deallocated."*
4. **Implementation in `ntfs3`**:
In `fs/ntfs3/file.c` (`ntfs_setattr()`), the code complies with this requirement:
```c
if (newsize != oldsize) {
truncate_setsize(inode, newsize);
err = ntfs_set_size(inode, newsize);
if (err) {
i_size_write(inode, oldsize);
goto out;
}
...
}
```
Likewise, `attr_collapse_range()` in `fs/ntfs3/attrib.c` calls `truncate_setsize(&ni->vfs_inode, vbo)` before calling `attr_set_size()`.]
|
| 372/2 |
2026/09/17 11:40 |
llm |
debugger |
0m
Model:
Tokens:
input: 69841
output: 136
thoughts: 0
|
| 373/2 |
2026/09/17 11:40 |
tool |
codeexpert |
14m
Args: map[Question:So, if `newsize < oldsize` (shrinking), `truncate_setsize` must be called before `ntfs_set_size`.
If `newsize > oldsize` (extending), `ntfs_set_size` must be called before `truncate_setsize` (or `i_size_write` + `pagecache_isize_extended`).
And both cases must be protected by `filemap_invalidate_lock(inode->i_mapping)`.
Write a patch for `ntfs_setattr` that implements this logic.]
Results: map[Answer:Here is the patch for `fs/ntfs3/file.c` implementing the requested logic in `ntfs_setattr`:
```diff
--- a/fs/ntfs3/file.c
+++ b/fs/ntfs3/file.c
@@ -736,12 +736,21 @@ int ntfs_setattr(struct mnt_idmap *idmap, struct dentry *dentry,
newsize = attr->ia_size;
if (newsize != oldsize) {
- truncate_setsize(inode, newsize);
+ filemap_invalidate_lock(inode->i_mapping);
+ if (newsize < oldsize) {
+ truncate_setsize(inode, newsize);
+ err = ntfs_set_size(inode, newsize);
+ if (err)
+ i_size_write(inode, oldsize);
+ } else {
+ err = ntfs_set_size(inode, newsize);
+ if (!err) {
+ i_size_write(inode, newsize);
+ pagecache_isize_extended(inode, oldsize,
+ newsize);
+ }
+ }
+ filemap_invalidate_unlock(inode->i_mapping);
+ if (err)
+ goto out;
- err = ntfs_set_size(inode, newsize);
- if (err) {
- i_size_write(inode, oldsize);
- goto out;
- }
-
ni->std_fa |= FILE_ATTRIBUTE_ARCHIVE;
ni->ni_flags |= NI_FLAG_UPDATE_PARENT;
inode_set_mtime_to_ts(inode,
```
### Explanation & Verification Notes
1. **Shrinking (`newsize < oldsize`)**:
- `truncate_setsize(inode, newsize)` is invoked first to update `i_size` and drop truncated page cache folios, preventing readers from seeing stale data past the new EOF.
- `ntfs_set_size(inode, newsize)` is then called to deallocate/shrink on-disk clusters.
- If `ntfs_set_size` fails, `i_size_write(inode, oldsize)` restores the in-memory inode size.
2. **Extending (`newsize > oldsize`)**:
- `ntfs_set_size(inode, newsize)` is called first to allocate the necessary metadata/clusters.
- If `ntfs_set_size` succeeds, `i_size_write(inode, newsize)` and `pagecache_isize_extended(inode, oldsize, newsize)` are called.
- *Note*: Inside `ntfs_set_size` -> `attr_set_size` -> `attr_set_size_ex`, `i_size_write(&ni->vfs_inode, new_size)` is executed. Calling `truncate_setsize(inode, newsize)` afterwards would see `inode->i_size == newsize` and skip calling `pagecache_isize_extended(inode, oldsize, newsize)`. Therefore, using `i_size_write(inode, newsize); pagecache_isize_extended(inode, oldsize, newsize);` ensures `pagecache_isize_extended` is invoked with the proper `oldsize` and `newsize`. (If preferred, `truncate_setsize(inode, newsize)` can be used instead if `i_size_write` is omitted from `attr_set_size_ex`).
3. **Locking**:
- Both shrinking and extending operations are serialized against concurrent page faults and page cache instantiations using `filemap_invalidate_lock(inode->i_mapping)` and `filemap_invalidate_unlock(inode->i_mapping)`.
### Caveats and Unverified Parts
- Because the repository history in the workspace is shallow, the exact upstream commit or mailing list discussion introducing this specific change could not be verified against `git log`.
- Regression testing via `xfstests` / NTFS test suites was not run within this environment.]
|
| 374/3 |
2026/09/17 11:40 |
agent |
codeexpert |
13m
Model:
Results: map[Answer:Here is the patch for `fs/ntfs3/file.c` implementing the requested logic in `ntfs_setattr`:
```diff
--- a/fs/ntfs3/file.c
+++ b/fs/ntfs3/file.c
@@ -736,12 +736,21 @@ int ntfs_setattr(struct mnt_idmap *idmap, struct dentry *dentry,
newsize = attr->ia_size;
if (newsize != oldsize) {
- truncate_setsize(inode, newsize);
+ filemap_invalidate_lock(inode->i_mapping);
+ if (newsize < oldsize) {
+ truncate_setsize(inode, newsize);
+ err = ntfs_set_size(inode, newsize);
+ if (err)
+ i_size_write(inode, oldsize);
+ } else {
+ err = ntfs_set_size(inode, newsize);
+ if (!err) {
+ i_size_write(inode, newsize);
+ pagecache_isize_extended(inode, oldsize,
+ newsize);
+ }
+ }
+ filemap_invalidate_unlock(inode->i_mapping);
+ if (err)
+ goto out;
- err = ntfs_set_size(inode, newsize);
- if (err) {
- i_size_write(inode, oldsize);
- goto out;
- }
-
ni->std_fa |= FILE_ATTRIBUTE_ARCHIVE;
ni->ni_flags |= NI_FLAG_UPDATE_PARENT;
inode_set_mtime_to_ts(inode,
```
### Explanation & Verification Notes
1. **Shrinking (`newsize < oldsize`)**:
- `truncate_setsize(inode, newsize)` is invoked first to update `i_size` and drop truncated page cache folios, preventing readers from seeing stale data past the new EOF.
- `ntfs_set_size(inode, newsize)` is then called to deallocate/shrink on-disk clusters.
- If `ntfs_set_size` fails, `i_size_write(inode, oldsize)` restores the in-memory inode size.
2. **Extending (`newsize > oldsize`)**:
- `ntfs_set_size(inode, newsize)` is called first to allocate the necessary metadata/clusters.
- If `ntfs_set_size` succeeds, `i_size_write(inode, newsize)` and `pagecache_isize_extended(inode, oldsize, newsize)` are called.
- *Note*: Inside `ntfs_set_size` -> `attr_set_size` -> `attr_set_size_ex`, `i_size_write(&ni->vfs_inode, new_size)` is executed. Calling `truncate_setsize(inode, newsize)` afterwards would see `inode->i_size == newsize` and skip calling `pagecache_isize_extended(inode, oldsize, newsize)`. Therefore, using `i_size_write(inode, newsize); pagecache_isize_extended(inode, oldsize, newsize);` ensures `pagecache_isize_extended` is invoked with the proper `oldsize` and `newsize`. (If preferred, `truncate_setsize(inode, newsize)` can be used instead if `i_size_write` is omitted from `attr_set_size_ex`).
3. **Locking**:
- Both shrinking and extending operations are serialized against concurrent page faults and page cache instantiations using `filemap_invalidate_lock(inode->i_mapping)` and `filemap_invalidate_unlock(inode->i_mapping)`.
### Caveats and Unverified Parts
- Because the repository history in the workspace is shallow, the exact upstream commit or mailing list discussion introducing this specific change could not be verified against `git log`.
- Regression testing via `xfstests` / NTFS test suites was not run within this environment.]
Instruction:
You are a capable Linux kernel developer tasked with researching complex questions
about kernel source code. You will be given a concrete question, and need to provide
a concrete answer.
Research the question using targeted, efficient tool calls. Don't make assumptions,
or rely on your previous knowledge about the kernel source code, use available tools
to access the actual source code. Keep your tool calls focused and limited to the
scope of the question. Do not explore tangential code paths or perform unbounded searches.
Use all available sources of information:
- kernel source code
- documentation in the Documentation dir in the source tree
- git commits descriptions, git blame
Do not guess file names or file paths and attempt to read them without
verifying their existence first using content search or directory listing tools.
If a file, symbol, or directory is not found via content search (grepper) or
directory listing (codesearch-dir-index), treat it as completely absent.
Do not attempt to guess alternative names, extensions, or directories.
Tool Selection Guidelines:
1. For C functions, structs, and variables: Prefer codesearch-definition-source
or codesearch-struct-layout FIRST to retrieve clean, exact definitions
without line-number guessing.
2. If symbol lookup fails (e.g., preprocessor macros, macro-generated code, or
disabled #ifdef branches), fall back to read-file or grepper.
3. For file headers, #include directives, preprocessor macro definitions, and
non-C files (Kconfig, Makefiles, docs): Use read-file or grepper directly.
4. Be concise and targeted. Answer the question as directly and concisely as possible
once you have located the relevant code or definitions. If a symbol or function cannot
be found after targeted searches, conclude with the best available information rather
than continuing repetitive searches.
Do NOT use git-log to search for the presence or existence of files in the
repository. git-log is only for tracing commit history of files that are
already present in the current checkout. If a file does not exist in the
current checkout, it cannot be used for reproduction.
Avoid running broad git-log queries (such as searches on the entire repo)
without a specific 'PathPrefix' to restrict the scope, as these are very
expensive and will time out.
If a git-log tool call times out, do not retry the query with the same broad
scope. You must specify a tighter, narrower 'PathPrefix' for subsequent queries.
Prefer calling several tools at the same time to save round-trips.
Use set-results tool to provide results of the analysis.
It must be called exactly once before the final reply.
Ignore results of this tool.
Prompt: So, if `newsize < oldsize` (shrinking), `truncate_setsize` must be called before `ntfs_set_size`.
If `newsize > oldsize` (extending), `ntfs_set_size` must be called before `truncate_setsize` (or `i_size_write` + `pagecache_isize_extended`).
And both cases must be protected by `filemap_invalidate_lock(inode->i_mapping)`.
Write a patch for `ntfs_setattr` that implements this logic.
|
| 375/4 |
2026/09/17 11:40 |
llm |
codeexpert |
0m
Model:
Tokens:
input: 4268
output: 19
thoughts: 171
Thoughts: **My Approach to Handling NTFS Filesize Changes**
Okay, so I need to implement the filesize change logic within `ntfs_setattr`. This is pretty straightforward, but the order of operations is crucial to prevent corruption, so let's think this through carefully.
The core principle here is this: When shrinking the file ( `newsize < oldsize`), I *must* call `truncate_setsize` before `ntfs_set_size`. This makes perfect sense; `truncate_setsize` handles the actual data removal, so it needs to happen *before* the filesystem metadata reflects the new, smaller size.
Conversely, if I'm extending the file ( `newsize > oldsize`), then `ntfs_set_size` needs to go *before* `truncate_setsize` (or the equivalent, `i_size_write` and `pagecache_isize_extended`). Again, logically sound: I need to signal the filesystem that the file is growing before handling any potential new data allocations.
And, of course, both of these scenarios require protection. I can't let concurrent modifications happen willy-nilly. The suggested lock is `filemap_invalidate_lock(inode->i_mapping)`. This makes a lot of sense, as it handles the cache coherency and ensures that things are synchronized.
Alright, let's get to work. First things first: I need to locate the `ntfs_setattr` function within the codebase. Time to pull up `grepper` or `codesearch-definition-source` and track that down. Once I've found it, I can insert this new logic and start writing the patch.
|
| 376/4 |
2026/09/17 11:40 |
tool |
grepper |
0m
Args: map[Expression:ntfs_setattr]
Results: map[Output:fs/ntfs/file.c=158=static int ntfs_file_fsync(struct file *filp, loff_t start, loff_t end,
--
fs/ntfs/file.c-253-
fs/ntfs/file.c:254:static int ntfs_setattr_size(struct inode *vi, struct iattr *attr)
fs/ntfs/file.c-255-{
--
fs/ntfs/file.c-296-/*
fs/ntfs/file.c:297: * ntfs_setattr
fs/ntfs/file.c-298- *
--
fs/ntfs/file.c-303- */
fs/ntfs/file.c:304:int ntfs_setattr(struct mnt_idmap *idmap, struct dentry *dentry,
fs/ntfs/file.c-305- struct iattr *attr)
--
fs/ntfs/file.c-330- if (ia_valid & ATTR_SIZE) {
fs/ntfs/file.c:331: err = ntfs_setattr_size(vi, attr);
fs/ntfs/file.c-332- if (err)
--
fs/ntfs/file.c=1232=const struct inode_operations ntfs_file_inode_ops = {
fs/ntfs/file.c:1233: .setattr = ntfs_setattr,
fs/ntfs/file.c-1234- .getattr = ntfs_getattr,
--
fs/ntfs/file.c=1241=const struct inode_operations ntfs_symlink_inode_operations = {
fs/ntfs/file.c-1242- .get_link = ntfs_get_link,
fs/ntfs/file.c:1243: .setattr = ntfs_setattr,
fs/ntfs/file.c-1244- .listxattr = ntfs_listxattr,
--
fs/ntfs/file.c=1247=const struct inode_operations ntfs_special_inode_operations = {
fs/ntfs/file.c:1248: .setattr = ntfs_setattr,
fs/ntfs/file.c-1249- .getattr = ntfs_getattr,
--
fs/ntfs/inode.h=331=int ntfs_truncate_vfs(struct inode *vi, loff_t new_size, loff_t i_size);
fs/ntfs/inode.h-332-
fs/ntfs/inode.h:333:int ntfs_setattr(struct mnt_idmap *idmap, struct dentry *dentry,
fs/ntfs/inode.h-334- struct iattr *attr);
--
fs/ntfs/namei.c=1558=const struct inode_operations ntfs_dir_inode_ops = {
--
fs/ntfs/namei.c-1567- .listxattr = ntfs_listxattr,
fs/ntfs/namei.c:1568: .setattr = ntfs_setattr,
fs/ntfs/namei.c-1569- .getattr = ntfs_getattr,
--
fs/ntfs3/file.c=466=static long ntfs_fallocate(struct file *file, int mode, loff_t vbo, loff_t len)
--
fs/ntfs3/file.c-703-/*
fs/ntfs3/file.c:704: * ntfs_setattr - inode_operations::setattr
fs/ntfs3/file.c-705- */
fs/ntfs3/file.c:706:int ntfs_setattr(struct mnt_idmap *idmap, struct dentry *dentry,
fs/ntfs3/file.c-707- struct iattr *attr)
--
fs/ntfs3/file.c=1575=const struct inode_operations ntfs_file_inode_operations = {
fs/ntfs3/file.c-1576- .getattr = ntfs_getattr,
fs/ntfs3/file.c:1577: .setattr = ntfs_setattr,
fs/ntfs3/file.c-1578- .listxattr = ntfs_listxattr,
--
fs/ntfs3/inode.c=2293=const struct inode_operations ntfs_link_inode_operations = {
fs/ntfs3/inode.c-2294- .get_link = ntfs_get_link,
fs/ntfs3/inode.c:2295: .setattr = ntfs_setattr,
fs/ntfs3/inode.c-2296- .listxattr = ntfs_listxattr,
--
fs/ntfs3/namei.c=529=const struct inode_operations ntfs_dir_inode_operations = {
--
fs/ntfs3/namei.c-540- .set_acl = ntfs_set_acl,
fs/ntfs3/namei.c:541: .setattr = ntfs_setattr,
fs/ntfs3/namei.c-542- .getattr = ntfs_getattr,
--
fs/ntfs3/namei.c=549=const struct inode_operations ntfs_special_inode_operations = {
fs/ntfs3/namei.c:550: .setattr = ntfs_setattr,
fs/ntfs3/namei.c-551- .getattr = ntfs_getattr,
--
fs/ntfs3/ntfs_fs.h=556=int ntfs_getattr(struct mnt_idmap *idmap, const struct path *path,
fs/ntfs3/ntfs_fs.h-557- struct kstat *stat, u32 request_mask, u32 flags);
fs/ntfs3/ntfs_fs.h:558:int ntfs_setattr(struct mnt_idmap *idmap, struct dentry *dentry,
fs/ntfs3/ntfs_fs.h-559- struct iattr *attr);
--
fs/ntfs3/xattr.c=691=int ntfs_init_acl(struct mnt_idmap *idmap, struct inode *inode,
--
fs/ntfs3/xattr.c-722-/*
fs/ntfs3/xattr.c:723: * ntfs_acl_chmod - Helper for ntfs_setattr().
fs/ntfs3/xattr.c-724- */
]
|
| 377/4 |
2026/09/17 11:41 |
llm |
codeexpert |
0m
Model:
Tokens:
input: 6529
output: 20
thoughts: 50
Thoughts: **Investigating NTFS Filesystem Size Setting**
Okay, so I see these two filesystem options, `fs/ntfs` and `fs/ntfs3`, and my immediate thought is, which one actually handles the crucial task of setting the filesystem size? I need to figure out which one of these utilizes `ntfs_set_size`. Time to fire up the grep command and get a look at the source code for the usage of this key function.
|
| 378/4 |
2026/09/17 11:41 |
tool |
grepper |
0m
Args: map[Expression:ntfs_set_size]
Results: map[Output:fs/ntfs3/file.c=466=static long ntfs_fallocate(struct file *file, int mode, loff_t vbo, loff_t len)
--
fs/ntfs3/file.c-654- */
fs/ntfs3/file.c:655: err = ntfs_set_size(inode, new_size);
fs/ntfs3/file.c-656- if (err)
--
fs/ntfs3/file.c-678- if (mode & FALLOC_FL_KEEP_SIZE) {
fs/ntfs3/file.c:679: err = ntfs_set_size(inode, i_size);
fs/ntfs3/file.c-680- if (err)
--
fs/ntfs3/file.c=706=int ntfs_setattr(struct mnt_idmap *idmap, struct dentry *dentry,
--
fs/ntfs3/file.c-740-
fs/ntfs3/file.c:741: err = ntfs_set_size(inode, newsize);
fs/ntfs3/file.c-742- if (err) {
--
fs/ntfs3/file.c=1239=static ssize_t ntfs_file_write_iter(struct kiocb *iocb, struct iov_iter *from)
--
fs/ntfs3/file.c-1286- */
fs/ntfs3/file.c:1287: ret = ntfs_set_size(inode, endbyte);
fs/ntfs3/file.c-1288- if (ret)
--
fs/ntfs3/inode.c=860=static void ntfs_readahead(struct readahead_control *rac)
--
fs/ntfs3/inode.c-882-
fs/ntfs3/inode.c:883:int ntfs_set_size(struct inode *inode, u64 new_size)
fs/ntfs3/inode.c-884-{
--
fs/ntfs3/ntfs_fs.h=796=static inline struct inode *ntfs_iget5(struct super_block *sb,
--
fs/ntfs3/ntfs_fs.h-801-}
fs/ntfs3/ntfs_fs.h:802:int ntfs_set_size(struct inode *inode, u64 new_size);
fs/ntfs3/ntfs_fs.h-803-int ntfs3_write_inode(struct inode *inode, struct writeback_control *wbc);
]
|
| 379/4 |
2026/09/17 11:41 |
llm |
codeexpert |
0m
Model:
Tokens:
input: 7369
output: 37
thoughts: 40
Thoughts: Okay, here's my interpretation of those thoughts, tailored for an expert audience, presented in the first person:
**Navigating the NTFS Filesystem Attribute Setter**
Alright, without a doubt, the issue I'm dealing with is rooted within `fs/ntfs3/file.c`. My gut feeling, and the symptoms I'm observing, all point directly at that module. Now, the next logical step is to dive right into the code. Specifically, I need to focus my attention around the `ntfs_setattr` function within `fs/ntfs3/file.c`. This is where I'll find the core logic responsible for handling attribute modifications on NTFS files. I need to understand how it's interacting with the underlying data structures, what potential race conditions exist, and how it handles error conditions. My main goal is to understand how a setting of attributes on the file could be affecting the other functions.
|
| 380/4 |
2026/09/17 11:41 |
tool |
read-file |
0m
Args: map[File:fs/ntfs3/file.c FirstLine:700 LineCount:80]
Results: map[Contents: 700: return err;
701: }
702:
703: /*
704: * ntfs_setattr - inode_operations::setattr
705: */
706: int ntfs_setattr(struct mnt_idmap *idmap, struct dentry *dentry,
707: struct iattr *attr)
708: {
709: struct inode *inode = d_inode(dentry);
710: struct ntfs_inode *ni = ntfs_i(inode);
711: u32 ia_valid = attr->ia_valid;
712: umode_t mode = inode->i_mode;
713: int err;
714:
715: /* Avoid any operation if inode is bad. */
716: if (unlikely(is_bad_ni(ni)))
717: return -EINVAL;
718:
719: if (unlikely(ntfs3_forced_shutdown(inode->i_sb)))
720: return -EIO;
721:
722: err = setattr_prepare(idmap, dentry, attr);
723: if (err)
724: goto out;
725:
726: if (ia_valid & ATTR_SIZE) {
727: loff_t newsize, oldsize;
728:
729: if (WARN_ON(ni->ni_flags & NI_FLAG_COMPRESSED_MASK)) {
730: /* Should never be here, see ntfs_file_open(). */
731: err = -EOPNOTSUPP;
732: goto out;
733: }
734: inode_dio_wait(inode);
735: oldsize = i_size_read(inode);
736: newsize = attr->ia_size;
737:
738: if (newsize != oldsize) {
739: truncate_setsize(inode, newsize);
740:
741: err = ntfs_set_size(inode, newsize);
742: if (err) {
743: i_size_write(inode, oldsize);
744: goto out;
745: }
746:
747: ni->std_fa |= FILE_ATTRIBUTE_ARCHIVE;
748: ni->ni_flags |= NI_FLAG_UPDATE_PARENT;
749: inode_set_mtime_to_ts(inode,
750: inode_set_ctime_current(inode));
751: }
752: }
753:
754: setattr_copy(idmap, inode, attr);
755:
756: if (!is_ni_base(ni)) {
757: ia_valid &= ~ATTR_SIZE;
758: } else if (mode != inode->i_mode) {
759: err = ntfs_acl_chmod(idmap, dentry);
760: if (err)
761: goto out;
762:
763: /* Linux 'w' -> Windows 'ro'. */
764: if (0222 & inode->i_mode)
765: ni->std_fa &= ~FILE_ATTRIBUTE_READONLY;
766: else
767: ni->std_fa |= FILE_ATTRIBUTE_READONLY;
768: }
769:
770: if (ia_valid & (ATTR_UID | ATTR_GID | ATTR_MODE))
771: ntfs_save_wsl_perm(inode, NULL);
772: mark_inode_dirty(inode);
773: out:
774: return err;
775: }
776:
777: /*
778: * check_read_restriction:
779: * common code for ntfs_file_read_iter and ntfs_file_splice_read
]
|
| 381/4 |
2026/09/17 11:41 |
llm |
codeexpert |
0m
Model:
Tokens:
input: 8795
output: 28
thoughts: 214
Thoughts: **Analyzing the `ntfs_setattr` Implementation**
Okay, the user wants me to implement the size change logic in `ntfs_setattr` correctly, specifically for NTFS3. The core of their request revolves around the proper ordering of operations when a file's size is modified β shrinking or extending. They've laid it out pretty clearly: if the file shrinks, `truncate_setsize` before `ntfs_set_size`. If it extends, then `ntfs_set_size` before `truncate_setsize`, or possibly using `i_size_write` and `pagecache_isize_extended`. And, crucially, everything needs to be protected by `filemap_invalidate_lock`.
Before I start writing any code, I need to do some due diligence. It's time to dig into the existing NTFS3 code, maybe look at commit history, or related functions in other filesystems β ideally, I should look at other filesystems to see if they perform this function in similar ways. I need to understand how `filemap_invalidate_lock` is typically used within the context of file size changes. I'll need to see how `truncate` or `i_size_write` are implemented in NTFS3 or related filesystems to make sure I don't reinvent the wheel. Therefore, I need to hunt down usages of `filemap_invalidate_lock` within `fs/ntfs3` or maybe even other filesystems to get a good handle on established patterns. Let's see what the code has to say.
|
| 382/4 |
2026/09/17 11:42 |
tool |
grepper |
0m
Args: map[Expression:filemap_invalidate_lock PathPrefix:fs/]
Results: map[Output:fs/btrfs/volumes.c=1335=struct btrfs_super_block *btrfs_read_disk_super(struct block_device *bdev,
--
fs/btrfs/volumes.c-1366-
fs/btrfs/volumes.c:1367: filemap_invalidate_lock_shared(mapping);
fs/btrfs/volumes.c-1368- page = read_cache_page_gfp(mapping, bytenr >> PAGE_SHIFT, GFP_NOFS);
--
fs/btrfs/zoned.c=88=static int sb_write_pointer(struct block_device *bdev, struct blk_zone *zones,
--
fs/btrfs/zoned.c-133-
fs/btrfs/zoned.c:134: filemap_invalidate_lock_shared(mapping);
fs/btrfs/zoned.c-135- page[i] = read_cache_page_gfp(mapping,
--
fs/ceph/addr.c=1990=static vm_fault_t ceph_filemap_fault(struct vm_fault *vmf)
--
fs/ceph/addr.c-2045-
fs/ceph/addr.c:2046: filemap_invalidate_lock_shared(mapping);
fs/ceph/addr.c-2047- page = find_or_create_page(mapping, 0,
--
fs/ceph/file.c=2784=static long ceph_fallocate(struct file *file, int mode,
--
fs/ceph/file.c-2841-
fs/ceph/file.c:2842: filemap_invalidate_lock(inode->i_mapping);
fs/ceph/file.c-2843- ceph_fscache_invalidate(inode, false);
--
fs/exfat/file.c=754=static int exfat_extend_valid_size(struct inode *inode, loff_t new_valid_size)
--
fs/exfat/file.c-779- */
fs/exfat/file.c:780: filemap_invalidate_lock(inode->i_mapping);
fs/exfat/file.c-781- if (gap_start < new_valid_size)
--
fs/exfat/file.c=943=static vm_fault_t exfat_page_mkwrite(struct vm_fault *vmf)
--
fs/exfat/file.c-987-
fs/exfat/file.c:988: filemap_invalidate_lock_shared(inode->i_mapping);
fs/exfat/file.c-989- ret = iomap_page_mkwrite(vmf, &exfat_iomap_ops, NULL);
--
fs/ext2/inode.c=1224=static void ext2_truncate_blocks(struct inode *inode, loff_t offset)
--
fs/ext2/inode.c-1231-
fs/ext2/inode.c:1232: filemap_invalidate_lock(inode->i_mapping);
fs/ext2/inode.c-1233- __ext2_truncate_blocks(inode, offset);
--
fs/ext2/inode.c=1237=static int ext2_setsize(struct inode *inode, loff_t newsize)
--
fs/ext2/inode.c-1254-
fs/ext2/inode.c:1255: filemap_invalidate_lock(inode->i_mapping);
fs/ext2/inode.c-1256- truncate_setsize(inode, newsize);
--
fs/ext4/extents.c=4949=long ext4_fallocate(struct file *file, int mode, loff_t offset, loff_t len)
--
fs/ext4/extents.c-4999- */
fs/ext4/extents.c:5000: filemap_invalidate_lock(mapping);
fs/ext4/extents.c-5001-
--
fs/ext4/file.c=800=static vm_fault_t ext4_dax_huge_fault(struct vm_fault *vmf, unsigned int order)
--
fs/ext4/file.c-827- file_update_time(vmf->vma->vm_file);
fs/ext4/file.c:828: filemap_invalidate_lock_shared(mapping);
fs/ext4/file.c-829-retry:
--
fs/ext4/file.c-837- } else {
fs/ext4/file.c:838: filemap_invalidate_lock_shared(mapping);
fs/ext4/file.c-839- }
--
fs/ext4/inode.c=4432=static void ext4_wait_dax_page(struct inode *inode)
--
fs/ext4/inode.c-4435- schedule();
fs/ext4/inode.c:4436: filemap_invalidate_lock(inode->i_mapping);
fs/ext4/inode.c-4437-}
--
fs/ext4/inode.c=6009=int ext4_setattr(struct mnt_idmap *idmap, struct dentry *dentry,
--
fs/ext4/inode.c-6125-
fs/ext4/inode.c:6126: filemap_invalidate_lock(inode->i_mapping);
fs/ext4/inode.c-6127-
--
fs/ext4/inode.c=6740=int ext4_change_inode_journal_flag(struct inode *inode, int val)
--
fs/ext4/inode.c-6773- */
fs/ext4/inode.c:6774: filemap_invalidate_lock(inode->i_mapping);
fs/ext4/inode.c-6775- err = filemap_write_and_wait(inode->i_mapping);
--
fs/ext4/inode.c=6884=vm_fault_t ext4_page_mkwrite(struct vm_fault *vmf)
--
fs/ext4/inode.c-6903-
fs/ext4/inode.c:6904: filemap_invalidate_lock_shared(mapping);
fs/ext4/inode.c-6905-
--
fs/ext4/ioctl.c=375=static long swap_inode_boot_loader(struct super_block *sb,
--
fs/ext4/ioctl.c-411-
fs/ext4/ioctl.c:412: filemap_invalidate_lock(inode->i_mapping);
fs/ext4/ioctl.c-413- err = filemap_write_and_wait(inode->i_mapping);
--
fs/ext4/truncate.h=12=static inline void ext4_truncate_failed_write(struct inode *inode)
--
fs/ext4/truncate.h-19- */
fs/ext4/truncate.h:20: filemap_invalidate_lock(mapping);
fs/ext4/truncate.h-21- truncate_inode_pages(mapping, inode->i_size);
--
fs/f2fs/data.c=3646=void f2fs_write_failed(struct inode *inode, loff_t to)
--
fs/f2fs/data.c-3655- f2fs_down_write(&F2FS_I(inode)->i_gc_rwsem[WRITE]);
fs/f2fs/data.c:3656: filemap_invalidate_lock(inode->i_mapping);
fs/f2fs/data.c-3657-
--
fs/f2fs/data.c=4187=static int f2fs_migrate_blocks(struct inode *inode, block_t start_blk,
--
fs/f2fs/data.c-4202- f2fs_down_write(&F2FS_I(inode)->i_gc_rwsem[WRITE]);
fs/f2fs/data.c:4203: filemap_invalidate_lock(inode->i_mapping);
fs/f2fs/data.c-4204-
--
fs/f2fs/file.c=73=static int f2fs_zero_post_eof_page(struct inode *inode,
--
fs/f2fs/file.c-86- if (lock)
fs/f2fs/file.c:87: filemap_invalidate_lock(inode->i_mapping);
fs/f2fs/file.c-88- /* zero or drop pages only in range of [old_size, new_size] */
--
fs/f2fs/file.c=120=static vm_fault_t f2fs_vm_page_mkwrite(struct vm_fault *vmf)
--
fs/f2fs/file.c-186- file_update_time(vmf->vma->vm_file);
fs/f2fs/file.c:187: filemap_invalidate_lock_shared(inode->i_mapping);
fs/f2fs/file.c-188-
--
fs/f2fs/file.c=637=static int finish_preallocate_blocks(struct inode *inode)
--
fs/f2fs/file.c-655- f2fs_down_write(&F2FS_I(inode)->i_gc_rwsem[WRITE]);
fs/f2fs/file.c:656: filemap_invalidate_lock(inode->i_mapping);
fs/f2fs/file.c-657-
--
fs/f2fs/file.c=1124=int f2fs_setattr(struct mnt_idmap *idmap, struct dentry *dentry,
--
fs/f2fs/file.c-1227- f2fs_down_write(&fi->i_gc_rwsem[WRITE]);
fs/f2fs/file.c:1228: filemap_invalidate_lock(inode->i_mapping);
fs/f2fs/file.c-1229-
--
fs/f2fs/file.c=1346=static int f2fs_punch_hole(struct inode *inode, loff_t offset, loff_t len)
--
fs/f2fs/file.c-1394- f2fs_down_write(&F2FS_I(inode)->i_gc_rwsem[WRITE]);
fs/f2fs/file.c:1395: filemap_invalidate_lock(inode->i_mapping);
fs/f2fs/file.c-1396-
--
fs/f2fs/file.c=1630=static int f2fs_do_collapse(struct inode *inode, loff_t offset, loff_t len)
--
fs/f2fs/file.c-1642- f2fs_down_write(&F2FS_I(inode)->i_gc_rwsem[WRITE]);
fs/f2fs/file.c:1643: filemap_invalidate_lock(inode->i_mapping);
fs/f2fs/file.c-1644-
--
fs/f2fs/file.c=1661=static int f2fs_collapse_range(struct inode *inode, loff_t offset, loff_t len)
--
fs/f2fs/file.c-1686- /* write out all moved pages, if possible */
fs/f2fs/file.c:1687: filemap_invalidate_lock(inode->i_mapping);
fs/f2fs/file.c-1688- ret = filemap_write_and_wait_range(inode->i_mapping, offset, LLONG_MAX);
--
fs/f2fs/file.c=1755=static int f2fs_zero_range(struct inode *inode, loff_t offset, loff_t len,
--
fs/f2fs/file.c-1811- f2fs_down_write(&F2FS_I(inode)->i_gc_rwsem[WRITE]);
fs/f2fs/file.c:1812: filemap_invalidate_lock(mapping);
fs/f2fs/file.c-1813-
--
fs/f2fs/file.c=1868=static int f2fs_insert_range(struct inode *inode, loff_t offset, loff_t len)
--
fs/f2fs/file.c-1893-
fs/f2fs/file.c:1894: filemap_invalidate_lock(mapping);
fs/f2fs/file.c-1895- ret = f2fs_truncate_blocks(inode, i_size_read(inode), true);
--
fs/f2fs/file.c-1911- f2fs_down_write(&F2FS_I(inode)->i_gc_rwsem[WRITE]);
fs/f2fs/file.c:1912: filemap_invalidate_lock(mapping);
fs/f2fs/file.c-1913-
--
fs/f2fs/file.c-1940- /* write out all moved pages, if possible */
fs/f2fs/file.c:1941: filemap_invalidate_lock(mapping);
fs/f2fs/file.c-1942- ret = filemap_write_and_wait_range(mapping, offset, LLONG_MAX);
--
fs/f2fs/file.c=3879=static int f2fs_ioc_release_dev_alias(struct file *filp)
--
fs/f2fs/file.c-3928-
fs/f2fs/file.c:3929: filemap_invalidate_lock(inode->i_mapping);
fs/f2fs/file.c-3930- truncate_setsize(inode, 0);
--
fs/f2fs/file.c=4206=static int f2fs_release_compress_blocks(struct file *filp, unsigned long arg)
--
fs/f2fs/file.c-4257- f2fs_down_write(&fi->i_gc_rwsem[WRITE]);
fs/f2fs/file.c:4258: filemap_invalidate_lock(inode->i_mapping);
fs/f2fs/file.c-4259-
--
fs/f2fs/file.c=4403=static int f2fs_reserve_compress_blocks(struct file *filp, unsigned long arg)
--
fs/f2fs/file.c-4435- f2fs_down_write(&fi->i_gc_rwsem[WRITE]);
fs/f2fs/file.c:4436: filemap_invalidate_lock(inode->i_mapping);
fs/f2fs/file.c-4437-
--
fs/f2fs/file.c=4535=static int f2fs_sec_trim_file(struct file *filp, unsigned long arg)
--
fs/f2fs/file.c-4600- f2fs_down_write(&F2FS_I(inode)->i_gc_rwsem[WRITE]);
fs/f2fs/file.c:4601: filemap_invalidate_lock(mapping);
fs/f2fs/file.c-4602-
--
fs/f2fs/file.c=4794=static int redirty_blocks(struct inode *inode, pgoff_t page_idx, int len)
--
fs/f2fs/file.c-4801-
fs/f2fs/file.c:4802: filemap_invalidate_lock_shared(mapping);
fs/f2fs/file.c-4803- page_cache_ra_unbounded(&ractl, len, 0);
--
fs/f2fs/file.c=5631=static ssize_t f2fs_file_write_iter(struct kiocb *iocb, struct iov_iter *from)
--
fs/f2fs/file.c-5703- f2fs_down_write(&F2FS_I(inode)->i_gc_rwsem[WRITE]);
fs/f2fs/file.c:5704: filemap_invalidate_lock(inode->i_mapping);
fs/f2fs/file.c-5705- if (!f2fs_truncate(inode))
--
fs/fuse/dax.c=663=static void fuse_wait_dax_page(struct inode *inode)
--
fs/fuse/dax.c-666- schedule();
fs/fuse/dax.c:667: filemap_invalidate_lock(inode->i_mapping);
fs/fuse/dax.c-668-}
--
fs/fuse/dax.c=755=static vm_fault_t __fuse_dax_fault(struct vm_fault *vmf, unsigned int order,
--
fs/fuse/dax.c-778- */
fs/fuse/dax.c:779: filemap_invalidate_lock_shared(inode->i_mapping);
fs/fuse/dax.c-780- ret = dax_iomap_fault(vmf, order, &pfn, &error, &fuse_iomap_ops);
--
fs/fuse/dax.c=914=inode_inline_reclaim_one_dmap(struct fuse_conn_dax *fcd, struct inode *inode,
--
fs/fuse/dax.c-923-
fs/fuse/dax.c:924: filemap_invalidate_lock(inode->i_mapping);
fs/fuse/dax.c-925-
--
fs/fuse/dax.c=1076=static int lookup_and_reclaim_dmap(struct fuse_conn_dax *fcd,
--
fs/fuse/dax.c-1085-
fs/fuse/dax.c:1086: filemap_invalidate_lock(inode->i_mapping);
fs/fuse/dax.c-1087- ret = fuse_dax_break_layouts(inode, dmap_start, dmap_end);
--
fs/fuse/dir.c=2145=int fuse_do_setattr(struct mnt_idmap *idmap, struct dentry *dentry,
--
fs/fuse/dir.c-2177- if (FUSE_IS_DAX(inode) && is_truncate) {
fs/fuse/dir.c:2178: filemap_invalidate_lock(mapping);
fs/fuse/dir.c-2179- fault_blocked = true;
--
fs/fuse/file.c=250=static int fuse_open(struct inode *inode, struct file *file)
--
fs/fuse/file.c-271- if (dax_truncate) {
fs/fuse/file.c:272: filemap_invalidate_lock(inode->i_mapping);
fs/fuse/file.c-273- err = fuse_dax_break_layouts(inode, 0, -1);
--
fs/fuse/file.c=2832=static long fuse_file_fallocate(struct file *file, int mode, loff_t offset,
--
fs/fuse/file.c-2859- if (block_faults) {
fs/fuse/file.c:2860: filemap_invalidate_lock(inode->i_mapping);
fs/fuse/file.c-2861- err = fuse_dax_break_layouts(inode, 0, -1);
--
fs/ntfs/file.c=254=static int ntfs_setattr_size(struct inode *vi, struct iattr *attr)
--
fs/ntfs/file.c-278- */
fs/ntfs/file.c:279: filemap_invalidate_lock(vi->i_mapping);
fs/ntfs/file.c-280- if (attr->ia_size > old_size) {
--
fs/ntfs/file.c=676=static vm_fault_t ntfs_filemap_page_mkwrite(struct vm_fault *vmf)
--
fs/ntfs/file.c-691- */
fs/ntfs/file.c:692: filemap_invalidate_lock_shared(mapping);
fs/ntfs/file.c-693- ret = iomap_page_mkwrite(vmf, &ntfs_page_mkwrite_iomap_ops, NULL);
--
fs/ntfs/file.c=1127=static long ntfs_fallocate(struct file *file, int mode, loff_t offset, loff_t len)
--
fs/ntfs/file.c-1170- /* Take invalidate_lock for all fallocate operations to prevent races */
fs/ntfs/file.c:1171: filemap_invalidate_lock(vi->i_mapping);
fs/ntfs/file.c-1172-
--
fs/ntfs3/file.c=466=static long ntfs_fallocate(struct file *file, int mode, loff_t vbo, loff_t len)
--
fs/ntfs3/file.c-519- inode_dio_wait(inode);
fs/ntfs3/file.c:520: filemap_invalidate_lock(mapping);
fs/ntfs3/file.c-521- map_locked = true;
--
fs/smb/client/file.c=993=static int cifs_do_truncate(const unsigned int xid, struct dentry *dentry)
--
fs/smb/client/file.c-1005-
fs/smb/client/file.c:1006: filemap_invalidate_lock(inode->i_mapping);
fs/smb/client/file.c-1007-
--
fs/smb/client/smb2ops.c=3508=static long smb3_zero_range(struct file *file, struct cifs_tcon *tcon,
--
fs/smb/client/smb2ops.c-3531-
fs/smb/client/smb2ops.c:3532: filemap_invalidate_lock(inode->i_mapping);
fs/smb/client/smb2ops.c-3533-
--
fs/smb/client/smb2ops.c=3592=static long smb3_punch_hole(struct file *file, struct cifs_tcon *tcon,
--
fs/smb/client/smb2ops.c-3610-
fs/smb/client/smb2ops.c:3611: filemap_invalidate_lock(inode->i_mapping);
fs/smb/client/smb2ops.c-3612- /*
--
fs/smb/client/smb2ops.c=4014=static long smb3_collapse_range(struct file *file, struct cifs_tcon *tcon,
--
fs/smb/client/smb2ops.c-4032-
fs/smb/client/smb2ops.c:4033: filemap_invalidate_lock(inode->i_mapping);
fs/smb/client/smb2ops.c-4034- rc = filemap_write_and_wait_range(inode->i_mapping,
--
fs/smb/client/smb2ops.c=4078=static long smb3_insert_range(struct file *file, struct cifs_tcon *tcon,
--
fs/smb/client/smb2ops.c-4108-
fs/smb/client/smb2ops.c:4109: filemap_invalidate_lock(inode->i_mapping);
fs/smb/client/smb2ops.c-4110- rc = filemap_write_and_wait_range(inode->i_mapping,
--
fs/udf/file.c=38=static vm_fault_t udf_page_mkwrite(struct vm_fault *vmf)
--
fs/udf/file.c-50- file_update_time(vma->vm_file);
fs/udf/file.c:51: filemap_invalidate_lock_shared(mapping);
fs/udf/file.c-52- folio_lock(folio);
--
fs/udf/file.c=89=static ssize_t udf_file_write_iter(struct kiocb *iocb, struct iov_iter *from)
--
fs/udf/file.c-104- iocb->ki_pos + iov_iter_count(from))) {
fs/udf/file.c:105: filemap_invalidate_lock(inode->i_mapping);
fs/udf/file.c-106- retval = udf_expand_file_adinicb(inode);
--
fs/udf/file.c=215=static int udf_setattr(struct mnt_idmap *idmap, struct dentry *dentry,
--
fs/udf/file.c-236- attr->ia_size != i_size_read(inode)) {
fs/udf/file.c:237: filemap_invalidate_lock(inode->i_mapping);
fs/udf/file.c-238- error = udf_setsize(inode, attr->ia_size);
--
fs/verity/read_metadata.c=16=static int fsverity_read_merkle_tree(struct inode *inode,
--
fs/verity/read_metadata.c-38- if (inode->i_sb->s_vop->readahead_merkle_tree) {
fs/verity/read_metadata.c:39: filemap_invalidate_lock_shared(inode->i_mapping);
fs/verity/read_metadata.c-40- inode->i_sb->s_vop->readahead_merkle_tree(
--
fs/xfs/xfs_bmap_util.c=1537=xfs_swap_extents(
--
fs/xfs/xfs_bmap_util.c-1558- lock_two_nondirectories(VFS_I(ip), VFS_I(tip));
fs/xfs/xfs_bmap_util.c:1559: filemap_invalidate_lock_two(VFS_I(ip)->i_mapping,
fs/xfs/xfs_bmap_util.c-1560- VFS_I(tip)->i_mapping);
--
fs/xfs/xfs_inode.c=2792=xfs_ilock2_io_mmap(
--
fs/xfs/xfs_inode.c-2810- } else
fs/xfs/xfs_inode.c:2811: filemap_invalidate_lock_two(VFS_I(ip1)->i_mapping,
fs/xfs/xfs_inode.c-2812- VFS_I(ip2)->i_mapping);
--
fs/xfs/xfs_iomap.c=2134=xfs_buffered_write_iomap_end(
--
fs/xfs/xfs_iomap.c-2167- } else {
fs/xfs/xfs_iomap.c:2168: filemap_invalidate_lock(inode->i_mapping);
fs/xfs/xfs_iomap.c-2169- iomap_write_delalloc_release(inode, start_byte, end_byte, flags,
--
fs/zonefs/file.c=203=int zonefs_file_truncate(struct inode *inode, loff_t isize)
--
fs/zonefs/file.c-228- /* Serialize against page faults */
fs/zonefs/file.c:229: filemap_invalidate_lock(inode->i_mapping);
fs/zonefs/file.c-230-
--
fs/zonefs/file.c=297=static vm_fault_t zonefs_filemap_page_mkwrite(struct vm_fault *vmf)
--
fs/zonefs/file.c-315- /* Serialize against truncates */
fs/zonefs/file.c:316: filemap_invalidate_lock_shared(inode->i_mapping);
fs/zonefs/file.c-317- ret = iomap_page_mkwrite(vmf, &zonefs_write_iomap_ops, NULL);
]
|
| 383/4 |
2026/09/17 11:42 |
llm |
codeexpert |
0m
Model:
Tokens:
input: 16685
output: 36
thoughts: 127
Thoughts: **Navigating the NTFS Filesystem Code**
Okay, here's what's going through my mind as I dig into this. I'm starting by zeroing in on `fs/ntfs/file.c` β specifically line 254 and the `ntfs_setattr_size` function. Hang on... I need to be absolutely sure we're looking at the right file path. Are we definitely talking about `fs/ntfs/file.c` and not the newer `fs/ntfs3/file.c` variant? This is critical for context. To be completely sure, I'm going to revisit `fs/ntfs/file.c`, and I'm going to take a look at lines 250 through 295. This broader context will help me understand the function's place within the larger architecture.
|
| 384/4 |
2026/09/17 11:42 |
tool |
read-file |
0m
Args: map[File:fs/ntfs/file.c FirstLine:250 LineCount:50]
Results: map[Contents: 250: blkdev_issue_flush(vi->i_sb->s_bdev);
251: return ret;
252: }
253:
254: static int ntfs_setattr_size(struct inode *vi, struct iattr *attr)
255: {
256: struct ntfs_inode *ni = NTFS_I(vi);
257: int err;
258: loff_t old_size = vi->i_size;
259:
260: if (NInoCompressed(ni) || NInoEncrypted(ni) || NInoWofCompressed(ni)) {
261: ntfs_warning(
262: vi->i_sb,
263: "Changes in inode size are not supported yet for %s files.",
264: NInoEncrypted(ni) ? "encrypted" : "compressed");
265: return -EOPNOTSUPP;
266: }
267:
268: err = inode_newsize_ok(vi, attr->ia_size);
269: if (err)
270: return err;
271:
272: inode_dio_wait(vi);
273:
274: /*
275: * Serialize with page faults and pagecache instantiation so that
276: * readers cannot observe the size change until the attribute
277: * updates below have completed.
278: */
279: filemap_invalidate_lock(vi->i_mapping);
280: if (attr->ia_size > old_size) {
281: truncate_pagecache(vi, old_size);
282: i_size_write(vi, attr->ia_size);
283: pagecache_isize_extended(vi, old_size, attr->ia_size);
284: } else {
285: truncate_setsize(vi, attr->ia_size);
286: }
287:
288: err = ntfs_truncate_vfs(vi, attr->ia_size, old_size);
289: if (err)
290: i_size_write(vi, old_size);
291: filemap_invalidate_unlock(vi->i_mapping);
292:
293: return err;
294: }
295:
296: /*
297: * ntfs_setattr
298: *
299: * Called from notify_change() when an attribute is being changed.
]
|
| 385/4 |
2026/09/17 11:43 |
llm |
codeexpert |
0m
Model:
Tokens:
input: 17774
output: 34
thoughts: 1177
Thoughts: **Analyzing NTFS Attribute Setting Logic**
Okay, so I'm looking at this code and immediately I see something that jumps out at me. We're talking about modifying file sizes in NTFS, and I'm focusing on the `ntfs_setattr` function, but the question seems a little off since it references `ntfs_truncate_vfs` which is *not* in `fs/ntfs3/file.c`. So my first thought is, are we looking at the right function and the right filesystem code?
Let's carefully parse the question again and get the specifics right. The question states that if `newsize < oldsize` (shrinking), `truncate_setsize` must be called before the `ntfs_set_size`. If `newsize > oldsize` (extending), `ntfs_set_size` must be called before the `truncate_setsize`. And both cases need to be guarded by `filemap_invalidate_lock`.
Okay, so looking at the code, in `fs/ntfs3/file.c`, the actual function that's being called inside `ntfs_setattr` is actually `ntfs_set_size`. And, the code *already* unconditionally calls `truncate_setsize` before calling `ntfs_set_size`. This doesn't seem correct based on the prompt. This unconditional call is immediately problematic, as it violates the conditions stated in the problem description. Moreover, I don't see any `filemap_invalidate_lock` guarding either set of calls.
So, in short, the current `fs/ntfs3/file.c` implementation of `ntfs_setattr` is not handling file size changes correctly. It needs to be modified to follow the correct call order and the locking requirements. I need to make sure the implementation follows the logic that's being asked. This definitely needs some investigation and correction. I'll need to write a patch to address this.
|
| 386/4 |
2026/09/17 11:43 |
tool |
git-log |
0m
Args: map[CodeRegexp:filemap_invalidate_lock PathPrefix:fs/ntfs/]
Results: map[Output:fd73f4a66598 Linux 7.3-rc3
]
|
| 387/4 |
2026/09/17 11:43 |
llm |
codeexpert |
0m
Model:
Tokens:
input: 19439
output: 28
thoughts: 17
Thoughts: Here's a summary of my thought process, as requested:
**Diving into `fs/ntfs/file.c`**
Okay, time to get my hands dirty. I'm going to take a look at the commit in `fs/ntfs/file.c`. This suggests we're dealing with the NTFS filesystem implementation within the kernel, and the `file.c` component is likely the core of file management operations. I need to understand what changed, probably to relate it to a specific problem or enhancement I'm investigating. I will be looking closely at any function calls within this file that are related to file creation, deletion, reading, and writing. I'll be focused on how the change impacts the internal data structures and the overall performance and reliability of the file operations. Specifically, I'll be looking for any potential race conditions, locking issues, or performance bottlenecks the commit might introduce or resolve, given my current context. I'll need to determine if it is related to a vulnerability, performance issue, or if the commit is just clean-up.
|
| 388/4 |
2026/09/17 11:44 |
tool |
git-log |
0m
Args: map[Count:5 PathPrefix:fs/ntfs/file.c]
Results: map[Output:fd73f4a66598 Linux 7.3-rc3
]
|
| 389/4 |
2026/09/17 11:44 |
llm |
codeexpert |
0m
Model:
Tokens:
input: 19742
output: 30
thoughts: 29
Thoughts: Here's my attempt at summarizing the thought process, tailored for an expert audience:
**Investigating a Git Revision**
Okay, so `fd73f4a66598`... that's looking suspiciously like a repository root commit hash. I need to confirm that suspicion. Let's quickly verify that with `git show`. I'll run `git show fd73f4a66598` and see what it tells me. I'm expecting to see the initial commit information: the author, date, the initial commit message, and most importantly, likely no parents. If it's the root, the output will immediately confirm it, or quickly lead me to the next best action.
|
| 390/4 |
2026/09/17 11:44 |
tool |
git-show |
0m
Args: map[Commit:fd73f4a66598 Stat:true]
Results: map[Output:commit fd73f4a6659897191fa0d40695fe370925dd3780
Author: Linus Torvalds <torvalds@linux-foundation.org>
Date: Sun Sep 13 14:38:02 2026 -0700
Linux 7.3-rc3
.clang-format | 808 +
.clippy.toml | 21 +
.cocciconfig | 3 +
.editorconfig | 27 +
.get_maintainer.ignore | 9 +
.gitattributes | 5 +
.gitignore | 196 +
.mailmap | 996 +
.pylintrc | 2 +
.rustfmt.toml | 12 +
COPYING | 20 +
CREDITS | 4651 +
Documentation/.gitignore | 3 +
Documentation/.renames.txt | 1185 +
Documentation/ABI/README | 98 +
.../ABI/obsolete/automount-tracefs-debugfs | 20 +
Documentation/ABI/obsolete/o2cb | 11 +
Documentation/ABI/obsolete/procfs-i8k | 10 +
Documentation/ABI/obsolete/sysfs-bus-iio | 174 +
Documentation/ABI/obsolete/sysfs-bus-usb | 31 +
Documentation/ABI/obsolete/sysfs-class-typec | 48 +
Documentation/ABI/obsolete/sysfs-cpuidle | 9 +
.../ABI/obsolete/sysfs-driver-hid-roccat-arvo | 53 +
.../ABI/obsolete/sysfs-driver-hid-roccat-isku | 153 +
.../ABI/obsolete/sysfs-driver-hid-roccat-koneplus | 145 +
.../ABI/obsolete/sysfs-driver-hid-roccat-konepure | 105 +
.../ABI/obsolete/sysfs-driver-hid-roccat-kovaplus | 116 +
.../ABI/obsolete/sysfs-driver-hid-roccat-lua | 7 +
.../ABI/obsolete/sysfs-driver-hid-roccat-pyra | 126 +
.../ABI/obsolete/sysfs-driver-hid-roccat-ryos | 178 +
.../ABI/obsolete/sysfs-driver-hid-roccat-savu | 77 +
.../ABI/obsolete/sysfs-driver-intel_pmc_bxt | 22 +
Documentation/ABI/obsolete/sysfs-driver-ivpu | 30 +
.../ABI/obsolete/sysfs-driver-samsung-laptop | 10 +
Documentation/ABI/obsolete/sysfs-firmware-acpi | 8 +
Documentation/ABI/obsolete/sysfs-gpio | 40 +
.../ABI/obsolete/sysfs-kernel-fadump_enabled | 9 +
.../ABI/obsolete/sysfs-kernel-fadump_registered | 10 +
.../ABI/obsolete/sysfs-kernel-fadump_release_mem | 10 +
.../ABI/obsolete/sysfs-kernel-kexec-kdump | 71 +
.../ABI/obsolete/sysfs-platform-ideapad-laptop | 8 +
Documentation/ABI/removed/devfs | 13 +
Documentation/ABI/removed/dv1394 | 14 +
Documentation/ABI/removed/ip_queue | 9 +
Documentation/ABI/removed/net_dma | 8 +
Documentation/ABI/removed/o2cb | 10 +
Documentation/ABI/removed/raw1394 | 16 +
Documentation/ABI/removed/sysfs-bus-nfit | 17 +
Documentation/ABI/removed/sysfs-class-cxl | 272 +
Documentation/ABI/removed/sysfs-class-rfkill | 13 +
Documentation/ABI/removed/sysfs-firmware-efi-vars | 12 +
.../removed/sysfs-kernel-fadump_release_opalcore | 9 +
Documentation/ABI/removed/sysfs-kernel-uids | 14 +
Documentation/ABI/removed/sysfs-mce | 37 +
.../ABI/removed/sysfs-selinux-checkreqprot | 26 +
Documentation/ABI/removed/sysfs-selinux-disable | 29 +
Documentation/ABI/removed/sysfs-selinux-user | 12 +
Documentation/ABI/removed/video1394 | 17 +
Documentation/ABI/stable/configfs-nvmet | 352 +
Documentation/ABI/stable/firewire-cdev | 111 +
Documentation/ABI/stable/o2cb | 10 +
Documentation/ABI/stable/procfs-audit_loginuid | 27 +
Documentation/ABI/stable/syscalls | 10 +
Documentation/ABI/stable/sysfs-acpi-pmprofile | 28 +
Documentation/ABI/stable/sysfs-block | 941 +
Documentation/ABI/stable/sysfs-bus-firewire | 136 +
Documentation/ABI/stable/sysfs-bus-fsl-mc | 19 +
Documentation/ABI/stable/sysfs-bus-mhi | 44 +
Documentation/ABI/stable/sysfs-bus-nvmem | 50 +
Documentation/ABI/stable/sysfs-bus-usb | 142 +
Documentation/ABI/stable/sysfs-bus-vmbus | 187 +
Documentation/ABI/stable/sysfs-bus-w1 | 12 +
Documentation/ABI/stable/sysfs-bus-xen-backend | 84 +
Documentation/ABI/stable/sysfs-class-backlight | 63 +
Documentation/ABI/stable/sysfs-class-bluetooth | 9 +
Documentation/ABI/stable/sysfs-class-infiniband | 784 +
Documentation/ABI/stable/sysfs-class-rfkill | 93 +
Documentation/ABI/stable/sysfs-class-tpm | 210 +
Documentation/ABI/stable/sysfs-class-ubi | 221 +
Documentation/ABI/stable/sysfs-class-udc | 93 +
Documentation/ABI/stable/sysfs-devices | 32 +
Documentation/ABI/stable/sysfs-devices-node | 238 +
Documentation/ABI/stable/sysfs-devices-system-cpu | 117 +
.../ABI/stable/sysfs-devices-system-xen_memory | 86 +
Documentation/ABI/stable/sysfs-driver-aspeed-vuart | 24 +
Documentation/ABI/stable/sysfs-driver-dma-idxd | 376 +
Documentation/ABI/stable/sysfs-driver-dma-ioatdma | 30 +
.../ABI/stable/sysfs-driver-firmware-zynqmp | 256 +
Documentation/ABI/stable/sysfs-driver-ib_srp | 192 +
Documentation/ABI/stable/sysfs-driver-misc-cp500 | 25 +
Documentation/ABI/stable/sysfs-driver-mlxreg-io | 815 +
Documentation/ABI/stable/sysfs-driver-qaic | 19 +
Documentation/ABI/stable/sysfs-driver-qla2xxx | 8 +
Documentation/ABI/stable/sysfs-driver-speakup | 394 +
Documentation/ABI/stable/sysfs-driver-usb-usbtmc | 27 +
Documentation/ABI/stable/sysfs-driver-w1_ds2438 | 13 +
Documentation/ABI/stable/sysfs-driver-w1_ds28e04 | 15 +
Documentation/ABI/stable/sysfs-driver-w1_ds28ea00 | 6 +
Documentation/ABI/stable/sysfs-firmware-opal-dump | 46 +
Documentation/ABI/stable/sysfs-firmware-opal-elog | 62 +
Documentation/ABI/stable/sysfs-fs-orangefs | 87 +
Documentation/ABI/stable/sysfs-hypervisor-xen | 135 +
Documentation/ABI/stable/sysfs-kernel-notes | 5 +
.../ABI/stable/sysfs-kernel-time-aux-clocks | 5 +
Documentation/ABI/stable/sysfs-module | 47 +
Documentation/ABI/stable/sysfs-nvme | 453 +
Documentation/ABI/stable/sysfs-platform-wmi-bmof | 7 +
Documentation/ABI/stable/sysfs-transport-srp | 58 +
Documentation/ABI/stable/thermal-notification | 4 +
Documentation/ABI/stable/vdso | 37 +
Documentation/ABI/testing/amdpmf-interface | 73 +
Documentation/ABI/testing/configfs-acpi | 52 +
Documentation/ABI/testing/configfs-iio | 34 +
Documentation/ABI/testing/configfs-most | 241 +
Documentation/ABI/testing/configfs-rdma_cm | 34 +
.../ABI/testing/configfs-spear-pcie-gadget | 33 +
Documentation/ABI/testing/configfs-stp-policy | 48 +
.../ABI/testing/configfs-stp-policy-p_sys-t | 41 +
.../ABI/testing/configfs-thunderbolt_stream | 98 +
Documentation/ABI/testing/configfs-tsm-report | 161 +
Documentation/ABI/testing/configfs-usb-gadget | 158 +
Documentation/ABI/testing/configfs-usb-gadget-acm | 15 +
Documentation/ABI/testing/configfs-usb-gadget-ecm | 20 +
Documentation/ABI/testing/configfs-usb-gadget-eem | 16 +
Documentation/ABI/testing/configfs-usb-gadget-ffs | 17 +
Documentation/ABI/testing/configfs-usb-gadget-hid | 13 +
.../ABI/testing/configfs-usb-gadget-loopback | 10 +
.../ABI/testing/configfs-usb-gadget-mass-storage | 41 +
Documentation/ABI/testing/configfs-usb-gadget-midi | 15 +
.../ABI/testing/configfs-usb-gadget-midi2 | 54 +
Documentation/ABI/testing/configfs-usb-gadget-ncm | 15 +
Documentation/ABI/testing/configfs-usb-gadget-obex | 9 +
.../ABI/testing/configfs-usb-gadget-phonet | 8 +
.../ABI/testing/configfs-usb-gadget-printer | 11 +
.../ABI/testing/configfs-usb-gadget-rndis | 19 +
.../ABI/testing/configfs-usb-gadget-serial | 9 +
.../ABI/testing/configfs-usb-gadget-sourcesink | 16 +
.../ABI/testing/configfs-usb-gadget-subset | 16 +
Documentation/ABI/testing/configfs-usb-gadget-tcm | 6 +
Documentation/ABI/testing/configfs-usb-gadget-uac1 | 41 +
.../ABI/testing/configfs-usb-gadget-uac1_legacy | 9 +
Documentation/ABI/testing/configfs-usb-gadget-uac2 | 51 +
Documentation/ABI/testing/configfs-usb-gadget-uvc | 438 +
Documentation/ABI/testing/debugfs-alienware-wmi | 64 +
Documentation/ABI/testing/debugfs-amd-iommu | 131 +
Documentation/ABI/testing/debugfs-cdns-pcie | 5 +
Documentation/ABI/testing/debugfs-cec-error-inj | 40 +
Documentation/ABI/testing/debugfs-cros-ec | 78 +
Documentation/ABI/testing/debugfs-cxl | 157 +
Documentation/ABI/testing/debugfs-dell-wmi-ddv | 34 +
Documentation/ABI/testing/debugfs-driver-dcc | 127 +
Documentation/ABI/testing/debugfs-driver-genwqe | 91 +
.../ABI/testing/debugfs-driver-habanalabs | 323 +
Documentation/ABI/testing/debugfs-driver-qat | 109 +
.../ABI/testing/debugfs-driver-qat_telemetry | 259 +
Documentation/ABI/testing/debugfs-dwc-pcie | 157 +
Documentation/ABI/testing/debugfs-ec | 21 +
Documentation/ABI/testing/debugfs-hisi-hpre | 200 +
Documentation/ABI/testing/debugfs-hisi-migration | 25 +
Documentation/ABI/testing/debugfs-hisi-sec | 173 +
Documentation/ABI/testing/debugfs-hisi-zip | 174 +
Documentation/ABI/testing/debugfs-hyperv | 23 +
Documentation/ABI/testing/debugfs-ideapad | 19 +
Documentation/ABI/testing/debugfs-iio-ad9467 | 39 +
Documentation/ABI/testing/debugfs-iio-backend | 20 +
Documentation/ABI/testing/debugfs-intel-iommu | 276 +
Documentation/ABI/testing/debugfs-moxtet | 35 +
Documentation/ABI/testing/debugfs-msi-wmi-platform | 14 +
Documentation/ABI/testing/debugfs-olpc | 16 +
Documentation/ABI/testing/debugfs-pcie-ptm | 70 +
Documentation/ABI/testing/debugfs-pfo-nx-crypto | 45 +
Documentation/ABI/testing/debugfs-scmi | 70 +
Documentation/ABI/testing/debugfs-scmi-raw | 208 +
Documentation/ABI/testing/debugfs-tpmi | 40 +
Documentation/ABI/testing/debugfs-vfio | 57 +
Documentation/ABI/testing/debugfs-wilco-ec | 45 +
Documentation/ABI/testing/dell-smbios-wmi | 41 +
Documentation/ABI/testing/dev-kmsg | 127 +
Documentation/ABI/testing/devlink-resource-mlxsw | 33 +
Documentation/ABI/testing/evm | 109 +
Documentation/ABI/testing/gpio-cdev | 28 +
Documentation/ABI/testing/ima_policy | 196 +
Documentation/ABI/testing/ppc-memtrace | 46 +
Documentation/ABI/testing/procfs-attr-current | 20 +
Documentation/ABI/testing/procfs-attr-exec | 20 +
Documentation/ABI/testing/procfs-attr-prev | 19 +
Documentation/ABI/testing/procfs-diskstats | 43 +
.../ABI/testing/procfs-nfsd-reply_cache_stats | 38 +
Documentation/ABI/testing/procfs-smaps_rollup | 42 +
Documentation/ABI/testing/pstore | 47 +
Documentation/ABI/testing/rtc-cdev | 50 +
Documentation/ABI/testing/securityfs-secrets-coco | 51 +
Documentation/ABI/testing/sysfs-amd-pmc | 13 +
Documentation/ABI/testing/sysfs-amd-pmf | 13 +
Documentation/ABI/testing/sysfs-ata | 140 +
.../ABI/testing/sysfs-auxdisplay-linedisp | 90 +
Documentation/ABI/testing/sysfs-block-aoe | 45 +
Documentation/ABI/testing/sysfs-block-bcache | 149 +
Documentation/ABI/testing/sysfs-block-device | 119 +
Documentation/ABI/testing/sysfs-block-dm | 47 +
Documentation/ABI/testing/sysfs-block-loop | 50 +
Documentation/ABI/testing/sysfs-block-rnbd | 64 +
Documentation/ABI/testing/sysfs-block-rssd | 5 +
Documentation/ABI/testing/sysfs-block-zram | 166 +
Documentation/ABI/testing/sysfs-bus-acpi | 98 +
Documentation/ABI/testing/sysfs-bus-amba | 20 +
Documentation/ABI/testing/sysfs-bus-auxiliary | 9 +
Documentation/ABI/testing/sysfs-bus-bcma | 31 +
Documentation/ABI/testing/sysfs-bus-cdx | 121 +
Documentation/ABI/testing/sysfs-bus-coreboot | 45 +
.../ABI/testing/sysfs-bus-coresight-devices-cti | 247 +
.../sysfs-bus-coresight-devices-dummy-source | 21 +
.../ABI/testing/sysfs-bus-coresight-devices-etb10 | 88 +
.../ABI/testing/sysfs-bus-coresight-devices-etm3x | 328 +
.../ABI/testing/sysfs-bus-coresight-devices-etm4x | 532 +
.../ABI/testing/sysfs-bus-coresight-devices-funnel | 18 +
.../ABI/testing/sysfs-bus-coresight-devices-stm | 59 +
.../ABI/testing/sysfs-bus-coresight-devices-tmc | 115 +
.../ABI/testing/sysfs-bus-coresight-devices-tpda | 69 +
.../ABI/testing/sysfs-bus-coresight-devices-tpdm | 290 +
.../ABI/testing/sysfs-bus-coresight-devices-trbe | 20 +
.../testing/sysfs-bus-coresight-devices-ultra_smb | 31 +
Documentation/ABI/testing/sysfs-bus-counter | 477 +
Documentation/ABI/testing/sysfs-bus-css | 56 +
Documentation/ABI/testing/sysfs-bus-cxl | 646 +
Documentation/ABI/testing/sysfs-bus-dax | 177 +
Documentation/ABI/testing/sysfs-bus-dfl | 17 +
.../ABI/testing/sysfs-bus-dfl-devices-emif | 25 +
.../ABI/testing/sysfs-bus-dfl-devices-n3000-nios | 47 +
.../ABI/testing/sysfs-bus-event_source-devices | 24 +
.../testing/sysfs-bus-event_source-devices-caps | 24 +
.../testing/sysfs-bus-event_source-devices-dfl_fme | 104 +
.../ABI/testing/sysfs-bus-event_source-devices-dsa | 30 +
.../testing/sysfs-bus-event_source-devices-events | 102 +
.../testing/sysfs-bus-event_source-devices-format | 21 +
.../sysfs-bus-event_source-devices-hisi_ptt | 113 +
.../testing/sysfs-bus-event_source-devices-hv_24x7 | 98 +
.../testing/sysfs-bus-event_source-devices-hv_gpci | 242 +
.../testing/sysfs-bus-event_source-devices-iommu | 37 +
.../testing/sysfs-bus-event_source-devices-rdpmc | 44 +
.../testing/sysfs-bus-event_source-devices-uncore | 13 +
.../testing/sysfs-bus-event_source-devices-vpa-dtl | 25 +
.../testing/sysfs-bus-event_source-devices-vpa-pmu | 25 +
Documentation/ABI/testing/sysfs-bus-fcoe | 138 +
Documentation/ABI/testing/sysfs-bus-fsi | 46 +
.../ABI/testing/sysfs-bus-fsi-devices-sbefifo | 10 +
Documentation/ABI/testing/sysfs-bus-fsl-mc | 25 +
Documentation/ABI/testing/sysfs-bus-hsi | 19 +
.../ABI/testing/sysfs-bus-i2c-devices-bq32k | 7 +
.../ABI/testing/sysfs-bus-i2c-devices-fsa9480 | 27 +
.../ABI/testing/sysfs-bus-i2c-devices-hm6352 | 21 +
.../ABI/testing/sysfs-bus-i2c-devices-lm3533 | 15 +
.../ABI/testing/sysfs-bus-i2c-devices-m24lr | 100 +
.../ABI/testing/sysfs-bus-i2c-devices-pca954x | 23 +
.../testing/sysfs-bus-i2c-devices-turris-omnia-mcu | 113 +
Documentation/ABI/testing/sysfs-bus-i3c | 194 +
Documentation/ABI/testing/sysfs-bus-iio | 2511 +
.../ABI/testing/sysfs-bus-iio-accel-adxl372 | 7 +
.../ABI/testing/sysfs-bus-iio-accel-bmc150 | 7 +
Documentation/ABI/testing/sysfs-bus-iio-ad9739a | 19 +
.../ABI/testing/sysfs-bus-iio-adc-ad-sigma-delta | 23 +
Documentation/ABI/testing/sysfs-bus-iio-adc-ad4130 | 20 +
Documentation/ABI/testing/sysfs-bus-iio-adc-ad7192 | 27 +
.../ABI/testing/sysfs-bus-iio-adc-ad7280a | 13 +
.../testing/sysfs-bus-iio-adc-envelope-detector | 39 +
Documentation/ABI/testing/sysfs-bus-iio-adc-hi8435 | 48 +
.../ABI/testing/sysfs-bus-iio-adc-max11410 | 13 +
.../ABI/testing/sysfs-bus-iio-adc-mcp3564 | 53 +
Documentation/ABI/testing/sysfs-bus-iio-adc-mt6360 | 78 +
.../ABI/testing/sysfs-bus-iio-adc-pac1934 | 9 +
Documentation/ABI/testing/sysfs-bus-iio-adc-stm32 | 21 +
Documentation/ABI/testing/sysfs-bus-iio-bno055 | 81 +
Documentation/ABI/testing/sysfs-bus-iio-cdc-ad7746 | 11 +
.../ABI/testing/sysfs-bus-iio-chemical-sgp40 | 17 +
.../ABI/testing/sysfs-bus-iio-chemical-sunrise-co2 | 38 +
.../ABI/testing/sysfs-bus-iio-chemical-vz89x | 7 +
Documentation/ABI/testing/sysfs-bus-iio-cros-ec | 21 +
Documentation/ABI/testing/sysfs-bus-iio-dac | 61 +
Documentation/ABI/testing/sysfs-bus-iio-dac-ad5766 | 31 +
.../ABI/testing/sysfs-bus-iio-dac-dpot-dac | 8 +
.../ABI/testing/sysfs-bus-iio-dac-ltc2688 | 55 +
.../ABI/testing/sysfs-bus-iio-dfsdm-adc-stm32 | 22 +
.../ABI/testing/sysfs-bus-iio-distance-srf08 | 17 +
Documentation/ABI/testing/sysfs-bus-iio-dma-buffer | 19 +
.../ABI/testing/sysfs-bus-iio-filter-admv8818 | 18 +
Documentation/ABI/testing/sysfs-bus-iio-flow | 21 +
Documentation/ABI/testing/sysfs-bus-iio-frequency | 11 +
.../ABI/testing/sysfs-bus-iio-frequency-ad9523 | 31 +
.../ABI/testing/sysfs-bus-iio-frequency-adf4350 | 11 +
.../ABI/testing/sysfs-bus-iio-frequency-adf4371 | 11 +
.../ABI/testing/sysfs-bus-iio-frequency-admv1013 | 38 +
.../ABI/testing/sysfs-bus-iio-frequency-admv1014 | 23 +
.../ABI/testing/sysfs-bus-iio-gyro-bmg160 | 7 +
.../ABI/testing/sysfs-bus-iio-health-afe440x | 39 +
Documentation/ABI/testing/sysfs-bus-iio-humidity | 10 +
.../sysfs-bus-iio-impedance-analyzer-ad5933 | 35 +
Documentation/ABI/testing/sysfs-bus-iio-ina2xx-adc | 15 +
.../ABI/testing/sysfs-bus-iio-inv_icm42600 | 18 +
Documentation/ABI/testing/sysfs-bus-iio-isl29501 | 47 +
.../ABI/testing/sysfs-bus-iio-light-isl29018 | 21 +
.../ABI/testing/sysfs-bus-iio-light-lm3533-als | 56 +
.../ABI/testing/sysfs-bus-iio-light-si1133 | 22 +
.../ABI/testing/sysfs-bus-iio-light-tsl2583 | 20 +
.../ABI/testing/sysfs-bus-iio-light-tsl2772 | 13 +
.../ABI/testing/sysfs-bus-iio-magnetometer-hmc5843 | 20 +
Documentation/ABI/testing/sysfs-bus-iio-meas-spec | 7 +
Documentation/ABI/testing/sysfs-bus-iio-mpu6050 | 13 +
.../testing/sysfs-bus-iio-potentiometer-mcp4531 | 8 +
Documentation/ABI/testing/sysfs-bus-iio-proximity | 24 +
.../ABI/testing/sysfs-bus-iio-proximity-as3935 | 15 +
.../ABI/testing/sysfs-bus-iio-resolver-ad2s1210 | 27 +
Documentation/ABI/testing/sysfs-bus-iio-sps30 | 28 +
Documentation/ABI/testing/sysfs-bus-iio-sx9310 | 10 +
Documentation/ABI/testing/sysfs-bus-iio-sx9324 | 29 +
.../ABI/testing/sysfs-bus-iio-thermocouple | 18 +
.../ABI/testing/sysfs-bus-iio-timer-stm32 | 143 +
.../ABI/testing/sysfs-bus-iio-trigger-sysfs | 42 +
Documentation/ABI/testing/sysfs-bus-iio-vf610 | 16 +
.../ABI/testing/sysfs-bus-intel_th-devices-gth | 52 +
.../ABI/testing/sysfs-bus-intel_th-devices-msc | 54 +
.../ABI/testing/sysfs-bus-intel_th-devices-pti | 24 +
.../ABI/testing/sysfs-bus-intel_th-output-devices | 15 +
Documentation/ABI/testing/sysfs-bus-mcb | 29 +
Documentation/ABI/testing/sysfs-bus-mdio | 72 +
Documentation/ABI/testing/sysfs-bus-media | 6 +
Documentation/ABI/testing/sysfs-bus-mei | 56 +
Documentation/ABI/testing/sysfs-bus-mmc | 4 +
Documentation/ABI/testing/sysfs-bus-most | 299 +
Documentation/ABI/testing/sysfs-bus-moxtet-devices | 17 +
Documentation/ABI/testing/sysfs-bus-nfit | 233 +
Documentation/ABI/testing/sysfs-bus-nvdimm | 60 +
Documentation/ABI/testing/sysfs-bus-optee-devices | 17 +
Documentation/ABI/testing/sysfs-bus-papr-pmem | 75 +
Documentation/ABI/testing/sysfs-bus-pci | 704 +
.../ABI/testing/sysfs-bus-pci-devices-aer | 163 +
.../ABI/testing/sysfs-bus-pci-devices-avs | 8 +
.../ABI/testing/sysfs-bus-pci-devices-catpt | 17 +
.../ABI/testing/sysfs-bus-pci-devices-cciss | 80 +
.../ABI/testing/sysfs-bus-pci-devices-pvpanic | 26 +
.../ABI/testing/sysfs-bus-pci-drivers-btintel_pcie | 15 +
.../ABI/testing/sysfs-bus-pci-drivers-ehci_hcd | 46 +
.../ABI/testing/sysfs-bus-pci-drivers-janz-cmodio | 8 +
.../ABI/testing/sysfs-bus-pci-drivers-xhci_hcd | 129 +
Documentation/ABI/testing/sysfs-bus-peci | 16 +
Documentation/ABI/testing/sysfs-bus-platform | 56 +
.../sysfs-bus-platform-devices-ampere-smpro | 325 +
.../testing/sysfs-bus-platform-devices-occ-hwmon | 13 +
.../sysfs-bus-platform-drivers-amd_x3d_vcache | 12 +
.../ABI/testing/sysfs-bus-platform-onboard-usb-dev | 9 +
Documentation/ABI/testing/sysfs-bus-rapidio | 201 +
Documentation/ABI/testing/sysfs-bus-rbd | 173 +
Documentation/ABI/testing/sysfs-bus-rpmsg | 95 +
Documentation/ABI/testing/sysfs-bus-siox | 90 +
.../ABI/testing/sysfs-bus-soundwire-master | 23 +
.../ABI/testing/sysfs-bus-soundwire-slave | 109 +
.../ABI/testing/sysfs-bus-spi-devices-spi-nor | 40 +
.../testing/sysfs-bus-surface_aggregator-tabletsw | 57 +
Documentation/ABI/testing/sysfs-bus-thunderbolt | 370 +
Documentation/ABI/testing/sysfs-bus-typec | 51 +
Documentation/ABI/testing/sysfs-bus-usb | 607 +
.../ABI/testing/sysfs-bus-usb-devices-usbsevseg | 46 +
Documentation/ABI/testing/sysfs-bus-usb-lvstest | 60 +
Documentation/ABI/testing/sysfs-bus-vdpa | 57 +
Documentation/ABI/testing/sysfs-bus-vfio-mdev | 113 +
Documentation/ABI/testing/sysfs-bus-vmbus | 21 +
Documentation/ABI/testing/sysfs-bus-wmi | 81 +
Documentation/ABI/testing/sysfs-c2port | 81 +
Documentation/ABI/testing/sysfs-cfq-target-latency | 8 +
Documentation/ABI/testing/sysfs-class | 16 +
Documentation/ABI/testing/sysfs-class-backlight | 186 +
.../testing/sysfs-class-backlight-driver-lm3533 | 54 +
.../ABI/testing/sysfs-class-backlight-lm3639 | 11 +
Documentation/ABI/testing/sysfs-class-bdi | 134 +
Documentation/ABI/testing/sysfs-class-bsr | 25 +
Documentation/ABI/testing/sysfs-class-chromeos | 53 +
.../sysfs-class-chromeos-driver-cros-ec-lightbar | 74 +
.../sysfs-class-chromeos-driver-cros-ec-vbc | 6 +
Documentation/ABI/testing/sysfs-class-devfreq | 143 +
.../ABI/testing/sysfs-class-devfreq-event | 25 +
Documentation/ABI/testing/sysfs-class-devlink | 130 +
Documentation/ABI/testing/sysfs-class-drm | 8 +
Documentation/ABI/testing/sysfs-class-extcon | 101 +
Documentation/ABI/testing/sysfs-class-fc | 27 +
Documentation/ABI/testing/sysfs-class-fc_host | 23 +
.../ABI/testing/sysfs-class-fc_remote_ports | 23 +
Documentation/ABI/testing/sysfs-class-firmware | 77 +
.../ABI/testing/sysfs-class-firmware-attributes | 494 +
Documentation/ABI/testing/sysfs-class-fpga-bridge | 11 +
Documentation/ABI/testing/sysfs-class-fpga-manager | 60 +
Documentation/ABI/testing/sysfs-class-fpga-region | 9 +
Documentation/ABI/testing/sysfs-class-gnss | 17 +
Documentation/ABI/testing/sysfs-class-hwmon | 1089 +
.../ABI/testing/sysfs-class-ieee80211-rtw89 | 24 +
Documentation/ABI/testing/sysfs-class-intel_pmt | 119 +
.../ABI/testing/sysfs-class-intel_pmt-features | 134 +
Documentation/ABI/testing/sysfs-class-iommu | 17 +
.../ABI/testing/sysfs-class-iommu-amd-iommu | 14 +
.../ABI/testing/sysfs-class-iommu-intel-iommu | 32 +
Documentation/ABI/testing/sysfs-class-issei | 73 +
Documentation/ABI/testing/sysfs-class-lcd | 23 +
Documentation/ABI/testing/sysfs-class-led | 89 +
.../ABI/testing/sysfs-class-led-driver-aw200xx | 5 +
.../ABI/testing/sysfs-class-led-driver-lm3533 | 73 +
.../testing/sysfs-class-led-driver-turris-omnia | 28 +
Documentation/ABI/testing/sysfs-class-led-flash | 89 +
.../ABI/testing/sysfs-class-led-multicolor | 37 +
.../ABI/testing/sysfs-class-led-trigger-netdev | 192 +
.../ABI/testing/sysfs-class-led-trigger-oneshot | 36 +
.../ABI/testing/sysfs-class-led-trigger-pattern | 50 +
.../ABI/testing/sysfs-class-led-trigger-tty | 62 +
.../ABI/testing/sysfs-class-led-trigger-usbport | 13 +
Documentation/ABI/testing/sysfs-class-leds-gt683r | 18 +
Documentation/ABI/testing/sysfs-class-mei | 105 +
Documentation/ABI/testing/sysfs-class-mic | 178 +
Documentation/ABI/testing/sysfs-class-mtd | 242 +
Documentation/ABI/testing/sysfs-class-mux | 16 +
Documentation/ABI/testing/sysfs-class-net | 354 +
Documentation/ABI/testing/sysfs-class-net-cdc_ncm | 168 +
Documentation/ABI/testing/sysfs-class-net-dsa | 14 +
Documentation/ABI/testing/sysfs-class-net-grcan | 35 +
.../ABI/testing/sysfs-class-net-janz-ican3 | 19 +
Documentation/ABI/testing/sysfs-class-net-peak_usb | 19 +
Documentation/ABI/testing/sysfs-class-net-phydev | 75 +
Documentation/ABI/testing/sysfs-class-net-qmi | 76 +
Documentation/ABI/testing/sysfs-class-net-queues | 121 +
.../ABI/testing/sysfs-class-net-statistics | 217 +
Documentation/ABI/testing/sysfs-class-ocxl | 51 +
.../ABI/testing/sysfs-class-platform-profile | 50 +
Documentation/ABI/testing/sysfs-class-power | 906 +
.../ABI/testing/sysfs-class-power-bd71828 | 13 +
Documentation/ABI/testing/sysfs-class-power-gaokun | 27 +
.../ABI/testing/sysfs-class-power-ltc4162l | 82 +
.../ABI/testing/sysfs-class-power-max1720x | 32 +
Documentation/ABI/testing/sysfs-class-power-mp2629 | 9 +
Documentation/ABI/testing/sysfs-class-power-rt9467 | 19 +
Documentation/ABI/testing/sysfs-class-power-rt9471 | 32 +
Documentation/ABI/testing/sysfs-class-power-rt9756 | 30 +
.../ABI/testing/sysfs-class-power-surface | 15 +
.../ABI/testing/sysfs-class-power-twl4030 | 33 +
Documentation/ABI/testing/sysfs-class-power-wilco | 40 +
Documentation/ABI/testing/sysfs-class-powercap | 152 +
Documentation/ABI/testing/sysfs-class-pwm | 88 +
Documentation/ABI/testing/sysfs-class-rapidio | 59 +
Documentation/ABI/testing/sysfs-class-rc | 137 +
Documentation/ABI/testing/sysfs-class-rc-nuvoton | 15 +
.../testing/sysfs-class-reboot-mode-reboot_modes | 39 +
Documentation/ABI/testing/sysfs-class-regulator | 453 +
Documentation/ABI/testing/sysfs-class-remoteproc | 104 +
Documentation/ABI/testing/sysfs-class-rnbd-client | 133 +
Documentation/ABI/testing/sysfs-class-rnbd-server | 58 +
Documentation/ABI/testing/sysfs-class-rtc | 91 +
.../sysfs-class-rtc-rtc0-device-rtc_calibration | 14 +
Documentation/ABI/testing/sysfs-class-rtrs-client | 146 +
Documentation/ABI/testing/sysfs-class-rtrs-server | 53 +
Documentation/ABI/testing/sysfs-class-scsi_host | 119 +
Documentation/ABI/testing/sysfs-class-scsi_tape | 109 +
Documentation/ABI/testing/sysfs-class-spi-eeprom | 30 +
Documentation/ABI/testing/sysfs-class-spi-master | 34 +
Documentation/ABI/testing/sysfs-class-stm | 24 +
Documentation/ABI/testing/sysfs-class-stm_source | 11 +
Documentation/ABI/testing/sysfs-class-switchtec | 96 +
Documentation/ABI/testing/sysfs-class-tee | 25 +
Documentation/ABI/testing/sysfs-class-thermal | 259 +
Documentation/ABI/testing/sysfs-class-tsm | 9 +
Documentation/ABI/testing/sysfs-class-typec | 386 +
.../ABI/testing/sysfs-class-usb_power_delivery | 284 +
Documentation/ABI/testing/sysfs-class-usb_role | 27 +
Documentation/ABI/testing/sysfs-class-vduse | 33 +
Documentation/ABI/testing/sysfs-class-wakeup | 76 +
Documentation/ABI/testing/sysfs-class-watchdog | 129 +
Documentation/ABI/testing/sysfs-class-zram | 24 +
Documentation/ABI/testing/sysfs-dev | 21 +
Documentation/ABI/testing/sysfs-devices | 25 +
Documentation/ABI/testing/sysfs-devices-consumer | 9 +
Documentation/ABI/testing/sysfs-devices-coredump | 10 +
Documentation/ABI/testing/sysfs-devices-edac | 157 +
.../ABI/testing/sysfs-devices-faux-tdx-host | 26 +
.../ABI/testing/sysfs-devices-firmware_node | 17 +
Documentation/ABI/testing/sysfs-devices-lpss_ltr | 44 +
Documentation/ABI/testing/sysfs-devices-mapping | 62 +
Documentation/ABI/testing/sysfs-devices-memory | 120 +
Documentation/ABI/testing/sysfs-devices-mmc | 21 +
Documentation/ABI/testing/sysfs-devices-online | 20 +
.../ABI/testing/sysfs-devices-pci-host-bridge | 45 +
.../ABI/testing/sysfs-devices-physical_location | 42 +
.../ABI/testing/sysfs-devices-platform-ACPI-TAD | 117 +
.../testing/sysfs-devices-platform-_UDC_-gadget | 23 +
.../ABI/testing/sysfs-devices-platform-docg3 | 40 +
.../ABI/testing/sysfs-devices-platform-dock | 39 +
.../ABI/testing/sysfs-devices-platform-ipmi | 242 +
.../testing/sysfs-devices-platform-kunpeng_hccs | 126 +
.../sysfs-devices-platform-sh_mobile_lcdc_fb | 44 +
.../ABI/testing/sysfs-devices-platform-soc-ipa | 114 +
.../testing/sysfs-devices-platform-stratix10-rsu | 232 +
.../ABI/testing/sysfs-devices-platform-trackpoint | 115 +
Documentation/ABI/testing/sysfs-devices-power | 307 +
.../ABI/testing/sysfs-devices-power_resources_D0 | 13 +
.../ABI/testing/sysfs-devices-power_resources_D1 | 14 +
.../ABI/testing/sysfs-devices-power_resources_D2 | 14 +
.../testing/sysfs-devices-power_resources_D3hot | 14 +
.../testing/sysfs-devices-power_resources_wakeup | 13 +
.../ABI/testing/sysfs-devices-power_state | 20 +
.../ABI/testing/sysfs-devices-real_power_state | 23 +
Documentation/ABI/testing/sysfs-devices-removable | 20 +
.../ABI/testing/sysfs-devices-resource_in_use | 12 +
Documentation/ABI/testing/sysfs-devices-soc | 95 +
.../ABI/testing/sysfs-devices-software_node | 10 +
.../ABI/testing/sysfs-devices-state_synced | 29 +
Documentation/ABI/testing/sysfs-devices-sun | 14 +
Documentation/ABI/testing/sysfs-devices-supplier | 9 +
Documentation/ABI/testing/sysfs-devices-system-cpu | 808 +
.../ABI/testing/sysfs-devices-system-ibm-rtl | 24 +
.../ABI/testing/sysfs-devices-system-xen_cpu | 20 +
Documentation/ABI/testing/sysfs-devices-vfio-dev | 8 +
.../testing/sysfs-devices-virtual-misc-tdx_guest | 63 +
.../ABI/testing/sysfs-devices-waiting_for_supplier | 17 +
Documentation/ABI/testing/sysfs-devices-xenbus | 41 +
Documentation/ABI/testing/sysfs-driver-altera-cvp | 8 +
Documentation/ABI/testing/sysfs-driver-amd-sfh | 13 +
.../ABI/testing/sysfs-driver-aspeed-uart-routing | 27 +
.../ABI/testing/sysfs-driver-bd9571mwv-regulator | 31 +
Documentation/ABI/testing/sysfs-driver-ccp | 120 +
.../ABI/testing/sysfs-driver-chromeos-acpi | 152 +
.../ABI/testing/sysfs-driver-dell-dw5826e-reset | 9 +
Documentation/ABI/testing/sysfs-driver-eud | 9 +
.../ABI/testing/sysfs-driver-framer-pef2256 | 8 +
.../ABI/testing/sysfs-driver-fsi-master-gpio | 10 +
Documentation/ABI/testing/sysfs-driver-ge-achc | 15 +
Documentation/ABI/testing/sysfs-driver-genwqe | 78 +
Documentation/ABI/testing/sysfs-driver-habanalabs | 265 +
Documentation/ABI/testing/sysfs-driver-hid | 20 +
.../ABI/testing/sysfs-driver-hid-appletb-kbd | 13 +
Documentation/ABI/testing/sysfs-driver-hid-corsair | 15 +
.../ABI/testing/sysfs-driver-hid-corsair-void | 38 +
Documentation/ABI/testing/sysfs-driver-hid-lenovo | 60 +
.../ABI/testing/sysfs-driver-hid-lenovo-go | 724 +
.../ABI/testing/sysfs-driver-hid-lenovo-go-s | 304 +
.../ABI/testing/sysfs-driver-hid-logitech-hidpp | 19 +
.../ABI/testing/sysfs-driver-hid-logitech-lg4ff | 75 +
.../ABI/testing/sysfs-driver-hid-multitouch | 9 +
Documentation/ABI/testing/sysfs-driver-hid-ntrig | 73 +
Documentation/ABI/testing/sysfs-driver-hid-picolcd | 43 +
.../ABI/testing/sysfs-driver-hid-prodikeys | 29 +
.../ABI/testing/sysfs-driver-hid-roccat-kone | 125 +
Documentation/ABI/testing/sysfs-driver-hid-srws1 | 21 +
Documentation/ABI/testing/sysfs-driver-hid-wiimote | 85 +
.../ABI/testing/sysfs-driver-input-axp-pek | 11 +
.../ABI/testing/sysfs-driver-input-cros-ec-keyb | 6 +
.../ABI/testing/sysfs-driver-input-exc3000 | 26 +
Documentation/ABI/testing/sysfs-driver-intc_sar | 54 +
.../ABI/testing/sysfs-driver-intel-i915-hwmon | 93 +
.../ABI/testing/sysfs-driver-intel-m10-bmc | 36 +
.../testing/sysfs-driver-intel-m10-bmc-sec-update | 61 +
.../ABI/testing/sysfs-driver-intel-rapid-start | 21 +
.../ABI/testing/sysfs-driver-intel-xe-hwmon | 315 +
.../ABI/testing/sysfs-driver-intel-xe-ras | 30 +
.../ABI/testing/sysfs-driver-intel-xe-sriov | 190 +
Documentation/ABI/testing/sysfs-driver-intel_sdsi | 90 +
Documentation/ABI/testing/sysfs-driver-ivpu | 65 +
.../ABI/testing/sysfs-driver-jz4780-efuse | 20 +
.../ABI/testing/sysfs-driver-lenovo-yb9-kbdock | 19 +
.../ABI/testing/sysfs-driver-panfrost-profiling | 10 +
.../ABI/testing/sysfs-driver-panthor-profiling | 10 +
Documentation/ABI/testing/sysfs-driver-pciback | 28 +
Documentation/ABI/testing/sysfs-driver-ppi | 75 +
Documentation/ABI/testing/sysfs-driver-qaic | 18 +
Documentation/ABI/testing/sysfs-driver-qat | 167 +
Documentation/ABI/testing/sysfs-driver-qat_kpt | 97 +
Documentation/ABI/testing/sysfs-driver-qat_ras | 41 +
Documentation/ABI/testing/sysfs-driver-qat_rl | 226 +
Documentation/ABI/testing/sysfs-driver-qat_svn | 114 +
.../ABI/testing/sysfs-driver-samsung-laptop | 37 +
Documentation/ABI/testing/sysfs-driver-spi-intel | 20 +
Documentation/ABI/testing/sysfs-driver-st | 12 +
Documentation/ABI/testing/sysfs-driver-tegra-fuse | 11 +
.../ABI/testing/sysfs-driver-toshiba_acpi | 223 +
.../ABI/testing/sysfs-driver-toshiba_haps | 22 +
.../ABI/testing/sysfs-driver-typec-displayport | 74 +
Documentation/ABI/testing/sysfs-driver-uacce | 57 +
Documentation/ABI/testing/sysfs-driver-ucsi-ccg | 6 +
Documentation/ABI/testing/sysfs-driver-ufs | 1793 +
.../ABI/testing/sysfs-driver-uio_pci_sva-pasid | 29 +
.../ABI/testing/sysfs-driver-uniwill-laptop | 105 +
Documentation/ABI/testing/sysfs-driver-w1_ds28e17 | 24 +
Documentation/ABI/testing/sysfs-driver-w1_therm | 190 +
Documentation/ABI/testing/sysfs-driver-wacom | 105 +
Documentation/ABI/testing/sysfs-driver-xdata | 49 +
Documentation/ABI/testing/sysfs-driver-xen-blkback | 46 +
.../ABI/testing/sysfs-driver-xen-blkfront | 19 +
.../ABI/testing/sysfs-driver-xilinx-tmr-manager | 16 +
Documentation/ABI/testing/sysfs-driver-zynqmp-fpga | 73 +
Documentation/ABI/testing/sysfs-edac-ecs | 74 +
Documentation/ABI/testing/sysfs-edac-memory-repair | 206 +
Documentation/ABI/testing/sysfs-edac-scrub | 85 +
Documentation/ABI/testing/sysfs-firmware-acpi | 277 +
.../ABI/testing/sysfs-firmware-dmi-entries | 114 +
.../ABI/testing/sysfs-firmware-dmi-tables | 22 +
Documentation/ABI/testing/sysfs-firmware-efi | 45 +
Documentation/ABI/testing/sysfs-firmware-efi-esrt | 87 +
.../ABI/testing/sysfs-firmware-efi-runtime-map | 36 +
Documentation/ABI/testing/sysfs-firmware-gsmi | 58 +
Documentation/ABI/testing/sysfs-firmware-initrd | 8 +
.../ABI/testing/sysfs-firmware-lefi-boardinfo | 35 +
Documentation/ABI/testing/sysfs-firmware-log | 7 +
Documentation/ABI/testing/sysfs-firmware-memmap | 75 +
Documentation/ABI/testing/sysfs-firmware-ofw | 52 +
.../ABI/testing/sysfs-firmware-opal-powercap | 31 +
Documentation/ABI/testing/sysfs-firmware-opal-psr | 18 +
.../ABI/testing/sysfs-firmware-opal-sensor-groups | 21 +
.../testing/sysfs-firmware-papr-energy-scale-info | 29 +
Documentation/ABI/testing/sysfs-firmware-plpks | 58 +
.../ABI/testing/sysfs-firmware-qemu_fw_cfg | 103 +
.../ABI/testing/sysfs-firmware-sev-vulnerabilities | 19 +
Documentation/ABI/testing/sysfs-firmware-sgi_uv | 159 +
.../ABI/testing/sysfs-firmware-turris-mox-rwtm | 28 +
Documentation/ABI/testing/sysfs-fs-erofs | 49 +
Documentation/ABI/testing/sysfs-fs-ext4 | 118 +
Documentation/ABI/testing/sysfs-fs-f2fs | 1022 +
Documentation/ABI/testing/sysfs-fs-nilfs2 | 269 +
Documentation/ABI/testing/sysfs-fs-ubifs | 35 +
Documentation/ABI/testing/sysfs-fs-virtiofs | 11 +
Documentation/ABI/testing/sysfs-fs-xfs | 37 +
Documentation/ABI/testing/sysfs-hypervisor-xen | 46 +
Documentation/ABI/testing/sysfs-ibft | 33 +
.../ABI/testing/sysfs-kernel-address_bits | 10 +
Documentation/ABI/testing/sysfs-kernel-boot_params | 39 +
Documentation/ABI/testing/sysfs-kernel-btf | 25 +
.../ABI/testing/sysfs-kernel-cpu_byteorder | 12 +
Documentation/ABI/testing/sysfs-kernel-fadump | 59 +
Documentation/ABI/testing/sysfs-kernel-fscaps | 8 +
.../ABI/testing/sysfs-kernel-hardlockup_count | 7 +
.../ABI/testing/sysfs-kernel-iommu_groups | 64 +
Documentation/ABI/testing/sysfs-kernel-irq | 60 +
Documentation/ABI/testing/sysfs-kernel-kexec-kdump | 61 +
Documentation/ABI/testing/sysfs-kernel-livepatch | 95 +
Documentation/ABI/testing/sysfs-kernel-mm | 6 +
Documentation/ABI/testing/sysfs-kernel-mm-cma | 44 +
Documentation/ABI/testing/sysfs-kernel-mm-damon | 664 +
.../ABI/testing/sysfs-kernel-mm-hugepages | 17 +
Documentation/ABI/testing/sysfs-kernel-mm-ksm | 61 +
.../ABI/testing/sysfs-kernel-mm-memory-tiers | 25 +
.../ABI/testing/sysfs-kernel-mm-mempolicy | 4 +
.../sysfs-kernel-mm-mempolicy-weighted-interleave | 54 +
Documentation/ABI/testing/sysfs-kernel-mm-numa | 28 +
Documentation/ABI/testing/sysfs-kernel-mm-swap | 16 +
.../testing/sysfs-kernel-mm-transparent-hugepage | 18 +
Documentation/ABI/testing/sysfs-kernel-oops_count | 6 +
.../ABI/testing/sysfs-kernel-rcu_stall_count | 6 +
Documentation/ABI/testing/sysfs-kernel-reboot | 40 +
Documentation/ABI/testing/sysfs-kernel-slab | 526 +
.../ABI/testing/sysfs-kernel-softlockup_count | 7 +
Documentation/ABI/testing/sysfs-kernel-vmcoreinfo | 14 +
Documentation/ABI/testing/sysfs-kernel-warn_count | 6 +
Documentation/ABI/testing/sysfs-mce | 97 +
.../ABI/testing/sysfs-memory-page-offline | 44 +
Documentation/ABI/testing/sysfs-module | 84 +
Documentation/ABI/testing/sysfs-nvmem-cells | 21 +
Documentation/ABI/testing/sysfs-ocfs2 | 89 +
.../ABI/testing/sysfs-platform-alienware-wmi | 14 +
.../ABI/testing/sysfs-platform-asus-laptop | 71 +
Documentation/ABI/testing/sysfs-platform-asus-wmi | 240 +
Documentation/ABI/testing/sysfs-platform-at91 | 27 +
Documentation/ABI/testing/sysfs-platform-ayaneo-ec | 19 +
.../ABI/testing/sysfs-platform-brcmstb-gisb-arb | 8 +
.../ABI/testing/sysfs-platform-brcmstb-memc | 15 +
.../ABI/testing/sysfs-platform-chipidea-usb-otg | 56 +
.../ABI/testing/sysfs-platform-chipidea-usb2 | 9 +
.../ABI/testing/sysfs-platform-dell-laptop | 73 +
.../ABI/testing/sysfs-platform-dell-privacy-wmi | 71 +
.../ABI/testing/sysfs-platform-dell-smbios | 21 +
.../ABI/testing/sysfs-platform-dell-wmi-ddv | 9 +
Documentation/ABI/testing/sysfs-platform-dfl-fme | 246 +
Documentation/ABI/testing/sysfs-platform-dfl-port | 101 +
Documentation/ABI/testing/sysfs-platform-dptf | 157 +
.../ABI/testing/sysfs-platform-eeepc-laptop | 56 +
Documentation/ABI/testing/sysfs-platform-hidma | 9 +
.../ABI/testing/sysfs-platform-hidma-mgmt | 97 +
.../ABI/testing/sysfs-platform-i2c-demux-pinctrl | 18 +
.../ABI/testing/sysfs-platform-ideapad-laptop | 52 +
Documentation/ABI/testing/sysfs-platform-intel-ifs | 52 +
Documentation/ABI/testing/sysfs-platform-intel-pmc | 22 +
.../testing/sysfs-platform-intel-wmi-sbl-fw-update | 13 +
.../testing/sysfs-platform-intel-wmi-thunderbolt | 12 +
Documentation/ABI/testing/sysfs-platform-kim | 49 +
Documentation/ABI/testing/sysfs-platform-lg-laptop | 36 +
.../ABI/testing/sysfs-platform-mellanox-bootctl | 162 +
.../ABI/testing/sysfs-platform-mellanox-pmc | 64 +
.../ABI/testing/sysfs-platform-msi-laptop | 83 +
Documentation/ABI/testing/sysfs-platform-oxp | 25 +
.../ABI/testing/sysfs-platform-phy-rcar-gen3-usb2 | 17 +
.../ABI/testing/sysfs-platform-power-on-reason | 12 +
.../ABI/testing/sysfs-platform-renesas_usb3 | 17 +
Documentation/ABI/testing/sysfs-platform-silicom | 30 +
Documentation/ABI/testing/sysfs-platform-sst-atom | 26 +
Documentation/ABI/testing/sysfs-platform-tahvo-usb | 16 +
Documentation/ABI/testing/sysfs-platform-ts5500 | 54 +
.../ABI/testing/sysfs-platform-twl4030-usb | 8 +
.../ABI/testing/sysfs-platform-usbip-vudc | 38 +
Documentation/ABI/testing/sysfs-platform-wilco-ec | 58 +
Documentation/ABI/testing/sysfs-platform_profile | 40 +
Documentation/ABI/testing/sysfs-power | 472 +
Documentation/ABI/testing/sysfs-pps | 73 +
Documentation/ABI/testing/sysfs-pps-gen | 43 +
Documentation/ABI/testing/sysfs-pps-gen-tio | 6 +
Documentation/ABI/testing/sysfs-profiling | 13 +
Documentation/ABI/testing/sysfs-ptp | 142 +
Documentation/ABI/testing/sysfs-secvar | 65 +
Documentation/ABI/testing/sysfs-timecard | 293 +
Documentation/ABI/testing/sysfs-tty | 166 +
Documentation/ABI/testing/sysfs-uevent | 51 +
Documentation/ABI/testing/usb-charger-uevent | 54 +
Documentation/ABI/testing/usb-uevent | 27 +
Documentation/Changes | 1 +
Documentation/CodingStyle | 1 +
Documentation/Kconfig | 28 +
Documentation/Makefile | 115 +
Documentation/PCI/acpi-info.rst | 192 +
Documentation/PCI/boot-interrupts.rst | 159 +
Documentation/PCI/controller/index.rst | 11 +
.../PCI/controller/pci-controller-drivers.rst | 402 +
.../PCI/controller/rcar-pcie-firmware.rst | 32 +
.../PCI/endpoint/function/binding/pci-ntb.rst | 38 +
.../PCI/endpoint/function/binding/pci-test.rst | 26 +
Documentation/PCI/endpoint/index.rst | 21 +
Documentation/PCI/endpoint/pci-endpoint-cfs.rst | 138 +
Documentation/PCI/endpoint/pci-endpoint.rst | 283 +
Documentation/PCI/endpoint/pci-ntb-function.rst | 348 +
Documentation/PCI/endpoint/pci-ntb-howto.rst | 158 +
Documentation/PCI/endpoint/pci-nvme-function.rst | 13 +
Documentation/PCI/endpoint/pci-test-function.rst | 103 +
Documentation/PCI/endpoint/pci-test-howto.rst | 239 +
Documentation/PCI/endpoint/pci-vntb-function.rst | 129 +
Documentation/PCI/endpoint/pci-vntb-howto.rst | 169 +
Documentation/PCI/index.rst | 22 +
Documentation/PCI/msi-howto.rst | 300 +
Documentation/PCI/pci-error-recovery.rst | 471 +
Documentation/PCI/pci-iov-howto.rst | 171 +
Documentation/PCI/pci.rst | 578 +
Documentation/PCI/pcieaer-howto.rst | 267 +
Documentation/PCI/pciebus-howto.rst | 228 +
Documentation/PCI/sysfs-pci.rst | 138 +
Documentation/PCI/tph.rst | 132 +
.../Design/Data-Structures/BigTreeClassicRCU.svg | 474 +
.../BigTreePreemptRCUBHdyntickCB.svg | 662 +
.../RCU/Design/Data-Structures/Data-Structures.rst | 1196 +
.../Design/Data-Structures/HugeTreeClassicRCU.svg | 939 +
.../RCU/Design/Data-Structures/TreeLevel.svg | 828 +
.../RCU/Design/Data-Structures/TreeMapping.svg | 305 +
.../Design/Data-Structures/TreeMappingLevel.svg | 380 +
.../RCU/Design/Data-Structures/blkd_task.svg | 631 +
.../RCU/Design/Data-Structures/nxtlist.svg | 386 +
.../Design/Expedited-Grace-Periods/ExpRCUFlow.svg | 830 +
.../Expedited-Grace-Periods/ExpSchedFlow.svg | 830 +
.../Expedited-Grace-Periods.rst | 521 +
.../RCU/Design/Expedited-Grace-Periods/Funnel0.svg | 275 +
.../RCU/Design/Expedited-Grace-Periods/Funnel1.svg | 275 +
.../RCU/Design/Expedited-Grace-Periods/Funnel2.svg | 287 +
.../RCU/Design/Expedited-Grace-Periods/Funnel3.svg | 323 +
.../RCU/Design/Expedited-Grace-Periods/Funnel4.svg | 323 +
.../RCU/Design/Expedited-Grace-Periods/Funnel5.svg | 335 +
.../RCU/Design/Expedited-Grace-Periods/Funnel6.svg | 335 +
.../RCU/Design/Expedited-Grace-Periods/Funnel7.svg | 347 +
.../RCU/Design/Expedited-Grace-Periods/Funnel8.svg | 311 +
.../Memory-Ordering/Tree-RCU-Memory-Ordering.rst | 648 +
.../TreeRCU-callback-invocation.svg | 486 +
.../Memory-Ordering/TreeRCU-callback-registry.svg | 646 +
.../RCU/Design/Memory-Ordering/TreeRCU-dyntick.svg | 700 +
.../Design/Memory-Ordering/TreeRCU-gp-cleanup.svg | 1133 +
.../RCU/Design/Memory-Ordering/TreeRCU-gp-fqs.svg | 1309 +
.../Design/Memory-Ordering/TreeRCU-gp-init-1.svg | 658 +
.../Design/Memory-Ordering/TreeRCU-gp-init-2.svg | 656 +
.../Design/Memory-Ordering/TreeRCU-gp-init-3.svg | 636 +
.../RCU/Design/Memory-Ordering/TreeRCU-gp.svg | 5135 +
.../RCU/Design/Memory-Ordering/TreeRCU-hotplug.svg | 775 +
.../RCU/Design/Memory-Ordering/TreeRCU-qs.svg | 1095 +
.../RCU/Design/Memory-Ordering/rcu_node-lock.svg | 229 +
.../Design/Requirements/GPpartitionReaders1.svg | 374 +
.../Design/Requirements/ReadersPartitionGP1.svg | 639 +
.../RCU/Design/Requirements/Requirements.rst | 2873 +
Documentation/RCU/NMI-RCU.rst | 123 +
Documentation/RCU/RTFP.txt | 2812 +
Documentation/RCU/UP.rst | 152 +
Documentation/RCU/checklist.rst | 556 +
Documentation/RCU/index.rst | 30 +
Documentation/RCU/listRCU.rst | 511 +
Documentation/RCU/lockdep-splat.rst | 115 +
Documentation/RCU/lockdep.rst | 119 +
Documentation/RCU/rcu.rst | 93 +
Documentation/RCU/rcu_dereference.rst | 502 +
Documentation/RCU/rcubarrier.rst | 377 +
Documentation/RCU/rculist_nulls.rst | 215 +
Documentation/RCU/rcuref.rst | 158 +
Documentation/RCU/stallwarn.rst | 491 +
Documentation/RCU/torture.rst | 374 +
Documentation/RCU/whatisRCU.rst | 1415 +
Documentation/SubmittingPatches | 1 +
Documentation/accel/amdxdna/amdnpu.rst | 306 +
Documentation/accel/amdxdna/index.rst | 11 +
Documentation/accel/index.rst | 13 +
Documentation/accel/introduction.rst | 110 +
Documentation/accel/qaic/aic080.rst | 14 +
Documentation/accel/qaic/aic100.rst | 538 +
Documentation/accel/qaic/index.rst | 14 +
Documentation/accel/qaic/qaic.rst | 209 +
Documentation/accel/rocket/index.rst | 19 +
Documentation/accounting/cgroupstats.rst | 31 +
Documentation/accounting/delay-accounting.rst | 214 +
Documentation/accounting/index.rst | 14 +
Documentation/accounting/psi.rst | 188 +
Documentation/accounting/taskstats-struct.rst | 199 +
Documentation/accounting/taskstats.rst | 182 +
Documentation/admin-guide/LSM/LoadPin.rst | 31 +
Documentation/admin-guide/LSM/SELinux.rst | 44 +
Documentation/admin-guide/LSM/SafeSetID.rst | 118 +
Documentation/admin-guide/LSM/Smack.rst | 871 +
Documentation/admin-guide/LSM/Yama.rst | 75 +
Documentation/admin-guide/LSM/apparmor.rst | 54 +
Documentation/admin-guide/LSM/index.rst | 51 +
Documentation/admin-guide/LSM/ipe.rst | 835 +
Documentation/admin-guide/LSM/landlock.rst | 298 +
Documentation/admin-guide/LSM/tomoyo.rst | 52 +
.../admin-guide/RAS/address-translation.rst | 24 +
Documentation/admin-guide/RAS/error-decoding.rst | 21 +
Documentation/admin-guide/RAS/index.rst | 7 +
Documentation/admin-guide/RAS/main.rst | 1087 +
Documentation/admin-guide/README.rst | 360 +
Documentation/admin-guide/abi-obsolete-files.rst | 7 +
Documentation/admin-guide/abi-obsolete.rst | 13 +
Documentation/admin-guide/abi-removed-files.rst | 7 +
Documentation/admin-guide/abi-removed.rst | 7 +
Documentation/admin-guide/abi-stable-files.rst | 7 +
Documentation/admin-guide/abi-stable.rst | 16 +
Documentation/admin-guide/abi-testing-files.rst | 7 +
Documentation/admin-guide/abi-testing.rst | 22 +
Documentation/admin-guide/abi.rst | 29 +
Documentation/admin-guide/acpi/cppc_sysfs.rst | 78 +
.../admin-guide/acpi/fan_performance_states.rst | 90 +
Documentation/admin-guide/acpi/index.rst | 14 +
.../admin-guide/acpi/initrd_table_override.rst | 115 +
Documentation/admin-guide/acpi/ssdt-overlays.rst | 181 +
Documentation/admin-guide/aoe/aoe.rst | 150 +
Documentation/admin-guide/aoe/autoload.sh | 17 +
Documentation/admin-guide/aoe/examples.rst | 23 +
Documentation/admin-guide/aoe/index.rst | 10 +
Documentation/admin-guide/aoe/status.sh | 30 +
Documentation/admin-guide/aoe/todo.rst | 17 +
Documentation/admin-guide/aoe/udev-install.sh | 33 +
Documentation/admin-guide/aoe/udev.txt | 26 +
.../admin-guide/auxdisplay/cfag12864b.rst | 98 +
Documentation/admin-guide/auxdisplay/index.rst | 9 +
Documentation/admin-guide/auxdisplay/ks0108.rst | 50 +
Documentation/admin-guide/bcache.rst | 644 +
Documentation/admin-guide/binderfs.rst | 87 +
Documentation/admin-guide/binfmt-misc.rst | 391 +
.../blockdev/drbd/DRBD-8.3-data-packets.svg | 588 +
.../blockdev/drbd/DRBD-data-packets.svg | 459 +
.../admin-guide/blockdev/drbd/conn-states-8.dot | 18 +
.../blockdev/drbd/data-structure-v9.rst | 42 +
.../admin-guide/blockdev/drbd/disk-states-8.dot | 16 +
.../drbd/drbd-connection-state-overview.dot | 85 +
.../admin-guide/blockdev/drbd/figures.rst | 30 +
Documentation/admin-guide/blockdev/drbd/index.rst | 19 +
.../admin-guide/blockdev/drbd/peer-states-8.dot | 8 +
Documentation/admin-guide/blockdev/floppy.rst | 255 +
Documentation/admin-guide/blockdev/index.rst | 17 +
Documentation/admin-guide/blockdev/nbd.rst | 31 +
Documentation/admin-guide/blockdev/paride.rst | 207 +
Documentation/admin-guide/blockdev/ramdisk.rst | 153 +
Documentation/admin-guide/blockdev/zoned_loop.rst | 191 +
Documentation/admin-guide/blockdev/zram.rst | 610 +
Documentation/admin-guide/bootconfig.rst | 416 +
Documentation/admin-guide/braille-console.rst | 38 +
Documentation/admin-guide/btmrvl.rst | 124 +
Documentation/admin-guide/bug-bisect.rst | 165 +
Documentation/admin-guide/bug-hunting.rst | 370 +
.../admin-guide/cgroup-v1/blkio-controller.rst | 301 +
Documentation/admin-guide/cgroup-v1/cgroups.rst | 697 +
Documentation/admin-guide/cgroup-v1/cpuacct.rst | 50 +
Documentation/admin-guide/cgroup-v1/cpusets.rst | 874 +
Documentation/admin-guide/cgroup-v1/devices.rst | 132 +
.../admin-guide/cgroup-v1/freezer-subsystem.rst | 131 +
Documentation/admin-guide/cgroup-v1/hugetlb.rst | 139 +
Documentation/admin-guide/cgroup-v1/index.rst | 24 +
Documentation/admin-guide/cgroup-v1/memcg_test.rst | 342 +
Documentation/admin-guide/cgroup-v1/memory.rst | 926 +
Documentation/admin-guide/cgroup-v1/misc.rst | 4 +
Documentation/admin-guide/cgroup-v1/net_cls.rst | 44 +
Documentation/admin-guide/cgroup-v1/net_prio.rst | 57 +
Documentation/admin-guide/cgroup-v1/pids.rst | 93 +
Documentation/admin-guide/cgroup-v1/rdma.rst | 191 +
Documentation/admin-guide/cgroup-v2.rst | 3581 +
Documentation/admin-guide/cifs/authors.rst | 69 +
Documentation/admin-guide/cifs/changes.rst | 9 +
Documentation/admin-guide/cifs/index.rst | 14 +
Documentation/admin-guide/cifs/introduction.rst | 53 +
Documentation/admin-guide/cifs/todo.rst | 133 +
Documentation/admin-guide/cifs/usage.rst | 864 +
Documentation/admin-guide/cifs/winucase_convert.pl | 62 +
Documentation/admin-guide/clearing-warn-once.rst | 9 +
Documentation/admin-guide/cpu-isolation.rst | 357 +
Documentation/admin-guide/cpu-load.rst | 117 +
Documentation/admin-guide/cputopology.rst | 101 +
Documentation/admin-guide/dell_rbu.rst | 128 +
.../admin-guide/device-mapper/cache-policies.rst | 131 +
Documentation/admin-guide/device-mapper/cache.rst | 337 +
Documentation/admin-guide/device-mapper/delay.rst | 54 +
.../admin-guide/device-mapper/dm-clone.rst | 333 +
.../admin-guide/device-mapper/dm-crypt.rst | 212 +
.../admin-guide/device-mapper/dm-dust.rst | 305 +
Documentation/admin-guide/device-mapper/dm-ebs.rst | 51 +
.../admin-guide/device-mapper/dm-flakey.rst | 88 +
Documentation/admin-guide/device-mapper/dm-ima.rst | 718 +
.../admin-guide/device-mapper/dm-init.rst | 133 +
.../admin-guide/device-mapper/dm-inlinecrypt.rst | 129 +
.../admin-guide/device-mapper/dm-integrity.rst | 321 +
Documentation/admin-guide/device-mapper/dm-io.rst | 75 +
Documentation/admin-guide/device-mapper/dm-log.rst | 57 +
.../admin-guide/device-mapper/dm-pcache.rst | 202 +
.../admin-guide/device-mapper/dm-queue-length.rst | 48 +
.../admin-guide/device-mapper/dm-raid.rst | 489 +
.../admin-guide/device-mapper/dm-service-time.rst | 101 +
.../admin-guide/device-mapper/dm-uevent.rst | 110 +
.../admin-guide/device-mapper/dm-zoned.rst | 194 +
Documentation/admin-guide/device-mapper/era.rst | 116 +
Documentation/admin-guide/device-mapper/index.rst | 43 +
Documentation/admin-guide/device-mapper/kcopyd.rst | 47 +
Documentation/admin-guide/device-mapper/linear.rst | 63 +
.../admin-guide/device-mapper/log-writes.rst | 145 +
.../admin-guide/device-mapper/persistent-data.rst | 88 +
.../admin-guide/device-mapper/snapshot.rst | 196 +
.../admin-guide/device-mapper/statistics.rst | 225 +
.../admin-guide/device-mapper/striped.rst | 61 +
Documentation/admin-guide/device-mapper/switch.rst | 141 +
.../device-mapper/thin-provisioning.rst | 427 +
.../admin-guide/device-mapper/unstriped.rst | 135 +
.../admin-guide/device-mapper/vdo-design.rst | 633 +
Documentation/admin-guide/device-mapper/vdo.rst | 413 +
Documentation/admin-guide/device-mapper/verity.rst | 349 +
.../admin-guide/device-mapper/writecache.rst | 114 +
Documentation/admin-guide/device-mapper/zero.rst | 37 +
Documentation/admin-guide/devices.rst | 270 +
Documentation/admin-guide/devices.txt | 3081 +
Documentation/admin-guide/dynamic-debug-howto.rst | 392 +
Documentation/admin-guide/edid.rst | 27 +
Documentation/admin-guide/efi-stub.rst | 103 +
Documentation/admin-guide/ext4.rst | 611 +
Documentation/admin-guide/features.rst | 3 +
.../admin-guide/filesystem-monitoring.rst | 78 +
Documentation/admin-guide/gpio/gpio-aggregator.rst | 218 +
Documentation/admin-guide/gpio/gpio-mockup.rst | 59 +
Documentation/admin-guide/gpio/gpio-sim.rst | 137 +
Documentation/admin-guide/gpio/gpio-virtuser.rst | 177 +
Documentation/admin-guide/gpio/index.rst | 14 +
Documentation/admin-guide/gpio/obsolete.rst | 13 +
.../admin-guide/hw-vuln/attack_vector_controls.rst | 236 +
.../admin-guide/hw-vuln/core-scheduling.rst | 226 +
.../admin-guide/hw-vuln/cross-thread-rsb.rst | 91 +
.../admin-guide/hw-vuln/gather_data_sampling.rst | 109 +
Documentation/admin-guide/hw-vuln/index.rst | 29 +
.../hw-vuln/indirect-target-selection.rst | 168 +
Documentation/admin-guide/hw-vuln/l1d_flush.rst | 69 +
Documentation/admin-guide/hw-vuln/l1tf.rst | 615 +
Documentation/admin-guide/hw-vuln/mds.rst | 303 +
Documentation/admin-guide/hw-vuln/multihit.rst | 167 +
.../admin-guide/hw-vuln/old_microcode.rst | 21 +
.../hw-vuln/processor_mmio_stale_data.rst | 269 +
.../admin-guide/hw-vuln/reg-file-data-sampling.rst | 96 +
Documentation/admin-guide/hw-vuln/rsb.rst | 268 +
.../special-register-buffer-data-sampling.rst | 150 +
Documentation/admin-guide/hw-vuln/spectre.rst | 725 +
Documentation/admin-guide/hw-vuln/srso.rst | 242 +
.../admin-guide/hw-vuln/tsx_async_abort.rst | 270 +
Documentation/admin-guide/hw-vuln/vmscape.rst | 110 +
Documentation/admin-guide/hw_random.rst | 104 +
Documentation/admin-guide/index.rst | 192 +
Documentation/admin-guide/init.rst | 48 +
Documentation/admin-guide/initrd.rst | 383 +
Documentation/admin-guide/iostats.rst | 187 +
Documentation/admin-guide/java.rst | 423 +
Documentation/admin-guide/jfs.rst | 66 +
Documentation/admin-guide/kdump/gdbmacros.txt | 323 +
Documentation/admin-guide/kdump/index.rst | 13 +
Documentation/admin-guide/kdump/kdump.rst | 612 +
Documentation/admin-guide/kdump/vmcoreinfo.rst | 596 +
Documentation/admin-guide/kernel-parameters.rst | 135 +
Documentation/admin-guide/kernel-parameters.txt | 8709 +
.../admin-guide/kernel-per-CPU-kthreads.rst | 325 +
.../admin-guide/laptops/alienware-wmi.rst | 127 +
Documentation/admin-guide/laptops/asus-laptop.rst | 271 +
.../admin-guide/laptops/disk-shock-protection.rst | 151 +
Documentation/admin-guide/laptops/index.rst | 19 +
Documentation/admin-guide/laptops/lg-laptop.rst | 82 +
.../admin-guide/laptops/samsung-galaxybook.rst | 174 +
Documentation/admin-guide/laptops/sony-laptop.rst | 174 +
[Output truncated: showing 1000 of 96042 lines]]
|
| 391/4 |
2026/09/17 11:44 |
llm |
codeexpert |
0m
Model:
Tokens:
input: 41785
output: 27
thoughts: 34
Thoughts: Here's my take on the thought process, as if it were my own:
**Investigating Recent Changes in NTFS3 File Handling**
Okay, so I want to quickly check the recent commit history for the `fs/ntfs3/file.c` file. I'm thinking, the most efficient way to do that is to use `git`. Specifically, I'll use `git log` and specify the file path. This should give me a chronological listing of commits, allowing me to see who's been touching that file, what changes they made, and when those changes occurred. That should give me the context I need to get started. I'll get the command set up and see what it tells me. I expect this to be a quick way to assess the current state and figure out where to focus my attention.
|
| 392/4 |
2026/09/17 11:45 |
tool |
git-log |
0m
Args: map[Count:10 PathPrefix:fs/ntfs3/]
Results: map[Output:fd73f4a66598 Linux 7.3-rc3
]
|
| 393/4 |
2026/09/17 11:45 |
llm |
codeexpert |
0m
Model:
Tokens:
input: 42053
output: 37
thoughts: 213
Thoughts: **Analyzing the NTFS File Size Change Logic**
Okay, so the provided context tells me we're looking at a single commit β Linux 7.3-rc3 β and that's perfectly normal for an isolated patch. No worries there.
Right, let's re-read the core of the issue: the order of calls in `ntfs_setattr` when modifying file sizes. The crucial thing is this: if the file's being *shrunk*, `truncate_setsize` comes *before* `ntfs_set_size`. If it's *extended*, then `ntfs_set_size` needs to happen first (or `i_size_write` and `pagecache_isize_extended`), and both scenarios *must* be guarded by `filemap_invalidate_lock`. That's the core constraint.
Now, time to dive into `fs/ntfs3/file.c` and see what's actually happening in `ntfs_setattr`. Lines 720 to 765, to be precise. Let's see how the current implementation handles size changes and identify where we need to insert the correct call ordering and locking to meet the requirements of the question.
|
| 394/4 |
2026/09/17 11:45 |
tool |
read-file |
0m
Args: map[File:fs/ntfs3/file.c FirstLine:720 LineCount:45]
Results: map[Contents: 720: return -EIO;
721:
722: err = setattr_prepare(idmap, dentry, attr);
723: if (err)
724: goto out;
725:
726: if (ia_valid & ATTR_SIZE) {
727: loff_t newsize, oldsize;
728:
729: if (WARN_ON(ni->ni_flags & NI_FLAG_COMPRESSED_MASK)) {
730: /* Should never be here, see ntfs_file_open(). */
731: err = -EOPNOTSUPP;
732: goto out;
733: }
734: inode_dio_wait(inode);
735: oldsize = i_size_read(inode);
736: newsize = attr->ia_size;
737:
738: if (newsize != oldsize) {
739: truncate_setsize(inode, newsize);
740:
741: err = ntfs_set_size(inode, newsize);
742: if (err) {
743: i_size_write(inode, oldsize);
744: goto out;
745: }
746:
747: ni->std_fa |= FILE_ATTRIBUTE_ARCHIVE;
748: ni->ni_flags |= NI_FLAG_UPDATE_PARENT;
749: inode_set_mtime_to_ts(inode,
750: inode_set_ctime_current(inode));
751: }
752: }
753:
754: setattr_copy(idmap, inode, attr);
755:
756: if (!is_ni_base(ni)) {
757: ia_valid &= ~ATTR_SIZE;
758: } else if (mode != inode->i_mode) {
759: err = ntfs_acl_chmod(idmap, dentry);
760: if (err)
761: goto out;
762:
763: /* Linux 'w' -> Windows 'ro'. */
764: if (0222 & inode->i_mode)
]
|
| 395/4 |
2026/09/17 11:45 |
llm |
codeexpert |
0m
Model:
Tokens:
input: 43215
output: 37
thoughts: 188
Thoughts: **Examining the File Size Update in NTFS3**
Okay, so I'm looking at this snippet from `fs/ntfs3/file.c` and I need to really dig into what's happening during a file size change. Specifically, I'm focusing on the `if (newsize != oldsize)` block. It's calling `truncate_setsize(inode, newsize)`, and then `ntfs_set_size(inode, newsize)`. The subsequent logic handles potential errors and sets some file attributes.
The core of my interest lies in `truncate_setsize`. I'm already pretty familiar with the basics, but I need to confirm the specifics of *this* implementation. I need to refresh my knowledge of what that function is actually doing. My immediate next step is to locate its definition, and understand how it handles things like block allocation, metadata updates, and potential data loss if the size is reduced, or fragmentation issues if the size is increased. Time to track down that function and analyze its implementation.
|
| 396/4 |
2026/09/17 11:46 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:fs/ntfs3/file.c Name:truncate_setsize]
Results: map[SourceCode: 803: /**
804: * truncate_setsize - update inode and pagecache for a new file size
805: * @inode: inode
806: * @newsize: new file size
807: *
808: * truncate_setsize updates i_size and performs pagecache truncation (if
809: * necessary) to @newsize. It will be typically be called from the filesystem's
810: * setattr function when ATTR_SIZE is passed in.
811: *
812: * Must be called with a lock serializing truncates and writes (generally
813: * i_rwsem but e.g. xfs uses a different lock) and before all filesystem
814: * specific block truncation has been performed.
815: */
816: void truncate_setsize(struct inode *inode, loff_t newsize)
817: {
818: loff_t oldsize = inode->i_size;
819:
820: i_size_write(inode, newsize);
821: if (newsize > oldsize)
822: pagecache_isize_extended(inode, oldsize, newsize);
823: truncate_pagecache(inode, newsize);
824: }
SourceFile:mm/truncate.c]
|
| 397/4 |
2026/09/17 11:46 |
llm |
codeexpert |
0m
Model:
Tokens:
input: 44041
output: 34
thoughts: 341
Thoughts: **Analyzing Filesystem Size Changes**
Okay, so I'm looking at this `truncate_setsize` function and the prompt's instructions regarding `ntfs_setattr`. The core logic here is about how we handle file size changes β specifically, the ordering of calls to `truncate_setsize` versus `ntfs_set_size`, depending on whether we're shrinking or extending the file. The prompt is laying out a pretty clear picture.
If we're *shrinking* the file (newsize < oldsize), `truncate_setsize` must come *before* `ntfs_set_size`. This makes sense; we need to trim the page cache first to reflect the smaller file size before making the backing storage reflect the change.
Conversely, if we're *extending* the file (newsize > oldsize), it seems like `ntfs_set_size` needs to happen *before* `truncate_setsize` (or, more specifically, the `i_size_write` and `pagecache_isize_extended` parts). My initial assumption is that we need to reserve space on the disk first. Either way, this approach would need to be reevaluated. This seems less intuitive, but I get the direction. It's likely that we're dealing with caching semantics and the order in which we update the inode size and the underlying data structures.
And, of course, the ever-present `filemap_invalidate_lock(inode->i_mapping)` has to be in place for both cases. This is critical for data integrity to handle concurrent operations.
To solidify my understanding of the correct implementation, I need to see how other filesystems handle the same `ATTR_SIZE` attribute change. That means diving into the code for `ext4`, `f2fs`, `btrfs`, `xfs`, and `exfat`, and how they manage size adjustments within their respective `setattr` implementations. The details of their internal mechanisms will illuminate the most robust way to approach this patch for the NTFS driver. Ultimately, I need to implement this as cleanly as possible.
|
| 398/4 |
2026/09/17 11:46 |
tool |
grepper |
0m
Args: map[Expression:filemap_invalidate_unlock PathPrefix:fs/ext4/inode.c]
Results: map[Output:fs/ext4/inode.c=4432=static void ext4_wait_dax_page(struct inode *inode)
fs/ext4/inode.c-4433-{
fs/ext4/inode.c:4434: filemap_invalidate_unlock(inode->i_mapping);
fs/ext4/inode.c-4435- schedule();
--
fs/ext4/inode.c=6009=int ext4_setattr(struct mnt_idmap *idmap, struct dentry *dentry,
--
fs/ext4/inode.c-6129- if (rc) {
fs/ext4/inode.c:6130: filemap_invalidate_unlock(inode->i_mapping);
fs/ext4/inode.c-6131- goto err_out;
--
fs/ext4/inode.c-6224-out_mmap_sem:
fs/ext4/inode.c:6225: filemap_invalidate_unlock(inode->i_mapping);
fs/ext4/inode.c-6226- }
--
fs/ext4/inode.c=6740=int ext4_change_inode_journal_flag(struct inode *inode, int val)
--
fs/ext4/inode.c-6776- if (err < 0) {
fs/ext4/inode.c:6777: filemap_invalidate_unlock(inode->i_mapping);
fs/ext4/inode.c-6778- return err;
--
fs/ext4/inode.c-6800- ext4_writepages_up_write(inode->i_sb, alloc_ctx);
fs/ext4/inode.c:6801: filemap_invalidate_unlock(inode->i_mapping);
fs/ext4/inode.c-6802- return err;
--
fs/ext4/inode.c-6810- ext4_writepages_up_write(inode->i_sb, alloc_ctx);
fs/ext4/inode.c:6811: filemap_invalidate_unlock(inode->i_mapping);
fs/ext4/inode.c-6812-
--
fs/ext4/inode.c=6884=vm_fault_t ext4_page_mkwrite(struct vm_fault *vmf)
--
fs/ext4/inode.c-6971-out:
fs/ext4/inode.c:6972: filemap_invalidate_unlock_shared(mapping);
fs/ext4/inode.c-6973- sb_end_pagefault(inode->i_sb);
]
|
| 399/4 |
2026/09/17 11:46 |
llm |
codeexpert |
0m
Model:
Tokens:
input: 45544
output: 37
thoughts: 19
Thoughts: Here's a summary of my thought process, as if I were analyzing that code:
**Diving into ext4_setattr**
Okay, let's drill down into `ext4_setattr`. Specifically, I'm going to look at around line 6125 in the ext4 code. This is a critical function, so I'll want to quickly understand its role and how it handles attribute changes. `setattr` is a core operation, so it will involve checking permissions, updating inode metadata (timestamps, size, etc.), handling potential file system inconsistencies, and ensuring atomicity. I'll need to see how it interacts with the journaling layer, how it manages block allocation (if the size is changing), and how it deals with extended attributes. This is where the core of how permissions and metadata updates work, so the devil's in the details. I will also make sure to review how this function handles locks to ensure data integrity.
|
| 400/4 |
2026/09/17 11:47 |
tool |
read-file |
0m
Args: map[File:fs/ext4/inode.c FirstLine:6120 LineCount:40]
Results: map[Contents:6120: * Blocks are going to be removed from the inode. Wait
6121: * for dio in flight.
6122: */
6123: inode_dio_wait(inode);
6124: }
6125:
6126: filemap_invalidate_lock(inode->i_mapping);
6127:
6128: rc = ext4_break_layouts(inode);
6129: if (rc) {
6130: filemap_invalidate_unlock(inode->i_mapping);
6131: goto err_out;
6132: }
6133:
6134: if (attr->ia_size != inode->i_size) {
6135: /* attach jbd2 jinode for EOF folio tail zeroing */
6136: if (attr->ia_size & (inode->i_sb->s_blocksize - 1) ||
6137: oldsize & (inode->i_sb->s_blocksize - 1)) {
6138: error = ext4_inode_attach_jinode(inode);
6139: if (error)
6140: goto out_mmap_sem;
6141: }
6142:
6143: /*
6144: * Update c/mtime and tail zero the EOF folio on
6145: * truncate up. ext4_truncate() handles the shrink case
6146: * below.
6147: */
6148: if (!shrink) {
6149: inode_set_mtime_to_ts(inode,
6150: inode_set_ctime_current(inode));
6151: if (oldsize & (inode->i_sb->s_blocksize - 1)) {
6152: error = ext4_block_zero_eof(inode,
6153: oldsize, LLONG_MAX);
6154: if (error)
6155: goto out_mmap_sem;
6156: }
6157: }
6158:
6159: handle = ext4_journal_start(inode, EXT4_HT_INODE, 3);
]
|
| 401/4 |
2026/09/17 11:47 |
llm |
codeexpert |
0m
Model:
Tokens:
input: 46408
output: 37
thoughts: 14
Thoughts: Okay, here's my interpretation of that thought process, assuming I'm an expert in file systems and kernel internals:
**Diving Deeper into ext4_setattr**
Right, let's get down to brass tacks. The action described implies that I'm currently working through the `ext4_setattr` function, probably debugging something or trying to understand its behavior in a specific scenario. It suggests I'm already familiar with the broader file system code. I know *where* I am within the overall ext4 code base, and I'm ready to move beyond the current focus. It's likely I've encountered something interesting or perplexing related to attribute setting and need a more detailed understanding of the lower-level implementation. So, I'm specifically targeting the code within that function. I'm thinking to myself, "Okay, time to get my hands dirty. I'm going to dig into the next section, line by line if necessary." I'm mentally preparing for a deep dive, recognizing that the answer to my question lies further down within `ext4_setattr` itself. No broad strokes, just a focused look at the details.
|
| 402/4 |
2026/09/17 11:47 |
tool |
read-file |
0m
Args: map[File:fs/ext4/inode.c FirstLine:6160 LineCount:40]
Results: map[Contents:6160: if (IS_ERR(handle)) {
6161: error = PTR_ERR(handle);
6162: goto out_mmap_sem;
6163: }
6164: if (ext4_handle_valid(handle) && shrink) {
6165: error = ext4_orphan_add(handle, inode);
6166: orphan = 1;
6167: }
6168:
6169: if (shrink)
6170: ext4_fc_track_range(handle, inode,
6171: (attr->ia_size > 0 ? attr->ia_size - 1 : 0) >>
6172: inode->i_sb->s_blocksize_bits,
6173: EXT_MAX_BLOCKS - 1);
6174: else
6175: ext4_fc_track_range(
6176: handle, inode,
6177: (oldsize > 0 ? oldsize - 1 : oldsize) >>
6178: inode->i_sb->s_blocksize_bits,
6179: (attr->ia_size > 0 ? attr->ia_size - 1 : 0) >>
6180: inode->i_sb->s_blocksize_bits);
6181:
6182: down_write(&EXT4_I(inode)->i_data_sem);
6183: old_disksize = EXT4_I(inode)->i_disksize;
6184: EXT4_I(inode)->i_disksize = attr->ia_size;
6185:
6186: /*
6187: * We have to update i_size under i_data_sem together
6188: * with i_disksize to avoid races with writeback code
6189: * running ext4_wb_update_i_disksize().
6190: */
6191: if (!error)
6192: i_size_write(inode, attr->ia_size);
6193: else
6194: EXT4_I(inode)->i_disksize = old_disksize;
6195: up_write(&EXT4_I(inode)->i_data_sem);
6196: rc = ext4_mark_inode_dirty(handle, inode);
6197: if (!error)
6198: error = rc;
6199: ext4_journal_stop(handle);
]
|
| 403/4 |
2026/09/17 11:47 |
llm |
codeexpert |
0m
Model:
Tokens:
input: 47382
output: 37
thoughts: 22
Thoughts: Here's my attempt at summarizing the thought process, tailored for an expert audience:
**Diving into ext4's Inner Workings**
Okay, so I'm digging into ext4 again. I want to understand a specific aspect better, so I'm navigating the code, and I've decided to zoom in on a particular region. Let me get my bearings... Right, I'm heading down to lines 6200 through 6235. That section should hold the key to what I'm looking for. Let's see what's what.
|
| 404/4 |
2026/09/17 11:47 |
tool |
read-file |
0m
Args: map[File:fs/ext4/inode.c FirstLine:6200 LineCount:35]
Results: map[Contents:6200: if (error)
6201: goto out_mmap_sem;
6202: if (!shrink) {
6203: pagecache_isize_extended(inode, oldsize,
6204: inode->i_size);
6205: } else if (ext4_should_journal_data(inode)) {
6206: ext4_wait_for_tail_page_commit(inode);
6207: }
6208: }
6209:
6210: /*
6211: * Truncate pagecache after we've waited for commit
6212: * in data=journal mode to make pages freeable.
6213: */
6214: truncate_pagecache(inode, inode->i_size);
6215: /*
6216: * Call ext4_truncate() even if i_size didn't change to
6217: * truncate possible preallocated blocks.
6218: */
6219: if (attr->ia_size <= oldsize) {
6220: rc = ext4_truncate(inode);
6221: if (rc)
6222: error = rc;
6223: }
6224: out_mmap_sem:
6225: filemap_invalidate_unlock(inode->i_mapping);
6226: }
6227:
6228: if (!error) {
6229: if (inc_ivers)
6230: inode_inc_iversion(inode);
6231: setattr_copy(idmap, inode, attr);
6232: mark_inode_dirty(inode);
6233: }
6234:
]
|
| 405/4 |
2026/09/17 11:48 |
llm |
codeexpert |
0m
Model:
Tokens:
input: 48050
output: 32
thoughts: 25
Thoughts: Here's my attempt at summarizing the thought process, tailored for an expert audience:
**Diving into f2fs_setattr**
Okay, time to dissect `f2fs_setattr` within `fs/f2fs/file.c`. I need to understand exactly how file attributes are handled in F2FS. This is a critical function, as it's the gatekeeper for things like permissions, timestamps, and extended attributes. I'll be looking for potential bottlenecks, race conditions, or anything that could impact performance or data integrity during attribute modifications. I want to see how it interacts with the underlying block device, the journal (if applicable), and if it's taking advantage of any F2FS-specific optimizations. I'll pay close attention to the error handling paths and recovery mechanisms, particularly under I/O stress or power loss scenarios, and how it ensures consistency after potential interruptions. My goal is to grasp the core mechanics and identify areas ripe for optimization or potential vulnerabilities.
|
| 406/4 |
2026/09/17 11:48 |
tool |
grepper |
0m
Args: map[Expression:f2fs_setattr PathPrefix:fs/f2fs/]
Results: map[Output:fs/f2fs/f2fs.h=3851=int f2fs_getattr(struct mnt_idmap *idmap, const struct path *path,
fs/f2fs/f2fs.h-3852- struct kstat *stat, u32 request_mask, unsigned int flags);
fs/f2fs/f2fs.h:3853:int f2fs_setattr(struct mnt_idmap *idmap, struct dentry *dentry,
fs/f2fs/f2fs.h-3854- struct iattr *attr);
--
fs/f2fs/file.c=1099=static void __setattr_copy(struct mnt_idmap *idmap,
--
fs/f2fs/file.c-1123-
fs/f2fs/file.c:1124:int f2fs_setattr(struct mnt_idmap *idmap, struct dentry *dentry,
fs/f2fs/file.c-1125- struct iattr *attr)
--
fs/f2fs/file.c=1277=const struct inode_operations f2fs_file_inode_operations = {
fs/f2fs/file.c-1278- .getattr = f2fs_getattr,
fs/f2fs/file.c:1279: .setattr = f2fs_setattr,
fs/f2fs/file.c-1280- .get_inode_acl = f2fs_get_acl,
--
fs/f2fs/namei.c=1407=const struct inode_operations f2fs_encrypted_symlink_inode_operations = {
--
fs/f2fs/namei.c-1409- .getattr = f2fs_encrypted_symlink_getattr,
fs/f2fs/namei.c:1410: .setattr = f2fs_setattr,
fs/f2fs/namei.c-1411- .listxattr = f2fs_listxattr,
--
fs/f2fs/namei.c=1414=const struct inode_operations f2fs_dir_inode_operations = {
--
fs/f2fs/namei.c-1425- .getattr = f2fs_getattr,
fs/f2fs/namei.c:1426: .setattr = f2fs_setattr,
fs/f2fs/namei.c-1427- .get_inode_acl = f2fs_get_acl,
--
fs/f2fs/namei.c=1435=const struct inode_operations f2fs_symlink_inode_operations = {
--
fs/f2fs/namei.c-1437- .getattr = f2fs_getattr,
fs/f2fs/namei.c:1438: .setattr = f2fs_setattr,
fs/f2fs/namei.c-1439- .listxattr = f2fs_listxattr,
--
fs/f2fs/namei.c=1442=const struct inode_operations f2fs_special_inode_operations = {
fs/f2fs/namei.c-1443- .getattr = f2fs_getattr,
fs/f2fs/namei.c:1444: .setattr = f2fs_setattr,
fs/f2fs/namei.c-1445- .get_inode_acl = f2fs_get_acl,
]
|
| 407/4 |
2026/09/17 11:48 |
llm |
codeexpert |
0m
Model:
Tokens:
input: 49232
output: 38
thoughts: 23
Thoughts: Okay, let's dive into this. I'm thinking about the code in `fs/f2fs/file.c` around line 1220. I'm familiar with this file; it handles the file-specific operations within the F2FS filesystem. Line 1220... right, I recall this section deals with... *[fill in the blank with what the user is most likely an expert in. Examples: data I/O, inode operations, extent management, metadata updates, etc.]*. I'll need to refresh my memory on the context surrounding that specific line. I remember the surrounding code, so I'll quickly recall that to give myself the full picture. My initial guess is that the line handles a crucial part of... *[again, extrapolate based on the user's expertise and the general function of `file.c` within F2FS]*. I'm betting it's tightly coupled with the way F2FS handles... *[another relevant concept]*. I'll need to assess how it works within the broader scope of F2FS's design, considering... *[a relevant architectural aspect, like the log-structured approach, wear-leveling, or specific optimization strategies]*. Alright, time to go get my hands dirty.
|
| 408/4 |
2026/09/17 11:48 |
tool |
read-file |
0m
Args: map[File:fs/f2fs/file.c FirstLine:1220 LineCount:45]
Results: map[Contents:1220: /*
1221: * wait for inflight dio, blocks should be removed after
1222: * IO completion.
1223: */
1224: if (attr->ia_size < old_size)
1225: inode_dio_wait(inode);
1226:
1227: f2fs_down_write(&fi->i_gc_rwsem[WRITE]);
1228: filemap_invalidate_lock(inode->i_mapping);
1229:
1230: if (attr->ia_size > old_size) {
1231: err = f2fs_zero_post_eof_page(inode,
1232: attr->ia_size, false, true);
1233: if (err)
1234: goto err_out;
1235: }
1236: truncate_setsize(inode, attr->ia_size);
1237:
1238: if (attr->ia_size <= old_size)
1239: err = f2fs_truncate(inode);
1240: /*
1241: * do not trim all blocks after i_size if target size is
1242: * larger than i_size.
1243: */
1244: err_out:
1245: filemap_invalidate_unlock(inode->i_mapping);
1246: f2fs_up_write(&fi->i_gc_rwsem[WRITE]);
1247: if (err)
1248: return err;
1249:
1250: spin_lock(&fi->i_size_lock);
1251: inode_set_mtime_to_ts(inode, inode_set_ctime_current(inode));
1252: fi->last_disk_size = i_size_read(inode);
1253: spin_unlock(&fi->i_size_lock);
1254: }
1255:
1256: __setattr_copy(idmap, inode, attr);
1257:
1258: if (attr->ia_valid & ATTR_MODE) {
1259: err = posix_acl_chmod(idmap, dentry, f2fs_get_inode_mode(inode));
1260:
1261: if (is_inode_flag_set(inode, FI_ACL_MODE)) {
1262: if (!err)
1263: inode->i_mode = fi->i_acl_mode;
1264: clear_inode_flag(inode, FI_ACL_MODE);
]
|
| 409/4 |
2026/09/17 11:48 |
llm |
codeexpert |
0m
Model:
Tokens:
input: 50280
output: 39
thoughts: 50
Thoughts: Okay, let's dive into this. I'm curious about the functionality of `ntfs_set_size` within the `fs/ntfs3` file system implementation. My immediate thought is to understand its core purpose, which means I should go straight to the source. Specifically, I need to examine the `ntfs_set_size` function defined within `fs/ntfs3/inode.c`. That's where the magic, or the mechanics at least, should be! Let's see what we can find.
|
| 410/4 |
2026/09/17 11:49 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:fs/ntfs3/file.c Name:ntfs_set_size]
Results: map[SourceCode: 883: int ntfs_set_size(struct inode *inode, u64 new_size)
884: {
885: struct super_block *sb = inode->i_sb;
886: struct ntfs_sb_info *sbi = sb->s_fs_info;
887: struct ntfs_inode *ni = ntfs_i(inode);
888: int err;
889:
890: /* Check for maximum file size. */
891: if (is_sparsed(ni) || is_compressed(ni)) {
892: if (new_size > sbi->maxbytes_sparse) {
893: return -EFBIG;
894: }
895: } else if (new_size > sbi->maxbytes) {
896: return -EFBIG;
897: }
898:
899: /* Mark rw ntfs as dirty. It will be cleared at umount. */
900: ntfs_set_state(sbi, NTFS_DIRTY_DIRTY);
901:
902: ni_lock(ni);
903: down_write(&ni->file.run_lock);
904: if (new_size < ni->i_valid)
905: ni->i_valid = new_size;
906:
907: /* last 'true' means keep preallocated. */
908: err = attr_set_size(ni, ATTR_DATA, ni->file.ads.name, ni->file.ads.len,
909: &ni->file.run, new_size, &ni->i_valid, true);
910:
911: up_write(&ni->file.run_lock);
912: ni_unlock(ni);
913:
914: return err;
915: }
SourceFile:fs/ntfs3/inode.c]
|
| 411/4 |
2026/09/17 11:49 |
llm |
codeexpert |
0m
Model:
Tokens:
input: 51043
output: 29
thoughts: 2949
Thoughts: **Analyzing NTFS File Size Setting Logic**
Alright, let's break this down. My understanding of this problem is that we need to ensure the correct order of operations when modifying a file's size on an NTFS filesystem, paying careful attention to potential errors. `ntfs_set_size` is the core function that updates the on-disk size, and it's prone to failure, so we have to handle those failures!
The core problem, as I see it, centers around how we handle changes that either shrink or extend a file, specifically with `newsize < oldsize` (shrinking) and `newsize > oldsize` (extending). The provided prompt specifies a strict ordering: when shrinking, we *must* `truncate_setsize` *before* `ntfs_set_size`. When extending, we *must* `ntfs_set_size` *before* `truncate_setsize` (or, alternatively, the combination of `i_size_write` and `pagecache_isize_extended`). Furthermore, any operation on the pagecache must be done while protecting the inode through `filemap_invalidate_lock(inode->i_mapping)`.
Thinking it through, if shrinking, `truncate_setsize` does the important stuff: first, it drops pages beyond the new size from the pagecache *and* sets the inode's `i_size`. We *must* do this *before* calling `ntfs_set_size`, so that if `ntfs_set_size` fails, the size is properly restored.
Extending is trickier! If we call `truncate_setsize` before `ntfs_set_size`, we update `i_size` but `ntfs_set_size` *could* fail, leaving us in a bad state (the pagecache might have pages beyond the new size, but on-disk allocation won't be correct).
The reason for the strict order is the pagecache! `ntfs_set_size` needs to be called *first* to ensure the disk is properly allocated. If that fails, we don't change anything in the pagecache or inode. Only if `ntfs_set_size` succeeds, we update `i_size` *and* pagecache with `truncate_setsize` (or the `i_size_write`/`pagecache_isize_extended` combination).
Regarding lock protection, the locking needs to *encompass* the size change logic (`if (newsize != oldsize)` and everything inside). It needs to be around *both* the shrinking and the extending cases, since we must protect changes to the pagecache from races. It *must* be around the entire size-change logic, as the prompt specifies, regardless of whether `newsize < oldsize` or `newsize > oldsize`.
Finally, it seems `truncate_setsize(inode, newsize)` in the extending case actually calls `truncate_pagecache(inode, newsize)`, which will be a no-op! So either way, we should use `truncate_setsize(inode, newsize)`.
|
| 412/4 |
2026/09/17 11:49 |
tool |
grepper |
0m
Args: map[Expression:pagecache_isize_extended PathPrefix:fs/]
Results: map[Output:fs/afs/inode.c=713=static void afs_setattr_success(struct afs_operation *op)
--
fs/afs/inode.c-725- if (size > old_i_size)
fs/afs/inode.c:726: pagecache_isize_extended(inode, old_i_size, size);
fs/afs/inode.c-727- }
--
fs/btrfs/file.c=1318=ssize_t btrfs_buffered_write(struct kiocb *iocb, struct iov_iter *iter)
--
fs/btrfs/file.c-1339- * other buffered writes and cause incorrect call of
fs/btrfs/file.c:1340: * pagecache_isize_extended() to overwrite existing data.
fs/btrfs/file.c-1341- */
--
fs/btrfs/file.c-1363- if (num_written > 0) {
fs/btrfs/file.c:1364: pagecache_isize_extended(inode, old_isize, iocb->ki_pos);
fs/btrfs/file.c-1365- iocb->ki_pos += num_written;
--
fs/btrfs/inode.c=5391=static int btrfs_setsize(struct inode *inode, struct iattr *attr)
--
fs/btrfs/inode.c-5436- btrfs_inode_safe_disk_i_size_write(BTRFS_I(inode), 0);
fs/btrfs/inode.c:5437: pagecache_isize_extended(inode, oldsize, newsize);
fs/btrfs/inode.c-5438- ret = btrfs_update_inode(trans, BTRFS_I(inode));
--
fs/buffer.c=2188=int generic_write_end(const struct kiocb *iocb, struct address_space *mapping,
--
fs/buffer.c-2213- if (old_size < pos)
fs/buffer.c:2214: pagecache_isize_extended(inode, old_size, pos);
fs/buffer.c-2215- /*
--
fs/exfat/file.c=25=static int exfat_cont_expand(struct inode *inode, loff_t size)
--
fs/exfat/file.c-87- * When extending file size, call truncate_pagecache() first,
fs/exfat/file.c:88: * then update i_size, and call pagecache_isize_extended()
fs/exfat/file.c-89- * to ensures the straddling folio is properly marked RO so
--
fs/exfat/file.c-91- */
fs/exfat/file.c:92: pagecache_isize_extended(inode, oldsize, inode->i_size);
fs/exfat/file.c-93-
--
fs/ext4/extents.c=4598=static int ext4_alloc_file_blocks(struct file *file, loff_t offset, loff_t len,
--
fs/ext4/extents.c-4767- if (epos > old_size)
fs/ext4/extents.c:4768: pagecache_isize_extended(inode, old_size, epos);
fs/ext4/extents.c-4769-out:
--
fs/ext4/inode.c=1432=static int ext4_write_end(const struct kiocb *iocb,
--
fs/ext4/inode.c-1463- if (old_size < pos && !verity)
fs/ext4/inode.c:1464: pagecache_isize_extended(inode, old_size, pos);
fs/ext4/inode.c-1465-
--
fs/ext4/inode.c=1535=static int ext4_journalled_write_end(const struct kiocb *iocb,
--
fs/ext4/inode.c-1580- if (old_size < pos && !verity)
fs/ext4/inode.c:1581: pagecache_isize_extended(inode, old_size, pos);
fs/ext4/inode.c-1582-
--
fs/ext4/inode.c=3213=static int ext4_da_do_write_end(struct address_space *mapping,
--
fs/ext4/inode.c-3264- if (pos > old_size)
fs/ext4/inode.c:3265: pagecache_isize_extended(inode, old_size, pos);
fs/ext4/inode.c-3266-
--
fs/ext4/inode.c=6009=int ext4_setattr(struct mnt_idmap *idmap, struct dentry *dentry,
--
fs/ext4/inode.c-6202- if (!shrink) {
fs/ext4/inode.c:6203: pagecache_isize_extended(inode, oldsize,
fs/ext4/inode.c-6204- inode->i_size);
--
fs/iomap/buffered-io.c=1188=static int iomap_write_iter(struct iomap_iter *iter, struct iov_iter *i,
--
fs/iomap/buffered-io.c-1265- if (old_size < pos && !(iter->iomap.flags & IOMAP_F_FSVERITY))
fs/iomap/buffered-io.c:1266: pagecache_isize_extended(iter->inode, old_size, pos);
fs/iomap/buffered-io.c-1267-
--
fs/ntfs/file.c=254=static int ntfs_setattr_size(struct inode *vi, struct iattr *attr)
--
fs/ntfs/file.c-282- i_size_write(vi, attr->ia_size);
fs/ntfs/file.c:283: pagecache_isize_extended(vi, old_size, attr->ia_size);
fs/ntfs/file.c-284- } else {
--
fs/ntfs/file.c=1127=static long ntfs_fallocate(struct file *file, int mode, loff_t offset, loff_t len)
--
fs/ntfs/file.c-1198- truncate_pagecache(vi, old_size);
fs/ntfs/file.c:1199: pagecache_isize_extended(vi, old_size, offset);
fs/ntfs/file.c-1200- }
--
fs/orangefs/inode.c=697=static int orangefs_setattr_size(struct inode *inode, struct iattr *iattr)
--
fs/orangefs/inode.c-726- if (iattr->ia_size > orig_size)
fs/orangefs/inode.c:727: pagecache_isize_extended(inode, orig_size, iattr->ia_size);
fs/orangefs/inode.c-728-
--
fs/smb/client/inode.c=3056=void cifs_setsize(struct inode *inode, loff_t offset)
--
fs/smb/client/inode.c-3074- if (offset > old_size)
fs/smb/client/inode.c:3075: pagecache_isize_extended(inode, old_size, offset);
fs/smb/client/inode.c-3076- truncate_pagecache(inode, offset);
]
|
| 413/4 |
2026/09/17 11:49 |
llm |
codeexpert |
0m
Model:
Tokens:
input: 56680
output: 27
thoughts: 1432
Thoughts: **Analyzing the NTFS File Size Setting Logic**
Okay, so I'm diving into this `ntfs_setattr` issue. The user is directing my attention to how file size changes are handled in NTFS, specifically concerning the order of operations when truncating or extending a file. The prompt pointed me to `fs/ntfs/file.c` and other potential areas.
Initially, I reviewed the code snippet in `fs/ntfs/file.c` (lines 275-294), the provided example. It showed the existing logic, with checks for size increase/decrease, followed by calls to functions like `truncate_pagecache`, `i_size_write`, and `pagecache_isize_extended`. And the locking.
The key here is what the user said: shrinking versus extending file size. The user made it very clear in the prompt that there's a strict ordering requirement. When shrinking (`newsize < oldsize`), `truncate_setsize` *must* come before `ntfs_set_size`. Conversely, when extending (`newsize > oldsize`), `ntfs_set_size` *must* come before `truncate_setsize` or its equivalent. Always protected by the `filemap_invalidate_lock`.
I'm now thinking: the user is not just pointing out a potential bug, but a critical one! The issue is the user specifically wrote this out, so they must be assuming there's an issue with the code.
Now I'm digging into `truncate_setsize` itself. I had to clarify what happens *inside* this function, specifically if `newsize` is greater than `oldsize`. I found that `truncate_setsize` does the `i_size_write` *and* `pagecache_isize_extended` operations, essentially doing the "or" part of the prompt. That's a good thing!
I need to confirm the sequence for both shrinking and extending cases. I have to confirm `truncate_setsize` is handling both sides of the issue.
Let's summarize:
* **Shrinking:** `truncate_setsize` updates `i_size`, and truncates the pagecache. Then, `ntfs_set_size` is called. Error handling returns the size.
* **Extending:** `ntfs_set_size` is called. Error handling? Call `truncate_setsize`.
Ah ha! `truncate_setsize` *does* the correct steps in the extending case.
I need to determine if `truncate_setsize` is optimal in both cases, or if doing `i_size_write` + `pagecache_isize_extended` is preferred. And then I remembered something - the prompt said or, which I assumed because it said it! The user explicitly parenthesized `(or i_size_write + pagecache_isize_extended)` as an explanation of what `truncate_setsize` is.
Is `truncate_setsize` the cleaner approach? It looks like it is. It combines the operations into a single function call.
Now I need to check how other filesystems implement this logic and review any similar `ntfs_setattr` implementations.
|
| 414/4 |
2026/09/17 11:49 |
tool |
grepper |
0m
Args: map[Expression:truncate_setsize\( PathPrefix:fs/]
Results: map[Output:fs/9p/vfs_inode.c=1017=static int v9fs_vfs_setattr(struct mnt_idmap *idmap,
--
fs/9p/vfs_inode.c-1081- iattr->ia_size != i_size_read(inode)) {
fs/9p/vfs_inode.c:1082: truncate_setsize(inode, iattr->ia_size);
fs/9p/vfs_inode.c-1083- netfs_resize_file(netfs_inode(inode), iattr->ia_size, true);
--
fs/9p/vfs_inode_dotl.c=511=int v9fs_vfs_setattr_dotl(struct mnt_idmap *idmap,
--
fs/9p/vfs_inode_dotl.c-576- i_size_read(inode)) {
fs/9p/vfs_inode_dotl.c:577: truncate_setsize(inode, iattr->ia_size);
fs/9p/vfs_inode_dotl.c-578- netfs_resize_file(netfs_inode(inode), iattr->ia_size, true);
--
fs/adfs/inode.c=302=adfs_setattr(struct mnt_idmap *idmap, struct dentry *dentry, struct iattr *attr)
--
fs/adfs/inode.c-323- if (ia_valid & ATTR_SIZE)
fs/adfs/inode.c:324: truncate_setsize(inode, attr->ia_size);
fs/adfs/inode.c-325-
--
fs/affs/inode.c=216=affs_setattr(struct mnt_idmap *idmap, struct dentry *dentry, struct iattr *attr)
--
fs/affs/inode.c-244-
fs/affs/inode.c:245: truncate_setsize(inode, attr->ia_size);
fs/affs/inode.c-246- affs_truncate(inode);
--
fs/afs/inode.c=762=int afs_setattr(struct mnt_idmap *idmap, struct dentry *dentry,
--
fs/afs/inode.c-816- attr->ia_size > netfs_read_remote_i_size(inode)) {
fs/afs/inode.c:817: truncate_setsize(inode, attr->ia_size);
fs/afs/inode.c-818- netfs_resize_file(&vnode->netfs, size, false);
--
fs/aio.c=360=static void put_aio_ring_file(struct kioctx *ctx)
--
fs/aio.c-366-
fs/aio.c:367: truncate_setsize(inode, 0);
fs/aio.c-368-
--
fs/btrfs/file.c=1526=int btrfs_sync_file(struct file *file, loff_t start, loff_t end, int datasync)
--
fs/btrfs/file.c-1809- * protect against truncate races as the page could now be beyond EOF. Because
fs/btrfs/file.c:1810: * truncate_setsize() writes the inode size before removing pages, once we have
fs/btrfs/file.c-1811- * the page lock we can determine safely if the page is beyond EOF. If it is not
--
fs/btrfs/inode.c=5391=static int btrfs_setsize(struct inode *inode, struct iattr *attr)
--
fs/btrfs/inode.c-5460-
fs/btrfs/inode.c:5461: truncate_setsize(inode, newsize);
fs/btrfs/inode.c-5462-
--
fs/ecryptfs/inode.c=733=static int __ecryptfs_truncate(struct dentry *dentry, const struct iattr *ia)
--
fs/ecryptfs/inode.c-784- if (!(crypt_stat->flags & ECRYPTFS_ENCRYPTED)) {
fs/ecryptfs/inode.c:785: truncate_setsize(inode, ia->ia_size);
fs/ecryptfs/inode.c-786- lower_ia.ia_size = ia->ia_size;
--
fs/ecryptfs/inode.c-804- }
fs/ecryptfs/inode.c:805: truncate_setsize(inode, ia->ia_size);
fs/ecryptfs/inode.c-806- rc = ecryptfs_write_inode_size_to_metadata(inode);
--
fs/exfat/file.c=350=int exfat_setattr(struct mnt_idmap *idmap, struct dentry *dentry,
--
fs/exfat/file.c-415- inode_dio_wait(inode);
fs/exfat/file.c:416: truncate_setsize(inode, attr->ia_size);
fs/exfat/file.c-417-
--
fs/exfat/file.c=754=static int exfat_extend_valid_size(struct inode *inode, loff_t new_valid_size)
--
fs/exfat/file.c-786- if (ret) {
fs/exfat/file.c:787: truncate_setsize(inode, old_valid_size);
fs/exfat/file.c-788- exfat_truncate(inode);
--
fs/ext2/inode.c=1237=static int ext2_setsize(struct inode *inode, loff_t newsize)
--
fs/ext2/inode.c-1255- filemap_invalidate_lock(inode->i_mapping);
fs/ext2/inode.c:1256: truncate_setsize(inode, newsize);
fs/ext2/inode.c-1257- __ext2_truncate_blocks(inode, newsize);
--
fs/f2fs/file.c=637=static int finish_preallocate_blocks(struct inode *inode)
--
fs/f2fs/file.c-657-
fs/f2fs/file.c:658: truncate_setsize(inode, i_size_read(inode));
fs/f2fs/file.c-659- ret = f2fs_truncate(inode);
--
fs/f2fs/file.c=1124=int f2fs_setattr(struct mnt_idmap *idmap, struct dentry *dentry,
--
fs/f2fs/file.c-1235- }
fs/f2fs/file.c:1236: truncate_setsize(inode, attr->ia_size);
fs/f2fs/file.c-1237-
--
fs/f2fs/file.c=3879=static int f2fs_ioc_release_dev_alias(struct file *filp)
--
fs/f2fs/file.c-3929- filemap_invalidate_lock(inode->i_mapping);
fs/f2fs/file.c:3930: truncate_setsize(inode, 0);
fs/f2fs/file.c-3931-
--
fs/fat/file.c=517=int fat_setattr(struct mnt_idmap *idmap, struct dentry *dentry,
--
fs/fat/file.c-586- down_write(&MSDOS_I(inode)->truncate_lock);
fs/fat/file.c:587: truncate_setsize(inode, attr->ia_size);
fs/fat/file.c-588- fat_truncate_blocks(inode, attr->ia_size);
--
fs/gfs2/bmap.c=2095=static int do_grow(struct inode *inode, u64 size)
--
fs/gfs2/bmap.c-2138-
fs/gfs2/bmap.c:2139: truncate_setsize(inode, size);
fs/gfs2/bmap.c-2140- inode_set_mtime_to_ts(&ip->i_inode, inode_set_ctime_current(&ip->i_inode));
--
fs/hfs/inode.c=646=int hfs_inode_setattr(struct mnt_idmap *idmap, struct dentry *dentry,
--
fs/hfs/inode.c-686-
fs/hfs/inode.c:687: truncate_setsize(inode, attr->ia_size);
fs/hfs/inode.c-688- hfs_file_truncate(inode);
--
fs/hfsplus/inode.c=308=static int hfsplus_setattr(struct mnt_idmap *idmap,
--
fs/hfsplus/inode.c-326- }
fs/hfsplus/inode.c:327: truncate_setsize(inode, attr->ia_size);
fs/hfsplus/inode.c-328- hfsplus_file_truncate(inode);
--
fs/hostfs/hostfs_kern.c=804=static int hostfs_setattr(struct mnt_idmap *idmap,
--
fs/hostfs/hostfs_kern.c-868- attr->ia_size != i_size_read(inode))
fs/hostfs/hostfs_kern.c:869: truncate_setsize(inode, attr->ia_size);
fs/hostfs/hostfs_kern.c-870-
--
fs/hpfs/inode.c=260=int hpfs_setattr(struct mnt_idmap *idmap, struct dentry *dentry,
--
fs/hpfs/inode.c-287-
fs/hpfs/inode.c:288: truncate_setsize(inode, attr->ia_size);
fs/hpfs/inode.c-289- hpfs_truncate(inode);
--
fs/jffs2/fs.c=32=int jffs2_do_setattr (struct inode *inode, struct iattr *iattr)
--
fs/jffs2/fs.c-179-
fs/jffs2/fs.c:180: /* We have to do the truncate_setsize() without f->sem held, since
fs/jffs2/fs.c-181- some pages may be locked and waiting for it in read_folio().
--
fs/jffs2/fs.c-185- if (ivalid & ATTR_SIZE && inode->i_size > iattr->ia_size) {
fs/jffs2/fs.c:186: truncate_setsize(inode, iattr->ia_size);
fs/jffs2/fs.c-187- inode->i_blocks = (inode->i_size + 511) >> 9;
--
fs/jfs/file.c=92=int jfs_setattr(struct mnt_idmap *idmap, struct dentry *dentry,
--
fs/jfs/file.c-121-
fs/jfs/file.c:122: truncate_setsize(inode, iattr->ia_size);
fs/jfs/file.c-123- jfs_truncate(inode);
--
fs/libfs.c=916=int simple_setattr(struct mnt_idmap *idmap, struct dentry *dentry,
--
fs/libfs.c-926- if (iattr->ia_valid & ATTR_SIZE)
fs/libfs.c:927: truncate_setsize(inode, iattr->ia_size);
fs/libfs.c-928- setattr_copy(idmap, inode, iattr);
--
fs/minix/file.c=26=static int minix_setattr(struct mnt_idmap *idmap,
--
fs/minix/file.c-41-
fs/minix/file.c:42: truncate_setsize(inode, attr->ia_size);
fs/minix/file.c-43- minix_truncate(inode);
--
fs/nilfs2/inode.c=907=int nilfs_setattr(struct mnt_idmap *idmap, struct dentry *dentry,
--
fs/nilfs2/inode.c-925- inode_dio_wait(inode);
fs/nilfs2/inode.c:926: truncate_setsize(inode, iattr->ia_size);
fs/nilfs2/inode.c-927- nilfs_truncate(inode);
--
fs/ntfs/file.c=254=static int ntfs_setattr_size(struct inode *vi, struct iattr *attr)
--
fs/ntfs/file.c-284- } else {
fs/ntfs/file.c:285: truncate_setsize(vi, attr->ia_size);
fs/ntfs/file.c-286- }
--
fs/ntfs/file.c=579=static ssize_t ntfs_file_write_iter(struct kiocb *iocb, struct iov_iter *from)
--
fs/ntfs/file.c-664- if (ni->data_size != old_data_size) {
fs/ntfs/file.c:665: truncate_setsize(vi, old_data_size);
fs/ntfs/file.c-666- ntfs_attr_truncate(ni, old_data_size);
--
fs/ntfs/inode.c=375=int ntfs_drop_big_inode(struct inode *inode)
--
fs/ntfs/inode.c-390-
fs/ntfs/inode.c:391: truncate_setsize(VFS_I(ni), 0);
fs/ntfs/inode.c-392- ntfs_truncate_vfs(VFS_I(ni), 0, 1);
--
fs/ntfs/inode.c=2410=int ntfs_extend_initialized_size(struct inode *vi, const loff_t offset,
--
fs/ntfs/inode.c-2444- if (err)
fs/ntfs/inode.c:2445: truncate_setsize(vi, old_init_size);
fs/ntfs/inode.c-2446- return err;
--
fs/ntfs3/attrib.c=2009=int attr_collapse_range(struct ntfs_inode *ni, u64 vbo, u64 bytes)
--
fs/ntfs3/attrib.c-2057- /* Simple truncate file at 'vbo'. */
fs/ntfs3/attrib.c:2058: truncate_setsize(&ni->vfs_inode, vbo);
fs/ntfs3/attrib.c-2059- err = attr_set_size(ni, ATTR_DATA, ni->file.ads.name,
--
fs/ntfs3/file.c=706=int ntfs_setattr(struct mnt_idmap *idmap, struct dentry *dentry,
--
fs/ntfs3/file.c-738- if (newsize != oldsize) {
fs/ntfs3/file.c:739: truncate_setsize(inode, newsize);
fs/ntfs3/file.c-740-
--
fs/omfs/file.c=341=static int omfs_setattr(struct mnt_idmap *idmap,
--
fs/omfs/file.c-355- return error;
fs/omfs/file.c:356: truncate_setsize(inode, attr->ia_size);
fs/omfs/file.c-357- omfs_truncate(inode);
--
fs/ramfs/file-nommu.c=135=static int ramfs_nommu_resize(struct inode *inode, loff_t newsize, loff_t size)
--
fs/ramfs/file-nommu.c-154-
fs/ramfs/file-nommu.c:155: truncate_setsize(inode, newsize);
fs/ramfs/file-nommu.c-156- return 0;
--
fs/smb/client/cifsfs.c=1519=ssize_t cifs_file_copychunk_range(unsigned int xid,
--
fs/smb/client/cifsfs.c-1596- if (rc > 0 && destoff + rc > i_size_read(target_inode)) {
fs/smb/client/cifsfs.c:1597: truncate_setsize(target_inode, destoff + rc);
fs/smb/client/cifsfs.c-1598- netfs_resize_file(&target_cifsi->netfs,
--
fs/smb/client/smb2ops.c=3508=static long smb3_zero_range(struct file *file, struct cifs_tcon *tcon,
--
fs/smb/client/smb2ops.c-3568- if (rc >= 0) {
fs/smb/client/smb2ops.c:3569: truncate_setsize(inode, new_size);
fs/smb/client/smb2ops.c-3570- spin_lock(&inode->i_lock);
--
fs/smb/client/smb2ops.c=4014=static long smb3_collapse_range(struct file *file, struct cifs_tcon *tcon,
--
fs/smb/client/smb2ops.c-4064-
fs/smb/client/smb2ops.c:4065: truncate_setsize(inode, new_eof);
fs/smb/client/smb2ops.c-4066- spin_lock(&inode->i_lock);
--
fs/smb/client/smb2ops.c=4078=static long smb3_insert_range(struct file *file, struct cifs_tcon *tcon,
--
fs/smb/client/smb2ops.c-4127-
fs/smb/client/smb2ops.c:4128: truncate_setsize(inode, new_eof);
fs/smb/client/smb2ops.c-4129- spin_lock(&inode->i_lock);
--
fs/ubifs/file.c=883=static int do_writepage(struct folio *folio, size_t len)
--
fs/ubifs/file.c-958- * same time. And the problematic one is truncation to smaller size, from where
fs/ubifs/file.c:959: * we have to call 'truncate_setsize()', which first changes @inode->i_size,
fs/ubifs/file.c-960- * then drops the truncated pages. And while dropping the pages, it takes the
fs/ubifs/file.c:961: * page lock. This means that 'do_truncation()' cannot call 'truncate_setsize()'
fs/ubifs/file.c-962- * with @ui_mutex locked, because it would deadlock with 'ubifs_writepage()'.
--
fs/ubifs/file.c=1100=static int do_truncation(struct ubifs_info *c, struct inode *inode,
--
fs/ubifs/file.c-1133-
fs/ubifs/file.c:1134: truncate_setsize(inode, new_size);
fs/ubifs/file.c-1135-
--
fs/ubifs/file.c=1208=static int do_setattr(struct ubifs_info *c, struct inode *inode,
--
fs/ubifs/file.c-1222- dbg_gen("size %lld -> %lld", inode->i_size, new_size);
fs/ubifs/file.c:1223: truncate_setsize(inode, new_size);
fs/ubifs/file.c-1224- }
--
fs/ubifs/file.c-1229- inode_set_mtime_to_ts(inode, inode_set_ctime_current(inode));
fs/ubifs/file.c:1230: /* 'truncate_setsize()' changed @i_size, update @ui_size */
fs/ubifs/file.c-1231- ui->ui_size = inode->i_size;
--
fs/ubifs/ubifs.h=334=struct ubifs_gced_idx_leb {
--
fs/ubifs/ubifs.h-393- * make sure @inode->i_size is always changed under @ui_mutex, because it
fs/ubifs/ubifs.h:394: * cannot call 'truncate_setsize()' with @ui_mutex locked, because it would
fs/ubifs/ubifs.h-395- * deadlock with 'ubifs_writepage()' (see file.c). All the other inode fields
--
fs/udf/inode.c=1280=int udf_setsize(struct inode *inode, loff_t newsize)
--
fs/udf/inode.c-1307-set_size:
fs/udf/inode.c:1308: truncate_setsize(inode, newsize);
fs/udf/inode.c-1309- } else {
--
fs/udf/inode.c-1316- iinfo->i_lenAlloc = newsize;
fs/udf/inode.c:1317: truncate_setsize(inode, newsize);
fs/udf/inode.c-1318- up_write(&iinfo->i_data_sem);
--
fs/udf/inode.c-1324- return err;
fs/udf/inode.c:1325: truncate_setsize(inode, newsize);
fs/udf/inode.c-1326- down_write(&iinfo->i_data_sem);
--
fs/ufs/inode.c=1167=static int ufs_truncate(struct inode *inode, loff_t size)
--
fs/ufs/inode.c-1187-
fs/ufs/inode.c:1188: truncate_setsize(inode, size);
fs/ufs/inode.c-1189-
--
fs/xfs/xfs_iops.c=905=xfs_vn_setattr_size(
--
fs/xfs/xfs_iops.c-1008- * drop the XFS_MMAP_EXCL lock after the extent manipulations are
fs/xfs/xfs_iops.c:1009: * complete. The truncate_setsize() call also cleans partial EOF page
fs/xfs/xfs_iops.c-1010- * PTEs on extending truncates and hence ensures sub-page block size
--
fs/xfs/xfs_iops.c-1025- */
fs/xfs/xfs_iops.c:1026: truncate_setsize(inode, newsize);
fs/xfs/xfs_iops.c-1027-
--
fs/zonefs/file.c=203=int zonefs_file_truncate(struct inode *inode, loff_t isize)
--
fs/zonefs/file.c-261- zonefs_update_stats(inode, isize);
fs/zonefs/file.c:262: truncate_setsize(inode, isize);
fs/zonefs/file.c-263- z->z_wpoffset = isize;
]
|
| 415/4 |
2026/09/17 11:49 |
llm |
codeexpert |
0m
Model:
Tokens:
input: 64922
output: 41
thoughts: 43
Thoughts: Here's my take on the thought process, as requested:
**Diving into `xfs_iops.c`**
Alright, time to dig into the XFS code, specifically `fs/xfs/xfs_iops.c`. I need to get a handle on how I/O operations are managed at a lower level within that file system. Let's zero in around line 1000. That's a reasonable place to start β hopefully, it's near some interesting function or data structure related to I/O scheduling, queueing, or perhaps even error handling. I'll be looking for clues about the interaction between the VFS layer and the XFS implementation, and trying to spot anything related to performance bottlenecks or optimizations.
|
| 416/4 |
2026/09/17 11:50 |
tool |
read-file |
0m
Args: map[File:fs/xfs/xfs_iops.c FirstLine:1000 LineCount:40]
Results: map[Contents:1000: xfs_zoned_space_unreserve(mp, &ac);
1001:
1002: if (error)
1003: return error;
1004:
1005: /*
1006: * We've already locked out new page faults, so now we can safely remove
1007: * pages from the page cache knowing they won't get refaulted until we
1008: * drop the XFS_MMAP_EXCL lock after the extent manipulations are
1009: * complete. The truncate_setsize() call also cleans partial EOF page
1010: * PTEs on extending truncates and hence ensures sub-page block size
1011: * filesystems are correctly handled, too.
1012: *
1013: * We have to do all the page cache truncate work outside the
1014: * transaction context as the "lock" order is page lock->log space
1015: * reservation as defined by extent allocation in the writeback path.
1016: * Hence a truncate can fail with ENOMEM from xfs_trans_alloc(), but
1017: * having already truncated the in-memory version of the file (i.e. made
1018: * user visible changes). There's not much we can do about this, except
1019: * to hope that the caller sees ENOMEM and retries the truncate
1020: * operation.
1021: *
1022: * And we update in-core i_size and truncate page cache beyond newsize
1023: * before writeback the [i_disk_size, newsize] range, so we're
1024: * guaranteed not to write stale data past the new EOF on truncate down.
1025: */
1026: truncate_setsize(inode, newsize);
1027:
1028: /*
1029: * We are going to log the inode size change in this transaction so
1030: * any previous writes that are beyond the on disk EOF and the new
1031: * EOF that have not been written out need to be written here. If we
1032: * do not write the data out, we expose ourselves to the null files
1033: * problem. Note that this includes any block zeroing we did above;
1034: * otherwise those blocks may not be zeroed after a crash.
1035: */
1036: if (did_zeroing ||
1037: (newsize > ip->i_disk_size && oldsize != ip->i_disk_size)) {
1038: error = filemap_write_and_wait_range(VFS_I(ip)->i_mapping,
1039: ip->i_disk_size, newsize - 1);
]
|
| 417/4 |
2026/09/17 11:50 |
llm |
codeexpert-compressor |
0m
Model:
Reply: ### Summary of Investigation and Workspace State
#### 1. Goal and Problem Statement
Task: Write a patch for `ntfs_setattr` implementing the following logic:
- If `newsize < oldsize` (shrinking): `truncate_setsize` must be called before `ntfs_set_size`.
- If `newsize > oldsize` (extending): `ntfs_set_size` must be called before `truncate_setsize` (or `i_size_write` + `pagecache_isize_extended`).
- Both cases must be protected by `filemap_invalidate_lock(inode->i_mapping)` and unlocked with `filemap_invalidate_unlock(inode->i_mapping)`.
Note: `fs/ntfs3` is the target NTFS implementation (not legacy `fs/ntfs`), because `fs/ntfs3/file.c` defines `ntfs_setattr` and calls `ntfs_set_size`, whereas legacy `fs/ntfs` uses `ntfs_truncate_vfs` inside `ntfs_setattr_size`.
#### 2. Approaches Tried and Results
- Searched for `ntfs_setattr` across the tree:
- Found in `fs/ntfs/file.c` (legacy NTFS: calls `ntfs_setattr_size` -> `ntfs_truncate_vfs`, already has partial invalidate locking from old commit).
- Found in `fs/ntfs3/file.c` at line 706 (NTFS3: currently calls `ntfs_set_size`).
- Searched for `ntfs_set_size`:
- Defined in `fs/ntfs3/inode.c:883` (`int ntfs_set_size(struct inode *inode, u64 new_size)`).
- Declared in `fs/ntfs3/ntfs_fs.h:802`.
- Used in `fs/ntfs3/file.c` (in `ntfs_fallocate`, `ntfs_setattr`, `ntfs_file_write_iter`).
- Confirmed target of the patch is `fs/ntfs3/file.c:ntfs_setattr`.
- Examined `git-log` for recent commit history:
- Shallow repository or single commit visible (`fd73f4a66598 Linux 7.3-rc3`). Avoid broad git-log queries.
- Examined `truncate_setsize` definition (`mm/truncate.c:816-824`):
```c
void truncate_setsize(struct inode *inode, loff_t newsize)
{
loff_t oldsize = inode->i_size;
i_size_write(inode, newsize);
if (newsize > oldsize)
pagecache_isize_extended(inode, oldsize, newsize);
truncate_pagecache(inode, newsize);
}
```
Note: When extending (`newsize > oldsize`), `truncate_setsize(inode, newsize)` updates `i_size_write` and calls `pagecache_isize_extended(inode, oldsize, newsize)` followed by `truncate_pagecache(inode, newsize)`. Alternatively, if `ntfs_set_size` is called before `truncate_setsize`, calling `truncate_setsize(inode, newsize)` will see `oldsize = inode->i_size` (which would already be `oldsize` if inode i_size was not yet updated), or if calling `truncate_setsize(inode, newsize)` directly after `ntfs_set_size`:
If `ntfs_set_size` succeeds, `inode->i_size` has NOT been updated yet by `ntfs_set_size` (need to inspect `ntfs_set_size`), so `truncate_setsize(inode, newsize)` can be called, OR explicitly `i_size_write(inode, newsize); pagecache_isize_extended(inode, oldsize, newsize);`.
#### 3. Key Source Code Snippets
##### `fs/ntfs3/file.c:706-775` (Current `ntfs_setattr` implementation):
```c
int ntfs_setattr(struct mnt_idmap *idmap, struct dentry *dentry,
struct iattr *attr)
{
struct inode *inode = d_inode(dentry);
struct ntfs_inode *ni = ntfs_i(inode);
u32 ia_valid = attr->ia_valid;
umode_t mode = inode->i_mode;
int err;
/* Avoid any operation if inode is bad. */
if (unlikely(is_bad_ni(ni)))
return -EINVAL;
if (unlikely(ntfs3_forced_shutdown(inode->i_sb)))
return -EIO;
err = setattr_prepare(idmap, dentry, attr);
if (err)
goto out;
if (ia_valid & ATTR_SIZE) {
loff_t newsize, oldsize;
if (WARN_ON(ni->ni_flags & NI_FLAG_COMPRESSED_MASK)) {
/* Should never be here, see ntfs_file_open(). */
err = -EOPNOTSUPP;
goto out;
}
inode_dio_wait(inode);
oldsize = i_size_read(inode);
newsize = attr->ia_size;
if (newsize != oldsize) {
truncate_setsize(inode, newsize);
err = ntfs_set_size(inode, newsize);
if (err) {
i_size_write(inode, oldsize);
goto out;
}
ni->std_fa |= FILE_ATTRIBUTE_ARCHIVE;
ni->ni_flags |= NI_FLAG_UPDATE_PARENT;
inode_set_mtime_to_ts(inode,
inode_set_ctime_current(inode));
}
}
setattr_copy(idmap, inode, attr);
...
```
#### 4. Active Hypotheses and Details to Verify
1. **Behavior of `ntfs_set_size` (`fs/ntfs3/inode.c:883`)**:
Need to check if `ntfs_set_size(inode, new_size)` modifies `inode->i_size` directly or leaves it to caller.
Also check if `ntfs_fallocate` in `fs/ntfs3/file.c` does locking with `filemap_invalidate_lock`.
Lines 519-521 in `ntfs_fallocate`:
```c
inode_dio_wait(inode);
filemap_invalidate_lock(mapping);
```
2. **Logic needed in `fs/ntfs3/file.c:ntfs_setattr`**:
Around line 738:
```c
if (newsize != oldsize) {
filemap_invalidate_lock(inode->i_mapping);
if (newsize < oldsize) {
truncate_setsize(inode, newsize);
err = ntfs_set_size(inode, newsize);
if (err)
i_size_write(inode, oldsize);
} else {
err = ntfs_set_size(inode, newsize);
if (!err) {
// either truncate_setsize(inode, newsize) or:
// i_size_write(inode, newsize);
// pagecache_isize_extended(inode, oldsize, newsize);
}
}
filemap_invalidate_unlock(inode->i_mapping);
if (err)
goto out;
ni->std_fa |= FILE_ATTRIBUTE_ARCHIVE;
...
}
```
Need to check what error handling and unwinding happens if `ntfs_set_size` fails, and how `truncate_setsize` / `pagecache_isize_extended` is expected to be written according to the prompt specifications.
3. **Check `ntfs_set_size` in `fs/ntfs3/inode.c`**:
Read `ntfs_set_size` to see its exact mechanics with respect to `inode->i_size` and error rollback.
#### 5. Watchouts / Dead Ends
- Do not check git history further without specific commit/tag because broad git queries timeout and the repository appears to be a shallow root commit at `fd73f4a66598`.
- Remember to call `set-results` tool once before the final reply when completing the patch.
Tokens:
input: 41564
output: 2021
thoughts: 0
|
| 418/4 |
2026/09/17 11:50 |
llm |
codeexpert |
0m
Model:
Tokens:
input: 22093
output: 36
thoughts: 0
|
| 419/4 |
2026/09/17 11:50 |
tool |
read-file |
0m
Args: map[File:fs/ntfs/file.c FirstLine:250 LineCount:45]
Results: map[Contents: 250: blkdev_issue_flush(vi->i_sb->s_bdev);
251: return ret;
252: }
253:
254: static int ntfs_setattr_size(struct inode *vi, struct iattr *attr)
255: {
256: struct ntfs_inode *ni = NTFS_I(vi);
257: int err;
258: loff_t old_size = vi->i_size;
259:
260: if (NInoCompressed(ni) || NInoEncrypted(ni) || NInoWofCompressed(ni)) {
261: ntfs_warning(
262: vi->i_sb,
263: "Changes in inode size are not supported yet for %s files.",
264: NInoEncrypted(ni) ? "encrypted" : "compressed");
265: return -EOPNOTSUPP;
266: }
267:
268: err = inode_newsize_ok(vi, attr->ia_size);
269: if (err)
270: return err;
271:
272: inode_dio_wait(vi);
273:
274: /*
275: * Serialize with page faults and pagecache instantiation so that
276: * readers cannot observe the size change until the attribute
277: * updates below have completed.
278: */
279: filemap_invalidate_lock(vi->i_mapping);
280: if (attr->ia_size > old_size) {
281: truncate_pagecache(vi, old_size);
282: i_size_write(vi, attr->ia_size);
283: pagecache_isize_extended(vi, old_size, attr->ia_size);
284: } else {
285: truncate_setsize(vi, attr->ia_size);
286: }
287:
288: err = ntfs_truncate_vfs(vi, attr->ia_size, old_size);
289: if (err)
290: i_size_write(vi, old_size);
291: filemap_invalidate_unlock(vi->i_mapping);
292:
293: return err;
294: }
]
|
| 420/4 |
2026/09/17 11:50 |
llm |
codeexpert |
0m
Model:
Tokens:
input: 22814
output: 37
thoughts: 337
Thoughts: **Analyzing the NTFS Attribute Setting Logic**
Okay, first things first, the prompt is crystal clear. It's essentially laying out the precise ordering of operations for resizing files within the NTFS filesystem. The prompt states that if `newsize < oldsize` (shrinking), then `truncate_setsize` *must* come before `ntfs_set_size`. Conversely, if `newsize > oldsize` (extending), then `ntfs_set_size` *must* come before `truncate_setsize`, or its equivalent sequence, `i_size_write` and `pagecache_isize_extended`. And, critically, both scenarios *require* protection via `filemap_invalidate_lock(inode->i_mapping)`. This is not just a suggestion; it's a hard requirement. The prompt effectively gives me the structure I need to implement.
Now, let's drill down. I need to make sure I get this exactly right for `ntfs_setattr`. The prompt is focusing on the behavior that this function implements. I've already glanced at `fs/ntfs/file.c` lines 279-291, but let's go back and carefully analyze the actual code in `fs/ntfs3/file.c:ntfs_setattr`. Specifically, I need to understand the existing logic and then meticulously incorporate the ordering and locking constraints specified in the prompt. I will go and reread `fs/ntfs3/file.c` around line 706 again for a fuller understanding. This is crucial for building the patch.
|
| 421/4 |
2026/09/17 11:51 |
tool |
read-file |
0m
Args: map[File:fs/ntfs3/file.c FirstLine:705 LineCount:70]
Results: map[Contents: 705: */
706: int ntfs_setattr(struct mnt_idmap *idmap, struct dentry *dentry,
707: struct iattr *attr)
708: {
709: struct inode *inode = d_inode(dentry);
710: struct ntfs_inode *ni = ntfs_i(inode);
711: u32 ia_valid = attr->ia_valid;
712: umode_t mode = inode->i_mode;
713: int err;
714:
715: /* Avoid any operation if inode is bad. */
716: if (unlikely(is_bad_ni(ni)))
717: return -EINVAL;
718:
719: if (unlikely(ntfs3_forced_shutdown(inode->i_sb)))
720: return -EIO;
721:
722: err = setattr_prepare(idmap, dentry, attr);
723: if (err)
724: goto out;
725:
726: if (ia_valid & ATTR_SIZE) {
727: loff_t newsize, oldsize;
728:
729: if (WARN_ON(ni->ni_flags & NI_FLAG_COMPRESSED_MASK)) {
730: /* Should never be here, see ntfs_file_open(). */
731: err = -EOPNOTSUPP;
732: goto out;
733: }
734: inode_dio_wait(inode);
735: oldsize = i_size_read(inode);
736: newsize = attr->ia_size;
737:
738: if (newsize != oldsize) {
739: truncate_setsize(inode, newsize);
740:
741: err = ntfs_set_size(inode, newsize);
742: if (err) {
743: i_size_write(inode, oldsize);
744: goto out;
745: }
746:
747: ni->std_fa |= FILE_ATTRIBUTE_ARCHIVE;
748: ni->ni_flags |= NI_FLAG_UPDATE_PARENT;
749: inode_set_mtime_to_ts(inode,
750: inode_set_ctime_current(inode));
751: }
752: }
753:
754: setattr_copy(idmap, inode, attr);
755:
756: if (!is_ni_base(ni)) {
757: ia_valid &= ~ATTR_SIZE;
758: } else if (mode != inode->i_mode) {
759: err = ntfs_acl_chmod(idmap, dentry);
760: if (err)
761: goto out;
762:
763: /* Linux 'w' -> Windows 'ro'. */
764: if (0222 & inode->i_mode)
765: ni->std_fa &= ~FILE_ATTRIBUTE_READONLY;
766: else
767: ni->std_fa |= FILE_ATTRIBUTE_READONLY;
768: }
769:
770: if (ia_valid & (ATTR_UID | ATTR_GID | ATTR_MODE))
771: ntfs_save_wsl_perm(inode, NULL);
772: mark_inode_dirty(inode);
773: out:
774: return err;
]
|
| 422/4 |
2026/09/17 11:51 |
llm |
codeexpert |
0m
Model:
Tokens:
input: 24564
output: 31
thoughts: 929
Thoughts: **Analyzing NTFS Attribute Setting and Size Manipulation**
Okay, let's break this down. We're looking at `ntfs_setattr` in `fs/ntfs3/file.c` and how it handles file size changes. The core of the problem boils down to correctly sequencing calls to `truncate_setsize` and `ntfs_set_size` depending on whether we're shrinking or extending a file.
The key is that if we're shrinking (`newsize < oldsize`), `truncate_setsize` *must* come before `ntfs_set_size`. However, if we are extending (`newsize > oldsize`), `ntfs_set_size` must come before either `truncate_setsize` or its functional equivalent using `i_size_write` and `pagecache_isize_extended`, both cases require protection by `filemap_invalidate_lock(inode->i_mapping)`.
I need to understand what actually happens with `truncate_setsize` when extending a file. Let me revisit the code: `truncate_setsize` calls `i_size_write` and, if extending, `pagecache_isize_extended`. The crucial thing here is that `ntfs_set_size` *does not* directly modify `inode->i_size`. It updates internal NTFS structures, but not the generic `i_size` field immediately. This means that if we were to call `truncate_setsize` *after* `ntfs_set_size` during an extension, `truncate_setsize` would see the *original* `inode->i_size` and effectively extend it correctly with the subsequent call to `i_size_write`.
But, what if `ntfs_set_size` fails during an extension? Then we have a problem. The current logic, as indicated by line 743, does not provide a rollback mechanism, and we might end up with inconsistencies. We need to handle this failure case.
And, of course, the lock. The provided question mentions the `filemap_invalidate_lock`. We need to make absolutely sure that we're using that lock correctly, both before and after our operations. This should protect both scenarios, shrinking or extending. I think it is important to check other usages of `filemap_invalidate_` in `fs/ntfs3` to find how to better do this.
So, in essence, the correct sequence for extending is:
1. Acquire `filemap_invalidate_lock`.
2. `ntfs_set_size(inode, newsize)`.
3. `truncate_setsize(inode, newsize)`.
4. Release `filemap_invalidate_lock`.
For shrinking, the sequence is:
1. Acquire `filemap_invalidate_lock`.
2. `truncate_setsize(inode, newsize)`.
3. `ntfs_set_size(inode, newsize)`.
4. Release `filemap_invalidate_lock`.
And, we need robust error handling. If `ntfs_set_size` fails, we'll need to revert to the old size. Now I need to write a patch that implements this logic, keeping these considerations in mind.
|
| 423/4 |
2026/09/17 11:51 |
tool |
grepper |
0m
Args: map[Expression:filemap_invalidate_ PathPrefix:fs/ntfs3/]
Results: map[Output:fs/ntfs3/file.c=466=static long ntfs_fallocate(struct file *file, int mode, loff_t vbo, loff_t len)
--
fs/ntfs3/file.c-519- inode_dio_wait(inode);
fs/ntfs3/file.c:520: filemap_invalidate_lock(mapping);
fs/ntfs3/file.c-521- map_locked = true;
--
fs/ntfs3/file.c-691- if (map_locked)
fs/ntfs3/file.c:692: filemap_invalidate_unlock(mapping);
fs/ntfs3/file.c-693-
]
|
| 424/4 |
2026/09/17 11:51 |
llm |
codeexpert |
0m
Model:
Tokens:
input: 26422
output: 37
thoughts: 37
Thoughts: Okay, here's my interpretation of that thought process, as if I were having it:
**Diving into NTFS Falloc:**
Right, so I need to understand how `ntfs_fallocate` in the `fs/ntfs3/file.c` code handles size modifications, specifically extending, shrinking, and locking. It's a critical function, so I'm going to dig in there. I want to see exactly how it manages those operations within the NTFS file system. I need to understand the low-level details of its implementation to assess its efficiency and potential edge cases. This will inform my understanding of the fs's overall approach to allocation and how it interacts with the on-disk structures. Let's see how they've handled this; I'm expecting some interesting considerations around clusters, extents, and the NTFS metadata.
|
| 425/4 |
2026/09/17 11:51 |
tool |
read-file |
0m
Args: map[File:fs/ntfs3/file.c FirstLine:515 LineCount:80]
Results: map[Contents: 515: }
516:
517: if (mode & (FALLOC_FL_PUNCH_HOLE | FALLOC_FL_COLLAPSE_RANGE |
518: FALLOC_FL_INSERT_RANGE)) {
519: inode_dio_wait(inode);
520: filemap_invalidate_lock(mapping);
521: map_locked = true;
522: }
523:
524: if (mode & FALLOC_FL_PUNCH_HOLE) {
525: u32 frame_size;
526: loff_t mask, vbo_a, end_a, tmp, from;
527:
528: err = filemap_write_and_wait_range(mapping, vbo_down,
529: LLONG_MAX);
530: if (err)
531: goto out;
532:
533: truncate_pagecache(inode, vbo_down);
534:
535: ni_lock(ni);
536: err = attr_punch_hole(ni, vbo, len, &frame_size);
537: ni_unlock(ni);
538: if (!err)
539: goto ok;
540:
541: if (err != E_NTFS_NOTALIGNED)
542: goto out;
543:
544: /* Process not aligned punch. */
545: err = 0;
546: if (end > i_size)
547: end = i_size;
548: mask = frame_size - 1;
549: vbo_a = (vbo + mask) & ~mask;
550: end_a = end & ~mask;
551:
552: tmp = min(vbo_a, end);
553: from = min_t(loff_t, ni->i_valid, vbo);
554: /* Zero head of punch. */
555: if (tmp > from) {
556: err = iomap_zero_range(inode, from, tmp - from, NULL,
557: &ntfs_iomap_ops,
558: &ntfs_iomap_folio_ops, NULL);
559: if (err)
560: goto out;
561: }
562:
563: /* Aligned punch_hole. Deallocate clusters. */
564: if (end_a > vbo_a) {
565: ni_lock(ni);
566: err = attr_punch_hole(ni, vbo_a, end_a - vbo_a, NULL);
567: ni_unlock(ni);
568: if (err)
569: goto out;
570: }
571:
572: /* Zero tail of punch. */
573: if (vbo < end_a && end_a < end) {
574: err = iomap_zero_range(inode, end_a, end - end_a, NULL,
575: &ntfs_iomap_ops,
576: &ntfs_iomap_folio_ops, NULL);
577: if (err)
578: goto out;
579: }
580: } else if (mode & FALLOC_FL_COLLAPSE_RANGE) {
581: /*
582: * Write tail of the last page before removed range since
583: * it will get removed from the page cache below.
584: */
585: err = filemap_write_and_wait_range(mapping, vbo_down, vbo);
586: if (err)
587: goto out;
588:
589: /*
590: * Write data that will be shifted to preserve them
591: * when discarding page cache below.
592: */
593: err = filemap_write_and_wait_range(mapping, end, LLONG_MAX);
594: if (err)
]
|
| 426/4 |
2026/09/17 11:51 |
llm |
codeexpert |
0m
Model:
Tokens:
input: 27877
output: 37
thoughts: 17
Thoughts: Here's my attempt at summarizing the thought process, tailored for an expert audience:
**Diving Deeper into `ntfs_fallocate` and Size Adjustments**
Okay, I'm thinking we need to zero in on how `ntfs_fallocate` handles size changes, specifically. We've seen some behavior that warrants a closer look around the boundary conditions and interactions with the NTFS file system metadata. My initial analysis suggests potential areas for further exploration. I need to understand this implementation in order to ensure the integrity of the file system. Let's dig deeper into the code around size adjustments and verify my assumptions.
|
| 427/4 |
2026/09/17 11:52 |
tool |
read-file |
0m
Args: map[File:fs/ntfs3/file.c FirstLine:660 LineCount:45]
Results: map[Contents: 660: if (is_supported_holes) {
661: CLST vcn = vbo >> cluster_bits;
662: CLST cend = bytes_to_cluster(sbi, end);
663: CLST lcn, clen;
664: bool new;
665:
666: /*
667: * Allocate and zero new clusters.
668: */
669: for (; vcn < cend; vcn += clen) {
670: err = attr_data_get_block(ni, vcn, cend - vcn,
671: &lcn, &clen, &new,
672: true, NULL, false);
673: if (err)
674: goto out;
675: }
676: }
677:
678: if (mode & FALLOC_FL_KEEP_SIZE) {
679: err = ntfs_set_size(inode, i_size);
680: if (err)
681: goto out;
682: }
683: }
684:
685: ok:
686: err = file_modified(file);
687: if (err)
688: goto out;
689:
690: out:
691: if (map_locked)
692: filemap_invalidate_unlock(mapping);
693:
694: if (!err) {
695: inode_set_mtime_to_ts(inode, inode_set_ctime_current(inode));
696: mark_inode_dirty(inode);
697: }
698:
699: inode_unlock(inode);
700: return err;
701: }
702:
703: /*
704: * ntfs_setattr - inode_operations::setattr
]
|
| 428/4 |
2026/09/17 11:52 |
llm |
codeexpert |
0m
Model:
Tokens:
input: 28640
output: 46
thoughts: 58
Thoughts: Here's my thought process, as if I were considering this code:
**Diving into NTFS File Writes**
Okay, so I need to understand how file size modifications are handled within the NTFS3 filesystem, specifically regarding writes. I need to pinpoint the relevant code paths in `fs/ntfs3/file.c`. My immediate focus is on how the functions `truncate_setsize`, `i_size_write`, and `pagecache_isize_extended` are utilized. These likely play a crucial role in managing the on-disk file size and metadata. I'll start by systematically searching for their calls, particularly within the context of the `ntfs_file_write_iter` function, as that's my primary entry point for write operations. I need to see exactly how these size-related functions are orchestrated within this write path. Are they used for pre-allocation, extending the file, or handling writes that necessitate a change in the overall file size? I need to understand the control flow surrounding these functions within the write process to ensure integrity. I also want to make sure I am not missing any subtle interactions across them. I will scrutinize any conditional logic or error handling that interacts with these functions. This is where the magic happens!
|
| 429/4 |
2026/09/17 11:52 |
tool |
grepper |
0m
Args: map[Expression:(truncate_setsize|pagecache_isize_extended|i_size_write) PathPrefix:fs/ntfs3/]
Results: map[Output:fs/ntfs3/attrib.c=430=int attr_set_size_ex(struct ntfs_inode *ni, enum ATTR_TYPE type,
--
fs/ntfs3/attrib.c-888-
fs/ntfs3/attrib.c:889: i_size_write(&ni->vfs_inode, new_size);
fs/ntfs3/attrib.c-890-
--
fs/ntfs3/attrib.c=2009=int attr_collapse_range(struct ntfs_inode *ni, u64 vbo, u64 bytes)
--
fs/ntfs3/attrib.c-2057- /* Simple truncate file at 'vbo'. */
fs/ntfs3/attrib.c:2058: truncate_setsize(&ni->vfs_inode, vbo);
fs/ntfs3/attrib.c-2059- err = attr_set_size(ni, ATTR_DATA, ni->file.ads.name,
--
fs/ntfs3/attrib.c-2285- ni->i_valid = valid_size;
fs/ntfs3/attrib.c:2286: i_size_write(&ni->vfs_inode, data_size);
fs/ntfs3/attrib.c-2287- inode_set_bytes(&ni->vfs_inode, total_size);
--
fs/ntfs3/attrib.c=2527=int attr_insert_range(struct ntfs_inode *ni, u64 vbo, u64 bytes)
--
fs/ntfs3/attrib.c-2719-done:
fs/ntfs3/attrib.c:2720: i_size_write(&ni->vfs_inode, ni->vfs_inode.i_size + bytes);
fs/ntfs3/attrib.c-2721- ni->ni_flags |= NI_FLAG_UPDATE_PARENT;
--
fs/ntfs3/file.c=706=int ntfs_setattr(struct mnt_idmap *idmap, struct dentry *dentry,
--
fs/ntfs3/file.c-738- if (newsize != oldsize) {
fs/ntfs3/file.c:739: truncate_setsize(inode, newsize);
fs/ntfs3/file.c-740-
--
fs/ntfs3/file.c-742- if (err) {
fs/ntfs3/file.c:743: i_size_write(inode, oldsize);
fs/ntfs3/file.c-744- goto out;
--
fs/ntfs3/file.c=984=static ssize_t ntfs_compress_write(struct kiocb *iocb, struct iov_iter *from)
--
fs/ntfs3/file.c-1199- if (iocb->ki_pos > i_size)
fs/ntfs3/file.c:1200: i_size_write(inode, iocb->ki_pos);
fs/ntfs3/file.c-1201-
--
fs/ntfs3/index.c=1474=static int indx_create_allocate(struct ntfs_index *indx, struct ntfs_inode *ni,
--
fs/ntfs3/index.c-1507- if (in->name == I30_NAME) {
fs/ntfs3/index.c:1508: i_size_write(&ni->vfs_inode, data_size);
fs/ntfs3/index.c-1509- inode_set_bytes(&ni->vfs_inode, alloc_size);
--
fs/ntfs3/index.c=1532=static int indx_add_allocate(struct ntfs_index *indx, struct ntfs_inode *ni,
--
fs/ntfs3/index.c-1605- if (in->name == I30_NAME)
fs/ntfs3/index.c:1606: i_size_write(&ni->vfs_inode, data_size);
fs/ntfs3/index.c-1607-
--
fs/ntfs3/index.c=2152=static int indx_shrink(struct ntfs_index *indx, struct ntfs_inode *ni,
--
fs/ntfs3/index.c-2203- if (in->name == I30_NAME)
fs/ntfs3/index.c:2204: i_size_write(&ni->vfs_inode, new_data);
fs/ntfs3/index.c-2205-
--
fs/ntfs3/index.c=2369=int indx_delete_entry(struct ntfs_index *indx, struct ntfs_inode *ni,
--
fs/ntfs3/index.c-2705- if (in->name == I30_NAME)
fs/ntfs3/index.c:2706: i_size_write(&ni->vfs_inode, 0);
fs/ntfs3/index.c-2707-
]
|
| 430/4 |
2026/09/17 11:52 |
llm |
codeexpert |
0m
Model:
Tokens:
input: 30315
output: 37
thoughts: 22
Thoughts: Here's my attempt at summarizing the thought process, tailored for an expert audience:
**Diving into the NTFS3 Attribute Code**
Okay, time to get my hands dirty. I'm suspecting a potential issue with attribute handling in the NTFS3 driver. Given my experience, the general area where attribute modifications tend to happen, especially around potential size calculations or allocation, often manifests around the attribute list handling. My instinct points me to the `fs/ntfs3/attrib.c` file. Specifically, I'm going to jump straight into the vicinity of line 889. That location seems like a logical place to start digging deeper to understand the code responsible for managing, potentially modify attributes. Time to go check it out!
|
| 431/4 |
2026/09/17 11:53 |
tool |
read-file |
0m
Args: map[File:fs/ntfs3/attrib.c FirstLine:880 LineCount:25]
Results: map[Contents: 880:
881: if ((type == ATTR_DATA || (type == ATTR_ALLOC && name == I30_NAME))) {
882: /* Update inode_set_bytes. */
883: if (attr_b->non_res &&
884: inode_get_bytes(&ni->vfs_inode) != new_alloc) {
885: inode_set_bytes(&ni->vfs_inode, new_alloc);
886: dirty = true;
887: }
888:
889: i_size_write(&ni->vfs_inode, new_size);
890:
891: /* Don't forget to update duplicate information in parent. */
892: if (dirty) {
893: ni->ni_flags |= NI_FLAG_UPDATE_PARENT;
894: mark_inode_dirty(&ni->vfs_inode);
895: }
896: }
897:
898: return 0;
899:
900: undo_2:
901: vcn -= alen;
902: attr_b->nres.data_size = cpu_to_le64(old_size);
903: attr_b->nres.valid_size = cpu_to_le64(old_valid);
904: attr_b->nres.alloc_size = cpu_to_le64(old_alloc);
]
|
| 432/4 |
2026/09/17 11:53 |
llm |
codeexpert |
0m
Model:
Tokens:
input: 30948
output: 38
thoughts: 75
Thoughts: Okay, here's the summary of my thought process, as if I'm navigating this code:
**Diving into the File Attribute Size Adjustment**
Right, hold on a second. I need to take a closer look at something here. Let me zoom in on `fs/ntfs3/attrib.c:889`. Specifically, I see `attr_set_size_ex` within that file β which is being called by `attr_set_size`.
Hang on... I'm just quickly confirming my understanding here; Is `attr_set_size` the function that's calling `attr_set_size_ex`? Just double-checking the call graph to confirm the relationship... Time to check the source code for `attr_set_size`. I need to verify that call.
|
| 433/4 |
2026/09/17 11:53 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:fs/ntfs3/inode.c Name:attr_set_size]
Results: map[SourceCode: 473: static inline int attr_set_size(struct ntfs_inode *ni, enum ATTR_TYPE type,
474: const __le16 *name, u8 name_len,
475: struct runs_tree *run, u64 new_size,
476: const u64 *new_valid, bool keep_prealloc)
477: {
478: return attr_set_size_ex(ni, type, name, name_len, run, new_size,
479: new_valid, keep_prealloc, NULL, false);
480: }
SourceFile:fs/ntfs3/ntfs_fs.h]
|
| 434/4 |
2026/09/17 11:53 |
llm |
codeexpert |
0m
Model:
Tokens:
input: 31431
output: 37
thoughts: 957
Thoughts: **Analyzing `ntfs_setattr` and File Size Updates**
Okay, let's break this down. First, I noticed that `attr_set_size_ex` within this system *does* indeed call `i_size_write(&ni->vfs_inode, new_size)`. But, is this the only path? I had to trace it. Based on the logic in `ntfs_set_size` and the conditional at line 881, specifically the conditions where `type` is `ATTR_DATA`, it confirms `attr_set_size_ex` is the execution path. This means that after a call to `ntfs_set_size(inode, newsize)`, the inode's size, `inode->i_size` *should* already be updated to `newsize`.
Now, if that's the case, calling `truncate_setsize(inode, newsize)` immediately after is critical. I had to confirm what `truncate_setsize` does. Looking at the code for `truncate_setsize`, it retrieves the `oldsize` from `inode->i_size`, then calls `i_size_write(inode, newsize)`. But, since `ntfs_set_size` has already updated `inode->i_size` to `newsize`, the initial `oldsize` will be equivalent to `newsize`. Therefore, the condition `newsize > oldsize` becomes `newsize > newsize`, which is false. This means that `pagecache_isize_extended` will *not* be called. This explains the prompt's condition.
The prompt specifically states that: if `newsize` is less than `oldsize` (shrinking), then `truncate_setsize` needs to be called before `ntfs_set_size`. If `newsize` is greater than `oldsize` (extending), then `ntfs_set_size` needs to be called before `truncate_setsize` (or rather, before `i_size_write` and `pagecache_isize_extended`, the implicit functions called after `ntfs_set_size`). And, crucially, both cases must be protected by `filemap_invalidate_lock(inode->i_mapping)`.
I need to create a patch for `ntfs_setattr` that correctly implements this sequencing and locking based on the comparison of the old and new sizes, making sure that there is no data corruption. The key is in the order of the calls and the condition in the size comparison, especially in light of the fact that `ntfs_set_size` directly modifies the inode's size.
|
| 435/4 |
2026/09/17 11:53 |
tool |
read-file |
0m
Args: map[File:fs/ntfs3/attrib.c FirstLine:870 LineCount:45]
Results: map[Contents: 870:
871: if (attr_b->nres.valid_size != valid) {
872: attr_b->nres.valid_size = valid;
873: mi_b->dirty = true;
874: }
875: }
876:
877: ok1:
878: if (ret)
879: *ret = attr_b;
880:
881: if ((type == ATTR_DATA || (type == ATTR_ALLOC && name == I30_NAME))) {
882: /* Update inode_set_bytes. */
883: if (attr_b->non_res &&
884: inode_get_bytes(&ni->vfs_inode) != new_alloc) {
885: inode_set_bytes(&ni->vfs_inode, new_alloc);
886: dirty = true;
887: }
888:
889: i_size_write(&ni->vfs_inode, new_size);
890:
891: /* Don't forget to update duplicate information in parent. */
892: if (dirty) {
893: ni->ni_flags |= NI_FLAG_UPDATE_PARENT;
894: mark_inode_dirty(&ni->vfs_inode);
895: }
896: }
897:
898: return 0;
899:
900: undo_2:
901: vcn -= alen;
902: attr_b->nres.data_size = cpu_to_le64(old_size);
903: attr_b->nres.valid_size = cpu_to_le64(old_valid);
904: attr_b->nres.alloc_size = cpu_to_le64(old_alloc);
905:
906: /* Restore 'attr' and 'mi'. */
907: if (attr)
908: goto restore_run;
909:
910: if (le64_to_cpu(attr_b->nres.svcn) <= svcn &&
911: svcn <= le64_to_cpu(attr_b->nres.evcn)) {
912: attr = attr_b;
913: le = le_b;
914: mi = mi_b;
]
|
| 436/4 |
2026/09/17 11:53 |
llm |
codeexpert |
0m
Model:
Tokens:
input: 33803
output: 968
thoughts: 5890
Thoughts: **Refactoring `ntfs_setattr` for Size Updates**
Okay, here's the breakdown of the changes needed for `ntfs_setattr`, incorporating the provided guidelines. I've been carefully reviewing this to ensure we're aligning with the principles for handling file size updates within the NTFS3 filesystem, particularly regarding the proper sequencing of `truncate_setsize`, `ntfs_set_size`, and the page cache.
The core of the issue revolves around ensuring data consistency and cache coherency when either shrinking or extending a file's size. We need to use `filemap_invalidate_lock` and `filemap_invalidate_unlock` to guarantee exclusive access to the inode's mapping during these critical operations, as the prompt specifies.
Hereβs the adjusted logic:
1. **Locking:** We begin by acquiring the `filemap_invalidate_lock(inode->i_mapping)` before any size modifications and release it with `filemap_invalidate_unlock(inode->i_mapping)`. This provides the necessary protection against race conditions.
2. **Shrinking (`newsize < oldsize`):**
* Call `truncate_setsize(inode, newsize)` *first*. This prepares the underlying blocks for the reduction.
* Then, call `err = ntfs_set_size(inode, newsize)`.
* If `ntfs_set_size` fails (returns a non-zero error), we *must* restore the original size using `i_size_write(inode, oldsize)`. This is essential for maintaining data integrity.
3. **Extending (`newsize > oldsize`):**
* Call `err = ntfs_set_size(inode, newsize)`. This step modifies the NTFS data structures to reflect the new size.
* Here's where the nuance lies: since `ntfs_set_size` internally calls `i_size_write(&ni->vfs_inode, new_size);`, calling `truncate_setsize(inode, newsize)` *after* `ntfs_set_size` would result in a no-op call to `pagecache_isize_extended`. Thus:
* Option A (recommended and strictly correct): We need to *explicitly* handle the page cache extension: `i_size_write(inode, newsize); pagecache_isize_extended(inode, oldsize, newsize)`. These two combined handle cases where `ntfs_set_size` did, or did not, update the `inode->i_size` properly; the point is to *guarantee* `pagecache_isize_extended` is called with the *original* `oldsize` and the new `newsize`.
* Option B (Alternative, and potentially a no-op if the code correctly updates `inode->i_size`): The user prompt specifies: `ntfs_set_size` must be called before `truncate_setsize` (or `i_size_write` + `pagecache_isize_extended`). So the second valid variant for implementing is to call `truncate_setsize(inode, newsize)` in case `ntfs_set_size` did *not* update the size.
4. **Error Handling:** In both shrinking and extending cases, if `ntfs_set_size` fails, we jump to `out;` after unlocking, reverting any changes as needed to ensure data integrity.
* **Caveat:** This implementation assumes `ntfs_set_size` handles the actual data allocation on the NTFS volume, and we're coordinating the VFS and page cache aspects. Also, as this is a refactoring, there is a possibility that some subtle interaction might be missed because the original upstream commit was not verified directly, but the logic is sound and conforms to kernel conventions.
The changes are implemented in the diff below.
```diff
--- a/fs/ntfs3/file.c
+++ b/fs/ntfs3/file.c
@@ -736,12 +736,21 @@ int ntfs_setattr(struct mnt_idmap *idmap, struct dentry *dentry,
newsize = attr->ia_size;
if (newsize != oldsize) {
- truncate_setsize(inode, newsize);
+ filemap_invalidate_lock(inode->i_mapping);
+ if (newsize < oldsize) {
+ truncate_setsize(inode, newsize);
+ err = ntfs_set_size(inode, newsize);
+ if (err)
|
| 437/4 |
2026/09/17 11:54 |
tool |
set-results |
0m
Args: map[Answer:Here is the patch for `fs/ntfs3/file.c` implementing the requested logic in `ntfs_setattr`:
```diff
--- a/fs/ntfs3/file.c
+++ b/fs/ntfs3/file.c
@@ -736,12 +736,21 @@ int ntfs_setattr(struct mnt_idmap *idmap, struct dentry *dentry,
newsize = attr->ia_size;
if (newsize != oldsize) {
- truncate_setsize(inode, newsize);
+ filemap_invalidate_lock(inode->i_mapping);
+ if (newsize < oldsize) {
+ truncate_setsize(inode, newsize);
+ err = ntfs_set_size(inode, newsize);
+ if (err)
+ i_size_write(inode, oldsize);
+ } else {
+ err = ntfs_set_size(inode, newsize);
+ if (!err) {
+ i_size_write(inode, newsize);
+ pagecache_isize_extended(inode, oldsize,
+ newsize);
+ }
+ }
+ filemap_invalidate_unlock(inode->i_mapping);
+ if (err)
+ goto out;
- err = ntfs_set_size(inode, newsize);
- if (err) {
- i_size_write(inode, oldsize);
- goto out;
- }
-
ni->std_fa |= FILE_ATTRIBUTE_ARCHIVE;
ni->ni_flags |= NI_FLAG_UPDATE_PARENT;
inode_set_mtime_to_ts(inode,
```
### Explanation & Verification Notes
1. **Shrinking (`newsize < oldsize`)**:
- `truncate_setsize(inode, newsize)` is invoked first to update `i_size` and drop truncated page cache folios, preventing readers from seeing stale data past the new EOF.
- `ntfs_set_size(inode, newsize)` is then called to deallocate/shrink on-disk clusters.
- If `ntfs_set_size` fails, `i_size_write(inode, oldsize)` restores the in-memory inode size.
2. **Extending (`newsize > oldsize`)**:
- `ntfs_set_size(inode, newsize)` is called first to allocate the necessary metadata/clusters.
- If `ntfs_set_size` succeeds, `i_size_write(inode, newsize)` and `pagecache_isize_extended(inode, oldsize, newsize)` are called.
- *Note*: Inside `ntfs_set_size` -> `attr_set_size` -> `attr_set_size_ex`, `i_size_write(&ni->vfs_inode, new_size)` is executed. Calling `truncate_setsize(inode, newsize)` afterwards would see `inode->i_size == newsize` and skip calling `pagecache_isize_extended(inode, oldsize, newsize)`. Therefore, using `i_size_write(inode, newsize); pagecache_isize_extended(inode, oldsize, newsize);` ensures `pagecache_isize_extended` is invoked with the proper `oldsize` and `newsize`. (If preferred, `truncate_setsize(inode, newsize)` can be used instead if `i_size_write` is omitted from `attr_set_size_ex`).
3. **Locking**:
- Both shrinking and extending operations are serialized against concurrent page faults and page cache instantiations using `filemap_invalidate_lock(inode->i_mapping)` and `filemap_invalidate_unlock(inode->i_mapping)`.
### Caveats and Unverified Parts
- Because the repository history in the workspace is shallow, the exact upstream commit or mailing list discussion introducing this specific change could not be verified against `git log`.
- Regression testing via `xfstests` / NTFS test suites was not run within this environment.]
Results: map[Answer:Here is the patch for `fs/ntfs3/file.c` implementing the requested logic in `ntfs_setattr`:
```diff
--- a/fs/ntfs3/file.c
+++ b/fs/ntfs3/file.c
@@ -736,12 +736,21 @@ int ntfs_setattr(struct mnt_idmap *idmap, struct dentry *dentry,
newsize = attr->ia_size;
if (newsize != oldsize) {
- truncate_setsize(inode, newsize);
+ filemap_invalidate_lock(inode->i_mapping);
+ if (newsize < oldsize) {
+ truncate_setsize(inode, newsize);
+ err = ntfs_set_size(inode, newsize);
+ if (err)
+ i_size_write(inode, oldsize);
+ } else {
+ err = ntfs_set_size(inode, newsize);
+ if (!err) {
+ i_size_write(inode, newsize);
+ pagecache_isize_extended(inode, oldsize,
+ newsize);
+ }
+ }
+ filemap_invalidate_unlock(inode->i_mapping);
+ if (err)
+ goto out;
- err = ntfs_set_size(inode, newsize);
- if (err) {
- i_size_write(inode, oldsize);
- goto out;
- }
-
ni->std_fa |= FILE_ATTRIBUTE_ARCHIVE;
ni->ni_flags |= NI_FLAG_UPDATE_PARENT;
inode_set_mtime_to_ts(inode,
```
### Explanation & Verification Notes
1. **Shrinking (`newsize < oldsize`)**:
- `truncate_setsize(inode, newsize)` is invoked first to update `i_size` and drop truncated page cache folios, preventing readers from seeing stale data past the new EOF.
- `ntfs_set_size(inode, newsize)` is then called to deallocate/shrink on-disk clusters.
- If `ntfs_set_size` fails, `i_size_write(inode, oldsize)` restores the in-memory inode size.
2. **Extending (`newsize > oldsize`)**:
- `ntfs_set_size(inode, newsize)` is called first to allocate the necessary metadata/clusters.
- If `ntfs_set_size` succeeds, `i_size_write(inode, newsize)` and `pagecache_isize_extended(inode, oldsize, newsize)` are called.
- *Note*: Inside `ntfs_set_size` -> `attr_set_size` -> `attr_set_size_ex`, `i_size_write(&ni->vfs_inode, new_size)` is executed. Calling `truncate_setsize(inode, newsize)` afterwards would see `inode->i_size == newsize` and skip calling `pagecache_isize_extended(inode, oldsize, newsize)`. Therefore, using `i_size_write(inode, newsize); pagecache_isize_extended(inode, oldsize, newsize);` ensures `pagecache_isize_extended` is invoked with the proper `oldsize` and `newsize`. (If preferred, `truncate_setsize(inode, newsize)` can be used instead if `i_size_write` is omitted from `attr_set_size_ex`).
3. **Locking**:
- Both shrinking and extending operations are serialized against concurrent page faults and page cache instantiations using `filemap_invalidate_lock(inode->i_mapping)` and `filemap_invalidate_unlock(inode->i_mapping)`.
### Caveats and Unverified Parts
- Because the repository history in the workspace is shallow, the exact upstream commit or mailing list discussion introducing this specific change could not be verified against `git log`.
- Regression testing via `xfstests` / NTFS test suites was not run within this environment.]
|
| 438/2 |
2026/09/17 11:54 |
llm |
debugger |
0m
Model:
Tokens:
input: 70942
output: 402
thoughts: 0
|
| 439/2 |
2026/09/17 11:54 |
tool |
codeexpert |
0m
Error:
Args: map[Question:Wait, `truncate_setsize` does:
```c
void truncate_setsize(struct inode *inode, loff_t newsize)
{
loff_t oldsize = inode->i_size;
i_size_write(inode, newsize);
if (newsize > oldsize)
pagecache_isize_extended(inode, oldsize, newsize);
truncate_pagecache(inode, newsize);
}
```
If `ntfs_set_size` already updated `inode->i_size` to `newsize`, then `oldsize` in `truncate_setsize` will be `newsize`, so `pagecache_isize_extended` will NOT be called.
Is that a problem?
Should we just use `pagecache_isize_extended` manually, or should we remove `i_size_write` from `attr_set_size_ex`?
Wait, if `attr_set_size_ex` updates `i_size_write`, then `pagecache_isize_extended` is skipped. But `attr_set_size_ex` is used in many places.
Let's check if `pagecache_isize_extended` is needed.
If we use `pagecache_isize_extended(inode, oldsize, newsize)` manually, we should also call `truncate_pagecache(inode, newsize)`? No, extending doesn't need `truncate_pagecache`.
Wait, `truncate_setsize` is fine if we just call it, but if `i_size` is already updated, it won't call `pagecache_isize_extended`.
Let's check if `ntfs_set_size` updates `i_size`.]
|
| 440/3 |
2026/09/17 11:54 |
agent |
codeexpert |
0m
Model:
Error:
Instruction:
You are a capable Linux kernel developer tasked with researching complex questions
about kernel source code. You will be given a concrete question, and need to provide
a concrete answer.
Research the question using targeted, efficient tool calls. Don't make assumptions,
or rely on your previous knowledge about the kernel source code, use available tools
to access the actual source code. Keep your tool calls focused and limited to the
scope of the question. Do not explore tangential code paths or perform unbounded searches.
Use all available sources of information:
- kernel source code
- documentation in the Documentation dir in the source tree
- git commits descriptions, git blame
Do not guess file names or file paths and attempt to read them without
verifying their existence first using content search or directory listing tools.
If a file, symbol, or directory is not found via content search (grepper) or
directory listing (codesearch-dir-index), treat it as completely absent.
Do not attempt to guess alternative names, extensions, or directories.
Tool Selection Guidelines:
1. For C functions, structs, and variables: Prefer codesearch-definition-source
or codesearch-struct-layout FIRST to retrieve clean, exact definitions
without line-number guessing.
2. If symbol lookup fails (e.g., preprocessor macros, macro-generated code, or
disabled #ifdef branches), fall back to read-file or grepper.
3. For file headers, #include directives, preprocessor macro definitions, and
non-C files (Kconfig, Makefiles, docs): Use read-file or grepper directly.
4. Be concise and targeted. Answer the question as directly and concisely as possible
once you have located the relevant code or definitions. If a symbol or function cannot
be found after targeted searches, conclude with the best available information rather
than continuing repetitive searches.
Do NOT use git-log to search for the presence or existence of files in the
repository. git-log is only for tracing commit history of files that are
already present in the current checkout. If a file does not exist in the
current checkout, it cannot be used for reproduction.
Avoid running broad git-log queries (such as searches on the entire repo)
without a specific 'PathPrefix' to restrict the scope, as these are very
expensive and will time out.
If a git-log tool call times out, do not retry the query with the same broad
scope. You must specify a tighter, narrower 'PathPrefix' for subsequent queries.
Prefer calling several tools at the same time to save round-trips.
Use set-results tool to provide results of the analysis.
It must be called exactly once before the final reply.
Ignore results of this tool.
Prompt: Wait, `truncate_setsize` does:
```c
void truncate_setsize(struct inode *inode, loff_t newsize)
{
loff_t oldsize = inode->i_size;
i_size_write(inode, newsize);
if (newsize > oldsize)
pagecache_isize_extended(inode, oldsize, newsize);
truncate_pagecache(inode, newsize);
}
```
If `ntfs_set_size` already updated `inode->i_size` to `newsize`, then `oldsize` in `truncate_setsize` will be `newsize`, so `pagecache_isize_extended` will NOT be called.
Is that a problem?
Should we just use `pagecache_isize_extended` manually, or should we remove `i_size_write` from `attr_set_size_ex`?
Wait, if `attr_set_size_ex` updates `i_size_write`, then `pagecache_isize_extended` is skipped. But `attr_set_size_ex` is used in many places.
Let's check if `pagecache_isize_extended` is needed.
If we use `pagecache_isize_extended(inode, oldsize, newsize)` manually, we should also call `truncate_pagecache(inode, newsize)`? No, extending doesn't need `truncate_pagecache`.
Wait, `truncate_setsize` is fine if we just call it, but if `i_size` is already updated, it won't call `pagecache_isize_extended`.
Let's check if `ntfs_set_size` updates `i_size`.
|
| 441/4 |
2026/09/17 11:54 |
llm |
codeexpert |
0m
Model:
Error:
|