Commit 4534a70b authored by Konstantin Komarov's avatar Konstantin Komarov

fs/ntfs3: Add headers and misc files

This adds headers and misc files
Signed-off-by: default avatarKonstantin Komarov <almaz.alexandrovich@paragon-software.com>
parent 36a21d51
/* SPDX-License-Identifier: GPL-2.0 */
/*
*
* Copyright (C) 2019-2021 Paragon Software GmbH, All rights reserved.
*
* useful functions for debuging
*/
// clang-format off
#ifndef Add2Ptr
#define Add2Ptr(P, I) ((void *)((u8 *)(P) + (I)))
#define PtrOffset(B, O) ((size_t)((size_t)(O) - (size_t)(B)))
#endif
#define QuadAlign(n) (((n) + 7u) & (~7u))
#define IsQuadAligned(n) (!((size_t)(n)&7u))
#define Quad2Align(n) (((n) + 15u) & (~15u))
#define IsQuad2Aligned(n) (!((size_t)(n)&15u))
#define Quad4Align(n) (((n) + 31u) & (~31u))
#define IsSizeTAligned(n) (!((size_t)(n) & (sizeof(size_t) - 1)))
#define DwordAlign(n) (((n) + 3u) & (~3u))
#define IsDwordAligned(n) (!((size_t)(n)&3u))
#define WordAlign(n) (((n) + 1u) & (~1u))
#define IsWordAligned(n) (!((size_t)(n)&1u))
#ifdef CONFIG_PRINTK
__printf(2, 3)
void ntfs_printk(const struct super_block *sb, const char *fmt, ...);
__printf(2, 3)
void ntfs_inode_printk(struct inode *inode, const char *fmt, ...);
#else
static inline __printf(2, 3)
void ntfs_printk(const struct super_block *sb, const char *fmt, ...)
{
}
static inline __printf(2, 3)
void ntfs_inode_printk(struct inode *inode, const char *fmt, ...)
{
}
#endif
/*
* Logging macros ( thanks Joe Perches <joe@perches.com> for implementation )
*/
#define ntfs_err(sb, fmt, ...) ntfs_printk(sb, KERN_ERR fmt, ##__VA_ARGS__)
#define ntfs_warn(sb, fmt, ...) ntfs_printk(sb, KERN_WARNING fmt, ##__VA_ARGS__)
#define ntfs_info(sb, fmt, ...) ntfs_printk(sb, KERN_INFO fmt, ##__VA_ARGS__)
#define ntfs_notice(sb, fmt, ...) \
ntfs_printk(sb, KERN_NOTICE fmt, ##__VA_ARGS__)
#define ntfs_inode_err(inode, fmt, ...) \
ntfs_inode_printk(inode, KERN_ERR fmt, ##__VA_ARGS__)
#define ntfs_inode_warn(inode, fmt, ...) \
ntfs_inode_printk(inode, KERN_WARNING fmt, ##__VA_ARGS__)
#define ntfs_malloc(s) kmalloc(s, GFP_NOFS)
#define ntfs_zalloc(s) kzalloc(s, GFP_NOFS)
#define ntfs_vmalloc(s) kvmalloc(s, GFP_KERNEL)
#define ntfs_free(p) kfree(p)
#define ntfs_vfree(p) kvfree(p)
#define ntfs_memdup(src, len) kmemdup(src, len, GFP_NOFS)
// clang-format on
This diff is collapsed.
This diff is collapsed.
// SPDX-License-Identifier: GPL-2.0
/*
*
* Copyright (C) 2019-2021 Paragon Software GmbH, All rights reserved.
*
*/
#include <linux/blkdev.h>
#include <linux/buffer_head.h>
#include <linux/module.h>
#include <linux/nls.h>
#include "debug.h"
#include "ntfs.h"
#include "ntfs_fs.h"
static inline u16 upcase_unicode_char(const u16 *upcase, u16 chr)
{
if (chr < 'a')
return chr;
if (chr <= 'z')
return chr - ('a' - 'A');
return upcase[chr];
}
/*
* Thanks Kari Argillander <kari.argillander@gmail.com> for idea and implementation 'bothcase'
*
* Straigth way to compare names:
* - case insensitive
* - if name equals and 'bothcases' then
* - case sensitive
* 'Straigth way' code scans input names twice in worst case
* Optimized code scans input names only once
*/
int ntfs_cmp_names(const __le16 *s1, size_t l1, const __le16 *s2, size_t l2,
const u16 *upcase, bool bothcase)
{
int diff1 = 0;
int diff2;
size_t len = min(l1, l2);
if (!bothcase && upcase)
goto case_insentive;
for (; len; s1++, s2++, len--) {
diff1 = le16_to_cpu(*s1) - le16_to_cpu(*s2);
if (diff1) {
if (bothcase && upcase)
goto case_insentive;
return diff1;
}
}
return l1 - l2;
case_insentive:
for (; len; s1++, s2++, len--) {
diff2 = upcase_unicode_char(upcase, le16_to_cpu(*s1)) -
upcase_unicode_char(upcase, le16_to_cpu(*s2));
if (diff2)
return diff2;
}
diff2 = l1 - l2;
return diff2 ? diff2 : diff1;
}
int ntfs_cmp_names_cpu(const struct cpu_str *uni1, const struct le_str *uni2,
const u16 *upcase, bool bothcase)
{
const u16 *s1 = uni1->name;
const __le16 *s2 = uni2->name;
size_t l1 = uni1->len;
size_t l2 = uni2->len;
size_t len = min(l1, l2);
int diff1 = 0;
int diff2;
if (!bothcase && upcase)
goto case_insentive;
for (; len; s1++, s2++, len--) {
diff1 = *s1 - le16_to_cpu(*s2);
if (diff1) {
if (bothcase && upcase)
goto case_insentive;
return diff1;
}
}
return l1 - l2;
case_insentive:
for (; len; s1++, s2++, len--) {
diff2 = upcase_unicode_char(upcase, *s1) -
upcase_unicode_char(upcase, le16_to_cpu(*s2));
if (diff2)
return diff2;
}
diff2 = l1 - l2;
return diff2 ? diff2 : diff1;
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment