inode.c (78ab59fee07f22464f32eafebab2bd97ba94ff2d) inode.c (d3624466b56dd5b1886c1dff500525b544c19c83)
1// SPDX-License-Identifier: GPL-2.0
2/*
3 *
4 * Copyright (C) 2019-2021 Paragon Software GmbH, All rights reserved.
5 *
6 */
7
8#include <linux/blkdev.h>

--- 75 unchanged lines hidden (view full) ---

84 goto out;
85 } else if (!is_rec_inuse(rec)) {
86 err = -EINVAL;
87 ntfs_err(sb, "Inode r=%x is not in use!", (u32)ino);
88 goto out;
89 }
90
91 if (le32_to_cpu(rec->total) != sbi->record_size) {
1// SPDX-License-Identifier: GPL-2.0
2/*
3 *
4 * Copyright (C) 2019-2021 Paragon Software GmbH, All rights reserved.
5 *
6 */
7
8#include <linux/blkdev.h>

--- 75 unchanged lines hidden (view full) ---

84 goto out;
85 } else if (!is_rec_inuse(rec)) {
86 err = -EINVAL;
87 ntfs_err(sb, "Inode r=%x is not in use!", (u32)ino);
88 goto out;
89 }
90
91 if (le32_to_cpu(rec->total) != sbi->record_size) {
92 // Bad inode?
92 /* Bad inode? */
93 err = -EINVAL;
94 goto out;
95 }
96
97 if (!is_rec_base(rec))
98 goto Ok;
99
100 /* Record should contain $I30 root. */

--- 499 unchanged lines hidden (view full) ---

600
601 valid = ni->i_valid;
602
603 if (ctx == GET_BLOCK_DIRECT_IO_W) {
604 /* ntfs_direct_IO will update ni->i_valid. */
605 if (vbo >= valid)
606 set_buffer_new(bh);
607 } else if (create) {
93 err = -EINVAL;
94 goto out;
95 }
96
97 if (!is_rec_base(rec))
98 goto Ok;
99
100 /* Record should contain $I30 root. */

--- 499 unchanged lines hidden (view full) ---

