示例#1
0
 protected override Errno OnOpenHandle(string path, OpenedPathInfo fi)
 {
     // return Errno.ENOENT; // Doesn't exist
     //if (fi.OpenAccess != OpenFlags.O_RDONLY)
     //    return Errno.EACCES; // Read only
     return 0;
 }
示例#2
0
        protected override Errno OnReadDirectory(string directory, OpenedPathInfo info, out IEnumerable<DirectoryEntry> paths)
        {
            List<DirectoryEntry> entries = new List<DirectoryEntry>();
            entries.Add(new DirectoryEntry("."));
            entries.Add(new DirectoryEntry(".."));

            FlacFsObjectInfo [] fsEntries = flacFs_.ListDirectoryContents(directory);
            foreach(FlacFsObjectInfo fsoi in fsEntries)
            {
                entries.Add(new DirectoryEntry(fsoi.Name));
            }
            paths = entries;
            return 0;
        }
示例#3
0
        protected override Errno OnReadDirectory(string path, OpenedPathInfo fi, out IEnumerable<DirectoryEntry> paths)
        {
            paths = null;
            //if (path != "/") {
            //    return Errno.ENOENT;
            //}

            IList<VFileInfo> vfiles;
            data.List (path, out vfiles);

            IList<DirectoryEntry> files = new List<DirectoryEntry> ();
            files.Add (new DirectoryEntry ("."));
            files.Add (new DirectoryEntry (".."));
            foreach (VFileInfo vf in vfiles) {
                files.Add (new DirectoryEntry (vf.Name));
            }
            paths = files;
            return 0;
        }
示例#4
0
 protected override Errno OnSynchronizeHandle(string path, OpenedPathInfo info, bool onlyUserData)
 {
     return 0;
 }
示例#5
0
        protected unsafe override Errno OnReadHandle(string path, OpenedPathInfo info, byte[] buf, 
				long offset, out int bytesRead)
        {
            int br = 0;
            var realPath = GetRealPath(path);
            using (var stream = File.OpenRead(realPath))
            {
                br = stream.Read(buf, (int)offset, buf.Length);
            }
            bytesRead = br;
            return 0;
        }
示例#6
0
 public unsafe override Errno WriteHandle(string path, OpenedPathInfo info, 
     byte[] buf, long offset, out int bytesWritten)
 {
     try {
     // "path" is not used in base.WriteHandle
     return base.WriteHandle(path, info, buf, offset, out bytesWritten);
       } catch (Exception ex) {
     Logger.WriteLineIf(LogLevel.Error, _log_props, string.Format(
       "Exception caught when writing to file. {0}", ex));
     throw;
       }
 }
示例#7
0
        /// <summary>
        /// Opens the handle.
        /// </summary>
        /// <param name="path">The path.</param>
        /// <param name="info">The info.</param>
        public override Errno OpenHandle(string path, OpenedPathInfo info)
        {
            Errno retVal;
              if (info.OpenAccess == OpenFlags.O_RDONLY) {
            String readPath = _pathFactory.CreateVirtualPath4Read(new VirtualRawPath(path));
            retVal = base.OpenHandle(readPath, info);
              } else {
            // This is a write.
            // @TODO Write to an existing file is not supported by BitTorrent.
            // It has to be enforced somewhere.
            String writePath = _pathFactory.CreateVirtualPath4Write(new VirtualRawPath(path));
            retVal = base.OpenHandle(writePath, info);
              }

              // Add to filesys context.
              VirtualPath vp = VirtualPath.CreateFromRawString(path);
              VirtualFile vf = _fileManager.ReadVirtualFile(vp);
              FileAccess fa = IOUtil.OpenFlags2FileAccess(info.OpenAccess);
              var openFileInfo = new OpenFileInfo(info.Handle, vp, vf, fa);
              _filesysContext.AddOpenFile(info.Handle, openFileInfo);

              return retVal;
        }
