SG_SAT_DATETIME(8) | SG3_UTILS | SG_SAT_DATETIME(8) |
sg_sat_datetime - report or set date and time on a ATA device
sg_sat_datetime [--dma] [--elapsed] [--format] [--help] [--hex] [--milliseconds=MS] [--readonly] [--seconds=SECS] [--srep] [--verbose] [--version] DEVICE
Sends a SET DATE & TIME EXT or READ LOG [DMA] EXT command to the ATA DEVICE to set the date and time or read it from the Device Statistics log address(04h), General Statistics page (01h). These commands are found in the ATA Command Set (ACS-5) standard. ATA commands are sent using ATA PASS-THROUGH SCSI commands.
If either the --milliseconds=MS or --seconds=SECS option is given (and both can't be given) then the SET DATE & TIME command is sent. Otherwise, the READ LOG EXT command, or if the --dma option is used, the READ LOG DMA EXT command is sent to the device.
The date and time is sent and received from the DEVICE generally as the number of milliseconds since the epoch of 1970-01-01 00:00:00 UTC and is held in a 48 bit unsigned integer. That same epoch is used by Unix machines, but they usually hold the number of seconds since that epoch. The Unix date command and especially its "+%s" format is useful in converting to and from timestamps and more humanly readable forms. See the EXAMPLES section below. If the date and time is not set after power-on reset, the value is the same as the device power-on hours in milliseconds.
Arguments to long options are mandatory for short options as well.
The exit status of sg_sat_datetime is 0 when it is successful. Otherwise, see the sg3_utils(8) man page.
The DEVICE should immediately start accumulating time after the date and time is set. ie. If you set and then retrieve the date and time, the returned values will likely have increased.
The ACS-5 standard makes no provision for a power-safe date and time storage. Unless the device has vendor-specific power-safe capability, after a power-on reset, per ACS-5, the date and time should be the power-on hours of the device returned in milliseconds (or seconds if --srep option is used).
On Unix machines (e.g. Linux, FreeBSD, and Solaris) the date command is useful when working with timestamps.
To fetch the timestamp from a DEVICE and display it in a humanly readable form the following could be used:
# sg_sat_datetime -S /dev/sg2
1681156506
# date --date=@1681156506
Mon Apr 10 02:55:06 PM CDT 2023
# date -R --date="@1681156506"
Mon, 10 Apr 2023 14:55:06 -0500
The latter two date commands show different forms of the same date (i.e. 1681156506 seconds since 1970-01-01 00:00:00 UTC). The sg_sat_datetime and date commands can be combined using backquotes:
# date -R --date=@`sg_sat_datetime -S /dev/sg2`
Mon, 10 Apr 2023 14:55:06 -0500
Alternatively, the --format option can be used to format the date
and time using the default locale.
# sg_sat_datetime --format /dev/sg2
Mon Apr 10 15:02:54 2023
To set the date and time on the DEVICE to now (approximately) the following could be used:
# date +%s
1681157099
# sg_sat_datetime --seconds=1681157099 /dev/sg0
Those two command lines could be combined into one by using backquotes:
# sg_sat_datetime --seconds=`date +%s` /dev/sg0
Written by Jeremy Bauer and Daniel Woeste with extensive use of sg_timestamp and sg_sat_read_gplog by Douglas Gilbert.
Report bugs to <dgilbert at interlog dot com>.
Copyright © 2023 Jeremy Bauer and Daniel Woeste of Western
Digital Corporation
This software is distributed under a FreeBSD license. There is NO warranty;
not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
sdparm(sdparm), sg_logs(sg3_utils), sg_timestamp(sg3_utils), sg_sat_read_gplog(sg3_utils)
May 2023 | sg3_utils-1.48 |