Re: [PATCH v18 01/10] fs/ntfs3: Add headers and misc files

2021-01-27 Thread Kari Argillander
On Fri, Jan 22, 2021 at 02:55:30PM +, Mark Harmstone wrote:
> On 22/1/21 2:01 pm, Konstantin Komarov wrote:
> > diff --git a/fs/ntfs3/upcase.c b/fs/ntfs3/upcase.c

> > +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];
> > +}
> 
> Shouldn't upcase_unicode_char be using the NTFS pseudo-file $UpCase?
> That way you should also be covered for other bicameral alphabets.

return upcase[chr] is just for that? Upcase table from $UpCase is constucted
in super.c and this will get it in and use it.


[PATCH v18 01/10] fs/ntfs3: Add headers and misc files

2021-01-22 Thread Konstantin Komarov
This adds headers and misc files

Signed-off-by: Konstantin Komarov 
---
 fs/ntfs3/debug.h   |   62 +++
 fs/ntfs3/ntfs.h| 1238 
 fs/ntfs3/ntfs_fs.h | 1056 +
 fs/ntfs3/upcase.c  |  100 
 4 files changed, 2456 insertions(+)
 create mode 100644 fs/ntfs3/debug.h
 create mode 100644 fs/ntfs3/ntfs.h
 create mode 100644 fs/ntfs3/ntfs_fs.h
 create mode 100644 fs/ntfs3/upcase.c

