/*
 *  Copyright (C) 2012-2013 Samsung Electronics Co., Ltd.
 *
 *  This program is free software; you can redistribute it and/or
 *  modify it under the terms of the GNU General Public License
 *  as published by the Free Software Foundation; either version 2
 *  of the License, or (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, see <http://www.gnu.org/licenses/>.
 */

/*
 *  linux/fs/fat/misc.c
 *
 *  Written 1992,1993 by Werner Almesberger
 *  22/11/2000 - Fixed fat_date_unix2dos for dates earlier than 01/01/1980
 *		 and date_dos2unix for date==0 by Igor Zhbanov(bsg@uniyar.ac.ru)
 */

/************************************************************************/
/*                                                                      */
/*  PROJECT : exFAT & FAT12/16/32 File System                           */
/*  FILE    : misc.c                                                    */
/*  PURPOSE : Helper function for checksum and handing sdFAT error      */
/*                                                                      */
/*----------------------------------------------------------------------*/
/*  NOTES                                                               */
/*                                                                      */
/*                                                                      */
/************************************************************************/

#include <linux/module.h>
#include <linux/fs.h>
#include <linux/buffer_head.h>
#include <linux/time.h>
#include <linux/blkdev.h>
#include "sdfat.h"
#include "version.h"


#ifdef CONFIG_SDFAT_SUPPORT_STLOG
#ifdef CONFIG_PROC_FSLOG
#include <linux/fslog.h>
#else
#include <linux/stlog.h>
#endif
#else
#define ST_LOG(fmt, ...)
#endif

#if LINUX_VERSION_CODE >= KERNEL_VERSION(5, 10, 0)
#include <linux/ktime.h>
#ifndef _TIME_T
#define _TIME_T
typedef ktime_t         time_t;
#endif
#endif

/*************************************************************************
 * FUNCTIONS WHICH HAS KERNEL VERSION DEPENDENCY
 *************************************************************************/
#ifdef CONFIG_SDFAT_UEVENT
static struct kobject sdfat_uevent_kobj;

int sdfat_uevent_init(struct kset *sdfat_kset)
{
	int err;
	struct kobj_type *ktype = get_ktype(&sdfat_kset->kobj);

	sdfat_uevent_kobj.kset = sdfat_kset;
	err = kobject_init_and_add(&sdfat_uevent_kobj, ktype, NULL, "uevent");
	if (err)
		pr_err("[SDFAT] Unable to create sdfat uevent kobj\n");

	return err;
}

void sdfat_uevent_uninit(void)
{
	kobject_del(&sdfat_uevent_kobj);
	memset(&sdfat_uevent_kobj, 0, sizeof(struct kobject));
}

void sdfat_uevent_ro_remount(struct super_block *sb)
{
	struct block_device *bdev = sb->s_bdev;
	dev_t bd_dev = bdev ? bdev->bd_dev : 0;
	
	char major[16], minor[16];
	char *envp[] = { major, minor, NULL };

	/* Do not trigger uevent if a device has been ejected */
	if (fsapi_check_bdi_valid(sb))
		return;

	snprintf(major, sizeof(major), "MAJOR=%d", MAJOR(bd_dev));
	snprintf(minor, sizeof(minor), "MINOR=%d", MINOR(bd_dev));

	kobject_uevent_env(&sdfat_uevent_kobj, KOBJ_CHANGE, envp);

	ST_LOG("[SDFAT](%s[%d:%d]): Uevent triggered\n",
			sb->s_id, MAJOR(bd_dev), MINOR(bd_dev));
}
#endif

/*
 * sdfat_fs_error reports a file system problem that might indicate fa data
 * corruption/inconsistency. Depending on 'errors' mount option the
 * panic() is called, or error message is printed FAT and nothing is done,
 * or filesystem is remounted read-only (default behavior).
 * In case the file system is remounted read-only, it can be made writable
 * again by remounting it.
 */
void __sdfat_fs_error(struct super_block *sb, int report, const char *fmt, ...)
{
	struct sdfat_mount_options *opts = &SDFAT_SB(sb)->options;
	va_list args;
	struct va_format vaf;
	struct block_device *bdev = sb->s_bdev;
	dev_t bd_dev = bdev ? bdev->bd_dev : 0;

	if (report) {
		va_start(args, fmt);
		vaf.fmt = fmt;
		vaf.va = &args;
		pr_err("[SDFAT](%s[%d:%d]):ERR: %pV\n",
			sb->s_id, MAJOR(bd_dev), MINOR(bd_dev), &vaf);
#ifdef CONFIG_SDFAT_SUPPORT_STLOG
		if (opts->errors == SDFAT_ERRORS_RO && !sb_rdonly(sb)) {
			ST_LOG("[SDFAT](%s[%d:%d]):ERR: %pV\n",
				sb->s_id, MAJOR(bd_dev), MINOR(bd_dev), &vaf);
		}
#endif
		va_end(args);
	}

	if (opts->errors == SDFAT_ERRORS_PANIC) {
		panic("[SDFAT](%s[%d:%d]): fs panic from previous error\n",
			sb->s_id, MAJOR(bd_dev), MINOR(bd_dev));
	} else if (opts->errors == SDFAT_ERRORS_RO && !sb_rdonly(sb)) {
		sb->s_flags |= SB_RDONLY;
		sdfat_statistics_set_mnt_ro();
		pr_err("[SDFAT](%s[%d:%d]): Filesystem has been set "
			"read-only\n", sb->s_id, MAJOR(bd_dev), MINOR(bd_dev));
#ifdef CONFIG_SDFAT_SUPPORT_STLOG
		ST_LOG("[SDFAT](%s[%d:%d]): Filesystem has been set read-only\n",
			sb->s_id, MAJOR(bd_dev), MINOR(bd_dev));
#endif
		sdfat_uevent_ro_remount(sb);
	}
}
EXPORT_SYMBOL(__sdfat_fs_error);

/**
 * __sdfat_msg() - print preformated SDFAT specific messages.
 * All logs except what uses sdfat_fs_error() should be written by __sdfat_msg()
 * If 'st' is set, the log is propagated to ST_LOG.
 */
void __sdfat_msg(struct super_block *sb, const char *level, int st, const char *fmt, ...)
{
	struct va_format vaf;
	va_list args;
	struct block_device *bdev = sb->s_bdev;
	dev_t bd_dev = bdev ? bdev->bd_dev : 0;

	va_start(args, fmt);
	vaf.fmt = fmt;
	vaf.va = &args;
	/* level means KERN_ pacility level */
	printk("%s[SDFAT](%s[%d:%d]): %pV\n", level,
			sb->s_id, MAJOR(bd_dev), MINOR(bd_dev), &vaf);
#ifdef CONFIG_SDFAT_SUPPORT_STLOG
	if (st) {
		ST_LOG("[SDFAT](%s[%d:%d]): %pV\n",
				sb->s_id, MAJOR(bd_dev), MINOR(bd_dev), &vaf);
	}
#endif
	va_end(args);
}
EXPORT_SYMBOL(__sdfat_msg);

void sdfat_log_version(void)
{
	pr_info("[SDFAT] Filesystem version %s\n", SDFAT_VERSION);
#ifdef CONFIG_SDFAT_SUPPORT_STLOG
	ST_LOG("[SDFAT] Filesystem version %s\n", SDFAT_VERSION);
#endif
}
EXPORT_SYMBOL(sdfat_log_version);

/* <linux/time.h> externs sys_tz
 * extern struct timezone sys_tz;
 */
#define UNIX_SECS_1980    315532800L

#if BITS_PER_LONG == 64
#define UNIX_SECS_2108    4354819200L
#endif

/* days between 1970/01/01 and 1980/01/01 (2 leap days) */
#define DAYS_DELTA_DECADE    (365 * 10 + 2)
/* 120 (2100 - 1980) isn't leap year */
#define NO_LEAP_YEAR_2100    (120)
#define IS_LEAP_YEAR(y)    (!((y) & 0x3) && (y) != NO_LEAP_YEAR_2100)

#define SECS_PER_MIN    (60)
#define SECS_PER_HOUR   (60 * SECS_PER_MIN)
#define SECS_PER_DAY    (24 * SECS_PER_HOUR)

/* do not use time_t directly to prevent compile errors on 32bit kernel */
#define time_do_div(ori, base)	\
({				\
	u64 __ori = ori;	\
	do_div(__ori, base);	\
	(time_t)__ori;		\
})

#define time_do_mod(ori, base)		\
({					\
	u64 __ori = ori;		\
	(time_t)do_div(__ori, base);	\
})

#define MAKE_LEAP_YEAR(leap_year, year)                         \
({								\
	/* 2100 isn't leap year */				\
	if (unlikely(year > NO_LEAP_YEAR_2100))			\
		leap_year = time_do_div((year + 3), 4) - 1;	\
	else							\
		leap_year = time_do_div((year + 3), 4);		\
})

