Esempio n. 1
0
        public static List <VolumeInfo> GetVolumesAsList()
        {
            var ve  = new VolumeEnumerator();
            var ret = new List <VolumeInfo>();

            do
            {
                ret.Add(ve.info);
            } while (ve.Next());

            return(ret);
        }
Esempio n. 2
0
        static void Main(string[] args)
        {
            if (args.Length < 1)
            {
                Console.WriteLine("Error: The JSON format program config file path must be specified as the first argument.");
                return;
            }

            if (!File.Exists(args[0]))
            {
                Console.WriteLine("Error: The JSON format program config file path does not exist.");
                return;
            }

            var config = JsonConvert.DeserializeObject <ProgramConfig>(File.ReadAllText(args[0]));

            var idTimeout = new ListTTL(60, "idTimeout.json");

            List <VolumeInfo> volumes = VolumeEnumerator.GetVolumesAsList();

            var mountPointsData = new byte[4096];

            foreach (var vol in volumes)
            {
                Console.WriteLine($"{vol.GUIDPath}");

                Int32 charsWritten;

                Array.Clear(mountPointsData, 0, mountPointsData.Length);

                Native.GetVolumePathNamesForVolumeName(vol.GUIDPath, mountPointsData, mountPointsData.Length, out charsWritten);

                var mountPoints = new List <string>();

                int y = 0;

                for (int x = 0; x < mountPointsData.Length; ++x)
                {
                    if (mountPointsData[x] == 0)
                    {
                        var delta = x - y;

                        if (mountPointsData[x] == 0 && mountPointsData[y] == 0)
                        {
                            break;
                        }

                        mountPoints.Add(Encoding.UTF8.GetString(mountPointsData, y, delta));

                        y = x;
                    }
                }

                var volumeNameSb = new StringBuilder(256);
                var fsName       = new StringBuilder(256);

                Int32 serialNum;
                Int32 componentLength;
                Int32 fsFlags;

                Native.GetVolumeInformation(vol.GUIDPath, volumeNameSb, volumeNameSb.Capacity, out serialNum, out componentLength, out fsFlags, fsName, fsName.Capacity);

                var volumeName = volumeNameSb.ToString();

                if (volumeName.Length == 0)
                {
                    volumeName = "NONAME";
                }

                if (idTimeout.Contains(volumeName))
                {
                    Console.WriteLine($"Main: volume rejected on basis of idTimeout {vol.GUIDPath}");
                    continue;
                }

                idTimeout.Add(volumeName);

                idTimeout.Close();

                if (mountPoints.Count > 0)
                {
                    string valid = null;

                    Console.WriteLine($"Main: volume {vol.GUIDPath} HAS mounts; evaluating if any are valid");

                    foreach (var mountPoint in mountPoints)
                    {
                        Console.WriteLine($"Main: checking mount-point {mountPoint}");
                        if (IsVolumeMountPointForUploadValid(mountPoint))
                        {
                            Console.WriteLine($"Main: mount-point was valid");
                            valid = mountPoint;
                            break;
                        }
                    }

                    if (valid == null)
                    {
                        Console.WriteLine($"Main: no mount points were valid; ignoring volume");
                        continue;
                    }

                    Console.WriteLine($"Main: removing mount points to protect data from user access");
                    foreach (var mountPoint in mountPoints)
                    {
                        Native.DeleteVolumeMountPoint(mountPoint);
                    }

                    Console.WriteLine($"Main: mounting as {volumeName}");
                    MountVolumeSpecialAndUpload(volumeName, vol.GUIDPath, config);
                }
                else
                {
                    Console.WriteLine($"Main: volume {vol.GUIDPath} has no mounts; mounting as {volumeName}");
                    MountVolumeSpecialAndUpload(volumeName, vol.GUIDPath, config);
                }
            }

            Console.WriteLine("Done");
        }