]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
fs/adfs: newdir: split out directory commit from update
authorRussell King <rmk+kernel@armlinux.org.uk>
Mon, 9 Dec 2019 11:10:47 +0000 (11:10 +0000)
committerAl Viro <viro@zeniv.linux.org.uk>
Tue, 21 Jan 2020 01:12:42 +0000 (20:12 -0500)
After changing a directory, we need to update the sequence numbers and
calculate the new check byte before the directory is scheduled to be
written back to the media.  Since this needs to happen for any change
to the directory, move this into a separate method.

Signed-off-by: Russell King <rmk+kernel@armlinux.org.uk>
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
fs/adfs/adfs.h
fs/adfs/dir.c
fs/adfs/dir_f.c

index 1f431a42e14c8e1e91bcc86d2c6bc5182076563e..c05555252fecf7fefb3b7581c9ae5286e23a4224 100644 (file)
@@ -130,6 +130,7 @@ struct adfs_dir_ops {
        int     (*update)(struct adfs_dir *dir, struct object_info *obj);
        int     (*create)(struct adfs_dir *dir, struct object_info *obj);
        int     (*remove)(struct adfs_dir *dir, struct object_info *obj);
+       int     (*commit)(struct adfs_dir *dir);
 };
 
 struct adfs_discmap {
index 7fda44464121efcf4dbceeb2eff0f2cdb82c0322..3d4bbe836fb58401772ac52f2f00ed70001d74c8 100644 (file)
@@ -293,6 +293,10 @@ adfs_dir_update(struct super_block *sb, struct object_info *obj, int wait)
                goto unlock;
 
        ret = ops->update(&dir, obj);
+       if (ret)
+               goto forget;
+
+       ret = ops->commit(&dir);
        if (ret)
                goto forget;
        up_write(&adfs_dir_rwsem);
index 36cfadb2b893651452e71438963426295259fc7f..30d526fecc3f40fbd69c0b216e2f89a6fe44e3e2 100644 (file)
@@ -292,25 +292,24 @@ static int adfs_f_update(struct adfs_dir *dir, struct object_info *obj)
        adfs_obj2dir(&de, obj);
 
        /* Write the directory entry back to the directory */
-       ret = adfs_dir_copyto(dir, pos, &de, 26);
-       if (ret)
-               return ret;
-       /*
-        * Increment directory sequence number
-        */
+       return adfs_dir_copyto(dir, offset, &de, 26);
+}
+
+static int adfs_f_commit(struct adfs_dir *dir)
+{
+       int ret;
+
+       /* Increment directory sequence number */
        dir->dirhead->startmasseq += 1;
        dir->newtail->endmasseq += 1;
 
-       ret = adfs_dir_checkbyte(dir);
-       /*
-        * Update directory check byte
-        */
-       dir->newtail->dircheckbyte = ret;
+       /* Update directory check byte */
+       dir->newtail->dircheckbyte = adfs_dir_checkbyte(dir);
 
+       /* Make sure the directory still validates correctly */
        ret = adfs_f_validate(dir);
        if (ret)
-               adfs_error(dir->sb, "whoops!  I broke a directory!");
+               adfs_msg(dir->sb, KERN_ERR, "error: update broke directory");
 
        return ret;
 }
@@ -321,4 +320,5 @@ const struct adfs_dir_ops adfs_f_dir_ops = {
        .setpos         = adfs_f_setpos,
        .getnext        = adfs_f_getnext,
        .update         = adfs_f_update,
+       .commit         = adfs_f_commit,
 };