linux-fsdevel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Konstantin Komarov <almaz.alexandrovich@paragon-software.com>
To: <ntfs3@lists.linux.dev>, LKML <linux-kernel@vger.kernel.org>,
	Linux-fsdevel <linux-fsdevel@vger.kernel.org>
Subject: [PATCH 06/11] fs/ntfs3: Redesign ntfs_create_inode to return error code instead of inode
Date: Wed, 17 Apr 2024 16:07:18 +0300	[thread overview]
Message-ID: <d282dfd1-82d0-4eda-8b9d-7b762f62a3dc@paragon-software.com> (raw)
In-Reply-To: <6c99c1bd-448d-4301-8404-50df34e8df8e@paragon-software.com>

Signed-off-by: Konstantin Komarov <almaz.alexandrovich@paragon-software.com>
---
  fs/ntfs3/inode.c   | 22 +++++++++++-----------
  fs/ntfs3/namei.c   | 31 ++++++++-----------------------
  fs/ntfs3/ntfs_fs.h |  9 ++++-----
  3 files changed, 23 insertions(+), 39 deletions(-)

diff --git a/fs/ntfs3/inode.c b/fs/ntfs3/inode.c
index eb7a8c9fba01..85a10d4a74c4 100644
--- a/fs/ntfs3/inode.c
+++ b/fs/ntfs3/inode.c
@@ -1210,11 +1210,10 @@ ntfs_create_reparse_buffer(struct ntfs_sb_info 
*sbi, const char *symname,
   *
   * NOTE: if fnd != NULL (ntfs_atomic_open) then @dir is locked
   */
-struct inode *ntfs_create_inode(struct mnt_idmap *idmap, struct inode *dir,
-                struct dentry *dentry,
-                const struct cpu_str *uni, umode_t mode,
-                dev_t dev, const char *symname, u32 size,
-                struct ntfs_fnd *fnd)
+int ntfs_create_inode(struct mnt_idmap *idmap, struct inode *dir,
+              struct dentry *dentry, const struct cpu_str *uni,
+              umode_t mode, dev_t dev, const char *symname, u32 size,
+              struct ntfs_fnd *fnd)
  {
      int err;
      struct super_block *sb = dir->i_sb;
@@ -1239,6 +1238,9 @@ struct inode *ntfs_create_inode(struct mnt_idmap 
*idmap, struct inode *dir,
      struct REPARSE_DATA_BUFFER *rp = NULL;
      bool rp_inserted = false;

+    /* New file will be resident or non resident. */
+    const bool new_file_resident = 1;
+
      if (!fnd)
          ni_lock_dir(dir_ni);

@@ -1478,7 +1480,7 @@ struct inode *ntfs_create_inode(struct mnt_idmap 
*idmap, struct inode *dir,
          attr->size = cpu_to_le32(SIZEOF_RESIDENT);
          attr->name_off = SIZEOF_RESIDENT_LE;
          attr->res.data_off = SIZEOF_RESIDENT_LE;
-    } else if (S_ISREG(mode)) {
+    } else if (!new_file_resident && S_ISREG(mode)) {
          /*
           * Regular file. Create empty non resident data attribute.
           */
@@ -1715,12 +1717,10 @@ struct inode *ntfs_create_inode(struct mnt_idmap 
*idmap, struct inode *dir,
      if (!fnd)
          ni_unlock(dir_ni);

-    if (err)
-        return ERR_PTR(err);
-
-    unlock_new_inode(inode);
+    if (!err)
+        unlock_new_inode(inode);

-    return inode;
+    return err;
  }

  int ntfs_link_inode(struct inode *inode, struct dentry *dentry)
diff --git a/fs/ntfs3/namei.c b/fs/ntfs3/namei.c
index edb6a7141246..71498421ce60 100644
--- a/fs/ntfs3/namei.c
+++ b/fs/ntfs3/namei.c
@@ -107,12 +107,8 @@ static struct dentry *ntfs_lookup(struct inode 
*dir, struct dentry *dentry,
  static int ntfs_create(struct mnt_idmap *idmap, struct inode *dir,
                 struct dentry *dentry, umode_t mode, bool excl)
  {
-    struct inode *inode;
-
-    inode = ntfs_create_inode(idmap, dir, dentry, NULL, S_IFREG | mode, 0,
-                  NULL, 0, NULL);
-
-    return IS_ERR(inode) ? PTR_ERR(inode) : 0;
+    return ntfs_create_inode(idmap, dir, dentry, NULL, S_IFREG | mode, 0,
+                 NULL, 0, NULL);
  }

  /*
@@ -123,12 +119,8 @@ static int ntfs_create(struct mnt_idmap *idmap, 
struct inode *dir,
  static int ntfs_mknod(struct mnt_idmap *idmap, struct inode *dir,
                struct dentry *dentry, umode_t mode, dev_t rdev)
  {
-    struct inode *inode;
-
-    inode = ntfs_create_inode(idmap, dir, dentry, NULL, mode, rdev, 
NULL, 0,
-                  NULL);
-
-    return IS_ERR(inode) ? PTR_ERR(inode) : 0;
+    return ntfs_create_inode(idmap, dir, dentry, NULL, mode, rdev, NULL, 0,
+                 NULL);
  }

  /*
@@ -200,15 +192,12 @@ static int ntfs_symlink(struct mnt_idmap *idmap, 
struct inode *dir,
              struct dentry *dentry, const char *symname)
  {
      u32 size = strlen(symname);
-    struct inode *inode;

      if (unlikely(ntfs3_forced_shutdown(dir->i_sb)))
          return -EIO;

-    inode = ntfs_create_inode(idmap, dir, dentry, NULL, S_IFLNK | 0777, 0,
-                  symname, size, NULL);
-
-    return IS_ERR(inode) ? PTR_ERR(inode) : 0;
+    return ntfs_create_inode(idmap, dir, dentry, NULL, S_IFLNK | 0777, 0,
+                 symname, size, NULL);
  }

  /*
@@ -217,12 +206,8 @@ static int ntfs_symlink(struct mnt_idmap *idmap, 
struct inode *dir,
  static int ntfs_mkdir(struct mnt_idmap *idmap, struct inode *dir,
                struct dentry *dentry, umode_t mode)
  {
-    struct inode *inode;
-
-    inode = ntfs_create_inode(idmap, dir, dentry, NULL, S_IFDIR | mode, 0,
-                  NULL, 0, NULL);
-
-    return IS_ERR(inode) ? PTR_ERR(inode) : 0;
+    return ntfs_create_inode(idmap, dir, dentry, NULL, S_IFDIR | mode, 0,
+                 NULL, 0, NULL);
  }

  /*
diff --git a/fs/ntfs3/ntfs_fs.h b/fs/ntfs3/ntfs_fs.h
index 79356fd29a14..3db6a61f61dc 100644
--- a/fs/ntfs3/ntfs_fs.h
+++ b/fs/ntfs3/ntfs_fs.h
@@ -714,11 +714,10 @@ int ntfs_sync_inode(struct inode *inode);
  int ntfs_flush_inodes(struct super_block *sb, struct inode *i1,
                struct inode *i2);
  int inode_write_data(struct inode *inode, const void *data, size_t bytes);
-struct inode *ntfs_create_inode(struct mnt_idmap *idmap, struct inode *dir,
-                struct dentry *dentry,
-                const struct cpu_str *uni, umode_t mode,
-                dev_t dev, const char *symname, u32 size,
-                struct ntfs_fnd *fnd);
+int ntfs_create_inode(struct mnt_idmap *idmap, struct inode *dir,
+              struct dentry *dentry, const struct cpu_str *uni,
+              umode_t mode, dev_t dev, const char *symname, u32 size,
+              struct ntfs_fnd *fnd);
  int ntfs_link_inode(struct inode *inode, struct dentry *dentry);
  int ntfs_unlink_inode(struct inode *dir, const struct dentry *dentry);
  void ntfs_evict_inode(struct inode *inode);
-- 
2.34.1


  parent reply	other threads:[~2024-04-17 13:07 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-04-17 13:03 [PATCH 00/11] Bugfix and refactoring Konstantin Komarov
2024-04-17 13:04 ` [PATCH 01/11] fs/ntfs3: Remove max link count info display during driver init Konstantin Komarov
2024-04-17 13:04 ` [PATCH 02/11] fs/ntfs3: Missed le32_to_cpu conversion Konstantin Komarov
2024-04-17 13:06 ` [PATCH 03/11] fs/ntfs3: Mark volume as dirty if xattr is broken Konstantin Komarov
2024-04-17 13:06 ` [PATCH 04/11] fs/ntfs3: Use variable length array instead of fixed size Konstantin Komarov
2024-04-17 13:06 ` [PATCH 05/11] fs/ntfs3: Use 64 bit variable to avoid 32 bit overflow Konstantin Komarov
2024-04-17 13:07 ` Konstantin Komarov [this message]
2024-04-17 13:07 ` [PATCH 07/11] fs/ntfs3: Check 'folio' pointer for NULL Konstantin Komarov
2024-04-17 13:08 ` [PATCH 08/11] fs/ntfs3: Always make file nonresident if fallocate (xfstest 438) Konstantin Komarov
2024-04-17 13:08 ` [PATCH 09/11] fs/ntfs3: Optimize to store sorted attribute definition table Konstantin Komarov
2024-04-17 13:09 ` [PATCH 10/11] fs/ntfs3: Remove cached label from sbi Konstantin Komarov
2024-04-22 20:42   ` Nathan Chancellor
2024-04-17 13:10 ` [PATCH 11/11] fs/ntfs3: Taking DOS names into account during link counting Konstantin Komarov
2024-04-18  6:31   ` Johan Hovold
2024-04-23  6:59     ` Konstantin Komarov
2024-04-18  6:42 ` [PATCH 00/11] Bugfix and refactoring Johan Hovold

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=d282dfd1-82d0-4eda-8b9d-7b762f62a3dc@paragon-software.com \
    --to=almaz.alexandrovich@paragon-software.com \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=ntfs3@lists.linux.dev \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).