From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-3.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9F37CC433DF for ; Sun, 11 Oct 2020 20:32:01 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 63B8E20776 for ; Sun, 11 Oct 2020 20:32:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729423AbgJKUcA (ORCPT ); Sun, 11 Oct 2020 16:32:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42208 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726507AbgJKUb7 (ORCPT ); Sun, 11 Oct 2020 16:31:59 -0400 Received: from ZenIV.linux.org.uk (zeniv.linux.org.uk [IPv6:2002:c35c:fd02::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6A6A4C0613CE for ; Sun, 11 Oct 2020 13:31:59 -0700 (PDT) Received: from viro by ZenIV.linux.org.uk with local (Exim 4.92.3 #3 (Red Hat Linux)) id 1kRi0V-00FaRp-PU; Sun, 11 Oct 2020 20:31:51 +0000 Date: Sun, 11 Oct 2020 21:31:51 +0100 From: Al Viro To: Mikhail Gavrilov Cc: Linux List Kernel Mailing Subject: Re: [question] What happens when dd writes data to a missing device? Message-ID: <20201011203151.GD3576660@ZenIV.linux.org.uk> References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Sender: Al Viro Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Oct 12, 2020 at 12:46:03AM +0500, Mikhail Gavrilov wrote: > Hi folks! > I have a question. > What happens when dd writes data to a missing device? > > For example: > # dd if=/home/mikhail/Downloads/Fedora-Workstation-Live-x86_64-Rawhide-20201010.n.0.iso > of=/dev/adb > > Today I and wrongly entered /dev/adb instead of /dev/sdb, > and what my surprise was when the data began to be written to the > /dev/adb device without errors. > > But my surprise was even greater when cat /dev/adb started to display > the written data. > > I have a question: > Where the data was written Into a file called "/dev/adb", of course. > and could it damage the stored data in > memory or on disk? Why would it? There's nothing magical about /dev - the same thing happened as if you said dd if=/home/mikhail/Downloads/whatever.iso of=/tmp/adb or, for that matter, of=/home/mikhail/copy-of-that-damn-iso - it had been asked to write into file with that name if it already existed or to create it and write into it if it didn't exist... So it had created a file in /dev with name adb and stored a copy into it. You might run out of space if the file had been large enough, but that's about it... Try ls -l /dev/adb /dev/sdb and compare these two - sdb will be something like brw-rw---- 1 root disk 8, 16 .... and adb - -rw-rw---- 1 root ... Block device and regular file respectively... man mknod if you are curious about device nodes and creating them manually - usually that's done by scripts called by udev when it discovers devices, but that's what they boil down to in the end. Again, there's nothing magical about /dev or the names of specific device nodes created in it - it's just the usual place to put that stuff into, but that's it; you could call mknod(2) to create such device nodes in any directory, using any names.