@@ -50,6 +50,11 @@ struct kmod_weakdep {
50
50
unsigned int n_weak ;
51
51
};
52
52
53
+ const char * kmod_mask_get_modname (const struct kmod_list * l )
54
+ {
55
+ return l -> data ;
56
+ }
57
+
53
58
const char * kmod_blacklist_get_modname (const struct kmod_list * l )
54
59
{
55
60
return l -> data ;
@@ -231,6 +236,27 @@ static int kmod_config_add_blacklist(struct kmod_config *config, const char *mod
231
236
return 0 ;
232
237
}
233
238
239
+ static int kmod_config_add_mask (struct kmod_config * config , const char * modname )
240
+ {
241
+ _cleanup_free_ char * p ;
242
+ struct kmod_list * list ;
243
+
244
+ DBG (config -> ctx , "modname=%s\n" , modname );
245
+
246
+ _clang_suppress_alloc_ p = strdup (modname );
247
+ if (!p )
248
+ return - ENOMEM ;
249
+
250
+ list = kmod_list_append (config -> masks , p );
251
+ if (!list )
252
+ return - ENOMEM ;
253
+
254
+ TAKE_PTR (p );
255
+ config -> masks = list ;
256
+
257
+ return 0 ;
258
+ }
259
+
234
260
static int kmod_config_add_softdep (struct kmod_config * config , const char * modname ,
235
261
const char * line )
236
262
{
@@ -612,18 +638,24 @@ static char *weakdep_to_char(struct kmod_weakdep *dep)
612
638
static void kcmdline_parse_result (struct kmod_config * config , char * modname , char * param ,
613
639
char * value )
614
640
{
641
+ bool is_blacklist , is_mask ;
615
642
if (modname == NULL || param == NULL )
616
643
return ;
617
644
618
645
DBG (config -> ctx , "%s %s\n" , modname , param );
619
646
620
- if (streq (modname , "modprobe" ) && !strncmp (param , "blacklist=" , 10 )) {
647
+ is_blacklist = !strncmp (param , "blacklist=" , 10 );
648
+ is_mask = !strncmp (param , "mask=" , 5 );
649
+ if (streq (modname , "modprobe" ) && (is_blacklist || is_mask )) {
621
650
for (;;) {
622
651
char * t = strsep (& value , "," );
623
652
if (t == NULL )
624
653
break ;
625
654
626
- kmod_config_add_blacklist (config , t );
655
+ if (is_blacklist )
656
+ kmod_config_add_blacklist (config , t );
657
+ else
658
+ kmod_config_add_mask (config , t );
627
659
}
628
660
} else {
629
661
if (underscores (modname ) < 0 ) {
@@ -829,6 +861,13 @@ static int kmod_config_parse(struct kmod_config *config, int fd, const char *fil
829
861
830
862
kmod_config_add_command (config , modname , installcmd , cmd ,
831
863
& config -> install_commands );
864
+ } else if (streq (cmd , "mask" )) {
865
+ char * modname = strtok_r (NULL , "\t " , & saveptr );
866
+
867
+ if (underscores (modname ) < 0 )
868
+ goto syntax_error ;
869
+
870
+ kmod_config_add_mask (config , modname );
832
871
} else if (streq (cmd , "remove" )) {
833
872
char * modname = strtok_r (NULL , "\t " , & saveptr );
834
873
char * removecmd = strtok_r (NULL , "\0" , & saveptr );
@@ -878,6 +917,7 @@ void kmod_config_free(struct kmod_config *config)
878
917
kmod_list_release (config -> blacklists , free );
879
918
kmod_list_release (config -> options , free );
880
919
kmod_list_release (config -> install_commands , free );
920
+ kmod_list_release (config -> masks , free );
881
921
kmod_list_release (config -> remove_commands , free );
882
922
kmod_list_release (config -> softdeps , free );
883
923
kmod_list_release (config -> weakdeps , free );
@@ -1100,6 +1140,7 @@ int kmod_config_new(struct kmod_ctx *ctx, struct kmod_config **p_config,
1100
1140
enum config_type {
1101
1141
CONFIG_TYPE_BLACKLIST = 0 ,
1102
1142
CONFIG_TYPE_INSTALL ,
1143
+ CONFIG_TYPE_MASK ,
1103
1144
CONFIG_TYPE_REMOVE ,
1104
1145
CONFIG_TYPE_ALIAS ,
1105
1146
CONFIG_TYPE_OPTION ,
@@ -1150,6 +1191,10 @@ static struct kmod_config_iter *kmod_config_iter_new(const struct kmod_ctx *ctx,
1150
1191
iter -> get_key = kmod_command_get_modname ;
1151
1192
iter -> get_value = kmod_command_get_command ;
1152
1193
break ;
1194
+ case CONFIG_TYPE_MASK :
1195
+ iter -> list = config -> masks ;
1196
+ iter -> get_key = kmod_mask_get_modname ;
1197
+ break ;
1153
1198
case CONFIG_TYPE_REMOVE :
1154
1199
iter -> list = config -> remove_commands ;
1155
1200
iter -> get_key = kmod_command_get_modname ;
@@ -1200,6 +1245,14 @@ KMOD_EXPORT struct kmod_config_iter *kmod_config_get_install_commands(const stru
1200
1245
return kmod_config_iter_new (ctx , CONFIG_TYPE_INSTALL );
1201
1246
}
1202
1247
1248
+ KMOD_EXPORT struct kmod_config_iter * kmod_config_get_masks (const struct kmod_ctx * ctx )
1249
+ {
1250
+ if (ctx == NULL )
1251
+ return NULL ;
1252
+
1253
+ return kmod_config_iter_new (ctx , CONFIG_TYPE_MASK );
1254
+ }
1255
+
1203
1256
// clang-format off
1204
1257
KMOD_EXPORT struct kmod_config_iter * kmod_config_get_remove_commands (const struct kmod_ctx * ctx )
1205
1258
// clang-format on
0 commit comments