Changeset View
Changeset View
Standalone View
Standalone View
sys/fs/ext2fs/ext2_inode_cnv.c
Show First 20 Lines • Show All 87 Lines • ▼ Show 20 Lines | ext2_print_inode(struct inode *in) | ||||
} else { | } else { | ||||
printf("Blocks:"); | printf("Blocks:"); | ||||
for (i = 0; i < (in->i_blocks <= 24 ? (in->i_blocks + 1) / 2 : 12); i++) | for (i = 0; i < (in->i_blocks <= 24 ? (in->i_blocks + 1) / 2 : 12); i++) | ||||
printf(" %d", in->i_db[i]); | printf(" %d", in->i_db[i]); | ||||
printf("\n"); | printf("\n"); | ||||
} | } | ||||
} | } | ||||
#endif /* EXT2FS_PRINT_EXTENTS */ | #endif /* EXT2FS_PRINT_EXTENTS */ | ||||
#define XTIME_TO_NSEC(x) ((le32toh(x) & EXT3_NSEC_MASK) >> 2) | |||||
static inline bool | static inline bool | ||||
pfg: You are replacing a macro so use inline here | |||||
ext2_old_valid_dev(dev_t dev) | ext2_old_valid_dev(dev_t dev) | ||||
{ | { | ||||
return (major(dev) < 256 && minor(dev) < 256); | return (major(dev) < 256 && minor(dev) < 256); | ||||
} | } | ||||
static inline uint16_t | static inline uint16_t | ||||
ext2_old_encode_dev(dev_t dev) | ext2_old_encode_dev(dev_t dev) | ||||
{ | { | ||||
Not Done Inline Actionsuse inline here, and move it nearer to the place where it will be used.: basically where the macro was. pfg: use inline here, and move it nearer to the place where it will be used.: basically where the… | |||||
return ((major(dev) << 8) | minor(dev)); | return ((major(dev) << 8) | minor(dev)); | ||||
} | } | ||||
static inline dev_t | static inline dev_t | ||||
ext2_old_decode_dev(uint16_t val) | ext2_old_decode_dev(uint16_t val) | ||||
{ | { | ||||
return (makedev((val >> 8) & 255, val & 255)); | return (makedev((val >> 8) & 255, val & 255)); | ||||
} | } | ||||
Show All 11 Lines | |||||
ext2_new_decode_dev(uint32_t dev) | ext2_new_decode_dev(uint32_t dev) | ||||
{ | { | ||||
unsigned maj = (dev & 0xfff00) >> 8; | unsigned maj = (dev & 0xfff00) >> 8; | ||||
unsigned min = (dev & 0xff) | ((dev >> 12) & 0xfff00); | unsigned min = (dev & 0xff) | ((dev >> 12) & 0xfff00); | ||||
return (makedev(maj, min)); | return (makedev(maj, min)); | ||||
} | } | ||||
static void | |||||
ext2_decode_extra_time(ext_time_t *sec, int32_t *nsec, uint32_t extra) | |||||
{ | |||||
if (extra & htole32(EXT3_EPOCH_MASK)) | |||||
*sec += (uint64_t)(le32toh(extra) & EXT3_EPOCH_MASK) << 32; | |||||
*nsec = (le32toh(extra) & EXT3_NSEC_MASK) >> EXT3_EPOCH_BITS; | |||||
} | |||||
/* | /* | ||||
* raw ext2 inode LE to host inode conversion | * raw ext2 inode LE to host inode conversion | ||||
*/ | */ | ||||
int | int | ||||
ext2_ei2i(struct ext2fs_dinode *ei, struct inode *ip) | ext2_ei2i(struct ext2fs_dinode *ei, struct inode *ip) | ||||
{ | { | ||||
struct m_ext2fs *fs = ip->i_e2fs; | struct m_ext2fs *fs = ip->i_e2fs; | ||||
uint32_t ei_flags_host; | uint32_t ei_flags_host; | ||||
Show All 29 Lines | ext2_ei2i(struct ext2fs_dinode *ei, struct inode *ip) | ||||
* unused - according to ext2 standards. Ufs marks this fact by | * unused - according to ext2 standards. Ufs marks this fact by | ||||
* setting i_mode to zero - why ? I can see that this might lead to | * setting i_mode to zero - why ? I can see that this might lead to | ||||
* problems in an undelete. | * problems in an undelete. | ||||
*/ | */ | ||||
ip->i_mode = ip->i_nlink ? le16toh(ei->e2di_mode) : 0; | ip->i_mode = ip->i_nlink ? le16toh(ei->e2di_mode) : 0; | ||||
ip->i_size = le32toh(ei->e2di_size); | ip->i_size = le32toh(ei->e2di_size); | ||||
if (S_ISREG(ip->i_mode)) | if (S_ISREG(ip->i_mode)) | ||||
ip->i_size |= (uint64_t)le32toh(ei->e2di_size_high) << 32; | ip->i_size |= (uint64_t)le32toh(ei->e2di_size_high) << 32; | ||||
ip->i_atime = le32toh(ei->e2di_atime); | ip->i_atime = (signed)le32toh(ei->e2di_atime); | ||||
ip->i_mtime = le32toh(ei->e2di_mtime); | ip->i_mtime = (signed)le32toh(ei->e2di_mtime); | ||||
ip->i_ctime = le32toh(ei->e2di_ctime); | ip->i_ctime = (signed)le32toh(ei->e2di_ctime); | ||||
if (E2DI_HAS_XTIME(ip)) { | if (E2DI_HAS_XTIME(ip)) { | ||||
ip->i_atimensec = XTIME_TO_NSEC(ei->e2di_atime_extra); | ext2_decode_extra_time(&ip->i_atime, &ip->i_atimensec, | ||||
ip->i_mtimensec = XTIME_TO_NSEC(ei->e2di_mtime_extra); | ei->e2di_atime_extra); | ||||
ip->i_ctimensec = XTIME_TO_NSEC(ei->e2di_ctime_extra); | ext2_decode_extra_time(&ip->i_mtime, &ip->i_mtimensec, | ||||
ip->i_birthtime = le32toh(ei->e2di_crtime); | ei->e2di_mtime_extra); | ||||
ip->i_birthnsec = XTIME_TO_NSEC(ei->e2di_crtime_extra); | ext2_decode_extra_time(&ip->i_ctime, &ip->i_ctimensec, | ||||
ei->e2di_ctime_extra); | |||||
ip->i_birthtime = (signed)le32toh(ei->e2di_crtime); | |||||
ext2_decode_extra_time(&ip->i_birthtime, &ip->i_birthnsec, | |||||
ei->e2di_crtime_extra); | |||||
} | } | ||||
ip->i_flags = 0; | ip->i_flags = 0; | ||||
ei_flags_host = le32toh(ei->e2di_flags); | ei_flags_host = le32toh(ei->e2di_flags); | ||||
ip->i_flags |= (ei_flags_host & EXT2_APPEND) ? SF_APPEND : 0; | ip->i_flags |= (ei_flags_host & EXT2_APPEND) ? SF_APPEND : 0; | ||||
ip->i_flags |= (ei_flags_host & EXT2_IMMUTABLE) ? SF_IMMUTABLE : 0; | ip->i_flags |= (ei_flags_host & EXT2_IMMUTABLE) ? SF_IMMUTABLE : 0; | ||||
ip->i_flags |= (ei_flags_host & EXT2_NODUMP) ? UF_NODUMP : 0; | ip->i_flags |= (ei_flags_host & EXT2_NODUMP) ? UF_NODUMP : 0; | ||||
ip->i_flag |= (ei_flags_host & EXT3_INDEX) ? IN_E3INDEX : 0; | ip->i_flag |= (ei_flags_host & EXT3_INDEX) ? IN_E3INDEX : 0; | ||||
ip->i_flag |= (ei_flags_host & EXT4_EXTENTS) ? IN_E4EXTENTS : 0; | ip->i_flag |= (ei_flags_host & EXT4_EXTENTS) ? IN_E4EXTENTS : 0; | ||||
Show All 24 Lines | if (S_ISCHR(ip->i_mode) || S_ISBLK(ip->i_mode)) { | ||||
for (i = 0; i < EXT2_NIADDR; i++) | for (i = 0; i < EXT2_NIADDR; i++) | ||||
ip->i_ib[i] = le32toh(ei->e2di_blocks[EXT2_NDIR_BLOCKS + i]); | ip->i_ib[i] = le32toh(ei->e2di_blocks[EXT2_NDIR_BLOCKS + i]); | ||||
} | } | ||||
/* Verify inode csum. */ | /* Verify inode csum. */ | ||||
return (ext2_ei_csum_verify(ip, ei)); | return (ext2_ei_csum_verify(ip, ei)); | ||||
} | } | ||||
#define NSEC_TO_XTIME(t) (htole32((t << 2) & EXT3_NSEC_MASK)) | static uint32_t | ||||
ext2_encode_extra_time(int64_t sec, int32_t nsec) | |||||
{ | |||||
uint32_t extra; | |||||
extra = ((sec - (int32_t)sec) >> 32) & EXT3_EPOCH_MASK; | |||||
return (htole32(extra | (nsec << EXT3_EPOCH_BITS))); | |||||
} | |||||
/* | /* | ||||
* inode to raw ext2 LE inode conversion | * inode to raw ext2 LE inode conversion | ||||
*/ | */ | ||||
int | int | ||||
ext2_i2ei(struct inode *ip, struct ext2fs_dinode *ei) | ext2_i2ei(struct inode *ip, struct ext2fs_dinode *ei) | ||||
{ | { | ||||
struct m_ext2fs *fs; | struct m_ext2fs *fs; | ||||
int i; | int i; | ||||
Show All 9 Lines | ext2_i2ei(struct inode *ip, struct ext2fs_dinode *ei) | ||||
ei->e2di_ctime = htole32(ip->i_ctime); | ei->e2di_ctime = htole32(ip->i_ctime); | ||||
/* | /* | ||||
* Godmar thinks: if dtime is nonzero, ext2 says this inode has been | * Godmar thinks: if dtime is nonzero, ext2 says this inode has been | ||||
* deleted, this would correspond to a zero link count | * deleted, this would correspond to a zero link count | ||||
*/ | */ | ||||
ei->e2di_dtime = htole32(le16toh(ei->e2di_nlink) ? 0 : | ei->e2di_dtime = htole32(le16toh(ei->e2di_nlink) ? 0 : | ||||
le32toh(ei->e2di_mtime)); | le32toh(ei->e2di_mtime)); | ||||
if (E2DI_HAS_XTIME(ip)) { | if (E2DI_HAS_XTIME(ip)) { | ||||
ei->e2di_ctime_extra = NSEC_TO_XTIME(ip->i_ctimensec); | ei->e2di_ctime_extra = ext2_encode_extra_time(ip->i_ctime, | ||||
ei->e2di_mtime_extra = NSEC_TO_XTIME(ip->i_mtimensec); | ip->i_ctimensec); | ||||
ei->e2di_atime_extra = NSEC_TO_XTIME(ip->i_atimensec); | ei->e2di_mtime_extra = ext2_encode_extra_time(ip->i_mtime, | ||||
ip->i_mtimensec); | |||||
ei->e2di_atime_extra = ext2_encode_extra_time(ip->i_atime, | |||||
ip->i_atimensec); | |||||
ei->e2di_crtime = htole32(ip->i_birthtime); | ei->e2di_crtime = htole32(ip->i_birthtime); | ||||
ei->e2di_crtime_extra = NSEC_TO_XTIME(ip->i_birthnsec); | ei->e2di_crtime_extra = ext2_encode_extra_time(ip->i_birthtime, | ||||
ip->i_birthnsec); | |||||
} | } | ||||
/* Keep these in host endian for a while since they change a lot */ | /* Keep these in host endian for a while since they change a lot */ | ||||
ei->e2di_flags = 0; | ei->e2di_flags = 0; | ||||
ei->e2di_flags |= htole32((ip->i_flags & SF_APPEND) ? EXT2_APPEND : 0); | ei->e2di_flags |= htole32((ip->i_flags & SF_APPEND) ? EXT2_APPEND : 0); | ||||
ei->e2di_flags |= htole32((ip->i_flags & SF_IMMUTABLE) ? EXT2_IMMUTABLE : 0); | ei->e2di_flags |= htole32((ip->i_flags & SF_IMMUTABLE) ? EXT2_IMMUTABLE : 0); | ||||
ei->e2di_flags |= htole32((ip->i_flags & UF_NODUMP) ? EXT2_NODUMP : 0); | ei->e2di_flags |= htole32((ip->i_flags & UF_NODUMP) ? EXT2_NODUMP : 0); | ||||
ei->e2di_flags |= htole32((ip->i_flag & IN_E3INDEX) ? EXT3_INDEX : 0); | ei->e2di_flags |= htole32((ip->i_flag & IN_E3INDEX) ? EXT3_INDEX : 0); | ||||
ei->e2di_flags |= htole32((ip->i_flag & IN_E4EXTENTS) ? EXT4_EXTENTS : 0); | ei->e2di_flags |= htole32((ip->i_flag & IN_E4EXTENTS) ? EXT4_EXTENTS : 0); | ||||
▲ Show 20 Lines • Show All 45 Lines • Show Last 20 Lines |
You are replacing a macro so use inline here