Skip to content

Commit

Permalink
Merge branch 'melt-rebase-ntfs3' into melt-rebase
Browse files Browse the repository at this point in the history
  • Loading branch information
Pzqqt committed Aug 19, 2024
2 parents 83ccaa2 + 33003f5 commit 7e42aed
Show file tree
Hide file tree
Showing 11 changed files with 34 additions and 26 deletions.
14 changes: 9 additions & 5 deletions fs/ntfs3/attrib.c
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ int attr_make_nonresident(struct ntfs_inode *ni, struct ATTRIB *attr,
struct ntfs_sb_info *sbi;
struct ATTRIB *attr_s;
struct MFT_REC *rec;
u32 used, asize, rsize, aoff, align;
u32 used, asize, rsize, aoff;
bool is_data;
CLST len, alen;
char *next;
Expand All @@ -263,10 +263,13 @@ int attr_make_nonresident(struct ntfs_inode *ni, struct ATTRIB *attr,
rsize = le32_to_cpu(attr->res.data_size);
is_data = attr->type == ATTR_DATA && !attr->name_len;

align = sbi->cluster_size;
if (is_attr_compressed(attr))
align <<= COMPRESSION_UNIT;
len = (rsize + align - 1) >> sbi->cluster_bits;
/* len - how many clusters required to store 'rsize' bytes */
if (is_attr_compressed(attr)) {
u8 shift = sbi->cluster_bits + NTFS_LZNT_CUNIT;
len = ((rsize + (1u << shift) - 1) >> shift) << NTFS_LZNT_CUNIT;
} else {
len = bytes_to_cluster(sbi, rsize);
}

run_init(run);

Expand Down Expand Up @@ -1562,6 +1565,7 @@ int attr_allocate_frame(struct ntfs_inode *ni, CLST frame, size_t compr_size,

attr_b->nres.total_size = cpu_to_le64(total_size);
inode_set_bytes(&ni->vfs_inode, total_size);
ni->ni_flags |= NI_FLAG_UPDATE_PARENT;

mi_b->dirty = true;
mark_inode_dirty(&ni->vfs_inode);
Expand Down
2 changes: 1 addition & 1 deletion fs/ntfs3/bitmap.c
Original file line number Diff line number Diff line change
Expand Up @@ -1363,7 +1363,7 @@ int wnd_extend(struct wnd_bitmap *wnd, size_t new_bits)

err = ntfs_vbo_to_lbo(sbi, &wnd->run, vbo, &lbo, &bytes);
if (err)
break;
return err;

bh = ntfs_bread(sb, lbo >> sb->s_blocksize_bits);
if (!bh)
Expand Down
3 changes: 2 additions & 1 deletion fs/ntfs3/dir.c
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,8 @@ static inline int ntfs_filldir(struct ntfs_sb_info *sbi, struct ntfs_inode *ni,
* It does additional locks/reads just to get the type of name.
* Should we use additional mount option to enable branch below?
*/
if ((fname->dup.fa & FILE_ATTRIBUTE_REPARSE_POINT) &&
if (((fname->dup.fa & FILE_ATTRIBUTE_REPARSE_POINT) ||
fname->dup.ea_size) &&
ino != ni->mi.rno) {
struct inode *inode = ntfs_iget5(sbi->sb, &e->ref, NULL);
if (!IS_ERR_OR_NULL(inode)) {
Expand Down
5 changes: 1 addition & 4 deletions fs/ntfs3/file.c
Original file line number Diff line number Diff line change
Expand Up @@ -398,10 +398,7 @@ static int ntfs_file_mmap(struct file *file, struct vm_area_struct *vma)
}

if (ni->i_valid < to) {
if (!inode_trylock(inode)) {
err = -EAGAIN;
goto out;
}
inode_lock(inode);
err = ntfs_extend_initialized_size(file, ni,
ni->i_valid, to);
inode_unlock(inode);
Expand Down
2 changes: 1 addition & 1 deletion fs/ntfs3/frecord.c
Original file line number Diff line number Diff line change
Expand Up @@ -1453,7 +1453,7 @@ int ni_insert_nonresident(struct ntfs_inode *ni, enum ATTR_TYPE type,

if (is_ext) {
if (flags & ATTR_FLAG_COMPRESSED)
attr->nres.c_unit = COMPRESSION_UNIT;
attr->nres.c_unit = NTFS_LZNT_CUNIT;
attr->nres.total_size = attr->nres.alloc_size;
}

Expand Down
11 changes: 9 additions & 2 deletions fs/ntfs3/fslog.c
Original file line number Diff line number Diff line change
Expand Up @@ -724,7 +724,8 @@ static bool check_rstbl(const struct RESTART_TABLE *rt, size_t bytes)

if (!rsize || rsize > bytes ||
rsize + sizeof(struct RESTART_TABLE) > bytes || bytes < ts ||
le16_to_cpu(rt->total) > ne || ff > ts || lf > ts ||
le16_to_cpu(rt->total) > ne ||
ff > ts - sizeof(__le32) || lf > ts - sizeof(__le32) ||
(ff && ff < sizeof(struct RESTART_TABLE)) ||
(lf && lf < sizeof(struct RESTART_TABLE))) {
return false;
Expand Down Expand Up @@ -754,6 +755,9 @@ static bool check_rstbl(const struct RESTART_TABLE *rt, size_t bytes)
return false;

off = le32_to_cpu(*(__le32 *)Add2Ptr(rt, off));

if (off > ts - sizeof(__le32))
return false;
}

return true;
Expand Down Expand Up @@ -2995,7 +2999,7 @@ static struct ATTRIB *attr_create_nonres_log(struct ntfs_sb_info *sbi,
if (is_ext) {
attr->name_off = SIZEOF_NONRESIDENT_EX_LE;
if (is_attr_compressed(attr))
attr->nres.c_unit = COMPRESSION_UNIT;
attr->nres.c_unit = NTFS_LZNT_CUNIT;

attr->nres.run_off =
cpu_to_le16(SIZEOF_NONRESIDENT_EX + name_size);
Expand Down Expand Up @@ -3931,6 +3935,9 @@ int log_replay(struct ntfs_inode *ni, bool *initialized)
goto out;
}

log->page_mask = log->page_size - 1;
log->page_bits = blksize_bits(log->page_size);

/* If the file size has shrunk then we won't mount it. */
if (l_size < le64_to_cpu(ra2->l_size)) {
err = -EINVAL;
Expand Down
2 changes: 1 addition & 1 deletion fs/ntfs3/fsntfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -475,7 +475,7 @@ static int ntfs_extend_mft(struct ntfs_sb_info *sbi)
struct ATTRIB *attr;
struct wnd_bitmap *wnd = &sbi->mft.bitmap;

new_mft_total = (wnd->nbits + MFT_INCREASE_CHUNK + 127) & (CLST)~127;
new_mft_total = ALIGN(wnd->nbits + NTFS_MFT_INCREASE_STEP, 128);
new_mft_bytes = (u64)new_mft_total << sbi->record_bits;

/* Step 1: Resize $MFT::DATA. */
Expand Down
4 changes: 2 additions & 2 deletions fs/ntfs3/index.c
Original file line number Diff line number Diff line change
Expand Up @@ -979,7 +979,7 @@ static struct indx_node *indx_new(struct ntfs_index *indx,
hdr->used =
cpu_to_le32(eo + sizeof(struct NTFS_DE) + sizeof(u64));
de_set_vbn_le(e, *sub_vbn);
hdr->flags = 1;
hdr->flags = NTFS_INDEX_HDR_HAS_SUBNODES;
} else {
e->size = cpu_to_le16(sizeof(struct NTFS_DE));
hdr->used = cpu_to_le32(eo + sizeof(struct NTFS_DE));
Expand Down Expand Up @@ -1684,7 +1684,7 @@ static int indx_insert_into_root(struct ntfs_index *indx, struct ntfs_inode *ni,
e->size = cpu_to_le16(sizeof(struct NTFS_DE) + sizeof(u64));
e->flags = NTFS_IE_HAS_SUBNODES | NTFS_IE_LAST;

hdr->flags = 1;
hdr->flags = NTFS_INDEX_HDR_HAS_SUBNODES;
hdr->used = hdr->total =
cpu_to_le32(new_root_size - offsetof(struct INDEX_ROOT, ihdr));

Expand Down
2 changes: 1 addition & 1 deletion fs/ntfs3/inode.c
Original file line number Diff line number Diff line change
Expand Up @@ -1465,7 +1465,7 @@ struct inode *ntfs_create_inode(
attr->size = cpu_to_le32(SIZEOF_NONRESIDENT_EX + 8);
attr->name_off = SIZEOF_NONRESIDENT_EX_LE;
attr->flags = ATTR_FLAG_COMPRESSED;
attr->nres.c_unit = COMPRESSION_UNIT;
attr->nres.c_unit = NTFS_LZNT_CUNIT;
asize = SIZEOF_NONRESIDENT_EX + 8;
} else {
attr->size = cpu_to_le32(SIZEOF_NONRESIDENT + 8);
Expand Down
13 changes: 5 additions & 8 deletions fs/ntfs3/ntfs.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,6 @@ typedef u32 CLST;
#define RESIDENT_LCN ((CLST)-2)
#define COMPRESSED_LCN ((CLST)-3)

#define COMPRESSION_UNIT 4
#define COMPRESS_MAX_CLUSTER 0x1000
#define MFT_INCREASE_CHUNK 1024

enum RECORD_NUM {
MFT_REC_MFT = 0,
MFT_REC_MIRR = 1,
Expand Down Expand Up @@ -690,14 +686,15 @@ static inline bool de_has_vcn_ex(const struct NTFS_DE *e)
offsetof(struct ATTR_FILE_NAME, name) + \
NTFS_NAME_LEN * sizeof(short), 8)

#define NTFS_INDEX_HDR_HAS_SUBNODES cpu_to_le32(1)

struct INDEX_HDR {
__le32 de_off; // 0x00: The offset from the start of this structure
// to the first NTFS_DE.
__le32 used; // 0x04: The size of this structure plus all
// entries (quad-word aligned).
__le32 total; // 0x08: The allocated size of for this structure plus all entries.
u8 flags; // 0x0C: 0x00 = Small directory, 0x01 = Large directory.
u8 res[3];
__le32 flags; // 0x0C: 0x00 = Small directory, 0x01 = Large directory.

//
// de_off + used <= total
Expand Down Expand Up @@ -744,7 +741,7 @@ static inline struct NTFS_DE *hdr_next_de(const struct INDEX_HDR *hdr,

static inline bool hdr_has_subnode(const struct INDEX_HDR *hdr)
{
return hdr->flags & 1;
return hdr->flags & NTFS_INDEX_HDR_HAS_SUBNODES;
}

struct INDEX_BUFFER {
Expand All @@ -764,7 +761,7 @@ static inline bool ib_is_empty(const struct INDEX_BUFFER *ib)

static inline bool ib_is_leaf(const struct INDEX_BUFFER *ib)
{
return !(ib->ihdr.flags & 1);
return !(ib->ihdr.flags & NTFS_INDEX_HDR_HAS_SUBNODES);
}

/* Index root structure ( 0x90 ). */
Expand Down
2 changes: 2 additions & 0 deletions fs/ntfs3/ntfs_fs.h
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,8 @@ struct ntfs_index {

/* Minimum MFT zone. */
#define NTFS_MIN_MFT_ZONE 100
/* Step to increase the MFT. */
#define NTFS_MFT_INCREASE_STEP 1024

/* Ntfs file system in-core superblock data. */
struct ntfs_sb_info {
Expand Down

0 comments on commit 7e42aed

Please sign in to comment.