Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| f6176009b1 | |||
| f903842054 |
@@ -94,6 +94,10 @@ PRODUCT_PACKAGES += \
|
||||
PawletSetupWizard \
|
||||
BgUpd
|
||||
|
||||
# bg-upd's own sepolicy domain — lives in its own repo (packages/apps/BgUpd/sepolicy),
|
||||
# included unconditionally since it's a core PawletOS system app, not an optional one.
|
||||
BOARD_SEPOLICY_DIRS += packages/apps/BgUpd/sepolicy
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# Day-one default WebView provider (com.android.webview / "chromium"), so the
|
||||
# device boots with a working WebView before bg-upd's first check ever runs.
|
||||
|
||||
@@ -42,6 +42,17 @@ PAWLET_VERSION := $(PAWLET_MAJOR_VERSION).$(PAWLET_MINOR_VERSION)-$(PAWLET_VERSI
|
||||
# Short display version (major-suffix, like LineageOS 23-<suffix>)
|
||||
PAWLET_DISPLAY_VERSION := $(PAWLET_MAJOR_VERSION)-$(PAWLET_VERSION_SUFFIX)
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# Security patch level
|
||||
# ---------------------------------------------------------------------------
|
||||
# Bumped manually whenever a monthly AOSP security bulletin's patches are
|
||||
# actually backported into the tree — this is a record of work done, not
|
||||
# something CI infers automatically. See PawletOS-Build/docs/security-patch-process.md
|
||||
# and PawletOS-Build/scripts/check_security_patch.py (run the latter to see
|
||||
# how far behind this date is against the latest published AOSP bulletin).
|
||||
PAWLET_SECURITY_PATCH := 2026-07-05
|
||||
PLATFORM_SECURITY_PATCH := $(PAWLET_SECURITY_PATCH)
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# System properties written into /product/build.prop
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
@@ -0,0 +1,64 @@
|
||||
# recovery_toolkit
|
||||
|
||||
TWRP's partition manager, backup engine, filesystem/format support, and
|
||||
scripting/automation tooling — the "standalone additive" bucket from the
|
||||
TWRP-vs-stock-recovery diff (confirmed via source grep: zero references
|
||||
either direction between this code and `recovery.cpp`/`install/install.cpp`,
|
||||
so none of it requires forking stock `bootable/recovery`). See the main
|
||||
workspace's `NOTES-ota-recovery-ab.md` for the full investigation.
|
||||
|
||||
Source copied verbatim from TeamWin's `android_bootable_recovery`
|
||||
(`android-14.1`), the only living copy found (Google removed the equivalent
|
||||
functionality's siblings — `applypatch`/`updater`/`edify` — from stock AOSP
|
||||
in 2024; see `external_update_binary`).
|
||||
|
||||
## Status: source staged, no build files yet
|
||||
|
||||
This is source-only. **None of these directories have an `Android.bp` yet.**
|
||||
That's real remaining work, not cleanup — each of these historically had its
|
||||
module definition scattered inside TWRP's single top-level
|
||||
`bootable/recovery/Android.bp`, not self-contained per-directory the way
|
||||
`applypatch`/`updater`/`edify` were, so each needs a new `Android.bp`
|
||||
written from scratch, not just copied and path-fixed.
|
||||
|
||||
## Layout
|
||||
|
||||
- `partitionmanager/` — `partition.cpp`, `partitionmanager.cpp`,
|
||||
`partitions.hpp`, `BasePartition.cpp`.
|
||||
- `backup/` — `twrpTar.*`, `tarWrite.*`, `twrpDigestDriver.*`,
|
||||
`twrpAdbBuFifo.*`, `twrpApex.*`, `infomanager.*`, plus `libtar/`,
|
||||
`twrpDigest/`, `adbbu/`, `twrpTarMain/` (each of those four already has
|
||||
its own directory structure from upstream, not yet inspected for existing
|
||||
build files).
|
||||
- Filesystem/format support: `exfat/`, `dosfstools/`, `libblkid/`,
|
||||
`simg2img/`, `minzip/`, `openaes/`, `gpt/`, `fuse/` (+ `fuse.h`), `mtp/`,
|
||||
`crypto/`.
|
||||
- `scripting/` (`openrecoveryscript.*`) + `orscmd/` + `twrpinstall/` —
|
||||
TWRP's scripting/automation interface. `twrpinstall/` is referenced by
|
||||
`recovery_ui/gui/Android.bp`'s `include_dirs` already (this module needs
|
||||
to exist before `recovery_ui` can build).
|
||||
- `helpers/` — shared utilities (`find_file.*`, `exclude.*`,
|
||||
`fixContexts.*`, `mounts.c`, `startupArgs.*`, `progresstracking.*`,
|
||||
`kernel_module_loader.*`, `abx-functions.hpp`, `twrp-functions.*`,
|
||||
`twrp.cpp`), plus `libcrecovery/`, `libmincrypt/`, `attr/`.
|
||||
|
||||
## Known gap shared with recovery_ui
|
||||
|
||||
`helpers/twrp.cpp` needs to build into `libaosprecovery` — TWRP builds this
|
||||
via a custom Go Soong plugin (`libaosprecovery_defaults.go`, not yet
|
||||
copied/ported) that `recovery_ui/gui`'s `libguitwrp` depends on as a
|
||||
`shared_libs` entry. `recovery_ui` won't link until this exists.
|
||||
|
||||
## Priority if picking up this work
|
||||
|
||||
`twrpinstall/` and `helpers/` (for `libaosprecovery`) block `recovery_ui`
|
||||
from building at all — do those first. `partitionmanager/` and `backup/`
|
||||
are the actual user-facing value (what makes this "TWRP" rather than just a
|
||||
GUI skin) and are next. Filesystem/format support modules
|
||||
(`exfat`/`dosfstools`/etc.) can come last — they're each independent and
|
||||
only needed for the specific formats they support.
|
||||
|
||||
## License
|
||||
|
||||
GPL-3.0 (TeamWin) — same situation as `recovery_ui`, full license text not
|
||||
yet added to this repo.
|
||||
@@ -0,0 +1,47 @@
|
||||
LOCAL_PATH:= $(call my-dir)
|
||||
|
||||
include $(CLEAR_VARS)
|
||||
LOCAL_MODULE := libtwadbbu
|
||||
LOCAL_MODULE_TAGS := optional
|
||||
LOCAL_CFLAGS = -fno-strict-aliasing -D_LARGFILE_SOURCE #-D_DEBUG_ADB_BACKUP
|
||||
LOCAL_C_INCLUDES += bionic external/zlib
|
||||
ifeq ($(shell test $(PLATFORM_SDK_VERSION) -lt 23; echo $$?),0)
|
||||
LOCAL_C_INCLUDES += external/stlport/stlport
|
||||
endif
|
||||
|
||||
LOCAL_SRC_FILES = \
|
||||
libtwadbbu.cpp \
|
||||
twrpback.cpp
|
||||
|
||||
LOCAL_SHARED_LIBRARIES += libz libc libstdc++ libtwrpdigest
|
||||
|
||||
ifeq ($(shell test $(PLATFORM_SDK_VERSION) -lt 23; echo $$?),0)
|
||||
LOCAL_SHARED_LIBRARIES += libstlport
|
||||
else
|
||||
LOCAL_SHARED_LIBRARIES += libc++
|
||||
endif
|
||||
|
||||
include $(BUILD_SHARED_LIBRARY)
|
||||
|
||||
include $(CLEAR_VARS)
|
||||
|
||||
LOCAL_SRC_FILES:= \
|
||||
adbbumain.cpp
|
||||
|
||||
LOCAL_SHARED_LIBRARIES += libstdc++ libz libtwadbbu
|
||||
|
||||
ifeq ($(shell test $(PLATFORM_SDK_VERSION) -lt 23; echo $$?),0)
|
||||
LOCAL_C_INCLUDES += external/stlport/stlport
|
||||
LOCAL_SHARED_LIBRARIES += libstlport
|
||||
else
|
||||
LOCAL_SHARED_LIBRARIES += libc++
|
||||
endif
|
||||
|
||||
LOCAL_C_INCLUDES += bionic external/zlib
|
||||
LOCAL_CFLAGS:= -c -W
|
||||
LOCAL_MODULE:= twrpbu
|
||||
LOCAL_MODULE_STEM := bu
|
||||
LOCAL_MODULE_TAGS:= optional
|
||||
LOCAL_MODULE_CLASS := RECOVERY_EXECUTABLES
|
||||
LOCAL_MODULE_PATH := $(TARGET_RECOVERY_ROOT_OUT)/system/bin
|
||||
include $(BUILD_EXECUTABLE)
|
||||
@@ -0,0 +1,95 @@
|
||||
/*
|
||||
Copyright 2013 to 2017 TeamWin
|
||||
TWRP 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 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
TWRP 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 TWRP. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <string.h>
|
||||
#include <fcntl.h>
|
||||
#include <errno.h>
|
||||
#include <ctype.h>
|
||||
#include <string>
|
||||
#include <sstream>
|
||||
#include <algorithm>
|
||||
|
||||
#include "twrpback.hpp"
|
||||
#include "twadbstream.h"
|
||||
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
int index;
|
||||
size_t pos = 0;
|
||||
bool ret = false;
|
||||
size_t maxpos = strlen(TWRPARG) + 2;
|
||||
std::string command;
|
||||
twrpback tw;
|
||||
|
||||
tw.adblogwrite("Starting adb backup and restore\n");
|
||||
command = argv[1];
|
||||
for (index = 2; index < argc; index++) {
|
||||
command = command + " " + argv[index];
|
||||
}
|
||||
|
||||
pos = command.find(TWRP_BACKUP_ARG);
|
||||
if (pos == std::string::npos || pos > (maxpos + strlen(TWRP_BACKUP_ARG) + 1)) {
|
||||
pos = command.find(TWRP_RESTORE_ARG);
|
||||
}
|
||||
if (pos == std::string::npos || pos > maxpos + strlen(TWRP_STREAM_ARG) + 1) {
|
||||
pos = command.find(TWRP_STREAM_ARG);
|
||||
}
|
||||
|
||||
tw.adblogwrite("command: " + command + "\n");
|
||||
command.erase(0, pos);
|
||||
command.erase(std::remove(command.begin(), command.end(), '\''), command.end());
|
||||
|
||||
if (command.substr(0, sizeof(TWRP_BACKUP_ARG) - 1) == TWRP_BACKUP_ARG) {
|
||||
tw.adblogwrite("Starting adb backup\n");
|
||||
if (isdigit(*argv[1]))
|
||||
tw.adbd_fd = atoi(argv[1]);
|
||||
else
|
||||
tw.adbd_fd = 1;
|
||||
ret = tw.backup(command);
|
||||
}
|
||||
else if (command.substr(0, sizeof(TWRP_RESTORE_ARG) - 1) == TWRP_RESTORE_ARG) {
|
||||
tw.adblogwrite("Starting adb restore\n");
|
||||
if (isdigit(*argv[1]))
|
||||
tw.adbd_fd = atoi(argv[1]);
|
||||
else
|
||||
tw.adbd_fd = 0;
|
||||
ret = tw.restore();
|
||||
}
|
||||
else if (command.substr(0, sizeof(TWRP_STREAM_ARG) - 1) == TWRP_STREAM_ARG) {
|
||||
tw.setStreamFileName(argv[3]);
|
||||
tw.threadStream();
|
||||
ret = true;
|
||||
}
|
||||
if (ret)
|
||||
tw.adblogwrite("Adb backup/restore completed\n");
|
||||
else
|
||||
tw.adblogwrite("Adb backup/restore failed\n");
|
||||
|
||||
if (unlink(TW_ADB_BU_CONTROL) < 0) {
|
||||
std::stringstream str;
|
||||
str << strerror(errno);
|
||||
tw.adblogwrite("Unable to remove TW_ADB_BU_CONTROL: " + str.str());
|
||||
}
|
||||
unlink(TW_ADB_TWRP_CONTROL);
|
||||
if (ret)
|
||||
return 0;
|
||||
else
|
||||
return -1;
|
||||
}
|
||||
@@ -0,0 +1,307 @@
|
||||
/*
|
||||
Copyright 2013 to 2017 TeamWin
|
||||
TWRP 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 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
TWRP 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 TWRP. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <string.h>
|
||||
#include <fcntl.h>
|
||||
#include <errno.h>
|
||||
#include <zlib.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/select.h>
|
||||
#include <sys/time.h>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <fstream>
|
||||
#include <sstream>
|
||||
#include <assert.h>
|
||||
|
||||
#include "twadbstream.h"
|
||||
#include "libtwadbbu.hpp"
|
||||
#include "twrpback.hpp"
|
||||
|
||||
bool twadbbu::Check_ADB_Backup_File(std::string fname) {
|
||||
struct AdbBackupStreamHeader adbbuhdr;
|
||||
uint32_t crc, adbbuhdrcrc;
|
||||
unsigned char buf[MAX_ADB_READ];
|
||||
int bytes;
|
||||
|
||||
int fd = open(fname.c_str(), O_RDONLY);
|
||||
if (fd < 0) {
|
||||
printf("Unable to open %s for reading: %s.\n", fname.c_str(), strerror(errno));
|
||||
close(fd);
|
||||
return false;
|
||||
}
|
||||
bytes = read(fd, &buf, sizeof(buf));
|
||||
close(fd);
|
||||
|
||||
if (memcpy(&adbbuhdr, buf, sizeof(adbbuhdr)) == NULL) {
|
||||
printf("Unable to memcpy: %s (%s).\n", fname.c_str(), strerror(errno));
|
||||
return false;
|
||||
}
|
||||
adbbuhdrcrc = adbbuhdr.crc;
|
||||
memset(&adbbuhdr.crc, 0, sizeof(adbbuhdr.crc));
|
||||
crc = crc32(0L, Z_NULL, 0);
|
||||
crc = crc32(crc, (const unsigned char*) &adbbuhdr, sizeof(adbbuhdr));
|
||||
|
||||
return (crc == adbbuhdrcrc);
|
||||
}
|
||||
|
||||
std::vector<std::string> twadbbu::Get_ADB_Backup_Files(std::string fname) {
|
||||
unsigned char buf[MAX_ADB_READ];
|
||||
struct AdbBackupControlType structcmd;
|
||||
std::vector<std::string> adb_partitions;
|
||||
|
||||
int fd = open(fname.c_str(), O_RDONLY);
|
||||
if (fd < 0) {
|
||||
printf("Unable to open %s for reading: %s\n", fname.c_str(), strerror(errno));
|
||||
close(fd);
|
||||
return std::vector<std::string>();
|
||||
}
|
||||
|
||||
while (true) {
|
||||
std::string cmdstr;
|
||||
int readbytes;
|
||||
if ((readbytes = read(fd, &buf, sizeof(buf))) > 0) {
|
||||
memcpy(&structcmd, buf, sizeof(structcmd));
|
||||
assert(structcmd.type == TWENDADB || structcmd.type == TWIMG || structcmd.type == TWFN);
|
||||
cmdstr = structcmd.type;
|
||||
std::string cmdtype = cmdstr.substr(0, sizeof(structcmd.type) - 1);
|
||||
if (cmdtype == TWENDADB) {
|
||||
struct AdbBackupControlType endadb;
|
||||
uint32_t crc, endadbcrc;
|
||||
|
||||
memcpy(&endadb, buf, sizeof(endadb));
|
||||
endadbcrc = endadb.crc;
|
||||
memset(&endadb.crc, 0, sizeof(endadb.crc));
|
||||
crc = crc32(0L, Z_NULL, 0);
|
||||
crc = crc32(crc, (const unsigned char*) &endadb, sizeof(endadb));
|
||||
|
||||
if (crc == endadbcrc) {
|
||||
break;
|
||||
}
|
||||
else {
|
||||
printf("ADB TWENDADB crc header doesn't match\n");
|
||||
close(fd);
|
||||
return std::vector<std::string>();
|
||||
}
|
||||
}
|
||||
else if (cmdtype == TWIMG || cmdtype == TWFN) {
|
||||
struct twfilehdr twfilehdr;
|
||||
uint32_t crc, twfilehdrcrc;
|
||||
|
||||
memcpy(&twfilehdr, buf, sizeof(twfilehdr));
|
||||
twfilehdrcrc = twfilehdr.crc;
|
||||
memset(&twfilehdr.crc, 0, sizeof(twfilehdr.crc));
|
||||
|
||||
crc = crc32(0L, Z_NULL, 0);
|
||||
crc = crc32(crc, (const unsigned char*) &twfilehdr, sizeof(twfilehdr));
|
||||
if (crc == twfilehdrcrc) {
|
||||
std::string adbfile = twfilehdr.name;
|
||||
int pos = adbfile.find_last_of("/") + 1;
|
||||
adbfile = adbfile.substr(pos, adbfile.size());
|
||||
adb_partitions.push_back(adbfile);
|
||||
}
|
||||
else {
|
||||
printf("ADB crc header doesn't match\n");
|
||||
close(fd);
|
||||
return std::vector<std::string>();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
close(fd);
|
||||
return adb_partitions;
|
||||
}
|
||||
|
||||
bool twadbbu::Write_ADB_Stream_Header(uint64_t partition_count) {
|
||||
struct AdbBackupStreamHeader twhdr;
|
||||
int adb_control_bu_fd;
|
||||
|
||||
memset(&twhdr, 0, sizeof(twhdr));
|
||||
adb_control_bu_fd = open(TW_ADB_BU_CONTROL, O_WRONLY | O_NONBLOCK);
|
||||
if (adb_control_bu_fd < 0) {
|
||||
printf("Cannot write to TW_ADB_BU_CONTROL: %s\n", strerror(errno));
|
||||
return false;
|
||||
}
|
||||
|
||||
strncpy(twhdr.start_of_header, TWRP, sizeof(twhdr.start_of_header));
|
||||
strncpy(twhdr.type, TWSTREAMHDR, sizeof(twhdr.type));
|
||||
twhdr.partition_count = partition_count;
|
||||
twhdr.version = ADB_BACKUP_VERSION;
|
||||
memset(twhdr.space, 0, sizeof(twhdr.space));
|
||||
twhdr.crc = crc32(0L, Z_NULL, 0);
|
||||
twhdr.crc = crc32(twhdr.crc, (const unsigned char*) &twhdr, sizeof(twhdr));
|
||||
if (write(adb_control_bu_fd, &twhdr, sizeof(twhdr)) < 0) {
|
||||
printf("Cannot write to adb control channel: %s\n", strerror(errno));
|
||||
close(adb_control_bu_fd);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool twadbbu::Write_ADB_Stream_Trailer() {
|
||||
int adb_control_bu_fd;
|
||||
struct AdbBackupControlType endadb;
|
||||
|
||||
memset(&endadb, 0, sizeof(endadb));
|
||||
|
||||
adb_control_bu_fd = open(TW_ADB_BU_CONTROL, O_WRONLY);
|
||||
if (adb_control_bu_fd < 0) {
|
||||
printf("Error opening adb_control_bu_fd: %s\n", strerror(errno));
|
||||
return false;
|
||||
}
|
||||
strncpy(endadb.start_of_header, TWRP, sizeof(endadb.start_of_header));
|
||||
strncpy(endadb.type, TWENDADB, sizeof(endadb.type));
|
||||
endadb.crc = crc32(0L, Z_NULL, 0);
|
||||
endadb.crc = crc32(endadb.crc, (const unsigned char*) &endadb, sizeof(endadb));
|
||||
if (write(adb_control_bu_fd, &endadb, sizeof(endadb)) < 0) {
|
||||
printf("Cannot write to ADB control: %s\n", strerror(errno));
|
||||
close(adb_control_bu_fd);
|
||||
return false;
|
||||
}
|
||||
close(adb_control_bu_fd);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool twadbbu::Write_TWFN(std::string Backup_FileName, uint64_t file_size, bool use_compression) {
|
||||
int adb_control_bu_fd;
|
||||
adb_control_bu_fd = open(TW_ADB_BU_CONTROL, O_WRONLY | O_NONBLOCK);
|
||||
struct twfilehdr twfilehdr;
|
||||
strncpy(twfilehdr.start_of_header, TWRP, sizeof(twfilehdr.start_of_header));
|
||||
strncpy(twfilehdr.type, TWFN, sizeof(twfilehdr.type));
|
||||
strncpy(twfilehdr.name, Backup_FileName.c_str(), sizeof(twfilehdr.name));
|
||||
twfilehdr.size = (file_size == 0 ? 1024 : file_size);
|
||||
twfilehdr.compressed = use_compression;
|
||||
twfilehdr.crc = crc32(0L, Z_NULL, 0);
|
||||
twfilehdr.crc = crc32(twfilehdr.crc, (const unsigned char*) &twfilehdr, sizeof(twfilehdr));
|
||||
|
||||
printf("Sending TWFN to adb\n");
|
||||
if (write(adb_control_bu_fd, &twfilehdr, sizeof(twfilehdr)) < 1) {
|
||||
printf("Cannot that write to adb_control_bu_fd: %s\n", strerror(errno));
|
||||
close(adb_control_bu_fd);
|
||||
return false;
|
||||
}
|
||||
fsync(adb_control_bu_fd);
|
||||
close(adb_control_bu_fd);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool twadbbu::Write_TWIMG(std::string Backup_FileName, uint64_t file_size) {
|
||||
int adb_control_bu_fd;
|
||||
struct twfilehdr twimghdr;
|
||||
|
||||
adb_control_bu_fd = open(TW_ADB_BU_CONTROL, O_WRONLY | O_NONBLOCK);
|
||||
strncpy(twimghdr.start_of_header, TWRP, sizeof(twimghdr.start_of_header));
|
||||
strncpy(twimghdr.type, TWIMG, sizeof(twimghdr.type));
|
||||
twimghdr.size = file_size;
|
||||
strncpy(twimghdr.name, Backup_FileName.c_str(), sizeof(twimghdr.name));
|
||||
twimghdr.crc = crc32(0L, Z_NULL, 0);
|
||||
twimghdr.crc = crc32(twimghdr.crc, (const unsigned char*) &twimghdr, sizeof(twimghdr));
|
||||
printf("Sending TWIMG to adb\n");
|
||||
if (write(adb_control_bu_fd, &twimghdr, sizeof(twimghdr)) < 1) {
|
||||
printf("Cannot write to adb control channel: %s\n", strerror(errno));
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool twadbbu::Write_TWEOF() {
|
||||
struct AdbBackupControlType tweof;
|
||||
int adb_control_bu_fd;
|
||||
int errctr = 0;
|
||||
|
||||
printf("opening TW_ADB_BU_CONTROL\n");
|
||||
adb_control_bu_fd = open(TW_ADB_BU_CONTROL, O_WRONLY | O_NONBLOCK);
|
||||
while (adb_control_bu_fd < 0) {
|
||||
printf("failed to open TW_ADB_BU_CONTROL. Retrying: %s\n", strerror(errno));
|
||||
adb_control_bu_fd = open(TW_ADB_BU_CONTROL, O_WRONLY | O_NONBLOCK);
|
||||
usleep(10000);
|
||||
errctr++;
|
||||
if (errctr > ADB_BU_MAX_ERROR) {
|
||||
printf("Cannot write to adb_control_bu_fd: %s.\n", strerror(errno));
|
||||
close(adb_control_bu_fd);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
memset(&tweof, 0, sizeof(tweof));
|
||||
strncpy(tweof.start_of_header, TWRP, sizeof(tweof.start_of_header));
|
||||
strncpy(tweof.type, TWEOF, sizeof(tweof.type));
|
||||
tweof.crc = crc32(0L, Z_NULL, 0);
|
||||
tweof.crc = crc32(tweof.crc, (const unsigned char*) &tweof, sizeof(tweof));
|
||||
printf("Sending TWEOF to adb backup\n");
|
||||
if (write(adb_control_bu_fd, &tweof, sizeof(tweof)) < 0) {
|
||||
printf("Cannot write to adb_control_bu_fd: %s.\n", strerror(errno));
|
||||
close(adb_control_bu_fd);
|
||||
return false;
|
||||
}
|
||||
close(adb_control_bu_fd);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool twadbbu::Write_TWERROR() {
|
||||
struct AdbBackupControlType twerror;
|
||||
int adb_control_bu_fd = open(TW_ADB_BU_CONTROL, O_WRONLY | O_NONBLOCK);
|
||||
|
||||
strncpy(twerror.start_of_header, TWRP, sizeof(twerror.start_of_header));
|
||||
strncpy(twerror.type, TWERROR, sizeof(twerror.type));
|
||||
memset(twerror.space, 0, sizeof(twerror.space));
|
||||
twerror.crc = crc32(0L, Z_NULL, 0);
|
||||
twerror.crc = crc32(twerror.crc, (const unsigned char*) &twerror, sizeof(twerror));
|
||||
if (write(adb_control_bu_fd, &twerror, sizeof(twerror)) < 0) {
|
||||
printf("Cannot write to adb control channel: %s\n", strerror(errno));
|
||||
return false;
|
||||
}
|
||||
close(adb_control_bu_fd);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool twadbbu::Write_TWENDADB() {
|
||||
struct AdbBackupControlType endadb;
|
||||
int adb_control_bu_fd = open(TW_ADB_BU_CONTROL, O_WRONLY | O_NONBLOCK);
|
||||
|
||||
memset(&endadb, 0, sizeof(endadb));
|
||||
strncpy(endadb.start_of_header, TWRP, sizeof(endadb.start_of_header));
|
||||
strncpy(endadb.type, TWENDADB, sizeof(endadb.type));
|
||||
endadb.crc = crc32(0L, Z_NULL, 0);
|
||||
endadb.crc = crc32(endadb.crc, (const unsigned char*) &endadb, sizeof(endadb));
|
||||
|
||||
printf("Sending TWENDADB to ADB Backup\n");
|
||||
if (write(adb_control_bu_fd, &endadb, sizeof(endadb)) < 1) {
|
||||
printf("Cannot write to ADB_CONTROL_BU_FD: %s\n", strerror(errno));
|
||||
return false;
|
||||
}
|
||||
|
||||
close(adb_control_bu_fd);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool twadbbu::Write_TWDATA(FILE* adbd_fp) {
|
||||
struct AdbBackupControlType data_block;
|
||||
memset(&data_block, 0, sizeof(data_block));
|
||||
strncpy(data_block.start_of_header, TWRP, sizeof(data_block.start_of_header));
|
||||
strncpy(data_block.type, TWDATA, sizeof(data_block.type));
|
||||
data_block.crc = crc32(0L, Z_NULL, 0);
|
||||
data_block.crc = crc32(data_block.crc, (const unsigned char*) &data_block, sizeof(data_block));
|
||||
if (fwrite(&data_block, 1, sizeof(data_block), adbd_fp) != sizeof(data_block)) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
/*
|
||||
Copyright 2013 to 2017 TeamWin
|
||||
TWRP 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 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
TWRP 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 TWRP. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#ifndef _LIBTWADBBU_HPP
|
||||
#define _LIBTWADBBU_HPP
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <string.h>
|
||||
#include <fcntl.h>
|
||||
#include <errno.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/select.h>
|
||||
#include <sys/time.h>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <fstream>
|
||||
#include <sstream>
|
||||
|
||||
#include "twadbstream.h"
|
||||
|
||||
class twadbbu {
|
||||
public:
|
||||
static bool Check_ADB_Backup_File(std::string fname); //Check if file is ADB Backup file
|
||||
static std::vector<std::string> Get_ADB_Backup_Files(std::string fname); //List ADB Files in String Vector
|
||||
static bool Write_ADB_Stream_Header(uint64_t partition_count); //Write ADB Stream Header to stream
|
||||
static bool Write_ADB_Stream_Trailer(); //Write ADB Stream Trailer to stream
|
||||
static bool Write_TWFN(std::string Backup_FileName, uint64_t file_size, bool use_compression); //Write a tar image to stream
|
||||
static bool Write_TWIMG(std::string Backup_FileName, uint64_t file_size); //Write a partition image to stream
|
||||
static bool Write_TWEOF(); //Write ADB End-Of-File marker to stream
|
||||
static bool Write_TWERROR(); //Write error message occurred to stream
|
||||
static bool Write_TWENDADB(); //Write ADB End-Of-Stream command to stream
|
||||
static bool Write_TWDATA(FILE* adbd_fp); //Write TWDATA separator
|
||||
};
|
||||
|
||||
#endif //__LIBTWADBBU_HPP
|
||||
@@ -0,0 +1,112 @@
|
||||
/*
|
||||
TWRP 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 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
TWRP 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 TWRP. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef __TWADBSTREAM_H
|
||||
#define __TWADBSTREAM_H
|
||||
|
||||
#define TWRPARG "--twrp"
|
||||
#define TWRP_BACKUP_ARG "backup"
|
||||
#define TWRP_RESTORE_ARG "restore"
|
||||
#define TWRP_STREAM_ARG "stream"
|
||||
#define TW_ADB_BACKUP "/tmp/twadbbackup" //FIFO for adb backup
|
||||
#define TW_ADB_RESTORE "/tmp/twadbrestore" //FIFO for adb restore
|
||||
#define TW_ADB_BU_CONTROL "/tmp/twadbbucontrol" //FIFO for sending control from TWRP to ADB Backup
|
||||
#define TW_ADB_TWRP_CONTROL "/tmp/twadbtwrpcontrol" //FIFO for sending control from ADB Backup to TWRP
|
||||
#define TWRP "TWRP" //Magic Value
|
||||
#define ADB_BU_MAX_ERROR 20 //Max amount of errors for while loops
|
||||
#define ADB_BACKUP_OP "adbbackup"
|
||||
#define ADB_RESTORE_OP "adbrestore"
|
||||
|
||||
//ADB Backup Control Commands
|
||||
#define TWSTREAMHDR "twstreamheader" //TWRP Parititon Count Control
|
||||
#define TWFN "twfilename" //TWRP Filename Control
|
||||
#define TWIMG "twimage" //TWRP Image name Control
|
||||
#define TWEOF "tweof" //End of File for Image/File
|
||||
#define MD5TRAILER "md5trailer" //Image/File MD5 Trailer
|
||||
#define TWDATA "twdatablock" // twrp adb backup data block header
|
||||
#define TWMD5 "twverifymd5" //This command is compared to the md5trailer by ORS to verify transfer
|
||||
#define TWENDADB "twendadb" //End Protocol
|
||||
#define TWERROR "twerror" //Send error
|
||||
#define ADB_BACKUP_VERSION 3 //Backup Version
|
||||
#define DATA_MAX_CHUNK_SIZE 1048576 //Maximum size between each data header
|
||||
#define MAX_ADB_READ 512 //align with default tar size for amount to read fom adb stream
|
||||
|
||||
/*
|
||||
structs for adb backup need to align to 512 bytes for reading 512
|
||||
bytes at a time
|
||||
Each struct contains a crc field so that when we are checking for commands
|
||||
and the crc doesn't match we still assume it's data matching the command
|
||||
struct but not really a command
|
||||
*/
|
||||
|
||||
/* stream format:
|
||||
| TW ADB Backup Header |
|
||||
| TW File Stream Header |
|
||||
| File Data |
|
||||
| File/Image MD5 Trailer |
|
||||
| TW File Stream Header |
|
||||
| File Data |
|
||||
| File/Image MD5 Trailer |
|
||||
| etc... |
|
||||
*/
|
||||
|
||||
//determine whether struct is 512 bytes, if not fail compilation
|
||||
#define ADBSTRUCT_STATIC_ASSERT(structure) typedef char adb_assertion[( !!(structure) )*2-1 ]
|
||||
|
||||
//generic cmd structure to align fields for sending commands to and from adb backup
|
||||
struct AdbBackupControlType {
|
||||
char start_of_header[8]; //stores the magic value #define TWRP
|
||||
char type[16]; //stores the type of command, TWENDADB, TWCNT, TWEOF, TWMD5, TWDATA and TWERROR
|
||||
uint32_t crc; //stores the zlib 32 bit crc of the AdbBackupControlType struct to allow for making sure we are processing metadata
|
||||
char space[484]; //stores space to align the struct to 512 bytes
|
||||
|
||||
//return a C++ string while not reading outside the type char array
|
||||
std::string get_type() {
|
||||
return std::string(type, strnlen(type, sizeof(type)-1));
|
||||
}
|
||||
};
|
||||
|
||||
//general info for file metadata stored in adb backup header
|
||||
struct twfilehdr {
|
||||
char start_of_header[8]; //stores the magic value #define TWRP
|
||||
char type[16]; //stores the type of file header, TWFN or TWIMG
|
||||
uint64_t size; //stores the size of the file contained after this header in the backup file
|
||||
uint64_t compressed; //stores whether the file is compressed or not. 1 == compressed and 0 == uncompressed
|
||||
uint32_t crc; //stores the zlib 32 bit crc of the twfilehdr struct to allow for making sure we are processing metadata
|
||||
char name[468]; //stores the filename of the file
|
||||
};
|
||||
|
||||
//md5 for files stored as a trailer to files in the adb backup file to check
|
||||
//that they are restored correctly
|
||||
struct AdbBackupFileTrailer {
|
||||
char start_of_trailer[8]; //stores the magic value #define TWRP
|
||||
char type[16]; //stores the AdbBackupFileTrailer type MD5TRAILER
|
||||
uint32_t crc; //stores the zlib 32 bit crc of the AdbBackupFileTrailer struct to allow for making sure we are processing metadata
|
||||
uint32_t ident; //stores crc to determine if header is encapsulated in stream as data
|
||||
char md5[40]; //stores the md5 computation of the file
|
||||
char space[440]; //stores space to align the struct to 512 bytes
|
||||
};
|
||||
|
||||
//info for version and number of partitions backed up
|
||||
struct AdbBackupStreamHeader {
|
||||
char start_of_header[8]; //stores the magic value #define TWRP
|
||||
char type[16]; //stores the AdbBackupStreamHeader value TWCNT
|
||||
uint64_t partition_count; //stores the number of partitions to restore in the stream
|
||||
uint64_t version; //stores the version of adb backup. increment ADB_BACKUP_VERSION each time the metadata is updated
|
||||
uint32_t crc; //stores the zlib 32 bit crc of the AdbBackupStreamHeader struct to allow for making sure we are processing metadata
|
||||
char space[468]; //stores space to align the struct to 512 bytes
|
||||
};
|
||||
|
||||
#endif //__TWADBSTREAM_H
|
||||
@@ -0,0 +1,935 @@
|
||||
/*
|
||||
Copyright 2013 to 2017 TeamWin
|
||||
TWRP 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 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
TWRP 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 TWRP. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <fcntl.h>
|
||||
#include <errno.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/select.h>
|
||||
#include <sys/time.h>
|
||||
#include <zlib.h>
|
||||
#include <ctype.h>
|
||||
#include <semaphore.h>
|
||||
#include <string>
|
||||
#include <sstream>
|
||||
#include <fstream>
|
||||
#include <algorithm>
|
||||
#include <utils/threads.h>
|
||||
#include <pthread.h>
|
||||
|
||||
#include "twadbstream.h"
|
||||
#include "twrpback.hpp"
|
||||
#include "libtwadbbu.hpp"
|
||||
#include "../twrpDigest/twrpDigest.hpp"
|
||||
#include "../twrpDigest/twrpMD5.hpp"
|
||||
#include "../twrpAdbBuFifo.hpp"
|
||||
|
||||
twrpback::twrpback(void) {
|
||||
adbd_fp = NULL;
|
||||
read_fd = 0;
|
||||
write_fd = 0;
|
||||
adb_control_twrp_fd = 0;
|
||||
adb_control_bu_fd = 0;
|
||||
adb_read_fd = 0;
|
||||
adb_write_fd = 0;
|
||||
ors_fd = 0;
|
||||
debug_adb_fd = 0;
|
||||
firstPart = true;
|
||||
createFifos();
|
||||
adbloginit();
|
||||
}
|
||||
|
||||
twrpback::~twrpback(void) {
|
||||
adblogfile.close();
|
||||
closeFifos();
|
||||
}
|
||||
|
||||
void twrpback::printErrMsg(std::string msg, int errNum) {
|
||||
std::stringstream str;
|
||||
str << strerror(errNum);
|
||||
adblogwrite(msg + " " + str.str() + "\n");
|
||||
}
|
||||
|
||||
void twrpback::createFifos(void) {
|
||||
if (mkfifo(TW_ADB_BU_CONTROL, 0666) < 0) {
|
||||
std::string msg = "Unable to create TW_ADB_BU_CONTROL fifo: ";
|
||||
printErrMsg(msg, errno);
|
||||
}
|
||||
if (mkfifo(TW_ADB_TWRP_CONTROL, 0666) < 0) {
|
||||
std::string msg = "Unable to create TW_ADB_TWRP_CONTROL fifo: ";
|
||||
printErrMsg(msg, errno);
|
||||
unlink(TW_ADB_BU_CONTROL);
|
||||
}
|
||||
}
|
||||
|
||||
void twrpback::closeFifos(void) {
|
||||
if (unlink(TW_ADB_BU_CONTROL) < 0) {
|
||||
std::string msg = "Unable to remove TW_ADB_BU_CONTROL: ";
|
||||
printErrMsg(msg, errno);
|
||||
}
|
||||
if (unlink(TW_ADB_TWRP_CONTROL) < 0) {
|
||||
std::string msg = "Unable to remove TW_ADB_TWRP_CONTROL: ";
|
||||
printErrMsg(msg, errno);
|
||||
}
|
||||
}
|
||||
|
||||
void twrpback::adbloginit(void) {
|
||||
adblogfile.open("/tmp/adb.log", std::fstream::app);
|
||||
}
|
||||
|
||||
void twrpback::adblogwrite(std::string writemsg) {
|
||||
adblogfile << writemsg << std::flush;
|
||||
}
|
||||
|
||||
void twrpback::close_backup_fds() {
|
||||
if (ors_fd > 0)
|
||||
close(ors_fd);
|
||||
if (write_fd > 0)
|
||||
close(write_fd);
|
||||
if (adb_read_fd > 0)
|
||||
close(adb_read_fd);
|
||||
if (adb_control_bu_fd > 0)
|
||||
close(adb_control_bu_fd);
|
||||
#ifdef _DEBUG_ADB_BACKUP
|
||||
if (debug_adb_fd > 0)
|
||||
close(debug_adb_fd);
|
||||
#endif
|
||||
if (adbd_fp != NULL)
|
||||
fclose(adbd_fp);
|
||||
if (access(TW_ADB_BACKUP, F_OK) == 0)
|
||||
unlink(TW_ADB_BACKUP);
|
||||
}
|
||||
|
||||
void twrpback::close_restore_fds() {
|
||||
if (ors_fd > 0)
|
||||
close(ors_fd);
|
||||
if (write_fd > 0)
|
||||
close(write_fd);
|
||||
if (adb_control_bu_fd > 0)
|
||||
close(adb_control_bu_fd);
|
||||
if (adb_control_twrp_fd > 0)
|
||||
close(adb_control_twrp_fd);
|
||||
if (adbd_fp != NULL)
|
||||
fclose(adbd_fp);
|
||||
if (access(TW_ADB_RESTORE, F_OK) == 0)
|
||||
unlink(TW_ADB_RESTORE);
|
||||
#ifdef _DEBUG_ADB_BACKUP
|
||||
if (debug_adb_fd > 0)
|
||||
close(debug_adb_fd);
|
||||
#endif
|
||||
}
|
||||
|
||||
bool twrpback::backup(std::string command) {
|
||||
twrpMD5 digest;
|
||||
int bytes = 0, errctr = 0;
|
||||
char adbReadStream[MAX_ADB_READ];
|
||||
uint64_t totalbytes = 0, dataChunkBytes = 0, fileBytes = 0;
|
||||
uint64_t md5fnsize = 0;
|
||||
struct AdbBackupControlType endadb;
|
||||
|
||||
//ADBSTRUCT_STATIC_ASSERT(sizeof(endadb) == MAX_ADB_READ);
|
||||
|
||||
bool writedata = true;
|
||||
bool compressed = false;
|
||||
bool firstDataPacket = true;
|
||||
|
||||
adbd_fp = fdopen(adbd_fd, "w");
|
||||
if (adbd_fp == NULL) {
|
||||
adblogwrite("Unable to open adb_fp\n");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (mkfifo(TW_ADB_BACKUP, 0666) < 0) {
|
||||
adblogwrite("Unable to create TW_ADB_BACKUP fifo\n");
|
||||
return false;
|
||||
}
|
||||
|
||||
adblogwrite("opening TW_ADB_FIFO\n");
|
||||
|
||||
write_fd = open(TW_ADB_FIFO, O_WRONLY);
|
||||
while (write_fd < 0) {
|
||||
write_fd = open(TW_ADB_FIFO, O_WRONLY);
|
||||
usleep(10000);
|
||||
errctr++;
|
||||
if (errctr > ADB_BU_MAX_ERROR) {
|
||||
std::string msg = "Unable to open TW_ADB_FIFO";
|
||||
printErrMsg(msg, errno);
|
||||
close_backup_fds();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
memset(operation, 0, sizeof(operation));
|
||||
if (snprintf(operation, sizeof(operation), "adbbackup %s", command.c_str()) >= (int)sizeof(operation)) {
|
||||
adblogwrite("Operation too big to write to ORS_INPUT_FILE\n");
|
||||
close_backup_fds();
|
||||
return false;
|
||||
}
|
||||
if (write(write_fd, operation, sizeof(operation)) != sizeof(operation)) {
|
||||
adblogwrite("Unable to write to ORS_INPUT_FILE\n");
|
||||
close_backup_fds();
|
||||
return false;
|
||||
}
|
||||
|
||||
memset(&adbReadStream, 0, sizeof(adbReadStream));
|
||||
memset(&cmd, 0, sizeof(cmd));
|
||||
|
||||
adblogwrite("opening TW_ADB_BU_CONTROL\n");
|
||||
adb_control_bu_fd = open(TW_ADB_BU_CONTROL, O_RDONLY | O_NONBLOCK);
|
||||
if (adb_control_bu_fd < 0) {
|
||||
adblogwrite("Unable to open TW_ADB_BU_CONTROL for reading.\n");
|
||||
close_backup_fds();
|
||||
return false;
|
||||
}
|
||||
|
||||
adblogwrite("opening TW_ADB_BACKUP\n");
|
||||
adb_read_fd = open(TW_ADB_BACKUP, O_RDONLY | O_NONBLOCK);
|
||||
if (adb_read_fd < 0) {
|
||||
adblogwrite("Unable to open TW_ADB_BACKUP for reading.\n");
|
||||
close_backup_fds();
|
||||
return false;
|
||||
}
|
||||
|
||||
//loop until TWENDADB sent
|
||||
while (true) {
|
||||
if (read(adb_control_bu_fd, &cmd, sizeof(cmd)) > 0) {
|
||||
struct AdbBackupControlType structcmd;
|
||||
|
||||
memcpy(&structcmd, cmd, sizeof(cmd));
|
||||
std::string cmdtype = structcmd.get_type();
|
||||
|
||||
//we received an error, exit and unlink
|
||||
if (cmdtype == TWERROR) {
|
||||
writedata = false;
|
||||
adblogwrite("Error received. Quitting...\n");
|
||||
close_backup_fds();
|
||||
return false;
|
||||
}
|
||||
//we received the end of adb backup stream so we should break the loop
|
||||
else if (cmdtype == TWENDADB) {
|
||||
writedata = false;
|
||||
adblogwrite("Recieved TWENDADB\n");
|
||||
memcpy(&endadb, cmd, sizeof(cmd));
|
||||
std::stringstream str;
|
||||
str << totalbytes;
|
||||
adblogwrite(str.str() + " total bytes written\n");
|
||||
break;
|
||||
}
|
||||
//we recieved the TWSTREAMHDR structure metadata to write to adb
|
||||
else if (cmdtype == TWSTREAMHDR) {
|
||||
writedata = false;
|
||||
adblogwrite("writing TWSTREAMHDR\n");
|
||||
if (fwrite(cmd, 1, sizeof(cmd), adbd_fp) != sizeof(cmd)) {
|
||||
std::string msg = "Error writing TWSTREAMHDR to adbd";
|
||||
printErrMsg(msg, errno);
|
||||
close_backup_fds();
|
||||
return false;
|
||||
}
|
||||
fflush(adbd_fp);
|
||||
}
|
||||
//we will be writing an image from TWRP
|
||||
else if (cmdtype == TWIMG) {
|
||||
struct twfilehdr twimghdr;
|
||||
|
||||
adblogwrite("writing TWIMG\n");
|
||||
digest.init();
|
||||
memset(&twimghdr, 0, sizeof(twimghdr));
|
||||
memcpy(&twimghdr, cmd, sizeof(cmd));
|
||||
md5fnsize = twimghdr.size;
|
||||
compressed = false;
|
||||
|
||||
#ifdef _DEBUG_ADB_BACKUP
|
||||
std::string debug_fname = "/data/media/";
|
||||
debug_fname.append(basename(twimghdr.name));
|
||||
debug_fname.append("-backup.img");
|
||||
debug_adb_fd = open(debug_fname.c_str(), O_WRONLY | O_CREAT, 0666);
|
||||
adblogwrite("Opening adb debug tar\n");
|
||||
#endif
|
||||
|
||||
if (fwrite(cmd, 1, sizeof(cmd), adbd_fp) != sizeof(cmd)) {
|
||||
adblogwrite("Error writing TWIMG to adbd\n");
|
||||
close_backup_fds();
|
||||
return false;
|
||||
}
|
||||
fflush(adbd_fp);
|
||||
writedata = true;
|
||||
}
|
||||
//we will be writing a tar from TWRP
|
||||
else if (cmdtype == TWFN) {
|
||||
struct twfilehdr twfilehdr;
|
||||
|
||||
adblogwrite("writing TWFN\n");
|
||||
digest.init();
|
||||
|
||||
//ADBSTRUCT_STATIC_ASSERT(sizeof(twfilehdr) == MAX_ADB_READ);
|
||||
|
||||
memset(&twfilehdr, 0, sizeof(twfilehdr));
|
||||
memcpy(&twfilehdr, cmd, sizeof(cmd));
|
||||
md5fnsize = twfilehdr.size;
|
||||
|
||||
compressed = twfilehdr.compressed == 1 ? true: false;
|
||||
|
||||
#ifdef _DEBUG_ADB_BACKUP
|
||||
std::string debug_fname = "/data/media/";
|
||||
debug_fname.append(basename(twfilehdr.name));
|
||||
debug_fname.append("-backup.tar");
|
||||
debug_adb_fd = open(debug_fname.c_str(), O_WRONLY | O_CREAT, 0666);
|
||||
adblogwrite("Opening adb debug tar\n");
|
||||
#endif
|
||||
|
||||
if (fwrite(cmd, 1, sizeof(cmd), adbd_fp) != sizeof(cmd)) {
|
||||
adblogwrite("Error writing TWFN to adbd\n");
|
||||
close_backup_fds();
|
||||
return false;
|
||||
}
|
||||
fflush(adbd_fp);
|
||||
writedata = true;
|
||||
}
|
||||
/*
|
||||
We received the command that we are done with the file stream.
|
||||
We will flush the remaining data stream.
|
||||
Update md5 and write final results to adb stream.
|
||||
If we need padding because the total bytes are not a multiple
|
||||
of 512, we pad the end with 0s to we reach 512.
|
||||
We also write the final md5 to the adb stream.
|
||||
*/
|
||||
else if (cmdtype == TWEOF) {
|
||||
adblogwrite("received TWEOF\n");
|
||||
while ((bytes = read(adb_read_fd, &adbReadStream, sizeof(adbReadStream)) != 0)) {
|
||||
totalbytes += bytes;
|
||||
fileBytes += bytes;
|
||||
dataChunkBytes += bytes;
|
||||
|
||||
char *writeAdbReadStream = new char [bytes];
|
||||
memcpy(writeAdbReadStream, adbReadStream, bytes);
|
||||
|
||||
digest.update((unsigned char *) writeAdbReadStream, bytes);
|
||||
if (fwrite(writeAdbReadStream, 1, bytes, adbd_fp) < 0) {
|
||||
std::string msg = "Cannot write to adbd stream: ";
|
||||
printErrMsg(msg, errno);
|
||||
}
|
||||
#if defined(_DEBUG_ADB_BACKUP)
|
||||
if (write(debug_adb_fd, writeAdbReadStream, bytes) < 1) {
|
||||
std::string msg = "Cannot write to ADB_CONTROL_READ_FD: ";
|
||||
printErrMsg(msg, errno);
|
||||
close_restore_fds();
|
||||
return false;
|
||||
}
|
||||
#endif
|
||||
fflush(adbd_fp);
|
||||
delete [] writeAdbReadStream;
|
||||
memset(adbReadStream, 0, sizeof(adbReadStream));
|
||||
}
|
||||
|
||||
if (fileBytes % DATA_MAX_CHUNK_SIZE != 0) {
|
||||
int64_t count = fileBytes / DATA_MAX_CHUNK_SIZE + 1;
|
||||
uint64_t ceilingBytes = count * DATA_MAX_CHUNK_SIZE;
|
||||
char padding[ceilingBytes - fileBytes];
|
||||
int paddingBytes = sizeof(padding);
|
||||
memset(padding, 0, paddingBytes);
|
||||
std::stringstream paddingStr;
|
||||
paddingStr << paddingBytes;
|
||||
adblogwrite("writing padding to stream: " + paddingStr.str() + " bytes\n");
|
||||
if (fwrite(padding, 1, paddingBytes, adbd_fp) != sizeof(padding)) {
|
||||
adblogwrite("Error writing padding to adbd\n");
|
||||
close_backup_fds();
|
||||
return false;
|
||||
}
|
||||
#if defined(_DEBUG_ADB_BACKUP)
|
||||
if (write(debug_adb_fd, padding, paddingBytes) < 1) {
|
||||
std::string msg = "Cannot write to ADB_CONTROL_READ_FD: ";
|
||||
printErrMsg(msg, errno);
|
||||
close_restore_fds();
|
||||
return false;
|
||||
}
|
||||
#endif
|
||||
totalbytes += paddingBytes;
|
||||
digest.update((unsigned char *) padding, paddingBytes);
|
||||
fflush(adbd_fp);
|
||||
}
|
||||
|
||||
AdbBackupFileTrailer md5trailer;
|
||||
|
||||
memset(&md5trailer, 0, sizeof(md5trailer));
|
||||
|
||||
std::string md5string = digest.return_digest_string();
|
||||
|
||||
strncpy(md5trailer.start_of_trailer, TWRP, sizeof(md5trailer.start_of_trailer));
|
||||
strncpy(md5trailer.type, MD5TRAILER, sizeof(md5trailer.type));
|
||||
strncpy(md5trailer.md5, md5string.c_str(), sizeof(md5trailer.md5));
|
||||
|
||||
md5trailer.crc = crc32(0L, Z_NULL, 0);
|
||||
md5trailer.crc = crc32(md5trailer.crc, (const unsigned char*) &md5trailer, sizeof(md5trailer));
|
||||
|
||||
md5trailer.ident = crc32(0L, Z_NULL, 0);
|
||||
md5trailer.ident = crc32(md5trailer.ident, (const unsigned char*) &md5trailer, sizeof(md5trailer));
|
||||
md5trailer.ident = crc32(md5trailer.ident, (const unsigned char*) &md5fnsize, sizeof(md5fnsize));
|
||||
|
||||
if (fwrite(&md5trailer, 1, sizeof(md5trailer), adbd_fp) != sizeof(md5trailer)) {
|
||||
adblogwrite("Error writing md5trailer to adbd\n");
|
||||
close_backup_fds();
|
||||
return false;
|
||||
}
|
||||
fflush(adbd_fp);
|
||||
writedata = false;
|
||||
firstDataPacket = true;
|
||||
fileBytes = 0;
|
||||
}
|
||||
memset(&cmd, 0, sizeof(cmd));
|
||||
dataChunkBytes = 0;
|
||||
}
|
||||
//If we are to write data because of a new file stream, lets write all the data.
|
||||
//This will allow us to not write data after a command structure has been written
|
||||
//to the adb stream.
|
||||
//If the stream is compressed, we need to always write the data.
|
||||
if (writedata || compressed) {
|
||||
while ((bytes = read(adb_read_fd, &adbReadStream, sizeof(adbReadStream))) > 0) {
|
||||
if (firstDataPacket) {
|
||||
if (!twadbbu::Write_TWDATA(adbd_fp)) {
|
||||
close_backup_fds();
|
||||
return false;
|
||||
}
|
||||
fileBytes += MAX_ADB_READ;
|
||||
fflush(adbd_fp);
|
||||
firstDataPacket = false;
|
||||
dataChunkBytes += sizeof(adbReadStream);
|
||||
}
|
||||
char *writeAdbReadStream = new char [bytes];
|
||||
memcpy(writeAdbReadStream, adbReadStream, bytes);
|
||||
|
||||
digest.update((unsigned char *) writeAdbReadStream, bytes);
|
||||
|
||||
totalbytes += bytes;
|
||||
fileBytes += bytes;
|
||||
dataChunkBytes += bytes;
|
||||
|
||||
if (fwrite(writeAdbReadStream, 1, bytes, adbd_fp) != (unsigned long long)bytes) {
|
||||
adblogwrite("Error writing backup data to adbd\n");
|
||||
close_backup_fds();
|
||||
return false;
|
||||
}
|
||||
#ifdef _DEBUG_ADB_BACKUP
|
||||
if (write(debug_adb_fd, writeAdbReadStream, bytes) < 1) {
|
||||
std::string msg = "Cannot write to ADB_CONTROL_READ_FD: ";
|
||||
printErrMsg(msg, errno);
|
||||
close_restore_fds();
|
||||
return false;
|
||||
}
|
||||
#endif
|
||||
fflush(adbd_fp);
|
||||
delete [] writeAdbReadStream;
|
||||
|
||||
memset(&adbReadStream, 0, sizeof(adbReadStream));
|
||||
|
||||
if (dataChunkBytes == DATA_MAX_CHUNK_SIZE) {
|
||||
dataChunkBytes = 0;
|
||||
firstDataPacket = true;
|
||||
}
|
||||
else if (dataChunkBytes > (DATA_MAX_CHUNK_SIZE - sizeof(adbReadStream))) {
|
||||
int bytesLeft = DATA_MAX_CHUNK_SIZE - dataChunkBytes;
|
||||
char extraData[bytesLeft];
|
||||
|
||||
memset(&extraData, 0, bytesLeft);
|
||||
while ((bytes = read(adb_read_fd, &extraData, bytesLeft)) != 0) {
|
||||
if (bytes > 0) {
|
||||
totalbytes += bytes;
|
||||
fileBytes += bytes;
|
||||
dataChunkBytes += bytes;
|
||||
|
||||
bytesLeft -= bytes;
|
||||
char *writeAdbReadStream = new char [bytes];
|
||||
memcpy(writeAdbReadStream, extraData, bytes);
|
||||
|
||||
digest.update((unsigned char *) writeAdbReadStream, bytes);
|
||||
if (fwrite(writeAdbReadStream, 1, bytes, adbd_fp) < 0) {
|
||||
std::string msg = "Cannot write to adbd stream: ";
|
||||
printErrMsg(msg, errno);
|
||||
close_restore_fds();
|
||||
return false;
|
||||
}
|
||||
#ifdef _DEBUG_ADB_BACKUP
|
||||
if (write(debug_adb_fd, writeAdbReadStream, bytes) < 1) {
|
||||
std::string msg = "Cannot write to ADB_CONTROL_READ_FD: ";
|
||||
printErrMsg(msg, errno);
|
||||
close_restore_fds();
|
||||
return false;
|
||||
}
|
||||
#endif
|
||||
fflush(adbd_fp);
|
||||
delete [] writeAdbReadStream;
|
||||
}
|
||||
memset(&extraData, 0, bytesLeft);
|
||||
if (bytesLeft == 0) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
fflush(adbd_fp);
|
||||
dataChunkBytes = 0;
|
||||
firstDataPacket = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//Write the final end adb structure to the adb stream
|
||||
if (fwrite(&endadb, 1, sizeof(endadb), adbd_fp) != sizeof(endadb)) {
|
||||
adblogwrite("Error writing endadb to adbd\n");
|
||||
close_backup_fds();
|
||||
return false;
|
||||
}
|
||||
fflush(adbd_fp);
|
||||
close_backup_fds();
|
||||
return true;
|
||||
}
|
||||
|
||||
bool twrpback::restore(void) {
|
||||
twrpMD5 digest;
|
||||
char cmd[MAX_ADB_READ];
|
||||
char readAdbStream[MAX_ADB_READ];
|
||||
struct AdbBackupControlType structcmd;
|
||||
int errctr = 0;
|
||||
uint64_t totalbytes = 0, dataChunkBytes = 0;
|
||||
uint64_t md5fnsize = 0, fileBytes = 0;
|
||||
bool read_from_adb;
|
||||
bool md5sumdata;
|
||||
bool compressed, tweofrcvd, extraData;
|
||||
|
||||
read_from_adb = true;
|
||||
|
||||
signal(SIGPIPE, SIG_IGN);
|
||||
signal(SIGHUP, SIG_IGN);
|
||||
|
||||
adbd_fp = fdopen(adbd_fd, "r");
|
||||
if (adbd_fp == NULL) {
|
||||
adblogwrite("Unable to open adb_fp\n");
|
||||
close_restore_fds();
|
||||
return false;
|
||||
}
|
||||
|
||||
if(mkfifo(TW_ADB_RESTORE, 0666)) {
|
||||
adblogwrite("Unable to create TW_ADB_RESTORE fifo\n");
|
||||
close_restore_fds();
|
||||
return false;
|
||||
}
|
||||
|
||||
adblogwrite("opening TW_ADB_FIFO\n");
|
||||
write_fd = open(TW_ADB_FIFO, O_WRONLY);
|
||||
|
||||
while (write_fd < 0) {
|
||||
write_fd = open(TW_ADB_FIFO, O_WRONLY);
|
||||
errctr++;
|
||||
if (errctr > ADB_BU_MAX_ERROR) {
|
||||
std::string msg = "Unable to open TW_ADB_FIFO.";
|
||||
printErrMsg(msg, errno);
|
||||
close_restore_fds();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
memset(operation, 0, sizeof(operation));
|
||||
sprintf(operation, "adbrestore");
|
||||
if (write(write_fd, operation, sizeof(operation)) != sizeof(operation)) {
|
||||
adblogwrite("Unable to write to TW_ADB_FIFO\n");
|
||||
close_restore_fds();
|
||||
return false;
|
||||
}
|
||||
|
||||
memset(&readAdbStream, 0, sizeof(readAdbStream));
|
||||
memset(&cmd, 0, sizeof(cmd));
|
||||
|
||||
adblogwrite("opening TW_ADB_BU_CONTROL\n");
|
||||
adb_control_bu_fd = open(TW_ADB_BU_CONTROL, O_RDONLY | O_NONBLOCK);
|
||||
if (adb_control_bu_fd < 0) {
|
||||
std::string msg = "Unable to open TW_ADB_BU_CONTROL for writing.";
|
||||
printErrMsg(msg, errno);
|
||||
close_restore_fds();
|
||||
return false;
|
||||
}
|
||||
|
||||
adblogwrite("opening TW_ADB_TWRP_CONTROL\n");
|
||||
adb_control_twrp_fd = open(TW_ADB_TWRP_CONTROL, O_WRONLY | O_NONBLOCK);
|
||||
if (adb_control_twrp_fd < 0) {
|
||||
std::string msg = "Unable to open TW_ADB_TWRP_CONTROL for writing. Retrying...";
|
||||
printErrMsg(msg, errno);
|
||||
while (adb_control_twrp_fd < 0) {
|
||||
adb_control_twrp_fd = open(TW_ADB_TWRP_CONTROL, O_WRONLY | O_NONBLOCK);
|
||||
usleep(10000);
|
||||
errctr++;
|
||||
if (errctr > ADB_BU_MAX_ERROR) {
|
||||
adblogwrite("Unable to open TW_ADB_TWRP_CONTROL\n");
|
||||
close_backup_fds();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//Loop until we receive TWENDADB from TWRP
|
||||
while (true) {
|
||||
memset(&cmd, 0, sizeof(cmd));
|
||||
if (read(adb_control_bu_fd, &cmd, sizeof(cmd)) > 0) {
|
||||
struct AdbBackupControlType structcmd;
|
||||
memcpy(&structcmd, cmd, sizeof(cmd));
|
||||
std::string cmdtype = structcmd.get_type();
|
||||
|
||||
//If we receive TWEOF from TWRP close adb data fifo
|
||||
if (cmdtype == TWEOF) {
|
||||
adblogwrite("Received TWEOF\n");
|
||||
read_from_adb = true;
|
||||
tweofrcvd = true;
|
||||
close(adb_write_fd);
|
||||
}
|
||||
//Break when TWRP sends TWENDADB
|
||||
else if (cmdtype == TWENDADB) {
|
||||
adblogwrite("Received TWENDADB\n");
|
||||
break;
|
||||
}
|
||||
//we received an error, exit and unlink
|
||||
else if (cmdtype == TWERROR) {
|
||||
adblogwrite("Error received. Quitting...\n");
|
||||
close_restore_fds();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
//If we should read from the adb stream, write commands and data to TWRP
|
||||
if (read_from_adb) {
|
||||
int readbytes;
|
||||
if ((readbytes = fread(readAdbStream, 1, sizeof(readAdbStream), adbd_fp)) == sizeof(readAdbStream)) {
|
||||
memcpy(&structcmd, readAdbStream, sizeof(readAdbStream));
|
||||
std::string cmdtype = structcmd.get_type();
|
||||
|
||||
//Tell TWRP we have read the entire adb stream
|
||||
if (cmdtype == TWENDADB) {
|
||||
struct AdbBackupControlType endadb;
|
||||
uint32_t crc, endadbcrc;
|
||||
|
||||
md5sumdata = false;
|
||||
memset(&endadb, 0, sizeof(endadb));
|
||||
memcpy(&endadb, readAdbStream, sizeof(readAdbStream));
|
||||
endadbcrc = endadb.crc;
|
||||
memset(&endadb.crc, 0, sizeof(endadb.crc));
|
||||
crc = crc32(0L, Z_NULL, 0);
|
||||
crc = crc32(crc, (const unsigned char*) &endadb, sizeof(endadb));
|
||||
|
||||
if (crc == endadbcrc) {
|
||||
adblogwrite("sending TWENDADB\n");
|
||||
if (write(adb_control_twrp_fd, &endadb, sizeof(endadb)) < 1) {
|
||||
std::string msg = "Cannot write to ADB_CONTROL_READ_FD: ";
|
||||
printErrMsg(msg, errno);
|
||||
close_restore_fds();
|
||||
return false;
|
||||
}
|
||||
read_from_adb = false;
|
||||
}
|
||||
else {
|
||||
adblogwrite("ADB TWENDADB crc header doesn't match\n");
|
||||
close_restore_fds();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
//Send TWRP partition metadata
|
||||
else if (cmdtype == TWSTREAMHDR) {
|
||||
struct AdbBackupStreamHeader cnthdr;
|
||||
uint32_t crc, cnthdrcrc;
|
||||
|
||||
//ADBSTRUCT_STATIC_ASSERT(sizeof(cnthdr) == MAX_ADB_READ);
|
||||
|
||||
md5sumdata = false;
|
||||
memset(&cnthdr, 0, sizeof(cnthdr));
|
||||
memcpy(&cnthdr, readAdbStream, sizeof(readAdbStream));
|
||||
cnthdrcrc = cnthdr.crc;
|
||||
memset(&cnthdr.crc, 0, sizeof(cnthdr.crc));
|
||||
crc = crc32(0L, Z_NULL, 0);
|
||||
crc = crc32(crc, (const unsigned char*) &cnthdr, sizeof(cnthdr));
|
||||
|
||||
if (crc == cnthdrcrc) {
|
||||
adblogwrite("Restoring TWSTREAMHDR\n");
|
||||
if (write(adb_control_twrp_fd, readAdbStream, sizeof(readAdbStream)) < 0) {
|
||||
std::string msg = "Cannot write to adb_control_twrp_fd: ";
|
||||
printErrMsg(msg, errno);
|
||||
close_restore_fds();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else {
|
||||
adblogwrite("ADB TWSTREAMHDR crc header doesn't match\n");
|
||||
close_restore_fds();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
//Tell TWRP we are sending a partition image
|
||||
else if (cmdtype == TWIMG) {
|
||||
struct twfilehdr twimghdr;
|
||||
uint32_t crc, twimghdrcrc;
|
||||
md5sumdata = false;
|
||||
fileBytes = 0;
|
||||
read_from_adb = true;
|
||||
dataChunkBytes = 0;
|
||||
extraData = false;
|
||||
|
||||
digest.init();
|
||||
adblogwrite("Restoring TWIMG\n");
|
||||
memset(&twimghdr, 0, sizeof(twimghdr));
|
||||
memcpy(&twimghdr, readAdbStream, sizeof(readAdbStream));
|
||||
md5fnsize = twimghdr.size;
|
||||
twimghdrcrc = twimghdr.crc;
|
||||
memset(&twimghdr.crc, 0, sizeof(twimghdr.crc));
|
||||
|
||||
crc = crc32(0L, Z_NULL, 0);
|
||||
crc = crc32(crc, (const unsigned char*) &twimghdr, sizeof(twimghdr));
|
||||
if (crc == twimghdrcrc) {
|
||||
if (write(adb_control_twrp_fd, readAdbStream, sizeof(readAdbStream)) < 1) {
|
||||
std::string msg = "Cannot write to adb_control_twrp_fd: ";
|
||||
printErrMsg(msg, errno);
|
||||
close_restore_fds();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else {
|
||||
adblogwrite("ADB TWIMG crc header doesn't match\n");
|
||||
close_restore_fds();
|
||||
return false;
|
||||
}
|
||||
|
||||
#ifdef _DEBUG_ADB_BACKUP
|
||||
std::string debug_fname = "/data/media/";
|
||||
debug_fname.append(basename(twimghdr.name));
|
||||
debug_fname.append("-restore.img");
|
||||
adblogwrite("image: " + debug_fname + "\n");
|
||||
debug_adb_fd = open(debug_fname.c_str(), O_WRONLY | O_CREAT, 0666);
|
||||
adblogwrite("Opened restore image\n");
|
||||
#endif
|
||||
|
||||
adblogwrite("opening TW_ADB_RESTORE\n");
|
||||
adb_write_fd = open(TW_ADB_RESTORE, O_WRONLY);
|
||||
}
|
||||
//Tell TWRP we are sending a tar stream
|
||||
else if (cmdtype == TWFN) {
|
||||
struct twfilehdr twfilehdr;
|
||||
uint32_t crc, twfilehdrcrc;
|
||||
fileBytes = 0;
|
||||
md5sumdata = false;
|
||||
read_from_adb = true;
|
||||
dataChunkBytes = 0;
|
||||
extraData = false;
|
||||
|
||||
digest.init();
|
||||
adblogwrite("Restoring TWFN\n");
|
||||
memset(&twfilehdr, 0, sizeof(twfilehdr));
|
||||
memcpy(&twfilehdr, readAdbStream, sizeof(readAdbStream));
|
||||
md5fnsize = twfilehdr.size;
|
||||
twfilehdrcrc = twfilehdr.crc;
|
||||
memset(&twfilehdr.crc, 0, sizeof(twfilehdr.crc));
|
||||
|
||||
crc = crc32(0L, Z_NULL, 0);
|
||||
crc = crc32(crc, (const unsigned char*) &twfilehdr, sizeof(twfilehdr));
|
||||
|
||||
if (crc == twfilehdrcrc) {
|
||||
if (write(adb_control_twrp_fd, readAdbStream, sizeof(readAdbStream)) < 1) {
|
||||
std::string msg = "Cannot write to adb_control_twrp_fd: ";
|
||||
printErrMsg(msg, errno);
|
||||
close_restore_fds();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else {
|
||||
adblogwrite("ADB TWFN crc header doesn't match\n");
|
||||
close_restore_fds();
|
||||
return false;
|
||||
}
|
||||
|
||||
#ifdef _DEBUG_ADB_BACKUP
|
||||
std::string debug_fname = "/data/media/";
|
||||
debug_fname.append(basename(twfilehdr.name));
|
||||
debug_fname.append("-restore.tar");
|
||||
adblogwrite("tar: " + debug_fname + "\n");
|
||||
debug_adb_fd = open(debug_fname.c_str(), O_WRONLY | O_CREAT, 0666);
|
||||
adblogwrite("Opened restore tar\n");
|
||||
#endif
|
||||
|
||||
compressed = twfilehdr.compressed == 1 ? true: false;
|
||||
adblogwrite("opening TW_ADB_RESTORE\n");
|
||||
adb_write_fd = open(TW_ADB_RESTORE, O_WRONLY);
|
||||
}
|
||||
else if (cmdtype == MD5TRAILER) {
|
||||
if (fileBytes >= md5fnsize)
|
||||
close(adb_write_fd);
|
||||
if (tweofrcvd) {
|
||||
read_from_adb = true;
|
||||
tweofrcvd = false;
|
||||
}
|
||||
else
|
||||
read_from_adb = false; //don't read from adb until TWRP sends TWEOF
|
||||
md5sumdata = false;
|
||||
if (!checkMD5Trailer(readAdbStream, md5fnsize, &digest)) {
|
||||
close_restore_fds();
|
||||
break;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
//Send the tar or partition image md5 to TWRP
|
||||
else if (cmdtype == TWDATA) {
|
||||
dataChunkBytes += sizeof(readAdbStream);
|
||||
while (true) {
|
||||
if ((readbytes = fread(readAdbStream, 1, sizeof(readAdbStream), adbd_fp)) != sizeof(readAdbStream)) {
|
||||
close_restore_fds();
|
||||
return false;
|
||||
}
|
||||
memcpy(&structcmd, readAdbStream, sizeof(readAdbStream));
|
||||
std::string cmdtype = structcmd.get_type();
|
||||
|
||||
dataChunkBytes += readbytes;
|
||||
totalbytes += readbytes;
|
||||
fileBytes += readbytes;
|
||||
|
||||
if (cmdtype == MD5TRAILER) {
|
||||
if (fileBytes >= md5fnsize)
|
||||
close(adb_write_fd);
|
||||
if (tweofrcvd) {
|
||||
tweofrcvd = false;
|
||||
read_from_adb = true;
|
||||
}
|
||||
else
|
||||
read_from_adb = false; //don't read from adb until TWRP sends TWEOF
|
||||
if (!checkMD5Trailer(readAdbStream, md5fnsize, &digest)) {
|
||||
close_restore_fds();
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
digest.update((unsigned char*)readAdbStream, readbytes);
|
||||
|
||||
read_from_adb = true;
|
||||
|
||||
#ifdef _DEBUG_ADB_BACKUP
|
||||
if (write(debug_adb_fd, readAdbStream, sizeof(readAdbStream)) < 0) {
|
||||
std::string msg = "Cannot write to ADB_CONTROL_READ_FD: ";
|
||||
printErrMsg(msg, errno);
|
||||
close_restore_fds();
|
||||
return false;
|
||||
}
|
||||
#endif
|
||||
|
||||
if (write(adb_write_fd, readAdbStream, sizeof(readAdbStream)) < 0) {
|
||||
std::string msg = "Cannot write to TWRP ADB FIFO: ";
|
||||
md5sumdata = true;
|
||||
printErrMsg(msg, errno);
|
||||
adblogwrite("end of stream reached.\n");
|
||||
break;
|
||||
}
|
||||
|
||||
if (dataChunkBytes == DATA_MAX_CHUNK_SIZE) {
|
||||
dataChunkBytes = 0;
|
||||
md5sumdata = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (md5sumdata) {
|
||||
digest.update((unsigned char*)readAdbStream, sizeof(readAdbStream));
|
||||
md5sumdata = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
std::stringstream str;
|
||||
str << totalbytes;
|
||||
close_restore_fds();
|
||||
adblogwrite(str.str() + " bytes restored from adbbackup\n");
|
||||
return true;
|
||||
}
|
||||
|
||||
void twrpback::streamFileForTWRP(void) {
|
||||
adblogwrite("streamFileForTwrp" + streamFn + "\n");
|
||||
}
|
||||
|
||||
void twrpback::setStreamFileName(std::string fn) {
|
||||
streamFn = fn;
|
||||
adbd_fd = open(fn.c_str(), O_RDONLY);
|
||||
if (adbd_fd < 0) {
|
||||
adblogwrite("Unable to open adb_fd\n");
|
||||
close(adbd_fd);
|
||||
return;
|
||||
}
|
||||
restore();
|
||||
}
|
||||
|
||||
void twrpback::threadStream(void) {
|
||||
pthread_t thread;
|
||||
ThreadPtr streamPtr = &twrpback::streamFileForTWRP;
|
||||
PThreadPtr p = *(PThreadPtr*)&streamPtr;
|
||||
pthread_create(&thread, NULL, p, this);
|
||||
pthread_join(thread, NULL);
|
||||
}
|
||||
|
||||
bool twrpback::checkMD5Trailer(char readAdbStream[], uint64_t md5fnsize, twrpMD5 *digest) {
|
||||
struct AdbBackupFileTrailer md5tr;
|
||||
uint32_t crc, md5trcrc, md5ident, md5identmatch;
|
||||
|
||||
//ADBSTRUCT_STATIC_ASSERT(sizeof(md5tr) == MAX_ADB_READ);
|
||||
memcpy(&md5tr, readAdbStream, MAX_ADB_READ);
|
||||
md5ident = md5tr.ident;
|
||||
|
||||
memset(&md5tr.ident, 0, sizeof(md5tr.ident));
|
||||
|
||||
md5identmatch = crc32(0L, Z_NULL, 0);
|
||||
md5identmatch = crc32(md5identmatch, (const unsigned char*) &md5tr, sizeof(md5tr));
|
||||
md5identmatch = crc32(md5identmatch, (const unsigned char*) &md5fnsize, sizeof(md5fnsize));
|
||||
|
||||
if (md5identmatch == md5ident) {
|
||||
adblogwrite("checking MD5TRAILER\n");
|
||||
md5trcrc = md5tr.crc;
|
||||
memset(&md5tr.crc, 0, sizeof(md5tr.crc));
|
||||
crc = crc32(0L, Z_NULL, 0);
|
||||
crc = crc32(crc, (const unsigned char*) &md5tr, sizeof(md5tr));
|
||||
if (crc == md5trcrc) {
|
||||
if (write(adb_control_twrp_fd, &md5tr, sizeof(md5tr)) < 1) {
|
||||
std::string msg = "Cannot write to adb_control_twrp_fd: ";
|
||||
printErrMsg(msg, errno);
|
||||
close_restore_fds();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else {
|
||||
adblogwrite("ADB MD5TRAILER crc header doesn't match\n");
|
||||
close_restore_fds();
|
||||
return false;
|
||||
}
|
||||
|
||||
AdbBackupFileTrailer md5;
|
||||
|
||||
memset(&md5, 0, sizeof(md5));
|
||||
strncpy(md5.start_of_trailer, TWRP, sizeof(md5.start_of_trailer));
|
||||
strncpy(md5.type, TWMD5, sizeof(md5.type));
|
||||
std::string md5string = digest->return_digest_string();
|
||||
strncpy(md5.md5, md5string.c_str(), sizeof(md5.md5));
|
||||
|
||||
adblogwrite("sending MD5 verification: " + md5string + "\n");
|
||||
if (write(adb_control_twrp_fd, &md5, sizeof(md5)) < 1) {
|
||||
std::string msg = "Cannot write to adb_control_twrp_fd: ";
|
||||
printErrMsg(msg, errno);
|
||||
close_restore_fds();
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
/*
|
||||
Copyright 2013 to 2017 TeamWin
|
||||
TWRP 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 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
TWRP 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 TWRP. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef _TWRPBACK_HPP
|
||||
#define _TWRPBACK_HPP
|
||||
|
||||
#include <fstream>
|
||||
#include "../twrpDigest/twrpMD5.hpp"
|
||||
|
||||
class twrpback {
|
||||
public:
|
||||
int adbd_fd; // adbd data stream
|
||||
twrpback(void);
|
||||
virtual ~twrpback(void);
|
||||
bool backup(std::string command); // adb backup stream
|
||||
bool restore(void); // adb restore stream
|
||||
void adblogwrite(std::string writemsg); // adb debugging log function
|
||||
void createFifos(void); // create fifos needed for adb backup
|
||||
void closeFifos(void); // close created fifos
|
||||
void streamFileForTWRP(void); // stream file to twrp via bu
|
||||
void setStreamFileName(std::string fn); // tell adb backup what file to load on storage
|
||||
void threadStream(void); // thread bu for streaming
|
||||
|
||||
private:
|
||||
int read_fd; // ors input fd
|
||||
int write_fd; // ors operation fd
|
||||
int ors_fd; // ors output fd
|
||||
int adb_control_twrp_fd; // fd for bu to twrp communication
|
||||
int adb_control_bu_fd; // fd for twrp to bu communication
|
||||
int adb_read_fd; // adb read data stream
|
||||
int adb_write_fd; // adb write data stream
|
||||
int debug_adb_fd; // fd to write debug tars
|
||||
bool firstPart; // first partition in the stream
|
||||
FILE *adbd_fp; // file pointer for adb stream
|
||||
char cmd[512]; // store result of commands
|
||||
char operation[512]; // operation to send to ors
|
||||
std::ofstream adblogfile; // adb stream log file
|
||||
std::string streamFn;
|
||||
typedef void (twrpback::*ThreadPtr)(void);
|
||||
typedef void* (*PThreadPtr)(void *);
|
||||
void adbloginit(void); // setup adb log stream file
|
||||
void close_backup_fds(); // close backup resources
|
||||
void close_restore_fds(); // close restore resources
|
||||
bool checkMD5Trailer(char adbReadStream[], uint64_t md5fnsize, twrpMD5* digest); // Check MD5 Trailer
|
||||
void printErrMsg(std::string msg, int errNum); // print error msg to adb log
|
||||
};
|
||||
|
||||
#endif // _TWRPBACK_HPP
|
||||
@@ -0,0 +1,22 @@
|
||||
LOCAL_PATH:= $(call my-dir)
|
||||
|
||||
include $(CLEAR_VARS)
|
||||
LOCAL_SRC_FILES := listxattr.c
|
||||
LOCAL_CFLAGS := -c -W
|
||||
LOCAL_MODULE := listxattr
|
||||
LOCAL_MODULE_TAGS := optional
|
||||
LOCAL_MODULE_CLASS := RECOVERY_EXECUTABLES
|
||||
LOCAL_MODULE_PATH := $(TARGET_RECOVERY_ROOT_OUT)/
|
||||
LOCAL_PACK_MODULE_RELOCATIONS := false
|
||||
|
||||
ifneq ($(TARGET_ARCH), arm64)
|
||||
ifneq ($(TARGET_ARCH), x86_64)
|
||||
LOCAL_LDFLAGS += -Wl,-dynamic-linker,/system/bin/linker
|
||||
else
|
||||
LOCAL_LDFLAGS += -Wl,-dynamic-linker,/system/bin/linker64
|
||||
endif
|
||||
else
|
||||
LOCAL_LDFLAGS += -Wl,-dynamic-linker,/system/bin/linker64
|
||||
endif
|
||||
|
||||
include $(BUILD_EXECUTABLE)
|
||||
@@ -0,0 +1,202 @@
|
||||
/****************************************************************************
|
||||
| (C) Copyright 2008 Novell, Inc. All Rights Reserved.
|
||||
|
|
||||
| GPLv2: This program is free software; you can redistribute it
|
||||
| and/or modify it under the terms of version 2 of the GNU General
|
||||
| Public License as published by the Free Software Foundation.
|
||||
|
|
||||
| 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.
|
||||
+-------------------------------------------------------------------------*/
|
||||
/*
|
||||
* NOTE from Dees_Troy: modified source to display values along with xattr names
|
||||
* Below code comments about usage are no longer accurate but came from the
|
||||
* original source code from the chromium project and combine features of
|
||||
* listxattr and getfattr:
|
||||
* https://chromium.googlesource.com/chromiumos/platform/punybench/+/factory-1235.B/file.m/listxattr.c
|
||||
* https://chromium.googlesource.com/chromiumos/platform/punybench/+/factory-1235.B/file.m/getxattr.c
|
||||
*/
|
||||
/*
|
||||
* LISTXATTR(2) Linux Programmer's Manual LISTXATTR(2)
|
||||
*
|
||||
*
|
||||
*
|
||||
* NAME
|
||||
* listxattr, llistxattr, flistxattr - list extended attribute names
|
||||
*
|
||||
* SYNOPSIS
|
||||
* #include <sys/types.h>
|
||||
* #include <attr/xattr.h>
|
||||
*
|
||||
* ssize_t listxattr (const char *path,
|
||||
* char *list, size_t size);
|
||||
* ssize_t llistxattr (const char *path,
|
||||
* char *list, size_t size);
|
||||
* ssize_t flistxattr (int filedes,
|
||||
* char *list, size_t size);
|
||||
*
|
||||
* DESCRIPTION
|
||||
* Extended attributes are name:value pairs associated with inodes
|
||||
* (files, directories, symlinks, etc). They are extensions to the
|
||||
* normal attributes which are associated with all inodes in the sys-
|
||||
* tem (i.e. the stat(2) data). A complete overview of extended
|
||||
* attributes concepts can be found in attr(5).
|
||||
*
|
||||
* listxattr retrieves the list of extended attribute names associated
|
||||
* with the given path in the filesystem. The list is the set of
|
||||
* (NULL-terminated) names, one after the other. Names of extended
|
||||
* attributes to which the calling process does not have access may be
|
||||
* omitted from the list. The length of the attribute name list is
|
||||
* returned.
|
||||
*
|
||||
* llistxattr is identical to listxattr, except in the case of a sym-
|
||||
* bolic link, where the list of names of extended attributes associ-
|
||||
* ated with the link itself is retrieved, not the file that it refers
|
||||
* to.
|
||||
*
|
||||
* flistxattr is identical to listxattr, only the open file pointed to
|
||||
* by filedes (as returned by open(2)) is interrogated in place of
|
||||
* path.
|
||||
*
|
||||
* A single extended attribute name is a simple NULL-terminated
|
||||
* string. The name includes a namespace prefix; there may be sev-
|
||||
* eral, disjoint namespaces associated with an individual inode.
|
||||
*
|
||||
* An empty buffer of size zero can be passed into these calls to
|
||||
* return the current size of the list of extended attribute names,
|
||||
* which can be used to estimate the size of a buffer which is suffi-
|
||||
* ciently large to hold the list of names.
|
||||
*
|
||||
* EXAMPLES
|
||||
* The list of names is returned as an unordered array of NULL-termi-
|
||||
* nated character strings (attribute names are separated by NULL
|
||||
* characters), like this:
|
||||
* user.name1\0system.name1\0user.name2\0
|
||||
*
|
||||
* Filesystems like ext2, ext3 and XFS which implement POSIX ACLs
|
||||
* using extended attributes, might return a list like this:
|
||||
* system.posix_acl_access\0system.posix_acl_default\0
|
||||
*
|
||||
* RETURN VALUE
|
||||
* On success, a positive number is returned indicating the size of
|
||||
* the extended attribute name list. On failure, -1 is returned and
|
||||
* errno is set appropriately.
|
||||
*
|
||||
* If the size of the list buffer is too small to hold the result,
|
||||
* errno is set to ERANGE.
|
||||
*
|
||||
* If extended attributes are not supported by the filesystem, or are
|
||||
* disabled, errno is set to ENOTSUP.
|
||||
*
|
||||
* The errors documented for the stat(2) system call are also applica-
|
||||
* ble here.
|
||||
*
|
||||
* AUTHORS
|
||||
* Andreas Gruenbacher, <a.gruenbacher@computer.org> and the SGI XFS
|
||||
* development team, <linux-xfs@oss.sgi.com>. Please send any bug
|
||||
* reports or comments to these addresses.
|
||||
*
|
||||
* SEE ALSO
|
||||
* getfattr(1), setfattr(1), getxattr(2), open(2), removexattr(2),
|
||||
* setxattr(2), stat(2), attr(5)
|
||||
*
|
||||
*
|
||||
*
|
||||
* Dec 2001 Extended Attributes LISTXATTR(2)
|
||||
*/
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <ctype.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/xattr.h>
|
||||
//#include <eprintf.h>
|
||||
//#include <puny.h>
|
||||
|
||||
/* dumpmem: dumps an n byte area of memory to screen */
|
||||
void dumpmem (const void *mem, unsigned int n)
|
||||
{
|
||||
const char *c = mem;
|
||||
unsigned i;
|
||||
int all_text = 1;
|
||||
if (n == 0) {
|
||||
printf("<empty>");
|
||||
return;
|
||||
}
|
||||
for (i = 0; i < n - 1; i++, c++) {
|
||||
if (!isprint(*c)) {
|
||||
all_text = 0;
|
||||
break;
|
||||
}
|
||||
}
|
||||
c = mem;
|
||||
if (all_text) {
|
||||
for (i = 0; i < n - 1; i++, c++) {
|
||||
putchar(*c);
|
||||
}
|
||||
return;
|
||||
} else {
|
||||
char hex[(n * 2) + 1];
|
||||
for(i = 0; i < n; i++, c++)
|
||||
sprintf(hex + (i * 2), "%02X", *c);
|
||||
hex[n] = 0;
|
||||
printf("0x%s", hex);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
void dump_list (char *file, char *list, ssize_t size)
|
||||
{
|
||||
int c;
|
||||
int i;
|
||||
int first = 1;
|
||||
int j = 0;
|
||||
char xattr[1024];
|
||||
char value[1024];
|
||||
ssize_t size2;
|
||||
for (i = 0; i < size; i++) {
|
||||
c = list[i];
|
||||
if (c) {
|
||||
if (first) {
|
||||
putchar('\t');
|
||||
first = 0;
|
||||
j = 0;
|
||||
}
|
||||
putchar(c);
|
||||
xattr[j++] = list[i];
|
||||
} else {
|
||||
xattr[j] = '\0';
|
||||
size2 = getxattr(file, xattr, value, sizeof(value));
|
||||
if (size2 < 0) {
|
||||
printf("file=%s xattr=%s returned:", file, xattr);
|
||||
} else {
|
||||
putchar('=');
|
||||
dumpmem(value, size2);
|
||||
}
|
||||
putchar('\n');
|
||||
first = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
void usage (void)
|
||||
{
|
||||
printf("listxattr <file>");
|
||||
}
|
||||
char List[1<<17];
|
||||
int main (int argc, char *argv[])
|
||||
{
|
||||
ssize_t size;
|
||||
if (argc < 2) {
|
||||
usage();
|
||||
exit(2);
|
||||
}
|
||||
size = listxattr(argv[1], List, sizeof(List));
|
||||
if (size == -1) {
|
||||
perror(argv[1]);
|
||||
exit(2);
|
||||
}
|
||||
printf("xattrs for %s:\n", argv[1]);
|
||||
dump_list(argv[1], List, size);
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,232 @@
|
||||
/*
|
||||
Copyright 2012 bigbiff/Dees_Troy TeamWin
|
||||
This file is part of TWRP/TeamWin Recovery Project.
|
||||
|
||||
TWRP 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 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
TWRP 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 TWRP. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <string>
|
||||
#include <map>
|
||||
#include <fstream>
|
||||
#include <sstream>
|
||||
|
||||
#include "infomanager.hpp"
|
||||
#include "twcommon.h"
|
||||
#include "partitions.hpp"
|
||||
#include "set_metadata.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
InfoManager::InfoManager() {
|
||||
file_version = 0;
|
||||
is_const = false;
|
||||
}
|
||||
|
||||
InfoManager::InfoManager(const string& filename) {
|
||||
file_version = 0;
|
||||
is_const = false;
|
||||
SetFile(filename);
|
||||
}
|
||||
|
||||
InfoManager::~InfoManager(void) {
|
||||
Clear();
|
||||
}
|
||||
|
||||
void InfoManager::SetFile(const string& filename) {
|
||||
File = filename;
|
||||
}
|
||||
|
||||
void InfoManager::SetFileVersion(int version) {
|
||||
file_version = version;
|
||||
}
|
||||
|
||||
void InfoManager::SetConst(void) {
|
||||
is_const = true;
|
||||
}
|
||||
|
||||
void InfoManager::Clear(void) {
|
||||
mValues.clear();
|
||||
}
|
||||
|
||||
int InfoManager::LoadValues(void) {
|
||||
string str;
|
||||
|
||||
// Read in the file, if possible
|
||||
FILE* in = fopen(File.c_str(), "rb");
|
||||
if (!in) {
|
||||
LOGINFO("InfoManager file '%s' not found.\n", File.c_str());
|
||||
return -1;
|
||||
} else {
|
||||
LOGINFO("InfoManager loading from '%s'.\n", File.c_str());
|
||||
}
|
||||
|
||||
if (file_version) {
|
||||
int read_file_version;
|
||||
if (fread(&read_file_version, 1, sizeof(int), in) != sizeof(int))
|
||||
goto error;
|
||||
if (read_file_version != file_version) {
|
||||
LOGINFO("InfoManager file version has changed, not reading file\n");
|
||||
goto error;
|
||||
}
|
||||
}
|
||||
|
||||
while (!feof(in)) {
|
||||
string Name;
|
||||
string Value;
|
||||
unsigned short length;
|
||||
char array[513];
|
||||
|
||||
if (fread(&length, 1, sizeof(unsigned short), in) != sizeof(unsigned short)) goto error;
|
||||
if (length >= 512) goto error;
|
||||
if (fread(array, 1, length, in) != length) goto error;
|
||||
array[length+1] = '\0';
|
||||
Name = array;
|
||||
|
||||
if (fread(&length, 1, sizeof(unsigned short), in) != sizeof(unsigned short)) goto error;
|
||||
if (length >= 512) goto error;
|
||||
if (fread(array, 1, length, in) != length) goto error;
|
||||
array[length+1] = '\0';
|
||||
Value = array;
|
||||
|
||||
map<string, string>::iterator pos;
|
||||
|
||||
pos = mValues.find(Name);
|
||||
if (pos != mValues.end()) {
|
||||
pos->second = Value;
|
||||
} else {
|
||||
mValues.insert(make_pair(Name, Value));
|
||||
}
|
||||
}
|
||||
error:
|
||||
fclose(in);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int InfoManager::SaveValues(void) {
|
||||
if (File.empty())
|
||||
return -1;
|
||||
|
||||
PartitionManager.Mount_By_Path(File, true);
|
||||
LOGINFO("InfoManager saving '%s'\n", File.c_str());
|
||||
FILE* out = fopen(File.c_str(), "wb");
|
||||
if (!out)
|
||||
return -1;
|
||||
|
||||
if (file_version) {
|
||||
fwrite(&file_version, 1, sizeof(int), out);
|
||||
}
|
||||
|
||||
map<string, string>::iterator iter;
|
||||
for (iter = mValues.begin(); iter != mValues.end(); ++iter) {
|
||||
unsigned short length = (unsigned short) iter->first.length() + 1;
|
||||
fwrite(&length, 1, sizeof(unsigned short), out);
|
||||
fwrite(iter->first.c_str(), 1, length, out);
|
||||
length = (unsigned short) iter->second.length() + 1;
|
||||
fwrite(&length, 1, sizeof(unsigned short), out);
|
||||
fwrite(iter->second.c_str(), 1, length, out);
|
||||
}
|
||||
fclose(out);
|
||||
tw_set_default_metadata(File.c_str());
|
||||
return 0;
|
||||
}
|
||||
|
||||
int InfoManager::GetValue(const string& varName, string& value) {
|
||||
string localStr = varName;
|
||||
|
||||
map<string, string>::iterator pos;
|
||||
pos = mValues.find(localStr);
|
||||
if (pos == mValues.end())
|
||||
return -1;
|
||||
|
||||
value = pos->second;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int InfoManager::GetValue(const string& varName, int& value) {
|
||||
string data;
|
||||
|
||||
if (GetValue(varName,data) != 0)
|
||||
return -1;
|
||||
|
||||
value = atoi(data.c_str());
|
||||
return 0;
|
||||
}
|
||||
|
||||
int InfoManager::GetValue(const string& varName, float& value) {
|
||||
string data;
|
||||
|
||||
if (GetValue(varName,data) != 0)
|
||||
return -1;
|
||||
|
||||
value = atof(data.c_str());
|
||||
return 0;
|
||||
}
|
||||
|
||||
unsigned long long InfoManager::GetValue(const string& varName, unsigned long long& value) {
|
||||
string data;
|
||||
|
||||
if (GetValue(varName,data) != 0)
|
||||
return -1;
|
||||
|
||||
value = strtoull(data.c_str(), NULL, 10);
|
||||
return 0;
|
||||
}
|
||||
|
||||
// This function will return an empty string if the value doesn't exist
|
||||
string InfoManager::GetStrValue(const string& varName) {
|
||||
string retVal;
|
||||
|
||||
GetValue(varName, retVal);
|
||||
return retVal;
|
||||
}
|
||||
|
||||
// This function will return 0 if the value doesn't exist
|
||||
int InfoManager::GetIntValue(const string& varName) {
|
||||
string retVal;
|
||||
GetValue(varName, retVal);
|
||||
return atoi(retVal.c_str());
|
||||
}
|
||||
|
||||
int InfoManager::SetValue(const string& varName, const string& value) {
|
||||
// Don't allow empty names or numerical starting values
|
||||
if (varName.empty() || (varName[0] >= '0' && varName[0] <= '9'))
|
||||
return -1;
|
||||
|
||||
map<string, string>::iterator pos;
|
||||
pos = mValues.find(varName);
|
||||
if (pos == mValues.end())
|
||||
mValues.insert(make_pair(varName, value));
|
||||
else if (!is_const)
|
||||
pos->second = value;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int InfoManager::SetValue(const string& varName, const int value) {
|
||||
ostringstream valStr;
|
||||
valStr << value;
|
||||
return SetValue(varName, valStr.str());
|
||||
}
|
||||
|
||||
int InfoManager::SetValue(const string& varName, const float value) {
|
||||
ostringstream valStr;
|
||||
valStr << value;
|
||||
return SetValue(varName, valStr.str());
|
||||
}
|
||||
|
||||
int InfoManager::SetValue(const string& varName, const unsigned long long& value) {
|
||||
ostringstream valStr;
|
||||
valStr << value;
|
||||
return SetValue(varName, valStr.str());
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
/*
|
||||
Copyright 2012 bigbiff/Dees_Troy TeamWin
|
||||
This file is part of TWRP/TeamWin Recovery Project.
|
||||
|
||||
TWRP 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 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
TWRP 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 TWRP. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef _INFOMANAGER_HPP_HEADER
|
||||
#define _INFOMANAGER_HPP_HEADER
|
||||
|
||||
#include <string>
|
||||
#include <utility>
|
||||
#include <map>
|
||||
|
||||
using namespace std;
|
||||
|
||||
class InfoManager
|
||||
{
|
||||
public:
|
||||
InfoManager();
|
||||
explicit InfoManager(const string& filename);
|
||||
virtual ~InfoManager();
|
||||
void SetFile(const string& filename);
|
||||
void SetFileVersion(int version);
|
||||
void SetConst();
|
||||
void Clear();
|
||||
int LoadValues();
|
||||
int SaveValues();
|
||||
|
||||
// Core get routines
|
||||
int GetValue(const string& varName, string& value);
|
||||
int GetValue(const string& varName, int& value);
|
||||
int GetValue(const string& varName, float& value);
|
||||
unsigned long long GetValue(const string& varName, unsigned long long& value);
|
||||
|
||||
string GetStrValue(const string& varName);
|
||||
int GetIntValue(const string& varName);
|
||||
|
||||
// Core set routines
|
||||
int SetValue(const string& varName, const string& value);
|
||||
int SetValue(const string& varName, const int value);
|
||||
int SetValue(const string& varName, const float value);
|
||||
int SetValue(const string& varName, const unsigned long long& value);
|
||||
|
||||
private:
|
||||
string File;
|
||||
map<string, string> mValues;
|
||||
int file_version;
|
||||
bool is_const;
|
||||
|
||||
};
|
||||
|
||||
#endif // _DATAMANAGER_HPP_HEADER
|
||||
|
||||
@@ -0,0 +1,113 @@
|
||||
/*
|
||||
Copyright 2012 bigbiff/Dees_Troy TeamWin
|
||||
This file is part of TWRP/TeamWin Recovery Project.
|
||||
|
||||
TWRP 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 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
TWRP 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 TWRP. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <fcntl.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include "libtar/libtar.h"
|
||||
#include "twcommon.h"
|
||||
|
||||
int flush = 0, eot_count = -1;
|
||||
unsigned char *write_buffer;
|
||||
unsigned buffer_size = 4096;
|
||||
unsigned buffer_loc = 0;
|
||||
int buffer_status = 0;
|
||||
int prog_pipe = -1;
|
||||
const unsigned long long progress_size = (unsigned long long)(T_BLOCKSIZE);
|
||||
|
||||
void reinit_libtar_buffer(void) {
|
||||
flush = 0;
|
||||
eot_count = -1;
|
||||
buffer_loc = 0;
|
||||
buffer_status = 1;
|
||||
}
|
||||
|
||||
void init_libtar_buffer(unsigned new_buff_size, int pipe_fd) {
|
||||
if (new_buff_size != 0)
|
||||
buffer_size = new_buff_size;
|
||||
|
||||
reinit_libtar_buffer();
|
||||
write_buffer = (unsigned char*) malloc(sizeof(char *) * buffer_size);
|
||||
prog_pipe = pipe_fd;
|
||||
}
|
||||
|
||||
void free_libtar_buffer(void) {
|
||||
if (buffer_status > 0)
|
||||
free(write_buffer);
|
||||
buffer_status = 0;
|
||||
prog_pipe = -1;
|
||||
}
|
||||
|
||||
ssize_t write_libtar_buffer(int fd, const void *buffer, size_t size) {
|
||||
void* ptr;
|
||||
|
||||
if (flush == 0) {
|
||||
ptr = write_buffer + buffer_loc;
|
||||
memcpy(ptr, buffer, size);
|
||||
buffer_loc += size;
|
||||
if (eot_count >= 0 && eot_count < 2)
|
||||
eot_count++;
|
||||
/* At the end of the tar file, libtar will add 2 blank blocks.
|
||||
Once we have received both EOT blocks, we will immediately
|
||||
write anything in the buffer to the file.
|
||||
*/
|
||||
|
||||
if (buffer_loc >= buffer_size || eot_count >= 2) {
|
||||
flush = 1;
|
||||
}
|
||||
}
|
||||
if (flush == 1) {
|
||||
flush = 0;
|
||||
if (buffer_loc == 0) {
|
||||
// nothing to write
|
||||
return 0;
|
||||
}
|
||||
if (write(fd, write_buffer, buffer_loc) != (int)buffer_loc) {
|
||||
LOGERR("Error writing tar file!\n");
|
||||
buffer_loc = 0;
|
||||
return -1;
|
||||
} else {
|
||||
unsigned long long fs = (unsigned long long)(buffer_loc);
|
||||
write(prog_pipe, &fs, sizeof(fs));
|
||||
buffer_loc = 0;
|
||||
return size;
|
||||
}
|
||||
} else {
|
||||
return size;
|
||||
}
|
||||
// Shouldn't ever get here
|
||||
return -1;
|
||||
}
|
||||
|
||||
void flush_libtar_buffer(int fd) {
|
||||
eot_count = 0;
|
||||
if (buffer_status)
|
||||
buffer_status = 2;
|
||||
}
|
||||
|
||||
void init_libtar_no_buffer(int pipe_fd) {
|
||||
buffer_size = T_BLOCKSIZE;
|
||||
prog_pipe = pipe_fd;
|
||||
buffer_status = 0;
|
||||
}
|
||||
|
||||
ssize_t write_libtar_no_buffer(int fd, const void *buffer, size_t size) {
|
||||
write(prog_pipe, &progress_size, sizeof(progress_size));
|
||||
return write(fd, buffer, size);
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
/*
|
||||
Copyright 2013 bigbiff/Dees_Troy TeamWin
|
||||
This file is part of TWRP/TeamWin Recovery Project.
|
||||
|
||||
TWRP 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 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
TWRP 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 TWRP. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef _TARWRITE_HEADER
|
||||
#define _TARWRITE_HEADER
|
||||
|
||||
void reinit_libtar_buffer();
|
||||
void init_libtar_buffer(unsigned new_buff_size, int pipe_fd);
|
||||
void free_libtar_buffer();
|
||||
writefunc_t write_libtar_buffer(int fd, const void *buffer, size_t size);
|
||||
void flush_libtar_buffer(int fd);
|
||||
|
||||
void init_libtar_no_buffer(int pipe_fd);
|
||||
writefunc_t write_libtar_no_buffer(int fd, const void *buffer, size_t size);
|
||||
|
||||
#endif // _TARWRITE_HEADER
|
||||
@@ -0,0 +1,349 @@
|
||||
/*
|
||||
Copyright 2013 to 2017 TeamWin
|
||||
This file is part of TWRP/TeamWin Recovery Project.
|
||||
|
||||
TWRP 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 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
TWRP 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 TWRP. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#define __STDC_FORMAT_MACROS 1
|
||||
#include <string>
|
||||
#include <sys/wait.h>
|
||||
#include <sys/stat.h>
|
||||
#include <pthread.h>
|
||||
#include <zlib.h>
|
||||
#include <inttypes.h>
|
||||
#include "twrpAdbBuFifo.hpp"
|
||||
#include "twcommon.h"
|
||||
#include "data.hpp"
|
||||
#include "variables.h"
|
||||
#include "partitions.hpp"
|
||||
#include "twrp-functions.hpp"
|
||||
#include "gui/gui.hpp"
|
||||
#include "gui/objects.hpp"
|
||||
#include "gui/pages.hpp"
|
||||
#include "adbbu/twadbstream.h"
|
||||
#include "adbbu/libtwadbbu.hpp"
|
||||
|
||||
twrpAdbBuFifo::twrpAdbBuFifo(void) {
|
||||
unlink(TW_ADB_FIFO);
|
||||
}
|
||||
|
||||
void twrpAdbBuFifo::Check_Adb_Fifo_For_Events(void) {
|
||||
char cmd[512];
|
||||
|
||||
memset(&cmd, 0, sizeof(cmd));
|
||||
|
||||
if (read(adb_fifo_fd, &cmd, sizeof(cmd)) > 0) {
|
||||
LOGINFO("adb backup cmd: %s\n", cmd);
|
||||
std::string cmdcheck(cmd);
|
||||
cmdcheck = cmdcheck.substr(0, strlen(ADB_BACKUP_OP));
|
||||
std::string Options(cmd);
|
||||
Options = Options.substr(strlen(ADB_BACKUP_OP) + 1, strlen(cmd));
|
||||
if (cmdcheck == ADB_BACKUP_OP)
|
||||
Backup_ADB_Command(Options);
|
||||
else {
|
||||
Restore_ADB_Backup();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool twrpAdbBuFifo::start(void) {
|
||||
LOGINFO("Starting Adb Backup FIFO\n");
|
||||
unlink(TW_ADB_FIFO);
|
||||
if (mkfifo(TW_ADB_FIFO, 06660) != 0) {
|
||||
LOGINFO("Unable to mkfifo %s\n", TW_ADB_FIFO);
|
||||
return false;
|
||||
}
|
||||
adb_fifo_fd = open(TW_ADB_FIFO, O_RDONLY | O_NONBLOCK);
|
||||
if (adb_fifo_fd < 0) {
|
||||
LOGERR("Unable to open TW_ADB_FIFO for reading.\n");
|
||||
close(adb_fifo_fd);
|
||||
return false;
|
||||
}
|
||||
while (true) {
|
||||
Check_Adb_Fifo_For_Events();
|
||||
usleep(8000);
|
||||
}
|
||||
//Shouldn't get here but cleanup anwyay
|
||||
close(adb_fifo_fd);
|
||||
return true;
|
||||
}
|
||||
|
||||
pthread_t twrpAdbBuFifo::threadAdbBuFifo(void) {
|
||||
pthread_t thread;
|
||||
ThreadPtr adbfifo = &twrpAdbBuFifo::start;
|
||||
PThreadPtr p = *(PThreadPtr*)&adbfifo;
|
||||
pthread_create(&thread, NULL, p, this);
|
||||
return thread;
|
||||
}
|
||||
|
||||
bool twrpAdbBuFifo::Backup_ADB_Command(std::string Options) {
|
||||
std::vector<std::string> args;
|
||||
std::string Backup_List;
|
||||
bool adbbackup = true, ret = false;
|
||||
std::string rmopt = "--";
|
||||
|
||||
std::replace(Options.begin(), Options.end(), ':', ' ');
|
||||
args = TWFunc::Split_String(Options, " ");
|
||||
|
||||
DataManager::SetValue(TW_USE_COMPRESSION_VAR, 0);
|
||||
DataManager::SetValue(TW_SKIP_DIGEST_GENERATE_VAR, 0);
|
||||
|
||||
if (args[1].compare("--twrp") != 0) {
|
||||
gui_err("twrp_adbbu_option=--twrp option is required to enable twrp adb backup");
|
||||
if (!twadbbu::Write_TWERROR())
|
||||
LOGERR("Unable to write to ADB Backup\n");
|
||||
sleep(2);
|
||||
return false;
|
||||
}
|
||||
|
||||
for (unsigned i = 2; i < args.size(); i++) {
|
||||
int compress;
|
||||
|
||||
std::string::size_type size = args[i].find(rmopt);
|
||||
if (size != std::string::npos)
|
||||
args[i].erase(size, rmopt.length());
|
||||
|
||||
if (args[i].compare("compress") == 0) {
|
||||
gui_msg("compression_on=Compression is on");
|
||||
DataManager::SetValue(TW_USE_COMPRESSION_VAR, 1);
|
||||
continue;
|
||||
}
|
||||
DataManager::GetValue(TW_USE_COMPRESSION_VAR, compress);
|
||||
gui_print("%s\n", args[i].c_str());
|
||||
std::string path;
|
||||
path = "/" + args[i];
|
||||
TWPartition* part = PartitionManager.Find_Partition_By_Path(path);
|
||||
if (part) {
|
||||
Backup_List += path;
|
||||
Backup_List += ";";
|
||||
}
|
||||
else {
|
||||
gui_msg(Msg(msg::kError, "partition_not_found=path: {1} not found in partition list")(path));
|
||||
if (!twadbbu::Write_TWERROR())
|
||||
LOGERR("Unable to write to TWRP ADB Backup.\n");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (Backup_List.empty()) {
|
||||
DataManager::GetValue("tw_backup_list", Backup_List);
|
||||
if (Backup_List.empty()) {
|
||||
gui_err("no_partition_selected=No partitions selected for backup.");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else
|
||||
DataManager::SetValue("tw_backup_list", Backup_List);
|
||||
|
||||
DataManager::SetValue("tw_action", "clear");
|
||||
DataManager::SetValue("tw_action_text1", gui_lookup("running_recovery_commands", "Running Recovery Commands"));
|
||||
DataManager::SetValue("tw_action_text2", "");
|
||||
gui_changePage("action_page");
|
||||
|
||||
ret = PartitionManager.Run_Backup(adbbackup);
|
||||
DataManager::SetValue(TW_BACKUP_NAME, gui_lookup("auto_generate", "(Auto Generate)"));
|
||||
if (!ret) {
|
||||
gui_err("backup_fail=Backup failed");
|
||||
return false;
|
||||
}
|
||||
gui_msg("backup_complete=Backup Complete");
|
||||
DataManager::SetValue("ui_progress", 100);
|
||||
sleep(2); //give time for user to see messages on console
|
||||
gui_changePage("main");
|
||||
return true;
|
||||
}
|
||||
|
||||
bool twrpAdbBuFifo::Restore_ADB_Backup(void) {
|
||||
int partition_count = 0;
|
||||
std::string Restore_Name;
|
||||
struct AdbBackupFileTrailer adbmd5;
|
||||
struct PartitionSettings part_settings;
|
||||
int adb_control_twrp_fd;
|
||||
int adb_control_bu_fd, ret = 0;
|
||||
char cmd[512];
|
||||
|
||||
part_settings.total_restore_size = 0;
|
||||
|
||||
PartitionManager.Mount_All_Storage();
|
||||
LOGINFO("opening TW_ADB_BU_CONTROL\n");
|
||||
adb_control_bu_fd = open(TW_ADB_BU_CONTROL, O_WRONLY | O_NONBLOCK);
|
||||
LOGINFO("opening TW_ADB_TWRP_CONTROL\n");
|
||||
adb_control_twrp_fd = open(TW_ADB_TWRP_CONTROL, O_RDONLY | O_NONBLOCK);
|
||||
memset(&adbmd5, 0, sizeof(adbmd5));
|
||||
|
||||
DataManager::SetValue("tw_action", "clear");
|
||||
DataManager::SetValue("tw_action_text1", gui_lookup("running_recovery_commands", "Running Recovery Commands"));
|
||||
DataManager::SetValue("tw_action_text2", "");
|
||||
gui_changePage("action_page");
|
||||
|
||||
while (true) {
|
||||
memset(&cmd, 0, sizeof(cmd));
|
||||
if (read(adb_control_twrp_fd, cmd, sizeof(cmd)) > 0) {
|
||||
struct AdbBackupControlType cmdstruct;
|
||||
|
||||
memset(&cmdstruct, 0, sizeof(cmdstruct));
|
||||
memcpy(&cmdstruct, cmd, sizeof(cmdstruct));
|
||||
std::string cmdtype = cmdstruct.get_type();
|
||||
if (cmdtype == TWSTREAMHDR) {
|
||||
struct AdbBackupStreamHeader twhdr;
|
||||
memcpy(&twhdr, cmd, sizeof(cmd));
|
||||
LOGINFO("ADB Partition count: %" PRIu64 "\n", twhdr.partition_count);
|
||||
LOGINFO("ADB version: %" PRIu64 "\n", twhdr.version);
|
||||
if (twhdr.version != ADB_BACKUP_VERSION) {
|
||||
LOGERR("Incompatible adb backup version!\n");
|
||||
ret = false;
|
||||
break;
|
||||
}
|
||||
partition_count = twhdr.partition_count;
|
||||
}
|
||||
else if (cmdtype == MD5TRAILER) {
|
||||
LOGINFO("Reading ADB Backup MD5TRAILER\n");
|
||||
memcpy(&adbmd5, cmd, sizeof(cmd));
|
||||
}
|
||||
else if (cmdtype == TWMD5) {
|
||||
int check_digest;
|
||||
|
||||
DataManager::GetValue(TW_SKIP_DIGEST_CHECK_VAR, check_digest);
|
||||
if (check_digest > 0) {
|
||||
TWFunc::GUI_Operation_Text(TW_VERIFY_DIGEST_TEXT, gui_parse_text("{@verifying_digest}"));
|
||||
gui_msg("verifying_digest=Verifying Digest");
|
||||
struct AdbBackupFileTrailer md5check;
|
||||
LOGINFO("Verifying md5sums\n");
|
||||
|
||||
memset(&md5check, 0, sizeof(md5check));
|
||||
memcpy(&md5check, cmd, sizeof(cmd));
|
||||
if (strcmp(md5check.md5, adbmd5.md5) != 0) {
|
||||
LOGERR("md5 doesn't match!\n");
|
||||
LOGERR("Stored file md5: %s\n", adbmd5.md5);
|
||||
LOGERR("ADB Backup check md5: %s\n", md5check.md5);
|
||||
ret = false;
|
||||
break;
|
||||
}
|
||||
else {
|
||||
LOGINFO("ADB Backup md5 matches\n");
|
||||
LOGINFO("Stored file md5: %s\n", adbmd5.md5);
|
||||
LOGINFO("ADB Backup check md5: %s\n", md5check.md5);
|
||||
continue;
|
||||
}
|
||||
} else {
|
||||
gui_msg("skip_digest=Skipping Digest check based on user setting.");
|
||||
continue;
|
||||
}
|
||||
|
||||
}
|
||||
else if (cmdtype == TWENDADB) {
|
||||
LOGINFO("received TWENDADB\n");
|
||||
ret = 1;
|
||||
break;
|
||||
}
|
||||
else {
|
||||
struct twfilehdr twimghdr;
|
||||
memcpy(&twimghdr, cmd, sizeof(cmd));
|
||||
std::string cmdstr(twimghdr.type);
|
||||
Restore_Name = twimghdr.name;
|
||||
part_settings.total_restore_size = twimghdr.size;
|
||||
if (cmdtype == TWIMG) {
|
||||
LOGINFO("ADB Type: %s\n", twimghdr.type);
|
||||
LOGINFO("ADB Restore_Name: %s\n", Restore_Name.c_str());
|
||||
LOGINFO("ADB Restore_size: %" PRIu64 "\n", part_settings.total_restore_size);
|
||||
string compression = (twimghdr.compressed == 1) ? "compressed" : "uncompressed";
|
||||
LOGINFO("ADB compression: %s\n", compression.c_str());
|
||||
std::string Backup_FileName;
|
||||
std::size_t pos = Restore_Name.find_last_of("/");
|
||||
std::string path = "/" + Restore_Name.substr(pos, Restore_Name.size());
|
||||
pos = path.find_first_of(".");
|
||||
path = path.substr(0, pos);
|
||||
if (path.substr(0,1).compare("//")) {
|
||||
path = path.substr(1, path.size());
|
||||
}
|
||||
|
||||
pos = Restore_Name.find_last_of("/");
|
||||
Backup_FileName = Restore_Name.substr(pos + 1, Restore_Name.size());
|
||||
part_settings.Part = PartitionManager.Find_Partition_By_Path(path);
|
||||
part_settings.Backup_Folder = path;
|
||||
part_settings.partition_count = partition_count;
|
||||
part_settings.adbbackup = true;
|
||||
part_settings.adb_compression = twimghdr.compressed;
|
||||
part_settings.PM_Method = PM_RESTORE;
|
||||
ProgressTracking progress(part_settings.total_restore_size);
|
||||
part_settings.progress = &progress;
|
||||
if (!PartitionManager.Restore_Partition(&part_settings)) {
|
||||
LOGERR("ADB Restore failed.\n");
|
||||
ret = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
else if (cmdtype == TWFN) {
|
||||
LOGINFO("ADB Type: %s\n", twimghdr.type);
|
||||
LOGINFO("ADB Restore_Name: %s\n", Restore_Name.c_str());
|
||||
LOGINFO("ADB Restore_size: %" PRIi64 "\n", part_settings.total_restore_size);
|
||||
string compression = (twimghdr.compressed == 1) ? "compressed" : "uncompressed";
|
||||
LOGINFO("ADB compression: %s\n", compression.c_str());
|
||||
std::string Backup_FileName;
|
||||
std::size_t pos = Restore_Name.find_last_of("/");
|
||||
std::string path = "/" + Restore_Name.substr(pos, Restore_Name.size());
|
||||
pos = path.find_first_of(".");
|
||||
path = path.substr(0, pos);
|
||||
if (path.substr(0,1).compare("//")) {
|
||||
path = path.substr(1, path.size());
|
||||
}
|
||||
|
||||
pos = Restore_Name.find_last_of("/");
|
||||
Backup_FileName = Restore_Name.substr(pos + 1, Restore_Name.size());
|
||||
pos = Restore_Name.find_last_of("/");
|
||||
part_settings.Part = PartitionManager.Find_Partition_By_Path(path);
|
||||
part_settings.Part->Set_Backup_FileName(Backup_FileName);
|
||||
PartitionManager.Set_Restore_Files(path);
|
||||
|
||||
if (path.compare(PartitionManager.Get_Android_Root_Path()) == 0) {
|
||||
if (part_settings.Part->Is_Read_Only()) {
|
||||
if (!twadbbu::Write_TWERROR())
|
||||
LOGERR("Unable to write to TWRP ADB Backup.\n");
|
||||
gui_msg(Msg(msg::kError, "restore_read_only=Cannot restore {1} -- mounted read only.")(part_settings.Part->Backup_Display_Name));
|
||||
ret = false;
|
||||
break;
|
||||
|
||||
}
|
||||
}
|
||||
part_settings.partition_count = partition_count;
|
||||
part_settings.adbbackup = true;
|
||||
part_settings.adb_compression = twimghdr.compressed;
|
||||
part_settings.total_restore_size += part_settings.Part->Get_Restore_Size(&part_settings);
|
||||
part_settings.PM_Method = PM_RESTORE;
|
||||
ProgressTracking progress(part_settings.total_restore_size);
|
||||
part_settings.progress = &progress;
|
||||
if (!PartitionManager.Restore_Partition(&part_settings)) {
|
||||
LOGERR("ADB Restore failed.\n");
|
||||
ret = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (ret != false)
|
||||
gui_msg("restore_complete=Restore Complete");
|
||||
else
|
||||
gui_err("restore_error=Error during restore process.");
|
||||
|
||||
if (!twadbbu::Write_TWENDADB())
|
||||
ret = false;
|
||||
sleep(2); //give time for user to see messages on console
|
||||
DataManager::SetValue("ui_progress", 100);
|
||||
gui_changePage("main");
|
||||
close(adb_control_bu_fd);
|
||||
return ret;
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
/*
|
||||
Copyright 2013 to 2017 TeamWin
|
||||
This file is part of TWRP/TeamWin Recovery Project.
|
||||
|
||||
TWRP 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 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
TWRP 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 TWRP. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef TWRPADBFIFO_HPP
|
||||
#define TWRPADBFIFO_HPP
|
||||
|
||||
#include <string>
|
||||
#include <pthread.h>
|
||||
|
||||
#define TW_ADB_FIFO "/tmp/twadbfifo"
|
||||
|
||||
class twrpAdbBuFifo {
|
||||
public:
|
||||
twrpAdbBuFifo(void);
|
||||
pthread_t threadAdbBuFifo(void);
|
||||
private:
|
||||
bool start(void);
|
||||
bool Backup_ADB_Command(std::string Options);
|
||||
void Check_Adb_Fifo_For_Events(void);
|
||||
bool Restore_ADB_Backup(void);
|
||||
typedef bool (twrpAdbBuFifo::*ThreadPtr)(void);
|
||||
typedef void* (*PThreadPtr)(void *);
|
||||
int adb_fifo_fd;
|
||||
};
|
||||
#endif
|
||||
@@ -0,0 +1,194 @@
|
||||
#include "twrpApex.hpp"
|
||||
#include "twrp-functions.hpp"
|
||||
#include "common.h"
|
||||
|
||||
namespace fs = std::filesystem;
|
||||
|
||||
bool twrpApex::loadApexImages() {
|
||||
std::vector<std::string> apexFiles;
|
||||
std::vector<std::string> checkApexFlatFiles;
|
||||
#ifdef TW_ADDITIONAL_APEX_FILES
|
||||
char* additionalFiles = strdup(EXPAND(TW_ADDITIONAL_APEX_FILES));
|
||||
char* additionalApexFiles = std::strtok(additionalFiles, " ");
|
||||
#endif
|
||||
|
||||
apexFiles.push_back(APEX_DIR "/com.android.apex.cts.shim.apex");
|
||||
apexFiles.push_back(APEX_DIR "/com.google.android.tzdata2.apex");
|
||||
apexFiles.push_back(APEX_DIR "/com.android.tzdata.apex");
|
||||
apexFiles.push_back(APEX_DIR "/com.android.art.release.apex");
|
||||
apexFiles.push_back(APEX_DIR "/com.google.android.media.swcodec.apex");
|
||||
apexFiles.push_back(APEX_DIR "/com.android.media.swcodec.apex");
|
||||
|
||||
#ifdef TW_ADDITIONAL_APEX_FILES
|
||||
while(additionalApexFiles) {
|
||||
std::stringstream apexFile;
|
||||
apexFile << APEX_DIR << "/" << additionalApexFiles;
|
||||
apexFiles.push_back(apexFile.str());
|
||||
additionalApexFiles = std::strtok(nullptr, " ");
|
||||
}
|
||||
#endif
|
||||
|
||||
if (access(APEX_DIR, F_OK) != 0) {
|
||||
LOGERR("Unable to open %s\n", APEX_DIR);
|
||||
return false;
|
||||
}
|
||||
for (const auto& entry : fs::directory_iterator(APEX_DIR)) {
|
||||
if (entry.is_regular_file()) {
|
||||
checkApexFlatFiles.push_back(entry.path().string());
|
||||
}
|
||||
}
|
||||
|
||||
if (checkApexFlatFiles.size() == 0) {
|
||||
// flattened apex directory
|
||||
LOGINFO("Bind mounting flattened apex directory\n");
|
||||
if (mount(APEX_DIR, APEX_BASE, "", MS_BIND, NULL) < 0) {
|
||||
LOGERR("Unable to bind mount flattened apex directory\n");
|
||||
return false;
|
||||
}
|
||||
android::base::SetProperty("twrp.apex.flattened", "true");
|
||||
return true;
|
||||
}
|
||||
if (!mountApexOnLoopbackDevices(apexFiles)) {
|
||||
LOGERR("Unable to create loop devices to mount apex files\n");
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
std::string twrpApex::unzipImage(std::string file) {
|
||||
ZipArchiveHandle handle;
|
||||
int32_t ret = OpenArchive(file.c_str(), &handle);
|
||||
if (ret != 0) {
|
||||
LOGINFO("unable to open zip archive %s. Reason: %s\n", file.c_str(), strerror(errno));
|
||||
return std::string();
|
||||
}
|
||||
|
||||
ZipEntry entry;
|
||||
std::string zip_string(APEX_PAYLOAD);
|
||||
ret = FindEntry(handle, zip_string, &entry);
|
||||
if (ret != 0) {
|
||||
LOGERR("unable to find %s in zip\n", APEX_PAYLOAD);
|
||||
CloseArchive(handle);
|
||||
return std::string();
|
||||
}
|
||||
|
||||
std::string baseFile = basename(file.c_str());
|
||||
std::string path("/tmp/");
|
||||
path = path + baseFile;
|
||||
int fd = open(path.c_str(), O_WRONLY|O_CREAT|O_TRUNC, 0666);
|
||||
ret = ExtractEntryToFile(handle, &entry, fd);
|
||||
if (ret != 0) {
|
||||
LOGERR("unable to extract %s\n", path.c_str());
|
||||
close(fd);
|
||||
CloseArchive(handle);
|
||||
return std::string();
|
||||
}
|
||||
|
||||
CloseArchive(handle);
|
||||
close(fd);
|
||||
return path;
|
||||
}
|
||||
|
||||
bool twrpApex::mountApexOnLoopbackDevices(std::vector<std::string> apexFiles) {
|
||||
int fd = open(LOOP_CONTROL, O_RDWR | O_CLOEXEC);
|
||||
if (fd < 0) {
|
||||
LOGERR("Unable to open %s device. Reason: %s\n", LOOP_CONTROL, strerror(errno));
|
||||
return false;
|
||||
}
|
||||
|
||||
size_t device_no = 0;
|
||||
for (auto&& apexFile:apexFiles) {
|
||||
int num = ioctl(fd, LOOP_CTL_GET_FREE);
|
||||
std::string loop_device = LOOP_BLOCK_DEVICE_DIR;
|
||||
loop_device = loop_device + "loop" + std::to_string(num);
|
||||
if (!TWFunc::Path_Exists(loop_device)) {
|
||||
int ret = mknod(loop_device.c_str(), S_IFBLK | S_IRUSR | S_IWUSR , makedev(7, device_no));
|
||||
if (ret != 0) {
|
||||
LOGERR("Unable to create loop device: %s\n", loop_device.c_str());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
std::string fileToMount = unzipImage(apexFile);
|
||||
if (fileToMount.empty()) {
|
||||
LOGINFO("Skipping non-existent apex file: %s\n", apexFile.c_str());
|
||||
continue;
|
||||
}
|
||||
bool load_result = loadApexImage(fileToMount, device_no);
|
||||
if (!load_result) {
|
||||
return false;
|
||||
}
|
||||
device_no++;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool twrpApex::loadApexImage(std::string fileToMount, size_t loop_device_number) {
|
||||
struct loop_info64 info;
|
||||
|
||||
int fd = open(fileToMount.c_str(), O_RDONLY | O_CLOEXEC);
|
||||
if (fd < 0) {
|
||||
LOGERR("unable to open apex file: %s. Reason: %s\n", fileToMount.c_str(), strerror(errno));
|
||||
return false;
|
||||
}
|
||||
|
||||
std::string loop_device = "/dev/block/loop" + std::to_string(loop_device_number);
|
||||
int loop_fd = open(loop_device.c_str(), O_RDONLY);
|
||||
if (loop_fd < 0) {
|
||||
LOGERR("unable to open loop device: %s\n", loop_device.c_str());
|
||||
close(fd);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (ioctl(loop_fd, LOOP_SET_FD, fd) < 0) {
|
||||
LOGERR("failed to mount %s to loop device %s. Reason: %s\n", fileToMount.c_str(), loop_device.c_str(),
|
||||
strerror(errno));
|
||||
close(fd);
|
||||
close(loop_fd);
|
||||
return false;
|
||||
}
|
||||
|
||||
close(fd);
|
||||
|
||||
memset(&info, 0, sizeof(struct loop_info64));
|
||||
strlcpy((char*)info.lo_crypt_name, "twrpApex", LO_NAME_SIZE);
|
||||
off_t apex_size = lseek(fd, 0, SEEK_END);
|
||||
info.lo_sizelimit = apex_size;
|
||||
if (ioctl(loop_fd, LOOP_SET_STATUS64, &info)) {
|
||||
LOGERR("failed to mount loop: %s: %s\n", fileToMount.c_str(), strerror(errno));
|
||||
close(loop_fd);
|
||||
return false;
|
||||
}
|
||||
if (ioctl(loop_fd, BLKFLSBUF, 0) == -1) {
|
||||
LOGERR("Unable to flush loop device buffers\n");
|
||||
return false;
|
||||
}
|
||||
if (ioctl(loop_fd, LOOP_SET_BLOCK_SIZE, 4096) == -1) {
|
||||
LOGINFO("Failed to set DIRECT_IO buffer size\n");
|
||||
}
|
||||
close(loop_fd);
|
||||
|
||||
std::string bind_mount(APEX_BASE);
|
||||
std::string apex_cleaned_mount = fileToMount;
|
||||
apex_cleaned_mount = std::regex_replace(apex_cleaned_mount, std::regex("\\.apex"), "");
|
||||
|
||||
bind_mount = bind_mount + basename(apex_cleaned_mount.c_str());
|
||||
|
||||
int ret = mkdir(bind_mount.c_str(), 0666);
|
||||
if (ret != 0) {
|
||||
LOGERR("Unable to create bind mount directory: %s\n", bind_mount.c_str());
|
||||
return false;
|
||||
}
|
||||
|
||||
ret = mount(loop_device.c_str(), bind_mount.c_str(), "ext4", MS_RDONLY, nullptr);
|
||||
if (ret != 0) {
|
||||
LOGERR("unable to mount loop device %s to %s. Reason: %s\n", loop_device.c_str(), bind_mount.c_str(), strerror(errno));
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool twrpApex::Unmount() {
|
||||
return (umount2(APEX_BASE, MNT_DETACH) == 0);
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
|
||||
#ifndef TWRPAPEX_HPP
|
||||
#define TWRPAPEX_HPP
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <filesystem>
|
||||
#include <regex>
|
||||
#include <sstream>
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <linux/loop.h>
|
||||
#include <sys/mount.h>
|
||||
#include <sys/sysmacros.h>
|
||||
#include <fcntl.h>
|
||||
#include <unistd.h>
|
||||
#include <android-base/properties.h>
|
||||
|
||||
#include <ziparchive/zip_archive.h>
|
||||
#include "twcommon.h"
|
||||
|
||||
#define APEX_DIR "/system_root/system/apex"
|
||||
#define APEX_PAYLOAD "apex_payload.img"
|
||||
#define LOOP_BLOCK_DEVICE_DIR "/dev/block/"
|
||||
#define APEX_BASE "/apex/"
|
||||
#define LOOP_CONTROL "/dev/loop-control"
|
||||
|
||||
class twrpApex {
|
||||
public:
|
||||
bool loadApexImages();
|
||||
bool Unmount();
|
||||
|
||||
private:
|
||||
std::string unzipImage(std::string file);
|
||||
bool mountApexOnLoopbackDevices(std::vector<std::string> apexFiles);
|
||||
bool loadApexImage(std::string fileToMount, size_t loop_device_number);
|
||||
};
|
||||
#endif
|
||||
@@ -0,0 +1,230 @@
|
||||
/*
|
||||
Copyright 2013 to 2017 TeamWin
|
||||
This file is part of TWRP/TeamWin Recovery Project.
|
||||
|
||||
TWRP 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 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
TWRP 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 TWRP. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
|
||||
#include <fcntl.h>
|
||||
#include <string>
|
||||
#include <unistd.h>
|
||||
#include "data.hpp"
|
||||
#include "partitions.hpp"
|
||||
#include "set_metadata.h"
|
||||
#include "twrpDigestDriver.hpp"
|
||||
#include "twrp-functions.hpp"
|
||||
#include "twcommon.h"
|
||||
#include "variables.h"
|
||||
#include "gui/gui.hpp"
|
||||
#include "twrpDigest/twrpDigest.hpp"
|
||||
#include "twrpDigest/twrpMD5.hpp"
|
||||
#include "twrpDigest/twrpSHA.hpp"
|
||||
|
||||
|
||||
bool twrpDigestDriver::Check_File_Digest(const string& Filename) {
|
||||
twrpDigest *digest;
|
||||
string digestfile = Filename, file_name = Filename;
|
||||
string digest_str;
|
||||
bool use_sha2 = false;
|
||||
|
||||
#ifndef TW_NO_SHA2_LIBRARY
|
||||
|
||||
digestfile += ".sha2";
|
||||
if (TWFunc::Path_Exists(digestfile)) {
|
||||
digest = new twrpSHA256();
|
||||
use_sha2 = true;
|
||||
}
|
||||
else {
|
||||
digestfile = Filename + ".sha256";
|
||||
if (TWFunc::Path_Exists(digestfile)) {
|
||||
digest = new twrpSHA256();
|
||||
use_sha2 = true;
|
||||
} else {
|
||||
digest = new twrpMD5();
|
||||
digestfile = Filename + ".md5";
|
||||
if (!TWFunc::Path_Exists(digestfile)) {
|
||||
digestfile = Filename + ".md5sum";
|
||||
}
|
||||
}
|
||||
}
|
||||
#else
|
||||
digest = new twrpMD5();
|
||||
digestfile = Filename + ".md5";
|
||||
if (!TWFunc::Path_Exists(digestfile)) {
|
||||
digestfile = Filename + ".md5sum";
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
if (!TWFunc::Path_Exists(digestfile)) {
|
||||
delete digest;
|
||||
gui_msg(Msg(msg::kWarning, "no_digest=Skipping Digest check: no Digest file found"));
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
if (TWFunc::read_file(digestfile, digest_str) != 0) {
|
||||
gui_msg("digest_error=Digest Error!");
|
||||
delete digest;
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!stream_file_to_digest(file_name, digest)) {
|
||||
delete digest;
|
||||
return false;
|
||||
}
|
||||
string digest_check = digest->return_digest_string();
|
||||
digest_check = digest_check + " " + TWFunc::Get_Filename(file_name);
|
||||
if (digest_check == digest_str) {
|
||||
if (use_sha2)
|
||||
LOGINFO("SHA2 Digest: %s %s\n", digest_str.c_str(), TWFunc::Get_Filename(Filename).c_str());
|
||||
else
|
||||
LOGINFO("MD5 Digest: %s %s\n", digest_str.c_str(), TWFunc::Get_Filename(Filename).c_str());
|
||||
gui_msg(Msg("digest_matched=Digest matched for '{1}'.")(Filename));
|
||||
delete digest;
|
||||
return true;
|
||||
}
|
||||
|
||||
gui_msg(Msg(msg::kError, "digest_fail_match=Digest failed to match on '{1}'.")(Filename));
|
||||
delete digest;
|
||||
return false;
|
||||
}
|
||||
|
||||
bool twrpDigestDriver::Check_Digest(string Full_Filename) {
|
||||
char split_filename[512];
|
||||
int index = 0;
|
||||
|
||||
sync();
|
||||
if (!TWFunc::Path_Exists(Full_Filename)) {
|
||||
// This is a split archive, we presume
|
||||
memset(split_filename, 0, sizeof(split_filename));
|
||||
while (index < 1000) {
|
||||
sprintf(split_filename, "%s%03i", Full_Filename.c_str(), index);
|
||||
if (!TWFunc::Path_Exists(split_filename))
|
||||
break;
|
||||
LOGINFO("split_filename: %s\n", split_filename);
|
||||
if (!Check_File_Digest(split_filename))
|
||||
return false;
|
||||
index++;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return Check_File_Digest(Full_Filename); // Single file archive
|
||||
}
|
||||
|
||||
bool twrpDigestDriver::Write_Digest(string Full_Filename) {
|
||||
twrpDigest *digest;
|
||||
string digest_filename, digest_str;
|
||||
int use_sha2;
|
||||
|
||||
#ifdef TW_NO_SHA2_LIBRARY
|
||||
use_sha2 = 0;
|
||||
#else
|
||||
DataManager::GetValue(TW_USE_SHA2, use_sha2);
|
||||
#endif
|
||||
|
||||
if (use_sha2) {
|
||||
#ifndef TW_NO_SHA2_LIBRARY
|
||||
digest = new twrpSHA256();
|
||||
digest_filename = Full_Filename + ".sha2";
|
||||
if (!stream_file_to_digest(Full_Filename, digest)) {
|
||||
delete digest;
|
||||
return false;
|
||||
}
|
||||
digest_str = digest->return_digest_string();
|
||||
if (digest_str.empty()) {
|
||||
delete digest;
|
||||
return false;
|
||||
}
|
||||
LOGINFO("SHA2 Digest: %s %s\n", digest_str.c_str(), TWFunc::Get_Filename(Full_Filename).c_str());
|
||||
#endif
|
||||
}
|
||||
else {
|
||||
digest = new twrpMD5();
|
||||
digest_filename = Full_Filename + ".md5";
|
||||
if (!stream_file_to_digest(Full_Filename, digest)) {
|
||||
delete digest;
|
||||
return false;
|
||||
}
|
||||
digest_str = digest->return_digest_string();
|
||||
if (digest_str.empty()) {
|
||||
delete digest;
|
||||
return false;
|
||||
}
|
||||
LOGINFO("MD5 Digest: %s %s\n", digest_str.c_str(), TWFunc::Get_Filename(Full_Filename).c_str());
|
||||
}
|
||||
|
||||
digest_str = digest_str + " " + TWFunc::Get_Filename(Full_Filename) + "\n";
|
||||
LOGINFO("digest_filename: %s\n", digest_filename.c_str());
|
||||
|
||||
if (TWFunc::write_to_file(digest_filename, digest_str)) {
|
||||
tw_set_default_metadata(digest_filename.c_str());
|
||||
gui_msg("digest_created= * Digest Created.");
|
||||
}
|
||||
else {
|
||||
gui_err("digest_error= * Digest Error!");
|
||||
delete digest;
|
||||
return false;
|
||||
}
|
||||
delete digest;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool twrpDigestDriver::Make_Digest(string Full_Filename) {
|
||||
string command, result;
|
||||
|
||||
TWFunc::GUI_Operation_Text(TW_GENERATE_DIGEST_TEXT, gui_parse_text("{@generating_digest1}"));
|
||||
gui_msg("generating_digest2= * Generating digest...");
|
||||
if (TWFunc::Path_Exists(Full_Filename)) {
|
||||
if (!Write_Digest(Full_Filename))
|
||||
return false;
|
||||
} else {
|
||||
char filename[512];
|
||||
int index = 0;
|
||||
sprintf(filename, "%s%03i", Full_Filename.c_str(), index);
|
||||
while (index < 1000) {
|
||||
string digest_src(filename);
|
||||
if (TWFunc::Path_Exists(filename)) {
|
||||
if (!Write_Digest(filename))
|
||||
return false;
|
||||
}
|
||||
else
|
||||
break;
|
||||
index++;
|
||||
sprintf(filename, "%s%03i", Full_Filename.c_str(), index);
|
||||
}
|
||||
if (index == 0) {
|
||||
LOGERR("Backup file: '%s' not found!\n", filename);
|
||||
return false;
|
||||
}
|
||||
gui_msg("digest_created= * Digest Created.");
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool twrpDigestDriver::stream_file_to_digest(string filename, twrpDigest* digest) {
|
||||
char buf[4096];
|
||||
int bytes;
|
||||
|
||||
int fd = open(filename.c_str(), O_RDONLY);
|
||||
if (fd < 0) {
|
||||
return false;
|
||||
}
|
||||
while ((bytes = read(fd, &buf, sizeof(buf))) != 0) {
|
||||
digest->update((unsigned char*)buf, bytes);
|
||||
}
|
||||
close(fd);
|
||||
return true;
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
/*
|
||||
Copyright 2013 to 2017 TeamWin
|
||||
This file is part of TWRP/TeamWin Recovery Project.
|
||||
|
||||
TWRP 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 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
TWRP 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 TWRP. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef __TWRP_DIGEST_DRIVER
|
||||
#define __TWRP_DIGEST_DRIVER
|
||||
#include <string>
|
||||
#include "twrpDigest/twrpDigest.hpp"
|
||||
|
||||
class twrpDigestDriver {
|
||||
public:
|
||||
|
||||
static bool Check_File_Digest(const string& Filename); //Check the digest of a TWRP partition backup
|
||||
static bool Check_Digest(string Full_Filename); //Check to make sure the digest is correct
|
||||
static bool Write_Digest(string Full_Filename); //Write the digest to a file
|
||||
static bool Make_Digest(string Full_Filename); //Create the digest for a partition backup
|
||||
static bool stream_file_to_digest(string filename, twrpDigest* digest); //Stream the file to twrpDigest
|
||||
};
|
||||
#endif //__TWRP_DIGEST_DRIVER
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,25 @@
|
||||
/*
|
||||
Copyright 2012 bigbiff/Dees_Troy TeamWin
|
||||
This file is part of TWRP/TeamWin Recovery Project.
|
||||
|
||||
TWRP 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 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
TWRP 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 TWRP. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef _TWRPTAR_HEADER
|
||||
#define _TWRPTAR_HEADER
|
||||
|
||||
ssize_t write_tar(int fd, const void *buffer, size_t size);
|
||||
ssize_t write_tar_no_buffer(int fd, const void *buffer, size_t size);
|
||||
|
||||
#endif // _TWRPTAR_HEADER
|
||||
@@ -0,0 +1,110 @@
|
||||
/*
|
||||
Copyright 2012 to 2016 bigbiff/Dees_Troy TeamWin
|
||||
This file is part of TWRP/TeamWin Recovery Project.
|
||||
|
||||
TWRP 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 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
TWRP 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 TWRP. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
extern "C" {
|
||||
#include "libtar/libtar.h"
|
||||
}
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#include <fstream>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include "exclude.hpp"
|
||||
#include "progresstracking.hpp"
|
||||
#include "partitions.hpp"
|
||||
#include "twrp-functions.hpp"
|
||||
|
||||
using namespace std;
|
||||
|
||||
struct TarListStruct {
|
||||
std::string fn;
|
||||
unsigned thread_id;
|
||||
};
|
||||
|
||||
struct thread_data_struct {
|
||||
std::vector<TarListStruct> *TarList;
|
||||
unsigned thread_id;
|
||||
};
|
||||
|
||||
class twrpTar {
|
||||
public:
|
||||
twrpTar();
|
||||
virtual ~twrpTar();
|
||||
int createTarFork(pid_t *tar_fork_pid);
|
||||
int extractTarFork();
|
||||
void setfn(string fn);
|
||||
void setdir(string dir);
|
||||
void setsize(unsigned long long backup_size);
|
||||
void setpassword(string pass);
|
||||
unsigned long long get_size();
|
||||
void Set_Archive_Type(Archive_Type archive_type);
|
||||
|
||||
public:
|
||||
int use_encryption;
|
||||
int userdata_encryption;
|
||||
int use_compression;
|
||||
int split_archives;
|
||||
string backup_name;
|
||||
int progress_pipe_fd;
|
||||
string partition_name;
|
||||
string backup_folder;
|
||||
PartitionSettings *part_settings;
|
||||
TWExclude *backup_exclusions;
|
||||
|
||||
private:
|
||||
int extract();
|
||||
int addFilesToExistingTar(vector <string> files, string tarFile);
|
||||
int createTar();
|
||||
int addFile(string fn, bool include_root);
|
||||
int entryExists(string entry);
|
||||
int closeTar();
|
||||
int removeEOT(string tarFile);
|
||||
int extractTar();
|
||||
string Strip_Root_Dir(string Path);
|
||||
int openTar();
|
||||
int Generate_TarList(string Path, std::vector<TarListStruct> *TarList, unsigned long long *Target_Size, unsigned *thread_id);
|
||||
static void* createList(void *cookie);
|
||||
static void* extractMulti(void *cookie);
|
||||
int tarList(std::vector<TarListStruct> *TarList, unsigned thread_id);
|
||||
unsigned long long uncompressedSize(string filename);
|
||||
static void Signal_Kill(int signum);
|
||||
|
||||
enum Archive_Type current_archive_type;
|
||||
unsigned long long Archive_Current_Size;
|
||||
unsigned long long Total_Backup_Size;
|
||||
bool include_root_dir;
|
||||
TAR *t;
|
||||
tartype_t tar_type; // Only used in createTar() but variable must persist while the tar is open
|
||||
int fd;
|
||||
int input_fd; // this stores the fd for libtar to write to
|
||||
pid_t pigz_pid;
|
||||
pid_t oaes_pid;
|
||||
unsigned long long file_count;
|
||||
|
||||
string tardir;
|
||||
string tarfn;
|
||||
string basefn;
|
||||
string password;
|
||||
|
||||
std::vector<TarListStruct> *ItemList;
|
||||
int output_fd; // this stores the output fd that gzip will read from
|
||||
unsigned thread_id;
|
||||
};
|
||||
@@ -0,0 +1,6 @@
|
||||
build = ["sources.bp"]
|
||||
|
||||
cc_library_static {
|
||||
name: "libscrypttwrp_static",
|
||||
include_dirs: ["bootable/recovery/crypto/scrypt/lib/util"]
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
LOCAL_PATH := $(call my-dir)
|
||||
|
||||
# Enable to be able to use ALOG* with #include "cutils/log.h"
|
||||
#log_c_includes += system/core/include
|
||||
#log_shared_libraries := liblog
|
||||
|
||||
# These makefiles are here instead of being Android.mk files in the
|
||||
# respective crypto, ssl, and apps directories so
|
||||
# that import_openssl.sh import won't remove them.
|
||||
include $(LOCAL_PATH)/build-config.mk
|
||||
include $(LOCAL_PATH)/Scrypt.mk
|
||||
|
||||
include $(LOCAL_PATH)/tests/Android.mk
|
||||
@@ -0,0 +1,36 @@
|
||||
/*-
|
||||
* Copyright 2009 Colin Percival
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* This file was originally written by Colin Percival as part of the Tarsnap
|
||||
* online backup system.
|
||||
*/
|
||||
|
||||
/*
|
||||
* version 20110505
|
||||
* D. J. Bernstein
|
||||
* Public domain.
|
||||
*
|
||||
* Based on crypto_core/salsa208/armneon/core.c from SUPERCOP 20130419
|
||||
*/
|
||||
@@ -0,0 +1,105 @@
|
||||
# Auto-generated - DO NOT EDIT!
|
||||
# To regenerate, edit scrypt.config, then run:
|
||||
# ./import_scrypt.sh import /path/to/scrypt-1.1.6.tar.gz
|
||||
#
|
||||
# Before including this file, the local Android.mk must define the following
|
||||
# variables:
|
||||
#
|
||||
# local_c_flags
|
||||
# local_c_includes
|
||||
# local_additional_dependencies
|
||||
#
|
||||
# This script will define the following variables:
|
||||
#
|
||||
# target_c_flags
|
||||
# target_c_includes
|
||||
# target_src_files
|
||||
#
|
||||
# host_c_flags
|
||||
# host_c_includes
|
||||
# host_src_files
|
||||
#
|
||||
|
||||
# Ensure these are empty.
|
||||
unknown_arch_c_flags :=
|
||||
unknown_arch_src_files :=
|
||||
unknown_arch_exclude_files :=
|
||||
|
||||
|
||||
common_c_flags :=
|
||||
|
||||
common_src_files := \
|
||||
lib/crypto/crypto_scrypt-ref.c \
|
||||
|
||||
common_c_includes := \
|
||||
lib/crypto \
|
||||
lib/util \
|
||||
|
||||
arm_c_flags :=
|
||||
|
||||
arm_src_files :=
|
||||
|
||||
arm_exclude_files :=
|
||||
|
||||
arm_neon_c_flags :=
|
||||
|
||||
arm_neon_src_files := \
|
||||
lib/crypto/crypto_scrypt-neon.c \
|
||||
|
||||
arm_neon_exclude_files := \
|
||||
lib/crypto/crypto_scrypt-ref.c \
|
||||
|
||||
x86_c_flags :=
|
||||
|
||||
x86_src_files := \
|
||||
lib/crypto/crypto_scrypt-sse.c \
|
||||
|
||||
x86_exclude_files := \
|
||||
lib/crypto/crypto_scrypt-ref.c \
|
||||
|
||||
x86_64_c_flags :=
|
||||
|
||||
x86_64_src_files := \
|
||||
lib/crypto/crypto_scrypt-sse.c \
|
||||
|
||||
x86_64_exclude_files := \
|
||||
lib/crypto/crypto_scrypt-ref.c \
|
||||
|
||||
mips_c_flags :=
|
||||
|
||||
mips_src_files :=
|
||||
|
||||
mips_exclude_files :=
|
||||
|
||||
target_arch := $(TARGET_ARCH)
|
||||
ifeq ($(target_arch)-$(TARGET_HAS_BIGENDIAN),mips-true)
|
||||
target_arch := unknown_arch
|
||||
endif
|
||||
|
||||
target_c_flags := $(common_c_flags) $($(target_arch)_c_flags) $(local_c_flags)
|
||||
target_c_includes := $(addprefix external/scrypt/,$(common_c_includes)) $(local_c_includes)
|
||||
target_src_files := $(common_src_files) $($(target_arch)_src_files)
|
||||
target_src_files := $(filter-out $($(target_arch)_exclude_files), $(target_src_files))
|
||||
|
||||
# Hacks for ARM NEON support
|
||||
ifneq (,$(filter $(target_arch), arm arm64))
|
||||
ifeq ($(ARCH_ARM_HAVE_NEON),true)
|
||||
target_c_flags += $(arm_neon_c_flags)
|
||||
target_src_files += $(arm_neon_src_files)
|
||||
target_src_files := $(filter-out $(arm_neon_exclude_files), $(target_src_files))
|
||||
endif
|
||||
endif
|
||||
|
||||
ifeq ($(HOST_OS)-$(HOST_ARCH),linux-x86)
|
||||
host_arch := x86
|
||||
else
|
||||
host_arch := unknown_arch
|
||||
endif
|
||||
|
||||
host_c_flags := $(common_c_flags) $($(host_arch)_c_flags) $(local_c_flags)
|
||||
host_c_includes := $(addprefix external/scrypt/,$(common_c_includes)) $(local_c_includes)
|
||||
host_src_files := $(common_src_files) $($(host_arch)_src_files)
|
||||
host_src_files := $(filter-out $($(host_arch)_exclude_files), $(host_src_files))
|
||||
|
||||
local_additional_dependencies += $(LOCAL_PATH)/Scrypt-config.mk
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
local_c_flags := -DUSE_OPENSSL_PBKDF2
|
||||
|
||||
local_c_includes := $(log_c_includes) external/openssl/include external/boringssl/src/include
|
||||
|
||||
local_additional_dependencies := $(LOCAL_PATH)/android-config.mk $(LOCAL_PATH)/Scrypt.mk
|
||||
|
||||
include $(LOCAL_PATH)/Scrypt-config.mk
|
||||
@@ -0,0 +1,16 @@
|
||||
#
|
||||
# These flags represent the build-time configuration of scrypt for Android
|
||||
#
|
||||
# The value of $(scrypt_cflags) was pruned from the Makefile generated
|
||||
# by running ./configure from import_scrypt.sh.
|
||||
#
|
||||
# This script performs minor but required patching for the Android build.
|
||||
#
|
||||
|
||||
LOCAL_CFLAGS += $(scrypt_cflags)
|
||||
|
||||
# Add in flags to let config.h be read properly
|
||||
LOCAL_CFLAGS += "-DHAVE_CONFIG_H"
|
||||
|
||||
# Add clang here when it works on host
|
||||
# LOCAL_CLANG := true
|
||||
@@ -0,0 +1,6 @@
|
||||
# Auto-generated - DO NOT EDIT!
|
||||
# To regenerate, edit scrypt.config, then run:
|
||||
# ./import_scrypt.sh import /path/to/scrypt-1.1.6.tar.gz
|
||||
#
|
||||
scrypt_cflags := \
|
||||
|
||||
@@ -0,0 +1,99 @@
|
||||
/* config.h. Generated from config.h.in by configure. */
|
||||
/* config.h.in. Generated from configure.ac by autoheader. */
|
||||
|
||||
/* Define to 1 if you have the `clock_gettime' function. */
|
||||
#define HAVE_CLOCK_GETTIME 1
|
||||
|
||||
/* Define to 1 if you have the declaration of `be64enc', and to 0 if you
|
||||
don't. */
|
||||
#define HAVE_DECL_BE64ENC 0
|
||||
|
||||
/* Define to 1 if you have the <err.h> header file. */
|
||||
#define HAVE_ERR_H 1
|
||||
|
||||
/* Define to 1 if you have the <inttypes.h> header file. */
|
||||
#define HAVE_INTTYPES_H 1
|
||||
|
||||
/* Define to 1 if you have the `rt' library (-lrt). */
|
||||
#define HAVE_LIBRT 1
|
||||
|
||||
/* Define to 1 if you have the <memory.h> header file. */
|
||||
#define HAVE_MEMORY_H 1
|
||||
|
||||
/* Define to 1 if you have the `posix_memalign' function. */
|
||||
#define HAVE_POSIX_MEMALIGN 1
|
||||
|
||||
/* Define to 1 if you have the <stdint.h> header file. */
|
||||
#define HAVE_STDINT_H 1
|
||||
|
||||
/* Define to 1 if you have the <stdlib.h> header file. */
|
||||
#define HAVE_STDLIB_H 1
|
||||
|
||||
/* Define to 1 if you have the <strings.h> header file. */
|
||||
#define HAVE_STRINGS_H 1
|
||||
|
||||
/* Define to 1 if you have the <string.h> header file. */
|
||||
#define HAVE_STRING_H 1
|
||||
|
||||
/* Define to 1 if the system has the type `struct sysinfo'. */
|
||||
#define HAVE_STRUCT_SYSINFO 1
|
||||
|
||||
/* Define to 1 if `mem_unit' is member of `struct sysinfo'. */
|
||||
#define HAVE_STRUCT_SYSINFO_MEM_UNIT 1
|
||||
|
||||
/* Define to 1 if `totalram' is member of `struct sysinfo'. */
|
||||
#define HAVE_STRUCT_SYSINFO_TOTALRAM 1
|
||||
|
||||
/* Define to 1 if the OS has a hw.usermem sysctl */
|
||||
/* #undef HAVE_SYSCTL_HW_USERMEM */
|
||||
|
||||
/* Define to 1 if you have the `sysinfo' function. */
|
||||
#define HAVE_SYSINFO 1
|
||||
|
||||
/* Define to 1 if you have the <sys/endian.h> header file. */
|
||||
/* #undef HAVE_SYS_ENDIAN_H */
|
||||
|
||||
/* Define to 1 if you have the <sys/param.h> header file. */
|
||||
#define HAVE_SYS_PARAM_H 1
|
||||
|
||||
/* Define to 1 if you have the <sys/stat.h> header file. */
|
||||
#define HAVE_SYS_STAT_H 1
|
||||
|
||||
/* Define to 1 if you have the <sys/sysinfo.h> header file. */
|
||||
#define HAVE_SYS_SYSINFO_H 1
|
||||
|
||||
/* Define to 1 if you have the <sys/types.h> header file. */
|
||||
#define HAVE_SYS_TYPES_H 1
|
||||
|
||||
/* Define to 1 if you have the <unistd.h> header file. */
|
||||
#define HAVE_UNISTD_H 1
|
||||
|
||||
/* Name of package */
|
||||
#define PACKAGE "scrypt"
|
||||
|
||||
/* Define to the address where bug reports for this package should be sent. */
|
||||
#define PACKAGE_BUGREPORT ""
|
||||
|
||||
/* Define to the full name of this package. */
|
||||
#define PACKAGE_NAME "scrypt"
|
||||
|
||||
/* Define to the full name and version of this package. */
|
||||
#define PACKAGE_STRING "scrypt 1.1.6"
|
||||
|
||||
/* Define to the one symbol short name of this package. */
|
||||
#define PACKAGE_TARNAME "scrypt"
|
||||
|
||||
/* Define to the version of this package. */
|
||||
#define PACKAGE_VERSION "1.1.6"
|
||||
|
||||
/* Define to 1 if you have the ANSI C header files. */
|
||||
#define STDC_HEADERS 1
|
||||
|
||||
/* Version number of package */
|
||||
#define VERSION "1.1.6"
|
||||
|
||||
/* Number of bits in a file offset, on hosts where this is settable. */
|
||||
/* #undef _FILE_OFFSET_BITS */
|
||||
|
||||
/* Define for large files, on AIX-style hosts. */
|
||||
/* #undef _LARGE_FILES */
|
||||
@@ -0,0 +1,493 @@
|
||||
#!/bin/bash
|
||||
#
|
||||
# Copyright (C) 2009 The Android Open Source Project
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
#
|
||||
|
||||
#
|
||||
# This script imports new versions of scrypt (http://www.tarsnap.com/scrypt/) into the
|
||||
# Android source tree. To run, (1) fetch the appropriate tarball from the scrypt repository,
|
||||
# (2) check the gpg/pgp signature, and then (3) run:
|
||||
# ./import_scrypt.sh import scrypt-*.tar.gz
|
||||
#
|
||||
# IMPORTANT: See README.android for additional details.
|
||||
|
||||
# turn on exit on error as well as a warning when it happens
|
||||
set -e
|
||||
set -x
|
||||
trap "echo WARNING: Exiting on non-zero subprocess exit code" ERR;
|
||||
|
||||
# Ensure consistent sorting order / tool output.
|
||||
export LANG=C
|
||||
export LC_ALL=C
|
||||
|
||||
export DIRNAME=$(dirname $0)
|
||||
|
||||
function die() {
|
||||
declare -r message=$1
|
||||
|
||||
echo $message
|
||||
exit 1
|
||||
}
|
||||
|
||||
function usage() {
|
||||
declare -r message=$1
|
||||
|
||||
if [ ! "$message" = "" ]; then
|
||||
echo $message
|
||||
fi
|
||||
echo "Usage:"
|
||||
echo " ./import_scrypt.sh import </path/to/scrypt-*.tar.gz>"
|
||||
echo " ./import_scrypt.sh regenerate <patch/*.patch>"
|
||||
echo " ./import_scrypt.sh generate <patch/*.patch> </path/to/scrypt-*.tar.gz>"
|
||||
exit 1
|
||||
}
|
||||
|
||||
function main() {
|
||||
if [ ! -d patches ]; then
|
||||
die "scrypt patch directory patches/ not found"
|
||||
fi
|
||||
|
||||
if [ ! -f scrypt.version ]; then
|
||||
die "scrypt.version not found"
|
||||
fi
|
||||
|
||||
source $DIRNAME/scrypt.version
|
||||
if [ "$SCRYPT_VERSION" == "" ]; then
|
||||
die "Invalid scrypt.version; see README.android for more information"
|
||||
fi
|
||||
|
||||
SCRYPT_DIR=scrypt-$SCRYPT_VERSION
|
||||
SCRYPT_DIR_ORIG=$SCRYPT_DIR.orig
|
||||
|
||||
if [ ! -f scrypt.config ]; then
|
||||
die "scrypt.config not found"
|
||||
fi
|
||||
|
||||
source $DIRNAME/scrypt.config
|
||||
if [ "$CONFIGURE_ARGS" == "" -o "$UNNEEDED_SOURCES" == "" -o "$NEEDED_SOURCES" == "" ]; then
|
||||
die "Invalid scrypt.config; see README.android for more information"
|
||||
fi
|
||||
|
||||
declare -r command=$1
|
||||
shift || usage "No command specified. Try import, regenerate, or generate."
|
||||
if [ "$command" = "import" ]; then
|
||||
declare -r tar=$1
|
||||
shift || usage "No tar file specified."
|
||||
import $tar
|
||||
elif [ "$command" = "regenerate" ]; then
|
||||
declare -r patch=$1
|
||||
shift || usage "No patch file specified."
|
||||
[ -d $SCRYPT_DIR ] || usage "$SCRYPT_DIR not found, did you mean to use generate?"
|
||||
[ -d $SCRYPT_DIR_ORIG_ORIG ] || usage "$SCRYPT_DIR_ORIG not found, did you mean to use generate?"
|
||||
regenerate $patch
|
||||
elif [ "$command" = "generate" ]; then
|
||||
declare -r patch=$1
|
||||
shift || usage "No patch file specified."
|
||||
declare -r tar=$1
|
||||
shift || usage "No tar file specified."
|
||||
generate $patch $tar
|
||||
else
|
||||
usage "Unknown command specified $command. Try import, regenerate, or generate."
|
||||
fi
|
||||
}
|
||||
|
||||
# Compute the name of an assembly source file generated by one of the
|
||||
# gen_asm_xxxx() functions below. The logic is the following:
|
||||
# - if "$2" is not empty, output it directly
|
||||
# - otherwise, change the file extension of $1 from .pl to .S and output
|
||||
# it.
|
||||
# Usage: default_asm_file "$1" "$2"
|
||||
# or default_asm_file "$@"
|
||||
#
|
||||
# $1: generator path (perl script)
|
||||
# $2: optional output file name.
|
||||
function default_asm_file () {
|
||||
if [ "$2" ]; then
|
||||
echo "$2"
|
||||
else
|
||||
echo "${1%%.pl}.S"
|
||||
fi
|
||||
}
|
||||
|
||||
# Generate an ARM assembly file.
|
||||
# $1: generator (perl script)
|
||||
# $2: [optional] output file name
|
||||
function gen_asm_arm () {
|
||||
local OUT
|
||||
OUT=$(default_asm_file "$@")
|
||||
perl "$1" > "$OUT"
|
||||
}
|
||||
|
||||
function gen_asm_mips () {
|
||||
local OUT
|
||||
OUT=$(default_asm_file "$@")
|
||||
# The perl scripts expect to run the target compiler as $CC to determine
|
||||
# the endianess of the target. Setting CC to true is a hack that forces the scripts
|
||||
# to generate little endian output
|
||||
CC=true perl "$1" o32 > "$OUT"
|
||||
}
|
||||
|
||||
function gen_asm_x86 () {
|
||||
local OUT
|
||||
OUT=$(default_asm_file "$@")
|
||||
perl "$1" elf -fPIC > "$OUT"
|
||||
}
|
||||
|
||||
function gen_asm_x86_64 () {
|
||||
local OUT
|
||||
OUT=$(default_asm_file "$@")
|
||||
perl "$1" elf "$OUT" > "$OUT"
|
||||
}
|
||||
|
||||
|
||||
# Filter all items in a list that match a given pattern.
|
||||
# $1: space-separated list
|
||||
# $2: egrep pattern.
|
||||
# Out: items in $1 that match $2
|
||||
function filter_by_egrep() {
|
||||
declare -r pattern=$1
|
||||
shift
|
||||
echo "$@" | tr ' ' '\n' | grep -e "$pattern" | tr '\n' ' '
|
||||
}
|
||||
|
||||
# Sort and remove duplicates in a space-separated list
|
||||
# $1: space-separated list
|
||||
# Out: new space-separated list
|
||||
function uniq_sort () {
|
||||
echo "$@" | tr ' ' '\n' | sort -u | tr '\n' ' '
|
||||
}
|
||||
|
||||
function print_autogenerated_header() {
|
||||
echo "# Auto-generated - DO NOT EDIT!"
|
||||
echo "# To regenerate, edit scrypt.config, then run:"
|
||||
echo "# ./import_scrypt.sh import /path/to/scrypt-$SCRYPT_VERSION.tar.gz"
|
||||
echo "#"
|
||||
}
|
||||
|
||||
function generate_build_config_mk() {
|
||||
./configure $CONFIGURE_ARGS
|
||||
#rm -f apps/CA.pl.bak crypto/scryptconf.h.bak
|
||||
|
||||
declare -r tmpfile=$(mktemp)
|
||||
(grep -e -D Makefile | grep -v CONFIGURE_ARGS= | grep -v OPTIONS=) > $tmpfile
|
||||
|
||||
declare -r cflags=$(filter_by_egrep "^-D" $(grep -e "^CFLAG=" $tmpfile))
|
||||
declare -r depflags=$(filter_by_egrep "^-D" $(grep -e "^DEPFLAG=" $tmpfile))
|
||||
rm -f $tmpfile
|
||||
|
||||
echo "Generating $(basename $1)"
|
||||
(
|
||||
print_autogenerated_header
|
||||
|
||||
echo "scrypt_cflags := \\"
|
||||
for cflag in $cflags $depflags; do
|
||||
echo " $cflag \\"
|
||||
done
|
||||
echo ""
|
||||
) > $1
|
||||
}
|
||||
|
||||
# Return the value of a computed variable name.
|
||||
# E.g.:
|
||||
# FOO=foo
|
||||
# BAR=bar
|
||||
# echo $(var_value FOO_$BAR) -> prints the value of ${FOO_bar}
|
||||
# $1: Variable name
|
||||
# Out: variable value
|
||||
var_value() {
|
||||
# Note: don't use 'echo' here, because it's sensitive to values
|
||||
# that begin with an underscore (e.g. "-n")
|
||||
eval printf \"%s\\n\" \$$1
|
||||
}
|
||||
|
||||
# Same as var_value, but returns sorted output without duplicates.
|
||||
# $1: Variable name
|
||||
# Out: variable value (if space-separated list, sorted with no duplicates)
|
||||
var_sorted_value() {
|
||||
uniq_sort $(var_value $1)
|
||||
}
|
||||
|
||||
# Print the definition of a given variable in a GNU Make build file.
|
||||
# $1: Variable name (e.g. common_src_files)
|
||||
# $2+: Variable value (e.g. list of sources)
|
||||
print_vardef_in_mk() {
|
||||
declare -r varname=$1
|
||||
shift
|
||||
if [ -z "$1" ]; then
|
||||
echo "$varname :="
|
||||
else
|
||||
echo "$varname := \\"
|
||||
for src; do
|
||||
echo " $src \\"
|
||||
done
|
||||
fi
|
||||
echo ""
|
||||
}
|
||||
|
||||
# Same as print_vardef_in_mk, but print a CFLAGS definition from
|
||||
# a list of compiler defines.
|
||||
# $1: Variable name (e.g. common_c_flags)
|
||||
# $2: List of defines (e.g. SCRYPT_NO_DONKEYS ...)
|
||||
print_defines_in_mk() {
|
||||
declare -r varname=$1
|
||||
shift
|
||||
if [ -z "$1" ]; then
|
||||
echo "$varname :="
|
||||
else
|
||||
echo "$varname := \\"
|
||||
for def; do
|
||||
echo " -D$def \\"
|
||||
done
|
||||
fi
|
||||
echo ""
|
||||
}
|
||||
|
||||
# Generate a configuration file like Scrypt-config.mk
|
||||
# This uses variable definitions from scrypt.config to build a config
|
||||
# file that can compute the list of target- and host-specific sources /
|
||||
# compiler flags for a given component.
|
||||
#
|
||||
# $1: Target file name. (e.g. Scrypt-config.mk)
|
||||
function generate_config_mk() {
|
||||
declare -r output="$1"
|
||||
declare -r all_archs="arm arm_neon x86 x86_64 mips"
|
||||
|
||||
echo "Generating $(basename $output)"
|
||||
(
|
||||
print_autogenerated_header
|
||||
echo \
|
||||
"# Before including this file, the local Android.mk must define the following
|
||||
# variables:
|
||||
#
|
||||
# local_c_flags
|
||||
# local_c_includes
|
||||
# local_additional_dependencies
|
||||
#
|
||||
# This script will define the following variables:
|
||||
#
|
||||
# target_c_flags
|
||||
# target_c_includes
|
||||
# target_src_files
|
||||
#
|
||||
# host_c_flags
|
||||
# host_c_includes
|
||||
# host_src_files
|
||||
#
|
||||
|
||||
# Ensure these are empty.
|
||||
unknown_arch_c_flags :=
|
||||
unknown_arch_src_files :=
|
||||
unknown_arch_exclude_files :=
|
||||
|
||||
"
|
||||
common_defines=$(var_sorted_value SCRYPT_DEFINES)
|
||||
print_defines_in_mk common_c_flags $common_defines
|
||||
|
||||
common_sources=$(var_sorted_value SCRYPT_SOURCES)
|
||||
print_vardef_in_mk common_src_files $common_sources
|
||||
|
||||
common_includes=$(var_sorted_value SCRYPT_INCLUDES)
|
||||
print_vardef_in_mk common_c_includes $common_includes
|
||||
|
||||
for arch in $all_archs; do
|
||||
arch_defines=$(var_sorted_value SCRYPT_DEFINES_${arch})
|
||||
print_defines_in_mk ${arch}_c_flags $arch_defines
|
||||
|
||||
arch_sources=$(var_sorted_value SCRYPT_SOURCES_${arch})
|
||||
print_vardef_in_mk ${arch}_src_files $arch_sources
|
||||
|
||||
arch_exclude_sources=$(var_sorted_value SCRYPT_SOURCES_EXCLUDES_${arch})
|
||||
print_vardef_in_mk ${arch}_exclude_files $arch_exclude_sources
|
||||
|
||||
done
|
||||
|
||||
echo "\
|
||||
target_arch := \$(TARGET_ARCH)
|
||||
ifeq (\$(target_arch)-\$(TARGET_HAS_BIGENDIAN),mips-true)
|
||||
target_arch := unknown_arch
|
||||
endif
|
||||
|
||||
target_c_flags := \$(common_c_flags) \$(\$(target_arch)_c_flags) \$(local_c_flags)
|
||||
target_c_includes := \$(addprefix external/scrypt/,\$(common_c_includes)) \$(local_c_includes)
|
||||
target_src_files := \$(common_src_files) \$(\$(target_arch)_src_files)
|
||||
target_src_files := \$(filter-out \$(\$(target_arch)_exclude_files), \$(target_src_files))
|
||||
|
||||
# Hacks for ARM NEON support
|
||||
ifeq (\$(target_arch),arm)
|
||||
ifeq (\$(ARCH_ARM_HAVE_NEON),true)
|
||||
target_c_flags += \$(arm_neon_c_flags)
|
||||
target_src_files += \$(arm_neon_src_files)
|
||||
target_src_files := \$(filter-out \$(arm_neon_exclude_files), \$(target_src_files))
|
||||
endif
|
||||
endif
|
||||
|
||||
ifeq (\$(HOST_OS)-\$(HOST_ARCH),linux-x86)
|
||||
host_arch := x86
|
||||
else
|
||||
host_arch := unknown_arch
|
||||
endif
|
||||
|
||||
host_c_flags := \$(common_c_flags) \$(\$(host_arch)_c_flags) \$(local_c_flags)
|
||||
host_c_includes := \$(addprefix external/scrypt/,\$(common_c_includes)) \$(local_c_includes)
|
||||
host_src_files := \$(common_src_files) \$(\$(host_arch)_src_files)
|
||||
host_src_files := \$(filter-out \$(\$(host_arch)_exclude_files), \$(host_src_files))
|
||||
|
||||
local_additional_dependencies += \$(LOCAL_PATH)/$(basename $output)
|
||||
"
|
||||
|
||||
) > "$output"
|
||||
}
|
||||
|
||||
function import() {
|
||||
declare -r SCRYPT_SOURCE=$1
|
||||
|
||||
untar $SCRYPT_SOURCE readonly
|
||||
applypatches $SCRYPT_DIR
|
||||
|
||||
cd $SCRYPT_DIR
|
||||
|
||||
generate_build_config_mk ../build-config.mk
|
||||
|
||||
touch ../MODULE_LICENSE_BSD_LIKE
|
||||
|
||||
cd ..
|
||||
|
||||
generate_config_mk Scrypt-config.mk
|
||||
|
||||
# Prune unnecessary sources
|
||||
prune
|
||||
|
||||
NEEDED_SOURCES="$NEEDED_SOURCES"
|
||||
for i in $NEEDED_SOURCES; do
|
||||
echo "Updating $i"
|
||||
rm -r $i
|
||||
mv $SCRYPT_DIR/$i .
|
||||
done
|
||||
|
||||
cleantar
|
||||
}
|
||||
|
||||
function regenerate() {
|
||||
declare -r patch=$1
|
||||
|
||||
generatepatch $patch
|
||||
}
|
||||
|
||||
function generate() {
|
||||
declare -r patch=$1
|
||||
declare -r SCRYPT_SOURCE=$2
|
||||
|
||||
untar $SCRYPT_SOURCE
|
||||
applypatches $SCRYPT_DIR_ORIG $patch
|
||||
prune
|
||||
|
||||
for i in $NEEDED_SOURCES; do
|
||||
echo "Restoring $i"
|
||||
rm -r $SCRYPT_DIR/$i
|
||||
cp -rf $i $SCRYPT_DIR/$i
|
||||
done
|
||||
|
||||
generatepatch $patch
|
||||
cleantar
|
||||
}
|
||||
|
||||
# Find all files in a sub-directory that are encoded in ISO-8859
|
||||
# $1: Directory.
|
||||
# Out: list of files in $1 that are encoded as ISO-8859.
|
||||
function find_iso8859_files() {
|
||||
find $1 -type f -print0 | xargs -0 file | fgrep "ISO-8859" | cut -d: -f1
|
||||
}
|
||||
|
||||
# Convert all ISO-8859 files in a given subdirectory to UTF-8
|
||||
# $1: Directory name
|
||||
function convert_iso8859_to_utf8() {
|
||||
declare -r iso_files=$(find_iso8859_files "$1")
|
||||
for iso_file in $iso_files; do
|
||||
iconv --from-code iso-8859-1 --to-code utf-8 $iso_file > $iso_file.tmp
|
||||
rm -f $iso_file
|
||||
mv $iso_file.tmp $iso_file
|
||||
done
|
||||
}
|
||||
|
||||
function untar() {
|
||||
declare -r SCRYPT_SOURCE=$1
|
||||
declare -r readonly=$2
|
||||
|
||||
# Remove old source
|
||||
cleantar
|
||||
|
||||
# Process new source
|
||||
tar -zxf $SCRYPT_SOURCE
|
||||
convert_iso8859_to_utf8 $SCRYPT_DIR
|
||||
cp -rfP $SCRYPT_DIR $SCRYPT_DIR_ORIG
|
||||
if [ ! -z $readonly ]; then
|
||||
find $SCRYPT_DIR_ORIG -type f -print0 | xargs -0 chmod a-w
|
||||
fi
|
||||
}
|
||||
|
||||
function prune() {
|
||||
echo "Removing $UNNEEDED_SOURCES"
|
||||
(cd $SCRYPT_DIR_ORIG && rm -rf $UNNEEDED_SOURCES)
|
||||
(cd $SCRYPT_DIR && rm -r $UNNEEDED_SOURCES)
|
||||
}
|
||||
|
||||
function cleantar() {
|
||||
rm -rf $SCRYPT_DIR_ORIG
|
||||
rm -rf $SCRYPT_DIR
|
||||
}
|
||||
|
||||
function applypatches () {
|
||||
declare -r dir=$1
|
||||
declare -r skip_patch=$2
|
||||
|
||||
cd $dir
|
||||
|
||||
# Apply appropriate patches
|
||||
for i in $SCRYPT_PATCHES; do
|
||||
if [ ! "$skip_patch" = "patches/$i" ]; then
|
||||
echo "Applying patch $i"
|
||||
patch -p1 --merge < ../patches/$i || die "Could not apply patches/$i. Fix source and run: $0 regenerate patches/$i"
|
||||
else
|
||||
echo "Skiping patch $i"
|
||||
fi
|
||||
|
||||
done
|
||||
|
||||
# Cleanup patch output
|
||||
find . \( -type f -o -type l \) -name "*.orig" -print0 | xargs -0 rm -f
|
||||
|
||||
cd ..
|
||||
}
|
||||
|
||||
function generatepatch() {
|
||||
declare -r patch=$1
|
||||
|
||||
# Cleanup stray files before generating patch
|
||||
find $SCRYPT_DIR -type f -name "*.orig" -print0 | xargs -0 rm -f
|
||||
find $SCRYPT_DIR -type f -name "*~" -print0 | xargs -0 rm -f
|
||||
|
||||
declare -r variable_name=SCRYPT_PATCHES_`basename $patch .patch | sed s/-/_/`_SOURCES
|
||||
# http://tldp.org/LDP/abs/html/ivr.html
|
||||
eval declare -r sources=\$$variable_name
|
||||
rm -f $patch
|
||||
touch $patch
|
||||
for i in $sources; do
|
||||
LC_ALL=C TZ=UTC0 diff -aup $SCRYPT_DIR_ORIG/$i $SCRYPT_DIR/$i >> $patch && die "ERROR: No diff for patch $path in file $i"
|
||||
done
|
||||
echo "Generated patch $patch"
|
||||
echo "NOTE To make sure there are not unwanted changes from conflicting patches, be sure to review the generated patch."
|
||||
}
|
||||
|
||||
main $@
|
||||
@@ -0,0 +1,6 @@
|
||||
The source code under this directory is taken from the client for the
|
||||
Tarsnap online backup system (and released under the 2-clause BSD license
|
||||
with permission of the author); keeping this code in sync with the Tarsnap
|
||||
code is highly desirable and explains why there is some functionality
|
||||
included here which is not actually used by the scrypt file encryption
|
||||
utility.
|
||||
@@ -0,0 +1,120 @@
|
||||
/*
|
||||
* version 20110505
|
||||
* D. J. Bernstein
|
||||
* Public domain.
|
||||
*
|
||||
* Based on crypto_core/salsa208/armneon/core.c from SUPERCOP 20130419
|
||||
*/
|
||||
|
||||
#define ROUNDS 8
|
||||
static void
|
||||
salsa20_8_intrinsic(void * input)
|
||||
{
|
||||
int i;
|
||||
|
||||
const uint32x4_t abab = {-1,0,-1,0};
|
||||
|
||||
/*
|
||||
* This is modified since we only have one argument. Usually you'd rearrange
|
||||
* the constant, key, and input bytes, but we just have one linear array to
|
||||
* rearrange which is a bit easier.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Change the input to be diagonals as if it's a 4x4 matrix of 32-bit values.
|
||||
*/
|
||||
uint32x4_t x0x5x10x15;
|
||||
uint32x4_t x12x1x6x11;
|
||||
uint32x4_t x8x13x2x7;
|
||||
uint32x4_t x4x9x14x3;
|
||||
|
||||
uint32x4_t x0x1x10x11;
|
||||
uint32x4_t x12x13x6x7;
|
||||
uint32x4_t x8x9x2x3;
|
||||
uint32x4_t x4x5x14x15;
|
||||
|
||||
uint32x4_t x0x1x2x3;
|
||||
uint32x4_t x4x5x6x7;
|
||||
uint32x4_t x8x9x10x11;
|
||||
uint32x4_t x12x13x14x15;
|
||||
|
||||
x0x1x2x3 = vld1q_u8((uint8_t *) input);
|
||||
x4x5x6x7 = vld1q_u8(16 + (uint8_t *) input);
|
||||
x8x9x10x11 = vld1q_u8(32 + (uint8_t *) input);
|
||||
x12x13x14x15 = vld1q_u8(48 + (uint8_t *) input);
|
||||
|
||||
x0x1x10x11 = vcombine_u32(vget_low_u32(x0x1x2x3), vget_high_u32(x8x9x10x11));
|
||||
x4x5x14x15 = vcombine_u32(vget_low_u32(x4x5x6x7), vget_high_u32(x12x13x14x15));
|
||||
x8x9x2x3 = vcombine_u32(vget_low_u32(x8x9x10x11), vget_high_u32(x0x1x2x3));
|
||||
x12x13x6x7 = vcombine_u32(vget_low_u32(x12x13x14x15), vget_high_u32(x4x5x6x7));
|
||||
|
||||
x0x5x10x15 = vbslq_u32(abab,x0x1x10x11,x4x5x14x15);
|
||||
x8x13x2x7 = vbslq_u32(abab,x8x9x2x3,x12x13x6x7);
|
||||
x4x9x14x3 = vbslq_u32(abab,x4x5x14x15,x8x9x2x3);
|
||||
x12x1x6x11 = vbslq_u32(abab,x12x13x6x7,x0x1x10x11);
|
||||
|
||||
uint32x4_t start0 = x0x5x10x15;
|
||||
uint32x4_t start1 = x12x1x6x11;
|
||||
uint32x4_t start3 = x4x9x14x3;
|
||||
uint32x4_t start2 = x8x13x2x7;
|
||||
|
||||
/* From here on this should be the same as the SUPERCOP version. */
|
||||
|
||||
uint32x4_t diag0 = start0;
|
||||
uint32x4_t diag1 = start1;
|
||||
uint32x4_t diag2 = start2;
|
||||
uint32x4_t diag3 = start3;
|
||||
|
||||
uint32x4_t a0;
|
||||
uint32x4_t a1;
|
||||
uint32x4_t a2;
|
||||
uint32x4_t a3;
|
||||
|
||||
for (i = ROUNDS;i > 0;i -= 2) {
|
||||
a0 = diag1 + diag0;
|
||||
diag3 ^= vsriq_n_u32(vshlq_n_u32(a0,7),a0,25);
|
||||
a1 = diag0 + diag3;
|
||||
diag2 ^= vsriq_n_u32(vshlq_n_u32(a1,9),a1,23);
|
||||
a2 = diag3 + diag2;
|
||||
diag1 ^= vsriq_n_u32(vshlq_n_u32(a2,13),a2,19);
|
||||
a3 = diag2 + diag1;
|
||||
diag0 ^= vsriq_n_u32(vshlq_n_u32(a3,18),a3,14);
|
||||
|
||||
diag3 = vextq_u32(diag3,diag3,3);
|
||||
diag2 = vextq_u32(diag2,diag2,2);
|
||||
diag1 = vextq_u32(diag1,diag1,1);
|
||||
|
||||
a0 = diag3 + diag0;
|
||||
diag1 ^= vsriq_n_u32(vshlq_n_u32(a0,7),a0,25);
|
||||
a1 = diag0 + diag1;
|
||||
diag2 ^= vsriq_n_u32(vshlq_n_u32(a1,9),a1,23);
|
||||
a2 = diag1 + diag2;
|
||||
diag3 ^= vsriq_n_u32(vshlq_n_u32(a2,13),a2,19);
|
||||
a3 = diag2 + diag3;
|
||||
diag0 ^= vsriq_n_u32(vshlq_n_u32(a3,18),a3,14);
|
||||
|
||||
diag1 = vextq_u32(diag1,diag1,3);
|
||||
diag2 = vextq_u32(diag2,diag2,2);
|
||||
diag3 = vextq_u32(diag3,diag3,1);
|
||||
}
|
||||
|
||||
x0x5x10x15 = diag0 + start0;
|
||||
x12x1x6x11 = diag1 + start1;
|
||||
x8x13x2x7 = diag2 + start2;
|
||||
x4x9x14x3 = diag3 + start3;
|
||||
|
||||
x0x1x10x11 = vbslq_u32(abab,x0x5x10x15,x12x1x6x11);
|
||||
x12x13x6x7 = vbslq_u32(abab,x12x1x6x11,x8x13x2x7);
|
||||
x8x9x2x3 = vbslq_u32(abab,x8x13x2x7,x4x9x14x3);
|
||||
x4x5x14x15 = vbslq_u32(abab,x4x9x14x3,x0x5x10x15);
|
||||
|
||||
x0x1x2x3 = vcombine_u32(vget_low_u32(x0x1x10x11),vget_high_u32(x8x9x2x3));
|
||||
x4x5x6x7 = vcombine_u32(vget_low_u32(x4x5x14x15),vget_high_u32(x12x13x6x7));
|
||||
x8x9x10x11 = vcombine_u32(vget_low_u32(x8x9x2x3),vget_high_u32(x0x1x10x11));
|
||||
x12x13x14x15 = vcombine_u32(vget_low_u32(x12x13x6x7),vget_high_u32(x4x5x14x15));
|
||||
|
||||
vst1q_u8((uint8_t *) input,(uint8x16_t) x0x1x2x3);
|
||||
vst1q_u8(16 + (uint8_t *) input,(uint8x16_t) x4x5x6x7);
|
||||
vst1q_u8(32 + (uint8_t *) input,(uint8x16_t) x8x9x10x11);
|
||||
vst1q_u8(48 + (uint8_t *) input,(uint8x16_t) x12x13x14x15);
|
||||
}
|
||||
@@ -0,0 +1,302 @@
|
||||
/*-
|
||||
* Copyright 2009 Colin Percival
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* This file was originally written by Colin Percival as part of the Tarsnap
|
||||
* online backup system.
|
||||
*/
|
||||
#include "scrypt_platform.h"
|
||||
|
||||
#include <arm_neon.h>
|
||||
|
||||
#include <errno.h>
|
||||
#include <stdint.h>
|
||||
#include <limits.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#ifdef USE_OPENSSL_PBKDF2
|
||||
#include <openssl/evp.h>
|
||||
#else
|
||||
#include "sha256.h"
|
||||
#endif
|
||||
#include "sysendian.h"
|
||||
|
||||
#include "crypto_scrypt.h"
|
||||
|
||||
#include "crypto_scrypt-neon-salsa208.h"
|
||||
|
||||
static void blkcpy(void *, void *, size_t);
|
||||
static void blkxor(void *, void *, size_t);
|
||||
void crypto_core_salsa208_armneon2(void *);
|
||||
static void blockmix_salsa8(uint8x16_t *, uint8x16_t *, uint8x16_t *, size_t);
|
||||
static uint64_t integerify(void *, size_t);
|
||||
static void smix(uint8_t *, size_t, uint64_t, void *, void *);
|
||||
|
||||
static void
|
||||
blkcpy(void * dest, void * src, size_t len)
|
||||
{
|
||||
uint8x16_t * D = dest;
|
||||
uint8x16_t * S = src;
|
||||
size_t L = len / 16;
|
||||
size_t i;
|
||||
|
||||
for (i = 0; i < L; i++)
|
||||
D[i] = S[i];
|
||||
}
|
||||
|
||||
static void
|
||||
blkxor(void * dest, void * src, size_t len)
|
||||
{
|
||||
uint8x16_t * D = dest;
|
||||
uint8x16_t * S = src;
|
||||
size_t L = len / 16;
|
||||
size_t i;
|
||||
|
||||
for (i = 0; i < L; i++)
|
||||
D[i] = veorq_u8(D[i], S[i]);
|
||||
}
|
||||
|
||||
/**
|
||||
* blockmix_salsa8(B, Y, r):
|
||||
* Compute B = BlockMix_{salsa20/8, r}(B). The input B must be 128r bytes in
|
||||
* length; the temporary space Y must also be the same size.
|
||||
*/
|
||||
static void
|
||||
blockmix_salsa8(uint8x16_t * Bin, uint8x16_t * Bout, uint8x16_t * X, size_t r)
|
||||
{
|
||||
size_t i;
|
||||
|
||||
/* 1: X <-- B_{2r - 1} */
|
||||
blkcpy(X, &Bin[8 * r - 4], 64);
|
||||
|
||||
/* 2: for i = 0 to 2r - 1 do */
|
||||
for (i = 0; i < r; i++) {
|
||||
/* 3: X <-- H(X \xor B_i) */
|
||||
blkxor(X, &Bin[i * 8], 64);
|
||||
salsa20_8_intrinsic((void *) X);
|
||||
|
||||
/* 4: Y_i <-- X */
|
||||
/* 6: B' <-- (Y_0, Y_2 ... Y_{2r-2}, Y_1, Y_3 ... Y_{2r-1}) */
|
||||
blkcpy(&Bout[i * 4], X, 64);
|
||||
|
||||
/* 3: X <-- H(X \xor B_i) */
|
||||
blkxor(X, &Bin[i * 8 + 4], 64);
|
||||
salsa20_8_intrinsic((void *) X);
|
||||
|
||||
/* 4: Y_i <-- X */
|
||||
/* 6: B' <-- (Y_0, Y_2 ... Y_{2r-2}, Y_1, Y_3 ... Y_{2r-1}) */
|
||||
blkcpy(&Bout[(r + i) * 4], X, 64);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* integerify(B, r):
|
||||
* Return the result of parsing B_{2r-1} as a little-endian integer.
|
||||
*/
|
||||
static uint64_t
|
||||
integerify(void * B, size_t r)
|
||||
{
|
||||
uint8_t * X = (void*)((uintptr_t)(B) + (2 * r - 1) * 64);
|
||||
|
||||
return (le64dec(X));
|
||||
}
|
||||
|
||||
/**
|
||||
* smix(B, r, N, V, XY):
|
||||
* Compute B = SMix_r(B, N). The input B must be 128r bytes in length; the
|
||||
* temporary storage V must be 128rN bytes in length; the temporary storage
|
||||
* XY must be 256r bytes in length. The value N must be a power of 2.
|
||||
*/
|
||||
static void
|
||||
smix(uint8_t * B, size_t r, uint64_t N, void * V, void * XY)
|
||||
{
|
||||
uint8x16_t * X = XY;
|
||||
uint8x16_t * Y = (void *)((uintptr_t)(XY) + 128 * r);
|
||||
uint8x16_t * Z = (void *)((uintptr_t)(XY) + 256 * r);
|
||||
uint64_t i, j;
|
||||
|
||||
/* 1: X <-- B */
|
||||
blkcpy(X, B, 128 * r);
|
||||
|
||||
/* 2: for i = 0 to N - 1 do */
|
||||
for (i = 0; i < N; i += 2) {
|
||||
/* 3: V_i <-- X */
|
||||
blkcpy((void *)((uintptr_t)(V) + i * 128 * r), X, 128 * r);
|
||||
|
||||
/* 4: X <-- H(X) */
|
||||
blockmix_salsa8(X, Y, Z, r);
|
||||
|
||||
/* 3: V_i <-- X */
|
||||
blkcpy((void *)((uintptr_t)(V) + (i + 1) * 128 * r),
|
||||
Y, 128 * r);
|
||||
|
||||
/* 4: X <-- H(X) */
|
||||
blockmix_salsa8(Y, X, Z, r);
|
||||
}
|
||||
|
||||
/* 6: for i = 0 to N - 1 do */
|
||||
for (i = 0; i < N; i += 2) {
|
||||
/* 7: j <-- Integerify(X) mod N */
|
||||
j = integerify(X, r) & (N - 1);
|
||||
|
||||
/* 8: X <-- H(X \xor V_j) */
|
||||
blkxor(X, (void *)((uintptr_t)(V) + j * 128 * r), 128 * r);
|
||||
blockmix_salsa8(X, Y, Z, r);
|
||||
|
||||
/* 7: j <-- Integerify(X) mod N */
|
||||
j = integerify(Y, r) & (N - 1);
|
||||
|
||||
/* 8: X <-- H(X \xor V_j) */
|
||||
blkxor(Y, (void *)((uintptr_t)(V) + j * 128 * r), 128 * r);
|
||||
blockmix_salsa8(Y, X, Z, r);
|
||||
}
|
||||
|
||||
/* 10: B' <-- X */
|
||||
blkcpy(B, X, 128 * r);
|
||||
}
|
||||
|
||||
/**
|
||||
* crypto_scrypt(passwd, passwdlen, salt, saltlen, N, r, p, buf, buflen):
|
||||
* Compute scrypt(passwd[0 .. passwdlen - 1], salt[0 .. saltlen - 1], N, r,
|
||||
* p, buflen) and write the result into buf. The parameters r, p, and buflen
|
||||
* must satisfy r * p < 2^30 and buflen <= (2^32 - 1) * 32. The parameter N
|
||||
* must be a power of 2.
|
||||
*
|
||||
* Return 0 on success; or -1 on error.
|
||||
*/
|
||||
int
|
||||
crypto_scrypt(const uint8_t * passwd, size_t passwdlen,
|
||||
const uint8_t * salt, size_t saltlen, uint64_t N, uint32_t r, uint32_t p,
|
||||
uint8_t * buf, size_t buflen)
|
||||
{
|
||||
void * B0, * V0, * XY0;
|
||||
uint8_t * B;
|
||||
uint32_t * V;
|
||||
uint32_t * XY;
|
||||
uint32_t i;
|
||||
|
||||
/* Sanity-check parameters. */
|
||||
#if SIZE_MAX > UINT32_MAX
|
||||
if (buflen > (((uint64_t)(1) << 32) - 1) * 32) {
|
||||
errno = EFBIG;
|
||||
goto err0;
|
||||
}
|
||||
#endif
|
||||
if ((uint64_t)(r) * (uint64_t)(p) >= (1 << 30)) {
|
||||
errno = EFBIG;
|
||||
goto err0;
|
||||
}
|
||||
if (((N & (N - 1)) != 0) || (N == 0)) {
|
||||
errno = EINVAL;
|
||||
goto err0;
|
||||
}
|
||||
if ((r > SIZE_MAX / 128 / p) ||
|
||||
#if SIZE_MAX / 256 <= UINT32_MAX
|
||||
(r > SIZE_MAX / 256) ||
|
||||
#endif
|
||||
(N > SIZE_MAX / 128 / r)) {
|
||||
errno = ENOMEM;
|
||||
goto err0;
|
||||
}
|
||||
|
||||
/* Allocate memory. */
|
||||
#ifdef HAVE_POSIX_MEMALIGN
|
||||
if ((errno = posix_memalign(&B0, 64, 128 * r * p)) != 0)
|
||||
goto err0;
|
||||
B = (uint8_t *)(B0);
|
||||
if ((errno = posix_memalign(&XY0, 64, 256 * r + 64)) != 0)
|
||||
goto err1;
|
||||
XY = (uint32_t *)(XY0);
|
||||
#ifndef MAP_ANON
|
||||
if ((errno = posix_memalign(&V0, 64, 128 * r * N)) != 0)
|
||||
goto err2;
|
||||
V = (uint32_t *)(V0);
|
||||
#endif
|
||||
#else
|
||||
if ((B0 = malloc(128 * r * p + 63)) == NULL)
|
||||
goto err0;
|
||||
B = (uint8_t *)(((uintptr_t)(B0) + 63) & ~ (uintptr_t)(63));
|
||||
if ((XY0 = malloc(256 * r + 64 + 63)) == NULL)
|
||||
goto err1;
|
||||
XY = (uint32_t *)(((uintptr_t)(XY0) + 63) & ~ (uintptr_t)(63));
|
||||
#ifndef MAP_ANON
|
||||
if ((V0 = malloc(128 * r * N + 63)) == NULL)
|
||||
goto err2;
|
||||
V = (uint32_t *)(((uintptr_t)(V0) + 63) & ~ (uintptr_t)(63));
|
||||
#endif
|
||||
#endif
|
||||
#ifdef MAP_ANON
|
||||
if ((V0 = mmap(NULL, 128 * r * N, PROT_READ | PROT_WRITE,
|
||||
#ifdef MAP_NOCORE
|
||||
MAP_ANON | MAP_PRIVATE | MAP_NOCORE,
|
||||
#else
|
||||
MAP_ANON | MAP_PRIVATE,
|
||||
#endif
|
||||
-1, 0)) == MAP_FAILED)
|
||||
goto err2;
|
||||
V = (uint32_t *)(V0);
|
||||
#endif
|
||||
|
||||
/* 1: (B_0 ... B_{p-1}) <-- PBKDF2(P, S, 1, p * MFLen) */
|
||||
#ifdef USE_OPENSSL_PBKDF2
|
||||
PKCS5_PBKDF2_HMAC((const char *)passwd, passwdlen, salt, saltlen, 1, EVP_sha256(), p * 128 * r, B);
|
||||
#else
|
||||
PBKDF2_SHA256(passwd, passwdlen, salt, saltlen, 1, B, p * 128 * r);
|
||||
#endif
|
||||
|
||||
/* 2: for i = 0 to p - 1 do */
|
||||
for (i = 0; i < p; i++) {
|
||||
/* 3: B_i <-- MF(B_i, N) */
|
||||
smix(&B[i * 128 * r], r, N, V, XY);
|
||||
}
|
||||
|
||||
/* 5: DK <-- PBKDF2(P, B, 1, dkLen) */
|
||||
#ifdef USE_OPENSSL_PBKDF2
|
||||
PKCS5_PBKDF2_HMAC((const char *)passwd, passwdlen, B, p * 128 * r, 1, EVP_sha256(), buflen, buf);
|
||||
#else
|
||||
PBKDF2_SHA256(passwd, passwdlen, B, p * 128 * r, 1, buf, buflen);
|
||||
#endif
|
||||
|
||||
/* Free memory. */
|
||||
#ifdef MAP_ANON
|
||||
if (munmap(V0, 128 * r * N))
|
||||
goto err2;
|
||||
#else
|
||||
free(V0);
|
||||
#endif
|
||||
free(XY0);
|
||||
free(B0);
|
||||
|
||||
/* Success! */
|
||||
return (0);
|
||||
|
||||
err2:
|
||||
free(XY0);
|
||||
err1:
|
||||
free(B0);
|
||||
err0:
|
||||
/* Failure! */
|
||||
return (-1);
|
||||
}
|
||||
@@ -0,0 +1,296 @@
|
||||
/*-
|
||||
* Copyright 2009 Colin Percival
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* This file was originally written by Colin Percival as part of the Tarsnap
|
||||
* online backup system.
|
||||
*/
|
||||
#include "scrypt_platform.h"
|
||||
|
||||
#include <errno.h>
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#ifdef USE_OPENSSL_PBKDF2
|
||||
#include <openssl/evp.h>
|
||||
#else
|
||||
#include "sha256.h"
|
||||
#endif
|
||||
#include "sysendian.h"
|
||||
|
||||
#include "crypto_scrypt.h"
|
||||
|
||||
static void blkcpy(uint8_t *, uint8_t *, size_t);
|
||||
static void blkxor(uint8_t *, uint8_t *, size_t);
|
||||
static void salsa20_8(uint8_t[64]);
|
||||
static void blockmix_salsa8(uint8_t *, uint8_t *, size_t);
|
||||
static uint64_t integerify(uint8_t *, size_t);
|
||||
static void smix(uint8_t *, size_t, uint64_t, uint8_t *, uint8_t *);
|
||||
|
||||
static void
|
||||
blkcpy(uint8_t * dest, uint8_t * src, size_t len)
|
||||
{
|
||||
size_t i;
|
||||
|
||||
for (i = 0; i < len; i++)
|
||||
dest[i] = src[i];
|
||||
}
|
||||
|
||||
static void
|
||||
blkxor(uint8_t * dest, uint8_t * src, size_t len)
|
||||
{
|
||||
size_t i;
|
||||
|
||||
for (i = 0; i < len; i++)
|
||||
dest[i] ^= src[i];
|
||||
}
|
||||
|
||||
/**
|
||||
* salsa20_8(B):
|
||||
* Apply the salsa20/8 core to the provided block.
|
||||
*/
|
||||
static void
|
||||
salsa20_8(uint8_t B[64])
|
||||
{
|
||||
uint32_t B32[16];
|
||||
uint32_t x[16];
|
||||
size_t i;
|
||||
|
||||
/* Convert little-endian values in. */
|
||||
for (i = 0; i < 16; i++)
|
||||
B32[i] = le32dec(&B[i * 4]);
|
||||
|
||||
/* Compute x = doubleround^4(B32). */
|
||||
for (i = 0; i < 16; i++)
|
||||
x[i] = B32[i];
|
||||
for (i = 0; i < 8; i += 2) {
|
||||
#define R(a,b) (((a) << (b)) | ((a) >> (32 - (b))))
|
||||
/* Operate on columns. */
|
||||
x[ 4] ^= R(x[ 0]+x[12], 7); x[ 8] ^= R(x[ 4]+x[ 0], 9);
|
||||
x[12] ^= R(x[ 8]+x[ 4],13); x[ 0] ^= R(x[12]+x[ 8],18);
|
||||
|
||||
x[ 9] ^= R(x[ 5]+x[ 1], 7); x[13] ^= R(x[ 9]+x[ 5], 9);
|
||||
x[ 1] ^= R(x[13]+x[ 9],13); x[ 5] ^= R(x[ 1]+x[13],18);
|
||||
|
||||
x[14] ^= R(x[10]+x[ 6], 7); x[ 2] ^= R(x[14]+x[10], 9);
|
||||
x[ 6] ^= R(x[ 2]+x[14],13); x[10] ^= R(x[ 6]+x[ 2],18);
|
||||
|
||||
x[ 3] ^= R(x[15]+x[11], 7); x[ 7] ^= R(x[ 3]+x[15], 9);
|
||||
x[11] ^= R(x[ 7]+x[ 3],13); x[15] ^= R(x[11]+x[ 7],18);
|
||||
|
||||
/* Operate on rows. */
|
||||
x[ 1] ^= R(x[ 0]+x[ 3], 7); x[ 2] ^= R(x[ 1]+x[ 0], 9);
|
||||
x[ 3] ^= R(x[ 2]+x[ 1],13); x[ 0] ^= R(x[ 3]+x[ 2],18);
|
||||
|
||||
x[ 6] ^= R(x[ 5]+x[ 4], 7); x[ 7] ^= R(x[ 6]+x[ 5], 9);
|
||||
x[ 4] ^= R(x[ 7]+x[ 6],13); x[ 5] ^= R(x[ 4]+x[ 7],18);
|
||||
|
||||
x[11] ^= R(x[10]+x[ 9], 7); x[ 8] ^= R(x[11]+x[10], 9);
|
||||
x[ 9] ^= R(x[ 8]+x[11],13); x[10] ^= R(x[ 9]+x[ 8],18);
|
||||
|
||||
x[12] ^= R(x[15]+x[14], 7); x[13] ^= R(x[12]+x[15], 9);
|
||||
x[14] ^= R(x[13]+x[12],13); x[15] ^= R(x[14]+x[13],18);
|
||||
#undef R
|
||||
}
|
||||
|
||||
/* Compute B32 = B32 + x. */
|
||||
for (i = 0; i < 16; i++)
|
||||
B32[i] += x[i];
|
||||
|
||||
/* Convert little-endian values out. */
|
||||
for (i = 0; i < 16; i++)
|
||||
le32enc(&B[4 * i], B32[i]);
|
||||
}
|
||||
|
||||
/**
|
||||
* blockmix_salsa8(B, Y, r):
|
||||
* Compute B = BlockMix_{salsa20/8, r}(B). The input B must be 128r bytes in
|
||||
* length; the temporary space Y must also be the same size.
|
||||
*/
|
||||
static void
|
||||
blockmix_salsa8(uint8_t * B, uint8_t * Y, size_t r)
|
||||
{
|
||||
uint8_t X[64];
|
||||
size_t i;
|
||||
|
||||
/* 1: X <-- B_{2r - 1} */
|
||||
blkcpy(X, &B[(2 * r - 1) * 64], 64);
|
||||
|
||||
/* 2: for i = 0 to 2r - 1 do */
|
||||
for (i = 0; i < 2 * r; i++) {
|
||||
/* 3: X <-- H(X \xor B_i) */
|
||||
blkxor(X, &B[i * 64], 64);
|
||||
salsa20_8(X);
|
||||
|
||||
/* 4: Y_i <-- X */
|
||||
blkcpy(&Y[i * 64], X, 64);
|
||||
}
|
||||
|
||||
/* 6: B' <-- (Y_0, Y_2 ... Y_{2r-2}, Y_1, Y_3 ... Y_{2r-1}) */
|
||||
for (i = 0; i < r; i++)
|
||||
blkcpy(&B[i * 64], &Y[(i * 2) * 64], 64);
|
||||
for (i = 0; i < r; i++)
|
||||
blkcpy(&B[(i + r) * 64], &Y[(i * 2 + 1) * 64], 64);
|
||||
}
|
||||
|
||||
/**
|
||||
* integerify(B, r):
|
||||
* Return the result of parsing B_{2r-1} as a little-endian integer.
|
||||
*/
|
||||
static uint64_t
|
||||
integerify(uint8_t * B, size_t r)
|
||||
{
|
||||
uint8_t * X = &B[(2 * r - 1) * 64];
|
||||
|
||||
return (le64dec(X));
|
||||
}
|
||||
|
||||
/**
|
||||
* smix(B, r, N, V, XY):
|
||||
* Compute B = SMix_r(B, N). The input B must be 128r bytes in length; the
|
||||
* temporary storage V must be 128rN bytes in length; the temporary storage
|
||||
* XY must be 256r bytes in length. The value N must be a power of 2.
|
||||
*/
|
||||
static void
|
||||
smix(uint8_t * B, size_t r, uint64_t N, uint8_t * V, uint8_t * XY)
|
||||
{
|
||||
uint8_t * X = XY;
|
||||
uint8_t * Y = &XY[128 * r];
|
||||
uint64_t i;
|
||||
uint64_t j;
|
||||
|
||||
/* 1: X <-- B */
|
||||
blkcpy(X, B, 128 * r);
|
||||
|
||||
/* 2: for i = 0 to N - 1 do */
|
||||
for (i = 0; i < N; i++) {
|
||||
/* 3: V_i <-- X */
|
||||
blkcpy(&V[i * (128 * r)], X, 128 * r);
|
||||
|
||||
/* 4: X <-- H(X) */
|
||||
blockmix_salsa8(X, Y, r);
|
||||
}
|
||||
|
||||
/* 6: for i = 0 to N - 1 do */
|
||||
for (i = 0; i < N; i++) {
|
||||
/* 7: j <-- Integerify(X) mod N */
|
||||
j = integerify(X, r) & (N - 1);
|
||||
|
||||
/* 8: X <-- H(X \xor V_j) */
|
||||
blkxor(X, &V[j * (128 * r)], 128 * r);
|
||||
blockmix_salsa8(X, Y, r);
|
||||
}
|
||||
|
||||
/* 10: B' <-- X */
|
||||
blkcpy(B, X, 128 * r);
|
||||
}
|
||||
|
||||
/**
|
||||
* crypto_scrypt(passwd, passwdlen, salt, saltlen, N, r, p, buf, buflen):
|
||||
* Compute scrypt(passwd[0 .. passwdlen - 1], salt[0 .. saltlen - 1], N, r,
|
||||
* p, buflen) and write the result into buf. The parameters r, p, and buflen
|
||||
* must satisfy r * p < 2^30 and buflen <= (2^32 - 1) * 32. The parameter N
|
||||
* must be a power of 2.
|
||||
*
|
||||
* Return 0 on success; or -1 on error.
|
||||
*/
|
||||
int
|
||||
crypto_scrypt(const uint8_t * passwd, size_t passwdlen,
|
||||
const uint8_t * salt, size_t saltlen, uint64_t N, uint32_t r, uint32_t p,
|
||||
uint8_t * buf, size_t buflen)
|
||||
{
|
||||
uint8_t * B;
|
||||
uint8_t * V;
|
||||
uint8_t * XY;
|
||||
uint32_t i;
|
||||
|
||||
/* Sanity-check parameters. */
|
||||
#if SIZE_MAX > UINT32_MAX
|
||||
if (buflen > (((uint64_t)(1) << 32) - 1) * 32) {
|
||||
errno = EFBIG;
|
||||
goto err0;
|
||||
}
|
||||
#endif
|
||||
if ((uint64_t)(r) * (uint64_t)(p) >= (1 << 30)) {
|
||||
errno = EFBIG;
|
||||
goto err0;
|
||||
}
|
||||
if (((N & (N - 1)) != 0) || (N == 0)) {
|
||||
errno = EINVAL;
|
||||
goto err0;
|
||||
}
|
||||
if ((r > SIZE_MAX / 128 / p) ||
|
||||
#if SIZE_MAX / 256 <= UINT32_MAX
|
||||
(r > SIZE_MAX / 256) ||
|
||||
#endif
|
||||
(N > SIZE_MAX / 128 / r)) {
|
||||
errno = ENOMEM;
|
||||
goto err0;
|
||||
}
|
||||
|
||||
/* Allocate memory. */
|
||||
if ((B = malloc(128 * r * p)) == NULL)
|
||||
goto err0;
|
||||
if ((XY = malloc(256 * r)) == NULL)
|
||||
goto err1;
|
||||
if ((V = malloc(128 * r * N)) == NULL)
|
||||
goto err2;
|
||||
|
||||
/* 1: (B_0 ... B_{p-1}) <-- PBKDF2(P, S, 1, p * MFLen) */
|
||||
#ifdef USE_OPENSSL_PBKDF2
|
||||
PKCS5_PBKDF2_HMAC((const char *)passwd, passwdlen, salt, saltlen, 1, EVP_sha256(), p * 128 * r, B);
|
||||
#else
|
||||
PBKDF2_SHA256(passwd, passwdlen, salt, saltlen, 1, B, p * 128 * r);
|
||||
#endif
|
||||
|
||||
/* 2: for i = 0 to p - 1 do */
|
||||
for (i = 0; i < p; i++) {
|
||||
/* 3: B_i <-- MF(B_i, N) */
|
||||
smix(&B[i * 128 * r], r, N, V, XY);
|
||||
}
|
||||
|
||||
/* 5: DK <-- PBKDF2(P, B, 1, dkLen) */
|
||||
#ifdef USE_OPENSSL_PBKDF2
|
||||
PKCS5_PBKDF2_HMAC((const char *)passwd, passwdlen, B, p * 128 * r, 1, EVP_sha256(), buflen, buf);
|
||||
#else
|
||||
PBKDF2_SHA256(passwd, passwdlen, B, p * 128 * r, 1, buf, buflen);
|
||||
#endif
|
||||
|
||||
/* Free memory. */
|
||||
free(V);
|
||||
free(XY);
|
||||
free(B);
|
||||
|
||||
/* Success! */
|
||||
return (0);
|
||||
|
||||
err2:
|
||||
free(XY);
|
||||
err1:
|
||||
free(B);
|
||||
err0:
|
||||
/* Failure! */
|
||||
return (-1);
|
||||
}
|
||||
@@ -0,0 +1,378 @@
|
||||
/*-
|
||||
* Copyright 2009 Colin Percival
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* This file was originally written by Colin Percival as part of the Tarsnap
|
||||
* online backup system.
|
||||
*/
|
||||
#include "scrypt_platform.h"
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/mman.h>
|
||||
|
||||
#include <emmintrin.h>
|
||||
#include <errno.h>
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#ifdef USE_OPENSSL_PBKDF2
|
||||
#include <openssl/evp.h>
|
||||
#else
|
||||
#include "sha256.h"
|
||||
#endif
|
||||
#include "sysendian.h"
|
||||
|
||||
#include "crypto_scrypt.h"
|
||||
|
||||
static void blkcpy(void *, void *, size_t);
|
||||
static void blkxor(void *, void *, size_t);
|
||||
static void salsa20_8(__m128i *);
|
||||
static void blockmix_salsa8(__m128i *, __m128i *, __m128i *, size_t);
|
||||
static uint64_t integerify(void *, size_t);
|
||||
static void smix(uint8_t *, size_t, uint64_t, void *, void *);
|
||||
|
||||
static void
|
||||
blkcpy(void * dest, void * src, size_t len)
|
||||
{
|
||||
__m128i * D = dest;
|
||||
__m128i * S = src;
|
||||
size_t L = len / 16;
|
||||
size_t i;
|
||||
|
||||
for (i = 0; i < L; i++)
|
||||
D[i] = S[i];
|
||||
}
|
||||
|
||||
static void
|
||||
blkxor(void * dest, void * src, size_t len)
|
||||
{
|
||||
__m128i * D = dest;
|
||||
__m128i * S = src;
|
||||
size_t L = len / 16;
|
||||
size_t i;
|
||||
|
||||
for (i = 0; i < L; i++)
|
||||
D[i] = _mm_xor_si128(D[i], S[i]);
|
||||
}
|
||||
|
||||
/**
|
||||
* salsa20_8(B):
|
||||
* Apply the salsa20/8 core to the provided block.
|
||||
*/
|
||||
static void
|
||||
salsa20_8(__m128i B[4])
|
||||
{
|
||||
__m128i X0, X1, X2, X3;
|
||||
__m128i T;
|
||||
size_t i;
|
||||
|
||||
X0 = B[0];
|
||||
X1 = B[1];
|
||||
X2 = B[2];
|
||||
X3 = B[3];
|
||||
|
||||
for (i = 0; i < 8; i += 2) {
|
||||
/* Operate on "columns". */
|
||||
T = _mm_add_epi32(X0, X3);
|
||||
X1 = _mm_xor_si128(X1, _mm_slli_epi32(T, 7));
|
||||
X1 = _mm_xor_si128(X1, _mm_srli_epi32(T, 25));
|
||||
T = _mm_add_epi32(X1, X0);
|
||||
X2 = _mm_xor_si128(X2, _mm_slli_epi32(T, 9));
|
||||
X2 = _mm_xor_si128(X2, _mm_srli_epi32(T, 23));
|
||||
T = _mm_add_epi32(X2, X1);
|
||||
X3 = _mm_xor_si128(X3, _mm_slli_epi32(T, 13));
|
||||
X3 = _mm_xor_si128(X3, _mm_srli_epi32(T, 19));
|
||||
T = _mm_add_epi32(X3, X2);
|
||||
X0 = _mm_xor_si128(X0, _mm_slli_epi32(T, 18));
|
||||
X0 = _mm_xor_si128(X0, _mm_srli_epi32(T, 14));
|
||||
|
||||
/* Rearrange data. */
|
||||
X1 = _mm_shuffle_epi32(X1, 0x93);
|
||||
X2 = _mm_shuffle_epi32(X2, 0x4E);
|
||||
X3 = _mm_shuffle_epi32(X3, 0x39);
|
||||
|
||||
/* Operate on "rows". */
|
||||
T = _mm_add_epi32(X0, X1);
|
||||
X3 = _mm_xor_si128(X3, _mm_slli_epi32(T, 7));
|
||||
X3 = _mm_xor_si128(X3, _mm_srli_epi32(T, 25));
|
||||
T = _mm_add_epi32(X3, X0);
|
||||
X2 = _mm_xor_si128(X2, _mm_slli_epi32(T, 9));
|
||||
X2 = _mm_xor_si128(X2, _mm_srli_epi32(T, 23));
|
||||
T = _mm_add_epi32(X2, X3);
|
||||
X1 = _mm_xor_si128(X1, _mm_slli_epi32(T, 13));
|
||||
X1 = _mm_xor_si128(X1, _mm_srli_epi32(T, 19));
|
||||
T = _mm_add_epi32(X1, X2);
|
||||
X0 = _mm_xor_si128(X0, _mm_slli_epi32(T, 18));
|
||||
X0 = _mm_xor_si128(X0, _mm_srli_epi32(T, 14));
|
||||
|
||||
/* Rearrange data. */
|
||||
X1 = _mm_shuffle_epi32(X1, 0x39);
|
||||
X2 = _mm_shuffle_epi32(X2, 0x4E);
|
||||
X3 = _mm_shuffle_epi32(X3, 0x93);
|
||||
}
|
||||
|
||||
B[0] = _mm_add_epi32(B[0], X0);
|
||||
B[1] = _mm_add_epi32(B[1], X1);
|
||||
B[2] = _mm_add_epi32(B[2], X2);
|
||||
B[3] = _mm_add_epi32(B[3], X3);
|
||||
}
|
||||
|
||||
/**
|
||||
* blockmix_salsa8(Bin, Bout, X, r):
|
||||
* Compute Bout = BlockMix_{salsa20/8, r}(Bin). The input Bin must be 128r
|
||||
* bytes in length; the output Bout must also be the same size. The
|
||||
* temporary space X must be 64 bytes.
|
||||
*/
|
||||
static void
|
||||
blockmix_salsa8(__m128i * Bin, __m128i * Bout, __m128i * X, size_t r)
|
||||
{
|
||||
size_t i;
|
||||
|
||||
/* 1: X <-- B_{2r - 1} */
|
||||
blkcpy(X, &Bin[8 * r - 4], 64);
|
||||
|
||||
/* 2: for i = 0 to 2r - 1 do */
|
||||
for (i = 0; i < r; i++) {
|
||||
/* 3: X <-- H(X \xor B_i) */
|
||||
blkxor(X, &Bin[i * 8], 64);
|
||||
salsa20_8(X);
|
||||
|
||||
/* 4: Y_i <-- X */
|
||||
/* 6: B' <-- (Y_0, Y_2 ... Y_{2r-2}, Y_1, Y_3 ... Y_{2r-1}) */
|
||||
blkcpy(&Bout[i * 4], X, 64);
|
||||
|
||||
/* 3: X <-- H(X \xor B_i) */
|
||||
blkxor(X, &Bin[i * 8 + 4], 64);
|
||||
salsa20_8(X);
|
||||
|
||||
/* 4: Y_i <-- X */
|
||||
/* 6: B' <-- (Y_0, Y_2 ... Y_{2r-2}, Y_1, Y_3 ... Y_{2r-1}) */
|
||||
blkcpy(&Bout[(r + i) * 4], X, 64);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* integerify(B, r):
|
||||
* Return the result of parsing B_{2r-1} as a little-endian integer.
|
||||
*/
|
||||
static uint64_t
|
||||
integerify(void * B, size_t r)
|
||||
{
|
||||
uint32_t * X = (void *)((uintptr_t)(B) + (2 * r - 1) * 64);
|
||||
|
||||
return (((uint64_t)(X[13]) << 32) + X[0]);
|
||||
}
|
||||
|
||||
/**
|
||||
* smix(B, r, N, V, XY):
|
||||
* Compute B = SMix_r(B, N). The input B must be 128r bytes in length;
|
||||
* the temporary storage V must be 128rN bytes in length; the temporary
|
||||
* storage XY must be 256r + 64 bytes in length. The value N must be a
|
||||
* power of 2 greater than 1. The arrays B, V, and XY must be aligned to a
|
||||
* multiple of 64 bytes.
|
||||
*/
|
||||
static void
|
||||
smix(uint8_t * B, size_t r, uint64_t N, void * V, void * XY)
|
||||
{
|
||||
__m128i * X = XY;
|
||||
__m128i * Y = (void *)((uintptr_t)(XY) + 128 * r);
|
||||
__m128i * Z = (void *)((uintptr_t)(XY) + 256 * r);
|
||||
uint32_t * X32 = (void *)X;
|
||||
uint64_t i, j;
|
||||
size_t k;
|
||||
|
||||
/* 1: X <-- B */
|
||||
for (k = 0; k < 2 * r; k++) {
|
||||
for (i = 0; i < 16; i++) {
|
||||
X32[k * 16 + i] =
|
||||
le32dec(&B[(k * 16 + (i * 5 % 16)) * 4]);
|
||||
}
|
||||
}
|
||||
|
||||
/* 2: for i = 0 to N - 1 do */
|
||||
for (i = 0; i < N; i += 2) {
|
||||
/* 3: V_i <-- X */
|
||||
blkcpy((void *)((uintptr_t)(V) + i * 128 * r), X, 128 * r);
|
||||
|
||||
/* 4: X <-- H(X) */
|
||||
blockmix_salsa8(X, Y, Z, r);
|
||||
|
||||
/* 3: V_i <-- X */
|
||||
blkcpy((void *)((uintptr_t)(V) + (i + 1) * 128 * r),
|
||||
Y, 128 * r);
|
||||
|
||||
/* 4: X <-- H(X) */
|
||||
blockmix_salsa8(Y, X, Z, r);
|
||||
}
|
||||
|
||||
/* 6: for i = 0 to N - 1 do */
|
||||
for (i = 0; i < N; i += 2) {
|
||||
/* 7: j <-- Integerify(X) mod N */
|
||||
j = integerify(X, r) & (N - 1);
|
||||
|
||||
/* 8: X <-- H(X \xor V_j) */
|
||||
blkxor(X, (void *)((uintptr_t)(V) + j * 128 * r), 128 * r);
|
||||
blockmix_salsa8(X, Y, Z, r);
|
||||
|
||||
/* 7: j <-- Integerify(X) mod N */
|
||||
j = integerify(Y, r) & (N - 1);
|
||||
|
||||
/* 8: X <-- H(X \xor V_j) */
|
||||
blkxor(Y, (void *)((uintptr_t)(V) + j * 128 * r), 128 * r);
|
||||
blockmix_salsa8(Y, X, Z, r);
|
||||
}
|
||||
|
||||
/* 10: B' <-- X */
|
||||
for (k = 0; k < 2 * r; k++) {
|
||||
for (i = 0; i < 16; i++) {
|
||||
le32enc(&B[(k * 16 + (i * 5 % 16)) * 4],
|
||||
X32[k * 16 + i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* crypto_scrypt(passwd, passwdlen, salt, saltlen, N, r, p, buf, buflen):
|
||||
* Compute scrypt(passwd[0 .. passwdlen - 1], salt[0 .. saltlen - 1], N, r,
|
||||
* p, buflen) and write the result into buf. The parameters r, p, and buflen
|
||||
* must satisfy r * p < 2^30 and buflen <= (2^32 - 1) * 32. The parameter N
|
||||
* must be a power of 2 greater than 1.
|
||||
*
|
||||
* Return 0 on success; or -1 on error.
|
||||
*/
|
||||
int
|
||||
crypto_scrypt(const uint8_t * passwd, size_t passwdlen,
|
||||
const uint8_t * salt, size_t saltlen, uint64_t N, uint32_t r, uint32_t p,
|
||||
uint8_t * buf, size_t buflen)
|
||||
{
|
||||
void * B0, * V0, * XY0;
|
||||
uint8_t * B;
|
||||
uint32_t * V;
|
||||
uint32_t * XY;
|
||||
uint32_t i;
|
||||
|
||||
/* Sanity-check parameters. */
|
||||
#if SIZE_MAX > UINT32_MAX
|
||||
if (buflen > (((uint64_t)(1) << 32) - 1) * 32) {
|
||||
errno = EFBIG;
|
||||
goto err0;
|
||||
}
|
||||
#endif
|
||||
if ((uint64_t)(r) * (uint64_t)(p) >= (1 << 30)) {
|
||||
errno = EFBIG;
|
||||
goto err0;
|
||||
}
|
||||
if (((N & (N - 1)) != 0) || (N == 0)) {
|
||||
errno = EINVAL;
|
||||
goto err0;
|
||||
}
|
||||
if ((r > SIZE_MAX / 128 / p) ||
|
||||
#if SIZE_MAX / 256 <= UINT32_MAX
|
||||
(r > (SIZE_MAX - 64) / 256) ||
|
||||
#endif
|
||||
(N > SIZE_MAX / 128 / r)) {
|
||||
errno = ENOMEM;
|
||||
goto err0;
|
||||
}
|
||||
|
||||
/* Allocate memory. */
|
||||
#ifdef HAVE_POSIX_MEMALIGN
|
||||
if ((errno = posix_memalign(&B0, 64, 128 * r * p)) != 0)
|
||||
goto err0;
|
||||
B = (uint8_t *)(B0);
|
||||
if ((errno = posix_memalign(&XY0, 64, 256 * r + 64)) != 0)
|
||||
goto err1;
|
||||
XY = (uint32_t *)(XY0);
|
||||
#ifndef MAP_ANON
|
||||
if ((errno = posix_memalign(&V0, 64, 128 * r * N)) != 0)
|
||||
goto err2;
|
||||
V = (uint32_t *)(V0);
|
||||
#endif
|
||||
#else
|
||||
if ((B0 = malloc(128 * r * p + 63)) == NULL)
|
||||
goto err0;
|
||||
B = (uint8_t *)(((uintptr_t)(B0) + 63) & ~ (uintptr_t)(63));
|
||||
if ((XY0 = malloc(256 * r + 64 + 63)) == NULL)
|
||||
goto err1;
|
||||
XY = (uint32_t *)(((uintptr_t)(XY0) + 63) & ~ (uintptr_t)(63));
|
||||
#ifndef MAP_ANON
|
||||
if ((V0 = malloc(128 * r * N + 63)) == NULL)
|
||||
goto err2;
|
||||
V = (uint32_t *)(((uintptr_t)(V0) + 63) & ~ (uintptr_t)(63));
|
||||
#endif
|
||||
#endif
|
||||
#ifdef MAP_ANON
|
||||
if ((V0 = mmap(NULL, 128 * r * N, PROT_READ | PROT_WRITE,
|
||||
#ifdef MAP_NOCORE
|
||||
MAP_ANON | MAP_PRIVATE | MAP_NOCORE,
|
||||
#else
|
||||
MAP_ANON | MAP_PRIVATE,
|
||||
#endif
|
||||
-1, 0)) == MAP_FAILED)
|
||||
goto err2;
|
||||
V = (uint32_t *)(V0);
|
||||
#endif
|
||||
|
||||
/* 1: (B_0 ... B_{p-1}) <-- PBKDF2(P, S, 1, p * MFLen) */
|
||||
#ifdef USE_OPENSSL_PBKDF2
|
||||
PKCS5_PBKDF2_HMAC((const char *)passwd, passwdlen, salt, saltlen, 1, EVP_sha256(), p * 128 * r, B);
|
||||
#else
|
||||
PBKDF2_SHA256(passwd, passwdlen, salt, saltlen, 1, B, p * 128 * r);
|
||||
#endif
|
||||
|
||||
/* 2: for i = 0 to p - 1 do */
|
||||
for (i = 0; i < p; i++) {
|
||||
/* 3: B_i <-- MF(B_i, N) */
|
||||
smix(&B[i * 128 * r], r, N, V, XY);
|
||||
}
|
||||
|
||||
/* 5: DK <-- PBKDF2(P, B, 1, dkLen) */
|
||||
#ifdef USE_OPENSSL_PBKDF2
|
||||
PKCS5_PBKDF2_HMAC((const char *)passwd, passwdlen, B, p * 128 * r, 1, EVP_sha256(), buflen, buf);
|
||||
#else
|
||||
PBKDF2_SHA256(passwd, passwdlen, B, p * 128 * r, 1, buf, buflen);
|
||||
#endif
|
||||
|
||||
/* Free memory. */
|
||||
#ifdef MAP_ANON
|
||||
if (munmap(V0, 128 * r * N))
|
||||
goto err2;
|
||||
#else
|
||||
free(V0);
|
||||
#endif
|
||||
free(XY0);
|
||||
free(B0);
|
||||
|
||||
/* Success! */
|
||||
return (0);
|
||||
|
||||
err2:
|
||||
free(XY0);
|
||||
err1:
|
||||
free(B0);
|
||||
err0:
|
||||
/* Failure! */
|
||||
return (-1);
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
/*-
|
||||
* Copyright 2009 Colin Percival
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* This file was originally written by Colin Percival as part of the Tarsnap
|
||||
* online backup system.
|
||||
*/
|
||||
#ifndef _CRYPTO_SCRYPT_H_
|
||||
#define _CRYPTO_SCRYPT_H_
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
/**
|
||||
* crypto_scrypt(passwd, passwdlen, salt, saltlen, N, r, p, buf, buflen):
|
||||
* Compute scrypt(passwd[0 .. passwdlen - 1], salt[0 .. saltlen - 1], N, r,
|
||||
* p, buflen) and write the result into buf. The parameters r, p, and buflen
|
||||
* must satisfy r * p < 2^30 and buflen <= (2^32 - 1) * 32. The parameter N
|
||||
* must be a power of 2 greater than 1.
|
||||
*
|
||||
* Return 0 on success; or -1 on error.
|
||||
*/
|
||||
int crypto_scrypt(const uint8_t *, size_t, const uint8_t *, size_t, uint64_t,
|
||||
uint32_t, uint32_t, uint8_t *, size_t);
|
||||
|
||||
#endif /* !_CRYPTO_SCRYPT_H_ */
|
||||
@@ -0,0 +1,140 @@
|
||||
/*-
|
||||
* Copyright 2007-2009 Colin Percival
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* This file was originally written by Colin Percival as part of the Tarsnap
|
||||
* online backup system.
|
||||
*/
|
||||
#ifndef _SYSENDIAN_H_
|
||||
#define _SYSENDIAN_H_
|
||||
|
||||
#include "scrypt_platform.h"
|
||||
|
||||
/* If we don't have be64enc, the <sys/endian.h> we have isn't usable. */
|
||||
#if !HAVE_DECL_BE64ENC
|
||||
#undef HAVE_SYS_ENDIAN_H
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_SYS_ENDIAN_H
|
||||
|
||||
#include <sys/endian.h>
|
||||
|
||||
#else
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
static inline uint32_t
|
||||
be32dec(const void *pp)
|
||||
{
|
||||
const uint8_t *p = (uint8_t const *)pp;
|
||||
|
||||
return ((uint32_t)(p[3]) + ((uint32_t)(p[2]) << 8) +
|
||||
((uint32_t)(p[1]) << 16) + ((uint32_t)(p[0]) << 24));
|
||||
}
|
||||
|
||||
static inline void
|
||||
be32enc(void *pp, uint32_t x)
|
||||
{
|
||||
uint8_t * p = (uint8_t *)pp;
|
||||
|
||||
p[3] = x & 0xff;
|
||||
p[2] = (x >> 8) & 0xff;
|
||||
p[1] = (x >> 16) & 0xff;
|
||||
p[0] = (x >> 24) & 0xff;
|
||||
}
|
||||
|
||||
static inline uint64_t
|
||||
be64dec(const void *pp)
|
||||
{
|
||||
const uint8_t *p = (uint8_t const *)pp;
|
||||
|
||||
return ((uint64_t)(p[7]) + ((uint64_t)(p[6]) << 8) +
|
||||
((uint64_t)(p[5]) << 16) + ((uint64_t)(p[4]) << 24) +
|
||||
((uint64_t)(p[3]) << 32) + ((uint64_t)(p[2]) << 40) +
|
||||
((uint64_t)(p[1]) << 48) + ((uint64_t)(p[0]) << 56));
|
||||
}
|
||||
|
||||
static inline void
|
||||
be64enc(void *pp, uint64_t x)
|
||||
{
|
||||
uint8_t * p = (uint8_t *)pp;
|
||||
|
||||
p[7] = x & 0xff;
|
||||
p[6] = (x >> 8) & 0xff;
|
||||
p[5] = (x >> 16) & 0xff;
|
||||
p[4] = (x >> 24) & 0xff;
|
||||
p[3] = (x >> 32) & 0xff;
|
||||
p[2] = (x >> 40) & 0xff;
|
||||
p[1] = (x >> 48) & 0xff;
|
||||
p[0] = (x >> 56) & 0xff;
|
||||
}
|
||||
|
||||
static inline uint32_t
|
||||
le32dec(const void *pp)
|
||||
{
|
||||
const uint8_t *p = (uint8_t const *)pp;
|
||||
|
||||
return ((uint32_t)(p[0]) + ((uint32_t)(p[1]) << 8) +
|
||||
((uint32_t)(p[2]) << 16) + ((uint32_t)(p[3]) << 24));
|
||||
}
|
||||
|
||||
static inline void
|
||||
le32enc(void *pp, uint32_t x)
|
||||
{
|
||||
uint8_t * p = (uint8_t *)pp;
|
||||
|
||||
p[0] = x & 0xff;
|
||||
p[1] = (x >> 8) & 0xff;
|
||||
p[2] = (x >> 16) & 0xff;
|
||||
p[3] = (x >> 24) & 0xff;
|
||||
}
|
||||
|
||||
static inline uint64_t
|
||||
le64dec(const void *pp)
|
||||
{
|
||||
const uint8_t *p = (uint8_t const *)pp;
|
||||
|
||||
return ((uint64_t)(p[0]) + ((uint64_t)(p[1]) << 8) +
|
||||
((uint64_t)(p[2]) << 16) + ((uint64_t)(p[3]) << 24) +
|
||||
((uint64_t)(p[4]) << 32) + ((uint64_t)(p[5]) << 40) +
|
||||
((uint64_t)(p[6]) << 48) + ((uint64_t)(p[7]) << 56));
|
||||
}
|
||||
|
||||
static inline void
|
||||
le64enc(void *pp, uint64_t x)
|
||||
{
|
||||
uint8_t * p = (uint8_t *)pp;
|
||||
|
||||
p[0] = x & 0xff;
|
||||
p[1] = (x >> 8) & 0xff;
|
||||
p[2] = (x >> 16) & 0xff;
|
||||
p[3] = (x >> 24) & 0xff;
|
||||
p[4] = (x >> 32) & 0xff;
|
||||
p[5] = (x >> 40) & 0xff;
|
||||
p[6] = (x >> 48) & 0xff;
|
||||
p[7] = (x >> 56) & 0xff;
|
||||
}
|
||||
#endif /* !HAVE_SYS_ENDIAN_H */
|
||||
|
||||
#endif /* !_SYSENDIAN_H_ */
|
||||
@@ -0,0 +1,11 @@
|
||||
bionic.patch:
|
||||
|
||||
Allows scrypt to compile against bionic.
|
||||
|
||||
use_openssl_pbkdf2.patch:
|
||||
|
||||
Uses the PBKDF2 function from OpenSSL (it uses accelerated SHA256)
|
||||
|
||||
arm-neon.patch:
|
||||
|
||||
Adds NEON acceleration for the Salsa20/8 mixing function.
|
||||
@@ -0,0 +1,436 @@
|
||||
diff --git a/lib/crypto/crypto_scrypt-neon-salsa208.h b/lib/crypto/crypto_scrypt-neon-salsa208.h
|
||||
new file mode 100644
|
||||
index 0000000..a3b1019
|
||||
--- /dev/null
|
||||
+++ b/lib/crypto/crypto_scrypt-neon-salsa208.h
|
||||
@@ -0,0 +1,120 @@
|
||||
+/*
|
||||
+ * version 20110505
|
||||
+ * D. J. Bernstein
|
||||
+ * Public domain.
|
||||
+ *
|
||||
+ * Based on crypto_core/salsa208/armneon/core.c from SUPERCOP 20130419
|
||||
+ */
|
||||
+
|
||||
+#define ROUNDS 8
|
||||
+static void
|
||||
+salsa20_8_intrinsic(void * input)
|
||||
+{
|
||||
+ int i;
|
||||
+
|
||||
+ const uint32x4_t abab = {-1,0,-1,0};
|
||||
+
|
||||
+ /*
|
||||
+ * This is modified since we only have one argument. Usually you'd rearrange
|
||||
+ * the constant, key, and input bytes, but we just have one linear array to
|
||||
+ * rearrange which is a bit easier.
|
||||
+ */
|
||||
+
|
||||
+ /*
|
||||
+ * Change the input to be diagonals as if it's a 4x4 matrix of 32-bit values.
|
||||
+ */
|
||||
+ uint32x4_t x0x5x10x15;
|
||||
+ uint32x4_t x12x1x6x11;
|
||||
+ uint32x4_t x8x13x2x7;
|
||||
+ uint32x4_t x4x9x14x3;
|
||||
+
|
||||
+ uint32x4_t x0x1x10x11;
|
||||
+ uint32x4_t x12x13x6x7;
|
||||
+ uint32x4_t x8x9x2x3;
|
||||
+ uint32x4_t x4x5x14x15;
|
||||
+
|
||||
+ uint32x4_t x0x1x2x3;
|
||||
+ uint32x4_t x4x5x6x7;
|
||||
+ uint32x4_t x8x9x10x11;
|
||||
+ uint32x4_t x12x13x14x15;
|
||||
+
|
||||
+ x0x1x2x3 = vld1q_u8((uint8_t *) input);
|
||||
+ x4x5x6x7 = vld1q_u8(16 + (uint8_t *) input);
|
||||
+ x8x9x10x11 = vld1q_u8(32 + (uint8_t *) input);
|
||||
+ x12x13x14x15 = vld1q_u8(48 + (uint8_t *) input);
|
||||
+
|
||||
+ x0x1x10x11 = vcombine_u32(vget_low_u32(x0x1x2x3), vget_high_u32(x8x9x10x11));
|
||||
+ x4x5x14x15 = vcombine_u32(vget_low_u32(x4x5x6x7), vget_high_u32(x12x13x14x15));
|
||||
+ x8x9x2x3 = vcombine_u32(vget_low_u32(x8x9x10x11), vget_high_u32(x0x1x2x3));
|
||||
+ x12x13x6x7 = vcombine_u32(vget_low_u32(x12x13x14x15), vget_high_u32(x4x5x6x7));
|
||||
+
|
||||
+ x0x5x10x15 = vbslq_u32(abab,x0x1x10x11,x4x5x14x15);
|
||||
+ x8x13x2x7 = vbslq_u32(abab,x8x9x2x3,x12x13x6x7);
|
||||
+ x4x9x14x3 = vbslq_u32(abab,x4x5x14x15,x8x9x2x3);
|
||||
+ x12x1x6x11 = vbslq_u32(abab,x12x13x6x7,x0x1x10x11);
|
||||
+
|
||||
+ uint32x4_t start0 = x0x5x10x15;
|
||||
+ uint32x4_t start1 = x12x1x6x11;
|
||||
+ uint32x4_t start3 = x4x9x14x3;
|
||||
+ uint32x4_t start2 = x8x13x2x7;
|
||||
+
|
||||
+ /* From here on this should be the same as the SUPERCOP version. */
|
||||
+
|
||||
+ uint32x4_t diag0 = start0;
|
||||
+ uint32x4_t diag1 = start1;
|
||||
+ uint32x4_t diag2 = start2;
|
||||
+ uint32x4_t diag3 = start3;
|
||||
+
|
||||
+ uint32x4_t a0;
|
||||
+ uint32x4_t a1;
|
||||
+ uint32x4_t a2;
|
||||
+ uint32x4_t a3;
|
||||
+
|
||||
+ for (i = ROUNDS;i > 0;i -= 2) {
|
||||
+ a0 = diag1 + diag0;
|
||||
+ diag3 ^= vsriq_n_u32(vshlq_n_u32(a0,7),a0,25);
|
||||
+ a1 = diag0 + diag3;
|
||||
+ diag2 ^= vsriq_n_u32(vshlq_n_u32(a1,9),a1,23);
|
||||
+ a2 = diag3 + diag2;
|
||||
+ diag1 ^= vsriq_n_u32(vshlq_n_u32(a2,13),a2,19);
|
||||
+ a3 = diag2 + diag1;
|
||||
+ diag0 ^= vsriq_n_u32(vshlq_n_u32(a3,18),a3,14);
|
||||
+
|
||||
+ diag3 = vextq_u32(diag3,diag3,3);
|
||||
+ diag2 = vextq_u32(diag2,diag2,2);
|
||||
+ diag1 = vextq_u32(diag1,diag1,1);
|
||||
+
|
||||
+ a0 = diag3 + diag0;
|
||||
+ diag1 ^= vsriq_n_u32(vshlq_n_u32(a0,7),a0,25);
|
||||
+ a1 = diag0 + diag1;
|
||||
+ diag2 ^= vsriq_n_u32(vshlq_n_u32(a1,9),a1,23);
|
||||
+ a2 = diag1 + diag2;
|
||||
+ diag3 ^= vsriq_n_u32(vshlq_n_u32(a2,13),a2,19);
|
||||
+ a3 = diag2 + diag3;
|
||||
+ diag0 ^= vsriq_n_u32(vshlq_n_u32(a3,18),a3,14);
|
||||
+
|
||||
+ diag1 = vextq_u32(diag1,diag1,3);
|
||||
+ diag2 = vextq_u32(diag2,diag2,2);
|
||||
+ diag3 = vextq_u32(diag3,diag3,1);
|
||||
+ }
|
||||
+
|
||||
+ x0x5x10x15 = diag0 + start0;
|
||||
+ x12x1x6x11 = diag1 + start1;
|
||||
+ x8x13x2x7 = diag2 + start2;
|
||||
+ x4x9x14x3 = diag3 + start3;
|
||||
+
|
||||
+ x0x1x10x11 = vbslq_u32(abab,x0x5x10x15,x12x1x6x11);
|
||||
+ x12x13x6x7 = vbslq_u32(abab,x12x1x6x11,x8x13x2x7);
|
||||
+ x8x9x2x3 = vbslq_u32(abab,x8x13x2x7,x4x9x14x3);
|
||||
+ x4x5x14x15 = vbslq_u32(abab,x4x9x14x3,x0x5x10x15);
|
||||
+
|
||||
+ x0x1x2x3 = vcombine_u32(vget_low_u32(x0x1x10x11),vget_high_u32(x8x9x2x3));
|
||||
+ x4x5x6x7 = vcombine_u32(vget_low_u32(x4x5x14x15),vget_high_u32(x12x13x6x7));
|
||||
+ x8x9x10x11 = vcombine_u32(vget_low_u32(x8x9x2x3),vget_high_u32(x0x1x10x11));
|
||||
+ x12x13x14x15 = vcombine_u32(vget_low_u32(x12x13x6x7),vget_high_u32(x4x5x14x15));
|
||||
+
|
||||
+ vst1q_u8((uint8_t *) input,(uint8x16_t) x0x1x2x3);
|
||||
+ vst1q_u8(16 + (uint8_t *) input,(uint8x16_t) x4x5x6x7);
|
||||
+ vst1q_u8(32 + (uint8_t *) input,(uint8x16_t) x8x9x10x11);
|
||||
+ vst1q_u8(48 + (uint8_t *) input,(uint8x16_t) x12x13x14x15);
|
||||
+}
|
||||
diff --git a/lib/crypto/crypto_scrypt-neon.c b/lib/crypto/crypto_scrypt-neon.c
|
||||
new file mode 100644
|
||||
index 0000000..a3bf052
|
||||
--- /dev/null
|
||||
+++ b/lib/crypto/crypto_scrypt-neon.c
|
||||
@@ -0,0 +1,304 @@
|
||||
+/*-
|
||||
+ * Copyright 2009 Colin Percival
|
||||
+ * All rights reserved.
|
||||
+ *
|
||||
+ * Redistribution and use in source and binary forms, with or without
|
||||
+ * modification, are permitted provided that the following conditions
|
||||
+ * are met:
|
||||
+ * 1. Redistributions of source code must retain the above copyright
|
||||
+ * notice, this list of conditions and the following disclaimer.
|
||||
+ * 2. Redistributions in binary form must reproduce the above copyright
|
||||
+ * notice, this list of conditions and the following disclaimer in the
|
||||
+ * documentation and/or other materials provided with the distribution.
|
||||
+ *
|
||||
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
||||
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
||||
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
+ * SUCH DAMAGE.
|
||||
+ *
|
||||
+ * This file was originally written by Colin Percival as part of the Tarsnap
|
||||
+ * online backup system.
|
||||
+ */
|
||||
+#include "scrypt_platform.h"
|
||||
+
|
||||
+#include <arm_neon.h>
|
||||
+
|
||||
+#include <errno.h>
|
||||
+#include <stdint.h>
|
||||
+#include <limits.h>
|
||||
+#include <stdlib.h>
|
||||
+#include <string.h>
|
||||
+
|
||||
+#ifdef USE_OPENSSL_PBKDF2
|
||||
+#include <openssl/evp.h>
|
||||
+#else
|
||||
+#include "sha256.h"
|
||||
+#endif
|
||||
+#include "sysendian.h"
|
||||
+
|
||||
+#include "crypto_scrypt.h"
|
||||
+
|
||||
+#include "crypto_scrypt-neon-salsa208.h"
|
||||
+
|
||||
+static void blkcpy(void *, void *, size_t);
|
||||
+static void blkxor(void *, void *, size_t);
|
||||
+void crypto_core_salsa208_armneon2(void *);
|
||||
+static void blockmix_salsa8(uint8x16_t *, uint8x16_t *, uint8x16_t *, size_t);
|
||||
+static uint64_t integerify(void *, size_t);
|
||||
+static void smix(uint8_t *, size_t, uint64_t, void *, void *);
|
||||
+
|
||||
+static void
|
||||
+blkcpy(void * dest, void * src, size_t len)
|
||||
+{
|
||||
+ uint8x16_t * D = dest;
|
||||
+ uint8x16_t * S = src;
|
||||
+ size_t L = len / 16;
|
||||
+ size_t i;
|
||||
+
|
||||
+ for (i = 0; i < L; i++)
|
||||
+ D[i] = S[i];
|
||||
+}
|
||||
+
|
||||
+static void
|
||||
+blkxor(void * dest, void * src, size_t len)
|
||||
+{
|
||||
+ uint8x16_t * D = dest;
|
||||
+ uint8x16_t * S = src;
|
||||
+ size_t L = len / 16;
|
||||
+ size_t i;
|
||||
+
|
||||
+ for (i = 0; i < L; i++)
|
||||
+ D[i] = veorq_u8(D[i], S[i]);
|
||||
+}
|
||||
+
|
||||
+/**
|
||||
+ * blockmix_salsa8(B, Y, r):
|
||||
+ * Compute B = BlockMix_{salsa20/8, r}(B). The input B must be 128r bytes in
|
||||
+ * length; the temporary space Y must also be the same size.
|
||||
+ */
|
||||
+static void
|
||||
+blockmix_salsa8(uint8x16_t * Bin, uint8x16_t * Bout, uint8x16_t * X, size_t r)
|
||||
+{
|
||||
+ size_t i;
|
||||
+
|
||||
+ /* 1: X <-- B_{2r - 1} */
|
||||
+ blkcpy(X, &Bin[8 * r - 4], 64);
|
||||
+
|
||||
+ /* 2: for i = 0 to 2r - 1 do */
|
||||
+ for (i = 0; i < r; i++) {
|
||||
+ /* 3: X <-- H(X \xor B_i) */
|
||||
+ blkxor(X, &Bin[i * 8], 64);
|
||||
+ salsa20_8_intrinsic((void *) X);
|
||||
+
|
||||
+ /* 4: Y_i <-- X */
|
||||
+ /* 6: B' <-- (Y_0, Y_2 ... Y_{2r-2}, Y_1, Y_3 ... Y_{2r-1}) */
|
||||
+ blkcpy(&Bout[i * 4], X, 64);
|
||||
+
|
||||
+ /* 3: X <-- H(X \xor B_i) */
|
||||
+ blkxor(X, &Bin[i * 8 + 4], 64);
|
||||
+ salsa20_8_intrinsic((void *) X);
|
||||
+
|
||||
+ /* 4: Y_i <-- X */
|
||||
+ /* 6: B' <-- (Y_0, Y_2 ... Y_{2r-2}, Y_1, Y_3 ... Y_{2r-1}) */
|
||||
+ blkcpy(&Bout[(r + i) * 4], X, 64);
|
||||
+ }
|
||||
+}
|
||||
+
|
||||
+/**
|
||||
+ * integerify(B, r):
|
||||
+ * Return the result of parsing B_{2r-1} as a little-endian integer.
|
||||
+ */
|
||||
+static uint64_t
|
||||
+integerify(void * B, size_t r)
|
||||
+{
|
||||
+ uint8_t * X = (void*)((uintptr_t)(B) + (2 * r - 1) * 64);
|
||||
+
|
||||
+ return (le64dec(X));
|
||||
+}
|
||||
+
|
||||
+/**
|
||||
+ * smix(B, r, N, V, XY):
|
||||
+ * Compute B = SMix_r(B, N). The input B must be 128r bytes in length; the
|
||||
+ * temporary storage V must be 128rN bytes in length; the temporary storage
|
||||
+ * XY must be 256r bytes in length. The value N must be a power of 2.
|
||||
+ */
|
||||
+static void
|
||||
+smix(uint8_t * B, size_t r, uint64_t N, void * V, void * XY)
|
||||
+{
|
||||
+ uint8x16_t * X = XY;
|
||||
+ uint8x16_t * Y = (void *)((uintptr_t)(XY) + 128 * r);
|
||||
+ uint8x16_t * Z = (void *)((uintptr_t)(XY) + 256 * r);
|
||||
+ uint32_t * X32 = (void *)X;
|
||||
+ uint64_t i, j;
|
||||
+ size_t k;
|
||||
+
|
||||
+ /* 1: X <-- B */
|
||||
+ blkcpy(X, B, 128 * r);
|
||||
+
|
||||
+ /* 2: for i = 0 to N - 1 do */
|
||||
+ for (i = 0; i < N; i += 2) {
|
||||
+ /* 3: V_i <-- X */
|
||||
+ blkcpy((void *)((uintptr_t)(V) + i * 128 * r), X, 128 * r);
|
||||
+
|
||||
+ /* 4: X <-- H(X) */
|
||||
+ blockmix_salsa8(X, Y, Z, r);
|
||||
+
|
||||
+ /* 3: V_i <-- X */
|
||||
+ blkcpy((void *)((uintptr_t)(V) + (i + 1) * 128 * r),
|
||||
+ Y, 128 * r);
|
||||
+
|
||||
+ /* 4: X <-- H(X) */
|
||||
+ blockmix_salsa8(Y, X, Z, r);
|
||||
+ }
|
||||
+
|
||||
+ /* 6: for i = 0 to N - 1 do */
|
||||
+ for (i = 0; i < N; i += 2) {
|
||||
+ /* 7: j <-- Integerify(X) mod N */
|
||||
+ j = integerify(X, r) & (N - 1);
|
||||
+
|
||||
+ /* 8: X <-- H(X \xor V_j) */
|
||||
+ blkxor(X, (void *)((uintptr_t)(V) + j * 128 * r), 128 * r);
|
||||
+ blockmix_salsa8(X, Y, Z, r);
|
||||
+
|
||||
+ /* 7: j <-- Integerify(X) mod N */
|
||||
+ j = integerify(Y, r) & (N - 1);
|
||||
+
|
||||
+ /* 8: X <-- H(X \xor V_j) */
|
||||
+ blkxor(Y, (void *)((uintptr_t)(V) + j * 128 * r), 128 * r);
|
||||
+ blockmix_salsa8(Y, X, Z, r);
|
||||
+ }
|
||||
+
|
||||
+ /* 10: B' <-- X */
|
||||
+ blkcpy(B, X, 128 * r);
|
||||
+}
|
||||
+
|
||||
+/**
|
||||
+ * crypto_scrypt(passwd, passwdlen, salt, saltlen, N, r, p, buf, buflen):
|
||||
+ * Compute scrypt(passwd[0 .. passwdlen - 1], salt[0 .. saltlen - 1], N, r,
|
||||
+ * p, buflen) and write the result into buf. The parameters r, p, and buflen
|
||||
+ * must satisfy r * p < 2^30 and buflen <= (2^32 - 1) * 32. The parameter N
|
||||
+ * must be a power of 2.
|
||||
+ *
|
||||
+ * Return 0 on success; or -1 on error.
|
||||
+ */
|
||||
+int
|
||||
+crypto_scrypt(const uint8_t * passwd, size_t passwdlen,
|
||||
+ const uint8_t * salt, size_t saltlen, uint64_t N, uint32_t r, uint32_t p,
|
||||
+ uint8_t * buf, size_t buflen)
|
||||
+{
|
||||
+ void * B0, * V0, * XY0;
|
||||
+ uint8_t * B;
|
||||
+ uint32_t * V;
|
||||
+ uint32_t * XY;
|
||||
+ uint32_t i;
|
||||
+
|
||||
+ /* Sanity-check parameters. */
|
||||
+#if SIZE_MAX > UINT32_MAX
|
||||
+ if (buflen > (((uint64_t)(1) << 32) - 1) * 32) {
|
||||
+ errno = EFBIG;
|
||||
+ goto err0;
|
||||
+ }
|
||||
+#endif
|
||||
+ if ((uint64_t)(r) * (uint64_t)(p) >= (1 << 30)) {
|
||||
+ errno = EFBIG;
|
||||
+ goto err0;
|
||||
+ }
|
||||
+ if (((N & (N - 1)) != 0) || (N == 0)) {
|
||||
+ errno = EINVAL;
|
||||
+ goto err0;
|
||||
+ }
|
||||
+ if ((r > SIZE_MAX / 128 / p) ||
|
||||
+#if SIZE_MAX / 256 <= UINT32_MAX
|
||||
+ (r > SIZE_MAX / 256) ||
|
||||
+#endif
|
||||
+ (N > SIZE_MAX / 128 / r)) {
|
||||
+ errno = ENOMEM;
|
||||
+ goto err0;
|
||||
+ }
|
||||
+
|
||||
+ /* Allocate memory. */
|
||||
+#ifdef HAVE_POSIX_MEMALIGN
|
||||
+ if ((errno = posix_memalign(&B0, 64, 128 * r * p)) != 0)
|
||||
+ goto err0;
|
||||
+ B = (uint8_t *)(B0);
|
||||
+ if ((errno = posix_memalign(&XY0, 64, 256 * r + 64)) != 0)
|
||||
+ goto err1;
|
||||
+ XY = (uint32_t *)(XY0);
|
||||
+#ifndef MAP_ANON
|
||||
+ if ((errno = posix_memalign(&V0, 64, 128 * r * N)) != 0)
|
||||
+ goto err2;
|
||||
+ V = (uint32_t *)(V0);
|
||||
+#endif
|
||||
+#else
|
||||
+ if ((B0 = malloc(128 * r * p + 63)) == NULL)
|
||||
+ goto err0;
|
||||
+ B = (uint8_t *)(((uintptr_t)(B0) + 63) & ~ (uintptr_t)(63));
|
||||
+ if ((XY0 = malloc(256 * r + 64 + 63)) == NULL)
|
||||
+ goto err1;
|
||||
+ XY = (uint32_t *)(((uintptr_t)(XY0) + 63) & ~ (uintptr_t)(63));
|
||||
+#ifndef MAP_ANON
|
||||
+ if ((V0 = malloc(128 * r * N + 63)) == NULL)
|
||||
+ goto err2;
|
||||
+ V = (uint32_t *)(((uintptr_t)(V0) + 63) & ~ (uintptr_t)(63));
|
||||
+#endif
|
||||
+#endif
|
||||
+#ifdef MAP_ANON
|
||||
+ if ((V0 = mmap(NULL, 128 * r * N, PROT_READ | PROT_WRITE,
|
||||
+#ifdef MAP_NOCORE
|
||||
+ MAP_ANON | MAP_PRIVATE | MAP_NOCORE,
|
||||
+#else
|
||||
+ MAP_ANON | MAP_PRIVATE,
|
||||
+#endif
|
||||
+ -1, 0)) == MAP_FAILED)
|
||||
+ goto err2;
|
||||
+ V = (uint32_t *)(V0);
|
||||
+#endif
|
||||
+
|
||||
+ /* 1: (B_0 ... B_{p-1}) <-- PBKDF2(P, S, 1, p * MFLen) */
|
||||
+#ifdef USE_OPENSSL_PBKDF2
|
||||
+ PKCS5_PBKDF2_HMAC((const char *)passwd, passwdlen, salt, saltlen, 1, EVP_sha256(), p * 128 * r, B);
|
||||
+#else
|
||||
+ PBKDF2_SHA256(passwd, passwdlen, salt, saltlen, 1, B, p * 128 * r);
|
||||
+#endif
|
||||
+
|
||||
+ /* 2: for i = 0 to p - 1 do */
|
||||
+ for (i = 0; i < p; i++) {
|
||||
+ /* 3: B_i <-- MF(B_i, N) */
|
||||
+ smix(&B[i * 128 * r], r, N, V, XY);
|
||||
+ }
|
||||
+
|
||||
+ /* 5: DK <-- PBKDF2(P, B, 1, dkLen) */
|
||||
+#ifdef USE_OPENSSL_PBKDF2
|
||||
+ PKCS5_PBKDF2_HMAC((const char *)passwd, passwdlen, B, p * 128 * r, 1, EVP_sha256(), buflen, buf);
|
||||
+#else
|
||||
+ PBKDF2_SHA256(passwd, passwdlen, B, p * 128 * r, 1, buf, buflen);
|
||||
+#endif
|
||||
+
|
||||
+ /* Free memory. */
|
||||
+#ifdef MAP_ANON
|
||||
+ if (munmap(V0, 128 * r * N))
|
||||
+ goto err2;
|
||||
+#else
|
||||
+ free(V0);
|
||||
+#endif
|
||||
+ free(XY0);
|
||||
+ free(B0);
|
||||
+
|
||||
+ /* Success! */
|
||||
+ return (0);
|
||||
+
|
||||
+err2:
|
||||
+ free(XY0);
|
||||
+err1:
|
||||
+ free(B0);
|
||||
+err0:
|
||||
+ /* Failure! */
|
||||
+ return (-1);
|
||||
+}
|
||||
@@ -0,0 +1,80 @@
|
||||
diff --git a/lib/crypto/crypto_scrypt-ref.c b/lib/crypto/crypto_scrypt-ref.c
|
||||
index 79a6f8f..60ef2aa 100644
|
||||
--- a/lib/crypto/crypto_scrypt-ref.c
|
||||
+++ b/lib/crypto/crypto_scrypt-ref.c
|
||||
@@ -34,7 +34,11 @@
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
+#ifdef USE_OPENSSL_PBKDF2
|
||||
+#include <openssl/evp.h>
|
||||
+#else
|
||||
#include "sha256.h"
|
||||
+#endif
|
||||
#include "sysendian.h"
|
||||
|
||||
#include "crypto_scrypt.h"
|
||||
@@ -256,7 +260,11 @@ crypto_scrypt(const uint8_t * passwd, size_t passwdlen,
|
||||
goto err2;
|
||||
|
||||
/* 1: (B_0 ... B_{p-1}) <-- PBKDF2(P, S, 1, p * MFLen) */
|
||||
+#ifdef USE_OPENSSL_PBKDF2
|
||||
+ PKCS5_PBKDF2_HMAC((const char *)passwd, passwdlen, salt, saltlen, 1, EVP_sha256(), p * 128 * r, B);
|
||||
+#else
|
||||
PBKDF2_SHA256(passwd, passwdlen, salt, saltlen, 1, B, p * 128 * r);
|
||||
+#endif
|
||||
|
||||
/* 2: for i = 0 to p - 1 do */
|
||||
for (i = 0; i < p; i++) {
|
||||
@@ -265,7 +273,11 @@ crypto_scrypt(const uint8_t * passwd, size_t passwdlen,
|
||||
}
|
||||
|
||||
/* 5: DK <-- PBKDF2(P, B, 1, dkLen) */
|
||||
+#ifdef USE_OPENSSL_PBKDF2
|
||||
+ PKCS5_PBKDF2_HMAC((const char *)passwd, passwdlen, B, p * 128 * r, 1, EVP_sha256(), buflen, buf);
|
||||
+#else
|
||||
PBKDF2_SHA256(passwd, passwdlen, B, p * 128 * r, 1, buf, buflen);
|
||||
+#endif
|
||||
|
||||
/* Free memory. */
|
||||
free(V);
|
||||
diff --git a/lib/crypto/crypto_scrypt-sse.c b/lib/crypto/crypto_scrypt-sse.c
|
||||
index 875175e..dd18f29 100644
|
||||
--- a/lib/crypto/crypto_scrypt-sse.c
|
||||
+++ b/lib/crypto/crypto_scrypt-sse.c
|
||||
@@ -37,7 +37,11 @@
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
+#ifdef USE_OPENSSL_PBKDF2
|
||||
+#include <openssl/evp.h>
|
||||
+#else
|
||||
#include "sha256.h"
|
||||
+#endif
|
||||
#include "sysendian.h"
|
||||
|
||||
#include "crypto_scrypt.h"
|
||||
@@ -332,7 +336,11 @@ crypto_scrypt(const uint8_t * passwd, size_t passwdlen,
|
||||
#endif
|
||||
|
||||
/* 1: (B_0 ... B_{p-1}) <-- PBKDF2(P, S, 1, p * MFLen) */
|
||||
+#ifdef USE_OPENSSL_PBKDF2
|
||||
+ PKCS5_PBKDF2_HMAC((const char *)passwd, passwdlen, salt, saltlen, 1, EVP_sha256(), p * 128 * r, B);
|
||||
+#else
|
||||
PBKDF2_SHA256(passwd, passwdlen, salt, saltlen, 1, B, p * 128 * r);
|
||||
+#endif
|
||||
|
||||
/* 2: for i = 0 to p - 1 do */
|
||||
for (i = 0; i < p; i++) {
|
||||
@@ -341,7 +349,11 @@ crypto_scrypt(const uint8_t * passwd, size_t passwdlen,
|
||||
}
|
||||
|
||||
/* 5: DK <-- PBKDF2(P, B, 1, dkLen) */
|
||||
+#ifdef USE_OPENSSL_PBKDF2
|
||||
+ PKCS5_PBKDF2_HMAC((const char *)passwd, passwdlen, B, p * 128 * r, 1, EVP_sha256(), buflen, buf);
|
||||
+#else
|
||||
PBKDF2_SHA256(passwd, passwdlen, B, p * 128 * r, 1, buf, buflen);
|
||||
+#endif
|
||||
|
||||
/* Free memory. */
|
||||
#ifdef MAP_ANON
|
||||
@@ -0,0 +1,94 @@
|
||||
CONFIGURE_ARGS="\
|
||||
\
|
||||
"
|
||||
|
||||
# unneeded directories
|
||||
UNNEEDED_SOURCES="\
|
||||
lib/scryptenc \
|
||||
"
|
||||
|
||||
# unneeded files
|
||||
UNNEEDED_SOURCES+="\
|
||||
config.h.in \
|
||||
configure \
|
||||
FORMAT \
|
||||
main.c \
|
||||
Makefile.in \
|
||||
scrypt.1 \
|
||||
lib/crypto/crypto_aesctr.c \
|
||||
lib/crypto/crypto_aesctr.h \
|
||||
lib/crypto/crypto_scrypt-nosse.c \
|
||||
lib/crypto/sha256.c \
|
||||
lib/crypto/sha256.h \
|
||||
lib/util/memlimit.c \
|
||||
lib/util/memlimit.h \
|
||||
lib/util/readpass.c \
|
||||
lib/util/readpass.h \
|
||||
lib/util/warn.c \
|
||||
lib/util/warn.h \
|
||||
"
|
||||
|
||||
NEEDED_SOURCES="\
|
||||
config.h \
|
||||
lib \
|
||||
scrypt_platform.h \
|
||||
"
|
||||
|
||||
SCRYPT_INCLUDES="\
|
||||
lib/crypto \
|
||||
lib/util \
|
||||
"
|
||||
|
||||
SCRYPT_SOURCES="\
|
||||
lib/crypto/crypto_scrypt-ref.c \
|
||||
"
|
||||
|
||||
SCRYPT_SOURCES_arm="\
|
||||
"
|
||||
|
||||
SCRYPT_SOURCES_EXCLUDES_arm="\
|
||||
"
|
||||
|
||||
SCRYPT_SOURCES_arm_neon="\
|
||||
lib/crypto/crypto_scrypt-neon.c \
|
||||
"
|
||||
|
||||
SCRYPT_SOURCES_EXCLUDES_arm_neon="\
|
||||
lib/crypto/crypto_scrypt-ref.c \
|
||||
"
|
||||
|
||||
SCRYPT_SOURCES_mips="\
|
||||
"
|
||||
|
||||
SCRYPT_SOURCES_EXCLUDES_mips="\
|
||||
"
|
||||
|
||||
SCRYPT_SOURCES_x86="\
|
||||
lib/crypto/crypto_scrypt-sse.c \
|
||||
"
|
||||
|
||||
SCRYPT_SOURCES_EXCLUDES_x86="\
|
||||
lib/crypto/crypto_scrypt-ref.c \
|
||||
"
|
||||
|
||||
SCRYPT_SOURCES_x86_64="\
|
||||
lib/crypto/crypto_scrypt-sse.c \
|
||||
"
|
||||
|
||||
SCRYPT_SOURCES_EXCLUDES_x86_64="\
|
||||
lib/crypto/crypto_scrypt-ref.c \
|
||||
"
|
||||
|
||||
SCRYPT_PATCHES="\
|
||||
use_openssl_pbkdf2.patch \
|
||||
arm-neon.patch \
|
||||
"
|
||||
|
||||
SCRYPT_PATCHES_use_openssl_pbkdf2_SOURCES="\
|
||||
lib/crypto/crypto_scrypt-ref.c \
|
||||
"
|
||||
|
||||
SCRYPT_PATCHES_bionic_SOURCES="\
|
||||
lib/crypto/crypto_scrypt-neon.c \
|
||||
lib/crypto/crypto_scrypt-neon-salsa208.h \
|
||||
"
|
||||
@@ -0,0 +1 @@
|
||||
SCRYPT_VERSION=1.1.6
|
||||
@@ -0,0 +1,12 @@
|
||||
#ifndef _SCRYPT_PLATFORM_H_
|
||||
#define _SCRYPT_PLATFORM_H_
|
||||
|
||||
#if defined(CONFIG_H_FILE)
|
||||
#include CONFIG_H_FILE
|
||||
#elif defined(HAVE_CONFIG_H)
|
||||
#include "config.h"
|
||||
#else
|
||||
#error Need either CONFIG_H_FILE or HAVE_CONFIG_H defined.
|
||||
#endif
|
||||
|
||||
#endif /* !_SCRYPT_PLATFORM_H_ */
|
||||
@@ -0,0 +1,82 @@
|
||||
// Auto-generated - DO NOT EDIT!
|
||||
// To regenerate, edit scrypt.config, then run:
|
||||
// ./import_scrypt.sh import /path/to/scrypt-1.1.6.tar.gz
|
||||
//
|
||||
|
||||
//
|
||||
// Copyright (C) 2017 The Android Open Source Project
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
//
|
||||
|
||||
cc_defaults {
|
||||
name: "libscrypttwrp_sources",
|
||||
|
||||
cflags: [
|
||||
"-DHAVE_CONFIG_H",
|
||||
"-DUSE_OPENSSL_PBKDF2",
|
||||
"-Wall",
|
||||
"-Werror",
|
||||
"-Wno-implicit-function-declaration",
|
||||
"-Wno-unused-variable",
|
||||
],
|
||||
|
||||
export_include_dirs: [
|
||||
"lib/crypto",
|
||||
],
|
||||
|
||||
local_include_dirs: [
|
||||
"lib/util",
|
||||
],
|
||||
|
||||
srcs: [
|
||||
"lib/crypto/crypto_scrypt-ref.c",
|
||||
],
|
||||
|
||||
arch: {
|
||||
arm: {
|
||||
neon: {
|
||||
srcs: [
|
||||
"lib/crypto/crypto_scrypt-neon.c",
|
||||
],
|
||||
exclude_srcs: [
|
||||
"lib/crypto/crypto_scrypt-ref.c",
|
||||
],
|
||||
},
|
||||
},
|
||||
arm64: {
|
||||
srcs: [
|
||||
"lib/crypto/crypto_scrypt-neon.c",
|
||||
],
|
||||
exclude_srcs: [
|
||||
"lib/crypto/crypto_scrypt-ref.c",
|
||||
],
|
||||
},
|
||||
x86: {
|
||||
srcs: [
|
||||
"lib/crypto/crypto_scrypt-sse.c",
|
||||
],
|
||||
exclude_srcs: [
|
||||
"lib/crypto/crypto_scrypt-ref.c",
|
||||
],
|
||||
},
|
||||
x86_64: {
|
||||
srcs: [
|
||||
"lib/crypto/crypto_scrypt-sse.c",
|
||||
],
|
||||
exclude_srcs: [
|
||||
"lib/crypto/crypto_scrypt-ref.c",
|
||||
],
|
||||
},
|
||||
},
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
# Build the scrypt unit tests
|
||||
|
||||
LOCAL_PATH:= $(call my-dir)
|
||||
include $(CLEAR_VARS)
|
||||
|
||||
LOCAL_ADDITIONAL_DEPENDENCIES := $(LOCAL_PATH)/Android.mk
|
||||
|
||||
LOCAL_SRC_FILES:= \
|
||||
scrypt_test.cpp
|
||||
|
||||
LOCAL_C_INCLUDES := $(LOCAL_PATH)/../lib/crypto
|
||||
|
||||
LOCAL_SHARED_LIBRARIES := \
|
||||
libcrypto
|
||||
|
||||
LOCAL_STATIC_LIBRARIES := \
|
||||
libscrypt_static \
|
||||
libgtest \
|
||||
libgtest_main
|
||||
|
||||
LOCAL_MODULE_TAGS := optional
|
||||
LOCAL_MODULE := scrypttwrp_test
|
||||
|
||||
include $(BUILD_NATIVE_TEST)
|
||||
@@ -0,0 +1,78 @@
|
||||
/*
|
||||
* Copyright (C) 2013 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#define LOG_TAG "scrypt_test"
|
||||
#include <nativehelper/UniquePtr.h>
|
||||
#include <utils/Log.h>
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
|
||||
extern "C" {
|
||||
#include <crypto_scrypt.h>
|
||||
}
|
||||
|
||||
namespace android {
|
||||
|
||||
typedef struct scrypt_test_setting_t {
|
||||
const char *pw, *salt;
|
||||
uint32_t Nfactor, rfactor, pfactor;
|
||||
} scrypt_test_setting;
|
||||
|
||||
static const scrypt_test_setting post_settings[] = {
|
||||
{"", "", 16, 1, 1},
|
||||
{"password", "NaCl", 1024, 8, 16},
|
||||
{"pleaseletmein", "SodiumChloride", 16384, 8, 1},
|
||||
{0, 0, 0, 0, 0}
|
||||
};
|
||||
|
||||
static const uint8_t post_vectors[][64] = {
|
||||
{0x77,0xd6,0x57,0x62,0x38,0x65,0x7b,0x20,0x3b,0x19,0xca,0x42,0xc1,0x8a,0x04,0x97,
|
||||
0xf1,0x6b,0x48,0x44,0xe3,0x07,0x4a,0xe8,0xdf,0xdf,0xfa,0x3f,0xed,0xe2,0x14,0x42,
|
||||
0xfc,0xd0,0x06,0x9d,0xed,0x09,0x48,0xf8,0x32,0x6a,0x75,0x3a,0x0f,0xc8,0x1f,0x17,
|
||||
0xe8,0xd3,0xe0,0xfb,0x2e,0x0d,0x36,0x28,0xcf,0x35,0xe2,0x0c,0x38,0xd1,0x89,0x06},
|
||||
{0xfd,0xba,0xbe,0x1c,0x9d,0x34,0x72,0x00,0x78,0x56,0xe7,0x19,0x0d,0x01,0xe9,0xfe,
|
||||
0x7c,0x6a,0xd7,0xcb,0xc8,0x23,0x78,0x30,0xe7,0x73,0x76,0x63,0x4b,0x37,0x31,0x62,
|
||||
0x2e,0xaf,0x30,0xd9,0x2e,0x22,0xa3,0x88,0x6f,0xf1,0x09,0x27,0x9d,0x98,0x30,0xda,
|
||||
0xc7,0x27,0xaf,0xb9,0x4a,0x83,0xee,0x6d,0x83,0x60,0xcb,0xdf,0xa2,0xcc,0x06,0x40},
|
||||
{0x70,0x23,0xbd,0xcb,0x3a,0xfd,0x73,0x48,0x46,0x1c,0x06,0xcd,0x81,0xfd,0x38,0xeb,
|
||||
0xfd,0xa8,0xfb,0xba,0x90,0x4f,0x8e,0x3e,0xa9,0xb5,0x43,0xf6,0x54,0x5d,0xa1,0xf2,
|
||||
0xd5,0x43,0x29,0x55,0x61,0x3f,0x0f,0xcf,0x62,0xd4,0x97,0x05,0x24,0x2a,0x9a,0xf9,
|
||||
0xe6,0x1e,0x85,0xdc,0x0d,0x65,0x1e,0x40,0xdf,0xcf,0x01,0x7b,0x45,0x57,0x58,0x87},
|
||||
};
|
||||
|
||||
class ScryptTest : public ::testing::Test {
|
||||
};
|
||||
|
||||
TEST_F(ScryptTest, TestVectors) {
|
||||
int i;
|
||||
|
||||
for (i = 0; post_settings[i].pw != NULL; i++) {
|
||||
uint8_t output[64];
|
||||
|
||||
scrypt_test_setting_t s = post_settings[i];
|
||||
ASSERT_EQ(0,
|
||||
crypto_scrypt((const uint8_t*) s.pw, strlen(s.pw), (const uint8_t*) s.salt,
|
||||
strlen(s.salt), s.Nfactor, s.rfactor, s.pfactor, output, sizeof(output)))
|
||||
<< "scrypt call should succeed for " << i << "; error=" << strerror(errno);
|
||||
ASSERT_EQ(0, memcmp(post_vectors[i], output, sizeof(output)))
|
||||
<< "Should match expected output";
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
ifneq ($(TARGET_SIMULATOR),true)
|
||||
LOCAL_PATH:= $(call my-dir)
|
||||
|
||||
include $(CLEAR_VARS)
|
||||
LOCAL_SRC_FILES := \
|
||||
src/boot.c \
|
||||
src/check.c \
|
||||
src/common.c \
|
||||
src/fat.c \
|
||||
src/file.c \
|
||||
src/io.c \
|
||||
src/lfn.c \
|
||||
src/fsck.fat.c
|
||||
|
||||
LOCAL_SHARED_LIBRARIES := libc
|
||||
LOCAL_CFLAGS += -D_USING_BIONIC_
|
||||
LOCAL_CFLAGS += -DUSE_ANDROID_RETVALS
|
||||
LOCAL_CFLAGS += -Wno-sign-compare
|
||||
LOCAL_MODULE = fsck.fat
|
||||
LOCAL_MODULE_TAGS := optional
|
||||
LOCAL_MODULE_CLASS := RECOVERY_EXECUTABLES
|
||||
LOCAL_MODULE_PATH := $(TARGET_RECOVERY_ROOT_OUT)/system/bin
|
||||
include $(BUILD_EXECUTABLE)
|
||||
|
||||
include $(CLEAR_VARS)
|
||||
LOCAL_SRC_FILES := \
|
||||
src/boot.c \
|
||||
src/check.c \
|
||||
src/common.c \
|
||||
src/fat.c \
|
||||
src/file.c \
|
||||
src/io.c \
|
||||
src/lfn.c \
|
||||
src/fatlabel.c
|
||||
|
||||
LOCAL_C_INCLUDES += bionic/libc/kernel/common
|
||||
LOCAL_SHARED_LIBRARIES := libc
|
||||
LOCAL_CFLAGS += -D_USING_BIONIC_
|
||||
LOCAL_CFLAGS += -Wno-sign-compare
|
||||
LOCAL_MODULE = fatlabel
|
||||
LOCAL_MODULE_TAGS := optional
|
||||
LOCAL_MODULE_CLASS := RECOVERY_EXECUTABLES
|
||||
LOCAL_MODULE_PATH := $(TARGET_RECOVERY_ROOT_OUT)/system/bin
|
||||
include $(BUILD_EXECUTABLE)
|
||||
|
||||
include $(CLEAR_VARS)
|
||||
LOCAL_SRC_FILES := src/mkfs.fat.c
|
||||
|
||||
LOCAL_SHARED_LIBRARIES := libc
|
||||
LOCAL_CFLAGS += -D_USING_BIONIC_
|
||||
LOCAL_CFLAGS += -Wno-sign-compare
|
||||
LOCAL_MODULE = mkfs.fat
|
||||
LOCAL_MODULE_TAGS := optional
|
||||
LOCAL_MODULE_CLASS := RECOVERY_EXECUTABLES
|
||||
LOCAL_MODULE_PATH := $(TARGET_RECOVERY_ROOT_OUT)/system/bin
|
||||
include $(BUILD_EXECUTABLE)
|
||||
|
||||
endif
|
||||
@@ -0,0 +1,674 @@
|
||||
GNU GENERAL PUBLIC LICENSE
|
||||
Version 3, 29 June 2007
|
||||
|
||||
Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
|
||||
Everyone is permitted to copy and distribute verbatim copies
|
||||
of this license document, but changing it is not allowed.
|
||||
|
||||
Preamble
|
||||
|
||||
The GNU General Public License is a free, copyleft license for
|
||||
software and other kinds of works.
|
||||
|
||||
The licenses for most software and other practical works are designed
|
||||
to take away your freedom to share and change the works. By contrast,
|
||||
the GNU General Public License is intended to guarantee your freedom to
|
||||
share and change all versions of a program--to make sure it remains free
|
||||
software for all its users. We, the Free Software Foundation, use the
|
||||
GNU General Public License for most of our software; it applies also to
|
||||
any other work released this way by its authors. You can apply it to
|
||||
your programs, too.
|
||||
|
||||
When we speak of free software, we are referring to freedom, not
|
||||
price. Our General Public Licenses are designed to make sure that you
|
||||
have the freedom to distribute copies of free software (and charge for
|
||||
them if you wish), that you receive source code or can get it if you
|
||||
want it, that you can change the software or use pieces of it in new
|
||||
free programs, and that you know you can do these things.
|
||||
|
||||
To protect your rights, we need to prevent others from denying you
|
||||
these rights or asking you to surrender the rights. Therefore, you have
|
||||
certain responsibilities if you distribute copies of the software, or if
|
||||
you modify it: responsibilities to respect the freedom of others.
|
||||
|
||||
For example, if you distribute copies of such a program, whether
|
||||
gratis or for a fee, you must pass on to the recipients the same
|
||||
freedoms that you received. You must make sure that they, too, receive
|
||||
or can get the source code. And you must show them these terms so they
|
||||
know their rights.
|
||||
|
||||
Developers that use the GNU GPL protect your rights with two steps:
|
||||
(1) assert copyright on the software, and (2) offer you this License
|
||||
giving you legal permission to copy, distribute and/or modify it.
|
||||
|
||||
For the developers' and authors' protection, the GPL clearly explains
|
||||
that there is no warranty for this free software. For both users' and
|
||||
authors' sake, the GPL requires that modified versions be marked as
|
||||
changed, so that their problems will not be attributed erroneously to
|
||||
authors of previous versions.
|
||||
|
||||
Some devices are designed to deny users access to install or run
|
||||
modified versions of the software inside them, although the manufacturer
|
||||
can do so. This is fundamentally incompatible with the aim of
|
||||
protecting users' freedom to change the software. The systematic
|
||||
pattern of such abuse occurs in the area of products for individuals to
|
||||
use, which is precisely where it is most unacceptable. Therefore, we
|
||||
have designed this version of the GPL to prohibit the practice for those
|
||||
products. If such problems arise substantially in other domains, we
|
||||
stand ready to extend this provision to those domains in future versions
|
||||
of the GPL, as needed to protect the freedom of users.
|
||||
|
||||
Finally, every program is threatened constantly by software patents.
|
||||
States should not allow patents to restrict development and use of
|
||||
software on general-purpose computers, but in those that do, we wish to
|
||||
avoid the special danger that patents applied to a free program could
|
||||
make it effectively proprietary. To prevent this, the GPL assures that
|
||||
patents cannot be used to render the program non-free.
|
||||
|
||||
The precise terms and conditions for copying, distribution and
|
||||
modification follow.
|
||||
|
||||
TERMS AND CONDITIONS
|
||||
|
||||
0. Definitions.
|
||||
|
||||
"This License" refers to version 3 of the GNU General Public License.
|
||||
|
||||
"Copyright" also means copyright-like laws that apply to other kinds of
|
||||
works, such as semiconductor masks.
|
||||
|
||||
"The Program" refers to any copyrightable work licensed under this
|
||||
License. Each licensee is addressed as "you". "Licensees" and
|
||||
"recipients" may be individuals or organizations.
|
||||
|
||||
To "modify" a work means to copy from or adapt all or part of the work
|
||||
in a fashion requiring copyright permission, other than the making of an
|
||||
exact copy. The resulting work is called a "modified version" of the
|
||||
earlier work or a work "based on" the earlier work.
|
||||
|
||||
A "covered work" means either the unmodified Program or a work based
|
||||
on the Program.
|
||||
|
||||
To "propagate" a work means to do anything with it that, without
|
||||
permission, would make you directly or secondarily liable for
|
||||
infringement under applicable copyright law, except executing it on a
|
||||
computer or modifying a private copy. Propagation includes copying,
|
||||
distribution (with or without modification), making available to the
|
||||
public, and in some countries other activities as well.
|
||||
|
||||
To "convey" a work means any kind of propagation that enables other
|
||||
parties to make or receive copies. Mere interaction with a user through
|
||||
a computer network, with no transfer of a copy, is not conveying.
|
||||
|
||||
An interactive user interface displays "Appropriate Legal Notices"
|
||||
to the extent that it includes a convenient and prominently visible
|
||||
feature that (1) displays an appropriate copyright notice, and (2)
|
||||
tells the user that there is no warranty for the work (except to the
|
||||
extent that warranties are provided), that licensees may convey the
|
||||
work under this License, and how to view a copy of this License. If
|
||||
the interface presents a list of user commands or options, such as a
|
||||
menu, a prominent item in the list meets this criterion.
|
||||
|
||||
1. Source Code.
|
||||
|
||||
The "source code" for a work means the preferred form of the work
|
||||
for making modifications to it. "Object code" means any non-source
|
||||
form of a work.
|
||||
|
||||
A "Standard Interface" means an interface that either is an official
|
||||
standard defined by a recognized standards body, or, in the case of
|
||||
interfaces specified for a particular programming language, one that
|
||||
is widely used among developers working in that language.
|
||||
|
||||
The "System Libraries" of an executable work include anything, other
|
||||
than the work as a whole, that (a) is included in the normal form of
|
||||
packaging a Major Component, but which is not part of that Major
|
||||
Component, and (b) serves only to enable use of the work with that
|
||||
Major Component, or to implement a Standard Interface for which an
|
||||
implementation is available to the public in source code form. A
|
||||
"Major Component", in this context, means a major essential component
|
||||
(kernel, window system, and so on) of the specific operating system
|
||||
(if any) on which the executable work runs, or a compiler used to
|
||||
produce the work, or an object code interpreter used to run it.
|
||||
|
||||
The "Corresponding Source" for a work in object code form means all
|
||||
the source code needed to generate, install, and (for an executable
|
||||
work) run the object code and to modify the work, including scripts to
|
||||
control those activities. However, it does not include the work's
|
||||
System Libraries, or general-purpose tools or generally available free
|
||||
programs which are used unmodified in performing those activities but
|
||||
which are not part of the work. For example, Corresponding Source
|
||||
includes interface definition files associated with source files for
|
||||
the work, and the source code for shared libraries and dynamically
|
||||
linked subprograms that the work is specifically designed to require,
|
||||
such as by intimate data communication or control flow between those
|
||||
subprograms and other parts of the work.
|
||||
|
||||
The Corresponding Source need not include anything that users
|
||||
can regenerate automatically from other parts of the Corresponding
|
||||
Source.
|
||||
|
||||
The Corresponding Source for a work in source code form is that
|
||||
same work.
|
||||
|
||||
2. Basic Permissions.
|
||||
|
||||
All rights granted under this License are granted for the term of
|
||||
copyright on the Program, and are irrevocable provided the stated
|
||||
conditions are met. This License explicitly affirms your unlimited
|
||||
permission to run the unmodified Program. The output from running a
|
||||
covered work is covered by this License only if the output, given its
|
||||
content, constitutes a covered work. This License acknowledges your
|
||||
rights of fair use or other equivalent, as provided by copyright law.
|
||||
|
||||
You may make, run and propagate covered works that you do not
|
||||
convey, without conditions so long as your license otherwise remains
|
||||
in force. You may convey covered works to others for the sole purpose
|
||||
of having them make modifications exclusively for you, or provide you
|
||||
with facilities for running those works, provided that you comply with
|
||||
the terms of this License in conveying all material for which you do
|
||||
not control copyright. Those thus making or running the covered works
|
||||
for you must do so exclusively on your behalf, under your direction
|
||||
and control, on terms that prohibit them from making any copies of
|
||||
your copyrighted material outside their relationship with you.
|
||||
|
||||
Conveying under any other circumstances is permitted solely under
|
||||
the conditions stated below. Sublicensing is not allowed; section 10
|
||||
makes it unnecessary.
|
||||
|
||||
3. Protecting Users' Legal Rights From Anti-Circumvention Law.
|
||||
|
||||
No covered work shall be deemed part of an effective technological
|
||||
measure under any applicable law fulfilling obligations under article
|
||||
11 of the WIPO copyright treaty adopted on 20 December 1996, or
|
||||
similar laws prohibiting or restricting circumvention of such
|
||||
measures.
|
||||
|
||||
When you convey a covered work, you waive any legal power to forbid
|
||||
circumvention of technological measures to the extent such circumvention
|
||||
is effected by exercising rights under this License with respect to
|
||||
the covered work, and you disclaim any intention to limit operation or
|
||||
modification of the work as a means of enforcing, against the work's
|
||||
users, your or third parties' legal rights to forbid circumvention of
|
||||
technological measures.
|
||||
|
||||
4. Conveying Verbatim Copies.
|
||||
|
||||
You may convey verbatim copies of the Program's source code as you
|
||||
receive it, in any medium, provided that you conspicuously and
|
||||
appropriately publish on each copy an appropriate copyright notice;
|
||||
keep intact all notices stating that this License and any
|
||||
non-permissive terms added in accord with section 7 apply to the code;
|
||||
keep intact all notices of the absence of any warranty; and give all
|
||||
recipients a copy of this License along with the Program.
|
||||
|
||||
You may charge any price or no price for each copy that you convey,
|
||||
and you may offer support or warranty protection for a fee.
|
||||
|
||||
5. Conveying Modified Source Versions.
|
||||
|
||||
You may convey a work based on the Program, or the modifications to
|
||||
produce it from the Program, in the form of source code under the
|
||||
terms of section 4, provided that you also meet all of these conditions:
|
||||
|
||||
a) The work must carry prominent notices stating that you modified
|
||||
it, and giving a relevant date.
|
||||
|
||||
b) The work must carry prominent notices stating that it is
|
||||
released under this License and any conditions added under section
|
||||
7. This requirement modifies the requirement in section 4 to
|
||||
"keep intact all notices".
|
||||
|
||||
c) You must license the entire work, as a whole, under this
|
||||
License to anyone who comes into possession of a copy. This
|
||||
License will therefore apply, along with any applicable section 7
|
||||
additional terms, to the whole of the work, and all its parts,
|
||||
regardless of how they are packaged. This License gives no
|
||||
permission to license the work in any other way, but it does not
|
||||
invalidate such permission if you have separately received it.
|
||||
|
||||
d) If the work has interactive user interfaces, each must display
|
||||
Appropriate Legal Notices; however, if the Program has interactive
|
||||
interfaces that do not display Appropriate Legal Notices, your
|
||||
work need not make them do so.
|
||||
|
||||
A compilation of a covered work with other separate and independent
|
||||
works, which are not by their nature extensions of the covered work,
|
||||
and which are not combined with it such as to form a larger program,
|
||||
in or on a volume of a storage or distribution medium, is called an
|
||||
"aggregate" if the compilation and its resulting copyright are not
|
||||
used to limit the access or legal rights of the compilation's users
|
||||
beyond what the individual works permit. Inclusion of a covered work
|
||||
in an aggregate does not cause this License to apply to the other
|
||||
parts of the aggregate.
|
||||
|
||||
6. Conveying Non-Source Forms.
|
||||
|
||||
You may convey a covered work in object code form under the terms
|
||||
of sections 4 and 5, provided that you also convey the
|
||||
machine-readable Corresponding Source under the terms of this License,
|
||||
in one of these ways:
|
||||
|
||||
a) Convey the object code in, or embodied in, a physical product
|
||||
(including a physical distribution medium), accompanied by the
|
||||
Corresponding Source fixed on a durable physical medium
|
||||
customarily used for software interchange.
|
||||
|
||||
b) Convey the object code in, or embodied in, a physical product
|
||||
(including a physical distribution medium), accompanied by a
|
||||
written offer, valid for at least three years and valid for as
|
||||
long as you offer spare parts or customer support for that product
|
||||
model, to give anyone who possesses the object code either (1) a
|
||||
copy of the Corresponding Source for all the software in the
|
||||
product that is covered by this License, on a durable physical
|
||||
medium customarily used for software interchange, for a price no
|
||||
more than your reasonable cost of physically performing this
|
||||
conveying of source, or (2) access to copy the
|
||||
Corresponding Source from a network server at no charge.
|
||||
|
||||
c) Convey individual copies of the object code with a copy of the
|
||||
written offer to provide the Corresponding Source. This
|
||||
alternative is allowed only occasionally and noncommercially, and
|
||||
only if you received the object code with such an offer, in accord
|
||||
with subsection 6b.
|
||||
|
||||
d) Convey the object code by offering access from a designated
|
||||
place (gratis or for a charge), and offer equivalent access to the
|
||||
Corresponding Source in the same way through the same place at no
|
||||
further charge. You need not require recipients to copy the
|
||||
Corresponding Source along with the object code. If the place to
|
||||
copy the object code is a network server, the Corresponding Source
|
||||
may be on a different server (operated by you or a third party)
|
||||
that supports equivalent copying facilities, provided you maintain
|
||||
clear directions next to the object code saying where to find the
|
||||
Corresponding Source. Regardless of what server hosts the
|
||||
Corresponding Source, you remain obligated to ensure that it is
|
||||
available for as long as needed to satisfy these requirements.
|
||||
|
||||
e) Convey the object code using peer-to-peer transmission, provided
|
||||
you inform other peers where the object code and Corresponding
|
||||
Source of the work are being offered to the general public at no
|
||||
charge under subsection 6d.
|
||||
|
||||
A separable portion of the object code, whose source code is excluded
|
||||
from the Corresponding Source as a System Library, need not be
|
||||
included in conveying the object code work.
|
||||
|
||||
A "User Product" is either (1) a "consumer product", which means any
|
||||
tangible personal property which is normally used for personal, family,
|
||||
or household purposes, or (2) anything designed or sold for incorporation
|
||||
into a dwelling. In determining whether a product is a consumer product,
|
||||
doubtful cases shall be resolved in favor of coverage. For a particular
|
||||
product received by a particular user, "normally used" refers to a
|
||||
typical or common use of that class of product, regardless of the status
|
||||
of the particular user or of the way in which the particular user
|
||||
actually uses, or expects or is expected to use, the product. A product
|
||||
is a consumer product regardless of whether the product has substantial
|
||||
commercial, industrial or non-consumer uses, unless such uses represent
|
||||
the only significant mode of use of the product.
|
||||
|
||||
"Installation Information" for a User Product means any methods,
|
||||
procedures, authorization keys, or other information required to install
|
||||
and execute modified versions of a covered work in that User Product from
|
||||
a modified version of its Corresponding Source. The information must
|
||||
suffice to ensure that the continued functioning of the modified object
|
||||
code is in no case prevented or interfered with solely because
|
||||
modification has been made.
|
||||
|
||||
If you convey an object code work under this section in, or with, or
|
||||
specifically for use in, a User Product, and the conveying occurs as
|
||||
part of a transaction in which the right of possession and use of the
|
||||
User Product is transferred to the recipient in perpetuity or for a
|
||||
fixed term (regardless of how the transaction is characterized), the
|
||||
Corresponding Source conveyed under this section must be accompanied
|
||||
by the Installation Information. But this requirement does not apply
|
||||
if neither you nor any third party retains the ability to install
|
||||
modified object code on the User Product (for example, the work has
|
||||
been installed in ROM).
|
||||
|
||||
The requirement to provide Installation Information does not include a
|
||||
requirement to continue to provide support service, warranty, or updates
|
||||
for a work that has been modified or installed by the recipient, or for
|
||||
the User Product in which it has been modified or installed. Access to a
|
||||
network may be denied when the modification itself materially and
|
||||
adversely affects the operation of the network or violates the rules and
|
||||
protocols for communication across the network.
|
||||
|
||||
Corresponding Source conveyed, and Installation Information provided,
|
||||
in accord with this section must be in a format that is publicly
|
||||
documented (and with an implementation available to the public in
|
||||
source code form), and must require no special password or key for
|
||||
unpacking, reading or copying.
|
||||
|
||||
7. Additional Terms.
|
||||
|
||||
"Additional permissions" are terms that supplement the terms of this
|
||||
License by making exceptions from one or more of its conditions.
|
||||
Additional permissions that are applicable to the entire Program shall
|
||||
be treated as though they were included in this License, to the extent
|
||||
that they are valid under applicable law. If additional permissions
|
||||
apply only to part of the Program, that part may be used separately
|
||||
under those permissions, but the entire Program remains governed by
|
||||
this License without regard to the additional permissions.
|
||||
|
||||
When you convey a copy of a covered work, you may at your option
|
||||
remove any additional permissions from that copy, or from any part of
|
||||
it. (Additional permissions may be written to require their own
|
||||
removal in certain cases when you modify the work.) You may place
|
||||
additional permissions on material, added by you to a covered work,
|
||||
for which you have or can give appropriate copyright permission.
|
||||
|
||||
Notwithstanding any other provision of this License, for material you
|
||||
add to a covered work, you may (if authorized by the copyright holders of
|
||||
that material) supplement the terms of this License with terms:
|
||||
|
||||
a) Disclaiming warranty or limiting liability differently from the
|
||||
terms of sections 15 and 16 of this License; or
|
||||
|
||||
b) Requiring preservation of specified reasonable legal notices or
|
||||
author attributions in that material or in the Appropriate Legal
|
||||
Notices displayed by works containing it; or
|
||||
|
||||
c) Prohibiting misrepresentation of the origin of that material, or
|
||||
requiring that modified versions of such material be marked in
|
||||
reasonable ways as different from the original version; or
|
||||
|
||||
d) Limiting the use for publicity purposes of names of licensors or
|
||||
authors of the material; or
|
||||
|
||||
e) Declining to grant rights under trademark law for use of some
|
||||
trade names, trademarks, or service marks; or
|
||||
|
||||
f) Requiring indemnification of licensors and authors of that
|
||||
material by anyone who conveys the material (or modified versions of
|
||||
it) with contractual assumptions of liability to the recipient, for
|
||||
any liability that these contractual assumptions directly impose on
|
||||
those licensors and authors.
|
||||
|
||||
All other non-permissive additional terms are considered "further
|
||||
restrictions" within the meaning of section 10. If the Program as you
|
||||
received it, or any part of it, contains a notice stating that it is
|
||||
governed by this License along with a term that is a further
|
||||
restriction, you may remove that term. If a license document contains
|
||||
a further restriction but permits relicensing or conveying under this
|
||||
License, you may add to a covered work material governed by the terms
|
||||
of that license document, provided that the further restriction does
|
||||
not survive such relicensing or conveying.
|
||||
|
||||
If you add terms to a covered work in accord with this section, you
|
||||
must place, in the relevant source files, a statement of the
|
||||
additional terms that apply to those files, or a notice indicating
|
||||
where to find the applicable terms.
|
||||
|
||||
Additional terms, permissive or non-permissive, may be stated in the
|
||||
form of a separately written license, or stated as exceptions;
|
||||
the above requirements apply either way.
|
||||
|
||||
8. Termination.
|
||||
|
||||
You may not propagate or modify a covered work except as expressly
|
||||
provided under this License. Any attempt otherwise to propagate or
|
||||
modify it is void, and will automatically terminate your rights under
|
||||
this License (including any patent licenses granted under the third
|
||||
paragraph of section 11).
|
||||
|
||||
However, if you cease all violation of this License, then your
|
||||
license from a particular copyright holder is reinstated (a)
|
||||
provisionally, unless and until the copyright holder explicitly and
|
||||
finally terminates your license, and (b) permanently, if the copyright
|
||||
holder fails to notify you of the violation by some reasonable means
|
||||
prior to 60 days after the cessation.
|
||||
|
||||
Moreover, your license from a particular copyright holder is
|
||||
reinstated permanently if the copyright holder notifies you of the
|
||||
violation by some reasonable means, this is the first time you have
|
||||
received notice of violation of this License (for any work) from that
|
||||
copyright holder, and you cure the violation prior to 30 days after
|
||||
your receipt of the notice.
|
||||
|
||||
Termination of your rights under this section does not terminate the
|
||||
licenses of parties who have received copies or rights from you under
|
||||
this License. If your rights have been terminated and not permanently
|
||||
reinstated, you do not qualify to receive new licenses for the same
|
||||
material under section 10.
|
||||
|
||||
9. Acceptance Not Required for Having Copies.
|
||||
|
||||
You are not required to accept this License in order to receive or
|
||||
run a copy of the Program. Ancillary propagation of a covered work
|
||||
occurring solely as a consequence of using peer-to-peer transmission
|
||||
to receive a copy likewise does not require acceptance. However,
|
||||
nothing other than this License grants you permission to propagate or
|
||||
modify any covered work. These actions infringe copyright if you do
|
||||
not accept this License. Therefore, by modifying or propagating a
|
||||
covered work, you indicate your acceptance of this License to do so.
|
||||
|
||||
10. Automatic Licensing of Downstream Recipients.
|
||||
|
||||
Each time you convey a covered work, the recipient automatically
|
||||
receives a license from the original licensors, to run, modify and
|
||||
propagate that work, subject to this License. You are not responsible
|
||||
for enforcing compliance by third parties with this License.
|
||||
|
||||
An "entity transaction" is a transaction transferring control of an
|
||||
organization, or substantially all assets of one, or subdividing an
|
||||
organization, or merging organizations. If propagation of a covered
|
||||
work results from an entity transaction, each party to that
|
||||
transaction who receives a copy of the work also receives whatever
|
||||
licenses to the work the party's predecessor in interest had or could
|
||||
give under the previous paragraph, plus a right to possession of the
|
||||
Corresponding Source of the work from the predecessor in interest, if
|
||||
the predecessor has it or can get it with reasonable efforts.
|
||||
|
||||
You may not impose any further restrictions on the exercise of the
|
||||
rights granted or affirmed under this License. For example, you may
|
||||
not impose a license fee, royalty, or other charge for exercise of
|
||||
rights granted under this License, and you may not initiate litigation
|
||||
(including a cross-claim or counterclaim in a lawsuit) alleging that
|
||||
any patent claim is infringed by making, using, selling, offering for
|
||||
sale, or importing the Program or any portion of it.
|
||||
|
||||
11. Patents.
|
||||
|
||||
A "contributor" is a copyright holder who authorizes use under this
|
||||
License of the Program or a work on which the Program is based. The
|
||||
work thus licensed is called the contributor's "contributor version".
|
||||
|
||||
A contributor's "essential patent claims" are all patent claims
|
||||
owned or controlled by the contributor, whether already acquired or
|
||||
hereafter acquired, that would be infringed by some manner, permitted
|
||||
by this License, of making, using, or selling its contributor version,
|
||||
but do not include claims that would be infringed only as a
|
||||
consequence of further modification of the contributor version. For
|
||||
purposes of this definition, "control" includes the right to grant
|
||||
patent sublicenses in a manner consistent with the requirements of
|
||||
this License.
|
||||
|
||||
Each contributor grants you a non-exclusive, worldwide, royalty-free
|
||||
patent license under the contributor's essential patent claims, to
|
||||
make, use, sell, offer for sale, import and otherwise run, modify and
|
||||
propagate the contents of its contributor version.
|
||||
|
||||
In the following three paragraphs, a "patent license" is any express
|
||||
agreement or commitment, however denominated, not to enforce a patent
|
||||
(such as an express permission to practice a patent or covenant not to
|
||||
sue for patent infringement). To "grant" such a patent license to a
|
||||
party means to make such an agreement or commitment not to enforce a
|
||||
patent against the party.
|
||||
|
||||
If you convey a covered work, knowingly relying on a patent license,
|
||||
and the Corresponding Source of the work is not available for anyone
|
||||
to copy, free of charge and under the terms of this License, through a
|
||||
publicly available network server or other readily accessible means,
|
||||
then you must either (1) cause the Corresponding Source to be so
|
||||
available, or (2) arrange to deprive yourself of the benefit of the
|
||||
patent license for this particular work, or (3) arrange, in a manner
|
||||
consistent with the requirements of this License, to extend the patent
|
||||
license to downstream recipients. "Knowingly relying" means you have
|
||||
actual knowledge that, but for the patent license, your conveying the
|
||||
covered work in a country, or your recipient's use of the covered work
|
||||
in a country, would infringe one or more identifiable patents in that
|
||||
country that you have reason to believe are valid.
|
||||
|
||||
If, pursuant to or in connection with a single transaction or
|
||||
arrangement, you convey, or propagate by procuring conveyance of, a
|
||||
covered work, and grant a patent license to some of the parties
|
||||
receiving the covered work authorizing them to use, propagate, modify
|
||||
or convey a specific copy of the covered work, then the patent license
|
||||
you grant is automatically extended to all recipients of the covered
|
||||
work and works based on it.
|
||||
|
||||
A patent license is "discriminatory" if it does not include within
|
||||
the scope of its coverage, prohibits the exercise of, or is
|
||||
conditioned on the non-exercise of one or more of the rights that are
|
||||
specifically granted under this License. You may not convey a covered
|
||||
work if you are a party to an arrangement with a third party that is
|
||||
in the business of distributing software, under which you make payment
|
||||
to the third party based on the extent of your activity of conveying
|
||||
the work, and under which the third party grants, to any of the
|
||||
parties who would receive the covered work from you, a discriminatory
|
||||
patent license (a) in connection with copies of the covered work
|
||||
conveyed by you (or copies made from those copies), or (b) primarily
|
||||
for and in connection with specific products or compilations that
|
||||
contain the covered work, unless you entered into that arrangement,
|
||||
or that patent license was granted, prior to 28 March 2007.
|
||||
|
||||
Nothing in this License shall be construed as excluding or limiting
|
||||
any implied license or other defenses to infringement that may
|
||||
otherwise be available to you under applicable patent law.
|
||||
|
||||
12. No Surrender of Others' Freedom.
|
||||
|
||||
If conditions are imposed on you (whether by court order, agreement or
|
||||
otherwise) that contradict the conditions of this License, they do not
|
||||
excuse you from the conditions of this License. If you cannot convey a
|
||||
covered work so as to satisfy simultaneously your obligations under this
|
||||
License and any other pertinent obligations, then as a consequence you may
|
||||
not convey it at all. For example, if you agree to terms that obligate you
|
||||
to collect a royalty for further conveying from those to whom you convey
|
||||
the Program, the only way you could satisfy both those terms and this
|
||||
License would be to refrain entirely from conveying the Program.
|
||||
|
||||
13. Use with the GNU Affero General Public License.
|
||||
|
||||
Notwithstanding any other provision of this License, you have
|
||||
permission to link or combine any covered work with a work licensed
|
||||
under version 3 of the GNU Affero General Public License into a single
|
||||
combined work, and to convey the resulting work. The terms of this
|
||||
License will continue to apply to the part which is the covered work,
|
||||
but the special requirements of the GNU Affero General Public License,
|
||||
section 13, concerning interaction through a network will apply to the
|
||||
combination as such.
|
||||
|
||||
14. Revised Versions of this License.
|
||||
|
||||
The Free Software Foundation may publish revised and/or new versions of
|
||||
the GNU General Public License from time to time. Such new versions will
|
||||
be similar in spirit to the present version, but may differ in detail to
|
||||
address new problems or concerns.
|
||||
|
||||
Each version is given a distinguishing version number. If the
|
||||
Program specifies that a certain numbered version of the GNU General
|
||||
Public License "or any later version" applies to it, you have the
|
||||
option of following the terms and conditions either of that numbered
|
||||
version or of any later version published by the Free Software
|
||||
Foundation. If the Program does not specify a version number of the
|
||||
GNU General Public License, you may choose any version ever published
|
||||
by the Free Software Foundation.
|
||||
|
||||
If the Program specifies that a proxy can decide which future
|
||||
versions of the GNU General Public License can be used, that proxy's
|
||||
public statement of acceptance of a version permanently authorizes you
|
||||
to choose that version for the Program.
|
||||
|
||||
Later license versions may give you additional or different
|
||||
permissions. However, no additional obligations are imposed on any
|
||||
author or copyright holder as a result of your choosing to follow a
|
||||
later version.
|
||||
|
||||
15. Disclaimer of Warranty.
|
||||
|
||||
THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
|
||||
APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
|
||||
HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
|
||||
OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
|
||||
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
|
||||
IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
|
||||
ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
|
||||
|
||||
16. Limitation of Liability.
|
||||
|
||||
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
|
||||
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
|
||||
THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
|
||||
GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
|
||||
USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
|
||||
DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
|
||||
PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
|
||||
EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
|
||||
SUCH DAMAGES.
|
||||
|
||||
17. Interpretation of Sections 15 and 16.
|
||||
|
||||
If the disclaimer of warranty and limitation of liability provided
|
||||
above cannot be given local legal effect according to their terms,
|
||||
reviewing courts shall apply local law that most closely approximates
|
||||
an absolute waiver of all civil liability in connection with the
|
||||
Program, unless a warranty or assumption of liability accompanies a
|
||||
copy of the Program in return for a fee.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
How to Apply These Terms to Your New Programs
|
||||
|
||||
If you develop a new program, and you want it to be of the greatest
|
||||
possible use to the public, the best way to achieve this is to make it
|
||||
free software which everyone can redistribute and change under these terms.
|
||||
|
||||
To do so, attach the following notices to the program. It is safest
|
||||
to attach them to the start of each source file to most effectively
|
||||
state the exclusion of warranty; and each file should have at least
|
||||
the "copyright" line and a pointer to where the full notice is found.
|
||||
|
||||
<one line to give the program's name and a brief idea of what it does.>
|
||||
Copyright (C) <year> <name of author>
|
||||
|
||||
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 3 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, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
Also add information on how to contact you by electronic and paper mail.
|
||||
|
||||
If the program does terminal interaction, make it output a short
|
||||
notice like this when it starts in an interactive mode:
|
||||
|
||||
<program> Copyright (C) <year> <name of author>
|
||||
This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
|
||||
This is free software, and you are welcome to redistribute it
|
||||
under certain conditions; type `show c' for details.
|
||||
|
||||
The hypothetical commands `show w' and `show c' should show the appropriate
|
||||
parts of the General Public License. Of course, your program's commands
|
||||
might be different; for a GUI interface, you would use an "about box".
|
||||
|
||||
You should also get your employer (if you work as a programmer) or school,
|
||||
if any, to sign a "copyright disclaimer" for the program, if necessary.
|
||||
For more information on this, and how to apply and follow the GNU GPL, see
|
||||
<http://www.gnu.org/licenses/>.
|
||||
|
||||
The GNU General Public License does not permit incorporating your program
|
||||
into proprietary programs. If your program is a subroutine library, you
|
||||
may consider it more useful to permit linking proprietary applications with
|
||||
the library. If this is what you want to do, use the GNU Lesser General
|
||||
Public License instead of this License. But first, please read
|
||||
<http://www.gnu.org/philosophy/why-not-lgpl.html>.
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,170 @@
|
||||
# Makefile
|
||||
#
|
||||
# Copyright (C) 2008-2014 Daniel Baumann <mail@daniel-baumann.ch>
|
||||
#
|
||||
# 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 3 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, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
# The complete text of the GNU General Public License
|
||||
# can be found in /usr/share/common-licenses/GPL-3 file.
|
||||
|
||||
SHELL := sh -e
|
||||
LANGUAGES = $(shell cd manpages/po && ls)
|
||||
|
||||
DESTDIR =
|
||||
PREFIX = /usr/local
|
||||
SBINDIR = $(PREFIX)/sbin
|
||||
DOCDIR = $(PREFIX)/share/doc
|
||||
MANDIR = $(PREFIX)/share/man
|
||||
|
||||
#OPTFLAGS = -O2 -fomit-frame-pointer -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64
|
||||
OPTFLAGS = -O2 -fomit-frame-pointer -D_GNU_SOURCE $(shell getconf LFS_CFLAGS)
|
||||
#WARNFLAGS = -Wall -pedantic -std=c99
|
||||
WARNFLAGS = -Wall -Wextra -Wno-sign-compare -Wno-missing-field-initializers -Wmissing-prototypes -Wstrict-prototypes -Wwrite-strings
|
||||
DEBUGFLAGS = -g
|
||||
CFLAGS += $(OPTFLAGS) $(WARNFLAGS) $(DEBUGFLAGS)
|
||||
|
||||
VPATH = src
|
||||
|
||||
all: build
|
||||
|
||||
build: fatlabel fsck.fat mkfs.fat
|
||||
|
||||
fatlabel: boot.o check.o common.o fat.o file.o io.o lfn.o fatlabel.o
|
||||
|
||||
fsck.fat: boot.o check.o common.o fat.o file.o io.o lfn.o fsck.fat.o
|
||||
|
||||
mkfs.fat: mkfs.fat.o
|
||||
|
||||
rebuild: distclean build
|
||||
|
||||
install: install-bin install-doc install-man install-symlinks
|
||||
|
||||
install-bin: build
|
||||
install -d -m 0755 $(DESTDIR)/$(SBINDIR)
|
||||
install -m 0755 fatlabel fsck.fat mkfs.fat $(DESTDIR)/$(SBINDIR)
|
||||
|
||||
install-doc:
|
||||
install -d -m 0755 $(DESTDIR)/$(DOCDIR)/dosfstools
|
||||
install -p -m 0644 ChangeLog doc/* $(DESTDIR)/$(DOCDIR)/dosfstools
|
||||
|
||||
install-man:
|
||||
for MANPAGE in manpages/en/*; \
|
||||
do \
|
||||
SECTION="8"; \
|
||||
mkdir -p $(DESTDIR)/$(MANDIR)/man$${SECTION}/; \
|
||||
install -m 0644 $${MANPAGE} $(DESTDIR)/$(MANDIR)/man$${SECTION}/$$(basename $${MANPAGE}); \
|
||||
done
|
||||
|
||||
for LANGUAGE in $(LANGUAGES); \
|
||||
do \
|
||||
for MANPAGE in manpages/$${LANGUAGE}/*; \
|
||||
do \
|
||||
SECTION="8"; \
|
||||
mkdir -p $(DESTDIR)/$(MANDIR)/$${LANGUAGE}/man$${SECTION}/; \
|
||||
install -m 0644 $${MANPAGE} $(DESTDIR)/$(MANDIR)/$${LANGUAGE}/man$${SECTION}/$$(basename $${MANPAGE} .$${LANGUAGE}.$${SECTION}).$${SECTION}; \
|
||||
done; \
|
||||
done
|
||||
install-symlinks: install-bin install-man
|
||||
if [ -e $(DESTDIR)/$(SBINDIR)/fatlabel ]; \
|
||||
then \
|
||||
ln -sf fatlabel $(DESTDIR)/$(SBINDIR)/dosfslabel; \
|
||||
if [ -e $(DESTDIR)/$(MANDIR)/man8/fatlabel.8 ]; \
|
||||
then \
|
||||
ln -sf fatlabel.8 $(DESTDIR)/$(MANDIR)/man8/dosfslabel.8; \
|
||||
fi; \
|
||||
fi
|
||||
|
||||
if [ -e $(DESTDIR)/$(SBINDIR)/fsck.fat ]; \
|
||||
then \
|
||||
ln -sf fsck.fat $(DESTDIR)/$(SBINDIR)/dosfsck; \
|
||||
ln -sf fsck.fat $(DESTDIR)/$(SBINDIR)/fsck.msdos; \
|
||||
ln -sf fsck.fat $(DESTDIR)/$(SBINDIR)/fsck.vfat; \
|
||||
if [ -e $(DESTDIR)/$(MANDIR)/man8/fsck.fat.8 ]; \
|
||||
then \
|
||||
ln -sf fsck.fat.8 $(DESTDIR)/$(MANDIR)/man8/dosfsck.8; \
|
||||
ln -sf fsck.fat.8 $(DESTDIR)/$(MANDIR)/man8/fsck.msdos.8; \
|
||||
ln -sf fsck.fat.8 $(DESTDIR)/$(MANDIR)/man8/fsck.vfat.8; \
|
||||
fi; \
|
||||
fi
|
||||
|
||||
if [ -e $(DESTDIR)/$(SBINDIR)/mkfs.fat ]; \
|
||||
then \
|
||||
ln -sf mkfs.fat $(DESTDIR)/$(SBINDIR)/mkdosfs; \
|
||||
ln -sf mkfs.fat $(DESTDIR)/$(SBINDIR)/mkfs.msdos; \
|
||||
ln -sf mkfs.fat $(DESTDIR)/$(SBINDIR)/mkfs.vfat; \
|
||||
if [ -e $(DESTDIR)/$(MANDIR)/man8/mkfs.fat.8 ]; \
|
||||
then \
|
||||
ln -sf mkfs.fat.8 $(DESTDIR)/$(MANDIR)/man8/mkdosfs.8; \
|
||||
ln -sf mkfs.fat.8 $(DESTDIR)/$(MANDIR)/man8/mkfs.msdos.8; \
|
||||
ln -sf mkfs.fat.8 $(DESTDIR)/$(MANDIR)/man8/mkfs.vfat.8; \
|
||||
fi; \
|
||||
fi
|
||||
|
||||
uninstall: uninstall-symlinks uninstall-man uninstall-doc uninstall-bin
|
||||
|
||||
uninstall-bin:
|
||||
rm -f $(DESTDIR)/$(SBINDIR)/fatlabel
|
||||
rm -f $(DESTDIR)/$(SBINDIR)/fsck.fat
|
||||
rm -f $(DESTDIR)/$(SBINDIR)/mkfs.fat
|
||||
|
||||
rmdir --ignore-fail-on-non-empty $(DESTDIR)/$(SBINDIR)
|
||||
|
||||
uninstall-doc:
|
||||
rm -rf $(DESTDIR)/$(DOCDIR)/dosfstools
|
||||
|
||||
rmdir --ignore-fail-on-non-empty $(DESTDIR)/$(DOCDIR)
|
||||
|
||||
uninstall-man:
|
||||
for MANPAGE in manpages/en/*; \
|
||||
do \
|
||||
SECTION="8"; \
|
||||
rm -f $(DESTDIR)/$(MANDIR)/man$${SECTION}/$$(basename $${MANPAGE} .en.$${SECTION}).$${SECTION}; \
|
||||
done
|
||||
|
||||
for LANGUAGE in $(LANGUAGES); \
|
||||
do \
|
||||
for MANPAGE in manpages/$${LANGUAGE}/*; \
|
||||
do \
|
||||
SECTION="8"; \
|
||||
rm -f $(DESTDIR)/$(MANDIR)/$${LANGUAGE}/man$${SECTION}/$$(basename $${MANPAGE} .$${LANGUAGE}.$${SECTION}).$${SECTION}; \
|
||||
done; \
|
||||
done
|
||||
|
||||
uninstall-symlinks:
|
||||
rm -f $(DESTDIR)/$(SBINDIR)/dosfslabel
|
||||
rm -f $(DESTDIR)/$(MANDIR)/man8/dosfslabel.8
|
||||
|
||||
rm -f $(DESTDIR)/$(SBINDIR)/dosfsck
|
||||
rm -f $(DESTDIR)/$(MANDIR)/man8/dosfsck.8
|
||||
rm -f $(DESTDIR)/$(SBINDIR)/fsck.msdos
|
||||
rm -f $(DESTDIR)/$(MANDIR)/man8/fsck.msdos.8
|
||||
rm -f $(DESTDIR)/$(SBINDIR)/fsck.vfat
|
||||
rm -f $(DESTDIR)/$(MANDIR)/man8/fsck.vfat.8
|
||||
|
||||
rm -f $(DESTDIR)/$(SBINDIR)/mkdosfs
|
||||
rm -f $(DESTDIR)/$(MANDIR)/man8/mkdosfs.8
|
||||
rm -f $(DESTDIR)/$(SBINDIR)/mkfs.msdos
|
||||
rm -f $(DESTDIR)/$(MANDIR)/man8/mkfs.msdos.8
|
||||
rm -f $(DESTDIR)/$(SBINDIR)/mkfs.vfat
|
||||
rm -f $(DESTDIR)/$(MANDIR)/man8/mkfs.vfat.8
|
||||
|
||||
reinstall: distclean install
|
||||
|
||||
clean:
|
||||
rm -f *.o
|
||||
|
||||
distclean: clean
|
||||
rm -f fatlabel fsck.fat mkfs.fat
|
||||
|
||||
.PHONY: build rebuild install install-bin install-doc install-man install-symlinks uninstall uninstall-bin uninstall-doc uninstall-man uninstall-symlinks reinstall clean distclean
|
||||
@@ -0,0 +1 @@
|
||||
3.0.28
|
||||
@@ -0,0 +1,18 @@
|
||||
#!/bin/sh
|
||||
PARAM="-npro -kr -i4 -ts8 -sob -l80 -ss -ncs -cp1"
|
||||
RES=`indent --version`
|
||||
V1=`echo $RES | cut -d' ' -f3 | cut -d'.' -f1`
|
||||
V2=`echo $RES | cut -d' ' -f3 | cut -d'.' -f2`
|
||||
V3=`echo $RES | cut -d' ' -f3 | cut -d'.' -f3`
|
||||
if [ $V1 -gt 2 ]; then
|
||||
PARAM="$PARAM -il0"
|
||||
elif [ $V1 -eq 2 ]; then
|
||||
if [ $V2 -gt 2 ]; then
|
||||
PARAM="$PARAM -il0";
|
||||
elif [ $V2 -eq 2 ]; then
|
||||
if [ $V3 -ge 10 ]; then
|
||||
PARAM="$PARAM -il0"
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
exec indent $PARAM "$@"
|
||||
@@ -0,0 +1,41 @@
|
||||
Announcing the release of mkdosfs version 0.3b (Yggdrasil)
|
||||
|
||||
It seems I didn't get the bug completely fixed in 0.3a. Some
|
||||
borderline cases would still allocate too many sectors for the FAT.
|
||||
Again, nothing to worry about, just a nitpick -- this one would only
|
||||
in certain cases add one sector per FAT.
|
||||
|
||||
Announcing the release of mkdosfs version 0.3a (Yggdrasil)
|
||||
|
||||
Fixed a bug which would cause too many sectors to be reserved for the
|
||||
FAT (filesystem will still work fine, but have slightly less space
|
||||
available).
|
||||
|
||||
Announcing the release of mkdosfs version 0.3 (Yggdrasil)
|
||||
|
||||
This version correctly handles even very large filesystems, and
|
||||
properly supports the modern (3.3+) DOS bootsector format, including a
|
||||
message printed on boot attempts.
|
||||
|
||||
Peter Anvin
|
||||
Yggdrasil Computing, Inc.
|
||||
hpa@yggdrasil.com
|
||||
|
||||
--------------
|
||||
|
||||
Announcing the release of mkdosfs version 0.2
|
||||
|
||||
|
||||
I've just uploaded mkdosfs to sunsite.unc.edu. It works in a similar way
|
||||
to Remy Card's mke2fs, but creates an MS-DOS filesystem.
|
||||
|
||||
The filename is mkdosfs-0.2.tar.gz.
|
||||
|
||||
This second release should fix a small bug that could lead to FAT sizes that
|
||||
Linux's dosfs would accept but MS-DOS wouldn't.
|
||||
|
||||
The archive contains a manual page, binary and source versions.
|
||||
|
||||
|
||||
Dave Hudson
|
||||
dave@humbug.demon.co.uk
|
||||
@@ -0,0 +1,10 @@
|
||||
Changes from version 0 to 1
|
||||
===========================
|
||||
|
||||
- fixed an off-by-two error in check.c:check_file
|
||||
- fixed marking clusters bad in fat.c:set_fat
|
||||
- fat.c:reclaim_free was also reclaiming bad clusters.
|
||||
- fixed many incorrect byte sex conversions in check.c and fat.c
|
||||
- -t and -w now require -a or -r
|
||||
- added option -d to drop files.
|
||||
- added option -u to try to "undelete" non-directory files.
|
||||
@@ -0,0 +1,161 @@
|
||||
version 2.11
|
||||
============
|
||||
|
||||
- all: don't use own llseek() anymore, glibc lseek() does everything we need
|
||||
- dosfsck: lfn.c: avoid segfault
|
||||
- dosfsck: check.c, lfn.c: check for orphaned LFN slots
|
||||
- dosfsck: check.c alloc_rootdir_entry(): set owner of newly alloced clusters
|
||||
- dosfsck: dosfsck.h: better use <byteswap.h> for byte swapping
|
||||
- dosfsck: io.c: added code for real DOS
|
||||
- mkdosfs: raised FAT12_THRESHOLD from 4078 to 4085, introduced MIN_CLUST_32
|
||||
- mkdosfs: fix loop device size
|
||||
- mkdosfs: by default, use FAT32 on devices >= 512MB
|
||||
- mkdosfs: fix a memory leak (blank_sector)
|
||||
- mkdosfs: fix parsing of number of blocks on command line, so that numbers
|
||||
>2G can be used
|
||||
- mkdosfs: add 'b' to getopt() string so this option can be used :)
|
||||
- mkdosfs: fix parsing of -i arg (should be unsigned)
|
||||
- mkdosfs: change default permissions of created images (-C) to 0666 & ~umask
|
||||
- mkdosfs: relax geometry check: if HDIO_GETGEO fails, print a warning and
|
||||
default to H=255,S=63
|
||||
- dosfsck: new option -n (no-op): just check non-interactively, but
|
||||
don't write anything to filesystem
|
||||
- A few #include changes to support compilation with linux 2.6
|
||||
headers (thanks to Jim Gifford <jim@jg555.com>)
|
||||
- dosfsck: remove directory entries pointing to start cluster 0, if they're
|
||||
not "." or ".." entries that should actually point to the root dir
|
||||
(pointed out by Thomas Winkler <twinkler@sysgo.de>)
|
||||
- mkdosfs: new option -h to set number of hidden sectors
|
||||
(thanks to Godwin Stewart <gstewart@spamcop.net>)
|
||||
- all: updated my mail address everywhere...
|
||||
|
||||
version 2.10
|
||||
============
|
||||
|
||||
- dosfsck: various 64-bit fixes and removed some warnings by Michal
|
||||
Cihar <mcihar@suse.cz>
|
||||
- mkdosfs: better error message if called without parameters (also
|
||||
suggested by Michal)
|
||||
|
||||
version 2.9
|
||||
===========
|
||||
|
||||
- dosfsck: if EOF from stdin, exit with error code
|
||||
- dosfsck: Fix potential for "Internal error: next_cluster on bad cluster".
|
||||
- dosfsck: When clearing long file names, don't overwrite the dir
|
||||
entries with all zeros, but put 0xe5 into the first byte.
|
||||
Otherwise, some OSes stop reading the directory at that point...
|
||||
- dosfsck: in statistics printed by -v, fix 32bit overflow in number
|
||||
of data bytes.
|
||||
- dosfsck: fix an potential overflow in "too many clusters" check
|
||||
- dosfsck: fix 64bit problem in fat.c (Debian bug #152769)
|
||||
- dosfsck: allow FAT size > 32MB.
|
||||
- dosfsck: allow for only one FAT
|
||||
- dosfsck: with -v, also check that last sector of the filesystem can
|
||||
be read (in case a partition is smaller than the fs thinks)
|
||||
- mkdosfs: add note in manpage that creating bootable filesystems is
|
||||
not supported.
|
||||
- mkdosfs: better error message with pointer to -I if target is a
|
||||
full-disk device.
|
||||
|
||||
version 2.8
|
||||
===========
|
||||
|
||||
- dosfsck: Fixed endless loop whenever a volume label was present.
|
||||
|
||||
version 2.7
|
||||
===========
|
||||
|
||||
- dosfsck: Don't check volume label for bad characters, everything
|
||||
seems to be allowed there... Also ignore duplicate names where one of
|
||||
them is a volume label.
|
||||
|
||||
version 2.6
|
||||
===========
|
||||
|
||||
- mkdosfs: Added correct heads definition for 2.88M floppies if not
|
||||
created via loopback.
|
||||
- dosfsck: If boot sector and its backup are different (FAT32), offer
|
||||
to write the backup to sector 0. (tnx to Pavel Roskin for this)
|
||||
- For 64 bit alpha, struct bootsector in dosfsck.h must be defined
|
||||
with __attribute__((packed)).
|
||||
- mkdosfs now actually accepts -R option. (tnx to David Kerrawn)
|
||||
- Fixed typo in dosfsck boot.c (recognition of boot signature in FSINFO)
|
||||
- Various compilation fixes for 2.4 kernel headers and for ia64.
|
||||
|
||||
version 2.5
|
||||
===========
|
||||
|
||||
- The llseek() implementation for alpha didn't really work; fixed it.
|
||||
|
||||
version 2.4
|
||||
===========
|
||||
|
||||
- Fix compiling problem on alpha (made a silly typo...)
|
||||
|
||||
version 2.3
|
||||
===========
|
||||
|
||||
- mkdosfs: Fixed usage message (printed only "bad address").
|
||||
- both: made man pages and usage statements more consistent.
|
||||
- both: fix llseek function for alpha.
|
||||
- dosfsck: fix reading of unaligned fields in boot sector for alpha.
|
||||
- dosfsck: fixed renaming of files (extension wasn't really written).
|
||||
|
||||
version 2.2
|
||||
===========
|
||||
|
||||
- Added dosfsck/COPYING, putting dosfsck officially under GPL (Werner
|
||||
and I agree that it should be GPL).
|
||||
- mkdosfs: Allow creation of a 16 bit FAT on filesystems that are too
|
||||
small for it if the user explicitly selected FAT16 (but a warning
|
||||
is printed). Formerly, you got the misleading error message "make
|
||||
the fs a bit smaller".
|
||||
- dosfsck: new option -y as synonym for -y; for compability with
|
||||
other fs checkers, which also accept this option.
|
||||
- dosfsck: Now prints messages similar to e2fsck: at start version
|
||||
and feature list; at end number of files (and directories) and
|
||||
number of used/total clusters. This makes the printouts of *fsck at
|
||||
boot time nicer.
|
||||
- dosfsck: -a (auto repair) now turns on -f (salvage files), too. -a
|
||||
should act as non-destructive as possible, so lost clusters should
|
||||
be assigned to files. Otherwise the data in them might be
|
||||
overwritten later.
|
||||
- dosfsck: Don't drop a directory with lots of bad entries in
|
||||
auto-repair mode for the same reason as above.
|
||||
- dosfsck: avoid deleting the whole FAT32 root dir if something is
|
||||
wrong with it (bad start cluster or the like).
|
||||
- general: also create symlinks {mkfs,fsck}.vfat.8 to the respective
|
||||
real man pages.
|
||||
|
||||
version 2.1
|
||||
===========
|
||||
|
||||
- Fix some forgotten loff_t's for filesystems > 4GB. (Thanks to
|
||||
<ki@kretz.co.at>).
|
||||
- Fix typo in mkdosfs manpage.
|
||||
- Removed inclusion of <linux/loop.h> from mkdosfs.c; it's unnecessary and
|
||||
caused problems in some environments.
|
||||
- Fix condition when to expect . and .. entries in a directory. (Was
|
||||
wrong for non-FAT32 if first entry in root dir was a directory also.)
|
||||
- Also create mkfs.vfat and fsck.vfat symlinks, so that also
|
||||
filesystems listed with type "vfat" in /etc/fstab can be
|
||||
automatically checked.
|
||||
|
||||
version 2.0
|
||||
===========
|
||||
|
||||
- merge of mkdosfs and dosfstools in one package
|
||||
- new maintainer: Roman Hodek <Roman.Hodek@informatik.uni-erlangen.de>
|
||||
- FAT32 support in both mkdosfs and dosfsck
|
||||
- VFAT (long filename) support in dosfsck
|
||||
- Support for Atari variant of MS-DOS filesystem in both tools
|
||||
- Working support for big-endian systems in both tools
|
||||
- Better support for loop devices in mkdosfs: usual floppy sizes are
|
||||
detected and media byte etc. set accordingly; if loop fs has no
|
||||
standard floppy size, use hd params
|
||||
(mainly by Giuliano Procida <gpp10@cus.cam.ac.uk>)
|
||||
- Removed lots of gcc warnings
|
||||
- Fixed some minor calculation bugs in mkdosfs.
|
||||
|
||||
For change logs previous to 2.0, see the CHANGES files in the subdirectories.
|
||||
@@ -0,0 +1,18 @@
|
||||
28th January 1995 H. Peter Anvin (hpa@yggdrasil.com)
|
||||
|
||||
Better algorithm to select cluster sizes on large filesystems.
|
||||
Added bogus boot sector code that on attempts to boot prints a
|
||||
message (which can be chosen at mkdosfs time) and lets the user
|
||||
press any key and try again. Corrected support for 1.2 Mb
|
||||
floppies. mkdosfs now generates the extended bootsector
|
||||
(superblock) format of DOS 3.3+, with support for volume ID's and
|
||||
volume labels (volume labels are also written to the root
|
||||
directory, as they should).
|
||||
|
||||
18th February 1994 Dave Hudson (dave@humbug.demon.co.uk)
|
||||
|
||||
Released version 0.2 - clears a bug in the FAT sizing code.
|
||||
|
||||
1st September 1993 Dave Hudson (dave@humbug.demon.co.uk)
|
||||
|
||||
Released version 0.1 - ALPHA release of mkdosfs
|
||||
@@ -0,0 +1,60 @@
|
||||
dosfsck, version 1
|
||||
==================
|
||||
|
||||
WARNING: This is ALPHA test software. Use at your own risk.
|
||||
|
||||
dosfsck is the Linux equivalent of PC/MS-DOS' CHKDSK. It checks the
|
||||
consistency of PC/MS-DOS filesystems and optionally tries to repair
|
||||
them. The tests dosfsck performs are described in the man page.
|
||||
|
||||
dosfsck needs header files from dosfs.9 (or later) to compile.
|
||||
|
||||
Before using dosfsck to repair a filesystem that contains data of any
|
||||
value, you should verify that dosfsck is able to correct all reported
|
||||
errors. (Except fatal errors and those reported as unfixable, of
|
||||
course.) In order to do this, run it with the -V option, e.g.
|
||||
|
||||
dosfsck -V /dev/sda1 (automatic check)
|
||||
or dosfsck -V -r /dev/sda1 (interactive check and repair)
|
||||
|
||||
dosfsck will perform two passes: in the first pass, inconsistencies are
|
||||
detected and a list of changes to correct the problems is generated. In
|
||||
the second pass, those changes are applied whenever dosfsck reads data
|
||||
from disk. Hence no fixable errors should be reported in the second
|
||||
pass if the first pass was successful.
|
||||
|
||||
Please notify the author if fixable errors are reported in the second
|
||||
pass.
|
||||
|
||||
After verifying that dosfsck appears to be able to perform the desired
|
||||
operations, either confirm that you want the changes to be performed
|
||||
(if dosfsck was started with -r) or re-run dosfsck with the -a option
|
||||
(if it was started without -r).
|
||||
|
||||
Please send bug reports, comments, flames, etc. to
|
||||
almesber@nessie.cs.id.ethz.ch or almesber@bernina.ethz.ch
|
||||
|
||||
- Werner
|
||||
|
||||
FAT32 and LFN support
|
||||
=====================
|
||||
|
||||
I've finally implemented some of the new features of MS-DOS
|
||||
filesystems: FAT32 and long filenames.
|
||||
|
||||
FAT32 is automatically detected and of course the different FAT
|
||||
structure is handled. (Internally many changes were needed, so 32 bit
|
||||
variables for all cluster numbers and 64 bit vars for offsets inside
|
||||
the filesystem.) New checks for FAT32 are most notably on the backup
|
||||
boot sector and the new info sector. Also the possibility that the
|
||||
root directory resides in a cluster chain (instead of in a static
|
||||
area) on FAT32 is handled.
|
||||
|
||||
dosfscheck also knows about VFAT long filenames now. It parses those
|
||||
names and uses them in listings etc. when available. There are also
|
||||
some checks on the (cruel) structure of how LFNs are stored and some
|
||||
attempts to fix problems.
|
||||
|
||||
- Roman <roman@hodek.net>
|
||||
|
||||
BTW, version 2 isn't ALPHA anymore :-)
|
||||
@@ -0,0 +1,60 @@
|
||||
|
||||
Atari format support
|
||||
====================
|
||||
|
||||
Both mkdosfs and dosfsck now can also handle the Atari variation of
|
||||
the MS-DOS filesystem format. The Atari format has some minor
|
||||
differences, some caused by the different machine architecture (m68k),
|
||||
some being "historic" (Atari didn't change some things that M$
|
||||
changed).
|
||||
|
||||
Both tools automatically select Atari format if they run on an Atari.
|
||||
Additionally the -A switch toggles between Atari and MS-DOS format.
|
||||
I.e., on an Atari it selects plain DOS format, on any other machine it
|
||||
switches to Atari format.
|
||||
|
||||
The differences are in detail:
|
||||
|
||||
- Atari TOS doesn't like cluster sizes != 2, so the usual solution
|
||||
for bigger partitions was to increase the logical sector size. So
|
||||
mkdosfs can handle sector sizes != 512 now, you can also manually
|
||||
select it with the -S option. On filesystems larger than approx. 32
|
||||
MB, the sector size is automatically increased (stead of the
|
||||
cluster size) to make the filesystem fit. mkdosfs will always use 2
|
||||
sectors per cluster (also with the floppy standard configurations),
|
||||
except when directed otherwise on the command line.
|
||||
|
||||
- From the docs, all values between 0xfff8 and 0xffff in the FAT mark
|
||||
an end-of-file. However, DOS usually uses 0xfff8 and Atari 0xffff.
|
||||
This seems to be only an consmetic difference. At least TOS doesn't
|
||||
complain about 0xffff EOF marks. Don't know what DOS thinks of
|
||||
0xfff8 :-) Anyway, both tools use the EOF mark common to the
|
||||
system (DOS/Atari).
|
||||
|
||||
- Something similar of the bad cluster marks: On Atari the FAT values
|
||||
0xfff0 to 0xfff7 are used for this, under DOS only 0xfff7 (the
|
||||
others can be normal cluster numbers, allowing 7 more clusters :-)
|
||||
However, both systems usually mark with 0xfff7. Just dosfsck has to
|
||||
interpret 0xfff0...0xfff7 differently.
|
||||
|
||||
- Some fields in the boot sector are interpreted differently. For
|
||||
example, Atari has a disk serial number (used to aid disk change
|
||||
detection) where DOS stores the system name; the 'hidden' field is
|
||||
32 bit for DOS, but 16 bit for Atari, and there's no 'total_sect'
|
||||
field; the 12/16 bit FAT decision is different: it's not based on
|
||||
the number of clusters, but always FAT12 on floppies and FAT16 on
|
||||
hard disks. mkdosfs nows about these differences and constructs the
|
||||
boot sector accordingly.
|
||||
|
||||
- In dosfsck, the boot sector differences also have to known, to not
|
||||
warn about things that are no error on Atari. In addition, most
|
||||
Atari formatting tools fill the 'tracks' and 'heads' fields with 0
|
||||
for hard disks, because they're meaningless on SCSI disks (Atari
|
||||
has/had no IDE). Due to this, the check that they should be
|
||||
non-zero is switched off.
|
||||
|
||||
- Under Atari TOS, some other characters are illegal in filenames:
|
||||
'<', '>', '|', '"', and ':' are allowed, but all non-ASCII chars
|
||||
(codes >= 128) are forbidden.
|
||||
|
||||
- Roman <Roman.Hodek@informatik.uni-erlangen.de>
|
||||
@@ -0,0 +1,50 @@
|
||||
mkdosfs - Make DOS filesystem utilty.
|
||||
|
||||
|
||||
I wrote this, partially to complement the dosfsck utility written by Werner
|
||||
Almesberger (who graciously gave me some pointers when I asked for some
|
||||
advice about writing this code), and also to avoid me having to boot DOS
|
||||
just to create data partitions (I use Linux to back up DOS :-) ).
|
||||
|
||||
The code is really derived from Remy Card's mke2fs utility - I used this as a
|
||||
framework, although all of the filesystem specific stuff was removed and the
|
||||
DOS stuff inserted. I believe originally mke2fs was based on Linus' mkfs
|
||||
code, hence the acknowledgements in the source code.
|
||||
|
||||
Neither Remy nor Linus have had any involvement with mkdosfs, so if there are
|
||||
any bugs they're almost certainly "all my own work".
|
||||
|
||||
The code has been available for ftp since 1st September 1993, and I have yet
|
||||
to receive any bug reports from users. I don't know of any bugs, but if you
|
||||
do find a bug or have any constructive comments, please mail me!
|
||||
|
||||
The only bug I found with version 0.1 was an obscure fault that could lead
|
||||
to an invalid (for MS-DOS, not Linux's dos fs) number of sectors used in the
|
||||
file allocation table(s).
|
||||
|
||||
|
||||
Dave Hudson
|
||||
dave@humbug.demon.co.uk
|
||||
|
||||
|
||||
FAT32 support
|
||||
=============
|
||||
|
||||
mkdosfs now can also create filesystems in the new FAT32 format. To do
|
||||
this, give mkdosfs a "-F 32" option. FAT32 isn't selected
|
||||
automatically (yet), even if very large clusters are needed with
|
||||
FAT16. With FAT32 you have two additional options, -R to select the
|
||||
number of reserved sectors (usually 32), and -b to select the location
|
||||
of the backup boot sector (default 6). Of course such a backup is
|
||||
created, as well as the new info sector. On FAT32, the root directory
|
||||
is always created as a cluster chain. Sorry, there's no switch to
|
||||
generate an old static root dir.
|
||||
|
||||
One bigger bug fix besides FAT32 was to reject filesystems that need a
|
||||
16 bit FAT to fit all possible clusters, but the bigger FAT needs some
|
||||
more sectors, so the total number of clusters drop below the border
|
||||
where MS-DOS expects a 12 bit FAT. So such filesystems would be FAT16,
|
||||
but interpreted as FAT32 by DOS. The fix is to reduce filesystem size
|
||||
a bit.
|
||||
|
||||
- Roman <roman@hodek.net>
|
||||
@@ -0,0 +1,14 @@
|
||||
-*- mode: indented-text -*-
|
||||
|
||||
- dosfsck: Better checking of file times: ctime <= mtime <= atime
|
||||
|
||||
- mkdosfs: If /etc/bootsect.dos (or similar) exists, use it as a
|
||||
template for generating boot sectors. This way, you can, e.g., make
|
||||
bootable DOS disks.
|
||||
|
||||
Addendum: Don't know if that's so wise... There are really many
|
||||
variants of DOS/Windows bootcode out in the wild, and the code is
|
||||
proprietary, too.
|
||||
|
||||
- dosfsck: read-only sector test (-t without -a or -r); just print
|
||||
out errors.
|
||||
@@ -0,0 +1,50 @@
|
||||
# Makefile
|
||||
|
||||
## dosfstools(7)
|
||||
## Copyright (C) 2006-2014 Daniel Baumann <mail@daniel-baumann.ch>
|
||||
##
|
||||
## This program comes with ABSOLUTELY NO WARRANTY; for details see COPYING.
|
||||
## This is free software, and you are welcome to redistribute it
|
||||
## under certain conditions; see COPYING for details.
|
||||
|
||||
|
||||
SHELL := sh -e
|
||||
|
||||
LANGUAGES = $(shell cd po && ls)
|
||||
|
||||
all: build
|
||||
|
||||
po4a.cfg:
|
||||
echo "[po4a_langs] $(LANGUAGES)" > po4a.cfg
|
||||
echo "[po4a_paths] pot/\$$master.pot \$$lang:po/\$$lang/\$$master.po" >> po4a.cfg
|
||||
|
||||
for MANPAGE in en/*; \
|
||||
do \
|
||||
SECTION="$$(basename $${MANPAGE} | sed -e 's|\.|\n|g' | tail -n1)"; \
|
||||
echo "[type: man] $${MANPAGE} \$$lang:\$$lang/$$(basename $${MANPAGE} .$${SECTION}).\$$lang.$${SECTION}" >> po4a.cfg; \
|
||||
done
|
||||
|
||||
update:
|
||||
./bin/update-version.sh
|
||||
|
||||
build: po4a.cfg
|
||||
@if [ ! -x "$$(which po4a 2>/dev/null)" ]; \
|
||||
then \
|
||||
echo "E: po4a - command not found"; \
|
||||
echo "I: po4a can be obtained from:"; \
|
||||
echo "I: http://po4a.alioth.debian.org/"; \
|
||||
echo "I: On Debian based systems, po4a can be installed with:"; \
|
||||
echo "I: apt-get install po4a"; \
|
||||
exit 1; \
|
||||
fi
|
||||
|
||||
po4a --keep 0 --no-backups -o untranslated=MT,ME \
|
||||
--package-name dosfstools po4a.cfg
|
||||
|
||||
clean:
|
||||
rm -rf $(LANGUAGES)
|
||||
|
||||
distclean: clean
|
||||
rm -f po4a.cfg
|
||||
|
||||
rebuild: distclean update build
|
||||
@@ -0,0 +1,55 @@
|
||||
#!/bin/sh
|
||||
|
||||
## dosfstools(7)
|
||||
## Copyright (C) 2006-2014 Daniel Baumann <mail@daniel-baumann.ch>
|
||||
##
|
||||
## This program comes with ABSOLUTELY NO WARRANTY; for details see COPYING.
|
||||
## This is free software, and you are welcome to redistribute it
|
||||
## under certain conditions; see COPYING for details.
|
||||
|
||||
|
||||
set -e
|
||||
|
||||
PROJECT="dosfstools"
|
||||
VERSION="$(cat ../VERSION)"
|
||||
|
||||
DATE="$(LC_ALL=C date +%Y\\\\-%m\\\\-%d)"
|
||||
|
||||
DAY="$(LC_ALL=C date +%d)"
|
||||
MONTH="$(LC_ALL=C date +%m)"
|
||||
YEAR="$(LC_ALL=C date +%Y)"
|
||||
|
||||
echo "Updating version headers..."
|
||||
|
||||
for MANPAGE in en/*
|
||||
do
|
||||
PROGRAM="$(basename ${MANPAGE} | sed -e 's|\(.*\).[0-9]$|\1|' | tr [a-z] [A-Z])"
|
||||
SECTION="$(basename ${MANPAGE} | sed -e 's|.*.\([0-9]\)$|\1|')"
|
||||
|
||||
sed -i -e "s|^.TH.*$|.TH ${PROGRAM} ${SECTION} ${DATE} ${VERSION} \"${PROJECT}\"|" ${MANPAGE}
|
||||
done
|
||||
|
||||
# European date format
|
||||
for _LANGUAGE in de es fr it
|
||||
do
|
||||
if ls po/${_LANGUAGE}/*.po > /dev/null 2>&1
|
||||
then
|
||||
for _FILE in po/${_LANGUAGE}/*.po
|
||||
do
|
||||
sed -i -e "s|^msgstr .*.2014-.*$|msgstr \"${DAY}.${MONTH}.${YEAR}\"|g" \
|
||||
-e "s|^msgstr .*.2014\"$|msgstr \"${DAY}.${MONTH}.${YEAR}\"|g" \
|
||||
"${_FILE}"
|
||||
done
|
||||
fi
|
||||
done
|
||||
|
||||
# Brazilian date format
|
||||
if ls po/pt_BR/*.po > /dev/null 2>&1
|
||||
then
|
||||
for _FILE in po/pt_BR/*.po
|
||||
do
|
||||
sed -i -e "s|^msgstr .*.2014-.*$|msgstr \"${DAY}-${MONTH}-${YEAR}\"|g" \
|
||||
-e "s|^msgstr .*-2014\"$|msgstr \"${DAY}-${MONTH}-${YEAR}\"|g" \
|
||||
"${_FILE}"
|
||||
done
|
||||
fi
|
||||
@@ -0,0 +1,68 @@
|
||||
.\" fatlabel.8 - manpage for fatlabel
|
||||
.\"
|
||||
.\" Copyright (C) 2006-2014 Daniel Baumann <daniel@debian.org>
|
||||
.\"
|
||||
.\" 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 3 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, see <http://www.gnu.org/licenses/>.
|
||||
.\"
|
||||
.\" The complete text of the GNU General Public License
|
||||
.\" can be found in /usr/share/common-licenses/GPL-3 file.
|
||||
.\"
|
||||
.\"
|
||||
.\"*******************************************************************
|
||||
.\"
|
||||
.\" This file was generated with po4a. Translate the source file.
|
||||
.\"
|
||||
.\"*******************************************************************
|
||||
.TH FATLABEL 8 2015\-05\-16 3.0.28 dosfstools
|
||||
.SH NAME
|
||||
.\" ----------------------------------------------------------------------------
|
||||
\fBfatlabel\fP \- set or get MS\-DOS filesystem label
|
||||
.SH SYNOPSIS
|
||||
.\" ----------------------------------------------------------------------------
|
||||
\fBfatlabel\fP \fIDEVICE\fP [\fILABEL\fP]
|
||||
.SH DESCRIPTION
|
||||
\fBfatlabel\fP set or gets a MS\-DOS filesystem label from a given device.
|
||||
.PP
|
||||
.\" ----------------------------------------------------------------------------
|
||||
If \fILABEL\fP is omitted, then the label name of the specified device is
|
||||
written on the standard output. A label can't be longer than 11 bytes.
|
||||
.SH OPTIONS
|
||||
.IP "\fB\-h\fP, \fB\-\-help\fP" 4
|
||||
Displays a help message.
|
||||
.IP "\fB\-V\fP, \fB\-\-version\fP" 4
|
||||
.\" ----------------------------------------------------------------------------
|
||||
Shows version.
|
||||
.SH "SEE ALSO"
|
||||
\fBfsck.fat\fP(8)
|
||||
.br
|
||||
.\" ----------------------------------------------------------------------------
|
||||
\fBmkfs.fat\fP(8)
|
||||
.SH HOMEPAGE
|
||||
.\" ----------------------------------------------------------------------------
|
||||
The home for the \fBdosfstools\fP project is its
|
||||
.UR https://github.com/dosfstools/dosfstools
|
||||
GitHub project page
|
||||
.UE .
|
||||
.SH AUTHORS
|
||||
\fBdosfstools\fP were written by
|
||||
.MT werner.almesberger@\:lrc.di.epfl.ch
|
||||
Werner Almesberger
|
||||
.ME ,
|
||||
.MT Roman.Hodek@\:informatik.\:uni-erlangen.de
|
||||
Roman Hodek
|
||||
.ME ,
|
||||
and others. The current maintainer is
|
||||
.MT aeb@\:debian.org
|
||||
Andreas Bombe
|
||||
.ME .
|
||||
@@ -0,0 +1,189 @@
|
||||
.\" fsck.fat.8 - manpage for fsck.fat
|
||||
.\"
|
||||
.\" Copyright (C) 2006-2014 Daniel Baumann <daniel@debian.org>
|
||||
.\"
|
||||
.\" 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 3 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, see <http://www.gnu.org/licenses/>.
|
||||
.\"
|
||||
.\" The complete text of the GNU General Public License
|
||||
.\" can be found in /usr/share/common-licenses/GPL-3 file.
|
||||
.\"
|
||||
.\"
|
||||
.\"*******************************************************************
|
||||
.\"
|
||||
.\" This file was generated with po4a. Translate the source file.
|
||||
.\"
|
||||
.\"*******************************************************************
|
||||
.TH FSCK.FAT 8 2015\-05\-16 3.0.28 dosfstools
|
||||
.SH NAME
|
||||
.\" ----------------------------------------------------------------------------
|
||||
\fBfsck.fat\fP \- check and repair MS\-DOS filesystems
|
||||
.SH SYNOPSIS
|
||||
.\" ----------------------------------------------------------------------------
|
||||
\fBfsck.fat\fP [\fIOPTIONS\fP] \fIDEVICE\fP
|
||||
.SH DESCRIPTION
|
||||
\fBfsck.fat\fP verifies the consistency of MS\-DOS filesystems and optionally
|
||||
tries to repair them.
|
||||
.PP
|
||||
The following filesystem problems can be corrected (in this order):
|
||||
.IP * 4
|
||||
FAT contains invalid cluster numbers. Cluster is changed to EOF.
|
||||
.IP * 4
|
||||
File's cluster chain contains a loop. The loop is broken.
|
||||
.IP * 4
|
||||
Bad clusters (read errors). The clusters are marked bad and they are
|
||||
removed from files owning them. This check is optional.
|
||||
.IP * 4
|
||||
Directories with a large number of bad entries (probably corrupt). The
|
||||
directory can be deleted.
|
||||
.IP * 4
|
||||
Files . and .. are non\-directories. They can be deleted or renamed.
|
||||
.IP * 4
|
||||
Directories . and .. in root directory. They are deleted.
|
||||
.IP * 4
|
||||
Bad filenames. They can be renamed.
|
||||
.IP * 4
|
||||
Duplicate directory entries. They can be deleted or renamed.
|
||||
.IP * 4
|
||||
Directories with non\-zero size field. Size is set to zero.
|
||||
.IP * 4
|
||||
Directory . does not point to parent directory. The start pointer is
|
||||
adjusted.
|
||||
.IP * 4
|
||||
Directory .. does not point to parent of parent directory. The start
|
||||
pointer is adjusted.
|
||||
.IP * 4
|
||||
Start cluster number of a file is invalid. The file is truncated.
|
||||
.IP * 4
|
||||
File contains bad or free clusters. The file is truncated.
|
||||
.IP * 4
|
||||
File's cluster chain is longer than indicated by the size fields. The file
|
||||
is truncated.
|
||||
.IP * 4
|
||||
Two or more files share the same cluster(s). All but one of the files are
|
||||
truncated. If the file being truncated is a directory file that has already
|
||||
been read, the filesystem check is restarted after truncation.
|
||||
.IP * 4
|
||||
File's cluster chain is shorter than indicated by the size fields. The file
|
||||
is truncated.
|
||||
.IP * 4
|
||||
Clusters are marked as used but are not owned by a file. They are marked as
|
||||
free.
|
||||
.PP
|
||||
Additionally, the following problems are detected, but not repaired:
|
||||
.IP * 4
|
||||
Invalid parameters in boot sector
|
||||
.IP * 4
|
||||
Absence of . and .. entries in non\-root directories
|
||||
.PP
|
||||
.\" ----------------------------------------------------------------------------
|
||||
When \fBfsck.fat\fP checks a filesystem, it accumulates all changes in memory
|
||||
and performs them only after all checks are complete. This can be disabled
|
||||
with the \fB\-w\fP option.
|
||||
.SH OPTIONS
|
||||
.IP \fB\-a\fP 4
|
||||
Automatically repair the filesystem. No user intervention is necessary.
|
||||
Whenever there is more than one method to solve a problem, the least
|
||||
destructive approach is used.
|
||||
.IP \fB\-A\fP 4
|
||||
Use Atari variation of the MS\-DOS filesystem. This is default if
|
||||
\fBfsck.fat\fP is run on an Atari, then this option turns off Atari format.
|
||||
There are some minor differences in Atari format: Some boot sector fields
|
||||
are interpreted slightly different, and the special FAT entries for
|
||||
end\-of\-file and bad cluster can be different. Under MS\-DOS 0xfff8 is used
|
||||
for EOF and Atari employs 0xffff by default, but both systems recognize all
|
||||
values from 0xfff8...0xffff as end\-of\-file. MS\-DOS uses only 0xfff7 for bad
|
||||
clusters, where on Atari values 0xfff0...0xfff7 are for this purpose (but
|
||||
the standard value is still 0xfff7).
|
||||
.IP \fB\-b\fP 4
|
||||
Make read\-only boot sector check.
|
||||
.IP "\fB\-d\fP \fIPATH\fP" 4
|
||||
Delete the specified file. If more than one file with that name exist, the
|
||||
first one is deleted. This option can be given more than once.
|
||||
.IP \fB\-f\fP 4
|
||||
Salvage unused cluster chains to files. By default, unused clusters are
|
||||
added to the free disk space except in auto mode (\fB\-a\fP).
|
||||
.IP \fB\-l\fP 4
|
||||
List path names of files being processed.
|
||||
.IP \fB\-n\fP 4
|
||||
No\-operation mode: non\-interactively check for errors, but don't write
|
||||
anything to the filesystem.
|
||||
.IP \fB\-p\fP 4
|
||||
Same as \fB\-a\fP, for compatibility with other *fsck.
|
||||
.IP \fB\-r\fP 4
|
||||
Interactively repair the filesystem. The user is asked for advice whenever
|
||||
there is more than one approach to fix an inconsistency. This is the
|
||||
default mode and the option is only retained for backwards compatibility.
|
||||
.IP \fB\-t\fP 4
|
||||
Mark unreadable clusters as bad.
|
||||
.IP "\fB\-u\fP \fIPATH\fP" 4
|
||||
Try to undelete the specified file. \fBfsck.fat\fP tries to allocate a chain
|
||||
of contiguous unallocated clusters beginning with the start cluster of the
|
||||
undeleted file. This option can be given more than once.
|
||||
.IP \fB\-v\fP 4
|
||||
Verbose mode. Generates slightly more output.
|
||||
.IP \fB\-V\fP 4
|
||||
Perform a verification pass. The filesystem check is repeated after the
|
||||
first run. The second pass should never report any fixable errors. It may
|
||||
take considerably longer than the first pass, because the first pass may
|
||||
have generated long list of modifications that have to be scanned for each
|
||||
disk read.
|
||||
.IP \fB\-w\fP 4
|
||||
Write changes to disk immediately.
|
||||
.IP \fB\-y\fP 4
|
||||
.\" ----------------------------------------------------------------------------
|
||||
Same as \fB\-a\fP (automatically repair filesystem) for compatibility with other
|
||||
fsck tools.
|
||||
.SH "EXIT STATUS"
|
||||
.IP 0 4
|
||||
No recoverable errors have been detected.
|
||||
.IP 1 4
|
||||
Recoverable errors have been detected or \fBfsck.fat\fP has discovered an
|
||||
internal inconsistency.
|
||||
.IP 2 4
|
||||
.\" ----------------------------------------------------------------------------
|
||||
Usage error. \fBfsck.fat\fP did not access the filesystem.
|
||||
.SH FILES
|
||||
.IP "fsck0000.rec, fsck0001.rec, ..." 4
|
||||
.\" ----------------------------------------------------------------------------
|
||||
When recovering from a corrupted filesystem, \fBfsck.fat\fP dumps recovered
|
||||
data into files named 'fsckNNNN.rec' in the top level directory of the
|
||||
filesystem.
|
||||
.SH BUGS
|
||||
.\" ----------------------------------------------------------------------------
|
||||
Does not create . and .. files where necessary. Does not remove entirely
|
||||
empty directories. Should give more diagnostic messages. Undeleting files
|
||||
should use a more sophisticated algorithm.
|
||||
.SH "SEE ALSO"
|
||||
\fBfatlabel\fP(8)
|
||||
.br
|
||||
.\" ----------------------------------------------------------------------------
|
||||
\fBmkfs.fat\fP(8)
|
||||
.SH HOMEPAGE
|
||||
.\" ----------------------------------------------------------------------------
|
||||
The home for the \fBdosfstools\fP project is its
|
||||
.UR https://github.com/dosfstools/dosfstools
|
||||
GitHub project page
|
||||
.UE .
|
||||
.SH AUTHORS
|
||||
\fBdosfstools\fP were written by
|
||||
.MT werner.almesberger@\:lrc.di.epfl.ch
|
||||
Werner Almesberger
|
||||
.ME ,
|
||||
.MT Roman.Hodek@\:informatik.\:uni-erlangen.de
|
||||
Roman Hodek
|
||||
.ME ,
|
||||
and others. The current maintainer is
|
||||
.MT aeb@\:debian.org
|
||||
Andreas Bombe
|
||||
.ME .
|
||||
@@ -0,0 +1,172 @@
|
||||
.\" mkfs.fat.8 - manpage for fs.fatck
|
||||
.\"
|
||||
.\" Copyright (C) 2006-2014 Daniel Baumann <daniel@debian.org>
|
||||
.\"
|
||||
.\" 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 3 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, see <http://www.gnu.org/licenses/>.
|
||||
.\"
|
||||
.\" The complete text of the GNU General Public License
|
||||
.\" can be found in /usr/share/common-licenses/GPL-3 file.
|
||||
.\"
|
||||
.\"
|
||||
.\"*******************************************************************
|
||||
.\"
|
||||
.\" This file was generated with po4a. Translate the source file.
|
||||
.\"
|
||||
.\"*******************************************************************
|
||||
.TH MKFS.FAT 8 2015\-05\-16 3.0.28 dosfstools
|
||||
.SH NAME
|
||||
.\" ----------------------------------------------------------------------------
|
||||
\fBmkfs.fat\fP \- create an MS\-DOS filesystem under Linux
|
||||
.SH SYNOPSIS
|
||||
.\" ----------------------------------------------------------------------------
|
||||
\fBmkfs.fat\fP [\fIOPTIONS\fP] \fIDEVICE\fP [\fIBLOCK\-COUNT\fP]
|
||||
.SH DESCRIPTION
|
||||
.\" ----------------------------------------------------------------------------
|
||||
\fBmkfs.fat\fP is used to create an MS\-DOS filesystem under Linux on a device
|
||||
(usually a disk partition). \fIDEVICE\fP is the special file corresponding to
|
||||
the device (e.g. /dev/sdXX). \fIBLOCK\-COUNT\fP is the number of blocks on the
|
||||
device. If omitted, \fBmkfs.fat\fP automatically determines the filesystem
|
||||
size.
|
||||
.SH OPTIONS
|
||||
.IP \fB\-a\fP 4
|
||||
Normally, for any filesystem except very small ones, \fBmkfs.fat\fP will align
|
||||
all the data structures to cluster size, to make sure that as long as the
|
||||
partition is properly aligned, so will all the data structures in the
|
||||
filesystem. This option disables alignment; this may provide a handful of
|
||||
additional clusters of storage at the expense of a significant performance
|
||||
degradation on RAIDs, flash media or large\-sector hard disks.
|
||||
.IP "\fB \-A\fP" 4
|
||||
Use Atari variation of the MS\-DOS filesystem. This is default if
|
||||
\fBmkfs.fat\fP is run on an Atari, then this option turns off Atari format.
|
||||
There are some differences when using Atari format: If not directed
|
||||
otherwise by the user, \fBmkfs.fat\fP will always use 2 sectors per cluster,
|
||||
since GEMDOS doesn't like other values very much. It will also obey the
|
||||
maximum number of sectors GEMDOS can handle. Larger filesystems are managed
|
||||
by raising the logical sector size. Under Atari format, an Atari\-compatible
|
||||
serial number for the filesystem is generated, and a 12 bit FAT is used only
|
||||
for filesystems that have one of the usual floppy sizes (720k, 1.2M, 1.44M,
|
||||
2.88M), a 16 bit FAT otherwise. This can be overridden with the \fB\-F\fP
|
||||
option. Some PC\-specific boot sector fields aren't written, and a boot
|
||||
message (option \fB\-m\fP) is ignored.
|
||||
.IP "\fB\-b\fP \fISECTOR\-OF\-BACKUP\fP" 4
|
||||
Selects the location of the backup boot sector for FAT32. Default depends
|
||||
on number of reserved sectors, but usually is sector 6. The backup must be
|
||||
within the range of reserved sectors.
|
||||
.IP \fB\-c\fP 4
|
||||
Check the device for bad blocks before creating the filesystem.
|
||||
.IP \fB\-C\fP 4
|
||||
Create the file given as \fIDEVICE\fP on the command line, and write the
|
||||
to\-be\-created filesystem to it. This can be used to create the new
|
||||
filesystem in a file instead of on a real device, and to avoid using \fBdd\fP
|
||||
in advance to create a file of appropriate size. With this option, the
|
||||
\fIBLOCK\-COUNT\fP must be given, because otherwise the intended size of the
|
||||
filesystem wouldn't be known. The file created is a sparse file, which
|
||||
actually only contains the meta\-data areas (boot sector, FATs, and root
|
||||
directory). The data portions won't be stored on the disk, but the file
|
||||
nevertheless will have the correct size. The resulting file can be copied
|
||||
later to a floppy disk or other device, or mounted through a loop device.
|
||||
.IP "\fB\-D\fP \fIDRIVE\-NUMBER\fP" 4
|
||||
Specify the BIOS drive number to be stored in the FAT boot sector. This
|
||||
value is usually 0x80 for hard disks and 0x00 for floppy devices or
|
||||
partitions to be used for floppy emulation.
|
||||
.IP "\fB\-f\fP \fINUMBER\-OF\-FATS\fP" 4
|
||||
Specify the number of file allocation tables in the filesystem. The default
|
||||
is 2.
|
||||
.IP "\fB\-F\fP \fIFAT\-SIZE\fP" 4
|
||||
Specifies the type of file allocation tables used (12, 16 or 32 bit). If
|
||||
nothing is specified, \fBmkfs.fat\fP will automatically select between 12, 16
|
||||
and 32 bit, whatever fits better for the filesystem size.
|
||||
.IP "\fB\-h\fP \fINUMBER\-OF\-HIDDEN\-SECTORS\fP" 4
|
||||
Select the number of hidden sectors in the volume. Apparently some digital
|
||||
cameras get indigestion if you feed them a CF card without such hidden
|
||||
sectors, this option allows you to satisfy them.
|
||||
.IP "\fB\-i\fP \fIVOLUME\-ID\fP" 4
|
||||
Sets the volume ID of the newly created filesystem; \fIVOLUME\-ID\fP is a 32\-bit
|
||||
hexadecimal number (for example, 2e24ec82). The default is a number which
|
||||
depends on the filesystem creation time.
|
||||
.IP \fB\-I\fP 4
|
||||
It is typical for fixed disk devices to be partitioned so, by default, you
|
||||
are not permitted to create a filesystem across the entire device.
|
||||
\fBmkfs.fat\fP will complain and tell you that it refuses to work. This is
|
||||
different when using MO disks. One doesn't always need partitions on MO
|
||||
disks. The filesystem can go directly to the whole disk. Under other OSes
|
||||
this is known as the 'superfloppy' format. This switch will force
|
||||
\fBmkfs.fat\fP to work properly.
|
||||
.IP "\fB\-l\fP \fIFILENAME\fP" 4
|
||||
Read the bad blocks list from \fIFILENAME\fP.
|
||||
.IP "\fB\-m\fP \fIMESSAGE\-FILE\fP" 4
|
||||
Sets the message the user receives on attempts to boot this filesystem
|
||||
without having properly installed an operating system. The message file
|
||||
must not exceed 418 bytes once line feeds have been converted to carriage
|
||||
return\-line feed combinations, and tabs have been expanded. If the filename
|
||||
is a hyphen (\-), the text is taken from standard input.
|
||||
.IP "\fB\-M\fP \fIFAT\-MEDIA\-TYPE\fP" 4
|
||||
Specify the media type to be stored in the FAT boot sector. This value is
|
||||
usually 0xF8 for hard disks and is 0xF0 or a value from 0xF9 to 0xFF for
|
||||
floppies or partitions to be used for floppy emulation.
|
||||
.IP "\fB\-n\fP \fIVOLUME\-NAME\fP" 4
|
||||
Sets the volume name (label) of the filesystem. The volume name can be up
|
||||
to 11 characters long. The default is no label.
|
||||
.IP "\fB\-r\fP \fIROOT\-DIR\-ENTRIES\fP" 4
|
||||
Select the number of entries available in the root directory. The default
|
||||
is 112 or 224 for floppies and 512 for hard disks.
|
||||
.IP "\fB\-R\fP \fINUMBER\-OF\-RESERVED\-SECTORS\fP" 4
|
||||
Select the number of reserved sectors. With FAT32 format at least 2
|
||||
reserved sectors are needed, the default is 32. Otherwise the default is 1
|
||||
(only the boot sector).
|
||||
.IP "\fB\-s\fP \fISECTORS\-PER\-CLUSTER\fP" 4
|
||||
Specify the number of disk sectors per cluster. Must be a power of 2,
|
||||
i.e. 1, 2, 4, 8, ... 128.
|
||||
.IP "\fB\-S\fP \fILOGICAL\-SECTOR\-SIZE\fP" 4
|
||||
Specify the number of bytes per logical sector. Must be a power of 2 and
|
||||
greater than or equal to 512, i.e. 512, 1024, 2048, 4096, 8192, 16384, or
|
||||
32768.
|
||||
.IP \fB\-v\fP 4
|
||||
Verbose execution.
|
||||
.IP \fB\-\-invariant\fP 4
|
||||
Use constants for normally randomly generated or time based data such as
|
||||
volume ID and creation time. Multiple runs of \fBmkfs.fat\fP on the same
|
||||
device create identical results with this option. Its main purpose is
|
||||
testing \fBmkfs.fat\fP.
|
||||
.IP \fB\-\-help\fP 4
|
||||
.\" ----------------------------------------------------------------------------
|
||||
Display option summary and exit.
|
||||
.SH BUGS
|
||||
.\" ----------------------------------------------------------------------------
|
||||
\fBmkfs.fat\fP can not create boot\-able filesystems. This isn't as easy as you
|
||||
might think at first glance for various reasons and has been discussed a lot
|
||||
already. \fBmkfs.fat\fP simply will not support it ;)
|
||||
.SH "SEE ALSO"
|
||||
\fBfatlabel\fP(8)
|
||||
.br
|
||||
.\" ----------------------------------------------------------------------------
|
||||
\fBfsck.fat\fP(8)
|
||||
.SH HOMEPAGE
|
||||
.\" ----------------------------------------------------------------------------
|
||||
The home for the \fBdosfstools\fP project is its
|
||||
.UR https://github.com/dosfstools/dosfstools
|
||||
GitHub project page
|
||||
.UE .
|
||||
.SH AUTHORS
|
||||
\fBdosfstools\fP were written by
|
||||
.MT werner.almesberger@\:lrc.di.epfl.ch
|
||||
Werner Almesberger
|
||||
.ME ,
|
||||
.MT Roman.Hodek@\:informatik.\:uni-erlangen.de
|
||||
Roman Hodek
|
||||
.ME ,
|
||||
and others. The current maintainer is
|
||||
.MT aeb@\:debian.org
|
||||
Andreas Bombe
|
||||
.ME .
|
||||
@@ -0,0 +1,65 @@
|
||||
.\" fatlabel.8 - manpage for fatlabel
|
||||
.\"
|
||||
.\" Copyright (C) 2006-2014 Daniel Baumann <daniel@debian.org>
|
||||
.\"
|
||||
.\" 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 3 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, see <http://www.gnu.org/licenses/>.
|
||||
.\"
|
||||
.\" The complete text of the GNU General Public License
|
||||
.\" can be found in /usr/share/common-licenses/GPL-3 file.
|
||||
.\"
|
||||
.\"
|
||||
.TH FATLABEL 8 2015\-05\-16 3.0.28 "dosfstools"
|
||||
.SH NAME
|
||||
\fBfatlabel\fR \- set or get MS\-DOS filesystem label
|
||||
.\" ----------------------------------------------------------------------------
|
||||
.SH SYNOPSIS
|
||||
\fBfatlabel\fR \fIDEVICE\fR [\fILABEL\fR]
|
||||
.\" ----------------------------------------------------------------------------
|
||||
.SH DESCRIPTION
|
||||
\fBfatlabel\fR set or gets a MS\-DOS filesystem label from a given device.
|
||||
.PP
|
||||
If \fILABEL\fR is omitted, then the label name of the specified device is
|
||||
written on the standard output.
|
||||
A label can't be longer than 11 bytes.
|
||||
.\" ----------------------------------------------------------------------------
|
||||
.SH OPTIONS
|
||||
.IP "\fB\-h\fR, \fB\-\-help\fR" 4
|
||||
Displays a help message.
|
||||
.IP "\fB\-V\fR, \fB\-\-version\fR" 4
|
||||
Shows version.
|
||||
.\" ----------------------------------------------------------------------------
|
||||
.SH SEE ALSO
|
||||
\fBfsck.fat\fR(8)
|
||||
.br
|
||||
\fBmkfs.fat\fR(8)
|
||||
.\" ----------------------------------------------------------------------------
|
||||
.SH HOMEPAGE
|
||||
The home for the \fBdosfstools\fR project is its
|
||||
.UR https://github.com/dosfstools/dosfstools
|
||||
GitHub project page
|
||||
.UE .
|
||||
.\" ----------------------------------------------------------------------------
|
||||
.SH AUTHORS
|
||||
\fBdosfstools\fR were written by
|
||||
.MT werner.almesberger@\:lrc.di.epfl.ch
|
||||
Werner Almesberger
|
||||
.ME ,
|
||||
.MT Roman.Hodek@\:informatik.\:uni-erlangen.de
|
||||
Roman Hodek
|
||||
.ME ,
|
||||
and others.
|
||||
The current maintainer is
|
||||
.MT aeb@\:debian.org
|
||||
Andreas Bombe
|
||||
.ME .
|
||||
@@ -0,0 +1,206 @@
|
||||
.\" fsck.fat.8 - manpage for fsck.fat
|
||||
.\"
|
||||
.\" Copyright (C) 2006-2014 Daniel Baumann <daniel@debian.org>
|
||||
.\"
|
||||
.\" 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 3 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, see <http://www.gnu.org/licenses/>.
|
||||
.\"
|
||||
.\" The complete text of the GNU General Public License
|
||||
.\" can be found in /usr/share/common-licenses/GPL-3 file.
|
||||
.\"
|
||||
.\"
|
||||
.TH FSCK.FAT 8 2015\-05\-16 3.0.28 "dosfstools"
|
||||
.SH NAME
|
||||
\fBfsck.fat\fR \- check and repair MS\-DOS filesystems
|
||||
.\" ----------------------------------------------------------------------------
|
||||
.SH SYNOPSIS
|
||||
\fBfsck.fat\fR [\fIOPTIONS\fR] \fIDEVICE\fR
|
||||
.\" ----------------------------------------------------------------------------
|
||||
.SH DESCRIPTION
|
||||
\fBfsck.fat\fR verifies the consistency of MS\-DOS filesystems and optionally
|
||||
tries to repair them.
|
||||
.PP
|
||||
The following filesystem problems can be corrected (in this order):
|
||||
.IP "*" 4
|
||||
FAT contains invalid cluster numbers.
|
||||
Cluster is changed to EOF.
|
||||
.IP "*" 4
|
||||
File's cluster chain contains a loop.
|
||||
The loop is broken.
|
||||
.IP "*" 4
|
||||
Bad clusters (read errors).
|
||||
The clusters are marked bad and they are removed from files owning them.
|
||||
This check is optional.
|
||||
.IP "*" 4
|
||||
Directories with a large number of bad entries (probably corrupt).
|
||||
The directory can be deleted.
|
||||
.IP "*" 4
|
||||
Files . and .. are non\-directories.
|
||||
They can be deleted or renamed.
|
||||
.IP "*" 4
|
||||
Directories . and .. in root directory.
|
||||
They are deleted.
|
||||
.IP "*" 4
|
||||
Bad filenames.
|
||||
They can be renamed.
|
||||
.IP "*" 4
|
||||
Duplicate directory entries.
|
||||
They can be deleted or renamed.
|
||||
.IP "*" 4
|
||||
Directories with non\-zero size field.
|
||||
Size is set to zero.
|
||||
.IP "*" 4
|
||||
Directory . does not point to parent directory.
|
||||
The start pointer is adjusted.
|
||||
.IP "*" 4
|
||||
Directory .. does not point to parent of parent directory.
|
||||
The start pointer is adjusted.
|
||||
.IP "*" 4
|
||||
Start cluster number of a file is invalid.
|
||||
The file is truncated.
|
||||
.IP "*" 4
|
||||
File contains bad or free clusters.
|
||||
The file is truncated.
|
||||
.IP "*" 4
|
||||
File's cluster chain is longer than indicated by the size fields.
|
||||
The file is truncated.
|
||||
.IP "*" 4
|
||||
Two or more files share the same cluster(s).
|
||||
All but one of the files are truncated.
|
||||
If the file being truncated is a directory file that has already been read, the
|
||||
filesystem check is restarted after truncation.
|
||||
.IP "*" 4
|
||||
File's cluster chain is shorter than indicated by the size fields.
|
||||
The file is truncated.
|
||||
.IP "*" 4
|
||||
Clusters are marked as used but are not owned by a file.
|
||||
They are marked as free.
|
||||
.PP
|
||||
Additionally, the following problems are detected, but not repaired:
|
||||
.IP "*" 4
|
||||
Invalid parameters in boot sector
|
||||
.IP "*" 4
|
||||
Absence of . and .. entries in non\-root directories
|
||||
.PP
|
||||
When \fBfsck.fat\fR checks a filesystem, it accumulates all changes in memory
|
||||
and performs them only after all checks are complete.
|
||||
This can be disabled with the \fB\-w\fR option.
|
||||
.\" ----------------------------------------------------------------------------
|
||||
.SH OPTIONS
|
||||
.IP "\fB\-a\fR" 4
|
||||
Automatically repair the filesystem.
|
||||
No user intervention is necessary.
|
||||
Whenever there is more than one method to solve a problem, the least
|
||||
destructive approach is used.
|
||||
.IP "\fB\-A\fR" 4
|
||||
Use Atari variation of the MS\-DOS filesystem.
|
||||
This is default if \fBfsck.fat\fR is run on an Atari, then this option turns
|
||||
off Atari format.
|
||||
There are some minor differences in Atari format:
|
||||
Some boot sector fields are interpreted slightly different, and the special FAT
|
||||
entries for end\-of\-file and bad cluster can be different.
|
||||
Under MS\-DOS 0xfff8 is used for EOF and Atari employs 0xffff by default, but
|
||||
both systems recognize all values from 0xfff8...0xffff as end\-of\-file.
|
||||
MS\-DOS uses only 0xfff7 for bad clusters, where on Atari values 0xfff0...0xfff7
|
||||
are for this purpose (but the standard value is still 0xfff7).
|
||||
.IP "\fB-b\fR" 4
|
||||
Make read-only boot sector check.
|
||||
.IP "\fB\-d\fR \fIPATH\fR" 4
|
||||
Delete the specified file.
|
||||
If more than one file with that name exist, the first one is deleted.
|
||||
This option can be given more than once.
|
||||
.IP "\fB\-f\fR" 4
|
||||
Salvage unused cluster chains to files.
|
||||
By default, unused clusters are added to the free disk space except in auto mode
|
||||
(\fB\-a\fR).
|
||||
.IP "\fB\-l\fR" 4
|
||||
List path names of files being processed.
|
||||
.IP "\fB\-n\fR" 4
|
||||
No\-operation mode: non\-interactively check for errors, but don't write
|
||||
anything to the filesystem.
|
||||
.IP "\fB\-p\fR" 4
|
||||
Same as \fB\-a\fR, for compatibility with other *fsck.
|
||||
.IP "\fB\-r\fR" 4
|
||||
Interactively repair the filesystem.
|
||||
The user is asked for advice whenever there is more than one approach to fix an
|
||||
inconsistency.
|
||||
This is the default mode and the option is only retained for backwards
|
||||
compatibility.
|
||||
.IP "\fB\-t\fR" 4
|
||||
Mark unreadable clusters as bad.
|
||||
.IP "\fB\-u\fR \fIPATH\fR" 4
|
||||
Try to undelete the specified file.
|
||||
\fBfsck.fat\fR tries to allocate a chain of contiguous unallocated clusters
|
||||
beginning with the start cluster of the undeleted file.
|
||||
This option can be given more than once.
|
||||
.IP "\fB\-v\fR" 4
|
||||
Verbose mode.
|
||||
Generates slightly more output.
|
||||
.IP "\fB\-V\fR" 4
|
||||
Perform a verification pass.
|
||||
The filesystem check is repeated after the first run.
|
||||
The second pass should never report any fixable errors.
|
||||
It may take considerably longer than the first pass, because the first pass may
|
||||
have generated long list of modifications that have to be scanned for each disk
|
||||
read.
|
||||
.IP "\fB\-w\fR" 4
|
||||
Write changes to disk immediately.
|
||||
.IP "\fB\-y\fR" 4
|
||||
Same as \fB\-a\fR (automatically repair filesystem) for compatibility with other
|
||||
fsck tools.
|
||||
.\" ----------------------------------------------------------------------------
|
||||
.SH "EXIT STATUS"
|
||||
.IP "0" 4
|
||||
No recoverable errors have been detected.
|
||||
.IP "1" 4
|
||||
Recoverable errors have been detected or \fBfsck.fat\fR has discovered an
|
||||
internal inconsistency.
|
||||
.IP "2" 4
|
||||
Usage error.
|
||||
\fBfsck.fat\fR did not access the filesystem.
|
||||
.\" ----------------------------------------------------------------------------
|
||||
.SH FILES
|
||||
.IP "fsck0000.rec, fsck0001.rec, ..." 4
|
||||
When recovering from a corrupted filesystem, \fBfsck.fat\fR dumps recovered data
|
||||
into files named 'fsckNNNN.rec' in the top level directory of the filesystem.
|
||||
.\" ----------------------------------------------------------------------------
|
||||
.SH BUGS
|
||||
Does not create . and .. files where necessary.
|
||||
Does not remove entirely empty directories.
|
||||
Should give more diagnostic messages.
|
||||
Undeleting files should use a more sophisticated algorithm.
|
||||
.\" ----------------------------------------------------------------------------
|
||||
.SH SEE ALSO
|
||||
\fBfatlabel\fR(8)
|
||||
.br
|
||||
\fBmkfs.fat\fR(8)
|
||||
.\" ----------------------------------------------------------------------------
|
||||
.SH HOMEPAGE
|
||||
The home for the \fBdosfstools\fR project is its
|
||||
.UR https://github.com/dosfstools/dosfstools
|
||||
GitHub project page
|
||||
.UE .
|
||||
.\" ----------------------------------------------------------------------------
|
||||
.SH AUTHORS
|
||||
\fBdosfstools\fR were written by
|
||||
.MT werner.almesberger@\:lrc.di.epfl.ch
|
||||
Werner Almesberger
|
||||
.ME ,
|
||||
.MT Roman.Hodek@\:informatik.\:uni-erlangen.de
|
||||
Roman Hodek
|
||||
.ME ,
|
||||
and others.
|
||||
The current maintainer is
|
||||
.MT aeb@\:debian.org
|
||||
Andreas Bombe
|
||||
.ME .
|
||||
@@ -0,0 +1,178 @@
|
||||
.\" mkfs.fat.8 - manpage for fs.fatck
|
||||
.\"
|
||||
.\" Copyright (C) 2006-2014 Daniel Baumann <daniel@debian.org>
|
||||
.\"
|
||||
.\" 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 3 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, see <http://www.gnu.org/licenses/>.
|
||||
.\"
|
||||
.\" The complete text of the GNU General Public License
|
||||
.\" can be found in /usr/share/common-licenses/GPL-3 file.
|
||||
.\"
|
||||
.\"
|
||||
.TH MKFS.FAT 8 2015\-05\-16 3.0.28 "dosfstools"
|
||||
.SH NAME
|
||||
\fBmkfs.fat\fR \- create an MS-DOS filesystem under Linux
|
||||
.\" ----------------------------------------------------------------------------
|
||||
.SH SYNOPSIS
|
||||
\fBmkfs.fat\fR [\fIOPTIONS\fR] \fIDEVICE\fR [\fIBLOCK-COUNT\fR]
|
||||
.\" ----------------------------------------------------------------------------
|
||||
.SH DESCRIPTION
|
||||
\fBmkfs.fat\fR is used to create an MS-DOS filesystem under Linux on a device
|
||||
(usually a disk partition).
|
||||
\fIDEVICE\fR is the special file corresponding to the device (e.g. /dev/sdXX).
|
||||
\fIBLOCK-COUNT\fR is the number of blocks on the device.
|
||||
If omitted, \fBmkfs.fat\fR automatically determines the filesystem size.
|
||||
.\" ----------------------------------------------------------------------------
|
||||
.SH OPTIONS
|
||||
.IP "\fB\-a\fR" 4
|
||||
Normally, for any filesystem except very small ones, \fBmkfs.fat\fR will align
|
||||
all the data structures to cluster size, to make sure that as long as the
|
||||
partition is properly aligned, so will all the data structures in the
|
||||
filesystem.
|
||||
This option disables alignment; this may provide a handful of additional
|
||||
clusters of storage at the expense of a significant performance degradation on
|
||||
RAIDs, flash media or large-sector hard disks.
|
||||
.IP "\fB \-A\fR" 4
|
||||
Use Atari variation of the MS-DOS filesystem.
|
||||
This is default if \fBmkfs.fat\fR is run on an Atari, then this option turns off
|
||||
Atari format.
|
||||
There are some differences when using Atari format:
|
||||
If not directed otherwise by the user, \fBmkfs.fat\fR will always use 2 sectors
|
||||
per cluster, since GEMDOS doesn't like other values very much.
|
||||
It will also obey the maximum number of sectors GEMDOS can handle.
|
||||
Larger filesystems are managed by raising the logical sector size.
|
||||
Under Atari format, an Atari-compatible serial number for the filesystem is
|
||||
generated, and a 12 bit FAT is used only for filesystems that have one of the
|
||||
usual floppy sizes (720k, 1.2M, 1.44M, 2.88M), a 16 bit FAT otherwise.
|
||||
This can be overridden with the \fB\-F\fR option.
|
||||
Some PC-specific boot sector fields aren't written, and a boot message (option
|
||||
\fB\-m\fR) is ignored.
|
||||
.IP "\fB\-b\fR \fISECTOR-OF-BACKUP\fR" 4
|
||||
Selects the location of the backup boot sector for FAT32.
|
||||
Default depends on number of reserved sectors, but usually is sector 6.
|
||||
The backup must be within the range of reserved sectors.
|
||||
.IP "\fB\-c" 4
|
||||
Check the device for bad blocks before creating the filesystem.
|
||||
.IP "\fB\-C\fR" 4
|
||||
Create the file given as \fIDEVICE\fR on the command line, and write the
|
||||
to-be-created filesystem to it.
|
||||
This can be used to create the new filesystem in a file instead of on a real
|
||||
device, and to avoid using \fBdd\fR in advance to create a file of appropriate
|
||||
size.
|
||||
With this option, the \fIBLOCK-COUNT\fR must be given, because otherwise the
|
||||
intended size of the filesystem wouldn't be known.
|
||||
The file created is a sparse file, which actually only contains the meta-data
|
||||
areas (boot sector, FATs, and root directory).
|
||||
The data portions won't be stored on the disk, but the file nevertheless will
|
||||
have the correct size.
|
||||
The resulting file can be copied later to a floppy disk or other device, or
|
||||
mounted through a loop device.
|
||||
.IP "\fB\-D\fR \fIDRIVE-NUMBER\fR" 4
|
||||
Specify the BIOS drive number to be stored in the FAT boot sector.
|
||||
This value is usually 0x80 for hard disks and 0x00 for floppy devices or
|
||||
partitions to be used for floppy emulation.
|
||||
.IP "\fB\-f\fR \fINUMBER-OF-FATS\fR" 4
|
||||
Specify the number of file allocation tables in the filesystem.
|
||||
The default is 2.
|
||||
.IP "\fB\-F\fR \fIFAT-SIZE\fR" 4
|
||||
Specifies the type of file allocation tables used (12, 16 or 32 bit).
|
||||
If nothing is specified, \fBmkfs.fat\fR will automatically select between 12, 16
|
||||
and 32 bit, whatever fits better for the filesystem size.
|
||||
.IP "\fB\-h\fR \fINUMBER-OF-HIDDEN-SECTORS\fR" 4
|
||||
Select the number of hidden sectors in the volume.
|
||||
Apparently some digital cameras get indigestion if you feed them a CF card
|
||||
without such hidden sectors, this option allows you to satisfy them.
|
||||
.IP "\fB\-i\fR \fIVOLUME-ID\fR" 4
|
||||
Sets the volume ID of the newly created filesystem; \fIVOLUME-ID\fR is a 32-bit
|
||||
hexadecimal number (for example, 2e24ec82).
|
||||
The default is a number which depends on the filesystem creation time.
|
||||
.IP "\fB\-I\fR" 4
|
||||
It is typical for fixed disk devices to be partitioned so, by default, you are
|
||||
not permitted to create a filesystem across the entire device.
|
||||
\fBmkfs.fat\fR will complain and tell you that it refuses to work.
|
||||
This is different when using MO disks.
|
||||
One doesn't always need partitions on MO disks.
|
||||
The filesystem can go directly to the whole disk.
|
||||
Under other OSes this is known as the 'superfloppy' format.
|
||||
This switch will force \fBmkfs.fat\fR to work properly.
|
||||
.IP "\fB\-l\fR \fIFILENAME\fR" 4
|
||||
Read the bad blocks list from \fIFILENAME\fR.
|
||||
.IP "\fB\-m\fR \fIMESSAGE-FILE\fR" 4
|
||||
Sets the message the user receives on attempts to boot this filesystem without
|
||||
having properly installed an operating system.
|
||||
The message file must not exceed 418 bytes once line feeds have been converted
|
||||
to carriage return-line feed combinations, and tabs have been expanded.
|
||||
If the filename is a hyphen (-), the text is taken from standard input.
|
||||
.IP "\fB\-M\fR \fIFAT-MEDIA-TYPE\fR" 4
|
||||
Specify the media type to be stored in the FAT boot sector.
|
||||
This value is usually 0xF8 for hard disks and is 0xF0 or a value from 0xF9 to
|
||||
0xFF for floppies or partitions to be used for floppy emulation.
|
||||
.IP "\fB\-n\fR \fIVOLUME-NAME\fR" 4
|
||||
Sets the volume name (label) of the filesystem.
|
||||
The volume name can be up to 11 characters long.
|
||||
The default is no label.
|
||||
.IP "\fB\-r\fR \fIROOT-DIR-ENTRIES\fR" 4
|
||||
Select the number of entries available in the root directory.
|
||||
The default is 112 or 224 for floppies and 512 for hard disks.
|
||||
.IP "\fB\-R\fR \fINUMBER-OF-RESERVED-SECTORS\fR" 4
|
||||
Select the number of reserved sectors.
|
||||
With FAT32 format at least 2 reserved sectors are needed, the default is 32.
|
||||
Otherwise the default is 1 (only the boot sector).
|
||||
.IP "\fB\-s\fR \fISECTORS-PER-CLUSTER\fR" 4
|
||||
Specify the number of disk sectors per cluster.
|
||||
Must be a power of 2, i.e. 1, 2, 4, 8, ... 128.
|
||||
.IP "\fB\-S\fR \fILOGICAL-SECTOR-SIZE\fR" 4
|
||||
Specify the number of bytes per logical sector.
|
||||
Must be a power of 2 and greater than or equal to 512, i.e. 512, 1024, 2048,
|
||||
4096, 8192, 16384, or 32768.
|
||||
.IP "\fB\-v\fR" 4
|
||||
Verbose execution.
|
||||
.IP "\fB\-\-invariant\fR" 4
|
||||
Use constants for normally randomly generated or time based data such as
|
||||
volume ID and creation time.
|
||||
Multiple runs of \fBmkfs.fat\fR on the same device create identical results
|
||||
with this option.
|
||||
Its main purpose is testing \fBmkfs.fat\fR.
|
||||
.IP "\fB\-\-help\fR" 4
|
||||
Display option summary and exit.
|
||||
.\" ----------------------------------------------------------------------------
|
||||
.SH BUGS
|
||||
\fBmkfs.fat\fR can not create boot-able filesystems.
|
||||
This isn't as easy as you might think at first glance for various reasons and
|
||||
has been discussed a lot already.
|
||||
\fBmkfs.fat\fR simply will not support it ;)
|
||||
.\" ----------------------------------------------------------------------------
|
||||
.SH SEE ALSO
|
||||
\fBfatlabel\fR(8)
|
||||
.br
|
||||
\fBfsck.fat\fR(8)
|
||||
.\" ----------------------------------------------------------------------------
|
||||
.SH HOMEPAGE
|
||||
The home for the \fBdosfstools\fR project is its
|
||||
.UR https://github.com/dosfstools/dosfstools
|
||||
GitHub project page
|
||||
.UE .
|
||||
.\" ----------------------------------------------------------------------------
|
||||
.SH AUTHORS
|
||||
\fBdosfstools\fR were written by
|
||||
.MT werner.almesberger@\:lrc.di.epfl.ch
|
||||
Werner Almesberger
|
||||
.ME ,
|
||||
.MT Roman.Hodek@\:informatik.\:uni-erlangen.de
|
||||
Roman Hodek
|
||||
.ME ,
|
||||
and others.
|
||||
The current maintainer is
|
||||
.MT aeb@\:debian.org
|
||||
Andreas Bombe
|
||||
.ME .
|
||||
@@ -0,0 +1,173 @@
|
||||
# German translations for dosfstools package
|
||||
#
|
||||
msgid ""
|
||||
msgstr ""
|
||||
"Project-Id-Version: dosfstools VERSION\n"
|
||||
"POT-Creation-Date: 2015-05-16 00:40+0200\n"
|
||||
"PO-Revision-Date: 2013-06-06 09:34+0300\n"
|
||||
"Last-Translator: Automatically generated\n"
|
||||
"Language-Team: none\n"
|
||||
"Language: de\n"
|
||||
"MIME-Version: 1.0\n"
|
||||
"Content-Type: text/plain; charset=ASCII\n"
|
||||
"Content-Transfer-Encoding: 8bit\n"
|
||||
"Plural-Forms: nplurals=2; plural=(n != 1);\n"
|
||||
|
||||
#. type: TH
|
||||
#: en/fatlabel.8:22
|
||||
#, no-wrap
|
||||
msgid "FATLABEL"
|
||||
msgstr ""
|
||||
|
||||
#. type: TH
|
||||
#: en/fatlabel.8:22 en/fsck.fat.8:22 en/mkfs.fat.8:22
|
||||
#, no-wrap
|
||||
msgid "2015-05-16"
|
||||
msgstr ""
|
||||
|
||||
#. type: TH
|
||||
#: en/fatlabel.8:22 en/fsck.fat.8:22 en/mkfs.fat.8:22
|
||||
#, no-wrap
|
||||
msgid "3.0.28"
|
||||
msgstr ""
|
||||
|
||||
#. type: TH
|
||||
#: en/fatlabel.8:22 en/fsck.fat.8:22 en/mkfs.fat.8:22
|
||||
#, no-wrap
|
||||
msgid "dosfstools"
|
||||
msgstr ""
|
||||
|
||||
#. type: SH
|
||||
#: en/fatlabel.8:23 en/fsck.fat.8:23 en/mkfs.fat.8:23
|
||||
#, no-wrap
|
||||
msgid "NAME"
|
||||
msgstr ""
|
||||
|
||||
#. ----------------------------------------------------------------------------
|
||||
#. type: Plain text
|
||||
#: en/fatlabel.8:26
|
||||
msgid "B<fatlabel> - set or get MS-DOS filesystem label"
|
||||
msgstr ""
|
||||
|
||||
#. type: SH
|
||||
#: en/fatlabel.8:26 en/fsck.fat.8:26 en/mkfs.fat.8:26
|
||||
#, no-wrap
|
||||
msgid "SYNOPSIS"
|
||||
msgstr ""
|
||||
|
||||
#. ----------------------------------------------------------------------------
|
||||
#. type: Plain text
|
||||
#: en/fatlabel.8:29
|
||||
msgid "B<fatlabel> I<DEVICE> [I<LABEL>]"
|
||||
msgstr ""
|
||||
|
||||
#. type: SH
|
||||
#: en/fatlabel.8:29 en/fsck.fat.8:29 en/mkfs.fat.8:29
|
||||
#, no-wrap
|
||||
msgid "DESCRIPTION"
|
||||
msgstr ""
|
||||
|
||||
#. type: Plain text
|
||||
#: en/fatlabel.8:31
|
||||
msgid "B<fatlabel> set or gets a MS-DOS filesystem label from a given device."
|
||||
msgstr ""
|
||||
|
||||
#. ----------------------------------------------------------------------------
|
||||
#. type: Plain text
|
||||
#: en/fatlabel.8:36
|
||||
msgid ""
|
||||
"If I<LABEL> is omitted, then the label name of the specified device is "
|
||||
"written on the standard output. A label can't be longer than 11 bytes."
|
||||
msgstr ""
|
||||
|
||||
#. type: SH
|
||||
#: en/fatlabel.8:36 en/fsck.fat.8:99 en/mkfs.fat.8:36
|
||||
#, no-wrap
|
||||
msgid "OPTIONS"
|
||||
msgstr ""
|
||||
|
||||
#. type: IP
|
||||
#: en/fatlabel.8:37
|
||||
#, no-wrap
|
||||
msgid "B<-h>, B<--help>"
|
||||
msgstr ""
|
||||
|
||||
#. type: Plain text
|
||||
#: en/fatlabel.8:39
|
||||
msgid "Displays a help message."
|
||||
msgstr ""
|
||||
|
||||
#. type: IP
|
||||
#: en/fatlabel.8:39
|
||||
#, no-wrap
|
||||
msgid "B<-V>, B<--version>"
|
||||
msgstr ""
|
||||
|
||||
#. ----------------------------------------------------------------------------
|
||||
#. type: Plain text
|
||||
#: en/fatlabel.8:42
|
||||
msgid "Shows version."
|
||||
msgstr ""
|
||||
|
||||
#. type: SH
|
||||
#: en/fatlabel.8:42 en/fsck.fat.8:183 en/mkfs.fat.8:155
|
||||
#, no-wrap
|
||||
msgid "SEE ALSO"
|
||||
msgstr ""
|
||||
|
||||
#. ----------------------------------------------------------------------------
|
||||
#. type: Plain text
|
||||
#: en/fatlabel.8:44 en/mkfs.fat.8:160
|
||||
msgid "B<fsck.fat>(8)"
|
||||
msgstr ""
|
||||
|
||||
#. ----------------------------------------------------------------------------
|
||||
#. type: Plain text
|
||||
#: en/fatlabel.8:47 en/fsck.fat.8:188
|
||||
msgid "B<mkfs.fat>(8)"
|
||||
msgstr ""
|
||||
|
||||
#. type: SH
|
||||
#: en/fatlabel.8:47 en/fsck.fat.8:188 en/mkfs.fat.8:160
|
||||
#, no-wrap
|
||||
msgid "HOMEPAGE"
|
||||
msgstr ""
|
||||
|
||||
#. ----------------------------------------------------------------------------
|
||||
#. type: Plain text
|
||||
#: en/fatlabel.8:53 en/fsck.fat.8:194 en/mkfs.fat.8:166
|
||||
msgid ""
|
||||
"The home for the B<dosfstools> project is its E<.UR https://github.com/"
|
||||
"dosfstools/dosfstools> GitHub project page E<.UE .>"
|
||||
msgstr ""
|
||||
|
||||
#. type: SH
|
||||
#: en/fatlabel.8:53 en/fsck.fat.8:194 en/mkfs.fat.8:166
|
||||
#, no-wrap
|
||||
msgid "AUTHORS"
|
||||
msgstr ""
|
||||
|
||||
#. type: Plain text
|
||||
#: en/fatlabel.8:55 en/fsck.fat.8:196 en/mkfs.fat.8:168
|
||||
msgid "B<dosfstools> were written by"
|
||||
msgstr ""
|
||||
|
||||
#. type: Plain text
|
||||
#: en/fatlabel.8:57 en/fsck.fat.8:198 en/mkfs.fat.8:170
|
||||
msgid "Werner Almesberger"
|
||||
msgstr ""
|
||||
|
||||
#. type: Plain text
|
||||
#: en/fatlabel.8:60 en/fsck.fat.8:201 en/mkfs.fat.8:173
|
||||
msgid "Roman Hodek"
|
||||
msgstr ""
|
||||
|
||||
#. type: Plain text
|
||||
#: en/fatlabel.8:63 en/fsck.fat.8:204 en/mkfs.fat.8:176
|
||||
msgid "and others. The current maintainer is"
|
||||
msgstr ""
|
||||
|
||||
#. type: Plain text
|
||||
#: en/fatlabel.8:65 en/fsck.fat.8:206 en/mkfs.fat.8:178
|
||||
msgid "Andreas Bombe"
|
||||
msgstr ""
|
||||
@@ -0,0 +1,559 @@
|
||||
# German translations for dosfstools package
|
||||
#
|
||||
msgid ""
|
||||
msgstr ""
|
||||
"Project-Id-Version: dosfstools VERSION\n"
|
||||
"POT-Creation-Date: 2015-05-16 00:40+0200\n"
|
||||
"PO-Revision-Date: 2013-06-06 09:34+0300\n"
|
||||
"Last-Translator: Automatically generated\n"
|
||||
"Language-Team: none\n"
|
||||
"Language: de\n"
|
||||
"MIME-Version: 1.0\n"
|
||||
"Content-Type: text/plain; charset=ASCII\n"
|
||||
"Content-Transfer-Encoding: 8bit\n"
|
||||
"Plural-Forms: nplurals=2; plural=(n != 1);\n"
|
||||
|
||||
#. type: TH
|
||||
#: en/fatlabel.8:22 en/fsck.fat.8:22 en/mkfs.fat.8:22
|
||||
#, no-wrap
|
||||
msgid "2015-05-16"
|
||||
msgstr ""
|
||||
|
||||
#. type: TH
|
||||
#: en/fatlabel.8:22 en/fsck.fat.8:22 en/mkfs.fat.8:22
|
||||
#, no-wrap
|
||||
msgid "3.0.28"
|
||||
msgstr ""
|
||||
|
||||
#. type: TH
|
||||
#: en/fatlabel.8:22 en/fsck.fat.8:22 en/mkfs.fat.8:22
|
||||
#, no-wrap
|
||||
msgid "dosfstools"
|
||||
msgstr ""
|
||||
|
||||
#. type: SH
|
||||
#: en/fatlabel.8:23 en/fsck.fat.8:23 en/mkfs.fat.8:23
|
||||
#, no-wrap
|
||||
msgid "NAME"
|
||||
msgstr ""
|
||||
|
||||
#. type: SH
|
||||
#: en/fatlabel.8:26 en/fsck.fat.8:26 en/mkfs.fat.8:26
|
||||
#, no-wrap
|
||||
msgid "SYNOPSIS"
|
||||
msgstr ""
|
||||
|
||||
#. type: SH
|
||||
#: en/fatlabel.8:29 en/fsck.fat.8:29 en/mkfs.fat.8:29
|
||||
#, no-wrap
|
||||
msgid "DESCRIPTION"
|
||||
msgstr ""
|
||||
|
||||
#. type: SH
|
||||
#: en/fatlabel.8:36 en/fsck.fat.8:99 en/mkfs.fat.8:36
|
||||
#, no-wrap
|
||||
msgid "OPTIONS"
|
||||
msgstr ""
|
||||
|
||||
#. type: SH
|
||||
#: en/fatlabel.8:42 en/fsck.fat.8:183 en/mkfs.fat.8:155
|
||||
#, no-wrap
|
||||
msgid "SEE ALSO"
|
||||
msgstr ""
|
||||
|
||||
#. ----------------------------------------------------------------------------
|
||||
#. type: Plain text
|
||||
#: en/fatlabel.8:47 en/fsck.fat.8:188
|
||||
msgid "B<mkfs.fat>(8)"
|
||||
msgstr ""
|
||||
|
||||
#. type: SH
|
||||
#: en/fatlabel.8:47 en/fsck.fat.8:188 en/mkfs.fat.8:160
|
||||
#, no-wrap
|
||||
msgid "HOMEPAGE"
|
||||
msgstr ""
|
||||
|
||||
#. ----------------------------------------------------------------------------
|
||||
#. type: Plain text
|
||||
#: en/fatlabel.8:53 en/fsck.fat.8:194 en/mkfs.fat.8:166
|
||||
msgid ""
|
||||
"The home for the B<dosfstools> project is its E<.UR https://github.com/"
|
||||
"dosfstools/dosfstools> GitHub project page E<.UE .>"
|
||||
msgstr ""
|
||||
|
||||
#. type: SH
|
||||
#: en/fatlabel.8:53 en/fsck.fat.8:194 en/mkfs.fat.8:166
|
||||
#, no-wrap
|
||||
msgid "AUTHORS"
|
||||
msgstr ""
|
||||
|
||||
#. type: Plain text
|
||||
#: en/fatlabel.8:55 en/fsck.fat.8:196 en/mkfs.fat.8:168
|
||||
msgid "B<dosfstools> were written by"
|
||||
msgstr ""
|
||||
|
||||
#. type: Plain text
|
||||
#: en/fatlabel.8:57 en/fsck.fat.8:198 en/mkfs.fat.8:170
|
||||
msgid "Werner Almesberger"
|
||||
msgstr ""
|
||||
|
||||
#. type: Plain text
|
||||
#: en/fatlabel.8:60 en/fsck.fat.8:201 en/mkfs.fat.8:173
|
||||
msgid "Roman Hodek"
|
||||
msgstr ""
|
||||
|
||||
#. type: Plain text
|
||||
#: en/fatlabel.8:63 en/fsck.fat.8:204 en/mkfs.fat.8:176
|
||||
msgid "and others. The current maintainer is"
|
||||
msgstr ""
|
||||
|
||||
#. type: Plain text
|
||||
#: en/fatlabel.8:65 en/fsck.fat.8:206 en/mkfs.fat.8:178
|
||||
msgid "Andreas Bombe"
|
||||
msgstr ""
|
||||
|
||||
#. type: TH
|
||||
#: en/fsck.fat.8:22
|
||||
#, no-wrap
|
||||
msgid "FSCK.FAT"
|
||||
msgstr ""
|
||||
|
||||
#. ----------------------------------------------------------------------------
|
||||
#. type: Plain text
|
||||
#: en/fsck.fat.8:26
|
||||
msgid "B<fsck.fat> - check and repair MS-DOS filesystems"
|
||||
msgstr ""
|
||||
|
||||
#. ----------------------------------------------------------------------------
|
||||
#. type: Plain text
|
||||
#: en/fsck.fat.8:29
|
||||
msgid "B<fsck.fat> [I<OPTIONS>] I<DEVICE>"
|
||||
msgstr ""
|
||||
|
||||
#. type: Plain text
|
||||
#: en/fsck.fat.8:32
|
||||
msgid ""
|
||||
"B<fsck.fat> verifies the consistency of MS-DOS filesystems and optionally "
|
||||
"tries to repair them."
|
||||
msgstr ""
|
||||
|
||||
#. type: Plain text
|
||||
#: en/fsck.fat.8:34
|
||||
msgid "The following filesystem problems can be corrected (in this order):"
|
||||
msgstr ""
|
||||
|
||||
#. type: IP
|
||||
#: en/fsck.fat.8:34 en/fsck.fat.8:37 en/fsck.fat.8:40 en/fsck.fat.8:44
|
||||
#: en/fsck.fat.8:47 en/fsck.fat.8:50 en/fsck.fat.8:53 en/fsck.fat.8:56
|
||||
#: en/fsck.fat.8:59 en/fsck.fat.8:62 en/fsck.fat.8:65 en/fsck.fat.8:68
|
||||
#: en/fsck.fat.8:71 en/fsck.fat.8:74 en/fsck.fat.8:77 en/fsck.fat.8:82
|
||||
#: en/fsck.fat.8:85 en/fsck.fat.8:90 en/fsck.fat.8:92
|
||||
#, no-wrap
|
||||
msgid "*"
|
||||
msgstr ""
|
||||
|
||||
#. type: Plain text
|
||||
#: en/fsck.fat.8:37
|
||||
msgid "FAT contains invalid cluster numbers. Cluster is changed to EOF."
|
||||
msgstr ""
|
||||
|
||||
#. type: Plain text
|
||||
#: en/fsck.fat.8:40
|
||||
msgid "File's cluster chain contains a loop. The loop is broken."
|
||||
msgstr ""
|
||||
|
||||
#. type: Plain text
|
||||
#: en/fsck.fat.8:44
|
||||
msgid ""
|
||||
"Bad clusters (read errors). The clusters are marked bad and they are "
|
||||
"removed from files owning them. This check is optional."
|
||||
msgstr ""
|
||||
|
||||
#. type: Plain text
|
||||
#: en/fsck.fat.8:47
|
||||
msgid ""
|
||||
"Directories with a large number of bad entries (probably corrupt). The "
|
||||
"directory can be deleted."
|
||||
msgstr ""
|
||||
|
||||
#. type: Plain text
|
||||
#: en/fsck.fat.8:50
|
||||
msgid "Files . and .. are non-directories. They can be deleted or renamed."
|
||||
msgstr ""
|
||||
|
||||
#. type: Plain text
|
||||
#: en/fsck.fat.8:53
|
||||
msgid "Directories . and .. in root directory. They are deleted."
|
||||
msgstr ""
|
||||
|
||||
#. type: Plain text
|
||||
#: en/fsck.fat.8:56
|
||||
msgid "Bad filenames. They can be renamed."
|
||||
msgstr ""
|
||||
|
||||
#. type: Plain text
|
||||
#: en/fsck.fat.8:59
|
||||
msgid "Duplicate directory entries. They can be deleted or renamed."
|
||||
msgstr ""
|
||||
|
||||
#. type: Plain text
|
||||
#: en/fsck.fat.8:62
|
||||
msgid "Directories with non-zero size field. Size is set to zero."
|
||||
msgstr ""
|
||||
|
||||
#. type: Plain text
|
||||
#: en/fsck.fat.8:65
|
||||
msgid ""
|
||||
"Directory . does not point to parent directory. The start pointer is "
|
||||
"adjusted."
|
||||
msgstr ""
|
||||
|
||||
#. type: Plain text
|
||||
#: en/fsck.fat.8:68
|
||||
msgid ""
|
||||
"Directory .. does not point to parent of parent directory. The start "
|
||||
"pointer is adjusted."
|
||||
msgstr ""
|
||||
|
||||
#. type: Plain text
|
||||
#: en/fsck.fat.8:71
|
||||
msgid "Start cluster number of a file is invalid. The file is truncated."
|
||||
msgstr ""
|
||||
|
||||
#. type: Plain text
|
||||
#: en/fsck.fat.8:74
|
||||
msgid "File contains bad or free clusters. The file is truncated."
|
||||
msgstr ""
|
||||
|
||||
#. type: Plain text
|
||||
#: en/fsck.fat.8:77
|
||||
msgid ""
|
||||
"File's cluster chain is longer than indicated by the size fields. The file "
|
||||
"is truncated."
|
||||
msgstr ""
|
||||
|
||||
#. type: Plain text
|
||||
#: en/fsck.fat.8:82
|
||||
msgid ""
|
||||
"Two or more files share the same cluster(s). All but one of the files are "
|
||||
"truncated. If the file being truncated is a directory file that has already "
|
||||
"been read, the filesystem check is restarted after truncation."
|
||||
msgstr ""
|
||||
|
||||
#. type: Plain text
|
||||
#: en/fsck.fat.8:85
|
||||
msgid ""
|
||||
"File's cluster chain is shorter than indicated by the size fields. The file "
|
||||
"is truncated."
|
||||
msgstr ""
|
||||
|
||||
#. type: Plain text
|
||||
#: en/fsck.fat.8:88
|
||||
msgid ""
|
||||
"Clusters are marked as used but are not owned by a file. They are marked as "
|
||||
"free."
|
||||
msgstr ""
|
||||
|
||||
#. type: Plain text
|
||||
#: en/fsck.fat.8:90
|
||||
msgid "Additionally, the following problems are detected, but not repaired:"
|
||||
msgstr ""
|
||||
|
||||
#. type: Plain text
|
||||
#: en/fsck.fat.8:92
|
||||
msgid "Invalid parameters in boot sector"
|
||||
msgstr ""
|
||||
|
||||
#. type: Plain text
|
||||
#: en/fsck.fat.8:94
|
||||
msgid "Absence of . and .. entries in non-root directories"
|
||||
msgstr ""
|
||||
|
||||
#. ----------------------------------------------------------------------------
|
||||
#. type: Plain text
|
||||
#: en/fsck.fat.8:99
|
||||
msgid ""
|
||||
"When B<fsck.fat> checks a filesystem, it accumulates all changes in memory "
|
||||
"and performs them only after all checks are complete. This can be disabled "
|
||||
"with the B<-w> option."
|
||||
msgstr ""
|
||||
|
||||
#. type: IP
|
||||
#: en/fsck.fat.8:100 en/mkfs.fat.8:37
|
||||
#, no-wrap
|
||||
msgid "B<-a>"
|
||||
msgstr ""
|
||||
|
||||
#. type: Plain text
|
||||
#: en/fsck.fat.8:105
|
||||
msgid ""
|
||||
"Automatically repair the filesystem. No user intervention is necessary. "
|
||||
"Whenever there is more than one method to solve a problem, the least "
|
||||
"destructive approach is used."
|
||||
msgstr ""
|
||||
|
||||
#. type: IP
|
||||
#: en/fsck.fat.8:105
|
||||
#, no-wrap
|
||||
msgid "B<-A>"
|
||||
msgstr ""
|
||||
|
||||
#. type: Plain text
|
||||
#: en/fsck.fat.8:116
|
||||
msgid ""
|
||||
"Use Atari variation of the MS-DOS filesystem. This is default if B<fsck."
|
||||
"fat> is run on an Atari, then this option turns off Atari format. There are "
|
||||
"some minor differences in Atari format: Some boot sector fields are "
|
||||
"interpreted slightly different, and the special FAT entries for end-of-file "
|
||||
"and bad cluster can be different. Under MS-DOS 0xfff8 is used for EOF and "
|
||||
"Atari employs 0xffff by default, but both systems recognize all values from "
|
||||
"0xfff8...0xffff as end-of-file. MS-DOS uses only 0xfff7 for bad clusters, "
|
||||
"where on Atari values 0xfff0...0xfff7 are for this purpose (but the standard "
|
||||
"value is still 0xfff7)."
|
||||
msgstr ""
|
||||
|
||||
#. type: IP
|
||||
#: en/fsck.fat.8:116
|
||||
#, no-wrap
|
||||
msgid "B<-b>"
|
||||
msgstr ""
|
||||
|
||||
#. type: Plain text
|
||||
#: en/fsck.fat.8:118
|
||||
msgid "Make read-only boot sector check."
|
||||
msgstr ""
|
||||
|
||||
#. type: IP
|
||||
#: en/fsck.fat.8:118
|
||||
#, no-wrap
|
||||
msgid "B<-d> I<PATH>"
|
||||
msgstr ""
|
||||
|
||||
#. type: Plain text
|
||||
#: en/fsck.fat.8:122
|
||||
msgid ""
|
||||
"Delete the specified file. If more than one file with that name exist, the "
|
||||
"first one is deleted. This option can be given more than once."
|
||||
msgstr ""
|
||||
|
||||
#. type: IP
|
||||
#: en/fsck.fat.8:122
|
||||
#, no-wrap
|
||||
msgid "B<-f>"
|
||||
msgstr ""
|
||||
|
||||
#. type: Plain text
|
||||
#: en/fsck.fat.8:126
|
||||
msgid ""
|
||||
"Salvage unused cluster chains to files. By default, unused clusters are "
|
||||
"added to the free disk space except in auto mode (B<-a>)."
|
||||
msgstr ""
|
||||
|
||||
#. type: IP
|
||||
#: en/fsck.fat.8:126
|
||||
#, no-wrap
|
||||
msgid "B<-l>"
|
||||
msgstr ""
|
||||
|
||||
#. type: Plain text
|
||||
#: en/fsck.fat.8:128
|
||||
msgid "List path names of files being processed."
|
||||
msgstr ""
|
||||
|
||||
#. type: IP
|
||||
#: en/fsck.fat.8:128
|
||||
#, no-wrap
|
||||
msgid "B<-n>"
|
||||
msgstr ""
|
||||
|
||||
#. type: Plain text
|
||||
#: en/fsck.fat.8:131
|
||||
msgid ""
|
||||
"No-operation mode: non-interactively check for errors, but don't write "
|
||||
"anything to the filesystem."
|
||||
msgstr ""
|
||||
|
||||
#. type: IP
|
||||
#: en/fsck.fat.8:131
|
||||
#, no-wrap
|
||||
msgid "B<-p>"
|
||||
msgstr ""
|
||||
|
||||
#. type: Plain text
|
||||
#: en/fsck.fat.8:133
|
||||
msgid "Same as B<-a>, for compatibility with other *fsck."
|
||||
msgstr ""
|
||||
|
||||
#. type: IP
|
||||
#: en/fsck.fat.8:133
|
||||
#, no-wrap
|
||||
msgid "B<-r>"
|
||||
msgstr ""
|
||||
|
||||
#. type: Plain text
|
||||
#: en/fsck.fat.8:139
|
||||
msgid ""
|
||||
"Interactively repair the filesystem. The user is asked for advice whenever "
|
||||
"there is more than one approach to fix an inconsistency. This is the "
|
||||
"default mode and the option is only retained for backwards compatibility."
|
||||
msgstr ""
|
||||
|
||||
#. type: IP
|
||||
#: en/fsck.fat.8:139
|
||||
#, no-wrap
|
||||
msgid "B<-t>"
|
||||
msgstr ""
|
||||
|
||||
#. type: Plain text
|
||||
#: en/fsck.fat.8:141
|
||||
msgid "Mark unreadable clusters as bad."
|
||||
msgstr ""
|
||||
|
||||
#. type: IP
|
||||
#: en/fsck.fat.8:141
|
||||
#, no-wrap
|
||||
msgid "B<-u> I<PATH>"
|
||||
msgstr ""
|
||||
|
||||
#. type: Plain text
|
||||
#: en/fsck.fat.8:146
|
||||
msgid ""
|
||||
"Try to undelete the specified file. B<fsck.fat> tries to allocate a chain "
|
||||
"of contiguous unallocated clusters beginning with the start cluster of the "
|
||||
"undeleted file. This option can be given more than once."
|
||||
msgstr ""
|
||||
|
||||
#. type: IP
|
||||
#: en/fsck.fat.8:146 en/mkfs.fat.8:138
|
||||
#, no-wrap
|
||||
msgid "B<-v>"
|
||||
msgstr ""
|
||||
|
||||
#. type: Plain text
|
||||
#: en/fsck.fat.8:149
|
||||
msgid "Verbose mode. Generates slightly more output."
|
||||
msgstr ""
|
||||
|
||||
#. type: IP
|
||||
#: en/fsck.fat.8:149
|
||||
#, no-wrap
|
||||
msgid "B<-V>"
|
||||
msgstr ""
|
||||
|
||||
#. type: Plain text
|
||||
#: en/fsck.fat.8:156
|
||||
msgid ""
|
||||
"Perform a verification pass. The filesystem check is repeated after the "
|
||||
"first run. The second pass should never report any fixable errors. It may "
|
||||
"take considerably longer than the first pass, because the first pass may "
|
||||
"have generated long list of modifications that have to be scanned for each "
|
||||
"disk read."
|
||||
msgstr ""
|
||||
|
||||
#. type: IP
|
||||
#: en/fsck.fat.8:156
|
||||
#, no-wrap
|
||||
msgid "B<-w>"
|
||||
msgstr ""
|
||||
|
||||
#. type: Plain text
|
||||
#: en/fsck.fat.8:158
|
||||
msgid "Write changes to disk immediately."
|
||||
msgstr ""
|
||||
|
||||
#. type: IP
|
||||
#: en/fsck.fat.8:158
|
||||
#, no-wrap
|
||||
msgid "B<-y>"
|
||||
msgstr ""
|
||||
|
||||
#. ----------------------------------------------------------------------------
|
||||
#. type: Plain text
|
||||
#: en/fsck.fat.8:162
|
||||
msgid ""
|
||||
"Same as B<-a> (automatically repair filesystem) for compatibility with other "
|
||||
"fsck tools."
|
||||
msgstr ""
|
||||
|
||||
#. type: SH
|
||||
#: en/fsck.fat.8:162
|
||||
#, no-wrap
|
||||
msgid "EXIT STATUS"
|
||||
msgstr ""
|
||||
|
||||
#. type: IP
|
||||
#: en/fsck.fat.8:163
|
||||
#, no-wrap
|
||||
msgid "0"
|
||||
msgstr ""
|
||||
|
||||
#. type: Plain text
|
||||
#: en/fsck.fat.8:165
|
||||
msgid "No recoverable errors have been detected."
|
||||
msgstr ""
|
||||
|
||||
#. type: IP
|
||||
#: en/fsck.fat.8:165
|
||||
#, no-wrap
|
||||
msgid "1"
|
||||
msgstr ""
|
||||
|
||||
#. type: Plain text
|
||||
#: en/fsck.fat.8:168
|
||||
msgid ""
|
||||
"Recoverable errors have been detected or B<fsck.fat> has discovered an "
|
||||
"internal inconsistency."
|
||||
msgstr ""
|
||||
|
||||
#. type: IP
|
||||
#: en/fsck.fat.8:168
|
||||
#, no-wrap
|
||||
msgid "2"
|
||||
msgstr ""
|
||||
|
||||
#. ----------------------------------------------------------------------------
|
||||
#. type: Plain text
|
||||
#: en/fsck.fat.8:172
|
||||
msgid "Usage error. B<fsck.fat> did not access the filesystem."
|
||||
msgstr ""
|
||||
|
||||
#. type: SH
|
||||
#: en/fsck.fat.8:172
|
||||
#, no-wrap
|
||||
msgid "FILES"
|
||||
msgstr ""
|
||||
|
||||
#. type: IP
|
||||
#: en/fsck.fat.8:173
|
||||
#, no-wrap
|
||||
msgid "fsck0000.rec, fsck0001.rec, ..."
|
||||
msgstr ""
|
||||
|
||||
#. ----------------------------------------------------------------------------
|
||||
#. type: Plain text
|
||||
#: en/fsck.fat.8:177
|
||||
msgid ""
|
||||
"When recovering from a corrupted filesystem, B<fsck.fat> dumps recovered "
|
||||
"data into files named 'fsckNNNN.rec' in the top level directory of the "
|
||||
"filesystem."
|
||||
msgstr ""
|
||||
|
||||
#. type: SH
|
||||
#: en/fsck.fat.8:177 en/mkfs.fat.8:149
|
||||
#, no-wrap
|
||||
msgid "BUGS"
|
||||
msgstr ""
|
||||
|
||||
#. ----------------------------------------------------------------------------
|
||||
#. type: Plain text
|
||||
#: en/fsck.fat.8:183
|
||||
msgid ""
|
||||
"Does not create . and .. files where necessary. Does not remove entirely "
|
||||
"empty directories. Should give more diagnostic messages. Undeleting files "
|
||||
"should use a more sophisticated algorithm."
|
||||
msgstr ""
|
||||
|
||||
#. type: Plain text
|
||||
#: en/fsck.fat.8:185 en/mkfs.fat.8:157
|
||||
msgid "B<fatlabel>(8)"
|
||||
msgstr ""
|
||||
@@ -0,0 +1,481 @@
|
||||
# German translations for dosfstools package
|
||||
#
|
||||
msgid ""
|
||||
msgstr ""
|
||||
"Project-Id-Version: dosfstools VERSION\n"
|
||||
"POT-Creation-Date: 2015-05-16 00:40+0200\n"
|
||||
"PO-Revision-Date: 2013-06-06 09:34+0300\n"
|
||||
"Last-Translator: Automatically generated\n"
|
||||
"Language-Team: none\n"
|
||||
"Language: de\n"
|
||||
"MIME-Version: 1.0\n"
|
||||
"Content-Type: text/plain; charset=ASCII\n"
|
||||
"Content-Transfer-Encoding: 8bit\n"
|
||||
"Plural-Forms: nplurals=2; plural=(n != 1);\n"
|
||||
|
||||
#. type: TH
|
||||
#: en/fatlabel.8:22 en/fsck.fat.8:22 en/mkfs.fat.8:22
|
||||
#, no-wrap
|
||||
msgid "2015-05-16"
|
||||
msgstr ""
|
||||
|
||||
#. type: TH
|
||||
#: en/fatlabel.8:22 en/fsck.fat.8:22 en/mkfs.fat.8:22
|
||||
#, no-wrap
|
||||
msgid "3.0.28"
|
||||
msgstr ""
|
||||
|
||||
#. type: TH
|
||||
#: en/fatlabel.8:22 en/fsck.fat.8:22 en/mkfs.fat.8:22
|
||||
#, no-wrap
|
||||
msgid "dosfstools"
|
||||
msgstr ""
|
||||
|
||||
#. type: SH
|
||||
#: en/fatlabel.8:23 en/fsck.fat.8:23 en/mkfs.fat.8:23
|
||||
#, no-wrap
|
||||
msgid "NAME"
|
||||
msgstr ""
|
||||
|
||||
#. type: SH
|
||||
#: en/fatlabel.8:26 en/fsck.fat.8:26 en/mkfs.fat.8:26
|
||||
#, no-wrap
|
||||
msgid "SYNOPSIS"
|
||||
msgstr ""
|
||||
|
||||
#. type: SH
|
||||
#: en/fatlabel.8:29 en/fsck.fat.8:29 en/mkfs.fat.8:29
|
||||
#, no-wrap
|
||||
msgid "DESCRIPTION"
|
||||
msgstr ""
|
||||
|
||||
#. type: SH
|
||||
#: en/fatlabel.8:36 en/fsck.fat.8:99 en/mkfs.fat.8:36
|
||||
#, no-wrap
|
||||
msgid "OPTIONS"
|
||||
msgstr ""
|
||||
|
||||
#. type: SH
|
||||
#: en/fatlabel.8:42 en/fsck.fat.8:183 en/mkfs.fat.8:155
|
||||
#, no-wrap
|
||||
msgid "SEE ALSO"
|
||||
msgstr ""
|
||||
|
||||
#. ----------------------------------------------------------------------------
|
||||
#. type: Plain text
|
||||
#: en/fatlabel.8:44 en/mkfs.fat.8:160
|
||||
msgid "B<fsck.fat>(8)"
|
||||
msgstr ""
|
||||
|
||||
#. type: SH
|
||||
#: en/fatlabel.8:47 en/fsck.fat.8:188 en/mkfs.fat.8:160
|
||||
#, no-wrap
|
||||
msgid "HOMEPAGE"
|
||||
msgstr ""
|
||||
|
||||
#. ----------------------------------------------------------------------------
|
||||
#. type: Plain text
|
||||
#: en/fatlabel.8:53 en/fsck.fat.8:194 en/mkfs.fat.8:166
|
||||
msgid ""
|
||||
"The home for the B<dosfstools> project is its E<.UR https://github.com/"
|
||||
"dosfstools/dosfstools> GitHub project page E<.UE .>"
|
||||
msgstr ""
|
||||
|
||||
#. type: SH
|
||||
#: en/fatlabel.8:53 en/fsck.fat.8:194 en/mkfs.fat.8:166
|
||||
#, no-wrap
|
||||
msgid "AUTHORS"
|
||||
msgstr ""
|
||||
|
||||
#. type: Plain text
|
||||
#: en/fatlabel.8:55 en/fsck.fat.8:196 en/mkfs.fat.8:168
|
||||
msgid "B<dosfstools> were written by"
|
||||
msgstr ""
|
||||
|
||||
#. type: Plain text
|
||||
#: en/fatlabel.8:57 en/fsck.fat.8:198 en/mkfs.fat.8:170
|
||||
msgid "Werner Almesberger"
|
||||
msgstr ""
|
||||
|
||||
#. type: Plain text
|
||||
#: en/fatlabel.8:60 en/fsck.fat.8:201 en/mkfs.fat.8:173
|
||||
msgid "Roman Hodek"
|
||||
msgstr ""
|
||||
|
||||
#. type: Plain text
|
||||
#: en/fatlabel.8:63 en/fsck.fat.8:204 en/mkfs.fat.8:176
|
||||
msgid "and others. The current maintainer is"
|
||||
msgstr ""
|
||||
|
||||
#. type: Plain text
|
||||
#: en/fatlabel.8:65 en/fsck.fat.8:206 en/mkfs.fat.8:178
|
||||
msgid "Andreas Bombe"
|
||||
msgstr ""
|
||||
|
||||
#. type: IP
|
||||
#: en/fsck.fat.8:100 en/mkfs.fat.8:37
|
||||
#, no-wrap
|
||||
msgid "B<-a>"
|
||||
msgstr ""
|
||||
|
||||
#. type: IP
|
||||
#: en/fsck.fat.8:146 en/mkfs.fat.8:138
|
||||
#, no-wrap
|
||||
msgid "B<-v>"
|
||||
msgstr ""
|
||||
|
||||
#. type: SH
|
||||
#: en/fsck.fat.8:177 en/mkfs.fat.8:149
|
||||
#, no-wrap
|
||||
msgid "BUGS"
|
||||
msgstr ""
|
||||
|
||||
#. type: Plain text
|
||||
#: en/fsck.fat.8:185 en/mkfs.fat.8:157
|
||||
msgid "B<fatlabel>(8)"
|
||||
msgstr ""
|
||||
|
||||
#. type: TH
|
||||
#: en/mkfs.fat.8:22
|
||||
#, no-wrap
|
||||
msgid "MKFS.FAT"
|
||||
msgstr ""
|
||||
|
||||
#. ----------------------------------------------------------------------------
|
||||
#. type: Plain text
|
||||
#: en/mkfs.fat.8:26
|
||||
msgid "B<mkfs.fat> - create an MS-DOS filesystem under Linux"
|
||||
msgstr ""
|
||||
|
||||
#. ----------------------------------------------------------------------------
|
||||
#. type: Plain text
|
||||
#: en/mkfs.fat.8:29
|
||||
msgid "B<mkfs.fat> [I<OPTIONS>] I<DEVICE> [I<BLOCK-COUNT>]"
|
||||
msgstr ""
|
||||
|
||||
#. ----------------------------------------------------------------------------
|
||||
#. type: Plain text
|
||||
#: en/mkfs.fat.8:36
|
||||
msgid ""
|
||||
"B<mkfs.fat> is used to create an MS-DOS filesystem under Linux on a device "
|
||||
"(usually a disk partition). I<DEVICE> is the special file corresponding to "
|
||||
"the device (e.g. /dev/sdXX). I<BLOCK-COUNT> is the number of blocks on the "
|
||||
"device. If omitted, B<mkfs.fat> automatically determines the filesystem "
|
||||
"size."
|
||||
msgstr ""
|
||||
|
||||
#. type: Plain text
|
||||
#: en/mkfs.fat.8:45
|
||||
msgid ""
|
||||
"Normally, for any filesystem except very small ones, B<mkfs.fat> will align "
|
||||
"all the data structures to cluster size, to make sure that as long as the "
|
||||
"partition is properly aligned, so will all the data structures in the "
|
||||
"filesystem. This option disables alignment; this may provide a handful of "
|
||||
"additional clusters of storage at the expense of a significant performance "
|
||||
"degradation on RAIDs, flash media or large-sector hard disks."
|
||||
msgstr ""
|
||||
|
||||
#. type: IP
|
||||
#: en/mkfs.fat.8:45
|
||||
#, no-wrap
|
||||
msgid "B< -A>"
|
||||
msgstr ""
|
||||
|
||||
#. type: Plain text
|
||||
#: en/mkfs.fat.8:60
|
||||
msgid ""
|
||||
"Use Atari variation of the MS-DOS filesystem. This is default if B<mkfs."
|
||||
"fat> is run on an Atari, then this option turns off Atari format. There are "
|
||||
"some differences when using Atari format: If not directed otherwise by the "
|
||||
"user, B<mkfs.fat> will always use 2 sectors per cluster, since GEMDOS "
|
||||
"doesn't like other values very much. It will also obey the maximum number "
|
||||
"of sectors GEMDOS can handle. Larger filesystems are managed by raising the "
|
||||
"logical sector size. Under Atari format, an Atari-compatible serial number "
|
||||
"for the filesystem is generated, and a 12 bit FAT is used only for "
|
||||
"filesystems that have one of the usual floppy sizes (720k, 1.2M, 1.44M, "
|
||||
"2.88M), a 16 bit FAT otherwise. This can be overridden with the B<-F> "
|
||||
"option. Some PC-specific boot sector fields aren't written, and a boot "
|
||||
"message (option B<-m>) is ignored."
|
||||
msgstr ""
|
||||
|
||||
#. type: IP
|
||||
#: en/mkfs.fat.8:60
|
||||
#, no-wrap
|
||||
msgid "B<-b> I<SECTOR-OF-BACKUP>"
|
||||
msgstr ""
|
||||
|
||||
#. type: Plain text
|
||||
#: en/mkfs.fat.8:64
|
||||
msgid ""
|
||||
"Selects the location of the backup boot sector for FAT32. Default depends "
|
||||
"on number of reserved sectors, but usually is sector 6. The backup must be "
|
||||
"within the range of reserved sectors."
|
||||
msgstr ""
|
||||
|
||||
#. type: IP
|
||||
#: en/mkfs.fat.8:64
|
||||
#, no-wrap
|
||||
msgid "B<-c>"
|
||||
msgstr ""
|
||||
|
||||
#. type: Plain text
|
||||
#: en/mkfs.fat.8:66
|
||||
msgid "Check the device for bad blocks before creating the filesystem."
|
||||
msgstr ""
|
||||
|
||||
#. type: IP
|
||||
#: en/mkfs.fat.8:66
|
||||
#, no-wrap
|
||||
msgid "B<-C>"
|
||||
msgstr ""
|
||||
|
||||
#. type: Plain text
|
||||
#: en/mkfs.fat.8:80
|
||||
msgid ""
|
||||
"Create the file given as I<DEVICE> on the command line, and write the to-be-"
|
||||
"created filesystem to it. This can be used to create the new filesystem in "
|
||||
"a file instead of on a real device, and to avoid using B<dd> in advance to "
|
||||
"create a file of appropriate size. With this option, the I<BLOCK-COUNT> "
|
||||
"must be given, because otherwise the intended size of the filesystem "
|
||||
"wouldn't be known. The file created is a sparse file, which actually only "
|
||||
"contains the meta-data areas (boot sector, FATs, and root directory). The "
|
||||
"data portions won't be stored on the disk, but the file nevertheless will "
|
||||
"have the correct size. The resulting file can be copied later to a floppy "
|
||||
"disk or other device, or mounted through a loop device."
|
||||
msgstr ""
|
||||
|
||||
#. type: IP
|
||||
#: en/mkfs.fat.8:80
|
||||
#, no-wrap
|
||||
msgid "B<-D> I<DRIVE-NUMBER>"
|
||||
msgstr ""
|
||||
|
||||
#. type: Plain text
|
||||
#: en/mkfs.fat.8:84
|
||||
msgid ""
|
||||
"Specify the BIOS drive number to be stored in the FAT boot sector. This "
|
||||
"value is usually 0x80 for hard disks and 0x00 for floppy devices or "
|
||||
"partitions to be used for floppy emulation."
|
||||
msgstr ""
|
||||
|
||||
#. type: IP
|
||||
#: en/mkfs.fat.8:84
|
||||
#, no-wrap
|
||||
msgid "B<-f> I<NUMBER-OF-FATS>"
|
||||
msgstr ""
|
||||
|
||||
#. type: Plain text
|
||||
#: en/mkfs.fat.8:87
|
||||
msgid ""
|
||||
"Specify the number of file allocation tables in the filesystem. The default "
|
||||
"is 2."
|
||||
msgstr ""
|
||||
|
||||
#. type: IP
|
||||
#: en/mkfs.fat.8:87
|
||||
#, no-wrap
|
||||
msgid "B<-F> I<FAT-SIZE>"
|
||||
msgstr ""
|
||||
|
||||
#. type: Plain text
|
||||
#: en/mkfs.fat.8:91
|
||||
msgid ""
|
||||
"Specifies the type of file allocation tables used (12, 16 or 32 bit). If "
|
||||
"nothing is specified, B<mkfs.fat> will automatically select between 12, 16 "
|
||||
"and 32 bit, whatever fits better for the filesystem size."
|
||||
msgstr ""
|
||||
|
||||
#. type: IP
|
||||
#: en/mkfs.fat.8:91
|
||||
#, no-wrap
|
||||
msgid "B<-h> I<NUMBER-OF-HIDDEN-SECTORS>"
|
||||
msgstr ""
|
||||
|
||||
#. type: Plain text
|
||||
#: en/mkfs.fat.8:95
|
||||
msgid ""
|
||||
"Select the number of hidden sectors in the volume. Apparently some digital "
|
||||
"cameras get indigestion if you feed them a CF card without such hidden "
|
||||
"sectors, this option allows you to satisfy them."
|
||||
msgstr ""
|
||||
|
||||
#. type: IP
|
||||
#: en/mkfs.fat.8:95
|
||||
#, no-wrap
|
||||
msgid "B<-i> I<VOLUME-ID>"
|
||||
msgstr ""
|
||||
|
||||
#. type: Plain text
|
||||
#: en/mkfs.fat.8:99
|
||||
msgid ""
|
||||
"Sets the volume ID of the newly created filesystem; I<VOLUME-ID> is a 32-bit "
|
||||
"hexadecimal number (for example, 2e24ec82). The default is a number which "
|
||||
"depends on the filesystem creation time."
|
||||
msgstr ""
|
||||
|
||||
#. type: IP
|
||||
#: en/mkfs.fat.8:99
|
||||
#, no-wrap
|
||||
msgid "B<-I>"
|
||||
msgstr ""
|
||||
|
||||
#. type: Plain text
|
||||
#: en/mkfs.fat.8:108
|
||||
msgid ""
|
||||
"It is typical for fixed disk devices to be partitioned so, by default, you "
|
||||
"are not permitted to create a filesystem across the entire device. B<mkfs."
|
||||
"fat> will complain and tell you that it refuses to work. This is different "
|
||||
"when using MO disks. One doesn't always need partitions on MO disks. The "
|
||||
"filesystem can go directly to the whole disk. Under other OSes this is "
|
||||
"known as the 'superfloppy' format. This switch will force B<mkfs.fat> to "
|
||||
"work properly."
|
||||
msgstr ""
|
||||
|
||||
#. type: IP
|
||||
#: en/mkfs.fat.8:108
|
||||
#, no-wrap
|
||||
msgid "B<-l> I<FILENAME>"
|
||||
msgstr ""
|
||||
|
||||
#. type: Plain text
|
||||
#: en/mkfs.fat.8:110
|
||||
msgid "Read the bad blocks list from I<FILENAME>."
|
||||
msgstr ""
|
||||
|
||||
#. type: IP
|
||||
#: en/mkfs.fat.8:110
|
||||
#, no-wrap
|
||||
msgid "B<-m> I<MESSAGE-FILE>"
|
||||
msgstr ""
|
||||
|
||||
#. type: Plain text
|
||||
#: en/mkfs.fat.8:116
|
||||
msgid ""
|
||||
"Sets the message the user receives on attempts to boot this filesystem "
|
||||
"without having properly installed an operating system. The message file "
|
||||
"must not exceed 418 bytes once line feeds have been converted to carriage "
|
||||
"return-line feed combinations, and tabs have been expanded. If the filename "
|
||||
"is a hyphen (-), the text is taken from standard input."
|
||||
msgstr ""
|
||||
|
||||
#. type: IP
|
||||
#: en/mkfs.fat.8:116
|
||||
#, no-wrap
|
||||
msgid "B<-M> I<FAT-MEDIA-TYPE>"
|
||||
msgstr ""
|
||||
|
||||
#. type: Plain text
|
||||
#: en/mkfs.fat.8:120
|
||||
msgid ""
|
||||
"Specify the media type to be stored in the FAT boot sector. This value is "
|
||||
"usually 0xF8 for hard disks and is 0xF0 or a value from 0xF9 to 0xFF for "
|
||||
"floppies or partitions to be used for floppy emulation."
|
||||
msgstr ""
|
||||
|
||||
#. type: IP
|
||||
#: en/mkfs.fat.8:120
|
||||
#, no-wrap
|
||||
msgid "B<-n> I<VOLUME-NAME>"
|
||||
msgstr ""
|
||||
|
||||
#. type: Plain text
|
||||
#: en/mkfs.fat.8:124
|
||||
msgid ""
|
||||
"Sets the volume name (label) of the filesystem. The volume name can be up "
|
||||
"to 11 characters long. The default is no label."
|
||||
msgstr ""
|
||||
|
||||
#. type: IP
|
||||
#: en/mkfs.fat.8:124
|
||||
#, no-wrap
|
||||
msgid "B<-r> I<ROOT-DIR-ENTRIES>"
|
||||
msgstr ""
|
||||
|
||||
#. type: Plain text
|
||||
#: en/mkfs.fat.8:127
|
||||
msgid ""
|
||||
"Select the number of entries available in the root directory. The default "
|
||||
"is 112 or 224 for floppies and 512 for hard disks."
|
||||
msgstr ""
|
||||
|
||||
#. type: IP
|
||||
#: en/mkfs.fat.8:127
|
||||
#, no-wrap
|
||||
msgid "B<-R> I<NUMBER-OF-RESERVED-SECTORS>"
|
||||
msgstr ""
|
||||
|
||||
#. type: Plain text
|
||||
#: en/mkfs.fat.8:131
|
||||
msgid ""
|
||||
"Select the number of reserved sectors. With FAT32 format at least 2 "
|
||||
"reserved sectors are needed, the default is 32. Otherwise the default is 1 "
|
||||
"(only the boot sector)."
|
||||
msgstr ""
|
||||
|
||||
#. type: IP
|
||||
#: en/mkfs.fat.8:131
|
||||
#, no-wrap
|
||||
msgid "B<-s> I<SECTORS-PER-CLUSTER>"
|
||||
msgstr ""
|
||||
|
||||
#. type: Plain text
|
||||
#: en/mkfs.fat.8:134
|
||||
msgid ""
|
||||
"Specify the number of disk sectors per cluster. Must be a power of 2, i.e. "
|
||||
"1, 2, 4, 8, ... 128."
|
||||
msgstr ""
|
||||
|
||||
#. type: IP
|
||||
#: en/mkfs.fat.8:134
|
||||
#, no-wrap
|
||||
msgid "B<-S> I<LOGICAL-SECTOR-SIZE>"
|
||||
msgstr ""
|
||||
|
||||
#. type: Plain text
|
||||
#: en/mkfs.fat.8:138
|
||||
msgid ""
|
||||
"Specify the number of bytes per logical sector. Must be a power of 2 and "
|
||||
"greater than or equal to 512, i.e. 512, 1024, 2048, 4096, 8192, 16384, or "
|
||||
"32768."
|
||||
msgstr ""
|
||||
|
||||
#. type: Plain text
|
||||
#: en/mkfs.fat.8:140
|
||||
msgid "Verbose execution."
|
||||
msgstr ""
|
||||
|
||||
#. type: IP
|
||||
#: en/mkfs.fat.8:140
|
||||
#, no-wrap
|
||||
msgid "B<--invariant>"
|
||||
msgstr ""
|
||||
|
||||
#. type: Plain text
|
||||
#: en/mkfs.fat.8:146
|
||||
msgid ""
|
||||
"Use constants for normally randomly generated or time based data such as "
|
||||
"volume ID and creation time. Multiple runs of B<mkfs.fat> on the same "
|
||||
"device create identical results with this option. Its main purpose is "
|
||||
"testing B<mkfs.fat>."
|
||||
msgstr ""
|
||||
|
||||
#. type: IP
|
||||
#: en/mkfs.fat.8:146
|
||||
#, no-wrap
|
||||
msgid "B<--help>"
|
||||
msgstr ""
|
||||
|
||||
#. ----------------------------------------------------------------------------
|
||||
#. type: Plain text
|
||||
#: en/mkfs.fat.8:149
|
||||
msgid "Display option summary and exit."
|
||||
msgstr ""
|
||||
|
||||
#. ----------------------------------------------------------------------------
|
||||
#. type: Plain text
|
||||
#: en/mkfs.fat.8:155
|
||||
msgid ""
|
||||
"B<mkfs.fat> can not create boot-able filesystems. This isn't as easy as you "
|
||||
"might think at first glance for various reasons and has been discussed a lot "
|
||||
"already. B<mkfs.fat> simply will not support it ;)"
|
||||
msgstr ""
|
||||
@@ -0,0 +1,5 @@
|
||||
[po4a_langs] de
|
||||
[po4a_paths] pot/$master.pot $lang:po/$lang/$master.po
|
||||
[type: man] en/fatlabel.8 $lang:$lang/fatlabel.$lang.8
|
||||
[type: man] en/fsck.fat.8 $lang:$lang/fsck.fat.$lang.8
|
||||
[type: man] en/mkfs.fat.8 $lang:$lang/mkfs.fat.$lang.8
|
||||
@@ -0,0 +1,176 @@
|
||||
# SOME DESCRIPTIVE TITLE
|
||||
# Copyright (C) YEAR Free Software Foundation, Inc.
|
||||
# This file is distributed under the same license as the dosfstools package.
|
||||
# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
|
||||
#
|
||||
#, fuzzy
|
||||
msgid ""
|
||||
msgstr ""
|
||||
"Project-Id-Version: dosfstools VERSION\n"
|
||||
"POT-Creation-Date: 2015-05-16 00:40+0200\n"
|
||||
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
|
||||
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
|
||||
"Language-Team: LANGUAGE <LL@li.org>\n"
|
||||
"Language: \n"
|
||||
"MIME-Version: 1.0\n"
|
||||
"Content-Type: text/plain; charset=CHARSET\n"
|
||||
"Content-Transfer-Encoding: 8bit\n"
|
||||
|
||||
#. type: TH
|
||||
#: en/fatlabel.8:22
|
||||
#, no-wrap
|
||||
msgid "FATLABEL"
|
||||
msgstr ""
|
||||
|
||||
#. type: TH
|
||||
#: en/fatlabel.8:22 en/fsck.fat.8:22 en/mkfs.fat.8:22
|
||||
#, no-wrap
|
||||
msgid "2015-05-16"
|
||||
msgstr ""
|
||||
|
||||
#. type: TH
|
||||
#: en/fatlabel.8:22 en/fsck.fat.8:22 en/mkfs.fat.8:22
|
||||
#, no-wrap
|
||||
msgid "3.0.28"
|
||||
msgstr ""
|
||||
|
||||
#. type: TH
|
||||
#: en/fatlabel.8:22 en/fsck.fat.8:22 en/mkfs.fat.8:22
|
||||
#, no-wrap
|
||||
msgid "dosfstools"
|
||||
msgstr ""
|
||||
|
||||
#. type: SH
|
||||
#: en/fatlabel.8:23 en/fsck.fat.8:23 en/mkfs.fat.8:23
|
||||
#, no-wrap
|
||||
msgid "NAME"
|
||||
msgstr ""
|
||||
|
||||
#. ----------------------------------------------------------------------------
|
||||
#. type: Plain text
|
||||
#: en/fatlabel.8:26
|
||||
msgid "B<fatlabel> - set or get MS-DOS filesystem label"
|
||||
msgstr ""
|
||||
|
||||
#. type: SH
|
||||
#: en/fatlabel.8:26 en/fsck.fat.8:26 en/mkfs.fat.8:26
|
||||
#, no-wrap
|
||||
msgid "SYNOPSIS"
|
||||
msgstr ""
|
||||
|
||||
#. ----------------------------------------------------------------------------
|
||||
#. type: Plain text
|
||||
#: en/fatlabel.8:29
|
||||
msgid "B<fatlabel> I<DEVICE> [I<LABEL>]"
|
||||
msgstr ""
|
||||
|
||||
#. type: SH
|
||||
#: en/fatlabel.8:29 en/fsck.fat.8:29 en/mkfs.fat.8:29
|
||||
#, no-wrap
|
||||
msgid "DESCRIPTION"
|
||||
msgstr ""
|
||||
|
||||
#. type: Plain text
|
||||
#: en/fatlabel.8:31
|
||||
msgid "B<fatlabel> set or gets a MS-DOS filesystem label from a given device."
|
||||
msgstr ""
|
||||
|
||||
#. ----------------------------------------------------------------------------
|
||||
#. type: Plain text
|
||||
#: en/fatlabel.8:36
|
||||
msgid ""
|
||||
"If I<LABEL> is omitted, then the label name of the specified device is "
|
||||
"written on the standard output. A label can't be longer than 11 bytes."
|
||||
msgstr ""
|
||||
|
||||
#. type: SH
|
||||
#: en/fatlabel.8:36 en/fsck.fat.8:99 en/mkfs.fat.8:36
|
||||
#, no-wrap
|
||||
msgid "OPTIONS"
|
||||
msgstr ""
|
||||
|
||||
#. type: IP
|
||||
#: en/fatlabel.8:37
|
||||
#, no-wrap
|
||||
msgid "B<-h>, B<--help>"
|
||||
msgstr ""
|
||||
|
||||
#. type: Plain text
|
||||
#: en/fatlabel.8:39
|
||||
msgid "Displays a help message."
|
||||
msgstr ""
|
||||
|
||||
#. type: IP
|
||||
#: en/fatlabel.8:39
|
||||
#, no-wrap
|
||||
msgid "B<-V>, B<--version>"
|
||||
msgstr ""
|
||||
|
||||
#. ----------------------------------------------------------------------------
|
||||
#. type: Plain text
|
||||
#: en/fatlabel.8:42
|
||||
msgid "Shows version."
|
||||
msgstr ""
|
||||
|
||||
#. type: SH
|
||||
#: en/fatlabel.8:42 en/fsck.fat.8:183 en/mkfs.fat.8:155
|
||||
#, no-wrap
|
||||
msgid "SEE ALSO"
|
||||
msgstr ""
|
||||
|
||||
#. ----------------------------------------------------------------------------
|
||||
#. type: Plain text
|
||||
#: en/fatlabel.8:44 en/mkfs.fat.8:160
|
||||
msgid "B<fsck.fat>(8)"
|
||||
msgstr ""
|
||||
|
||||
#. ----------------------------------------------------------------------------
|
||||
#. type: Plain text
|
||||
#: en/fatlabel.8:47 en/fsck.fat.8:188
|
||||
msgid "B<mkfs.fat>(8)"
|
||||
msgstr ""
|
||||
|
||||
#. type: SH
|
||||
#: en/fatlabel.8:47 en/fsck.fat.8:188 en/mkfs.fat.8:160
|
||||
#, no-wrap
|
||||
msgid "HOMEPAGE"
|
||||
msgstr ""
|
||||
|
||||
#. ----------------------------------------------------------------------------
|
||||
#. type: Plain text
|
||||
#: en/fatlabel.8:53 en/fsck.fat.8:194 en/mkfs.fat.8:166
|
||||
msgid ""
|
||||
"The home for the B<dosfstools> project is its E<.UR https://github.com/"
|
||||
"dosfstools/dosfstools> GitHub project page E<.UE .>"
|
||||
msgstr ""
|
||||
|
||||
#. type: SH
|
||||
#: en/fatlabel.8:53 en/fsck.fat.8:194 en/mkfs.fat.8:166
|
||||
#, no-wrap
|
||||
msgid "AUTHORS"
|
||||
msgstr ""
|
||||
|
||||
#. type: Plain text
|
||||
#: en/fatlabel.8:55 en/fsck.fat.8:196 en/mkfs.fat.8:168
|
||||
msgid "B<dosfstools> were written by"
|
||||
msgstr ""
|
||||
|
||||
#. type: Plain text
|
||||
#: en/fatlabel.8:57 en/fsck.fat.8:198 en/mkfs.fat.8:170
|
||||
msgid "Werner Almesberger"
|
||||
msgstr ""
|
||||
|
||||
#. type: Plain text
|
||||
#: en/fatlabel.8:60 en/fsck.fat.8:201 en/mkfs.fat.8:173
|
||||
msgid "Roman Hodek"
|
||||
msgstr ""
|
||||
|
||||
#. type: Plain text
|
||||
#: en/fatlabel.8:63 en/fsck.fat.8:204 en/mkfs.fat.8:176
|
||||
msgid "and others. The current maintainer is"
|
||||
msgstr ""
|
||||
|
||||
#. type: Plain text
|
||||
#: en/fatlabel.8:65 en/fsck.fat.8:206 en/mkfs.fat.8:178
|
||||
msgid "Andreas Bombe"
|
||||
msgstr ""
|
||||
@@ -0,0 +1,562 @@
|
||||
# SOME DESCRIPTIVE TITLE
|
||||
# Copyright (C) YEAR Free Software Foundation, Inc.
|
||||
# This file is distributed under the same license as the dosfstools package.
|
||||
# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
|
||||
#
|
||||
#, fuzzy
|
||||
msgid ""
|
||||
msgstr ""
|
||||
"Project-Id-Version: dosfstools VERSION\n"
|
||||
"POT-Creation-Date: 2015-05-16 00:40+0200\n"
|
||||
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
|
||||
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
|
||||
"Language-Team: LANGUAGE <LL@li.org>\n"
|
||||
"Language: \n"
|
||||
"MIME-Version: 1.0\n"
|
||||
"Content-Type: text/plain; charset=CHARSET\n"
|
||||
"Content-Transfer-Encoding: 8bit\n"
|
||||
|
||||
#. type: TH
|
||||
#: en/fatlabel.8:22 en/fsck.fat.8:22 en/mkfs.fat.8:22
|
||||
#, no-wrap
|
||||
msgid "2015-05-16"
|
||||
msgstr ""
|
||||
|
||||
#. type: TH
|
||||
#: en/fatlabel.8:22 en/fsck.fat.8:22 en/mkfs.fat.8:22
|
||||
#, no-wrap
|
||||
msgid "3.0.28"
|
||||
msgstr ""
|
||||
|
||||
#. type: TH
|
||||
#: en/fatlabel.8:22 en/fsck.fat.8:22 en/mkfs.fat.8:22
|
||||
#, no-wrap
|
||||
msgid "dosfstools"
|
||||
msgstr ""
|
||||
|
||||
#. type: SH
|
||||
#: en/fatlabel.8:23 en/fsck.fat.8:23 en/mkfs.fat.8:23
|
||||
#, no-wrap
|
||||
msgid "NAME"
|
||||
msgstr ""
|
||||
|
||||
#. type: SH
|
||||
#: en/fatlabel.8:26 en/fsck.fat.8:26 en/mkfs.fat.8:26
|
||||
#, no-wrap
|
||||
msgid "SYNOPSIS"
|
||||
msgstr ""
|
||||
|
||||
#. type: SH
|
||||
#: en/fatlabel.8:29 en/fsck.fat.8:29 en/mkfs.fat.8:29
|
||||
#, no-wrap
|
||||
msgid "DESCRIPTION"
|
||||
msgstr ""
|
||||
|
||||
#. type: SH
|
||||
#: en/fatlabel.8:36 en/fsck.fat.8:99 en/mkfs.fat.8:36
|
||||
#, no-wrap
|
||||
msgid "OPTIONS"
|
||||
msgstr ""
|
||||
|
||||
#. type: SH
|
||||
#: en/fatlabel.8:42 en/fsck.fat.8:183 en/mkfs.fat.8:155
|
||||
#, no-wrap
|
||||
msgid "SEE ALSO"
|
||||
msgstr ""
|
||||
|
||||
#. ----------------------------------------------------------------------------
|
||||
#. type: Plain text
|
||||
#: en/fatlabel.8:47 en/fsck.fat.8:188
|
||||
msgid "B<mkfs.fat>(8)"
|
||||
msgstr ""
|
||||
|
||||
#. type: SH
|
||||
#: en/fatlabel.8:47 en/fsck.fat.8:188 en/mkfs.fat.8:160
|
||||
#, no-wrap
|
||||
msgid "HOMEPAGE"
|
||||
msgstr ""
|
||||
|
||||
#. ----------------------------------------------------------------------------
|
||||
#. type: Plain text
|
||||
#: en/fatlabel.8:53 en/fsck.fat.8:194 en/mkfs.fat.8:166
|
||||
msgid ""
|
||||
"The home for the B<dosfstools> project is its E<.UR https://github.com/"
|
||||
"dosfstools/dosfstools> GitHub project page E<.UE .>"
|
||||
msgstr ""
|
||||
|
||||
#. type: SH
|
||||
#: en/fatlabel.8:53 en/fsck.fat.8:194 en/mkfs.fat.8:166
|
||||
#, no-wrap
|
||||
msgid "AUTHORS"
|
||||
msgstr ""
|
||||
|
||||
#. type: Plain text
|
||||
#: en/fatlabel.8:55 en/fsck.fat.8:196 en/mkfs.fat.8:168
|
||||
msgid "B<dosfstools> were written by"
|
||||
msgstr ""
|
||||
|
||||
#. type: Plain text
|
||||
#: en/fatlabel.8:57 en/fsck.fat.8:198 en/mkfs.fat.8:170
|
||||
msgid "Werner Almesberger"
|
||||
msgstr ""
|
||||
|
||||
#. type: Plain text
|
||||
#: en/fatlabel.8:60 en/fsck.fat.8:201 en/mkfs.fat.8:173
|
||||
msgid "Roman Hodek"
|
||||
msgstr ""
|
||||
|
||||
#. type: Plain text
|
||||
#: en/fatlabel.8:63 en/fsck.fat.8:204 en/mkfs.fat.8:176
|
||||
msgid "and others. The current maintainer is"
|
||||
msgstr ""
|
||||
|
||||
#. type: Plain text
|
||||
#: en/fatlabel.8:65 en/fsck.fat.8:206 en/mkfs.fat.8:178
|
||||
msgid "Andreas Bombe"
|
||||
msgstr ""
|
||||
|
||||
#. type: TH
|
||||
#: en/fsck.fat.8:22
|
||||
#, no-wrap
|
||||
msgid "FSCK.FAT"
|
||||
msgstr ""
|
||||
|
||||
#. ----------------------------------------------------------------------------
|
||||
#. type: Plain text
|
||||
#: en/fsck.fat.8:26
|
||||
msgid "B<fsck.fat> - check and repair MS-DOS filesystems"
|
||||
msgstr ""
|
||||
|
||||
#. ----------------------------------------------------------------------------
|
||||
#. type: Plain text
|
||||
#: en/fsck.fat.8:29
|
||||
msgid "B<fsck.fat> [I<OPTIONS>] I<DEVICE>"
|
||||
msgstr ""
|
||||
|
||||
#. type: Plain text
|
||||
#: en/fsck.fat.8:32
|
||||
msgid ""
|
||||
"B<fsck.fat> verifies the consistency of MS-DOS filesystems and optionally "
|
||||
"tries to repair them."
|
||||
msgstr ""
|
||||
|
||||
#. type: Plain text
|
||||
#: en/fsck.fat.8:34
|
||||
msgid "The following filesystem problems can be corrected (in this order):"
|
||||
msgstr ""
|
||||
|
||||
#. type: IP
|
||||
#: en/fsck.fat.8:34 en/fsck.fat.8:37 en/fsck.fat.8:40 en/fsck.fat.8:44
|
||||
#: en/fsck.fat.8:47 en/fsck.fat.8:50 en/fsck.fat.8:53 en/fsck.fat.8:56
|
||||
#: en/fsck.fat.8:59 en/fsck.fat.8:62 en/fsck.fat.8:65 en/fsck.fat.8:68
|
||||
#: en/fsck.fat.8:71 en/fsck.fat.8:74 en/fsck.fat.8:77 en/fsck.fat.8:82
|
||||
#: en/fsck.fat.8:85 en/fsck.fat.8:90 en/fsck.fat.8:92
|
||||
#, no-wrap
|
||||
msgid "*"
|
||||
msgstr ""
|
||||
|
||||
#. type: Plain text
|
||||
#: en/fsck.fat.8:37
|
||||
msgid "FAT contains invalid cluster numbers. Cluster is changed to EOF."
|
||||
msgstr ""
|
||||
|
||||
#. type: Plain text
|
||||
#: en/fsck.fat.8:40
|
||||
msgid "File's cluster chain contains a loop. The loop is broken."
|
||||
msgstr ""
|
||||
|
||||
#. type: Plain text
|
||||
#: en/fsck.fat.8:44
|
||||
msgid ""
|
||||
"Bad clusters (read errors). The clusters are marked bad and they are "
|
||||
"removed from files owning them. This check is optional."
|
||||
msgstr ""
|
||||
|
||||
#. type: Plain text
|
||||
#: en/fsck.fat.8:47
|
||||
msgid ""
|
||||
"Directories with a large number of bad entries (probably corrupt). The "
|
||||
"directory can be deleted."
|
||||
msgstr ""
|
||||
|
||||
#. type: Plain text
|
||||
#: en/fsck.fat.8:50
|
||||
msgid "Files . and .. are non-directories. They can be deleted or renamed."
|
||||
msgstr ""
|
||||
|
||||
#. type: Plain text
|
||||
#: en/fsck.fat.8:53
|
||||
msgid "Directories . and .. in root directory. They are deleted."
|
||||
msgstr ""
|
||||
|
||||
#. type: Plain text
|
||||
#: en/fsck.fat.8:56
|
||||
msgid "Bad filenames. They can be renamed."
|
||||
msgstr ""
|
||||
|
||||
#. type: Plain text
|
||||
#: en/fsck.fat.8:59
|
||||
msgid "Duplicate directory entries. They can be deleted or renamed."
|
||||
msgstr ""
|
||||
|
||||
#. type: Plain text
|
||||
#: en/fsck.fat.8:62
|
||||
msgid "Directories with non-zero size field. Size is set to zero."
|
||||
msgstr ""
|
||||
|
||||
#. type: Plain text
|
||||
#: en/fsck.fat.8:65
|
||||
msgid ""
|
||||
"Directory . does not point to parent directory. The start pointer is "
|
||||
"adjusted."
|
||||
msgstr ""
|
||||
|
||||
#. type: Plain text
|
||||
#: en/fsck.fat.8:68
|
||||
msgid ""
|
||||
"Directory .. does not point to parent of parent directory. The start "
|
||||
"pointer is adjusted."
|
||||
msgstr ""
|
||||
|
||||
#. type: Plain text
|
||||
#: en/fsck.fat.8:71
|
||||
msgid "Start cluster number of a file is invalid. The file is truncated."
|
||||
msgstr ""
|
||||
|
||||
#. type: Plain text
|
||||
#: en/fsck.fat.8:74
|
||||
msgid "File contains bad or free clusters. The file is truncated."
|
||||
msgstr ""
|
||||
|
||||
#. type: Plain text
|
||||
#: en/fsck.fat.8:77
|
||||
msgid ""
|
||||
"File's cluster chain is longer than indicated by the size fields. The file "
|
||||
"is truncated."
|
||||
msgstr ""
|
||||
|
||||
#. type: Plain text
|
||||
#: en/fsck.fat.8:82
|
||||
msgid ""
|
||||
"Two or more files share the same cluster(s). All but one of the files are "
|
||||
"truncated. If the file being truncated is a directory file that has already "
|
||||
"been read, the filesystem check is restarted after truncation."
|
||||
msgstr ""
|
||||
|
||||
#. type: Plain text
|
||||
#: en/fsck.fat.8:85
|
||||
msgid ""
|
||||
"File's cluster chain is shorter than indicated by the size fields. The file "
|
||||
"is truncated."
|
||||
msgstr ""
|
||||
|
||||
#. type: Plain text
|
||||
#: en/fsck.fat.8:88
|
||||
msgid ""
|
||||
"Clusters are marked as used but are not owned by a file. They are marked as "
|
||||
"free."
|
||||
msgstr ""
|
||||
|
||||
#. type: Plain text
|
||||
#: en/fsck.fat.8:90
|
||||
msgid "Additionally, the following problems are detected, but not repaired:"
|
||||
msgstr ""
|
||||
|
||||
#. type: Plain text
|
||||
#: en/fsck.fat.8:92
|
||||
msgid "Invalid parameters in boot sector"
|
||||
msgstr ""
|
||||
|
||||
#. type: Plain text
|
||||
#: en/fsck.fat.8:94
|
||||
msgid "Absence of . and .. entries in non-root directories"
|
||||
msgstr ""
|
||||
|
||||
#. ----------------------------------------------------------------------------
|
||||
#. type: Plain text
|
||||
#: en/fsck.fat.8:99
|
||||
msgid ""
|
||||
"When B<fsck.fat> checks a filesystem, it accumulates all changes in memory "
|
||||
"and performs them only after all checks are complete. This can be disabled "
|
||||
"with the B<-w> option."
|
||||
msgstr ""
|
||||
|
||||
#. type: IP
|
||||
#: en/fsck.fat.8:100 en/mkfs.fat.8:37
|
||||
#, no-wrap
|
||||
msgid "B<-a>"
|
||||
msgstr ""
|
||||
|
||||
#. type: Plain text
|
||||
#: en/fsck.fat.8:105
|
||||
msgid ""
|
||||
"Automatically repair the filesystem. No user intervention is necessary. "
|
||||
"Whenever there is more than one method to solve a problem, the least "
|
||||
"destructive approach is used."
|
||||
msgstr ""
|
||||
|
||||
#. type: IP
|
||||
#: en/fsck.fat.8:105
|
||||
#, no-wrap
|
||||
msgid "B<-A>"
|
||||
msgstr ""
|
||||
|
||||
#. type: Plain text
|
||||
#: en/fsck.fat.8:116
|
||||
msgid ""
|
||||
"Use Atari variation of the MS-DOS filesystem. This is default if B<fsck."
|
||||
"fat> is run on an Atari, then this option turns off Atari format. There are "
|
||||
"some minor differences in Atari format: Some boot sector fields are "
|
||||
"interpreted slightly different, and the special FAT entries for end-of-file "
|
||||
"and bad cluster can be different. Under MS-DOS 0xfff8 is used for EOF and "
|
||||
"Atari employs 0xffff by default, but both systems recognize all values from "
|
||||
"0xfff8...0xffff as end-of-file. MS-DOS uses only 0xfff7 for bad clusters, "
|
||||
"where on Atari values 0xfff0...0xfff7 are for this purpose (but the standard "
|
||||
"value is still 0xfff7)."
|
||||
msgstr ""
|
||||
|
||||
#. type: IP
|
||||
#: en/fsck.fat.8:116
|
||||
#, no-wrap
|
||||
msgid "B<-b>"
|
||||
msgstr ""
|
||||
|
||||
#. type: Plain text
|
||||
#: en/fsck.fat.8:118
|
||||
msgid "Make read-only boot sector check."
|
||||
msgstr ""
|
||||
|
||||
#. type: IP
|
||||
#: en/fsck.fat.8:118
|
||||
#, no-wrap
|
||||
msgid "B<-d> I<PATH>"
|
||||
msgstr ""
|
||||
|
||||
#. type: Plain text
|
||||
#: en/fsck.fat.8:122
|
||||
msgid ""
|
||||
"Delete the specified file. If more than one file with that name exist, the "
|
||||
"first one is deleted. This option can be given more than once."
|
||||
msgstr ""
|
||||
|
||||
#. type: IP
|
||||
#: en/fsck.fat.8:122
|
||||
#, no-wrap
|
||||
msgid "B<-f>"
|
||||
msgstr ""
|
||||
|
||||
#. type: Plain text
|
||||
#: en/fsck.fat.8:126
|
||||
msgid ""
|
||||
"Salvage unused cluster chains to files. By default, unused clusters are "
|
||||
"added to the free disk space except in auto mode (B<-a>)."
|
||||
msgstr ""
|
||||
|
||||
#. type: IP
|
||||
#: en/fsck.fat.8:126
|
||||
#, no-wrap
|
||||
msgid "B<-l>"
|
||||
msgstr ""
|
||||
|
||||
#. type: Plain text
|
||||
#: en/fsck.fat.8:128
|
||||
msgid "List path names of files being processed."
|
||||
msgstr ""
|
||||
|
||||
#. type: IP
|
||||
#: en/fsck.fat.8:128
|
||||
#, no-wrap
|
||||
msgid "B<-n>"
|
||||
msgstr ""
|
||||
|
||||
#. type: Plain text
|
||||
#: en/fsck.fat.8:131
|
||||
msgid ""
|
||||
"No-operation mode: non-interactively check for errors, but don't write "
|
||||
"anything to the filesystem."
|
||||
msgstr ""
|
||||
|
||||
#. type: IP
|
||||
#: en/fsck.fat.8:131
|
||||
#, no-wrap
|
||||
msgid "B<-p>"
|
||||
msgstr ""
|
||||
|
||||
#. type: Plain text
|
||||
#: en/fsck.fat.8:133
|
||||
msgid "Same as B<-a>, for compatibility with other *fsck."
|
||||
msgstr ""
|
||||
|
||||
#. type: IP
|
||||
#: en/fsck.fat.8:133
|
||||
#, no-wrap
|
||||
msgid "B<-r>"
|
||||
msgstr ""
|
||||
|
||||
#. type: Plain text
|
||||
#: en/fsck.fat.8:139
|
||||
msgid ""
|
||||
"Interactively repair the filesystem. The user is asked for advice whenever "
|
||||
"there is more than one approach to fix an inconsistency. This is the "
|
||||
"default mode and the option is only retained for backwards compatibility."
|
||||
msgstr ""
|
||||
|
||||
#. type: IP
|
||||
#: en/fsck.fat.8:139
|
||||
#, no-wrap
|
||||
msgid "B<-t>"
|
||||
msgstr ""
|
||||
|
||||
#. type: Plain text
|
||||
#: en/fsck.fat.8:141
|
||||
msgid "Mark unreadable clusters as bad."
|
||||
msgstr ""
|
||||
|
||||
#. type: IP
|
||||
#: en/fsck.fat.8:141
|
||||
#, no-wrap
|
||||
msgid "B<-u> I<PATH>"
|
||||
msgstr ""
|
||||
|
||||
#. type: Plain text
|
||||
#: en/fsck.fat.8:146
|
||||
msgid ""
|
||||
"Try to undelete the specified file. B<fsck.fat> tries to allocate a chain "
|
||||
"of contiguous unallocated clusters beginning with the start cluster of the "
|
||||
"undeleted file. This option can be given more than once."
|
||||
msgstr ""
|
||||
|
||||
#. type: IP
|
||||
#: en/fsck.fat.8:146 en/mkfs.fat.8:138
|
||||
#, no-wrap
|
||||
msgid "B<-v>"
|
||||
msgstr ""
|
||||
|
||||
#. type: Plain text
|
||||
#: en/fsck.fat.8:149
|
||||
msgid "Verbose mode. Generates slightly more output."
|
||||
msgstr ""
|
||||
|
||||
#. type: IP
|
||||
#: en/fsck.fat.8:149
|
||||
#, no-wrap
|
||||
msgid "B<-V>"
|
||||
msgstr ""
|
||||
|
||||
#. type: Plain text
|
||||
#: en/fsck.fat.8:156
|
||||
msgid ""
|
||||
"Perform a verification pass. The filesystem check is repeated after the "
|
||||
"first run. The second pass should never report any fixable errors. It may "
|
||||
"take considerably longer than the first pass, because the first pass may "
|
||||
"have generated long list of modifications that have to be scanned for each "
|
||||
"disk read."
|
||||
msgstr ""
|
||||
|
||||
#. type: IP
|
||||
#: en/fsck.fat.8:156
|
||||
#, no-wrap
|
||||
msgid "B<-w>"
|
||||
msgstr ""
|
||||
|
||||
#. type: Plain text
|
||||
#: en/fsck.fat.8:158
|
||||
msgid "Write changes to disk immediately."
|
||||
msgstr ""
|
||||
|
||||
#. type: IP
|
||||
#: en/fsck.fat.8:158
|
||||
#, no-wrap
|
||||
msgid "B<-y>"
|
||||
msgstr ""
|
||||
|
||||
#. ----------------------------------------------------------------------------
|
||||
#. type: Plain text
|
||||
#: en/fsck.fat.8:162
|
||||
msgid ""
|
||||
"Same as B<-a> (automatically repair filesystem) for compatibility with other "
|
||||
"fsck tools."
|
||||
msgstr ""
|
||||
|
||||
#. type: SH
|
||||
#: en/fsck.fat.8:162
|
||||
#, no-wrap
|
||||
msgid "EXIT STATUS"
|
||||
msgstr ""
|
||||
|
||||
#. type: IP
|
||||
#: en/fsck.fat.8:163
|
||||
#, no-wrap
|
||||
msgid "0"
|
||||
msgstr ""
|
||||
|
||||
#. type: Plain text
|
||||
#: en/fsck.fat.8:165
|
||||
msgid "No recoverable errors have been detected."
|
||||
msgstr ""
|
||||
|
||||
#. type: IP
|
||||
#: en/fsck.fat.8:165
|
||||
#, no-wrap
|
||||
msgid "1"
|
||||
msgstr ""
|
||||
|
||||
#. type: Plain text
|
||||
#: en/fsck.fat.8:168
|
||||
msgid ""
|
||||
"Recoverable errors have been detected or B<fsck.fat> has discovered an "
|
||||
"internal inconsistency."
|
||||
msgstr ""
|
||||
|
||||
#. type: IP
|
||||
#: en/fsck.fat.8:168
|
||||
#, no-wrap
|
||||
msgid "2"
|
||||
msgstr ""
|
||||
|
||||
#. ----------------------------------------------------------------------------
|
||||
#. type: Plain text
|
||||
#: en/fsck.fat.8:172
|
||||
msgid "Usage error. B<fsck.fat> did not access the filesystem."
|
||||
msgstr ""
|
||||
|
||||
#. type: SH
|
||||
#: en/fsck.fat.8:172
|
||||
#, no-wrap
|
||||
msgid "FILES"
|
||||
msgstr ""
|
||||
|
||||
#. type: IP
|
||||
#: en/fsck.fat.8:173
|
||||
#, no-wrap
|
||||
msgid "fsck0000.rec, fsck0001.rec, ..."
|
||||
msgstr ""
|
||||
|
||||
#. ----------------------------------------------------------------------------
|
||||
#. type: Plain text
|
||||
#: en/fsck.fat.8:177
|
||||
msgid ""
|
||||
"When recovering from a corrupted filesystem, B<fsck.fat> dumps recovered "
|
||||
"data into files named 'fsckNNNN.rec' in the top level directory of the "
|
||||
"filesystem."
|
||||
msgstr ""
|
||||
|
||||
#. type: SH
|
||||
#: en/fsck.fat.8:177 en/mkfs.fat.8:149
|
||||
#, no-wrap
|
||||
msgid "BUGS"
|
||||
msgstr ""
|
||||
|
||||
#. ----------------------------------------------------------------------------
|
||||
#. type: Plain text
|
||||
#: en/fsck.fat.8:183
|
||||
msgid ""
|
||||
"Does not create . and .. files where necessary. Does not remove entirely "
|
||||
"empty directories. Should give more diagnostic messages. Undeleting files "
|
||||
"should use a more sophisticated algorithm."
|
||||
msgstr ""
|
||||
|
||||
#. type: Plain text
|
||||
#: en/fsck.fat.8:185 en/mkfs.fat.8:157
|
||||
msgid "B<fatlabel>(8)"
|
||||
msgstr ""
|
||||
@@ -0,0 +1,484 @@
|
||||
# SOME DESCRIPTIVE TITLE
|
||||
# Copyright (C) YEAR Free Software Foundation, Inc.
|
||||
# This file is distributed under the same license as the dosfstools package.
|
||||
# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
|
||||
#
|
||||
#, fuzzy
|
||||
msgid ""
|
||||
msgstr ""
|
||||
"Project-Id-Version: dosfstools VERSION\n"
|
||||
"POT-Creation-Date: 2015-05-16 00:40+0200\n"
|
||||
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
|
||||
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
|
||||
"Language-Team: LANGUAGE <LL@li.org>\n"
|
||||
"Language: \n"
|
||||
"MIME-Version: 1.0\n"
|
||||
"Content-Type: text/plain; charset=CHARSET\n"
|
||||
"Content-Transfer-Encoding: 8bit\n"
|
||||
|
||||
#. type: TH
|
||||
#: en/fatlabel.8:22 en/fsck.fat.8:22 en/mkfs.fat.8:22
|
||||
#, no-wrap
|
||||
msgid "2015-05-16"
|
||||
msgstr ""
|
||||
|
||||
#. type: TH
|
||||
#: en/fatlabel.8:22 en/fsck.fat.8:22 en/mkfs.fat.8:22
|
||||
#, no-wrap
|
||||
msgid "3.0.28"
|
||||
msgstr ""
|
||||
|
||||
#. type: TH
|
||||
#: en/fatlabel.8:22 en/fsck.fat.8:22 en/mkfs.fat.8:22
|
||||
#, no-wrap
|
||||
msgid "dosfstools"
|
||||
msgstr ""
|
||||
|
||||
#. type: SH
|
||||
#: en/fatlabel.8:23 en/fsck.fat.8:23 en/mkfs.fat.8:23
|
||||
#, no-wrap
|
||||
msgid "NAME"
|
||||
msgstr ""
|
||||
|
||||
#. type: SH
|
||||
#: en/fatlabel.8:26 en/fsck.fat.8:26 en/mkfs.fat.8:26
|
||||
#, no-wrap
|
||||
msgid "SYNOPSIS"
|
||||
msgstr ""
|
||||
|
||||
#. type: SH
|
||||
#: en/fatlabel.8:29 en/fsck.fat.8:29 en/mkfs.fat.8:29
|
||||
#, no-wrap
|
||||
msgid "DESCRIPTION"
|
||||
msgstr ""
|
||||
|
||||
#. type: SH
|
||||
#: en/fatlabel.8:36 en/fsck.fat.8:99 en/mkfs.fat.8:36
|
||||
#, no-wrap
|
||||
msgid "OPTIONS"
|
||||
msgstr ""
|
||||
|
||||
#. type: SH
|
||||
#: en/fatlabel.8:42 en/fsck.fat.8:183 en/mkfs.fat.8:155
|
||||
#, no-wrap
|
||||
msgid "SEE ALSO"
|
||||
msgstr ""
|
||||
|
||||
#. ----------------------------------------------------------------------------
|
||||
#. type: Plain text
|
||||
#: en/fatlabel.8:44 en/mkfs.fat.8:160
|
||||
msgid "B<fsck.fat>(8)"
|
||||
msgstr ""
|
||||
|
||||
#. type: SH
|
||||
#: en/fatlabel.8:47 en/fsck.fat.8:188 en/mkfs.fat.8:160
|
||||
#, no-wrap
|
||||
msgid "HOMEPAGE"
|
||||
msgstr ""
|
||||
|
||||
#. ----------------------------------------------------------------------------
|
||||
#. type: Plain text
|
||||
#: en/fatlabel.8:53 en/fsck.fat.8:194 en/mkfs.fat.8:166
|
||||
msgid ""
|
||||
"The home for the B<dosfstools> project is its E<.UR https://github.com/"
|
||||
"dosfstools/dosfstools> GitHub project page E<.UE .>"
|
||||
msgstr ""
|
||||
|
||||
#. type: SH
|
||||
#: en/fatlabel.8:53 en/fsck.fat.8:194 en/mkfs.fat.8:166
|
||||
#, no-wrap
|
||||
msgid "AUTHORS"
|
||||
msgstr ""
|
||||
|
||||
#. type: Plain text
|
||||
#: en/fatlabel.8:55 en/fsck.fat.8:196 en/mkfs.fat.8:168
|
||||
msgid "B<dosfstools> were written by"
|
||||
msgstr ""
|
||||
|
||||
#. type: Plain text
|
||||
#: en/fatlabel.8:57 en/fsck.fat.8:198 en/mkfs.fat.8:170
|
||||
msgid "Werner Almesberger"
|
||||
msgstr ""
|
||||
|
||||
#. type: Plain text
|
||||
#: en/fatlabel.8:60 en/fsck.fat.8:201 en/mkfs.fat.8:173
|
||||
msgid "Roman Hodek"
|
||||
msgstr ""
|
||||
|
||||
#. type: Plain text
|
||||
#: en/fatlabel.8:63 en/fsck.fat.8:204 en/mkfs.fat.8:176
|
||||
msgid "and others. The current maintainer is"
|
||||
msgstr ""
|
||||
|
||||
#. type: Plain text
|
||||
#: en/fatlabel.8:65 en/fsck.fat.8:206 en/mkfs.fat.8:178
|
||||
msgid "Andreas Bombe"
|
||||
msgstr ""
|
||||
|
||||
#. type: IP
|
||||
#: en/fsck.fat.8:100 en/mkfs.fat.8:37
|
||||
#, no-wrap
|
||||
msgid "B<-a>"
|
||||
msgstr ""
|
||||
|
||||
#. type: IP
|
||||
#: en/fsck.fat.8:146 en/mkfs.fat.8:138
|
||||
#, no-wrap
|
||||
msgid "B<-v>"
|
||||
msgstr ""
|
||||
|
||||
#. type: SH
|
||||
#: en/fsck.fat.8:177 en/mkfs.fat.8:149
|
||||
#, no-wrap
|
||||
msgid "BUGS"
|
||||
msgstr ""
|
||||
|
||||
#. type: Plain text
|
||||
#: en/fsck.fat.8:185 en/mkfs.fat.8:157
|
||||
msgid "B<fatlabel>(8)"
|
||||
msgstr ""
|
||||
|
||||
#. type: TH
|
||||
#: en/mkfs.fat.8:22
|
||||
#, no-wrap
|
||||
msgid "MKFS.FAT"
|
||||
msgstr ""
|
||||
|
||||
#. ----------------------------------------------------------------------------
|
||||
#. type: Plain text
|
||||
#: en/mkfs.fat.8:26
|
||||
msgid "B<mkfs.fat> - create an MS-DOS filesystem under Linux"
|
||||
msgstr ""
|
||||
|
||||
#. ----------------------------------------------------------------------------
|
||||
#. type: Plain text
|
||||
#: en/mkfs.fat.8:29
|
||||
msgid "B<mkfs.fat> [I<OPTIONS>] I<DEVICE> [I<BLOCK-COUNT>]"
|
||||
msgstr ""
|
||||
|
||||
#. ----------------------------------------------------------------------------
|
||||
#. type: Plain text
|
||||
#: en/mkfs.fat.8:36
|
||||
msgid ""
|
||||
"B<mkfs.fat> is used to create an MS-DOS filesystem under Linux on a device "
|
||||
"(usually a disk partition). I<DEVICE> is the special file corresponding to "
|
||||
"the device (e.g. /dev/sdXX). I<BLOCK-COUNT> is the number of blocks on the "
|
||||
"device. If omitted, B<mkfs.fat> automatically determines the filesystem "
|
||||
"size."
|
||||
msgstr ""
|
||||
|
||||
#. type: Plain text
|
||||
#: en/mkfs.fat.8:45
|
||||
msgid ""
|
||||
"Normally, for any filesystem except very small ones, B<mkfs.fat> will align "
|
||||
"all the data structures to cluster size, to make sure that as long as the "
|
||||
"partition is properly aligned, so will all the data structures in the "
|
||||
"filesystem. This option disables alignment; this may provide a handful of "
|
||||
"additional clusters of storage at the expense of a significant performance "
|
||||
"degradation on RAIDs, flash media or large-sector hard disks."
|
||||
msgstr ""
|
||||
|
||||
#. type: IP
|
||||
#: en/mkfs.fat.8:45
|
||||
#, no-wrap
|
||||
msgid "B< -A>"
|
||||
msgstr ""
|
||||
|
||||
#. type: Plain text
|
||||
#: en/mkfs.fat.8:60
|
||||
msgid ""
|
||||
"Use Atari variation of the MS-DOS filesystem. This is default if B<mkfs."
|
||||
"fat> is run on an Atari, then this option turns off Atari format. There are "
|
||||
"some differences when using Atari format: If not directed otherwise by the "
|
||||
"user, B<mkfs.fat> will always use 2 sectors per cluster, since GEMDOS "
|
||||
"doesn't like other values very much. It will also obey the maximum number "
|
||||
"of sectors GEMDOS can handle. Larger filesystems are managed by raising the "
|
||||
"logical sector size. Under Atari format, an Atari-compatible serial number "
|
||||
"for the filesystem is generated, and a 12 bit FAT is used only for "
|
||||
"filesystems that have one of the usual floppy sizes (720k, 1.2M, 1.44M, "
|
||||
"2.88M), a 16 bit FAT otherwise. This can be overridden with the B<-F> "
|
||||
"option. Some PC-specific boot sector fields aren't written, and a boot "
|
||||
"message (option B<-m>) is ignored."
|
||||
msgstr ""
|
||||
|
||||
#. type: IP
|
||||
#: en/mkfs.fat.8:60
|
||||
#, no-wrap
|
||||
msgid "B<-b> I<SECTOR-OF-BACKUP>"
|
||||
msgstr ""
|
||||
|
||||
#. type: Plain text
|
||||
#: en/mkfs.fat.8:64
|
||||
msgid ""
|
||||
"Selects the location of the backup boot sector for FAT32. Default depends "
|
||||
"on number of reserved sectors, but usually is sector 6. The backup must be "
|
||||
"within the range of reserved sectors."
|
||||
msgstr ""
|
||||
|
||||
#. type: IP
|
||||
#: en/mkfs.fat.8:64
|
||||
#, no-wrap
|
||||
msgid "B<-c>"
|
||||
msgstr ""
|
||||
|
||||
#. type: Plain text
|
||||
#: en/mkfs.fat.8:66
|
||||
msgid "Check the device for bad blocks before creating the filesystem."
|
||||
msgstr ""
|
||||
|
||||
#. type: IP
|
||||
#: en/mkfs.fat.8:66
|
||||
#, no-wrap
|
||||
msgid "B<-C>"
|
||||
msgstr ""
|
||||
|
||||
#. type: Plain text
|
||||
#: en/mkfs.fat.8:80
|
||||
msgid ""
|
||||
"Create the file given as I<DEVICE> on the command line, and write the to-be-"
|
||||
"created filesystem to it. This can be used to create the new filesystem in "
|
||||
"a file instead of on a real device, and to avoid using B<dd> in advance to "
|
||||
"create a file of appropriate size. With this option, the I<BLOCK-COUNT> "
|
||||
"must be given, because otherwise the intended size of the filesystem "
|
||||
"wouldn't be known. The file created is a sparse file, which actually only "
|
||||
"contains the meta-data areas (boot sector, FATs, and root directory). The "
|
||||
"data portions won't be stored on the disk, but the file nevertheless will "
|
||||
"have the correct size. The resulting file can be copied later to a floppy "
|
||||
"disk or other device, or mounted through a loop device."
|
||||
msgstr ""
|
||||
|
||||
#. type: IP
|
||||
#: en/mkfs.fat.8:80
|
||||
#, no-wrap
|
||||
msgid "B<-D> I<DRIVE-NUMBER>"
|
||||
msgstr ""
|
||||
|
||||
#. type: Plain text
|
||||
#: en/mkfs.fat.8:84
|
||||
msgid ""
|
||||
"Specify the BIOS drive number to be stored in the FAT boot sector. This "
|
||||
"value is usually 0x80 for hard disks and 0x00 for floppy devices or "
|
||||
"partitions to be used for floppy emulation."
|
||||
msgstr ""
|
||||
|
||||
#. type: IP
|
||||
#: en/mkfs.fat.8:84
|
||||
#, no-wrap
|
||||
msgid "B<-f> I<NUMBER-OF-FATS>"
|
||||
msgstr ""
|
||||
|
||||
#. type: Plain text
|
||||
#: en/mkfs.fat.8:87
|
||||
msgid ""
|
||||
"Specify the number of file allocation tables in the filesystem. The default "
|
||||
"is 2."
|
||||
msgstr ""
|
||||
|
||||
#. type: IP
|
||||
#: en/mkfs.fat.8:87
|
||||
#, no-wrap
|
||||
msgid "B<-F> I<FAT-SIZE>"
|
||||
msgstr ""
|
||||
|
||||
#. type: Plain text
|
||||
#: en/mkfs.fat.8:91
|
||||
msgid ""
|
||||
"Specifies the type of file allocation tables used (12, 16 or 32 bit). If "
|
||||
"nothing is specified, B<mkfs.fat> will automatically select between 12, 16 "
|
||||
"and 32 bit, whatever fits better for the filesystem size."
|
||||
msgstr ""
|
||||
|
||||
#. type: IP
|
||||
#: en/mkfs.fat.8:91
|
||||
#, no-wrap
|
||||
msgid "B<-h> I<NUMBER-OF-HIDDEN-SECTORS>"
|
||||
msgstr ""
|
||||
|
||||
#. type: Plain text
|
||||
#: en/mkfs.fat.8:95
|
||||
msgid ""
|
||||
"Select the number of hidden sectors in the volume. Apparently some digital "
|
||||
"cameras get indigestion if you feed them a CF card without such hidden "
|
||||
"sectors, this option allows you to satisfy them."
|
||||
msgstr ""
|
||||
|
||||
#. type: IP
|
||||
#: en/mkfs.fat.8:95
|
||||
#, no-wrap
|
||||
msgid "B<-i> I<VOLUME-ID>"
|
||||
msgstr ""
|
||||
|
||||
#. type: Plain text
|
||||
#: en/mkfs.fat.8:99
|
||||
msgid ""
|
||||
"Sets the volume ID of the newly created filesystem; I<VOLUME-ID> is a 32-bit "
|
||||
"hexadecimal number (for example, 2e24ec82). The default is a number which "
|
||||
"depends on the filesystem creation time."
|
||||
msgstr ""
|
||||
|
||||
#. type: IP
|
||||
#: en/mkfs.fat.8:99
|
||||
#, no-wrap
|
||||
msgid "B<-I>"
|
||||
msgstr ""
|
||||
|
||||
#. type: Plain text
|
||||
#: en/mkfs.fat.8:108
|
||||
msgid ""
|
||||
"It is typical for fixed disk devices to be partitioned so, by default, you "
|
||||
"are not permitted to create a filesystem across the entire device. B<mkfs."
|
||||
"fat> will complain and tell you that it refuses to work. This is different "
|
||||
"when using MO disks. One doesn't always need partitions on MO disks. The "
|
||||
"filesystem can go directly to the whole disk. Under other OSes this is "
|
||||
"known as the 'superfloppy' format. This switch will force B<mkfs.fat> to "
|
||||
"work properly."
|
||||
msgstr ""
|
||||
|
||||
#. type: IP
|
||||
#: en/mkfs.fat.8:108
|
||||
#, no-wrap
|
||||
msgid "B<-l> I<FILENAME>"
|
||||
msgstr ""
|
||||
|
||||
#. type: Plain text
|
||||
#: en/mkfs.fat.8:110
|
||||
msgid "Read the bad blocks list from I<FILENAME>."
|
||||
msgstr ""
|
||||
|
||||
#. type: IP
|
||||
#: en/mkfs.fat.8:110
|
||||
#, no-wrap
|
||||
msgid "B<-m> I<MESSAGE-FILE>"
|
||||
msgstr ""
|
||||
|
||||
#. type: Plain text
|
||||
#: en/mkfs.fat.8:116
|
||||
msgid ""
|
||||
"Sets the message the user receives on attempts to boot this filesystem "
|
||||
"without having properly installed an operating system. The message file "
|
||||
"must not exceed 418 bytes once line feeds have been converted to carriage "
|
||||
"return-line feed combinations, and tabs have been expanded. If the filename "
|
||||
"is a hyphen (-), the text is taken from standard input."
|
||||
msgstr ""
|
||||
|
||||
#. type: IP
|
||||
#: en/mkfs.fat.8:116
|
||||
#, no-wrap
|
||||
msgid "B<-M> I<FAT-MEDIA-TYPE>"
|
||||
msgstr ""
|
||||
|
||||
#. type: Plain text
|
||||
#: en/mkfs.fat.8:120
|
||||
msgid ""
|
||||
"Specify the media type to be stored in the FAT boot sector. This value is "
|
||||
"usually 0xF8 for hard disks and is 0xF0 or a value from 0xF9 to 0xFF for "
|
||||
"floppies or partitions to be used for floppy emulation."
|
||||
msgstr ""
|
||||
|
||||
#. type: IP
|
||||
#: en/mkfs.fat.8:120
|
||||
#, no-wrap
|
||||
msgid "B<-n> I<VOLUME-NAME>"
|
||||
msgstr ""
|
||||
|
||||
#. type: Plain text
|
||||
#: en/mkfs.fat.8:124
|
||||
msgid ""
|
||||
"Sets the volume name (label) of the filesystem. The volume name can be up "
|
||||
"to 11 characters long. The default is no label."
|
||||
msgstr ""
|
||||
|
||||
#. type: IP
|
||||
#: en/mkfs.fat.8:124
|
||||
#, no-wrap
|
||||
msgid "B<-r> I<ROOT-DIR-ENTRIES>"
|
||||
msgstr ""
|
||||
|
||||
#. type: Plain text
|
||||
#: en/mkfs.fat.8:127
|
||||
msgid ""
|
||||
"Select the number of entries available in the root directory. The default "
|
||||
"is 112 or 224 for floppies and 512 for hard disks."
|
||||
msgstr ""
|
||||
|
||||
#. type: IP
|
||||
#: en/mkfs.fat.8:127
|
||||
#, no-wrap
|
||||
msgid "B<-R> I<NUMBER-OF-RESERVED-SECTORS>"
|
||||
msgstr ""
|
||||
|
||||
#. type: Plain text
|
||||
#: en/mkfs.fat.8:131
|
||||
msgid ""
|
||||
"Select the number of reserved sectors. With FAT32 format at least 2 "
|
||||
"reserved sectors are needed, the default is 32. Otherwise the default is 1 "
|
||||
"(only the boot sector)."
|
||||
msgstr ""
|
||||
|
||||
#. type: IP
|
||||
#: en/mkfs.fat.8:131
|
||||
#, no-wrap
|
||||
msgid "B<-s> I<SECTORS-PER-CLUSTER>"
|
||||
msgstr ""
|
||||
|
||||
#. type: Plain text
|
||||
#: en/mkfs.fat.8:134
|
||||
msgid ""
|
||||
"Specify the number of disk sectors per cluster. Must be a power of 2, i.e. "
|
||||
"1, 2, 4, 8, ... 128."
|
||||
msgstr ""
|
||||
|
||||
#. type: IP
|
||||
#: en/mkfs.fat.8:134
|
||||
#, no-wrap
|
||||
msgid "B<-S> I<LOGICAL-SECTOR-SIZE>"
|
||||
msgstr ""
|
||||
|
||||
#. type: Plain text
|
||||
#: en/mkfs.fat.8:138
|
||||
msgid ""
|
||||
"Specify the number of bytes per logical sector. Must be a power of 2 and "
|
||||
"greater than or equal to 512, i.e. 512, 1024, 2048, 4096, 8192, 16384, or "
|
||||
"32768."
|
||||
msgstr ""
|
||||
|
||||
#. type: Plain text
|
||||
#: en/mkfs.fat.8:140
|
||||
msgid "Verbose execution."
|
||||
msgstr ""
|
||||
|
||||
#. type: IP
|
||||
#: en/mkfs.fat.8:140
|
||||
#, no-wrap
|
||||
msgid "B<--invariant>"
|
||||
msgstr ""
|
||||
|
||||
#. type: Plain text
|
||||
#: en/mkfs.fat.8:146
|
||||
msgid ""
|
||||
"Use constants for normally randomly generated or time based data such as "
|
||||
"volume ID and creation time. Multiple runs of B<mkfs.fat> on the same "
|
||||
"device create identical results with this option. Its main purpose is "
|
||||
"testing B<mkfs.fat>."
|
||||
msgstr ""
|
||||
|
||||
#. type: IP
|
||||
#: en/mkfs.fat.8:146
|
||||
#, no-wrap
|
||||
msgid "B<--help>"
|
||||
msgstr ""
|
||||
|
||||
#. ----------------------------------------------------------------------------
|
||||
#. type: Plain text
|
||||
#: en/mkfs.fat.8:149
|
||||
msgid "Display option summary and exit."
|
||||
msgstr ""
|
||||
|
||||
#. ----------------------------------------------------------------------------
|
||||
#. type: Plain text
|
||||
#: en/mkfs.fat.8:155
|
||||
msgid ""
|
||||
"B<mkfs.fat> can not create boot-able filesystems. This isn't as easy as you "
|
||||
"might think at first glance for various reasons and has been discussed a lot "
|
||||
"already. B<mkfs.fat> simply will not support it ;)"
|
||||
msgstr ""
|
||||
@@ -0,0 +1,568 @@
|
||||
/* boot.c - Read and analyze ia PC/MS-DOS boot sector
|
||||
|
||||
Copyright (C) 1993 Werner Almesberger <werner.almesberger@lrc.di.epfl.ch>
|
||||
Copyright (C) 1998 Roman Hodek <Roman.Hodek@informatik.uni-erlangen.de>
|
||||
Copyright (C) 2008-2014 Daniel Baumann <mail@daniel-baumann.ch>
|
||||
|
||||
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 3 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, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
The complete text of the GNU General Public License
|
||||
can be found in /usr/share/common-licenses/GPL-3 file.
|
||||
*/
|
||||
|
||||
/* FAT32, VFAT, Atari format support, and various fixes additions May 1998
|
||||
* by Roman Hodek <Roman.Hodek@informatik.uni-erlangen.de> */
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <time.h>
|
||||
|
||||
#include "common.h"
|
||||
#include "fsck.fat.h"
|
||||
#include "fat.h"
|
||||
#include "io.h"
|
||||
#include "boot.h"
|
||||
#include "check.h"
|
||||
|
||||
#define ROUND_TO_MULTIPLE(n,m) ((n) && (m) ? (n)+(m)-1-((n)-1)%(m) : 0)
|
||||
/* don't divide by zero */
|
||||
|
||||
/* cut-over cluster counts for FAT12 and FAT16 */
|
||||
#define FAT12_THRESHOLD 4085
|
||||
#define FAT16_THRESHOLD 65525
|
||||
|
||||
static struct {
|
||||
uint8_t media;
|
||||
const char *descr;
|
||||
} mediabytes[] = {
|
||||
{
|
||||
0xf0, "5.25\" or 3.5\" HD floppy"}, {
|
||||
0xf8, "hard disk"}, {
|
||||
0xf9, "3,5\" 720k floppy 2s/80tr/9sec or "
|
||||
"5.25\" 1.2M floppy 2s/80tr/15sec"}, {
|
||||
0xfa, "5.25\" 320k floppy 1s/80tr/8sec"}, {
|
||||
0xfb, "3.5\" 640k floppy 2s/80tr/8sec"}, {
|
||||
0xfc, "5.25\" 180k floppy 1s/40tr/9sec"}, {
|
||||
0xfd, "5.25\" 360k floppy 2s/40tr/9sec"}, {
|
||||
0xfe, "5.25\" 160k floppy 1s/40tr/8sec"}, {
|
||||
0xff, "5.25\" 320k floppy 2s/40tr/8sec"},};
|
||||
|
||||
/* Unaligned fields must first be accessed byte-wise */
|
||||
#define GET_UNALIGNED_W(f) \
|
||||
( (uint16_t)f[0] | ((uint16_t)f[1]<<8) )
|
||||
|
||||
static const char *get_media_descr(unsigned char media)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = 0; i < sizeof(mediabytes) / sizeof(*mediabytes); ++i) {
|
||||
if (mediabytes[i].media == media)
|
||||
return (mediabytes[i].descr);
|
||||
}
|
||||
return ("undefined");
|
||||
}
|
||||
|
||||
static void dump_boot(DOS_FS * fs, struct boot_sector *b, unsigned lss)
|
||||
{
|
||||
unsigned short sectors;
|
||||
|
||||
printf("Boot sector contents:\n");
|
||||
if (!atari_format) {
|
||||
char id[9];
|
||||
strncpy(id, (const char *)b->system_id, 8);
|
||||
id[8] = 0;
|
||||
printf("System ID \"%s\"\n", id);
|
||||
} else {
|
||||
/* On Atari, a 24 bit serial number is stored at offset 8 of the boot
|
||||
* sector */
|
||||
printf("Serial number 0x%x\n",
|
||||
b->system_id[5] | (b->system_id[6] << 8) | (b->
|
||||
system_id[7] << 16));
|
||||
}
|
||||
printf("Media byte 0x%02x (%s)\n", b->media, get_media_descr(b->media));
|
||||
printf("%10d bytes per logical sector\n", GET_UNALIGNED_W(b->sector_size));
|
||||
printf("%10d bytes per cluster\n", fs->cluster_size);
|
||||
printf("%10d reserved sector%s\n", le16toh(b->reserved),
|
||||
le16toh(b->reserved) == 1 ? "" : "s");
|
||||
printf("First FAT starts at byte %llu (sector %llu)\n",
|
||||
(unsigned long long)fs->fat_start,
|
||||
(unsigned long long)fs->fat_start / lss);
|
||||
printf("%10d FATs, %d bit entries\n", b->fats, fs->fat_bits);
|
||||
printf("%10d bytes per FAT (= %u sectors)\n", fs->fat_size,
|
||||
fs->fat_size / lss);
|
||||
if (!fs->root_cluster) {
|
||||
printf("Root directory starts at byte %llu (sector %llu)\n",
|
||||
(unsigned long long)fs->root_start,
|
||||
(unsigned long long)fs->root_start / lss);
|
||||
printf("%10d root directory entries\n", fs->root_entries);
|
||||
} else {
|
||||
printf("Root directory start at cluster %lu (arbitrary size)\n",
|
||||
(unsigned long)fs->root_cluster);
|
||||
}
|
||||
printf("Data area starts at byte %llu (sector %llu)\n",
|
||||
(unsigned long long)fs->data_start,
|
||||
(unsigned long long)fs->data_start / lss);
|
||||
printf("%10lu data clusters (%llu bytes)\n", (unsigned long)fs->clusters,
|
||||
(unsigned long long)fs->clusters * fs->cluster_size);
|
||||
printf("%u sectors/track, %u heads\n", le16toh(b->secs_track),
|
||||
le16toh(b->heads));
|
||||
printf("%10u hidden sectors\n", atari_format ?
|
||||
/* On Atari, the hidden field is only 16 bit wide and unused */
|
||||
(((unsigned char *)&b->hidden)[0] |
|
||||
((unsigned char *)&b->hidden)[1] << 8) : le32toh(b->hidden));
|
||||
sectors = GET_UNALIGNED_W(b->sectors);
|
||||
printf("%10u sectors total\n", sectors ? sectors : le32toh(b->total_sect));
|
||||
}
|
||||
|
||||
static void check_backup_boot(DOS_FS * fs, struct boot_sector *b, int lss)
|
||||
{
|
||||
struct boot_sector b2;
|
||||
|
||||
if (!fs->backupboot_start) {
|
||||
printf("There is no backup boot sector.\n");
|
||||
if (le16toh(b->reserved) < 3) {
|
||||
printf("And there is no space for creating one!\n");
|
||||
return;
|
||||
}
|
||||
if (interactive)
|
||||
printf("1) Create one\n2) Do without a backup\n");
|
||||
else
|
||||
printf(" Auto-creating backup boot block.\n");
|
||||
if (!interactive || get_key("12", "?") == '1') {
|
||||
int bbs;
|
||||
/* The usual place for the backup boot sector is sector 6. Choose
|
||||
* that or the last reserved sector. */
|
||||
if (le16toh(b->reserved) >= 7 && le16toh(b->info_sector) != 6)
|
||||
bbs = 6;
|
||||
else {
|
||||
bbs = le16toh(b->reserved) - 1;
|
||||
if (bbs == le16toh(b->info_sector))
|
||||
--bbs; /* this is never 0, as we checked reserved >= 3! */
|
||||
}
|
||||
fs->backupboot_start = bbs * lss;
|
||||
b->backup_boot = htole16(bbs);
|
||||
fs_write(fs->backupboot_start, sizeof(*b), b);
|
||||
fs_write((loff_t) offsetof(struct boot_sector, backup_boot),
|
||||
sizeof(b->backup_boot), &b->backup_boot);
|
||||
printf("Created backup of boot sector in sector %d\n", bbs);
|
||||
return;
|
||||
} else
|
||||
return;
|
||||
}
|
||||
|
||||
fs_read(fs->backupboot_start, sizeof(b2), &b2);
|
||||
if (memcmp(b, &b2, sizeof(b2)) != 0) {
|
||||
/* there are any differences */
|
||||
uint8_t *p, *q;
|
||||
int i, pos, first = 1;
|
||||
char buf[20];
|
||||
|
||||
printf("There are differences between boot sector and its backup.\n");
|
||||
printf("This is mostly harmless. Differences: (offset:original/backup)\n ");
|
||||
pos = 2;
|
||||
for (p = (uint8_t *) b, q = (uint8_t *) & b2, i = 0; i < sizeof(b2);
|
||||
++p, ++q, ++i) {
|
||||
if (*p != *q) {
|
||||
sprintf(buf, "%s%u:%02x/%02x", first ? "" : ", ",
|
||||
(unsigned)(p - (uint8_t *) b), *p, *q);
|
||||
if (pos + strlen(buf) > 78)
|
||||
printf("\n "), pos = 2;
|
||||
printf("%s", buf);
|
||||
pos += strlen(buf);
|
||||
first = 0;
|
||||
}
|
||||
}
|
||||
printf("\n");
|
||||
|
||||
if (interactive)
|
||||
printf("1) Copy original to backup\n"
|
||||
"2) Copy backup to original\n" "3) No action\n");
|
||||
else
|
||||
printf(" Not automatically fixing this.\n");
|
||||
switch (interactive ? get_key("123", "?") : '3') {
|
||||
case '1':
|
||||
fs_write(fs->backupboot_start, sizeof(*b), b);
|
||||
break;
|
||||
case '2':
|
||||
fs_write(0, sizeof(b2), &b2);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void init_fsinfo(struct info_sector *i)
|
||||
{
|
||||
i->magic = htole32(0x41615252);
|
||||
i->signature = htole32(0x61417272);
|
||||
i->free_clusters = htole32(-1);
|
||||
i->next_cluster = htole32(2);
|
||||
i->boot_sign = htole16(0xaa55);
|
||||
}
|
||||
|
||||
static void read_fsinfo(DOS_FS * fs, struct boot_sector *b, int lss)
|
||||
{
|
||||
struct info_sector i;
|
||||
|
||||
if (!b->info_sector) {
|
||||
printf("No FSINFO sector\n");
|
||||
if (interactive)
|
||||
printf("1) Create one\n2) Do without FSINFO\n");
|
||||
else
|
||||
printf(" Not automatically creating it.\n");
|
||||
if (interactive && get_key("12", "?") == '1') {
|
||||
/* search for a free reserved sector (not boot sector and not
|
||||
* backup boot sector) */
|
||||
uint32_t s;
|
||||
for (s = 1; s < le16toh(b->reserved); ++s)
|
||||
if (s != le16toh(b->backup_boot))
|
||||
break;
|
||||
if (s > 0 && s < le16toh(b->reserved)) {
|
||||
init_fsinfo(&i);
|
||||
fs_write((loff_t) s * lss, sizeof(i), &i);
|
||||
b->info_sector = htole16(s);
|
||||
fs_write((loff_t) offsetof(struct boot_sector, info_sector),
|
||||
sizeof(b->info_sector), &b->info_sector);
|
||||
if (fs->backupboot_start)
|
||||
fs_write(fs->backupboot_start +
|
||||
offsetof(struct boot_sector, info_sector),
|
||||
sizeof(b->info_sector), &b->info_sector);
|
||||
} else {
|
||||
printf("No free reserved sector found -- "
|
||||
"no space for FSINFO sector!\n");
|
||||
return;
|
||||
}
|
||||
} else
|
||||
return;
|
||||
}
|
||||
|
||||
fs->fsinfo_start = le16toh(b->info_sector) * lss;
|
||||
fs_read(fs->fsinfo_start, sizeof(i), &i);
|
||||
|
||||
if (i.magic != htole32(0x41615252) ||
|
||||
i.signature != htole32(0x61417272) || i.boot_sign != htole16(0xaa55)) {
|
||||
printf("FSINFO sector has bad magic number(s):\n");
|
||||
if (i.magic != htole32(0x41615252))
|
||||
printf(" Offset %llu: 0x%08x != expected 0x%08x\n",
|
||||
(unsigned long long)offsetof(struct info_sector, magic),
|
||||
le32toh(i.magic), 0x41615252);
|
||||
if (i.signature != htole32(0x61417272))
|
||||
printf(" Offset %llu: 0x%08x != expected 0x%08x\n",
|
||||
(unsigned long long)offsetof(struct info_sector, signature),
|
||||
le32toh(i.signature), 0x61417272);
|
||||
if (i.boot_sign != htole16(0xaa55))
|
||||
printf(" Offset %llu: 0x%04x != expected 0x%04x\n",
|
||||
(unsigned long long)offsetof(struct info_sector, boot_sign),
|
||||
le16toh(i.boot_sign), 0xaa55);
|
||||
if (interactive)
|
||||
printf("1) Correct\n2) Don't correct (FSINFO invalid then)\n");
|
||||
else
|
||||
printf(" Auto-correcting it.\n");
|
||||
if (!interactive || get_key("12", "?") == '1') {
|
||||
init_fsinfo(&i);
|
||||
fs_write(fs->fsinfo_start, sizeof(i), &i);
|
||||
} else
|
||||
fs->fsinfo_start = 0;
|
||||
}
|
||||
|
||||
if (fs->fsinfo_start)
|
||||
fs->free_clusters = le32toh(i.free_clusters);
|
||||
}
|
||||
|
||||
static char print_fat_dirty_state(void)
|
||||
{
|
||||
printf("Dirty bit is set. Fs was not properly unmounted and"
|
||||
" some data may be corrupt.\n");
|
||||
|
||||
if (interactive) {
|
||||
printf("1) Remove dirty bit\n" "2) No action\n");
|
||||
return get_key("12", "?");
|
||||
} else
|
||||
printf(" Automatically removing dirty bit.\n");
|
||||
return '1';
|
||||
}
|
||||
|
||||
static void check_fat_state_bit(DOS_FS * fs, void *b)
|
||||
{
|
||||
if (fs->fat_bits == 32) {
|
||||
struct boot_sector *b32 = b;
|
||||
|
||||
if (b32->reserved3 & FAT_STATE_DIRTY) {
|
||||
printf("0x41: ");
|
||||
if (print_fat_dirty_state() == '1') {
|
||||
b32->reserved3 &= ~FAT_STATE_DIRTY;
|
||||
fs_write(0, sizeof(*b32), b32);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
struct boot_sector_16 *b16 = b;
|
||||
|
||||
if (b16->reserved2 & FAT_STATE_DIRTY) {
|
||||
printf("0x25: ");
|
||||
if (print_fat_dirty_state() == '1') {
|
||||
b16->reserved2 &= ~FAT_STATE_DIRTY;
|
||||
fs_write(0, sizeof(*b16), b16);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void read_boot(DOS_FS * fs)
|
||||
{
|
||||
struct boot_sector b;
|
||||
unsigned total_sectors;
|
||||
unsigned short logical_sector_size, sectors;
|
||||
unsigned fat_length;
|
||||
loff_t data_size;
|
||||
|
||||
fs_read(0, sizeof(b), &b);
|
||||
logical_sector_size = GET_UNALIGNED_W(b.sector_size);
|
||||
if (!logical_sector_size)
|
||||
die("Logical sector size is zero.");
|
||||
|
||||
/* This was moved up because it's the first thing that will fail */
|
||||
/* if the platform needs special handling of unaligned multibyte accesses */
|
||||
/* but such handling isn't being provided. See GET_UNALIGNED_W() above. */
|
||||
if (logical_sector_size & (SECTOR_SIZE - 1))
|
||||
die("Logical sector size (%d bytes) is not a multiple of the physical "
|
||||
"sector size.", logical_sector_size);
|
||||
|
||||
fs->cluster_size = b.cluster_size * logical_sector_size;
|
||||
if (!fs->cluster_size)
|
||||
die("Cluster size is zero.");
|
||||
if (b.fats != 2 && b.fats != 1)
|
||||
die("Currently, only 1 or 2 FATs are supported, not %d.\n", b.fats);
|
||||
fs->nfats = b.fats;
|
||||
sectors = GET_UNALIGNED_W(b.sectors);
|
||||
total_sectors = sectors ? sectors : le32toh(b.total_sect);
|
||||
if (verbose)
|
||||
printf("Checking we can access the last sector of the filesystem\n");
|
||||
/* Can't access last odd sector anyway, so round down */
|
||||
fs_test((loff_t) ((total_sectors & ~1) - 1) * (loff_t) logical_sector_size,
|
||||
logical_sector_size);
|
||||
fat_length = le16toh(b.fat_length) ?
|
||||
le16toh(b.fat_length) : le32toh(b.fat32_length);
|
||||
fs->fat_start = (loff_t) le16toh(b.reserved) * logical_sector_size;
|
||||
fs->root_start = ((loff_t) le16toh(b.reserved) + b.fats * fat_length) *
|
||||
logical_sector_size;
|
||||
fs->root_entries = GET_UNALIGNED_W(b.dir_entries);
|
||||
fs->data_start = fs->root_start + ROUND_TO_MULTIPLE(fs->root_entries <<
|
||||
MSDOS_DIR_BITS,
|
||||
logical_sector_size);
|
||||
data_size = (loff_t) total_sectors *logical_sector_size - fs->data_start;
|
||||
fs->clusters = data_size / fs->cluster_size;
|
||||
fs->root_cluster = 0; /* indicates standard, pre-FAT32 root dir */
|
||||
fs->fsinfo_start = 0; /* no FSINFO structure */
|
||||
fs->free_clusters = -1; /* unknown */
|
||||
if (!b.fat_length && b.fat32_length) {
|
||||
fs->fat_bits = 32;
|
||||
fs->root_cluster = le32toh(b.root_cluster);
|
||||
if (!fs->root_cluster && fs->root_entries)
|
||||
/* M$ hasn't specified this, but it looks reasonable: If
|
||||
* root_cluster is 0 but there is a separate root dir
|
||||
* (root_entries != 0), we handle the root dir the old way. Give a
|
||||
* warning, but convertig to a root dir in a cluster chain seems
|
||||
* to complex for now... */
|
||||
printf("Warning: FAT32 root dir not in cluster chain! "
|
||||
"Compatibility mode...\n");
|
||||
else if (!fs->root_cluster && !fs->root_entries)
|
||||
die("No root directory!");
|
||||
else if (fs->root_cluster && fs->root_entries)
|
||||
printf("Warning: FAT32 root dir is in a cluster chain, but "
|
||||
"a separate root dir\n"
|
||||
" area is defined. Cannot fix this easily.\n");
|
||||
if (fs->clusters < FAT16_THRESHOLD)
|
||||
printf("Warning: Filesystem is FAT32 according to fat_length "
|
||||
"and fat32_length fields,\n"
|
||||
" but has only %lu clusters, less than the required "
|
||||
"minimum of %d.\n"
|
||||
" This may lead to problems on some systems.\n",
|
||||
(unsigned long)fs->clusters, FAT16_THRESHOLD);
|
||||
|
||||
check_fat_state_bit(fs, &b);
|
||||
fs->backupboot_start = le16toh(b.backup_boot) * logical_sector_size;
|
||||
check_backup_boot(fs, &b, logical_sector_size);
|
||||
|
||||
read_fsinfo(fs, &b, logical_sector_size);
|
||||
} else if (!atari_format) {
|
||||
/* On real MS-DOS, a 16 bit FAT is used whenever there would be too
|
||||
* much clusers otherwise. */
|
||||
fs->fat_bits = (fs->clusters >= FAT12_THRESHOLD) ? 16 : 12;
|
||||
if (fs->clusters >= FAT16_THRESHOLD)
|
||||
die("Too many clusters (%lu) for FAT16 filesystem.", fs->clusters);
|
||||
check_fat_state_bit(fs, &b);
|
||||
} else {
|
||||
/* On Atari, things are more difficult: GEMDOS always uses 12bit FATs
|
||||
* on floppies, and always 16 bit on harddisks. */
|
||||
fs->fat_bits = 16; /* assume 16 bit FAT for now */
|
||||
/* If more clusters than fat entries in 16-bit fat, we assume
|
||||
* it's a real MSDOS FS with 12-bit fat. */
|
||||
if (fs->clusters + 2 > fat_length * logical_sector_size * 8 / 16 ||
|
||||
/* if it's a floppy disk --> 12bit fat */
|
||||
device_no == 2 ||
|
||||
/* if it's a ramdisk or loopback device and has one of the usual
|
||||
* floppy sizes -> 12bit FAT */
|
||||
((device_no == 1 || device_no == 7) &&
|
||||
(total_sectors == 720 || total_sectors == 1440 ||
|
||||
total_sectors == 2880)))
|
||||
fs->fat_bits = 12;
|
||||
}
|
||||
/* On FAT32, the high 4 bits of a FAT entry are reserved */
|
||||
fs->eff_fat_bits = (fs->fat_bits == 32) ? 28 : fs->fat_bits;
|
||||
fs->fat_size = fat_length * logical_sector_size;
|
||||
|
||||
fs->label = calloc(12, sizeof(uint8_t));
|
||||
if (fs->fat_bits == 12 || fs->fat_bits == 16) {
|
||||
struct boot_sector_16 *b16 = (struct boot_sector_16 *)&b;
|
||||
if (b16->extended_sig == 0x29)
|
||||
memmove(fs->label, b16->label, 11);
|
||||
else
|
||||
fs->label = NULL;
|
||||
} else if (fs->fat_bits == 32) {
|
||||
if (b.extended_sig == 0x29)
|
||||
memmove(fs->label, &b.label, 11);
|
||||
else
|
||||
fs->label = NULL;
|
||||
}
|
||||
|
||||
if (fs->clusters >
|
||||
((uint64_t)fs->fat_size * 8 / fs->fat_bits) - 2)
|
||||
die("Filesystem has %d clusters but only space for %d FAT entries.",
|
||||
fs->clusters,
|
||||
((unsigned long long)fs->fat_size * 8 / fs->fat_bits) - 2);
|
||||
if (!fs->root_entries && !fs->root_cluster)
|
||||
die("Root directory has zero size.");
|
||||
if (fs->root_entries & (MSDOS_DPS - 1))
|
||||
die("Root directory (%d entries) doesn't span an integral number of "
|
||||
"sectors.", fs->root_entries);
|
||||
if (logical_sector_size & (SECTOR_SIZE - 1))
|
||||
die("Logical sector size (%d bytes) is not a multiple of the physical "
|
||||
"sector size.", logical_sector_size);
|
||||
#if 0 /* linux kernel doesn't check that either */
|
||||
/* ++roman: On Atari, these two fields are often left uninitialized */
|
||||
if (!atari_format && (!b.secs_track || !b.heads))
|
||||
die("Invalid disk format in boot sector.");
|
||||
#endif
|
||||
if (verbose)
|
||||
dump_boot(fs, &b, logical_sector_size);
|
||||
}
|
||||
|
||||
static void write_boot_label(DOS_FS * fs, char *label)
|
||||
{
|
||||
if (fs->fat_bits == 12 || fs->fat_bits == 16) {
|
||||
struct boot_sector_16 b16;
|
||||
|
||||
fs_read(0, sizeof(b16), &b16);
|
||||
if (b16.extended_sig != 0x29) {
|
||||
b16.extended_sig = 0x29;
|
||||
b16.serial = 0;
|
||||
memmove(b16.fs_type, fs->fat_bits == 12 ? "FAT12 " : "FAT16 ",
|
||||
8);
|
||||
}
|
||||
memmove(b16.label, label, 11);
|
||||
fs_write(0, sizeof(b16), &b16);
|
||||
} else if (fs->fat_bits == 32) {
|
||||
struct boot_sector b;
|
||||
|
||||
fs_read(0, sizeof(b), &b);
|
||||
if (b.extended_sig != 0x29) {
|
||||
b.extended_sig = 0x29;
|
||||
b.serial = 0;
|
||||
memmove(b.fs_type, "FAT32 ", 8);
|
||||
}
|
||||
memmove(b.label, label, 11);
|
||||
fs_write(0, sizeof(b), &b);
|
||||
if (fs->backupboot_start)
|
||||
fs_write(fs->backupboot_start, sizeof(b), &b);
|
||||
}
|
||||
}
|
||||
|
||||
loff_t find_volume_de(DOS_FS * fs, DIR_ENT * de)
|
||||
{
|
||||
uint32_t cluster;
|
||||
loff_t offset;
|
||||
int i;
|
||||
|
||||
if (fs->root_cluster) {
|
||||
for (cluster = fs->root_cluster;
|
||||
cluster != 0 && cluster != -1;
|
||||
cluster = next_cluster(fs, cluster)) {
|
||||
offset = cluster_start(fs, cluster);
|
||||
for (i = 0; i * sizeof(DIR_ENT) < fs->cluster_size; i++) {
|
||||
fs_read(offset, sizeof(DIR_ENT), de);
|
||||
if (de->attr != VFAT_LN_ATTR && de->attr & ATTR_VOLUME)
|
||||
return offset;
|
||||
offset += sizeof(DIR_ENT);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
for (i = 0; i < fs->root_entries; i++) {
|
||||
offset = fs->root_start + i * sizeof(DIR_ENT);
|
||||
fs_read(offset, sizeof(DIR_ENT), de);
|
||||
if (de->attr != VFAT_LN_ATTR && de->attr & ATTR_VOLUME)
|
||||
return offset;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void write_volume_label(DOS_FS * fs, char *label)
|
||||
{
|
||||
time_t now = time(NULL);
|
||||
struct tm *mtime = localtime(&now);
|
||||
loff_t offset;
|
||||
int created;
|
||||
DIR_ENT de;
|
||||
|
||||
created = 0;
|
||||
offset = find_volume_de(fs, &de);
|
||||
if (offset == 0) {
|
||||
created = 1;
|
||||
offset = alloc_rootdir_entry(fs, &de, label);
|
||||
}
|
||||
memcpy(de.name, label, 11);
|
||||
de.time = htole16((unsigned short)((mtime->tm_sec >> 1) +
|
||||
(mtime->tm_min << 5) +
|
||||
(mtime->tm_hour << 11)));
|
||||
de.date = htole16((unsigned short)(mtime->tm_mday +
|
||||
((mtime->tm_mon + 1) << 5) +
|
||||
((mtime->tm_year - 80) << 9)));
|
||||
if (created) {
|
||||
de.attr = ATTR_VOLUME;
|
||||
de.ctime_ms = 0;
|
||||
de.ctime = de.time;
|
||||
de.cdate = de.date;
|
||||
de.adate = de.date;
|
||||
de.starthi = 0;
|
||||
de.start = 0;
|
||||
de.size = 0;
|
||||
}
|
||||
|
||||
fs_write(offset, sizeof(DIR_ENT), &de);
|
||||
}
|
||||
|
||||
void write_label(DOS_FS * fs, char *label)
|
||||
{
|
||||
int l = strlen(label);
|
||||
|
||||
while (l < 11)
|
||||
label[l++] = ' ';
|
||||
|
||||
write_boot_label(fs, label);
|
||||
write_volume_label(fs, label);
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
/* boot.h - Read and analyze ia PC/MS-DOS boot sector
|
||||
|
||||
Copyright (C) 1993 Werner Almesberger <werner.almesberger@lrc.di.epfl.ch>
|
||||
Copyright (C) 2008-2014 Daniel Baumann <mail@daniel-baumann.ch>
|
||||
|
||||
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 3 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, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
The complete text of the GNU General Public License
|
||||
can be found in /usr/share/common-licenses/GPL-3 file.
|
||||
*/
|
||||
|
||||
#ifndef _BOOT_H
|
||||
#define _BOOT_H
|
||||
|
||||
void read_boot(DOS_FS * fs);
|
||||
void write_label(DOS_FS * fs, char *label);
|
||||
loff_t find_volume_de(DOS_FS * fs, DIR_ENT * de);
|
||||
|
||||
/* Reads the boot sector from the currently open device and initializes *FS */
|
||||
|
||||
#endif
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,40 @@
|
||||
/* check.h - Check and repair a PC/MS-DOS filesystem
|
||||
|
||||
Copyright (C) 1993 Werner Almesberger <werner.almesberger@lrc.di.epfl.ch>
|
||||
Copyright (C) 2008-2014 Daniel Baumann <mail@daniel-baumann.ch>
|
||||
|
||||
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 3 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, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
The complete text of the GNU General Public License
|
||||
can be found in /usr/share/common-licenses/GPL-3 file.
|
||||
*/
|
||||
|
||||
#ifndef _CHECK_H
|
||||
#define _CHECK_H
|
||||
|
||||
loff_t alloc_rootdir_entry(DOS_FS * fs, DIR_ENT * de, const char *pattern);
|
||||
|
||||
/* Allocate a free slot in the root directory for a new file. The file name is
|
||||
constructed after 'pattern', which must include a %d type format for printf
|
||||
and expand to exactly 11 characters. The name actually used is written into
|
||||
the 'de' structure, the rest of *de is cleared. The offset returned is to
|
||||
where in the filesystem the entry belongs. */
|
||||
|
||||
int scan_root(DOS_FS * fs);
|
||||
|
||||
/* Scans the root directory and recurses into all subdirectories. See check.c
|
||||
for all the details. Returns a non-zero integer if the filesystem has to
|
||||
be checked again. */
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,119 @@
|
||||
/* common.c - Common functions
|
||||
|
||||
Copyright (C) 1993 Werner Almesberger <werner.almesberger@lrc.di.epfl.ch>
|
||||
Copyright (C) 1998 Roman Hodek <Roman.Hodek@informatik.uni-erlangen.de>
|
||||
Copyright (C) 2008-2014 Daniel Baumann <mail@daniel-baumann.ch>
|
||||
|
||||
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 3 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, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
The complete text of the GNU General Public License
|
||||
can be found in /usr/share/common-licenses/GPL-3 file.
|
||||
*/
|
||||
|
||||
/* FAT32, VFAT, Atari format support, and various fixes additions May 1998
|
||||
* by Roman Hodek <Roman.Hodek@informatik.uni-erlangen.de> */
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdarg.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include "common.h"
|
||||
|
||||
typedef struct _link {
|
||||
void *data;
|
||||
struct _link *next;
|
||||
} LINK;
|
||||
|
||||
void die(const char *msg, ...)
|
||||
{
|
||||
va_list args;
|
||||
|
||||
va_start(args, msg);
|
||||
vfprintf(stderr, msg, args);
|
||||
va_end(args);
|
||||
fprintf(stderr, "\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
void pdie(const char *msg, ...)
|
||||
{
|
||||
va_list args;
|
||||
|
||||
va_start(args, msg);
|
||||
vfprintf(stderr, msg, args);
|
||||
va_end(args);
|
||||
fprintf(stderr, ":%s\n", strerror(errno));
|
||||
exit(1);
|
||||
}
|
||||
|
||||
void *alloc(int size)
|
||||
{
|
||||
void *this;
|
||||
|
||||
if ((this = malloc(size)))
|
||||
return this;
|
||||
pdie("malloc");
|
||||
return NULL; /* for GCC */
|
||||
}
|
||||
|
||||
void *qalloc(void **root, int size)
|
||||
{
|
||||
LINK *link;
|
||||
|
||||
link = alloc(sizeof(LINK));
|
||||
link->next = *root;
|
||||
*root = link;
|
||||
return link->data = alloc(size);
|
||||
}
|
||||
|
||||
void qfree(void **root)
|
||||
{
|
||||
LINK *this;
|
||||
|
||||
while (*root) {
|
||||
this = (LINK *) * root;
|
||||
*root = this->next;
|
||||
free(this->data);
|
||||
free(this);
|
||||
}
|
||||
}
|
||||
|
||||
int min(int a, int b)
|
||||
{
|
||||
return a < b ? a : b;
|
||||
}
|
||||
|
||||
char get_key(const char *valid, const char *prompt)
|
||||
{
|
||||
int ch, okay;
|
||||
|
||||
while (1) {
|
||||
if (prompt)
|
||||
printf("%s ", prompt);
|
||||
fflush(stdout);
|
||||
while (ch = getchar(), ch == ' ' || ch == '\t') ;
|
||||
if (ch == EOF)
|
||||
exit(1);
|
||||
if (!strchr(valid, okay = ch))
|
||||
okay = 0;
|
||||
while (ch = getchar(), ch != '\n' && ch != EOF) ;
|
||||
if (ch == EOF)
|
||||
exit(1);
|
||||
if (okay)
|
||||
return okay;
|
||||
printf("Invalid input.\n");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
/* common.h - Common functions
|
||||
|
||||
Copyright (C) 1993 Werner Almesberger <werner.almesberger@lrc.di.epfl.ch>
|
||||
Copyright (C) 2008-2014 Daniel Baumann <mail@daniel-baumann.ch>
|
||||
|
||||
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 3 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, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
The complete text of the GNU General Public License
|
||||
can be found in /usr/share/common-licenses/GPL-3 file.
|
||||
*/
|
||||
|
||||
#ifndef _COMMON_H
|
||||
#define _COMMON_H
|
||||
|
||||
void die(const char *msg, ...) __attribute((noreturn));
|
||||
|
||||
/* Displays a prinf-style message and terminates the program. */
|
||||
|
||||
void pdie(const char *msg, ...) __attribute((noreturn));
|
||||
|
||||
/* Like die, but appends an error message according to the state of errno. */
|
||||
|
||||
void *alloc(int size);
|
||||
|
||||
/* mallocs SIZE bytes and returns a pointer to the data. Terminates the program
|
||||
if malloc fails. */
|
||||
|
||||
void *qalloc(void **root, int size);
|
||||
|
||||
/* Like alloc, but registers the data area in a list described by ROOT. */
|
||||
|
||||
void qfree(void **root);
|
||||
|
||||
/* Deallocates all qalloc'ed data areas described by ROOT. */
|
||||
|
||||
int min(int a, int b);
|
||||
|
||||
/* Returns the smaller integer value of a and b. */
|
||||
|
||||
char get_key(const char *valid, const char *prompt);
|
||||
|
||||
/* Displays PROMPT and waits for user input. Only characters in VALID are
|
||||
accepted. Terminates the program on EOF. Returns the character. */
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,558 @@
|
||||
/* fat.c - Read/write access to the FAT
|
||||
|
||||
Copyright (C) 1993 Werner Almesberger <werner.almesberger@lrc.di.epfl.ch>
|
||||
Copyright (C) 1998 Roman Hodek <Roman.Hodek@informatik.uni-erlangen.de>
|
||||
Copyright (C) 2008-2014 Daniel Baumann <mail@daniel-baumann.ch>
|
||||
|
||||
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 3 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, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
The complete text of the GNU General Public License
|
||||
can be found in /usr/share/common-licenses/GPL-3 file.
|
||||
*/
|
||||
|
||||
/* FAT32, VFAT, Atari format support, and various fixes additions May 1998
|
||||
* by Roman Hodek <Roman.Hodek@informatik.uni-erlangen.de> */
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "common.h"
|
||||
#include "fsck.fat.h"
|
||||
#include "io.h"
|
||||
#include "check.h"
|
||||
#include "fat.h"
|
||||
|
||||
/**
|
||||
* Fetch the FAT entry for a specified cluster.
|
||||
*
|
||||
* @param[out] entry Cluster to which cluster of interest is linked
|
||||
* @param[in] fat FAT table for the partition
|
||||
* @param[in] cluster Cluster of interest
|
||||
* @param[in] fs Information from the FAT boot sectors (bits per FAT entry)
|
||||
*/
|
||||
void get_fat(FAT_ENTRY * entry, void *fat, uint32_t cluster, DOS_FS * fs)
|
||||
{
|
||||
unsigned char *ptr;
|
||||
|
||||
switch (fs->fat_bits) {
|
||||
case 12:
|
||||
ptr = &((unsigned char *)fat)[cluster * 3 / 2];
|
||||
entry->value = 0xfff & (cluster & 1 ? (ptr[0] >> 4) | (ptr[1] << 4) :
|
||||
(ptr[0] | ptr[1] << 8));
|
||||
break;
|
||||
case 16:
|
||||
entry->value = le16toh(((unsigned short *)fat)[cluster]);
|
||||
break;
|
||||
case 32:
|
||||
/* According to M$, the high 4 bits of a FAT32 entry are reserved and
|
||||
* are not part of the cluster number. So we cut them off. */
|
||||
{
|
||||
uint32_t e = le32toh(((unsigned int *)fat)[cluster]);
|
||||
entry->value = e & 0xfffffff;
|
||||
entry->reserved = e >> 28;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
die("Bad FAT entry size: %d bits.", fs->fat_bits);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Build a bookkeeping structure from the partition's FAT table.
|
||||
* If the partition has multiple FATs and they don't agree, try to pick a winner,
|
||||
* and queue a command to overwrite the loser.
|
||||
* One error that is fixed here is a cluster that links to something out of range.
|
||||
*
|
||||
* @param[inout] fs Information about the filesystem
|
||||
*/
|
||||
void read_fat(DOS_FS * fs)
|
||||
{
|
||||
int eff_size, alloc_size;
|
||||
uint32_t i;
|
||||
void *first, *second = NULL;
|
||||
int first_ok, second_ok;
|
||||
uint32_t total_num_clusters;
|
||||
|
||||
/* Clean up from previous pass */
|
||||
if (fs->fat)
|
||||
free(fs->fat);
|
||||
if (fs->cluster_owner)
|
||||
free(fs->cluster_owner);
|
||||
fs->fat = NULL;
|
||||
fs->cluster_owner = NULL;
|
||||
|
||||
total_num_clusters = fs->clusters + 2UL;
|
||||
eff_size = (total_num_clusters * fs->fat_bits + 7) / 8ULL;
|
||||
|
||||
if (fs->fat_bits != 12)
|
||||
alloc_size = eff_size;
|
||||
else
|
||||
/* round up to an even number of FAT entries to avoid special
|
||||
* casing the last entry in get_fat() */
|
||||
alloc_size = (total_num_clusters * 12 + 23) / 24 * 3;
|
||||
|
||||
first = alloc(alloc_size);
|
||||
fs_read(fs->fat_start, eff_size, first);
|
||||
if (fs->nfats > 1) {
|
||||
second = alloc(alloc_size);
|
||||
fs_read(fs->fat_start + fs->fat_size, eff_size, second);
|
||||
}
|
||||
if (second && memcmp(first, second, eff_size) != 0) {
|
||||
FAT_ENTRY first_media, second_media;
|
||||
get_fat(&first_media, first, 0, fs);
|
||||
get_fat(&second_media, second, 0, fs);
|
||||
first_ok = (first_media.value & FAT_EXTD(fs)) == FAT_EXTD(fs);
|
||||
second_ok = (second_media.value & FAT_EXTD(fs)) == FAT_EXTD(fs);
|
||||
if (first_ok && !second_ok) {
|
||||
printf("FATs differ - using first FAT.\n");
|
||||
fs_write(fs->fat_start + fs->fat_size, eff_size, first);
|
||||
}
|
||||
if (!first_ok && second_ok) {
|
||||
printf("FATs differ - using second FAT.\n");
|
||||
fs_write(fs->fat_start, eff_size, second);
|
||||
memcpy(first, second, eff_size);
|
||||
}
|
||||
if (first_ok && second_ok) {
|
||||
if (interactive) {
|
||||
printf("FATs differ but appear to be intact. Use which FAT ?\n"
|
||||
"1) Use first FAT\n2) Use second FAT\n");
|
||||
if (get_key("12", "?") == '1') {
|
||||
fs_write(fs->fat_start + fs->fat_size, eff_size, first);
|
||||
} else {
|
||||
fs_write(fs->fat_start, eff_size, second);
|
||||
memcpy(first, second, eff_size);
|
||||
}
|
||||
} else {
|
||||
printf("FATs differ but appear to be intact. Using first "
|
||||
"FAT.\n");
|
||||
fs_write(fs->fat_start + fs->fat_size, eff_size, first);
|
||||
}
|
||||
}
|
||||
if (!first_ok && !second_ok) {
|
||||
printf("Both FATs appear to be corrupt. Giving up.\n");
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
if (second) {
|
||||
free(second);
|
||||
}
|
||||
fs->fat = (unsigned char *)first;
|
||||
|
||||
fs->cluster_owner = alloc(total_num_clusters * sizeof(DOS_FILE *));
|
||||
memset(fs->cluster_owner, 0, (total_num_clusters * sizeof(DOS_FILE *)));
|
||||
|
||||
/* Truncate any cluster chains that link to something out of range */
|
||||
for (i = 2; i < fs->clusters + 2; i++) {
|
||||
FAT_ENTRY curEntry;
|
||||
get_fat(&curEntry, fs->fat, i, fs);
|
||||
if (curEntry.value == 1) {
|
||||
printf("Cluster %ld out of range (1). Setting to EOF.\n", (long)(i - 2));
|
||||
set_fat(fs, i, -1);
|
||||
}
|
||||
if (curEntry.value >= fs->clusters + 2 &&
|
||||
(curEntry.value < FAT_MIN_BAD(fs))) {
|
||||
printf("Cluster %ld out of range (%ld > %ld). Setting to EOF.\n",
|
||||
(long)(i - 2), (long)curEntry.value, (long)(fs->clusters + 2 - 1));
|
||||
set_fat(fs, i, -1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the FAT entry for a specified cluster
|
||||
* (i.e., change the cluster it links to).
|
||||
* Queue a command to write out this change.
|
||||
*
|
||||
* @param[in,out] fs Information about the filesystem
|
||||
* @param[in] cluster Cluster to change
|
||||
* @param[in] new Cluster to link to
|
||||
* Special values:
|
||||
* 0 == free cluster
|
||||
* -1 == end-of-chain
|
||||
* -2 == bad cluster
|
||||
*/
|
||||
void set_fat(DOS_FS * fs, uint32_t cluster, int32_t new)
|
||||
{
|
||||
unsigned char *data = NULL;
|
||||
int size;
|
||||
loff_t offs;
|
||||
|
||||
if (new == -1)
|
||||
new = FAT_EOF(fs);
|
||||
else if ((long)new == -2)
|
||||
new = FAT_BAD(fs);
|
||||
switch (fs->fat_bits) {
|
||||
case 12:
|
||||
data = fs->fat + cluster * 3 / 2;
|
||||
offs = fs->fat_start + cluster * 3 / 2;
|
||||
if (cluster & 1) {
|
||||
FAT_ENTRY prevEntry;
|
||||
get_fat(&prevEntry, fs->fat, cluster - 1, fs);
|
||||
data[0] = ((new & 0xf) << 4) | (prevEntry.value >> 8);
|
||||
data[1] = new >> 4;
|
||||
} else {
|
||||
FAT_ENTRY subseqEntry;
|
||||
get_fat(&subseqEntry, fs->fat, cluster + 1, fs);
|
||||
data[0] = new & 0xff;
|
||||
data[1] = (new >> 8) | (cluster == fs->clusters - 1 ? 0 :
|
||||
(0xff & subseqEntry.value) << 4);
|
||||
}
|
||||
size = 2;
|
||||
break;
|
||||
case 16:
|
||||
data = fs->fat + cluster * 2;
|
||||
offs = fs->fat_start + cluster * 2;
|
||||
*(unsigned short *)data = htole16(new);
|
||||
size = 2;
|
||||
break;
|
||||
case 32:
|
||||
{
|
||||
FAT_ENTRY curEntry;
|
||||
get_fat(&curEntry, fs->fat, cluster, fs);
|
||||
|
||||
data = fs->fat + cluster * 4;
|
||||
offs = fs->fat_start + cluster * 4;
|
||||
/* According to M$, the high 4 bits of a FAT32 entry are reserved and
|
||||
* are not part of the cluster number. So we never touch them. */
|
||||
*(uint32_t *)data = htole32((new & 0xfffffff) |
|
||||
(curEntry.reserved << 28));
|
||||
size = 4;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
die("Bad FAT entry size: %d bits.", fs->fat_bits);
|
||||
}
|
||||
fs_write(offs, size, data);
|
||||
if (fs->nfats > 1) {
|
||||
fs_write(offs + fs->fat_size, size, data);
|
||||
}
|
||||
}
|
||||
|
||||
int bad_cluster(DOS_FS * fs, uint32_t cluster)
|
||||
{
|
||||
FAT_ENTRY curEntry;
|
||||
get_fat(&curEntry, fs->fat, cluster, fs);
|
||||
|
||||
return FAT_IS_BAD(fs, curEntry.value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the cluster to which the specified cluster is linked.
|
||||
* If the linked cluster is marked bad, abort.
|
||||
*
|
||||
* @param[in] fs Information about the filesystem
|
||||
* @param[in] cluster Cluster to follow
|
||||
*
|
||||
* @return -1 'cluster' is at the end of the chain
|
||||
* @return Other values Next cluster in this chain
|
||||
*/
|
||||
uint32_t next_cluster(DOS_FS * fs, uint32_t cluster)
|
||||
{
|
||||
uint32_t value;
|
||||
FAT_ENTRY curEntry;
|
||||
|
||||
get_fat(&curEntry, fs->fat, cluster, fs);
|
||||
|
||||
value = curEntry.value;
|
||||
if (FAT_IS_BAD(fs, value))
|
||||
die("Internal error: next_cluster on bad cluster");
|
||||
return FAT_IS_EOF(fs, value) ? -1 : value;
|
||||
}
|
||||
|
||||
loff_t cluster_start(DOS_FS * fs, uint32_t cluster)
|
||||
{
|
||||
return fs->data_start + ((loff_t) cluster -
|
||||
2) * (uint64_t)fs->cluster_size;
|
||||
}
|
||||
|
||||
/**
|
||||
* Update internal bookkeeping to show that the specified cluster belongs
|
||||
* to the specified dentry.
|
||||
*
|
||||
* @param[in,out] fs Information about the filesystem
|
||||
* @param[in] cluster Cluster being assigned
|
||||
* @param[in] owner Information on dentry that owns this cluster
|
||||
* (may be NULL)
|
||||
*/
|
||||
void set_owner(DOS_FS * fs, uint32_t cluster, DOS_FILE * owner)
|
||||
{
|
||||
if (fs->cluster_owner == NULL)
|
||||
die("Internal error: attempt to set owner in non-existent table");
|
||||
|
||||
if (owner && fs->cluster_owner[cluster]
|
||||
&& (fs->cluster_owner[cluster] != owner))
|
||||
die("Internal error: attempt to change file owner");
|
||||
fs->cluster_owner[cluster] = owner;
|
||||
}
|
||||
|
||||
DOS_FILE *get_owner(DOS_FS * fs, uint32_t cluster)
|
||||
{
|
||||
if (fs->cluster_owner == NULL)
|
||||
return NULL;
|
||||
else
|
||||
return fs->cluster_owner[cluster];
|
||||
}
|
||||
|
||||
void fix_bad(DOS_FS * fs)
|
||||
{
|
||||
uint32_t i;
|
||||
|
||||
if (verbose)
|
||||
printf("Checking for bad clusters.\n");
|
||||
for (i = 2; i < fs->clusters + 2; i++) {
|
||||
FAT_ENTRY curEntry;
|
||||
get_fat(&curEntry, fs->fat, i, fs);
|
||||
|
||||
if (!get_owner(fs, i) && !FAT_IS_BAD(fs, curEntry.value))
|
||||
if (!fs_test(cluster_start(fs, i), fs->cluster_size)) {
|
||||
printf("Cluster %lu is unreadable.\n", (unsigned long)i);
|
||||
set_fat(fs, i, -2);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void reclaim_free(DOS_FS * fs)
|
||||
{
|
||||
int reclaimed;
|
||||
uint32_t i;
|
||||
|
||||
if (verbose)
|
||||
printf("Checking for unused clusters.\n");
|
||||
reclaimed = 0;
|
||||
for (i = 2; i < fs->clusters + 2; i++) {
|
||||
FAT_ENTRY curEntry;
|
||||
get_fat(&curEntry, fs->fat, i, fs);
|
||||
|
||||
if (!get_owner(fs, i) && curEntry.value &&
|
||||
!FAT_IS_BAD(fs, curEntry.value)) {
|
||||
set_fat(fs, i, 0);
|
||||
reclaimed++;
|
||||
}
|
||||
}
|
||||
if (reclaimed)
|
||||
printf("Reclaimed %d unused cluster%s (%llu bytes).\n", (int)reclaimed,
|
||||
reclaimed == 1 ? "" : "s",
|
||||
(unsigned long long)reclaimed * fs->cluster_size);
|
||||
}
|
||||
|
||||
/**
|
||||
* Assign the specified owner to all orphan chains (except cycles).
|
||||
* Break cross-links between orphan chains.
|
||||
*
|
||||
* @param[in,out] fs Information about the filesystem
|
||||
* @param[in] owner dentry to be assigned ownership of orphans
|
||||
* @param[in,out] num_refs For each orphan cluster [index], how many
|
||||
* clusters link to it.
|
||||
* @param[in] start_cluster Where to start scanning for orphans
|
||||
*/
|
||||
static void tag_free(DOS_FS * fs, DOS_FILE * owner, uint32_t *num_refs,
|
||||
uint32_t start_cluster)
|
||||
{
|
||||
int prev;
|
||||
uint32_t i, walk;
|
||||
|
||||
if (start_cluster == 0)
|
||||
start_cluster = 2;
|
||||
|
||||
for (i = start_cluster; i < fs->clusters + 2; i++) {
|
||||
FAT_ENTRY curEntry;
|
||||
get_fat(&curEntry, fs->fat, i, fs);
|
||||
|
||||
/* If the current entry is the head of an un-owned chain... */
|
||||
if (curEntry.value && !FAT_IS_BAD(fs, curEntry.value) &&
|
||||
!get_owner(fs, i) && !num_refs[i]) {
|
||||
prev = 0;
|
||||
/* Walk the chain, claiming ownership as we go */
|
||||
for (walk = i; walk != -1; walk = next_cluster(fs, walk)) {
|
||||
if (!get_owner(fs, walk)) {
|
||||
set_owner(fs, walk, owner);
|
||||
} else {
|
||||
/* We've run into cross-links between orphaned chains,
|
||||
* or a cycle with a tail.
|
||||
* Terminate this orphan chain (break the link)
|
||||
*/
|
||||
set_fat(fs, prev, -1);
|
||||
|
||||
/* This is not necessary because 'walk' is owned and thus
|
||||
* will never become the head of a chain (the only case
|
||||
* that would matter during reclaim to files).
|
||||
* It's easier to decrement than to prove that it's
|
||||
* unnecessary.
|
||||
*/
|
||||
num_refs[walk]--;
|
||||
break;
|
||||
}
|
||||
prev = walk;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Recover orphan chains to files, handling any cycles or cross-links.
|
||||
*
|
||||
* @param[in,out] fs Information about the filesystem
|
||||
*/
|
||||
void reclaim_file(DOS_FS * fs)
|
||||
{
|
||||
DOS_FILE orphan;
|
||||
int reclaimed, files;
|
||||
int changed = 0;
|
||||
uint32_t i, next, walk;
|
||||
uint32_t *num_refs = NULL; /* Only for orphaned clusters */
|
||||
uint32_t total_num_clusters;
|
||||
|
||||
if (verbose)
|
||||
printf("Reclaiming unconnected clusters.\n");
|
||||
|
||||
total_num_clusters = fs->clusters + 2UL;
|
||||
num_refs = alloc(total_num_clusters * sizeof(uint32_t));
|
||||
memset(num_refs, 0, (total_num_clusters * sizeof(uint32_t)));
|
||||
|
||||
/* Guarantee that all orphan chains (except cycles) end cleanly
|
||||
* with an end-of-chain mark.
|
||||
*/
|
||||
|
||||
for (i = 2; i < total_num_clusters; i++) {
|
||||
FAT_ENTRY curEntry;
|
||||
get_fat(&curEntry, fs->fat, i, fs);
|
||||
|
||||
next = curEntry.value;
|
||||
if (!get_owner(fs, i) && next && next < fs->clusters + 2) {
|
||||
/* Cluster is linked, but not owned (orphan) */
|
||||
FAT_ENTRY nextEntry;
|
||||
get_fat(&nextEntry, fs->fat, next, fs);
|
||||
|
||||
/* Mark it end-of-chain if it links into an owned cluster,
|
||||
* a free cluster, or a bad cluster.
|
||||
*/
|
||||
if (get_owner(fs, next) || !nextEntry.value ||
|
||||
FAT_IS_BAD(fs, nextEntry.value))
|
||||
set_fat(fs, i, -1);
|
||||
else
|
||||
num_refs[next]++;
|
||||
}
|
||||
}
|
||||
|
||||
/* Scan until all the orphans are accounted for,
|
||||
* and all cycles and cross-links are broken
|
||||
*/
|
||||
do {
|
||||
tag_free(fs, &orphan, num_refs, changed);
|
||||
changed = 0;
|
||||
|
||||
/* Any unaccounted-for orphans must be part of a cycle */
|
||||
for (i = 2; i < total_num_clusters; i++) {
|
||||
FAT_ENTRY curEntry;
|
||||
get_fat(&curEntry, fs->fat, i, fs);
|
||||
|
||||
if (curEntry.value && !FAT_IS_BAD(fs, curEntry.value) &&
|
||||
!get_owner(fs, i)) {
|
||||
if (!num_refs[curEntry.value]--)
|
||||
die("Internal error: num_refs going below zero");
|
||||
set_fat(fs, i, -1);
|
||||
changed = curEntry.value;
|
||||
printf("Broke cycle at cluster %lu in free chain.\n", (unsigned long)i);
|
||||
|
||||
/* If we've created a new chain head,
|
||||
* tag_free() can claim it
|
||||
*/
|
||||
if (num_refs[curEntry.value] == 0)
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
while (changed);
|
||||
|
||||
/* Now we can start recovery */
|
||||
files = reclaimed = 0;
|
||||
for (i = 2; i < total_num_clusters; i++)
|
||||
/* If this cluster is the head of an orphan chain... */
|
||||
if (get_owner(fs, i) == &orphan && !num_refs[i]) {
|
||||
DIR_ENT de;
|
||||
loff_t offset;
|
||||
files++;
|
||||
offset = alloc_rootdir_entry(fs, &de, "FSCK%04dREC");
|
||||
de.start = htole16(i & 0xffff);
|
||||
if (fs->fat_bits == 32)
|
||||
de.starthi = htole16(i >> 16);
|
||||
for (walk = i; walk > 0 && walk != -1;
|
||||
walk = next_cluster(fs, walk)) {
|
||||
de.size = htole32(le32toh(de.size) + fs->cluster_size);
|
||||
reclaimed++;
|
||||
}
|
||||
fs_write(offset, sizeof(DIR_ENT), &de);
|
||||
}
|
||||
if (reclaimed)
|
||||
printf("Reclaimed %d unused cluster%s (%llu bytes) in %d chain%s.\n",
|
||||
reclaimed, reclaimed == 1 ? "" : "s",
|
||||
(unsigned long long)reclaimed * fs->cluster_size, files,
|
||||
files == 1 ? "" : "s");
|
||||
|
||||
free(num_refs);
|
||||
}
|
||||
|
||||
uint32_t update_free(DOS_FS * fs)
|
||||
{
|
||||
uint32_t i;
|
||||
uint32_t free = 0;
|
||||
int do_set = 0;
|
||||
|
||||
for (i = 2; i < fs->clusters + 2; i++) {
|
||||
FAT_ENTRY curEntry;
|
||||
get_fat(&curEntry, fs->fat, i, fs);
|
||||
|
||||
if (!get_owner(fs, i) && !FAT_IS_BAD(fs, curEntry.value))
|
||||
++free;
|
||||
}
|
||||
|
||||
if (!fs->fsinfo_start)
|
||||
return free;
|
||||
|
||||
if (verbose)
|
||||
printf("Checking free cluster summary.\n");
|
||||
if (fs->free_clusters != 0xFFFFFFFF) {
|
||||
if (free != fs->free_clusters) {
|
||||
printf("Free cluster summary wrong (%ld vs. really %ld)\n",
|
||||
(long)fs->free_clusters, (long)free);
|
||||
if (interactive)
|
||||
printf("1) Correct\n2) Don't correct\n");
|
||||
else
|
||||
printf(" Auto-correcting.\n");
|
||||
if (!interactive || get_key("12", "?") == '1')
|
||||
do_set = 1;
|
||||
}
|
||||
} else {
|
||||
printf("Free cluster summary uninitialized (should be %ld)\n", (long)free);
|
||||
if (rw) {
|
||||
if (interactive)
|
||||
printf("1) Set it\n2) Leave it uninitialized\n");
|
||||
else
|
||||
printf(" Auto-setting.\n");
|
||||
if (!interactive || get_key("12", "?") == '1')
|
||||
do_set = 1;
|
||||
}
|
||||
}
|
||||
|
||||
if (do_set) {
|
||||
uint32_t le_free = htole32(free);
|
||||
fs->free_clusters = free;
|
||||
fs_write(fs->fsinfo_start + offsetof(struct info_sector, free_clusters),
|
||||
sizeof(le_free), &le_free);
|
||||
}
|
||||
|
||||
return free;
|
||||
}
|
||||
@@ -0,0 +1,85 @@
|
||||
/* fat.h - Read/write access to the FAT
|
||||
|
||||
Copyright (C) 1993 Werner Almesberger <werner.almesberger@lrc.di.epfl.ch>
|
||||
Copyright (C) 2008-2014 Daniel Baumann <mail@daniel-baumann.ch>
|
||||
|
||||
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 3 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, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
THe complete text of the GNU General Public License
|
||||
can be found in /usr/share/common-licenses/GPL-3 file.
|
||||
*/
|
||||
|
||||
#ifndef _FAT_H
|
||||
#define _FAT_H
|
||||
|
||||
void read_fat(DOS_FS * fs);
|
||||
|
||||
/* Loads the FAT of the filesystem described by FS. Initializes the FAT,
|
||||
replaces broken FATs and rejects invalid cluster entries. */
|
||||
|
||||
void get_fat(FAT_ENTRY * entry, void *fat, uint32_t cluster, DOS_FS * fs);
|
||||
|
||||
/* Retrieve the FAT entry (next chained cluster) for CLUSTER. */
|
||||
|
||||
void set_fat(DOS_FS * fs, uint32_t cluster, int32_t new);
|
||||
|
||||
/* Changes the value of the CLUSTERth cluster of the FAT of FS to NEW. Special
|
||||
values of NEW are -1 (EOF, 0xff8 or 0xfff8) and -2 (bad sector, 0xff7 or
|
||||
0xfff7) */
|
||||
|
||||
int bad_cluster(DOS_FS * fs, uint32_t cluster);
|
||||
|
||||
/* Returns a non-zero integer if the CLUSTERth cluster is marked as bad or zero
|
||||
otherwise. */
|
||||
|
||||
uint32_t next_cluster(DOS_FS * fs, uint32_t cluster);
|
||||
|
||||
/* Returns the number of the cluster following CLUSTER, or -1 if this is the
|
||||
last cluster of the respective cluster chain. CLUSTER must not be a bad
|
||||
cluster. */
|
||||
|
||||
loff_t cluster_start(DOS_FS * fs, uint32_t cluster);
|
||||
|
||||
/* Returns the byte offset of CLUSTER, relative to the respective device. */
|
||||
|
||||
void set_owner(DOS_FS * fs, uint32_t cluster, DOS_FILE * owner);
|
||||
|
||||
/* Sets the owner pointer of the respective cluster to OWNER. If OWNER was NULL
|
||||
before, it can be set to NULL or any non-NULL value. Otherwise, only NULL is
|
||||
accepted as the new value. */
|
||||
|
||||
DOS_FILE *get_owner(DOS_FS * fs, uint32_t cluster);
|
||||
|
||||
/* Returns the owner of the repective cluster or NULL if the cluster has no
|
||||
owner. */
|
||||
|
||||
void fix_bad(DOS_FS * fs);
|
||||
|
||||
/* Scans the disk for currently unused bad clusters and marks them as bad. */
|
||||
|
||||
void reclaim_free(DOS_FS * fs);
|
||||
|
||||
/* Marks all allocated, but unused clusters as free. */
|
||||
|
||||
void reclaim_file(DOS_FS * fs);
|
||||
|
||||
/* Scans the FAT for chains of allocated, but unused clusters and creates files
|
||||
for them in the root directory. Also tries to fix all inconsistencies (e.g.
|
||||
loops, shared clusters, etc.) in the process. */
|
||||
|
||||
uint32_t update_free(DOS_FS * fs);
|
||||
|
||||
/* Updates free cluster count in FSINFO sector. */
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,144 @@
|
||||
/* fatlabel.c - User interface
|
||||
|
||||
Copyright (C) 1993 Werner Almesberger <werner.almesberger@lrc.di.epfl.ch>
|
||||
Copyright (C) 1998 Roman Hodek <Roman.Hodek@informatik.uni-erlangen.de>
|
||||
Copyright (C) 2007 Red Hat, Inc.
|
||||
Copyright (C) 2008-2014 Daniel Baumann <mail@daniel-baumann.ch>
|
||||
|
||||
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 3 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, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
The complete text of the GNU General Public License
|
||||
can be found in /usr/share/common-licenses/GPL-3 file.
|
||||
*/
|
||||
|
||||
#include "version.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include <getopt.h>
|
||||
#include <ctype.h>
|
||||
|
||||
#include "common.h"
|
||||
#include "fsck.fat.h"
|
||||
#include "io.h"
|
||||
#include "boot.h"
|
||||
#include "fat.h"
|
||||
#include "file.h"
|
||||
#include "check.h"
|
||||
|
||||
int interactive = 0, rw = 0, list = 0, test = 0, verbose = 0, write_immed = 0;
|
||||
int atari_format = 0;
|
||||
unsigned n_files = 0;
|
||||
void *mem_queue = NULL;
|
||||
|
||||
static void usage(int error)
|
||||
{
|
||||
FILE *f = error ? stderr : stdout;
|
||||
int status = error ? 1 : 0;
|
||||
|
||||
fprintf(f, "usage: fatlabel device [label]\n");
|
||||
exit(status);
|
||||
}
|
||||
|
||||
/*
|
||||
* ++roman: On m68k, check if this is an Atari; if yes, turn on Atari variant
|
||||
* of MS-DOS filesystem by default.
|
||||
*/
|
||||
static void check_atari(void)
|
||||
{
|
||||
#ifdef __mc68000__
|
||||
FILE *f;
|
||||
char line[128], *p;
|
||||
|
||||
if (!(f = fopen("/proc/hardware", "r"))) {
|
||||
perror("/proc/hardware");
|
||||
return;
|
||||
}
|
||||
|
||||
while (fgets(line, sizeof(line), f)) {
|
||||
if (strncmp(line, "Model:", 6) == 0) {
|
||||
p = line + 6;
|
||||
p += strspn(p, " \t");
|
||||
if (strncmp(p, "Atari ", 6) == 0)
|
||||
atari_format = 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
fclose(f);
|
||||
#endif
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
DOS_FS fs = { 0 };
|
||||
rw = 0;
|
||||
|
||||
int i;
|
||||
|
||||
char *device = NULL;
|
||||
char label[12] = { 0 };
|
||||
|
||||
loff_t offset;
|
||||
DIR_ENT de;
|
||||
|
||||
check_atari();
|
||||
|
||||
if (argc < 2 || argc > 3)
|
||||
usage(1);
|
||||
|
||||
if (!strcmp(argv[1], "-h") || !strcmp(argv[1], "--help"))
|
||||
usage(0);
|
||||
else if (!strcmp(argv[1], "-V") || !strcmp(argv[1], "--version")) {
|
||||
printf("fatlabel " VERSION " (" VERSION_DATE ")\n");
|
||||
exit(0);
|
||||
}
|
||||
|
||||
device = argv[1];
|
||||
if (argc == 3) {
|
||||
strncpy(label, argv[2], 11);
|
||||
if (strlen(argv[2]) > 11) {
|
||||
fprintf(stderr,
|
||||
"fatlabel: labels can be no longer than 11 characters\n");
|
||||
exit(1);
|
||||
}
|
||||
for (i = 0; label[i] && i < 11; i++)
|
||||
/* don't know if here should be more strict !uppercase(label[i]) */
|
||||
if (islower(label[i])) {
|
||||
fprintf(stderr,
|
||||
"fatlabel: warning - lowercase labels might not work properly with DOS or Windows\n");
|
||||
break;
|
||||
}
|
||||
rw = 1;
|
||||
}
|
||||
|
||||
fs_open(device, rw);
|
||||
read_boot(&fs);
|
||||
if (fs.fat_bits == 32)
|
||||
read_fat(&fs);
|
||||
if (!rw) {
|
||||
offset = find_volume_de(&fs, &de);
|
||||
if (offset == 0)
|
||||
fprintf(stdout, "%s\n", fs.label);
|
||||
else
|
||||
fprintf(stdout, "%.8s%.3s\n", de.name, de.ext);
|
||||
exit(0);
|
||||
}
|
||||
|
||||
write_label(&fs, label);
|
||||
fs_close(rw);
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,276 @@
|
||||
/* file.c - Additional file attributes
|
||||
|
||||
Copyright (C) 1993 Werner Almesberger <werner.almesberger@lrc.di.epfl.ch>
|
||||
Copyright (C) 1998 Roman Hodek <Roman.Hodek@informatik.uni-erlangen.de>
|
||||
Copyright (C) 2008-2014 Daniel Baumann <mail@daniel-baumann.ch>
|
||||
|
||||
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 3 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, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
The complete text of the GNU General Public License
|
||||
can be found in /usr/share/common-licenses/GPL-3 file.
|
||||
*/
|
||||
|
||||
/* FAT32, VFAT, Atari format support, and various fixes additions May 1998
|
||||
* by Roman Hodek <Roman.Hodek@informatik.uni-erlangen.de> */
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <ctype.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "common.h"
|
||||
#include "file.h"
|
||||
#include "msdos_fs.h"
|
||||
|
||||
FDSC *fp_root = NULL;
|
||||
|
||||
static void put_char(char **p, unsigned char c)
|
||||
{
|
||||
if ((c >= ' ' && c < 0x7f) || c >= 0xa0)
|
||||
*(*p)++ = c;
|
||||
else {
|
||||
*(*p)++ = '\\';
|
||||
*(*p)++ = '0' + (c >> 6);
|
||||
*(*p)++ = '0' + ((c >> 3) & 7);
|
||||
*(*p)++ = '0' + (c & 7);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct the "pretty-printed" representation of the name in a short directory entry.
|
||||
*
|
||||
* @param[in] fixed Pointer to name[0] of a DIR_ENT
|
||||
*
|
||||
* @return Pointer to static string containing pretty "8.3" equivalent of the
|
||||
* name in the directory entry.
|
||||
*/
|
||||
char *file_name(unsigned char *fixed)
|
||||
{
|
||||
static char path[MSDOS_NAME * 4 + 2];
|
||||
char *p;
|
||||
int i, j;
|
||||
|
||||
p = path;
|
||||
for (i = j = 0; i < 8; i++)
|
||||
if (fixed[i] != ' ') {
|
||||
while (j++ < i)
|
||||
*p++ = ' ';
|
||||
put_char(&p, fixed[i]);
|
||||
}
|
||||
if (strncmp((const char *)(fixed + 8), " ", 3)) {
|
||||
*p++ = '.';
|
||||
for (i = j = 0; i < 3; i++)
|
||||
if (fixed[i + 8] != ' ') {
|
||||
while (j++ < i)
|
||||
*p++ = ' ';
|
||||
put_char(&p, fixed[i + 8]);
|
||||
}
|
||||
}
|
||||
*p = 0;
|
||||
return path;
|
||||
}
|
||||
|
||||
int file_cvt(unsigned char *name, unsigned char *fixed)
|
||||
{
|
||||
unsigned char c;
|
||||
int size, ext, cnt;
|
||||
|
||||
size = 8;
|
||||
ext = 0;
|
||||
while (*name) {
|
||||
c = *name;
|
||||
if (c < ' ' || c > 0x7e || strchr("*?<>|\"/", c)) {
|
||||
printf("Invalid character in name. Use \\ooo for special "
|
||||
"characters.\n");
|
||||
return 0;
|
||||
}
|
||||
if (c == '.') {
|
||||
if (ext) {
|
||||
printf("Duplicate dots in name.\n");
|
||||
return 0;
|
||||
}
|
||||
while (size--)
|
||||
*fixed++ = ' ';
|
||||
size = 3;
|
||||
ext = 1;
|
||||
name++;
|
||||
continue;
|
||||
}
|
||||
if (c == '\\') {
|
||||
c = 0;
|
||||
for (cnt = 3; cnt; cnt--) {
|
||||
if (*name < '0' || *name > '7') {
|
||||
printf("Invalid octal character.\n");
|
||||
return 0;
|
||||
}
|
||||
c = c * 8 + *name++ - '0';
|
||||
}
|
||||
if (cnt < 4) {
|
||||
printf("Expected three octal digits.\n");
|
||||
return 0;
|
||||
}
|
||||
name += 3;
|
||||
}
|
||||
if (islower(c))
|
||||
c = toupper(c);
|
||||
if (size) {
|
||||
*fixed++ = c;
|
||||
size--;
|
||||
}
|
||||
name++;
|
||||
}
|
||||
if (*name || size == 8)
|
||||
return 0;
|
||||
if (!ext) {
|
||||
while (size--)
|
||||
*fixed++ = ' ';
|
||||
size = 3;
|
||||
}
|
||||
while (size--)
|
||||
*fixed++ = ' ';
|
||||
return 1;
|
||||
}
|
||||
|
||||
void file_add(char *path, FD_TYPE type)
|
||||
{
|
||||
FDSC **current, *walk;
|
||||
char name[MSDOS_NAME];
|
||||
char *here;
|
||||
|
||||
current = &fp_root;
|
||||
if (*path != '/')
|
||||
die("%s: Absolute path required.", path);
|
||||
path++;
|
||||
while (1) {
|
||||
if ((here = strchr(path, '/')))
|
||||
*here = 0;
|
||||
if (!file_cvt((unsigned char *)path, (unsigned char *)name))
|
||||
exit(2);
|
||||
for (walk = *current; walk; walk = walk->next)
|
||||
if (!here && (!strncmp(name, walk->name, MSDOS_NAME) || (type ==
|
||||
fdt_undelete
|
||||
&&
|
||||
!strncmp
|
||||
(name + 1,
|
||||
walk->name
|
||||
+ 1,
|
||||
MSDOS_NAME
|
||||
- 1))))
|
||||
die("Ambiguous name: \"%s\"", path);
|
||||
else if (here && !strncmp(name, walk->name, MSDOS_NAME))
|
||||
break;
|
||||
if (!walk) {
|
||||
walk = alloc(sizeof(FDSC));
|
||||
strncpy(walk->name, name, MSDOS_NAME);
|
||||
walk->type = here ? fdt_none : type;
|
||||
walk->first = NULL;
|
||||
walk->next = *current;
|
||||
*current = walk;
|
||||
}
|
||||
current = &walk->first;
|
||||
if (!here)
|
||||
break;
|
||||
*here = '/';
|
||||
path = here + 1;
|
||||
}
|
||||
}
|
||||
|
||||
FDSC **file_cd(FDSC ** curr, char *fixed)
|
||||
{
|
||||
FDSC **walk;
|
||||
|
||||
if (!curr || !*curr)
|
||||
return NULL;
|
||||
for (walk = curr; *walk; walk = &(*walk)->next)
|
||||
if (!strncmp((*walk)->name, fixed, MSDOS_NAME) && (*walk)->first)
|
||||
return &(*walk)->first;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static FDSC **file_find(FDSC ** dir, char *fixed)
|
||||
{
|
||||
if (!dir || !*dir)
|
||||
return NULL;
|
||||
if (*(unsigned char *)fixed == DELETED_FLAG) {
|
||||
while (*dir) {
|
||||
if (!strncmp((*dir)->name + 1, fixed + 1, MSDOS_NAME - 1)
|
||||
&& !(*dir)->first)
|
||||
return dir;
|
||||
dir = &(*dir)->next;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
while (*dir) {
|
||||
if (!strncmp((*dir)->name, fixed, MSDOS_NAME) && !(*dir)->first)
|
||||
return dir;
|
||||
dir = &(*dir)->next;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* Returns the attribute of the file FIXED in directory CURR or FDT_NONE if no
|
||||
such file exists or if CURR is NULL. */
|
||||
FD_TYPE file_type(FDSC ** curr, char *fixed)
|
||||
{
|
||||
FDSC **this;
|
||||
|
||||
if ((this = file_find(curr, fixed)))
|
||||
return (*this)->type;
|
||||
return fdt_none;
|
||||
}
|
||||
|
||||
void file_modify(FDSC ** curr, char *fixed)
|
||||
{
|
||||
FDSC **this, *next;
|
||||
|
||||
if (!(this = file_find(curr, fixed)))
|
||||
die("Internal error: file_find failed");
|
||||
switch ((*this)->type) {
|
||||
case fdt_drop:
|
||||
printf("Dropping %s\n", file_name((unsigned char *)fixed));
|
||||
*(unsigned char *)fixed = DELETED_FLAG;
|
||||
break;
|
||||
case fdt_undelete:
|
||||
*fixed = *(*this)->name;
|
||||
printf("Undeleting %s\n", file_name((unsigned char *)fixed));
|
||||
break;
|
||||
default:
|
||||
die("Internal error: file_modify");
|
||||
}
|
||||
next = (*this)->next;
|
||||
free(*this);
|
||||
*this = next;
|
||||
}
|
||||
|
||||
static void report_unused(FDSC * this)
|
||||
{
|
||||
FDSC *next;
|
||||
|
||||
while (this) {
|
||||
next = this->next;
|
||||
if (this->first)
|
||||
report_unused(this->first);
|
||||
else if (this->type != fdt_none)
|
||||
printf("Warning: did not %s file %s\n", this->type == fdt_drop ?
|
||||
"drop" : "undelete", file_name((unsigned char *)this->name));
|
||||
free(this);
|
||||
this = next;
|
||||
}
|
||||
}
|
||||
|
||||
void file_unused(void)
|
||||
{
|
||||
report_unused(fp_root);
|
||||
}
|
||||
@@ -0,0 +1,72 @@
|
||||
/* file.h - Additional file attributes
|
||||
|
||||
Copyright (C) 1993 Werner Almesberger <werner.almesberger@lrc.di.epfl.ch>
|
||||
Copyright (C) 2008-2014 Daniel Baumann <mail@daniel-baumann.ch>
|
||||
|
||||
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 3 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, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
The complete text of the GNU General Public License
|
||||
can be found in /usr/share/common-licenses/GPL-3 file.
|
||||
*/
|
||||
|
||||
#ifndef _FILE_H
|
||||
#define _FILE_H
|
||||
|
||||
#include "msdos_fs.h"
|
||||
|
||||
typedef enum { fdt_none, fdt_drop, fdt_undelete } FD_TYPE;
|
||||
|
||||
typedef struct _fptr {
|
||||
char name[MSDOS_NAME];
|
||||
FD_TYPE type;
|
||||
struct _fptr *first; /* first entry */
|
||||
struct _fptr *next; /* next file in directory */
|
||||
} FDSC;
|
||||
|
||||
extern FDSC *fp_root;
|
||||
|
||||
char *file_name(unsigned char *fixed);
|
||||
|
||||
/* Returns a pointer to a pretty-printed representation of a fixed MS-DOS file
|
||||
name. */
|
||||
|
||||
int file_cvt(unsigned char *name, unsigned char *fixed);
|
||||
|
||||
/* Converts a pretty-printed file name to the fixed MS-DOS format. Returns a
|
||||
non-zero integer on success, zero on failure. */
|
||||
|
||||
void file_add(char *path, FD_TYPE type);
|
||||
|
||||
/* Define special attributes for a path. TYPE can be either FDT_DROP or
|
||||
FDT_UNDELETE. */
|
||||
|
||||
FDSC **file_cd(FDSC ** curr, char *fixed);
|
||||
|
||||
/* Returns a pointer to the directory descriptor of the subdirectory FIXED of
|
||||
CURR, or NULL if no such subdirectory exists. */
|
||||
|
||||
FD_TYPE file_type(FDSC ** curr, char *fixed);
|
||||
|
||||
/* Returns the attribute of the file FIXED in directory CURR or FDT_NONE if no
|
||||
such file exists or if CURR is NULL. */
|
||||
|
||||
void file_modify(FDSC ** curr, char *fixed);
|
||||
|
||||
/* Performs the necessary operation on the entry of CURR that is named FIXED. */
|
||||
|
||||
void file_unused(void);
|
||||
|
||||
/* Displays warnings for all unused file attributes. */
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,215 @@
|
||||
/* fsck.fat.c - User interface
|
||||
|
||||
Copyright (C) 1993 Werner Almesberger <werner.almesberger@lrc.di.epfl.ch>
|
||||
Copyright (C) 1998 Roman Hodek <Roman.Hodek@informatik.uni-erlangen.de>
|
||||
Copyright (C) 2008-2014 Daniel Baumann <mail@daniel-baumann.ch>
|
||||
|
||||
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 3 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, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
The complete text of the GNU General Public License
|
||||
can be found in /usr/share/common-licenses/GPL-3 file.
|
||||
*/
|
||||
|
||||
/* FAT32, VFAT, Atari format support, and various fixes additions May 1998
|
||||
* by Roman Hodek <Roman.Hodek@informatik.uni-erlangen.de> */
|
||||
|
||||
#include "version.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include <getopt.h>
|
||||
|
||||
#include "common.h"
|
||||
#include "fsck.fat.h"
|
||||
#include "io.h"
|
||||
#include "boot.h"
|
||||
#include "fat.h"
|
||||
#include "file.h"
|
||||
#include "check.h"
|
||||
|
||||
int interactive = 0, rw = 0, list = 0, test = 0, verbose = 0, write_immed = 0;
|
||||
int atari_format = 0, boot_only = 0;
|
||||
unsigned n_files = 0;
|
||||
void *mem_queue = NULL;
|
||||
|
||||
static void usage(char *name)
|
||||
{
|
||||
fprintf(stderr, "usage: %s [-aAbflrtvVwy] [-d path -d ...] "
|
||||
"[-u path -u ...]\n%15sdevice\n", name, "");
|
||||
fprintf(stderr, " -a automatically repair the filesystem\n");
|
||||
fprintf(stderr, " -A toggle Atari filesystem format\n");
|
||||
fprintf(stderr, " -b make read-only boot sector check\n");
|
||||
fprintf(stderr, " -d path drop that file\n");
|
||||
fprintf(stderr, " -f salvage unused chains to files\n");
|
||||
fprintf(stderr, " -l list path names\n");
|
||||
fprintf(stderr,
|
||||
" -n no-op, check non-interactively without changing\n");
|
||||
fprintf(stderr, " -p same as -a, for compat with other *fsck\n");
|
||||
fprintf(stderr, " -r interactively repair the filesystem (default)\n");
|
||||
fprintf(stderr, " -t test for bad clusters\n");
|
||||
fprintf(stderr, " -u path try to undelete that (non-directory) file\n");
|
||||
fprintf(stderr, " -v verbose mode\n");
|
||||
fprintf(stderr, " -V perform a verification pass\n");
|
||||
fprintf(stderr, " -w write changes to disk immediately\n");
|
||||
fprintf(stderr, " -y same as -a, for compat with other *fsck\n");
|
||||
exit(2);
|
||||
}
|
||||
|
||||
/*
|
||||
* ++roman: On m68k, check if this is an Atari; if yes, turn on Atari variant
|
||||
* of MS-DOS filesystem by default.
|
||||
*/
|
||||
static void check_atari(void)
|
||||
{
|
||||
#ifdef __mc68000__
|
||||
FILE *f;
|
||||
char line[128], *p;
|
||||
|
||||
if (!(f = fopen("/proc/hardware", "r"))) {
|
||||
perror("/proc/hardware");
|
||||
return;
|
||||
}
|
||||
|
||||
while (fgets(line, sizeof(line), f)) {
|
||||
if (strncmp(line, "Model:", 6) == 0) {
|
||||
p = line + 6;
|
||||
p += strspn(p, " \t");
|
||||
if (strncmp(p, "Atari ", 6) == 0)
|
||||
atari_format = 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
fclose(f);
|
||||
#endif
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
DOS_FS fs;
|
||||
int salvage_files, verify, c;
|
||||
uint32_t free_clusters = 0;
|
||||
|
||||
memset(&fs, 0, sizeof(fs));
|
||||
salvage_files = verify = 0;
|
||||
rw = interactive = 1;
|
||||
check_atari();
|
||||
|
||||
while ((c = getopt(argc, argv, "Aad:bflnprtu:vVwy")) != -1)
|
||||
switch (c) {
|
||||
case 'A': /* toggle Atari format */
|
||||
atari_format = !atari_format;
|
||||
break;
|
||||
case 'a':
|
||||
case 'p':
|
||||
case 'y':
|
||||
rw = 1;
|
||||
interactive = 0;
|
||||
salvage_files = 1;
|
||||
break;
|
||||
case 'b':
|
||||
rw = 0;
|
||||
interactive = 0;
|
||||
boot_only = 1;
|
||||
break;
|
||||
case 'd':
|
||||
file_add(optarg, fdt_drop);
|
||||
break;
|
||||
case 'f':
|
||||
salvage_files = 1;
|
||||
break;
|
||||
case 'l':
|
||||
list = 1;
|
||||
break;
|
||||
case 'n':
|
||||
rw = 0;
|
||||
interactive = 0;
|
||||
break;
|
||||
case 'r':
|
||||
rw = 1;
|
||||
interactive = 1;
|
||||
break;
|
||||
case 't':
|
||||
test = 1;
|
||||
break;
|
||||
case 'u':
|
||||
file_add(optarg, fdt_undelete);
|
||||
break;
|
||||
case 'v':
|
||||
verbose = 1;
|
||||
break;
|
||||
case 'V':
|
||||
verify = 1;
|
||||
break;
|
||||
case 'w':
|
||||
write_immed = 1;
|
||||
break;
|
||||
default:
|
||||
usage(argv[0]);
|
||||
}
|
||||
if ((test || write_immed) && !rw) {
|
||||
fprintf(stderr, "-t and -w can not be used in read only mode\n");
|
||||
exit(2);
|
||||
}
|
||||
if (optind != argc - 1)
|
||||
usage(argv[0]);
|
||||
|
||||
printf("fsck.fat " VERSION " (" VERSION_DATE ")\n");
|
||||
fs_open(argv[optind], rw);
|
||||
|
||||
read_boot(&fs);
|
||||
if (boot_only)
|
||||
goto exit;
|
||||
|
||||
if (verify)
|
||||
printf("Starting check/repair pass.\n");
|
||||
while (read_fat(&fs), scan_root(&fs))
|
||||
qfree(&mem_queue);
|
||||
if (test)
|
||||
fix_bad(&fs);
|
||||
if (salvage_files)
|
||||
reclaim_file(&fs);
|
||||
else
|
||||
reclaim_free(&fs);
|
||||
free_clusters = update_free(&fs);
|
||||
file_unused();
|
||||
qfree(&mem_queue);
|
||||
if (verify) {
|
||||
n_files = 0;
|
||||
printf("Starting verification pass.\n");
|
||||
read_fat(&fs);
|
||||
scan_root(&fs);
|
||||
reclaim_free(&fs);
|
||||
qfree(&mem_queue);
|
||||
}
|
||||
|
||||
exit:
|
||||
if (fs_changed()) {
|
||||
if (rw) {
|
||||
if (interactive)
|
||||
rw = get_key("yn", "Perform changes ? (y/n)") == 'y';
|
||||
else
|
||||
printf("Performing changes.\n");
|
||||
} else
|
||||
printf("Leaving filesystem unchanged.\n");
|
||||
}
|
||||
|
||||
if (!boot_only)
|
||||
printf("%s: %u files, %lu/%lu clusters\n", argv[optind],
|
||||
n_files, (unsigned long)fs.clusters - free_clusters, (unsigned long)fs.clusters);
|
||||
|
||||
return fs_close(rw) ? 1 : 0;
|
||||
}
|
||||
@@ -0,0 +1,191 @@
|
||||
/* fsck.fat.h - Common data structures and global variables
|
||||
|
||||
Copyright (C) 1993 Werner Almesberger <werner.almesberger@lrc.di.epfl.ch>
|
||||
Copyright (C) 1998 Roman Hodek <Roman.Hodek@informatik.uni-erlangen.de>
|
||||
Copyright (C) 2008-2014 Daniel Baumann <mail@daniel-baumann.ch>
|
||||
|
||||
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 3 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, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
The complete text of the GNU General Public License
|
||||
can be found in /usr/share/common-licenses/GPL-3 file.
|
||||
*/
|
||||
|
||||
/* FAT32, VFAT, Atari format support, and various fixes additions May 1998
|
||||
* by Roman Hodek <Roman.Hodek@informatik.uni-erlangen.de> */
|
||||
|
||||
#ifndef _DOSFSCK_H
|
||||
#define _DOSFSCK_H
|
||||
|
||||
#include <fcntl.h>
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
#include <endian.h>
|
||||
|
||||
#include "msdos_fs.h"
|
||||
|
||||
#define VFAT_LN_ATTR (ATTR_RO | ATTR_HIDDEN | ATTR_SYS | ATTR_VOLUME)
|
||||
|
||||
#define FAT_STATE_DIRTY 0x01
|
||||
|
||||
/* ++roman: Use own definition of boot sector structure -- the kernel headers'
|
||||
* name for it is msdos_boot_sector in 2.0 and fat_boot_sector in 2.1 ... */
|
||||
struct boot_sector {
|
||||
uint8_t ignored[3]; /* Boot strap short or near jump */
|
||||
uint8_t system_id[8]; /* Name - can be used to special case
|
||||
partition manager volumes */
|
||||
uint8_t sector_size[2]; /* bytes per logical sector */
|
||||
uint8_t cluster_size; /* sectors/cluster */
|
||||
uint16_t reserved; /* reserved sectors */
|
||||
uint8_t fats; /* number of FATs */
|
||||
uint8_t dir_entries[2]; /* root directory entries */
|
||||
uint8_t sectors[2]; /* number of sectors */
|
||||
uint8_t media; /* media code (unused) */
|
||||
uint16_t fat_length; /* sectors/FAT */
|
||||
uint16_t secs_track; /* sectors per track */
|
||||
uint16_t heads; /* number of heads */
|
||||
uint32_t hidden; /* hidden sectors (unused) */
|
||||
uint32_t total_sect; /* number of sectors (if sectors == 0) */
|
||||
|
||||
/* The following fields are only used by FAT32 */
|
||||
uint32_t fat32_length; /* sectors/FAT */
|
||||
uint16_t flags; /* bit 8: fat mirroring, low 4: active fat */
|
||||
uint8_t version[2]; /* major, minor filesystem version */
|
||||
uint32_t root_cluster; /* first cluster in root directory */
|
||||
uint16_t info_sector; /* filesystem info sector */
|
||||
uint16_t backup_boot; /* backup boot sector */
|
||||
uint8_t reserved2[12]; /* Unused */
|
||||
|
||||
uint8_t drive_number; /* Logical Drive Number */
|
||||
uint8_t reserved3; /* Unused */
|
||||
|
||||
uint8_t extended_sig; /* Extended Signature (0x29) */
|
||||
uint32_t serial; /* Serial number */
|
||||
uint8_t label[11]; /* FS label */
|
||||
uint8_t fs_type[8]; /* FS Type */
|
||||
|
||||
/* fill up to 512 bytes */
|
||||
uint8_t junk[422];
|
||||
} __attribute__ ((packed));
|
||||
|
||||
struct boot_sector_16 {
|
||||
uint8_t ignored[3]; /* Boot strap short or near jump */
|
||||
uint8_t system_id[8]; /* Name - can be used to special case
|
||||
partition manager volumes */
|
||||
uint8_t sector_size[2]; /* bytes per logical sector */
|
||||
uint8_t cluster_size; /* sectors/cluster */
|
||||
uint16_t reserved; /* reserved sectors */
|
||||
uint8_t fats; /* number of FATs */
|
||||
uint8_t dir_entries[2]; /* root directory entries */
|
||||
uint8_t sectors[2]; /* number of sectors */
|
||||
uint8_t media; /* media code (unused) */
|
||||
uint16_t fat_length; /* sectors/FAT */
|
||||
uint16_t secs_track; /* sectors per track */
|
||||
uint16_t heads; /* number of heads */
|
||||
uint32_t hidden; /* hidden sectors (unused) */
|
||||
uint32_t total_sect; /* number of sectors (if sectors == 0) */
|
||||
|
||||
uint8_t drive_number; /* Logical Drive Number */
|
||||
uint8_t reserved2; /* Unused */
|
||||
|
||||
uint8_t extended_sig; /* Extended Signature (0x29) */
|
||||
uint32_t serial; /* Serial number */
|
||||
uint8_t label[11]; /* FS label */
|
||||
uint8_t fs_type[8]; /* FS Type */
|
||||
|
||||
/* fill up to 512 bytes */
|
||||
uint8_t junk[450];
|
||||
} __attribute__ ((packed));
|
||||
|
||||
struct info_sector {
|
||||
uint32_t magic; /* Magic for info sector ('RRaA') */
|
||||
uint8_t junk[0x1dc];
|
||||
uint32_t reserved1; /* Nothing as far as I can tell */
|
||||
uint32_t signature; /* 0x61417272 ('rrAa') */
|
||||
uint32_t free_clusters; /* Free cluster count. -1 if unknown */
|
||||
uint32_t next_cluster; /* Most recently allocated cluster. */
|
||||
uint32_t reserved2[3];
|
||||
uint16_t reserved3;
|
||||
uint16_t boot_sign;
|
||||
};
|
||||
|
||||
typedef struct {
|
||||
uint8_t name[8], ext[3]; /* name and extension */
|
||||
uint8_t attr; /* attribute bits */
|
||||
uint8_t lcase; /* Case for base and extension */
|
||||
uint8_t ctime_ms; /* Creation time, milliseconds */
|
||||
uint16_t ctime; /* Creation time */
|
||||
uint16_t cdate; /* Creation date */
|
||||
uint16_t adate; /* Last access date */
|
||||
uint16_t starthi; /* High 16 bits of cluster in FAT32 */
|
||||
uint16_t time, date, start; /* time, date and first cluster */
|
||||
uint32_t size; /* file size (in bytes) */
|
||||
} __attribute__ ((packed)) DIR_ENT;
|
||||
|
||||
typedef struct _dos_file {
|
||||
DIR_ENT dir_ent;
|
||||
char *lfn;
|
||||
loff_t offset;
|
||||
loff_t lfn_offset;
|
||||
struct _dos_file *parent; /* parent directory */
|
||||
struct _dos_file *next; /* next entry */
|
||||
struct _dos_file *first; /* first entry (directory only) */
|
||||
} DOS_FILE;
|
||||
|
||||
typedef struct {
|
||||
uint32_t value;
|
||||
uint32_t reserved;
|
||||
} FAT_ENTRY;
|
||||
|
||||
typedef struct {
|
||||
int nfats;
|
||||
loff_t fat_start;
|
||||
unsigned int fat_size; /* unit is bytes */
|
||||
unsigned int fat_bits; /* size of a FAT entry */
|
||||
unsigned int eff_fat_bits; /* # of used bits in a FAT entry */
|
||||
uint32_t root_cluster; /* 0 for old-style root dir */
|
||||
loff_t root_start;
|
||||
unsigned int root_entries;
|
||||
loff_t data_start;
|
||||
unsigned int cluster_size;
|
||||
uint32_t clusters;
|
||||
loff_t fsinfo_start; /* 0 if not present */
|
||||
long free_clusters;
|
||||
loff_t backupboot_start; /* 0 if not present */
|
||||
unsigned char *fat;
|
||||
DOS_FILE **cluster_owner;
|
||||
char *label;
|
||||
} DOS_FS;
|
||||
|
||||
extern int interactive, rw, list, verbose, test, write_immed;
|
||||
extern int atari_format;
|
||||
extern unsigned n_files;
|
||||
extern void *mem_queue;
|
||||
|
||||
/* value to use as end-of-file marker */
|
||||
#define FAT_EOF(fs) ((atari_format ? 0xfff : 0xff8) | FAT_EXTD(fs))
|
||||
#define FAT_IS_EOF(fs,v) ((uint32_t)(v) >= (0xff8|FAT_EXTD(fs)))
|
||||
/* value to mark bad clusters */
|
||||
#define FAT_BAD(fs) (0xff7 | FAT_EXTD(fs))
|
||||
/* range of values used for bad clusters */
|
||||
#define FAT_MIN_BAD(fs) ((atari_format ? 0xff0 : 0xff7) | FAT_EXTD(fs))
|
||||
#define FAT_MAX_BAD(fs) ((atari_format ? 0xff7 : 0xff7) | FAT_EXTD(fs))
|
||||
#define FAT_IS_BAD(fs,v) ((v) >= FAT_MIN_BAD(fs) && (v) <= FAT_MAX_BAD(fs))
|
||||
|
||||
/* return -16 as a number with fs->fat_bits bits */
|
||||
#define FAT_EXTD(fs) (((1 << fs->eff_fat_bits)-1) & ~0xf)
|
||||
|
||||
/* marker for files with no 8.3 name */
|
||||
#define FAT_NO_83NAME 32
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,232 @@
|
||||
/* io.c - Virtual disk input/output
|
||||
|
||||
Copyright (C) 1993 Werner Almesberger <werner.almesberger@lrc.di.epfl.ch>
|
||||
Copyright (C) 1998 Roman Hodek <Roman.Hodek@informatik.uni-erlangen.de>
|
||||
Copyright (C) 2008-2014 Daniel Baumann <mail@daniel-baumann.ch>
|
||||
|
||||
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 3 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, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
The complete text of the GNU General Public License
|
||||
can be found in /usr/share/common-licenses/GPL-3 file.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Thu Feb 26 01:15:36 CET 1998: Martin Schulze <joey@infodrom.north.de>
|
||||
* Fixed nasty bug that caused every file with a name like
|
||||
* xxxxxxxx.xxx to be treated as bad name that needed to be fixed.
|
||||
*/
|
||||
|
||||
/* FAT32, VFAT, Atari format support, and various fixes additions May 1998
|
||||
* by Roman Hodek <Roman.Hodek@informatik.uni-erlangen.de> */
|
||||
|
||||
#define _LARGEFILE64_SOURCE
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#include <linux/fd.h>
|
||||
|
||||
#include "fsck.fat.h"
|
||||
#include "common.h"
|
||||
#include "io.h"
|
||||
|
||||
typedef struct _change {
|
||||
void *data;
|
||||
loff_t pos;
|
||||
int size;
|
||||
struct _change *next;
|
||||
} CHANGE;
|
||||
|
||||
static CHANGE *changes, *last;
|
||||
static int fd, did_change = 0;
|
||||
|
||||
unsigned device_no;
|
||||
|
||||
#ifdef __DJGPP__
|
||||
#include "volume.h" /* DOS lowlevel disk access functions */
|
||||
loff_t llseek(int fd, loff_t offset, int whence)
|
||||
{
|
||||
if ((whence != SEEK_SET) || (fd == 4711))
|
||||
return -1; /* only those supported */
|
||||
return VolumeSeek(offset);
|
||||
}
|
||||
|
||||
#define open OpenVolume
|
||||
#define close CloseVolume
|
||||
#define read(a,b,c) ReadVolume(b,c)
|
||||
#define write(a,b,c) WriteVolume(b,c)
|
||||
#else
|
||||
loff_t llseek(int fd, loff_t offset, int whence)
|
||||
{
|
||||
return (loff_t) lseek64(fd, (off64_t) offset, whence);
|
||||
}
|
||||
#endif
|
||||
|
||||
void fs_open(char *path, int rw)
|
||||
{
|
||||
struct stat stbuf;
|
||||
|
||||
if ((fd = open(path, rw ? O_RDWR : O_RDONLY)) < 0) {
|
||||
perror("open");
|
||||
exit(6);
|
||||
}
|
||||
changes = last = NULL;
|
||||
did_change = 0;
|
||||
|
||||
#ifndef _DJGPP_
|
||||
if (fstat(fd, &stbuf) < 0)
|
||||
pdie("fstat %s", path);
|
||||
device_no = S_ISBLK(stbuf.st_mode) ? (stbuf.st_rdev >> 8) & 0xff : 0;
|
||||
#else
|
||||
if (IsWorkingOnImageFile()) {
|
||||
if (fstat(GetVolumeHandle(), &stbuf) < 0)
|
||||
pdie("fstat image %s", path);
|
||||
device_no = 0;
|
||||
} else {
|
||||
/* return 2 for floppy, 1 for ramdisk, 7 for loopback */
|
||||
/* used by boot.c in Atari mode: floppy always FAT12, */
|
||||
/* loopback / ramdisk only FAT12 if usual floppy size, */
|
||||
/* harddisk always FAT16 on Atari... */
|
||||
device_no = (GetVolumeHandle() < 2) ? 2 : 1;
|
||||
/* telling "floppy" for A:/B:, "ramdisk" for the rest */
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
/**
|
||||
* Read data from the partition, accounting for any pending updates that are
|
||||
* queued for writing.
|
||||
*
|
||||
* @param[in] pos Byte offset, relative to the beginning of the partition,
|
||||
* at which to read
|
||||
* @param[in] size Number of bytes to read
|
||||
* @param[out] data Where to put the data read
|
||||
*/
|
||||
void fs_read(loff_t pos, int size, void *data)
|
||||
{
|
||||
CHANGE *walk;
|
||||
int got;
|
||||
|
||||
if (llseek(fd, pos, 0) != pos)
|
||||
pdie("Seek to %lld", pos);
|
||||
if ((got = read(fd, data, size)) < 0)
|
||||
pdie("Read %d bytes at %lld", size, pos);
|
||||
if (got != size)
|
||||
die("Got %d bytes instead of %d at %lld", got, size, pos);
|
||||
for (walk = changes; walk; walk = walk->next) {
|
||||
if (walk->pos < pos + size && walk->pos + walk->size > pos) {
|
||||
if (walk->pos < pos)
|
||||
memcpy(data, (char *)walk->data + pos - walk->pos, min(size,
|
||||
walk->
|
||||
size -
|
||||
pos +
|
||||
walk->
|
||||
pos));
|
||||
else
|
||||
memcpy((char *)data + walk->pos - pos, walk->data,
|
||||
min(walk->size, size + pos - walk->pos));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int fs_test(loff_t pos, int size)
|
||||
{
|
||||
void *scratch;
|
||||
int okay;
|
||||
|
||||
if (llseek(fd, pos, 0) != pos)
|
||||
pdie("Seek to %lld", pos);
|
||||
scratch = alloc(size);
|
||||
okay = read(fd, scratch, size) == size;
|
||||
free(scratch);
|
||||
return okay;
|
||||
}
|
||||
|
||||
void fs_write(loff_t pos, int size, void *data)
|
||||
{
|
||||
CHANGE *new;
|
||||
int did;
|
||||
|
||||
if (write_immed) {
|
||||
did_change = 1;
|
||||
if (llseek(fd, pos, 0) != pos)
|
||||
pdie("Seek to %lld", pos);
|
||||
if ((did = write(fd, data, size)) == size)
|
||||
return;
|
||||
if (did < 0)
|
||||
pdie("Write %d bytes at %lld", size, pos);
|
||||
die("Wrote %d bytes instead of %d at %lld", did, size, pos);
|
||||
}
|
||||
new = alloc(sizeof(CHANGE));
|
||||
new->pos = pos;
|
||||
memcpy(new->data = alloc(new->size = size), data, size);
|
||||
new->next = NULL;
|
||||
if (last)
|
||||
last->next = new;
|
||||
else
|
||||
changes = new;
|
||||
last = new;
|
||||
}
|
||||
|
||||
static void fs_flush(void)
|
||||
{
|
||||
CHANGE *this;
|
||||
int size;
|
||||
|
||||
while (changes) {
|
||||
this = changes;
|
||||
changes = changes->next;
|
||||
if (llseek(fd, this->pos, 0) != this->pos)
|
||||
fprintf(stderr,
|
||||
"Seek to %lld failed: %s\n Did not write %d bytes.\n",
|
||||
(long long)this->pos, strerror(errno), this->size);
|
||||
else if ((size = write(fd, this->data, this->size)) < 0)
|
||||
fprintf(stderr, "Writing %d bytes at %lld failed: %s\n", this->size,
|
||||
(long long)this->pos, strerror(errno));
|
||||
else if (size != this->size)
|
||||
fprintf(stderr, "Wrote %d bytes instead of %d bytes at %lld."
|
||||
"\n", size, this->size, (long long)this->pos);
|
||||
free(this->data);
|
||||
free(this);
|
||||
}
|
||||
}
|
||||
|
||||
int fs_close(int write)
|
||||
{
|
||||
CHANGE *next;
|
||||
int changed;
|
||||
|
||||
changed = ! !changes;
|
||||
if (write)
|
||||
fs_flush();
|
||||
else
|
||||
while (changes) {
|
||||
next = changes->next;
|
||||
free(changes->data);
|
||||
free(changes);
|
||||
changes = next;
|
||||
}
|
||||
if (close(fd) < 0)
|
||||
pdie("closing filesystem");
|
||||
return changed || did_change;
|
||||
}
|
||||
|
||||
int fs_changed(void)
|
||||
{
|
||||
return ! !changes || did_change;
|
||||
}
|
||||
@@ -0,0 +1,71 @@
|
||||
/* io.h - Virtual disk input/output
|
||||
|
||||
Copyright (C) 1993 Werner Almesberger <werner.almesberger@lrc.di.epfl.ch>
|
||||
Copyright (C) 1998 Roman Hodek <Roman.Hodek@informatik.uni-erlangen.de>
|
||||
Copyright (C) 2008-2014 Daniel Baumann <mail@daniel-baumann.ch>
|
||||
|
||||
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 3 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, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
The complete text of the GNU General Public License
|
||||
can be found in /usr/share/common-licenses/GPL-3 file.
|
||||
*/
|
||||
|
||||
/* FAT32, VFAT, Atari format support, and various fixes additions May 1998
|
||||
* by Roman Hodek <Roman.Hodek@informatik.uni-erlangen.de> */
|
||||
|
||||
#ifndef _IO_H
|
||||
#define _IO_H
|
||||
|
||||
#include <fcntl.h> /* for loff_t */
|
||||
|
||||
loff_t llseek(int fd, loff_t offset, int whence);
|
||||
|
||||
/* lseek() analogue for large offsets. */
|
||||
|
||||
void fs_open(char *path, int rw);
|
||||
|
||||
/* Opens the filesystem PATH. If RW is zero, the filesystem is opened
|
||||
read-only, otherwise, it is opened read-write. */
|
||||
|
||||
void fs_read(loff_t pos, int size, void *data);
|
||||
|
||||
/* Reads SIZE bytes starting at POS into DATA. Performs all applicable
|
||||
changes. */
|
||||
|
||||
int fs_test(loff_t pos, int size);
|
||||
|
||||
/* Returns a non-zero integer if SIZE bytes starting at POS can be read without
|
||||
errors. Otherwise, it returns zero. */
|
||||
|
||||
void fs_write(loff_t pos, int size, void *data);
|
||||
|
||||
/* If write_immed is non-zero, SIZE bytes are written from DATA to the disk,
|
||||
starting at POS. If write_immed is zero, the change is added to a list in
|
||||
memory. */
|
||||
|
||||
int fs_close(int write);
|
||||
|
||||
/* Closes the filesystem, performs all pending changes if WRITE is non-zero
|
||||
and removes the list of changes. Returns a non-zero integer if the file
|
||||
system has been changed since the last fs_open, zero otherwise. */
|
||||
|
||||
int fs_changed(void);
|
||||
|
||||
/* Determines whether the filesystem has changed. See fs_close. */
|
||||
|
||||
extern unsigned device_no;
|
||||
|
||||
/* Major number of device (0 if file) and size (in 512 byte sectors) */
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,528 @@
|
||||
/* lfn.c - Functions for handling VFAT long filenames
|
||||
|
||||
Copyright (C) 1998 Roman Hodek <Roman.Hodek@informatik.uni-erlangen.de>
|
||||
Copyright (C) 2008-2014 Daniel Baumann <mail@daniel-baumann.ch>
|
||||
|
||||
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 3 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, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
The complete text of the GNU General Public License
|
||||
can be found in /usr/share/common-licenses/GPL-3 file.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <limits.h>
|
||||
#include <time.h>
|
||||
|
||||
#include "common.h"
|
||||
#include "io.h"
|
||||
#include "fsck.fat.h"
|
||||
#include "lfn.h"
|
||||
#include "file.h"
|
||||
|
||||
typedef struct {
|
||||
uint8_t id; /* sequence number for slot */
|
||||
uint8_t name0_4[10]; /* first 5 characters in name */
|
||||
uint8_t attr; /* attribute byte */
|
||||
uint8_t reserved; /* always 0 */
|
||||
uint8_t alias_checksum; /* checksum for 8.3 alias */
|
||||
uint8_t name5_10[12]; /* 6 more characters in name */
|
||||
uint16_t start; /* starting cluster number, 0 in long slots */
|
||||
uint8_t name11_12[4]; /* last 2 characters in name */
|
||||
} LFN_ENT;
|
||||
|
||||
#define LFN_ID_START 0x40
|
||||
#define LFN_ID_SLOTMASK 0x1f
|
||||
|
||||
#define CHARS_PER_LFN 13
|
||||
|
||||
/* These modul-global vars represent the state of the LFN parser */
|
||||
unsigned char *lfn_unicode = NULL;
|
||||
unsigned char lfn_checksum;
|
||||
int lfn_slot = -1;
|
||||
loff_t *lfn_offsets = NULL;
|
||||
int lfn_parts = 0;
|
||||
|
||||
static unsigned char fat_uni2esc[64] = {
|
||||
'0', '1', '2', '3', '4', '5', '6', '7',
|
||||
'8', '9', 'A', 'B', 'C', 'D', 'E', 'F',
|
||||
'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N',
|
||||
'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V',
|
||||
'W', 'X', 'Y', 'Z', 'a', 'b', 'c', 'd',
|
||||
'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l',
|
||||
'm', 'n', 'o', 'p', 'q', 'r', 's', 't',
|
||||
'u', 'v', 'w', 'x', 'y', 'z', '+', '-'
|
||||
};
|
||||
|
||||
/* This defines which unicode chars are directly convertable to ISO-8859-1 */
|
||||
#define UNICODE_CONVERTABLE(cl,ch) (ch == 0 && (cl < 0x80 || cl >= 0xa0))
|
||||
|
||||
/* for maxlen param */
|
||||
#define UNTIL_0 INT_MAX
|
||||
|
||||
/* Convert name part in 'lfn' from unicode to ASCII */
|
||||
#define CNV_THIS_PART(lfn) \
|
||||
({ \
|
||||
unsigned char __part_uni[CHARS_PER_LFN*2]; \
|
||||
copy_lfn_part( __part_uni, lfn ); \
|
||||
cnv_unicode( __part_uni, CHARS_PER_LFN, 0 ); \
|
||||
})
|
||||
|
||||
/* Convert name parts collected so far (from previous slots) from unicode to
|
||||
* ASCII */
|
||||
#define CNV_PARTS_SO_FAR() \
|
||||
(cnv_unicode( lfn_unicode+(lfn_slot*CHARS_PER_LFN*2), \
|
||||
lfn_parts*CHARS_PER_LFN, 0 ))
|
||||
|
||||
#define BYTES_TO_WCHAR(cl,ch) ((wchar_t)((unsigned)(cl) + ((unsigned)(ch) << 8)))
|
||||
static size_t mbslen(wchar_t x)
|
||||
{
|
||||
wchar_t wstr[] = { x, 0 };
|
||||
return wcstombs(NULL, wstr, 0);
|
||||
}
|
||||
|
||||
static size_t wctombs(char *dest, wchar_t x)
|
||||
{
|
||||
wchar_t wstr[] = { x, 0 };
|
||||
size_t size = wcstombs(NULL, wstr, 0);
|
||||
if (size != (size_t) - 1)
|
||||
size = wcstombs(dest, wstr, size + 1);
|
||||
return size;
|
||||
}
|
||||
|
||||
/* This function converts an unicode string to a normal ASCII string, assuming
|
||||
* ISO-8859-1 charset. Characters not in 8859-1 are converted to the same
|
||||
* escape notation as used by the kernel, i.e. the uuencode-like ":xxx" */
|
||||
static char *cnv_unicode(const unsigned char *uni, int maxlen, int use_q)
|
||||
{
|
||||
const unsigned char *up;
|
||||
unsigned char *out, *cp;
|
||||
int len, val;
|
||||
size_t x;
|
||||
|
||||
for (len = 0, up = uni; (up - uni) / 2 < maxlen && (up[0] || up[1]);
|
||||
up += 2) {
|
||||
if ((x = mbslen(BYTES_TO_WCHAR(up[0], up[1]))) != (size_t) - 1)
|
||||
len += x;
|
||||
else if (UNICODE_CONVERTABLE(up[0], up[1]))
|
||||
++len;
|
||||
else
|
||||
len += 4;
|
||||
}
|
||||
cp = out = use_q ? qalloc(&mem_queue, len + 1) : alloc(len + 1);
|
||||
|
||||
for (up = uni; (up - uni) / 2 < maxlen && (up[0] || up[1]); up += 2) {
|
||||
if ((x =
|
||||
wctombs((char *)cp, BYTES_TO_WCHAR(up[0], up[1]))) != (size_t) - 1)
|
||||
cp += x;
|
||||
else if (UNICODE_CONVERTABLE(up[0], up[1]))
|
||||
*cp++ = up[0];
|
||||
else {
|
||||
/* here the same escape notation is used as in the Linux kernel */
|
||||
*cp++ = ':';
|
||||
val = (up[1] << 8) + up[0];
|
||||
cp[2] = fat_uni2esc[val & 0x3f];
|
||||
val >>= 6;
|
||||
cp[1] = fat_uni2esc[val & 0x3f];
|
||||
val >>= 6;
|
||||
cp[0] = fat_uni2esc[val & 0x3f];
|
||||
cp += 3;
|
||||
}
|
||||
}
|
||||
*cp = 0;
|
||||
|
||||
return (char *)out;
|
||||
}
|
||||
|
||||
static void copy_lfn_part(unsigned char *dst, LFN_ENT * lfn)
|
||||
{
|
||||
memcpy(dst, lfn->name0_4, 10);
|
||||
memcpy(dst + 10, lfn->name5_10, 12);
|
||||
memcpy(dst + 22, lfn->name11_12, 4);
|
||||
}
|
||||
|
||||
static void clear_lfn_slots(int start, int end)
|
||||
{
|
||||
int i;
|
||||
LFN_ENT empty;
|
||||
|
||||
/* New dir entry is zeroed except first byte, which is set to 0xe5.
|
||||
* This is to avoid that some FAT-reading OSes (not Linux! ;) stop reading
|
||||
* a directory at the first zero entry...
|
||||
*/
|
||||
memset(&empty, 0, sizeof(empty));
|
||||
empty.id = DELETED_FLAG;
|
||||
|
||||
for (i = start; i <= end; ++i) {
|
||||
fs_write(lfn_offsets[i], sizeof(LFN_ENT), &empty);
|
||||
}
|
||||
}
|
||||
|
||||
void lfn_fix_checksum(loff_t from, loff_t to, const char *short_name)
|
||||
{
|
||||
int i;
|
||||
uint8_t sum;
|
||||
for (sum = 0, i = 0; i < 11; i++)
|
||||
sum = (((sum & 1) << 7) | ((sum & 0xfe) >> 1)) + short_name[i];
|
||||
|
||||
for (; from < to; from += sizeof(LFN_ENT)) {
|
||||
fs_write(from + offsetof(LFN_ENT, alias_checksum), sizeof(sum), &sum);
|
||||
}
|
||||
}
|
||||
|
||||
void lfn_reset(void)
|
||||
{
|
||||
if (lfn_unicode)
|
||||
free(lfn_unicode);
|
||||
lfn_unicode = NULL;
|
||||
if (lfn_offsets)
|
||||
free(lfn_offsets);
|
||||
lfn_offsets = NULL;
|
||||
lfn_slot = -1;
|
||||
}
|
||||
|
||||
/* This function is only called with de->attr == VFAT_LN_ATTR. It stores part
|
||||
* of the long name. */
|
||||
void lfn_add_slot(DIR_ENT * de, loff_t dir_offset)
|
||||
{
|
||||
LFN_ENT *lfn = (LFN_ENT *) de;
|
||||
int slot = lfn->id & LFN_ID_SLOTMASK;
|
||||
unsigned offset;
|
||||
|
||||
if (lfn_slot == 0)
|
||||
lfn_check_orphaned();
|
||||
|
||||
if (de->attr != VFAT_LN_ATTR)
|
||||
die("lfn_add_slot called with non-LFN directory entry");
|
||||
|
||||
if (lfn->id & LFN_ID_START && slot != 0) {
|
||||
if (lfn_slot != -1) {
|
||||
int can_clear = 0;
|
||||
/* There is already a LFN "in progess", so it is an error that a
|
||||
* new start entry is here. */
|
||||
/* Causes: 1) if slot# == expected: start bit set mysteriously, 2)
|
||||
* old LFN overwritten by new one */
|
||||
/* Fixes: 1) delete previous LFN 2) if slot# == expected and
|
||||
* checksum ok: clear start bit */
|
||||
/* XXX: Should delay that until next LFN known (then can better
|
||||
* display the name) */
|
||||
printf("A new long file name starts within an old one.\n");
|
||||
if (slot == lfn_slot && lfn->alias_checksum == lfn_checksum) {
|
||||
char *part1 = CNV_THIS_PART(lfn);
|
||||
char *part2 = CNV_PARTS_SO_FAR();
|
||||
printf(" It could be that the LFN start bit is wrong here\n"
|
||||
" if \"%s\" seems to match \"%s\".\n", part1, part2);
|
||||
free(part1);
|
||||
free(part2);
|
||||
can_clear = 1;
|
||||
}
|
||||
if (interactive) {
|
||||
printf("1: Delete previous LFN\n2: Leave it as it is.\n");
|
||||
if (can_clear)
|
||||
printf("3: Clear start bit and concatenate LFNs\n");
|
||||
} else
|
||||
printf(" Not auto-correcting this.\n");
|
||||
if (interactive) {
|
||||
switch (get_key(can_clear ? "123" : "12", "?")) {
|
||||
case '1':
|
||||
clear_lfn_slots(0, lfn_parts - 1);
|
||||
lfn_reset();
|
||||
break;
|
||||
case '2':
|
||||
break;
|
||||
case '3':
|
||||
lfn->id &= ~LFN_ID_START;
|
||||
fs_write(dir_offset + offsetof(LFN_ENT, id),
|
||||
sizeof(lfn->id), &lfn->id);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
lfn_slot = slot;
|
||||
lfn_checksum = lfn->alias_checksum;
|
||||
lfn_unicode = alloc((lfn_slot * CHARS_PER_LFN + 1) * 2);
|
||||
lfn_offsets = alloc(lfn_slot * sizeof(loff_t));
|
||||
lfn_parts = 0;
|
||||
} else if (lfn_slot == -1 && slot != 0) {
|
||||
/* No LFN in progress, but slot found; start bit missing */
|
||||
/* Causes: 1) start bit got lost, 2) Previous slot with start bit got
|
||||
* lost */
|
||||
/* Fixes: 1) delete LFN, 2) set start bit */
|
||||
char *part = CNV_THIS_PART(lfn);
|
||||
printf("Long filename fragment \"%s\" found outside a LFN "
|
||||
"sequence.\n (Maybe the start bit is missing on the "
|
||||
"last fragment)\n", part);
|
||||
if (interactive) {
|
||||
printf("1: Delete fragment\n2: Leave it as it is.\n"
|
||||
"3: Set start bit\n");
|
||||
} else
|
||||
printf(" Not auto-correcting this.\n");
|
||||
switch (interactive ? get_key("123", "?") : '2') {
|
||||
case '1':
|
||||
if (!lfn_offsets)
|
||||
lfn_offsets = alloc(sizeof(loff_t));
|
||||
lfn_offsets[0] = dir_offset;
|
||||
clear_lfn_slots(0, 0);
|
||||
lfn_reset();
|
||||
return;
|
||||
case '2':
|
||||
lfn_reset();
|
||||
return;
|
||||
case '3':
|
||||
lfn->id |= LFN_ID_START;
|
||||
fs_write(dir_offset + offsetof(LFN_ENT, id),
|
||||
sizeof(lfn->id), &lfn->id);
|
||||
lfn_slot = slot;
|
||||
lfn_checksum = lfn->alias_checksum;
|
||||
lfn_unicode = alloc((lfn_slot * CHARS_PER_LFN + 1) * 2);
|
||||
lfn_offsets = alloc(lfn_slot * sizeof(loff_t));
|
||||
lfn_parts = 0;
|
||||
break;
|
||||
}
|
||||
} else if (slot != lfn_slot) {
|
||||
/* wrong sequence number */
|
||||
/* Causes: 1) seq-no destroyed */
|
||||
/* Fixes: 1) delete LFN, 2) fix number (maybe only if following parts
|
||||
* are ok?, maybe only if checksum is ok?) (Attention: space
|
||||
* for name was allocated before!) */
|
||||
int can_fix = 0;
|
||||
printf("Unexpected long filename sequence number "
|
||||
"(%d vs. expected %d).\n", slot, lfn_slot);
|
||||
if (lfn->alias_checksum == lfn_checksum && lfn_slot > 0) {
|
||||
char *part1 = CNV_THIS_PART(lfn);
|
||||
char *part2 = CNV_PARTS_SO_FAR();
|
||||
printf(" It could be that just the number is wrong\n"
|
||||
" if \"%s\" seems to match \"%s\".\n", part1, part2);
|
||||
free(part1);
|
||||
free(part2);
|
||||
can_fix = 1;
|
||||
}
|
||||
if (interactive) {
|
||||
printf
|
||||
("1: Delete LFN\n2: Leave it as it is (and ignore LFN so far)\n");
|
||||
if (can_fix)
|
||||
printf("3: Correct sequence number\n");
|
||||
} else
|
||||
printf(" Not auto-correcting this.\n");
|
||||
switch (interactive ? get_key(can_fix ? "123" : "12", "?") : '2') {
|
||||
case '1':
|
||||
if (!lfn_offsets) {
|
||||
lfn_offsets = alloc(sizeof(loff_t));
|
||||
lfn_parts = 0;
|
||||
}
|
||||
lfn_offsets[lfn_parts++] = dir_offset;
|
||||
clear_lfn_slots(0, lfn_parts - 1);
|
||||
lfn_reset();
|
||||
return;
|
||||
case '2':
|
||||
lfn_reset();
|
||||
return;
|
||||
case '3':
|
||||
lfn->id = (lfn->id & ~LFN_ID_SLOTMASK) | lfn_slot;
|
||||
fs_write(dir_offset + offsetof(LFN_ENT, id),
|
||||
sizeof(lfn->id), &lfn->id);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (lfn->alias_checksum != lfn_checksum) {
|
||||
/* checksum mismatch */
|
||||
/* Causes: 1) checksum field here destroyed */
|
||||
/* Fixes: 1) delete LFN, 2) fix checksum */
|
||||
printf("Checksum in long filename part wrong "
|
||||
"(%02x vs. expected %02x).\n",
|
||||
lfn->alias_checksum, lfn_checksum);
|
||||
if (interactive) {
|
||||
printf("1: Delete LFN\n2: Leave it as it is.\n"
|
||||
"3: Correct checksum\n");
|
||||
} else
|
||||
printf(" Not auto-correcting this.\n");
|
||||
if (interactive) {
|
||||
switch (get_key("123", "?")) {
|
||||
case '1':
|
||||
lfn_offsets[lfn_parts++] = dir_offset;
|
||||
clear_lfn_slots(0, lfn_parts - 1);
|
||||
lfn_reset();
|
||||
return;
|
||||
case '2':
|
||||
break;
|
||||
case '3':
|
||||
lfn->alias_checksum = lfn_checksum;
|
||||
fs_write(dir_offset + offsetof(LFN_ENT, alias_checksum),
|
||||
sizeof(lfn->alias_checksum), &lfn->alias_checksum);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (lfn_slot != -1) {
|
||||
lfn_slot--;
|
||||
offset = lfn_slot * CHARS_PER_LFN * 2;
|
||||
copy_lfn_part(lfn_unicode + offset, lfn);
|
||||
if (lfn->id & LFN_ID_START)
|
||||
lfn_unicode[offset + 26] = lfn_unicode[offset + 27] = 0;
|
||||
lfn_offsets[lfn_parts++] = dir_offset;
|
||||
}
|
||||
|
||||
if (lfn->reserved != 0) {
|
||||
printf("Reserved field in VFAT long filename slot is not 0 "
|
||||
"(but 0x%02x).\n", lfn->reserved);
|
||||
if (interactive)
|
||||
printf("1: Fix.\n2: Leave it.\n");
|
||||
else
|
||||
printf("Auto-setting to 0.\n");
|
||||
if (!interactive || get_key("12", "?") == '1') {
|
||||
lfn->reserved = 0;
|
||||
fs_write(dir_offset + offsetof(LFN_ENT, reserved),
|
||||
sizeof(lfn->reserved), &lfn->reserved);
|
||||
}
|
||||
}
|
||||
if (lfn->start != htole16(0)) {
|
||||
printf("Start cluster field in VFAT long filename slot is not 0 "
|
||||
"(but 0x%04x).\n", lfn->start);
|
||||
if (interactive)
|
||||
printf("1: Fix.\n2: Leave it.\n");
|
||||
else
|
||||
printf("Auto-setting to 0.\n");
|
||||
if (!interactive || get_key("12", "?") == '1') {
|
||||
lfn->start = htole16(0);
|
||||
fs_write(dir_offset + offsetof(LFN_ENT, start),
|
||||
sizeof(lfn->start), &lfn->start);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* This function is always called when de->attr != VFAT_LN_ATTR is found, to
|
||||
* retrieve the previously constructed LFN. */
|
||||
char *lfn_get(DIR_ENT * de, loff_t * lfn_offset)
|
||||
{
|
||||
char *lfn;
|
||||
uint8_t sum;
|
||||
int i;
|
||||
|
||||
*lfn_offset = 0;
|
||||
if (de->attr == VFAT_LN_ATTR)
|
||||
die("lfn_get called with LFN directory entry");
|
||||
|
||||
#if 0
|
||||
if (de->lcase)
|
||||
printf("lcase=%02x\n", de->lcase);
|
||||
#endif
|
||||
|
||||
if (lfn_slot == -1)
|
||||
/* no long name for this file */
|
||||
return NULL;
|
||||
|
||||
if (lfn_slot != 0) {
|
||||
/* The long name isn't finished yet. */
|
||||
/* Causes: 1) LFN slot overwritten by non-VFAT aware tool */
|
||||
/* Fixes: 1) delete LFN 2) move overwriting entry to somewhere else
|
||||
* and let user enter missing part of LFN (hard to do :-()
|
||||
* 3) renumber entries and truncate name */
|
||||
char *long_name = CNV_PARTS_SO_FAR();
|
||||
char *short_name = file_name(de->name);
|
||||
printf("Unfinished long file name \"%s\".\n"
|
||||
" (Start may have been overwritten by %s)\n",
|
||||
long_name, short_name);
|
||||
free(long_name);
|
||||
if (interactive) {
|
||||
printf("1: Delete LFN\n2: Leave it as it is.\n"
|
||||
"3: Fix numbering (truncates long name and attaches "
|
||||
"it to short name %s)\n", short_name);
|
||||
} else
|
||||
printf(" Not auto-correcting this.\n");
|
||||
switch (interactive ? get_key("123", "?") : '2') {
|
||||
case '1':
|
||||
clear_lfn_slots(0, lfn_parts - 1);
|
||||
lfn_reset();
|
||||
return NULL;
|
||||
case '2':
|
||||
lfn_reset();
|
||||
return NULL;
|
||||
case '3':
|
||||
for (i = 0; i < lfn_parts; ++i) {
|
||||
uint8_t id = (lfn_parts - i) | (i == 0 ? LFN_ID_START : 0);
|
||||
fs_write(lfn_offsets[i] + offsetof(LFN_ENT, id),
|
||||
sizeof(id), &id);
|
||||
}
|
||||
memmove(lfn_unicode, lfn_unicode + lfn_slot * CHARS_PER_LFN * 2,
|
||||
lfn_parts * CHARS_PER_LFN * 2);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
for (sum = 0, i = 0; i < 8; i++)
|
||||
sum = (((sum & 1) << 7) | ((sum & 0xfe) >> 1)) + de->name[i];
|
||||
for (i = 0; i < 3; i++)
|
||||
sum = (((sum & 1) << 7) | ((sum & 0xfe) >> 1)) + de->ext[i];
|
||||
if (sum != lfn_checksum) {
|
||||
/* checksum doesn't match, long name doesn't apply to this alias */
|
||||
/* Causes: 1) alias renamed */
|
||||
/* Fixes: 1) Fix checksum in LFN entries */
|
||||
char *long_name = CNV_PARTS_SO_FAR();
|
||||
char *short_name = file_name(de->name);
|
||||
printf("Wrong checksum for long file name \"%s\".\n"
|
||||
" (Short name %s may have changed without updating the long name)\n",
|
||||
long_name, short_name);
|
||||
free(long_name);
|
||||
if (interactive) {
|
||||
printf("1: Delete LFN\n2: Leave it as it is.\n"
|
||||
"3: Fix checksum (attaches to short name %s)\n", short_name);
|
||||
} else
|
||||
printf(" Not auto-correcting this.\n");
|
||||
if (interactive) {
|
||||
switch (get_key("123", "?")) {
|
||||
case '1':
|
||||
clear_lfn_slots(0, lfn_parts - 1);
|
||||
lfn_reset();
|
||||
return NULL;
|
||||
case '2':
|
||||
lfn_reset();
|
||||
return NULL;
|
||||
case '3':
|
||||
for (i = 0; i < lfn_parts; ++i) {
|
||||
fs_write(lfn_offsets[i] + offsetof(LFN_ENT, alias_checksum),
|
||||
sizeof(sum), &sum);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
*lfn_offset = lfn_offsets[0];
|
||||
lfn = cnv_unicode(lfn_unicode, UNTIL_0, 1);
|
||||
lfn_reset();
|
||||
return (lfn);
|
||||
}
|
||||
|
||||
void lfn_check_orphaned(void)
|
||||
{
|
||||
char *long_name;
|
||||
|
||||
if (lfn_slot == -1)
|
||||
return;
|
||||
|
||||
long_name = CNV_PARTS_SO_FAR();
|
||||
printf("Orphaned long file name part \"%s\"\n", long_name);
|
||||
if (interactive)
|
||||
printf("1: Delete.\n2: Leave it.\n");
|
||||
else
|
||||
printf(" Auto-deleting.\n");
|
||||
if (!interactive || get_key("12", "?") == '1') {
|
||||
clear_lfn_slots(0, lfn_parts - 1);
|
||||
}
|
||||
lfn_reset();
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
/* lfn.h - Functions for handling VFAT long filenames
|
||||
|
||||
Copyright (C) 1998 Roman Hodek <Roman.Hodek@informatik.uni-erlangen.de>
|
||||
Copyright (C) 2008-2014 Daniel Baumann <mail@daniel-baumann.ch>
|
||||
|
||||
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 3 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, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
The complete text of the GNU General Public License
|
||||
can be found in /usr/share/common-licenses/GPL-3 file.
|
||||
*/
|
||||
|
||||
#ifndef _LFN_H
|
||||
#define _LFN_H
|
||||
|
||||
void lfn_reset(void);
|
||||
/* Reset the state of the LFN parser. */
|
||||
|
||||
void lfn_add_slot(DIR_ENT * de, loff_t dir_offset);
|
||||
/* Process a dir slot that is a VFAT LFN entry. */
|
||||
|
||||
char *lfn_get(DIR_ENT * de, loff_t * lfn_offset);
|
||||
/* Retrieve the long name for the proper dir entry. */
|
||||
|
||||
void lfn_check_orphaned(void);
|
||||
|
||||
void lfn_fix_checksum(loff_t from, loff_t to, const char *short_name);
|
||||
|
||||
#endif
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,61 @@
|
||||
/* msdos_fs.h - MS-DOS filesystem constants/structures
|
||||
|
||||
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 3 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, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
The complete text of the GNU General Public License
|
||||
can be found in /usr/share/common-licenses/GPL-3 file.
|
||||
*/
|
||||
|
||||
#ifndef _MSDOS_FS_H
|
||||
#define _MSDOS_FS_H
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#define SECTOR_SIZE 512 /* sector size (bytes) */
|
||||
#define MSDOS_DPS (SECTOR_SIZE / sizeof(struct msdos_dir_entry))
|
||||
#define MSDOS_DPS_BITS 4 /* log2(MSDOS_DPS) */
|
||||
#define MSDOS_DIR_BITS 5 /* log2(sizeof(struct msdos_dir_entry)) */
|
||||
|
||||
#define ATTR_NONE 0 /* no attribute bits */
|
||||
#define ATTR_RO 1 /* read-only */
|
||||
#define ATTR_HIDDEN 2 /* hidden */
|
||||
#define ATTR_SYS 4 /* system */
|
||||
#define ATTR_VOLUME 8 /* volume label */
|
||||
#define ATTR_DIR 16 /* directory */
|
||||
#define ATTR_ARCH 32 /* archived */
|
||||
|
||||
/* attribute bits that are copied "as is" */
|
||||
#define ATTR_UNUSED (ATTR_VOLUME | ATTR_ARCH | ATTR_SYS | ATTR_HIDDEN)
|
||||
|
||||
#define DELETED_FLAG 0xe5 /* marks file as deleted when in name[0] */
|
||||
#define IS_FREE(n) (!*(n) || *(n) == DELETED_FLAG)
|
||||
|
||||
#define MSDOS_NAME 11 /* maximum name length */
|
||||
#define MSDOS_DOT ". " /* ".", padded to MSDOS_NAME chars */
|
||||
#define MSDOS_DOTDOT ".. " /* "..", padded to MSDOS_NAME chars */
|
||||
|
||||
struct msdos_dir_entry {
|
||||
uint8_t name[8], ext[3]; /* name and extension */
|
||||
uint8_t attr; /* attribute bits */
|
||||
uint8_t lcase; /* Case for base and extension */
|
||||
uint8_t ctime_cs; /* Creation time, centiseconds (0-199) */
|
||||
uint16_t ctime; /* Creation time */
|
||||
uint16_t cdate; /* Creation date */
|
||||
uint16_t adate; /* Last access date */
|
||||
uint16_t starthi; /* High 16 bits of cluster in FAT32 */
|
||||
uint16_t time, date, start; /* time, date and first cluster */
|
||||
uint32_t size; /* file size (in bytes) */
|
||||
} __attribute__ ((packed));
|
||||
|
||||
#endif /* _MSDOS_FS_H */
|
||||
@@ -0,0 +1,29 @@
|
||||
/* version.h
|
||||
|
||||
Copyright (C) 1998-2005 Roman Hodek <Roman.Hodek@informatik.uni-erlangen.de>
|
||||
Copyright (C) 2008-2014 Daniel Baumann <mail@daniel-baumann.ch>
|
||||
|
||||
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 3 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, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
The complete text of the GNU General Public License
|
||||
can be found in /usr/share/common-licenses/GPL-3 file.
|
||||
*/
|
||||
|
||||
#ifndef _version_h
|
||||
#define _version_h
|
||||
|
||||
#define VERSION "3.0.28"
|
||||
#define VERSION_DATE "2015-05-16"
|
||||
|
||||
#endif
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user