Ejemplo n.º 1
0
    static void xdr2fattr( Dictionary<int,Object> attr, int fattr , XdrDecodingStream xdr)
    {

        switch(fattr) {

            case NFSv4Protocol.FATTR4_SIZE :
                uint64_t size = new uint64_t();
                size.xdrDecode(xdr);
                attr.Add(fattr, size);
                break;
            case NFSv4Protocol.FATTR4_MODE :
                mode4 mode = new mode4();
                mode.xdrDecode(xdr);
                attr.Add(fattr, mode);
                break;
            case NFSv4Protocol.FATTR4_TYPE :
                fattr4_type type = new fattr4_type();
                type.xdrDecode(xdr);
                attr.Add(fattr,type );
                break;
            case NFSv4Protocol.FATTR4_TIME_CREATE :
                nfstime4 time = new nfstime4();
                time.xdrDecode(xdr);
                attr.Add(fattr,time);
                break;
           case NFSv4Protocol.FATTR4_TIME_ACCESS :
                nfstime4 time2 = new nfstime4();
                time2.xdrDecode(xdr);
                attr.Add(fattr,time2);
                break;
           case NFSv4Protocol.FATTR4_TIME_MODIFY :
                nfstime4 time3 = new nfstime4();
                time3.xdrDecode(xdr);
                attr.Add(fattr,time3);
                break;
            /*case NFSv4Protocol.FATTR4_OWNER :
// TODO: use princilat
utf8str_cs owner = new utf8str_cs ();
owner.xdrDecode(xdr);
String new_owner = new String(owner.value.value);
attr.Add(fattr,new_owner );
break;
case NFSv4Protocol.FATTR4_OWNER_GROUP :
// TODO: use princilat
utf8str_cs owner_group = new utf8str_cs ();
owner_group.xdrDecode(xdr);
String new_group = new String(owner_group.value.value);
attr.Add(fattr,new_group );
break;*/
            default:
                break;

        }


    }
Ejemplo n.º 2
0
        static uint64_t ReadUint64(Vector buffer,
                                   out int number_of_read_digits)
        {
            uint64_t result = 0;
            int      i      = 0;

            while (i < buffer.length() && result <= (kMaxUint64 / 10 - 1))
            {
                int digit = buffer[i++] - '0';
                result = 10 * result + (ulong)digit;
            }
            number_of_read_digits = i;
            return(result);
        }
Ejemplo n.º 3
0
        public void create(string path, uint64_t size, bool overwrite, ref std::error_code ec)
        {
            if (isOpened())
            {
                close(ref ec);
                if (ec != null)
                {
                    return;
                }
            }

//C++ TO C# CONVERTER TODO TASK: Only lambda expressions having all locals passed by reference can be converted to C#:
//ORIGINAL LINE: Tools::ScopeExit failExitHandler([this, &ec]
            Tools.ScopeExit failExitHandler(() =>
            {
                ec = std::error_code(errno, std::system_category());
                std::error_code ignore = new std::error_code();
                close(ref ignore);
            });

            m_file = global::open(path, O_RDWR | O_CREAT | (overwrite ? O_TRUNC : O_EXCL), S_IRUSR | S_IWUSR);
            if (m_file == -1)
            {
                return;
            }

            int result = global::ftruncate(m_file, (off_t)size);

            if (result == -1)
            {
                return;
            }

//C++ TO C# CONVERTER TODO TASK: There is no equivalent to 'reinterpret_cast' in C#:
            m_data = reinterpret_cast <uint8_t>(global::mmap(null, (size_t)size, PROT_READ | PROT_WRITE, MAP_SHARED, m_file, 0));
            if (m_data == MAP_FAILED)
            {
                return;
            }

//C++ TO C# CONVERTER TODO TASK: The following line was determined to be a copy assignment (rather than a reference assignment) - this should be verified and a 'CopyFrom' method should be created:
//ORIGINAL LINE: m_size = size;
            m_size.CopyFrom(size);
            m_path = path;
            ec     = std::error_code();

            failExitHandler.cancel();
        }
