mirror of
https://gitee.com/openharmony/third_party_f2fs-tools
synced 2025-04-01 21:01:47 +00:00
f2fs-tools: get kernel version via uname(2)
This patch introduces uname(2) to get kernel version. Reviewed-by: Chao Yu <yuchao0@huawei.com> Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
This commit is contained in:
parent
286226d820
commit
595fd57a4f
@ -102,6 +102,7 @@ AC_CHECK_HEADERS(m4_flatten([
|
||||
sys/syscall.h
|
||||
sys/mount.h
|
||||
sys/sysmacros.h
|
||||
sys/utsname.h
|
||||
sys/xattr.h
|
||||
unistd.h
|
||||
]))
|
||||
|
@ -625,7 +625,7 @@ int validate_super_block(struct f2fs_sb_info *sbi, int block)
|
||||
dev_read_version(c.version, 0, VERSION_LEN);
|
||||
get_kernel_version(c.version);
|
||||
} else {
|
||||
memset(c.version, 0, VERSION_LEN);
|
||||
get_kernel_uname_version(c.version);
|
||||
}
|
||||
|
||||
/* build sb version */
|
||||
|
@ -13,6 +13,7 @@
|
||||
#define HAVE_SYS_IOCTL_H 1
|
||||
#define HAVE_SYS_SYSCALL_H 1
|
||||
#define HAVE_SYS_MOUNT_H 1
|
||||
#define HAVE_SYS_UTSNAME_H 1
|
||||
#define HAVE_SYS_SYSMACROS_H 1
|
||||
#define HAVE_SYS_XATTR_H 1
|
||||
#define HAVE_UNISTD_H 1
|
||||
@ -43,6 +44,7 @@
|
||||
#define HAVE_SYS_IOCTL_H 1
|
||||
#define HAVE_SYS_SYSCALL_H 1
|
||||
#define HAVE_SYS_MOUNT_H 1
|
||||
#define HAVE_SYS_UTSNAME_H 1
|
||||
#define HAVE_SYS_XATTR_H 1
|
||||
#define HAVE_UNISTD_H 1
|
||||
|
||||
|
@ -1118,6 +1118,7 @@ extern int dev_reada_block(__u64);
|
||||
|
||||
extern int dev_read_version(void *, __u64, size_t);
|
||||
extern void get_kernel_version(__u8 *);
|
||||
extern void get_kernel_uname_version(__u8 *);
|
||||
f2fs_hash_t f2fs_dentry_hash(const unsigned char *, int);
|
||||
|
||||
static inline bool f2fs_has_extra_isize(struct f2fs_inode *inode)
|
||||
|
@ -27,6 +27,9 @@
|
||||
#ifdef HAVE_SYS_SYSMACROS_H
|
||||
#include <sys/sysmacros.h>
|
||||
#endif
|
||||
#ifdef HAVE_SYS_UTSNAME_H
|
||||
#include <sys/utsname.h>
|
||||
#endif
|
||||
#ifndef WITH_ANDROID
|
||||
#ifdef HAVE_SCSI_SG_H
|
||||
#include <scsi/sg.h>
|
||||
@ -740,6 +743,21 @@ void get_kernel_version(__u8 *version)
|
||||
memset(version + i, 0, VERSION_LEN + 1 - i);
|
||||
}
|
||||
|
||||
void get_kernel_uname_version(__u8 *version)
|
||||
{
|
||||
#ifdef HAVE_SYS_UTSNAME_H
|
||||
struct utsname buf;
|
||||
|
||||
memset(version, 0, VERSION_LEN);
|
||||
if (uname(&buf))
|
||||
return;
|
||||
|
||||
snprintf((char *)version,
|
||||
VERSION_LEN, "%s %s", buf.release, buf.version);
|
||||
#else
|
||||
memset(version, 0, VERSION_LEN);
|
||||
#endif
|
||||
}
|
||||
|
||||
#if defined(__linux__) && defined(_IO) && !defined(BLKGETSIZE)
|
||||
#define BLKGETSIZE _IO(0x12,96)
|
||||
@ -796,7 +814,9 @@ int get_device_info(int i)
|
||||
}
|
||||
|
||||
if (c.kd == -1) {
|
||||
#if !defined(WITH_ANDROID) && defined(__linux__)
|
||||
c.kd = open("/proc/version", O_RDONLY);
|
||||
#endif
|
||||
if (c.kd < 0) {
|
||||
MSG(0, "\tInfo: No support kernel version!\n");
|
||||
c.kd = -2;
|
||||
|
@ -442,7 +442,7 @@ static int f2fs_prepare_super_block(void)
|
||||
get_kernel_version(c.version);
|
||||
MSG(0, "Info: format version with\n \"%s\"\n", c.version);
|
||||
} else {
|
||||
memset(c.version, 0, VERSION_LEN);
|
||||
get_kernel_uname_version(c.version);
|
||||
}
|
||||
|
||||
memcpy(sb->version, c.version, VERSION_LEN);
|
||||
|
Loading…
x
Reference in New Issue
Block a user