|
Kmods SIG |
50e2b3 |
From 772b29cca528fcb21374bb3e597d848779938d16 Mon Sep 17 00:00:00 2001
|
|
Kmods SIG |
50e2b3 |
From: Namjae Jeon <namjae.jeon@samsung.com>
|
|
Kmods SIG |
50e2b3 |
Date: Mon, 2 Mar 2020 15:21:40 +0900
|
|
Kmods SIG |
50e2b3 |
Subject: [Backport 772b29cca528] exfat: add misc operations
|
|
Kmods SIG |
50e2b3 |
MIME-Version: 1.0
|
|
Kmods SIG |
50e2b3 |
Content-Type: text/plain; charset=UTF-8
|
|
Kmods SIG |
50e2b3 |
Content-Transfer-Encoding: 8bit
|
|
Kmods SIG |
50e2b3 |
|
|
Kmods SIG |
50e2b3 |
This adds the implementation of misc operations for exfat.
|
|
Kmods SIG |
50e2b3 |
|
|
Kmods SIG |
50e2b3 |
Signed-off-by: Namjae Jeon <namjae.jeon@samsung.com>
|
|
Kmods SIG |
50e2b3 |
Signed-off-by: Sungjong Seo <sj1557.seo@samsung.com>
|
|
Kmods SIG |
50e2b3 |
Reviewed-by: Arnd Bergmann <arnd@arndb.de>
|
|
Kmods SIG |
50e2b3 |
Reviewed-by: Pali Rohár <pali.rohar@gmail.com>
|
|
Kmods SIG |
50e2b3 |
Reviewed-by: Christoph Hellwig <hch@lst.de>
|
|
Kmods SIG |
50e2b3 |
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
|
|
Kmods SIG |
50e2b3 |
---
|
|
Kmods SIG |
50e2b3 |
src/misc.c | 163 ++++++++++++++++++++++++++++++++++++++++++++++++
|
|
Kmods SIG |
50e2b3 |
1 file changed, 163 insertions(+)
|
|
Kmods SIG |
50e2b3 |
create mode 100644 src/misc.c
|
|
Kmods SIG |
50e2b3 |
|
|
Kmods SIG |
50e2b3 |
diff --git a/src/misc.c b/src/misc.c
|
|
Kmods SIG |
50e2b3 |
new file mode 100644
|
|
Kmods SIG |
50e2b3 |
index 0000000000000000000000000000000000000000..14a3300848f6a0fb754b9d34bdacbc31b90f5d07
|
|
Kmods SIG |
50e2b3 |
--- /dev/null
|
|
Kmods SIG |
50e2b3 |
+++ b/src/misc.c
|
|
Kmods SIG |
50e2b3 |
@@ -0,0 +1,163 @@
|
|
Kmods SIG |
50e2b3 |
+// SPDX-License-Identifier: GPL-2.0-or-later
|
|
Kmods SIG |
50e2b3 |
+/*
|
|
Kmods SIG |
50e2b3 |
+ * Written 1992,1993 by Werner Almesberger
|
|
Kmods SIG |
50e2b3 |
+ * 22/11/2000 - Fixed fat_date_unix2dos for dates earlier than 01/01/1980
|
|
Kmods SIG |
50e2b3 |
+ * and date_dos2unix for date==0 by Igor Zhbanov(bsg@uniyar.ac.ru)
|
|
Kmods SIG |
50e2b3 |
+ * Copyright (C) 2012-2013 Samsung Electronics Co., Ltd.
|
|
Kmods SIG |
50e2b3 |
+ */
|
|
Kmods SIG |
50e2b3 |
+
|
|
Kmods SIG |
50e2b3 |
+#include <linux/time.h>
|
|
Kmods SIG |
50e2b3 |
+#include <linux/fs.h>
|
|
Kmods SIG |
50e2b3 |
+#include <linux/slab.h>
|
|
Kmods SIG |
50e2b3 |
+#include <linux/buffer_head.h>
|
|
Kmods SIG |
50e2b3 |
+
|
|
Kmods SIG |
50e2b3 |
+#include "exfat_raw.h"
|
|
Kmods SIG |
50e2b3 |
+#include "exfat_fs.h"
|
|
Kmods SIG |
50e2b3 |
+
|
|
Kmods SIG |
50e2b3 |
+/*
|
|
Kmods SIG |
50e2b3 |
+ * exfat_fs_error reports a file system problem that might indicate fa data
|
|
Kmods SIG |
50e2b3 |
+ * corruption/inconsistency. Depending on 'errors' mount option the
|
|
Kmods SIG |
50e2b3 |
+ * panic() is called, or error message is printed FAT and nothing is done,
|
|
Kmods SIG |
50e2b3 |
+ * or filesystem is remounted read-only (default behavior).
|
|
Kmods SIG |
50e2b3 |
+ * In case the file system is remounted read-only, it can be made writable
|
|
Kmods SIG |
50e2b3 |
+ * again by remounting it.
|
|
Kmods SIG |
50e2b3 |
+ */
|
|
Kmods SIG |
50e2b3 |
+void __exfat_fs_error(struct super_block *sb, int report, const char *fmt, ...)
|
|
Kmods SIG |
50e2b3 |
+{
|
|
Kmods SIG |
50e2b3 |
+ struct exfat_mount_options *opts = &EXFAT_SB(sb)->options;
|
|
Kmods SIG |
50e2b3 |
+ va_list args;
|
|
Kmods SIG |
50e2b3 |
+ struct va_format vaf;
|
|
Kmods SIG |
50e2b3 |
+
|
|
Kmods SIG |
50e2b3 |
+ if (report) {
|
|
Kmods SIG |
50e2b3 |
+ va_start(args, fmt);
|
|
Kmods SIG |
50e2b3 |
+ vaf.fmt = fmt;
|
|
Kmods SIG |
50e2b3 |
+ vaf.va = &arg;;
|
|
Kmods SIG |
50e2b3 |
+ exfat_msg(sb, KERN_ERR, "error, %pV\n", &vaf;;
|
|
Kmods SIG |
50e2b3 |
+ va_end(args);
|
|
Kmods SIG |
50e2b3 |
+ }
|
|
Kmods SIG |
50e2b3 |
+
|
|
Kmods SIG |
50e2b3 |
+ if (opts->errors == EXFAT_ERRORS_PANIC) {
|
|
Kmods SIG |
50e2b3 |
+ panic("exFAT-fs (%s): fs panic from previous error\n",
|
|
Kmods SIG |
50e2b3 |
+ sb->s_id);
|
|
Kmods SIG |
50e2b3 |
+ } else if (opts->errors == EXFAT_ERRORS_RO && !sb_rdonly(sb)) {
|
|
Kmods SIG |
50e2b3 |
+ sb->s_flags |= SB_RDONLY;
|
|
Kmods SIG |
50e2b3 |
+ exfat_msg(sb, KERN_ERR, "Filesystem has been set read-only");
|
|
Kmods SIG |
50e2b3 |
+ }
|
|
Kmods SIG |
50e2b3 |
+}
|
|
Kmods SIG |
50e2b3 |
+
|
|
Kmods SIG |
50e2b3 |
+/*
|
|
Kmods SIG |
50e2b3 |
+ * exfat_msg() - print preformated EXFAT specific messages.
|
|
Kmods SIG |
50e2b3 |
+ * All logs except what uses exfat_fs_error() should be written by exfat_msg()
|
|
Kmods SIG |
50e2b3 |
+ */
|
|
Kmods SIG |
50e2b3 |
+void exfat_msg(struct super_block *sb, const char *level, const char *fmt, ...)
|
|
Kmods SIG |
50e2b3 |
+{
|
|
Kmods SIG |
50e2b3 |
+ struct va_format vaf;
|
|
Kmods SIG |
50e2b3 |
+ va_list args;
|
|
Kmods SIG |
50e2b3 |
+
|
|
Kmods SIG |
50e2b3 |
+ va_start(args, fmt);
|
|
Kmods SIG |
50e2b3 |
+ vaf.fmt = fmt;
|
|
Kmods SIG |
50e2b3 |
+ vaf.va = &arg;;
|
|
Kmods SIG |
50e2b3 |
+ /* level means KERN_ pacility level */
|
|
Kmods SIG |
50e2b3 |
+ printk("%sexFAT-fs (%s): %pV\n", level, sb->s_id, &vaf;;
|
|
Kmods SIG |
50e2b3 |
+ va_end(args);
|
|
Kmods SIG |
50e2b3 |
+}
|
|
Kmods SIG |
50e2b3 |
+
|
|
Kmods SIG |
50e2b3 |
+#define SECS_PER_MIN (60)
|
|
Kmods SIG |
50e2b3 |
+#define TIMEZONE_SEC(x) ((x) * 15 * SECS_PER_MIN)
|
|
Kmods SIG |
50e2b3 |
+
|
|
Kmods SIG |
50e2b3 |
+static void exfat_adjust_tz(struct timespec64 *ts, u8 tz_off)
|
|
Kmods SIG |
50e2b3 |
+{
|
|
Kmods SIG |
50e2b3 |
+ if (tz_off <= 0x3F)
|
|
Kmods SIG |
50e2b3 |
+ ts->tv_sec -= TIMEZONE_SEC(tz_off);
|
|
Kmods SIG |
50e2b3 |
+ else /* 0x40 <= (tz_off & 0x7F) <=0x7F */
|
|
Kmods SIG |
50e2b3 |
+ ts->tv_sec += TIMEZONE_SEC(0x80 - tz_off);
|
|
Kmods SIG |
50e2b3 |
+}
|
|
Kmods SIG |
50e2b3 |
+
|
|
Kmods SIG |
50e2b3 |
+/* Convert a EXFAT time/date pair to a UNIX date (seconds since 1 1 70). */
|
|
Kmods SIG |
50e2b3 |
+void exfat_get_entry_time(struct exfat_sb_info *sbi, struct timespec64 *ts,
|
|
Kmods SIG |
50e2b3 |
+ u8 tz, __le16 time, __le16 date, u8 time_ms)
|
|
Kmods SIG |
50e2b3 |
+{
|
|
Kmods SIG |
50e2b3 |
+ u16 t = le16_to_cpu(time);
|
|
Kmods SIG |
50e2b3 |
+ u16 d = le16_to_cpu(date);
|
|
Kmods SIG |
50e2b3 |
+
|
|
Kmods SIG |
50e2b3 |
+ ts->tv_sec = mktime64(1980 + (d >> 9), d >> 5 & 0x000F, d & 0x001F,
|
|
Kmods SIG |
50e2b3 |
+ t >> 11, (t >> 5) & 0x003F, (t & 0x001F) << 1);
|
|
Kmods SIG |
50e2b3 |
+
|
|
Kmods SIG |
50e2b3 |
+
|
|
Kmods SIG |
50e2b3 |
+ /* time_ms field represent 0 ~ 199(1990 ms) */
|
|
Kmods SIG |
50e2b3 |
+ if (time_ms) {
|
|
Kmods SIG |
50e2b3 |
+ ts->tv_sec += time_ms / 100;
|
|
Kmods SIG |
50e2b3 |
+ ts->tv_nsec = (time_ms % 100) * 10 * NSEC_PER_MSEC;
|
|
Kmods SIG |
50e2b3 |
+ }
|
|
Kmods SIG |
50e2b3 |
+
|
|
Kmods SIG |
50e2b3 |
+ if (tz & EXFAT_TZ_VALID)
|
|
Kmods SIG |
50e2b3 |
+ /* Adjust timezone to UTC0. */
|
|
Kmods SIG |
50e2b3 |
+ exfat_adjust_tz(ts, tz & ~EXFAT_TZ_VALID);
|
|
Kmods SIG |
50e2b3 |
+ else
|
|
Kmods SIG |
50e2b3 |
+ /* Convert from local time to UTC using time_offset. */
|
|
Kmods SIG |
50e2b3 |
+ ts->tv_sec -= sbi->options.time_offset * SECS_PER_MIN;
|
|
Kmods SIG |
50e2b3 |
+}
|
|
Kmods SIG |
50e2b3 |
+
|
|
Kmods SIG |
50e2b3 |
+/* Convert linear UNIX date to a EXFAT time/date pair. */
|
|
Kmods SIG |
50e2b3 |
+void exfat_set_entry_time(struct exfat_sb_info *sbi, struct timespec64 *ts,
|
|
Kmods SIG |
50e2b3 |
+ u8 *tz, __le16 *time, __le16 *date, u8 *time_ms)
|
|
Kmods SIG |
50e2b3 |
+{
|
|
Kmods SIG |
50e2b3 |
+ struct tm tm;
|
|
Kmods SIG |
50e2b3 |
+ u16 t, d;
|
|
Kmods SIG |
50e2b3 |
+
|
|
Kmods SIG |
50e2b3 |
+ time64_to_tm(ts->tv_sec, 0, &tm;;
|
|
Kmods SIG |
50e2b3 |
+ t = (tm.tm_hour << 11) | (tm.tm_min << 5) | (tm.tm_sec >> 1);
|
|
Kmods SIG |
50e2b3 |
+ d = ((tm.tm_year - 80) << 9) | ((tm.tm_mon + 1) << 5) | tm.tm_mday;
|
|
Kmods SIG |
50e2b3 |
+
|
|
Kmods SIG |
50e2b3 |
+ *time = cpu_to_le16(t);
|
|
Kmods SIG |
50e2b3 |
+ *date = cpu_to_le16(d);
|
|
Kmods SIG |
50e2b3 |
+
|
|
Kmods SIG |
50e2b3 |
+ /* time_ms field represent 0 ~ 199(1990 ms) */
|
|
Kmods SIG |
50e2b3 |
+ if (time_ms)
|
|
Kmods SIG |
50e2b3 |
+ *time_ms = (tm.tm_sec & 1) * 100 +
|
|
Kmods SIG |
50e2b3 |
+ ts->tv_nsec / (10 * NSEC_PER_MSEC);
|
|
Kmods SIG |
50e2b3 |
+
|
|
Kmods SIG |
50e2b3 |
+ /*
|
|
Kmods SIG |
50e2b3 |
+ * Record 00h value for OffsetFromUtc field and 1 value for OffsetValid
|
|
Kmods SIG |
50e2b3 |
+ * to indicate that local time and UTC are the same.
|
|
Kmods SIG |
50e2b3 |
+ */
|
|
Kmods SIG |
50e2b3 |
+ *tz = EXFAT_TZ_VALID;
|
|
Kmods SIG |
50e2b3 |
+}
|
|
Kmods SIG |
50e2b3 |
+
|
|
Kmods SIG |
50e2b3 |
+unsigned short exfat_calc_chksum_2byte(void *data, int len,
|
|
Kmods SIG |
50e2b3 |
+ unsigned short chksum, int type)
|
|
Kmods SIG |
50e2b3 |
+{
|
|
Kmods SIG |
50e2b3 |
+ int i;
|
|
Kmods SIG |
50e2b3 |
+ unsigned char *c = (unsigned char *)data;
|
|
Kmods SIG |
50e2b3 |
+
|
|
Kmods SIG |
50e2b3 |
+ for (i = 0; i < len; i++, c++) {
|
|
Kmods SIG |
50e2b3 |
+ if (((i == 2) || (i == 3)) && (type == CS_DIR_ENTRY))
|
|
Kmods SIG |
50e2b3 |
+ continue;
|
|
Kmods SIG |
50e2b3 |
+ chksum = (((chksum & 1) << 15) | ((chksum & 0xFFFE) >> 1)) +
|
|
Kmods SIG |
50e2b3 |
+ (unsigned short)*c;
|
|
Kmods SIG |
50e2b3 |
+ }
|
|
Kmods SIG |
50e2b3 |
+ return chksum;
|
|
Kmods SIG |
50e2b3 |
+}
|
|
Kmods SIG |
50e2b3 |
+
|
|
Kmods SIG |
50e2b3 |
+void exfat_update_bh(struct super_block *sb, struct buffer_head *bh, int sync)
|
|
Kmods SIG |
50e2b3 |
+{
|
|
Kmods SIG |
50e2b3 |
+ set_bit(EXFAT_SB_DIRTY, &EXFAT_SB(sb)->s_state);
|
|
Kmods SIG |
50e2b3 |
+ set_buffer_uptodate(bh);
|
|
Kmods SIG |
50e2b3 |
+ mark_buffer_dirty(bh);
|
|
Kmods SIG |
50e2b3 |
+
|
|
Kmods SIG |
50e2b3 |
+ if (sync)
|
|
Kmods SIG |
50e2b3 |
+ sync_dirty_buffer(bh);
|
|
Kmods SIG |
50e2b3 |
+}
|
|
Kmods SIG |
50e2b3 |
+
|
|
Kmods SIG |
50e2b3 |
+void exfat_chain_set(struct exfat_chain *ec, unsigned int dir,
|
|
Kmods SIG |
50e2b3 |
+ unsigned int size, unsigned char flags)
|
|
Kmods SIG |
50e2b3 |
+{
|
|
Kmods SIG |
50e2b3 |
+ ec->dir = dir;
|
|
Kmods SIG |
50e2b3 |
+ ec->size = size;
|
|
Kmods SIG |
50e2b3 |
+ ec->flags = flags;
|
|
Kmods SIG |
50e2b3 |
+}
|
|
Kmods SIG |
50e2b3 |
+
|
|
Kmods SIG |
50e2b3 |
+void exfat_chain_dup(struct exfat_chain *dup, struct exfat_chain *ec)
|
|
Kmods SIG |
50e2b3 |
+{
|
|
Kmods SIG |
50e2b3 |
+ return exfat_chain_set(dup, ec->dir, ec->size, ec->flags);
|
|
Kmods SIG |
50e2b3 |
+}
|
|
Kmods SIG |
50e2b3 |
--
|
|
Kmods SIG |
50e2b3 |
2.31.1
|
|
Kmods SIG |
50e2b3 |
|