diff --git a/fs/ntfs3/debug.h b/fs/ntfs3/debug.h
new file mode 100644
index ..41893421081a
--- /dev/null
+++ b/fs/ntfs3/debug.h
@@ -0,0 +1,62 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ *
+ * Copyright (C) 2019-2020 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  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_free(p)   kfree(p)
+#define ntfs_memdup(src, len)  kmemdup(src, len, GFP_NOFS)
+// clang-format on
diff --git a/fs/ntfs3/ntfs.h b/fs/ntfs3/ntfs.h
new file mode 100644
index ..19aac05ff3d1
--- /dev/null
+++ b/fs/ntfs3/ntfs.h
@@ -0,0 +1,1238 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ *
+ * Copyright (C) 2019-2020 Paragon Software GmbH, All rights reserved.
+ *
+ * on-disk ntfs structs
+ */
+
+// clang-format off
+
+/* TODO:
+ * - Check 4K mft record and 512 bytes cluster
+ */
+
+/*
+ * Activate this define to use binary search in indexes
+ */
+#define NTFS3_INDEX_BINARY_SEARCH
+
+/*
+ * Check each run for marked clusters
+ */
+#define NTFS3_CHECK_FREE_CLST
+
+#define NTFS_NAME_LEN 255
+
+/*
+ * ntfs.sys used 500 maximum links
+ * on-disk struct allows up to 0x
+ */
+#define NTFS_LINK_MAX 0x400
+//#define NTFS_LINK_MAX 0x
+
+/*
+ * Activate to use 64 bit clusters instead of 32 bits in ntfs.sys
+ * Logical and virtual cluster number
+ * If needed, may be redefined to use 64 bit value
+ */
+//#define NTFS3_64BIT_CLUSTER
+
+#define NTFS_LZNT_MAX_CLUSTER  4096
+#define NTFS_LZNT_CUNIT4
+#define NTFS_LZNT_CLUSTERS (1uhigh) << 32);
+#else
+   return le32_to_cpu(ref->low);
+#endif
+}
+
+struct NTFS_BOOT {
+   u8 jump_code[3];// 0x00: Jump to boot code
+   u8 system_id[8];// 0x03: System ID, equals "NTFS"
+
+   // NOTE: this member is not aligned(!)
+   // bytes_per_sector[0] must be 0
+   // bytes_per_sector[1] must be multiplied by 256
+   u8 bytes_per_sector[2]; // 0x0B: Bytes per sector
+
+   u8 sectors_per_clusters;// 0x0D: Sectors per cluster
+   u8 unused1[7];
+   u8 media_type;  // 0x15: Media type (0xF8 - harddisk)
+   u8 unused2[2];
+   __le16 sct_per_track;   // 0x18: number of sectors per track
+   __le16 heads;   // 0x1A: number of heads per cylinder
+   __le32 hidden_sectors;  // 0x1C: number of 'hidden' sectors
+   u8 unused3[4];
+   u8 bios_drive_num;  // 0x24: BIOS drive number =0x80
+   u8 unused4;
+   u8 signature_ex;// 0x26: Extended BOOT 

Re: [PATCH v18 01/10] fs/ntfs3: Add headers and misc files

2021-01-22 Thread Mark Harmstone
Hi Konstantin,

Shouldn't upcase_unicode_char be using the NTFS pseudo-file $UpCase? That way 
you should also be covered for other bicameral alphabets.

Mark

On 22/1/21 2:01 pm, Konstantin Komarov wrote:
> This adds headers and misc files
>
> Signed-off-by: Konstantin Komarov 
> ---
>  fs/ntfs3/debug.h   |   62 +++
>  fs/ntfs3/ntfs.h| 1238 
>  fs/ntfs3/ntfs_fs.h | 1056 +
>  fs/ntfs3/upcase.c  |  100 
>  4 files changed, 2456 insertions(+)
>  create mode 100644 fs/ntfs3/debug.h
>  create mode 100644 fs/ntfs3/ntfs.h
>  create mode 100644 fs/ntfs3/ntfs_fs.h
>  create mode 100644 fs/ntfs3/upcase.c
>
> diff --git a/fs/ntfs3/debug.h b/fs/ntfs3/debug.h
> new file mode 100644
> index ..41893421081a
> --- /dev/null
> +++ b/fs/ntfs3/debug.h
> @@ -0,0 +1,62 @@
> +/* SPDX-License-Identifier: GPL-2.0 */
> +/*
> + *
> + * Copyright (C) 2019-2020 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  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_free(p) kfree(p)
> +#define ntfs_memdup(src, len)kmemdup(src, len, GFP_NOFS)
> +// clang-format on
> diff --git a/fs/ntfs3/ntfs.h b/fs/ntfs3/ntfs.h
> new file mode 100644
> index ..19aac05ff3d1
> --- /dev/null
> +++ b/fs/ntfs3/ntfs.h
> @@ -0,0 +1,1238 @@
> +/* SPDX-License-Identifier: GPL-2.0 */
> +/*
> + *
> + * Copyright (C) 2019-2020 Paragon Software GmbH, All rights reserved.
> + *
> + * on-disk ntfs structs
> + */
> +
> +// clang-format off
> +
> +/* TODO:
> + * - Check 4K mft record and 512 bytes cluster
> + */
> +
> +/*
> + * Activate this define to use binary search in indexes
> + */
> +#define NTFS3_INDEX_BINARY_SEARCH
> +
> +/*
> + * Check each run for marked clusters
> + */
> +#define NTFS3_CHECK_FREE_CLST
> +
> +#define NTFS_NAME_LEN 255
> +
> +/*
> + * ntfs.sys used 500 maximum links
> + * on-disk struct allows up to 0x
> + */
> +#define NTFS_LINK_MAX 0x400
> +//#define NTFS_LINK_MAX 0x
> +
> +/*
> + * Activate to use 64 bit clusters instead of 32 bits in ntfs.sys
> + * Logical and virtual cluster number
> + * If needed, may be redefined to use 64 bit value
> + */
> +//#define NTFS3_64BIT_CLUSTER
> +
> +#define NTFS_LZNT_MAX_CLUSTER4096
> +#define NTFS_LZNT_CUNIT  4
> +#define NTFS_LZNT_CLUSTERS   (1u< +
> +struct GUID {
> + __le32 Data1;
> + __le16 Data2;
> + __le16 Data3;
> + u8 Data4[8];
> +};
> +
> +/*
> + * this struct repeats layout of ATTR_FILE_NAME
> + * at offset 0x40
> + * it used to store global constants NAME_MFT/NAME_MIRROR...
> + * most constant names are shorter than 10
> + */
> +struct cpu_str {
> + u8 len;
> + u8 unused;
> + u16 name[10];
> +};
> +
> +struct le_str {
> + u8 len;
> + u8 unused;
> + __le16 name[1];
> +};
> +
>