Skip to content

Commit a59e1b9

Browse files
committed
Version 2.0.0
This version splits the core code of the ptio utility into a library (libptio). No change to the ptio tool itself. Signed-off-by: Damien Le Moal <[email protected]>
1 parent 7d0be8d commit a59e1b9

28 files changed

+409
-261
lines changed

.gitignore

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# SPDX-License-Identifier: CC0-1.0
22
#
3-
# Copyright (c) 2021 Western Digital Corporation or its affiliates.
3+
# SPDX-FileCopyrightText: 2024 Western Digital Corporation or its affiliates.
44

55
# Object files
66
*.o
@@ -28,7 +28,7 @@
2828
*.i*86
2929
*.x86_64
3030
*.hex
31-
src/ptio
31+
tools/ptio
3232

3333
# Kernel compile files
3434
*.symvers

CONTRIBUTING

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
SPDX-License-Identifier: CC0-1.0
22

3-
Copyright (C) 2021 Western Digital Corporation or its affiliates.
3+
SPDX-FileCopyrightText: 2024 Western Digital Corporation or its affiliates.
44

55
This project embraces the Developer Certificate of Origin (DCO) for
66
contributions. This means you must agree to the following prior to submitting

COPYING.GPL

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Copyright (C) 2021, Western Digital Corporation or its affiliates.
1+
SPDX-FileCopyrightText: 2024 Western Digital Corporation or its affiliates.
22

33
GNU GENERAL PUBLIC LICENSE
44
Version 2, June 1991

LICENSES/GPL-2.0-or-later.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Copyright (C) 2019, Western Digital Corporation or its affiliates.
1+
SPDX-FileCopyrightText: 2024 Western Digital Corporation or its affiliates.
22

33
GNU GENERAL PUBLIC LICENSE
44
Version 2, June 1991

Makefile.am

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,39 @@
11
# SPDX-License-Identifier: CC0-1.0
22
#
3-
# Copyright (C) 2024 Western Digital Corporation or its affiliates.
3+
# SPDX-FileCopyrightText: 2024 Western Digital Corporation or its affiliates.
44

55
ACLOCAL_AMFLAGS = -I m4
66

7-
SUBDIRS = src man
7+
SUBDIRS = lib tools
88

9-
EXTRA_DIST = autogen.sh README.md COPYING.GPL CONTRIBUTING
9+
EXTRA_DIST = autogen.sh \
10+
README.md \
11+
LICENSES/GPL-2.0-or-later.txt
1012

1113
if BUILD_RPM
1214

1315
rpmdir = $(abs_top_builddir)/rpmbuild
1416

15-
EXTRA_DIST += ptio.spec
17+
EXTRA_DIST += pt-tools.spec
1618
RPMARCH=`$(RPM) --eval %_target_cpu`
1719

