From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by master.gitmailbox.com (Postfix) with ESMTP id B608642B1B for ; Sun, 15 May 2022 20:24:52 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 2FF4368B4E7; Sun, 15 May 2022 23:24:50 +0300 (EEST) Received: from NAM11-CO1-obe.outbound.protection.outlook.com (mail-co1nam11olkn2062.outbound.protection.outlook.com [40.92.18.62]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 8729268B295 for ; Sun, 15 May 2022 23:24:43 +0300 (EEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=P0eN4894lr4G/IbtpxQ93qnkf7dOxVB9goZ85GTZ3q40N62BOQrUhy9OZ+jbiJGm1bAJFA+pNi5C3sWkVCwknr8eRhDwZVrx3VKGM5OobO1U0h3ozFEGsJ7pQyiPkppEnRikSvbPq66ets7wEjm04Qon9uzkE7t2q/kgCklFQRP2DGHJzV4nHF8PqikiKuXkueK7bRpVphOePRu91m+XAAZj2HZCUD/t78WqJFxo8VG59vuFnp0jL/1ppZmj+WIo9Lih7ieF3mn5Ypa/VjEiTMA2FRwPT2UykxnbfiII+3gEs5B+wl/AHa15k1AbQiqniZGDcbpPeIiUF2JXHbiBcA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=vBYQtmvTOElHn2UQQaCZWHzvUtA3Nk3EpkmsV5cvIrI=; b=c+e/OZzCuJwfWz4yQA2NG+ktgGZiRxWUc0MZw3F2dbW8Cyh7lN2YhlNe5Jb6QNWJrpsV67/faPYRW0PW2aYmLIAzpyGe5sxC0KMvm1qN3q5b77zafNalmJYqaCrxQ42zB115Iafz+4Bts6hMvZmjYT7UIOpKoDeuw0pTmjSaPSC/26cq3NIo/ZwYwEQw0HSIJTpIefFk+s8SVmQz5WXHnVfWOMaeMLHM6VxgNDOH+2VLBkmyVUqrL4bNNEUpzGFmY/Xc2LB/kvqbXch6JI1IdJ5QRdDzLjBDYfbm+ThUSoBMS5rH1Um4GDWXMABdFPoe9P4iHd2Df0mRhqkNGEPbEw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none; dmarc=none; dkim=none; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=hotmail.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=vBYQtmvTOElHn2UQQaCZWHzvUtA3Nk3EpkmsV5cvIrI=; b=dGvQpvqD9KOaZwhX5ubfTLbggRRBSUElZzID50Q5a/v76SrSK29+p8/g04YdcjRe3I4RAvV2MBSkH/W+upPQtPjV/Hd3Cuu9ofppIkCfr++fXaEaVVAGPMZmYAUXI+YHKVf3GJ+kwq5XFB6XdJCIr3AC/hR3B2f5Pn3dZaflC27WvKWK+mSyknnu8FLZj0mqwygLGBdXVPRR7fT3HPoQNE2lyvcY8atFX8kNBQmeLGCmOmEcoB2jOVSDTs+394soNMMbP4JnMCJ6OBzuQ/xEYmxRMO2jBsVEKtW1j9BNSnMFiPm1tMUHgHLLRaPL5TkeoTLM4u07g3oIExCgCexkEw== Received: from DM8P223MB0365.NAMP223.PROD.OUTLOOK.COM (2603:10b6:8:b::20) by BN0P223MB0037.NAMP223.PROD.OUTLOOK.COM (2603:10b6:408:147::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5250.14; Sun, 15 May 2022 20:24:40 +0000 Received: from DM8P223MB0365.NAMP223.PROD.OUTLOOK.COM ([fe80::c536:493f:7cda:53dc]) by DM8P223MB0365.NAMP223.PROD.OUTLOOK.COM ([fe80::c536:493f:7cda:53dc%3]) with mapi id 15.20.5250.018; Sun, 15 May 2022 20:24:40 +0000 From: Soft Works To: FFmpeg development discussions and patches Thread-Topic: [FFmpeg-devel] [PATCH 1/2] avutil/wchar_filename, file_open: Support long file names on Windows Thread-Index: AQHYaI5kR2eyWqnDvUa3fdgqeUyvxa0gTrqA Date: Sun, 15 May 2022 20:24:40 +0000 Message-ID: References: <26c579e4ee0065a81f46b18adeba1b97385d8257.1652435595.git.ffmpegagent@gmail.com> In-Reply-To: Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-tmn: [GlAINc9RL2zvUJ/dfb6YAxX7Wp0wAXkE] x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: bd1eb29d-db2d-4d22-e77a-08da36b0f070 x-ms-traffictypediagnostic: BN0P223MB0037:EE_ x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: jGyb0QpeYCnU2CA27Q8V+fifyUGY2tRGsawGmLTnMvSLJrmhId/RK1L+2jNsqDO7Kr5ZiVefg+T0l7A6i2VezOjPmcc0XoFG5iQ7qQCY2PDQ7anj4u2kpK+duzdqpAio1ZQKmFHJkswlZX0Yos06LT+e2if2HDsL8loaKtQrkecDOGcSv1YAgDjM1W+UijAzpukfJ8nRgjiPDjoFH2Ji/fRuTNJokBiRk+3CVEhsTI5fzHPfOpddnFS0/3nwU8l7uIncpKYeZb41shwVH2ZKPRvnjHBMKzNZiOF22YHLMHvB+NND0aDZQTxFT8Jofe1gX5if+MNQsD7udZbz1vhj7brCvLMeRRHgiUl36Gu1dnINZGBOvuhpzgVYBMpX/Zyv2x8GZhvTskAUOV/l9vz993xOqM7D7k+SeMeyoAEuMxqO8EPfksCKLPgZxjZkZz1gype6JSeDotxz4DMAhb7d8TcdKSO02jAmtCkCkMofFkTyNWFbSuXYZU/RIqn4lYRTEfRBA4C+QHg9bEk8RkhKu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eTlDRDQzZDg3ZU1IVElzSWVHaDV4ejhCSzZOc3FMZjBiaGpM?= =?utf-8?B?b0l3YUh3Ti92VUJ1eXRQTUhIdERzRGM2bXVnaVYwYTAxTnVtWDYvM2FkTU96?= =?utf-8?B?UG1tdzZzdlR3R1NXY1o4SGNGMWlPdnNHeWtZaTNaMW1EK0dDTFY0QmNyekl5?= =?utf-8?B?RS9vYkdMV3REbTBqZ2tGTmxhdXpwQkwxS2pPTWRpOUJpOVNpL25qK3hmYTRZ?= =?utf-8?B?ckhIeHlaNDhHTThmS2FWemNMZ2VzV2pCQy9ON252YkFoaXRac29ZWjlpSGl0?= =?utf-8?Q?60NAeng+vjw=3D?= MIME-Version: 1.0 X-OriginatorOrg: sct-15-20-4755-11-msonline-outlook-1ff67.templateTenant X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: DM8P223MB0365.NAMP223.PROD.OUTLOOK.COM X-MS-Exchange-CrossTenant-RMS-PersistedConsumerOrg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-CrossTenant-Network-Message-Id: bd1eb29d-db2d-4d22-e77a-08da36b0f070 X-MS-Exchange-CrossTenant-originalarrivaltime: 15 May 2022 20:24:40.2108 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa X-MS-Exchange-CrossTenant-rms-persistedconsumerorg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-Transport-CrossTenantHeadersStamped: BN0P223MB0037 Subject: Re: [FFmpeg-devel] [PATCH 1/2] avutil/wchar_filename, file_open: Support long file names on Windows X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Archived-At: List-Archive: List-Post: > -----Original Message----- > From: ffmpeg-devel On Behalf Of nil- > admirari@mailo.com > Sent: Sunday, May 15, 2022 9:03 PM > To: ffmpeg-devel@ffmpeg.org > Subject: Re: [FFmpeg-devel] [PATCH 1/2] avutil/wchar_filename, > file_open: Support long file names on Windows > > > diff --git a/libavutil/wchar_filename.h b/libavutil/wchar_filename.h > > ... > > +static inline int path_is_extended(const wchar_t *path) > > ... > > Why path handling functions ended up in wchar_filename.h? > Isn't it better to move them to file_open or os_support? The functions are needed in both. file_open.c cannot be included in libavformat/os_support.h and neither the other way round, so they need to be in a 3rd place. How about renaming wchar_filename.h to windows_filename.h ? > > + num_chars = GetFullPathNameW(*ppath_w, num_chars, temp_w, > NULL); > > Turns out that GetFullPathNameW handles long path names without the > manifest > or a prefix \\?\. Other WinAPI functions, require either a prefix or a > manifest, > which is why I thought that path normalisation must be done by hand. Yea, that's where we are lucky. > > +static inline int path_normalize(wchar_t **ppath_w) > > +{ > > + int ret; > > + > > + // see .NET6: PathHelper.Normalize() > > + if ((ret = get_full_path_name(ppath_w)) < 0) > > + return ret; > > + > > + /* What .NET does at this point is to call > PathHelper.TryExpandShortFileName() > > + in case the path contains a '~' character. > > + We don't need to do this as we don't need to normalize the > file name > > + for presentation, and the extended path prefix works with > 8.3 path > > + components as well */ > > + return 0; > > +} > > This function simply forwards the return code of get_full_path_name(). > The only non-trivial part of it is a comment. I wanted those functions to resemble the handling path from .NET. I had already started the implementation of TryExpandShortFilePath() as well, but then I figured that this isn't necessary. For this, I had tested a long path in the form with 8.3 path components (where even the 8.3 form is longer than 260) and even those paths work with the extended prefix. That's why I skipped this part as in our case it will only be used internally while in .NET it is done because the GetFullPathMethod() is also used for other purposes where expansion is desirable. Of course we could merge some of those functions together, but the compiler will do the inlining anyway, that's why I chose to keep the functions separate for better clarity. > > +static inline int path_is_extended(const wchar_t *path) > > +{ > > + // see .NET6: PathInternal.IsExtended() > > + size_t len = wcslen(path); > > + if (len >= 4 && path[0] == L'\\' && (path[1] == L'\\' || > path[1] == L'?') && path[2] == L'?' && path[3] == L'\\') > > + return 1; > > + > > + return 0; > > +} > > > > +static inline int add_extended_prefix(wchar_t **ppath_w) > > +{ > > + const wchar_t *unc_prefix = L"\\\\?\\UNC\\"; > > ... > > + // see .NET6: PathInternal.EnsureExtendedPrefix() > > + if (path_w[0] == L'\\' && path_w[1] == L'\\') { > > ... > > + wcscpy(temp_w, unc_prefix); > > + wcscat(temp_w, path_w + 2); > > > > +static inline int get_extended_win32_path(const char *path, wchar_t > **ppath_w) > > +{ > > ... > > + if (path_is_extended(*ppath_w)) { > > + ... > > + return 0; > > + } > > ... > > + if ((ret = add_extended_prefix(ppath_w)) < 0) > > Actual PathInternal.EnsureExtendedPrefix > (https://github.com/dotnet/runtime/blob/main/src/libraries/Common/src/ > System/IO/PathInternal.Windows.cs) > checks for > > if (IsPartiallyQualified(path.AsSpan()) || > IsDevice(path.AsSpan())) > return path; > where IsDevice handles \\.\, which you do not handle. If I'm not > mistaken, > the code paths presented above will turn such paths into \\?\UNC\\.\, > which is an error. I have skipped those checks because we won't have partially qualified paths at this point (due to having called GetFullPathNameW) and device paths are not allowed to be longer than 260, so this it might happen that the UNC prefix gets added, but only when it's a long path which doesn't work anyway (I've tested those cases). > > +static inline int add_extended_prefix(wchar_t **pp ath_w) > > +{ > > + const wchar_t *unc_prefix = L"\\\\?\\UNC\\"; > > ... > > + temp_w = (wchar_t *)av_calloc(len + 6 + 1, > sizeof(wchar_t)); > > Wouldn't it be better to use sizeof unc_prefix instead of magic > numbers? Then we would need to subtract the terminating zeros and divide by two => ugly. Or do another wcslen() call => unnecessary. I have added comments right above now, explaining those numbers. Thanks for your review, softworkz _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".