hc
2023-12-08 01573e231f18eb2d99162747186f59511f56b64d
kernel/include/linux/sysfs.h
....@@ -7,7 +7,7 @@
77 * Copyright (c) 2007 SUSE Linux Products GmbH
88 * Copyright (c) 2007 Tejun Heo <teheo@suse.de>
99 *
10
- * Please see Documentation/filesystems/sysfs.txt for more information.
10
+ * Please see Documentation/filesystems/sysfs.rst for more information.
1111 */
1212
1313 #ifndef _SYSFS_H_
....@@ -123,6 +123,13 @@
123123 .show = _name##_show, \
124124 }
125125
126
+#define __ATTR_RW_MODE(_name, _mode) { \
127
+ .attr = { .name = __stringify(_name), \
128
+ .mode = VERIFY_OCTAL_PERMISSIONS(_mode) }, \
129
+ .show = _name##_show, \
130
+ .store = _name##_store, \
131
+}
132
+
126133 #define __ATTR_WO(_name) { \
127134 .attr = { .name = __stringify(_name), .mode = 0200 }, \
128135 .store = _name##_store, \
....@@ -196,6 +203,12 @@
196203 .size = _size, \
197204 }
198205
206
+#define __BIN_ATTR_WO(_name, _size) { \
207
+ .attr = { .name = __stringify(_name), .mode = 0200 }, \
208
+ .write = _name##_write, \
209
+ .size = _size, \
210
+}
211
+
199212 #define __BIN_ATTR_RW(_name, _size) \
200213 __BIN_ATTR(_name, 0644, _name##_read, _name##_write, _size)
201214
....@@ -207,6 +220,9 @@
207220
208221 #define BIN_ATTR_RO(_name, _size) \
209222 struct bin_attribute bin_attr_##_name = __BIN_ATTR_RO(_name, _size)
223
+
224
+#define BIN_ATTR_WO(_name, _size) \
225
+struct bin_attribute bin_attr_##_name = __BIN_ATTR_WO(_name, _size)
210226
211227 #define BIN_ATTR_RW(_name, _size) \
212228 struct bin_attribute bin_attr_##_name = __BIN_ATTR_RW(_name, _size)
....@@ -234,7 +250,7 @@
234250 const struct attribute *attr,
235251 const void *ns);
236252 int __must_check sysfs_create_files(struct kobject *kobj,
237
- const struct attribute **attr);
253
+ const struct attribute * const *attr);
238254 int __must_check sysfs_chmod_file(struct kobject *kobj,
239255 const struct attribute *attr, umode_t mode);
240256 struct kernfs_node *sysfs_break_active_protection(struct kobject *kobj,
....@@ -243,7 +259,7 @@
243259 void sysfs_remove_file_ns(struct kobject *kobj, const struct attribute *attr,
244260 const void *ns);
245261 bool sysfs_remove_file_self(struct kobject *kobj, const struct attribute *attr);
246
-void sysfs_remove_files(struct kobject *kobj, const struct attribute **attr);
262
+void sysfs_remove_files(struct kobject *kobj, const struct attribute * const *attr);
247263
248264 int __must_check sysfs_create_bin_file(struct kobject *kobj,
249265 const struct bin_attribute *attr);
....@@ -268,6 +284,8 @@
268284 const struct attribute_group *grp);
269285 int __must_check sysfs_create_groups(struct kobject *kobj,
270286 const struct attribute_group **groups);
287
+int __must_check sysfs_update_groups(struct kobject *kobj,
288
+ const struct attribute_group **groups);
271289 int sysfs_update_group(struct kobject *kobj,
272290 const struct attribute_group *grp);
273291 void sysfs_remove_group(struct kobject *kobj,
....@@ -286,9 +304,10 @@
286304 struct kobject *target, const char *link_name);
287305 void sysfs_remove_link_from_group(struct kobject *kobj, const char *group_name,
288306 const char *link_name);
289
-int __compat_only_sysfs_link_entry_to_kobj(struct kobject *kobj,
290
- struct kobject *target_kobj,
291
- const char *target_name);
307
+int compat_only_sysfs_link_entry_to_kobj(struct kobject *kobj,
308
+ struct kobject *target_kobj,
309
+ const char *target_name,
310
+ const char *symlink_name);
292311
293312 void sysfs_notify(struct kobject *kobj, const char *dir, const char *attr);
294313
....@@ -299,6 +318,17 @@
299318 return kernfs_enable_ns(kn);
300319 }
301320
321
+int sysfs_file_change_owner(struct kobject *kobj, const char *name, kuid_t kuid,
322
+ kgid_t kgid);
323
+int sysfs_change_owner(struct kobject *kobj, kuid_t kuid, kgid_t kgid);
324
+int sysfs_link_change_owner(struct kobject *kobj, struct kobject *targ,
325
+ const char *name, kuid_t kuid, kgid_t kgid);
326
+int sysfs_groups_change_owner(struct kobject *kobj,
327
+ const struct attribute_group **groups,
328
+ kuid_t kuid, kgid_t kgid);
329
+int sysfs_group_change_owner(struct kobject *kobj,
330
+ const struct attribute_group *groups, kuid_t kuid,
331
+ kgid_t kgid);
302332 __printf(2, 3)
303333 int sysfs_emit(char *buf, const char *fmt, ...);
304334 __printf(3, 4)
....@@ -347,7 +377,7 @@
347377 }
348378
349379 static inline int sysfs_create_files(struct kobject *kobj,
350
- const struct attribute **attr)
380
+ const struct attribute * const *attr)
351381 {
352382 return 0;
353383 }
....@@ -382,7 +412,7 @@
382412 }
383413
384414 static inline void sysfs_remove_files(struct kobject *kobj,
385
- const struct attribute **attr)
415
+ const struct attribute * const *attr)
386416 {
387417 }
388418
....@@ -438,6 +468,12 @@
438468 return 0;
439469 }
440470
471
+static inline int sysfs_update_groups(struct kobject *kobj,
472
+ const struct attribute_group **groups)
473
+{
474
+ return 0;
475
+}
476
+
441477 static inline int sysfs_update_group(struct kobject *kobj,
442478 const struct attribute_group *grp)
443479 {
....@@ -488,10 +524,10 @@
488524 {
489525 }
490526
491
-static inline int __compat_only_sysfs_link_entry_to_kobj(
492
- struct kobject *kobj,
493
- struct kobject *target_kobj,
494
- const char *target_name)
527
+static inline int compat_only_sysfs_link_entry_to_kobj(struct kobject *kobj,
528
+ struct kobject *target_kobj,
529
+ const char *target_name,
530
+ const char *symlink_name)
495531 {
496532 return 0;
497533 }
....@@ -510,6 +546,40 @@
510546 {
511547 }
512548
549
+static inline int sysfs_file_change_owner(struct kobject *kobj,
550
+ const char *name, kuid_t kuid,
551
+ kgid_t kgid)
552
+{
553
+ return 0;
554
+}
555
+
556
+static inline int sysfs_link_change_owner(struct kobject *kobj,
557
+ struct kobject *targ,
558
+ const char *name, kuid_t kuid,
559
+ kgid_t kgid)
560
+{
561
+ return 0;
562
+}
563
+
564
+static inline int sysfs_change_owner(struct kobject *kobj, kuid_t kuid, kgid_t kgid)
565
+{
566
+ return 0;
567
+}
568
+
569
+static inline int sysfs_groups_change_owner(struct kobject *kobj,
570
+ const struct attribute_group **groups,
571
+ kuid_t kuid, kgid_t kgid)
572
+{
573
+ return 0;
574
+}
575
+
576
+static inline int sysfs_group_change_owner(struct kobject *kobj,
577
+ const struct attribute_group *groups,
578
+ kuid_t kuid, kgid_t kgid)
579
+{
580
+ return 0;
581
+}
582
+
513583 __printf(2, 3)
514584 static inline int sysfs_emit(char *buf, const char *fmt, ...)
515585 {