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,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS,URIBL_BLOCKED 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 E65DCC4727C for ; Wed, 30 Sep 2020 17:49:36 +0000 (UTC) Received: from shelob.surriel.com (shelob.surriel.com [96.67.55.147]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 3ED372074B for ; Wed, 30 Sep 2020 17:49:35 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=kroah.com header.i=@kroah.com header.b="n+casK3K"; dkim=temperror (0-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="rbomI1s9" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 3ED372074B Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=kroah.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=kernelnewbies-bounces@kernelnewbies.org Received: from localhost ([::1] helo=shelob.surriel.com) by shelob.surriel.com with esmtp (Exim 4.94) (envelope-from ) id 1kNgE3-0001yE-7q; Wed, 30 Sep 2020 13:49:11 -0400 Received: from wout2-smtp.messagingengine.com ([64.147.123.25]) by shelob.surriel.com with esmtps (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94) (envelope-from ) id 1kNgE1-0001xw-N9 for kernelnewbies@kernelnewbies.org; Wed, 30 Sep 2020 13:49:10 -0400 Received: from compute2.internal (compute2.nyi.internal [10.202.2.42]) by mailout.west.internal (Postfix) with ESMTP id ED77FF8E; Wed, 30 Sep 2020 13:49:05 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute2.internal (MEProxy); Wed, 30 Sep 2020 13:49:06 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kroah.com; h= date:from:to:cc:subject:message-id:references:mime-version :content-type:in-reply-to; s=fm1; bh=9ObrK20Z8IhHAIGgf/DCdO+/sAY U86RRFfnJw/u6Gak=; b=n+casK3KEiVtxoud+zWt93rk7D/ujw5LAR3VMZUihgi SKcyqXiJW5KMRY6PJPteiV1qtVXqujdGjA4TAV6CQHwqwpHPCBEf3iaCy1TSMcNR g1FXEw/oX0jxC0f2AgwJC7YDf4iR+c+e1jzl5O6FpWP8X/ALOU6EQmijAuJ0J5Rz dTsQvJ+mMbR82aW4UCb9Q+wRJw3V2EPu3UBryCpFoYtj2CU5Hlfd6z0qeaTCl9jv DzklOs7+tjCE88Yf1IXdM0TzBtEuAMWG+NDKZC6QnoYLDxTvTlYpnFDL/wgaQcX+ VHLtTP6lZe6MzjyMFEw/HedqkYYHYfoVb2PSSXJ7TMg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to:x-me-proxy :x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s=fm3; bh=9ObrK2 0Z8IhHAIGgf/DCdO+/sAYU86RRFfnJw/u6Gak=; b=rbomI1s9rP7dqvIdwMfhE0 QOprEiPGe/nrMEXkd9GuVWXXU0I6H68pb2oHgLET6r/MQyN44NSug7PQRL9nxaSO yLKJGlQAXCF16Wzjk/yTrfJ1ovw8IwcQoFCXD0ka7C+spZsXuQbhESMQkLXVv2oG epfvYnI9pv4X/nroKBG1JqnWC6ZNyEQFjOBDfY1GyJvttT+VoM9GTLlqGfuHUNyl 9qbmd9BNxZOcK5dOIeaUVguR89VqiFK2hGs6K1jCKNhA/ba8VrwjYaeAOFodjBl+ eYL8ShsMFhlj0p9wP/UwYHu/LOVIgrAYbnPAyf4NTsubhK+oPY/TwxupGVjTIVQQ == X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedujedrfedvgdduudegucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucenucfjughrpeffhffvuffkfhggtggujgesthdtre dttddtvdenucfhrhhomhepifhrvghgucfmjfcuoehgrhgvgheskhhrohgrhhdrtghomheq necuggftrfgrthhtvghrnhepveeuheejgfffgfeivddukedvkedtleelleeghfeljeeiue eggeevueduudekvdetnecukfhppeekfedrkeeirdejgedrieegnecuvehluhhsthgvrhfu ihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomhepghhrvghgsehkrhhorghhrdgtoh hm X-ME-Proxy: Received: from localhost (83-86-74-64.cable.dynamic.v4.ziggo.nl [83.86.74.64]) by mail.messagingengine.com (Postfix) with ESMTPA id 02EE1328005A; Wed, 30 Sep 2020 13:49:04 -0400 (EDT) Date: Wed, 30 Sep 2020 19:49:06 +0200 From: Greg KH To: ymdatta Subject: Re: Accessing allocated space in a debugfs file Message-ID: <20200930174906.GA1687038@kroah.com> References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: Cc: kernelnewbies@kernelnewbies.org X-BeenThere: kernelnewbies@kernelnewbies.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: Learn about the Linux kernel List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: kernelnewbies-bounces@kernelnewbies.org On Wed, Sep 30, 2020 at 10:32:05PM +0530, ymdatta wrote: > Hello everyone, > > I am trying to create a debugfs file for exposing some information to the > userspace. (I am exploring on how to use debugfs) > > >From the documentation (Documentation/filesystems/debugfs.txt), i came > across a function called > > struct dentry *debugfs_create_file_size(...,loff_t file_size); > > This essentially creates a file with an initial size. > > I want to write in this file, how should i be accessing the space created > from previous function call. That's not what "size" means here. "size" just sets the value that you see if you look at the directory for that debugfs file (or stat() it). If you don't set a specific "size", it will just show up as 4k (PAGE_SIZE). > I have looked through the source code, but i have found very few places > where this function is used. In one of the use cases [0], the memory > equal to the size is allocated in the open file operation, and the > private_data member is pointed to this. (Looking at [0] helps in > understanding this). But from #kernelnewbies channel, i found that > private_data is a pointer for tty/char drivers. debugfs is a virtual filesystem, there is no "backing store" or place to put your data in it. It is there so that you can write code that can handle open/read/write/close to happen on a file, and your code will provide the data to userspace directly. The simplest way to create a debugfs file is to just point it at a variable, and then you can change the variable value in the kernel, and userspace reading from the file will see whatever the value is at that point in time. Does that help? thanks, greg k-h _______________________________________________ Kernelnewbies mailing list Kernelnewbies@kernelnewbies.org https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies