private iPhoneFile(iPhone phone, long handle, OpenMode mode)
     : base()
 {
     this.phone = phone;
     this.mode = mode;
     this.handle = handle;
 }
 /// <summary>
 /// Opens a file for reading
 /// </summary>
 /// <param name="phone">A valid iPhone object</param>
 /// <param name="path">The file to be opened for reading</param>
 /// <returns>An unshared <c>iPhoneFile</c> object on the specified path with Write access. </returns>
 public static iPhoneFile OpenRead(iPhone phone, string path)
 {
     return iPhoneFile.Open(phone, path, FileAccess.Read);
 }
 /// <summary>
 /// Opens a file for writing
 /// </summary>
 /// <param name="phone">A valid iPhone object</param>
 /// <param name="path">The file to be opened for writing</param>
 /// <returns>An unshared <c>iPhoneFile</c> object on the specified path with Write access. </returns>
 public static iPhoneFile OpenWrite(iPhone phone, string path)
 {
     return iPhoneFile.Open(phone, path, FileAccess.Write);
 }
        /// <summary>
        /// Opens an iPhoneFile stream on the specified path
        /// </summary>
        /// <param name="phone">A valid iPhone object</param>
        /// <param name="path">The file to open</param>
        /// <param name="openmode">A <see cref="FileAccess"/> value that specifies the operations that can be performed on the file</param>
        /// <returns></returns>
        public static unsafe iPhoneFile Open(iPhone phone, string path, FileAccess openmode)
        {
            OpenMode	mode;
            int			ret;
            long		handle;
            string		full_path;

            mode = OpenMode.None;
            switch(openmode) {
                case FileAccess.Read: mode = OpenMode.Read; break;
                case FileAccess.Write: mode = OpenMode.Write; break;
                case FileAccess.ReadWrite: throw new NotImplementedException("Read+Write not (yet) implemented");
            }

            full_path = phone.FullPath(phone.GetCurrentDirectory(), path);
            ret = MobileDevice.AFCFileRefOpen(phone.AFCHandle, iPhone.string2bytes(full_path), (int)mode, 0, out handle);
            if (ret != 0)
                throw new IOException("AFCFileRefOpen failed with error " + ret.ToString());

            return new iPhoneFile(phone, handle, mode);
        }