src/hdaccess.c: use /sys/dev/block/*/device/{model,serial,rev} to get
information about disks
This commit is contained in:
parent
da2ed0b7aa
commit
5870c3c967
2 changed files with 52 additions and 2 deletions
|
@ -6,7 +6,7 @@ AC_INIT([testdisk],[7.2-WIP],[grenier@cgsecurity.org])
|
|||
AC_LANG(C)
|
||||
sinclude(acx_pthread.m4)
|
||||
sinclude(mkdir.m4)
|
||||
TESTDISKDATE="February 2023"
|
||||
TESTDISKDATE="August 2023"
|
||||
AC_SUBST(TESTDISKDATE)
|
||||
AC_DEFINE_UNQUOTED([TESTDISKDATE],"$TESTDISKDATE",[Date of release])
|
||||
AC_CONFIG_AUX_DIR(config)
|
||||
|
@ -330,7 +330,7 @@ AC_SYS_LARGEFILE
|
|||
AC_HEADER_STDC
|
||||
#AC_CHECK_HEADERS([sys/types.h sys/stat.h stdlib.h stdint.h unistd.h])
|
||||
AC_HEADER_SYS_WAIT
|
||||
AC_CHECK_HEADERS([byteswap.h curses.h cygwin/fs.h cygwin/version.h dal/file_dal.h dal/file.h ddk/ntddstor.h dirent.h endian.h errno.h fcntl.h features.h giconv.h glob.h iconv.h io.h libgen.h limits.h linux/fs.h linux/hdreg.h linux/types.h locale.h machine/endian.h malloc.h ncurses.h ncurses/curses.h ncurses/ncurses.h ncursesw/curses.h ncursesw/ncurses.h ntfs/version.h pwd.h scsi/scsi.h scsi/scsi_ioctl.h scsi/sg.h setjmp.h signal.h stdarg.h sys/cygwin.h sys/disk.h sys/disklabel.h sys/dkio.h sys/endian.h sys/ioctl.h sys/param.h sys/select.h sys/time.h sys/utsname.h sys/vtoc.h time.h utime.h w32api/ddk/ntdddisk.h windef.h windows.h zlib.h])
|
||||
AC_CHECK_HEADERS([byteswap.h curses.h cygwin/fs.h cygwin/version.h dal/file_dal.h dal/file.h ddk/ntddstor.h dirent.h endian.h errno.h fcntl.h features.h giconv.h glob.h iconv.h io.h libgen.h limits.h linux/fs.h linux/hdreg.h linux/types.h locale.h machine/endian.h malloc.h ncurses.h ncurses/curses.h ncurses/ncurses.h ncursesw/curses.h ncursesw/ncurses.h ntfs/version.h pwd.h scsi/scsi.h scsi/scsi_ioctl.h scsi/sg.h setjmp.h signal.h stdarg.h sys/cygwin.h sys/disk.h sys/disklabel.h sys/dkio.h sys/endian.h sys/ioctl.h sys/sysmacros.h sys/param.h sys/select.h sys/time.h sys/utsname.h sys/vtoc.h time.h utime.h w32api/ddk/ntdddisk.h windef.h windows.h zlib.h])
|
||||
|
||||
#--------------------------------------------------------------------
|
||||
# Check for iconv support (for Unicode conversion).
|
||||
|
|
|
@ -81,6 +81,9 @@
|
|||
#ifdef HAVE_SYS_DKIO_H
|
||||
#include <sys/dkio.h>
|
||||
#endif
|
||||
#ifdef HAVE_SYS_SYSMACROS_H
|
||||
#include <sys/sysmacros.h>
|
||||
#endif
|
||||
/* linux/fs.h may not be needed because sys/mount.h is present */
|
||||
/* #ifdef HAVE_LINUX_FS_H */
|
||||
/* #include <linux/fs.h> */
|
||||
|
@ -1117,6 +1120,53 @@ static int scsi_query_product_info (const int sg_fd, char **vendor, char **produ
|
|||
@*/
|
||||
static void disk_get_model(const int hd_h, disk_t *dev, const unsigned int verbose)
|
||||
{
|
||||
#if defined(TARGET_LINUX) && defined(HAVE_SYS_SYSMACROS_H)
|
||||
struct stat stat_rec;
|
||||
if(fstat(hd_h,&stat_rec)>=0 && S_ISBLK(stat_rec.st_mode))
|
||||
{
|
||||
FILE *f;
|
||||
char name_buf[4096];
|
||||
if(dev->model==NULL)
|
||||
{
|
||||
snprintf(name_buf, sizeof(name_buf), "/sys/dev/block/%u:%u/device/model", major(stat_rec.st_rdev), minor(stat_rec.st_rdev));
|
||||
if((f = fopen(name_buf, "r")) != NULL)
|
||||
{
|
||||
char tmp[41];
|
||||
if (fgets(tmp, 40, f) != NULL)
|
||||
{
|
||||
dev->model=strip_dup(tmp);
|
||||
}
|
||||
fclose(f);
|
||||
}
|
||||
}
|
||||
if(dev->serial_no == NULL)
|
||||
{
|
||||
snprintf(name_buf, sizeof(name_buf), "/sys/dev/block/%u:%u/device/serial", major(stat_rec.st_rdev), minor(stat_rec.st_rdev));
|
||||
if((f = fopen(name_buf, "r")) != NULL)
|
||||
{
|
||||
char tmp[41];
|
||||
if (fgets(tmp, 40, f) != NULL)
|
||||
{
|
||||
dev->serial_no=strip_dup(tmp);
|
||||
}
|
||||
fclose(f);
|
||||
}
|
||||
}
|
||||
if(dev->fw_rev== NULL)
|
||||
{
|
||||
snprintf(name_buf, sizeof(name_buf), "/sys/dev/block/%u:%u/device/rev", major(stat_rec.st_rdev), minor(stat_rec.st_rdev));
|
||||
if((f = fopen(name_buf, "r")) != NULL)
|
||||
{
|
||||
char tmp[41];
|
||||
if (fgets(tmp, 40, f) != NULL)
|
||||
{
|
||||
dev->fw_rev=strip_dup(tmp);
|
||||
}
|
||||
fclose(f);
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
#ifdef HDIO_GET_IDENTITY
|
||||
if(dev->model!=NULL)
|
||||
return;
|
||||
|
|
Loading…
Reference in a new issue