2 * Copyright (C) 2010-2016 Junjiro R. Okajima
4 * This program, aufs is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
22 #include <linux/proc_fs.h>
25 static int au_procfs_plm_release(struct inode
*inode
, struct file
*file
)
27 struct au_sbinfo
*sbinfo
;
29 sbinfo
= file
->private_data
;
31 au_plink_maint_leave(sbinfo
);
32 kobject_put(&sbinfo
->si_kobj
);
38 static void au_procfs_plm_write_clean(struct file
*file
)
40 struct au_sbinfo
*sbinfo
;
42 sbinfo
= file
->private_data
;
44 au_plink_clean(sbinfo
->si_sb
, /*verbose*/0);
47 static int au_procfs_plm_write_si(struct file
*file
, unsigned long id
)
50 struct super_block
*sb
;
51 struct au_sbinfo
*sbinfo
;
54 if (unlikely(file
->private_data
))
58 /* don't use au_sbilist_lock() here */
59 spin_lock(&au_sbilist
.spin
);
60 hlist_for_each_entry(sbinfo
, &au_sbilist
.head
, si_list
)
61 if (id
== sysaufs_si_id(sbinfo
)) {
62 kobject_get(&sbinfo
->si_kobj
);
66 spin_unlock(&au_sbilist
.spin
);
72 err
= au_plink_maint_enter(sb
);
74 /* keep kobject_get() */
75 file
->private_data
= sbinfo
;
77 kobject_put(&sbinfo
->si_kobj
);
83 * Accept a valid "si=xxxx" only.
84 * Once it is accepted successfully, accept "clean" too.
86 static ssize_t
au_procfs_plm_write(struct file
*file
, const char __user
*ubuf
,
87 size_t count
, loff_t
*ppos
)
91 /* last newline is allowed */
92 char buf
[3 + sizeof(unsigned long) * 2 + 1];
95 if (unlikely(!capable(CAP_SYS_ADMIN
)))
99 if (unlikely(count
> sizeof(buf
)))
102 err
= copy_from_user(buf
, ubuf
, count
);
110 if (!strcmp("clean", buf
)) {
111 au_procfs_plm_write_clean(file
);
113 } else if (unlikely(strncmp("si=", buf
, 3)))
116 err
= kstrtoul(buf
+ 3, 16, &id
);
120 err
= au_procfs_plm_write_si(file
, id
);
125 err
= count
; /* success */
130 static const struct file_operations au_procfs_plm_fop
= {
131 .write
= au_procfs_plm_write
,
132 .release
= au_procfs_plm_release
,
136 /* ---------------------------------------------------------------------- */
138 static struct proc_dir_entry
*au_procfs_dir
;
140 void au_procfs_fin(void)
142 remove_proc_entry(AUFS_PLINK_MAINT_NAME
, au_procfs_dir
);
143 remove_proc_entry(AUFS_PLINK_MAINT_DIR
, NULL
);
146 int __init
au_procfs_init(void)
149 struct proc_dir_entry
*entry
;
152 au_procfs_dir
= proc_mkdir(AUFS_PLINK_MAINT_DIR
, NULL
);
153 if (unlikely(!au_procfs_dir
))
156 entry
= proc_create(AUFS_PLINK_MAINT_NAME
, S_IFREG
| S_IWUSR
,
157 au_procfs_dir
, &au_procfs_plm_fop
);
158 if (unlikely(!entry
))
162 goto out
; /* success */
166 remove_proc_entry(AUFS_PLINK_MAINT_DIR
, NULL
);