Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion file.c
Original file line number Diff line number Diff line change
Expand Up @@ -96,10 +96,19 @@ static int simplefs_readpage(struct file *file, struct page *page)
/* Called by the page cache to write a dirty page to the physical disk (when
* sync is called or when memory is needed).
*/
#if LINUX_VERSION_CODE >= KERNEL_VERSION(6, 8, 0)
static int simplefs_writepage(struct page *page, struct writeback_control *wbc)
{
struct folio *folio = page_folio(page);
return __block_write_full_folio(page->mapping->host, folio,
simplefs_file_get_block, wbc);
}
#else
static int simplefs_writepage(struct page *page, struct writeback_control *wbc)
{
return block_write_full_page(page, simplefs_file_get_block, wbc);
}
#endif

/* Called by the VFS when a write() syscall is made on a file, before writing
* the data into the page cache. This function checks if the write operation
Expand Down Expand Up @@ -183,7 +192,11 @@ static int simplefs_write_end(struct file *file,
/* Update inode metadata */
inode->i_blocks = inode->i_size / SIMPLEFS_BLOCK_SIZE + 2;

#if LINUX_VERSION_CODE >= KERNEL_VERSION(6, 6, 0)
#if LINUX_VERSION_CODE >= KERNEL_VERSION(6, 7, 0)
cur_time = current_time(inode);
inode_set_mtime_to_ts(inode, cur_time);
inode_set_ctime_to_ts(inode, cur_time);
#elif LINUX_VERSION_CODE >= KERNEL_VERSION(6, 6, 0)
cur_time = current_time(inode);
inode->i_mtime = cur_time;
inode_set_ctime_to_ts(inode, cur_time);
Expand Down
41 changes: 34 additions & 7 deletions inode.c
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,16 @@ struct inode *simplefs_iget(struct super_block *sb, unsigned long ino)
inode->i_ctime.tv_nsec = 0;
#endif

#if LINUX_VERSION_CODE >= KERNEL_VERSION(6, 7, 0)
inode_set_atime(inode, (time64_t) le32_to_cpu(cinode->i_atime), 0);
inode_set_mtime(inode, (time64_t) le32_to_cpu(cinode->i_mtime), 0);
#else
inode->i_atime.tv_sec = (time64_t) le32_to_cpu(cinode->i_atime);
inode->i_atime.tv_nsec = 0;
inode->i_mtime.tv_sec = (time64_t) le32_to_cpu(cinode->i_mtime);
inode->i_mtime.tv_nsec = 0;
#endif

inode->i_blocks = le32_to_cpu(cinode->i_blocks);
set_nlink(inode, le32_to_cpu(cinode->i_nlink));

Expand Down Expand Up @@ -161,7 +167,12 @@ static struct dentry *simplefs_lookup(struct inode *dir,
brelse(bh);

/* Update directory access time */
#if LINUX_VERSION_CODE >= KERNEL_VERSION(6, 7, 0)
inode_set_atime_to_ts(dir, current_time(dir));
#else
dir->i_atime = current_time(dir);
#endif

mark_inode_dirty(dir);

/* Fill the dentry with the inode */
Expand Down Expand Up @@ -219,7 +230,9 @@ static struct inode *simplefs_new_inode(struct inode *dir, mode_t mode)
#endif
set_nlink(inode, 1);

#if LINUX_VERSION_CODE >= KERNEL_VERSION(6, 6, 0)
#if LINUX_VERSION_CODE >= KERNEL_VERSION(6, 7, 0)
simple_inode_init_ts(inode);
#elif LINUX_VERSION_CODE >= KERNEL_VERSION(6, 6, 0)
cur_time = current_time(inode);
inode->i_atime = inode->i_mtime = cur_time;
inode_set_ctime_to_ts(inode, cur_time);
Expand Down Expand Up @@ -261,7 +274,9 @@ static struct inode *simplefs_new_inode(struct inode *dir, mode_t mode)
set_nlink(inode, 1);
}

#if LINUX_VERSION_CODE >= KERNEL_VERSION(6, 6, 0)
#if LINUX_VERSION_CODE >= KERNEL_VERSION(6, 7, 0)
simple_inode_init_ts(inode);
#elif LINUX_VERSION_CODE >= KERNEL_VERSION(6, 6, 0)
cur_time = current_time(inode);
inode->i_atime = inode->i_mtime = cur_time;
inode_set_ctime_to_ts(inode, cur_time);
Expand Down Expand Up @@ -395,7 +410,9 @@ static int simplefs_create(struct inode *dir,
/* Update stats and mark dir and new inode dirty */
mark_inode_dirty(inode);

#if LINUX_VERSION_CODE >= KERNEL_VERSION(6, 6, 0)
#if LINUX_VERSION_CODE >= KERNEL_VERSION(6, 7, 0)
simple_inode_init_ts(dir);
#elif LINUX_VERSION_CODE >= KERNEL_VERSION(6, 6, 0)
cur_time = current_time(dir);
dir->i_mtime = dir->i_atime = cur_time;
inode_set_ctime_to_ts(dir, cur_time);
Expand Down Expand Up @@ -537,7 +554,9 @@ static int simplefs_unlink(struct inode *dir, struct dentry *dentry)
goto clean_inode;

/* Update inode stats */
#if LINUX_VERSION_CODE >= KERNEL_VERSION(6, 6, 0)
#if LINUX_VERSION_CODE >= KERNEL_VERSION(6, 7, 0)
simple_inode_init_ts(dir);
#elif LINUX_VERSION_CODE >= KERNEL_VERSION(6, 6, 0)
cur_time = current_time(dir);
dir->i_mtime = dir->i_atime = cur_time;
inode_set_ctime_to_ts(dir, cur_time);
Expand Down Expand Up @@ -606,7 +625,11 @@ static int simplefs_unlink(struct inode *dir, struct dentry *dentry)
i_gid_write(inode, 0);
inode->i_mode = 0;

#if LINUX_VERSION_CODE >= KERNEL_VERSION(6, 6, 0)
#if LINUX_VERSION_CODE >= KERNEL_VERSION(6, 7, 0)
inode_set_mtime(inode, 0, 0);
inode_set_atime(inode, 0, 0);
inode_set_ctime(inode, 0, 0);
#elif LINUX_VERSION_CODE >= KERNEL_VERSION(6, 6, 0)
inode->i_mtime.tv_sec = inode->i_atime.tv_sec = 0;
inode_set_ctime(inode, 0, 0);
#else
Expand Down Expand Up @@ -749,7 +772,9 @@ static int simplefs_rename(struct inode *old_dir,
brelse(bh2);

/* Update new parent inode metadata */
#if LINUX_VERSION_CODE >= KERNEL_VERSION(6, 6, 0)
#if LINUX_VERSION_CODE >= KERNEL_VERSION(6, 7, 0)
simple_inode_init_ts(new_dir);
#elif LINUX_VERSION_CODE >= KERNEL_VERSION(6, 6, 0)
cur_time = current_time(new_dir);
new_dir->i_atime = new_dir->i_mtime = cur_time;
inode_set_ctime_to_ts(new_dir, cur_time);
Expand All @@ -768,7 +793,9 @@ static int simplefs_rename(struct inode *old_dir,
goto release_new;

/* Update old parent inode metadata */
#if LINUX_VERSION_CODE >= KERNEL_VERSION(6, 6, 0)
#if LINUX_VERSION_CODE >= KERNEL_VERSION(6, 7, 0)
simple_inode_init_ts(old_dir);
#elif LINUX_VERSION_CODE >= KERNEL_VERSION(6, 6, 0)
cur_time = current_time(old_dir);
old_dir->i_atime = old_dir->i_mtime = cur_time;
inode_set_ctime_to_ts(old_dir, cur_time);
Expand Down
11 changes: 10 additions & 1 deletion super.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,11 @@
#include <linux/statfs.h>

#include "simplefs.h"

struct dentry *simplefs_mount(struct file_system_type *fs_type,
int flags,
const char *dev_name,
void *data);
void simplefs_kill_sb(struct super_block *sb);
static struct kmem_cache *simplefs_inode_cache;

int simplefs_init_inode_cache(void)
Expand Down Expand Up @@ -78,8 +82,13 @@ static int simplefs_write_inode(struct inode *inode,
disk_inode->i_ctime = inode->i_ctime.tv_sec;
#endif

#if LINUX_VERSION_CODE >= KERNEL_VERSION(6, 7, 0)
disk_inode->i_atime = inode_get_atime_sec(inode);
disk_inode->i_atime = inode_get_mtime_sec(inode);
#else
disk_inode->i_atime = inode->i_atime.tv_sec;
disk_inode->i_mtime = inode->i_mtime.tv_sec;
#endif
disk_inode->i_blocks = inode->i_blocks;
disk_inode->i_nlink = inode->i_nlink;
disk_inode->ei_block = ci->ei_block;
Expand Down