Skip to content

Commit 28dc837

Browse files
committed
working
1 parent 7822b81 commit 28dc837

File tree

7 files changed

+116
-131
lines changed

7 files changed

+116
-131
lines changed

.github/workflows/qemu-init.sh

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/bin/sh
22

3-
busybox insmod rust_minimal.ko
4-
busybox rmmod rust_minimal.ko
3+
# busybox insmod rust_minimal.ko
4+
# busybox rmmod rust_minimal.ko
55

66
# busybox insmod rust_print.ko
77
# busybox rmmod rust_print.ko
@@ -40,12 +40,18 @@ busybox rmmod rust_minimal.ko
4040
busybox insmod rust_seq_file.ko
4141
busybox mkdir proc
4242
busybox mount -t proc proc /proc
43+
busybox mkdir debugfs
44+
busybox mount -t debugfs debugfs /debugfs
4345
export RUST_SEQ_MINOR=$(busybox cat /proc/misc | busybox grep rust_seq_file | busybox cut -d ' ' -f 1)
4446
busybox mknod /dev/rust_seq_file0 c 10 $RUST_SEQ_MINOR
47+
busybox echo "reading from device"
4548
busybox cat /dev/rust_seq_file0
4649
busybox cat /dev/rust_seq_file0
47-
busybox cat /proc/rust_seq_file
50+
busybox echo "reading debug file"
51+
busybox cat /debugfs/rust_seq_file
52+
busybox echo "removing device file"
4853
busybox rm /dev/rust_seq_file0
54+
busybox echo "removing module"
4955
busybox rmmod rust_seq_file.ko
5056

5157
busybox reboot -f

fs/debugfs/inode.c

Lines changed: 49 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
* See ./Documentation/core-api/kernel-api.rst for more details.
1111
*/
1212

13-
#define pr_fmt(fmt) "debugfs: " fmt
13+
#define pr_fmt(fmt) "debugfs: " fmt
1414

1515
#include <linux/module.h>
1616
#include <linux/fs.h>
@@ -30,7 +30,7 @@
3030

3131
#include "internal.h"
3232

33-
#define DEBUGFS_DEFAULT_MODE 0700
33+
#define DEBUGFS_DEFAULT_MODE 0700
3434

3535
static struct vfsmount *debugfs_mount;
3636
static int debugfs_mount_count;
@@ -56,24 +56,24 @@ static int debugfs_setattr(struct user_namespace *mnt_userns,
5656
}
5757

5858
static const struct inode_operations debugfs_file_inode_operations = {
59-
.setattr = debugfs_setattr,
59+
.setattr = debugfs_setattr,
6060
};
6161
static const struct inode_operations debugfs_dir_inode_operations = {
62-
.lookup = simple_lookup,
63-
.setattr = debugfs_setattr,
62+
.lookup = simple_lookup,
63+
.setattr = debugfs_setattr,
6464
};
6565
static const struct inode_operations debugfs_symlink_inode_operations = {
66-
.get_link = simple_get_link,
67-
.setattr = debugfs_setattr,
66+
.get_link = simple_get_link,
67+
.setattr = debugfs_setattr,
6868
};
6969

7070
static struct inode *debugfs_get_inode(struct super_block *sb)
7171
{
7272
struct inode *inode = new_inode(sb);
7373
if (inode) {
7474
inode->i_ino = get_next_ino();
75-
inode->i_atime = inode->i_mtime =
76-
inode->i_ctime = current_time(inode);
75+
inode->i_atime = inode->i_mtime = inode->i_ctime =
76+
current_time(inode);
7777
}
7878
return inode;
7979
}
@@ -84,19 +84,12 @@ struct debugfs_mount_opts {
8484
umode_t mode;
8585
};
8686

87-
enum {
88-
Opt_uid,
89-
Opt_gid,
90-
Opt_mode,
91-
Opt_err
92-
};
87+
enum { Opt_uid, Opt_gid, Opt_mode, Opt_err };
9388

94-
static const match_table_t tokens = {
95-
{Opt_uid, "uid=%u"},
96-
{Opt_gid, "gid=%u"},
97-
{Opt_mode, "mode=%o"},
98-
{Opt_err, NULL}
99-
};
89+
static const match_table_t tokens = { { Opt_uid, "uid=%u" },
90+
{ Opt_gid, "gid=%u" },
91+
{ Opt_mode, "mode=%o" },
92+
{ Opt_err, NULL } };
10093