示例#8
0
        /// <summary>
        /// Creates the handle.
        /// </summary>
        /// <param name="path">The path.</param>
        /// <param name="info">The info.</param>
        /// <param name="mode">The mode.</param>
        /// <returns></returns>
        /// <remarks>This method is for FilesysOp.Write.</remarks>
        public override Errno CreateHandle(string path, OpenedPathInfo info, FilePermissions mode)
        {
            // Create the handle for the write.
              String writePath =
            _pathFactory.CreateVirtualPath4Write(new VirtualRawPath(path));
              Errno retVal = base.CreateHandle(writePath, info, mode);

              // Create the VF so the reads afterwards knows about the file.
              VirtualPath vp = VirtualPath.CreateFromRawString(path);
              VirtualFile vf = CreateAndWriteVirtualFile(vp);
              var ofi = new OpenFileInfo(info.Handle, vp, vf, FileAccess.Write);
              _filesysContext.AddOpenFile(info.Handle, ofi);
              return retVal;
        }
示例#9
0
 protected override Errno OnTruncateHandle(string path, OpenedPathInfo info, long size)
 {
     int r = Syscall.ftruncate ((int) info.Handle, size);
     if (r == -1)
         return Stdlib.GetLastError ();
     return 0;
 }
示例#10
0
 protected override Errno OnCreateHandle(string path, OpenedPathInfo info, FilePermissions mode)
 {
     int fd = Syscall.open (basedir+path, info.OpenFlags, mode);
     if (fd == -1)
         return Stdlib.GetLastError ();
     info.Handle = (IntPtr) fd;
     return 0;
 }
示例#11
0
        protected override Errno OnReadHandle(string path, OpenedPathInfo fi, byte[] buf, long offset, out int bytesWritten)
        {
            Logging.Write (string.Format ("(OnRead: Path {0}, buflen {1}, offset {2})", path, buf.Length, offset));
            string nodepath = SoundCloudFS.FileTree.Node.ParseNodeName(path);
            string trackfilename = SoundCloudFS.FileTree.Node.ParseTrackFilename(path);
            int nodeid = SoundCloudFS.FileTree.Node.FindNode(nodepath);

            bytesWritten = 0;
            int size = buf.Length;
            //if(7 != 32) { return Errno.ENOENT; }
            bool found = false;
            for(int etrack = 0; etrack < Engine.FSNodes[nodeid].Tracks.Length; etrack++)
            {
                Logging.Write(nodepath + "/" + Engine.FSNodes[nodeid].Tracks[etrack].Filename);
                if(Engine.FSNodes[nodeid].Tracks[etrack] != null && path == nodepath + "/" + Engine.FSNodes[nodeid].Tracks[etrack].Filename)
                {
                    Engine.FSNodes[nodeid].Tracks[etrack].Touch();

                    if(!Engine.FSNodes[nodeid].Tracks[etrack].Retrieved)
                    {

                        if(!Engine.FSNodes[nodeid].Tracks[etrack].Retrieve()) { return Errno.EAGAIN; }
                    }

                    if(offset < Engine.FSNodes[nodeid].Tracks[etrack].RawData.Length)
                    {
                        if(offset + (long)size > (long)Engine.FSNodes[nodeid].Tracks[etrack].RawData.Length) { size = (int)((long)Engine.FSNodes[nodeid].Tracks[etrack].RawData.Length - offset); }
                        Buffer.BlockCopy(Engine.FSNodes[nodeid].Tracks[etrack].RawData, (int)offset, buf, 0, size);
                        found = true;
                        break;
                    }
                    else
                    {
                        size = 0;
                    }
                }
            }
            if(!found) { Logging.Write("ReadFile: File Not Found"); return Errno.ENOENT; }
            bytesWritten = size;
            /*if (path == data_im_path)
                FillData ();
            if (path == hello_path || path == data_im_path) {
                byte[] source = path == hello_path ? hello_str : data_im_str;
                if (offset < (long) source.Length) {
                    if (offset + (long) size > (long) source.Length)
                        size = (int) ((long) source.Length - offset);
                    Buffer.BlockCopy (source, (int) offset, buf, 0, size);
                }
                else
                    size = 0;
            }
            else if (path == data_path) {
                int max = System.Math.Min ((int) data_size, (int) (offset + buf.Length));
                for (int i = 0, j = (int) offset; j < max; ++i, ++j) {
                    if ((j % 27) == 0)
                        buf [i] = (byte) '\n';
                    else
                        buf [i] = (byte) ((j % 26) + 'a');
                }
            }
            else
                return Errno.ENOENT;
            */
            //bytesWritten = size;
            return 0;
        }
