From: OGAWA Hirofumi <hirofumi@mail.parknet.co.jp>
To: Andrew Morton <akpm@osdl.org>
Cc: linux-kernel@vger.kernel.org
Subject: [PATCH 17/29] FAT: msdos_add_entry() cleanup
Date: Sun, 06 Mar 2005 03:53:09 +0900 [thread overview]
Message-ID: <87k6olq60a.fsf_-_@devron.myhome.or.jp> (raw)
In-Reply-To: <87oedyorgu.fsf_-_@devron.myhome.or.jp> (OGAWA Hirofumi's message of "Sun, 06 Mar 2005 03:52:33 +0900")
The msdos_add_entry() use similar interface to vfat_add_entry().
And use a same timestamp on some operations path.
Signed-off-by: OGAWA Hirofumi <hirofumi@mail.parknet.co.jp>
---
fs/msdos/namei.c | 162 ++++++++++++++++++++++++++++---------------------------
1 files changed, 84 insertions(+), 78 deletions(-)
diff -puN fs/msdos/namei.c~sync07-fat_dir4 fs/msdos/namei.c
--- linux-2.6.11/fs/msdos/namei.c~sync07-fat_dir4 2005-03-06 02:36:50.000000000 +0900
+++ linux-2.6.11-hirofumi/fs/msdos/namei.c 2005-03-06 02:36:50.000000000 +0900
@@ -253,31 +253,38 @@ out:
/***** Creates a directory entry (name is already formatted). */
static int msdos_add_entry(struct inode *dir, const unsigned char *name,
- struct buffer_head **bh,
- struct msdos_dir_entry **de,
- loff_t *i_pos, int is_dir, int is_hid)
+ int is_dir, int is_hid, struct timespec *ts,
+ struct fat_slot_info *sinfo)
{
- int res;
+ struct msdos_dir_entry de;
+ __le16 time, date;
+ int offset;
- res = fat_add_entries(dir, 1, bh, de, i_pos);
- if (res < 0)
- return res;
+ memcpy(de.name, name, MSDOS_NAME);
+ de.attr = is_dir ? ATTR_DIR : ATTR_ARCH;
+ if (is_hid)
+ de.attr |= ATTR_HIDDEN;
+ de.lcase = 0;
+ fat_date_unix2dos(ts->tv_sec, &time, &date);
+ de.time = de.ctime = time;
+ de.date = de.cdate = de.adate = date;
+ de.ctime_cs = 0;
+ de.start = 0;
+ de.starthi = 0;
+ de.size = 0;
+
+ offset = fat_add_entries(dir, 1, &sinfo->bh, &sinfo->de, &sinfo->i_pos);
+ if (offset < 0)
+ return offset;
+ sinfo->slot_off = offset;
+ sinfo->nr_slots = 1;
- /*
- * XXX all times should be set by caller upon successful completion.
- */
- dir->i_ctime = dir->i_mtime = CURRENT_TIME_SEC;
+ memcpy(sinfo->de, &de, sizeof(de));
+ mark_buffer_dirty(sinfo->bh);
+
+ dir->i_ctime = dir->i_mtime = *ts;
mark_inode_dirty(dir);
- memcpy((*de)->name, name, MSDOS_NAME);
- (*de)->attr = is_dir ? ATTR_DIR : ATTR_ARCH;
- if (is_hid)
- (*de)->attr |= ATTR_HIDDEN;
- (*de)->start = 0;
- (*de)->starthi = 0;
- fat_date_unix2dos(dir->i_mtime.tv_sec, &(*de)->time, &(*de)->date);
- (*de)->size = 0;
- mark_buffer_dirty(*bh);
return 0;
}
@@ -286,45 +293,43 @@ static int msdos_create(struct inode *di
struct nameidata *nd)
{
struct super_block *sb = dir->i_sb;
- struct fat_slot_info sinfo;
- struct buffer_head *bh;
- struct msdos_dir_entry *de;
struct inode *inode;
- loff_t i_pos;
- int res, is_hid;
+ struct fat_slot_info sinfo;
+ struct timespec ts;
unsigned char msdos_name[MSDOS_NAME];
+ int err, is_hid;
lock_kernel();
- res = msdos_format_name(dentry->d_name.name, dentry->d_name.len,
+
+ err = msdos_format_name(dentry->d_name.name, dentry->d_name.len,
msdos_name, &MSDOS_SB(sb)->options);
- if (res < 0) {
- unlock_kernel();
- return res;
- }
+ if (err)
+ goto out;
is_hid = (dentry->d_name.name[0] == '.') && (msdos_name[0] != '.');
/* Have to do it due to foo vs. .foo conflicts */
if (!fat_scan(dir, msdos_name, &sinfo)) {
brelse(sinfo.bh);
- unlock_kernel();
- return -EINVAL;
+ err = -EINVAL;
+ goto out;
}
- res = msdos_add_entry(dir, msdos_name, &bh, &de, &i_pos, 0, is_hid);
- if (res) {
- unlock_kernel();
- return res;
- }
- inode = fat_build_inode(sb, de, i_pos);
- brelse(bh);
+ ts = CURRENT_TIME_SEC;
+ err = msdos_add_entry(dir, msdos_name, 0, is_hid, &ts, &sinfo);
+ if (err)
+ goto out;
+ inode = fat_build_inode(sb, sinfo.de, sinfo.i_pos);
+ brelse(sinfo.bh);
if (IS_ERR(inode)) {
- unlock_kernel();
- return PTR_ERR(inode);
+ err = PTR_ERR(inode);
+ goto out;
}
- inode->i_mtime = inode->i_atime = inode->i_ctime = CURRENT_TIME_SEC;
- mark_inode_dirty(inode);
+ inode->i_mtime = inode->i_atime = inode->i_ctime = ts;
+ /* timestamp is already written, so mark_inode_dirty() is unneeded. */
+
d_instantiate(dentry, inode);
+out:
unlock_kernel();
- return 0;
+ return err;
}
/***** Remove a directory */
@@ -367,65 +372,63 @@ static int msdos_mkdir(struct inode *dir
{
struct super_block *sb = dir->i_sb;
struct fat_slot_info sinfo;
- struct buffer_head *bh;
- struct msdos_dir_entry *de;
struct inode *inode;
- int res, is_hid;
unsigned char msdos_name[MSDOS_NAME];
- loff_t i_pos;
+ struct timespec ts;
+ int err, is_hid;
lock_kernel();
- res = msdos_format_name(dentry->d_name.name, dentry->d_name.len,
+
+ err = msdos_format_name(dentry->d_name.name, dentry->d_name.len,
msdos_name, &MSDOS_SB(sb)->options);
- if (res < 0) {
- unlock_kernel();
- return res;
- }
+ if (err)
+ goto out;
is_hid = (dentry->d_name.name[0] == '.') && (msdos_name[0] != '.');
/* foo vs .foo situation */
if (!fat_scan(dir, msdos_name, &sinfo)) {
brelse(sinfo.bh);
- res = -EINVAL;
- goto out_unlock;
+ err = -EINVAL;
+ goto out;
}
- res = msdos_add_entry(dir, msdos_name, &bh, &de, &i_pos, 1, is_hid);
- if (res)
- goto out_unlock;
- inode = fat_build_inode(dir->i_sb, de, i_pos);
+ ts = CURRENT_TIME_SEC;
+ err = msdos_add_entry(dir, msdos_name, 1, is_hid, &ts, &sinfo);
+ if (err)
+ goto out;
+ inode = fat_build_inode(sb, sinfo.de, sinfo.i_pos);
if (IS_ERR(inode)) {
- brelse(bh);
- res = PTR_ERR(inode);
- goto out_unlock;
+ brelse(sinfo.bh);
+ err = PTR_ERR(inode);
+ goto out;
}
+ inode->i_mtime = inode->i_atime = inode->i_ctime = ts;
+ /* timestamp is already written, so mark_inode_dirty() is unneeded. */
dir->i_nlink++;
inode->i_nlink = 2; /* no need to mark them dirty */
- res = fat_new_dir(inode, dir, 0);
- if (res)
+ err = fat_new_dir(inode, dir, 0);
+ if (err)
goto mkdir_error;
- brelse(bh);
+ brelse(sinfo.bh);
d_instantiate(dentry, inode);
- res = 0;
-
-out_unlock:
+out:
unlock_kernel();
- return res;
+ return err;
mkdir_error:
inode->i_nlink = 0;
- inode->i_ctime = dir->i_ctime = dir->i_mtime = CURRENT_TIME_SEC;
+ inode->i_ctime = dir->i_ctime = dir->i_mtime = ts;
dir->i_nlink--;
mark_inode_dirty(inode);
mark_inode_dirty(dir);
- de->name[0] = DELETED_FLAG;
- mark_buffer_dirty(bh);
- brelse(bh);
+ sinfo.de->name[0] = DELETED_FLAG;
+ mark_buffer_dirty(sinfo.bh);
+ brelse(sinfo.bh);
fat_detach(inode);
iput(inode);
- goto out_unlock;
+ goto out;
}
/***** Unlink a file */
@@ -465,6 +468,7 @@ static int do_msdos_rename(struct inode
loff_t dotdot_i_pos;
struct inode *old_inode, *new_inode;
struct fat_slot_info old_sinfo, sinfo;
+ struct timespec ts;
int err, is_dir;
old_sinfo.bh = dotdot_bh = NULL;
@@ -507,6 +511,8 @@ static int do_msdos_rename(struct inode
goto out;
}
}
+
+ ts = CURRENT_TIME_SEC;
if (new_inode) {
if (err)
goto out;
@@ -523,8 +529,8 @@ static int do_msdos_rename(struct inode
}
fat_detach(new_inode);
} else {
- err = msdos_add_entry(new_dir, new_name, &sinfo.bh, &sinfo.de,
- &sinfo.i_pos, is_dir, is_hid);
+ err = msdos_add_entry(new_dir, new_name, is_dir, is_hid,
+ &ts, &sinfo);
if (err)
goto out;
brelse(sinfo.bh);
@@ -546,12 +552,12 @@ static int do_msdos_rename(struct inode
mark_inode_dirty(old_inode);
old_dir->i_version++;
- old_dir->i_ctime = old_dir->i_mtime = CURRENT_TIME_SEC;
+ old_dir->i_ctime = old_dir->i_mtime = ts;
mark_inode_dirty(old_dir);
if (new_inode) {
new_inode->i_nlink--;
- new_inode->i_ctime = CURRENT_TIME_SEC;
+ new_inode->i_ctime = ts;
mark_inode_dirty(new_inode);
}
if (is_dir) {
_
next prev parent reply other threads:[~2005-03-05 20:09 UTC|newest]
Thread overview: 40+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <87ll92rl6a.fsf@devron.myhome.or.jp>
2005-03-05 18:41 ` [PATCH 1/29] fat: fix writev(), add aio support OGAWA Hirofumi
2005-03-05 18:42 ` [PATCH 2/29] FAT: Updated FAT attributes patch OGAWA Hirofumi
2005-03-05 18:43 ` [PATCH 3/29] FAT: fat_readdirx() with dotOK=yes fix OGAWA Hirofumi
2005-03-05 18:43 ` [PATCH 4/29] let fat handle MS_SYNCHRONOUS flag OGAWA Hirofumi
2005-03-06 22:38 ` Christoph Hellwig
2005-03-07 14:56 ` OGAWA Hirofumi
2005-03-05 18:44 ` [PATCH 5/29] FAT: Rewrite the FAT (File Allocation Table) access stuff OGAWA Hirofumi
2005-03-05 18:45 ` [PATCH 6/29] FAT: add debugging code to fatent.c OGAWA Hirofumi
2005-03-05 18:47 ` [PATCH 7/29] FAT: Use "unsigned int" for ->free_clusters and ->prev_free OGAWA Hirofumi
2005-03-05 18:47 ` [PATCH 8/29] FAT: "struct vfat_slot_info" cleanup OGAWA Hirofumi
2005-03-05 18:48 ` [PATCH 9/29] FAT: Use "struct fat_slot_info" for fat_search_long() OGAWA Hirofumi
2005-03-05 18:49 ` [PATCH 10/29] FAT: Add fat_remove_entries() OGAWA Hirofumi
2005-03-05 18:49 ` [PATCH 11/29] FAT: fat_build_inode() cleanup OGAWA Hirofumi
2005-03-05 18:50 ` [PATCH 12/29] FAT: Use "struct fat_slot_info" for fat_scan() OGAWA Hirofumi
2005-03-05 18:50 ` [PATCH 13/29] FAT: Use "struct fat_slot_info" for msdos_find() OGAWA Hirofumi
2005-03-05 18:51 ` [PATCH 14/29] FAT: vfat_build_slots() cleanup OGAWA Hirofumi
2005-03-05 18:52 ` [PATCH 15/29] FAT: Use a same timestamp on some operations path OGAWA Hirofumi
2005-03-05 18:52 ` [PATCH 16/29] FAT: msdos_rename() cleanup OGAWA Hirofumi
2005-03-05 18:53 ` OGAWA Hirofumi [this message]
2005-03-05 18:53 ` [PATCH 18/29] FAT: Allocate the cluster before adding the directory entry OGAWA Hirofumi
2005-03-05 18:54 ` [PATCH 19/29] FAT: Rewrite fat_add_entries() OGAWA Hirofumi
2005-03-05 18:55 ` [PATCH 20/29] FAT: Use fat_remove_entries() for msdos OGAWA Hirofumi
2005-03-05 18:55 ` [PATCH 21/29] FAT: make the fat_get_entry()/fat__get_entry() the static OGAWA Hirofumi
2005-03-05 18:56 ` [PATCH 22/29] FAT: "i_pos" cleanup OGAWA Hirofumi
2005-03-05 18:56 ` [PATCH 23/29] FAT: Remove the multiple MSDOS_SB() call OGAWA Hirofumi
2005-03-05 18:57 ` [PATCH 24/29] FAT: Remove unneed mark_inode_dirty() OGAWA Hirofumi
2005-03-05 18:57 ` [PATCH 25/29] FAT: Fix fat_truncate() OGAWA Hirofumi
2005-03-05 18:58 ` [PATCH 26/29] FAT: Fix fat_write_inode() OGAWA Hirofumi
2005-03-05 18:58 ` [PATCH 27/29] FAT: Use synchronous update for {vfat,msdos}_add_entry() OGAWA Hirofumi
2005-03-05 18:59 ` [PATCH 28/29] FAT: Update ->rename() path OGAWA Hirofumi
2005-03-05 19:00 ` [PATCH 29/29] FAT: Fix typo OGAWA Hirofumi
2005-03-06 22:44 ` [PATCH 23/29] FAT: Remove the multiple MSDOS_SB() call Christoph Hellwig
2005-03-07 22:01 ` Adrian Bunk
2005-03-08 13:48 ` OGAWA Hirofumi
2005-03-06 15:53 ` [PATCH 2/29] FAT: Updated FAT attributes patch Michael Geng
2005-03-06 17:02 ` OGAWA Hirofumi
2005-03-06 22:45 ` Christoph Hellwig
2005-03-06 0:07 ` [PATCH] FAT: Support synchronous updates OGAWA Hirofumi
2005-03-07 1:10 ` [PATCH] FAT: Support synchronous update Andrew Morton
2005-03-07 15:02 ` OGAWA Hirofumi
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=87k6olq60a.fsf_-_@devron.myhome.or.jp \
--to=hirofumi@mail.parknet.co.jp \
--cc=akpm@osdl.org \
--cc=linux-kernel@vger.kernel.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