+#if CONFIG_EMBEDDED
+ dev_t dev = mp->mnt_vfsstat.f_fsid.val[0];
+ int error, waitcount = 0;
+ struct timespec ts = {1, 0};
+
+ // wait for any other pending unmounts to complete
+ lock_watch_table();
+ while (fsevent_unmount_dev != 0) {
+ error = msleep((caddr_t)&fsevent_unmount_dev, &watch_table_lock, PRIBIO, "fsevent_unmount_wait", &ts);
+ if (error == EWOULDBLOCK)
+ error = 0;
+ if (!error && (++waitcount >= 10)) {
+ error = EWOULDBLOCK;
+ printf("timeout waiting to signal unmount pending for dev %d (fsevent_unmount_dev %d)\n", dev, fsevent_unmount_dev);
+ }
+ if (error) {
+ // there's a problem, bail out
+ unlock_watch_table();
+ return;
+ }
+ }
+ if (fs_event_type_watchers[FSE_UNMOUNT_PENDING] == 0) {
+ // nobody watching for unmount pending events
+ unlock_watch_table();
+ return;
+ }
+ // this is now the current unmount pending
+ fsevent_unmount_dev = dev;
+ fsevent_unmount_ack_count = fs_event_type_watchers[FSE_UNMOUNT_PENDING];
+ unlock_watch_table();
+
+ // send an event to notify the watcher they need to get off the mount
+ error = add_fsevent(FSE_UNMOUNT_PENDING, ctx, FSE_ARG_DEV, dev, FSE_ARG_DONE);
+
+ // wait for acknowledgment(s) (give up if it takes too long)
+ lock_watch_table();
+ waitcount = 0;
+ while (fsevent_unmount_dev == dev) {
+ error = msleep((caddr_t)&fsevent_unmount_dev, &watch_table_lock, PRIBIO, "fsevent_unmount_pending", &ts);
+ if (error == EWOULDBLOCK)
+ error = 0;
+ if (!error && (++waitcount >= 10)) {
+ error = EWOULDBLOCK;
+ printf("unmount pending ack timeout for dev %d\n", dev);
+ }
+ if (error) {
+ // there's a problem, bail out
+ if (fsevent_unmount_dev == dev) {
+ fsevent_unmount_dev = 0;
+ fsevent_unmount_ack_count = 0;
+ }
+ wakeup((caddr_t)&fsevent_unmount_dev);
+ break;
+ }
+ }
+ unlock_watch_table();
+#endif