1820
rpm: dist
1921
@echo "Building RPM package..."
2022
@mkdir -p $(rpmdir)
2123
$(RPMBUILD) -ta --clean \
2224
-D "_topdir $(rpmdir)" \
23-
-D "pkg_name ptio" \
25+
-D "pkg_name pt-tools" \
2426
-D "pkg_version $(PACKAGE_VERSION)" \
25-
ptio-$(PACKAGE_VERSION).tar.gz
27+
pt-tools-$(PACKAGE_VERSION).tar.gz
2628
@mv -f $(rpmdir)/RPMS/$(RPMARCH)/*.rpm $(abs_top_builddir)
27-
@mv -f $(rpmdir)/RPMS/noarch/*.rpm $(abs_top_builddir)
2829
@mv -f $(rpmdir)/SRPMS/*.rpm $(abs_top_builddir)
2930
@rm -rf $(rpmdir)
30-
@rm -f ptio-$(PACKAGE_VERSION).tar.gz
31+
@rm -f pt-tools-$(PACKAGE_VERSION).tar.gz
3132
else
3233
rpm:
3334
@echo "Building RPM packages requires rpmbuild and rpm utilities"
3435
exit 1
3536
endif
37+
38+
CLEANFILES = *.rpm *.tar.gz
39+
DISTCLEANFILES = *.rpm *.tar.gz configure

README.md

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
Copyright (C) 2024, Western Digital Corporation or its affiliates.
1+
SPDX-FileCopyrightText: 2024 Western Digital Corporation or its affiliates.
22

33
# <p align="center">Passthrough IO tools</p>
44

5-
This project provides the *ptio* command line utility to execute SCSI or ATA
6-
passthrough commands.
5+
This project provides the *ptio* library and command line utility to execute
6+
SCSI or ATA passthrough commands.
77

88
## License
99

@@ -44,24 +44,25 @@ The following packages must be installed prior to compiling *pt-tools*.
4444

4545
## Compilation and Installation
4646

47-
The following commands will compile the *ptio* utility.
47+
The following commands will compile the *ptio* library and command line utility.
4848

4949
```
5050
$ sh ./autogen.sh
5151
$ ./configure
5252
$ make
5353
```
5454

55-
To install the compiled executable file and the man page for the *ptio*
56-
utility, the following command can be used.
55+
To install the compiled library and the utilities and their man pages, the
56+
use the following command.
5757

5858
```
5959
$ sudo make install
6060
```
6161

62-
The default installation directory is /usr/bin. This default location can be
63-
changed using the configure script. Executing the following command displays
64-
the options used to control the installation path.
62+
The default installation directory is /usr/lib64 for the *libptio.so* library.
63+
The utilities executable files are installed by default under /usr/bin.
64+
This default location can be changed using the configure script. Executing the
65+
following command displays the options used to control the installation path.
6566

6667
```
6768
$ ./configure --help
@@ -79,13 +80,13 @@ $ ./configure
7980
$ make rpm
8081
```
8182

82-
Five RPM packages are built: a binary package providing *ptio* executable
83-
and its documentation, a source RPM package, a *debuginfo*
84-
RPM package and a *debugsource* RPM package, and an RPM package containing the
85-
test suite.
83+
Seven RPM packages are built: a binary package providing the *libptio* library,
84+
a package providing *libptio* header file for development, a binary package
85+
providing the *ptio* command line utility and its documentation, a source RPM
86+
package, two *debuginfo* RPM packages and a *debugsource* RPM package.
8687

8788
The source RPM package can be used to build the binary and debug RPM packages
88-
outside of *pt-tools* source tree using the following command.
89+
outside of the *pt-tools* source tree using the following command.
8990

9091
```
9192
$ rpmbuild --rebuild pt-tools-<version>.src.rpm
@@ -96,9 +97,8 @@ $ rpmbuild --rebuild pt-tools-<version>.src.rpm
9697
Read the [CONTRIBUTING](CONTRIBUTING) file and send patches to:
9798

9899
Damien Le Moal <[email protected]>
99-
Niklas Cassel <[email protected]>
100100

101-
# *ptio* Command Line Tool
101+
# *ptio* Command Line Utility
102102

103103
The *ptio* command line tool allows executing SCSI or ATA passthrough commands.
104104

autogen.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@
22
#
33
# SPDX-License-Identifier: CC0-1.0
44
#
5-
# Copyright (C) 2024 Western Digital Corporation or its affiliates.
5+
# SPDX-FileCopyrightText: 2024 Western Digital Corporation or its affiliates.
66

77
exec autoreconf -f -i

configure.ac

Lines changed: 28 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,45 @@
11
# SPDX-License-Identifier: CC0-1.0
22
#
3-
# Copyright (C) 2024 Western Digital Corporation or its affiliates.
3+
# SPDX-FileCopyrightText: 2024 Western Digital Corporation or its affiliates.
44

5-
AC_INIT([pt-tools], [1.0.0],
5+
AC_INIT([pt-tools], [2.0.0],
66
77
[pt-tools], [https://bitbucket.wdc.com/users/damien.lemoal_wdc.com/repos/pt-tools/browse])
88

9-
AC_PREFIX_DEFAULT(/usr)
10-
AC_CONFIG_HEADERS([src/config.h])
11-
AC_CONFIG_MACRO_DIR([m4])
129
AC_CONFIG_AUX_DIR([build-aux])
10+
AC_CANONICAL_TARGET
11+
AC_CONFIG_MACRO_DIR([m4])
12+
AC_CONFIG_HEADERS([include/config.h])
13+
AC_PREFIX_DEFAULT(/usr)
1314
AM_INIT_AUTOMAKE([-Wall foreign subdir-objects])
1415
AM_SILENT_RULES([yes])
1516

17+
# Change default CFLAGS from "-g -O2" to "-O2" for regular builds.
18+
AC_ARG_ENABLE(debug,
19+
[ --enable-debug Compile with "-g" option],
20+
[DBGCFLAGS="-g"],
21+
[DBGCFLAGS="-O2"])
22+
CFLAGS="$CFLAGS $DBGCFLAGS"
23+
24+
AC_PROG_CC
25+
AM_PROG_CC_C_O
26+
AC_PROG_INSTALL
27+
1628
AC_USE_SYSTEM_EXTENSIONS
1729
AC_SYS_LARGEFILE
1830

1931
m4_ifdef([AM_PROG_AR], [AM_PROG_AR])
2032
m4_pattern_allow([AM_PROG_AR])
2133
LT_INIT
2234

23-
# Checks for programs.
24-
AC_PROG_CC
25-
AM_PROG_CC_C_O
35+
# Package version details: <major>.<minor>.<release>
36+
PACKAGE_VERSION_MAJOR=$(echo $PACKAGE_VERSION | awk -F. '{print $1}')
37+
PACKAGE_VERSION_MINOR=$(echo $PACKAGE_VERSION | awk -F. '{print $2}')
38+
PACKAGE_VERSION_RELEASE=$(echo $PACKAGE_VERSION | awk -F. '{print $3}')
39+
40+
# libtool friendly library version format
41+
LIBPTIO_VERSION_LT=$PACKAGE_VERSION_MAJOR:$PACKAGE_VERSION_MINOR:$PACKAGE_VERSION_RELEASE
42+
AC_SUBST([LIBPTIO_VERSION_LT])
2643

2744
# Checks for header files.
2845
AC_CHECK_HEADER(scsi/scsi.h, [],
@@ -39,9 +56,10 @@ AM_CONDITIONAL([BUILD_RPM],
3956
[test "x$RPMBUILD" != xnotfound && test "x$RPM" != xnotfound])
4057

4158
AC_CONFIG_FILES([
59+
lib/libptio.pc
60+
lib/Makefile
61+
tools/Makefile
4262
Makefile
43-
man/Makefile
44-
src/Makefile
4563
])
4664

4765
AC_OUTPUT

include/libptio/ptio.h

Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
// SPDX-License-Identifier: GPL-2.0-or-later
2+
/*
3+
* SPDX-FileCopyrightText: 2024 Western Digital Corporation or its affiliates.
4+
*
5+
* Authors: Damien Le Moal ([email protected])
6+
*/
7+
#ifndef LIBPTIO_H
8+
#define LIBPTIO_H
9+
10+
#include <stdint.h>
11+
#include <inttypes.h>
12+
#include <stdbool.h>
13+
#include <sys/types.h>
14+
#include <scsi/sg.h>
15+
16+
/*
17+
* CDB types.
18+
*/
19+
enum ptio_cdb_type {
20+
PTIO_CDB_NONE = 0,
21+
PTIO_CDB_SCSI,
22+
PTIO_CDB_ATA,
23+
};
24+
25+
/*
26+
* Command data transfer direction.
27+
*/
28+
enum ptio_dxfer {
29+
PTIO_DXFER_NONE = 0,
30+
PTIO_DXFER_FROM_DEV,
31+
PTIO_DXFER_TO_DEV,
32+
};
33+
34+
/*
35+
* Device flags.
36+
*/
37+
#define PTIO_VERBOSE (1 << 0)
38+
#define PTIO_ATA (1 << 1)
39+
#define PTIO_INFO (1 << 2)
40+
#define PTIO_REVALIDATE (1 << 3)
41+
42+
#define PTIO_VENDOR_LEN 9
43+
#define PTIO_ID_LEN 17
44+
#define PTIO_REV_LEN 5
45+
46+
#define PTIO_SAT_VENDOR_LEN 9
47+
#define PTIO_SAT_PRODUCT_LEN 17
48+
#define PTIO_SAT_REV_LEN 5
49+
50+
#define PTIO_SENSE_MAX_LENGTH 64
51+
#define PTIO_CDB_MAX_SIZE 32
52+
53+
struct ptio_dev {
54+
/* Device file path and basename */
55+
char *path;
56+
char *name;
57+
58+
/* Device file descriptor */
59+
int fd;
60+
61+
/* Device info */
62+
unsigned int flags;
63+
64+
unsigned int acs_ver;
65+
66+
char vendor[PTIO_VENDOR_LEN];
67+
char id[PTIO_ID_LEN];
68+
char rev[PTIO_REV_LEN];
69+
char sat_vendor[PTIO_SAT_VENDOR_LEN];
70+
char sat_product[PTIO_SAT_PRODUCT_LEN];
71+
char sat_rev[PTIO_SAT_REV_LEN];
72+
73+
size_t logical_block_size;
74+
size_t physical_block_size;
75+
unsigned long long capacity;
76+
};
77+
78+
struct ptio_cmd {
79+
uint8_t cdb[PTIO_CDB_MAX_SIZE];
80+
size_t cdbsz;
81+
enum ptio_cdb_type cdbtype;
82+
83+
uint8_t *buf;
84+
size_t bufsz;
85+
enum ptio_dxfer dxfer;
86+
87+
sg_io_hdr_t io_hdr;
88+
89+
uint8_t sense_buf[PTIO_SENSE_MAX_LENGTH];
90+
uint8_t sense_key;
91+
uint16_t asc_ascq;
92+
};
93+
94+
extern int ptio_open_dev(struct ptio_dev *dev, enum ptio_dxfer dxfer);
95+
extern void ptio_close_dev(struct ptio_dev *dev);
96+
97+
extern int ptio_revalidate_dev(struct ptio_dev *dev);
98+
extern int ptio_get_dev_information(struct ptio_dev *dev);
99+
extern const char *ptio_ata_acs_ver(struct ptio_dev *dev);
100+
101+
extern int ptio_parse_cdb(char *cdb_str, uint8_t *cdb);
102+
103+
extern uint8_t *ptio_alloc_buf(size_t bufsz);
104+
extern uint8_t *ptio_read_buf(char *path, size_t *bufsz);
105+
extern int ptio_write_buf(char *path, uint8_t *buf, size_t bufsz);
106+
extern void ptio_print_buf(uint8_t *buf, size_t bufsz);
107+
108+
extern int ptio_exec_cmd(struct ptio_dev *dev, struct ptio_cmd *cmd,
109+
uint8_t *cdb, size_t cdbsz, enum ptio_cdb_type cdb_type,
110+
uint8_t *buf, size_t bufsz, enum ptio_dxfer dxfer);
111+
112+
static inline bool ptio_dev_is_ata(struct ptio_dev *dev)
113+
{
114+
return dev->flags & PTIO_ATA;
115+
}
116+
117+
#endif /* LIBPTIO_H */

include/stamp-h1

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
timestamp for include/config.h

0 commit comments

Comments
 (0)