Ejemplo n.º 4
0
        public byte[] Add(byte[] a, byte[] b, out bool overflow)
        {
            uint64_t _a = new uint64_t(a);
            uint64_t _b = new uint64_t(b);

            uint64_t result = _a + _b;

            byte[] r = result.ToBinary();
            byte[] values;

            overflow = false;

            if (a.Length >= b.Length)
            {
                values = new byte[a.Length];
            }
            else
            {
                values = new byte[b.Length];
            }

            Array.Copy(r, values, values.Length);
            if (values.Length < 8)
            {
                overflow = (r[values.Length + 1] > 0);
            }
            else
            {
                try
                {
                    UInt64 temp = checked (_a + _b);
                }
                catch (OverflowException)
                {
                    overflow = true;
                    flags    = flags | ALUFlags.Overflow;
                }
            }

            flags = ALUFlags.None;
            if (overflow)
            {
                flags = flags | ALUFlags.Overflow;
            }
            return(values);
        }
Ejemplo n.º 5
0
        public void Compare(byte[] a, byte[] b)
        {
            uint64_t _a = new uint64_t(a);
            uint64_t _b = new uint64_t(b);

            flags = ALUFlags.None;
            if (_a.Value == _b.Value)
            {
                flags = flags | ALUFlags.Equal;
            }
            if (_a.Value > _b.Value)
            {
                flags = flags | ALUFlags.GreaterThan;
            }
            if (_a.Value < _b.Value)
            {
                flags = flags | ALUFlags.LessThan;
            }
        }