/* Linear day numbers of the respective 1sts in non-leap years. */
static time_t accum_days_in_year[] = {
	/* Month : N 01  02  03  04  05  06  07  08  09  10  11  12 */
	0, 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334, 0, 0, 0,
};

#define TIMEZONE_SEC(x)	((x) * 15 * SECS_PER_MIN)
/* Convert a FAT time/date pair to a UNIX date (seconds since 1 1 70). */
void sdfat_time_fat2unix(struct sdfat_sb_info *sbi, sdfat_timespec_t *ts,
								DATE_TIME_T *tp)
{
	time_t year = tp->Year;
	time_t ld; /* leap day */

	MAKE_LEAP_YEAR(ld, year);

	if (IS_LEAP_YEAR(year) && (tp->Month) > 2)
		ld++;

	ts->tv_sec =  tp->Second  + tp->Minute * SECS_PER_MIN
			+ tp->Hour * SECS_PER_HOUR
			+ (year * 365 + ld + accum_days_in_year[tp->Month]
			+ (tp->Day - 1) + DAYS_DELTA_DECADE) * SECS_PER_DAY;

	ts->tv_nsec = 0;

	/* Treat as local time */
	if (!sbi->options.tz_utc && !tp->Timezone.valid) {
		ts->tv_sec += sys_tz.tz_minuteswest * SECS_PER_MIN;
		return;
	}

	/* Treat as UTC time */
	if (!tp->Timezone.valid)
		return;

	/* Treat as UTC time, but need to adjust timezone to UTC0 */
	if (tp->Timezone.off <= 0x3F)
		ts->tv_sec -= TIMEZONE_SEC(tp->Timezone.off);
	else /* 0x40 <= (tp->Timezone & 0x7F) <=0x7F */
		ts->tv_sec += TIMEZONE_SEC(0x80 - tp->Timezone.off);
}

#define TIMEZONE_CUR_OFFSET()	((sys_tz.tz_minuteswest / (-15)) & 0x7F)
/* Convert linear UNIX date to a FAT time/date pair. */
void sdfat_time_unix2fat(struct sdfat_sb_info *sbi, sdfat_timespec_t *ts,
								DATE_TIME_T *tp)
{
	bool tz_valid = (sbi->fsi.vol_type == EXFAT) ? true : false;
	time_t second = ts->tv_sec;
	time_t day, month, year;
	time_t ld; /* leap day */

	tp->Timezone.value = 0x00;

	/* Treats as local time with proper time */
	if (tz_valid || !sbi->options.tz_utc) {
		second -= sys_tz.tz_minuteswest * SECS_PER_MIN;
		if (tz_valid) {
			tp->Timezone.valid = 1;
			tp->Timezone.off = TIMEZONE_CUR_OFFSET();
		}
	}

	/* Jan 1 GMT 00:00:00 1980. But what about another time zone? */
	if (second < UNIX_SECS_1980) {
		tp->Second  = 0;
		tp->Minute  = 0;
		tp->Hour = 0;
		tp->Day  = 1;
		tp->Month  = 1;
		tp->Year = 0;
		return;
	}
#if (BITS_PER_LONG == 64)
	if (second >= UNIX_SECS_2108) {
		tp->Second  = 59;
		tp->Minute  = 59;
		tp->Hour = 23;
		tp->Day  = 31;
		tp->Month  = 12;
		tp->Year = 127;
		return;
	}
#endif

	day = time_do_div(second, SECS_PER_DAY) - DAYS_DELTA_DECADE;
	year = time_do_div(day, 365);

	MAKE_LEAP_YEAR(ld, year);
	if (year * 365 + ld > day)
		year--;

	MAKE_LEAP_YEAR(ld, year);
	day -= year * 365 + ld;

	if (IS_LEAP_YEAR(year) && day == accum_days_in_year[3]) {
		month = 2;
	} else {
		if (IS_LEAP_YEAR(year) && day > accum_days_in_year[3])
			day--;
		for (month = 1; month < 12; month++) {
			if (accum_days_in_year[month + 1] > day)
				break;
		}
	}
	day -= accum_days_in_year[month];

	tp->Second = (u16)time_do_mod(second, SECS_PER_MIN);
	tp->Minute = (u16)time_do_mod(time_do_div(second, SECS_PER_MIN), 60);
	tp->Hour = (u16)time_do_mod(time_do_div(second, SECS_PER_HOUR), 24);
	tp->Day  = (u16)(day + 1);
	tp->Month  = (u16)month;
	tp->Year = (u16)year;
}

