示例#1
0
        public static MountModel Create(string path, MountContext context, MountEntity entity)
        {
            var get        = Get(path);
            var mntContext = get?.MountContext ?? context;
            var exMount    = Get(path);

            if (exMount != null)
            {
                return(exMount);
            }
            var mount = new MountModel {
                _Id          = Guid.NewGuid().ToString(),
                Guid         = Guid.NewGuid().ToString(),
                DFPTimestamp = Timestamp.Now,
                MountContext = mntContext,
                MountEntity  = entity,
                Path         = path
            };

            DeNSo.Session.New.Set(mount);
            return(mount);
        }
示例#2
0
        public static IEnumerable <MountModel> Get()
        {
            var list       = new List <MountModel>();
            var deny       = new List <string>();
            var procmounts = FileSystem.ReadFile("/proc/mounts");

            if (procmounts.Length > 0)
            {
                var rows = procmounts.Split(new[] { "\n" }, StringSplitOptions.RemoveEmptyEntries).ToArray();
                foreach (var row in rows)
                {
                    var cells = row.Split(new[] { " " }, StringSplitOptions.RemoveEmptyEntries).ToArray();
                    if (cells.Length <= 0)
                    {
                        continue;
                    }
                    var mm = new MountModel {
                        Device       = cells[0].Trim(),
                        Path         = cells[1].Trim(),
                        MountContext = MountContext.Other,
                        Type         = cells[2].Trim(),
                        Options      = cells[3].Trim()
                    };
                    if (mm.Options.Contains("rw"))
                    {
                        mm.MountStatus = MountStatus.MountedReadWrite;
                    }
                    else if (mm.Options.Contains("ro"))
                    {
                        mm.MountStatus = MountStatus.MountedReadOnly;
                    }
                    else
                    {
                        mm.MountStatus = MountStatus.Mounted;
                    }

                    if (mm.Type.Contains("squash"))
                    {
                        mm.MountedPath = GetSquashMount(mm.Device);
                    }
                    else
                    {
                        var mntpt = GetBindMount(mm.Path);
                        if (mntpt == null)
                        {
                            mm.MountedPath = "";
                        }
                        else
                        {
                            mm.MountedPath = mntpt;
                            deny.Add(mntpt.Trim());
                        }
                    }
                    list.Add(mm);
                }
            }

            var preList = list.Where(m => !deny.Contains(m.Path)).OrderBy(m => m.Device).ThenBy(m => m.Path).ToList();

            foreach (var el in deny.Select(d => preList.FirstOrDefault(m => m.Path == d)).Where(el => el != null))
            {
                preList.Remove(el);
            }

            return(preList);
        }