示例#12
0
        protected override Errno OnReadDirectory(string path, OpenedPathInfo fi,
				out IEnumerable<DirectoryEntry> paths)
        {
            Logging.Write(string.Format ("(OnReadDirectory {0})", path));
            paths = null;
            string nodepath = SoundCloudFS.FileTree.Node.ParseNodeName(path);

            int nodeid = SoundCloudFS.FileTree.Node.FindNode(nodepath);
            if(nodeid < 0) { return Errno.ENOENT; }

            //if (path != "/")
            //	return Errno.ENOENT;

            paths = GetEntries(nodeid);
            return 0;
        }
示例#13
0
        protected override Errno OnOpenHandle(string path, OpenedPathInfo fi)
        {
            Logging.Write(string.Format ("(OnOpen {0} Flags={1})", path, fi.OpenFlags));

            //if(fi.OpenAccess == OpenFlags.O_TRUNC & OpenFlags.O_WRONLY) { Logging.Write("File opened for truncation."); return 0; }

            if(fi.OpenAccess != OpenFlags.O_RDONLY) {
                Logging.Write("Somethign being opened as not READ ONLY!");
                return 0;
                //return Errno.EACCES;
            }

            string nodepath = SoundCloudFS.FileTree.Node.ParseNodeName(path);
            string trackfilename = SoundCloudFS.FileTree.Node.ParseTrackFilename(path);
            int nodeid = SoundCloudFS.FileTree.Node.FindNode(nodepath);

            for(int etrack = 0; etrack < Engine.FSNodes[nodeid].Tracks.Length; etrack++)
            {
                if(Engine.FSNodes[nodeid].Tracks[etrack] != null)
                {
                    if(nodepath + "/" + Engine.FSNodes[nodeid].Tracks[etrack].Filename == path)
                    {
                        Engine.FSNodes[nodeid].Tracks[etrack].Touch();
                        return 0;
                    }
                }
            }

            return Errno.ENOENT;
            /*if (path != hello_path && path != data_path && path != data_im_path)
                return Errno.ENOENT;
            if (path == data_im_path && !have_data_im)
                return Errno.ENOENT;
            if (fi.OpenAccess != OpenFlags.O_RDONLY)
                return Errno.EACCES;
            return 0;*/
        }
示例#14
0
        protected unsafe override Errno OnWriteHandle(string path, OpenedPathInfo info,
            byte[] buf, long offset, out int bytesWritten)
        {
            Logger.WriteLineIf(LogLevel.Verbose, _fslog_props, string.Format("OnWriteHandle, path={0}, handle={1}, buflength={2}, offset={3}", path, info.Handle, buf.Length, offset));

              return this._rfs.WriteHandle(path, info, buf, offset, out bytesWritten);
        }
示例#15
0
        protected override Errno OnTruncateHandle(string path, OpenedPathInfo info, long size)
        {
            Logger.WriteLineIf(LogLevel.Verbose, _fslog_props, string.Format("OnTruncateHandle, path={0}, handle={1}, size={2}", path, info.Handle, size));

              return this._rfs.TruncateHandle(path, info, size);
        }
示例#16
0
 protected override Errno OnReleaseHandle(string path, OpenedPathInfo info)
 {
     int r = Syscall.close ((int) info.Handle);
     if (r == -1)
         return Stdlib.GetLastError ();
     return 0;
 }
示例#17
0
 protected override Errno OnSynchronizeHandle(string path, OpenedPathInfo info, bool onlyUserData)
 {
     int r;
     if (onlyUserData)
         r = Syscall.fdatasync ((int) info.Handle);
     else
         r = Syscall.fsync ((int) info.Handle);
     if (r == -1)
         return Stdlib.GetLastError ();
     return 0;
 }
示例#18
0
 protected override Errno OnFlushHandle(string path, OpenedPathInfo info)
 {
     /* This is called from every close on an open file, so call the
        close on the underlying filesystem.  But since flush may be
        called multiple times for an open file, this must not really
        close the file.  This is important if used on a network
        filesystem like NFS which flush the data/metadata on close() */
     int r = Syscall.close (Syscall.dup ((int) info.Handle));
     if (r == -1)
         return Stdlib.GetLastError ();
     return 0;
 }
示例#19
0
        protected unsafe override Errno OnWriteHandle(string path, OpenedPathInfo info,
				byte[] buf, long offset, out int bytesWritten)
        {
            int r;
            fixed (byte *pb = buf) {
                r = bytesWritten = (int) Syscall.pwrite ((int) info.Handle,
                        pb, (ulong) buf.Length, offset);
            }
            if (r == -1)
                return Stdlib.GetLastError ();
            return 0;
        }