TIMESTAMP_T *tm_now(struct inode *inode, TIMESTAMP_T *tp)
{
	sdfat_timespec_t ts = current_time(inode);
	DATE_TIME_T dt;

	sdfat_time_unix2fat(SDFAT_SB(inode->i_sb), &ts, &dt);

	tp->year = dt.Year;
	tp->mon = dt.Month;
	tp->day = dt.Day;
	tp->hour = dt.Hour;
	tp->min = dt.Minute;
	tp->sec = dt.Second;
	tp->tz.value = dt.Timezone.value;

	return tp;
}

u8 calc_chksum_1byte(void *data, s32 len, u8 chksum)
{
	s32 i;
	u8 *c = (u8 *) data;

	for (i = 0; i < len; i++, c++)
		chksum = (((chksum & 1) << 7) | ((chksum & 0xFE) >> 1)) + *c;

	return chksum;
}

u16 calc_chksum_2byte(void *data, s32 len, u16 chksum, s32 type)
{
	s32 i;
	u8 *c = (u8 *) data;

	for (i = 0; i < len; i++, c++) {
		if (((i == 2) || (i == 3)) && (type == CS_DIR_ENTRY))
			continue;
		chksum = (((chksum & 1) << 15) | ((chksum & 0xFFFE) >> 1)) + (u16) *c;
	}
	return chksum;
}

#ifdef CONFIG_SDFAT_TRACE_ELAPSED_TIME
struct timeval __t1, __t2;
u32 sdfat_time_current_usec(struct timeval *tv)
{
	do_gettimeofday(tv);
	return (u32)(tv->tv_sec*1000000 + tv->tv_usec);
}
#endif /* CONFIG_SDFAT_TRACE_ELAPSED_TIME */

#ifdef CONFIG_SDFAT_DBG_CAREFUL
/* Check the consistency of i_size_ondisk (FAT32, or flags 0x01 only) */
void sdfat_debug_check_clusters(struct inode *inode)
{
	unsigned int num_clusters;
	volatile uint32_t tmp_fat_chain[50];
	volatile int tmp_i = 0;
	volatile unsigned int num_clusters_org, tmp_i = 0;
	CHAIN_T clu;
	FILE_ID_T *fid = &(SDFAT_I(inode)->fid);
	FS_INFO_T *fsi = &(SDFAT_SB(inode->i_sb)->fsi);

	if (SDFAT_I(inode)->i_size_ondisk == 0)
		num_clusters = 0;
	else
		num_clusters = ((SDFAT_I(inode)->i_size_ondisk-1) >> fsi->cluster_size_bits) + 1;

	clu.dir = fid->start_clu;
	clu.size = num_clusters;
	clu.flags = fid->flags;

	num_clusters_org = num_clusters;

	if (clu.flags == 0x03)
		return;

	while (num_clusters > 0) {
		/* FAT chain logging */
		tmp_fat_chain[tmp_i] = clu.dir;
		tmp_i++;
		if (tmp_i >= 50)
			tmp_i = 0;

		BUG_ON(IS_CLUS_EOF(clu.dir) || IS_CLUS_FREE(clu.dir));

		if (get_next_clus_safe(inode->i_sb, &(clu.dir)))
			EMSG("%s: failed to access to FAT\n");

		num_clusters--;
	}

	BUG_ON(!IS_CLUS_EOF(clu.dir));
}

#endif /* CONFIG_SDFAT_DBG_CAREFUL */

#ifdef CONFIG_SDFAT_DBG_MSG
void __sdfat_dmsg(int level, const char *fmt, ...)
{
#ifdef CONFIG_SDFAT_DBG_SHOW_PID
	struct va_format vaf;
	va_list args;

	/* should check type */
	if (level > SDFAT_MSG_LEVEL)
		return;

	va_start(args, fmt);
	vaf.fmt = fmt;
	vaf.va = &args;
	/* fmt already includes KERN_ pacility level */
	printk("[%u] %pV", current->pid,  &vaf);
	va_end(args);
#else
	va_list args;

	/* should check type */
	if (level > SDFAT_MSG_LEVEL)
		return;

	va_start(args, fmt);
	/* fmt already includes KERN_ pacility level */
	vprintk(fmt, args);
	va_end(args);
#endif
}
#endif