10194
struct debugfs_fs_info {
10295
struct debugfs_mount_opts mount_opts;
@@ -140,7 +133,7 @@ static int debugfs_parse_options(char *data, struct debugfs_mount_opts *opts)
140133
return -EINVAL;
141134
opts->mode = option & S_IALLUGO;
142135
break;
143-
/*
136+
/*
144137
* We might like to report bad mount options here;
145138
* but traditionally debugfs has ignored all mount options
146139
*/
@@ -206,10 +199,10 @@ static void debugfs_free_inode(struct inode *inode)
206199
}
207200

208201
static const struct super_operations debugfs_super_operations = {
209-
.statfs = simple_statfs,
210-
.remount_fs = debugfs_remount,
211-
.show_options = debugfs_show_options,
212-
.free_inode = debugfs_free_inode,
202+
.statfs = simple_statfs,
203+
.remount_fs = debugfs_remount,
204+
.show_options = debugfs_show_options,
205+
.free_inode = debugfs_free_inode,
213206
};
214207

215208
static void debugfs_release_dentry(struct dentry *dentry)
@@ -235,7 +228,7 @@ static const struct dentry_operations debugfs_dops = {
235228

236229
static int debug_fill_super(struct super_block *sb, void *data, int silent)
237230
{
238-
static const struct tree_descr debug_files[] = {{""}};
231+
static const struct tree_descr debug_files[] = { { "" } };
239232
struct debugfs_fs_info *fsi;
240233
int err;
241234

@@ -250,7 +243,7 @@ static int debug_fill_super(struct super_block *sb, void *data, int silent)
250243
if (err)
251244
goto fail;
252245

253-
err = simple_fill_super(sb, DEBUGFS_MAGIC, debug_files);
246+
err = simple_fill_super(sb, DEBUGFS_MAGIC, debug_files);
254247
if (err)
255248
goto fail;
256249

@@ -267,9 +260,8 @@ static int debug_fill_super(struct super_block *sb, void *data, int silent)
267260
return err;
268261
}
269262

270-
static struct dentry *debug_mount(struct file_system_type *fs_type,
271-
int flags, const char *dev_name,
272-
void *data)
263+
static struct dentry *debug_mount(struct file_system_type *fs_type, int flags,
264+
const char *dev_name, void *data)
273265
{
274266
if (!(debugfs_allow & DEBUGFS_ALLOW_API))
275267
return ERR_PTR(-EPERM);
@@ -278,10 +270,10 @@ static struct dentry *debug_mount(struct file_system_type *fs_type,
278270
}
279271

280272
static struct file_system_type debug_fs_type = {
281-
.owner = THIS_MODULE,
282-
.name = "debugfs",
283-
.mount = debug_mount,
284-
.kill_sb = kill_litter_super,
273+
.owner = THIS_MODULE,
274+
.name = "debugfs",
275+
.mount = debug_mount,
276+
.kill_sb = kill_litter_super,
285277
};
286278
MODULE_ALIAS_FS("debugfs");
287279

@@ -383,10 +375,10 @@ static struct dentry *end_creating(struct dentry *dentry)
383375
return dentry;
384376
}
385377

386-
static struct dentry *__debugfs_create_file(const char *name, umode_t mode,
387-
struct dentry *parent, void *data,
388-
const struct file_operations *proxy_fops,
389-
const struct file_operations *real_fops)
378+
static struct dentry *
379+
__debugfs_create_file(const char *name, umode_t mode, struct dentry *parent,
380+
void *data, const struct file_operations *proxy_fops,
381+
const struct file_operations *real_fops)
390382
{
391383
struct dentry *dentry;
392384
struct inode *inode;
@@ -417,7 +409,7 @@ static struct dentry *__debugfs_create_file(const char *name, umode_t mode,
417409
inode->i_op = &debugfs_file_inode_operations;
418410
inode->i_fop = proxy_fops;
419411
dentry->d_fsdata = (void *)((unsigned long)real_fops |
420-
DEBUGFS_FSDATA_IS_REAL_FOPS_BIT);
412+
DEBUGFS_FSDATA_IS_REAL_FOPS_BIT);
421413

422414
d_instantiate(dentry, inode);
423415
fsnotify_create(d_inode(dentry->d_parent), dentry);
@@ -455,11 +447,11 @@ struct dentry *debugfs_create_file(const char *name, umode_t mode,
455447
struct dentry *parent, void *data,
456448
const struct file_operations *fops)
457449
{
458-
459-
return __debugfs_create_file(name, mode, parent, data,
460-
fops ? &debugfs_full_proxy_file_operations :
461-
&debugfs_noop_file_operations,
462-
fops);
450+
return __debugfs_create_file(
451+
name, mode, parent, data,
452+
fops ? &debugfs_full_proxy_file_operations :
453+
&debugfs_noop_file_operations,
454+
fops);
463455
}
464456
EXPORT_SYMBOL_GPL(debugfs_create_file);
465457

@@ -491,14 +483,14 @@ EXPORT_SYMBOL_GPL(debugfs_create_file);
491483
* thus, may be used here.
492484
*/
493485
struct dentry *debugfs_create_file_unsafe(const char *name, umode_t mode,
494-
struct dentry *parent, void *data,
495-
const struct file_operations *fops)
486+
struct dentry *parent, void *data,
487+
const struct file_operations *fops)
496488
{
497-
498-
return __debugfs_create_file(name, mode, parent, data,
499-
fops ? &debugfs_open_proxy_file_operations :
500-
&debugfs_noop_file_operations,
501-
fops);
489+
return __debugfs_create_file(
490+
name, mode, parent, data,
491+
fops ? &debugfs_open_proxy_file_operations :
492+
&debugfs_noop_file_operations,
493+
fops);
502494
}
503495
EXPORT_SYMBOL_GPL(debugfs_create_file_unsafe);
504496

@@ -596,10 +588,8 @@ EXPORT_SYMBOL_GPL(debugfs_create_dir);
596588
*
597589
* @f should return what ->d_automount() would.
598590
*/
599-
struct dentry *debugfs_create_automount(const char *name,
600-
struct dentry *parent,
601-
debugfs_automount_t f,
602-
void *data)
591+
struct dentry *debugfs_create_automount(const char *name, struct dentry *parent,
592+
debugfs_automount_t f, void *data)
603593
{
604594
struct dentry *dentry = start_creating(name, parent);
605595
struct inode *inode;
@@ -705,7 +695,7 @@ static void __debugfs_file_removed(struct dentry *dentry)
705695

706696
static void remove_one(struct dentry *victim)
707697
{
708-
if (d_is_reg(victim))
698+
if (d_is_reg(victim))
709699
__debugfs_file_removed(victim);
710700
simple_release_fs(&debugfs_mount, &debugfs_mount_count);
711701
}
@@ -754,7 +744,7 @@ EXPORT_SYMBOL_GPL(debugfs_remove);
754744
* returned.
755745
*/
756746
struct dentry *debugfs_rename(struct dentry *old_dir, struct dentry *old_dentry,
757-
struct dentry *new_dir, const char *new_name)
747+
struct dentry *new_dir, const char *new_name)
758748
{
759749
int error;
760750
struct dentry *dentry = NULL, *trap;
@@ -790,8 +780,7 @@ struct dentry *debugfs_rename(struct dentry *old_dir, struct dentry *old_dentry,
790780
}
791781
d_move(old_dentry, dentry);
792782
fsnotify_move(d_inode(old_dir), d_inode(new_dir), &old_name.name,
793-
d_is_dir(old_dentry),
794-
NULL, old_dentry);
783+
d_is_dir(old_dentry), NULL, old_dentry);
795784
release_dentry_name_snapshot(&old_name);
796785
unlock_rename(new_dir, old_dir);
797786
dput(dentry);

fs/seq_file.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,8 @@ int seq_open(struct file *file, const struct seq_operations *op)
8383
* file.open() which calls seq_open() and then sets FMODE_PWRITE.
8484
*/
8585
file->f_mode &= ~FMODE_PWRITE;
86+
pr_alert("seq_open has file %p and private_data %p", file,
87+
file->private_data);
8688
return 0;
8789
}
8890
EXPORT_SYMBOL(seq_open);
@@ -176,6 +178,8 @@ ssize_t seq_read_iter(struct kiocb *iocb, struct iov_iter *iter)
176178
void *p;
177179
int err = 0;
178180

181+
pr_alert("Start seq_read_iter private is %p", m->private);
182+
179183
if (!iov_iter_count(iter))
180184
return 0;
181185

@@ -222,6 +226,8 @@ ssize_t seq_read_iter(struct kiocb *iocb, struct iov_iter *iter)
222226
}
223227
// get a non-empty record in the buffer
224228
m->from = 0;
229+
pr_alert("Start seq_read_iter just before calling start %p",
230+
m->private);
225231
p = m->op->start(m, &m->index);
226232
while (1) {
227233
err = PTR_ERR(p);

rust/kernel/debugfs.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,6 @@ impl<T: PointerWrapper> Drop for DebugFsDirEntry<T> {
5151
bindings::debugfs_remove(self.dentry);
5252
}
5353
// SAFETY: `self.data` was created by a call to `T::into_pointer`.
54-
unsafe { drop(T::from_pointer(self.data)) }
54+
unsafe { T::from_pointer(self.data) };
5555
}
5656
}

0 commit comments

Comments
 (0)