file.lastModified() is never what was set with file.setLastModified()

前端 未结 5 1182
情深已故
情深已故 2020-12-19 01:16

I do have a problem with millis set and read on Android 2.3.4 on a Nexus One. This is the code:

File fileFolder = new File(Environment.getExternalStorageDire         


        
5条回答
  •  离开以前
    2020-12-19 01:24

    On Jelly Bean+, it's different (mostly on Nexus devices yet, and others that use the new fuse layer for /mnt/shell/emulated sdcard emulation):

    It's a VFS permission problem, the syscall utimensat() fails with EPERM due to inappropriate permissions (e.g. ownership).

    in platform/system/core/sdcard/sdcard.c:

    /* all files owned by root.sdcard */
    attr->uid = 0;
    attr->gid = AID_SDCARD_RW;

    From utimensat()'s syscall man page:

    2. the caller's effective user ID must match the owner of the file; or  
    3. the caller must have appropriate privileges.  
    
    To make any change other than setting both timestamps to the current time  
    (i.e., times is not NULL, and both tv_nsec fields are not UTIME_NOW and both  
    tv_nsec fields are not UTIME_OMIT), either condition 2 or 3 above must apply.  
    

    Old FAT offers an override of the iattr->valid flag via a mount option to allow changing timestamps to anyone, FUSE+Android's sdcard-FUSE don't do this at the moment (so the 'inode_change_ok() call fails) and the attempt gets rejected with -EPERM. Here's FAT's ./fs/fat/file.c:

    /* Check for setting the inode time. */  
    ia_valid = attr->ia_valid;  
    if (ia_valid & TIMES_SET_FLAGS) {  
        if (fat_allow_set_time(sbi, inode))  
            attr->ia_valid &= ~TIMES_SET_FLAGS;  
    }  
    
    error = inode_change_ok(inode, attr);
    

    I also added this info to this open bug.

提交回复
热议问题