11 #include <sys/mount.h>
13 #include <talloc/talloc.h>
14 #include <list/list.h>
16 #include <types/types.h>
17 #include <system/system.h>
18 #include <process/process.h>
20 #include <i18n/i18n.h>
22 #include <sys/types.h>
23 #include <sys/socket.h>
25 #include <arpa/inet.h>
27 #include "device-handler.h"
28 #include "discover-server.h"
29 #include "user-event.h"
40 struct device_handler {
41 struct discover_server *server;
45 struct network *network;
46 struct user_event *user_event;
48 struct discover_device **devices;
49 unsigned int n_devices;
51 struct waitset *waitset;
52 struct waiter *timeout_waiter;
53 bool autoboot_enabled;
54 unsigned int sec_to_boot;
56 struct discover_boot_option *default_boot_option;
57 struct list unresolved_boot_options;
59 struct boot_task *pending_boot;
60 bool pending_boot_is_default;
63 static int mount_device(struct discover_device *dev);
64 static int umount_device(struct discover_device *dev);
66 static int device_handler_init_sources(struct device_handler *handler);
67 static void device_handler_reinit_sources(struct device_handler *handler);
69 static void device_handler_update_lang(const char *lang);
71 void discover_context_add_boot_option(struct discover_context *ctx,
72 struct discover_boot_option *boot_option)
74 boot_option->source = ctx->parser;
75 list_add_tail(&ctx->boot_options, &boot_option->list);
76 talloc_steal(ctx, boot_option);
80 * device_handler_get_device_count - Get the count of current handler devices.
83 int device_handler_get_device_count(const struct device_handler *handler)
85 return handler->n_devices;
89 * device_handler_get_device - Get a handler device by index.
92 const struct discover_device *device_handler_get_device(
93 const struct device_handler *handler, unsigned int index)
95 if (index >= handler->n_devices) {
96 assert(0 && "bad index");
100 return handler->devices[index];
103 struct discover_boot_option *discover_boot_option_create(
104 struct discover_context *ctx,
105 struct discover_device *device)
107 struct discover_boot_option *opt;
109 opt = talloc_zero(ctx, struct discover_boot_option);
110 opt->option = talloc_zero(opt, struct boot_option);
111 opt->device = device;
116 static int device_match_uuid(struct discover_device *dev, const char *uuid)
118 return dev->uuid && !strcmp(dev->uuid, uuid);
121 static int device_match_label(struct discover_device *dev, const char *label)
123 return dev->label && !strcmp(dev->label, label);
126 static int device_match_id(struct discover_device *dev, const char *id)
128 return !strcmp(dev->device->id, id);
131 static int device_match_serial(struct discover_device *dev, const char *serial)
133 const char *val = discover_device_get_param(dev, "ID_SERIAL");
134 return val && !strcmp(val, serial);
137 static struct discover_device *device_lookup(
138 struct device_handler *device_handler,
139 int (match_fn)(struct discover_device *, const char *),
142 struct discover_device *dev;
148 for (i = 0; i < device_handler->n_devices; i++) {
149 dev = device_handler->devices[i];
151 if (match_fn(dev, str))
158 struct discover_device *device_lookup_by_name(struct device_handler *handler,
161 if (!strncmp(name, "/dev/", strlen("/dev/")))
162 name += strlen("/dev/");
164 return device_lookup_by_id(handler, name);
167 struct discover_device *device_lookup_by_uuid(
168 struct device_handler *device_handler,
171 return device_lookup(device_handler, device_match_uuid, uuid);
174 struct discover_device *device_lookup_by_label(
175 struct device_handler *device_handler,
178 return device_lookup(device_handler, device_match_label, label);
181 struct discover_device *device_lookup_by_id(
182 struct device_handler *device_handler,
185 return device_lookup(device_handler, device_match_id, id);
188 struct discover_device *device_lookup_by_serial(
189 struct device_handler *device_handler,
192 return device_lookup(device_handler, device_match_serial, serial);
195 void device_handler_destroy(struct device_handler *handler)
197 talloc_free(handler);
200 static int destroy_device(void *arg)
202 struct discover_device *dev = arg;
209 struct discover_device *discover_device_create(struct device_handler *handler,
212 struct discover_device *dev;
214 dev = device_lookup_by_id(handler, id);
218 dev = talloc_zero(handler, struct discover_device);
219 dev->device = talloc_zero(dev, struct device);
220 dev->device->id = talloc_strdup(dev->device, id);
221 list_init(&dev->params);
222 list_init(&dev->boot_options);
224 talloc_set_destructor(dev, destroy_device);
229 struct discover_device_param {
232 struct list_item list;
235 void discover_device_set_param(struct discover_device *device,
236 const char *name, const char *value)
238 struct discover_device_param *param;
241 list_for_each_entry(&device->params, param, list) {
242 if (!strcmp(param->name, name)) {
251 param = talloc(device, struct discover_device_param);
252 param->name = talloc_strdup(param, name);
253 list_add(&device->params, ¶m->list);
256 list_remove(¶m->list);
260 talloc_free(param->value);
263 param->value = talloc_strdup(param, value);
266 const char *discover_device_get_param(struct discover_device *device,
269 struct discover_device_param *param;
271 list_for_each_entry(&device->params, param, list) {
272 if (!strcmp(param->name, name))
278 struct device_handler *device_handler_init(struct discover_server *server,
279 struct waitset *waitset, int dry_run)
281 struct device_handler *handler;
284 handler = talloc_zero(NULL, struct device_handler);
285 handler->server = server;
286 handler->waitset = waitset;
287 handler->dry_run = dry_run;
288 handler->autoboot_enabled = config_get()->autoboot_enabled;
290 list_init(&handler->unresolved_boot_options);
292 /* set up our mount point base */
293 pb_mkdir_recursive(mount_base());
297 if (config_get()->safe_mode)
300 rc = device_handler_init_sources(handler);
302 talloc_free(handler);
309 void device_handler_reinit(struct device_handler *handler)
311 struct discover_boot_option *opt, *tmp;
314 device_handler_cancel_default(handler);
316 /* free unresolved boot options */
317 list_for_each_entry_safe(&handler->unresolved_boot_options,
320 list_init(&handler->unresolved_boot_options);
322 /* drop all devices */
323 for (i = 0; i < handler->n_devices; i++)
324 discover_server_notify_device_remove(handler->server,
325 handler->devices[i]->device);
327 talloc_free(handler->devices);
328 handler->devices = NULL;
329 handler->n_devices = 0;
331 device_handler_reinit_sources(handler);
334 void device_handler_remove(struct device_handler *handler,
335 struct discover_device *device)
337 struct discover_boot_option *opt, *tmp;
340 for (i = 0; i < handler->n_devices; i++)
341 if (handler->devices[i] == device)
344 if (i == handler->n_devices) {
349 /* Free any unresolved options, as they're currently allocated
350 * against the handler */
351 list_for_each_entry_safe(&handler->unresolved_boot_options,
353 if (opt->device != device)
355 list_remove(&opt->list);
359 /* if this is a network device, we have to unregister it from the
361 if (device->device->type == DEVICE_TYPE_NETWORK)
362 network_unregister_device(handler->network, device);
364 handler->n_devices--;
365 memmove(&handler->devices[i], &handler->devices[i + 1],
366 (handler->n_devices - i) * sizeof(handler->devices[0]));
367 handler->devices = talloc_realloc(handler, handler->devices,
368 struct discover_device *, handler->n_devices);
370 if (device->notified)
371 discover_server_notify_device_remove(handler->server,
377 static void boot_status(void *arg, struct boot_status *status)
379 struct device_handler *handler = arg;
381 discover_server_notify_boot_status(handler->server, status);
384 static void countdown_status(struct device_handler *handler,
385 struct discover_boot_option *opt, unsigned int sec)
387 struct boot_status status;
389 status.type = BOOT_STATUS_INFO;
390 status.progress = -1;
391 status.detail = NULL;
392 status.message = talloc_asprintf(handler,
393 _("Booting in %d sec: %s"), sec, opt->option->name);
395 discover_server_notify_boot_status(handler->server, &status);
397 talloc_free(status.message);
400 static int default_timeout(void *arg)
402 struct device_handler *handler = arg;
403 struct discover_boot_option *opt;
405 if (!handler->default_boot_option)
408 if (handler->pending_boot)
411 opt = handler->default_boot_option;
413 if (handler->sec_to_boot) {
414 countdown_status(handler, opt, handler->sec_to_boot);
415 handler->sec_to_boot--;
416 handler->timeout_waiter = waiter_register_timeout(
417 handler->waitset, 1000,
418 default_timeout, handler);
422 handler->timeout_waiter = NULL;
424 pb_log("Timeout expired, booting default option %s\n", opt->option->id);
426 handler->pending_boot = boot(handler, handler->default_boot_option,
427 NULL, handler->dry_run, boot_status, handler);
428 handler->pending_boot_is_default = true;
432 static bool priority_match(struct boot_priority *prio,
433 struct discover_boot_option *opt)
435 return prio->type == opt->device->device->type ||
436 prio->type == DEVICE_TYPE_ANY;
439 static int default_option_priority(struct discover_boot_option *opt)
441 const struct config *config;
442 struct boot_priority *prio;
445 config = config_get();
447 for (i = 0; i < config->n_boot_priorities; i++) {
448 prio = &config->boot_priorities[i];
449 if (priority_match(prio, opt))
450 return prio->priority;
456 static bool device_allows_default(struct discover_device *dev)
460 dev_str = config_get()->boot_device;
462 if (!dev_str || !strlen(dev_str))
465 /* default devices are specified by UUIDs at present */
466 if (strcmp(dev->uuid, dev_str))
472 static void set_default(struct device_handler *handler,
473 struct discover_boot_option *opt)
477 if (!handler->autoboot_enabled)
480 /* do we allow default-booting from this device? */
481 if (!device_allows_default(opt->device))
484 new_prio = default_option_priority(opt);
486 /* A negative priority indicates that we don't want to boot this device
491 /* Resolve any conflicts: if we have a new default option, it only
492 * replaces the current if it has a higher priority. */
493 if (handler->default_boot_option) {
496 cur_prio = default_option_priority(
497 handler->default_boot_option);
499 if (new_prio > cur_prio) {
500 handler->default_boot_option = opt;
501 /* extend the timeout a little, so the user sees some
502 * indication of the change */
503 handler->sec_to_boot += 2;
509 handler->sec_to_boot = config_get()->autoboot_timeout_sec;
510 handler->default_boot_option = opt;
512 pb_log("Boot option %s set as default, timeout %u sec.\n",
513 opt->option->id, handler->sec_to_boot);
515 default_timeout(handler);
518 static bool resource_is_resolved(struct resource *res)
520 return !res || res->resolved;
523 /* We only use this in an assert, which will disappear if we're compiling
524 * with NDEBUG, so we need the 'used' attribute for these builds */
525 static bool __attribute__((used)) boot_option_is_resolved(
526 struct discover_boot_option *opt)
528 return resource_is_resolved(opt->boot_image) &&
529 resource_is_resolved(opt->initrd) &&
530 resource_is_resolved(opt->dtb) &&
531 resource_is_resolved(opt->icon);
534 static bool resource_resolve(struct resource *res, const char *name,
535 struct discover_boot_option *opt,
536 struct device_handler *handler)
538 struct parser *parser = opt->source;
540 if (resource_is_resolved(res))
543 pb_debug("Attempting to resolve resource %s->%s with parser %s\n",
544 opt->option->id, name, parser->name);
545 parser->resolve_resource(handler, res);
547 return res->resolved;
550 static bool boot_option_resolve(struct discover_boot_option *opt,
551 struct device_handler *handler)
553 return resource_resolve(opt->boot_image, "boot_image", opt, handler) &&
554 resource_resolve(opt->initrd, "initrd", opt, handler) &&
555 resource_resolve(opt->dtb, "dtb", opt, handler) &&
556 resource_resolve(opt->icon, "icon", opt, handler);
559 static void boot_option_finalise(struct device_handler *handler,
560 struct discover_boot_option *opt)
562 assert(boot_option_is_resolved(opt));
564 /* check that the parsers haven't set any of the final data */
565 assert(!opt->option->boot_image_file);
566 assert(!opt->option->initrd_file);
567 assert(!opt->option->dtb_file);
568 assert(!opt->option->icon_file);
569 assert(!opt->option->device_id);
572 opt->option->boot_image_file = opt->boot_image->url->full;
574 opt->option->initrd_file = opt->initrd->url->full;
576 opt->option->dtb_file = opt->dtb->url->full;
578 opt->option->icon_file = opt->icon->url->full;
580 opt->option->device_id = opt->device->device->id;
582 if (opt->option->is_default)
583 set_default(handler, opt);
586 static void notify_boot_option(struct device_handler *handler,
587 struct discover_boot_option *opt)
589 struct discover_device *dev = opt->device;
592 discover_server_notify_device_add(handler->server,
593 opt->device->device);
594 dev->notified = true;
595 discover_server_notify_boot_option_add(handler->server, opt->option);
598 static void process_boot_option_queue(struct device_handler *handler)
600 struct discover_boot_option *opt, *tmp;
602 list_for_each_entry_safe(&handler->unresolved_boot_options,
605 pb_debug("queue: attempting resolution for %s\n",
608 if (!boot_option_resolve(opt, handler))
611 pb_debug("\tresolved!\n");
613 list_remove(&opt->list);
614 list_add_tail(&opt->device->boot_options, &opt->list);
615 talloc_steal(opt->device, opt);
616 boot_option_finalise(handler, opt);
617 notify_boot_option(handler, opt);
621 struct discover_context *device_handler_discover_context_create(
622 struct device_handler *handler,
623 struct discover_device *device)
625 struct discover_context *ctx;
627 ctx = talloc_zero(handler, struct discover_context);
628 ctx->device = device;
629 list_init(&ctx->boot_options);
635 * context_commit - Commit a temporary discovery context to the handler,
636 * and notify the clients about any new options / devices
638 void device_handler_discover_context_commit(struct device_handler *handler,
639 struct discover_context *ctx)
641 struct discover_device *dev = ctx->device;
642 struct discover_boot_option *opt, *tmp;
644 if (!device_lookup_by_id(handler, dev->device->id))
645 device_handler_add_device(handler, dev);
647 /* move boot options from the context to the device */
648 list_for_each_entry_safe(&ctx->boot_options, opt, tmp, list) {
649 list_remove(&opt->list);
651 if (boot_option_resolve(opt, handler)) {
652 pb_log("boot option %s is resolved, "
653 "sending to clients\n",
655 list_add_tail(&dev->boot_options, &opt->list);
656 talloc_steal(dev, opt);
657 boot_option_finalise(handler, opt);
658 notify_boot_option(handler, opt);
660 if (!opt->source->resolve_resource) {
661 pb_log("parser %s gave us an unresolved "
662 "resource (%s), but no way to "
664 opt->source->name, opt->option->id);
667 pb_log("boot option %s is unresolved, "
670 list_add(&handler->unresolved_boot_options,
672 talloc_steal(handler, opt);
678 void device_handler_add_device(struct device_handler *handler,
679 struct discover_device *device)
681 handler->n_devices++;
682 handler->devices = talloc_realloc(handler, handler->devices,
683 struct discover_device *, handler->n_devices);
684 handler->devices[handler->n_devices - 1] = device;
686 if (device->device->type == DEVICE_TYPE_NETWORK)
687 network_register_device(handler->network, device);
690 /* Start discovery on a hotplugged device. The device will be in our devices
691 * array, but has only just been initialised by the hotplug source.
693 int device_handler_discover(struct device_handler *handler,
694 struct discover_device *dev)
696 struct discover_context *ctx;
699 process_boot_option_queue(handler);
701 /* create our context */
702 ctx = device_handler_discover_context_create(handler, dev);
704 rc = mount_device(dev);
708 /* add this device to our system info */
709 system_info_register_blockdev(dev->device->id, dev->uuid,
712 /* run the parsers. This will populate the ctx's boot_option list. */
713 iterate_parsers(ctx);
715 /* add discovered stuff to the handler */
716 device_handler_discover_context_commit(handler, ctx);
724 /* Incoming dhcp event */
725 int device_handler_dhcp(struct device_handler *handler,
726 struct discover_device *dev, struct event *event)
728 struct discover_context *ctx;
730 /* create our context */
731 ctx = device_handler_discover_context_create(handler, dev);
734 iterate_parsers(ctx);
736 device_handler_discover_context_commit(handler, ctx);
743 /* incoming conf event */
744 int device_handler_conf(struct device_handler *handler,
745 struct discover_device *dev, struct pb_url *url)
747 struct discover_context *ctx;
749 /* create our context */
750 ctx = device_handler_discover_context_create(handler, dev);
753 iterate_parsers(ctx);
755 device_handler_discover_context_commit(handler, ctx);
762 static struct discover_boot_option *find_boot_option_by_id(
763 struct device_handler *handler, const char *id)
767 for (i = 0; i < handler->n_devices; i++) {
768 struct discover_device *dev = handler->devices[i];
769 struct discover_boot_option *opt;
771 list_for_each_entry(&dev->boot_options, opt, list)
772 if (!strcmp(opt->option->id, id))
779 void device_handler_boot(struct device_handler *handler,
780 struct boot_command *cmd)
782 struct discover_boot_option *opt = NULL;
784 if (cmd->option_id && strlen(cmd->option_id))
785 opt = find_boot_option_by_id(handler, cmd->option_id);
787 if (handler->pending_boot)
788 boot_cancel(handler->pending_boot);
789 handler->pending_boot = boot(handler, opt, cmd, handler->dry_run,
790 boot_status, handler);
791 handler->pending_boot_is_default = false;
794 void device_handler_cancel_default(struct device_handler *handler)
796 struct boot_status status;
798 if (handler->timeout_waiter)
799 waiter_remove(handler->timeout_waiter);
801 handler->timeout_waiter = NULL;
802 handler->autoboot_enabled = false;
804 /* we only send status if we had a default boot option queued */
805 if (!handler->default_boot_option)
808 pb_log("Cancelling default boot option\n");
810 if (handler->pending_boot && handler->pending_boot_is_default) {
811 boot_cancel(handler->pending_boot);
812 handler->pending_boot = NULL;
813 handler->pending_boot_is_default = false;
816 handler->default_boot_option = NULL;
818 status.type = BOOT_STATUS_INFO;
819 status.progress = -1;
820 status.detail = NULL;
821 status.message = _("Default boot cancelled");
823 discover_server_notify_boot_status(handler->server, &status);
826 void device_handler_update_config(struct device_handler *handler,
827 struct config *config)
831 rc = config_set(config);
835 discover_server_notify_config(handler->server, config);
836 device_handler_update_lang(config->lang);
837 device_handler_reinit(handler);
840 static char *device_from_addr(void *ctx, struct pb_url *url)
842 char *ipaddr, *buf, *tok, *dev = NULL;
843 const char *delim = " ";
844 struct sockaddr_in *ip;
845 struct sockaddr_in si;
846 struct addrinfo *res;
850 /* Note: IPv4 only */
851 rc = inet_pton(AF_INET, url->host, &(si.sin_addr));
855 /* need to turn hostname into a valid IP */
856 rc = getaddrinfo(url->host, NULL, NULL, &res);
858 pb_debug("%s: Invalid URL\n",__func__);
861 ipaddr = talloc_array(ctx,char,INET_ADDRSTRLEN);
862 ip = (struct sockaddr_in *) res->ai_addr;
863 inet_ntop(AF_INET, &(ip->sin_addr), ipaddr, INET_ADDRSTRLEN);
867 const char *argv[] = {
869 "route", "show", "to", "match",
874 p = process_create(ctx);
876 p->path = pb_system_apps.ip;
878 p->keep_stdout = true;
880 rc = process_run_sync(p);
883 /* ip has complained for some reason; most likely
884 * there is no route to the host - bail out */
885 pb_debug("%s: No route to %s\n",__func__,url->host);
890 /* If a route is found, ip-route output will be of the form
891 * "... dev DEVNAME ... " */
892 tok = strtok(buf, delim);
894 if (!strcmp(tok, "dev")) {
895 tok = strtok(NULL, delim);
896 dev = talloc_strdup(ctx, tok);
899 tok = strtok(NULL, delim);
904 pb_debug("%s: Found interface '%s'\n", __func__,dev);
909 void device_handler_process_url(struct device_handler *handler,
912 struct discover_context *ctx;
913 struct discover_device *dev;
914 struct boot_status *status;
915 struct pb_url *pb_url;
919 status = talloc(handler, struct boot_status);
921 status->type = BOOT_STATUS_ERROR;
922 status->progress = 0;
923 status->detail = talloc_asprintf(status,
924 _("Received config URL %s"), url);
926 if (!handler->network) {
927 status->message = talloc_asprintf(handler,
928 _("No network configured"));
932 event = talloc(handler, struct event);
933 event->type = EVENT_TYPE_USER;
934 event->action = EVENT_ACTION_CONF;
936 event->params = talloc_array(event, struct param, 1);
937 param = &event->params[0];
938 param->name = talloc_strdup(event, "pxeconffile");
939 param->value = talloc_strdup(event, url);
942 pb_url = pb_url_parse(event, event->params->value);
943 if (!pb_url || !pb_url->host) {
944 status->message = talloc_asprintf(handler,
945 _("Invalid config URL!"));
949 event->device = device_from_addr(event, pb_url);
950 if (!event->device) {
951 status->message = talloc_asprintf(status,
952 _("Unable to route to host %s"),
957 dev = discover_device_create(handler, event->device);
958 ctx = device_handler_discover_context_create(handler, dev);
961 iterate_parsers(ctx);
963 device_handler_discover_context_commit(handler, ctx);
967 status->type = BOOT_STATUS_INFO;
968 status->message = talloc_asprintf(status, _("Config file %s parsed"),
971 boot_status(handler, status);
975 #ifndef PETITBOOT_TEST
977 static void device_handler_update_lang(const char *lang)
979 const char *cur_lang;
984 cur_lang = setlocale(LC_ALL, NULL);
985 if (cur_lang && !strcmp(cur_lang, lang))
988 setlocale(LC_ALL, lang);
991 static int device_handler_init_sources(struct device_handler *handler)
993 /* init our device sources: udev, network and user events */
994 handler->udev = udev_init(handler, handler->waitset);
998 handler->network = network_init(handler, handler->waitset,
1000 if (!handler->network)
1003 handler->user_event = user_event_init(handler, handler->waitset);
1004 if (!handler->user_event)
1010 static void device_handler_reinit_sources(struct device_handler *handler)
1012 /* if we haven't initialised sources previously (becuase we started in
1013 * safe mode), then init once here. */
1014 if (!(handler->udev || handler->network || handler->user_event)) {
1015 device_handler_init_sources(handler);
1019 udev_reinit(handler->udev);
1021 network_shutdown(handler->network);
1022 handler->network = network_init(handler, handler->waitset,
1026 static bool check_existing_mount(struct discover_device *dev)
1028 struct stat devstat, mntstat;
1033 rc = stat(dev->device_path, &devstat);
1035 pb_debug("%s: stat failed: %s\n", __func__, strerror(errno));
1039 if (!S_ISBLK(devstat.st_mode)) {
1040 pb_debug("%s: %s isn't a block device?\n", __func__,
1045 fp = fopen("/proc/self/mounts", "r");
1048 mnt = getmntent(fp);
1052 if (!mnt->mnt_fsname || mnt->mnt_fsname[0] != '/')
1055 rc = stat(mnt->mnt_fsname, &mntstat);
1059 if (!S_ISBLK(mntstat.st_mode))
1062 if (mntstat.st_rdev == devstat.st_rdev) {
1063 dev->mount_path = talloc_strdup(dev, mnt->mnt_dir);
1064 dev->mounted_rw = !!hasmntopt(mnt, "rw");
1065 dev->mounted = true;
1066 dev->unmount = false;
1068 pb_debug("%s: %s is already mounted (r%c) at %s\n",
1069 __func__, dev->device_path,
1070 dev->mounted_rw ? 'w' : 'o',
1081 static int mount_device(struct discover_device *dev)
1086 if (!dev->device_path)
1092 if (check_existing_mount(dev))
1095 fstype = discover_device_get_param(dev, "ID_FS_TYPE");
1099 dev->mount_path = join_paths(dev, mount_base(),
1102 if (pb_mkdir_recursive(dev->mount_path)) {
1103 pb_log("couldn't create mount directory %s: %s\n",
1104 dev->mount_path, strerror(errno));
1108 pb_log("mounting device %s read-only\n", dev->device_path);
1110 rc = mount(dev->device_path, dev->mount_path, fstype,
1111 MS_RDONLY | MS_SILENT, "");
1113 dev->mounted = true;
1114 dev->mounted_rw = false;
1115 dev->unmount = true;
1119 pb_log("couldn't mount device %s: mount failed: %s\n",
1120 dev->device_path, strerror(errno));
1122 pb_rmdir_recursive(mount_base(), dev->mount_path);
1124 talloc_free(dev->mount_path);
1125 dev->mount_path = NULL;
1129 static int umount_device(struct discover_device *dev)
1133 if (!dev->mounted || !dev->unmount)
1136 pb_log("unmounting device %s\n", dev->device_path);
1137 rc = umount(dev->mount_path);
1141 dev->mounted = false;
1143 pb_rmdir_recursive(mount_base(), dev->mount_path);
1145 talloc_free(dev->mount_path);
1146 dev->mount_path = NULL;
1151 int device_request_write(struct discover_device *dev, bool *release)
1160 if (dev->mounted_rw)
1163 pb_log("remounting device %s read-write\n", dev->device_path);
1164 rc = mount(dev->device_path, dev->mount_path, "",
1165 MS_REMOUNT | MS_SILENT, "");
1169 dev->mounted_rw = true;
1174 void device_release_write(struct discover_device *dev, bool release)
1179 pb_log("remounting device %s read-only\n", dev->device_path);
1180 mount(dev->device_path, dev->mount_path, "",
1181 MS_REMOUNT | MS_RDONLY | MS_SILENT, "");
1182 dev->mounted_rw = false;
1187 static void device_handler_update_lang(const char *lang __attribute__((unused)))
1191 static int device_handler_init_sources(
1192 struct device_handler *handler __attribute__((unused)))
1197 static void device_handler_reinit_sources(
1198 struct device_handler *handler __attribute__((unused)))
1202 static int umount_device(struct discover_device *dev __attribute__((unused)))
1207 static int __attribute__((unused)) mount_device(
1208 struct discover_device *dev __attribute__((unused)))
1213 int device_request_write(struct discover_device *dev __attribute__((unused)),
1220 void device_release_write(struct discover_device *dev __attribute__((unused)),
1221 bool release __attribute__((unused)))