mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Ahmad Fatoum <a.fatoum@pengutronix.de>
To: barebox@lists.infradead.org
Cc: Ahmad Fatoum <a.fatoum@pengutronix.de>
Subject: [PATCH 2/2] pstore: add unlink implementation for deleting pstore files
Date: Wed,  8 May 2024 13:18:36 +0200	[thread overview]
Message-ID: <20240508111836.307806-2-a.fatoum@pengutronix.de> (raw)
In-Reply-To: <20240508111836.307806-1-a.fatoum@pengutronix.de>

During debugging, it can be useful to delete a pstore file to start
fresh. There's already support for this in the code base using the erase
callback, but it was so far never called. Call it from the newly
introduced unlink operation.

Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
 fs/pstore/fs.c | 24 ++++++++++++++++++++++++
 1 file changed, 24 insertions(+)

diff --git a/fs/pstore/fs.c b/fs/pstore/fs.c
index f2ffc0ac6251..f11db91582aa 100644
--- a/fs/pstore/fs.c
+++ b/fs/pstore/fs.c
@@ -182,6 +182,29 @@ static int pstore_lseek(struct device *dev, FILE *file, loff_t pos)
 	return 0;
 }
 
+static int pstore_unlink(struct device *dev, const char *filename)
+{
+	struct list_head *head = dev->priv;
+	struct pstore_private *d;
+	int ret;
+
+	d = pstore_get_by_name(head, filename);
+	if (!d)
+		return -ENOENT;
+
+	if (!d->psi->erase)
+		return -EPERM;
+
+	ret = d->psi->erase(d->type, d->id, d->count, d->psi);
+	if (ret)
+		return ret;
+
+	list_del(&d->list);
+	free(d);
+
+	return 0;
+}
+
 static DIR *pstore_opendir(struct device *dev, const char *pathname)
 {
 	DIR *dir;
@@ -256,6 +279,7 @@ static struct fs_driver pstore_driver = {
 	.close     = pstore_close,
 	.read      = pstore_read,
 	.lseek     = pstore_lseek,
+	.unlink    = pstore_unlink,
 	.opendir   = pstore_opendir,
 	.readdir   = pstore_readdir,
 	.closedir  = pstore_closedir,
-- 
2.39.2




  reply	other threads:[~2024-05-08 11:19 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-05-08 11:18 [PATCH 1/2] pstore: move slash handling into common function Ahmad Fatoum
2024-05-08 11:18 ` Ahmad Fatoum [this message]
2024-05-08 12:42 ` Sascha Hauer
2024-05-08 12:43 ` Sascha Hauer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240508111836.307806-2-a.fatoum@pengutronix.de \
    --to=a.fatoum@pengutronix.de \
    --cc=barebox@lists.infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox