debugfs set_inode_field ctime 纳秒

问题描述

我正在使用 debugfs 在 ext4 文件系统上更改文件的 ctime(附加到此特定文件的 ctime 的程序循环)。

因此使用的命令是:

debugfs -w -R 'set_inode_field foo/bar ctime 20130503145204' /dev/vdb1

但这会导致后面跟着一个 ctime:

myserver:~ # stat foo/bar 
  File: „foo/bar“
  Size: 1234        Blocks: 24         IO Block: 4096   reguläre Datei
Device: 1234h/1234d Inode: 1234567     Links: 1
Access: (0660/-rw-rw----)  Uid: (  123/ whatever)   Gid: ( 1234/ whatever)
Access: 2021-02-12 21:17:51.146954174 +0100
Modify: 2021-02-12 14:51:32.152323937 +0100
Change: 2013-05-03 16:52:04.991865222 +0200

不符合预期:2013-05-03 16:52:04.000000000 +0200

原因,它正常工作的原因是旧的 ext3 FS 仅以第二个分辨率存储 ctime。 ext2/ext3 中的 inode structur size 为 128 字节。使用 ext4,此大小增加到 156 字节(i_extra_isize = 28,请参阅:https://ext4.wiki.kernel.org/index.php/Ext4_Disk_Layout#Inode_Size)导致纳秒分辨率。

如何格式化 debugfs 命令以将 ctime 设置为精确的纳秒?

解决方法

经过一番挖掘,我设法解决了这个问题。解决方法:阅读手册。

debugfs 支持设置 ctime/atime/mtime/crtime time_extra bytes with

package com.todolist.webbapp.config;

import java.beans.PropertyVetoException;
import java.util.Properties;

import javax.sql.DataSource;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;
import org.springframework.core.env.Environment;
import org.springframework.orm.hibernate5.HibernateTransactionManager;
import org.springframework.orm.hibernate5.LocalSessionFactoryBean;
import org.springframework.transaction.annotation.EnableTransactionManagement;
import org.springframework.web.servlet.ViewResolver;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
import org.springframework.web.servlet.view.InternalResourceViewResolver;

import com.mchange.v2.c3p0.ComboPooledDataSource;

@Configuration
@EnableTransactionManagement
@EnableWebMvc
@ComponentScan(basePackages = "com.todolist.webbapp")
@PropertySource("classpath:persistence-mysql.properties")
public class WebAppConfig implements WebMvcConfigurer {

    @Autowired
    private Environment env;

    @Bean
    public ViewResolver viewResolver() {

        InternalResourceViewResolver viewResolver = new InternalResourceViewResolver();

        viewResolver.setPrefix("/WEB-INF/view/");

        viewResolver.setSuffix(".jsp");
        
        viewResolver.setContentType("text/html ; charset=UTF-8");

        return viewResolver;
    }

ctime_extra 字段是一个无符号整数,因此值 0 给出了预期的设置。

dtime 没有加宽,因此不支持 dtime_extra

相关问答

依赖报错 idea导入项目后依赖报错,解决方案:https://blog....
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下...
错误1:gradle项目控制台输出为乱码 # 解决方案:https://bl...
错误还原:在查询的过程中,传入的workType为0时,该条件不起...
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct...