Esempio n. 1
0
        public void RemountMountPoint(MountPoint mnt, bool readOnly)
        {
            string command = $"mount -o {(readOnly ? "ro" : "rw")},remount -t {mnt.FileSystem} {mnt.Block} {mnt.Name}";

            this.ExecuteShellCommand(command, NullOutputReceiver.Instance);
            RefreshMountPoints();
        }
Esempio n. 2
0
 public void RemountMountPoint(string mountPoint, bool readOnly)
 {
     if (this.MountPoints.ContainsKey(mountPoint))
     {
         MountPoint mnt = this.MountPoints[mountPoint];
         RemountMountPoint(mnt, readOnly);
     }
     else
     {
         throw new IOException("Invalid mount point");
     }
 }
Esempio n. 3
0
        /// <summary>
        /// Mounts the specified device.
        /// </summary>
        /// <param name="mountPoint">The mp.</param>
        /// <param name="options">The options.</param>
        public void Mount(MountPoint mountPoint, string options)
        {
            mountPoint.ThrowIfNull("mountPoint");
            Device.ThrowIfNull("Device");

            CommandErrorReceiver cer = new CommandErrorReceiver( );

            if (Device.BusyBox.Available)
            {
                Device.ExecuteShellCommand("busybox mount {0} {4} -t {1} {2} {3}", cer, mountPoint.IsReadOnly ? "-r" : "-w",
                                           mountPoint.FileSystem, mountPoint.Block, mountPoint.Name,
                                           !string.IsNullOrEmpty(options) ? string.Format("-o {0}", options) : string.Empty);
            }
            else
            {
                Device.ExecuteShellCommand("mount {0} {4} -t {1} {2} {3}", cer, mountPoint.IsReadOnly ? "-r" : "-w",
                                           mountPoint.FileSystem, mountPoint.Block, mountPoint.Name,
                                           !string.IsNullOrEmpty(options) ? string.Format("-o {0}", options) : string.Empty);
            }
        }
Esempio n. 4
0
        /// <summary>
        /// Processes the new lines.
        /// </summary>
        /// <param name="lines">The lines.</param>
        /// <workitem id="16001">Bug w/ MountPointReceiver.cs/ProcessNewLines()</workitem>
        protected override void ProcessNewLines(string[] lines)
        {
            Device.MountPoints.Clear();
            foreach (string line in lines)
            {
                Match m = line.Match(RE_MOUNTPOINT_PATTERN, RegexOptions.Compiled | RegexOptions.IgnoreCase | RegexOptions.IgnorePatternWhitespace);
                if (m.Success)
                {
                    string     block = m.Groups[1].Value.Trim().Replace("//", "/");
                    string     name  = m.Groups[2].Value.Trim();
                    string     fs    = m.Groups[3].Value.Trim();
                    bool       ro    = Util.equals("ro", m.Groups[4].Value.Trim());
                    MountPoint mnt   = new MountPoint(block, name, fs, ro);
                    string     key   = name.Substring(1);
                    // currently does not support multiple mounts to the same location...
                    if (!Device.MountPoints.ContainsKey(name))
                    {
                        Device.MountPoints.Add(name, mnt);
                    }
                }
            }

            /*
             *          foreach ( var line in lines ) {
             *                  Match m = Regex.Match ( line, RE_MOUNTPOINT_PATTERN, RegexOptions.Compiled | RegexOptions.IgnoreCase | RegexOptions.IgnorePatternWhitespace );
             *                  if ( m.Success ) {
             *                          String block = m.Groups[1].Value.Trim ( ).Replace ( "//", "/" );
             *                          String name = m.Groups[2].Value.Trim ( );
             *                          String fs = m.Groups[3].Value.Trim ( );
             *                          bool ro = String.Compare ( "ro", m.Groups[4].Value.Trim ( ), false ) == 0;
             *                          MountPoint mnt = new MountPoint ( block, name, fs, ro );
             *                          String key = name.Substring ( 1 );
             *                          // currently does not support multiple mounts to the same location...
             *                          if ( !Device.MountPoints.ContainsKey ( name ) ) {
             *                                  Device.MountPoints.Add ( name, mnt );
             *                          }
             *                  }
             *          }*/
        }
Esempio n. 5
0
 /// <summary>
 /// Processes the new lines.
 /// </summary>
 /// <param name="lines">The lines.</param>
 /// <workitem id="16001">Bug w/ MountPointReceiver.cs/ProcessNewLines()</workitem>
 protected override void ProcessNewLines(string[] lines)
 {
     Device.MountPoints.Clear();
     foreach (string line in lines)
         {
         Match m = line.Match(RE_MOUNTPOINT_PATTERN, RegexOptions.Compiled | RegexOptions.IgnoreCase | RegexOptions.IgnorePatternWhitespace);
         if (m.Success)
             {
             string block = m.Groups[1].Value.Trim().Replace("//", "/");
             string name = m.Groups[2].Value.Trim();
             string fs = m.Groups[3].Value.Trim();
             bool ro = Util.equals("ro", m.Groups[4].Value.Trim());
             MountPoint mnt = new MountPoint(block, name, fs, ro);
             string key = name.Substring(1);
             // currently does not support multiple mounts to the same location...
             if (!Device.MountPoints.ContainsKey(name))
                 {
                 Device.MountPoints.Add(name, mnt);
                 }
             }
         }
     /*
     foreach ( var line in lines ) {
         Match m = Regex.Match ( line, RE_MOUNTPOINT_PATTERN, RegexOptions.Compiled | RegexOptions.IgnoreCase | RegexOptions.IgnorePatternWhitespace );
         if ( m.Success ) {
             String block = m.Groups[1].Value.Trim ( ).Replace ( "//", "/" );
             String name = m.Groups[2].Value.Trim ( );
             String fs = m.Groups[3].Value.Trim ( );
             bool ro = String.Compare ( "ro", m.Groups[4].Value.Trim ( ), false ) == 0;
             MountPoint mnt = new MountPoint ( block, name, fs, ro );
             String key = name.Substring ( 1 );
             // currently does not support multiple mounts to the same location...
             if ( !Device.MountPoints.ContainsKey ( name ) ) {
                 Device.MountPoints.Add ( name, mnt );
             }
         }
     }*/
 }
Esempio n. 6
0
        /// <summary>
        /// Unmounts the specified mount point.
        /// </summary>
        /// <param name="mountPoint">The mountPoint.</param>
        /// <param name="options">The options.</param>
        public void Unmount(MountPoint mountPoint, string options)
        {
            mountPoint.ThrowIfNull("mountPoint");

            Unmount(mountPoint.Name, options);
        }
Esempio n. 7
0
 /// <summary>
 /// Unmounts the specified mount point.
 /// </summary>
 /// <param name="mountPoint">The mountPoint.</param>
 public void Unmount(MountPoint mountPoint)
 {
     Unmount(mountPoint, string.Empty);
 }
