@@ -5126,6 +5126,66 @@ static struct file_system_type shmem_fs_type = {
51265126 .fs_flags = FS_USERNS_MOUNT | FS_ALLOW_IDMAP ,
51275127};
51285128
5129+ #if defined(CONFIG_SYSFS ) && defined(CONFIG_TMPFS )
5130+
5131+ #define __INIT_KOBJ_ATTR (_name , _mode , _show , _store ) \
5132+ { \
5133+ .attr = { .name = __stringify(_name), .mode = _mode }, \
5134+ .show = _show, \
5135+ .store = _store, \
5136+ }
5137+
5138+ #define TMPFS_ATTR_W (_name , _store ) \
5139+ static struct kobj_attribute tmpfs_attr_##_name = \
5140+ __INIT_KOBJ_ATTR(_name, 0200, NULL, _store)
5141+
5142+ #define TMPFS_ATTR_RW (_name , _show , _store ) \
5143+ static struct kobj_attribute tmpfs_attr_##_name = \
5144+ __INIT_KOBJ_ATTR(_name, 0644, _show, _store)
5145+
5146+ #define TMPFS_ATTR_RO (_name , _show ) \
5147+ static struct kobj_attribute tmpfs_attr_##_name = \
5148+ __INIT_KOBJ_ATTR(_name, 0444, _show, NULL)
5149+
5150+ #if IS_ENABLED (CONFIG_UNICODE )
5151+ static ssize_t casefold_show (struct kobject * kobj , struct kobj_attribute * a ,
5152+ char * buf )
5153+ {
5154+ return sysfs_emit (buf , "supported\n" );
5155+ }
5156+ TMPFS_ATTR_RO (casefold , casefold_show );
5157+ #endif
5158+
5159+ static struct attribute * tmpfs_attributes [] = {
5160+ #if IS_ENABLED (CONFIG_UNICODE )
5161+ & tmpfs_attr_casefold .attr ,
5162+ #endif
5163+ NULL
5164+ };
5165+
5166+ static const struct attribute_group tmpfs_attribute_group = {
5167+ .attrs = tmpfs_attributes ,
5168+ .name = "features"
5169+ };
5170+
5171+ static struct kobject * tmpfs_kobj ;
5172+
5173+ static int __init tmpfs_sysfs_init (void )
5174+ {
5175+ int ret ;
5176+
5177+ tmpfs_kobj = kobject_create_and_add ("tmpfs" , fs_kobj );
5178+ if (!tmpfs_kobj )
5179+ return - ENOMEM ;
5180+
5181+ ret = sysfs_create_group (tmpfs_kobj , & tmpfs_attribute_group );
5182+ if (ret )
5183+ kobject_put (tmpfs_kobj );
5184+
5185+ return ret ;
5186+ }
5187+ #endif /* CONFIG_SYSFS && CONFIG_TMPFS */
5188+
51295189void __init shmem_init (void )
51305190{
51315191 int error ;
@@ -5149,6 +5209,14 @@ void __init shmem_init(void)
51495209 goto out1 ;
51505210 }
51515211
5212+ #if defined(CONFIG_SYSFS ) && defined(CONFIG_TMPFS )
5213+ error = tmpfs_sysfs_init ();
5214+ if (error ) {
5215+ pr_err ("Could not init tmpfs sysfs\n" );
5216+ goto out1 ;
5217+ }
5218+ #endif
5219+
51525220#ifdef CONFIG_TRANSPARENT_HUGEPAGE
51535221 if (has_transparent_hugepage () && shmem_huge > SHMEM_HUGE_DENY )
51545222 SHMEM_SB (shm_mnt -> mnt_sb )-> huge = shmem_huge ;
@@ -5546,65 +5614,3 @@ struct page *shmem_read_mapping_page_gfp(struct address_space *mapping,
55465614 return page ;
55475615}
55485616EXPORT_SYMBOL_GPL (shmem_read_mapping_page_gfp );
5549-
5550- #if defined(CONFIG_SYSFS ) && defined(CONFIG_TMPFS )
5551-
5552- #define __INIT_KOBJ_ATTR (_name , _mode , _show , _store ) \
5553- { \
5554- .attr = { .name = __stringify(_name), .mode = _mode }, \
5555- .show = _show, \
5556- .store = _store, \
5557- }
5558-
5559- #define TMPFS_ATTR_W (_name , _store ) \
5560- static struct kobj_attribute tmpfs_attr_##_name = \
5561- __INIT_KOBJ_ATTR(_name, 0200, NULL, _store)
5562-
5563- #define TMPFS_ATTR_RW (_name , _show , _store ) \
5564- static struct kobj_attribute tmpfs_attr_##_name = \
5565- __INIT_KOBJ_ATTR(_name, 0644, _show, _store)
5566-
5567- #define TMPFS_ATTR_RO (_name , _show ) \
5568- static struct kobj_attribute tmpfs_attr_##_name = \
5569- __INIT_KOBJ_ATTR(_name, 0444, _show, NULL)
5570-
5571- #if IS_ENABLED (CONFIG_UNICODE )
5572- static ssize_t casefold_show (struct kobject * kobj , struct kobj_attribute * a ,
5573- char * buf )
5574- {
5575- return sysfs_emit (buf , "supported\n" );
5576- }
5577- TMPFS_ATTR_RO (casefold , casefold_show );
5578- #endif
5579-
5580- static struct attribute * tmpfs_attributes [] = {
5581- #if IS_ENABLED (CONFIG_UNICODE )
5582- & tmpfs_attr_casefold .attr ,
5583- #endif
5584- NULL
5585- };
5586-
5587- static const struct attribute_group tmpfs_attribute_group = {
5588- .attrs = tmpfs_attributes ,
5589- .name = "features"
5590- };
5591-
5592- static struct kobject * tmpfs_kobj ;
5593-
5594- static int __init tmpfs_sysfs_init (void )
5595- {
5596- int ret ;
5597-
5598- tmpfs_kobj = kobject_create_and_add ("tmpfs" , fs_kobj );
5599- if (!tmpfs_kobj )
5600- return - ENOMEM ;
5601-
5602- ret = sysfs_create_group (tmpfs_kobj , & tmpfs_attribute_group );
5603- if (ret )
5604- kobject_put (tmpfs_kobj );
5605-
5606- return ret ;
5607- }
5608-
5609- fs_initcall (tmpfs_sysfs_init );
5610- #endif /* CONFIG_SYSFS && CONFIG_TMPFS */
0 commit comments