diff --git a/BUILD.gn b/BUILD.gn
new file mode 100644
index 0000000000000000000000000000000000000000..103f79a355bf55a8a1d92f9f4346b2c265d7b255
--- /dev/null
+++ b/BUILD.gn
@@ -0,0 +1,59 @@
+#Copyright (c) 2021 Huawei Device Co., Ltd.
+#Licensed under the Apache License, Version 2.0 (the "License");
+#you may not use this file except in compliance with the License.
+#You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+#Unless required by applicable law or agreed to in writing, software
+#distributed under the License is distributed on an "AS IS" BASIS,
+#WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+#See the License for the specific language governing permissions and
+#limitations under the License.
+
+import("//build/ohos.gni")
+import("//build/ohos/ndk/ndk.gni")
+
+config("gptdisk_config") {
+ include_dirs = [
+ ".",
+ "//third_party/e2fsprogs/lib/",
+ "//third_party/popt/",
+ ]
+ cflags_cc = [
+ "-Wall",
+ "-D_FILE_OFFSET_BITS=64",
+ "-Wno-unused-parameter",
+ "-Wno-pragma-pack",
+ "-Wno-error=header-hygiene",
+ "-Wno-register",
+ ]
+}
+ohos_executable("sgdisk") {
+ install_enable = true
+ sources = [
+ "attributes.cc",
+ "basicmbr.cc",
+ "bsd.cc",
+ "crc32.cc",
+ "diskio-unix.cc",
+ "diskio.cc",
+ "gpt.cc",
+ "gptcl.cc",
+ "gptpart.cc",
+ "guid.cc",
+ "mbr.cc",
+ "mbrpart.cc",
+ # "ohos_popt.cc",
+ "parttypes.cc",
+ "sgdisk.cc",
+ "support.cc",
+ ]
+ public_configs = [ ":gptdisk_config" ]
+ deps = [
+ "//third_party/e2fsprogs/lib/uuid:libext2_uuid",
+ "//third_party/popt:popt_static",
+ ]
+ subsystem_name = "storage"
+ part_name = "storage_standard"
+}
diff --git a/OAT.xml b/OAT.xml
new file mode 100644
index 0000000000000000000000000000000000000000..45fc7326d61cfba8adc38a9812d0db9cf89712ac
--- /dev/null
+++ b/OAT.xml
@@ -0,0 +1,115 @@
+
+
+
+
+
+ ./
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/README.OpenSource b/README.OpenSource
new file mode 100644
index 0000000000000000000000000000000000000000..8495f5fe5ec68e0400b66850151bd3a81944cade
--- /dev/null
+++ b/README.OpenSource
@@ -0,0 +1,11 @@
+[
+ {
+ "Name" : "gptfdisk",
+ "License" : "GPL-2.0-or-later",
+ "License File" : "COPYING",
+ "Version Number" : "1.0.5",
+ "Owner" : "Roderick W. Smith, rodsmith@rodsbooks.com",
+ "Upstream URL" : "https://sourceforge.net/projects/gptfdisk/files/gptfdisk/1.0.5/gptfdisk-1.0.5.tar.gz/download",
+ "Description" : "GPT fdisk is a disk partitioning tool loosely modeled on Linux fdisk, but used for modifying GUID Partition Table (GPT) disks. The related FixParts utility fixes some common problems on Master Boot Re"
+ }
+]
diff --git a/README.md b/README.md
new file mode 100644
index 0000000000000000000000000000000000000000..ec882c45151c2206dd9acf39482b06362be2506f
--- /dev/null
+++ b/README.md
@@ -0,0 +1,302 @@
+# third_party_gptfdisk
+GPT fdisk (aka gdisk, cgdisk, and sgdisk) and FixParts
+by Roderick W. Smith, rodsmith@rodsbooks.com
+
+#### Introduction
+------------
+This package includes the source code for four related disk partitioning
+programs:
+- gdisk -- This program is modeled after Linux fdisk, but it operates on
+ GUID Partition Table (GPT) disks rather than the Master Boot Record (MBR)
+ disks that fdisk modifies. As such, gdisk is an interactive text-mode
+ tool for manipulating partitions, but it does nothing to the contents of
+ those partitions (usually filesystems, but sometimes swap space or other
+ data).
+
+- cgdisk -- This program is modeled after Linux cfdisk, but it operates on
+ GPT disks rather than the MBR disks that cfdisk modifies. As such, cgdisk
+ is a curses-based text-mode tool for manipulating partitions, which is to
+ say that it uses an interface that relies on arrow keys and a dynamic
+ display rather than the command letters and a scrolling display like
+ gdisk uses.
+
+- sgdisk -- This program is conceptually similar to the Linux sfdisk and
+ FreeBSD gpt programs, but its operational details differ. It enables
+ manipulation of GPT disks using command-line options, so it's suitable
+ for use in scripts or by experts to perform specific tasks that might
+ take several commands in gdisk to accomplish.
+
+- fixparts -- This program, unlike the preceding three, operates on MBR
+ disks. It's intended to fix certain problems that can be created by
+ various utilities. Specifically, it can fix mis-sized extended partitions
+ and primary partitions located in the middle of extended partitions. It
+ also enables changing primary vs. logical partition status (within limits
+ of what's legal in the MBR scheme) and making a few other minor changes.
+ It does NOT support creating new partitions; for that, you should use
+ fdisk, parted, or some other tool.
+
+
+#### More details about the abilities of these tools follows.
+
+All four programs rely on the same set of underlying code base; they differ
+only in their control interfaces (defined in gdisk.cc, cgdisk.cc,
+sgdisk.cc, and fixparts.cc, respectively) and in which support code they
+use.
+
+#### GPT fdisk (gdisk, cgdisk, and sgdisk) Details
+---------------------------------------------
+
+The gdisk program is intended as a (somewhat) fdisk-workalike program for
+GPT-partitioned disks, cgdisk is similarly a workalike for fdisk, and
+sgdisk provides most of gdisk's functionality in a more script-friendly
+program. Although libparted and programs that use it (GNU Parted, gparted,
+etc.) provide the ability to handle GPT disks, they have certain
+limitations that gdisk overcomes. Specific advantages of gdisk, cgdisk, and
+sgdisk include:
+
+* The ability to convert MBR-partitioned disks in-place to GPT format,
+ without losing data
+
+* The ability to convert BSD disklabels in-place to create GPT
+ partitions, without losing data
+
+* The ability to convert from GPT format to MBR format without data loss
+ (gdisk and sgdisk only)
+
+* More flexible specification of filesystem type code GUIDs, which
+ GNU Parted tends to corrupt
+
+* Clear identification of the number of unallocated sectors on a
+ disk
+
+* A user interface that's familiar to long-time users of Linux
+ fdisk and cfdisk (gdisk and cgdisk only)
+
+* The MBR boot loader code is left alone
+
+* The ability to create a hybrid MBR, which permits GPT-unaware OSes to
+ access up to three GPT partitions on the disk (gdisk and sgdisk only)
+
+Of course, GPT fdisk isn't without its limitations. Most notably, it lacks
+the filesystem awareness and filesystem-related features of GParted. You
+can't resize a partition's filesystem or create a partition with a
+filesystem already in place with gdisk, for instance. There's no GUI
+version of gdisk.
+
+The GPT fdisk package provides three program files: the interactive
+text-mode gdisk, the curses-based interactive cgdisk, and the
+command-line-driven sgdisk. The first two are intended for use in manually
+partitioning disks or changing partitioning details; sgdisk is intended for
+use in scripts to help automate tasks such as disk cloning or preparing
+multiple disks for Linux installation.
+1. xxxx
+2. xxxx
+3. xxxx
+
+#### FixParts Details
+----------------
+
+This program's creation was motivated by cries for help I've seen in online
+forums from users who have found their partition tables to be corrupted by
+various buggy partitioning tools. Although most OSes can handle the
+afflicted disks fine, libparted-based tools (GParted, parted, most Linux
+installers, etc.) tend to flake out when presented with these disks.
+Typically, the symptom is a disk that appears to hold no partitions;
+however, sometimes the libparted tool presents partitions other than those
+that the OS sees.
+
+I've observed four causes of these symptoms, three of which FixParts can
+correct:
+
+* Old GPT data -- If a disk is used as a GPT disk and then re-used as an
+ MBR disk, the GPT data may be incompletely erased. This happens if the
+ disk is repartitioned with fdisk or the Microsoft Windows installer, for
+ instance. (Tools based on libparted correctly remove the old GPT data
+ when converting from GPT to MBR format.) FixParts checks for this problem
+ when it starts and offers to correct it. If you opt to erase the GPT
+ data, this erasure occurs immediately, unlike other changes the program
+ makes.
+
+* Mis-sized extended partitions -- Some tools create an extended partition
+ that's too large, typically ending after the last sector of the disk.
+ FixParts automatically corrects this problem (if you use the 'w' option
+ to save the partition table).
+
+* Primary partitions inside an extended partition -- Some utilities create
+ or move primary partitions to within the range covered by the extended
+ partition. FixParts can usually correct this problem by turning the
+ primary partition into a logical partition or by changing one or more
+ other logical partitions into primaries. Such corrections aren't always
+ possible, though, at least not without deleting or resizing other
+ partitions.
+
+* Leftover RAID data -- If a disk is used in a RAID array and then re-used
+ as a non-RAID disk, some utilities can become confused and fail to see
+ the disk. FixParts can NOT correct this problem. You must destroy the old
+ RAID data, or possibly remove the dmraid package from the system, to fix
+ this problem.
+
+When run, FixParts presents an fdisk-like interface, enabling you to adjust
+partition types (primary, logical, or omitted), change type codes, change
+the bootable flag, and so on. Although you can delete a partition (by
+omitting it), you can't create new partitions with the program. If you're
+used to partitioning disks, particularly with Linux fdisk, two unusual
+features of FixParts require elaboration:
+
+* No extended partitions -- Internally, FixParts reads the partition table
+ and discards data on any extended partition(s) it finds. When you save
+ the partition table, the program generates a new extended partition. This
+ design means that the program automatically corrects many problems
+ related to the extended partition. It also means that you'll see no
+ evidence of extended partitions in the FixParts user interface, although
+ it keeps track of the requirements and prevents you from creating illegal
+ layouts, such as a primary between two logicals.
+
+* Partition numbering -- In most Linux tools, partitions 1-4 are primaries
+ and partitions 5 and up are logicals. Although a legal partition table
+ loaded into FixParts will initially conform to this convention, some
+ types of damaged table might not, and various changes you make can also
+ cause deviations. When FixParts writes the partition table, its numbering
+ will be altered to conform to the standard MBR conventions, but you
+ should use the explicit labeling of partitions as primary or logical
+ rather than the partition numbers to determine a partition's status.
+1. xxxx
+2. xxxx
+3. xxxx
+
+#### Installing
+----------
+
+To compile GPT fdisk, you must have appropriate development tools
+installed, most notably the GNU Compiler Collection (GCC) and its g++
+compiler for C++. I've also tested compilation with Clang, which seems to
+work; however, I've not done extensive testing of the resulting binaries,
+beyond checking a few basics. Under Windows, Microsoft Visual C++ 2008 can
+be used instead. In addition, note these requirements:
+
+* On Linux, FreeBSD, OS X, and Solaris, libuuid must be installed. This is
+ the standard for Linux and OS X, although you may need to install a
+ package called uuid-dev or something similar to get the headers. On
+ FreeBSD, the e2fsprogs-libuuid port must be installed.
+
+* The ICU library (http://site.icu-project.org), which provides support for
+ Unicode partition names, is optional on all platforms except Windows, on
+ which it's not supported. Using this library was required to get proper
+ UTF-16 partition name support in GPT fdisk versions prior to 0.8.9, but
+ as of that version it should not longer be required. Nonetheless, you can
+ use it if you're having problems with the new UTF-16 support. This
+ library is normally installed in Linux and OS X, but you may need to
+ install the development headers (libicu-dev or something similar in
+ Linux; or the libicu36-dev Fink package in OS X). To compile with ICU
+ support, you must modify the Makefile: Look for commented-out lines that
+ refer to USE_UTF16, -licuuc, -licudata, or -licucore. Uncomment them and
+ comment out the equivalents that lack these lines.
+
+* The cgdisk program requires the ncurses library and its development files
+ (headers). Most Linux distributions install ncurses by default, but you
+ may need to install a package called libncurses5-dev, ncurses-devel, or
+ something similar to obtain the header files. These files were installed
+ already on my Mac OS X development system; however, they may have been
+ installed as dependencies of other programs I've installed. If you're
+ having problems installing ncurses, you can compile gdisk and/or sgdisk
+ without cgdisk by specifying only the targets you want to compile to
+ make.
+
+* The sgdisk program requires the popt library and its development files
+ (headers). Most Linux distributions install popt by default, but you may
+ need to install a package called popt-dev, popt-devel, or something
+ similar to obtain the header files. Mac OS users can find a version of
+ popt for Mac OS from Darwin Ports (http://popt.darwinports.com), MacPorts
+ (https://trac.macports.org/browser/trunk/dports/devel/popt/Portfile), Fink
+ (http://www.finkproject.org), or brew (http://macappstore.org/popt/);
+ however, you'll first need to install the relevant environment
+ (instructions exist on the relevant projects' pages). When I re-built my
+ Mac build environment in February of 2020, I found that brew was, by far,
+ the easiest of these to install. Some of the others seem to have been
+ abandoned, but I didn't investigate thoroughly. I'm leaving the references
+ in case they might be useful in the future. Instead of installing one of
+ These ports, you can compile gdisk and/or cgdisk alone, without sgdisk;
+ gdisk and cgdisk don't require popt.
+
+When all the necessary development tools and libraries are installed, you
+can uncompress the package and type "make" at the command prompt in the
+resulting directory. (You may need to type "make -f Makefile.mac" on Mac OS
+X, "make -f Makefile.freebsd" on FreeBSD, "make -f Makefile.solaris" on
+Solaris, or "make -f Makefile.mingw" to compile using MinGW for Windows.)
+You may also need to add header (include) directories or library
+directories by setting the CXXFLAGS environment variable or by editing the
+Makefile. The result should be program files called gdisk, cgdisk, sgdisk,
+and fixparts. Typing "make gdisk", "make cgdisk", "make sgdisk", or "make
+fixparts" will compile only the requested programs. You can use these
+programs in place or copy the files to a suitable directory, such as
+/usr/local/sbin. You can copy the man pages (gdisk.8, cgdisk.8, sgdisk.8,
+and fixparts.8) to /usr/local/man/man8 to make them available.
+
+1. Fork the repository
+2. Create Feat_xxx branch
+3. Commit your code
+4. Create Pull Request
+
+#### Caveats
+-------
+
+THIS SOFTWARE IS BETA SOFTWARE! IF IT WIPES OUT YOUR HARD DISK OR EATS YOUR
+CAT, DON'T BLAME ME! To date, I've tested the software on several USB flash
+drives, physical hard disks, and virtual disks in the QEMU and VirtualBox
+environments. Many others have now used the software on their computers, as
+well. I believe all data-corruption bugs to be squashed, but I know full well
+that the odds of my missing something are high. This is particularly true for
+large (over-2TiB) drives; my only direct testing with such disks is with
+virtual QEMU and VirtualBox disks. I've received user reports of success with
+RAID arrays over 2TiB in size, though.
+
+My main development platform is a system running the 64-bit version of
+Ubuntu Linux. I've also tested on several other 32- and 64-bit Linux
+distributions, Intel-based Mac OS X 10.6 and several later versions, 64-bit
+FreeBSD 7.1, and Windows 7 and 10.
+
+1. Fork the repository
+2. Create Feat_xxx branch
+3. Commit your code
+4. Create Pull Request
+
+#### Redistribution
+--------------
+
+This program is licensed under terms of the GNU GPL (see the file COPYING).
+1. Fork the repository
+2. Create Feat_xxx branch
+3. Commit your code
+4. Create Pull Request
+
+#### Acknowledgements
+----------------
+
+This code is mostly my own; however, I've used three functions from two
+other GPLed programs:
+
+- The code used to generate CRCs is taken from the efone program by
+ Krzysztof Dabrowski and ElysiuM deeZine. (See the crc32.h and
+ crc32.cc source code files.)
+
+- A function to find the disk size is taken from Linux fdisk by A. V. Le
+ Blanc. This code has subsequently been heavily modified.
+
+Additional code contributors include:
+
+- Yves Blusseau (1otnwmz02@sneakemail.com)
+
+- David Hubbard (david.c.hubbard@gmail.com)
+
+- Justin Maggard (justin.maggard@netgear.com)
+
+- Dwight Schauer (dschauer@ti.com)
+
+- Florian Zumbiehl (florz@florz.de)
+
+- Guillaume Delacour (contributed the gdisk_test.sh script)
+
+1. Fork the repository
+2. Create Feat_xxx branch
+3. Commit your code
+4. Create Pull Request
diff --git a/attributes.cc b/attributes.cc
index f3cd58527b36e38d04646c4da3293aa334bea3a5..bbd5aad86e5d499441a50acf4a68a4e5df478581 100644
--- a/attributes.cc
+++ b/attributes.cc
@@ -7,7 +7,9 @@
under the terms of the GNU GPL version 2, as detailed in the COPYING file. */
#define __STDC_LIMIT_MACROS
+#ifndef __STDC_CONSTANT_MACROS
#define __STDC_CONSTANT_MACROS
+#endif
#include
#include
diff --git a/basicmbr.cc b/basicmbr.cc
index dd4870668adaed583f83aafeff7a27836b470c56..8ac97894a80bb33823c3fdf928d713db9060c5ed 100644
--- a/basicmbr.cc
+++ b/basicmbr.cc
@@ -7,7 +7,9 @@
under the terms of the GNU GPL version 2, as detailed in the COPYING file. */
#define __STDC_LIMIT_MACROS
+#ifndef __STDC_CONSTANT_MACROS
#define __STDC_CONSTANT_MACROS
+#endif
#include
#include
diff --git a/bsd.cc b/bsd.cc
index f487f18e82d19cb36b29b0274c6af882c3dc9d12..59557c2e37e574925379aaaf4cbc7a5aaa4b33a7 100644
--- a/bsd.cc
+++ b/bsd.cc
@@ -7,7 +7,9 @@
under the terms of the GNU GPL version 2, as detailed in the COPYING file. */
#define __STDC_LIMIT_MACROS
+#ifndef __STDC_CONSTANT_MACROS
#define __STDC_CONSTANT_MACROS
+#endif
#include
//#include
diff --git a/diskio-unix.cc b/diskio-unix.cc
index d9f8b8d8bedc72346b30f12e1495691a99d48700..c6b30a7635e0a1996c9a616a223d3f4c2c0b9d5a 100644
--- a/diskio-unix.cc
+++ b/diskio-unix.cc
@@ -13,7 +13,9 @@
// under the terms of the GNU GPL version 2, as detailed in the COPYING file.
#define __STDC_LIMIT_MACROS
+#ifndef __STDC_CONSTANT_MACROS
#define __STDC_CONSTANT_MACROS
+#endif
#include
#include
diff --git a/diskio-windows.cc b/diskio-windows.cc
index 80cd7f25bd8cf3f120f3079485053272c204e4b1..6e64113bc3535f5f86236eb179828e0b61ea0078 100644
--- a/diskio-windows.cc
+++ b/diskio-windows.cc
@@ -13,7 +13,9 @@
// under the terms of the GNU GPL version 2, as detailed in the COPYING file.
#define __STDC_LIMIT_MACROS
+#ifndef __STDC_CONSTANT_MACROS
#define __STDC_CONSTANT_MACROS
+#endif
#include
#include
diff --git a/diskio.cc b/diskio.cc
index 556138e1e0722ce98ad4dd66ab485d9097d58f1f..7a89d0992fef21382adef281b3a64159c8155725 100644
--- a/diskio.cc
+++ b/diskio.cc
@@ -13,7 +13,9 @@
// under the terms of the GNU GPL version 2, as detailed in the COPYING file.
#define __STDC_LIMIT_MACROS
+#ifndef __STDC_CONSTANT_MACROS
#define __STDC_CONSTANT_MACROS
+#endif
#ifdef _WIN32
#include
diff --git a/gpt.cc b/gpt.cc
index fe8e9563852702ec9d63fc5cfa5434fa678de337..1546313a88bc579c46a19a5e7cdaa759a2087912 100644
--- a/gpt.cc
+++ b/gpt.cc
@@ -7,7 +7,9 @@
under the terms of the GNU GPL version 2, as detailed in the COPYING file. */
#define __STDC_LIMIT_MACROS
+#ifndef __STDC_CONSTANT_MACROS
#define __STDC_CONSTANT_MACROS
+#endif
#include
#include
diff --git a/gptpart.cc b/gptpart.cc
index b4f269832d78290f6c4560cc8e3891efcf09e0db..b7f9d7ffa2f399469413f764c3c0f6ba28210047 100644
--- a/gptpart.cc
+++ b/gptpart.cc
@@ -13,7 +13,9 @@
// under the terms of the GNU GPL version 2, as detailed in the COPYING file.
#define __STDC_LIMIT_MACROS
+#ifndef __STDC_CONSTANT_MACROS
#define __STDC_CONSTANT_MACROS
+#endif
#ifdef USE_UTF16
#include
diff --git a/guid.cc b/guid.cc
index 1e73ab77d854d5d49e3cf069f60df52c726b3b2c..e3e495cbeb7069e58ae36c94ae1b725e9478142c 100644
--- a/guid.cc
+++ b/guid.cc
@@ -12,7 +12,9 @@
//
#define __STDC_LIMIT_MACROS
+#ifndef __STDC_CONSTANT_MACROS
#define __STDC_CONSTANT_MACROS
+#endif
#include
#include
diff --git a/mbr.cc b/mbr.cc
index c3483a04ac1a17266c465a18fdf84a44984d0bb7..a01fe90a5f2ea64099e6fd4e7443361271cb878b 100644
--- a/mbr.cc
+++ b/mbr.cc
@@ -7,7 +7,9 @@
under the terms of the GNU GPL version 2, as detailed in the COPYING file. */
#define __STDC_LIMIT_MACROS
+#ifndef __STDC_CONSTANT_MACROS
#define __STDC_CONSTANT_MACROS
+#endif
#include
#include
diff --git a/mbrpart.cc b/mbrpart.cc
index 0ca5814ddca6a23fce485bfb4a3d56f64645019e..c805d751a75d75b3c775ad34d76f31ee2a20e5df 100644
--- a/mbrpart.cc
+++ b/mbrpart.cc
@@ -18,7 +18,9 @@
*/
#define __STDC_LIMIT_MACROS
+#ifndef __STDC_CONSTANT_MACROS
#define __STDC_CONSTANT_MACROS
+#endif
#include
#include
diff --git a/parttypes.cc b/parttypes.cc
index 38a49ffa99e826a269b090c8d69b9fc007096ec5..a325a9c9deb510a9300aac0fec951769b9d9abe1 100644
--- a/parttypes.cc
+++ b/parttypes.cc
@@ -6,7 +6,9 @@
under the terms of the GNU GPL version 2, as detailed in the COPYING file. */
#define __STDC_LIMIT_MACROS
+#ifndef __STDC_CONSTANT_MACROS
#define __STDC_CONSTANT_MACROS
+#endif
#include
#include
diff --git a/support.cc b/support.cc
index 88c130b06b6dd990fd12915950d6795264252510..9c71a5ca80bc1bb71cc68ebcd982ebbe47963d40 100644
--- a/support.cc
+++ b/support.cc
@@ -7,8 +7,12 @@
under the terms of the GNU GPL version 2, as detailed in the COPYING file. */
#define __STDC_LIMIT_MACROS
+#ifndef __STDC_CONSTANT_MACROS
#define __STDC_CONSTANT_MACROS
+#endif
+#ifndef __STDC_FORMAT_MACROS
#define __STDC_FORMAT_MACROS
+#endif
#include
#include