Lines Matching +full:set +full:- +full:aces
1 // SPDX-License-Identifier: GPL-2.0
4 * Copyright (C) 2019-2021 Paragon Software GmbH, All rights reserved.
18 // clang-format off
126 // clang-format on
129 * ntfs_fix_pre_write - Insert fixups into @rhdr before writing to disk.
135 u16 fo = le16_to_cpu(rhdr->fix_off); in ntfs_fix_pre_write()
136 u16 fn = le16_to_cpu(rhdr->fix_num); in ntfs_fix_pre_write()
138 if ((fo & 1) || fo + fn * sizeof(short) > SECTOR_SIZE || !fn-- || in ntfs_fix_pre_write()
153 ptr = Add2Ptr(rhdr, SECTOR_SIZE - sizeof(short)); in ntfs_fix_pre_write()
155 while (fn--) { in ntfs_fix_pre_write()
164 * ntfs_fix_post_read - Remove fixups after reading from disk.
175 fo = le16_to_cpu(rhdr->fix_off); in ntfs_fix_post_read()
177 le16_to_cpu(rhdr->fix_num); in ntfs_fix_post_read()
180 if ((fo & 1) || fo + fn * sizeof(short) > SECTOR_SIZE || !fn-- || in ntfs_fix_post_read()
182 return -E_NTFS_CORRUPT; in ntfs_fix_post_read()
188 ptr = Add2Ptr(rhdr, SECTOR_SIZE - sizeof(short)); in ntfs_fix_post_read()
191 while (fn--) { in ntfs_fix_post_read()
195 ret = -E_NTFS_FIXUP; in ntfs_fix_post_read()
207 * ntfs_extend_init - Load $Extend file.
212 struct super_block *sb = sbi->sb; in ntfs_extend_init()
216 if (sbi->volume.major_ver < 3) { in ntfs_extend_init()
233 if (!S_ISDIR(inode->i_mode)) { in ntfs_extend_init()
234 err = -EINVAL; in ntfs_extend_init()
244 sbi->objid.ni = ntfs_i(inode2); in ntfs_extend_init()
245 sbi->objid_no = inode2->i_ino; in ntfs_extend_init()
252 sbi->quota_no = inode2->i_ino; in ntfs_extend_init()
259 sbi->reparse.ni = ntfs_i(inode2); in ntfs_extend_init()
260 sbi->reparse_no = inode2->i_ino; in ntfs_extend_init()
266 sbi->usn_jrnl_no = inode2->i_ino; in ntfs_extend_init()
279 struct super_block *sb = sbi->sb; in ntfs_loadlog_and_replay()
285 if (ni->vfs_inode.i_size >= 0x100000000ull) { in ntfs_loadlog_and_replay()
287 err = -EINVAL; in ntfs_loadlog_and_replay()
291 sbi->flags |= NTFS_FLAGS_LOG_REPLAYING; in ntfs_loadlog_and_replay()
304 u64 t64 = sbi->mft.lbo; in ntfs_loadlog_and_replay()
306 sbi->mft.lbo = sbi->mft.lbo2; in ntfs_loadlog_and_replay()
308 sbi->mft.lbo = t64; in ntfs_loadlog_and_replay()
314 err = -EINVAL; in ntfs_loadlog_and_replay()
319 sbi->mft.ni = ntfs_i(inode); in ntfs_loadlog_and_replay()
322 err = ni_load_all_mi(sbi->mft.ni); in ntfs_loadlog_and_replay()
327 sbi->mft.ni = NULL; in ntfs_loadlog_and_replay()
329 sync_blockdev(sb->s_bdev); in ntfs_loadlog_and_replay()
330 invalidate_bdev(sb->s_bdev); in ntfs_loadlog_and_replay()
332 if (sbi->flags & NTFS_FLAGS_NEED_REPLAY) { in ntfs_loadlog_and_replay()
340 /* Fill LogFile by '-1' if it is initialized. */ in ntfs_loadlog_and_replay()
341 err = ntfs_bio_fill_1(sbi, &ni->file.run); in ntfs_loadlog_and_replay()
344 sbi->flags &= ~NTFS_FLAGS_LOG_REPLAYING; in ntfs_loadlog_and_replay()
350 * ntfs_look_for_free_space - Look for a free space in bitmap.
358 struct super_block *sb = sbi->sb; in ntfs_look_for_free_space()
360 struct wnd_bitmap *wnd = &sbi->used.bitmap; in ntfs_look_for_free_space()
362 down_write_nested(&wnd->rw_lock, BITMAP_MUTEX_CLUSTERS); in ntfs_look_for_free_space()
375 ntfs_err(sbi->sb, "no free space to extend mft"); in ntfs_look_for_free_space()
376 err = -ENOSPC; in ntfs_look_for_free_space()
383 wnd_zone_set(wnd, lcn + alen, zlen - alen); in ntfs_look_for_free_space()
397 lcn = sbi->used.next_free_lcn; in ntfs_look_for_free_space()
399 if (lcn >= wnd->nbits) in ntfs_look_for_free_space()
412 err = -ENOSPC; in ntfs_look_for_free_space()
420 new_zlen = max_t(size_t, zlen - ztrim, NTFS_MIN_MFT_ZONE); in ntfs_look_for_free_space()
428 err = -ENOSPC; in ntfs_look_for_free_space()
439 /* Set hint for next requests. */ in ntfs_look_for_free_space()
441 sbi->used.next_free_lcn = alcn + alen; in ntfs_look_for_free_space()
443 up_write(&wnd->rw_lock); in ntfs_look_for_free_space()
457 wnd = &sbi->used.bitmap; in ntfs_check_for_free_space()
458 down_read_nested(&wnd->rw_lock, BITMAP_MUTEX_CLUSTERS); in ntfs_check_for_free_space()
461 up_read(&wnd->rw_lock); in ntfs_check_for_free_space()
466 avail = free - (zlen + clen); in ntfs_check_for_free_space()
468 wnd = &sbi->mft.bitmap; in ntfs_check_for_free_space()
469 down_read_nested(&wnd->rw_lock, BITMAP_MUTEX_MFT); in ntfs_check_for_free_space()
472 up_read(&wnd->rw_lock); in ntfs_check_for_free_space()
477 return avail >= bytes_to_cluster(sbi, mlen << sbi->record_bits); in ntfs_check_for_free_space()
481 * ntfs_extend_mft - Allocate additional MFT records.
483 * sbi->mft.bitmap is locked for write.
486 * ntfs_look_free_mft ->
487 * ntfs_extend_mft ->
488 * attr_set_size ->
489 * ni_insert_nonresident ->
490 * ni_insert_attr ->
491 * ni_ins_attr_ext ->
492 * ntfs_look_free_mft ->
501 struct ntfs_inode *ni = sbi->mft.ni; in ntfs_extend_mft()
505 struct wnd_bitmap *wnd = &sbi->mft.bitmap; in ntfs_extend_mft()
507 new_mft_total = ALIGN(wnd->nbits + NTFS_MFT_INCREASE_STEP, 128); in ntfs_extend_mft()
508 new_mft_bytes = (u64)new_mft_total << sbi->record_bits; in ntfs_extend_mft()
511 down_write(&ni->file.run_lock); in ntfs_extend_mft()
512 err = attr_set_size(ni, ATTR_DATA, NULL, 0, &ni->file.run, in ntfs_extend_mft()
516 up_write(&ni->file.run_lock); in ntfs_extend_mft()
520 attr->nres.valid_size = attr->nres.data_size; in ntfs_extend_mft()
521 new_mft_total = le64_to_cpu(attr->nres.alloc_size) >> sbi->record_bits; in ntfs_extend_mft()
522 ni->mi.dirty = true; in ntfs_extend_mft()
527 err = attr_set_size(ni, ATTR_BITMAP, NULL, 0, &sbi->mft.bitmap.run, in ntfs_extend_mft()
531 down_write_nested(&sbi->used.bitmap.rw_lock, BITMAP_MUTEX_CLUSTERS); in ntfs_extend_mft()
535 up_write(&sbi->used.bitmap.rw_lock); in ntfs_extend_mft()
536 up_write(&ni->file.run_lock); in ntfs_extend_mft()
546 ntfs_clear_mft_tail(sbi, sbi->mft.used, new_mft_total); in ntfs_extend_mft()
548 err = _ni_write_inode(&ni->vfs_inode, 0); in ntfs_extend_mft()
554 * ntfs_look_free_mft - Look for a free MFT record.
563 struct super_block *sb = sbi->sb; in ntfs_look_free_mft()
564 struct wnd_bitmap *wnd = &sbi->mft.bitmap; in ntfs_look_free_mft()
567 static_assert(sizeof(sbi->mft.reserved_bitmap) * 8 >= in ntfs_look_free_mft()
568 MFT_REC_FREE - MFT_REC_RESERVED); in ntfs_look_free_mft()
571 down_write_nested(&wnd->rw_lock, BITMAP_MUTEX_MFT); in ntfs_look_free_mft()
580 wnd_zone_set(wnd, zbit + 1, zlen - 1); in ntfs_look_free_mft()
588 mft_total = wnd->nbits; in ntfs_look_free_mft()
596 if (!mft || MFT_REC_FREE == sbi->mft.next_reserved) in ntfs_look_free_mft()
602 * Look for free record reserved area [11-16) == in ntfs_look_free_mft()
606 if (!sbi->mft.reserved_bitmap) { in ntfs_look_free_mft()
608 sbi->mft.reserved_bitmap = 0xFF; in ntfs_look_free_mft()
635 mrec = ni->mi.mrec; in ntfs_look_free_mft()
640 if (mrec->hard_links) in ntfs_look_free_mft()
650 __clear_bit(ir - MFT_REC_RESERVED, in ntfs_look_free_mft()
651 &sbi->mft.reserved_bitmap); in ntfs_look_free_mft()
656 zbit = find_next_zero_bit(&sbi->mft.reserved_bitmap, in ntfs_look_free_mft()
659 sbi->mft.next_reserved = MFT_REC_FREE; in ntfs_look_free_mft()
664 sbi->mft.next_reserved = zbit; in ntfs_look_free_mft()
667 zlen = zbit == MFT_REC_FREE ? (MFT_REC_USER - MFT_REC_FREE) : 4; in ntfs_look_free_mft()
668 if (zbit + zlen > wnd->nbits) in ntfs_look_free_mft()
669 zlen = wnd->nbits - zbit; in ntfs_look_free_mft()
672 zlen -= 1; in ntfs_look_free_mft()
675 from = sbi->mft.used; in ntfs_look_free_mft()
681 sbi->mft.used = to; in ntfs_look_free_mft()
688 zlen -= 1; in ntfs_look_free_mft()
696 if (sbi->mft.next_free < MFT_REC_USER) in ntfs_look_free_mft()
697 sbi->mft.next_free = MFT_REC_USER; in ntfs_look_free_mft()
700 if (sbi->mft.next_free >= sbi->mft.bitmap.nbits) { in ntfs_look_free_mft()
702 sbi->mft.next_free = sbi->mft.bitmap.nbits; in ntfs_look_free_mft()
705 sbi->mft.next_free = *rno + 1; in ntfs_look_free_mft()
716 err = -ENOMEM; in ntfs_look_free_mft()
723 else if (*rno >= MFT_REC_RESERVED && sbi->mft.reserved_bitmap_inited) in ntfs_look_free_mft()
724 __set_bit(*rno - MFT_REC_RESERVED, &sbi->mft.reserved_bitmap); in ntfs_look_free_mft()
728 up_write(&wnd->rw_lock); in ntfs_look_free_mft()
734 * ntfs_mark_rec_free - Mark record as free.
735 * is_mft - true if we are changing MFT
739 struct wnd_bitmap *wnd = &sbi->mft.bitmap; in ntfs_mark_rec_free()
742 down_write_nested(&wnd->rw_lock, BITMAP_MUTEX_MFT); in ntfs_mark_rec_free()
743 if (rno >= wnd->nbits) in ntfs_mark_rec_free()
751 } else if (rno >= MFT_REC_RESERVED && sbi->mft.reserved_bitmap_inited) { in ntfs_mark_rec_free()
752 __clear_bit(rno - MFT_REC_RESERVED, &sbi->mft.reserved_bitmap); in ntfs_mark_rec_free()
757 else if (rno < sbi->mft.next_free && rno >= MFT_REC_USER) in ntfs_mark_rec_free()
758 sbi->mft.next_free = rno; in ntfs_mark_rec_free()
762 up_write(&wnd->rw_lock); in ntfs_mark_rec_free()
766 * ntfs_clear_mft_tail - Format empty records [from, to).
768 * sbi->mft.bitmap is locked for write.
781 rs = sbi->record_size; in ntfs_clear_mft_tail()
782 ni = sbi->mft.ni; in ntfs_clear_mft_tail()
783 run = &ni->file.run; in ntfs_clear_mft_tail()
785 down_read(&ni->file.run_lock); in ntfs_clear_mft_tail()
794 err = ntfs_write_bh(sbi, &sbi->new_rec->rhdr, &nb, 0); in ntfs_clear_mft_tail()
801 sbi->mft.used = from; in ntfs_clear_mft_tail()
802 up_read(&ni->file.run_lock); in ntfs_clear_mft_tail()
807 * ntfs_refresh_zone - Refresh MFT zone.
809 * sbi->used.bitmap is locked for rw.
810 * sbi->mft.bitmap is locked for write.
811 * sbi->mft.ni->file.run_lock for write.
817 struct wnd_bitmap *wnd = &sbi->used.bitmap; in ntfs_refresh_zone()
818 struct ntfs_inode *ni = sbi->mft.ni; in ntfs_refresh_zone()
825 (u64)sbi->mft.bitmap.nbits << sbi->record_bits); in ntfs_refresh_zone()
827 if (!run_lookup_entry(&ni->file.run, vcn - 1, &lcn, &len, NULL)) in ntfs_refresh_zone()
832 return -EINVAL; in ntfs_refresh_zone()
837 zlen = wnd_find(wnd, sbi->zone_max, lcn_s, 0, &lcn_s); in ntfs_refresh_zone()
844 * ntfs_update_mftmirr - Update $MFTMirr data.
849 struct super_block *sb = sbi->sb; in ntfs_update_mftmirr()
854 * sb can be NULL here. In this case sbi->flags should be 0 too. in ntfs_update_mftmirr()
856 if (!sb || !(sbi->flags & NTFS_FLAGS_MFTMIRR) || in ntfs_update_mftmirr()
860 blocksize = sb->s_blocksize; in ntfs_update_mftmirr()
861 bytes = sbi->mft.recs_mirr << sbi->record_bits; in ntfs_update_mftmirr()
862 block1 = sbi->mft.lbo >> sb->s_blocksize_bits; in ntfs_update_mftmirr()
863 block2 = sbi->mft.lbo2 >> sb->s_blocksize_bits; in ntfs_update_mftmirr()
865 for (; bytes >= blocksize; bytes -= blocksize) { in ntfs_update_mftmirr()
882 memcpy(bh2->b_data, bh1->b_data, blocksize); in ntfs_update_mftmirr()
897 sbi->flags &= ~NTFS_FLAGS_MFTMIRR; in ntfs_update_mftmirr()
907 struct ntfs_sb_info *sbi = inode->i_sb->s_fs_info; in ntfs_bad_inode()
935 if (sbi->volume.real_dirty || sb_rdonly(sbi->sb)) in ntfs_set_state()
940 (sbi->volume.flags & VOLUME_FLAG_DIRTY)) in ntfs_set_state()
943 ni = sbi->volume.ni; in ntfs_set_state()
945 return -EINVAL; in ntfs_set_state()
947 mutex_lock_nested(&ni->ni_lock, NTFS_INODE_MUTEX_DIRTY); in ntfs_set_state()
951 err = -EINVAL; in ntfs_set_state()
957 err = -EINVAL; in ntfs_set_state()
961 info_flags = info->flags; in ntfs_set_state()
965 ntfs_notice(sbi->sb, "Mark volume as dirty due to NTFS errors"); in ntfs_set_state()
966 sbi->volume.real_dirty = true; in ntfs_set_state()
969 info->flags |= VOLUME_FLAG_DIRTY; in ntfs_set_state()
972 info->flags &= ~VOLUME_FLAG_DIRTY; in ntfs_set_state()
976 if (info_flags != info->flags) { in ntfs_set_state()
977 sbi->volume.flags = info->flags; in ntfs_set_state()
978 mi->dirty = true; in ntfs_set_state()
987 mark_inode_dirty_sync(&ni->vfs_inode); in ntfs_set_state()
991 err = _ni_write_inode(&ni->vfs_inode, 1); in ntfs_set_state()
997 * security_hash - Calculates a hash of security descriptor.
1005 while (bytes--) in security_hash()
1015 struct ntfs_sb_info *sbi = sb->s_fs_info; in ntfs_bread()
1018 if (unlikely(block >= sbi->volume.blocks)) { in ntfs_bread()
1021 (u64)block << sb->s_blocksize_bits); in ntfs_bread()
1030 (u64)block << sb->s_blocksize_bits); in ntfs_bread()
1036 struct block_device *bdev = sb->s_bdev; in ntfs_sb_read()
1037 u32 blocksize = sb->s_blocksize; in ntfs_sb_read()
1038 u64 block = lbo >> sb->s_blocksize_bits; in ntfs_sb_read()
1039 u32 off = lbo & (blocksize - 1); in ntfs_sb_read()
1040 u32 op = blocksize - off; in ntfs_sb_read()
1046 return -EIO; in ntfs_sb_read()
1051 memcpy(buffer, bh->b_data + off, op); in ntfs_sb_read()
1055 bytes -= op; in ntfs_sb_read()
1065 u32 blocksize = sb->s_blocksize; in ntfs_sb_write()
1066 struct block_device *bdev = sb->s_bdev; in ntfs_sb_write()
1067 sector_t block = lbo >> sb->s_blocksize_bits; in ntfs_sb_write()
1068 u32 off = lbo & (blocksize - 1); in ntfs_sb_write()
1069 u32 op = blocksize - off; in ntfs_sb_write()
1072 if (!wait && (sb->s_flags & SB_SYNCHRONOUS)) in ntfs_sb_write()
1084 return -EIO; in ntfs_sb_write()
1089 return -ENOMEM; in ntfs_sb_write()
1097 memcpy(bh->b_data + off, buf, op); in ntfs_sb_write()
1100 memset(bh->b_data + off, -1, op); in ntfs_sb_write()
1122 bytes -= op; in ntfs_sb_write()
1130 struct super_block *sb = sbi->sb; in ntfs_sb_write_run()
1131 u8 cluster_bits = sbi->cluster_bits; in ntfs_sb_write_run()
1132 u32 off = vbo & sbi->cluster_mask; in ntfs_sb_write_run()
1138 return -ENOENT; in ntfs_sb_write_run()
1141 return -EINVAL; in ntfs_sb_write_run()
1144 len = ((u64)clen << cluster_bits) - off; in ntfs_sb_write_run()
1153 bytes -= op; in ntfs_sb_write_run()
1160 return -ENOENT; in ntfs_sb_write_run()
1163 return -EINVAL; in ntfs_sb_write_run()
1178 struct super_block *sb = sbi->sb; in ntfs_bread_run()
1179 u8 cluster_bits = sbi->cluster_bits; in ntfs_bread_run()
1184 return ERR_PTR(-ENOENT); in ntfs_bread_run()
1186 lbo = ((u64)lcn << cluster_bits) + (vbo & sbi->cluster_mask); in ntfs_bread_run()
1188 return ntfs_bread(sb, lbo >> sb->s_blocksize_bits); in ntfs_bread_run()
1195 struct super_block *sb = sbi->sb; in ntfs_read_run_nb()
1196 u32 blocksize = sb->s_blocksize; in ntfs_read_run_nb()
1197 u8 cluster_bits = sbi->cluster_bits; in ntfs_read_run_nb()
1198 u32 off = vbo & sbi->cluster_mask; in ntfs_read_run_nb()
1208 if (vbo > MFT_REC_VOL * sbi->record_size) { in ntfs_read_run_nb()
1209 err = -ENOENT; in ntfs_read_run_nb()
1214 lbo = vbo + sbi->mft.lbo; in ntfs_read_run_nb()
1215 len = sbi->record_size; in ntfs_read_run_nb()
1217 err = -ENOENT; in ntfs_read_run_nb()
1221 err = -EINVAL; in ntfs_read_run_nb()
1226 len = ((u64)clen << cluster_bits) - off; in ntfs_read_run_nb()
1229 off = lbo & (blocksize - 1); in ntfs_read_run_nb()
1231 nb->off = off; in ntfs_read_run_nb()
1232 nb->bytes = bytes; in ntfs_read_run_nb()
1237 sector_t block = lbo >> sb->s_blocksize_bits; in ntfs_read_run_nb()
1240 u32 op = blocksize - off; in ntfs_read_run_nb()
1247 err = -EIO; in ntfs_read_run_nb()
1252 memcpy(buf, bh->b_data + off, op); in ntfs_read_run_nb()
1258 } else if (nbh >= ARRAY_SIZE(nb->bh)) { in ntfs_read_run_nb()
1259 err = -EINVAL; in ntfs_read_run_nb()
1262 nb->bh[nbh++] = bh; in ntfs_read_run_nb()
1263 nb->nbufs = nbh; in ntfs_read_run_nb()
1266 bytes -= op; in ntfs_read_run_nb()
1269 len32 -= op; in ntfs_read_run_nb()
1278 err = -ENOENT; in ntfs_read_run_nb()
1283 err = -EINVAL; in ntfs_read_run_nb()
1296 put_bh(nb->bh[--nbh]); in ntfs_read_run_nb()
1297 nb->bh[nbh] = NULL; in ntfs_read_run_nb()
1300 nb->nbufs = 0; in ntfs_read_run_nb()
1307 * Return: < 0 if error, 0 if ok, -E_NTFS_FIXUP if need to update fixups.
1317 return ntfs_fix_post_read(rhdr, nb->bytes, true); in ntfs_read_bh()
1324 struct super_block *sb = sbi->sb; in ntfs_get_bh()
1325 u32 blocksize = sb->s_blocksize; in ntfs_get_bh()
1326 u8 cluster_bits = sbi->cluster_bits; in ntfs_get_bh()
1334 nb->bytes = bytes; in ntfs_get_bh()
1337 err = -ENOENT; in ntfs_get_bh()
1341 off = vbo & sbi->cluster_mask; in ntfs_get_bh()
1343 len = ((u64)clen << cluster_bits) - off; in ntfs_get_bh()
1345 nb->off = off = lbo & (blocksize - 1); in ntfs_get_bh()
1349 sector_t block = lbo >> sb->s_blocksize_bits; in ntfs_get_bh()
1355 if (nbh >= ARRAY_SIZE(nb->bh)) { in ntfs_get_bh()
1356 err = -EINVAL; in ntfs_get_bh()
1360 op = blocksize - off; in ntfs_get_bh()
1367 err = -ENOMEM; in ntfs_get_bh()
1376 err = -EIO; in ntfs_get_bh()
1381 nb->bh[nbh++] = bh; in ntfs_get_bh()
1382 bytes -= op; in ntfs_get_bh()
1384 nb->nbufs = nbh; in ntfs_get_bh()
1389 len32 -= op; in ntfs_get_bh()
1396 err = -ENOENT; in ntfs_get_bh()
1406 put_bh(nb->bh[--nbh]); in ntfs_get_bh()
1407 nb->bh[nbh] = NULL; in ntfs_get_bh()
1410 nb->nbufs = 0; in ntfs_get_bh()
1419 struct super_block *sb = sbi->sb; in ntfs_write_bh()
1420 u32 block_size = sb->s_blocksize; in ntfs_write_bh()
1421 u32 bytes = nb->bytes; in ntfs_write_bh()
1422 u32 off = nb->off; in ntfs_write_bh()
1423 u16 fo = le16_to_cpu(rhdr->fix_off); in ntfs_write_bh()
1424 u16 fn = le16_to_cpu(rhdr->fix_num); in ntfs_write_bh()
1429 if ((fo & 1) || fo + fn * sizeof(short) > SECTOR_SIZE || !fn-- || in ntfs_write_bh()
1431 return -EINVAL; in ntfs_write_bh()
1434 for (idx = 0; bytes && idx < nb->nbufs; idx += 1, off = 0) { in ntfs_write_bh()
1435 u32 op = block_size - off; in ntfs_write_bh()
1437 struct buffer_head *bh = nb->bh[idx]; in ntfs_write_bh()
1448 bh_data = bh->b_data + off; in ntfs_write_bh()
1468 ptr = Add2Ptr(bh_data, SECTOR_SIZE - sizeof(short)); in ntfs_write_bh()
1487 bytes -= op; in ntfs_write_bh()
1495 * ntfs_bio_pages - Read/write pages from/to disk.
1503 struct super_block *sb = sbi->sb; in ntfs_bio_pages()
1504 struct block_device *bdev = sb->s_bdev; in ntfs_bio_pages()
1506 u8 cluster_bits = sbi->cluster_bits; in ntfs_bio_pages()
1521 bytes = lbo - vbo; in ntfs_bio_pages()
1525 err = -ENOENT; in ntfs_bio_pages()
1528 off = vbo & sbi->cluster_mask; in ntfs_bio_pages()
1534 len = ((u64)clen << cluster_bits) - off; in ntfs_bio_pages()
1536 new = bio_alloc(bdev, nr_pages - page_idx, op, GFP_NOFS); in ntfs_bio_pages()
1542 bio->bi_iter.bi_sector = lbo >> 9; in ntfs_bio_pages()
1545 off = vbo & (PAGE_SIZE - 1); in ntfs_bio_pages()
1546 add = off + len > PAGE_SIZE ? (PAGE_SIZE - off) : len; in ntfs_bio_pages()
1553 bytes -= add; in ntfs_bio_pages()
1559 err = -EINVAL; in ntfs_bio_pages()
1567 len -= add; in ntfs_bio_pages()
1574 err = -ENOENT; in ntfs_bio_pages()
1591 * ntfs_bio_fill_1 - Helper for ntfs_loadlog_and_replay().
1593 * Fill on-disk logfile range by (-1)
1599 struct super_block *sb = sbi->sb; in ntfs_bio_fill_1()
1600 struct block_device *bdev = sb->s_bdev; in ntfs_bio_fill_1()
1601 u8 cluster_bits = sbi->cluster_bits; in ntfs_bio_fill_1()
1612 return -ENOMEM; in ntfs_bio_fill_1()
1615 memset(kaddr, -1, PAGE_SIZE); in ntfs_bio_fill_1()
1621 err = -ENOENT; in ntfs_bio_fill_1()
1639 bio->bi_iter.bi_sector = lbo >> 9; in ntfs_bio_fill_1()
1650 len -= add; in ntfs_bio_fill_1()
1671 u8 cluster_bits = sbi->cluster_bits; in ntfs_vbo_to_lbo()
1674 return -ENOENT; in ntfs_vbo_to_lbo()
1676 off = vbo & sbi->cluster_mask; in ntfs_vbo_to_lbo()
1677 *lbo = lcn == SPARSE_LCN ? -1 : (((u64)lcn << cluster_bits) + off); in ntfs_vbo_to_lbo()
1678 *bytes = ((u64)len << cluster_bits) - off; in ntfs_vbo_to_lbo()
1687 struct super_block *sb = sbi->sb; in ntfs_new_inode()
1692 return ERR_PTR(-ENOMEM); in ntfs_new_inode()
1696 err = mi_format_new(&ni->mi, sbi, rno, flag, false); in ntfs_new_inode()
1700 inode->i_ino = rno; in ntfs_new_inode()
1702 err = -EIO; in ntfs_new_inode()
1717 * Owner S-1-5-32-544 (Administrators)
1718 * Group S-1-5-32-544 (Administrators)
1719 * ACE: allow S-1-1-0 (Everyone) with FILE_ALL_ACCESS
1735 return struct_size(sid, SubAuthority, sid->SubAuthorityCount); in sid_length()
1749 if (acl->AclRevision != ACL_REVISION && in is_acl_valid()
1750 acl->AclRevision != ACL_REVISION_DS) { in is_acl_valid()
1753 * object-specific ACE, in which case this value must be ACL_REVISION_DS. in is_acl_valid()
1754 * All ACEs in an ACL must be at the same revision level. in is_acl_valid()
1759 if (acl->Sbz1) in is_acl_valid()
1762 if (le16_to_cpu(acl->AclSize) > len) in is_acl_valid()
1765 if (acl->Sbz2) in is_acl_valid()
1768 len -= sizeof(struct ACL); in is_acl_valid()
1770 ace_count = le16_to_cpu(acl->AceCount); in is_acl_valid()
1776 ace_size = le16_to_cpu(ace->AceSize); in is_acl_valid()
1780 len -= ace_size; in is_acl_valid()
1794 if (sd->Revision != 1) in is_sd_valid()
1797 if (sd->Sbz1) in is_sd_valid()
1800 if (!(sd->Control & SE_SELF_RELATIVE)) in is_sd_valid()
1803 sd_owner = le32_to_cpu(sd->Owner); in is_sd_valid()
1810 if (owner->Revision != 1) in is_sd_valid()
1817 sd_group = le32_to_cpu(sd->Group); in is_sd_valid()
1824 if (group->Revision != 1) in is_sd_valid()
1831 sd_sacl = le32_to_cpu(sd->Sacl); in is_sd_valid()
1838 if (!is_acl_valid(sacl, len - sd_sacl)) in is_sd_valid()
1842 sd_dacl = le32_to_cpu(sd->Dacl); in is_sd_valid()
1849 if (!is_acl_valid(dacl, len - sd_dacl)) in is_sd_valid()
1857 * ntfs_security_init - Load and parse $Secure.
1862 struct super_block *sb = sbi->sb; in ntfs_security_init()
1875 struct ntfs_index *indx_sdh = &sbi->security.index_sdh; in ntfs_security_init()
1876 struct ntfs_index *indx_sii = &sbi->security.index_sii; in ntfs_security_init()
1898 root_sdh->type != ATTR_ZERO || in ntfs_security_init()
1899 root_sdh->rule != NTFS_COLLATION_TYPE_SECURITY_HASH || in ntfs_security_init()
1901 le32_to_cpu(root_sdh->ihdr.used) > in ntfs_security_init()
1902 le32_to_cpu(attr->res.data_size)) { in ntfs_security_init()
1904 err = -EINVAL; in ntfs_security_init()
1918 root_sii->type != ATTR_ZERO || in ntfs_security_init()
1919 root_sii->rule != NTFS_COLLATION_TYPE_UINT || in ntfs_security_init()
1921 le32_to_cpu(root_sii->ihdr.used) > in ntfs_security_init()
1922 le32_to_cpu(attr->res.data_size)) { in ntfs_security_init()
1924 err = -EINVAL; in ntfs_security_init()
1936 err = -ENOMEM; in ntfs_security_init()
1940 sds_size = inode->i_size; in ntfs_security_init()
1943 sbi->security.next_id = SECURITY_ID_FIRST; in ntfs_security_init()
1945 sbi->security.next_off = in ntfs_security_init()
1946 ALIGN(sds_size - SecurityDescriptorsBlockSize, 16); in ntfs_security_init()
1959 if (le16_to_cpu(ne->view.data_size) < sizeof(sii_e->sec_hdr)) in ntfs_security_init()
1962 next_id = le32_to_cpu(sii_e->sec_id) + 1; in ntfs_security_init()
1963 if (next_id >= sbi->security.next_id) in ntfs_security_init()
1964 sbi->security.next_id = next_id; in ntfs_security_init()
1967 sbi->security.ni = ni; in ntfs_security_init()
1977 * ntfs_get_security_by_id - Read security descriptor by id.
1985 struct ntfs_inode *ni = sbi->security.ni; in ntfs_get_security_by_id()
1986 struct ntfs_index *indx = &sbi->security.index_sii; in ntfs_get_security_by_id()
1996 mutex_lock_nested(&ni->ni_lock, NTFS_INODE_MUTEX_SECURITY); in ntfs_get_security_by_id()
2000 err = -ENOMEM; in ntfs_get_security_by_id()
2006 err = -EINVAL; in ntfs_get_security_by_id()
2019 t32 = le32_to_cpu(sii_e->sec_hdr.size); in ntfs_get_security_by_id()
2021 err = -EINVAL; in ntfs_get_security_by_id()
2026 /* Looks like too big security. 0x10000 - is arbitrary big number. */ in ntfs_get_security_by_id()
2027 err = -EFBIG; in ntfs_get_security_by_id()
2031 *size = t32 - sizeof(struct SECURITY_HDR); in ntfs_get_security_by_id()
2035 err = -ENOMEM; in ntfs_get_security_by_id()
2039 err = ntfs_read_run_nb(sbi, &ni->file.run, in ntfs_get_security_by_id()
2040 le64_to_cpu(sii_e->sec_hdr.off), &d_security, in ntfs_get_security_by_id()
2045 if (memcmp(&d_security, &sii_e->sec_hdr, sizeof(d_security))) { in ntfs_get_security_by_id()
2046 err = -EINVAL; in ntfs_get_security_by_id()
2050 err = ntfs_read_run_nb(sbi, &ni->file.run, in ntfs_get_security_by_id()
2051 le64_to_cpu(sii_e->sec_hdr.off) + in ntfs_get_security_by_id()
2069 * ntfs_insert_security - Insert security descriptor into $Secure::SDS.
2084 struct ntfs_inode *ni = sbi->security.ni; in ntfs_insert_security()
2085 struct ntfs_index *indx_sdh = &sbi->security.index_sdh; in ntfs_insert_security()
2086 struct ntfs_index *indx_sii = &sbi->security.index_sii; in ntfs_insert_security()
2113 return -ENOMEM; in ntfs_insert_security()
2115 mutex_lock_nested(&ni->ni_lock, NTFS_INODE_MUTEX_SECURITY); in ntfs_insert_security()
2119 err = -ENOMEM; in ntfs_insert_security()
2125 err = -EINVAL; in ntfs_insert_security()
2131 err = -EINVAL; in ntfs_insert_security()
2137 * Use "SDH" and hash -> to get the offset in "SDS". in ntfs_insert_security()
2140 &d_security->key.sec_id, &diff, (struct NTFS_DE **)&e, in ntfs_insert_security()
2146 if (le32_to_cpu(e->sec_hdr.size) == new_sec_size) { in ntfs_insert_security()
2147 err = ntfs_read_run_nb(sbi, &ni->file.run, in ntfs_insert_security()
2148 le64_to_cpu(e->sec_hdr.off), in ntfs_insert_security()
2153 if (le32_to_cpu(d_security->size) == new_sec_size && in ntfs_insert_security()
2154 d_security->key.hash == hash_key.hash && in ntfs_insert_security()
2157 *security_id = d_security->key.sec_id; in ntfs_insert_security()
2168 if (!e || e->key.hash != hash_key.hash) in ntfs_insert_security()
2173 next = sbi->security.next_off & (SecurityDescriptorsBlockSize - 1); in ntfs_insert_security()
2174 left = SecurityDescriptorsBlockSize - next; in ntfs_insert_security()
2178 /* Zero "left" bytes from sbi->security.next_off. */ in ntfs_insert_security()
2179 sbi->security.next_off += SecurityDescriptorsBlockSize + left; in ntfs_insert_security()
2183 //used = ni->vfs_inode.i_size & (SecurityDescriptorsBlockSize - 1); in ntfs_insert_security()
2187 * 0x40438 == ni->vfs_inode.i_size in ntfs_insert_security()
2188 * 0x00440 == sbi->security.next_off in ntfs_insert_security()
2189 * need to zero [0x438-0x440) in ntfs_insert_security()
2191 * u32 tozero = next - used; in ntfs_insert_security()
2192 * zero "tozero" bytes from sbi->security.next_off - tozero in ntfs_insert_security()
2196 d_security->key.hash = hash_key.hash; in ntfs_insert_security()
2197 d_security->key.sec_id = cpu_to_le32(sbi->security.next_id); in ntfs_insert_security()
2198 d_security->off = cpu_to_le64(sbi->security.next_off); in ntfs_insert_security()
2199 d_security->size = cpu_to_le32(new_sec_size); in ntfs_insert_security()
2203 err = ntfs_sb_write_run(sbi, &ni->file.run, sbi->security.next_off, in ntfs_insert_security()
2209 mirr_off = sbi->security.next_off + SecurityDescriptorsBlockSize; in ntfs_insert_security()
2212 if (new_sds_size > ni->vfs_inode.i_size) { in ntfs_insert_security()
2214 ARRAY_SIZE(SDS_NAME), &ni->file.run, in ntfs_insert_security()
2221 err = ntfs_sb_write_run(sbi, &ni->file.run, mirr_off, d_security, in ntfs_insert_security()
2232 sii_e.de.key_size = cpu_to_le16(sizeof(d_security->key.sec_id)); in ntfs_insert_security()
2235 sii_e.sec_id = d_security->key.sec_id; in ntfs_insert_security()
2251 sdh_e.key.hash = d_security->key.hash; in ntfs_insert_security()
2252 sdh_e.key.sec_id = d_security->key.sec_id; in ntfs_insert_security()
2263 *security_id = d_security->key.sec_id; in ntfs_insert_security()
2268 sbi->security.next_id += 1; in ntfs_insert_security()
2269 sbi->security.next_off += aligned_sec_size; in ntfs_insert_security()
2273 mark_inode_dirty(&ni->vfs_inode); in ntfs_insert_security()
2281 * ntfs_reparse_init - Load and parse $Extend/$Reparse.
2286 struct ntfs_inode *ni = sbi->reparse.ni; in ntfs_reparse_init()
2287 struct ntfs_index *indx = &sbi->reparse.index_r; in ntfs_reparse_init()
2299 err = -EINVAL; in ntfs_reparse_init()
2304 if (root_r->type != ATTR_ZERO || in ntfs_reparse_init()
2305 root_r->rule != NTFS_COLLATION_TYPE_UINTS) { in ntfs_reparse_init()
2306 err = -EINVAL; in ntfs_reparse_init()
2319 * ntfs_objid_init - Load and parse $Extend/$ObjId.
2324 struct ntfs_inode *ni = sbi->objid.ni; in ntfs_objid_init()
2325 struct ntfs_index *indx = &sbi->objid.index_o; in ntfs_objid_init()
2337 err = -EINVAL; in ntfs_objid_init()
2342 if (root->type != ATTR_ZERO || in ntfs_objid_init()
2343 root->rule != NTFS_COLLATION_TYPE_UINTS) { in ntfs_objid_init()
2344 err = -EINVAL; in ntfs_objid_init()
2359 struct ntfs_inode *ni = sbi->objid.ni; in ntfs_objid_remove()
2360 struct ntfs_index *indx = &sbi->objid.index_o; in ntfs_objid_remove()
2363 return -EINVAL; in ntfs_objid_remove()
2365 mutex_lock_nested(&ni->ni_lock, NTFS_INODE_MUTEX_OBJID); in ntfs_objid_remove()
2369 mark_inode_dirty(&ni->vfs_inode); in ntfs_objid_remove()
2379 struct ntfs_inode *ni = sbi->reparse.ni; in ntfs_insert_reparse()
2380 struct ntfs_index *indx = &sbi->reparse.index_r; in ntfs_insert_reparse()
2384 return -EINVAL; in ntfs_insert_reparse()
2395 mutex_lock_nested(&ni->ni_lock, NTFS_INODE_MUTEX_REPARSE); in ntfs_insert_reparse()
2399 mark_inode_dirty(&ni->vfs_inode); in ntfs_insert_reparse()
2409 struct ntfs_inode *ni = sbi->reparse.ni; in ntfs_remove_reparse()
2410 struct ntfs_index *indx = &sbi->reparse.index_r; in ntfs_remove_reparse()
2417 return -EINVAL; in ntfs_remove_reparse()
2422 mutex_lock_nested(&ni->ni_lock, NTFS_INODE_MUTEX_REPARSE); in ntfs_remove_reparse()
2431 err = -ENOMEM; in ntfs_remove_reparse()
2437 err = -EINVAL; in ntfs_remove_reparse()
2441 /* 1 - forces to ignore rkey.ReparseTag when comparing keys. */ in ntfs_remove_reparse()
2447 if (memcmp(&re->key.ref, ref, sizeof(*ref))) { in ntfs_remove_reparse()
2452 memcpy(&rkey, &re->key, sizeof(rkey)); in ntfs_remove_reparse()
2465 mark_inode_dirty(&ni->vfs_inode); in ntfs_remove_reparse()
2474 ntfs_unmap_meta(sbi->sb, lcn, len); in ntfs_unmap_and_discard()
2481 struct wnd_bitmap *wnd = &sbi->used.bitmap; in mark_as_free_ex()
2484 down_write_nested(&wnd->rw_lock, BITMAP_MUTEX_CLUSTERS); in mark_as_free_ex()
2486 /* mark volume as dirty out of wnd->rw_lock */ in mark_as_free_ex()
2519 zlen = min(zone_len + len, sbi->zone_max); in mark_as_free_ex()
2525 if (zlen == sbi->zone_max) in mark_as_free_ex()
2540 up_write(&wnd->rw_lock); in mark_as_free_ex()
2546 * run_deallocate - Deallocate clusters.
2569 for (i = 0; i < fname->len; ++i) { in name_has_forbidden_chars()
2570 ch = le16_to_cpu(fname->name[i]); in name_has_forbidden_chars()
2596 if (fname->len > 0) { in name_has_forbidden_chars()
2597 ch = le16_to_cpu(fname->name[fname->len - 1]); in name_has_forbidden_chars()
2609 const __le16 *name = fname->name; in is_reserved_name()
2610 int len = fname->len; in is_reserved_name()
2611 const u16 *upcase = sbi->upcase; in is_reserved_name()
2638 * valid_windows_name - Check if a file name is valid in Windows.
2647 * ntfs_set_label - updates current ntfs label.
2654 struct ntfs_inode *ni = sbi->volume.ni; in ntfs_set_label()
2659 return -ENOMEM; in ntfs_set_label()
2661 err = ntfs_nls_to_utf16(sbi, label, len, uni, (PATH_MAX - 2) / 2, in ntfs_set_label()
2666 uni_bytes = uni->len * sizeof(u16); in ntfs_set_label()
2668 ntfs_warn(sbi->sb, "new label is too long"); in ntfs_set_label()
2669 err = -EFBIG; in ntfs_set_label()
2683 /* write new label in on-disk struct. */ in ntfs_set_label()
2684 memcpy(resident_data(attr), uni->name, uni_bytes); in ntfs_set_label()
2687 if (len >= ARRAY_SIZE(sbi->volume.label)) in ntfs_set_label()
2688 len = ARRAY_SIZE(sbi->volume.label) - 1; in ntfs_set_label()
2689 memcpy(sbi->volume.label, label, len); in ntfs_set_label()
2690 sbi->volume.label[len] = 0; in ntfs_set_label()
2691 mark_inode_dirty_sync(&ni->vfs_inode); in ntfs_set_label()
2697 err = _ni_write_inode(&ni->vfs_inode, 0); in ntfs_set_label()