2 * Copyright (C) 2010-2011 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, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
23 #include <linux/proc_fs.h>
26 static int au_procfs_plm_release(struct inode
*inode
, struct file
*file
)
28 struct au_sbinfo
*sbinfo
;
30 sbinfo
= file
->private_data
;
32 au_plink_maint_leave(sbinfo
);
33 kobject_put(&sbinfo
->si_kobj
);
39 static void au_procfs_plm_write_clean(struct file
*file
)
41 struct au_sbinfo
*sbinfo
;
43 sbinfo
= file
->private_data
;
45 au_plink_clean(sbinfo
->si_sb
, /*verbose*/0);
48 static int au_procfs_plm_write_si(struct file
*file
, unsigned long id
)
51 struct super_block
*sb
;
52 struct au_sbinfo
*sbinfo
;
55 if (unlikely(file
->private_data
))
59 /* don't use au_sbilist_lock() here */
60 spin_lock(&au_sbilist
.spin
);
61 list_for_each_entry(sbinfo
, &au_sbilist
.head
, si_list
)
62 if (id
== sysaufs_si_id(sbinfo
)) {
63 kobject_get(&sbinfo
->si_kobj
);
67 spin_unlock(&au_sbilist
.spin
);
73 err
= au_plink_maint_enter(sb
);
75 /* keep kobject_get() */
76 file
->private_data
= sbinfo
;
78 kobject_put(&sbinfo
->si_kobj
);
84 * Accept a valid "si=xxxx" only.
85 * Once it is accepted successfully, accept "clean" too.
87 static ssize_t
au_procfs_plm_write(struct file
*file
, const char __user
*ubuf
,
88 size_t count
, loff_t
*ppos
)
92 /* last newline is allowed */
93 char buf
[3 + sizeof(unsigned long) * 2 + 1];
96 if (unlikely(!capable(CAP_SYS_ADMIN
)))
100 if (unlikely(count
> sizeof(buf
)))
103 err
= copy_from_user(buf
, ubuf
, count
);
111 if (!strcmp("clean", buf
)) {
112 au_procfs_plm_write_clean(file
);
114 } else if (unlikely(strncmp("si=", buf
, 3)))
117 err
= strict_strtoul(buf
+ 3, 16, &id
);
121 err
= au_procfs_plm_write_si(file
, id
);
126 err
= count
; /* success */
131 static const struct file_operations au_procfs_plm_fop
= {
132 .write
= au_procfs_plm_write
,
133 .release
= au_procfs_plm_release
,
137 /* ---------------------------------------------------------------------- */
139 static struct proc_dir_entry
*au_procfs_dir
;
141 void au_procfs_fin(void)
143 remove_proc_entry(AUFS_PLINK_MAINT_NAME
, au_procfs_dir
);
144 remove_proc_entry(AUFS_PLINK_MAINT_DIR
, NULL
);
147 int __init
au_procfs_init(void)
150 struct proc_dir_entry
*entry
;
153 au_procfs_dir
= proc_mkdir(AUFS_PLINK_MAINT_DIR
, NULL
);
154 if (unlikely(!au_procfs_dir
))
157 entry
= proc_create(AUFS_PLINK_MAINT_NAME
, S_IFREG
| S_IWUSR
,
158 au_procfs_dir
, &au_procfs_plm_fop
);
159 if (unlikely(!entry
))
163 goto out
; /* success */
167 remove_proc_entry(AUFS_PLINK_MAINT_DIR
, NULL
);