From: Gabriel Dalimonte <gabriel.dalimonte@gmail.com>
To: u-boot@lists.denx.de
Cc: Gabriel Dalimonte <gabriel.dalimonte@gmail.com>,
Heinrich Schuchardt <xypron.glpk@gmx.de>,
Tom Rini <trini@konsulko.com>
Subject: [PATCH 1/6] fs: fat: factor out dentry link create/delete
Date: Wed, 22 Jan 2025 00:32:26 -0500 [thread overview]
Message-ID: <20250122053232.17365-2-gabriel.dalimonte@gmail.com> (raw)
In-Reply-To: <20250122053232.17365-1-gabriel.dalimonte@gmail.com>
Signed-off-by: Gabriel Dalimonte <gabriel.dalimonte@gmail.com>
---
fs/fat/fat_write.c | 122 ++++++++++++++++++++++++---------------------
1 file changed, 66 insertions(+), 56 deletions(-)
diff --git a/fs/fat/fat_write.c b/fs/fat/fat_write.c
index ea877ee917..b86e78abc0 100644
--- a/fs/fat/fat_write.c
+++ b/fs/fat/fat_write.c
@@ -1215,6 +1215,44 @@ static void fill_dentry(fsdata *mydata, dir_entry *dentptr,
memcpy(&dentptr->nameext, shortname, SHORT_NAME_SIZE);
}
+/**
+ * create_link() - inserts a directory entry for a cluster
+ *
+ * @itr: directory iterator
+ * @basename: name of the new entry
+ * @clust: cluster number the new directory entry should point to
+ * @size: file size
+ * @attr: file attributes
+ * Return: 0 for success
+ */
+static int create_link(fat_itr *itr, char *basename, __u32 clust, __u32 size,
+ __u8 attr)
+{
+ char shortname[SHORT_NAME_SIZE];
+ int ndent;
+ int ret;
+
+ /* Check if long name is needed */
+ ndent = set_name(itr, basename, shortname);
+ if (ndent < 0)
+ return ndent;
+ ret = fat_find_empty_dentries(itr, ndent);
+ if (ret)
+ return ret;
+ if (ndent > 1) {
+ /* Set long name entries */
+ ret = fill_dir_slot(itr, basename, shortname);
+ if (ret)
+ return ret;
+ }
+
+ /* Add attribute as archive */
+ fill_dentry(itr->fsdata, itr->dent, shortname, clust, size,
+ attr | ATTR_ARCH);
+
+ return 0;
+}
+
/**
* find_directory_entry() - find a directory entry by filename
*
@@ -1420,35 +1458,15 @@ int file_fat_write_at(const char *filename, loff_t pos, void *buffer,
/* Update change date */
dentry_set_time(retdent);
} else {
- /* Create a new file */
- char shortname[SHORT_NAME_SIZE];
- int ndent;
-
if (pos) {
/* No hole allowed */
ret = -EINVAL;
goto exit;
}
- /* Check if long name is needed */
- ndent = set_name(itr, basename, shortname);
- if (ndent < 0) {
- ret = ndent;
- goto exit;
- }
- ret = fat_find_empty_dentries(itr, ndent);
+ ret = create_link(itr, basename, 0, size, 0);
if (ret)
goto exit;
- if (ndent > 1) {
- /* Set long name entries */
- ret = fill_dir_slot(itr, basename, shortname);
- if (ret)
- goto exit;
- }
-
- /* Set short name entry */
- fill_dentry(itr->fsdata, itr->dent, shortname, 0, size,
- ATTR_ARCH);
retdent = itr->dent;
}
@@ -1564,6 +1582,31 @@ static int delete_long_name(fat_itr *itr)
return 0;
}
+/**
+ * delete_dentry_link() - deletes a directory entry, but not the cluster chain
+ * it points to
+ *
+ * @itr: the first directory entry (if a longname) to remove
+ * Return: 0 for success
+ */
+static int delete_dentry_link(fat_itr *itr)
+{
+ itr->dent = itr->dent_start;
+ itr->remaining = itr->dent_rem;
+ /* Delete long name */
+ if ((itr->dent->attr & ATTR_VFAT) == ATTR_VFAT &&
+ (itr->dent->nameext.name[0] & LAST_LONG_ENTRY_MASK)) {
+ int ret;
+
+ ret = delete_long_name(itr);
+ if (ret)
+ return ret;
+ }
+ /* Delete short name */
+ delete_single_dentry(itr);
+ return flush_dir(itr);
+}
+
/**
* delete_dentry_long() - remove directory entry
*
@@ -1589,21 +1632,7 @@ static int delete_dentry_long(fat_itr *itr)
if (ret)
return ret;
}
- itr->dent = itr->dent_start;
- itr->remaining = itr->dent_rem;
- dent = itr->dent_start;
- /* Delete long name */
- if ((dent->attr & ATTR_VFAT) == ATTR_VFAT &&
- (dent->nameext.name[0] & LAST_LONG_ENTRY_MASK)) {
- int ret;
-
- ret = delete_long_name(itr);
- if (ret)
- return ret;
- }
- /* Delete short name */
- delete_single_dentry(itr);
- return flush_dir(itr);
+ return delete_dentry_link(itr);
}
int fat_unlink(const char *filename)
@@ -1725,9 +1754,6 @@ int fat_mkdir(const char *dirname)
ret = -EEXIST;
goto exit;
} else {
- char shortname[SHORT_NAME_SIZE];
- int ndent;
-
if (itr->is_root) {
/* root dir cannot have "." or ".." */
if (!strcmp(l_dirname, ".") ||
@@ -1737,25 +1763,9 @@ int fat_mkdir(const char *dirname)
}
}
- /* Check if long name is needed */
- ndent = set_name(itr, basename, shortname);
- if (ndent < 0) {
- ret = ndent;
- goto exit;
- }
- ret = fat_find_empty_dentries(itr, ndent);
+ ret = create_link(itr, basename, 0, 0, ATTR_DIR);
if (ret)
goto exit;
- if (ndent > 1) {
- /* Set long name entries */
- ret = fill_dir_slot(itr, basename, shortname);
- if (ret)
- goto exit;
- }
-
- /* Set attribute as archive for regular file */
- fill_dentry(itr->fsdata, itr->dent, shortname, 0, 0,
- ATTR_DIR | ATTR_ARCH);
retdent = itr->dent;
}
--
2.34.1
next prev parent reply other threads:[~2025-01-22 13:22 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-01-22 5:32 [PATCH 0/6] add support for renaming to EFI_FILE_PROTOCOL.SetInfo() Gabriel Dalimonte
2025-01-22 5:32 ` Gabriel Dalimonte [this message]
2025-01-22 7:08 ` [PATCH 1/6] fs: fat: factor out dentry link create/delete Heinrich Schuchardt
2025-01-26 4:34 ` Gabriel D'Alimonte
2025-01-22 5:32 ` [PATCH 2/6] fs: add rename infrastructure Gabriel Dalimonte
2025-01-22 8:10 ` Heinrich Schuchardt
2025-01-22 9:18 ` Heinrich Schuchardt
2025-01-26 4:38 ` Gabriel D'Alimonte
2025-01-22 5:32 ` [PATCH 3/6] fs: fat: add rename Gabriel Dalimonte
2025-01-22 8:41 ` Heinrich Schuchardt
2025-01-22 5:32 ` [PATCH 4/6] fs: fat: update parent dirs metadata on rename Gabriel Dalimonte
2025-01-22 9:00 ` Heinrich Schuchardt
2025-01-26 4:39 ` Gabriel D'Alimonte
2025-01-22 5:32 ` [PATCH 5/6] efi_loader: move path out of file_handle Gabriel Dalimonte
2025-01-22 5:32 ` [PATCH 6/6] efi_loader: support file rename in SetInfo() Gabriel Dalimonte
2025-02-04 12:53 ` Ilias Apalodimas
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=20250122053232.17365-2-gabriel.dalimonte@gmail.com \
--to=gabriel.dalimonte@gmail.com \
--cc=trini@konsulko.com \
--cc=u-boot@lists.denx.de \
--cc=xypron.glpk@gmx.de \
/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