pmt: initial 2.9.6 release [source]
This commit is contained in:
39
.github/workflows/build.yml
vendored
39
.github/workflows/build.yml
vendored
@@ -15,16 +15,22 @@ jobs:
|
||||
id: cleanup
|
||||
uses: rokibhasansagar/slimhub_actions@main
|
||||
|
||||
- name: Update and setup packages
|
||||
id: general-packages-progress
|
||||
- name: Setup GitHub CLI
|
||||
id: setup-gh
|
||||
run: |
|
||||
type -p curl >/dev/null || (sudo apt update && sudo apt install curl -y)
|
||||
curl -fsSL https://cli.github.com/packages/githubcli-archive-keyring.gpg | sudo dd of=/usr/share/keyrings/githubcli-archive-keyring.gpg \
|
||||
&& sudo chmod go+r /usr/share/keyrings/githubcli-archive-keyring.gpg \
|
||||
&& echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/githubcli-archive-keyring.gpg] https://cli.github.com/packages stable main" | sudo tee /etc/apt/sources.list.d/github-cli.list > /dev/null \
|
||||
&& sudo apt update \
|
||||
&& sudo apt install gh -y
|
||||
|
||||
- name: Update and setup packages
|
||||
id: general-packages-progress
|
||||
run: |
|
||||
sudo apt update \
|
||||
&& sudo apt upgrade -y \
|
||||
&& sudo apt install make xz-utils aria2 gawk gh -y
|
||||
&& sudo apt install make xz-utils aria2 gawk -y
|
||||
|
||||
- name: Save spefic version variables
|
||||
id: save-vars
|
||||
@@ -40,7 +46,6 @@ jobs:
|
||||
sudo chmod -R 777 pmt
|
||||
echo "PMT_SRCDIR=/home/pmt" >> $GITHUB_ENV
|
||||
echo "NDK_DIR=/home/ndk/android-ndk" >> $GITHUB_ENV
|
||||
echo "NDK_IN_DIR=/home/ndk" >> $GITHUB_ENV
|
||||
sudo mkdir -p "/home/ndk" && cd "/home/ndk" && sudo chmod 777 "/home/ndk"
|
||||
|
||||
- name: Setup Android NDK
|
||||
@@ -57,9 +62,11 @@ jobs:
|
||||
- name: Build pmt
|
||||
id: build-pmt
|
||||
run: |
|
||||
make gen-ndk-makefiles
|
||||
export NDK_PROJECT_PATH=${PWD}
|
||||
export NDK_ROOT_DIR=${{ env.NDK_DIR }}
|
||||
. build/bash/gen-header
|
||||
echo "NDK_ROOT_DIR=${NDK_ROOT_DIR}" >> $GITHUB_ENV
|
||||
bash build/bash/gen-header
|
||||
cd ${{ env.NDK_DIR }}
|
||||
./ndk-build
|
||||
working-directory: ${{ env.PMT_SRCDIR }}
|
||||
@@ -68,18 +75,26 @@ jobs:
|
||||
id: small-transactions
|
||||
run: |
|
||||
export CXX_64="${PWD}/toolchains/llvm/prebuilt/linux-x86_64/bin/aarch64-linux-android21-clang++"
|
||||
export CXX_32="${PWD}/toolchains/llvm/prebuilt/linux-x86_64/bin/armv7a-linux-androideabi21-clang++"
|
||||
export AR="${PWD}/toolchains/llvm/prebuilt/linux-x86_64/bin/llvm-ar"
|
||||
export CXX_VERSION=$(${CXX_64} --version | head -n 1)
|
||||
echo "CXX_VERSION=${CXX_VERSION}" >> $GITHUB_ENV
|
||||
. ${{ env.PMT_SRCDIR }}/build/workflow/build.config
|
||||
. ${{ env.PMT_SRCDIR }}/build/workflow/relnotes > /home/pmt/release_body.txt
|
||||
cd ${{ env.PMT_SRCDIR }}
|
||||
zip -rq pmt-objs-local.zip obj/local/arm64-v8a obj/local/armeabi-v7a
|
||||
xz libs/arm64-v8a/pmt
|
||||
xz libs/armeabi-v7a/pmt
|
||||
mv libs/arm64-v8a/pmt.xz ${PWD}/pmt-arm64-v8a-$(date +%Y%m%d).xz
|
||||
mv libs/armeabi-v7a/pmt.xz ${PWD}/pmt-armeabi-v7a-$(date +%Y%m%d).xz
|
||||
cp build/mandoc/mandoc pmt.8
|
||||
gzip -c pmt.8 > mandoc.gz
|
||||
for arch in arm64-v8a armeabi-v7a; do
|
||||
xz libs/${arch}/pmt
|
||||
mv libs/${arch}/pmt.xz ${PWD}/pmt-${arch}-$(date +%Y%m%d).xz
|
||||
done
|
||||
for CXX_COMP in ${CXX_64} ${CXX_32}; do
|
||||
make clean
|
||||
make PMT_CXX="${CXX_COMP}" PMT_AR="${AR}" PMT_EXTRA_CFLAGS="-D__NDK_BUILD"
|
||||
[[ "${CXX_COMP}" == *"aarch64"* ]] && make deb FOR_THIS=64
|
||||
[[ "${CXX_COMP}" == *"armv7a"* ]] && make deb FOR_THIS=32
|
||||
mv out/debpackage/*.deb .
|
||||
make clean
|
||||
done
|
||||
working-directory: ${{ env.NDK_DIR }}
|
||||
|
||||
- name: Upload to release
|
||||
@@ -88,8 +103,8 @@ jobs:
|
||||
with:
|
||||
files: |
|
||||
/home/pmt/pmt*.xz
|
||||
/home/pmt/pmt*.deb
|
||||
/home/pmt/pmt-objs-local.zip
|
||||
/home/pmt/mandoc.gz
|
||||
name: Partition Manager ${{ env.PMT_VERSION }} Release
|
||||
tag_name: ${{ env.PMT_VERSION }}
|
||||
body_path: /home/pmt/release_body.txt
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
.\" See the License for the specific language governing permissions and
|
||||
.\" limitations under the License.
|
||||
.\"
|
||||
.TH "PMT" "8" "September 2024" "PMT 2.9.0" "Partition Manager"
|
||||
.TH "PMT" "8" "October 2024" "PMT 2.9.6" "Partition Manager"
|
||||
.SH NAME
|
||||
.B pmt
|
||||
\- Android Partition Manager Tool
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
export PMT_VERSION="2.9.1"
|
||||
export PMT_VERSION_CODE=291
|
||||
export PMT_VERSION="2.9.6"
|
||||
export PMT_VERSION_CODE=296
|
||||
export NDK_VERSION="r27"
|
||||
export NDK_IS="android-ndk"
|
||||
export NDK_LINK="https://dl.google.com/android/repository/android-ndk-${NDK_VERSION}-linux.zip"
|
||||
|
||||
@@ -18,84 +18,84 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#define deprecated_opt 1
|
||||
#define changed_opt 2
|
||||
#define end_depr_pointer 0
|
||||
#define not_changed 0
|
||||
#define not_changed_long nullptr
|
||||
/* annotated macros */
|
||||
#define DeprecatedOption 1
|
||||
#define ChangedOption 2
|
||||
#define EndDeprcationPoint 0
|
||||
#define NotChanged 0
|
||||
#define NotChangedLong nullptr
|
||||
|
||||
/* versions */
|
||||
#define v150 "1.5.0"
|
||||
#define v160 "1.6.0"
|
||||
#define v170 "1.7.0"
|
||||
#define v180 "1.8.0"
|
||||
#define v190 "1.9.0"
|
||||
#define v200 "2.0.0"
|
||||
#define v210 "2.1.0"
|
||||
#define v220 "2.2.0"
|
||||
#define v230 "2.3.0"
|
||||
#define v240 "2.4.0"
|
||||
#define v250 "2.5.0"
|
||||
#define v260 "2.6.0"
|
||||
#define v270 "2.7.0"
|
||||
#define v280 "2.8.0"
|
||||
#define v290 "2.9.0"
|
||||
#define vUNK nullptr
|
||||
#define v150 "1.5.0"
|
||||
#define v160 "1.6.0"
|
||||
#define v170 "1.7.0"
|
||||
#define v180 "1.8.0"
|
||||
#define v190 "1.9.0"
|
||||
#define v200 "2.0.0"
|
||||
#define v210 "2.1.0"
|
||||
#define v220 "2.2.0"
|
||||
#define v230 "2.3.0"
|
||||
#define v240 "2.4.0"
|
||||
#define v250 "2.5.0"
|
||||
#define v260 "2.6.0"
|
||||
#define v270 "2.7.0"
|
||||
#define v280 "2.8.0"
|
||||
#define v290 "2.9.0"
|
||||
#define v291 "2.9.1"
|
||||
#define v296 "2.9.6"
|
||||
#define vUNKNOWN nullptr
|
||||
|
||||
struct pmt_deprecates {
|
||||
int depr_type;
|
||||
int option;
|
||||
int option_new;
|
||||
const char* option_long;
|
||||
const char* option_long_new;
|
||||
const char* depr_version;
|
||||
struct DeprecationVarTab {
|
||||
const int DeprecationType;
|
||||
const int Option;
|
||||
const int Option_new;
|
||||
const char* Option_long;
|
||||
const char* Option_long_new;
|
||||
const char* DeprecatedOnVersion;
|
||||
};
|
||||
|
||||
static struct pmt_deprecates depr_table[] = {
|
||||
{deprecated_opt, 'b', not_changed, "backup", not_changed_long, v210},
|
||||
{deprecated_opt, 'F', not_changed, "flash", not_changed_long, v210},
|
||||
{deprecated_opt, 'r', not_changed, "format", not_changed_long, v210},
|
||||
{deprecated_opt, 'L', not_changed, "license", not_changed_long, v250},
|
||||
{changed_opt, 'D', 'p', "list", not_changed_long, v210},
|
||||
{changed_opt, 'c', 'P', "context", "search-path", v290},
|
||||
{end_depr_pointer, not_changed, not_changed, not_changed_long, not_changed_long, vUNK}
|
||||
static struct DeprecationVarTab DeprecationTable[] = {
|
||||
{DeprecatedOption, 'b', NotChanged, "backup", NotChangedLong, v210},
|
||||
{DeprecatedOption, 'F', NotChanged, "flash", NotChangedLong, v210},
|
||||
{DeprecatedOption, 'r', NotChanged, "format", NotChangedLong, v210},
|
||||
{DeprecatedOption, 'L', NotChanged, "license", NotChangedLong, v250},
|
||||
{ChangedOption, 'D', 'p', "list", NotChangedLong, v210},
|
||||
{ChangedOption, 'c', 'P', "context", "search-path", v290},
|
||||
{EndDeprcationPoint, NotChanged, NotChanged, NotChangedLong, NotChanged, vUNKNOWN}
|
||||
};
|
||||
|
||||
static void
|
||||
__process_deprecated_opts(int opt, const string& opt_long, const char* depr_msg)
|
||||
__process_deprecated_opts(int Opt, const string& OptionLong, const char* DeprecationMsg)
|
||||
{
|
||||
static string long_e_msg;
|
||||
string LongErrMsg = (OptionLong.empty()) ? PartitionManager::Display::UsingDispString->not_changed_opt : OptionLong;
|
||||
|
||||
if (opt_long.empty())
|
||||
long_e_msg = PartitionManager::Display::UsingDispString->not_changed_opt;
|
||||
else
|
||||
long_e_msg = opt_long;
|
||||
|
||||
for (int optctrl = 0; depr_table[optctrl].depr_type != 0; optctrl++)
|
||||
for (int optctrl = 0; DeprecationTable[optctrl].DeprecationType != 0; optctrl++)
|
||||
{
|
||||
|
||||
if (depr_table[optctrl].depr_type == 1)
|
||||
if (DeprecationTable[optctrl].DeprecationType == 1)
|
||||
{
|
||||
if (opt == depr_table[optctrl].option || strcmp(opt_long.c_str(), depr_table[optctrl].option_long) == 0)
|
||||
{
|
||||
LOGD("%s [%s]: -%c (%s): %s\n", PartitionManager::Display::UsingDispString->depr_opt_str, depr_table[optctrl].depr_version, (char)depr_table[optctrl].option, depr_table[optctrl].option_long, depr_msg);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
if (Opt == DeprecationTable[optctrl].Option || strcmp(OptionLong.c_str(), DeprecationTable[optctrl].Option_long) == 0)
|
||||
LOGD("%s [%s]: -%c (%s): %s\n",
|
||||
PartitionManager::Display::UsingDispString->depr_opt_str,
|
||||
DeprecationTable[optctrl].DeprecatedOnVersion,
|
||||
(char)DeprecationTable[optctrl].Option,
|
||||
DeprecationTable[optctrl].Option_long,
|
||||
DeprecationMsg); exit(1);
|
||||
}
|
||||
else if (depr_table[optctrl].depr_type == 2)
|
||||
else if (DeprecationTable[optctrl].DeprecationType == 2)
|
||||
{
|
||||
if (opt == depr_table[optctrl].option || strcmp(opt_long.c_str(), depr_table[optctrl].option_long) == 0)
|
||||
{
|
||||
LOGD("%s [%s]: -%c (%s): %s\n", PartitionManager::Display::UsingDispString->switched_opt_str, depr_table[optctrl].depr_version, (char)depr_table[optctrl].option, long_e_msg.c_str(), depr_msg);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
if (Opt == DeprecationTable[optctrl].Option || strcmp(OptionLong.c_str(), DeprecationTable[optctrl].Option_long) == 0)
|
||||
LOGD("%s [%s]: -%c (%s): %s\n",
|
||||
PartitionManager::Display::UsingDispString->switched_opt_str,
|
||||
DeprecationTable[optctrl].DeprecatedOnVersion,
|
||||
(char)DeprecationTable[optctrl].Option,
|
||||
LongErrMsg.c_str(),
|
||||
DeprecationMsg); exit(1);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
#define DEPR_HANDLE(x, y, z) \
|
||||
__process_deprecated_opts(x, y, z)
|
||||
#define DEPR_HANDLE __process_deprecated_opts
|
||||
|
||||
/* end of code */
|
||||
|
||||
@@ -18,8 +18,6 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
extern "C" {
|
||||
int mke2fs_main(int argc, char* argv[]);
|
||||
}
|
||||
extern "C" int mke2fs_main(int argc, char* argv[]);
|
||||
|
||||
/* end of code */
|
||||
@@ -18,10 +18,6 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
namespace PartitionManager {
|
||||
namespace Functions {
|
||||
void DisplayHelp(void);
|
||||
}
|
||||
}
|
||||
namespace PartitionManager { void DisplayHelp(void); }
|
||||
|
||||
/* end */
|
||||
|
||||
@@ -29,7 +29,6 @@
|
||||
#include <string>
|
||||
#include <cstring>
|
||||
#include <cstdarg>
|
||||
|
||||
#ifdef IS_MAIN
|
||||
#include <clocale>
|
||||
#endif
|
||||
@@ -54,8 +53,6 @@
|
||||
#endif
|
||||
#ifdef INC_TOOLS_REQS
|
||||
#include <sys/vfs.h>
|
||||
|
||||
typedef unsigned short ushort_t;
|
||||
#endif
|
||||
#ifdef INC_LIBGEN
|
||||
#include <libgen.h>
|
||||
@@ -71,11 +68,38 @@ typedef enum {
|
||||
LOG_LEVEL_DEBUG
|
||||
} LogLevel;
|
||||
|
||||
/* config structure */
|
||||
struct Configuration {
|
||||
bool UseLogical;
|
||||
bool UseCustomSearchPath;
|
||||
bool UsesSlots;
|
||||
bool UsesLogical;
|
||||
bool OnlyViewSize;
|
||||
bool SilentEnabled;
|
||||
bool FlashMode;
|
||||
bool BackupMode;
|
||||
bool FormatMode;
|
||||
bool PartSizeViewMode;
|
||||
bool ForceMode;
|
||||
bool VerboseMode;
|
||||
bool InstalledOnTermux;
|
||||
};
|
||||
|
||||
/**
|
||||
* Fast error processing without errno entry
|
||||
* but errno can be given in the entrance
|
||||
*/
|
||||
extern "C" char* strqerror(int errno_macro = errno);
|
||||
extern "C" char* strqerror(int __qerrno = errno);
|
||||
|
||||
/**
|
||||
* ushort_t = unsigned short type
|
||||
*/
|
||||
typedef unsigned short ushort_t;
|
||||
|
||||
/**
|
||||
* bool type configurations
|
||||
*/
|
||||
extern struct Configuration Config;
|
||||
|
||||
/* create a special namespace */
|
||||
namespace PartitionManager {
|
||||
@@ -94,22 +118,6 @@ namespace PartitionManager {
|
||||
extern int PartSizeViewType;
|
||||
} /* namespace Integers */
|
||||
|
||||
namespace Booleans {
|
||||
extern bool UseLogical;
|
||||
extern bool UseCustomSearchPath;
|
||||
extern bool UsesSlots;
|
||||
extern bool UsesLogical;
|
||||
extern bool OnlyViewSize;
|
||||
extern bool SilentEnabled;
|
||||
extern bool FlashMode;
|
||||
extern bool BackupMode;
|
||||
extern bool FormatMode;
|
||||
extern bool PartSizeViewMode;
|
||||
extern bool ForceMode;
|
||||
extern bool VerboseMode;
|
||||
extern bool InstalledOnTermux;
|
||||
} /* namespace Booleans */
|
||||
|
||||
namespace Display {
|
||||
extern struct langdb_general* UsingDispString;
|
||||
extern struct langdb_docs* UsingDocDispString;
|
||||
@@ -119,39 +127,37 @@ namespace PartitionManager {
|
||||
extern struct langdb_docs LangDocTr;
|
||||
} /* namespace Display */
|
||||
|
||||
namespace Functions {
|
||||
int ListPartitions(void);
|
||||
int GetState(const string& filepath, const string& stype = "file");
|
||||
int Start(unsigned short progress_code);
|
||||
void SetLanguage(const string& lang, unsigned short null_conf_stat);
|
||||
void DisplayLog(LogLevel status, const char* fmt, ...);
|
||||
void DisplayVerboseLog(LogLevel status, const char* fmt, ...);
|
||||
void CheckDevPoint(void);
|
||||
void CheckRoot(void);
|
||||
bool CleanSWPoint(void);
|
||||
bool LoadLanguage(void);
|
||||
} /* namespace Functions */
|
||||
|
||||
/* functions */
|
||||
int ListPartitions(void);
|
||||
int GetState(const string& filepath, const string& stype = "file");
|
||||
int PartitionManagerMain(const ushort_t& progress_code);
|
||||
void SetLanguage(const string& lang, ushort_t null_conf_stat);
|
||||
void DisplayLog(LogLevel LogPriority, const char* fmt, ...);
|
||||
void DisplayVerboseLog(LogLevel LogPriority, const char* func, const int& line, const char* fmt, ...);
|
||||
void CheckDevPoint(void);
|
||||
void CheckRoot(void);
|
||||
bool CleanSWPoint(void);
|
||||
bool LoadLanguage(void);
|
||||
} /* namespace PartitionManager */
|
||||
|
||||
/* logging macros */
|
||||
#define LOGF(fmt, ...) \
|
||||
PartitionManager::Functions::DisplayLog(LOG_LEVEL_FATAL, fmt, ##__VA_ARGS__)
|
||||
((void)PartitionManager::DisplayLog(LOG_LEVEL_FATAL, (fmt)__VA_OPT__(, ) __VA_ARGS__))
|
||||
#define LOGE(fmt, ...) \
|
||||
PartitionManager::Functions::DisplayLog(LOG_LEVEL_ERROR, fmt, ##__VA_ARGS__)
|
||||
((void)PartitionManager::DisplayLog(LOG_LEVEL_ERROR, (fmt)__VA_OPT__(, ) __VA_ARGS__))
|
||||
#define LOGW(fmt, ...) \
|
||||
PartitionManager::Functions::DisplayLog(LOG_LEVEL_WARN, fmt, ##__VA_ARGS__)
|
||||
((void)PartitionManager::DisplayLog(LOG_LEVEL_WARN, (fmt)__VA_OPT__(, ) __VA_ARGS__))
|
||||
#define LOGD(fmt, ...) \
|
||||
PartitionManager::Functions::DisplayLog(LOG_LEVEL_DEBUG, fmt, ##__VA_ARGS__)
|
||||
((void)PartitionManager::DisplayLog(LOG_LEVEL_DEBUG, (fmt)__VA_OPT__(, ) __VA_ARGS__))
|
||||
|
||||
/* verbose logging macros */
|
||||
#define VLOGF(fmt, ...) \
|
||||
PartitionManager::Functions::DisplayVerboseLog(LOG_LEVEL_FATAL, fmt, ##__VA_ARGS__)
|
||||
((void)PartitionManager::DisplayVerboseLog(LOG_LEVEL_FATAL, __func__, __LINE__, (fmt)__VA_OPT__(, ) __VA_ARGS__))
|
||||
#define VLOGE(fmt, ...) \
|
||||
PartitionManager::Functions::DisplayVerboseLog(LOG_LEVEL_ERROR, fmt, ##__VA_ARGS__)
|
||||
((void)PartitionManager::DisplayVerboseLog(LOG_LEVEL_ERROR, __func__, __LINE__, (fmt)__VA_OPT__(, ) __VA_ARGS__))
|
||||
#define VLOGW(fmt, ...) \
|
||||
PartitionManager::Functions::DisplayVerboseLog(LOG_LEVEL_WARN, fmt, ##__VA_ARGS__)
|
||||
((void)PartitionManager::DisplayVerboseLog(LOG_LEVEL_WARN, __func__, __LINE__, (fmt)__VA_OPT__(, ) __VA_ARGS__))
|
||||
#define VLOGD(fmt, ...) \
|
||||
PartitionManager::Functions::DisplayVerboseLog(LOG_LEVEL_DEBUG, fmt, ##__VA_ARGS__)
|
||||
((void)PartitionManager::DisplayVerboseLog(LOG_LEVEL_DEBUG, __func__, __LINE__, (fmt)__VA_OPT__(, ) __VA_ARGS__))
|
||||
|
||||
/* end of code */
|
||||
|
||||
@@ -25,7 +25,7 @@
|
||||
/* versioning */
|
||||
#define PMT_MAJOR 2
|
||||
#define PMT_MINOR 9
|
||||
#define PMT_PATCHLEVEL 1
|
||||
#define PMT_PATCHLEVEL 6
|
||||
|
||||
namespace PartitionManager {
|
||||
namespace Functions {
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
# limitations under the License.
|
||||
|
||||
########
|
||||
# 2.9.1
|
||||
# 2.9.6
|
||||
########
|
||||
|
||||
LOCAL_PATH := $(call my-dir)
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
# limitations under the License.
|
||||
|
||||
########
|
||||
# 2.9.1
|
||||
# 2.9.6
|
||||
########
|
||||
|
||||
# architecture
|
||||
|
||||
@@ -24,82 +24,66 @@
|
||||
using namespace PartitionManager;
|
||||
|
||||
/* it's prints standart logs */
|
||||
void Functions::DisplayLog(LogLevel status, const char* _Nullable fmt, ...)
|
||||
void PartitionManager::DisplayLog(LogLevel LogPriority, const char* _Nonnull fmt, ...)
|
||||
{
|
||||
va_list args;
|
||||
va_start(args, fmt);
|
||||
|
||||
switch (status)
|
||||
if (!Config.SilentEnabled)
|
||||
{
|
||||
switch (LogPriority)
|
||||
{
|
||||
case LOG_LEVEL_ERROR:
|
||||
if (!Booleans::SilentEnabled)
|
||||
{
|
||||
fprintf(stderr, "%s: ", Strings::ExecutingName.c_str());
|
||||
vfprintf(stderr, fmt, args);
|
||||
}
|
||||
exit(1);
|
||||
fprintf(stderr, "%s: ", Strings::ExecutingName.c_str());
|
||||
vfprintf(stderr, fmt, args);
|
||||
break;
|
||||
case LOG_LEVEL_WARN:
|
||||
if (!Booleans::SilentEnabled)
|
||||
{
|
||||
fprintf(stdout, "%s: ", Display::UsingDispString->warn);
|
||||
vfprintf(stdout, fmt, args);
|
||||
}
|
||||
fprintf(stdout, "%s: ", Display::UsingDispString->warn);
|
||||
vfprintf(stdout, fmt, args);
|
||||
break;
|
||||
case LOG_LEVEL_FATAL:
|
||||
if (!Booleans::SilentEnabled)
|
||||
{
|
||||
fprintf(stderr, "%s: ", Display::UsingDispString->fatal);
|
||||
vfprintf(stderr, fmt, args);
|
||||
}
|
||||
abort();
|
||||
fprintf(stderr, "%s: ", Display::UsingDispString->fatal);
|
||||
vfprintf(stderr, fmt, args);
|
||||
break;
|
||||
case LOG_LEVEL_DEBUG:
|
||||
if (!Booleans::SilentEnabled)
|
||||
vfprintf(stdout, fmt, args);
|
||||
vfprintf(stdout, fmt, args);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (LogPriority == LOG_LEVEL_ERROR) exit(1);
|
||||
else if (LogPriority == LOG_LEVEL_FATAL) abort();
|
||||
|
||||
va_end(args);
|
||||
}
|
||||
|
||||
/* it's prints verbose logs */
|
||||
void Functions::DisplayVerboseLog(LogLevel status, const char* fmt, ...)
|
||||
void PartitionManager::DisplayVerboseLog(LogLevel LogPriority, const char* func, const int& line, const char* _Nonnull fmt, ...)
|
||||
{
|
||||
va_list args;
|
||||
va_start(args, fmt);
|
||||
|
||||
switch (status)
|
||||
if (Config.VerboseMode)
|
||||
{
|
||||
case LOG_LEVEL_ERROR:
|
||||
if (Booleans::VerboseMode)
|
||||
{
|
||||
fprintf(stderr, "E:[stderr]: ");
|
||||
vfprintf(stderr, fmt, args);
|
||||
}
|
||||
switch (LogPriority)
|
||||
{
|
||||
case LOG_LEVEL_ERROR:
|
||||
fprintf(stderr, "<E> [%s() Line<%d>]: ", func, line);
|
||||
vfprintf(stderr, fmt, args);
|
||||
break;
|
||||
case LOG_LEVEL_WARN:
|
||||
if (Booleans::VerboseMode)
|
||||
{
|
||||
fprintf(stdout, "W:[stdout]: ");
|
||||
vfprintf(stdout, fmt, args);
|
||||
}
|
||||
fprintf(stdout, "<W> [%s() Line<%d>]: ", func, line);
|
||||
vfprintf(stdout, fmt, args);
|
||||
break;
|
||||
case LOG_LEVEL_FATAL:
|
||||
if (Booleans::VerboseMode)
|
||||
{
|
||||
fprintf(stderr, "F:[stderr]: ");
|
||||
vfprintf(stderr, fmt, args);
|
||||
abort();
|
||||
}
|
||||
fprintf(stderr, "<F> [%s() Line<%d>]: ", func, line);
|
||||
vfprintf(stderr, fmt, args);
|
||||
break;
|
||||
case LOG_LEVEL_DEBUG:
|
||||
if (Booleans::VerboseMode)
|
||||
{
|
||||
fprintf(stdout, "D:[stdout]: ");
|
||||
vfprintf(stdout, fmt, args);
|
||||
}
|
||||
fprintf(stdout, "<D> [%s() Line<%d>]: ", func, line);
|
||||
vfprintf(stdout, fmt, args);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
va_end(args);
|
||||
@@ -109,6 +93,6 @@ void Functions::DisplayVerboseLog(LogLevel status, const char* fmt, ...)
|
||||
* Last error is taken from strerror by taking
|
||||
* the contents of errno or taking a special entry
|
||||
*/
|
||||
char* strqerror(int errno_macro) { return strerror(errno_macro); }
|
||||
char* strqerror(int __qerrno) { return strerror(__qerrno); }
|
||||
|
||||
/* end of code */
|
||||
|
||||
@@ -29,14 +29,12 @@
|
||||
* If the desired type is not in -1 value is returned.
|
||||
* If the search type is unknown, 3 value is returned
|
||||
*/
|
||||
int PartitionManager::Functions::GetState(const string& filepath, const string& stype)
|
||||
int PartitionManager::GetState(const string& filepath, const string& stype)
|
||||
{
|
||||
static struct stat GetStat;
|
||||
|
||||
VLOGD("GetStat: checking `%s' with 'stat <sys/stat.h>'...\n", filepath.c_str());
|
||||
if (stat(filepath.c_str(), &GetStat) != 0)
|
||||
return 1;
|
||||
struct stat GetStat;
|
||||
VLOGD("Checking `%s' with 'stat <sys/stat.h>'...\n", filepath.c_str());
|
||||
|
||||
if (stat(filepath.c_str(), &GetStat) != 0) return 1;
|
||||
if (stype == "dir")
|
||||
return (S_ISDIR(GetStat.st_mode)) ? 0 : -1;
|
||||
else if (stype == "file")
|
||||
@@ -45,10 +43,9 @@ int PartitionManager::Functions::GetState(const string& filepath, const string&
|
||||
return (S_ISBLK(GetStat.st_mode)) ? 0 : -1;
|
||||
else if (stype == "link")
|
||||
return (S_ISLNK(GetStat.st_mode)) ? 0 : -1;
|
||||
else
|
||||
return 3;
|
||||
else return 3;
|
||||
|
||||
return 2;
|
||||
return 2; /* it's a dummy value */
|
||||
}
|
||||
|
||||
/* end of code */
|
||||
|
||||
@@ -28,7 +28,7 @@ using namespace PartitionManager;
|
||||
struct langdb_docs* Display::UsingDocDispString = nullptr;
|
||||
|
||||
static void
|
||||
prepare_langconf_docs(void)
|
||||
PrepareLangconfDocs(void)
|
||||
{
|
||||
if (Strings::CurrentLanguage == "en")
|
||||
Display::UsingDocDispString = &Display::LangDocEn;
|
||||
@@ -36,11 +36,11 @@ prepare_langconf_docs(void)
|
||||
Display::UsingDocDispString = &Display::LangDocTr;
|
||||
}
|
||||
|
||||
void Functions::DisplayHelp(void)
|
||||
void PartitionManager::DisplayHelp(void)
|
||||
{
|
||||
VLOGD("DisplayHelp: Loading language for help messages... Calling prepare_langconf_docs() <local function>...\n");
|
||||
prepare_langconf_docs();
|
||||
VLOGD("DisplayHelp: Printing...\n");
|
||||
VLOGD("Loading language for help messages... Calling PrepareLangconfDocs() <local function>...\n");
|
||||
PrepareLangconfDocs();
|
||||
VLOGD("Printing...\n");
|
||||
LOGD("%s: %s %s\n", Display::UsingDocDispString->usage_docstr, Strings::ExecutingName.c_str(), Display::UsingDocDispString->docs_strs_l1);
|
||||
LOGD(" %s: %s %s\n", Display::UsingDocDispString->or_str, Strings::ExecutingName.c_str(), Display::UsingDocDispString->docs_strs_l2);
|
||||
LOGD(" %s: %s %s\n", Display::UsingDocDispString->or_str, Strings::ExecutingName.c_str(), Display::UsingDocDispString->docs_strs_l3);
|
||||
|
||||
@@ -42,7 +42,7 @@ string supp_langs[] = {
|
||||
static bool
|
||||
InternalStorageDirFound(void)
|
||||
{
|
||||
return (Functions::GetState(INTERNAL_STORAGE_DIR, "dir") == 0) ? true : false;
|
||||
return (GetState(INTERNAL_STORAGE_DIR, "dir") == 0) ? true : false;
|
||||
}
|
||||
|
||||
static bool
|
||||
@@ -57,29 +57,29 @@ LanguageControl(const string& lang)
|
||||
return false;
|
||||
}
|
||||
|
||||
bool Functions::LoadLanguage(void)
|
||||
bool PartitionManager::LoadLanguage(void)
|
||||
{
|
||||
string lang_fpr = "en";
|
||||
langconf.close();
|
||||
|
||||
VLOGD("LoadLanguage: checking install type...\n");
|
||||
if (Functions::GetState(TERMUX_PMT_MANDOC) == 0)
|
||||
Booleans::InstalledOnTermux = true;
|
||||
VLOGD("Checking install type...\n");
|
||||
if (GetState(TERMUX_PMT_MANDOC) == 0)
|
||||
Config.InstalledOnTermux = true;
|
||||
|
||||
VLOGD("LoadLanguage: checking internal storage dir: `%s'\n", INTERNAL_STORAGE_DIR);
|
||||
VLOGD("Checking internal storage dir: `%s'\n", INTERNAL_STORAGE_DIR);
|
||||
if (!InternalStorageDirFound())
|
||||
LOGE("PartitionManagerLoadLanguage: internal storage directory (`%s') not found or accessible.\n", INTERNAL_STORAGE_DIR);
|
||||
LOGE("PartitionManagerLanguageTools: İnternal storage directory (`%s') not found or accessible.\n", INTERNAL_STORAGE_DIR);
|
||||
|
||||
VLOGD("LoadLanguage: trying to open `%s' with 'open <fstream>'\n", PMTLANG_CONF);
|
||||
VLOGD("Trying to open `%s' with 'open <fstream>'\n", PMTLANG_CONF);
|
||||
langconf.open(PMTLANG_CONF, ios::in | ios::out);
|
||||
|
||||
VLOGD("LoadLanguage: checking status: `%s'...\n", PMTLANG_CONF);
|
||||
VLOGD("Checking status: `%s'...\n", PMTLANG_CONF);
|
||||
if (!langconf.is_open())
|
||||
{
|
||||
langconf.open(PMTLANG_CONF, ios::out | ios::trunc);
|
||||
|
||||
VLOGD("LoadLanguage: calling SetLanguage()...\n");
|
||||
Functions::SetLanguage("en", 1);
|
||||
VLOGD("Calling SetLanguage()...\n");
|
||||
SetLanguage("en", 1);
|
||||
Display::UsingDispString = &Display::LangEn;
|
||||
Strings::CurrentLanguage = "en";
|
||||
|
||||
@@ -90,7 +90,7 @@ bool Functions::LoadLanguage(void)
|
||||
}
|
||||
else
|
||||
{
|
||||
VLOGD("LoadLanguage: reading `%s'\n", PMTLANG_CONF);
|
||||
VLOGD("Reading `%s'\n", PMTLANG_CONF);
|
||||
while (getline(langconf, lang_fpr))
|
||||
{
|
||||
if (lang_fpr == "en")
|
||||
@@ -99,20 +99,20 @@ bool Functions::LoadLanguage(void)
|
||||
goto SetTr;
|
||||
else
|
||||
{
|
||||
VLOGD("LoadLanguage: calling SetLanguage()\n");
|
||||
Functions::SetLanguage("en", 1);
|
||||
VLOGD("LoadLanguage: re-calling LoadLanguage()\n");
|
||||
Functions::LoadLanguage();
|
||||
VLOGD("Calling SetLanguage()\n");
|
||||
SetLanguage("en", 1);
|
||||
VLOGD("Re-calling LoadLanguage()\n");
|
||||
PartitionManager::LoadLanguage();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
if (!getline(langconf, lang_fpr))
|
||||
{
|
||||
VLOGD("LoadLanguage: calling SetLanguage()\n");
|
||||
Functions::SetLanguage("en", 1);
|
||||
VLOGD("LoadLanguage: re-calling LoadLanguage()\n");
|
||||
Functions::LoadLanguage();
|
||||
VLOGD("Calling SetLanguage()\n");
|
||||
SetLanguage("en", 1);
|
||||
VLOGD("Re-calling LoadLanguage()\n");
|
||||
PartitionManager::LoadLanguage();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -121,38 +121,38 @@ SetEn:
|
||||
langconf.close();
|
||||
Display::UsingDispString = &Display::LangEn;
|
||||
Strings::CurrentLanguage = "en";
|
||||
VLOGD("LoadLanguage: loaded \"en\"\n");
|
||||
VLOGD("Loaded \"en\"\n");
|
||||
return true;
|
||||
|
||||
SetTr:
|
||||
langconf.close();
|
||||
Display::UsingDispString = &Display::LangTr;
|
||||
Strings::CurrentLanguage = "tr";
|
||||
VLOGD("LoadLanguage: loaded \"tr\"\n");
|
||||
VLOGD("Loaded \"tr\"\n");
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void Functions::SetLanguage(const string& lang, unsigned short null_conf_stat)
|
||||
void PartitionManager::SetLanguage(const string& lang, ushort_t null_conf_stat)
|
||||
{
|
||||
VLOGD("SetLanguage: checking speficed language (from input).\n");
|
||||
VLOGD("Checking speficed language (from input).\n");
|
||||
if (!LanguageControl(lang))
|
||||
LOGE("Unknown language: %s.\n", lang.c_str());
|
||||
|
||||
langconf.close();
|
||||
|
||||
VLOGD("SetLanguage: checking internal storage dir: `%s'\n", INTERNAL_STORAGE_DIR);
|
||||
VLOGD("Checking internal storage dir: `%s'\n", INTERNAL_STORAGE_DIR);
|
||||
if (!InternalStorageDirFound())
|
||||
LOGE("PartitionManagerSetLanguage: internal storage directory (`%s') not found or accessible.\n", INTERNAL_STORAGE_DIR);
|
||||
LOGE("PartitionManagerSetLanguage: Internal storage directory (`%s') not found or accessible.\n", INTERNAL_STORAGE_DIR);
|
||||
|
||||
VLOGD("SetLanguage: trying to open `%s' with 'open <fstream>'\n", PMTLANG_CONF);
|
||||
VLOGD("Trying to open `%s' with 'open <fstream>'\n", PMTLANG_CONF);
|
||||
langconf.open(PMTLANG_CONF, ios::out | ios::trunc);
|
||||
|
||||
if (!langconf.is_open())
|
||||
LOGE("PartitionManagerLanguageTools: Cannot open/write config file!!!\n");
|
||||
|
||||
VLOGD("SetLanguage: write \"%s\" to `%s' with 'std <iostream>'\n", lang.c_str(), PMTLANG_CONF);
|
||||
VLOGD("Write \"%s\" to `%s' with 'std <iostream>'\n", lang.c_str(), PMTLANG_CONF);
|
||||
langconf << lang;
|
||||
if (!langconf)
|
||||
LOGE("PartitionManagerLanguageTools: Couldn't write config!!!\n");
|
||||
@@ -161,23 +161,23 @@ void Functions::SetLanguage(const string& lang, unsigned short null_conf_stat)
|
||||
|
||||
if (null_conf_stat != 1)
|
||||
{
|
||||
VLOGD("SetLanguage: generating dummy file `%s' with 'ofstream <fstream>'\n", PMT_SW_POINT);
|
||||
VLOGD("Generating dummy file `%s' with 'ofstream <fstream>'\n", PMT_SW_POINT);
|
||||
ofstream sw_point(PMT_SW_POINT, ios::trunc);
|
||||
if (sw_point.is_open())
|
||||
sw_point.close();
|
||||
}
|
||||
}
|
||||
|
||||
bool Functions::CleanSWPoint(void)
|
||||
bool PartitionManager::CleanSWPoint(void)
|
||||
{
|
||||
if (Functions::GetState(PMT_SW_POINT) == 0)
|
||||
if (GetState(PMT_SW_POINT) == 0)
|
||||
{
|
||||
VLOGD("CleanSWPoint: removing (force) `%s' with 'remove <unistd.h>'\n", PMT_SW_POINT);
|
||||
VLOGD("Removing (force) `%s' with 'remove <unistd.h>'\n", PMT_SW_POINT);
|
||||
remove(PMT_SW_POINT);
|
||||
return true;
|
||||
}
|
||||
else
|
||||
return false;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/* end of code */
|
||||
|
||||
@@ -80,15 +80,15 @@ directory:
|
||||
}
|
||||
|
||||
/* list existing partitions */
|
||||
int Functions::ListPartitions(void)
|
||||
int PartitionManager::ListPartitions(void)
|
||||
{
|
||||
VLOGD("ListPartitions: selecting search path...\n");
|
||||
string AccessDir = (Booleans::UseCustomSearchPath) ? Strings::CustomSearchPath : CUR_DEV_SP;
|
||||
VLOGD("Selecting search path...\n");
|
||||
string AccessDir = (Config.UseCustomSearchPath) ? Strings::CustomSearchPath : CUR_DEV_SP;
|
||||
|
||||
VLOGD("ListPartitions: trying to access `%s'...\n", AccessDir.c_str());
|
||||
VLOGD("Trying to access `%s'...\n", AccessDir.c_str());
|
||||
if (ListDir(AccessDir) != 0)
|
||||
{
|
||||
if (!Booleans::ForceMode)
|
||||
if (!Config.ForceMode)
|
||||
LOGE("%s: `%s': %s\n",
|
||||
Display::UsingDispString->not_open,
|
||||
AccessDir.c_str(),
|
||||
@@ -102,9 +102,9 @@ int Functions::ListPartitions(void)
|
||||
ListDir(AccessDir, true);
|
||||
}
|
||||
|
||||
if (Booleans::UsesLogical)
|
||||
if (Config.UsesLogical)
|
||||
{
|
||||
VLOGD("ListPartitions: checking for listing `%s'...\n", LGC_DEV_SP);
|
||||
VLOGD("Checking for listing `%s'...\n", LGC_DEV_SP);
|
||||
|
||||
if (ListDir(LGC_DEV_SP) != 0)
|
||||
LOGE("%s: `%s': %s\n",
|
||||
@@ -118,17 +118,17 @@ int Functions::ListPartitions(void)
|
||||
}
|
||||
}
|
||||
|
||||
VLOGD("ListPartitions: (if have) warnings are printed...\n");
|
||||
VLOGD("(if have) warnings are printed...\n");
|
||||
|
||||
if (Booleans::UsesLogical)
|
||||
if (Config.UsesLogical)
|
||||
{
|
||||
LOGD("\n");
|
||||
LOGW("%s\n", Display::UsingDispString->logical_warn);
|
||||
}
|
||||
|
||||
if (Booleans::UsesSlots)
|
||||
if (Config.UsesSlots)
|
||||
{
|
||||
if (!Booleans::UsesSlots)
|
||||
if (!Config.UsesLogical)
|
||||
LOGD("\n");
|
||||
|
||||
LOGW("%s\n", Display::UsingDispString->ab_warn);
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -22,49 +22,49 @@
|
||||
#include <sys/system_properties.h>
|
||||
|
||||
static int
|
||||
GetProperty(const char* _Nonnull property, const char* desired_val, const char* desired_val2 = nullptr)
|
||||
GetProperty(const char* _Nonnull property, const char* _Nonnull val1, const char* _Nullable val2 = nullptr)
|
||||
{
|
||||
char val[PROP_VALUE_MAX];
|
||||
int len = __system_property_get(property, val);
|
||||
|
||||
VLOGD("GetProperty: get property value: '%s'\n", property);
|
||||
VLOGD("Get property value: '%s'\n", property);
|
||||
if (len > 0)
|
||||
{
|
||||
VLOGD("GetProperty: %s=%s\n", property, val);
|
||||
VLOGD("%s=%s\n", property, val);
|
||||
|
||||
VLOGD("GetProperty: comparing '%s' property value '%s'\n", property, desired_val);
|
||||
if (strcmp(val, desired_val) == 0)
|
||||
VLOGD("Comparing '%s' property value '%s'\n", property, val1);
|
||||
if (strcmp(val, val1) == 0)
|
||||
{
|
||||
VLOGD("GetProperty: '%s' is '%s'. Stop (0).\n", property, desired_val);
|
||||
VLOGD("'%s' is '%s'. Stop (0).\n", property, val1);
|
||||
return 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
VLOGE("GetProperty: '%s' property is not '%s'. Comparing desired value 2 (if speficed).\n", property, desired_val);
|
||||
VLOGE("'%s' property is not '%s'. Comparing desired value 2 (if speficed).\n", property, val1);
|
||||
|
||||
if (desired_val2 != nullptr)
|
||||
if (val2 != nullptr)
|
||||
{
|
||||
if (strcmp(val, desired_val2) == 0)
|
||||
if (strcmp(val, val2) == 0)
|
||||
{
|
||||
VLOGD("GetProperty: '%s' is '%s'.Stop (0).\n", property, desired_val2);
|
||||
VLOGD("'%s' is '%s'.Stop (0).\n", property, val2);
|
||||
return 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
VLOGE("GetProperty: '%s' is not '%s'. Stop (1).\n", property, desired_val2);
|
||||
VLOGE("'%s' is not '%s'. Stop (1).\n", property, val2);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
VLOGE("GetProperty: '%s' is not '%s'. Stop (1).\n", property, desired_val);
|
||||
VLOGE("'%s' is not '%s'. Stop (1).\n", property, val1);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
VLOGE("GetProperty: cannot get property '%s'. No such property or empty. Stop (1).\n", property);
|
||||
VLOGE("Cannot get property '%s'. No such property or empty. Stop (1).\n", property);
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -74,19 +74,19 @@ GetProperty(const char* _Nonnull property, const char* desired_val, const char*
|
||||
using namespace PartitionManager;
|
||||
|
||||
/* check parts */
|
||||
void Functions::CheckDevPoint(void)
|
||||
void PartitionManager::CheckDevPoint(void)
|
||||
{
|
||||
/* true = ab | false = a only */
|
||||
Booleans::UsesSlots = (GetProperty("ro.boot.slot_suffix", "_a", "_b") == 0 || GetProperty("ro.boot.slot", "_a", "_b") == 0) ? true : false;
|
||||
Config.UsesSlots = (GetProperty("ro.boot.slot_suffix", "_a", "_b") == 0 || GetProperty("ro.boot.slot", "_a", "_b") == 0) ? true : false;
|
||||
|
||||
if (Booleans::UsesSlots)
|
||||
VLOGW("CheckDevPoint: 1 warning generated: A/B partitions status.\n");
|
||||
if (Config.UsesSlots)
|
||||
VLOGW("1 warning generated: A/B partitions status.\n");
|
||||
|
||||
/* true = logical | false = normal */
|
||||
Booleans::UsesLogical = (GetProperty("ro.boot.dynamic_partitions", "true") == 0) ? true : false;
|
||||
Config.UsesLogical = (GetProperty("ro.boot.dynamic_partitions", "true") == 0) ? true : false;
|
||||
|
||||
if (Booleans::UsesLogical)
|
||||
VLOGW("CheckDevPoint: 1 warning generated: logical partitions status.\n");
|
||||
if (Config.UsesLogical)
|
||||
VLOGW("1 warning generated: logical partitions status.\n");
|
||||
}
|
||||
|
||||
/* end of code */
|
||||
|
||||
@@ -23,13 +23,13 @@
|
||||
#include <PartitionManager/PartitionManager.h>
|
||||
|
||||
/* root checker function */
|
||||
void PartitionManager::Functions::CheckRoot(void)
|
||||
void PartitionManager::CheckRoot(void)
|
||||
{
|
||||
VLOGD("CheckRoot: trying to get UID with 'getuid <unistd.h>'\n");
|
||||
VLOGD("Trying to get UID with 'getuid <unistd.h>'\n");
|
||||
|
||||
if (getuid() != 0)
|
||||
{
|
||||
VLOGE("CheckRoot: cannot get UID. Not executed with root!\n");
|
||||
VLOGE("You are not superuser!\n");
|
||||
LOGE("%s\n", PartitionManager::Display::UsingDispString->no_root);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,8 +27,10 @@
|
||||
#include <PartitionManager/PartSizeMacros.h>
|
||||
#include <PartitionManager/FileSystemUtils.h>
|
||||
|
||||
static fstream sourceF, targetF;
|
||||
static long long Count;
|
||||
|
||||
namespace PartitionManager {
|
||||
namespace Functions {
|
||||
|
||||
/**
|
||||
* it is meant to calculate the size of the quickly given file.
|
||||
@@ -37,9 +39,9 @@ namespace Functions {
|
||||
static long long
|
||||
CalculateSizeLongLong(const string& fp)
|
||||
{
|
||||
VLOGD("CalculateSizeLongLong: calculating file size: `%s'\n", fp.c_str());
|
||||
VLOGD("Calculating file size: `%s'\n", fp.c_str());
|
||||
|
||||
VLOGD("CalculateSizeLongLong: reading `%s' with 'ifstream <fstream>'\n", fp.c_str());
|
||||
VLOGD("Reading `%s' with 'ifstream <fstream>'\n", fp.c_str());
|
||||
ifstream file(fp, ios::binary | ios::ate);
|
||||
|
||||
return (!file) ? -1 : static_cast<long long>(file.tellg());
|
||||
@@ -50,23 +52,23 @@ CalculateSizeLongLong(const string& fp)
|
||||
* It's for quick action.
|
||||
*/
|
||||
static void
|
||||
PartitionNotFound(const char* p) { LOGE("%s: %s\n", p, Display::UsingDispString->part_not_found); }
|
||||
PartitionNotFound(const string& part) { LOGE("%s: %s\n", part.c_str(), Display::UsingDispString->part_not_found); }
|
||||
|
||||
/* the partitions are meant to quickly find. */
|
||||
static void
|
||||
SearchPartition(const string& fp)
|
||||
{
|
||||
VLOGD("SearchPartition: calling GetState()...\n");
|
||||
VLOGD("Calling GetState()...\n");
|
||||
static int op = GetState(fp, "blk");
|
||||
|
||||
if (op == 1)
|
||||
PartitionNotFound(basename(fp.c_str()));
|
||||
else if (op == -1 && !Booleans::ForceMode)
|
||||
else if (op == -1 && !Config.ForceMode)
|
||||
LOGE("%s\n", Display::UsingDispString->not_block);
|
||||
}
|
||||
|
||||
static void
|
||||
PrintInfo(ushort_t pcode, double psz, double fsz)
|
||||
PrintInfo(const ushort_t& pcode, const double& psz, const double& fsz)
|
||||
{
|
||||
LOGD("##########################################\n");
|
||||
LOGD("# --> %s: %s\n",
|
||||
@@ -74,7 +76,7 @@ PrintInfo(ushort_t pcode, double psz, double fsz)
|
||||
Strings::TargetPartition.c_str());
|
||||
LOGD("# --> %s: %s\n",
|
||||
Display::UsingDispString->part_type,
|
||||
(Booleans::UseLogical) ? Display::UsingDispString->yes : Display::UsingDispString->no);
|
||||
(Config.UseLogical) ? Display::UsingDispString->yes : Display::UsingDispString->no);
|
||||
|
||||
if (psz != -1)
|
||||
LOGD("# --> %s: %.2fMB\n",
|
||||
@@ -100,63 +102,93 @@ PrintInfo(ushort_t pcode, double psz, double fsz)
|
||||
LOGD("##########################################\n");
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
static bool
|
||||
IsDoubleOf1024(float size)
|
||||
{
|
||||
float num = size / 1024;
|
||||
char str[35];
|
||||
sprintf(str, "%f", num);
|
||||
IsDoubleOf1024(T size) { return size % (T)1024 == 0; }
|
||||
|
||||
return (strstr(str, ".000000") != nullptr) ? true : false;
|
||||
static void
|
||||
ReadAndWrite(const string& FNameForMsg, const int& bfsize)
|
||||
{
|
||||
long long copiedData = 0;
|
||||
char buffer[bfsize];
|
||||
|
||||
while (sourceF.read(buffer, bfsize) && copiedData < Count)
|
||||
{
|
||||
streamsize readed_data = sourceF.gcount();
|
||||
targetF.write(buffer, readed_data);
|
||||
|
||||
if (targetF.fail() || targetF.bad())
|
||||
LOGF("%s: %s: %s\n",
|
||||
Display::UsingDispString->not_write,
|
||||
FNameForMsg.c_str(),
|
||||
strqerror());
|
||||
|
||||
copiedData += readed_data;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
OpenSourceFile(const string& fp)
|
||||
{
|
||||
VLOGD("Trying to open `%s' with 'open <fstream>'.\n", fp.c_str());
|
||||
|
||||
sourceF.open(fp, ios::binary | ios::in);
|
||||
if (!sourceF.is_open())
|
||||
LOGE("%s: %s: %s\n",
|
||||
Display::UsingDispString->not_read,
|
||||
fp.c_str(),
|
||||
strqerror());
|
||||
}
|
||||
|
||||
static void
|
||||
OpenTargetFile(const string& fp)
|
||||
{
|
||||
VLOGD("Trying to open `%s' with 'open <fstream>'.\n", fp.c_str());
|
||||
|
||||
targetF.open(fp, ios::binary | ios::out);
|
||||
if (!targetF.is_open())
|
||||
LOGE("%s: %s: %s\n",
|
||||
Display::UsingDispString->not_gen,
|
||||
fp.c_str(),
|
||||
strqerror());
|
||||
}
|
||||
|
||||
} /* namespace Functions */
|
||||
} /* namespace PartitionManager */
|
||||
|
||||
using namespace PartitionManager;
|
||||
|
||||
int Functions::Start(ushort_t progress_code)
|
||||
int PartitionManager::PartitionManagerMain(const ushort_t& progress_code)
|
||||
{
|
||||
/* Some required variables */
|
||||
fstream sourceF, targetF;
|
||||
string accessPrefix, opName;
|
||||
long long copiedData = 0;
|
||||
bool IsFirstProcessOnTarget = true;
|
||||
|
||||
if (Booleans::UseLogical)
|
||||
if (Config.UseLogical)
|
||||
accessPrefix = "/dev/block/mapper/" + Strings::TargetPartition;
|
||||
else
|
||||
accessPrefix = (Booleans::UseCustomSearchPath) ? (Strings::CustomSearchPath) + ("/") + (Strings::TargetPartition) : ("/dev/block/by-name/") + (Strings::TargetPartition);
|
||||
accessPrefix = (Config.UseCustomSearchPath) ? (Strings::CustomSearchPath) + ("/") + (Strings::TargetPartition) : ("/dev/block/by-name/") + (Strings::TargetPartition);
|
||||
|
||||
VLOGD("PartitionManager: calling SearchPartition() for searching partition (path); `%s'\n", accessPrefix.c_str());
|
||||
Functions::SearchPartition(accessPrefix);
|
||||
VLOGD("Calling SearchPartition() for searching partition (path); `%s'\n", accessPrefix.c_str());
|
||||
SearchPartition(accessPrefix);
|
||||
|
||||
static long long count = (long long)(CalculateSizeLongLong(accessPrefix) + ((1024 * 1024) * 4));
|
||||
const int BFSIZE = (Functions::IsDoubleOf1024((float)Functions::CalculateSizeLongLong(accessPrefix))) ? 1024 : 1;
|
||||
char buffer[BFSIZE];
|
||||
Count = (long long)(CalculateSizeLongLong(accessPrefix) + ((1024 * 1024) * 4));
|
||||
const int BFSIZE = (IsDoubleOf1024(CalculateSizeLongLong(accessPrefix))) ? 1024 : 1;
|
||||
double FlashFileSize = 0;
|
||||
|
||||
double PartitionSize = (double)(static_cast<double>(Functions::CalculateSizeLongLong(accessPrefix)) / (1024 * 1024));
|
||||
double PartitionSize = (double)(static_cast<double>(CalculateSizeLongLong(accessPrefix)) / (1024 * 1024));
|
||||
if (!Strings::TargetFlashFile.empty())
|
||||
FlashFileSize = (double)(static_cast<double>(Functions::CalculateSizeLongLong(Strings::TargetFlashFile)) / (1024 * 1024));
|
||||
FlashFileSize = (double)(static_cast<double>(CalculateSizeLongLong(Strings::TargetFlashFile)) / (1024 * 1024));
|
||||
|
||||
if (progress_code != 4) PrintInfo(progress_code, PartitionSize, FlashFileSize);
|
||||
|
||||
if (progress_code == 1)
|
||||
{
|
||||
VLOGD("PartitionManager: trying to open `%s' with 'open <fstream>'.\n", accessPrefix.c_str());
|
||||
sourceF.open(accessPrefix, ios::binary | ios::in);
|
||||
if (!sourceF.is_open())
|
||||
LOGE("%s: %s: %s\n",
|
||||
Display::UsingDispString->not_read,
|
||||
accessPrefix.c_str(),
|
||||
strqerror());
|
||||
OpenSourceFile(accessPrefix);
|
||||
|
||||
/* determine output */
|
||||
if (Strings::OutputName == Strings::TargetPartition)
|
||||
{
|
||||
opName = Strings::OutputName + ".img";
|
||||
VLOGW("PartitionManager: output not speficed. Selecting automaticly.\n");
|
||||
VLOGW("Output not speficed. Selecting automaticly.\n");
|
||||
LOGW("%s: %s\n",
|
||||
Display::UsingDispString->out_not_spec,
|
||||
opName.c_str());
|
||||
@@ -168,37 +200,10 @@ int Functions::Start(ushort_t progress_code)
|
||||
if (GetState(opName) == 0)
|
||||
LOGE("'%s': File exits.\n", opName.c_str());
|
||||
|
||||
VLOGD("PartitionManager: trying to open `%s' with 'open <fstream>'.\n", opName.c_str());
|
||||
targetF.open(opName, ios::binary | ios::out);
|
||||
if (!targetF.is_open())
|
||||
LOGE("%s: %s: %s\n",
|
||||
Display::UsingDispString->not_gen,
|
||||
opName.c_str(),
|
||||
strqerror());
|
||||
OpenTargetFile(opName);
|
||||
|
||||
VLOGD("PartitionManager: read (partition) and write (output) 'read, write <fstream>'\n");
|
||||
/* start writing */
|
||||
while (sourceF.read(buffer, BFSIZE) && copiedData < count)
|
||||
{
|
||||
if (GetState(opName) != 0 && IsFirstProcessOnTarget)
|
||||
LOGE("%s\n", Display::UsingDispString->no_found_on_process);
|
||||
|
||||
streamsize readed_data = sourceF.gcount();
|
||||
targetF.write(buffer, readed_data);
|
||||
|
||||
if (targetF.fail() || targetF.bad())
|
||||
{
|
||||
if (Functions::GetState(opName) == 0)
|
||||
remove(opName.c_str());
|
||||
LOGF("%s: %s: %s\n",
|
||||
Display::UsingDispString->not_write,
|
||||
opName.c_str(),
|
||||
strqerror());
|
||||
}
|
||||
|
||||
IsFirstProcessOnTarget = false;
|
||||
copiedData += readed_data;
|
||||
}
|
||||
VLOGD("Read (partition) and write (output) 'read, write <fstream>'\n");
|
||||
ReadAndWrite(opName.c_str(), BFSIZE);
|
||||
|
||||
/* close files */
|
||||
sourceF.close();
|
||||
@@ -212,41 +217,15 @@ int Functions::Start(ushort_t progress_code)
|
||||
{
|
||||
if (PartitionSize != -1 && FlashFileSize != -1)
|
||||
{
|
||||
if (FlashFileSize > PartitionSize && !Booleans::ForceMode)
|
||||
if (FlashFileSize > PartitionSize && !Config.ForceMode)
|
||||
LOGE("%s\n", Display::UsingDispString->ffile_more_part);
|
||||
}
|
||||
|
||||
VLOGD("PartitionManager: trying to open `%s' with 'open <fstream>'.\n", Strings::TargetFlashFile.c_str());
|
||||
sourceF.open(Strings::TargetFlashFile, ios::binary | ios::in);
|
||||
if (!sourceF.is_open())
|
||||
LOGF("%s: %s: %s\n",
|
||||
Display::UsingDispString->not_read,
|
||||
Strings::TargetFlashFile.c_str(),
|
||||
strqerror());
|
||||
OpenSourceFile(Strings::TargetFlashFile);
|
||||
OpenTargetFile(accessPrefix);
|
||||
|
||||
VLOGD("PartitionManager: trying to open `%s' with 'open <fstream>'.\n", accessPrefix.c_str());
|
||||
targetF.open(accessPrefix, ios::binary | ios::in | ios::out | ios::trunc);
|
||||
if (!targetF.is_open())
|
||||
LOGF("%s: %s: %s\n",
|
||||
Display::UsingDispString->not_read,
|
||||
accessPrefix.c_str(),
|
||||
strqerror());
|
||||
|
||||
VLOGD("PartitionManager: read (flash file) and write (partition) 'read, write <fstream>'\n");
|
||||
/* start writing */
|
||||
while (sourceF.read(buffer, BFSIZE) && copiedData < count)
|
||||
{
|
||||
streamsize readed_data = sourceF.gcount();
|
||||
targetF.write(buffer, readed_data);
|
||||
|
||||
if (targetF.fail() || targetF.bad())
|
||||
LOGF("%s: %s: %s\n",
|
||||
Display::UsingDispString->not_write,
|
||||
accessPrefix.c_str(),
|
||||
strqerror());
|
||||
|
||||
copiedData += readed_data;
|
||||
}
|
||||
VLOGD("Read (flash file) and write (partition) 'read, write <fstream>'\n");
|
||||
ReadAndWrite(accessPrefix.c_str(), BFSIZE);
|
||||
|
||||
sourceF.close();
|
||||
targetF.close();
|
||||
@@ -256,14 +235,14 @@ int Functions::Start(ushort_t progress_code)
|
||||
else if (progress_code == 3)
|
||||
{
|
||||
/* get target partition block size */
|
||||
VLOGD("PartitionManager: getting block size `%s' with 'statfs <sys/vfs.h>'\n", accessPrefix.c_str());
|
||||
VLOGD("Getting block size '%s' with 'statfs <sys/vfs.h>'\n", accessPrefix.c_str());
|
||||
|
||||
struct statfs file_sys_inf;
|
||||
if (statfs(accessPrefix.c_str(), &file_sys_inf) != 0)
|
||||
LOGE("%s\n", Display::UsingDispString->cannot_get_bsz);
|
||||
|
||||
/* generate mke2fs argument list */
|
||||
VLOGD("PartitionManager: generating mke2fs argument list...\n");
|
||||
VLOGD("Generating mke2fs argument list...\n");
|
||||
char bsize[25] = "";
|
||||
#ifdef __LP64__
|
||||
sprintf(bsize, "%lu", file_sys_inf.f_bsize);
|
||||
@@ -287,7 +266,7 @@ int Functions::Start(ushort_t progress_code)
|
||||
Strings::TargetFormatFS.c_str());
|
||||
|
||||
/* run mke2fs */
|
||||
VLOGD("PartitionManager: calling mke2fs_main...\n");
|
||||
VLOGD("Calling mke2fs_main...\n");
|
||||
if (mke2fs_main(sizeof(arguments), arguments) != 0)
|
||||
LOGF("%s\n", Display::UsingDispString->format_fail);
|
||||
|
||||
@@ -295,12 +274,12 @@ int Functions::Start(ushort_t progress_code)
|
||||
}
|
||||
else if (progress_code == 4)
|
||||
{
|
||||
VLOGD("PartitionManager: getting size of '%s' (long long)\n", accessPrefix.c_str());
|
||||
VLOGD("Getting size of '%s' (long long)\n", accessPrefix.c_str());
|
||||
long long psize = (long long)CalculateSizeLongLong(accessPrefix);
|
||||
|
||||
if (psize == -1)
|
||||
{
|
||||
VLOGE("PartitionManager: cannot get partition size!\n");
|
||||
VLOGE("Cannot get partition size!\n");
|
||||
LOGE("%s: %s\n",
|
||||
Display::UsingDispString->fail_get_psize,
|
||||
strqerror());
|
||||
@@ -309,7 +288,7 @@ int Functions::Start(ushort_t progress_code)
|
||||
static char* SizeType;
|
||||
static char Holder[50];
|
||||
|
||||
if (!Booleans::OnlyViewSize)
|
||||
if (!Config.OnlyViewSize)
|
||||
{
|
||||
sprintf(Holder, "%s: ", Strings::TargetPartition.c_str());
|
||||
|
||||
@@ -321,7 +300,7 @@ int Functions::Start(ushort_t progress_code)
|
||||
else
|
||||
SizeType = "";
|
||||
|
||||
VLOGD("PartitionManager: Displaying partition size...\n");
|
||||
VLOGD("Displaying partition size...\n");
|
||||
|
||||
if (Integers::PartSizeViewType == VIEW_AS_BYTE)
|
||||
LOGD("%s%llu%s\n",
|
||||
|
||||
@@ -25,9 +25,9 @@
|
||||
|
||||
using namespace PartitionManager;
|
||||
|
||||
void Functions::DisplayVersion(void)
|
||||
void PartitionManager::DisplayVersion(void)
|
||||
{
|
||||
VLOGD("DisplayVersion: printing main info...\n");
|
||||
VLOGD("Printing main info...\n");
|
||||
LOGD("%s %s %d.%d.%d (%d%d%d / C++) ",
|
||||
Strings::ExecutingName.c_str(),
|
||||
Display::UsingDispString->version_str,
|
||||
@@ -38,14 +38,10 @@ void Functions::DisplayVersion(void)
|
||||
PMT_MINOR,
|
||||
PMT_PATCHLEVEL);
|
||||
|
||||
#if __SIZEOF_POINTER__ == 4
|
||||
LOGD("32-bit %s\n", Display::UsingDispString->bin_str);
|
||||
#elif __SIZEOF_POINTER__ == 8
|
||||
#ifdef __LP64__
|
||||
LOGD("64-bit %s\n", Display::UsingDispString->bin_str);
|
||||
#else
|
||||
LOGD("<%s> %s\n",
|
||||
Display::UsingDispString->unknw_str,
|
||||
Display::UsingDispString->bin_str);
|
||||
LOGD("32-bit %s\n", Display::UsingDispString->bin_str);
|
||||
#endif
|
||||
|
||||
LOGD("mke2fs %s %s (%s)\n",
|
||||
|
||||
@@ -1,167 +0,0 @@
|
||||
/*
|
||||
* bmove.c --- Move blocks around to make way for a particular
|
||||
* filesystem structure.
|
||||
*
|
||||
* Copyright (C) 1997 Theodore Ts'o.
|
||||
*
|
||||
* %Begin-Header%
|
||||
* This file may be redistributed under the terms of the GNU Library
|
||||
* General Public License, version 2.
|
||||
* %End-Header%
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#if HAVE_UNISTD_H
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
#if HAVE_SYS_TYPES_H
|
||||
#include <sys/types.h>
|
||||
#endif
|
||||
#if HAVE_SYS_TIME_H
|
||||
#include <sys/time.h>
|
||||
#endif
|
||||
|
||||
#include "ext2_fs.h"
|
||||
#include "ext2fsP.h"
|
||||
|
||||
struct process_block_struct {
|
||||
ext2_ino_t ino;
|
||||
struct ext2_inode * inode;
|
||||
ext2fs_block_bitmap reserve;
|
||||
ext2fs_block_bitmap alloc_map;
|
||||
errcode_t error;
|
||||
char *buf;
|
||||
int add_dir;
|
||||
int flags;
|
||||
};
|
||||
|
||||
static int process_block(ext2_filsys fs, blk64_t *block_nr,
|
||||
e2_blkcnt_t blockcnt, blk64_t ref_block,
|
||||
int ref_offset, void *priv_data)
|
||||
{
|
||||
struct process_block_struct *pb;
|
||||
errcode_t retval;
|
||||
int ret;
|
||||
blk64_t block, orig;
|
||||
|
||||
pb = (struct process_block_struct *) priv_data;
|
||||
block = orig = *block_nr;
|
||||
ret = 0;
|
||||
|
||||
/*
|
||||
* Let's see if this is one which we need to relocate
|
||||
*/
|
||||
if (ext2fs_test_block_bitmap2(pb->reserve, block)) {
|
||||
do {
|
||||
if (++block >= ext2fs_blocks_count(fs->super))
|
||||
block = fs->super->s_first_data_block;
|
||||
if (block == orig) {
|
||||
pb->error = EXT2_ET_BLOCK_ALLOC_FAIL;
|
||||
return BLOCK_ABORT;
|
||||
}
|
||||
} while (ext2fs_test_block_bitmap2(pb->reserve, block) ||
|
||||
ext2fs_test_block_bitmap2(pb->alloc_map, block));
|
||||
|
||||
retval = io_channel_read_blk64(fs->io, orig, 1, pb->buf);
|
||||
if (retval) {
|
||||
pb->error = retval;
|
||||
return BLOCK_ABORT;
|
||||
}
|
||||
retval = io_channel_write_blk64(fs->io, block, 1, pb->buf);
|
||||
if (retval) {
|
||||
pb->error = retval;
|
||||
return BLOCK_ABORT;
|
||||
}
|
||||
*block_nr = block;
|
||||
ext2fs_mark_block_bitmap2(pb->alloc_map, block);
|
||||
ret = BLOCK_CHANGED;
|
||||
if (pb->flags & EXT2_BMOVE_DEBUG)
|
||||
printf("ino=%u, blockcnt=%lld, %llu->%llu\n",
|
||||
(unsigned) pb->ino, blockcnt,
|
||||
(unsigned long long) orig,
|
||||
(unsigned long long) block);
|
||||
}
|
||||
if (pb->add_dir) {
|
||||
retval = ext2fs_add_dir_block2(fs->dblist, pb->ino,
|
||||
block, blockcnt);
|
||||
if (retval) {
|
||||
pb->error = retval;
|
||||
ret |= BLOCK_ABORT;
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
errcode_t ext2fs_move_blocks(ext2_filsys fs,
|
||||
ext2fs_block_bitmap reserve,
|
||||
ext2fs_block_bitmap alloc_map,
|
||||
int flags)
|
||||
{
|
||||
ext2_ino_t ino;
|
||||
struct ext2_inode inode;
|
||||
errcode_t retval;
|
||||
struct process_block_struct pb;
|
||||
ext2_inode_scan scan;
|
||||
char *block_buf;
|
||||
|
||||
retval = ext2fs_open_inode_scan(fs, 0, &scan);
|
||||
if (retval)
|
||||
return retval;
|
||||
|
||||
pb.reserve = reserve;
|
||||
pb.error = 0;
|
||||
pb.alloc_map = alloc_map ? alloc_map : fs->block_map;
|
||||
pb.flags = flags;
|
||||
|
||||
retval = ext2fs_get_array(4, fs->blocksize, &block_buf);
|
||||
if (retval)
|
||||
return retval;
|
||||
pb.buf = block_buf + fs->blocksize * 3;
|
||||
|
||||
/*
|
||||
* If GET_DBLIST is set in the flags field, then we should
|
||||
* gather directory block information while we're doing the
|
||||
* block move.
|
||||
*/
|
||||
if (flags & EXT2_BMOVE_GET_DBLIST) {
|
||||
if (fs->dblist) {
|
||||
ext2fs_free_dblist(fs->dblist);
|
||||
fs->dblist = NULL;
|
||||
}
|
||||
retval = ext2fs_init_dblist(fs, 0);
|
||||
if (retval)
|
||||
return retval;
|
||||
}
|
||||
|
||||
retval = ext2fs_get_next_inode(scan, &ino, &inode);
|
||||
if (retval)
|
||||
return retval;
|
||||
|
||||
while (ino) {
|
||||
if ((inode.i_links_count == 0) ||
|
||||
!ext2fs_inode_has_valid_blocks2(fs, &inode))
|
||||
goto next;
|
||||
|
||||
pb.ino = ino;
|
||||
pb.inode = &inode;
|
||||
|
||||
pb.add_dir = (LINUX_S_ISDIR(inode.i_mode) &&
|
||||
flags & EXT2_BMOVE_GET_DBLIST);
|
||||
|
||||
retval = ext2fs_block_iterate3(fs, ino, 0, block_buf,
|
||||
process_block, &pb);
|
||||
if (retval)
|
||||
return retval;
|
||||
if (pb.error)
|
||||
return pb.error;
|
||||
|
||||
next:
|
||||
retval = ext2fs_get_next_inode(scan, &ino, &inode);
|
||||
if (retval == EXT2_ET_BAD_BLOCK_IN_INODE_TABLE)
|
||||
goto next;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -1,199 +0,0 @@
|
||||
/*
|
||||
* brel_ma.c
|
||||
*
|
||||
* Copyright (C) 1996, 1997 Theodore Ts'o.
|
||||
*
|
||||
* TODO: rewrite to not use a direct array!!! (Fortunately this
|
||||
* module isn't really used yet.)
|
||||
*
|
||||
* %Begin-Header%
|
||||
* This file may be redistributed under the terms of the GNU Library
|
||||
* General Public License, version 2.
|
||||
* %End-Header%
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
#include <fcntl.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#if HAVE_UNISTD_H
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
#if HAVE_ERRNO_H
|
||||
#include <errno.h>
|
||||
#endif
|
||||
|
||||
#include "ext2_fs.h"
|
||||
#include "ext2fs.h"
|
||||
#include "brel.h"
|
||||
|
||||
static errcode_t bma_put(ext2_brel brel, blk64_t old,
|
||||
struct ext2_block_relocate_entry *ent);
|
||||
static errcode_t bma_get(ext2_brel brel, blk64_t old,
|
||||
struct ext2_block_relocate_entry *ent);
|
||||
static errcode_t bma_start_iter(ext2_brel brel);
|
||||
static errcode_t bma_next(ext2_brel brel, blk64_t *old,
|
||||
struct ext2_block_relocate_entry *ent);
|
||||
static errcode_t bma_move(ext2_brel brel, blk64_t old, blk64_t new);
|
||||
static errcode_t bma_delete(ext2_brel brel, blk64_t old);
|
||||
static errcode_t bma_free(ext2_brel brel);
|
||||
|
||||
struct brel_ma {
|
||||
__u32 magic;
|
||||
blk64_t max_block;
|
||||
struct ext2_block_relocate_entry *entries;
|
||||
};
|
||||
|
||||
errcode_t ext2fs_brel_memarray_create(char *name, blk64_t max_block,
|
||||
ext2_brel *new_brel)
|
||||
{
|
||||
ext2_brel brel = 0;
|
||||
errcode_t retval;
|
||||
struct brel_ma *ma = 0;
|
||||
size_t size;
|
||||
|
||||
*new_brel = 0;
|
||||
|
||||
/*
|
||||
* Allocate memory structures
|
||||
*/
|
||||
retval = ext2fs_get_mem(sizeof(struct ext2_block_relocation_table),
|
||||
&brel);
|
||||
if (retval)
|
||||
goto errout;
|
||||
memset(brel, 0, sizeof(struct ext2_block_relocation_table));
|
||||
|
||||
retval = ext2fs_get_mem(strlen(name)+1, &brel->name);
|
||||
if (retval)
|
||||
goto errout;
|
||||
strcpy(brel->name, name);
|
||||
|
||||
retval = ext2fs_get_mem(sizeof(struct brel_ma), &ma);
|
||||
if (retval)
|
||||
goto errout;
|
||||
memset(ma, 0, sizeof(struct brel_ma));
|
||||
brel->priv_data = ma;
|
||||
|
||||
size = (size_t) (sizeof(struct ext2_block_relocate_entry) *
|
||||
(max_block+1));
|
||||
retval = ext2fs_get_array(max_block+1,
|
||||
sizeof(struct ext2_block_relocate_entry), &ma->entries);
|
||||
if (retval)
|
||||
goto errout;
|
||||
memset(ma->entries, 0, size);
|
||||
ma->max_block = max_block;
|
||||
|
||||
/*
|
||||
* Fill in the brel data structure
|
||||
*/
|
||||
brel->put = bma_put;
|
||||
brel->get = bma_get;
|
||||
brel->start_iter = bma_start_iter;
|
||||
brel->next = bma_next;
|
||||
brel->move = bma_move;
|
||||
brel->delete = bma_delete;
|
||||
brel->free = bma_free;
|
||||
|
||||
*new_brel = brel;
|
||||
return 0;
|
||||
|
||||
errout:
|
||||
bma_free(brel);
|
||||
return retval;
|
||||
}
|
||||
|
||||
static errcode_t bma_put(ext2_brel brel, blk64_t old,
|
||||
struct ext2_block_relocate_entry *ent)
|
||||
{
|
||||
struct brel_ma *ma;
|
||||
|
||||
ma = brel->priv_data;
|
||||
if (old > ma->max_block)
|
||||
return EXT2_ET_INVALID_ARGUMENT;
|
||||
ma->entries[(unsigned)old] = *ent;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static errcode_t bma_get(ext2_brel brel, blk64_t old,
|
||||
struct ext2_block_relocate_entry *ent)
|
||||
{
|
||||
struct brel_ma *ma;
|
||||
|
||||
ma = brel->priv_data;
|
||||
if (old > ma->max_block)
|
||||
return EXT2_ET_INVALID_ARGUMENT;
|
||||
if (ma->entries[(unsigned)old].new == 0)
|
||||
return ENOENT;
|
||||
*ent = ma->entries[old];
|
||||
return 0;
|
||||
}
|
||||
|
||||
static errcode_t bma_start_iter(ext2_brel brel)
|
||||
{
|
||||
brel->current = 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static errcode_t bma_next(ext2_brel brel, blk64_t *old,
|
||||
struct ext2_block_relocate_entry *ent)
|
||||
{
|
||||
struct brel_ma *ma;
|
||||
|
||||
ma = brel->priv_data;
|
||||
while (++brel->current < ma->max_block) {
|
||||
if (ma->entries[(unsigned)brel->current].new == 0)
|
||||
continue;
|
||||
*old = brel->current;
|
||||
*ent = ma->entries[(unsigned)brel->current];
|
||||
return 0;
|
||||
}
|
||||
*old = 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static errcode_t bma_move(ext2_brel brel, blk64_t old, blk64_t new)
|
||||
{
|
||||
struct brel_ma *ma;
|
||||
|
||||
ma = brel->priv_data;
|
||||
if ((old > ma->max_block) || (new > ma->max_block))
|
||||
return EXT2_ET_INVALID_ARGUMENT;
|
||||
if (ma->entries[(unsigned)old].new == 0)
|
||||
return ENOENT;
|
||||
ma->entries[(unsigned)new] = ma->entries[old];
|
||||
ma->entries[(unsigned)old].new = 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static errcode_t bma_delete(ext2_brel brel, blk64_t old)
|
||||
{
|
||||
struct brel_ma *ma;
|
||||
|
||||
ma = brel->priv_data;
|
||||
if (old > ma->max_block)
|
||||
return EXT2_ET_INVALID_ARGUMENT;
|
||||
if (ma->entries[(unsigned)old].new == 0)
|
||||
return ENOENT;
|
||||
ma->entries[(unsigned)old].new = 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static errcode_t bma_free(ext2_brel brel)
|
||||
{
|
||||
struct brel_ma *ma;
|
||||
|
||||
if (!brel)
|
||||
return 0;
|
||||
|
||||
ma = brel->priv_data;
|
||||
|
||||
if (ma) {
|
||||
if (ma->entries)
|
||||
ext2fs_free_mem(&ma->entries);
|
||||
ext2fs_free_mem(&ma);
|
||||
}
|
||||
if (brel->name)
|
||||
ext2fs_free_mem(&brel->name);
|
||||
ext2fs_free_mem(&brel);
|
||||
return 0;
|
||||
}
|
||||
@@ -1,459 +0,0 @@
|
||||
/*
|
||||
* dosio.c -- Disk I/O module for the ext2fs/DOS library.
|
||||
*
|
||||
* Copyright (c) 1997 by Theodore Ts'o.
|
||||
*
|
||||
* Copyright (c) 1997 Mark Habersack
|
||||
*
|
||||
* %Begin-Header%
|
||||
* This file may be redistributed under the terms of the GNU Library
|
||||
* General Public License, version 2.
|
||||
* %End-Header%
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
#include <stdio.h>
|
||||
#include <bios.h>
|
||||
#include <string.h>
|
||||
#include <ctype.h>
|
||||
#include <io.h>
|
||||
#ifdef HAVE_ERRNO_H
|
||||
#include <errno.h>
|
||||
#endif
|
||||
|
||||
#include <ext2fs/ext2_types.h>
|
||||
#include "utils.h"
|
||||
#include "dosio.h"
|
||||
#include "et/com_err.h"
|
||||
#include "ext2_err.h"
|
||||
#include "ext2fs/io.h"
|
||||
|
||||
/*
|
||||
* Some helper macros
|
||||
*/
|
||||
#define LINUX_EXT2FS 0x83
|
||||
#define LINUX_SWAP 0x82
|
||||
#define WRITE_ERR(_msg_) write(2, _msg_, strlen(_msg_))
|
||||
#define WRITE_ERR_S(_msg_) write(2, _msg_, sizeof(_msg_))
|
||||
|
||||
/*
|
||||
* Exported variables
|
||||
*/
|
||||
unsigned long _dio_error;
|
||||
unsigned long _dio_hw_error;
|
||||
|
||||
/*
|
||||
* Array of all opened partitions
|
||||
*/
|
||||
static PARTITION **partitions = NULL;
|
||||
static unsigned short npart = 0; /* Number of mapped partitions */
|
||||
static PARTITION *active = NULL;
|
||||
|
||||
/*
|
||||
* I/O Manager routine prototypes
|
||||
*/
|
||||
static errcode_t dos_open(const char *dev, int flags, io_channel *channel);
|
||||
static errcode_t dos_close(io_channel channel);
|
||||
static errcode_t dos_set_blksize(io_channel channel, int blksize);
|
||||
static errcode_t dos_read_blk(io_channel channel, unsigned long block,
|
||||
int count, void *buf);
|
||||
static errcode_t dos_write_blk(io_channel channel, unsigned long block,
|
||||
int count, const void *buf);
|
||||
static errcode_t dos_flush(io_channel channel);
|
||||
|
||||
static struct struct_io_manager struct_dos_manager = {
|
||||
.magic = EXT2_ET_MAGIC_IO_MANAGER,
|
||||
.name = "DOS I/O Manager",
|
||||
.open = dos_open,
|
||||
.close = dos_close,
|
||||
.set_blksize = dos_set_blksize,
|
||||
.read_blk = dos_read_blk,
|
||||
.write_blk = dos_write_blk,
|
||||
.flush = dos_flush
|
||||
};
|
||||
|
||||
io_manager dos_io_manager = &struct_dos_manager;
|
||||
|
||||
/*
|
||||
* Macro taken from unix_io.c
|
||||
*/
|
||||
/*
|
||||
* For checking structure magic numbers...
|
||||
*/
|
||||
|
||||
#define EXT2_CHECK_MAGIC(struct, code) \
|
||||
if ((struct)->magic != (code)) return (code)
|
||||
|
||||
/*
|
||||
* Calculates a CHS address of a sector from its LBA
|
||||
* offset for the given partition.
|
||||
*/
|
||||
static void lba2chs(unsigned long lba_addr, CHS *chs, PARTITION *part)
|
||||
{
|
||||
unsigned long abss;
|
||||
|
||||
chs->offset = lba_addr & 0x000001FF;
|
||||
abss = (lba_addr >> 9) + part->start;
|
||||
chs->cyl = abss / (part->sects * part->heads);
|
||||
chs->head = (abss / part->sects) % part->heads;
|
||||
chs->sector = (abss % part->sects) + 1;
|
||||
}
|
||||
|
||||
#ifdef __TURBOC__
|
||||
#pragma argsused
|
||||
#endif
|
||||
/*
|
||||
* Scans the passed partition table looking for *pno partition
|
||||
* that has LINUX_EXT2FS type.
|
||||
*
|
||||
* TODO:
|
||||
* For partition numbers >5 Linux uses DOS extended partitions -
|
||||
* dive into them an return an appropriate entry. Also dive into
|
||||
* extended partitions when scanning for a first Linux/ext2fs.
|
||||
*/
|
||||
static PTABLE_ENTRY *scan_partition_table(PTABLE_ENTRY *pentry,
|
||||
unsigned short phys,
|
||||
unsigned char *pno)
|
||||
{
|
||||
unsigned i;
|
||||
|
||||
if(*pno != 0xFF && *pno >= 5)
|
||||
return NULL; /* We don't support extended partitions for now */
|
||||
|
||||
if(*pno != 0xFF)
|
||||
{
|
||||
if(pentry[*pno].type == LINUX_EXT2FS)
|
||||
return &pentry[*pno];
|
||||
else
|
||||
{
|
||||
if(!pentry[*pno].type)
|
||||
*pno = 0xFE;
|
||||
else if(pentry[*pno].type == LINUX_SWAP)
|
||||
*pno = 0xFD;
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
for(i = 0; i < 4; i++)
|
||||
if(pentry[i].type == LINUX_EXT2FS)
|
||||
{
|
||||
*pno = i;
|
||||
return &pentry[i];
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/*
|
||||
* Allocate libext2fs structures associated with I/O manager
|
||||
*/
|
||||
static io_channel alloc_io_channel(PARTITION *part)
|
||||
{
|
||||
io_channel ioch;
|
||||
|
||||
ioch = (io_channel)malloc(sizeof(struct struct_io_channel));
|
||||
if (!ioch)
|
||||
return NULL;
|
||||
memset(ioch, 0, sizeof(struct struct_io_channel));
|
||||
ioch->magic = EXT2_ET_MAGIC_IO_CHANNEL;
|
||||
ioch->manager = dos_io_manager;
|
||||
ioch->name = (char *)malloc(strlen(part->dev)+1);
|
||||
if (!ioch->name) {
|
||||
free(ioch);
|
||||
return NULL;
|
||||
}
|
||||
strcpy(ioch->name, part->dev);
|
||||
ioch->private_data = part;
|
||||
ioch->block_size = 1024; /* The smallest ext2fs block size */
|
||||
ioch->read_error = 0;
|
||||
ioch->write_error = 0;
|
||||
|
||||
return ioch;
|
||||
}
|
||||
|
||||
#ifdef __TURBOC__
|
||||
#pragma argsused
|
||||
#endif
|
||||
/*
|
||||
* Open the 'name' partition, initialize all information structures
|
||||
* we need to keep and create libext2fs I/O manager.
|
||||
*/
|
||||
static errcode_t dos_open(const char *dev, int flags, io_channel *channel)
|
||||
{
|
||||
unsigned char *tmp, sec[512];
|
||||
PARTITION *part;
|
||||
PTABLE_ENTRY *pent;
|
||||
PARTITION **newparts;
|
||||
|
||||
if(!dev)
|
||||
{
|
||||
_dio_error = ERR_BADDEV;
|
||||
return EXT2_ET_BAD_DEVICE_NAME;
|
||||
}
|
||||
|
||||
/*
|
||||
* First check whether the dev name is OK
|
||||
*/
|
||||
tmp = (unsigned char*)strrchr(dev, '/');
|
||||
if(!tmp)
|
||||
{
|
||||
_dio_error = ERR_BADDEV;
|
||||
return EXT2_ET_BAD_DEVICE_NAME;
|
||||
}
|
||||
*tmp = 0;
|
||||
if(strcmp(dev, "/dev"))
|
||||
{
|
||||
_dio_error = ERR_BADDEV;
|
||||
return EXT2_ET_BAD_DEVICE_NAME;
|
||||
}
|
||||
*tmp++ = '/';
|
||||
|
||||
/*
|
||||
* Check whether the partition data is already in cache
|
||||
*/
|
||||
|
||||
part = (PARTITION*)malloc(sizeof(PARTITION));
|
||||
if (!part)
|
||||
return ENOMEM;
|
||||
{
|
||||
int i = 0;
|
||||
|
||||
for(;i < npart; i++)
|
||||
if(!strcmp(partitions[i]->dev, dev))
|
||||
{
|
||||
/* Found it! Make it the active one */
|
||||
active = partitions[i];
|
||||
*channel = alloc_io_channel(active);
|
||||
if (!*channel)
|
||||
return ENOMEM;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Drive number & optionally partn number
|
||||
*/
|
||||
switch(tmp[0])
|
||||
{
|
||||
case 'h':
|
||||
case 's':
|
||||
part->phys = 0x80;
|
||||
part->phys += toupper(tmp[2]) - 'A';
|
||||
/*
|
||||
* Do we have the partition number?
|
||||
*/
|
||||
if(tmp[3])
|
||||
part->pno = isdigit((int)tmp[3]) ? tmp[3] - '0' - 1: 0;
|
||||
else
|
||||
part->pno = 0xFF;
|
||||
break;
|
||||
|
||||
case 'f':
|
||||
if(tmp[2])
|
||||
part->phys = isdigit((int)tmp[2]) ? tmp[2] - '0' : 0;
|
||||
else
|
||||
part->phys = 0x00; /* We'll assume /dev/fd0 */
|
||||
break;
|
||||
|
||||
default:
|
||||
_dio_error = ERR_BADDEV;
|
||||
return ENODEV;
|
||||
}
|
||||
|
||||
if(part->phys < 0x80)
|
||||
{
|
||||
/* We don't support floppies for now */
|
||||
_dio_error = ERR_NOTSUPP;
|
||||
return EINVAL;
|
||||
}
|
||||
|
||||
part->dev = strdup(dev);
|
||||
|
||||
/*
|
||||
* Get drive's geometry
|
||||
*/
|
||||
_dio_hw_error = biosdisk(DISK_GET_GEOMETRY,
|
||||
part->phys,
|
||||
0, /* head */
|
||||
0, /* cylinder */
|
||||
1, /* sector */
|
||||
1, /* just one sector */
|
||||
sec);
|
||||
|
||||
if(!HW_OK())
|
||||
{
|
||||
_dio_error = ERR_HARDWARE;
|
||||
free(part->dev);
|
||||
free(part);
|
||||
return EFAULT;
|
||||
}
|
||||
|
||||
/*
|
||||
* Calculate the geometry
|
||||
*/
|
||||
part->cyls = (unsigned short)(((sec[0] >> 6) << 8) + sec[1] + 1);
|
||||
part->heads = sec[3] + 1;
|
||||
part->sects = sec[0] & 0x3F;
|
||||
|
||||
/*
|
||||
* Now that we know all we need, let's look for the partition
|
||||
*/
|
||||
_dio_hw_error = biosdisk(DISK_READ, part->phys, 0, 0, 1, 1, sec);
|
||||
|
||||
if(!HW_OK())
|
||||
{
|
||||
_dio_error = ERR_HARDWARE;
|
||||
free(part->dev);
|
||||
free(part);
|
||||
return EFAULT;
|
||||
}
|
||||
|
||||
pent = (PTABLE_ENTRY*)&sec[0x1BE];
|
||||
pent = scan_partition_table(pent, part->phys, &part->pno);
|
||||
|
||||
if(!pent)
|
||||
{
|
||||
_dio_error = part->pno == 0xFE ? ERR_EMPTYPART :
|
||||
part->pno == 0xFD ? ERR_LINUXSWAP : ERR_NOTEXT2FS;
|
||||
free(part->dev);
|
||||
free(part);
|
||||
return ENODEV;
|
||||
}
|
||||
|
||||
/*
|
||||
* Calculate the remaining figures
|
||||
*/
|
||||
{
|
||||
unsigned long fsec, fhead, fcyl;
|
||||
|
||||
fsec = (unsigned long)(pent->start_sec & 0x3F);
|
||||
fhead = (unsigned long)pent->start_head;
|
||||
fcyl = ((pent->start_sec >> 6) << 8) + pent->start_cyl;
|
||||
part->start = fsec + fhead * part->sects + fcyl *
|
||||
(part->heads * part->sects) - 1;
|
||||
part->len = pent->size;
|
||||
}
|
||||
|
||||
/*
|
||||
* Add the partition to the table
|
||||
*/
|
||||
newparts = (PARTITION**)realloc(partitions, sizeof(PARTITION) * npart);
|
||||
if (!newparts) {
|
||||
free(part);
|
||||
return ENOMEM;
|
||||
}
|
||||
partitions = newparts;
|
||||
partitions[npart++] = active = part;
|
||||
|
||||
/*
|
||||
* Now alloc all libe2fs structures
|
||||
*/
|
||||
*channel = alloc_io_channel(active);
|
||||
if (!*channel)
|
||||
return ENOMEM;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static errcode_t dos_close(io_channel channel)
|
||||
{
|
||||
free(channel->name);
|
||||
free(channel);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static errcode_t dos_set_blksize(io_channel channel, int blksize)
|
||||
{
|
||||
channel->block_size = blksize;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static errcode_t dos_read_blk(io_channel channel, unsigned long block,
|
||||
int count, void *buf)
|
||||
{
|
||||
PARTITION *part;
|
||||
size_t size;
|
||||
ext2_loff_t loc;
|
||||
CHS chs;
|
||||
|
||||
EXT2_CHECK_MAGIC(channel, EXT2_ET_MAGIC_IO_CHANNEL);
|
||||
part = (PARTITION*)channel->private_data;
|
||||
|
||||
size = (size_t)((count < 0) ? -count : count * channel->block_size);
|
||||
loc = (ext2_loff_t) block * channel->block_size;
|
||||
|
||||
lba2chs(loc, &chs, part);
|
||||
/*
|
||||
* Potential bug here:
|
||||
* If DJGPP is used then reads of >18 sectors will fail!
|
||||
* Have to rewrite biosdisk.
|
||||
*/
|
||||
_dio_hw_error = biosdisk(DISK_READ,
|
||||
part->phys,
|
||||
chs.head,
|
||||
chs.cyl,
|
||||
chs.sector,
|
||||
size < 512 ? 1 : size/512,
|
||||
buf);
|
||||
|
||||
if(!HW_OK())
|
||||
{
|
||||
_dio_error = ERR_HARDWARE;
|
||||
return EFAULT;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static errcode_t dos_write_blk(io_channel channel, unsigned long block,
|
||||
int count, const void *buf)
|
||||
{
|
||||
PARTITION *part;
|
||||
size_t size;
|
||||
ext2_loff_t loc;
|
||||
CHS chs;
|
||||
|
||||
EXT2_CHECK_MAGIC(channel, EXT2_ET_MAGIC_IO_CHANNEL);
|
||||
part = (PARTITION*)channel->private_data;
|
||||
|
||||
if(count == 1)
|
||||
size = (size_t)channel->block_size;
|
||||
else
|
||||
{
|
||||
if (count < 0)
|
||||
size = (size_t)-count;
|
||||
else
|
||||
size = (size_t)(count * channel->block_size);
|
||||
}
|
||||
|
||||
loc = (ext2_loff_t)block * channel->block_size;
|
||||
lba2chs(loc, &chs, part);
|
||||
_dio_hw_error = biosdisk(DISK_WRITE,
|
||||
part->phys,
|
||||
chs.head,
|
||||
chs.cyl,
|
||||
chs.sector,
|
||||
size < 512 ? 1 : size/512,
|
||||
(void*)buf);
|
||||
|
||||
if(!HW_OK())
|
||||
{
|
||||
_dio_error = ERR_HARDWARE;
|
||||
return EFAULT;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
#ifdef __TURBOC__
|
||||
#pragma argsused
|
||||
#endif
|
||||
static errcode_t dos_flush(io_channel channel)
|
||||
{
|
||||
/*
|
||||
* No buffers, no flush...
|
||||
*/
|
||||
return 0;
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -1,621 +0,0 @@
|
||||
/*
|
||||
Unix SMB/CIFS implementation.
|
||||
Samba database functions
|
||||
Copyright (C) Andrew Tridgell 1999-2000
|
||||
Copyright (C) Paul `Rusty' Russell 2000
|
||||
Copyright (C) Jeremy Allison 2000
|
||||
Copyright (C) Andrew Esh 2001
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
#include <errno.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <fcntl.h>
|
||||
#include <unistd.h>
|
||||
#include <string.h>
|
||||
#include <fcntl.h>
|
||||
#include <time.h>
|
||||
#include <sys/mman.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/time.h>
|
||||
#include <ctype.h>
|
||||
#include <signal.h>
|
||||
#include <stdarg.h>
|
||||
|
||||
#include "tdb.h"
|
||||
|
||||
static int do_command(void);
|
||||
const char *cmdname;
|
||||
char *arg1, *arg2;
|
||||
size_t arg1len, arg2len;
|
||||
int bIterate = 0;
|
||||
char *line;
|
||||
TDB_DATA iterate_kbuf;
|
||||
char cmdline[1024];
|
||||
|
||||
enum commands {
|
||||
CMD_CREATE_TDB,
|
||||
CMD_OPEN_TDB,
|
||||
CMD_ERASE,
|
||||
CMD_DUMP,
|
||||
CMD_INSERT,
|
||||
CMD_MOVE,
|
||||
CMD_STORE,
|
||||
CMD_SHOW,
|
||||
CMD_KEYS,
|
||||
CMD_HEXKEYS,
|
||||
CMD_DELETE,
|
||||
CMD_LIST_HASH_FREE,
|
||||
CMD_LIST_FREE,
|
||||
CMD_INFO,
|
||||
CMD_FIRST,
|
||||
CMD_NEXT,
|
||||
CMD_SYSTEM,
|
||||
CMD_QUIT,
|
||||
CMD_HELP
|
||||
};
|
||||
|
||||
typedef struct {
|
||||
const char *name;
|
||||
enum commands cmd;
|
||||
} COMMAND_TABLE;
|
||||
|
||||
COMMAND_TABLE cmd_table[] = {
|
||||
{"create", CMD_CREATE_TDB},
|
||||
{"open", CMD_OPEN_TDB},
|
||||
{"erase", CMD_ERASE},
|
||||
{"dump", CMD_DUMP},
|
||||
{"insert", CMD_INSERT},
|
||||
{"move", CMD_MOVE},
|
||||
{"store", CMD_STORE},
|
||||
{"show", CMD_SHOW},
|
||||
{"keys", CMD_KEYS},
|
||||
{"hexkeys", CMD_HEXKEYS},
|
||||
{"delete", CMD_DELETE},
|
||||
{"list", CMD_LIST_HASH_FREE},
|
||||
{"free", CMD_LIST_FREE},
|
||||
{"info", CMD_INFO},
|
||||
{"first", CMD_FIRST},
|
||||
{"1", CMD_FIRST},
|
||||
{"next", CMD_NEXT},
|
||||
{"n", CMD_NEXT},
|
||||
{"quit", CMD_QUIT},
|
||||
{"q", CMD_QUIT},
|
||||
{"!", CMD_SYSTEM},
|
||||
{NULL, CMD_HELP}
|
||||
};
|
||||
|
||||
/* a tdb tool for manipulating a tdb database */
|
||||
|
||||
static TDB_CONTEXT *tdb;
|
||||
|
||||
static int print_rec(TDB_CONTEXT *the_tdb, TDB_DATA key, TDB_DATA dbuf, void *state);
|
||||
static int print_key(TDB_CONTEXT *the_tdb, TDB_DATA key, TDB_DATA dbuf, void *state);
|
||||
static int print_hexkey(TDB_CONTEXT *the_tdb, TDB_DATA key, TDB_DATA dbuf, void *state);
|
||||
|
||||
static void print_asc(const char *buf,int len)
|
||||
{
|
||||
int i;
|
||||
|
||||
/* We're probably printing ASCII strings so don't try to display
|
||||
the trailing NULL character. */
|
||||
|
||||
if (buf[len - 1] == 0)
|
||||
len--;
|
||||
|
||||
for (i=0;i<len;i++)
|
||||
printf("%c",isprint(buf[i])?buf[i]:'.');
|
||||
}
|
||||
|
||||
static void print_data(const char *buf,int len)
|
||||
{
|
||||
int i=0;
|
||||
if (len<=0) return;
|
||||
printf("[%03X] ",i);
|
||||
for (i=0;i<len;) {
|
||||
printf("%02X ",(int)buf[i]);
|
||||
i++;
|
||||
if (i%8 == 0) printf(" ");
|
||||
if (i%16 == 0) {
|
||||
print_asc(&buf[i-16],8); printf(" ");
|
||||
print_asc(&buf[i-8],8); printf("\n");
|
||||
if (i<len) printf("[%03X] ",i);
|
||||
}
|
||||
}
|
||||
if (i%16) {
|
||||
int n;
|
||||
|
||||
n = 16 - (i%16);
|
||||
printf(" ");
|
||||
if (n>8) printf(" ");
|
||||
while (n--) printf(" ");
|
||||
|
||||
n = i%16;
|
||||
if (n > 8) n = 8;
|
||||
print_asc(&buf[i-(i%16)],n); printf(" ");
|
||||
n = (i%16) - n;
|
||||
if (n>0) print_asc(&buf[i-n],n);
|
||||
printf("\n");
|
||||
}
|
||||
}
|
||||
|
||||
static void help(void)
|
||||
{
|
||||
printf("\n"
|
||||
"tdbtool: \n"
|
||||
" create dbname : create a database\n"
|
||||
" open dbname : open an existing database\n"
|
||||
" erase : erase the database\n"
|
||||
" dump : dump the database as strings\n"
|
||||
" keys : dump the database keys as strings\n"
|
||||
" hexkeys : dump the database keys as hex values\n"
|
||||
" info : print summary info about the database\n"
|
||||
" insert key data : insert a record\n"
|
||||
" move key file : move a record to a destination tdb\n"
|
||||
" store key data : store a record (replace)\n"
|
||||
" show key : show a record by key\n"
|
||||
" delete key : delete a record by key\n"
|
||||
" list : print the database hash table and freelist\n"
|
||||
" free : print the database freelist\n"
|
||||
" ! command : execute system command\n"
|
||||
" 1 | first : print the first record\n"
|
||||
" n | next : print the next record\n"
|
||||
" q | quit : terminate\n"
|
||||
" \\n : repeat 'next' command\n"
|
||||
"\n");
|
||||
}
|
||||
|
||||
static void terror(const char *why)
|
||||
{
|
||||
printf("%s\n", why);
|
||||
}
|
||||
|
||||
static void create_tdb(const char *tdbname)
|
||||
{
|
||||
if (tdb) tdb_close(tdb);
|
||||
tdb = tdb_open(tdbname, 0, TDB_CLEAR_IF_FIRST,
|
||||
O_RDWR | O_CREAT | O_TRUNC, 0600);
|
||||
if (!tdb) {
|
||||
printf("Could not create %s: %s\n", tdbname, strerror(errno));
|
||||
}
|
||||
}
|
||||
|
||||
static void open_tdb(const char *tdbname)
|
||||
{
|
||||
if (tdb) tdb_close(tdb);
|
||||
tdb = tdb_open(tdbname, 0, 0, O_RDWR, 0600);
|
||||
if (!tdb) {
|
||||
printf("Could not open %s: %s\n", tdbname, strerror(errno));
|
||||
}
|
||||
}
|
||||
|
||||
static void insert_tdb(char *keyname, size_t keylen, char* data, size_t datalen)
|
||||
{
|
||||
TDB_DATA key, dbuf;
|
||||
|
||||
if ((keyname == NULL) || (keylen == 0)) {
|
||||
terror("need key");
|
||||
return;
|
||||
}
|
||||
|
||||
key.dptr = (unsigned char *)keyname;
|
||||
key.dsize = keylen;
|
||||
dbuf.dptr = (unsigned char *)data;
|
||||
dbuf.dsize = datalen;
|
||||
|
||||
if (tdb_store(tdb, key, dbuf, TDB_INSERT) == -1) {
|
||||
terror("insert failed");
|
||||
}
|
||||
}
|
||||
|
||||
static void store_tdb(char *keyname, size_t keylen, char* data, size_t datalen)
|
||||
{
|
||||
TDB_DATA key, dbuf;
|
||||
|
||||
if ((keyname == NULL) || (keylen == 0)) {
|
||||
terror("need key");
|
||||
return;
|
||||
}
|
||||
|
||||
if ((data == NULL) || (datalen == 0)) {
|
||||
terror("need data");
|
||||
return;
|
||||
}
|
||||
|
||||
key.dptr = (unsigned char *)keyname;
|
||||
key.dsize = keylen;
|
||||
dbuf.dptr = (unsigned char *)data;
|
||||
dbuf.dsize = datalen;
|
||||
|
||||
printf("Storing key:\n");
|
||||
print_rec(tdb, key, dbuf, NULL);
|
||||
|
||||
if (tdb_store(tdb, key, dbuf, TDB_REPLACE) == -1) {
|
||||
terror("store failed");
|
||||
}
|
||||
}
|
||||
|
||||
static void show_tdb(char *keyname, size_t keylen)
|
||||
{
|
||||
TDB_DATA key, dbuf;
|
||||
|
||||
if ((keyname == NULL) || (keylen == 0)) {
|
||||
terror("need key");
|
||||
return;
|
||||
}
|
||||
|
||||
key.dptr = (unsigned char *)keyname;
|
||||
key.dsize = keylen;
|
||||
|
||||
dbuf = tdb_fetch(tdb, key);
|
||||
if (!dbuf.dptr) {
|
||||
terror("fetch failed");
|
||||
return;
|
||||
}
|
||||
|
||||
print_rec(tdb, key, dbuf, NULL);
|
||||
|
||||
free( dbuf.dptr );
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
static void delete_tdb(char *keyname, size_t keylen)
|
||||
{
|
||||
TDB_DATA key;
|
||||
|
||||
if ((keyname == NULL) || (keylen == 0)) {
|
||||
terror("need key");
|
||||
return;
|
||||
}
|
||||
|
||||
key.dptr = (unsigned char *)keyname;
|
||||
key.dsize = keylen;
|
||||
|
||||
if (tdb_delete(tdb, key) != 0) {
|
||||
terror("delete failed");
|
||||
}
|
||||
}
|
||||
|
||||
static void move_rec(char *keyname, size_t keylen, char* tdbname)
|
||||
{
|
||||
TDB_DATA key, dbuf;
|
||||
TDB_CONTEXT *dst_tdb;
|
||||
|
||||
if ((keyname == NULL) || (keylen == 0)) {
|
||||
terror("need key");
|
||||
return;
|
||||
}
|
||||
|
||||
if ( !tdbname ) {
|
||||
terror("need destination tdb name");
|
||||
return;
|
||||
}
|
||||
|
||||
key.dptr = (unsigned char *)keyname;
|
||||
key.dsize = keylen;
|
||||
|
||||
dbuf = tdb_fetch(tdb, key);
|
||||
if (!dbuf.dptr) {
|
||||
terror("fetch failed");
|
||||
return;
|
||||
}
|
||||
|
||||
print_rec(tdb, key, dbuf, NULL);
|
||||
|
||||
dst_tdb = tdb_open(tdbname, 0, 0, O_RDWR, 0600);
|
||||
if ( !dst_tdb ) {
|
||||
terror("unable to open destination tdb");
|
||||
return;
|
||||
}
|
||||
|
||||
if ( tdb_store( dst_tdb, key, dbuf, TDB_REPLACE ) == -1 ) {
|
||||
terror("failed to move record");
|
||||
}
|
||||
else
|
||||
printf("record moved\n");
|
||||
|
||||
tdb_close( dst_tdb );
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
static int print_rec(TDB_CONTEXT *the_tdb, TDB_DATA key, TDB_DATA dbuf, void *state)
|
||||
{
|
||||
printf("\nkey %d bytes\n", (int)key.dsize);
|
||||
print_asc((const char *)key.dptr, key.dsize);
|
||||
printf("\ndata %d bytes\n", (int)dbuf.dsize);
|
||||
print_data((const char *)dbuf.dptr, dbuf.dsize);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int print_key(TDB_CONTEXT *the_tdb, TDB_DATA key, TDB_DATA dbuf, void *state)
|
||||
{
|
||||
printf("key %d bytes: ", (int)key.dsize);
|
||||
print_asc((const char *)key.dptr, key.dsize);
|
||||
printf("\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int print_hexkey(TDB_CONTEXT *the_tdb, TDB_DATA key, TDB_DATA dbuf, void *state)
|
||||
{
|
||||
printf("key %d bytes\n", (int)key.dsize);
|
||||
print_data((const char *)key.dptr, key.dsize);
|
||||
printf("\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int total_bytes;
|
||||
|
||||
static int traverse_fn(TDB_CONTEXT *the_tdb, TDB_DATA key, TDB_DATA dbuf, void *state)
|
||||
{
|
||||
total_bytes += dbuf.dsize;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void info_tdb(void)
|
||||
{
|
||||
int count;
|
||||
total_bytes = 0;
|
||||
if ((count = tdb_traverse(tdb, traverse_fn, NULL)) == -1)
|
||||
printf("Error = %s\n", tdb_errorstr(tdb));
|
||||
else
|
||||
printf("%d records totalling %d bytes\n", count, total_bytes);
|
||||
}
|
||||
|
||||
static char *tdb_getline(const char *prompt)
|
||||
{
|
||||
static char thisline[1024];
|
||||
char *p;
|
||||
fputs(prompt, stdout);
|
||||
thisline[0] = 0;
|
||||
p = fgets(thisline, sizeof(thisline)-1, stdin);
|
||||
if (p) p = strchr(p, '\n');
|
||||
if (p) *p = 0;
|
||||
return p?thisline:NULL;
|
||||
}
|
||||
|
||||
static int do_delete_fn(TDB_CONTEXT *the_tdb, TDB_DATA key, TDB_DATA dbuf,
|
||||
void *state)
|
||||
{
|
||||
return tdb_delete(the_tdb, key);
|
||||
}
|
||||
|
||||
static void first_record(TDB_CONTEXT *the_tdb, TDB_DATA *pkey)
|
||||
{
|
||||
TDB_DATA dbuf;
|
||||
*pkey = tdb_firstkey(the_tdb);
|
||||
|
||||
dbuf = tdb_fetch(the_tdb, *pkey);
|
||||
if (!dbuf.dptr) terror("fetch failed");
|
||||
else {
|
||||
print_rec(the_tdb, *pkey, dbuf, NULL);
|
||||
}
|
||||
}
|
||||
|
||||
static void next_record(TDB_CONTEXT *the_tdb, TDB_DATA *pkey)
|
||||
{
|
||||
TDB_DATA dbuf;
|
||||
*pkey = tdb_nextkey(the_tdb, *pkey);
|
||||
|
||||
dbuf = tdb_fetch(the_tdb, *pkey);
|
||||
if (!dbuf.dptr)
|
||||
terror("fetch failed");
|
||||
else
|
||||
print_rec(the_tdb, *pkey, dbuf, NULL);
|
||||
}
|
||||
|
||||
static int do_command(void)
|
||||
{
|
||||
COMMAND_TABLE *ctp = cmd_table;
|
||||
enum commands mycmd = CMD_HELP;
|
||||
int cmd_len;
|
||||
|
||||
if (cmdname && strlen(cmdname) == 0) {
|
||||
mycmd = CMD_NEXT;
|
||||
} else {
|
||||
while (ctp->name) {
|
||||
cmd_len = strlen(ctp->name);
|
||||
if (strncmp(ctp->name,cmdname,cmd_len) == 0) {
|
||||
mycmd = ctp->cmd;
|
||||
break;
|
||||
}
|
||||
ctp++;
|
||||
}
|
||||
}
|
||||
|
||||
switch (mycmd) {
|
||||
case CMD_CREATE_TDB:
|
||||
bIterate = 0;
|
||||
create_tdb(arg1);
|
||||
return 0;
|
||||
case CMD_OPEN_TDB:
|
||||
bIterate = 0;
|
||||
open_tdb(arg1);
|
||||
return 0;
|
||||
case CMD_SYSTEM:
|
||||
/* Shell command */
|
||||
system(arg1);
|
||||
return 0;
|
||||
case CMD_QUIT:
|
||||
return 1;
|
||||
default:
|
||||
/* all the rest require a open database */
|
||||
if (!tdb) {
|
||||
bIterate = 0;
|
||||
terror("database not open");
|
||||
help();
|
||||
return 0;
|
||||
}
|
||||
switch (mycmd) {
|
||||
case CMD_ERASE:
|
||||
bIterate = 0;
|
||||
tdb_traverse(tdb, do_delete_fn, NULL);
|
||||
return 0;
|
||||
case CMD_DUMP:
|
||||
bIterate = 0;
|
||||
tdb_traverse(tdb, print_rec, NULL);
|
||||
return 0;
|
||||
case CMD_INSERT:
|
||||
bIterate = 0;
|
||||
insert_tdb(arg1, arg1len,arg2,arg2len);
|
||||
return 0;
|
||||
case CMD_MOVE:
|
||||
bIterate = 0;
|
||||
move_rec(arg1,arg1len,arg2);
|
||||
return 0;
|
||||
case CMD_STORE:
|
||||
bIterate = 0;
|
||||
store_tdb(arg1,arg1len,arg2,arg2len);
|
||||
return 0;
|
||||
case CMD_SHOW:
|
||||
bIterate = 0;
|
||||
show_tdb(arg1, arg1len);
|
||||
return 0;
|
||||
case CMD_KEYS:
|
||||
tdb_traverse(tdb, print_key, NULL);
|
||||
return 0;
|
||||
case CMD_HEXKEYS:
|
||||
tdb_traverse(tdb, print_hexkey, NULL);
|
||||
return 0;
|
||||
case CMD_DELETE:
|
||||
bIterate = 0;
|
||||
delete_tdb(arg1,arg1len);
|
||||
return 0;
|
||||
case CMD_LIST_HASH_FREE:
|
||||
tdb_dump_all(tdb);
|
||||
return 0;
|
||||
case CMD_LIST_FREE:
|
||||
tdb_printfreelist(tdb);
|
||||
return 0;
|
||||
case CMD_INFO:
|
||||
info_tdb();
|
||||
return 0;
|
||||
case CMD_FIRST:
|
||||
bIterate = 1;
|
||||
first_record(tdb, &iterate_kbuf);
|
||||
return 0;
|
||||
case CMD_NEXT:
|
||||
if (bIterate)
|
||||
next_record(tdb, &iterate_kbuf);
|
||||
return 0;
|
||||
case CMD_HELP:
|
||||
help();
|
||||
return 0;
|
||||
case CMD_CREATE_TDB:
|
||||
case CMD_OPEN_TDB:
|
||||
case CMD_SYSTEM:
|
||||
case CMD_QUIT:
|
||||
/*
|
||||
* unhandled commands. cases included here to avoid compiler
|
||||
* warnings.
|
||||
*/
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static char *convert_string(char *instring, size_t *sizep)
|
||||
{
|
||||
size_t length = 0;
|
||||
char *outp, *inp;
|
||||
char temp[3];
|
||||
|
||||
|
||||
outp = inp = instring;
|
||||
|
||||
while (*inp) {
|
||||
if (*inp == '\\') {
|
||||
inp++;
|
||||
if (*inp && strchr("0123456789abcdefABCDEF",(int)*inp)) {
|
||||
temp[0] = *inp++;
|
||||
temp[1] = '\0';
|
||||
if (*inp && strchr("0123456789abcdefABCDEF",(int)*inp)) {
|
||||
temp[1] = *inp++;
|
||||
temp[2] = '\0';
|
||||
}
|
||||
*outp++ = (char)strtol((const char *)temp,NULL,16);
|
||||
} else {
|
||||
*outp++ = *inp++;
|
||||
}
|
||||
} else {
|
||||
*outp++ = *inp++;
|
||||
}
|
||||
length++;
|
||||
}
|
||||
*sizep = length;
|
||||
return instring;
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
cmdname = "";
|
||||
arg1 = NULL;
|
||||
arg1len = 0;
|
||||
arg2 = NULL;
|
||||
arg2len = 0;
|
||||
|
||||
if (argv[1]) {
|
||||
cmdname = "open";
|
||||
arg1 = argv[1];
|
||||
do_command();
|
||||
cmdname = "";
|
||||
arg1 = NULL;
|
||||
}
|
||||
|
||||
switch (argc) {
|
||||
case 1:
|
||||
case 2:
|
||||
/* Interactive mode */
|
||||
while ((cmdname = tdb_getline("tdb> "))) {
|
||||
arg2 = arg1 = NULL;
|
||||
if ((arg1 = strchr((const char *)cmdname,' ')) != NULL) {
|
||||
arg1++;
|
||||
arg2 = arg1;
|
||||
while (*arg2) {
|
||||
if (*arg2 == ' ') {
|
||||
*arg2++ = '\0';
|
||||
break;
|
||||
}
|
||||
if ((*arg2++ == '\\') && (*arg2 == ' ')) {
|
||||
arg2++;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (arg1) arg1 = convert_string(arg1,&arg1len);
|
||||
if (arg2) arg2 = convert_string(arg2,&arg2len);
|
||||
if (do_command()) break;
|
||||
}
|
||||
break;
|
||||
case 5:
|
||||
arg2 = convert_string(argv[4],&arg2len);
|
||||
case 4:
|
||||
arg1 = convert_string(argv[3],&arg1len);
|
||||
case 3:
|
||||
cmdname = argv[2];
|
||||
default:
|
||||
do_command();
|
||||
break;
|
||||
}
|
||||
|
||||
if (tdb) tdb_close(tdb);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -1,369 +0,0 @@
|
||||
/*
|
||||
* This testing program makes sure the badblocks implementation works.
|
||||
*
|
||||
* Copyright (C) 1996 by Theodore Ts'o.
|
||||
*
|
||||
* %Begin-Header%
|
||||
* This file may be redistributed under the terms of the GNU Library
|
||||
* General Public License, version 2.
|
||||
* %End-Header%
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#if HAVE_UNISTD_H
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
#include <fcntl.h>
|
||||
#include <time.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/types.h>
|
||||
#if HAVE_ERRNO_H
|
||||
#include <errno.h>
|
||||
#endif
|
||||
|
||||
#include "ext2_fs.h"
|
||||
#include "ext2fs.h"
|
||||
|
||||
#define ADD_BLK 0x0001
|
||||
#define DEL_BLK 0x0002
|
||||
|
||||
blk_t test1[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 0 };
|
||||
blk_t test2[] = { 11, 10, 9, 8, 7, 6, 5, 4, 3, 3, 2, 1, 0 };
|
||||
blk_t test3[] = { 3, 1, 4, 5, 9, 2, 7, 10, 5, 6, 10, 8, 0 };
|
||||
blk_t test4[] = { 20, 50, 12, 17, 13, 2, 66, 23, 56, 0 };
|
||||
blk_t test4a[] = {
|
||||
20, 1,
|
||||
50, 1,
|
||||
3, 0,
|
||||
17, 1,
|
||||
18, 0,
|
||||
16, 0,
|
||||
11, 0,
|
||||
12, 1,
|
||||
13, 1,
|
||||
14, 0,
|
||||
80, 0,
|
||||
45, 0,
|
||||
66, 1,
|
||||
0 };
|
||||
blk_t test5[] = { 31, 20, 17, 51, 23, 1, 56, 57, 0 };
|
||||
blk_t test5a[] = {
|
||||
50, ADD_BLK,
|
||||
51, DEL_BLK,
|
||||
57, DEL_BLK,
|
||||
66, ADD_BLK,
|
||||
31, DEL_BLK,
|
||||
12, ADD_BLK,
|
||||
2, ADD_BLK,
|
||||
13, ADD_BLK,
|
||||
1, DEL_BLK,
|
||||
0
|
||||
};
|
||||
|
||||
|
||||
static int test_fail = 0;
|
||||
static int test_expected_fail = 0;
|
||||
|
||||
static errcode_t create_test_list(blk_t *vec, badblocks_list *ret)
|
||||
{
|
||||
errcode_t retval;
|
||||
badblocks_list bb;
|
||||
int i;
|
||||
|
||||
retval = ext2fs_badblocks_list_create(&bb, 5);
|
||||
if (retval) {
|
||||
com_err("create_test_list", retval, "while creating list");
|
||||
return retval;
|
||||
}
|
||||
for (i=0; vec[i]; i++) {
|
||||
retval = ext2fs_badblocks_list_add(bb, vec[i]);
|
||||
if (retval) {
|
||||
com_err("create_test_list", retval,
|
||||
"while adding test vector %d", i);
|
||||
ext2fs_badblocks_list_free(bb);
|
||||
return retval;
|
||||
}
|
||||
}
|
||||
*ret = bb;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void print_list(badblocks_list bb, int verify)
|
||||
{
|
||||
errcode_t retval;
|
||||
badblocks_iterate iter;
|
||||
blk_t blk;
|
||||
int i, ok;
|
||||
|
||||
retval = ext2fs_badblocks_list_iterate_begin(bb, &iter);
|
||||
if (retval) {
|
||||
com_err("print_list", retval, "while setting up iterator");
|
||||
return;
|
||||
}
|
||||
ok = i = 1;
|
||||
while (ext2fs_badblocks_list_iterate(iter, &blk)) {
|
||||
printf("%u ", blk);
|
||||
if (i++ != blk)
|
||||
ok = 0;
|
||||
}
|
||||
ext2fs_badblocks_list_iterate_end(iter);
|
||||
if (verify) {
|
||||
if (ok)
|
||||
printf("--- OK");
|
||||
else {
|
||||
printf("--- NOT OK");
|
||||
test_fail++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void validate_test_seq(badblocks_list bb, blk_t *vec)
|
||||
{
|
||||
int i, match, ok;
|
||||
|
||||
for (i = 0; vec[i]; i += 2) {
|
||||
match = ext2fs_badblocks_list_test(bb, vec[i]);
|
||||
if (match == vec[i+1])
|
||||
ok = 1;
|
||||
else {
|
||||
ok = 0;
|
||||
test_fail++;
|
||||
}
|
||||
printf("\tblock %u is %s --- %s\n", vec[i],
|
||||
match ? "present" : "absent",
|
||||
ok ? "OK" : "NOT OK");
|
||||
}
|
||||
}
|
||||
|
||||
static void do_test_seq(badblocks_list bb, blk_t *vec)
|
||||
{
|
||||
int i, match;
|
||||
|
||||
for (i = 0; vec[i]; i += 2) {
|
||||
switch (vec[i+1]) {
|
||||
case ADD_BLK:
|
||||
ext2fs_badblocks_list_add(bb, vec[i]);
|
||||
match = ext2fs_badblocks_list_test(bb, vec[i]);
|
||||
printf("Adding block %u --- now %s\n", vec[i],
|
||||
match ? "present" : "absent");
|
||||
if (!match) {
|
||||
printf("FAILURE!\n");
|
||||
test_fail++;
|
||||
}
|
||||
break;
|
||||
case DEL_BLK:
|
||||
ext2fs_badblocks_list_del(bb, vec[i]);
|
||||
match = ext2fs_badblocks_list_test(bb, vec[i]);
|
||||
printf("Removing block %u --- now %s\n", vec[i],
|
||||
ext2fs_badblocks_list_test(bb, vec[i]) ?
|
||||
"present" : "absent");
|
||||
if (match) {
|
||||
printf("FAILURE!\n");
|
||||
test_fail++;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
int file_test(badblocks_list bb)
|
||||
{
|
||||
badblocks_list new_bb = 0;
|
||||
errcode_t retval;
|
||||
FILE *f;
|
||||
|
||||
f = tmpfile();
|
||||
if (!f) {
|
||||
fprintf(stderr, "Error opening temp file: %s\n",
|
||||
error_message(errno));
|
||||
return 1;
|
||||
}
|
||||
retval = ext2fs_write_bb_FILE(bb, 0, f);
|
||||
if (retval) {
|
||||
com_err("file_test", retval, "while writing bad blocks");
|
||||
return 1;
|
||||
}
|
||||
|
||||
rewind(f);
|
||||
retval = ext2fs_read_bb_FILE2(0, f, &new_bb, 0, 0);
|
||||
if (retval) {
|
||||
com_err("file_test", retval, "while reading bad blocks");
|
||||
return 1;
|
||||
}
|
||||
fclose(f);
|
||||
|
||||
if (ext2fs_badblocks_equal(bb, new_bb)) {
|
||||
printf("Block bitmap matched after reading and writing.\n");
|
||||
} else {
|
||||
printf("Block bitmap NOT matched.\n");
|
||||
test_fail++;
|
||||
}
|
||||
ext2fs_badblocks_list_free(new_bb);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void invalid_proc(ext2_filsys fs, blk_t blk)
|
||||
{
|
||||
if (blk == 34500) {
|
||||
printf("Expected invalid block\n");
|
||||
test_expected_fail++;
|
||||
} else {
|
||||
printf("Invalid block #: %u\n", blk);
|
||||
test_fail++;
|
||||
}
|
||||
}
|
||||
|
||||
void file_test_invalid(badblocks_list bb)
|
||||
{
|
||||
badblocks_list new_bb = 0;
|
||||
errcode_t retval;
|
||||
ext2_filsys fs;
|
||||
FILE *f;
|
||||
|
||||
fs = malloc(sizeof(struct struct_ext2_filsys));
|
||||
memset(fs, 0, sizeof(struct struct_ext2_filsys));
|
||||
fs->magic = EXT2_ET_MAGIC_EXT2FS_FILSYS;
|
||||
fs->super = malloc(SUPERBLOCK_SIZE);
|
||||
memset(fs->super, 0, SUPERBLOCK_SIZE);
|
||||
fs->super->s_first_data_block = 1;
|
||||
ext2fs_blocks_count_set(fs->super, 100);
|
||||
|
||||
f = tmpfile();
|
||||
if (!f) {
|
||||
fprintf(stderr, "Error opening temp file: %s\n",
|
||||
error_message(errno));
|
||||
test_fail++;
|
||||
goto out;
|
||||
}
|
||||
retval = ext2fs_write_bb_FILE(bb, 0, f);
|
||||
if (retval) {
|
||||
com_err("file_test", retval, "while writing bad blocks");
|
||||
test_fail++;
|
||||
goto out;
|
||||
}
|
||||
fprintf(f, "34500\n");
|
||||
|
||||
rewind(f);
|
||||
test_expected_fail = 0;
|
||||
retval = ext2fs_read_bb_FILE(fs, f, &new_bb, invalid_proc);
|
||||
if (retval) {
|
||||
com_err("file_test", retval, "while reading bad blocks");
|
||||
test_fail++;
|
||||
goto out;
|
||||
}
|
||||
fclose(f);
|
||||
if (!test_expected_fail) {
|
||||
printf("Expected test failure didn't happen!\n");
|
||||
test_fail++;
|
||||
}
|
||||
|
||||
|
||||
if (ext2fs_badblocks_equal(bb, new_bb)) {
|
||||
printf("Block bitmap matched after reading and writing.\n");
|
||||
} else {
|
||||
printf("Block bitmap NOT matched.\n");
|
||||
test_fail++;
|
||||
}
|
||||
ext2fs_badblocks_list_free(new_bb);
|
||||
out:
|
||||
free(fs->super);
|
||||
free(fs);
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
badblocks_list bb1, bb2, bb3, bb4, bb5;
|
||||
int equal;
|
||||
errcode_t retval;
|
||||
|
||||
add_error_table(&et_ext2_error_table);
|
||||
|
||||
bb1 = bb2 = bb3 = bb4 = bb5 = 0;
|
||||
|
||||
printf("test1: ");
|
||||
retval = create_test_list(test1, &bb1);
|
||||
if (retval == 0)
|
||||
print_list(bb1, 1);
|
||||
printf("\n");
|
||||
|
||||
printf("test2: ");
|
||||
retval = create_test_list(test2, &bb2);
|
||||
if (retval == 0)
|
||||
print_list(bb2, 1);
|
||||
printf("\n");
|
||||
|
||||
printf("test3: ");
|
||||
retval = create_test_list(test3, &bb3);
|
||||
if (retval == 0)
|
||||
print_list(bb3, 1);
|
||||
printf("\n");
|
||||
|
||||
printf("test4: ");
|
||||
retval = create_test_list(test4, &bb4);
|
||||
if (retval == 0) {
|
||||
print_list(bb4, 0);
|
||||
printf("\n");
|
||||
validate_test_seq(bb4, test4a);
|
||||
}
|
||||
printf("\n");
|
||||
|
||||
printf("test5: ");
|
||||
retval = create_test_list(test5, &bb5);
|
||||
if (retval == 0) {
|
||||
print_list(bb5, 0);
|
||||
printf("\n");
|
||||
do_test_seq(bb5, test5a);
|
||||
printf("After test5 sequence: ");
|
||||
print_list(bb5, 0);
|
||||
printf("\n");
|
||||
}
|
||||
printf("\n");
|
||||
|
||||
if (bb1 && bb2 && bb3 && bb4 && bb5) {
|
||||
printf("Comparison tests:\n");
|
||||
equal = ext2fs_badblocks_equal(bb1, bb2);
|
||||
printf("bb1 and bb2 are %sequal.\n", equal ? "" : "NOT ");
|
||||
if (equal)
|
||||
test_fail++;
|
||||
|
||||
equal = ext2fs_badblocks_equal(bb1, bb3);
|
||||
printf("bb1 and bb3 are %sequal.\n", equal ? "" : "NOT ");
|
||||
if (!equal)
|
||||
test_fail++;
|
||||
|
||||
equal = ext2fs_badblocks_equal(bb1, bb4);
|
||||
printf("bb1 and bb4 are %sequal.\n", equal ? "" : "NOT ");
|
||||
if (equal)
|
||||
test_fail++;
|
||||
|
||||
equal = ext2fs_badblocks_equal(bb4, bb5);
|
||||
printf("bb4 and bb5 are %sequal.\n", equal ? "" : "NOT ");
|
||||
if (!equal)
|
||||
test_fail++;
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
file_test(bb4);
|
||||
|
||||
file_test_invalid(bb4);
|
||||
|
||||
if (test_fail == 0)
|
||||
printf("ext2fs library badblocks tests checks out OK!\n");
|
||||
|
||||
if (bb1)
|
||||
ext2fs_badblocks_list_free(bb1);
|
||||
if (bb2)
|
||||
ext2fs_badblocks_list_free(bb2);
|
||||
if (bb3)
|
||||
ext2fs_badblocks_list_free(bb3);
|
||||
if (bb4)
|
||||
ext2fs_badblocks_list_free(bb4);
|
||||
if (bb5)
|
||||
ext2fs_badblocks_list_free(bb5);
|
||||
|
||||
return test_fail;
|
||||
|
||||
}
|
||||
@@ -1,732 +0,0 @@
|
||||
/*
|
||||
* tst_bitmaps.c
|
||||
*
|
||||
* Copyright (C) 2011 Theodore Ts'o.
|
||||
*
|
||||
* %Begin-Header%
|
||||
* This file may be redistributed under the terms of the GNU Library
|
||||
* General Public License, version 2.
|
||||
* %End-Header%
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
#include <unistd.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#ifdef HAVE_GETOPT_H
|
||||
#include <getopt.h>
|
||||
#endif
|
||||
#include <string.h>
|
||||
#include <fcntl.h>
|
||||
#include <time.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/types.h>
|
||||
#include "ss/ss.h"
|
||||
|
||||
#include "ext2_fs.h"
|
||||
#include "ext2fs.h"
|
||||
#include "ext2fsP.h"
|
||||
|
||||
extern ss_request_table tst_bitmaps_cmds;
|
||||
|
||||
static char subsystem_name[] = "tst_bitmaps";
|
||||
static char version[] = "1.0";
|
||||
|
||||
ext2_filsys test_fs;
|
||||
int exit_status = 0;
|
||||
|
||||
static int source_file(const char *cmd_file, int sci_idx)
|
||||
{
|
||||
FILE *f;
|
||||
char buf[256];
|
||||
char *cp;
|
||||
int retval;
|
||||
int noecho;
|
||||
|
||||
if (strcmp(cmd_file, "-") == 0)
|
||||
f = stdin;
|
||||
else {
|
||||
f = fopen(cmd_file, "r");
|
||||
if (!f) {
|
||||
perror(cmd_file);
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
fflush(stdout);
|
||||
fflush(stderr);
|
||||
setbuf(stdout, NULL);
|
||||
setbuf(stderr, NULL);
|
||||
while (!feof(f)) {
|
||||
if (fgets(buf, sizeof(buf), f) == NULL)
|
||||
break;
|
||||
if (buf[0] == '#')
|
||||
continue;
|
||||
noecho = 0;
|
||||
if (buf[0] == '-') {
|
||||
noecho = 1;
|
||||
buf[0] = ' ';
|
||||
}
|
||||
cp = strchr(buf, '\n');
|
||||
if (cp)
|
||||
*cp = 0;
|
||||
cp = strchr(buf, '\r');
|
||||
if (cp)
|
||||
*cp = 0;
|
||||
if (!noecho)
|
||||
printf("%s: %s\n", subsystem_name, buf);
|
||||
retval = ss_execute_line(sci_idx, buf);
|
||||
if (retval) {
|
||||
ss_perror(sci_idx, retval, buf);
|
||||
exit_status++;
|
||||
}
|
||||
}
|
||||
return exit_status;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* This function resets the libc getopt() function, which keeps
|
||||
* internal state. Bad design! Stupid libc API designers! No
|
||||
* biscuit!
|
||||
*
|
||||
* BSD-derived getopt() functions require that optind be reset to 1 in
|
||||
* order to reset getopt() state. This used to be generally accepted
|
||||
* way of resetting getopt(). However, glibc's getopt()
|
||||
* has additional getopt() state beyond optind, and requires that
|
||||
* optind be set zero to reset its state. So the unfortunate state of
|
||||
* affairs is that BSD-derived versions of getopt() misbehave if
|
||||
* optind is set to 0 in order to reset getopt(), and glibc's getopt()
|
||||
* will core dump if optind is set 1 in order to reset getopt().
|
||||
*
|
||||
* More modern versions of BSD require that optreset be set to 1 in
|
||||
* order to reset getopt(). Sigh. Standards, anyone?
|
||||
*
|
||||
* We hide the hair here.
|
||||
*/
|
||||
void reset_getopt(void)
|
||||
{
|
||||
#if defined(__GLIBC__) || defined(__linux__)
|
||||
optind = 0;
|
||||
#else
|
||||
optind = 1;
|
||||
#endif
|
||||
#ifdef HAVE_OPTRESET
|
||||
optreset = 1; /* Makes BSD getopt happy */
|
||||
#endif
|
||||
}
|
||||
|
||||
/*
|
||||
* This function will convert a string to an unsigned long, printing
|
||||
* an error message if it fails, and returning success or failure in err.
|
||||
*/
|
||||
unsigned long parse_ulong(const char *str, const char *cmd,
|
||||
const char *descr, int *err)
|
||||
{
|
||||
char *tmp;
|
||||
unsigned long ret;
|
||||
|
||||
ret = strtoul(str, &tmp, 0);
|
||||
if (*tmp == 0) {
|
||||
if (err)
|
||||
*err = 0;
|
||||
return ret;
|
||||
}
|
||||
com_err(cmd, 0, "Bad %s - %s", descr, str);
|
||||
if (err)
|
||||
*err = 1;
|
||||
else
|
||||
exit(1);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
int check_fs_open(char *name)
|
||||
{
|
||||
if (!test_fs) {
|
||||
com_err(name, 0, "Filesystem not open");
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void setup_filesystem(const char *name,
|
||||
unsigned int blocks, unsigned int inodes,
|
||||
unsigned int type, int flags)
|
||||
{
|
||||
struct ext2_super_block param;
|
||||
errcode_t retval;
|
||||
|
||||
memset(¶m, 0, sizeof(param));
|
||||
ext2fs_blocks_count_set(¶m, blocks);
|
||||
param.s_inodes_count = inodes;
|
||||
|
||||
retval = ext2fs_initialize("test fs", flags, ¶m,
|
||||
test_io_manager, &test_fs);
|
||||
|
||||
if (retval) {
|
||||
com_err(name, retval, "while initializing filesystem");
|
||||
return;
|
||||
}
|
||||
test_fs->default_bitmap_type = type;
|
||||
ext2fs_free_block_bitmap(test_fs->block_map);
|
||||
test_fs->block_map = 0;
|
||||
ext2fs_free_inode_bitmap(test_fs->inode_map);
|
||||
test_fs->inode_map = 0;
|
||||
retval = ext2fs_allocate_block_bitmap(test_fs, "block bitmap",
|
||||
&test_fs->block_map);
|
||||
if (retval) {
|
||||
com_err(name, retval, "while allocating block bitmap");
|
||||
goto errout;
|
||||
}
|
||||
retval = ext2fs_allocate_inode_bitmap(test_fs, "inode bitmap",
|
||||
&test_fs->inode_map);
|
||||
if (retval) {
|
||||
com_err(name, retval, "while allocating inode bitmap");
|
||||
goto errout;
|
||||
}
|
||||
return;
|
||||
|
||||
errout:
|
||||
ext2fs_close_free(&test_fs);
|
||||
}
|
||||
|
||||
void setup_cmd(int argc, char **argv, int sci_idx EXT2FS_ATTR((unused)),
|
||||
void *infop EXT2FS_ATTR((unused)))
|
||||
{
|
||||
int c, err;
|
||||
unsigned int blocks = 128;
|
||||
unsigned int inodes = 0;
|
||||
unsigned int type = EXT2FS_BMAP64_BITARRAY;
|
||||
int flags = EXT2_FLAG_64BITS;
|
||||
|
||||
if (test_fs)
|
||||
ext2fs_close_free(&test_fs);
|
||||
|
||||
reset_getopt();
|
||||
while ((c = getopt(argc, argv, "b:i:lt:")) != EOF) {
|
||||
switch (c) {
|
||||
case 'b':
|
||||
blocks = parse_ulong(optarg, argv[0],
|
||||
"number of blocks", &err);
|
||||
if (err)
|
||||
return;
|
||||
break;
|
||||
case 'i':
|
||||
inodes = parse_ulong(optarg, argv[0],
|
||||
"number of blocks", &err);
|
||||
if (err)
|
||||
return;
|
||||
break;
|
||||
case 'l': /* Legacy bitmaps */
|
||||
flags = 0;
|
||||
break;
|
||||
case 't':
|
||||
type = parse_ulong(optarg, argv[0],
|
||||
"bitmap backend type", &err);
|
||||
if (err)
|
||||
return;
|
||||
break;
|
||||
default:
|
||||
fprintf(stderr, "%s: usage: setup [-b blocks] "
|
||||
"[-i inodes] [-t type]\n", argv[0]);
|
||||
return;
|
||||
}
|
||||
}
|
||||
setup_filesystem(argv[0], blocks, inodes, type, flags);
|
||||
}
|
||||
|
||||
void close_cmd(int argc, char **argv, int sci_idx EXT2FS_ATTR((unused)),
|
||||
void *infop EXT2FS_ATTR((unused)))
|
||||
{
|
||||
if (check_fs_open(argv[0]))
|
||||
return;
|
||||
|
||||
ext2fs_close_free(&test_fs);
|
||||
}
|
||||
|
||||
|
||||
void dump_bitmap(ext2fs_generic_bitmap bmap, unsigned int start, unsigned num)
|
||||
{
|
||||
unsigned char *buf;
|
||||
errcode_t retval;
|
||||
int i, len = (num - start + 7) / 8;
|
||||
|
||||
buf = malloc(len);
|
||||
if (!buf) {
|
||||
com_err("dump_bitmap", 0, "couldn't allocate buffer");
|
||||
return;
|
||||
}
|
||||
memset(buf, 0, len);
|
||||
retval = ext2fs_get_generic_bmap_range(bmap, (__u64) start, num, buf);
|
||||
if (retval) {
|
||||
com_err("dump_bitmap", retval,
|
||||
"while calling ext2fs_generic_bmap_range");
|
||||
free(buf);
|
||||
return;
|
||||
}
|
||||
for (i=0; i < len; i++)
|
||||
printf("%02x", buf[i]);
|
||||
printf("\n");
|
||||
printf("bits set: %u\n", ext2fs_bitcount(buf, len));
|
||||
free(buf);
|
||||
}
|
||||
|
||||
void dump_inode_bitmap_cmd(int argc, char **argv,
|
||||
int sci_idx EXT2FS_ATTR((unused)),
|
||||
void *infop EXT2FS_ATTR((unused)))
|
||||
{
|
||||
if (check_fs_open(argv[0]))
|
||||
return;
|
||||
|
||||
printf("inode bitmap: ");
|
||||
dump_bitmap(test_fs->inode_map, 1, test_fs->super->s_inodes_count);
|
||||
}
|
||||
|
||||
void dump_block_bitmap_cmd(int argc, char **argv,
|
||||
int sci_idx EXT2FS_ATTR((unused)),
|
||||
void *infop EXT2FS_ATTR((unused)))
|
||||
{
|
||||
if (check_fs_open(argv[0]))
|
||||
return;
|
||||
|
||||
printf("block bitmap: ");
|
||||
dump_bitmap(test_fs->block_map, test_fs->super->s_first_data_block,
|
||||
test_fs->super->s_blocks_count);
|
||||
}
|
||||
|
||||
void do_setb(int argc, char *argv[], int sci_idx EXT2FS_ATTR((unused)),
|
||||
void *infop EXT2FS_ATTR((unused)))
|
||||
{
|
||||
unsigned int block, num;
|
||||
int err;
|
||||
int test_result, op_result;
|
||||
|
||||
if (check_fs_open(argv[0]))
|
||||
return;
|
||||
|
||||
if (argc != 2 && argc != 3) {
|
||||
com_err(argv[0], 0, "Usage: setb <block> [num]");
|
||||
return;
|
||||
}
|
||||
|
||||
block = parse_ulong(argv[1], argv[0], "block", &err);
|
||||
if (err)
|
||||
return;
|
||||
|
||||
if (argc == 3) {
|
||||
num = parse_ulong(argv[2], argv[0], "num", &err);
|
||||
if (err)
|
||||
return;
|
||||
|
||||
ext2fs_mark_block_bitmap_range2(test_fs->block_map,
|
||||
block, num);
|
||||
printf("Marking blocks %u to %u\n", block, block + num - 1);
|
||||
return;
|
||||
}
|
||||
|
||||
test_result = ext2fs_test_block_bitmap2(test_fs->block_map, block);
|
||||
op_result = ext2fs_mark_block_bitmap2(test_fs->block_map, block);
|
||||
printf("Setting block %u, was %s before\n", block, op_result ?
|
||||
"set" : "clear");
|
||||
if (!test_result != !op_result)
|
||||
com_err(argv[0], 0, "*ERROR* test_result different! (%d, %d)",
|
||||
test_result, op_result);
|
||||
}
|
||||
|
||||
void do_clearb(int argc, char *argv[], int sci_idx EXT2FS_ATTR((unused)),
|
||||
void *infop EXT2FS_ATTR((unused)))
|
||||
{
|
||||
unsigned int block, num;
|
||||
int err;
|
||||
int test_result, op_result;
|
||||
|
||||
if (check_fs_open(argv[0]))
|
||||
return;
|
||||
|
||||
if (argc != 2 && argc != 3) {
|
||||
com_err(argv[0], 0, "Usage: clearb <block> [num]");
|
||||
return;
|
||||
}
|
||||
|
||||
block = parse_ulong(argv[1], argv[0], "block", &err);
|
||||
if (err)
|
||||
return;
|
||||
|
||||
if (argc == 3) {
|
||||
num = parse_ulong(argv[2], argv[0], "num", &err);
|
||||
if (err)
|
||||
return;
|
||||
|
||||
ext2fs_unmark_block_bitmap_range2(test_fs->block_map,
|
||||
block, num);
|
||||
printf("Clearing blocks %u to %u\n", block, block + num - 1);
|
||||
return;
|
||||
}
|
||||
|
||||
test_result = ext2fs_test_block_bitmap2(test_fs->block_map, block);
|
||||
op_result = ext2fs_unmark_block_bitmap2(test_fs->block_map, block);
|
||||
printf("Clearing block %u, was %s before\n", block, op_result ?
|
||||
"set" : "clear");
|
||||
if (!test_result != !op_result)
|
||||
com_err(argv[0], 0, "*ERROR* test_result different! (%d, %d)",
|
||||
test_result, op_result);
|
||||
}
|
||||
|
||||
void do_testb(int argc, char *argv[], int sci_idx EXT2FS_ATTR((unused)),
|
||||
void *infop EXT2FS_ATTR((unused)))
|
||||
{
|
||||
unsigned int block, num;
|
||||
int err;
|
||||
int test_result;
|
||||
|
||||
if (check_fs_open(argv[0]))
|
||||
return;
|
||||
|
||||
if (argc != 2 && argc != 3) {
|
||||
com_err(argv[0], 0, "Usage: testb <block> [num]");
|
||||
return;
|
||||
}
|
||||
|
||||
block = parse_ulong(argv[1], argv[0], "block", &err);
|
||||
if (err)
|
||||
return;
|
||||
|
||||
if (argc == 3) {
|
||||
num = parse_ulong(argv[2], argv[0], "num", &err);
|
||||
if (err)
|
||||
return;
|
||||
|
||||
test_result =
|
||||
ext2fs_test_block_bitmap_range2(test_fs->block_map,
|
||||
block, num);
|
||||
printf("Blocks %u to %u are %sall clear.\n",
|
||||
block, block + num - 1, test_result ? "" : "NOT ");
|
||||
return;
|
||||
}
|
||||
|
||||
test_result = ext2fs_test_block_bitmap2(test_fs->block_map, block);
|
||||
printf("Block %u is %s\n", block, test_result ? "set" : "clear");
|
||||
}
|
||||
|
||||
void do_ffzb(int argc, char *argv[], int sci_idx EXT2FS_ATTR((unused)),
|
||||
void *infop EXT2FS_ATTR((unused)))
|
||||
{
|
||||
unsigned int start, end;
|
||||
int err;
|
||||
errcode_t retval;
|
||||
blk64_t out;
|
||||
|
||||
if (check_fs_open(argv[0]))
|
||||
return;
|
||||
|
||||
if (argc != 3 && argc != 3) {
|
||||
com_err(argv[0], 0, "Usage: ffzb <start> <end>");
|
||||
return;
|
||||
}
|
||||
|
||||
start = parse_ulong(argv[1], argv[0], "start", &err);
|
||||
if (err)
|
||||
return;
|
||||
|
||||
end = parse_ulong(argv[2], argv[0], "end", &err);
|
||||
if (err)
|
||||
return;
|
||||
|
||||
retval = ext2fs_find_first_zero_block_bitmap2(test_fs->block_map,
|
||||
start, end, &out);
|
||||
if (retval) {
|
||||
printf("ext2fs_find_first_zero_block_bitmap2() returned %s\n",
|
||||
error_message(retval));
|
||||
return;
|
||||
}
|
||||
printf("First unmarked block is %llu\n", (unsigned long long) out);
|
||||
}
|
||||
|
||||
void do_ffsb(int argc, char *argv[], int sci_idx EXT2FS_ATTR((unused)),
|
||||
void *infop EXT2FS_ATTR((unused)))
|
||||
{
|
||||
unsigned int start, end;
|
||||
int err;
|
||||
errcode_t retval;
|
||||
blk64_t out;
|
||||
|
||||
if (check_fs_open(argv[0]))
|
||||
return;
|
||||
|
||||
if (argc != 3 && argc != 3) {
|
||||
com_err(argv[0], 0, "Usage: ffsb <start> <end>");
|
||||
return;
|
||||
}
|
||||
|
||||
start = parse_ulong(argv[1], argv[0], "start", &err);
|
||||
if (err)
|
||||
return;
|
||||
|
||||
end = parse_ulong(argv[2], argv[0], "end", &err);
|
||||
if (err)
|
||||
return;
|
||||
|
||||
retval = ext2fs_find_first_set_block_bitmap2(test_fs->block_map,
|
||||
start, end, &out);
|
||||
if (retval) {
|
||||
printf("ext2fs_find_first_set_block_bitmap2() returned %s\n",
|
||||
error_message(retval));
|
||||
return;
|
||||
}
|
||||
printf("First marked block is %llu\n", (unsigned long long) out);
|
||||
}
|
||||
|
||||
|
||||
void do_zerob(int argc, char *argv[], int sci_idx EXT2FS_ATTR((unused)),
|
||||
void *infop EXT2FS_ATTR((unused)))
|
||||
{
|
||||
if (check_fs_open(argv[0]))
|
||||
return;
|
||||
|
||||
printf("Clearing block bitmap.\n");
|
||||
ext2fs_clear_block_bitmap(test_fs->block_map);
|
||||
}
|
||||
|
||||
void do_seti(int argc, char *argv[], int sci_idx EXT2FS_ATTR((unused)),
|
||||
void *infop EXT2FS_ATTR((unused)))
|
||||
{
|
||||
unsigned int inode;
|
||||
int err;
|
||||
int test_result, op_result;
|
||||
|
||||
if (check_fs_open(argv[0]))
|
||||
return;
|
||||
|
||||
if (argc != 2) {
|
||||
com_err(argv[0], 0, "Usage: seti <inode>");
|
||||
return;
|
||||
}
|
||||
|
||||
inode = parse_ulong(argv[1], argv[0], "inode", &err);
|
||||
if (err)
|
||||
return;
|
||||
|
||||
test_result = ext2fs_test_inode_bitmap2(test_fs->inode_map, inode);
|
||||
op_result = ext2fs_mark_inode_bitmap2(test_fs->inode_map, inode);
|
||||
printf("Setting inode %u, was %s before\n", inode, op_result ?
|
||||
"set" : "clear");
|
||||
if (!test_result != !op_result) {
|
||||
com_err(argv[0], 0, "*ERROR* test_result different! (%d, %d)",
|
||||
test_result, op_result);
|
||||
exit_status++;
|
||||
}
|
||||
}
|
||||
|
||||
void do_cleari(int argc, char *argv[], int sci_idx EXT2FS_ATTR((unused)),
|
||||
void *infop EXT2FS_ATTR((unused)))
|
||||
{
|
||||
unsigned int inode;
|
||||
int err;
|
||||
int test_result, op_result;
|
||||
|
||||
if (check_fs_open(argv[0]))
|
||||
return;
|
||||
|
||||
if (argc != 2) {
|
||||
com_err(argv[0], 0, "Usage: clearb <inode>");
|
||||
return;
|
||||
}
|
||||
|
||||
inode = parse_ulong(argv[1], argv[0], "inode", &err);
|
||||
if (err)
|
||||
return;
|
||||
|
||||
test_result = ext2fs_test_inode_bitmap2(test_fs->inode_map, inode);
|
||||
op_result = ext2fs_unmark_inode_bitmap2(test_fs->inode_map, inode);
|
||||
printf("Clearing inode %u, was %s before\n", inode, op_result ?
|
||||
"set" : "clear");
|
||||
if (!test_result != !op_result) {
|
||||
com_err(argv[0], 0, "*ERROR* test_result different! (%d, %d)",
|
||||
test_result, op_result);
|
||||
exit_status++;
|
||||
}
|
||||
}
|
||||
|
||||
void do_testi(int argc, char *argv[], int sci_idx EXT2FS_ATTR((unused)),
|
||||
void *infop EXT2FS_ATTR((unused)))
|
||||
{
|
||||
unsigned int inode;
|
||||
int err;
|
||||
int test_result;
|
||||
|
||||
if (check_fs_open(argv[0]))
|
||||
return;
|
||||
|
||||
if (argc != 2) {
|
||||
com_err(argv[0], 0, "Usage: testb <inode>");
|
||||
return;
|
||||
}
|
||||
|
||||
inode = parse_ulong(argv[1], argv[0], "inode", &err);
|
||||
if (err)
|
||||
return;
|
||||
|
||||
test_result = ext2fs_test_inode_bitmap2(test_fs->inode_map, inode);
|
||||
printf("Inode %u is %s\n", inode, test_result ? "set" : "clear");
|
||||
}
|
||||
|
||||
void do_ffzi(int argc, char *argv[], int sci_idx EXT2FS_ATTR((unused)),
|
||||
void *infop EXT2FS_ATTR((unused)))
|
||||
{
|
||||
unsigned int start, end;
|
||||
int err;
|
||||
errcode_t retval;
|
||||
ext2_ino_t out;
|
||||
|
||||
if (check_fs_open(argv[0]))
|
||||
return;
|
||||
|
||||
if (argc != 3 && argc != 3) {
|
||||
com_err(argv[0], 0, "Usage: ffzi <start> <end>");
|
||||
return;
|
||||
}
|
||||
|
||||
start = parse_ulong(argv[1], argv[0], "start", &err);
|
||||
if (err)
|
||||
return;
|
||||
|
||||
end = parse_ulong(argv[2], argv[0], "end", &err);
|
||||
if (err)
|
||||
return;
|
||||
|
||||
retval = ext2fs_find_first_zero_inode_bitmap2(test_fs->inode_map,
|
||||
start, end, &out);
|
||||
if (retval) {
|
||||
printf("ext2fs_find_first_zero_inode_bitmap2() returned %s\n",
|
||||
error_message(retval));
|
||||
return;
|
||||
}
|
||||
printf("First unmarked inode is %u\n", out);
|
||||
}
|
||||
|
||||
void do_ffsi(int argc, char *argv[], int sci_idx EXT2FS_ATTR((unused)),
|
||||
void *infop EXT2FS_ATTR((unused)))
|
||||
{
|
||||
unsigned int start, end;
|
||||
int err;
|
||||
errcode_t retval;
|
||||
ext2_ino_t out;
|
||||
|
||||
if (check_fs_open(argv[0]))
|
||||
return;
|
||||
|
||||
if (argc != 3 && argc != 3) {
|
||||
com_err(argv[0], 0, "Usage: ffsi <start> <end>");
|
||||
return;
|
||||
}
|
||||
|
||||
start = parse_ulong(argv[1], argv[0], "start", &err);
|
||||
if (err)
|
||||
return;
|
||||
|
||||
end = parse_ulong(argv[2], argv[0], "end", &err);
|
||||
if (err)
|
||||
return;
|
||||
|
||||
retval = ext2fs_find_first_set_inode_bitmap2(test_fs->inode_map,
|
||||
start, end, &out);
|
||||
if (retval) {
|
||||
printf("ext2fs_find_first_set_inode_bitmap2() returned %s\n",
|
||||
error_message(retval));
|
||||
return;
|
||||
}
|
||||
printf("First marked inode is %u\n", out);
|
||||
}
|
||||
|
||||
void do_zeroi(int argc, char *argv[], int sci_idx EXT2FS_ATTR((unused)),
|
||||
void *infop EXT2FS_ATTR((unused)))
|
||||
{
|
||||
if (check_fs_open(argv[0]))
|
||||
return;
|
||||
|
||||
printf("Clearing inode bitmap.\n");
|
||||
ext2fs_clear_inode_bitmap(test_fs->inode_map);
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
unsigned int blocks = 128;
|
||||
unsigned int inodes = 0;
|
||||
unsigned int type = EXT2FS_BMAP64_BITARRAY;
|
||||
int c, err, code;
|
||||
char *request = (char *)NULL;
|
||||
char *cmd_file = 0;
|
||||
int sci_idx;
|
||||
int flags = EXT2_FLAG_64BITS;
|
||||
|
||||
add_error_table(&et_ss_error_table);
|
||||
add_error_table(&et_ext2_error_table);
|
||||
while ((c = getopt (argc, argv, "b:i:lt:R:f:")) != EOF) {
|
||||
switch (c) {
|
||||
case 'b':
|
||||
blocks = parse_ulong(optarg, argv[0],
|
||||
"number of blocks", &err);
|
||||
if (err)
|
||||
exit(1);
|
||||
break;
|
||||
case 'i':
|
||||
inodes = parse_ulong(optarg, argv[0],
|
||||
"number of blocks", &err);
|
||||
if (err)
|
||||
exit(1);
|
||||
break;
|
||||
case 'l': /* Legacy bitmaps */
|
||||
flags = 0;
|
||||
break;
|
||||
case 't':
|
||||
type = parse_ulong(optarg, argv[0],
|
||||
"bitmap backend type", &err);
|
||||
if (err)
|
||||
exit(1);
|
||||
break;
|
||||
case 'R':
|
||||
request = optarg;
|
||||
break;
|
||||
case 'f':
|
||||
cmd_file = optarg;
|
||||
break;
|
||||
default:
|
||||
com_err(argv[0], 0, "Usage: %s [-R request] "
|
||||
"[-f cmd_file]", subsystem_name);
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
sci_idx = ss_create_invocation(subsystem_name, version,
|
||||
(char *)NULL, &tst_bitmaps_cmds, &code);
|
||||
if (code) {
|
||||
ss_perror(sci_idx, code, "creating invocation");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
(void) ss_add_request_table (sci_idx, &ss_std_requests, 1, &code);
|
||||
if (code) {
|
||||
ss_perror(sci_idx, code, "adding standard requests");
|
||||
exit (1);
|
||||
}
|
||||
|
||||
printf("%s %s. Type '?' for a list of commands.\n\n",
|
||||
subsystem_name, version);
|
||||
|
||||
setup_filesystem(argv[0], blocks, inodes, type, flags);
|
||||
|
||||
if (request) {
|
||||
code = ss_execute_line(sci_idx, request);
|
||||
if (code) {
|
||||
ss_perror(sci_idx, code, request);
|
||||
exit_status++;
|
||||
}
|
||||
} else if (cmd_file) {
|
||||
exit_status = source_file(cmd_file, sci_idx);
|
||||
} else {
|
||||
ss_listen(sci_idx);
|
||||
}
|
||||
|
||||
exit(exit_status);
|
||||
}
|
||||
|
||||
@@ -1,51 +0,0 @@
|
||||
command_table tst_bitmaps_cmds;
|
||||
|
||||
request setup_cmd, "Setup file system",
|
||||
setup;
|
||||
|
||||
request close_cmd, "Close file system",
|
||||
close;
|
||||
|
||||
request dump_inode_bitmap_cmd, "Dump the inode bitmap",
|
||||
dump_inode_bitmap, dump_ib;
|
||||
|
||||
request dump_block_bitmap_cmd, "Dump the block bitmap",
|
||||
dump_block_bitmap, dump_bb;
|
||||
|
||||
request do_setb, "Set block",
|
||||
set_block, setb;
|
||||
|
||||
request do_clearb, "Clear block",
|
||||
clear_block, clearb;
|
||||
|
||||
request do_testb, "Test block",
|
||||
test_block, testb;
|
||||
|
||||
request do_ffzb, "Find first zero block",
|
||||
find_first_zero_block, ffzb;
|
||||
|
||||
request do_ffsb, "Find first set block",
|
||||
find_first_set_block, ffsb;
|
||||
|
||||
request do_zerob, "Clear block bitmap",
|
||||
clear_block_bitmap, zerob;
|
||||
|
||||
request do_seti, "Set inode",
|
||||
set_inode, seti;
|
||||
|
||||
request do_cleari, "Clear inode",
|
||||
clear_inode, cleari;
|
||||
|
||||
request do_testi, "Test inode",
|
||||
test_inode, testi;
|
||||
|
||||
request do_ffzi, "Find first zero inode",
|
||||
find_first_zero_inode, ffzi;
|
||||
|
||||
request do_ffsi, "Find first set inode",
|
||||
find_first_set_inode, ffsi;
|
||||
|
||||
request do_zeroi, "Clear inode bitmap",
|
||||
clear_inode_bitmap, zeroi;
|
||||
|
||||
end;
|
||||
@@ -1,150 +0,0 @@
|
||||
setb 12 0
|
||||
setb 12
|
||||
setb 12
|
||||
clearb 12
|
||||
clearb 12
|
||||
setb 12
|
||||
setb 14
|
||||
setb 16
|
||||
testb 13
|
||||
testb 15
|
||||
testb 12
|
||||
testb 14
|
||||
setb 13
|
||||
setb 15
|
||||
testb 12
|
||||
testb 11
|
||||
testb 15
|
||||
testb 16
|
||||
dump_bb
|
||||
ffzb 11 16
|
||||
ffzb 12 16
|
||||
ffzb 12 20
|
||||
ffsb 0 127
|
||||
ffsb 1 128
|
||||
ffsb 1 127
|
||||
ffsb 1 10
|
||||
ffsb 1 11
|
||||
ffsb 12 12
|
||||
ffsb 13 12
|
||||
ffsb 12 15
|
||||
clearb 13
|
||||
ffzb 12 20
|
||||
ffsb 13 18
|
||||
setb 13
|
||||
clearb 12 7
|
||||
testb 12 7
|
||||
setb 15
|
||||
testb 12 7
|
||||
clearb 15
|
||||
testb 12 7
|
||||
setb 12 0
|
||||
setb 12 7
|
||||
dump_bb
|
||||
seti 2
|
||||
seti 5
|
||||
seti 4
|
||||
seti 3
|
||||
seti 4
|
||||
seti 5
|
||||
testi 6
|
||||
testi 1
|
||||
dump_ib
|
||||
ffzi 1 6
|
||||
ffzi 2 5
|
||||
ffzi 2 6
|
||||
ffsi 0 31
|
||||
ffsi 1 33
|
||||
ffsi 1 32
|
||||
ffsi 2 32
|
||||
ffsi 6 32
|
||||
cleari 4
|
||||
ffzi 2 6
|
||||
ffsi 4 32
|
||||
ffsi 5 32
|
||||
zeroi
|
||||
testi 5
|
||||
seti 5
|
||||
seti 5
|
||||
cleari 5
|
||||
cleari 5
|
||||
testi 17
|
||||
testi 6
|
||||
testi 4
|
||||
clearb 7 12
|
||||
dump_bb
|
||||
setb 1
|
||||
dump_bb
|
||||
setb 2
|
||||
dump_bb
|
||||
setb 3
|
||||
dump_bb
|
||||
setb 4
|
||||
dump_bb
|
||||
setb 5
|
||||
dump_bb
|
||||
setb 6
|
||||
dump_bb
|
||||
setb 7
|
||||
dump_bb
|
||||
setb 8
|
||||
dump_bb
|
||||
setb 10
|
||||
setb 12
|
||||
setb 14
|
||||
setb 17
|
||||
setb 19
|
||||
setb 24
|
||||
setb 26
|
||||
setb 27
|
||||
setb 30
|
||||
setb 31
|
||||
setb 32
|
||||
setb 35
|
||||
setb 39
|
||||
setb 40
|
||||
setb 44
|
||||
setb 46
|
||||
setb 47
|
||||
setb 49
|
||||
setb 51
|
||||
setb 52
|
||||
clearb 2
|
||||
clearb 3
|
||||
clearb 7
|
||||
dump_bb
|
||||
ffsb 14 127
|
||||
ffsb 15 127
|
||||
ffsb 36 127
|
||||
ffsb 32 127
|
||||
ffsb 52 127
|
||||
ffsb 53 127
|
||||
ffsb 46 127
|
||||
ffsb 45 127
|
||||
ffsb 41 127
|
||||
ffsb 20 127
|
||||
ffsb 1 127
|
||||
ffsb 2 127
|
||||
ffsb 3 127
|
||||
ffsb 4 127
|
||||
ffsb 5 127
|
||||
ffsb 6 127
|
||||
ffsb 7 127
|
||||
ffsb 8 127
|
||||
ffzb 1 127
|
||||
ffzb 2 127
|
||||
ffzb 3 127
|
||||
ffzb 4 127
|
||||
ffzb 5 127
|
||||
ffzb 6 127
|
||||
ffzb 7 127
|
||||
ffzb 8 127
|
||||
ffzb 45 127
|
||||
ffzb 46 127
|
||||
ffzb 47 127
|
||||
ffzb 48 127
|
||||
ffzb 49 127
|
||||
ffzb 50 127
|
||||
ffzb 51 127
|
||||
quit
|
||||
|
||||
@@ -1,313 +0,0 @@
|
||||
tst_bitmaps 1.0. Type '?' for a list of commands.
|
||||
|
||||
tst_bitmaps: setb 12 0
|
||||
Marking blocks 12 to 11
|
||||
tst_bitmaps: setb 12
|
||||
Setting block 12, was clear before
|
||||
tst_bitmaps: setb 12
|
||||
Setting block 12, was set before
|
||||
tst_bitmaps: clearb 12
|
||||
Clearing block 12, was set before
|
||||
tst_bitmaps: clearb 12
|
||||
Clearing block 12, was clear before
|
||||
tst_bitmaps: setb 12
|
||||
Setting block 12, was clear before
|
||||
tst_bitmaps: setb 14
|
||||
Setting block 14, was clear before
|
||||
tst_bitmaps: setb 16
|
||||
Setting block 16, was clear before
|
||||
tst_bitmaps: testb 13
|
||||
Block 13 is clear
|
||||
tst_bitmaps: testb 15
|
||||
Block 15 is clear
|
||||
tst_bitmaps: testb 12
|
||||
Block 12 is set
|
||||
tst_bitmaps: testb 14
|
||||
Block 14 is set
|
||||
tst_bitmaps: setb 13
|
||||
Setting block 13, was clear before
|
||||
tst_bitmaps: setb 15
|
||||
Setting block 15, was clear before
|
||||
tst_bitmaps: testb 12
|
||||
Block 12 is set
|
||||
tst_bitmaps: testb 11
|
||||
Block 11 is clear
|
||||
tst_bitmaps: testb 15
|
||||
Block 15 is set
|
||||
tst_bitmaps: testb 16
|
||||
Block 16 is set
|
||||
tst_bitmaps: dump_bb
|
||||
block bitmap: 00f80000000000000000000000000000
|
||||
bits set: 5
|
||||
tst_bitmaps: ffzb 11 16
|
||||
First unmarked block is 11
|
||||
tst_bitmaps: ffzb 12 16
|
||||
ext2fs_find_first_zero_block_bitmap2() returned No such file or directory
|
||||
tst_bitmaps: ffzb 12 20
|
||||
First unmarked block is 17
|
||||
tst_bitmaps: ffsb 0 127
|
||||
ext2fs_find_first_set_block_bitmap2() returned Invalid argument
|
||||
tst_bitmaps: ffsb 1 128
|
||||
ext2fs_find_first_set_block_bitmap2() returned Invalid argument
|
||||
tst_bitmaps: ffsb 1 127
|
||||
First marked block is 12
|
||||
tst_bitmaps: ffsb 1 10
|
||||
ext2fs_find_first_set_block_bitmap2() returned No such file or directory
|
||||
tst_bitmaps: ffsb 1 11
|
||||
ext2fs_find_first_set_block_bitmap2() returned No such file or directory
|
||||
tst_bitmaps: ffsb 12 12
|
||||
First marked block is 12
|
||||
tst_bitmaps: ffsb 13 12
|
||||
ext2fs_find_first_set_block_bitmap2() returned Invalid argument
|
||||
tst_bitmaps: ffsb 12 15
|
||||
First marked block is 12
|
||||
tst_bitmaps: clearb 13
|
||||
Clearing block 13, was set before
|
||||
tst_bitmaps: ffzb 12 20
|
||||
First unmarked block is 13
|
||||
tst_bitmaps: ffsb 13 18
|
||||
First marked block is 14
|
||||
tst_bitmaps: setb 13
|
||||
Setting block 13, was clear before
|
||||
tst_bitmaps: clearb 12 7
|
||||
Clearing blocks 12 to 18
|
||||
tst_bitmaps: testb 12 7
|
||||
Blocks 12 to 18 are all clear.
|
||||
tst_bitmaps: setb 15
|
||||
Setting block 15, was clear before
|
||||
tst_bitmaps: testb 12 7
|
||||
Blocks 12 to 18 are NOT all clear.
|
||||
tst_bitmaps: clearb 15
|
||||
Clearing block 15, was set before
|
||||
tst_bitmaps: testb 12 7
|
||||
Blocks 12 to 18 are all clear.
|
||||
tst_bitmaps: setb 12 0
|
||||
Marking blocks 12 to 11
|
||||
tst_bitmaps: setb 12 7
|
||||
Marking blocks 12 to 18
|
||||
tst_bitmaps: dump_bb
|
||||
block bitmap: 00f80300000000000000000000000000
|
||||
bits set: 7
|
||||
tst_bitmaps: seti 2
|
||||
Setting inode 2, was clear before
|
||||
tst_bitmaps: seti 5
|
||||
Setting inode 5, was clear before
|
||||
tst_bitmaps: seti 4
|
||||
Setting inode 4, was clear before
|
||||
tst_bitmaps: seti 3
|
||||
Setting inode 3, was clear before
|
||||
tst_bitmaps: seti 4
|
||||
Setting inode 4, was set before
|
||||
tst_bitmaps: seti 5
|
||||
Setting inode 5, was set before
|
||||
tst_bitmaps: testi 6
|
||||
Inode 6 is clear
|
||||
tst_bitmaps: testi 1
|
||||
Inode 1 is clear
|
||||
tst_bitmaps: dump_ib
|
||||
inode bitmap: 1e000000
|
||||
bits set: 4
|
||||
tst_bitmaps: ffzi 1 6
|
||||
First unmarked inode is 1
|
||||
tst_bitmaps: ffzi 2 5
|
||||
ext2fs_find_first_zero_inode_bitmap2() returned No such file or directory
|
||||
tst_bitmaps: ffzi 2 6
|
||||
First unmarked inode is 6
|
||||
tst_bitmaps: ffsi 0 31
|
||||
ext2fs_find_first_set_inode_bitmap2() returned Invalid argument
|
||||
tst_bitmaps: ffsi 1 33
|
||||
ext2fs_find_first_set_inode_bitmap2() returned Invalid argument
|
||||
tst_bitmaps: ffsi 1 32
|
||||
First marked inode is 2
|
||||
tst_bitmaps: ffsi 2 32
|
||||
First marked inode is 2
|
||||
tst_bitmaps: ffsi 6 32
|
||||
ext2fs_find_first_set_inode_bitmap2() returned No such file or directory
|
||||
tst_bitmaps: cleari 4
|
||||
Clearing inode 4, was set before
|
||||
tst_bitmaps: ffzi 2 6
|
||||
First unmarked inode is 4
|
||||
tst_bitmaps: ffsi 4 32
|
||||
First marked inode is 5
|
||||
tst_bitmaps: ffsi 5 32
|
||||
First marked inode is 5
|
||||
tst_bitmaps: zeroi
|
||||
Clearing inode bitmap.
|
||||
tst_bitmaps: testi 5
|
||||
Inode 5 is clear
|
||||
tst_bitmaps: seti 5
|
||||
Setting inode 5, was clear before
|
||||
tst_bitmaps: seti 5
|
||||
Setting inode 5, was set before
|
||||
tst_bitmaps: cleari 5
|
||||
Clearing inode 5, was set before
|
||||
tst_bitmaps: cleari 5
|
||||
Clearing inode 5, was clear before
|
||||
tst_bitmaps: testi 17
|
||||
Inode 17 is clear
|
||||
tst_bitmaps: testi 6
|
||||
Inode 6 is clear
|
||||
tst_bitmaps: testi 4
|
||||
Inode 4 is clear
|
||||
tst_bitmaps: clearb 7 12
|
||||
Clearing blocks 7 to 18
|
||||
tst_bitmaps: dump_bb
|
||||
block bitmap: 00000000000000000000000000000000
|
||||
bits set: 0
|
||||
tst_bitmaps: setb 1
|
||||
Setting block 1, was clear before
|
||||
tst_bitmaps: dump_bb
|
||||
block bitmap: 01000000000000000000000000000000
|
||||
bits set: 1
|
||||
tst_bitmaps: setb 2
|
||||
Setting block 2, was clear before
|
||||
tst_bitmaps: dump_bb
|
||||
block bitmap: 03000000000000000000000000000000
|
||||
bits set: 2
|
||||
tst_bitmaps: setb 3
|
||||
Setting block 3, was clear before
|
||||
tst_bitmaps: dump_bb
|
||||
block bitmap: 07000000000000000000000000000000
|
||||
bits set: 3
|
||||
tst_bitmaps: setb 4
|
||||
Setting block 4, was clear before
|
||||
tst_bitmaps: dump_bb
|
||||
block bitmap: 0f000000000000000000000000000000
|
||||
bits set: 4
|
||||
tst_bitmaps: setb 5
|
||||
Setting block 5, was clear before
|
||||
tst_bitmaps: dump_bb
|
||||
block bitmap: 1f000000000000000000000000000000
|
||||
bits set: 5
|
||||
tst_bitmaps: setb 6
|
||||
Setting block 6, was clear before
|
||||
tst_bitmaps: dump_bb
|
||||
block bitmap: 3f000000000000000000000000000000
|
||||
bits set: 6
|
||||
tst_bitmaps: setb 7
|
||||
Setting block 7, was clear before
|
||||
tst_bitmaps: dump_bb
|
||||
block bitmap: 7f000000000000000000000000000000
|
||||
bits set: 7
|
||||
tst_bitmaps: setb 8
|
||||
Setting block 8, was clear before
|
||||
tst_bitmaps: dump_bb
|
||||
block bitmap: ff000000000000000000000000000000
|
||||
bits set: 8
|
||||
tst_bitmaps: setb 10
|
||||
Setting block 10, was clear before
|
||||
tst_bitmaps: setb 12
|
||||
Setting block 12, was clear before
|
||||
tst_bitmaps: setb 14
|
||||
Setting block 14, was clear before
|
||||
tst_bitmaps: setb 17
|
||||
Setting block 17, was clear before
|
||||
tst_bitmaps: setb 19
|
||||
Setting block 19, was clear before
|
||||
tst_bitmaps: setb 24
|
||||
Setting block 24, was clear before
|
||||
tst_bitmaps: setb 26
|
||||
Setting block 26, was clear before
|
||||
tst_bitmaps: setb 27
|
||||
Setting block 27, was clear before
|
||||
tst_bitmaps: setb 30
|
||||
Setting block 30, was clear before
|
||||
tst_bitmaps: setb 31
|
||||
Setting block 31, was clear before
|
||||
tst_bitmaps: setb 32
|
||||
Setting block 32, was clear before
|
||||
tst_bitmaps: setb 35
|
||||
Setting block 35, was clear before
|
||||
tst_bitmaps: setb 39
|
||||
Setting block 39, was clear before
|
||||
tst_bitmaps: setb 40
|
||||
Setting block 40, was clear before
|
||||
tst_bitmaps: setb 44
|
||||
Setting block 44, was clear before
|
||||
tst_bitmaps: setb 46
|
||||
Setting block 46, was clear before
|
||||
tst_bitmaps: setb 47
|
||||
Setting block 47, was clear before
|
||||
tst_bitmaps: setb 49
|
||||
Setting block 49, was clear before
|
||||
tst_bitmaps: setb 51
|
||||
Setting block 51, was clear before
|
||||
tst_bitmaps: setb 52
|
||||
Setting block 52, was clear before
|
||||
tst_bitmaps: clearb 2
|
||||
Clearing block 2, was set before
|
||||
tst_bitmaps: clearb 3
|
||||
Clearing block 3, was set before
|
||||
tst_bitmaps: clearb 7
|
||||
Clearing block 7, was set before
|
||||
tst_bitmaps: dump_bb
|
||||
block bitmap: b92a85e6c4680d000000000000000000
|
||||
bits set: 25
|
||||
tst_bitmaps: ffsb 14 127
|
||||
First marked block is 14
|
||||
tst_bitmaps: ffsb 15 127
|
||||
First marked block is 17
|
||||
tst_bitmaps: ffsb 36 127
|
||||
First marked block is 39
|
||||
tst_bitmaps: ffsb 32 127
|
||||
First marked block is 32
|
||||
tst_bitmaps: ffsb 52 127
|
||||
First marked block is 52
|
||||
tst_bitmaps: ffsb 53 127
|
||||
ext2fs_find_first_set_block_bitmap2() returned No such file or directory
|
||||
tst_bitmaps: ffsb 46 127
|
||||
First marked block is 46
|
||||
tst_bitmaps: ffsb 45 127
|
||||
First marked block is 46
|
||||
tst_bitmaps: ffsb 41 127
|
||||
First marked block is 44
|
||||
tst_bitmaps: ffsb 20 127
|
||||
First marked block is 24
|
||||
tst_bitmaps: ffsb 1 127
|
||||
First marked block is 1
|
||||
tst_bitmaps: ffsb 2 127
|
||||
First marked block is 4
|
||||
tst_bitmaps: ffsb 3 127
|
||||
First marked block is 4
|
||||
tst_bitmaps: ffsb 4 127
|
||||
First marked block is 4
|
||||
tst_bitmaps: ffsb 5 127
|
||||
First marked block is 5
|
||||
tst_bitmaps: ffsb 6 127
|
||||
First marked block is 6
|
||||
tst_bitmaps: ffsb 7 127
|
||||
First marked block is 8
|
||||
tst_bitmaps: ffsb 8 127
|
||||
First marked block is 8
|
||||
tst_bitmaps: ffzb 1 127
|
||||
First unmarked block is 2
|
||||
tst_bitmaps: ffzb 2 127
|
||||
First unmarked block is 2
|
||||
tst_bitmaps: ffzb 3 127
|
||||
First unmarked block is 3
|
||||
tst_bitmaps: ffzb 4 127
|
||||
First unmarked block is 7
|
||||
tst_bitmaps: ffzb 5 127
|
||||
First unmarked block is 7
|
||||
tst_bitmaps: ffzb 6 127
|
||||
First unmarked block is 7
|
||||
tst_bitmaps: ffzb 7 127
|
||||
First unmarked block is 7
|
||||
tst_bitmaps: ffzb 8 127
|
||||
First unmarked block is 9
|
||||
tst_bitmaps: ffzb 45 127
|
||||
First unmarked block is 45
|
||||
tst_bitmaps: ffzb 46 127
|
||||
First unmarked block is 48
|
||||
tst_bitmaps: ffzb 47 127
|
||||
First unmarked block is 48
|
||||
tst_bitmaps: ffzb 48 127
|
||||
First unmarked block is 48
|
||||
tst_bitmaps: ffzb 49 127
|
||||
First unmarked block is 50
|
||||
tst_bitmaps: ffzb 50 127
|
||||
First unmarked block is 50
|
||||
tst_bitmaps: ffzb 51 127
|
||||
First unmarked block is 53
|
||||
tst_bitmaps: quit
|
||||
tst_bitmaps:
|
||||
@@ -1,288 +0,0 @@
|
||||
/*
|
||||
* This testing program makes sure the bitops functions work
|
||||
*
|
||||
* Copyright (C) 2001 by Theodore Ts'o.
|
||||
*
|
||||
* %Begin-Header%
|
||||
* This file may be redistributed under the terms of the GNU Library
|
||||
* General Public License, version 2.
|
||||
* %End-Header%
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#if HAVE_UNISTD_H
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
#include <fcntl.h>
|
||||
#include <time.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/types.h>
|
||||
#if HAVE_ERRNO_H
|
||||
#include <errno.h>
|
||||
#endif
|
||||
#include <sys/time.h>
|
||||
#include <sys/resource.h>
|
||||
|
||||
#include "ext2_fs.h"
|
||||
#include "ext2fs.h"
|
||||
|
||||
unsigned char bitarray[] = {
|
||||
0x80, 0xF0, 0x40, 0x40, 0x0, 0x0, 0x0, 0x0, 0x10, 0x20, 0x00, 0x00
|
||||
};
|
||||
|
||||
int bits_list[] = {
|
||||
7, 12, 13, 14,15, 22, 30, 68, 77, -1,
|
||||
};
|
||||
|
||||
#define BIG_TEST_BIT (((unsigned) 1 << 31) + 42)
|
||||
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
int i, j, size;
|
||||
unsigned char testarray[12];
|
||||
unsigned char *bigarray;
|
||||
|
||||
size = sizeof(bitarray)*8;
|
||||
#if 0
|
||||
i = ext2fs_find_first_bit_set(bitarray, size);
|
||||
while (i < size) {
|
||||
printf("Bit set: %d\n", i);
|
||||
i = ext2fs_find_next_bit_set(bitarray, size, i+1);
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Test test_bit */
|
||||
for (i=0,j=0; i < size; i++) {
|
||||
if (ext2fs_test_bit(i, bitarray)) {
|
||||
if (bits_list[j] == i) {
|
||||
j++;
|
||||
} else {
|
||||
printf("Bit %d set, not expected\n", i);
|
||||
exit(1);
|
||||
}
|
||||
} else {
|
||||
if (bits_list[j] == i) {
|
||||
printf("Expected bit %d to be clear.\n", i);
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
printf("ext2fs_test_bit appears to be correct\n");
|
||||
|
||||
/* Test ext2fs_set_bit */
|
||||
memset(testarray, 0, sizeof(testarray));
|
||||
for (i=0; bits_list[i] > 0; i++) {
|
||||
ext2fs_set_bit(bits_list[i], testarray);
|
||||
}
|
||||
if (memcmp(testarray, bitarray, sizeof(testarray)) == 0) {
|
||||
printf("ext2fs_set_bit test succeeded.\n");
|
||||
} else {
|
||||
printf("ext2fs_set_bit test failed.\n");
|
||||
for (i=0; i < sizeof(testarray); i++) {
|
||||
printf("%02x ", testarray[i]);
|
||||
}
|
||||
printf("\n");
|
||||
exit(1);
|
||||
}
|
||||
for (i=0; bits_list[i] > 0; i++) {
|
||||
ext2fs_clear_bit(bits_list[i], testarray);
|
||||
}
|
||||
for (i=0; i < sizeof(testarray); i++) {
|
||||
if (testarray[i]) {
|
||||
printf("ext2fs_clear_bit failed, "
|
||||
"testarray[%d] is %d\n", i, testarray[i]);
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
printf("ext2fs_clear_bit test succeed.\n");
|
||||
|
||||
|
||||
/* Do bigarray test */
|
||||
bigarray = malloc(1 << 29);
|
||||
if (!bigarray) {
|
||||
fprintf(stderr, "Failed to allocate scratch memory!\n");
|
||||
exit(0);
|
||||
}
|
||||
|
||||
bigarray[BIG_TEST_BIT >> 3] = 0;
|
||||
|
||||
ext2fs_set_bit(BIG_TEST_BIT, bigarray);
|
||||
printf("big bit number (%u) test: %d, expected %d\n", BIG_TEST_BIT,
|
||||
bigarray[BIG_TEST_BIT >> 3], (1 << (BIG_TEST_BIT & 7)));
|
||||
if (bigarray[BIG_TEST_BIT >> 3] != (1 << (BIG_TEST_BIT & 7)))
|
||||
exit(1);
|
||||
|
||||
ext2fs_clear_bit(BIG_TEST_BIT, bigarray);
|
||||
|
||||
printf("big bit number (%u) test: %d, expected 0\n", BIG_TEST_BIT,
|
||||
bigarray[BIG_TEST_BIT >> 3]);
|
||||
if (bigarray[BIG_TEST_BIT >> 3] != 0)
|
||||
exit(1);
|
||||
|
||||
printf("ext2fs_set_bit big_test successful\n");
|
||||
|
||||
|
||||
/* Now test ext2fs_fast_set_bit */
|
||||
memset(testarray, 0, sizeof(testarray));
|
||||
for (i=0; bits_list[i] > 0; i++) {
|
||||
ext2fs_fast_set_bit(bits_list[i], testarray);
|
||||
}
|
||||
if (memcmp(testarray, bitarray, sizeof(testarray)) == 0) {
|
||||
printf("ext2fs_fast_set_bit test succeeded.\n");
|
||||
} else {
|
||||
printf("ext2fs_fast_set_bit test failed.\n");
|
||||
for (i=0; i < sizeof(testarray); i++) {
|
||||
printf("%02x ", testarray[i]);
|
||||
}
|
||||
printf("\n");
|
||||
exit(1);
|
||||
}
|
||||
for (i=0; bits_list[i] > 0; i++) {
|
||||
ext2fs_clear_bit(bits_list[i], testarray);
|
||||
}
|
||||
for (i=0; i < sizeof(testarray); i++) {
|
||||
if (testarray[i]) {
|
||||
printf("ext2fs_clear_bit failed, "
|
||||
"testarray[%d] is %d\n", i, testarray[i]);
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
printf("ext2fs_clear_bit test succeed.\n");
|
||||
|
||||
|
||||
bigarray[BIG_TEST_BIT >> 3] = 0;
|
||||
|
||||
ext2fs_fast_set_bit(BIG_TEST_BIT, bigarray);
|
||||
printf("big bit number (%u) test: %d, expected %d\n", BIG_TEST_BIT,
|
||||
bigarray[BIG_TEST_BIT >> 3], (1 << (BIG_TEST_BIT & 7)));
|
||||
if (bigarray[BIG_TEST_BIT >> 3] != (1 << (BIG_TEST_BIT & 7)))
|
||||
exit(1);
|
||||
|
||||
ext2fs_fast_clear_bit(BIG_TEST_BIT, bigarray);
|
||||
|
||||
printf("big bit number (%u) test: %d, expected 0\n", BIG_TEST_BIT,
|
||||
bigarray[BIG_TEST_BIT >> 3]);
|
||||
if (bigarray[BIG_TEST_BIT >> 3] != 0)
|
||||
exit(1);
|
||||
|
||||
printf("ext2fs_fast_set_bit big_test successful\n");
|
||||
|
||||
/* Repeat foregoing tests for 64-bit bitops */
|
||||
|
||||
/* Test test_bit */
|
||||
for (i=0,j=0; i < size; i++) {
|
||||
if (ext2fs_test_bit64(i, bitarray)) {
|
||||
if (bits_list[j] == i) {
|
||||
j++;
|
||||
} else {
|
||||
printf("64-bit: Bit %d set, not expected\n",
|
||||
i);
|
||||
exit(1);
|
||||
}
|
||||
} else {
|
||||
if (bits_list[j] == i) {
|
||||
printf("64-bit: "
|
||||
"Expected bit %d to be clear.\n", i);
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
printf("64-bit: ext2fs_test_bit appears to be correct\n");
|
||||
|
||||
/* Test ext2fs_set_bit */
|
||||
memset(testarray, 0, sizeof(testarray));
|
||||
for (i=0; bits_list[i] > 0; i++) {
|
||||
ext2fs_set_bit64(bits_list[i], testarray);
|
||||
}
|
||||
if (memcmp(testarray, bitarray, sizeof(testarray)) == 0) {
|
||||
printf("64-bit: ext2fs_set_bit test succeeded.\n");
|
||||
} else {
|
||||
printf("64-bit: ext2fs_set_bit test failed.\n");
|
||||
for (i=0; i < sizeof(testarray); i++) {
|
||||
printf("%02x ", testarray[i]);
|
||||
}
|
||||
printf("\n");
|
||||
exit(1);
|
||||
}
|
||||
for (i=0; bits_list[i] > 0; i++) {
|
||||
ext2fs_clear_bit64(bits_list[i], testarray);
|
||||
}
|
||||
for (i=0; i < sizeof(testarray); i++) {
|
||||
if (testarray[i]) {
|
||||
printf("64-bit: ext2fs_clear_bit failed, "
|
||||
"testarray[%d] is %d\n", i, testarray[i]);
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
printf("64-bit: ext2fs_clear_bit test succeed.\n");
|
||||
|
||||
/* Do bigarray test */
|
||||
bigarray[BIG_TEST_BIT >> 3] = 0;
|
||||
|
||||
ext2fs_set_bit64(BIG_TEST_BIT, bigarray);
|
||||
printf("64-bit: big bit number (%u) test: %d, expected %d\n",
|
||||
BIG_TEST_BIT, bigarray[BIG_TEST_BIT >> 3],
|
||||
(1 << (BIG_TEST_BIT & 7)));
|
||||
if (bigarray[BIG_TEST_BIT >> 3] != (1 << (BIG_TEST_BIT & 7)))
|
||||
exit(1);
|
||||
|
||||
ext2fs_clear_bit64(BIG_TEST_BIT, bigarray);
|
||||
|
||||
printf("64-bit: big bit number (%u) test: %d, expected 0\n",
|
||||
BIG_TEST_BIT,
|
||||
bigarray[BIG_TEST_BIT >> 3]);
|
||||
if (bigarray[BIG_TEST_BIT >> 3] != 0)
|
||||
exit(1);
|
||||
|
||||
printf("64-bit: ext2fs_set_bit big_test successful\n");
|
||||
|
||||
/* Now test ext2fs_fast_set_bit */
|
||||
memset(testarray, 0, sizeof(testarray));
|
||||
for (i=0; bits_list[i] > 0; i++) {
|
||||
ext2fs_fast_set_bit64(bits_list[i], testarray);
|
||||
}
|
||||
if (memcmp(testarray, bitarray, sizeof(testarray)) == 0) {
|
||||
printf("64-bit: ext2fs_fast_set_bit test succeeded.\n");
|
||||
} else {
|
||||
printf("64-bit: ext2fs_fast_set_bit test failed.\n");
|
||||
for (i=0; i < sizeof(testarray); i++) {
|
||||
printf("%02x ", testarray[i]);
|
||||
}
|
||||
printf("\n");
|
||||
exit(1);
|
||||
}
|
||||
for (i=0; bits_list[i] > 0; i++) {
|
||||
ext2fs_clear_bit64(bits_list[i], testarray);
|
||||
}
|
||||
for (i=0; i < sizeof(testarray); i++) {
|
||||
if (testarray[i]) {
|
||||
printf("64-bit: ext2fs_clear_bit failed, "
|
||||
"testarray[%d] is %d\n", i, testarray[i]);
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
printf("64-bit: ext2fs_clear_bit test succeed.\n");
|
||||
|
||||
bigarray[BIG_TEST_BIT >> 3] = 0;
|
||||
|
||||
ext2fs_fast_set_bit64(BIG_TEST_BIT, bigarray);
|
||||
printf("64-bit: big bit number (%u) test: %d, expected %d\n",
|
||||
BIG_TEST_BIT, bigarray[BIG_TEST_BIT >> 3],
|
||||
(1 << (BIG_TEST_BIT & 7)));
|
||||
if (bigarray[BIG_TEST_BIT >> 3] != (1 << (BIG_TEST_BIT & 7)))
|
||||
exit(1);
|
||||
|
||||
ext2fs_fast_clear_bit64(BIG_TEST_BIT, bigarray);
|
||||
|
||||
printf("64-bit: big bit number (%u) test: %d, expected 0\n",
|
||||
BIG_TEST_BIT, bigarray[BIG_TEST_BIT >> 3]);
|
||||
if (bigarray[BIG_TEST_BIT >> 3] != 0)
|
||||
exit(1);
|
||||
|
||||
printf("64-bit: ext2fs_fast_set_bit big_test successful\n");
|
||||
free(bigarray);
|
||||
exit(0);
|
||||
}
|
||||
@@ -1,93 +0,0 @@
|
||||
/*
|
||||
* This testing program makes sure the byteswap functions work
|
||||
*
|
||||
* Copyright (C) 2000 by Theodore Ts'o.
|
||||
*
|
||||
* %Begin-Header%
|
||||
* This file may be redistributed under the terms of the GNU Library
|
||||
* General Public License, version 2.
|
||||
* %End-Header%
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#if HAVE_UNISTD_H
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
#include <fcntl.h>
|
||||
#include <time.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/types.h>
|
||||
#if HAVE_ERRNO_H
|
||||
#include <errno.h>
|
||||
#endif
|
||||
|
||||
#include "ext2_fs.h"
|
||||
#include "ext2fs.h"
|
||||
|
||||
__u16 test1[] = {
|
||||
0x0001, 0x0100,
|
||||
0x1234, 0x3412,
|
||||
0xff00, 0x00ff,
|
||||
0x4000, 0x0040,
|
||||
0xfeff, 0xfffe,
|
||||
0x0000, 0x0000
|
||||
};
|
||||
|
||||
__u32 test2[] = {
|
||||
0x00000001, 0x01000000,
|
||||
0x80000000, 0x00000080,
|
||||
0x12345678, 0x78563412,
|
||||
0xffff0000, 0x0000ffff,
|
||||
0x00ff0000, 0x0000ff00,
|
||||
0xff000000, 0x000000ff,
|
||||
0x00000000, 0x00000000
|
||||
};
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
int i;
|
||||
int errors = 0;
|
||||
|
||||
printf("Testing ext2fs_swab16\n");
|
||||
i=0;
|
||||
do {
|
||||
printf("swab16(0x%04x) = 0x%04x\n", test1[i],
|
||||
ext2fs_swab16(test1[i]));
|
||||
if (ext2fs_swab16(test1[i]) != test1[i+1]) {
|
||||
printf("Error!!! %04x != %04x\n",
|
||||
ext2fs_swab16(test1[i]), test1[i+1]);
|
||||
errors++;
|
||||
}
|
||||
if (ext2fs_swab16(test1[i+1]) != test1[i]) {
|
||||
printf("Error!!! %04x != %04x\n",
|
||||
ext2fs_swab16(test1[i+1]), test1[i]);
|
||||
errors++;
|
||||
}
|
||||
i += 2;
|
||||
} while (test1[i] != 0);
|
||||
|
||||
printf("Testing ext2fs_swab32\n");
|
||||
i = 0;
|
||||
do {
|
||||
printf("swab32(0x%08x) = 0x%08x\n", test2[i],
|
||||
ext2fs_swab32(test2[i]));
|
||||
if (ext2fs_swab32(test2[i]) != test2[i+1]) {
|
||||
printf("Error!!! %04x != %04x\n",
|
||||
ext2fs_swab32(test2[i]), test2[i+1]);
|
||||
errors++;
|
||||
}
|
||||
if (ext2fs_swab32(test2[i+1]) != test2[i]) {
|
||||
printf("Error!!! %04x != %04x\n",
|
||||
ext2fs_swab32(test2[i+1]), test2[i]);
|
||||
errors++;
|
||||
}
|
||||
i += 2;
|
||||
} while (test2[i] != 0);
|
||||
|
||||
if (!errors)
|
||||
printf("No errors found in the byteswap implementation!\n");
|
||||
|
||||
return errors;
|
||||
}
|
||||
@@ -1,6 +0,0 @@
|
||||
command_table libext2fs_cmds;
|
||||
|
||||
request do_block_iterate, "block_iterate",
|
||||
block_iterate;
|
||||
|
||||
end;
|
||||
@@ -1,81 +0,0 @@
|
||||
/*
|
||||
* This testing program checks the offset of the ext2_filsys structure
|
||||
*
|
||||
* Copyright (C) 2007 by Theodore Ts'o.
|
||||
*
|
||||
* %Begin-Header%
|
||||
* This file may be redistributed under the terms of the GNU Library
|
||||
* General Public License, version 2.
|
||||
* %End-Header%
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "ext2fs.h"
|
||||
|
||||
struct struct_ext2_filsys fs;
|
||||
|
||||
#ifndef offsetof
|
||||
#define offsetof(type, member) __builtin_offsetof (type, member)
|
||||
#endif
|
||||
#define check_field(x) cur_offset = do_field(#x, sizeof(fs.x), \
|
||||
offsetof(struct struct_ext2_filsys, x), \
|
||||
cur_offset)
|
||||
|
||||
static int do_field(const char *field, size_t size, int offset, int cur_offset)
|
||||
{
|
||||
if (offset != cur_offset) {
|
||||
printf("\t(padding %d bytes?)\n", offset - cur_offset);
|
||||
}
|
||||
printf("%8d %-30s %3u\n", offset, field, (unsigned) size);
|
||||
return offset + size;
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
#if (__GNUC__ >= 4)
|
||||
int cur_offset = 0;
|
||||
|
||||
printf("%8s %-30s %3s\n", "offset", "field", "size");
|
||||
check_field(magic);
|
||||
check_field(io);
|
||||
check_field(flags);
|
||||
check_field(device_name);
|
||||
check_field(super);
|
||||
check_field(blocksize);
|
||||
check_field(fragsize);
|
||||
check_field(group_desc_count);
|
||||
check_field(desc_blocks);
|
||||
check_field(group_desc);
|
||||
check_field(inode_blocks_per_group);
|
||||
check_field(inode_map);
|
||||
check_field(block_map);
|
||||
check_field(get_blocks);
|
||||
check_field(check_directory);
|
||||
check_field(write_bitmaps);
|
||||
check_field(read_inode);
|
||||
check_field(write_inode);
|
||||
check_field(badblocks);
|
||||
check_field(dblist);
|
||||
check_field(stride);
|
||||
check_field(orig_super);
|
||||
check_field(image_header);
|
||||
check_field(umask);
|
||||
check_field(now);
|
||||
check_field(cluster_ratio_bits);
|
||||
check_field(reserved);
|
||||
check_field(priv_data);
|
||||
check_field(icache);
|
||||
check_field(image_io);
|
||||
check_field(get_alloc_block);
|
||||
check_field(block_alloc_stats);
|
||||
check_field(mmp_buf);
|
||||
check_field(mmp_cmp);
|
||||
check_field(mmp_fd);
|
||||
check_field(mmp_last_written);
|
||||
printf("Ending offset is %d\n\n", cur_offset);
|
||||
#endif
|
||||
exit(0);
|
||||
}
|
||||
@@ -1,63 +0,0 @@
|
||||
/*
|
||||
* tst_getsize.c --- this function tests the getsize function
|
||||
*
|
||||
* Copyright (C) 1997 by Theodore Ts'o.
|
||||
*
|
||||
* %Begin-Header%
|
||||
* This file may be redistributed under the terms of the GNU Library
|
||||
* General Public License, version 2.
|
||||
* %End-Header%
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#if HAVE_UNISTD_H
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
#include <fcntl.h>
|
||||
#include <time.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/types.h>
|
||||
#if HAVE_ERRNO_H
|
||||
#include <errno.h>
|
||||
#endif
|
||||
|
||||
#include "ext2_fs.h"
|
||||
#include "ext2fs.h"
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
int lsectsize, psectsize;
|
||||
int retval;
|
||||
int fd;
|
||||
|
||||
if (argc < 2) {
|
||||
fprintf(stderr, "Usage: %s device\n", argv[0]);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
retval = ext2fs_get_device_sectsize(argv[1], &lsectsize);
|
||||
if (retval) {
|
||||
com_err(argv[0], retval,
|
||||
"while calling ext2fs_get_device_sectsize");
|
||||
exit(1);
|
||||
}
|
||||
retval = ext2fs_get_device_phys_sectsize(argv[1], &psectsize);
|
||||
if (retval) {
|
||||
com_err(argv[0], retval,
|
||||
"while calling ext2fs_get_device_phys_sectsize");
|
||||
exit(1);
|
||||
}
|
||||
printf("Device %s has logical/physical sector size of %d/%d.\n",
|
||||
argv[1], lsectsize, psectsize);
|
||||
fd = open(argv[1], O_RDONLY);
|
||||
if (fd < 0) {
|
||||
perror("open");
|
||||
exit(1);
|
||||
}
|
||||
printf("The device's DIO alignment is %d\n",
|
||||
ext2fs_get_dio_alignment(fd));
|
||||
close(fd);
|
||||
exit(0);
|
||||
}
|
||||
@@ -1,47 +0,0 @@
|
||||
/*
|
||||
* tst_getsize.c --- this function tests the getsize function
|
||||
*
|
||||
* Copyright (C) 1997 by Theodore Ts'o.
|
||||
*
|
||||
* %Begin-Header%
|
||||
* This file may be redistributed under the terms of the GNU Library
|
||||
* General Public License, version 2.
|
||||
* %End-Header%
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#if HAVE_UNISTD_H
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
#include <fcntl.h>
|
||||
#include <time.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/types.h>
|
||||
#if HAVE_ERRNO_H
|
||||
#include <errno.h>
|
||||
#endif
|
||||
|
||||
#include "ext2_fs.h"
|
||||
#include "ext2fs.h"
|
||||
|
||||
int main(int argc, const char *argv[])
|
||||
{
|
||||
errcode_t retval;
|
||||
blk64_t blocks;
|
||||
|
||||
if (argc < 2) {
|
||||
fprintf(stderr, "%s device\n", argv[0]);
|
||||
exit(1);
|
||||
}
|
||||
add_error_table(&et_ext2_error_table);
|
||||
retval = ext2fs_get_device_size2(argv[1], 1024, &blocks);
|
||||
if (retval) {
|
||||
com_err(argv[0], retval, "while getting device size");
|
||||
exit(1);
|
||||
}
|
||||
printf("%s is device has %llu blocks.\n", argv[1],
|
||||
(unsigned long long) blocks);
|
||||
return 0;
|
||||
}
|
||||
@@ -1,89 +0,0 @@
|
||||
/*
|
||||
* This testing program makes sure the ext2_inode structure is 1024 bytes long
|
||||
*
|
||||
* Copyright (C) 2007 by Theodore Ts'o.
|
||||
*
|
||||
* %Begin-Header%
|
||||
* This file may be redistributed under the terms of the GNU Library
|
||||
* General Public License, version 2.
|
||||
* %End-Header%
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "ext2_fs.h"
|
||||
|
||||
struct ext2_inode_large inode;
|
||||
|
||||
#ifndef offsetof
|
||||
#define offsetof(type, member) __builtin_offsetof(type, member)
|
||||
#endif
|
||||
|
||||
#define check_field(x, s) cur_offset = do_field(#x, s, sizeof(inode.x), \
|
||||
offsetof(struct ext2_inode_large, x), \
|
||||
cur_offset)
|
||||
|
||||
static int do_field(const char *field, unsigned size, unsigned cur_size,
|
||||
unsigned offset, unsigned cur_offset)
|
||||
{
|
||||
if (size != cur_size) {
|
||||
printf("error: %s size %u should be %u\n",
|
||||
field, cur_size, size);
|
||||
exit(1);
|
||||
}
|
||||
if (offset != cur_offset) {
|
||||
printf("error: %s offset %u should be %u\n",
|
||||
field, cur_offset, offset);
|
||||
exit(1);
|
||||
}
|
||||
printf("%8d %-30s %3u\n", offset, field, (unsigned) size);
|
||||
return offset + size;
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
#if (__GNUC__ >= 4)
|
||||
int cur_offset = 0;
|
||||
|
||||
printf("%8s %-30s %3s\n", "offset", "field", "size");
|
||||
check_field(i_mode, 2);
|
||||
check_field(i_uid, 2);
|
||||
check_field(i_size, 4);
|
||||
check_field(i_atime, 4);
|
||||
check_field(i_ctime, 4);
|
||||
check_field(i_mtime, 4);
|
||||
check_field(i_dtime, 4);
|
||||
check_field(i_gid, 2);
|
||||
check_field(i_links_count, 2);
|
||||
check_field(i_blocks, 4);
|
||||
check_field(i_flags, 4);
|
||||
check_field(osd1.linux1.l_i_version, 4);
|
||||
check_field(i_block, 15 * 4);
|
||||
check_field(i_generation, 4);
|
||||
check_field(i_file_acl, 4);
|
||||
check_field(i_size_high, 4);
|
||||
check_field(i_faddr, 4);
|
||||
check_field(osd2.linux2.l_i_blocks_hi, 2);
|
||||
check_field(osd2.linux2.l_i_file_acl_high, 2);
|
||||
check_field(osd2.linux2.l_i_uid_high, 2);
|
||||
check_field(osd2.linux2.l_i_gid_high, 2);
|
||||
check_field(osd2.linux2.l_i_checksum_lo, 2);
|
||||
check_field(osd2.linux2.l_i_reserved, 2);
|
||||
do_field("Small inode end", 0, 0, cur_offset, 128);
|
||||
check_field(i_extra_isize, 2);
|
||||
check_field(i_checksum_hi, 2);
|
||||
check_field(i_ctime_extra, 4);
|
||||
check_field(i_mtime_extra, 4);
|
||||
check_field(i_atime_extra, 4);
|
||||
check_field(i_crtime, 4);
|
||||
check_field(i_crtime_extra, 4);
|
||||
check_field(i_version_hi, 4);
|
||||
check_field(i_projid, 4);
|
||||
/* This size will change as new fields are added */
|
||||
do_field("Large inode end", 0, 0, cur_offset, sizeof(inode));
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
@@ -1,227 +0,0 @@
|
||||
/*
|
||||
* tst_inode.c --- this function tests the inode scan function
|
||||
*
|
||||
* Copyright (C) 1996 by Theodore Ts'o.
|
||||
*
|
||||
* %Begin-Header%
|
||||
* This file may be redistributed under the terms of the GNU Library
|
||||
* General Public License, version 2.
|
||||
* %End-Header%
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#if HAVE_UNISTD_H
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
#include <fcntl.h>
|
||||
#include <time.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/types.h>
|
||||
#if HAVE_ERRNO_H
|
||||
#include <errno.h>
|
||||
#endif
|
||||
|
||||
#include "ext2_fs.h"
|
||||
#include "ext2fs.h"
|
||||
|
||||
blk64_t test_vec[] = { 8, 12, 24, 34, 43, 44, 100, 0 };
|
||||
|
||||
ext2_filsys test_fs;
|
||||
ext2fs_block_bitmap bad_block_map, touched_map;
|
||||
ext2fs_inode_bitmap bad_inode_map;
|
||||
badblocks_list test_badblocks;
|
||||
|
||||
int first_no_comma = 1;
|
||||
int failed = 0;
|
||||
|
||||
static void iscan_test_read_blk64(unsigned long long block, int count, errcode_t err)
|
||||
{
|
||||
int i;
|
||||
|
||||
if (first_no_comma)
|
||||
first_no_comma = 0;
|
||||
else
|
||||
printf(", ");
|
||||
|
||||
if (count > 1)
|
||||
printf("%llu-%llu", block, block+count-1);
|
||||
else
|
||||
printf("%llu", block);
|
||||
|
||||
for (i=0; i < count; i++, block++) {
|
||||
if (ext2fs_test_block_bitmap2(touched_map, block)) {
|
||||
printf("\nDuplicate block?!? --- %llu\n", block);
|
||||
failed++;
|
||||
first_no_comma = 1;
|
||||
}
|
||||
ext2fs_mark_block_bitmap2(touched_map, block);
|
||||
}
|
||||
}
|
||||
|
||||
static void iscan_test_read_blk(unsigned long block, int count, errcode_t err)
|
||||
{
|
||||
iscan_test_read_blk64(block, count, err);
|
||||
}
|
||||
|
||||
/*
|
||||
* Setup the variables for doing the inode scan test.
|
||||
*/
|
||||
static void setup(void)
|
||||
{
|
||||
errcode_t retval;
|
||||
int i;
|
||||
struct ext2_super_block param;
|
||||
|
||||
initialize_ext2_error_table();
|
||||
|
||||
memset(¶m, 0, sizeof(param));
|
||||
ext2fs_blocks_count_set(¶m, 12000);
|
||||
|
||||
|
||||
test_io_cb_read_blk = iscan_test_read_blk;
|
||||
test_io_cb_read_blk64 = iscan_test_read_blk64;
|
||||
|
||||
retval = ext2fs_initialize("test fs", EXT2_FLAG_64BITS, ¶m,
|
||||
test_io_manager, &test_fs);
|
||||
if (retval) {
|
||||
com_err("setup", retval,
|
||||
"While initializing filesystem");
|
||||
exit(1);
|
||||
}
|
||||
retval = ext2fs_allocate_tables(test_fs);
|
||||
if (retval) {
|
||||
com_err("setup", retval,
|
||||
"While allocating tables for test filesystem");
|
||||
exit(1);
|
||||
}
|
||||
retval = ext2fs_allocate_block_bitmap(test_fs, "bad block map",
|
||||
&bad_block_map);
|
||||
if (retval) {
|
||||
com_err("setup", retval,
|
||||
"While allocating bad_block bitmap");
|
||||
exit(1);
|
||||
}
|
||||
retval = ext2fs_allocate_block_bitmap(test_fs, "touched map",
|
||||
&touched_map);
|
||||
if (retval) {
|
||||
com_err("setup", retval,
|
||||
"While allocating touched block bitmap");
|
||||
exit(1);
|
||||
}
|
||||
retval = ext2fs_allocate_inode_bitmap(test_fs, "bad inode map",
|
||||
&bad_inode_map);
|
||||
if (retval) {
|
||||
com_err("setup", retval,
|
||||
"While allocating bad inode bitmap");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
retval = ext2fs_badblocks_list_create(&test_badblocks, 5);
|
||||
if (retval) {
|
||||
com_err("setup", retval, "while creating badblocks list");
|
||||
exit(1);
|
||||
}
|
||||
for (i=0; test_vec[i]; i++) {
|
||||
retval = ext2fs_badblocks_list_add(test_badblocks, test_vec[i]);
|
||||
if (retval) {
|
||||
com_err("setup", retval,
|
||||
"while adding test vector %d", i);
|
||||
exit(1);
|
||||
}
|
||||
ext2fs_mark_block_bitmap2(bad_block_map, test_vec[i]);
|
||||
}
|
||||
test_fs->badblocks = test_badblocks;
|
||||
}
|
||||
|
||||
/*
|
||||
* Iterate using inode_scan
|
||||
*/
|
||||
static void iterate(void)
|
||||
{
|
||||
struct ext2_inode inode;
|
||||
ext2_inode_scan scan;
|
||||
errcode_t retval;
|
||||
ext2_ino_t ino;
|
||||
|
||||
retval = ext2fs_open_inode_scan(test_fs, 8, &scan);
|
||||
if (retval) {
|
||||
com_err("iterate", retval, "While opening inode scan");
|
||||
exit(1);
|
||||
}
|
||||
printf("Reading blocks: ");
|
||||
retval = ext2fs_get_next_inode(scan, &ino, &inode);
|
||||
if (retval) {
|
||||
com_err("iterate", retval, "while reading first inode");
|
||||
exit(1);
|
||||
}
|
||||
while (ino) {
|
||||
retval = ext2fs_get_next_inode(scan, &ino, &inode);
|
||||
if (retval == EXT2_ET_BAD_BLOCK_IN_INODE_TABLE) {
|
||||
ext2fs_mark_inode_bitmap2(bad_inode_map, ino);
|
||||
continue;
|
||||
}
|
||||
if (retval) {
|
||||
com_err("iterate", retval,
|
||||
"while getting next inode");
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
printf("\n");
|
||||
ext2fs_close_inode_scan(scan);
|
||||
}
|
||||
|
||||
/*
|
||||
* Verify the touched map
|
||||
*/
|
||||
static void check_map(void)
|
||||
{
|
||||
int i, j, first=1;
|
||||
blk64_t blk;
|
||||
|
||||
for (i=0; test_vec[i]; i++) {
|
||||
if (ext2fs_test_block_bitmap2(touched_map, test_vec[i])) {
|
||||
printf("Bad block was touched --- %llu\n",
|
||||
(unsigned long long) test_vec[i]);
|
||||
failed++;
|
||||
first_no_comma = 1;
|
||||
}
|
||||
ext2fs_mark_block_bitmap2(touched_map, test_vec[i]);
|
||||
}
|
||||
for (i = 0; i < test_fs->group_desc_count; i++) {
|
||||
for (j=0, blk = ext2fs_inode_table_loc(test_fs, i);
|
||||
j < test_fs->inode_blocks_per_group;
|
||||
j++, blk++) {
|
||||
if (!ext2fs_test_block_bitmap2(touched_map, blk) &&
|
||||
!ext2fs_test_block_bitmap2(bad_block_map, blk)) {
|
||||
printf("Missing block --- %llu\n",
|
||||
(unsigned long long) blk);
|
||||
failed++;
|
||||
}
|
||||
}
|
||||
}
|
||||
printf("Bad inodes: ");
|
||||
for (i=1; i <= test_fs->super->s_inodes_count; i++) {
|
||||
if (ext2fs_test_inode_bitmap2(bad_inode_map, i)) {
|
||||
if (first)
|
||||
first = 0;
|
||||
else
|
||||
printf(", ");
|
||||
printf("%u", i);
|
||||
}
|
||||
}
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
setup();
|
||||
iterate();
|
||||
check_map();
|
||||
if (!failed)
|
||||
printf("Inode scan tested OK!\n");
|
||||
return failed;
|
||||
}
|
||||
|
||||
@@ -1,72 +0,0 @@
|
||||
/*
|
||||
* tst_libext2fs.c
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#if HAVE_UNISTD_H
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
#if HAVE_ERRNO_H
|
||||
#include <errno.h>
|
||||
#endif
|
||||
#if HAVE_SYS_STAT_H
|
||||
#include <sys/stat.h>
|
||||
#endif
|
||||
#if HAVE_SYS_TYPES_H
|
||||
#include <sys/types.h>
|
||||
#endif
|
||||
|
||||
#include "ext2_fs.h"
|
||||
#include "ext2fsP.h"
|
||||
|
||||
#include "ss/ss.h"
|
||||
#include "debugfs.h"
|
||||
|
||||
/*
|
||||
* Hook in new commands into debugfs
|
||||
* Override debugfs's prompt
|
||||
*/
|
||||
const char *debug_prog_name = "tst_libext2fs";
|
||||
extern ss_request_table libext2fs_cmds;
|
||||
ss_request_table *extra_cmds = &libext2fs_cmds;
|
||||
|
||||
static int print_blocks_proc(ext2_filsys fs EXT2FS_ATTR((unused)),
|
||||
blk64_t *blocknr, e2_blkcnt_t blockcnt,
|
||||
blk64_t ref_block, int ref_offset,
|
||||
void *private EXT2FS_ATTR((unused)))
|
||||
{
|
||||
printf("%6lld %8llu (%d %llu)\n", (long long) blockcnt,
|
||||
(unsigned long long) *blocknr, ref_offset,
|
||||
(unsigned long long) ref_block);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
void do_block_iterate(int argc, char **argv, int sci_idx EXT2FS_ATTR((unused)),
|
||||
void *infop EXT2FS_ATTR((unused)))
|
||||
{
|
||||
const char *usage = "block_iterate <file> <flags";
|
||||
ext2_ino_t ino;
|
||||
int err = 0;
|
||||
int flags = 0;
|
||||
|
||||
if (common_args_process(argc, argv, 2, 3, argv[0], usage, 0))
|
||||
return;
|
||||
|
||||
ino = string_to_inode(argv[1]);
|
||||
if (!ino)
|
||||
return;
|
||||
|
||||
if (argc > 2) {
|
||||
flags = parse_ulong(argv[2], argv[0], "flags", &err);
|
||||
if (err)
|
||||
return;
|
||||
}
|
||||
flags |= BLOCK_FLAG_READ_ONLY;
|
||||
|
||||
ext2fs_block_iterate3(current_fs, ino, flags, NULL,
|
||||
print_blocks_proc, NULL);
|
||||
putc('\n', stdout);
|
||||
}
|
||||
@@ -1,160 +0,0 @@
|
||||
/*
|
||||
* This testing program makes sure superblock size is 1024 bytes long
|
||||
*
|
||||
* Copyright (C) 2007 by Theodore Ts'o.
|
||||
*
|
||||
* %Begin-Header%
|
||||
* This file may be redistributed under the terms of the GNU Library
|
||||
* General Public License, version 2.
|
||||
* %End-Header%
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "ext2_fs.h"
|
||||
|
||||
#define sb_struct ext2_super_block
|
||||
#define sb_struct_name "ext2_super_block"
|
||||
|
||||
struct sb_struct sb;
|
||||
|
||||
#ifndef offsetof
|
||||
#define offsetof(type, member) __builtin_offsetof (type, member)
|
||||
#endif
|
||||
|
||||
#define check_field(x, s) cur_offset = do_field(#x, s, sizeof(sb.x), \
|
||||
offsetof(struct sb_struct, x), \
|
||||
cur_offset)
|
||||
|
||||
static int do_field(const char *field, unsigned size, unsigned cur_size,
|
||||
unsigned offset, unsigned cur_offset)
|
||||
{
|
||||
if (size != cur_size) {
|
||||
printf("error: %s size %u should be %u\n",
|
||||
field, cur_size, size);
|
||||
exit(1);
|
||||
}
|
||||
if (offset != cur_offset) {
|
||||
printf("error: %s offset %u should be %u\n",
|
||||
field, cur_offset, offset);
|
||||
exit(1);
|
||||
}
|
||||
printf("%8d %-30s %3u\n", offset, field, size);
|
||||
return offset + size;
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
#if (__GNUC__ >= 4)
|
||||
int cur_offset = 0;
|
||||
|
||||
printf("%8s %-30s %3s\n", "offset", "field", "size");
|
||||
check_field(s_inodes_count, 4);
|
||||
check_field(s_blocks_count, 4);
|
||||
check_field(s_r_blocks_count, 4);
|
||||
check_field(s_free_blocks_count, 4);
|
||||
check_field(s_free_inodes_count, 4);
|
||||
check_field(s_first_data_block, 4);
|
||||
check_field(s_log_block_size, 4);
|
||||
check_field(s_log_cluster_size, 4);
|
||||
check_field(s_blocks_per_group, 4);
|
||||
check_field(s_clusters_per_group, 4);
|
||||
check_field(s_inodes_per_group, 4);
|
||||
check_field(s_mtime, 4);
|
||||
check_field(s_wtime, 4);
|
||||
check_field(s_mnt_count, 2);
|
||||
check_field(s_max_mnt_count, 2);
|
||||
check_field(s_magic, 2);
|
||||
check_field(s_state, 2);
|
||||
check_field(s_errors, 2);
|
||||
check_field(s_minor_rev_level, 2);
|
||||
check_field(s_lastcheck, 4);
|
||||
check_field(s_checkinterval, 4);
|
||||
check_field(s_creator_os, 4);
|
||||
check_field(s_rev_level, 4);
|
||||
check_field(s_def_resuid, 2);
|
||||
check_field(s_def_resgid, 2);
|
||||
check_field(s_first_ino, 4);
|
||||
check_field(s_inode_size, 2);
|
||||
check_field(s_block_group_nr, 2);
|
||||
check_field(s_feature_compat, 4);
|
||||
check_field(s_feature_incompat, 4);
|
||||
check_field(s_feature_ro_compat, 4);
|
||||
check_field(s_uuid, 16);
|
||||
check_field(s_volume_name, 16);
|
||||
check_field(s_last_mounted, 64);
|
||||
check_field(s_algorithm_usage_bitmap, 4);
|
||||
check_field(s_prealloc_blocks, 1);
|
||||
check_field(s_prealloc_dir_blocks, 1);
|
||||
check_field(s_reserved_gdt_blocks, 2);
|
||||
check_field(s_journal_uuid, 16);
|
||||
check_field(s_journal_inum, 4);
|
||||
check_field(s_journal_dev, 4);
|
||||
check_field(s_last_orphan, 4);
|
||||
check_field(s_hash_seed, 4 * 4);
|
||||
check_field(s_def_hash_version, 1);
|
||||
check_field(s_jnl_backup_type, 1);
|
||||
check_field(s_desc_size, 2);
|
||||
check_field(s_default_mount_opts, 4);
|
||||
check_field(s_first_meta_bg, 4);
|
||||
check_field(s_mkfs_time, 4);
|
||||
check_field(s_jnl_blocks, 17 * 4);
|
||||
check_field(s_blocks_count_hi, 4);
|
||||
check_field(s_r_blocks_count_hi, 4);
|
||||
check_field(s_free_blocks_hi, 4);
|
||||
check_field(s_min_extra_isize, 2);
|
||||
check_field(s_want_extra_isize, 2);
|
||||
check_field(s_flags, 4);
|
||||
check_field(s_raid_stride, 2);
|
||||
check_field(s_mmp_update_interval, 2);
|
||||
check_field(s_mmp_block, 8);
|
||||
check_field(s_raid_stripe_width, 4);
|
||||
check_field(s_log_groups_per_flex, 1);
|
||||
check_field(s_checksum_type, 1);
|
||||
check_field(s_encryption_level, 1);
|
||||
check_field(s_reserved_pad, 1);
|
||||
check_field(s_kbytes_written, 8);
|
||||
check_field(s_snapshot_inum, 4);
|
||||
check_field(s_snapshot_id, 4);
|
||||
check_field(s_snapshot_r_blocks_count, 8);
|
||||
check_field(s_snapshot_list, 4);
|
||||
check_field(s_error_count, 4);
|
||||
check_field(s_first_error_time, 4);
|
||||
check_field(s_first_error_ino, 4);
|
||||
check_field(s_first_error_block, 8);
|
||||
check_field(s_first_error_func, 32);
|
||||
check_field(s_first_error_line, 4);
|
||||
check_field(s_last_error_time, 4);
|
||||
check_field(s_last_error_ino, 4);
|
||||
check_field(s_last_error_line, 4);
|
||||
check_field(s_last_error_block, 8);
|
||||
check_field(s_last_error_func, 32);
|
||||
check_field(s_mount_opts, 64);
|
||||
check_field(s_usr_quota_inum, 4);
|
||||
check_field(s_grp_quota_inum, 4);
|
||||
check_field(s_overhead_clusters, 4);
|
||||
check_field(s_backup_bgs, 8);
|
||||
check_field(s_encrypt_algos, 4);
|
||||
check_field(s_encrypt_pw_salt, 16);
|
||||
check_field(s_lpf_ino, 4);
|
||||
check_field(s_prj_quota_inum, 4);
|
||||
check_field(s_checksum_seed, 4);
|
||||
check_field(s_wtime_hi, 1);
|
||||
check_field(s_mtime_hi, 1);
|
||||
check_field(s_mkfs_time_hi, 1);
|
||||
check_field(s_lastcheck_hi, 1);
|
||||
check_field(s_first_error_time_hi, 1);
|
||||
check_field(s_last_error_time_hi, 1);
|
||||
check_field(s_first_error_errcode, 1);
|
||||
check_field(s_last_error_errcode, 1);
|
||||
check_field(s_encoding, 2);
|
||||
check_field(s_encoding_flags, 2);
|
||||
check_field(s_reserved, 95 * 4);
|
||||
check_field(s_checksum, 4);
|
||||
do_field("Superblock end", 0, 0, cur_offset, 1024);
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
@@ -1,64 +0,0 @@
|
||||
/*
|
||||
* This testing program makes sure the ext2_types header file
|
||||
*
|
||||
* Copyright (C) 2006 by Theodore Ts'o.
|
||||
*
|
||||
* %Begin-Header%
|
||||
* This file may be redistributed under the terms of the GNU Library
|
||||
* General Public License, version 2.
|
||||
* %End-Header%
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "ext2fs/ext2_types.h"
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
if (sizeof(__u8) != 1) {
|
||||
printf("Sizeof(__u8) is %d should be 1\n",
|
||||
(int)sizeof(__u8));
|
||||
exit(1);
|
||||
}
|
||||
if (sizeof(__s8) != 1) {
|
||||
printf("Sizeof(_s8) is %d should be 1\n",
|
||||
(int)sizeof(__s8));
|
||||
exit(1);
|
||||
}
|
||||
if (sizeof(__u16) != 2) {
|
||||
printf("Sizeof(__u16) is %d should be 2\n",
|
||||
(int)sizeof(__u16));
|
||||
exit(1);
|
||||
}
|
||||
if (sizeof(__s16) != 2) {
|
||||
printf("Sizeof(__s16) is %d should be 2\n",
|
||||
(int)sizeof(__s16));
|
||||
exit(1);
|
||||
}
|
||||
if (sizeof(__u32) != 4) {
|
||||
printf("Sizeof(__u32) is %d should be 4\n",
|
||||
(int)sizeof(__u32));
|
||||
exit(1);
|
||||
}
|
||||
if (sizeof(__s32) != 4) {
|
||||
printf("Sizeof(__s32) is %d should be 4\n",
|
||||
(int)sizeof(__s32));
|
||||
exit(1);
|
||||
}
|
||||
if (sizeof(__u64) != 8) {
|
||||
printf("Sizeof(__u64) is %d should be 8\n",
|
||||
(int)sizeof(__u64));
|
||||
exit(1);
|
||||
}
|
||||
if (sizeof(__s64) != 8) {
|
||||
printf("Sizeof(__s64) is %d should be 8\n",
|
||||
(int)sizeof(__s64));
|
||||
exit(1);
|
||||
}
|
||||
printf("The ext2_types.h types are correct.\n");
|
||||
exit(0);
|
||||
}
|
||||
|
||||
@@ -3,8 +3,8 @@
|
||||
# By YZBruh | ShawkTeam
|
||||
|
||||
# Variables
|
||||
LOCAL_VERSION="2.9.1"
|
||||
LOCAL_RELDATE="20241003"
|
||||
LOCAL_VERSION="2.9.6"
|
||||
LOCAL_RELDATE="20241026"
|
||||
LOCAL_OWNER="ShawkTeam"
|
||||
LOCAL_REPO="pmt"
|
||||
LOCAL_RELEASE_TAG="${LOCAL_VERSION}"
|
||||
@@ -257,9 +257,10 @@ while (($# >= 1)); do
|
||||
;;
|
||||
--package)
|
||||
PACKAGE=true
|
||||
[ -z ${2} ] \
|
||||
&& printc "Option '--package' requires an argument (file)." \
|
||||
&& exit 1
|
||||
[ -z ${2} ] && \
|
||||
{ printc "Option '--package' requires an argument (file)."
|
||||
exit 1
|
||||
}
|
||||
LOCAL_PACKAGE="${2}"
|
||||
ALREADY_SHIFT=true && shift 1
|
||||
;;
|
||||
@@ -285,7 +286,7 @@ while (($# >= 1)); do
|
||||
done
|
||||
|
||||
### Main ###
|
||||
[ -z "${1}" -a "${SOME_SPEC}" != 1 ] && view_help && exit 1
|
||||
[ -z "${1}" -a "${SOME_SPEC}" != 1 ] && { view_help; exit 1; }
|
||||
|
||||
if [ "${PROCESS}" = 1 -o "${PROCESS}" = 2 ]; then
|
||||
script_head
|
||||
|
||||
Reference in New Issue
Block a user