Skip to content

Commit 5dc836a

Browse files
terraluna977eafer
authored andcommitted
Support for kernel 6.7
[eafer: fixed some issues with folios and timestamps] Signed-off-by: Ernesto A. Fernández <ernesto@corellium.com>
1 parent fe13bc9 commit 5dc836a

File tree

5 files changed

+81
-11
lines changed

5 files changed

+81
-11
lines changed

apfs.h

+4
Original file line numberDiff line numberDiff line change
@@ -1142,7 +1142,11 @@ apfs_getblk(struct super_block *sb, sector_t block)
11421142
{
11431143
structbuffer_head*bh;
11441144

1145+
#ifLINUX_VERSION_CODE<KERNEL_VERSION(6, 7, 0)
11451146
bh=__getblk_gfp(APFS_NXI(sb)->nx_bdev, block, sb->s_blocksize, __GFP_MOVABLE);
1147+
#else
1148+
bh=bdev_getblk(APFS_NXI(sb)->nx_bdev, block, sb->s_blocksize, __GFP_MOVABLE);
1149+
#endif
11461150
if (bh)
11471151
set_buffer_uptodate(bh);
11481152
returnbh;

dir.c

+12-4
Original file line numberDiff line numberDiff line change
@@ -604,8 +604,10 @@ static int apfs_create_dentry(struct dentry *dentry, struct inode *inode)
604604
/* Now update the parent inode */
605605
#ifLINUX_VERSION_CODE<KERNEL_VERSION(6, 6, 0)
606606
parent->i_mtime=parent->i_ctime=current_time(inode);
607-
#else
607+
#elifLINUX_VERSION_CODE<KERNEL_VERSION(6, 7, 0)
608608
parent->i_mtime=inode_set_ctime_current(parent);
609+
#else
610+
inode_set_mtime_to_ts(parent, inode_set_ctime_current(parent));
609611
#endif
610612
++APFS_I(parent)->i_nchildren;
611613
apfs_inode_join_transaction(parent->i_sb, parent);
@@ -1037,8 +1039,10 @@ static int apfs_delete_dentry(struct dentry *dentry)
10371039
/* Now update the parent inode */
10381040
#ifLINUX_VERSION_CODE<KERNEL_VERSION(6, 6, 0)
10391041
parent->i_mtime=parent->i_ctime=current_time(parent);
1040-
#else
1042+
#elifLINUX_VERSION_CODE<KERNEL_VERSION(6, 7, 0)
10411043
parent->i_mtime=inode_set_ctime_current(parent);
1044+
#else
1045+
inode_set_mtime_to_ts(parent, inode_set_ctime_current(parent));
10421046
#endif
10431047
--APFS_I(parent)->i_nchildren;
10441048
apfs_inode_join_transaction(sb, parent);
@@ -1201,8 +1205,10 @@ static int apfs_create_orphan_link(struct inode *inode)
12011205
/* Now update the child count for private-dir */
12021206
#ifLINUX_VERSION_CODE<KERNEL_VERSION(6, 6, 0)
12031207
priv_dir->i_mtime=priv_dir->i_ctime=current_time(priv_dir);
1204-
#else
1208+
#elifLINUX_VERSION_CODE<KERNEL_VERSION(6, 7, 0)
12051209
priv_dir->i_mtime=inode_set_ctime_current(priv_dir);
1210+
#else
1211+
inode_set_mtime_to_ts(priv_dir, inode_set_ctime_current(priv_dir));
12061212
#endif
12071213
++APFS_I(priv_dir)->i_nchildren;
12081214
apfs_inode_join_transaction(sb, priv_dir);
@@ -1250,8 +1256,10 @@ int apfs_delete_orphan_link(struct inode *inode)
12501256
/* Now update the child count for private-dir */
12511257
#ifLINUX_VERSION_CODE<KERNEL_VERSION(6, 6, 0)
12521258
priv_dir->i_mtime=priv_dir->i_ctime=current_time(priv_dir);
1253-
#else
1259+
#elifLINUX_VERSION_CODE<KERNEL_VERSION(6, 7, 0)
12541260
priv_dir->i_mtime=inode_set_ctime_current(priv_dir);
1261+
#else
1262+
inode_set_mtime_to_ts(priv_dir, inode_set_ctime_current(priv_dir));
12551263
#endif
12561264
--APFS_I(priv_dir)->i_nchildren;
12571265
apfs_inode_join_transaction(sb, priv_dir);

extents.c

+11-1
Original file line numberDiff line numberDiff line change
@@ -1694,8 +1694,10 @@ int apfs_clone_file_range(struct file *src_file, loff_t off, struct file *dst_fi
16941694

16951695
#ifLINUX_VERSION_CODE<KERNEL_VERSION(6, 6, 0)
16961696
dst_inode->i_mtime=dst_inode->i_ctime=current_time(dst_inode);
1697-
#else
1697+
#elifLINUX_VERSION_CODE<KERNEL_VERSION(6, 7, 0)
16981698
dst_inode->i_mtime=inode_set_ctime_current(dst_inode);
1699+
#else
1700+
inode_set_mtime_to_ts(dst_inode, inode_set_ctime_current(dst_inode));
16991701
#endif
17001702
dst_inode->i_size=src_inode->i_size;
17011703
dst_ai->i_key_class=src_ai->i_key_class;
@@ -2171,7 +2173,11 @@ int apfs_nonsparse_dstream_read(struct apfs_dstream_info *dstream, void *buf, si
21712173
goto out;
21722174
}
21732175

2176+
#ifLINUX_VERSION_CODE<KERNEL_VERSION(6, 7, 0)
21742177
bhs[idx] =__getblk_gfp(APFS_NXI(sb)->nx_bdev, bno, sb->s_blocksize, __GFP_MOVABLE);
2178+
#else
2179+
bhs[idx] =bdev_getblk(APFS_NXI(sb)->nx_bdev, bno, sb->s_blocksize, __GFP_MOVABLE);
2180+
#endif
21752181
if (!bhs[idx]) {
21762182
apfs_err(sb, "failed to map block 0x%llx", bno);
21772183
ret=-EIO;
@@ -2243,7 +2249,11 @@ void apfs_nonsparse_dstream_preread(struct apfs_dstream_info *dstream)
22432249
if (ret||bno==0)
22442250
return;
22452251

2252+
#ifLINUX_VERSION_CODE<KERNEL_VERSION(6, 7, 0)
22462253
bh=__getblk_gfp(APFS_NXI(sb)->nx_bdev, bno, sb->s_blocksize, __GFP_MOVABLE);
2254+
#else
2255+
bh=bdev_getblk(APFS_NXI(sb)->nx_bdev, bno, sb->s_blocksize, __GFP_MOVABLE);
2256+
#endif
22472257
if (!bh)
22482258
return;
22492259
if (!buffer_uptodate(bh)) {

file.c

+12-1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ static vm_fault_t apfs_page_mkwrite(struct vm_fault *vmf)
1818
structvm_area_struct*vma=vmf->vma;
1919
#endif
2020
structpage*page=vmf->page;
21+
#ifLINUX_VERSION_CODE >= KERNEL_VERSION(6, 7, 0)
22+
structfolio*folio;
23+
#endif
2124
structinode*inode=file_inode(vma->vm_file);
2225
structsuper_block*sb=inode->i_sb;
2326
structbuffer_head*bh, *head;
@@ -54,8 +57,16 @@ static vm_fault_t apfs_page_mkwrite(struct vm_fault *vmf)
5457
goto out_unlock;
5558
}
5659

57-
if (!page_has_buffers(page))
60+
if (!page_has_buffers(page)) {
61+
#ifLINUX_VERSION_CODE<KERNEL_VERSION(6, 7, 0)
5862
create_empty_buffers(page, sb->s_blocksize, 0);
63+
#else
64+
folio=page_folio(page);
65+
bh=folio_buffers(folio);
66+
if (!bh)
67+
bh=create_empty_buffers(folio, sb->s_blocksize, 0);
68+
#endif
69+
}
5970

6071
size=i_size_read(inode);
6172
if (page->index==size >> PAGE_SHIFT)

inode.c

+42-5
Original file line numberDiff line numberDiff line change
@@ -476,6 +476,9 @@ int __apfs_write_begin(struct file *file, struct address_space *mapping, loff_t
476476
structapfs_dstream_info*dstream=&APFS_I(inode)->i_dstream;
477477
structsuper_block*sb=inode->i_sb;
478478
structpage*page;
479+
#ifLINUX_VERSION_CODE >= KERNEL_VERSION(6, 7, 0)
480+
structfolio*folio;
481+
#endif
479482
structbuffer_head*bh, *head;
480483
unsigned intblocksize, block_start, block_end, from, to;
481484
pgoff_tindex=pos >> PAGE_SHIFT;
@@ -508,8 +511,16 @@ int __apfs_write_begin(struct file *file, struct address_space *mapping, loff_t
508511
#endif
509512
if (!page)
510513
return-ENOMEM;
511-
if (!page_has_buffers(page))
514+
if (!page_has_buffers(page)) {
515+
#ifLINUX_VERSION_CODE<KERNEL_VERSION(6, 7, 0)
512516
create_empty_buffers(page, sb->s_blocksize, 0);
517+
#else
518+
folio=page_folio(page);
519+
bh=folio_buffers(folio);
520+
if (!bh)
521+
bh=create_empty_buffers(folio, sb->s_blocksize, 0);
522+
#endif
523+
}
513524

514525
/* CoW moves existing blocks, so read them but mark them as unmapped */
515526
head=page_buffers(page);
@@ -787,13 +798,19 @@ static int apfs_inode_from_query(struct apfs_query *query, struct inode *inode)
787798
ai->i_nchildren=le32_to_cpu(inode_val->nchildren);
788799
}
789800

790-
inode->i_atime=ns_to_timespec64(le64_to_cpu(inode_val->access_time));
791801
#ifLINUX_VERSION_CODE<KERNEL_VERSION(6, 6, 0)
792802
inode->i_ctime=ns_to_timespec64(le64_to_cpu(inode_val->change_time));
793803
#else
794804
inode_set_ctime_to_ts(inode, ns_to_timespec64(le64_to_cpu(inode_val->change_time)));
795805
#endif
806+
807+
#ifLINUX_VERSION_CODE<KERNEL_VERSION(6, 7, 0)
808+
inode->i_atime=ns_to_timespec64(le64_to_cpu(inode_val->access_time));
796809
inode->i_mtime=ns_to_timespec64(le64_to_cpu(inode_val->mod_time));
810+
#else
811+
inode_set_atime_to_ts(inode, ns_to_timespec64(le64_to_cpu(inode_val->access_time)));
812+
inode_set_mtime_to_ts(inode, ns_to_timespec64(le64_to_cpu(inode_val->mod_time)));
813+
#endif
797814
ai->i_crtime=ns_to_timespec64(le64_to_cpu(inode_val->create_time));
798815

799816
dstream->ds_size=inode->i_size=inode->i_blocks=0;
@@ -1097,6 +1114,9 @@ static int apfs_build_inode_val(struct inode *inode, struct qstr *qname,
10971114
{
10981115
structapfs_inode_val*val;
10991116
structapfs_x_fieldxkey;
1117+
#ifLINUX_VERSION_CODE >= KERNEL_VERSION(6, 7, 0)
1118+
structtimespec64ts;
1119+
#endif
11001120
inttotal_xlen, val_len;
11011121
boolis_device=S_ISCHR(inode->i_mode) ||S_ISBLK(inode->i_mode);
11021122
__le32rdev;
@@ -1115,7 +1135,12 @@ static int apfs_build_inode_val(struct inode *inode, struct qstr *qname,
11151135
val->parent_id=cpu_to_le64(APFS_I(inode)->i_parent_id);
11161136
val->private_id=cpu_to_le64(apfs_ino(inode));
11171137

1138+
#ifLINUX_VERSION_CODE<KERNEL_VERSION(6, 7, 0)
11181139
val->mod_time=cpu_to_le64(timespec64_to_ns(&inode->i_mtime));
1140+
#else
1141+
ts=inode_get_mtime(inode);
1142+
val->mod_time=cpu_to_le64(timespec64_to_ns(&ts));
1143+
#endif
11191144
val->create_time=val->change_time=val->access_time=val->mod_time;
11201145

11211146
if (S_ISDIR(inode->i_mode))
@@ -1477,14 +1502,22 @@ int apfs_update_inode(struct inode *inode, char *new_name)
14771502
if (gid_valid(sbi->s_gid))
14781503
inode_raw->group=cpu_to_le32(ai->i_saved_gid);
14791504

1480-
inode_raw->access_time=cpu_to_le64(timespec64_to_ns(&inode->i_atime));
14811505
#ifLINUX_VERSION_CODE<KERNEL_VERSION(6, 6, 0)
14821506
inode_raw->change_time=cpu_to_le64(timespec64_to_ns(&inode->i_ctime));
14831507
#else
14841508
structtimespec64ictime=inode_get_ctime(inode);
14851509
inode_raw->change_time=cpu_to_le64(timespec64_to_ns(&ictime));
14861510
#endif
1511+
1512+
#ifLINUX_VERSION_CODE<KERNEL_VERSION(6, 7, 0)
1513+
inode_raw->access_time=cpu_to_le64(timespec64_to_ns(&inode->i_atime));
14871514
inode_raw->mod_time=cpu_to_le64(timespec64_to_ns(&inode->i_mtime));
1515+
#else
1516+
structtimespec64ts=inode_get_mtime(inode);
1517+
inode_raw->mod_time=cpu_to_le64(timespec64_to_ns(&ts));
1518+
ts=inode_get_atime(inode);
1519+
inode_raw->access_time=cpu_to_le64(timespec64_to_ns(&ts));
1520+
#endif
14881521
inode_raw->create_time=cpu_to_le64(timespec64_to_ns(&ai->i_crtime));
14891522

14901523
if (S_ISDIR(inode->i_mode)) {
@@ -1665,9 +1698,11 @@ struct inode *apfs_new_inode(struct inode *dir, umode_t mode, dev_t rdev)
16651698
now=current_time(inode);
16661699
#ifLINUX_VERSION_CODE<KERNEL_VERSION(6, 6, 0)
16671700
inode->i_atime=inode->i_mtime=inode->i_ctime=ai->i_crtime=now;
1668-
#else
1701+
#elifLINUX_VERSION_CODE<KERNEL_VERSION(6, 7, 0)
16691702
inode_set_ctime_to_ts(inode, now);
16701703
inode->i_atime=inode->i_mtime=ai->i_crtime=now;
1704+
#else
1705+
ai->i_crtime=simple_inode_init_ts(inode);
16711706
#endif
16721707
vsb_raw->apfs_last_mod_time=cpu_to_le64(timespec64_to_ns(&now));
16731708

@@ -1762,8 +1797,10 @@ static int apfs_setsize(struct inode *inode, loff_t new_size)
17621797
return0;
17631798
#ifLINUX_VERSION_CODE<KERNEL_VERSION(6, 6, 0)
17641799
inode->i_mtime=inode->i_ctime=current_time(inode);
1765-
#else
1800+
#elifLINUX_VERSION_CODE<KERNEL_VERSION(6, 7, 0)
17661801
inode->i_mtime=inode_set_ctime_current(inode);
1802+
#else
1803+
inode_set_mtime_to_ts(inode, inode_set_ctime_current(inode));
17671804
#endif
17681805

17691806
err=apfs_inode_create_dstream_rec(inode);

0 commit comments

Comments
 (0)
close