From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wm1-f51.google.com (mail-wm1-f51.google.com [209.85.128.51]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E20A22FD698 for ; Wed, 18 Feb 2026 13:29:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.51 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1771421376; cv=none; b=qsnIIKd5pTdEzY6+dapzYDmioLqnZUj4+kydF4KaPmy3mjoVcyhmt+tlzQMCQ2EsAiqWwSV942qF0k9EOJrXkSMjJ7PBAUgzLdxp8ua9arxak99alKO9pHdAFkVZ0PtBMz/yTdLuduR2l3/ySm9ap1dOT7ntytOURCHy1pm13Hg= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1771421376; c=relaxed/simple; bh=0PkuZoUk+Tc3pZq5oW4s6ngtVAHdr+f9SP6oIha8QwY=; h=Message-ID:Date:MIME-Version:From:Cc:Subject:To:Content-Type; b=N0i9aR33Fwnkv0lyyB5mvDWC+N4GRLGpqQhyWe+UftaT0UVojY/FPBjFu4QqMHdUZM6EoqS63tr2KeDaexDEviBAPJGYPqxHqF4xVCb/gVWAK10Itr3FsLPK324CTsGfKRG2Tly8pwMqm4vn/TTPDMdKHChcs571hNSFntjWNs4= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=aZcyhhGT; arc=none smtp.client-ip=209.85.128.51 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="aZcyhhGT" Received: by mail-wm1-f51.google.com with SMTP id 5b1f17b1804b1-4836f363d0dso47070205e9.3 for ; Wed, 18 Feb 2026 05:29:34 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1771421373; x=1772026173; darn=vger.kernel.org; h=content-transfer-encoding:to:subject:cc:from:content-language :user-agent:mime-version:date:message-id:from:to:cc:subject:date :message-id:reply-to; bh=yBIoPuTMi/6ruSqVzRLcP1R/zZrBDdqVk2s3C2l9HiI=; b=aZcyhhGTObSeaUtCg1TFn9VgsnmJvgaBannKgaoVl5NTCuwYg07UeSwcFO9yBnpRai ynoLV1g5Mtv9TLcZ92FMLP5VRS6mvM/x5Ln5zQDft7TvXCILcqC7t9lPmk56Rl2l1eFy fOkRpqpod37WgoH/evdEtRu/hb1bIeRmc6f6W9ZyRheIUfX8AeEwsEGFSKy7RUy2bgyM Mg28sC4IpKhXYAQtPg5kZpCV+5GJZRn556di4VuPk9IRQ7oj1xTecRJSTF361qlOCjMz /5Zcw0kJ3etLH+u2GY5QUAR7/mCe72KbqBoWH6ei2H2f0FAHwyv+UQEdaaQ72LzVPImQ i/cw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1771421373; x=1772026173; h=content-transfer-encoding:to:subject:cc:from:content-language :user-agent:mime-version:date:message-id:x-gm-gg:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=yBIoPuTMi/6ruSqVzRLcP1R/zZrBDdqVk2s3C2l9HiI=; b=omtaYGYiRIh2X9uFbYl55BLQ9jPjkzqMB2oS9r0o1wJkBUTvhcIsaFYsMxOxkRy0cU dswK6xlt6li3WGT3CpI3qxYlncMT6bEaMozhpofJdxggVB5R23cWUjCcOBnGxq+Wutpb iqsUlKK6tkB9+G3c0Tzb3rGVFFZaiY2N3wHBXrrOQhdYK6BCPc3vIiCCdXhnwxKK5LY5 PJd9nvD9oFLdIrsgZoAPNCwpTWHUyZSXnCjXmraEH1iPbMpuJEITeBjQIvqaz7j1zwjR cWQOXQwPMSLv1Yr+mGar38S4llzCfxQFDHkulRJFNCJA3vshvuGI36CX3Gl9ULE5A16F cszw== X-Forwarded-Encrypted: i=1; AJvYcCVDXOUI820q9R3J9YM7NMe5KTQqBth3hQosf9u8huuXaiDAW9YoZ+Om/KvwbkHMI8SaR7dS3bphc9oajN0=@vger.kernel.org X-Gm-Message-State: AOJu0YxpHf7rvnU2qWB3HSdP7XXaqPyo4sB7UTT9UNMyqaB/U6ySLneu g/ZlSPiDgRaAMPcP06plB475Cp5AFDXpNFaS5xMhhiQ2N8+PC7qrsPlLusDBtA== X-Gm-Gg: AZuq6aL7Gav+iNngFMtERgyUabfhAJG75Zwr5KNYDZzcKjAPv8Lymg0SGSyE9w16i4D H5S+cVQ1Vbmh83DaUCgg706vsMtuAXOWrjhIHPTR/r/GAr1to2LKzOLLQP6MozJB2UCcYZTA64R kmYkK9RAC7rj4bA/q4ouLckq/yUSn39LNbVnJopOPvLM3NbgfFfOuMiwf2/wQwLMO36DMtilfry YAqG1fsmvn4vTR46mWzFu7kFS5cYEhhEd+H+iZgzCG9HOc+JtjJjVQzemnBdwyG6emODR0K0ZjK VwzQXMRwWFllAZK9q4VAZZBbmoUzFw4d8C6DimVUrlfd43vyMMxx3HCwwouyDCLnzppbN3Swi1O F+Ow4kWwq17XnsEVG+cuG/gtGtDzrqJMAhgZb1kYXul7AHyqwIPycvcEIveIjGqkmr2l0z+ctgF 7UuOhhp5nlvAlcnWTN4DVBobHZY4X3dHmCzfuzPj7DX4Py X-Received: by 2002:a05:600c:609a:b0:483:7020:864 with SMTP id 5b1f17b1804b1-48379c178eamr258480935e9.25.1771421372830; Wed, 18 Feb 2026 05:29:32 -0800 (PST) Received: from [10.128.170.182] ([77.234.210.12]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4837e565f5esm419668495e9.10.2026.02.18.05.29.31 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 18 Feb 2026 05:29:32 -0800 (PST) Message-ID: <3d8f73f4-3a64-4a86-8fc9-d910d4fa3be1@gmail.com> Date: Wed, 18 Feb 2026 16:29:30 +0300 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Content-Language: en-US From: Vyacheslav Kovalevsky Cc: linux-ext4@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Writing more than 4096 bytes with O_SYNC flag does not persist all previously written data if system crashes To: tytso@mit.edu, adilger.kernel@dilger.ca Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit Detailed description ==================== Hello, there seems to be an issue with ext4 crash behavior: 1. Create and sync a new file. 2. Open the file and write some data (must be more than 4096 bytes). 3. Close the file. 4. Open the file with O_SYNC flag and write some data. After system crash the file will have the wrong size and some previously written data will be lost. According to Linux manual O_SYNC can replaced with fsync() call after each write operation: ``` By the time write(2) (or similar) returns, the output data and associated file metadata have been transferred to the underlying hardware (i.e., as though each write(2) was followed by a call to fsync(2)). ``` In this case it is not true, using O_SYNC does not persist the data like fsync() does (see test below). System info =========== Linux version 6.19.2 How to reproduce ================ ``` #include #include #include #include #include #include #include #define BUFFER_LEN 5000 // should be at least ~ 4096+1 int main() {   int status;   int file_fd0;   int file_fd1;   int file_fd2;   char buffer[BUFFER_LEN + 1] = {};   for (int i = 0; i <= BUFFER_LEN; ++i) {     buffer[i] = (char)i;   }   status = creat("file", S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH);   printf("CREAT: %d\n", status);   file_fd0 = status;   status = close(file_fd0);   printf("CLOSE: %d\n", status);   sync();   status = open("file", O_WRONLY);   printf("OPEN: %d\n", status);   file_fd1 = status;   status = write(file_fd1, buffer, BUFFER_LEN);   printf("WRITE: %d\n", status);   status = close(file_fd1);   printf("CLOSE: %d\n", status);   status = open("file", O_WRONLY | O_SYNC);   printf("OPEN: %d\n", status);   file_fd2 = status;   status = write(file_fd2, "Test data!", 10);   printf("WRITE: %d\n", status);   status = close(file_fd2);   printf("CLOSE: %d\n", status); } // after crash file size is 4096 instead of 5000 ``` Output: ``` CREAT: 3 CLOSE: 0 OPEN: 3 WRITE: 5000 CLOSE: 0 OPEN: 3 WRITE: 10 CLOSE: 0 ``` File content after crash: ``` $ xxd file 00000000: 5465 7374 2064 6174 6121 0a0b 0c0d 0e0f  Test data!...... 00000010: 1011 1213 1415 1617 1819 1a1b 1c1d 1e1f ................ 00000020: 2021 2223 2425 2627 2829 2a2b 2c2d 2e2f  !"#$%&'()*+,-./ ......... 00000ff0: f0f1 f2f3 f4f5 f6f7 f8f9 fafb fcfd feff ................ ``` Steps: 1. Create and mount new ext4 file system in default configuration. 2. Change directory to root of the file system and run the compiled test. 3. Cause hard system crash (e.g. QEMU `system_reset` command). 4. Remount file system after crash. 5. Observe that file size is 4096 instead of 5000. Notes: - This also seems to affect XFS in the same way.