Skip to content

Commit 2df5e1e

Browse files
authored
feat: implement mount without blocking (#932)
1 parent 6a50f48 commit 2df5e1e

File tree

2 files changed

+22
-8
lines changed

2 files changed

+22
-8
lines changed

cmd/ipsw/cmd/mount.go

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,13 @@ func init() {
4747
mountCmd.Flags().String("pem-db", "", "AEA pem DB JSON file")
4848
mountCmd.Flags().StringP("mount-point", "m", "", "Custom mount point (default: /tmp/<dmg>.mount)")
4949
mountCmd.Flags().String("ident", "", "Identity Variant to select specific RestoreRamDisk (e.g. 'Erase', 'Upgrade', 'Recovery')")
50+
mountCmd.Flags().BoolP("detach", "d", false, "Mount without blocking (leave mounted in background)")
5051
viper.BindPFlag("mount.key", mountCmd.Flags().Lookup("key"))
5152
viper.BindPFlag("mount.lookup", mountCmd.Flags().Lookup("lookup"))
5253
viper.BindPFlag("mount.pem-db", mountCmd.Flags().Lookup("pem-db"))
5354
viper.BindPFlag("mount.mount-point", mountCmd.Flags().Lookup("mount-point"))
5455
viper.BindPFlag("mount.ident", mountCmd.Flags().Lookup("ident"))
56+
viper.BindPFlag("mount.detach", mountCmd.Flags().Lookup("detach"))
5557
}
5658

5759
// mountCmd represents the mount command
@@ -79,6 +81,9 @@ var mountCmd = &cobra.Command{
7981
8082
# Mount a RestoreRamDisk by identity (defaults to the first if not specified)
8183
$ ipsw mount rdisk iPhone.ipsw --ident Erase
84+
85+
# Mount in background without blocking (detach mode)
86+
$ ipsw mount fs iPhone.ipsw --detach
8287
`),
8388
ValidArgsFunction: func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
8489
if len(args) == 0 {
@@ -98,6 +103,7 @@ var mountCmd = &cobra.Command{
98103
pemDB := viper.GetString("mount.pem-db")
99104
mountPoint := viper.GetString("mount.mount-point")
100105
ident := viper.GetString("mount.ident")
106+
detach := viper.GetBool("mount.detach")
101107
// validate flags
102108
if len(key) > 0 && lookupKeys {
103109
return fmt.Errorf("cannot use --key AND --lookup flags together")
@@ -157,13 +163,18 @@ var mountCmd = &cobra.Command{
157163
log.Infof("Mounted %s DMG %s", args[0], filepath.Base(mctx.DmgPath))
158164
}
159165

160-
// block until user hits ctrl-c
161-
done := make(chan os.Signal, 1)
162-
signal.Notify(done, syscall.SIGINT, syscall.SIGTERM)
163-
utils.Indent(log.Info, 2)(fmt.Sprintf("Press Ctrl+C to unmount '%s' ...", mctx.MountPoint))
164-
<-done
165-
166-
utils.Indent(log.Info, 2)(fmt.Sprintf("Unmounting %s", mctx.MountPoint))
167-
return mctx.Unmount()
166+
if detach {
167+
utils.Indent(log.Info, 2)(fmt.Sprintf("Detaching, run `hdiutil detach %s` to unmount manually", mctx.MountPoint))
168+
return nil
169+
} else {
170+
// block until user hits ctrl-c
171+
done := make(chan os.Signal, 1)
172+
signal.Notify(done, syscall.SIGINT, syscall.SIGTERM)
173+
utils.Indent(log.Info, 2)(fmt.Sprintf("Press Ctrl+C to unmount '%s' ...", mctx.MountPoint))
174+
<-done
175+
176+
utils.Indent(log.Info, 2)(fmt.Sprintf("Unmounting %s", mctx.MountPoint))
177+
return mctx.Unmount()
178+
}
168179
},
169180
}

www/docs/cli/ipsw/mount.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ ipsw mount [fs|sys|app|exc|rdisk] IPSW [flags]
2020
# Mount the filesystem DMG from an IPSW
2121
$ ipsw mount fs iPhone15,2_16.5_20F66_Restore.ipsw
2222

23+
# Mount the filesystem without blocking or prompting the user to unmount the DMG
24+
$ ipsw mount fs --detach iPhone15,2_16.5_20F66_Restore.ipsw
25+
2326
# Mount the system DMG with a specific decryption key
2427
$ ipsw mount sys iPhone.ipsw --key "a1b2c3d4e5f6..."
2528

0 commit comments

Comments
 (0)