Esempio n. 8
0
        /// <summary>
        /// Attempts to install on the device
        /// </summary>
        /// <param name="busybox">The path to the busybox binary to install.</param>
        /// <returns><c>true</c>, if successful; otherwise, <c>false</c></returns>
        public bool Install(string busybox)
        {
            busybox.ThrowIfNullOrWhiteSpace("busybox");

            FileEntry bb = null;

            try {
                Device.ExecuteShellCommand(BUSYBOX_COMMAND, NullOutputReceiver.Instance);
                return(true);
            } catch {
                // we are just checking if it is already installed so we really expect it to wind up here.
            }

            try {
                MountPoint mp   = Device.MountPoints["/data"];
                bool       isRO = mp.IsReadOnly;
                Device.RemountMountPoint(Device.MountPoints["/data"], false);

                FileEntry path = null;
                try {
                    path = Device.FileListingService.FindFileEntry(BUSYBOX_BIN);
                } catch (FileNotFoundException) {
                    // path doesn't exist, so we make it.
                    Device.FileSystem.MakeDirectory(BUSYBOX_BIN);
                    // attempt to get the FileEntry after the directory has been made
                    path = Device.FileListingService.FindFileEntry(BUSYBOX_BIN);
                }

                Device.FileSystem.Chmod(path.FullPath, "0755");

                string bbPath = LinuxPath.Combine(path.FullPath, BUSYBOX_COMMAND);

                Device.FileSystem.Copy(busybox, bbPath);


                bb = Device.FileListingService.FindFileEntry(bbPath);
                Device.FileSystem.Chmod(bb.FullPath, "0755");

                Device.ExecuteShellCommand("{0}/busybox --install {0}", new ConsoleOutputReceiver( ), path.FullPath);

                // check if this path exists in the path already
                if (Device.EnvironmentVariables.ContainsKey("PATH"))
                {
                    var paths = Device.EnvironmentVariables["PATH"].Split(':');
                    var found = paths.Where(p => Util.equals(p, BUSYBOX_BIN)).Count( ) > 0;

                    // we didnt find it, so add it.
                    if (!found)
                    {
                        // this doesn't seem to actually work
                        Device.ExecuteShellCommand(@"echo \ Mad Bee buxybox >> /init.rc", NullOutputReceiver.Instance);
                        Device.ExecuteShellCommand(@"echo export PATH={0}:\$PATH >> /init.rc", NullOutputReceiver.Instance, BUSYBOX_BIN);
                    }
                }


                if (mp.IsReadOnly != isRO)
                {
                    // Put it back, if we changed it
                    Device.RemountMountPoint(mp, isRO);
                }

                Device.ExecuteShellCommand("sync", NullOutputReceiver.Instance);
            } catch (Exception) {
                throw;
            }

            CheckForBusyBox( );
            return(true);
        }
Esempio n. 9
0
 public void RemountMountPoint(MountPoint mnt, bool readOnly)
 {
     string command = $"mount -o {(readOnly ? "ro" : "rw")},remount -t {mnt.FileSystem} {mnt.Block} {mnt.Name}";
     this.ExecuteShellCommand(command, NullOutputReceiver.Instance);
     RefreshMountPoints();
 }
Esempio n. 10
0
        /// <summary>
        /// Unmounts the specified mount point.
        /// </summary>
        /// <param name="mountPoint">The mountPoint.</param>
        /// <param name="options">The options.</param>
        public void Unmount( MountPoint mountPoint, string options )
        {
            mountPoint.ThrowIfNull ( "mountPoint" );

            Unmount ( mountPoint.Name, options );
        }
Esempio n. 11
0
 /// <summary>
 /// Unmounts the specified mount point.
 /// </summary>
 /// <param name="mountPoint">The mountPoint.</param>
 public void Unmount( MountPoint mountPoint )
 {
     Unmount ( mountPoint, string.Empty );
 }
Esempio n. 12
0
        /// <summary>
        /// Mounts the specified device.
        /// </summary>
        /// <param name="mountPoint">The mp.</param>
        /// <param name="options">The options.</param>
        public void Mount( MountPoint mountPoint, string options )
        {
            mountPoint.ThrowIfNull ( "mountPoint" );
            Device.ThrowIfNull ( "Device" );

            CommandErrorReceiver cer = new CommandErrorReceiver ( );
            if ( Device.BusyBox.Available ) {
                Device.ExecuteShellCommand ( "busybox mount {0} {4} -t {1} {2} {3}", cer, mountPoint.IsReadOnly ? "-r" : "-w",
                    mountPoint.FileSystem, mountPoint.Block, mountPoint.Name,
                    !string.IsNullOrEmpty ( options ) ? string.Format ( "-o {0}", options ) : string.Empty );
            } else {
                Device.ExecuteShellCommand ( "mount {0} {4} -t {1} {2} {3}", cer, mountPoint.IsReadOnly ? "-r" : "-w",
                    mountPoint.FileSystem, mountPoint.Block, mountPoint.Name,
                    !string.IsNullOrEmpty ( options ) ? string.Format ( "-o {0}", options ) : string.Empty );
            }
        }