Commit fa3cacf5 authored by Kari Argillander's avatar Kari Argillander Committed by Konstantin Komarov

fs/ntfs3: Use kernel ALIGN macros over driver specific

The static checkers (Smatch) were complaining because QuadAlign() was
buggy.  If you try to align something higher than UINT_MAX it got
truncated to a u32.

Smatch warning was:
	fs/ntfs3/attrib.c:383 attr_set_size_res()
	warn: was expecting a 64 bit value instead of '~7'

So that this will not happen again we will change all these macros to
kernel made ones. This can also help some other static analyzing tools
to give us better warnings.

Patch was generated with Coccinelle script and after that some style
issue was hand fixed.

Coccinelle script:

virtual patch

@alloc depends on patch@
expression x;
@@
(
-	#define QuadAlign(n)		(((n) + 7u) & (~7u))
|
-	QuadAlign(x)
+	ALIGN(x, 8)
|
-	#define IsQuadAligned(n)	(!((size_t)(n)&7u))
|
-	IsQuadAligned(x)
+	IS_ALIGNED(x, 8)
|
-	#define Quad2Align(n)		(((n) + 15u) & (~15u))
|
-	Quad2Align(x)
+	ALIGN(x, 16)
|
-	#define IsQuad2Aligned(n)	(!((size_t)(n)&15u))
|
-	IsQuad2Aligned(x)
+	IS_ALIGNED(x, 16)
|
-	#define Quad4Align(n)		(((n) + 31u) & (~31u))
|
-	Quad4Align(x)
+	ALIGN(x, 32)
|
-	#define IsSizeTAligned(n)	(!((size_t)(n) & (sizeof(size_t) - 1)))
|
-	IsSizeTAligned(x)
+	IS_ALIGNED(x, sizeof(size_t))
|
-	#define DwordAlign(n)		(((n) + 3u) & (~3u))
|
-	DwordAlign(x)
+	ALIGN(x, 4)
|
-	#define IsDwordAligned(n)	(!((size_t)(n)&3u))
|
-	IsDwordAligned(x)
+	IS_ALIGNED(x, 4)
|
-	#define WordAlign(n)		(((n) + 1u) & (~1u))
|
-	WordAlign(x)
+	ALIGN(x, 2)
|
-	#define IsWordAligned(n)	(!((size_t)(n)&1u))
|
-	IsWordAligned(x)
+	IS_ALIGNED(x, 2)
|
)
Reported-by: default avatarDan Carpenter <dan.carpenter@oracle.com>
Signed-off-by: default avatarKari Argillander <kari.argillander@gmail.com>
Signed-off-by: default avatarKonstantin Komarov <almaz.alexandrovich@paragon-software.com>
parent 24516d48
...@@ -380,7 +380,7 @@ static int attr_set_size_res(struct ntfs_inode *ni, struct ATTRIB *attr, ...@@ -380,7 +380,7 @@ static int attr_set_size_res(struct ntfs_inode *ni, struct ATTRIB *attr,
u32 rsize = le32_to_cpu(attr->res.data_size); u32 rsize = le32_to_cpu(attr->res.data_size);
u32 tail = used - aoff - asize; u32 tail = used - aoff - asize;
char *next = Add2Ptr(attr, asize); char *next = Add2Ptr(attr, asize);
s64 dsize = QuadAlign(new_size) - QuadAlign(rsize); s64 dsize = ALIGN(new_size, 8) - ALIGN(rsize, 8);
if (dsize < 0) { if (dsize < 0) {
memmove(next + dsize, next, tail); memmove(next + dsize, next, tail);
......
...@@ -15,17 +15,6 @@ ...@@ -15,17 +15,6 @@
#define PtrOffset(B, O) ((size_t)((size_t)(O) - (size_t)(B))) #define PtrOffset(B, O) ((size_t)((size_t)(O) - (size_t)(B)))
#endif #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 #ifdef CONFIG_PRINTK
__printf(2, 3) __printf(2, 3)
void ntfs_printk(const struct super_block *sb, const char *fmt, ...); void ntfs_printk(const struct super_block *sb, const char *fmt, ...);
......
...@@ -1249,7 +1249,7 @@ static int ni_expand_mft_list(struct ntfs_inode *ni) ...@@ -1249,7 +1249,7 @@ static int ni_expand_mft_list(struct ntfs_inode *ni)
if (err < 0) if (err < 0)
goto out; goto out;
run_size = QuadAlign(err); run_size = ALIGN(err, 8);
err = 0; err = 0;
if (plen < svcn) { if (plen < svcn) {
...@@ -1269,7 +1269,7 @@ static int ni_expand_mft_list(struct ntfs_inode *ni) ...@@ -1269,7 +1269,7 @@ static int ni_expand_mft_list(struct ntfs_inode *ni)
if (err < 0) if (err < 0)
goto out; goto out;
run_size = QuadAlign(err); run_size = ALIGN(err, 8);
err = 0; err = 0;
if (plen < evcn + 1 - svcn) { if (plen < evcn + 1 - svcn) {
...@@ -1392,7 +1392,7 @@ int ni_insert_nonresident(struct ntfs_inode *ni, enum ATTR_TYPE type, ...@@ -1392,7 +1392,7 @@ int ni_insert_nonresident(struct ntfs_inode *ni, enum ATTR_TYPE type,
struct ATTRIB *attr; struct ATTRIB *attr;
bool is_ext = bool is_ext =
(flags & (ATTR_FLAG_SPARSED | ATTR_FLAG_COMPRESSED)) && !svcn; (flags & (ATTR_FLAG_SPARSED | ATTR_FLAG_COMPRESSED)) && !svcn;
u32 name_size = QuadAlign(name_len * sizeof(short)); u32 name_size = ALIGN(name_len * sizeof(short), 8);
u32 name_off = is_ext ? SIZEOF_NONRESIDENT_EX : SIZEOF_NONRESIDENT; u32 name_off = is_ext ? SIZEOF_NONRESIDENT_EX : SIZEOF_NONRESIDENT;
u32 run_off = name_off + name_size; u32 run_off = name_off + name_size;
u32 run_size, asize; u32 run_size, asize;
...@@ -1403,7 +1403,7 @@ int ni_insert_nonresident(struct ntfs_inode *ni, enum ATTR_TYPE type, ...@@ -1403,7 +1403,7 @@ int ni_insert_nonresident(struct ntfs_inode *ni, enum ATTR_TYPE type,
if (err < 0) if (err < 0)
goto out; goto out;
run_size = QuadAlign(err); run_size = ALIGN(err, 8);
if (plen < len) { if (plen < len) {
err = -EINVAL; err = -EINVAL;
...@@ -1463,8 +1463,8 @@ int ni_insert_resident(struct ntfs_inode *ni, u32 data_size, ...@@ -1463,8 +1463,8 @@ int ni_insert_resident(struct ntfs_inode *ni, u32 data_size,
struct ATTRIB **new_attr, struct mft_inode **mi) struct ATTRIB **new_attr, struct mft_inode **mi)
{ {
int err; int err;
u32 name_size = QuadAlign(name_len * sizeof(short)); u32 name_size = ALIGN(name_len * sizeof(short), 8);
u32 asize = SIZEOF_RESIDENT + name_size + QuadAlign(data_size); u32 asize = SIZEOF_RESIDENT + name_size + ALIGN(data_size, 8);
struct ATTRIB *attr; struct ATTRIB *attr;
err = ni_insert_attr(ni, type, name, name_len, asize, SIZEOF_RESIDENT, err = ni_insert_attr(ni, type, name, name_len, asize, SIZEOF_RESIDENT,
...@@ -2853,7 +2853,7 @@ static bool ni_update_parent(struct ntfs_inode *ni, struct NTFS_DUP_INFO *dup, ...@@ -2853,7 +2853,7 @@ static bool ni_update_parent(struct ntfs_inode *ni, struct NTFS_DUP_INFO *dup,
} else if (!attr->non_res) { } else if (!attr->non_res) {
u32 data_size = le32_to_cpu(attr->res.data_size); u32 data_size = le32_to_cpu(attr->res.data_size);
dup->alloc_size = cpu_to_le64(QuadAlign(data_size)); dup->alloc_size = cpu_to_le64(ALIGN(data_size, 8));
dup->data_size = cpu_to_le64(data_size); dup->data_size = cpu_to_le64(data_size);
} else { } else {
u64 new_valid = ni->i_valid; u64 new_valid = ni->i_valid;
......
...@@ -456,7 +456,7 @@ static inline bool is_rst_page_hdr_valid(u32 file_off, ...@@ -456,7 +456,7 @@ static inline bool is_rst_page_hdr_valid(u32 file_off,
return false; return false;
ro = le16_to_cpu(rhdr->ra_off); ro = le16_to_cpu(rhdr->ra_off);
if (!IsQuadAligned(ro) || ro > sys_page) if (!IS_ALIGNED(ro, 8) || ro > sys_page)
return false; return false;
end_usa = ((sys_page >> SECTOR_SHIFT) + 1) * sizeof(short); end_usa = ((sys_page >> SECTOR_SHIFT) + 1) * sizeof(short);
...@@ -488,7 +488,7 @@ static inline bool is_rst_area_valid(const struct RESTART_HDR *rhdr) ...@@ -488,7 +488,7 @@ static inline bool is_rst_area_valid(const struct RESTART_HDR *rhdr)
off = le16_to_cpu(ra->client_off); off = le16_to_cpu(ra->client_off);
if (!IsQuadAligned(off) || ro + off > SECTOR_SIZE - sizeof(short)) if (!IS_ALIGNED(off, 8) || ro + off > SECTOR_SIZE - sizeof(short))
return false; return false;
off += cl * sizeof(struct CLIENT_REC); off += cl * sizeof(struct CLIENT_REC);
...@@ -526,8 +526,8 @@ static inline bool is_rst_area_valid(const struct RESTART_HDR *rhdr) ...@@ -526,8 +526,8 @@ static inline bool is_rst_area_valid(const struct RESTART_HDR *rhdr)
} }
/* The log page data offset and record header length must be quad-aligned */ /* The log page data offset and record header length must be quad-aligned */
if (!IsQuadAligned(le16_to_cpu(ra->data_off)) || if (!IS_ALIGNED(le16_to_cpu(ra->data_off), 8) ||
!IsQuadAligned(le16_to_cpu(ra->rec_hdr_len))) !IS_ALIGNED(le16_to_cpu(ra->rec_hdr_len), 8))
return false; return false;
return true; return true;
...@@ -1355,9 +1355,9 @@ static void log_create(struct ntfs_log *log, u32 l_size, const u64 last_lsn, ...@@ -1355,9 +1355,9 @@ static void log_create(struct ntfs_log *log, u32 l_size, const u64 last_lsn,
log->l_flags |= NTFSLOG_MULTIPLE_PAGE_IO; log->l_flags |= NTFSLOG_MULTIPLE_PAGE_IO;
/* Compute the log page values */ /* Compute the log page values */
log->data_off = QuadAlign( log->data_off = ALIGN(
offsetof(struct RECORD_PAGE_HDR, fixups) + offsetof(struct RECORD_PAGE_HDR, fixups) +
sizeof(short) * ((log->page_size >> SECTOR_SHIFT) + 1)); sizeof(short) * ((log->page_size >> SECTOR_SHIFT) + 1), 8);
log->data_size = log->page_size - log->data_off; log->data_size = log->page_size - log->data_off;
log->record_header_len = sizeof(struct LFS_RECORD_HDR); log->record_header_len = sizeof(struct LFS_RECORD_HDR);
...@@ -1365,9 +1365,9 @@ static void log_create(struct ntfs_log *log, u32 l_size, const u64 last_lsn, ...@@ -1365,9 +1365,9 @@ static void log_create(struct ntfs_log *log, u32 l_size, const u64 last_lsn,
log->reserved = log->data_size - log->record_header_len; log->reserved = log->data_size - log->record_header_len;
/* Compute the restart page values. */ /* Compute the restart page values. */
log->ra_off = QuadAlign( log->ra_off = ALIGN(
offsetof(struct RESTART_HDR, fixups) + offsetof(struct RESTART_HDR, fixups) +
sizeof(short) * ((log->sys_page_size >> SECTOR_SHIFT) + 1)); sizeof(short) * ((log->sys_page_size >> SECTOR_SHIFT) + 1), 8);
log->restart_size = log->sys_page_size - log->ra_off; log->restart_size = log->sys_page_size - log->ra_off;
log->ra_size = struct_size(log->ra, clients, 1); log->ra_size = struct_size(log->ra, clients, 1);
log->current_openlog_count = open_log_count; log->current_openlog_count = open_log_count;
...@@ -1496,7 +1496,7 @@ static int next_log_lsn(struct ntfs_log *log, const struct LFS_RECORD_HDR *rh, ...@@ -1496,7 +1496,7 @@ static int next_log_lsn(struct ntfs_log *log, const struct LFS_RECORD_HDR *rh,
vbo = hdr_off + log->data_off; vbo = hdr_off + log->data_off;
} else { } else {
vbo = QuadAlign(end); vbo = ALIGN(end, 8);
} }
/* Compute the lsn based on the file offset and the sequence count */ /* Compute the lsn based on the file offset and the sequence count */
...@@ -2982,7 +2982,7 @@ static struct ATTRIB *attr_create_nonres_log(struct ntfs_sb_info *sbi, ...@@ -2982,7 +2982,7 @@ static struct ATTRIB *attr_create_nonres_log(struct ntfs_sb_info *sbi,
__le16 flags) __le16 flags)
{ {
struct ATTRIB *attr; struct ATTRIB *attr;
u32 name_size = QuadAlign(name_len * sizeof(short)); u32 name_size = ALIGN(name_len * sizeof(short), 8);
bool is_ext = flags & (ATTR_FLAG_COMPRESSED | ATTR_FLAG_SPARSED); bool is_ext = flags & (ATTR_FLAG_COMPRESSED | ATTR_FLAG_SPARSED);
u32 asize = name_size + u32 asize = name_size +
(is_ext ? SIZEOF_NONRESIDENT_EX : SIZEOF_NONRESIDENT); (is_ext ? SIZEOF_NONRESIDENT_EX : SIZEOF_NONRESIDENT);
...@@ -3220,7 +3220,7 @@ static int do_action(struct ntfs_log *log, struct OPEN_ATTR_ENRTY *oe, ...@@ -3220,7 +3220,7 @@ static int do_action(struct ntfs_log *log, struct OPEN_ATTR_ENRTY *oe,
goto dirty_vol; goto dirty_vol;
memmove(attr, attr2, dlen); memmove(attr, attr2, dlen);
rec->used = cpu_to_le32(QuadAlign(roff + dlen)); rec->used = cpu_to_le32(ALIGN(roff + dlen, 8));
mi->dirty = true; mi->dirty = true;
break; break;
...@@ -3231,7 +3231,7 @@ static int do_action(struct ntfs_log *log, struct OPEN_ATTR_ENRTY *oe, ...@@ -3231,7 +3231,7 @@ static int do_action(struct ntfs_log *log, struct OPEN_ATTR_ENRTY *oe,
used = le32_to_cpu(rec->used); used = le32_to_cpu(rec->used);
if (!check_if_attr(rec, lrh) || dlen < SIZEOF_RESIDENT || if (!check_if_attr(rec, lrh) || dlen < SIZEOF_RESIDENT ||
!IsQuadAligned(asize) || !IS_ALIGNED(asize, 8) ||
Add2Ptr(attr2, asize) > Add2Ptr(lrh, rec_len) || Add2Ptr(attr2, asize) > Add2Ptr(lrh, rec_len) ||
dlen > record_size - used) { dlen > record_size - used) {
goto dirty_vol; goto dirty_vol;
...@@ -3296,7 +3296,7 @@ static int do_action(struct ntfs_log *log, struct OPEN_ATTR_ENRTY *oe, ...@@ -3296,7 +3296,7 @@ static int do_action(struct ntfs_log *log, struct OPEN_ATTR_ENRTY *oe,
if (nsize > asize && nsize - asize > record_size - used) if (nsize > asize && nsize - asize > record_size - used)
goto dirty_vol; goto dirty_vol;
nsize = QuadAlign(nsize); nsize = ALIGN(nsize, 8);
data_off = le16_to_cpu(attr->res.data_off); data_off = le16_to_cpu(attr->res.data_off);
if (nsize < asize) { if (nsize < asize) {
...@@ -3341,7 +3341,7 @@ static int do_action(struct ntfs_log *log, struct OPEN_ATTR_ENRTY *oe, ...@@ -3341,7 +3341,7 @@ static int do_action(struct ntfs_log *log, struct OPEN_ATTR_ENRTY *oe,
goto dirty_vol; goto dirty_vol;
} }
nsize = QuadAlign(nsize); nsize = ALIGN(nsize, 8);
memmove(Add2Ptr(attr, nsize), Add2Ptr(attr, asize), memmove(Add2Ptr(attr, nsize), Add2Ptr(attr, asize),
used - le16_to_cpu(lrh->record_off) - asize); used - le16_to_cpu(lrh->record_off) - asize);
...@@ -5103,8 +5103,8 @@ int log_replay(struct ntfs_inode *ni, bool *initialized) ...@@ -5103,8 +5103,8 @@ int log_replay(struct ntfs_inode *ni, bool *initialized)
rh->sys_page_size = cpu_to_le32(log->page_size); rh->sys_page_size = cpu_to_le32(log->page_size);
rh->page_size = cpu_to_le32(log->page_size); rh->page_size = cpu_to_le32(log->page_size);
t16 = QuadAlign(offsetof(struct RESTART_HDR, fixups) + t16 = ALIGN(offsetof(struct RESTART_HDR, fixups) +
sizeof(short) * t16); sizeof(short) * t16, 8);
rh->ra_off = cpu_to_le16(t16); rh->ra_off = cpu_to_le16(t16);
rh->minor_ver = cpu_to_le16(1); // 0x1A: rh->minor_ver = cpu_to_le16(1); // 0x1A:
rh->major_ver = cpu_to_le16(1); // 0x1C: rh->major_ver = cpu_to_le16(1); // 0x1C:
......
...@@ -1944,7 +1944,7 @@ int ntfs_security_init(struct ntfs_sb_info *sbi) ...@@ -1944,7 +1944,7 @@ int ntfs_security_init(struct ntfs_sb_info *sbi)
sbi->security.next_id = SECURITY_ID_FIRST; sbi->security.next_id = SECURITY_ID_FIRST;
/* Always write new security at the end of bucket */ /* Always write new security at the end of bucket */
sbi->security.next_off = sbi->security.next_off =
Quad2Align(sds_size - SecurityDescriptorsBlockSize); ALIGN(sds_size - SecurityDescriptorsBlockSize, 16);
off = 0; off = 0;
ne = NULL; ne = NULL;
...@@ -2096,7 +2096,7 @@ int ntfs_insert_security(struct ntfs_sb_info *sbi, ...@@ -2096,7 +2096,7 @@ int ntfs_insert_security(struct ntfs_sb_info *sbi,
struct NTFS_DE_SII sii_e; struct NTFS_DE_SII sii_e;
struct SECURITY_HDR *d_security; struct SECURITY_HDR *d_security;
u32 new_sec_size = size_sd + SIZEOF_SECURITY_HDR; u32 new_sec_size = size_sd + SIZEOF_SECURITY_HDR;
u32 aligned_sec_size = Quad2Align(new_sec_size); u32 aligned_sec_size = ALIGN(new_sec_size, 16);
struct SECURITY_KEY hash_key; struct SECURITY_KEY hash_key;
struct ntfs_fnd *fnd_sdh = NULL; struct ntfs_fnd *fnd_sdh = NULL;
const struct INDEX_ROOT *root_sdh; const struct INDEX_ROOT *root_sdh;
......
...@@ -702,7 +702,7 @@ static struct NTFS_DE *hdr_find_e(const struct ntfs_index *indx, ...@@ -702,7 +702,7 @@ static struct NTFS_DE *hdr_find_e(const struct ntfs_index *indx,
if (max_idx >= nslots) { if (max_idx >= nslots) {
u16 *ptr; u16 *ptr;
int new_slots = QuadAlign(2 * nslots); int new_slots = ALIGN(2 * nslots, 8);
ptr = ntfs_malloc(sizeof(u16) * new_slots); ptr = ntfs_malloc(sizeof(u16) * new_slots);
if (ptr) if (ptr)
...@@ -959,7 +959,7 @@ static struct indx_node *indx_new(struct ntfs_index *indx, ...@@ -959,7 +959,7 @@ static struct indx_node *indx_new(struct ntfs_index *indx,
index->rhdr.fix_num = cpu_to_le16(fn); index->rhdr.fix_num = cpu_to_le16(fn);
index->vbn = cpu_to_le64(vbn); index->vbn = cpu_to_le64(vbn);
hdr = &index->ihdr; hdr = &index->ihdr;
eo = QuadAlign(sizeof(struct INDEX_BUFFER) + fn * sizeof(short)); eo = ALIGN(sizeof(struct INDEX_BUFFER) + fn * sizeof(short), 8);
hdr->de_off = cpu_to_le32(eo); hdr->de_off = cpu_to_le32(eo);
e = Add2Ptr(hdr, eo); e = Add2Ptr(hdr, eo);
......
...@@ -1335,7 +1335,7 @@ struct inode *ntfs_create_inode(struct user_namespace *mnt_userns, ...@@ -1335,7 +1335,7 @@ struct inode *ntfs_create_inode(struct user_namespace *mnt_userns,
fname->dup.ea_size = fname->dup.reparse = 0; fname->dup.ea_size = fname->dup.reparse = 0;
dsize = le16_to_cpu(new_de->key_size); dsize = le16_to_cpu(new_de->key_size);
asize = QuadAlign(SIZEOF_RESIDENT + dsize); asize = ALIGN(SIZEOF_RESIDENT + dsize, 8);
attr->type = ATTR_NAME; attr->type = ATTR_NAME;
attr->size = cpu_to_le32(asize); attr->size = cpu_to_le32(asize);
...@@ -1349,7 +1349,7 @@ struct inode *ntfs_create_inode(struct user_namespace *mnt_userns, ...@@ -1349,7 +1349,7 @@ struct inode *ntfs_create_inode(struct user_namespace *mnt_userns,
if (security_id == SECURITY_ID_INVALID) { if (security_id == SECURITY_ID_INVALID) {
/* Insert security attribute */ /* Insert security attribute */
asize = SIZEOF_RESIDENT + QuadAlign(sd_size); asize = SIZEOF_RESIDENT + ALIGN(sd_size, 8);
attr->type = ATTR_SECURE; attr->type = ATTR_SECURE;
attr->size = cpu_to_le32(asize); attr->size = cpu_to_le32(asize);
...@@ -1472,7 +1472,7 @@ struct inode *ntfs_create_inode(struct user_namespace *mnt_userns, ...@@ -1472,7 +1472,7 @@ struct inode *ntfs_create_inode(struct user_namespace *mnt_userns,
attr->id = cpu_to_le16(aid++); attr->id = cpu_to_le16(aid++);
/* resident or non resident? */ /* resident or non resident? */
asize = QuadAlign(SIZEOF_RESIDENT + nsize); asize = ALIGN(SIZEOF_RESIDENT + nsize, 8);
t16 = PtrOffset(rec, attr); t16 = PtrOffset(rec, attr);
if (asize + t16 + 8 > sbi->record_size) { if (asize + t16 + 8 > sbi->record_size) {
...@@ -1508,7 +1508,7 @@ struct inode *ntfs_create_inode(struct user_namespace *mnt_userns, ...@@ -1508,7 +1508,7 @@ struct inode *ntfs_create_inode(struct user_namespace *mnt_userns,
goto out5; goto out5;
} }
asize = SIZEOF_NONRESIDENT + QuadAlign(err); asize = SIZEOF_NONRESIDENT + ALIGN(err, 8);
inode->i_size = nsize; inode->i_size = nsize;
} else { } else {
attr->res.data_off = SIZEOF_RESIDENT_LE; attr->res.data_off = SIZEOF_RESIDENT_LE;
......
...@@ -57,7 +57,7 @@ int fill_name_de(struct ntfs_sb_info *sbi, void *buf, const struct qstr *name, ...@@ -57,7 +57,7 @@ int fill_name_de(struct ntfs_sb_info *sbi, void *buf, const struct qstr *name,
fname->type = FILE_NAME_POSIX; fname->type = FILE_NAME_POSIX;
data_size = fname_full_size(fname); data_size = fname_full_size(fname);
e->size = cpu_to_le16(QuadAlign(data_size) + sizeof(struct NTFS_DE)); e->size = cpu_to_le16(ALIGN(data_size, 8) + sizeof(struct NTFS_DE));
e->key_size = cpu_to_le16(data_size); e->key_size = cpu_to_le16(data_size);
e->flags = 0; e->flags = 0;
e->res = 0; e->res = 0;
......
...@@ -392,8 +392,8 @@ static inline u64 attr_ondisk_size(const struct ATTRIB *attr) ...@@ -392,8 +392,8 @@ static inline u64 attr_ondisk_size(const struct ATTRIB *attr)
return attr->non_res ? ((attr->flags & return attr->non_res ? ((attr->flags &
(ATTR_FLAG_COMPRESSED | ATTR_FLAG_SPARSED)) ? (ATTR_FLAG_COMPRESSED | ATTR_FLAG_SPARSED)) ?
le64_to_cpu(attr->nres.total_size) : le64_to_cpu(attr->nres.total_size) :
le64_to_cpu(attr->nres.alloc_size)) : le64_to_cpu(attr->nres.alloc_size))
QuadAlign(le32_to_cpu(attr->res.data_size)); : ALIGN(le32_to_cpu(attr->res.data_size), 8);
} }
static inline u64 attr_size(const struct ATTRIB *attr) static inline u64 attr_size(const struct ATTRIB *attr)
...@@ -529,8 +529,8 @@ static_assert(sizeof(struct ATTR_LIST_ENTRY) == 0x20); ...@@ -529,8 +529,8 @@ static_assert(sizeof(struct ATTR_LIST_ENTRY) == 0x20);
static inline u32 le_size(u8 name_len) static inline u32 le_size(u8 name_len)
{ {
return QuadAlign(offsetof(struct ATTR_LIST_ENTRY, name) + return ALIGN(offsetof(struct ATTR_LIST_ENTRY, name) +
name_len * sizeof(short)); name_len * sizeof(short), 8);
} }
/* returns 0 if 'attr' has the same type and name */ /* returns 0 if 'attr' has the same type and name */
...@@ -692,9 +692,9 @@ static inline bool de_has_vcn_ex(const struct NTFS_DE *e) ...@@ -692,9 +692,9 @@ static inline bool de_has_vcn_ex(const struct NTFS_DE *e)
} }
#define MAX_BYTES_PER_NAME_ENTRY \ #define MAX_BYTES_PER_NAME_ENTRY \
QuadAlign(sizeof(struct NTFS_DE) + \ ALIGN(sizeof(struct NTFS_DE) + \
offsetof(struct ATTR_FILE_NAME, name) + \ offsetof(struct ATTR_FILE_NAME, name) + \
NTFS_NAME_LEN * sizeof(short)) NTFS_NAME_LEN * sizeof(short), 8)
struct INDEX_HDR { struct INDEX_HDR {
__le32 de_off; // 0x00: The offset from the start of this structure __le32 de_off; // 0x00: The offset from the start of this structure
......
...@@ -900,7 +900,7 @@ static inline bool run_is_empty(struct runs_tree *run) ...@@ -900,7 +900,7 @@ static inline bool run_is_empty(struct runs_tree *run)
/* NTFS uses quad aligned bitmaps */ /* NTFS uses quad aligned bitmaps */
static inline size_t bitmap_size(size_t bits) static inline size_t bitmap_size(size_t bits)
{ {
return QuadAlign((bits + 7) >> 3); return ALIGN((bits + 7) >> 3, 8);
} }
#define _100ns2seconds 10000000 #define _100ns2seconds 10000000
......
...@@ -206,7 +206,7 @@ struct ATTRIB *mi_enum_attr(struct mft_inode *mi, struct ATTRIB *attr) ...@@ -206,7 +206,7 @@ struct ATTRIB *mi_enum_attr(struct mft_inode *mi, struct ATTRIB *attr)
return NULL; return NULL;
if (off >= used || off < MFTRECORD_FIXUP_OFFSET_1 || if (off >= used || off < MFTRECORD_FIXUP_OFFSET_1 ||
!IsDwordAligned(off)) { !IS_ALIGNED(off, 4)) {
return NULL; return NULL;
} }
...@@ -235,7 +235,7 @@ struct ATTRIB *mi_enum_attr(struct mft_inode *mi, struct ATTRIB *attr) ...@@ -235,7 +235,7 @@ struct ATTRIB *mi_enum_attr(struct mft_inode *mi, struct ATTRIB *attr)
/* Can we use the first field (attr->type) */ /* Can we use the first field (attr->type) */
if (off + 8 > used) { if (off + 8 > used) {
static_assert(QuadAlign(sizeof(enum ATTR_TYPE)) == 8); static_assert(ALIGN(sizeof(enum ATTR_TYPE), 8) == 8);
return NULL; return NULL;
} }
...@@ -539,7 +539,7 @@ bool mi_resize_attr(struct mft_inode *mi, struct ATTRIB *attr, int bytes) ...@@ -539,7 +539,7 @@ bool mi_resize_attr(struct mft_inode *mi, struct ATTRIB *attr, int bytes)
next = Add2Ptr(attr, asize); next = Add2Ptr(attr, asize);
if (bytes > 0) { if (bytes > 0) {
dsize = QuadAlign(bytes); dsize = ALIGN(bytes, 8);
if (used + dsize > total) if (used + dsize > total)
return false; return false;
nsize = asize + dsize; nsize = asize + dsize;
...@@ -549,7 +549,7 @@ bool mi_resize_attr(struct mft_inode *mi, struct ATTRIB *attr, int bytes) ...@@ -549,7 +549,7 @@ bool mi_resize_attr(struct mft_inode *mi, struct ATTRIB *attr, int bytes)
used += dsize; used += dsize;
rsize += dsize; rsize += dsize;
} else { } else {
dsize = QuadAlign(-bytes); dsize = ALIGN(-bytes, 8);
if (dsize > asize) if (dsize > asize)
return false; return false;
nsize = asize - dsize; nsize = asize - dsize;
...@@ -596,7 +596,7 @@ int mi_pack_runs(struct mft_inode *mi, struct ATTRIB *attr, ...@@ -596,7 +596,7 @@ int mi_pack_runs(struct mft_inode *mi, struct ATTRIB *attr,
return err; return err;
} }
new_run_size = QuadAlign(err); new_run_size = ALIGN(err, 8);
memmove(next + new_run_size - run_size, next + dsize, tail); memmove(next + new_run_size - run_size, next + dsize, tail);
......
...@@ -809,9 +809,9 @@ static int ntfs_init_from_boot(struct super_block *sb, u32 sector_size, ...@@ -809,9 +809,9 @@ static int ntfs_init_from_boot(struct super_block *sb, u32 sector_size,
sbi->attr_size_tr = (5 * record_size >> 4); // ~320 bytes sbi->attr_size_tr = (5 * record_size >> 4); // ~320 bytes
sbi->max_bytes_per_attr = sbi->max_bytes_per_attr =
record_size - QuadAlign(MFTRECORD_FIXUP_OFFSET_1) - record_size - ALIGN(MFTRECORD_FIXUP_OFFSET_1, 8) -
QuadAlign(((record_size >> SECTOR_SHIFT) * sizeof(short))) - ALIGN(((record_size >> SECTOR_SHIFT) * sizeof(short)), 8) -
QuadAlign(sizeof(enum ATTR_TYPE)); ALIGN(sizeof(enum ATTR_TYPE), 8);
sbi->index_size = boot->index_size < 0 sbi->index_size = boot->index_size < 0
? 1u << (-boot->index_size) ? 1u << (-boot->index_size)
...@@ -859,9 +859,9 @@ static int ntfs_init_from_boot(struct super_block *sb, u32 sector_size, ...@@ -859,9 +859,9 @@ static int ntfs_init_from_boot(struct super_block *sb, u32 sector_size,
rec->rhdr.fix_off = cpu_to_le16(MFTRECORD_FIXUP_OFFSET_1); rec->rhdr.fix_off = cpu_to_le16(MFTRECORD_FIXUP_OFFSET_1);
fn = (sbi->record_size >> SECTOR_SHIFT) + 1; fn = (sbi->record_size >> SECTOR_SHIFT) + 1;
rec->rhdr.fix_num = cpu_to_le16(fn); rec->rhdr.fix_num = cpu_to_le16(fn);
ao = QuadAlign(MFTRECORD_FIXUP_OFFSET_1 + sizeof(short) * fn); ao = ALIGN(MFTRECORD_FIXUP_OFFSET_1 + sizeof(short) * fn, 8);
rec->attr_off = cpu_to_le16(ao); rec->attr_off = cpu_to_le16(ao);
rec->used = cpu_to_le32(ao + QuadAlign(sizeof(enum ATTR_TYPE))); rec->used = cpu_to_le32(ao + ALIGN(sizeof(enum ATTR_TYPE), 8));
rec->total = cpu_to_le32(sbi->record_size); rec->total = cpu_to_le32(sbi->record_size);
((struct ATTRIB *)Add2Ptr(rec, ao))->type = ATTR_END; ((struct ATTRIB *)Add2Ptr(rec, ao))->type = ATTR_END;
......
...@@ -26,9 +26,9 @@ ...@@ -26,9 +26,9 @@
static inline size_t unpacked_ea_size(const struct EA_FULL *ea) static inline size_t unpacked_ea_size(const struct EA_FULL *ea)
{ {
return ea->size ? le32_to_cpu(ea->size) return ea->size ? le32_to_cpu(ea->size)
: DwordAlign(struct_size( : ALIGN(struct_size(
ea, name, ea, name,
1 + ea->name_len + le16_to_cpu(ea->elength))); 1 + ea->name_len + le16_to_cpu(ea->elength)), 4);
} }
static inline size_t packed_ea_size(const struct EA_FULL *ea) static inline size_t packed_ea_size(const struct EA_FULL *ea)
...@@ -289,7 +289,7 @@ static noinline int ntfs_set_ea(struct inode *inode, const char *name, ...@@ -289,7 +289,7 @@ static noinline int ntfs_set_ea(struct inode *inode, const char *name,
goto out; goto out;
} }
add = DwordAlign(struct_size(ea_all, name, 1 + name_len + val_size)); add = ALIGN(struct_size(ea_all, name, 1 + name_len + val_size), 4);
err = ntfs_read_ea(ni, &ea_all, add, &info); err = ntfs_read_ea(ni, &ea_all, add, &info);
if (err) if (err)
......
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