Skip to content

Commit 716308a

Browse files
author
Christoph Hellwig
committed
init: add an init_stat helper
Add a simple helper to stat with a kernel space file name and switch the early init code over to it. Signed-off-by: Christoph Hellwig <[email protected]>
1 parent 5fee64f commit 716308a

File tree

4 files changed

+20
-2
lines changed

4 files changed

+20
-2
lines changed

drivers/md/md-autodetect.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#include <linux/mount.h>
66
#include <linux/major.h>
77
#include <linux/delay.h>
8+
#include <linux/init_syscalls.h>
89
#include <linux/raid/detect.h>
910
#include <linux/raid/md_u.h>
1011
#include <linux/raid/md_p.h>
@@ -151,7 +152,7 @@ static void __init md_setup_drive(struct md_setup_args *args)
151152
if (strncmp(devname, "/dev/", 5) == 0)
152153
devname += 5;
153154
snprintf(comp_name, 63, "/dev/%s", devname);
154-
if (vfs_stat(comp_name, &stat) == 0 && S_ISBLK(stat.mode))
155+
if (init_stat(comp_name, &stat, 0) == 0 && S_ISBLK(stat.mode))
155156
dev = new_decode_dev(stat.rdev);
156157
if (!dev) {
157158
pr_warn("md: Unknown device name: %s\n", devname);

fs/init.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,21 @@ int __init init_eaccess(const char *filename)
122122
return error;
123123
}
124124

125+
int __init init_stat(const char *filename, struct kstat *stat, int flags)
126+
{
127+
int lookup_flags = (flags & AT_SYMLINK_NOFOLLOW) ? 0 : LOOKUP_FOLLOW;
128+
struct path path;
129+
int error;
130+
131+
error = kern_path(filename, lookup_flags, &path);
132+
if (error)
133+
return error;
134+
error = vfs_getattr(&path, stat, STATX_BASIC_STATS,
135+
flags | AT_NO_AUTOMOUNT);
136+
path_put(&path);
137+
return error;
138+
}
139+
125140
int __init init_mknod(const char *filename, umode_t mode, unsigned int dev)
126141
{
127142
struct dentry *dentry;

include/linux/init_syscalls.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ int __init init_chroot(const char *filename);
88
int __init init_chown(const char *filename, uid_t user, gid_t group, int flags);
99
int __init init_chmod(const char *filename, umode_t mode);
1010
int __init init_eaccess(const char *filename);
11+
int __init init_stat(const char *filename, struct kstat *stat, int flags);
1112
int __init init_mknod(const char *filename, umode_t mode, unsigned int dev);
1213
int __init init_link(const char *oldname, const char *newname);
1314
int __init init_symlink(const char *oldname, const char *newname);

init/initramfs.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,8 @@ static void __init clean_path(char *path, umode_t fmode)
298298
{
299299
struct kstat st;
300300

301-
if (!vfs_lstat(path, &st) && (st.mode ^ fmode) & S_IFMT) {
301+
if (init_stat(path, &st, AT_SYMLINK_NOFOLLOW) &&
302+
(st.mode ^ fmode) & S_IFMT) {
302303
if (S_ISDIR(st.mode))
303304
init_rmdir(path);
304305
else

0 commit comments

Comments
 (0)