Ejemplo n.º 6
0
        public static SortedSet<Tuple<SortedSet<string>, UInt64>> fptree_growth(FPTree fptree)
        {
            if (fptree.empty())
            {
                return { };
            }

            if (contains_single_path(fptree))
            {
                // generate all possible combinations of the items in the tree

                SortedSet<Tuple<SortedSet<string>, uint64_t>> single_path_patterns = new SortedSet<Tuple<SortedSet<string>, uint64_t>>();

                // for each node in the tree
                Debug.Assert(fptree.root.children.Count == 1);
                var curr_fpnode = fptree.root.children[0];
                while (curr_fpnode)
                {
                    string curr_fpnode_item = curr_fpnode.item;
                    uint64_t curr_fpnode_frequency = curr_fpnode.frequency;

                    // add a pattern formed only by the item of the current node
                    Tuple<SortedSet<string>, uint64_t> new_pattern = new Tuple<SortedSet<string>, uint64_t>({ curr_fpnode_item }, curr_fpnode_frequency);
Ejemplo n.º 7
0
        public void flush(uint8_t data, uint64_t size, ref std::error_code ec)
        {
            Debug.Assert(isOpened());

            uintptr_t pageSize = (uintptr_t)sysconf(_SC_PAGESIZE);
//C++ TO C# CONVERTER TODO TASK: There is no equivalent to 'reinterpret_cast' in C#:
            uintptr_t dataAddr   = reinterpret_cast <uintptr_t>(data);
            uintptr_t pageOffset = (dataAddr / pageSize) * pageSize;

//C++ TO C# CONVERTER TODO TASK: There is no equivalent to 'reinterpret_cast' in C#:
            int result = global::msync(reinterpret_cast <object>(pageOffset), (size_t)(dataAddr % pageSize + size), MS_SYNC);

            if (result == 0)
            {
                result = global::fsync(m_file);
                if (result == 0)
                {
                    ec = std::error_code();
                    return;
                }
            }

            ec = std::error_code(errno, std::system_category());
        }
Ejemplo n.º 8
0
 public CachedPower(ulong significand, short binary_exponent, short decimal_exponent)
 {
     this.significand      = significand;
     this.binary_exponent  = binary_exponent;
     this.decimal_exponent = decimal_exponent;
 }
Ejemplo n.º 9
0
        public void sleep(std::chrono.nanoseconds duration)
        {
            Debug.Assert(dispatcher != null);
            Debug.Assert(context == null);
            if (dispatcher.interrupted())
            {
                throw InterruptedException();
            }

            if (duration.count() == 0)
            {
                dispatcher.yield();
            }
            else
            {
                timer = dispatcher.getTimer();

                var        seconds = std::chrono.duration_cast <std::chrono.seconds>(duration);
                itimerspec expires = new itimerspec();
                expires.it_interval.tv_nsec = expires.it_interval.tv_sec = 0;
                expires.it_value.tv_sec     = seconds.count();
                expires.it_value.tv_nsec    = std::chrono.duration_cast <std::chrono.nanoseconds>(duration - seconds).count();
                timerfd_settime(timer, 0, expires, null);

                ContextPair      contextPair  = new ContextPair();
                OperationContext timerContext = new OperationContext();
                timerContext.interrupted = false;
                timerContext.context     = dispatcher.getCurrentContext();
                contextPair.writeContext = null;
                contextPair.readContext  = timerContext;

                epoll_event timerEvent = new epoll_event();
                timerEvent.events   = EPOLLIN | EPOLLONESHOT;
                timerEvent.data.ptr = contextPair;

                if (epoll_ctl(dispatcher.getEpoll(), EPOLL_CTL_MOD, timer, timerEvent) == -1)
                {
                    throw new System.Exception("Timer::sleep, epoll_ctl failed, " + lastErrorMessage());
                }
                dispatcher.getCurrentContext().interruptProcedure = () =>
                {
                    Debug.Assert(dispatcher != null);
                    Debug.Assert(context != null);
                    OperationContext timerContext = (OperationContext)context;
                    if (!timerContext.interrupted)
                    {
                        uint64_t value = 0;
                        if (global::read(timer, value, sizeof(uint64_t)) == -1)
                        {
                            //C++ TO C# CONVERTER TODO TASK: There is no equivalent to most C++ 'pragma' directives in C#:
                            //#pragma GCC diagnostic push
                            //C++ TO C# CONVERTER TODO TASK: There is no equivalent to most C++ 'pragma' directives in C#:
                            //#pragma GCC diagnostic ignored "-Wlogical-op"
                            if (errno == EAGAIN || errno == EWOULDBLOCK)
                            {
                                //C++ TO C# CONVERTER TODO TASK: There is no equivalent to most C++ 'pragma' directives in C#:
                                //#pragma GCC diagnostic pop
                                timerContext.interrupted = true;
                                dispatcher.pushContext(timerContext.context);
                            }
                            else
                            {
                                throw new System.Exception("Timer::sleep, interrupt procedure, read failed, " + lastErrorMessage());
                            }
                        }
                        else
                        {
                            Debug.Assert(value > 0);
                            dispatcher.pushContext(timerContext.context);
                        }

                        epoll_event timerEvent = new epoll_event();
                        timerEvent.events   = EPOLLONESHOT;
                        timerEvent.data.ptr = null;

                        if (epoll_ctl(dispatcher.getEpoll(), EPOLL_CTL_MOD, timer, timerEvent) == -1)
                        {
                            throw new System.Exception("Timer::sleep, interrupt procedure, epoll_ctl failed, " + lastErrorMessage());
                        }
                    }
                };

                context = timerContext;
                dispatcher.dispatch();
                dispatcher.getCurrentContext().interruptProcedure = null;
                Debug.Assert(dispatcher != null);
                Debug.Assert(timerContext.context == dispatcher.getCurrentContext());
                Debug.Assert(contextPair.writeContext == null);
                Debug.Assert(context == &timerContext);
                context = null;
                timerContext.context = null;
                dispatcher.pushTimer(timer);
                if (timerContext.interrupted)
                {
                    throw InterruptedException();
                }
            }
        }
Ejemplo n.º 10
0
        // If the function returns true then the result is the correct double.
        // Otherwise it is either the correct double or the double that is just below
        // the correct double.
        static bool DiyFpStrtod(Vector buffer,
                                int exponent,
                                out double result)
        {
            DiyFp input;
            int   remaining_decimals;

            ReadDiyFp(buffer, out input, out remaining_decimals);
            // Since we may have dropped some digits the input is not accurate.
            // If remaining_decimals is different than 0 than the error is at most
            // .5 ulp (unit in the last place).
            // We don't want to deal with fractions and therefore keep a common
            // denominator.
            const int kDenominatorLog = 3;
            const int kDenominator    = 1 << kDenominatorLog;

            // Move the remaining decimals into the exponent.
            exponent += remaining_decimals;
            uint64_t error = (ulong)(remaining_decimals == 0 ? 0 : kDenominator / 2);

            int old_e = input.e;

            input.Normalize();
            error <<= old_e - input.e;

            if (exponent < PowersOfTenCache.kMinDecimalExponent)
            {
                result = 0.0;
                return(true);
            }
            DiyFp cached_power;
            int   cached_decimal_exponent;

            PowersOfTenCache.GetCachedPowerForDecimalExponent(exponent,
                                                              out cached_power,
                                                              out cached_decimal_exponent);

            if (cached_decimal_exponent != exponent)
            {
                int   adjustment_exponent = exponent - cached_decimal_exponent;
                DiyFp adjustment_power    = AdjustmentPowerOfTen(adjustment_exponent);
                input.Multiply(ref adjustment_power);
                if (kMaxUint64DecimalDigits - buffer.length() >= adjustment_exponent)
                {
                    // The product of input with the adjustment power fits into a 64 bit
                    // integer.
                }
                else
                {
                    // The adjustment power is exact. There is hence only an error of 0.5.
                    error += kDenominator / 2;
                }
            }

            input.Multiply(ref cached_power);
            // The error introduced by a multiplication of a*b equals
            //   error_a + error_b + error_a*error_b/2^64 + 0.5
            // Substituting a with 'input' and b with 'cached_power' we have
            //   error_b = 0.5  (all cached powers have an error of less than 0.5 ulp),
            //   error_ab = 0 or 1 / kDenominator > error_a*error_b/ 2^64
            int error_b     = kDenominator / 2;
            int error_ab    = (error == 0 ? 0 : 1); // We round up to 1.
            int fixed_error = kDenominator / 2;

            error += (ulong)(error_b + error_ab + fixed_error);

            old_e = input.e;
            input.Normalize();
            error <<= old_e - input.e;

            // See if the double's significand changes if we add/subtract the error.
            int order_of_magnitude         = DiyFp.kSignificandSize + input.e;
            int effective_significand_size = Double.SignificandSizeForOrderOfMagnitude(order_of_magnitude);
            int precision_digits_count     = DiyFp.kSignificandSize - effective_significand_size;

            if (precision_digits_count + kDenominatorLog >= DiyFp.kSignificandSize)
            {
                // This can only happen for very small denormals. In this case the
                // half-way multiplied by the denominator exceeds the range of an uint64.
                // Simply shift everything to the right.
                int shift_amount = (precision_digits_count + kDenominatorLog) -
                                   DiyFp.kSignificandSize + 1;
                input.f = (input.f >> shift_amount);
                input.e = (input.e + shift_amount);
                // We add 1 for the lost precision of error, and kDenominator for
                // the lost precision of input.f().
                error = (error >> shift_amount) + 1 + kDenominator;
                precision_digits_count -= shift_amount;
            }
            // We use uint64_ts now. This only works if the DiyFp uses uint64_ts too.
            uint64_t one64 = 1;
            uint64_t precision_bits_mask = (one64 << precision_digits_count) - 1;
            uint64_t precision_bits      = input.f & precision_bits_mask;
            uint64_t half_way            = one64 << (precision_digits_count - 1);

            precision_bits *= kDenominator;
            half_way       *= kDenominator;
            DiyFp rounded_input = new DiyFp(input.f >> precision_digits_count, input.e + precision_digits_count);

            if (precision_bits >= half_way + error)
            {
                rounded_input.f = (rounded_input.f + 1);
            }
            // If the last_bits are too close to the half-way case than we are too
            // inaccurate and round down. In this case we return false so that we can
            // fall back to a more precise algorithm.

            result = new Double(rounded_input).value();
            if (half_way - error < precision_bits && precision_bits < half_way + error)
            {
                // Too imprecise. The caller will have to fall back to a slower version.
                // However the returned number is guaranteed to be either the correct
                // double, or the next-lower double.
                return(false);
            }
            else
            {
                return(true);
            }
        }
Ejemplo n.º 11
0
 public static extern int JS_ToIndex(JSContext ctx, out uint64_t plen, JSValueConst val);
Ejemplo n.º 12
0
 public Opcode(uint64_t value, uint16_t address)
     : this()
 {
     this.Address = address;
     FromBinary(value.ToBinary());
 }
Ejemplo n.º 13
0
        public NFSAttributes GetItemAttributes(string ItemFullName, bool ThrowExceptionIfNotFound = true)
        {
            if (_ProtocolV4 == null)
            {
                throw new NFSConnectionException("NFS Client not connected!");
            }

            ItemFullName = ItemFullName.Replace(".\\.\\", ".\\");

            if (useFHCache)
            {
                if (cached_attrs.ContainsKey(ItemFullName))
                {
                    return((NFSAttributes)cached_attrs[ItemFullName]);
                }
            }

            //we will return it in the old way !! ;)
            NFSAttributes attributes = null;

            if (String.IsNullOrEmpty(ItemFullName))
            {
                //should not happen
                return(attributes);
            }


            if (ItemFullName == ".\\.")
            {
                return(new NFSAttributes(0, 0, 0, NFSItemTypes.NFDIR, new NFSPermission(7, 7, 7), 4096, _rootFH.value));
            }



            nfs_fh4 currentItem = _rootFH;
            int     initial     = 1;

            String[] PathTree = ItemFullName.Split(@"\".ToCharArray());

            if (useFHCache)
            {
                string parent = System.IO.Path.GetDirectoryName(ItemFullName);
                //get cached parent dir to avoid too much directory
                if (parent != ItemFullName)
                {
                    if (cached_attrs.ContainsKey(parent))
                    {
                        currentItem.value = ((NFSAttributes)cached_attrs[parent]).Handle;
                        initial           = PathTree.Length - 1;
                    }
                }
            }


            for (int pC = initial; pC < PathTree.Length; pC++)
            {
                List <int> attrs = new List <int>(1);
                attrs.Add(NFSv4Protocol.FATTR4_TIME_CREATE);
                attrs.Add(NFSv4Protocol.FATTR4_TIME_ACCESS);
                attrs.Add(NFSv4Protocol.FATTR4_TIME_MODIFY);
                attrs.Add(NFSv4Protocol.FATTR4_TYPE);
                attrs.Add(NFSv4Protocol.FATTR4_MODE);
                attrs.Add(NFSv4Protocol.FATTR4_SIZE);

                List <nfs_argop4> ops = new List <nfs_argop4>();

                ops.Add(SequenceStub.generateRequest(false, _sessionid.value,
                                                     _sequenceID.value.value, 12, 0));

                ops.Add(PutfhStub.generateRequest(currentItem));
                ops.Add(LookupStub.generateRequest(PathTree[pC]));

                //ops.Add(PutfhStub.generateRequest(_cwd));
                //ops.Add(LookupStub.generateRequest(PathTree[PathTree.Length-1]));

                ops.Add(GetfhStub.generateRequest());
                ops.Add(GetattrStub.generateRequest(attrs));

                COMPOUND4res compound4res = sendCompound(ops, "");

                if (compound4res.status == nfsstat4.NFS4_OK)
                {
                    currentItem = compound4res.resarray[3].opgetfh.resok4.object1;

                    //nfs_fh4 currentItem = compound4res.resarray[3].opgetfh.resok4.object1;

                    //results
                    Dictionary <int, Object> attrrs_results = GetattrStub.decodeType(compound4res.resarray[4].opgetattr.resok4.obj_attributes);

                    //times
                    nfstime4 time_acc = (nfstime4)attrrs_results[NFSv4Protocol.FATTR4_TIME_ACCESS];

                    int time_acc_int = unchecked ((int)time_acc.seconds.value);

                    nfstime4 time_modify = (nfstime4)attrrs_results[NFSv4Protocol.FATTR4_TIME_MODIFY];

                    int time_modif = unchecked ((int)time_modify.seconds.value);


                    int time_creat = 0;
                    //linux should now store create time if it is let's check it else use modify date
                    if (attrrs_results.ContainsKey(NFSv4Protocol.FATTR4_TIME_CREATE))
                    {
                        nfstime4 time_create = (nfstime4)attrrs_results[NFSv4Protocol.FATTR4_TIME_CREATE];

                        time_creat = unchecked ((int)time_create.seconds.value);
                    }
                    else
                    {
                        time_creat = time_modif;
                    }



                    //3 = type
                    NFSItemTypes nfstype = NFSItemTypes.NFREG;

                    fattr4_type type = (fattr4_type)attrrs_results[NFSv4Protocol.FATTR4_TYPE];

                    if (type.value == 2)
                    {
                        nfstype = NFSItemTypes.NFDIR;
                    }

                    //4 = mode is int also
                    mode4 mode = (mode4)attrrs_results[NFSv4Protocol.FATTR4_MODE];

                    byte other = (byte)(mode.value.value % 8);

                    byte grup = (byte)((mode.value.value >> 3) % 8);

                    byte user = (byte)((mode.value.value >> 6) % 8);

                    NFSPermission per = new NFSPermission(user, grup, other);


                    uint64_t size = (uint64_t)attrrs_results[NFSv4Protocol.FATTR4_SIZE];
                    //here we do attributes compatible with old nfs versions
                    attributes = new NFSAttributes(time_creat, time_acc_int, time_modif, nfstype, per, size.value, currentItem.value);
                }
                else if (compound4res.status == nfsstat4.NFS4ERR_NOENT)
                {
                    return(null);
                }

                else
                {
                    throw new NFSConnectionException(nfsstat4.getErrorString(compound4res.status));
                }
            }

            // if(attributes.NFSType == NFSItemTypes.NFDIR)
            if (useFHCache)
            {
                cached_attrs.Add(ItemFullName, attributes);
            }

            return(attributes);
        }