600
601 valid = ni->i_valid;
602
603 if (ctx == GET_BLOCK_DIRECT_IO_W) {
604 /* ntfs_direct_IO will update ni->i_valid. */
605 if (vbo >= valid)
606 set_buffer_new(bh);
607 } else if (create) {
608 /*normal write*/
608 /* Normal write. */
609 if (bytes > bh->b_size)
610 bytes = bh->b_size;
611
612 if (vbo >= valid)
613 set_buffer_new(bh);
614
615 if (vbo + bytes > valid) {
616 ni->i_valid = vbo + bytes;

--- 469 unchanged lines hidden (view full) ---

1086 data = Add2Ptr(data, PAGE_SIZE);
1087 }
1088 return 0;
1089}
1090
1091/*
1092 * ntfs_reparse_bytes
1093 *
609 if (bytes > bh->b_size)
610 bytes = bh->b_size;
611
612 if (vbo >= valid)
613 set_buffer_new(bh);
614
615 if (vbo + bytes > valid) {
616 ni->i_valid = vbo + bytes;

--- 469 unchanged lines hidden (view full) ---

1086 data = Add2Ptr(data, PAGE_SIZE);
1087 }
1088 return 0;
1089}
1090
1091/*
1092 * ntfs_reparse_bytes
1093 *
1094 * Number of bytes to for REPARSE_DATA_BUFFER(IO_REPARSE_TAG_SYMLINK)
1094 * Number of bytes for REPARSE_DATA_BUFFER(IO_REPARSE_TAG_SYMLINK)
1095 * for unicode string of @uni_len length.
1096 */
1097static inline u32 ntfs_reparse_bytes(u32 uni_len)
1098{
1099 /* Header + unicode string + decorated unicode string. */
1100 return sizeof(short) * (2 * uni_len + 4) +
1101 offsetof(struct REPARSE_DATA_BUFFER,
1102 SymbolicLinkReparseBuffer.PathBuffer);

--- 97 unchanged lines hidden (view full) ---

1200 struct REPARSE_DATA_BUFFER *rp = NULL;
1201 bool rp_inserted = false;
1202
1203 dir_root = indx_get_root(&dir_ni->dir, dir_ni, NULL, NULL);
1204 if (!dir_root)
1205 return ERR_PTR(-EINVAL);
1206
1207 if (S_ISDIR(mode)) {
1095 * for unicode string of @uni_len length.
1096 */
1097static inline u32 ntfs_reparse_bytes(u32 uni_len)
1098{
1099 /* Header + unicode string + decorated unicode string. */
1100 return sizeof(short) * (2 * uni_len + 4) +
1101 offsetof(struct REPARSE_DATA_BUFFER,
1102 SymbolicLinkReparseBuffer.PathBuffer);

--- 97 unchanged lines hidden (view full) ---

1200 struct REPARSE_DATA_BUFFER *rp = NULL;
1201 bool rp_inserted = false;
1202
1203 dir_root = indx_get_root(&dir_ni->dir, dir_ni, NULL, NULL);
1204 if (!dir_root)
1205 return ERR_PTR(-EINVAL);
1206
1207 if (S_ISDIR(mode)) {
1208 /* use parent's directory attributes */
1208 /* Use parent's directory attributes. */
1209 fa = dir_ni->std_fa | FILE_ATTRIBUTE_DIRECTORY |
1210 FILE_ATTRIBUTE_ARCHIVE;
1211 /*
1209 fa = dir_ni->std_fa | FILE_ATTRIBUTE_DIRECTORY |
1210 FILE_ATTRIBUTE_ARCHIVE;
1211 /*
1212 * By default child directory inherits parent attributes
1213 * root directory is hidden + system
1214 * Make an exception for children in root
1212 * By default child directory inherits parent attributes.
1213 * Root directory is hidden + system.
1214 * Make an exception for children in root.
1215 */
1216 if (dir->i_ino == MFT_REC_ROOT)
1217 fa &= ~(FILE_ATTRIBUTE_HIDDEN | FILE_ATTRIBUTE_SYSTEM);
1218 } else if (S_ISLNK(mode)) {
1219 /* It is good idea that link should be the same type (file/dir) as target */
1220 fa = FILE_ATTRIBUTE_REPARSE_POINT;
1221
1222 /*
1215 */
1216 if (dir->i_ino == MFT_REC_ROOT)
1217 fa &= ~(FILE_ATTRIBUTE_HIDDEN | FILE_ATTRIBUTE_SYSTEM);
1218 } else if (S_ISLNK(mode)) {
1219 /* It is good idea that link should be the same type (file/dir) as target */
1220 fa = FILE_ATTRIBUTE_REPARSE_POINT;
1221
1222 /*
1223 * linux: there are dir/file/symlink and so on.
1224 * NTFS: symlinks are "dir + reparse" or "file + reparse".
1223 * Linux: there are dir/file/symlink and so on.
1224 * NTFS: symlinks are "dir + reparse" or "file + reparse"
1225 * It is good idea to create:
1226 * dir + reparse if 'symname' points to directory
1227 * or
1228 * file + reparse if 'symname' points to file
1229 * Unfortunately kern_path hangs if symname contains 'dir'.
1230 */
1231
1232 /*

--- 622 unchanged lines hidden (view full) ---

1855 err = sizeof("OneDrive") - 1;
1856 if (err > buflen)
1857 err = buflen;
1858 memcpy(buffer, "OneDrive", err);
1859 goto out;
1860
1861 default:
1862 if (IsReparseTagMicrosoft(rp->ReparseTag)) {
1225 * It is good idea to create:
1226 * dir + reparse if 'symname' points to directory
1227 * or
1228 * file + reparse if 'symname' points to file
1229 * Unfortunately kern_path hangs if symname contains 'dir'.
1230 */
1231
1232 /*

--- 622 unchanged lines hidden (view full) ---

1855 err = sizeof("OneDrive") - 1;
1856 if (err > buflen)
1857 err = buflen;
1858 memcpy(buffer, "OneDrive", err);
1859 goto out;
1860
1861 default:
1862 if (IsReparseTagMicrosoft(rp->ReparseTag)) {
1863 /* unknown Microsoft Tag */
1863 /* Unknown Microsoft Tag. */
1864 goto out;
1865 }
1866 if (!IsReparseTagNameSurrogate(rp->ReparseTag) ||
1867 i_size <= sizeof(struct REPARSE_POINT)) {
1868 goto out;
1869 }
1870
1871 /* Users tag. */

--- 86 unchanged lines hidden ---
1864 goto out;
1865 }
1866 if (!IsReparseTagNameSurrogate(rp->ReparseTag) ||
1867 i_size <= sizeof(struct REPARSE_POINT)) {
1868 goto out;
1869 }
1870
1871 /* Users tag. */

--- 86 unchanged lines hidden ---