Exemple #1
0
        /*
         * struct inotify_event {
         *      __s32           wd;
         *      __u32           mask;
         *      __u32           cookie;
         *      __u32           len;		// Includes any trailing null in 'name'
         *      char            name[0];
         * };
         */

        static int ReadEvent(byte [] source, int off, int size, out InotifyEvent evt)
        {
            evt = new InotifyEvent();
            if (size <= 0 || off > size - 16)
            {
                return(-1);
            }

            int len;

            if (BitConverter.IsLittleEndian)
            {
                evt.WatchDescriptor = source [off] + (source [off + 1] << 8) +
                                      (source [off + 2] << 16) + (source [off + 3] << 24);
                evt.Mask = (InotifyMask)(source [off + 4] + (source [off + 5] << 8) +
                                         (source [off + 6] << 16) + (source [off + 7] << 24));
                // Ignore Cookie -> +4
                len = source [off + 12] + (source [off + 13] << 8) +
                      (source [off + 14] << 16) + (source [off + 15] << 24);
            }
            else
            {
                evt.WatchDescriptor = source [off + 3] + (source [off + 2] << 8) +
                                      (source [off + 1] << 16) + (source [off] << 24);
                evt.Mask = (InotifyMask)(source [off + 7] + (source [off + 6] << 8) +
                                         (source [off + 5] << 16) + (source [off + 4] << 24));
                // Ignore Cookie -> +4
                len = source [off + 15] + (source [off + 14] << 8) +
                      (source [off + 13] << 16) + (source [off + 12] << 24);
            }

            if (len > 0)
            {
                if (off > size - 16 - len)
                {
                    return(-1);
                }
                string name = Encoding.UTF8.GetString(source, off + 16, len);
                evt.Name = name.Trim('\0');
            }
            else
            {
                evt.Name = null;
            }

            return(16 + len);
        }
Exemple #2
0
        private static int ReadEvent(byte[] source, int off, int size, out InotifyEvent evt)
        {
            evt = default(InotifyEvent);
            if (size <= 0 || off > size - 16)
            {
                return(-1);
            }
            int num;

            if (BitConverter.IsLittleEndian)
            {
                evt.WatchDescriptor = (int)source[off] + ((int)source[off + 1] << 8) + ((int)source[off + 2] << 16) + ((int)source[off + 3] << 24);
                evt.Mask            = (InotifyMask)((int)source[off + 4] + ((int)source[off + 5] << 8) + ((int)source[off + 6] << 16) + ((int)source[off + 7] << 24));
                num = (int)source[off + 12] + ((int)source[off + 13] << 8) + ((int)source[off + 14] << 16) + ((int)source[off + 15] << 24);
            }
            else
            {
                evt.WatchDescriptor = (int)source[off + 3] + ((int)source[off + 2] << 8) + ((int)source[off + 1] << 16) + ((int)source[off] << 24);
                evt.Mask            = (InotifyMask)((int)source[off + 7] + ((int)source[off + 6] << 8) + ((int)source[off + 5] << 16) + ((int)source[off + 4] << 24));
                num = (int)source[off + 15] + ((int)source[off + 14] << 8) + ((int)source[off + 13] << 16) + ((int)source[off + 12] << 24);
            }
            if (num > 0)
            {
                if (off > size - 16 - num)
                {
                    return(-1);
                }
                string @string = Encoding.UTF8.GetString(source, off + 16, num);
                evt.Name = @string.Trim(new char[1]);
            }
            else
            {
                evt.Name = null;
            }
            return(16 + num);
        }
Exemple #3
0
		/*
		struct inotify_event {
			__s32           wd;
			__u32           mask;
			__u32           cookie;
			__u32           len;		// Includes any trailing null in 'name'
			char            name[0];
		};
		*/

		static int ReadEvent (byte [] source, int off, int size, out InotifyEvent evt)
		{
			evt = new InotifyEvent ();
			if (size <= 0 || off > size - 16) {
				return -1;
			}

			int len;
			if (BitConverter.IsLittleEndian) {
				evt.WatchDescriptor = source [off] + (source [off + 1] << 8) +
							(source [off + 2] << 16) + (source [off + 3] << 24);
				evt.Mask = (InotifyMask) (source [off + 4] + (source [off + 5] << 8) +
							(source [off + 6] << 16) + (source [off + 7] << 24));
				// Ignore Cookie -> +4
				len = source [off + 12] + (source [off + 13] << 8) +
					(source [off + 14] << 16) + (source [off + 15] << 24);
			} else {
				evt.WatchDescriptor = source [off + 3] + (source [off + 2] << 8) +
							(source [off + 1] << 16) + (source [off] << 24);
				evt.Mask = (InotifyMask) (source [off + 7] + (source [off + 6] << 8) +
							(source [off + 5] << 16) + (source [off + 4] << 24));
				// Ignore Cookie -> +4
				len = source [off + 15] + (source [off + 14] << 8) +
					(source [off + 13] << 16) + (source [off + 12] << 24);
			}

			if (len > 0) {
				if (off > size - 16 - len)
					return -1;
				string name = Encoding.UTF8.GetString (source, off + 16, len);
				evt.Name = name.Trim ('\0');
			} else {
				evt.Name = null;
			}

			return 16 + len;
		}