示例#20
0
 protected override Errno OnGetHandleStatus(string path, OpenedPathInfo info, out Stat buf)
 {
     int r = Syscall.fstat ((int) info.Handle, out buf);
     if (r == -1)
         return Stdlib.GetLastError ();
     return 0;
 }
示例#21
0
 /// <summary>
 /// Gets the handle status. This method gets the status of the virtual file
 /// and replaces the size with that of the real data file.
 /// </summary>
 public override Errno GetHandleStatus(string path, OpenedPathInfo info, 
     out Stat buf)
 {
     Errno ret;
       ret = base.GetHandleStatus(path, info, out buf);
       if ((buf.st_mode & FilePermissions.S_IFREG) != 0) {
     // Make a change to file size if is a file (S_IFREG)
     buf.st_size = _fileManager.GetFileLength(
       VirtualPath.CreateFromRawString(path));
       }
       return ret;
 }
示例#22
0
 protected override Errno OnLockHandle(string file, OpenedPathInfo info, FcntlCommand cmd, ref Flock @lock)
 {
     int r = Syscall.fcntl ((int) info.Handle, cmd, ref @lock);
     if (r == -1)
         return Stdlib.GetLastError ();
     return 0;
 }
示例#23
0
 public override Errno ReleaseHandle(string path, OpenedPathInfo info)
 {
     _filesysContext.RemoveOpenFile(info.Handle);
       VirtualPath vp = VirtualPath.CreateFromRawString(path);
       UpdateFileSizeInVirtualFile(vp);
       return base.ReleaseHandle(path, info);
 }
示例#24
0
        protected override Errno OnOpenDirectory(string path, OpenedPathInfo info)
        {
            IntPtr dp = Syscall.opendir (basedir+path);
            if (dp == IntPtr.Zero)
                return Stdlib.GetLastError ();

            info.Handle = dp;
            return 0;
        }
示例#25
0
        protected override Errno OnReadDirectory(string path, OpenedPathInfo fi,
				out IEnumerable<DirectoryEntry> paths)
        {
            List<DirectoryEntry> entries = new List<DirectoryEntry>();
            entries.Add(new DirectoryEntry("."));
            entries.Add(new DirectoryEntry(".."));

            var depth = path.Count(x => x == '/');

            switch (depth)
            {
                case 1:
                    if (path == "/")
                    {
                        foreach (var name in _tagDictionary.Keys.Select(x => x.Name).Distinct())
                        {
                            entries.Add(new DirectoryEntry(name));
                        }
                    }
                    else
                    {
                        foreach (var tag in _tagDictionary.Keys.Where(x => x.Name == path.Substring(1)))
                        {
                            entries.Add(new DirectoryEntry(tag.Value));
                        }
                    }
                    break;
                case 2:
                    var key = CreateTag(path);
                    foreach (var file in _tagDictionary[key])
                    {
                        entries.Add(new DirectoryEntry(file.Name));
                    }
                    break;
            }

            paths = entries;
            return 0;
        }
示例#26
0
 protected override Errno OnOpenHandle(string path, OpenedPathInfo info)
 {
     int fd = Syscall.open (basedir+path, info.OpenFlags);
     if (fd == -1)
         return Stdlib.GetLastError ();
     info.Handle = (IntPtr) fd;
     return 0;
 }
示例#27
0
 protected override Errno OnReleaseHandle(string path, OpenedPathInfo info)
 {
     return 0;
 }
示例#28
0
        protected override Errno OnReadDirectory(string path, OpenedPathInfo fi,
				out IEnumerable<DirectoryEntry> paths)
        {
            IntPtr dp = (IntPtr) fi.Handle;

            paths = ReadDirectory (dp);

            return 0;
        }
示例#29
0
 protected override Errno OnOpenHandle(string path, OpenedPathInfo info)
 {
     return 0;
     //			string realPath = GetRealPath(path);
     //			return ProcessFile(realPath, info.OpenFlags, delegate (int fd)
     //			{
     //				return 0;
     //			}
     //			);
 }
示例#30
0
 protected override Errno OnReleaseDirectory(string path, OpenedPathInfo info)
 {
     IntPtr dp = (IntPtr) info.Handle;
     Syscall.closedir (dp);
     return 0;
 }