2008-02-03 18:36:46

by Marcin Ślusarz

[permalink] [raw]
Subject: [PATCH 0/6] udf: next round of cleanups

Hi

This patchset contains next round of various UDF fs cleanups.

[PATCH 1/6] udf: udf_get_block, inode_bmap - remove unneeded checks

[PATCH 2/6] udf: create function for conversion from timestamp to timespec
[PATCH 3/6] udf: convert udf_stamp_to_time to return struct timespec
[PATCH 4/6] udf: convert udf_stamp_to_time and udf_time_to_stamp to use timestamps
[PATCH 5/6] udf: remove unneeded kernel_timestamp type
These 4 patches can be folded into one if requested, but I think it's
easier to analyze them when they are split.

[PATCH 6/6] udf: super.c reorganization
Pretty mechanical work. Can be dropped and redone if it will
conflict with someone else patch.

fs/udf/ecma_167.h | 13 -
fs/udf/inode.c | 183 ++++++-----------
fs/udf/super.c | 553 ++++++++++++++++++++++++++----------------------------
fs/udf/udfdecl.h | 8
fs/udf/udfend.h | 22 --
fs/udf/udftime.c | 39 +--
6 files changed, 358 insertions(+), 460 deletions(-)

Applies on top of patches I've sent lately (http://lkml.org/lkml/2008/1/30/482)

Jan: Are you going to create git tree for udf?

Marcin Slusarz


2008-02-03 18:37:23

by Marcin Ślusarz

[permalink] [raw]
Subject: [PATCH 1/6] udf: udf_get_block, inode_bmap - remove unneeded checks

block cannot be less than 0, because it's sector_t,
so remove unneeded checks

Signed-off-by: Marcin Slusarz <[email protected]>
Cc: Jan Kara <[email protected]>
---
fs/udf/inode.c | 12 ------------
1 files changed, 0 insertions(+), 12 deletions(-)

diff --git a/fs/udf/inode.c b/fs/udf/inode.c
index c2d0477..531443d 100644
--- a/fs/udf/inode.c
+++ b/fs/udf/inode.c
@@ -323,9 +323,6 @@ static int udf_get_block(struct inode *inode, sector_t block,

lock_kernel();

- if (block < 0)
- goto abort_negative;
-
iinfo = UDF_I(inode);
if (block == iinfo->i_next_alloc_block + 1) {
iinfo->i_next_alloc_block++;
@@ -347,10 +344,6 @@ static int udf_get_block(struct inode *inode, sector_t block,
abort:
unlock_kernel();
return err;
-
-abort_negative:
- udf_warning(inode->i_sb, "udf_get_block", "block < 0");
- goto abort;
}

static struct buffer_head *udf_getblk(struct inode *inode, long block,
@@ -2081,11 +2074,6 @@ int8_t inode_bmap(struct inode *inode, sector_t block,
int8_t etype;
struct udf_inode_info *iinfo;

- if (block < 0) {
- printk(KERN_ERR "udf: inode_bmap: block < 0\n");
- return -1;
- }
-
iinfo = UDF_I(inode);
pos->offset = 0;
pos->block = iinfo->i_location;
--
1.5.3.7

2008-02-03 18:37:45

by Marcin Ślusarz

[permalink] [raw]
Subject: [PATCH 2/6] udf: create function for conversion from timestamp to timespec

Signed-off-by: Marcin Slusarz <[email protected]>
Cc: Jan Kara <[email protected]>
---
fs/udf/inode.c | 79 ++++++++++++++++---------------------------------------
1 files changed, 23 insertions(+), 56 deletions(-)

diff --git a/fs/udf/inode.c b/fs/udf/inode.c
index 531443d..2578677 100644
--- a/fs/udf/inode.c
+++ b/fs/udf/inode.c
@@ -1151,12 +1151,24 @@ static void __udf_read_inode(struct inode *inode)
brelse(bh);
}

+static void udf_fill_inode_time(struct timespec *tspec,
+ const timestamp *tstamp,
+ struct udf_sb_info *sbi)
+{
+ time_t convtime;
+ long convtime_usec;
+ if (udf_stamp_to_time(&convtime, &convtime_usec,
+ lets_to_cpu(*tstamp))) {
+ tspec->tv_sec = convtime;
+ tspec->tv_nsec = convtime_usec * 1000;
+ } else
+ *tspec = sbi->s_record_time;
+}
+
static void udf_fill_inode(struct inode *inode, struct buffer_head *bh)
{
struct fileEntry *fe;
struct extendedFileEntry *efe;
- time_t convtime;
- long convtime_usec;
int offset;
struct udf_sb_info *sbi = UDF_SB(inode->i_sb);
struct udf_inode_info *iinfo = UDF_I(inode);
@@ -1244,29 +1256,10 @@ static void udf_fill_inode(struct inode *inode, struct buffer_head *bh)
inode->i_blocks = le64_to_cpu(fe->logicalBlocksRecorded) <<
(inode->i_sb->s_blocksize_bits - 9);

- if (udf_stamp_to_time(&convtime, &convtime_usec,
- lets_to_cpu(fe->accessTime))) {
- inode->i_atime.tv_sec = convtime;
- inode->i_atime.tv_nsec = convtime_usec * 1000;
- } else {
- inode->i_atime = sbi->s_record_time;
- }
-
- if (udf_stamp_to_time(&convtime, &convtime_usec,
- lets_to_cpu(fe->modificationTime))) {
- inode->i_mtime.tv_sec = convtime;
- inode->i_mtime.tv_nsec = convtime_usec * 1000;
- } else {
- inode->i_mtime = sbi->s_record_time;
- }
-
- if (udf_stamp_to_time(&convtime, &convtime_usec,
- lets_to_cpu(fe->attrTime))) {
- inode->i_ctime.tv_sec = convtime;
- inode->i_ctime.tv_nsec = convtime_usec * 1000;
- } else {
- inode->i_ctime = sbi->s_record_time;
- }
+ udf_fill_inode_time(&inode->i_atime, &fe->accessTime, sbi);
+ udf_fill_inode_time(&inode->i_mtime, &fe->modificationTime,
+ sbi);
+ udf_fill_inode_time(&inode->i_ctime, &fe->attrTime, sbi);

iinfo->i_unique = le64_to_cpu(fe->uniqueID);
iinfo->i_lenEAttr = le32_to_cpu(fe->lengthExtendedAttr);
@@ -1276,37 +1269,11 @@ static void udf_fill_inode(struct inode *inode, struct buffer_head *bh)
inode->i_blocks = le64_to_cpu(efe->logicalBlocksRecorded) <<
(inode->i_sb->s_blocksize_bits - 9);

- if (udf_stamp_to_time(&convtime, &convtime_usec,
- lets_to_cpu(efe->accessTime))) {
- inode->i_atime.tv_sec = convtime;
- inode->i_atime.tv_nsec = convtime_usec * 1000;
- } else {
- inode->i_atime = sbi->s_record_time;
- }
-
- if (udf_stamp_to_time(&convtime, &convtime_usec,
- lets_to_cpu(efe->modificationTime))) {
- inode->i_mtime.tv_sec = convtime;
- inode->i_mtime.tv_nsec = convtime_usec * 1000;
- } else {
- inode->i_mtime = sbi->s_record_time;
- }
-
- if (udf_stamp_to_time(&convtime, &convtime_usec,
- lets_to_cpu(efe->createTime))) {
- iinfo->i_crtime.tv_sec = convtime;
- iinfo->i_crtime.tv_nsec = convtime_usec * 1000;
- } else {
- iinfo->i_crtime = sbi->s_record_time;
- }
-
- if (udf_stamp_to_time(&convtime, &convtime_usec,
- lets_to_cpu(efe->attrTime))) {
- inode->i_ctime.tv_sec = convtime;
- inode->i_ctime.tv_nsec = convtime_usec * 1000;
- } else {
- inode->i_ctime = sbi->s_record_time;
- }
+ udf_fill_inode_time(&inode->i_atime, &efe->accessTime, sbi);
+ udf_fill_inode_time(&inode->i_mtime, &efe->modificationTime,
+ sbi);
+ udf_fill_inode_time(&iinfo->i_crtime, &efe->createTime, sbi);
+ udf_fill_inode_time(&inode->i_ctime, &efe->attrTime, sbi);

iinfo->i_unique = le64_to_cpu(efe->uniqueID);
iinfo->i_lenEAttr = le32_to_cpu(efe->lengthExtendedAttr);
--
1.5.3.7

2008-02-03 18:37:59

by Marcin Ślusarz

[permalink] [raw]
Subject: [PATCH 3/6] udf: convert udf_stamp_to_time to return struct timespec

Signed-off-by: Marcin Slusarz <[email protected]>
Cc: Jan Kara <[email protected]>
---
fs/udf/inode.c | 49 ++++++++++++++++++++++++++-----------------------
fs/udf/super.c | 9 ++-------
fs/udf/udfdecl.h | 4 ++--
fs/udf/udftime.c | 17 +++++++----------
4 files changed, 37 insertions(+), 42 deletions(-)

diff --git a/fs/udf/inode.c b/fs/udf/inode.c
index 2578677..252efe0 100644
--- a/fs/udf/inode.c
+++ b/fs/udf/inode.c
@@ -1151,20 +1151,6 @@ static void __udf_read_inode(struct inode *inode)
brelse(bh);
}

-static void udf_fill_inode_time(struct timespec *tspec,
- const timestamp *tstamp,
- struct udf_sb_info *sbi)
-{
- time_t convtime;
- long convtime_usec;
- if (udf_stamp_to_time(&convtime, &convtime_usec,
- lets_to_cpu(*tstamp))) {
- tspec->tv_sec = convtime;
- tspec->tv_nsec = convtime_usec * 1000;
- } else
- *tspec = sbi->s_record_time;
-}
-
static void udf_fill_inode(struct inode *inode, struct buffer_head *bh)
{
struct fileEntry *fe;
@@ -1256,10 +1242,17 @@ static void udf_fill_inode(struct inode *inode, struct buffer_head *bh)
inode->i_blocks = le64_to_cpu(fe->logicalBlocksRecorded) <<
(inode->i_sb->s_blocksize_bits - 9);

- udf_fill_inode_time(&inode->i_atime, &fe->accessTime, sbi);
- udf_fill_inode_time(&inode->i_mtime, &fe->modificationTime,
- sbi);
- udf_fill_inode_time(&inode->i_ctime, &fe->attrTime, sbi);
+ if (!udf_stamp_to_time(&inode->i_atime,
+ lets_to_cpu(fe->accessTime)))
+ inode->i_atime = sbi->s_record_time;
+
+ if (!udf_stamp_to_time(&inode->i_mtime,
+ lets_to_cpu(fe->modificationTime)))
+ inode->i_mtime = sbi->s_record_time;
+
+ if (!udf_stamp_to_time(&inode->i_ctime,
+ lets_to_cpu(fe->attrTime)))
+ inode->i_ctime = sbi->s_record_time;

iinfo->i_unique = le64_to_cpu(fe->uniqueID);
iinfo->i_lenEAttr = le32_to_cpu(fe->lengthExtendedAttr);
@@ -1269,11 +1262,21 @@ static void udf_fill_inode(struct inode *inode, struct buffer_head *bh)
inode->i_blocks = le64_to_cpu(efe->logicalBlocksRecorded) <<
(inode->i_sb->s_blocksize_bits - 9);

- udf_fill_inode_time(&inode->i_atime, &efe->accessTime, sbi);
- udf_fill_inode_time(&inode->i_mtime, &efe->modificationTime,
- sbi);
- udf_fill_inode_time(&iinfo->i_crtime, &efe->createTime, sbi);
- udf_fill_inode_time(&inode->i_ctime, &efe->attrTime, sbi);
+ if (!udf_stamp_to_time(&inode->i_atime,
+ lets_to_cpu(efe->accessTime)))
+ inode->i_atime = sbi->s_record_time;
+
+ if (!udf_stamp_to_time(&inode->i_mtime,
+ lets_to_cpu(efe->modificationTime)))
+ inode->i_mtime = sbi->s_record_time;
+
+ if (!udf_stamp_to_time(&iinfo->i_crtime,
+ lets_to_cpu(efe->createTime)))
+ iinfo->i_crtime = sbi->s_record_time;
+
+ if (!udf_stamp_to_time(&inode->i_ctime,
+ lets_to_cpu(efe->attrTime)))
+ inode->i_ctime = sbi->s_record_time;

iinfo->i_unique = le64_to_cpu(efe->uniqueID);
iinfo->i_lenEAttr = le32_to_cpu(efe->lengthExtendedAttr);
diff --git a/fs/udf/super.c b/fs/udf/super.c
index 0dcee12..9f565a9 100644
--- a/fs/udf/super.c
+++ b/fs/udf/super.c
@@ -909,24 +909,19 @@ static int udf_find_fileset(struct super_block *sb,
static void udf_load_pvoldesc(struct super_block *sb, struct buffer_head *bh)
{
struct primaryVolDesc *pvoldesc;
- time_t recording;
- long recording_usec;
struct ustr instr;
struct ustr outstr;

pvoldesc = (struct primaryVolDesc *)bh->b_data;

- if (udf_stamp_to_time(&recording, &recording_usec,
+ if (udf_stamp_to_time(&UDF_SB(sb)->s_record_time,
lets_to_cpu(pvoldesc->recordingDateAndTime))) {
kernel_timestamp ts;
ts = lets_to_cpu(pvoldesc->recordingDateAndTime);
- udf_debug("recording time %ld/%ld, %04u/%02u/%02u"
+ udf_debug("recording time %04u/%02u/%02u"
" %02u:%02u (%x)\n",
- recording, recording_usec,
ts.year, ts.month, ts.day, ts.hour,
ts.minute, ts.typeAndTimezone);
- UDF_SB(sb)->s_record_time.tv_sec = recording;
- UDF_SB(sb)->s_record_time.tv_nsec = recording_usec * 1000;
}

if (!udf_build_ustr(&instr, pvoldesc->volIdent, 32))
diff --git a/fs/udf/udfdecl.h b/fs/udf/udfdecl.h
index 375be1b..508be85 100644
--- a/fs/udf/udfdecl.h
+++ b/fs/udf/udfdecl.h
@@ -204,7 +204,7 @@ extern short_ad *udf_get_fileshortad(uint8_t *, int, uint32_t *, int);
extern uint16_t udf_crc(const uint8_t *, uint32_t, uint16_t);

/* udftime.c */
-extern time_t *udf_stamp_to_time(time_t *, long *, kernel_timestamp);
-extern kernel_timestamp *udf_time_to_stamp(kernel_timestamp *, struct timespec);
+extern struct timespec *udf_stamp_to_time(struct timespec *dest, kernel_timestamp src);
+extern kernel_timestamp *udf_time_to_stamp(kernel_timestamp *dest, struct timespec src);

#endif /* __UDF_DECL_H */
diff --git a/fs/udf/udftime.c b/fs/udf/udftime.c
index ce59573..12fae6c 100644
--- a/fs/udf/udftime.c
+++ b/fs/udf/udftime.c
@@ -85,7 +85,7 @@ extern struct timezone sys_tz;
#define SECS_PER_HOUR (60 * 60)
#define SECS_PER_DAY (SECS_PER_HOUR * 24)

-time_t *udf_stamp_to_time(time_t *dest, long *dest_usec, kernel_timestamp src)
+struct timespec *udf_stamp_to_time(struct timespec *dest, kernel_timestamp src)
{
int yday;
uint8_t type = src.typeAndTimezone >> 12;
@@ -97,23 +97,20 @@ time_t *udf_stamp_to_time(time_t *dest, long *dest_usec, kernel_timestamp src)
offset = (offset >> 4);
if (offset == -2047) /* unspecified offset */
offset = 0;
- } else {
+ } else
offset = 0;
- }

if ((src.year < EPOCH_YEAR) ||
(src.year >= EPOCH_YEAR + MAX_YEAR_SECONDS)) {
- *dest = -1;
- *dest_usec = -1;
return NULL;
}
- *dest = year_seconds[src.year - EPOCH_YEAR];
- *dest -= offset * 60;
+ dest->tv_sec = year_seconds[src.year - EPOCH_YEAR];
+ dest->tv_sec -= offset * 60;

yday = ((__mon_yday[__isleap(src.year)][src.month - 1]) + src.day - 1);
- *dest += (((yday * 24) + src.hour) * 60 + src.minute) * 60 + src.second;
- *dest_usec = src.centiseconds * 10000 +
- src.hundredsOfMicroseconds * 100 + src.microseconds;
+ dest->tv_sec += (((yday * 24) + src.hour) * 60 + src.minute) * 60 + src.second;
+ dest->tv_nsec = 1000 * (src.centiseconds * 10000 +
+ src.hundredsOfMicroseconds * 100 + src.microseconds);
return dest;
}

--
1.5.3.7

2008-02-03 18:38:27

by Marcin Ślusarz

[permalink] [raw]
Subject: [PATCH 4/6] udf: convert udf_stamp_to_time and udf_time_to_stamp to use timestamps

kernel_timestamp type was almost unused - only callers of udf_stamp_to_time
and udf_time_to_stamp used it, so let these functions handle endianness
internally and don't clutter code with conversions

Signed-off-by: Marcin Slusarz <[email protected]>
Cc: Jan Kara <[email protected]>
---
fs/udf/inode.c | 43 ++++++++++++++-----------------------------
fs/udf/super.c | 16 ++++++----------
fs/udf/udfdecl.h | 4 ++--
fs/udf/udftime.c | 22 ++++++++++++----------
4 files changed, 34 insertions(+), 51 deletions(-)

diff --git a/fs/udf/inode.c b/fs/udf/inode.c
index 252efe0..654b504 100644
--- a/fs/udf/inode.c
+++ b/fs/udf/inode.c
@@ -1242,16 +1242,13 @@ static void udf_fill_inode(struct inode *inode, struct buffer_head *bh)
inode->i_blocks = le64_to_cpu(fe->logicalBlocksRecorded) <<
(inode->i_sb->s_blocksize_bits - 9);

- if (!udf_stamp_to_time(&inode->i_atime,
- lets_to_cpu(fe->accessTime)))
+ if (!udf_stamp_to_time(&inode->i_atime, fe->accessTime))
inode->i_atime = sbi->s_record_time;

- if (!udf_stamp_to_time(&inode->i_mtime,
- lets_to_cpu(fe->modificationTime)))
+ if (!udf_stamp_to_time(&inode->i_mtime, fe->modificationTime))
inode->i_mtime = sbi->s_record_time;

- if (!udf_stamp_to_time(&inode->i_ctime,
- lets_to_cpu(fe->attrTime)))
+ if (!udf_stamp_to_time(&inode->i_ctime, fe->attrTime))
inode->i_ctime = sbi->s_record_time;

iinfo->i_unique = le64_to_cpu(fe->uniqueID);
@@ -1262,20 +1259,16 @@ static void udf_fill_inode(struct inode *inode, struct buffer_head *bh)
inode->i_blocks = le64_to_cpu(efe->logicalBlocksRecorded) <<
(inode->i_sb->s_blocksize_bits - 9);

- if (!udf_stamp_to_time(&inode->i_atime,
- lets_to_cpu(efe->accessTime)))
+ if (!udf_stamp_to_time(&inode->i_atime, efe->accessTime))
inode->i_atime = sbi->s_record_time;

- if (!udf_stamp_to_time(&inode->i_mtime,
- lets_to_cpu(efe->modificationTime)))
+ if (!udf_stamp_to_time(&inode->i_mtime, efe->modificationTime))
inode->i_mtime = sbi->s_record_time;

- if (!udf_stamp_to_time(&iinfo->i_crtime,
- lets_to_cpu(efe->createTime)))
+ if (!udf_stamp_to_time(&iinfo->i_crtime, efe->createTime))
iinfo->i_crtime = sbi->s_record_time;

- if (!udf_stamp_to_time(&inode->i_ctime,
- lets_to_cpu(efe->attrTime)))
+ if (!udf_stamp_to_time(&inode->i_ctime, efe->attrTime))
inode->i_ctime = sbi->s_record_time;

iinfo->i_unique = le64_to_cpu(efe->uniqueID);
@@ -1412,7 +1405,6 @@ static int udf_update_inode(struct inode *inode, int do_sync)
uint32_t udfperms;
uint16_t icbflags;
uint16_t crclen;
- kernel_timestamp cpu_time;
int err = 0;
struct udf_sb_info *sbi = UDF_SB(inode->i_sb);
unsigned char blocksize_bits = inode->i_sb->s_blocksize_bits;
@@ -1515,12 +1507,9 @@ static int udf_update_inode(struct inode *inode, int do_sync)
(inode->i_blocks + (1 << (blocksize_bits - 9)) - 1) >>
(blocksize_bits - 9));

- if (udf_time_to_stamp(&cpu_time, inode->i_atime))
- fe->accessTime = cpu_to_lets(cpu_time);
- if (udf_time_to_stamp(&cpu_time, inode->i_mtime))
- fe->modificationTime = cpu_to_lets(cpu_time);
- if (udf_time_to_stamp(&cpu_time, inode->i_ctime))
- fe->attrTime = cpu_to_lets(cpu_time);
+ udf_time_to_stamp(&fe->accessTime, inode->i_atime);
+ udf_time_to_stamp(&fe->modificationTime, inode->i_mtime);
+ udf_time_to_stamp(&fe->attrTime, inode->i_ctime);
memset(&(fe->impIdent), 0, sizeof(regid));
strcpy(fe->impIdent.ident, UDF_ID_DEVELOPER);
fe->impIdent.identSuffix[0] = UDF_OS_CLASS_UNIX;
@@ -1555,14 +1544,10 @@ static int udf_update_inode(struct inode *inode, int do_sync)
iinfo->i_crtime.tv_nsec > inode->i_ctime.tv_nsec))
iinfo->i_crtime = inode->i_ctime;

- if (udf_time_to_stamp(&cpu_time, inode->i_atime))
- efe->accessTime = cpu_to_lets(cpu_time);
- if (udf_time_to_stamp(&cpu_time, inode->i_mtime))
- efe->modificationTime = cpu_to_lets(cpu_time);
- if (udf_time_to_stamp(&cpu_time, iinfo->i_crtime))
- efe->createTime = cpu_to_lets(cpu_time);
- if (udf_time_to_stamp(&cpu_time, inode->i_ctime))
- efe->attrTime = cpu_to_lets(cpu_time);
+ udf_time_to_stamp(&efe->accessTime, inode->i_atime);
+ udf_time_to_stamp(&efe->modificationTime, inode->i_mtime);
+ udf_time_to_stamp(&efe->createTime, iinfo->i_crtime);
+ udf_time_to_stamp(&efe->attrTime, inode->i_ctime);

memset(&(efe->impIdent), 0, sizeof(regid));
strcpy(efe->impIdent.ident, UDF_ID_DEVELOPER);
diff --git a/fs/udf/super.c b/fs/udf/super.c
index 9f565a9..8a98a2e 100644
--- a/fs/udf/super.c
+++ b/fs/udf/super.c
@@ -915,7 +915,7 @@ static void udf_load_pvoldesc(struct super_block *sb, struct buffer_head *bh)
pvoldesc = (struct primaryVolDesc *)bh->b_data;

if (udf_stamp_to_time(&UDF_SB(sb)->s_record_time,
- lets_to_cpu(pvoldesc->recordingDateAndTime))) {
+ pvoldesc->recordingDateAndTime)) {
kernel_timestamp ts;
ts = lets_to_cpu(pvoldesc->recordingDateAndTime);
udf_debug("recording time %04u/%02u/%02u"
@@ -1561,7 +1561,6 @@ static void udf_open_lvid(struct super_block *sb)
struct udf_sb_info *sbi = UDF_SB(sb);
struct buffer_head *bh = sbi->s_lvid_bh;
if (bh) {
- kernel_timestamp cpu_time;
struct logicalVolIntegrityDesc *lvid =
(struct logicalVolIntegrityDesc *)bh->b_data;
struct logicalVolIntegrityDescImpUse *lvidiu =
@@ -1569,8 +1568,7 @@ static void udf_open_lvid(struct super_block *sb)

lvidiu->impIdent.identSuffix[0] = UDF_OS_CLASS_UNIX;
lvidiu->impIdent.identSuffix[1] = UDF_OS_ID_LINUX;
- if (udf_time_to_stamp(&cpu_time, CURRENT_TIME))
- lvid->recordingDateAndTime = cpu_to_lets(cpu_time);
+ udf_time_to_stamp(&lvid->recordingDateAndTime, CURRENT_TIME);
lvid->integrityType = LVID_INTEGRITY_TYPE_OPEN;

lvid->descTag.descCRC = cpu_to_le16(
@@ -1585,7 +1583,6 @@ static void udf_open_lvid(struct super_block *sb)

static void udf_close_lvid(struct super_block *sb)
{
- kernel_timestamp cpu_time;
struct udf_sb_info *sbi = UDF_SB(sb);
struct buffer_head *bh = sbi->s_lvid_bh;
struct logicalVolIntegrityDesc *lvid;
@@ -1600,8 +1597,7 @@ static void udf_close_lvid(struct super_block *sb)
udf_sb_lvidiu(sbi);
lvidiu->impIdent.identSuffix[0] = UDF_OS_CLASS_UNIX;
lvidiu->impIdent.identSuffix[1] = UDF_OS_ID_LINUX;
- if (udf_time_to_stamp(&cpu_time, CURRENT_TIME))
- lvid->recordingDateAndTime = cpu_to_lets(cpu_time);
+ udf_time_to_stamp(&lvid->recordingDateAndTime, CURRENT_TIME);
if (UDF_MAX_WRITE_VERSION > le16_to_cpu(lvidiu->maxUDFWriteRev))
lvidiu->maxUDFWriteRev =
cpu_to_le16(UDF_MAX_WRITE_VERSION);
@@ -1786,12 +1782,12 @@ static int udf_fill_super(struct super_block *sb, void *options, int silent)
}

if (!silent) {
- kernel_timestamp ts;
+ timestamp ts;
udf_time_to_stamp(&ts, sbi->s_record_time);
udf_info("UDF: Mounting volume '%s', "
"timestamp %04u/%02u/%02u %02u:%02u (%x)\n",
- sbi->s_volume_ident, ts.year, ts.month, ts.day,
- ts.hour, ts.minute, ts.typeAndTimezone);
+ sbi->s_volume_ident, le16_to_cpu(ts.year), ts.month, ts.day,
+ ts.hour, ts.minute, le16_to_cpu(ts.typeAndTimezone));
}
if (!(sb->s_flags & MS_RDONLY))
udf_open_lvid(sb);
diff --git a/fs/udf/udfdecl.h b/fs/udf/udfdecl.h
index 508be85..2dd04bb 100644
--- a/fs/udf/udfdecl.h
+++ b/fs/udf/udfdecl.h
@@ -204,7 +204,7 @@ extern short_ad *udf_get_fileshortad(uint8_t *, int, uint32_t *, int);
extern uint16_t udf_crc(const uint8_t *, uint32_t, uint16_t);

/* udftime.c */
-extern struct timespec *udf_stamp_to_time(struct timespec *dest, kernel_timestamp src);
-extern kernel_timestamp *udf_time_to_stamp(kernel_timestamp *dest, struct timespec src);
+extern struct timespec *udf_stamp_to_time(struct timespec *dest, timestamp src);
+extern timestamp *udf_time_to_stamp(timestamp *dest, struct timespec src);

#endif /* __UDF_DECL_H */
diff --git a/fs/udf/udftime.c b/fs/udf/udftime.c
index 12fae6c..d125bd9 100644
--- a/fs/udf/udftime.c
+++ b/fs/udf/udftime.c
@@ -85,14 +85,16 @@ extern struct timezone sys_tz;
#define SECS_PER_HOUR (60 * 60)
#define SECS_PER_DAY (SECS_PER_HOUR * 24)

-struct timespec *udf_stamp_to_time(struct timespec *dest, kernel_timestamp src)
+struct timespec *udf_stamp_to_time(struct timespec *dest, timestamp src)
{
int yday;
- uint8_t type = src.typeAndTimezone >> 12;
+ u16 typeAndTimezone = le16_to_cpu(src.typeAndTimezone);
+ u16 year = le16_to_cpu(src.year);
+ uint8_t type = typeAndTimezone >> 12;
int16_t offset;

if (type == 1) {
- offset = src.typeAndTimezone << 4;
+ offset = typeAndTimezone << 4;
/* sign extent offset */
offset = (offset >> 4);
if (offset == -2047) /* unspecified offset */
@@ -100,21 +102,21 @@ struct timespec *udf_stamp_to_time(struct timespec *dest, kernel_timestamp src)
} else
offset = 0;

- if ((src.year < EPOCH_YEAR) ||
- (src.year >= EPOCH_YEAR + MAX_YEAR_SECONDS)) {
+ if ((year < EPOCH_YEAR) ||
+ (year >= EPOCH_YEAR + MAX_YEAR_SECONDS)) {
return NULL;
}
- dest->tv_sec = year_seconds[src.year - EPOCH_YEAR];
+ dest->tv_sec = year_seconds[year - EPOCH_YEAR];
dest->tv_sec -= offset * 60;

- yday = ((__mon_yday[__isleap(src.year)][src.month - 1]) + src.day - 1);
+ yday = ((__mon_yday[__isleap(year)][src.month - 1]) + src.day - 1);
dest->tv_sec += (((yday * 24) + src.hour) * 60 + src.minute) * 60 + src.second;
dest->tv_nsec = 1000 * (src.centiseconds * 10000 +
src.hundredsOfMicroseconds * 100 + src.microseconds);
return dest;
}

-kernel_timestamp *udf_time_to_stamp(kernel_timestamp *dest, struct timespec ts)
+timestamp *udf_time_to_stamp(timestamp *dest, struct timespec ts)
{
long int days, rem, y;
const unsigned short int *ip;
@@ -125,7 +127,7 @@ kernel_timestamp *udf_time_to_stamp(kernel_timestamp *dest, struct timespec ts)
if (!dest)
return NULL;

- dest->typeAndTimezone = 0x1000 | (offset & 0x0FFF);
+ dest->typeAndTimezone = cpu_to_le16(0x1000 | (offset & 0x0FFF));

ts.tv_sec += offset * 60;
days = ts.tv_sec / SECS_PER_DAY;
@@ -148,7 +150,7 @@ kernel_timestamp *udf_time_to_stamp(kernel_timestamp *dest, struct timespec ts)
- LEAPS_THRU_END_OF(y - 1));
y = yg;
}
- dest->year = y;
+ dest->year = cpu_to_le16(y);
ip = __mon_yday[__isleap(y)];
for (y = 11; days < (long int)ip[y]; --y)
continue;
--
1.5.3.7

2008-02-03 18:38:46

by Marcin Ślusarz

[permalink] [raw]
Subject: [PATCH 5/6] udf: remove unneeded kernel_timestamp type

remove now unneeded kernel_timestamp type with conversion functions

Signed-off-by: Marcin Slusarz <[email protected]>
Cc: Jan Kara <[email protected]>
---
fs/udf/ecma_167.h | 13 -------------
fs/udf/super.c | 9 +++++----
fs/udf/udfend.h | 22 ----------------------
3 files changed, 5 insertions(+), 39 deletions(-)

diff --git a/fs/udf/ecma_167.h b/fs/udf/ecma_167.h
index 5638771..a0974df 100644
--- a/fs/udf/ecma_167.h
+++ b/fs/udf/ecma_167.h
@@ -70,19 +70,6 @@ typedef struct {
uint8_t microseconds;
} __attribute__ ((packed)) timestamp;

-typedef struct {
- uint16_t typeAndTimezone;
- int16_t year;
- uint8_t month;
- uint8_t day;
- uint8_t hour;
- uint8_t minute;
- uint8_t second;
- uint8_t centiseconds;
- uint8_t hundredsOfMicroseconds;
- uint8_t microseconds;
-} __attribute__ ((packed)) kernel_timestamp;
-
/* Type and Time Zone (ECMA 167r3 1/7.3.1) */
#define TIMESTAMP_TYPE_MASK 0xF000
#define TIMESTAMP_TYPE_CUT 0x0000
diff --git a/fs/udf/super.c b/fs/udf/super.c
index 8a98a2e..3a7faad 100644
--- a/fs/udf/super.c
+++ b/fs/udf/super.c
@@ -916,12 +916,13 @@ static void udf_load_pvoldesc(struct super_block *sb, struct buffer_head *bh)

if (udf_stamp_to_time(&UDF_SB(sb)->s_record_time,
pvoldesc->recordingDateAndTime)) {
- kernel_timestamp ts;
- ts = lets_to_cpu(pvoldesc->recordingDateAndTime);
+#ifdef UDFFS_DEBUG
+ timestamp *ts = &pvoldesc->recordingDateAndTime;
udf_debug("recording time %04u/%02u/%02u"
" %02u:%02u (%x)\n",
- ts.year, ts.month, ts.day, ts.hour,
- ts.minute, ts.typeAndTimezone);
+ le16_to_cpu(ts->year), ts->month, ts->day, ts->hour,
+ ts->minute, le16_to_cpu(ts->typeAndTimezone));
+#endif
}

if (!udf_build_ustr(&instr, pvoldesc->volIdent, 32))
diff --git a/fs/udf/udfend.h b/fs/udf/udfend.h
index c4bd120..489f52f 100644
--- a/fs/udf/udfend.h
+++ b/fs/udf/udfend.h
@@ -24,17 +24,6 @@ static inline lb_addr cpu_to_lelb(kernel_lb_addr in)
return out;
}

-static inline kernel_timestamp lets_to_cpu(timestamp in)
-{
- kernel_timestamp out;
-
- memcpy(&out, &in, sizeof(timestamp));
- out.typeAndTimezone = le16_to_cpu(in.typeAndTimezone);
- out.year = le16_to_cpu(in.year);
-
- return out;
-}
-
static inline short_ad lesa_to_cpu(short_ad in)
{
short_ad out;
@@ -85,15 +74,4 @@ static inline kernel_extent_ad leea_to_cpu(extent_ad in)
return out;
}

-static inline timestamp cpu_to_lets(kernel_timestamp in)
-{
- timestamp out;
-
- memcpy(&out, &in, sizeof(timestamp));
- out.typeAndTimezone = cpu_to_le16(in.typeAndTimezone);
- out.year = cpu_to_le16(in.year);
-
- return out;
-}
-
#endif /* __UDF_ENDIAN_H */
--
1.5.3.7

2008-02-03 18:44:24

by Marcin Ślusarz

[permalink] [raw]
Subject: [PATCH 6/6] udf: super.c reorganization

reorganize few code blocks in super.c which
were needlessly indented (and hard to read):

so change from:
rettype fun()
{
init;
if (sth) {
long block of code;
}
}

to:
rettype fun()
{
init;
if (!sth)
return;
long block of code;
}

or

from:
rettype fun2()
{
init;
while (sth) {
init2();
if (sth2) {
long block of code;
}
}
}

to:
rettype fun2()
{
init;
while (sth) {
init2();
if (!sth2)
continue;
long block of code;
}
}

Signed-off-by: Marcin Slusarz <[email protected]>
Cc: Jan Kara <[email protected]>
---
fs/udf/super.c | 519 ++++++++++++++++++++++++++++----------------------------
1 files changed, 259 insertions(+), 260 deletions(-)

diff --git a/fs/udf/super.c b/fs/udf/super.c
index 3a7faad..b622d4c 100644
--- a/fs/udf/super.c
+++ b/fs/udf/super.c
@@ -798,18 +798,18 @@ static void udf_find_anchor(struct super_block *sb)
}

for (i = 0; i < ARRAY_SIZE(sbi->s_anchor); i++) {
- if (sbi->s_anchor[i]) {
- bh = udf_read_tagged(sb, sbi->s_anchor[i],
- sbi->s_anchor[i], &ident);
- if (!bh)
+ if (!sbi->s_anchor[i])
+ continue;
+ bh = udf_read_tagged(sb, sbi->s_anchor[i],
+ sbi->s_anchor[i], &ident);
+ if (!bh)
+ sbi->s_anchor[i] = 0;
+ else {
+ brelse(bh);
+ if ((ident != TAG_IDENT_AVDP) &&
+ (i || (ident != TAG_IDENT_FE &&
+ ident != TAG_IDENT_EFE)))
sbi->s_anchor[i] = 0;
- else {
- brelse(bh);
- if ((ident != TAG_IDENT_AVDP) &&
- (i || (ident != TAG_IDENT_FE &&
- ident != TAG_IDENT_EFE)))
- sbi->s_anchor[i] = 0;
- }
}
}

@@ -1001,108 +1001,108 @@ static int udf_load_partdesc(struct super_block *sb, struct buffer_head *bh)
sbi = UDF_SB(sb);

for (i = 0; i < sbi->s_partitions; i++) {
+ struct partitionHeaderDesc *phd;
+
map = &sbi->s_partmaps[i];
udf_debug("Searching map: (%d == %d)\n",
map->s_partition_num,
le16_to_cpu(p->partitionNumber));
- if (map->s_partition_num ==
- le16_to_cpu(p->partitionNumber)) {
- map->s_partition_len =
- le32_to_cpu(p->partitionLength); /* blocks */
- map->s_partition_root =
- le32_to_cpu(p->partitionStartingLocation);
- if (p->accessType ==
- cpu_to_le32(PD_ACCESS_TYPE_READ_ONLY))
- map->s_partition_flags |=
- UDF_PART_FLAG_READ_ONLY;
- if (p->accessType ==
- cpu_to_le32(PD_ACCESS_TYPE_WRITE_ONCE))
- map->s_partition_flags |=
- UDF_PART_FLAG_WRITE_ONCE;
- if (p->accessType ==
- cpu_to_le32(PD_ACCESS_TYPE_REWRITABLE))
+ if (map->s_partition_num !=
+ le16_to_cpu(p->partitionNumber))
+ continue;
+
+ map->s_partition_len =
+ le32_to_cpu(p->partitionLength); /* blocks */
+ map->s_partition_root =
+ le32_to_cpu(p->partitionStartingLocation);
+ if (p->accessType == cpu_to_le32(PD_ACCESS_TYPE_READ_ONLY))
+ map->s_partition_flags |= UDF_PART_FLAG_READ_ONLY;
+ if (p->accessType == cpu_to_le32(PD_ACCESS_TYPE_WRITE_ONCE))
+ map->s_partition_flags |= UDF_PART_FLAG_WRITE_ONCE;
+ if (p->accessType == cpu_to_le32(PD_ACCESS_TYPE_REWRITABLE))
+ map->s_partition_flags |= UDF_PART_FLAG_REWRITABLE;
+ if (p->accessType == cpu_to_le32(PD_ACCESS_TYPE_OVERWRITABLE))
+ map->s_partition_flags |= UDF_PART_FLAG_OVERWRITABLE;
+
+ if (strcmp(p->partitionContents.ident,
+ PD_PARTITION_CONTENTS_NSR02) &&
+ strcmp(p->partitionContents.ident,
+ PD_PARTITION_CONTENTS_NSR03))
+ break;
+
+ phd = (struct partitionHeaderDesc *)
+ (p->partitionContentsUse);
+ if (phd->unallocSpaceTable.extLength) {
+ kernel_lb_addr loc = {
+ .logicalBlockNum = le32_to_cpu(
+ phd->unallocSpaceTable.extPosition),
+ .partitionReferenceNum = i,
+ };
+
+ map->s_uspace.s_table =
+ udf_iget(sb, loc);
+ if (!map->s_uspace.s_table) {
+ udf_debug("cannot load unallocSpaceTable "
+ "(part %d)\n", i);
+ return 1;
+ }
+ map->s_partition_flags |=
+ UDF_PART_FLAG_UNALLOC_TABLE;
+ udf_debug("unallocSpaceTable (part %d) @ %ld\n",
+ i, map->s_uspace.s_table->i_ino);
+ }
+ if (phd->unallocSpaceBitmap.extLength) {
+ struct udf_bitmap *bitmap =
+ udf_sb_alloc_bitmap(sb, i);
+ map->s_uspace.s_bitmap = bitmap;
+ if (bitmap != NULL) {
+ bitmap->s_extLength = le32_to_cpu(
+ phd->unallocSpaceBitmap.extLength);
+ bitmap->s_extPosition = le32_to_cpu(
+ phd->unallocSpaceBitmap.extPosition);
map->s_partition_flags |=
- UDF_PART_FLAG_REWRITABLE;
- if (p->accessType ==
- cpu_to_le32(PD_ACCESS_TYPE_OVERWRITABLE))
+ UDF_PART_FLAG_UNALLOC_BITMAP;
+ udf_debug("unallocSpaceBitmap (part %d) @ %d\n",
+ i, bitmap->s_extPosition);
+ }
+ }
+ if (phd->partitionIntegrityTable.extLength)
+ udf_debug("partitionIntegrityTable (part %d)\n", i);
+ if (phd->freedSpaceTable.extLength) {
+ kernel_lb_addr loc = {
+ .logicalBlockNum = le32_to_cpu(
+ phd->freedSpaceTable.extPosition),
+ .partitionReferenceNum = i,
+ };
+
+ map->s_fspace.s_table =
+ udf_iget(sb, loc);
+ if (!map->s_fspace.s_table) {
+ udf_debug("cannot load freedSpaceTable "
+ "(part %d)\n", i);
+ return 1;
+ }
+ map->s_partition_flags |=
+ UDF_PART_FLAG_FREED_TABLE;
+ udf_debug("freedSpaceTable (part %d) @ %ld\n",
+ i, map->s_fspace.s_table->i_ino);
+ }
+ if (phd->freedSpaceBitmap.extLength) {
+ struct udf_bitmap *bitmap =
+ udf_sb_alloc_bitmap(sb, i);
+ map->s_fspace.s_bitmap = bitmap;
+ if (bitmap != NULL) {
+ bitmap->s_extLength = le32_to_cpu(
+ phd->freedSpaceBitmap.extLength);
+ bitmap->s_extPosition = le32_to_cpu(
+ phd->freedSpaceBitmap.extPosition);
map->s_partition_flags |=
- UDF_PART_FLAG_OVERWRITABLE;
-
- if (!strcmp(p->partitionContents.ident,
- PD_PARTITION_CONTENTS_NSR02) ||
- !strcmp(p->partitionContents.ident,
- PD_PARTITION_CONTENTS_NSR03)) {
- struct partitionHeaderDesc *phd;
-
- phd = (struct partitionHeaderDesc *)
- (p->partitionContentsUse);
- if (phd->unallocSpaceTable.extLength) {
- kernel_lb_addr loc = {
- .logicalBlockNum = le32_to_cpu(phd->unallocSpaceTable.extPosition),
- .partitionReferenceNum = i,
- };
-
- map->s_uspace.s_table =
- udf_iget(sb, loc);
- if (!map->s_uspace.s_table) {
- udf_debug("cannot load unallocSpaceTable (part %d)\n", i);
- return 1;
- }
- map->s_partition_flags |=
- UDF_PART_FLAG_UNALLOC_TABLE;
- udf_debug("unallocSpaceTable (part %d) @ %ld\n",
- i, map->s_uspace.s_table->i_ino);
- }
- if (phd->unallocSpaceBitmap.extLength) {
- struct udf_bitmap *bitmap =
- udf_sb_alloc_bitmap(sb, i);
- map->s_uspace.s_bitmap = bitmap;
- if (bitmap != NULL) {
- bitmap->s_extLength =
- le32_to_cpu(phd->unallocSpaceBitmap.extLength);
- bitmap->s_extPosition =
- le32_to_cpu(phd->unallocSpaceBitmap.extPosition);
- map->s_partition_flags |= UDF_PART_FLAG_UNALLOC_BITMAP;
- udf_debug("unallocSpaceBitmap (part %d) @ %d\n",
- i, bitmap->s_extPosition);
- }
- }
- if (phd->partitionIntegrityTable.extLength)
- udf_debug("partitionIntegrityTable (part %d)\n", i);
- if (phd->freedSpaceTable.extLength) {
- kernel_lb_addr loc = {
- .logicalBlockNum = le32_to_cpu(phd->freedSpaceTable.extPosition),
- .partitionReferenceNum = i,
- };
-
- map->s_fspace.s_table =
- udf_iget(sb, loc);
- if (!map->s_fspace.s_table) {
- udf_debug("cannot load freedSpaceTable (part %d)\n", i);
- return 1;
- }
- map->s_partition_flags |=
- UDF_PART_FLAG_FREED_TABLE;
- udf_debug("freedSpaceTable (part %d) @ %ld\n",
- i, map->s_fspace.s_table->i_ino);
- }
- if (phd->freedSpaceBitmap.extLength) {
- struct udf_bitmap *bitmap =
- udf_sb_alloc_bitmap(sb, i);
- map->s_fspace.s_bitmap = bitmap;
- if (bitmap != NULL) {
- bitmap->s_extLength =
- le32_to_cpu(phd->freedSpaceBitmap.extLength);
- bitmap->s_extPosition =
- le32_to_cpu(phd->freedSpaceBitmap.extPosition);
- map->s_partition_flags |= UDF_PART_FLAG_FREED_BITMAP;
- udf_debug("freedSpaceBitmap (part %d) @ %d\n",
- i, bitmap->s_extPosition);
- }
- }
+ UDF_PART_FLAG_FREED_BITMAP;
+ udf_debug("freedSpaceBitmap (part %d) @ %d\n",
+ i, bitmap->s_extPosition);
}
- break;
}
+ break;
}
if (i == sbi->s_partitions)
udf_debug("Partition (%d) not found in partition map\n",
@@ -1187,19 +1187,17 @@ static int udf_load_logicalvol(struct super_block *sb, struct buffer_head *bh,
map->s_type_specific.s_sparing.
s_spar_map[j] = bh2;

- if (bh2 != NULL) {
- st = (struct sparingTable *)
- bh2->b_data;
- if (ident != 0 || strncmp(
- st->sparingIdent.ident,
- UDF_ID_SPARING,
- strlen(UDF_ID_SPARING))) {
- brelse(bh2);
- map->s_type_specific.
- s_sparing.
- s_spar_map[j] =
- NULL;
- }
+ if (bh2 == NULL)
+ continue;
+
+ st = (struct sparingTable *)bh2->b_data;
+ if (ident != 0 || strncmp(
+ st->sparingIdent.ident,
+ UDF_ID_SPARING,
+ strlen(UDF_ID_SPARING))) {
+ brelse(bh2);
+ map->s_type_specific.s_sparing.
+ s_spar_map[j] = NULL;
}
}
map->s_partition_func = udf_get_pblock_spar15;
@@ -1364,40 +1362,40 @@ static int udf_process_sequence(struct super_block *sb, long block,
brelse(bh);
}
for (i = 0; i < VDS_POS_LENGTH; i++) {
- if (vds[i].block) {
- bh = udf_read_tagged(sb, vds[i].block, vds[i].block,
- &ident);
-
- if (i == VDS_POS_PRIMARY_VOL_DESC) {
- udf_load_pvoldesc(sb, bh);
- } else if (i == VDS_POS_LOGICAL_VOL_DESC) {
- if (udf_load_logicalvol(sb, bh, fileset)) {
- brelse(bh);
- return 1;
- }
- } else if (i == VDS_POS_PARTITION_DESC) {
- struct buffer_head *bh2 = NULL;
- if (udf_load_partdesc(sb, bh)) {
- brelse(bh);
- return 1;
- }
- for (j = vds[i].block + 1;
- j < vds[VDS_POS_TERMINATING_DESC].block;
- j++) {
- bh2 = udf_read_tagged(sb, j, j, &ident);
- gd = (struct generic_desc *)bh2->b_data;
- if (ident == TAG_IDENT_PD)
- if (udf_load_partdesc(sb,
- bh2)) {
- brelse(bh);
- brelse(bh2);
- return 1;
- }
- brelse(bh2);
- }
+ if (!vds[i].block)
+ continue;
+
+ bh = udf_read_tagged(sb, vds[i].block, vds[i].block,
+ &ident);
+
+ if (i == VDS_POS_PRIMARY_VOL_DESC)
+ udf_load_pvoldesc(sb, bh);
+ else if (i == VDS_POS_LOGICAL_VOL_DESC) {
+ if (udf_load_logicalvol(sb, bh, fileset)) {
+ brelse(bh);
+ return 1;
+ }
+ } else if (i == VDS_POS_PARTITION_DESC) {
+ struct buffer_head *bh2 = NULL;
+ if (udf_load_partdesc(sb, bh)) {
+ brelse(bh);
+ return 1;
+ }
+ for (j = vds[i].block + 1;
+ j < vds[VDS_POS_TERMINATING_DESC].block;
+ j++) {
+ bh2 = udf_read_tagged(sb, j, j, &ident);
+ gd = (struct generic_desc *)bh2->b_data;
+ if (ident == TAG_IDENT_PD)
+ if (udf_load_partdesc(sb, bh2)) {
+ brelse(bh);
+ brelse(bh2);
+ return 1;
+ }
+ brelse(bh2);
}
- brelse(bh);
}
+ brelse(bh);
}

return 0;
@@ -1409,6 +1407,7 @@ static int udf_process_sequence(struct super_block *sb, long block,
static int udf_check_valid(struct super_block *sb, int novrs, int silent)
{
long block;
+ struct udf_sb_info *sbi;

if (novrs) {
udf_debug("Validity check skipped because of novrs option\n");
@@ -1416,18 +1415,16 @@ static int udf_check_valid(struct super_block *sb, int novrs, int silent)
}
/* Check that it is NSR02 compliant */
/* Process any "CD-ROM Volume Descriptor Set" (ECMA 167 2/8.3.1) */
- else {
- block = udf_vrs(sb, silent);
- if (block == -1) {
- struct udf_sb_info *sbi = UDF_SB(sb);
- udf_debug("Failed to read byte 32768. Assuming open "
- "disc. Skipping validity check\n");
- if (!sbi->s_last_block)
- sbi->s_last_block = udf_get_last_block(sb);
- return 0;
- } else
- return !block;
- }
+ block = udf_vrs(sb, silent);
+ if (block != -1)
+ return !block;
+
+ sbi = UDF_SB(sb);
+ udf_debug("Failed to read byte 32768. Assuming open "
+ "disc. Skipping validity check\n");
+ if (!sbi->s_last_block)
+ sbi->s_last_block = udf_get_last_block(sb);
+ return 0;
}

static int udf_load_partition(struct super_block *sb, kernel_lb_addr *fileset)
@@ -1446,6 +1443,7 @@ static int udf_load_partition(struct super_block *sb, kernel_lb_addr *fileset)
for (i = 0; i < ARRAY_SIZE(sbi->s_anchor); i++) {
if (!sbi->s_anchor[i])
continue;
+
bh = udf_read_tagged(sb, sbi->s_anchor[i], sbi->s_anchor[i],
&ident);
if (!bh)
@@ -1487,72 +1485,73 @@ static int udf_load_partition(struct super_block *sb, kernel_lb_addr *fileset)
for (i = 0; i < sbi->s_partitions; i++) {
kernel_lb_addr uninitialized_var(ino);
struct udf_part_map *map = &sbi->s_partmaps[i];
- switch (map->s_partition_type) {
- case UDF_VIRTUAL_MAP15:
- case UDF_VIRTUAL_MAP20:
- if (!sbi->s_last_block) {
- sbi->s_last_block = udf_get_last_block(sb);
- udf_find_anchor(sb);
- }

- if (!sbi->s_last_block) {
- udf_debug("Unable to determine Lastblock (For "
- "Virtual Partition)\n");
- return 1;
- }
+ if (map->s_partition_type != UDF_VIRTUAL_MAP15 &&
+ map->s_partition_type != UDF_VIRTUAL_MAP20)
+ continue;

- for (j = 0; j < sbi->s_partitions; j++) {
- struct udf_part_map *map2 = &sbi->s_partmaps[j];
- if (j != i &&
- map->s_volumeseqnum ==
- map2->s_volumeseqnum &&
- map->s_partition_num ==
- map2->s_partition_num) {
- ino.partitionReferenceNum = j;
- ino.logicalBlockNum =
- sbi->s_last_block -
- map2->s_partition_root;
- break;
- }
+ if (!sbi->s_last_block) {
+ sbi->s_last_block = udf_get_last_block(sb);
+ udf_find_anchor(sb);
+ }
+
+ if (!sbi->s_last_block) {
+ udf_debug("Unable to determine Lastblock (For "
+ "Virtual Partition)\n");
+ return 1;
+ }
+
+ for (j = 0; j < sbi->s_partitions; j++) {
+ struct udf_part_map *map2 = &sbi->s_partmaps[j];
+ if (j != i &&
+ map->s_volumeseqnum ==
+ map2->s_volumeseqnum &&
+ map->s_partition_num ==
+ map2->s_partition_num) {
+ ino.partitionReferenceNum = j;
+ ino.logicalBlockNum =
+ sbi->s_last_block -
+ map2->s_partition_root;
+ break;
}
+ }

- if (j == sbi->s_partitions)
- return 1;
+ if (j == sbi->s_partitions)
+ return 1;

- sbi->s_vat_inode = udf_iget(sb, ino);
- if (!sbi->s_vat_inode)
- return 1;
+ sbi->s_vat_inode = udf_iget(sb, ino);
+ if (!sbi->s_vat_inode)
+ return 1;

- if (map->s_partition_type == UDF_VIRTUAL_MAP15) {
- map->s_type_specific.s_virtual.s_start_offset =
- udf_ext0_offset(sbi->s_vat_inode);
- map->s_type_specific.s_virtual.s_num_entries =
- (sbi->s_vat_inode->i_size - 36) >> 2;
- } else if (map->s_partition_type == UDF_VIRTUAL_MAP20) {
- uint32_t pos;
- struct virtualAllocationTable20 *vat20;
-
- pos = udf_block_map(sbi->s_vat_inode, 0);
- bh = sb_bread(sb, pos);
- if (!bh)
- return 1;
- vat20 = (struct virtualAllocationTable20 *)
- bh->b_data +
- udf_ext0_offset(sbi->s_vat_inode);
- map->s_type_specific.s_virtual.s_start_offset =
- le16_to_cpu(vat20->lengthHeader) +
- udf_ext0_offset(sbi->s_vat_inode);
- map->s_type_specific.s_virtual.s_num_entries =
- (sbi->s_vat_inode->i_size -
- map->s_type_specific.s_virtual.
- s_start_offset) >> 2;
- brelse(bh);
- }
- map->s_partition_root = udf_get_pblock(sb, 0, i, 0);
- map->s_partition_len =
- sbi->s_partmaps[ino.partitionReferenceNum].
- s_partition_len;
+ if (map->s_partition_type == UDF_VIRTUAL_MAP15) {
+ map->s_type_specific.s_virtual.s_start_offset =
+ udf_ext0_offset(sbi->s_vat_inode);
+ map->s_type_specific.s_virtual.s_num_entries =
+ (sbi->s_vat_inode->i_size - 36) >> 2;
+ } else if (map->s_partition_type == UDF_VIRTUAL_MAP20) {
+ uint32_t pos;
+ struct virtualAllocationTable20 *vat20;
+
+ pos = udf_block_map(sbi->s_vat_inode, 0);
+ bh = sb_bread(sb, pos);
+ if (!bh)
+ return 1;
+ vat20 = (struct virtualAllocationTable20 *)
+ bh->b_data +
+ udf_ext0_offset(sbi->s_vat_inode);
+ map->s_type_specific.s_virtual.s_start_offset =
+ le16_to_cpu(vat20->lengthHeader) +
+ udf_ext0_offset(sbi->s_vat_inode);
+ map->s_type_specific.s_virtual.s_num_entries =
+ (sbi->s_vat_inode->i_size -
+ map->s_type_specific.s_virtual.
+ s_start_offset) >> 2;
+ brelse(bh);
}
+ map->s_partition_root = udf_get_pblock(sb, 0, i, 0);
+ map->s_partition_len =
+ sbi->s_partmaps[ino.partitionReferenceNum].
+ s_partition_len;
}
return 0;
}
@@ -1561,25 +1560,25 @@ static void udf_open_lvid(struct super_block *sb)
{
struct udf_sb_info *sbi = UDF_SB(sb);
struct buffer_head *bh = sbi->s_lvid_bh;
- if (bh) {
- struct logicalVolIntegrityDesc *lvid =
- (struct logicalVolIntegrityDesc *)bh->b_data;
- struct logicalVolIntegrityDescImpUse *lvidiu =
- udf_sb_lvidiu(sbi);
+ struct logicalVolIntegrityDesc *lvid;
+ struct logicalVolIntegrityDescImpUse *lvidiu;
+ if (!bh)
+ return;

- lvidiu->impIdent.identSuffix[0] = UDF_OS_CLASS_UNIX;
- lvidiu->impIdent.identSuffix[1] = UDF_OS_ID_LINUX;
- udf_time_to_stamp(&lvid->recordingDateAndTime, CURRENT_TIME);
- lvid->integrityType = LVID_INTEGRITY_TYPE_OPEN;
+ lvid = (struct logicalVolIntegrityDesc *)bh->b_data;
+ lvidiu = udf_sb_lvidiu(sbi);

- lvid->descTag.descCRC = cpu_to_le16(
- udf_crc((char *)lvid + sizeof(tag),
- le16_to_cpu(lvid->descTag.descCRCLength),
- 0));
+ lvidiu->impIdent.identSuffix[0] = UDF_OS_CLASS_UNIX;
+ lvidiu->impIdent.identSuffix[1] = UDF_OS_ID_LINUX;
+ udf_time_to_stamp(&lvid->recordingDateAndTime, CURRENT_TIME);
+ lvid->integrityType = LVID_INTEGRITY_TYPE_OPEN;

- lvid->descTag.tagChecksum = udf_tag_checksum(&lvid->descTag);
- mark_buffer_dirty(bh);
- }
+ lvid->descTag.descCRC = cpu_to_le16(
+ udf_crc((char *)lvid + sizeof(tag),
+ le16_to_cpu(lvid->descTag.descCRCLength), 0));
+
+ lvid->descTag.tagChecksum = udf_tag_checksum(&lvid->descTag);
+ mark_buffer_dirty(bh);
}

static void udf_close_lvid(struct super_block *sb)
@@ -1587,35 +1586,35 @@ static void udf_close_lvid(struct super_block *sb)
struct udf_sb_info *sbi = UDF_SB(sb);
struct buffer_head *bh = sbi->s_lvid_bh;
struct logicalVolIntegrityDesc *lvid;
+ struct logicalVolIntegrityDescImpUse *lvidiu;

if (!bh)
return;

lvid = (struct logicalVolIntegrityDesc *)bh->b_data;

- if (lvid->integrityType == LVID_INTEGRITY_TYPE_OPEN) {
- struct logicalVolIntegrityDescImpUse *lvidiu =
- udf_sb_lvidiu(sbi);
- lvidiu->impIdent.identSuffix[0] = UDF_OS_CLASS_UNIX;
- lvidiu->impIdent.identSuffix[1] = UDF_OS_ID_LINUX;
- udf_time_to_stamp(&lvid->recordingDateAndTime, CURRENT_TIME);
- if (UDF_MAX_WRITE_VERSION > le16_to_cpu(lvidiu->maxUDFWriteRev))
- lvidiu->maxUDFWriteRev =
- cpu_to_le16(UDF_MAX_WRITE_VERSION);
- if (sbi->s_udfrev > le16_to_cpu(lvidiu->minUDFReadRev))
- lvidiu->minUDFReadRev = cpu_to_le16(sbi->s_udfrev);
- if (sbi->s_udfrev > le16_to_cpu(lvidiu->minUDFWriteRev))
- lvidiu->minUDFWriteRev = cpu_to_le16(sbi->s_udfrev);
- lvid->integrityType = cpu_to_le32(LVID_INTEGRITY_TYPE_CLOSE);
-
- lvid->descTag.descCRC = cpu_to_le16(
- udf_crc((char *)lvid + sizeof(tag),
- le16_to_cpu(lvid->descTag.descCRCLength),
- 0));
-
- lvid->descTag.tagChecksum = udf_tag_checksum(&lvid->descTag);
- mark_buffer_dirty(bh);
- }
+ if (lvid->integrityType != LVID_INTEGRITY_TYPE_OPEN)
+ return;
+
+ lvidiu = udf_sb_lvidiu(sbi);
+ lvidiu->impIdent.identSuffix[0] = UDF_OS_CLASS_UNIX;
+ lvidiu->impIdent.identSuffix[1] = UDF_OS_ID_LINUX;
+ udf_time_to_stamp(&lvid->recordingDateAndTime, CURRENT_TIME);
+ if (UDF_MAX_WRITE_VERSION > le16_to_cpu(lvidiu->maxUDFWriteRev))
+ lvidiu->maxUDFWriteRev = cpu_to_le16(UDF_MAX_WRITE_VERSION);
+ if (sbi->s_udfrev > le16_to_cpu(lvidiu->minUDFReadRev))
+ lvidiu->minUDFReadRev = cpu_to_le16(sbi->s_udfrev);
+ if (sbi->s_udfrev > le16_to_cpu(lvidiu->minUDFWriteRev))
+ lvidiu->minUDFWriteRev = cpu_to_le16(sbi->s_udfrev);
+ lvid->integrityType = cpu_to_le32(LVID_INTEGRITY_TYPE_CLOSE);
+
+ lvid->descTag.descCRC = cpu_to_le16(
+ udf_crc((char *)lvid + sizeof(tag),
+ le16_to_cpu(lvid->descTag.descCRCLength),
+ 0));
+
+ lvid->descTag.tagChecksum = udf_tag_checksum(&lvid->descTag);
+ mark_buffer_dirty(bh);
}

static void udf_sb_free_bitmap(struct udf_bitmap *bitmap)
--
1.5.3.7

2008-02-05 15:30:20

by Jan Kara

[permalink] [raw]
Subject: Re: [PATCH 1/6] udf: udf_get_block, inode_bmap - remove unneeded checks

On Sun 03-02-08 19:36:06, [email protected] wrote:
> block cannot be less than 0, because it's sector_t,
> so remove unneeded checks
>
> Signed-off-by: Marcin Slusarz <[email protected]>
> Cc: Jan Kara <[email protected]>
Acked-by: Jan Kara <[email protected]>

Honza
> ---
> fs/udf/inode.c | 12 ------------
> 1 files changed, 0 insertions(+), 12 deletions(-)
>
> diff --git a/fs/udf/inode.c b/fs/udf/inode.c
> index c2d0477..531443d 100644
> --- a/fs/udf/inode.c
> +++ b/fs/udf/inode.c
> @@ -323,9 +323,6 @@ static int udf_get_block(struct inode *inode, sector_t block,
>
> lock_kernel();
>
> - if (block < 0)
> - goto abort_negative;
> -
> iinfo = UDF_I(inode);
> if (block == iinfo->i_next_alloc_block + 1) {
> iinfo->i_next_alloc_block++;
> @@ -347,10 +344,6 @@ static int udf_get_block(struct inode *inode, sector_t block,
> abort:
> unlock_kernel();
> return err;
> -
> -abort_negative:
> - udf_warning(inode->i_sb, "udf_get_block", "block < 0");
> - goto abort;
> }
>
> static struct buffer_head *udf_getblk(struct inode *inode, long block,
> @@ -2081,11 +2074,6 @@ int8_t inode_bmap(struct inode *inode, sector_t block,
> int8_t etype;
> struct udf_inode_info *iinfo;
>
> - if (block < 0) {
> - printk(KERN_ERR "udf: inode_bmap: block < 0\n");
> - return -1;
> - }
> -
> iinfo = UDF_I(inode);
> pos->offset = 0;
> pos->block = iinfo->i_location;
> --
> 1.5.3.7
>
--
Jan Kara <[email protected]>
SUSE Labs, CR

2008-02-05 15:32:22

by Jan Kara

[permalink] [raw]
Subject: Re: [PATCH 2/6] udf: create function for conversion from timestamp to timespec

On Sun 03-02-08 19:36:07, [email protected] wrote:
> Signed-off-by: Marcin Slusarz <[email protected]>
> Cc: Jan Kara <[email protected]>
Acked-by: Jan Kara <[email protected]>

Honza

> ---
> fs/udf/inode.c | 79 ++++++++++++++++---------------------------------------
> 1 files changed, 23 insertions(+), 56 deletions(-)
>
> diff --git a/fs/udf/inode.c b/fs/udf/inode.c
> index 531443d..2578677 100644
> --- a/fs/udf/inode.c
> +++ b/fs/udf/inode.c
> @@ -1151,12 +1151,24 @@ static void __udf_read_inode(struct inode *inode)
> brelse(bh);
> }
>
> +static void udf_fill_inode_time(struct timespec *tspec,
> + const timestamp *tstamp,
> + struct udf_sb_info *sbi)
> +{
> + time_t convtime;
> + long convtime_usec;
> + if (udf_stamp_to_time(&convtime, &convtime_usec,
> + lets_to_cpu(*tstamp))) {
> + tspec->tv_sec = convtime;
> + tspec->tv_nsec = convtime_usec * 1000;
> + } else
> + *tspec = sbi->s_record_time;
> +}
> +
> static void udf_fill_inode(struct inode *inode, struct buffer_head *bh)
> {
> struct fileEntry *fe;
> struct extendedFileEntry *efe;
> - time_t convtime;
> - long convtime_usec;
> int offset;
> struct udf_sb_info *sbi = UDF_SB(inode->i_sb);
> struct udf_inode_info *iinfo = UDF_I(inode);
> @@ -1244,29 +1256,10 @@ static void udf_fill_inode(struct inode *inode, struct buffer_head *bh)
> inode->i_blocks = le64_to_cpu(fe->logicalBlocksRecorded) <<
> (inode->i_sb->s_blocksize_bits - 9);
>
> - if (udf_stamp_to_time(&convtime, &convtime_usec,
> - lets_to_cpu(fe->accessTime))) {
> - inode->i_atime.tv_sec = convtime;
> - inode->i_atime.tv_nsec = convtime_usec * 1000;
> - } else {
> - inode->i_atime = sbi->s_record_time;
> - }
> -
> - if (udf_stamp_to_time(&convtime, &convtime_usec,
> - lets_to_cpu(fe->modificationTime))) {
> - inode->i_mtime.tv_sec = convtime;
> - inode->i_mtime.tv_nsec = convtime_usec * 1000;
> - } else {
> - inode->i_mtime = sbi->s_record_time;
> - }
> -
> - if (udf_stamp_to_time(&convtime, &convtime_usec,
> - lets_to_cpu(fe->attrTime))) {
> - inode->i_ctime.tv_sec = convtime;
> - inode->i_ctime.tv_nsec = convtime_usec * 1000;
> - } else {
> - inode->i_ctime = sbi->s_record_time;
> - }
> + udf_fill_inode_time(&inode->i_atime, &fe->accessTime, sbi);
> + udf_fill_inode_time(&inode->i_mtime, &fe->modificationTime,
> + sbi);
> + udf_fill_inode_time(&inode->i_ctime, &fe->attrTime, sbi);
>
> iinfo->i_unique = le64_to_cpu(fe->uniqueID);
> iinfo->i_lenEAttr = le32_to_cpu(fe->lengthExtendedAttr);
> @@ -1276,37 +1269,11 @@ static void udf_fill_inode(struct inode *inode, struct buffer_head *bh)
> inode->i_blocks = le64_to_cpu(efe->logicalBlocksRecorded) <<
> (inode->i_sb->s_blocksize_bits - 9);
>
> - if (udf_stamp_to_time(&convtime, &convtime_usec,
> - lets_to_cpu(efe->accessTime))) {
> - inode->i_atime.tv_sec = convtime;
> - inode->i_atime.tv_nsec = convtime_usec * 1000;
> - } else {
> - inode->i_atime = sbi->s_record_time;
> - }
> -
> - if (udf_stamp_to_time(&convtime, &convtime_usec,
> - lets_to_cpu(efe->modificationTime))) {
> - inode->i_mtime.tv_sec = convtime;
> - inode->i_mtime.tv_nsec = convtime_usec * 1000;
> - } else {
> - inode->i_mtime = sbi->s_record_time;
> - }
> -
> - if (udf_stamp_to_time(&convtime, &convtime_usec,
> - lets_to_cpu(efe->createTime))) {
> - iinfo->i_crtime.tv_sec = convtime;
> - iinfo->i_crtime.tv_nsec = convtime_usec * 1000;
> - } else {
> - iinfo->i_crtime = sbi->s_record_time;
> - }
> -
> - if (udf_stamp_to_time(&convtime, &convtime_usec,
> - lets_to_cpu(efe->attrTime))) {
> - inode->i_ctime.tv_sec = convtime;
> - inode->i_ctime.tv_nsec = convtime_usec * 1000;
> - } else {
> - inode->i_ctime = sbi->s_record_time;
> - }
> + udf_fill_inode_time(&inode->i_atime, &efe->accessTime, sbi);
> + udf_fill_inode_time(&inode->i_mtime, &efe->modificationTime,
> + sbi);
> + udf_fill_inode_time(&iinfo->i_crtime, &efe->createTime, sbi);
> + udf_fill_inode_time(&inode->i_ctime, &efe->attrTime, sbi);
>
> iinfo->i_unique = le64_to_cpu(efe->uniqueID);
> iinfo->i_lenEAttr = le32_to_cpu(efe->lengthExtendedAttr);
> --
> 1.5.3.7
>
--
Jan Kara <[email protected]>
SUSE Labs, CR

2008-02-05 15:48:43

by Jan Kara

[permalink] [raw]
Subject: Re: [PATCH 3/6] udf: convert udf_stamp_to_time to return struct timespec


Uh, oh. I guess you somehow mangled the ordering of patches. In this
patch you revert what you've done in the previous patch. Otherwise I agree
with the idea of the change...

Honza


On Sun 03-02-08 19:36:08, [email protected] wrote:
> Signed-off-by: Marcin Slusarz <[email protected]>
> Cc: Jan Kara <[email protected]>
> ---
> fs/udf/inode.c | 49 ++++++++++++++++++++++++++-----------------------
> fs/udf/super.c | 9 ++-------
> fs/udf/udfdecl.h | 4 ++--
> fs/udf/udftime.c | 17 +++++++----------
> 4 files changed, 37 insertions(+), 42 deletions(-)
>
> diff --git a/fs/udf/inode.c b/fs/udf/inode.c
> index 2578677..252efe0 100644
> --- a/fs/udf/inode.c
> +++ b/fs/udf/inode.c
> @@ -1151,20 +1151,6 @@ static void __udf_read_inode(struct inode *inode)
> brelse(bh);
> }
>
> -static void udf_fill_inode_time(struct timespec *tspec,
> - const timestamp *tstamp,
> - struct udf_sb_info *sbi)
> -{
> - time_t convtime;
> - long convtime_usec;
> - if (udf_stamp_to_time(&convtime, &convtime_usec,
> - lets_to_cpu(*tstamp))) {
> - tspec->tv_sec = convtime;
> - tspec->tv_nsec = convtime_usec * 1000;
> - } else
> - *tspec = sbi->s_record_time;
> -}
> -

> static void udf_fill_inode(struct inode *inode, struct buffer_head *bh)
> {
> struct fileEntry *fe;
> @@ -1256,10 +1242,17 @@ static void udf_fill_inode(struct inode *inode, struct buffer_head *bh)
> inode->i_blocks = le64_to_cpu(fe->logicalBlocksRecorded) <<
> (inode->i_sb->s_blocksize_bits - 9);
>
> - udf_fill_inode_time(&inode->i_atime, &fe->accessTime, sbi);
> - udf_fill_inode_time(&inode->i_mtime, &fe->modificationTime,
> - sbi);
> - udf_fill_inode_time(&inode->i_ctime, &fe->attrTime, sbi);
> + if (!udf_stamp_to_time(&inode->i_atime,
> + lets_to_cpu(fe->accessTime)))
> + inode->i_atime = sbi->s_record_time;
> +
> + if (!udf_stamp_to_time(&inode->i_mtime,
> + lets_to_cpu(fe->modificationTime)))
> + inode->i_mtime = sbi->s_record_time;
> +
> + if (!udf_stamp_to_time(&inode->i_ctime,
> + lets_to_cpu(fe->attrTime)))
> + inode->i_ctime = sbi->s_record_time;
>
> iinfo->i_unique = le64_to_cpu(fe->uniqueID);
> iinfo->i_lenEAttr = le32_to_cpu(fe->lengthExtendedAttr);
> @@ -1269,11 +1262,21 @@ static void udf_fill_inode(struct inode *inode, struct buffer_head *bh)
> inode->i_blocks = le64_to_cpu(efe->logicalBlocksRecorded) <<
> (inode->i_sb->s_blocksize_bits - 9);
>
> - udf_fill_inode_time(&inode->i_atime, &efe->accessTime, sbi);
> - udf_fill_inode_time(&inode->i_mtime, &efe->modificationTime,
> - sbi);
> - udf_fill_inode_time(&iinfo->i_crtime, &efe->createTime, sbi);
> - udf_fill_inode_time(&inode->i_ctime, &efe->attrTime, sbi);
> + if (!udf_stamp_to_time(&inode->i_atime,
> + lets_to_cpu(efe->accessTime)))
> + inode->i_atime = sbi->s_record_time;
> +
> + if (!udf_stamp_to_time(&inode->i_mtime,
> + lets_to_cpu(efe->modificationTime)))
> + inode->i_mtime = sbi->s_record_time;
> +
> + if (!udf_stamp_to_time(&iinfo->i_crtime,
> + lets_to_cpu(efe->createTime)))
> + iinfo->i_crtime = sbi->s_record_time;
> +
> + if (!udf_stamp_to_time(&inode->i_ctime,
> + lets_to_cpu(efe->attrTime)))
> + inode->i_ctime = sbi->s_record_time;
>
> iinfo->i_unique = le64_to_cpu(efe->uniqueID);
> iinfo->i_lenEAttr = le32_to_cpu(efe->lengthExtendedAttr);
> diff --git a/fs/udf/super.c b/fs/udf/super.c
> index 0dcee12..9f565a9 100644
> --- a/fs/udf/super.c
> +++ b/fs/udf/super.c
> @@ -909,24 +909,19 @@ static int udf_find_fileset(struct super_block *sb,
> static void udf_load_pvoldesc(struct super_block *sb, struct buffer_head *bh)
> {
> struct primaryVolDesc *pvoldesc;
> - time_t recording;
> - long recording_usec;
> struct ustr instr;
> struct ustr outstr;
>
> pvoldesc = (struct primaryVolDesc *)bh->b_data;
>
> - if (udf_stamp_to_time(&recording, &recording_usec,
> + if (udf_stamp_to_time(&UDF_SB(sb)->s_record_time,
> lets_to_cpu(pvoldesc->recordingDateAndTime))) {
> kernel_timestamp ts;
> ts = lets_to_cpu(pvoldesc->recordingDateAndTime);
> - udf_debug("recording time %ld/%ld, %04u/%02u/%02u"
> + udf_debug("recording time %04u/%02u/%02u"
> " %02u:%02u (%x)\n",
> - recording, recording_usec,
> ts.year, ts.month, ts.day, ts.hour,
> ts.minute, ts.typeAndTimezone);
> - UDF_SB(sb)->s_record_time.tv_sec = recording;
> - UDF_SB(sb)->s_record_time.tv_nsec = recording_usec * 1000;
> }
>
> if (!udf_build_ustr(&instr, pvoldesc->volIdent, 32))
> diff --git a/fs/udf/udfdecl.h b/fs/udf/udfdecl.h
> index 375be1b..508be85 100644
> --- a/fs/udf/udfdecl.h
> +++ b/fs/udf/udfdecl.h
> @@ -204,7 +204,7 @@ extern short_ad *udf_get_fileshortad(uint8_t *, int, uint32_t *, int);
> extern uint16_t udf_crc(const uint8_t *, uint32_t, uint16_t);
>
> /* udftime.c */
> -extern time_t *udf_stamp_to_time(time_t *, long *, kernel_timestamp);
> -extern kernel_timestamp *udf_time_to_stamp(kernel_timestamp *, struct timespec);
> +extern struct timespec *udf_stamp_to_time(struct timespec *dest, kernel_timestamp src);
> +extern kernel_timestamp *udf_time_to_stamp(kernel_timestamp *dest, struct timespec src);
>
> #endif /* __UDF_DECL_H */
> diff --git a/fs/udf/udftime.c b/fs/udf/udftime.c
> index ce59573..12fae6c 100644
> --- a/fs/udf/udftime.c
> +++ b/fs/udf/udftime.c
> @@ -85,7 +85,7 @@ extern struct timezone sys_tz;
> #define SECS_PER_HOUR (60 * 60)
> #define SECS_PER_DAY (SECS_PER_HOUR * 24)
>
> -time_t *udf_stamp_to_time(time_t *dest, long *dest_usec, kernel_timestamp src)
> +struct timespec *udf_stamp_to_time(struct timespec *dest, kernel_timestamp src)
> {
> int yday;
> uint8_t type = src.typeAndTimezone >> 12;
> @@ -97,23 +97,20 @@ time_t *udf_stamp_to_time(time_t *dest, long *dest_usec, kernel_timestamp src)
> offset = (offset >> 4);
> if (offset == -2047) /* unspecified offset */
> offset = 0;
> - } else {
> + } else
> offset = 0;
> - }
>
> if ((src.year < EPOCH_YEAR) ||
> (src.year >= EPOCH_YEAR + MAX_YEAR_SECONDS)) {
> - *dest = -1;
> - *dest_usec = -1;
> return NULL;
> }
> - *dest = year_seconds[src.year - EPOCH_YEAR];
> - *dest -= offset * 60;
> + dest->tv_sec = year_seconds[src.year - EPOCH_YEAR];
> + dest->tv_sec -= offset * 60;
>
> yday = ((__mon_yday[__isleap(src.year)][src.month - 1]) + src.day - 1);
> - *dest += (((yday * 24) + src.hour) * 60 + src.minute) * 60 + src.second;
> - *dest_usec = src.centiseconds * 10000 +
> - src.hundredsOfMicroseconds * 100 + src.microseconds;
> + dest->tv_sec += (((yday * 24) + src.hour) * 60 + src.minute) * 60 + src.second;
> + dest->tv_nsec = 1000 * (src.centiseconds * 10000 +
> + src.hundredsOfMicroseconds * 100 + src.microseconds);
> return dest;
> }
>
> --
> 1.5.3.7

Honza
--
Jan Kara <[email protected]>
SUSE Labs, CR

2008-02-05 16:00:15

by Jan Kara

[permalink] [raw]
Subject: Re: [PATCH 4/6] udf: convert udf_stamp_to_time and udf_time_to_stamp to use timestamps

On Sun 03-02-08 19:36:09, [email protected] wrote:
> kernel_timestamp type was almost unused - only callers of udf_stamp_to_time
> and udf_time_to_stamp used it, so let these functions handle endianness
> internally and don't clutter code with conversions
OK, but please also rename the functions to something like
udf_disk_stamp_to_time() and udf_time_to_disk_stamp() so that the name
suggests that it internally handles endianess...

Honza
>
> Signed-off-by: Marcin Slusarz <[email protected]>
> Cc: Jan Kara <[email protected]>
> ---
> fs/udf/inode.c | 43 ++++++++++++++-----------------------------
> fs/udf/super.c | 16 ++++++----------
> fs/udf/udfdecl.h | 4 ++--
> fs/udf/udftime.c | 22 ++++++++++++----------
> 4 files changed, 34 insertions(+), 51 deletions(-)
>
> diff --git a/fs/udf/inode.c b/fs/udf/inode.c
> index 252efe0..654b504 100644
> --- a/fs/udf/inode.c
> +++ b/fs/udf/inode.c
> @@ -1242,16 +1242,13 @@ static void udf_fill_inode(struct inode *inode, struct buffer_head *bh)
> inode->i_blocks = le64_to_cpu(fe->logicalBlocksRecorded) <<
> (inode->i_sb->s_blocksize_bits - 9);
>
> - if (!udf_stamp_to_time(&inode->i_atime,
> - lets_to_cpu(fe->accessTime)))
> + if (!udf_stamp_to_time(&inode->i_atime, fe->accessTime))
> inode->i_atime = sbi->s_record_time;
>
> - if (!udf_stamp_to_time(&inode->i_mtime,
> - lets_to_cpu(fe->modificationTime)))
> + if (!udf_stamp_to_time(&inode->i_mtime, fe->modificationTime))
> inode->i_mtime = sbi->s_record_time;
>
> - if (!udf_stamp_to_time(&inode->i_ctime,
> - lets_to_cpu(fe->attrTime)))
> + if (!udf_stamp_to_time(&inode->i_ctime, fe->attrTime))
> inode->i_ctime = sbi->s_record_time;
>
> iinfo->i_unique = le64_to_cpu(fe->uniqueID);
> @@ -1262,20 +1259,16 @@ static void udf_fill_inode(struct inode *inode, struct buffer_head *bh)
> inode->i_blocks = le64_to_cpu(efe->logicalBlocksRecorded) <<
> (inode->i_sb->s_blocksize_bits - 9);
>
> - if (!udf_stamp_to_time(&inode->i_atime,
> - lets_to_cpu(efe->accessTime)))
> + if (!udf_stamp_to_time(&inode->i_atime, efe->accessTime))
> inode->i_atime = sbi->s_record_time;
>
> - if (!udf_stamp_to_time(&inode->i_mtime,
> - lets_to_cpu(efe->modificationTime)))
> + if (!udf_stamp_to_time(&inode->i_mtime, efe->modificationTime))
> inode->i_mtime = sbi->s_record_time;
>
> - if (!udf_stamp_to_time(&iinfo->i_crtime,
> - lets_to_cpu(efe->createTime)))
> + if (!udf_stamp_to_time(&iinfo->i_crtime, efe->createTime))
> iinfo->i_crtime = sbi->s_record_time;
>
> - if (!udf_stamp_to_time(&inode->i_ctime,
> - lets_to_cpu(efe->attrTime)))
> + if (!udf_stamp_to_time(&inode->i_ctime, efe->attrTime))
> inode->i_ctime = sbi->s_record_time;
>
> iinfo->i_unique = le64_to_cpu(efe->uniqueID);
> @@ -1412,7 +1405,6 @@ static int udf_update_inode(struct inode *inode, int do_sync)
> uint32_t udfperms;
> uint16_t icbflags;
> uint16_t crclen;
> - kernel_timestamp cpu_time;
> int err = 0;
> struct udf_sb_info *sbi = UDF_SB(inode->i_sb);
> unsigned char blocksize_bits = inode->i_sb->s_blocksize_bits;
> @@ -1515,12 +1507,9 @@ static int udf_update_inode(struct inode *inode, int do_sync)
> (inode->i_blocks + (1 << (blocksize_bits - 9)) - 1) >>
> (blocksize_bits - 9));
>
> - if (udf_time_to_stamp(&cpu_time, inode->i_atime))
> - fe->accessTime = cpu_to_lets(cpu_time);
> - if (udf_time_to_stamp(&cpu_time, inode->i_mtime))
> - fe->modificationTime = cpu_to_lets(cpu_time);
> - if (udf_time_to_stamp(&cpu_time, inode->i_ctime))
> - fe->attrTime = cpu_to_lets(cpu_time);
> + udf_time_to_stamp(&fe->accessTime, inode->i_atime);
> + udf_time_to_stamp(&fe->modificationTime, inode->i_mtime);
> + udf_time_to_stamp(&fe->attrTime, inode->i_ctime);
> memset(&(fe->impIdent), 0, sizeof(regid));
> strcpy(fe->impIdent.ident, UDF_ID_DEVELOPER);
> fe->impIdent.identSuffix[0] = UDF_OS_CLASS_UNIX;
> @@ -1555,14 +1544,10 @@ static int udf_update_inode(struct inode *inode, int do_sync)
> iinfo->i_crtime.tv_nsec > inode->i_ctime.tv_nsec))
> iinfo->i_crtime = inode->i_ctime;
>
> - if (udf_time_to_stamp(&cpu_time, inode->i_atime))
> - efe->accessTime = cpu_to_lets(cpu_time);
> - if (udf_time_to_stamp(&cpu_time, inode->i_mtime))
> - efe->modificationTime = cpu_to_lets(cpu_time);
> - if (udf_time_to_stamp(&cpu_time, iinfo->i_crtime))
> - efe->createTime = cpu_to_lets(cpu_time);
> - if (udf_time_to_stamp(&cpu_time, inode->i_ctime))
> - efe->attrTime = cpu_to_lets(cpu_time);
> + udf_time_to_stamp(&efe->accessTime, inode->i_atime);
> + udf_time_to_stamp(&efe->modificationTime, inode->i_mtime);
> + udf_time_to_stamp(&efe->createTime, iinfo->i_crtime);
> + udf_time_to_stamp(&efe->attrTime, inode->i_ctime);
>
> memset(&(efe->impIdent), 0, sizeof(regid));
> strcpy(efe->impIdent.ident, UDF_ID_DEVELOPER);
> diff --git a/fs/udf/super.c b/fs/udf/super.c
> index 9f565a9..8a98a2e 100644
> --- a/fs/udf/super.c
> +++ b/fs/udf/super.c
> @@ -915,7 +915,7 @@ static void udf_load_pvoldesc(struct super_block *sb, struct buffer_head *bh)
> pvoldesc = (struct primaryVolDesc *)bh->b_data;
>
> if (udf_stamp_to_time(&UDF_SB(sb)->s_record_time,
> - lets_to_cpu(pvoldesc->recordingDateAndTime))) {
> + pvoldesc->recordingDateAndTime)) {
> kernel_timestamp ts;
> ts = lets_to_cpu(pvoldesc->recordingDateAndTime);
> udf_debug("recording time %04u/%02u/%02u"
> @@ -1561,7 +1561,6 @@ static void udf_open_lvid(struct super_block *sb)
> struct udf_sb_info *sbi = UDF_SB(sb);
> struct buffer_head *bh = sbi->s_lvid_bh;
> if (bh) {
> - kernel_timestamp cpu_time;
> struct logicalVolIntegrityDesc *lvid =
> (struct logicalVolIntegrityDesc *)bh->b_data;
> struct logicalVolIntegrityDescImpUse *lvidiu =
> @@ -1569,8 +1568,7 @@ static void udf_open_lvid(struct super_block *sb)
>
> lvidiu->impIdent.identSuffix[0] = UDF_OS_CLASS_UNIX;
> lvidiu->impIdent.identSuffix[1] = UDF_OS_ID_LINUX;
> - if (udf_time_to_stamp(&cpu_time, CURRENT_TIME))
> - lvid->recordingDateAndTime = cpu_to_lets(cpu_time);
> + udf_time_to_stamp(&lvid->recordingDateAndTime, CURRENT_TIME);
> lvid->integrityType = LVID_INTEGRITY_TYPE_OPEN;
>
> lvid->descTag.descCRC = cpu_to_le16(
> @@ -1585,7 +1583,6 @@ static void udf_open_lvid(struct super_block *sb)
>
> static void udf_close_lvid(struct super_block *sb)
> {
> - kernel_timestamp cpu_time;
> struct udf_sb_info *sbi = UDF_SB(sb);
> struct buffer_head *bh = sbi->s_lvid_bh;
> struct logicalVolIntegrityDesc *lvid;
> @@ -1600,8 +1597,7 @@ static void udf_close_lvid(struct super_block *sb)
> udf_sb_lvidiu(sbi);
> lvidiu->impIdent.identSuffix[0] = UDF_OS_CLASS_UNIX;
> lvidiu->impIdent.identSuffix[1] = UDF_OS_ID_LINUX;
> - if (udf_time_to_stamp(&cpu_time, CURRENT_TIME))
> - lvid->recordingDateAndTime = cpu_to_lets(cpu_time);
> + udf_time_to_stamp(&lvid->recordingDateAndTime, CURRENT_TIME);
> if (UDF_MAX_WRITE_VERSION > le16_to_cpu(lvidiu->maxUDFWriteRev))
> lvidiu->maxUDFWriteRev =
> cpu_to_le16(UDF_MAX_WRITE_VERSION);
> @@ -1786,12 +1782,12 @@ static int udf_fill_super(struct super_block *sb, void *options, int silent)
> }
>
> if (!silent) {
> - kernel_timestamp ts;
> + timestamp ts;
> udf_time_to_stamp(&ts, sbi->s_record_time);
> udf_info("UDF: Mounting volume '%s', "
> "timestamp %04u/%02u/%02u %02u:%02u (%x)\n",
> - sbi->s_volume_ident, ts.year, ts.month, ts.day,
> - ts.hour, ts.minute, ts.typeAndTimezone);
> + sbi->s_volume_ident, le16_to_cpu(ts.year), ts.month, ts.day,
> + ts.hour, ts.minute, le16_to_cpu(ts.typeAndTimezone));
> }
> if (!(sb->s_flags & MS_RDONLY))
> udf_open_lvid(sb);
> diff --git a/fs/udf/udfdecl.h b/fs/udf/udfdecl.h
> index 508be85..2dd04bb 100644
> --- a/fs/udf/udfdecl.h
> +++ b/fs/udf/udfdecl.h
> @@ -204,7 +204,7 @@ extern short_ad *udf_get_fileshortad(uint8_t *, int, uint32_t *, int);
> extern uint16_t udf_crc(const uint8_t *, uint32_t, uint16_t);
>
> /* udftime.c */
> -extern struct timespec *udf_stamp_to_time(struct timespec *dest, kernel_timestamp src);
> -extern kernel_timestamp *udf_time_to_stamp(kernel_timestamp *dest, struct timespec src);
> +extern struct timespec *udf_stamp_to_time(struct timespec *dest, timestamp src);
> +extern timestamp *udf_time_to_stamp(timestamp *dest, struct timespec src);
>
> #endif /* __UDF_DECL_H */
> diff --git a/fs/udf/udftime.c b/fs/udf/udftime.c
> index 12fae6c..d125bd9 100644
> --- a/fs/udf/udftime.c
> +++ b/fs/udf/udftime.c
> @@ -85,14 +85,16 @@ extern struct timezone sys_tz;
> #define SECS_PER_HOUR (60 * 60)
> #define SECS_PER_DAY (SECS_PER_HOUR * 24)
>
> -struct timespec *udf_stamp_to_time(struct timespec *dest, kernel_timestamp src)
> +struct timespec *udf_stamp_to_time(struct timespec *dest, timestamp src)
> {
> int yday;
> - uint8_t type = src.typeAndTimezone >> 12;
> + u16 typeAndTimezone = le16_to_cpu(src.typeAndTimezone);
> + u16 year = le16_to_cpu(src.year);
> + uint8_t type = typeAndTimezone >> 12;
> int16_t offset;
>
> if (type == 1) {
> - offset = src.typeAndTimezone << 4;
> + offset = typeAndTimezone << 4;
> /* sign extent offset */
> offset = (offset >> 4);
> if (offset == -2047) /* unspecified offset */
> @@ -100,21 +102,21 @@ struct timespec *udf_stamp_to_time(struct timespec *dest, kernel_timestamp src)
> } else
> offset = 0;
>
> - if ((src.year < EPOCH_YEAR) ||
> - (src.year >= EPOCH_YEAR + MAX_YEAR_SECONDS)) {
> + if ((year < EPOCH_YEAR) ||
> + (year >= EPOCH_YEAR + MAX_YEAR_SECONDS)) {
> return NULL;
> }
> - dest->tv_sec = year_seconds[src.year - EPOCH_YEAR];
> + dest->tv_sec = year_seconds[year - EPOCH_YEAR];
> dest->tv_sec -= offset * 60;
>
> - yday = ((__mon_yday[__isleap(src.year)][src.month - 1]) + src.day - 1);
> + yday = ((__mon_yday[__isleap(year)][src.month - 1]) + src.day - 1);
> dest->tv_sec += (((yday * 24) + src.hour) * 60 + src.minute) * 60 + src.second;
> dest->tv_nsec = 1000 * (src.centiseconds * 10000 +
> src.hundredsOfMicroseconds * 100 + src.microseconds);
> return dest;
> }
>
> -kernel_timestamp *udf_time_to_stamp(kernel_timestamp *dest, struct timespec ts)
> +timestamp *udf_time_to_stamp(timestamp *dest, struct timespec ts)
> {
> long int days, rem, y;
> const unsigned short int *ip;
> @@ -125,7 +127,7 @@ kernel_timestamp *udf_time_to_stamp(kernel_timestamp *dest, struct timespec ts)
> if (!dest)
> return NULL;
>
> - dest->typeAndTimezone = 0x1000 | (offset & 0x0FFF);
> + dest->typeAndTimezone = cpu_to_le16(0x1000 | (offset & 0x0FFF));
>
> ts.tv_sec += offset * 60;
> days = ts.tv_sec / SECS_PER_DAY;
> @@ -148,7 +150,7 @@ kernel_timestamp *udf_time_to_stamp(kernel_timestamp *dest, struct timespec ts)
> - LEAPS_THRU_END_OF(y - 1));
> y = yg;
> }
> - dest->year = y;
> + dest->year = cpu_to_le16(y);
> ip = __mon_yday[__isleap(y)];
> for (y = 11; days < (long int)ip[y]; --y)
> continue;
> --
> 1.5.3.7
>
--
Jan Kara <[email protected]>
SUSE Labs, CR

2008-02-05 16:01:30

by Jan Kara

[permalink] [raw]
Subject: Re: [PATCH 5/6] udf: remove unneeded kernel_timestamp type

On Sun 03-02-08 19:36:10, [email protected] wrote:
> remove now unneeded kernel_timestamp type with conversion functions
OK. Acked-by: Jan Kara <[email protected]>

Honza
>
> Signed-off-by: Marcin Slusarz <[email protected]>
> Cc: Jan Kara <[email protected]>
> ---
> fs/udf/ecma_167.h | 13 -------------
> fs/udf/super.c | 9 +++++----
> fs/udf/udfend.h | 22 ----------------------
> 3 files changed, 5 insertions(+), 39 deletions(-)
>
> diff --git a/fs/udf/ecma_167.h b/fs/udf/ecma_167.h
> index 5638771..a0974df 100644
> --- a/fs/udf/ecma_167.h
> +++ b/fs/udf/ecma_167.h
> @@ -70,19 +70,6 @@ typedef struct {
> uint8_t microseconds;
> } __attribute__ ((packed)) timestamp;
>
> -typedef struct {
> - uint16_t typeAndTimezone;
> - int16_t year;
> - uint8_t month;
> - uint8_t day;
> - uint8_t hour;
> - uint8_t minute;
> - uint8_t second;
> - uint8_t centiseconds;
> - uint8_t hundredsOfMicroseconds;
> - uint8_t microseconds;
> -} __attribute__ ((packed)) kernel_timestamp;
> -
> /* Type and Time Zone (ECMA 167r3 1/7.3.1) */
> #define TIMESTAMP_TYPE_MASK 0xF000
> #define TIMESTAMP_TYPE_CUT 0x0000
> diff --git a/fs/udf/super.c b/fs/udf/super.c
> index 8a98a2e..3a7faad 100644
> --- a/fs/udf/super.c
> +++ b/fs/udf/super.c
> @@ -916,12 +916,13 @@ static void udf_load_pvoldesc(struct super_block *sb, struct buffer_head *bh)
>
> if (udf_stamp_to_time(&UDF_SB(sb)->s_record_time,
> pvoldesc->recordingDateAndTime)) {
> - kernel_timestamp ts;
> - ts = lets_to_cpu(pvoldesc->recordingDateAndTime);
> +#ifdef UDFFS_DEBUG
> + timestamp *ts = &pvoldesc->recordingDateAndTime;
> udf_debug("recording time %04u/%02u/%02u"
> " %02u:%02u (%x)\n",
> - ts.year, ts.month, ts.day, ts.hour,
> - ts.minute, ts.typeAndTimezone);
> + le16_to_cpu(ts->year), ts->month, ts->day, ts->hour,
> + ts->minute, le16_to_cpu(ts->typeAndTimezone));
> +#endif
> }
>
> if (!udf_build_ustr(&instr, pvoldesc->volIdent, 32))
> diff --git a/fs/udf/udfend.h b/fs/udf/udfend.h
> index c4bd120..489f52f 100644
> --- a/fs/udf/udfend.h
> +++ b/fs/udf/udfend.h
> @@ -24,17 +24,6 @@ static inline lb_addr cpu_to_lelb(kernel_lb_addr in)
> return out;
> }
>
> -static inline kernel_timestamp lets_to_cpu(timestamp in)
> -{
> - kernel_timestamp out;
> -
> - memcpy(&out, &in, sizeof(timestamp));
> - out.typeAndTimezone = le16_to_cpu(in.typeAndTimezone);
> - out.year = le16_to_cpu(in.year);
> -
> - return out;
> -}
> -
> static inline short_ad lesa_to_cpu(short_ad in)
> {
> short_ad out;
> @@ -85,15 +74,4 @@ static inline kernel_extent_ad leea_to_cpu(extent_ad in)
> return out;
> }
>
> -static inline timestamp cpu_to_lets(kernel_timestamp in)
> -{
> - timestamp out;
> -
> - memcpy(&out, &in, sizeof(timestamp));
> - out.typeAndTimezone = cpu_to_le16(in.typeAndTimezone);
> - out.year = cpu_to_le16(in.year);
> -
> - return out;
> -}
> -
> #endif /* __UDF_ENDIAN_H */
> --
> 1.5.3.7
>
--
Jan Kara <[email protected]>
SUSE Labs, CR

2008-02-05 16:23:06

by Jan Kara

[permalink] [raw]
Subject: Re: [PATCH 6/6] udf: super.c reorganization

On Sun 03-02-08 19:42:38, Marcin Slusarz wrote:
> reorganize few code blocks in super.c which
> were needlessly indented (and hard to read):
>
> so change from:
> rettype fun()
> {
> init;
> if (sth) {
> long block of code;
> }
> }
>
> to:
> rettype fun()
> {
> init;
> if (!sth)
> return;
> long block of code;
> }
>
> or
>
> from:
> rettype fun2()
> {
> init;
> while (sth) {
> init2();
> if (sth2) {
> long block of code;
> }
> }
> }
>
> to:
> rettype fun2()
> {
> init;
> while (sth) {
> init2();
> if (!sth2)
> continue;
> long block of code;
> }
> }

I think change in udf_load_partdesc() should be done differently (see
comment below) but otherwise the patch is fine.

>
> Signed-off-by: Marcin Slusarz <[email protected]>
> Cc: Jan Kara <[email protected]>
> ---
> fs/udf/super.c | 519 ++++++++++++++++++++++++++++----------------------------
> 1 files changed, 259 insertions(+), 260 deletions(-)
>
> diff --git a/fs/udf/super.c b/fs/udf/super.c
> index 3a7faad..b622d4c 100644
> --- a/fs/udf/super.c
> +++ b/fs/udf/super.c

> @@ -798,18 +798,18 @@ static void udf_find_anchor(struct super_block *sb)
> }
>
> for (i = 0; i < ARRAY_SIZE(sbi->s_anchor); i++) {
> - if (sbi->s_anchor[i]) {
> - bh = udf_read_tagged(sb, sbi->s_anchor[i],
> - sbi->s_anchor[i], &ident);
> - if (!bh)
> + if (!sbi->s_anchor[i])
> + continue;
> + bh = udf_read_tagged(sb, sbi->s_anchor[i],
> + sbi->s_anchor[i], &ident);
> + if (!bh)
> + sbi->s_anchor[i] = 0;
> + else {
> + brelse(bh);
> + if ((ident != TAG_IDENT_AVDP) &&
> + (i || (ident != TAG_IDENT_FE &&
> + ident != TAG_IDENT_EFE)))
> sbi->s_anchor[i] = 0;
> - else {
> - brelse(bh);
> - if ((ident != TAG_IDENT_AVDP) &&
> - (i || (ident != TAG_IDENT_FE &&
> - ident != TAG_IDENT_EFE)))
> - sbi->s_anchor[i] = 0;
> - }
> }
> }
>
> @@ -1001,108 +1001,108 @@ static int udf_load_partdesc(struct super_block *sb, struct buffer_head *bh)
> sbi = UDF_SB(sb);
>
Actually, the loop below would be even more readable it you did:

if (map->s_partition_num == le16_to_cpu(p->partitionNumber))
break;
And do the work after we exit from the loop.


> for (i = 0; i < sbi->s_partitions; i++) {
> + struct partitionHeaderDesc *phd;
> +
> map = &sbi->s_partmaps[i];
> udf_debug("Searching map: (%d == %d)\n",
> map->s_partition_num,
> le16_to_cpu(p->partitionNumber));
> - if (map->s_partition_num ==
> - le16_to_cpu(p->partitionNumber)) {
> - map->s_partition_len =
> - le32_to_cpu(p->partitionLength); /* blocks */
> - map->s_partition_root =
> - le32_to_cpu(p->partitionStartingLocation);
> - if (p->accessType ==
> - cpu_to_le32(PD_ACCESS_TYPE_READ_ONLY))
> - map->s_partition_flags |=
> - UDF_PART_FLAG_READ_ONLY;
> - if (p->accessType ==
> - cpu_to_le32(PD_ACCESS_TYPE_WRITE_ONCE))
> - map->s_partition_flags |=
> - UDF_PART_FLAG_WRITE_ONCE;
> - if (p->accessType ==
> - cpu_to_le32(PD_ACCESS_TYPE_REWRITABLE))
> + if (map->s_partition_num !=
> + le16_to_cpu(p->partitionNumber))
> + continue;
> +
> + map->s_partition_len =
> + le32_to_cpu(p->partitionLength); /* blocks */
> + map->s_partition_root =
> + le32_to_cpu(p->partitionStartingLocation);
> + if (p->accessType == cpu_to_le32(PD_ACCESS_TYPE_READ_ONLY))
> + map->s_partition_flags |= UDF_PART_FLAG_READ_ONLY;
> + if (p->accessType == cpu_to_le32(PD_ACCESS_TYPE_WRITE_ONCE))
> + map->s_partition_flags |= UDF_PART_FLAG_WRITE_ONCE;
> + if (p->accessType == cpu_to_le32(PD_ACCESS_TYPE_REWRITABLE))
> + map->s_partition_flags |= UDF_PART_FLAG_REWRITABLE;
> + if (p->accessType == cpu_to_le32(PD_ACCESS_TYPE_OVERWRITABLE))
> + map->s_partition_flags |= UDF_PART_FLAG_OVERWRITABLE;
> +
> + if (strcmp(p->partitionContents.ident,
> + PD_PARTITION_CONTENTS_NSR02) &&
> + strcmp(p->partitionContents.ident,
> + PD_PARTITION_CONTENTS_NSR03))
> + break;
> +
> + phd = (struct partitionHeaderDesc *)
> + (p->partitionContentsUse);
> + if (phd->unallocSpaceTable.extLength) {
> + kernel_lb_addr loc = {
> + .logicalBlockNum = le32_to_cpu(
> + phd->unallocSpaceTable.extPosition),
> + .partitionReferenceNum = i,
> + };
> +
> + map->s_uspace.s_table =
> + udf_iget(sb, loc);
> + if (!map->s_uspace.s_table) {
> + udf_debug("cannot load unallocSpaceTable "
> + "(part %d)\n", i);
> + return 1;
> + }
> + map->s_partition_flags |=
> + UDF_PART_FLAG_UNALLOC_TABLE;
> + udf_debug("unallocSpaceTable (part %d) @ %ld\n",
> + i, map->s_uspace.s_table->i_ino);
> + }
> + if (phd->unallocSpaceBitmap.extLength) {
> + struct udf_bitmap *bitmap =
> + udf_sb_alloc_bitmap(sb, i);
> + map->s_uspace.s_bitmap = bitmap;
> + if (bitmap != NULL) {
> + bitmap->s_extLength = le32_to_cpu(
> + phd->unallocSpaceBitmap.extLength);
> + bitmap->s_extPosition = le32_to_cpu(
> + phd->unallocSpaceBitmap.extPosition);
> map->s_partition_flags |=
> - UDF_PART_FLAG_REWRITABLE;
> - if (p->accessType ==
> - cpu_to_le32(PD_ACCESS_TYPE_OVERWRITABLE))
> + UDF_PART_FLAG_UNALLOC_BITMAP;
> + udf_debug("unallocSpaceBitmap (part %d) @ %d\n",
> + i, bitmap->s_extPosition);
> + }
> + }
> + if (phd->partitionIntegrityTable.extLength)
> + udf_debug("partitionIntegrityTable (part %d)\n", i);
> + if (phd->freedSpaceTable.extLength) {
> + kernel_lb_addr loc = {
> + .logicalBlockNum = le32_to_cpu(
> + phd->freedSpaceTable.extPosition),
> + .partitionReferenceNum = i,
> + };
> +
> + map->s_fspace.s_table =
> + udf_iget(sb, loc);
> + if (!map->s_fspace.s_table) {
> + udf_debug("cannot load freedSpaceTable "
> + "(part %d)\n", i);
> + return 1;
> + }
> + map->s_partition_flags |=
> + UDF_PART_FLAG_FREED_TABLE;
> + udf_debug("freedSpaceTable (part %d) @ %ld\n",
> + i, map->s_fspace.s_table->i_ino);
> + }
> + if (phd->freedSpaceBitmap.extLength) {
> + struct udf_bitmap *bitmap =
> + udf_sb_alloc_bitmap(sb, i);
> + map->s_fspace.s_bitmap = bitmap;
> + if (bitmap != NULL) {
> + bitmap->s_extLength = le32_to_cpu(
> + phd->freedSpaceBitmap.extLength);
> + bitmap->s_extPosition = le32_to_cpu(
> + phd->freedSpaceBitmap.extPosition);
> map->s_partition_flags |=
> - UDF_PART_FLAG_OVERWRITABLE;
> -
> - if (!strcmp(p->partitionContents.ident,
> - PD_PARTITION_CONTENTS_NSR02) ||
> - !strcmp(p->partitionContents.ident,
> - PD_PARTITION_CONTENTS_NSR03)) {
> - struct partitionHeaderDesc *phd;
> -
> - phd = (struct partitionHeaderDesc *)
> - (p->partitionContentsUse);
> - if (phd->unallocSpaceTable.extLength) {
> - kernel_lb_addr loc = {
> - .logicalBlockNum = le32_to_cpu(phd->unallocSpaceTable.extPosition),
> - .partitionReferenceNum = i,
> - };
> -
> - map->s_uspace.s_table =
> - udf_iget(sb, loc);
> - if (!map->s_uspace.s_table) {
> - udf_debug("cannot load unallocSpaceTable (part %d)\n", i);
> - return 1;
> - }
> - map->s_partition_flags |=
> - UDF_PART_FLAG_UNALLOC_TABLE;
> - udf_debug("unallocSpaceTable (part %d) @ %ld\n",
> - i, map->s_uspace.s_table->i_ino);
> - }
> - if (phd->unallocSpaceBitmap.extLength) {
> - struct udf_bitmap *bitmap =
> - udf_sb_alloc_bitmap(sb, i);
> - map->s_uspace.s_bitmap = bitmap;
> - if (bitmap != NULL) {
> - bitmap->s_extLength =
> - le32_to_cpu(phd->unallocSpaceBitmap.extLength);
> - bitmap->s_extPosition =
> - le32_to_cpu(phd->unallocSpaceBitmap.extPosition);
> - map->s_partition_flags |= UDF_PART_FLAG_UNALLOC_BITMAP;
> - udf_debug("unallocSpaceBitmap (part %d) @ %d\n",
> - i, bitmap->s_extPosition);
> - }
> - }
> - if (phd->partitionIntegrityTable.extLength)
> - udf_debug("partitionIntegrityTable (part %d)\n", i);
> - if (phd->freedSpaceTable.extLength) {
> - kernel_lb_addr loc = {
> - .logicalBlockNum = le32_to_cpu(phd->freedSpaceTable.extPosition),
> - .partitionReferenceNum = i,
> - };
> -
> - map->s_fspace.s_table =
> - udf_iget(sb, loc);
> - if (!map->s_fspace.s_table) {
> - udf_debug("cannot load freedSpaceTable (part %d)\n", i);
> - return 1;
> - }
> - map->s_partition_flags |=
> - UDF_PART_FLAG_FREED_TABLE;
> - udf_debug("freedSpaceTable (part %d) @ %ld\n",
> - i, map->s_fspace.s_table->i_ino);
> - }
> - if (phd->freedSpaceBitmap.extLength) {
> - struct udf_bitmap *bitmap =
> - udf_sb_alloc_bitmap(sb, i);
> - map->s_fspace.s_bitmap = bitmap;
> - if (bitmap != NULL) {
> - bitmap->s_extLength =
> - le32_to_cpu(phd->freedSpaceBitmap.extLength);
> - bitmap->s_extPosition =
> - le32_to_cpu(phd->freedSpaceBitmap.extPosition);
> - map->s_partition_flags |= UDF_PART_FLAG_FREED_BITMAP;
> - udf_debug("freedSpaceBitmap (part %d) @ %d\n",
> - i, bitmap->s_extPosition);
> - }
> - }
> + UDF_PART_FLAG_FREED_BITMAP;
> + udf_debug("freedSpaceBitmap (part %d) @ %d\n",
> + i, bitmap->s_extPosition);
> }
> - break;
> }
> + break;
> }
> if (i == sbi->s_partitions)
> udf_debug("Partition (%d) not found in partition map\n",
> @@ -1187,19 +1187,17 @@ static int udf_load_logicalvol(struct super_block *sb, struct buffer_head *bh,
> map->s_type_specific.s_sparing.
> s_spar_map[j] = bh2;
>
> - if (bh2 != NULL) {
> - st = (struct sparingTable *)
> - bh2->b_data;
> - if (ident != 0 || strncmp(
> - st->sparingIdent.ident,
> - UDF_ID_SPARING,
> - strlen(UDF_ID_SPARING))) {
> - brelse(bh2);
> - map->s_type_specific.
> - s_sparing.
> - s_spar_map[j] =
> - NULL;
> - }
> + if (bh2 == NULL)
> + continue;
> +
> + st = (struct sparingTable *)bh2->b_data;
> + if (ident != 0 || strncmp(
> + st->sparingIdent.ident,
> + UDF_ID_SPARING,
> + strlen(UDF_ID_SPARING))) {
> + brelse(bh2);
> + map->s_type_specific.s_sparing.
> + s_spar_map[j] = NULL;
> }
> }
> map->s_partition_func = udf_get_pblock_spar15;
> @@ -1364,40 +1362,40 @@ static int udf_process_sequence(struct super_block *sb, long block,
> brelse(bh);
> }
> for (i = 0; i < VDS_POS_LENGTH; i++) {
> - if (vds[i].block) {
> - bh = udf_read_tagged(sb, vds[i].block, vds[i].block,
> - &ident);
> -
> - if (i == VDS_POS_PRIMARY_VOL_DESC) {
> - udf_load_pvoldesc(sb, bh);
> - } else if (i == VDS_POS_LOGICAL_VOL_DESC) {
> - if (udf_load_logicalvol(sb, bh, fileset)) {
> - brelse(bh);
> - return 1;
> - }
> - } else if (i == VDS_POS_PARTITION_DESC) {
> - struct buffer_head *bh2 = NULL;
> - if (udf_load_partdesc(sb, bh)) {
> - brelse(bh);
> - return 1;
> - }
> - for (j = vds[i].block + 1;
> - j < vds[VDS_POS_TERMINATING_DESC].block;
> - j++) {
> - bh2 = udf_read_tagged(sb, j, j, &ident);
> - gd = (struct generic_desc *)bh2->b_data;
> - if (ident == TAG_IDENT_PD)
> - if (udf_load_partdesc(sb,
> - bh2)) {
> - brelse(bh);
> - brelse(bh2);
> - return 1;
> - }
> - brelse(bh2);
> - }
> + if (!vds[i].block)
> + continue;
> +
> + bh = udf_read_tagged(sb, vds[i].block, vds[i].block,
> + &ident);
> +
> + if (i == VDS_POS_PRIMARY_VOL_DESC)
> + udf_load_pvoldesc(sb, bh);
> + else if (i == VDS_POS_LOGICAL_VOL_DESC) {
> + if (udf_load_logicalvol(sb, bh, fileset)) {
> + brelse(bh);
> + return 1;
> + }
> + } else if (i == VDS_POS_PARTITION_DESC) {
> + struct buffer_head *bh2 = NULL;
> + if (udf_load_partdesc(sb, bh)) {
> + brelse(bh);
> + return 1;
> + }
> + for (j = vds[i].block + 1;
> + j < vds[VDS_POS_TERMINATING_DESC].block;
> + j++) {
> + bh2 = udf_read_tagged(sb, j, j, &ident);
> + gd = (struct generic_desc *)bh2->b_data;
> + if (ident == TAG_IDENT_PD)
> + if (udf_load_partdesc(sb, bh2)) {
> + brelse(bh);
> + brelse(bh2);
> + return 1;
> + }
> + brelse(bh2);
> }
> - brelse(bh);
> }
> + brelse(bh);
> }
>
> return 0;
> @@ -1409,6 +1407,7 @@ static int udf_process_sequence(struct super_block *sb, long block,
> static int udf_check_valid(struct super_block *sb, int novrs, int silent)
> {
> long block;
> + struct udf_sb_info *sbi;
>
> if (novrs) {
> udf_debug("Validity check skipped because of novrs option\n");
> @@ -1416,18 +1415,16 @@ static int udf_check_valid(struct super_block *sb, int novrs, int silent)
> }
> /* Check that it is NSR02 compliant */
> /* Process any "CD-ROM Volume Descriptor Set" (ECMA 167 2/8.3.1) */
> - else {
> - block = udf_vrs(sb, silent);
> - if (block == -1) {
> - struct udf_sb_info *sbi = UDF_SB(sb);
> - udf_debug("Failed to read byte 32768. Assuming open "
> - "disc. Skipping validity check\n");
> - if (!sbi->s_last_block)
> - sbi->s_last_block = udf_get_last_block(sb);
> - return 0;
> - } else
> - return !block;
> - }
> + block = udf_vrs(sb, silent);
> + if (block != -1)
> + return !block;
> +
> + sbi = UDF_SB(sb);
> + udf_debug("Failed to read byte 32768. Assuming open "
> + "disc. Skipping validity check\n");
> + if (!sbi->s_last_block)
> + sbi->s_last_block = udf_get_last_block(sb);
> + return 0;
> }
>
> static int udf_load_partition(struct super_block *sb, kernel_lb_addr *fileset)
> @@ -1446,6 +1443,7 @@ static int udf_load_partition(struct super_block *sb, kernel_lb_addr *fileset)
> for (i = 0; i < ARRAY_SIZE(sbi->s_anchor); i++) {
> if (!sbi->s_anchor[i])
> continue;
> +
> bh = udf_read_tagged(sb, sbi->s_anchor[i], sbi->s_anchor[i],
> &ident);
> if (!bh)
> @@ -1487,72 +1485,73 @@ static int udf_load_partition(struct super_block *sb, kernel_lb_addr *fileset)
> for (i = 0; i < sbi->s_partitions; i++) {
> kernel_lb_addr uninitialized_var(ino);
> struct udf_part_map *map = &sbi->s_partmaps[i];
> - switch (map->s_partition_type) {
> - case UDF_VIRTUAL_MAP15:
> - case UDF_VIRTUAL_MAP20:
> - if (!sbi->s_last_block) {
> - sbi->s_last_block = udf_get_last_block(sb);
> - udf_find_anchor(sb);
> - }
>
> - if (!sbi->s_last_block) {
> - udf_debug("Unable to determine Lastblock (For "
> - "Virtual Partition)\n");
> - return 1;
> - }
> + if (map->s_partition_type != UDF_VIRTUAL_MAP15 &&
> + map->s_partition_type != UDF_VIRTUAL_MAP20)
> + continue;
>
> - for (j = 0; j < sbi->s_partitions; j++) {
> - struct udf_part_map *map2 = &sbi->s_partmaps[j];
> - if (j != i &&
> - map->s_volumeseqnum ==
> - map2->s_volumeseqnum &&
> - map->s_partition_num ==
> - map2->s_partition_num) {
> - ino.partitionReferenceNum = j;
> - ino.logicalBlockNum =
> - sbi->s_last_block -
> - map2->s_partition_root;
> - break;
> - }
> + if (!sbi->s_last_block) {
> + sbi->s_last_block = udf_get_last_block(sb);
> + udf_find_anchor(sb);
> + }
> +
> + if (!sbi->s_last_block) {
> + udf_debug("Unable to determine Lastblock (For "
> + "Virtual Partition)\n");
> + return 1;
> + }
> +
> + for (j = 0; j < sbi->s_partitions; j++) {
> + struct udf_part_map *map2 = &sbi->s_partmaps[j];
> + if (j != i &&
> + map->s_volumeseqnum ==
> + map2->s_volumeseqnum &&
> + map->s_partition_num ==
> + map2->s_partition_num) {
> + ino.partitionReferenceNum = j;
> + ino.logicalBlockNum =
> + sbi->s_last_block -
> + map2->s_partition_root;
> + break;
> }
> + }
>
> - if (j == sbi->s_partitions)
> - return 1;
> + if (j == sbi->s_partitions)
> + return 1;
>
> - sbi->s_vat_inode = udf_iget(sb, ino);
> - if (!sbi->s_vat_inode)
> - return 1;
> + sbi->s_vat_inode = udf_iget(sb, ino);
> + if (!sbi->s_vat_inode)
> + return 1;
>
> - if (map->s_partition_type == UDF_VIRTUAL_MAP15) {
> - map->s_type_specific.s_virtual.s_start_offset =
> - udf_ext0_offset(sbi->s_vat_inode);
> - map->s_type_specific.s_virtual.s_num_entries =
> - (sbi->s_vat_inode->i_size - 36) >> 2;
> - } else if (map->s_partition_type == UDF_VIRTUAL_MAP20) {
> - uint32_t pos;
> - struct virtualAllocationTable20 *vat20;
> -
> - pos = udf_block_map(sbi->s_vat_inode, 0);
> - bh = sb_bread(sb, pos);
> - if (!bh)
> - return 1;
> - vat20 = (struct virtualAllocationTable20 *)
> - bh->b_data +
> - udf_ext0_offset(sbi->s_vat_inode);
> - map->s_type_specific.s_virtual.s_start_offset =
> - le16_to_cpu(vat20->lengthHeader) +
> - udf_ext0_offset(sbi->s_vat_inode);
> - map->s_type_specific.s_virtual.s_num_entries =
> - (sbi->s_vat_inode->i_size -
> - map->s_type_specific.s_virtual.
> - s_start_offset) >> 2;
> - brelse(bh);
> - }
> - map->s_partition_root = udf_get_pblock(sb, 0, i, 0);
> - map->s_partition_len =
> - sbi->s_partmaps[ino.partitionReferenceNum].
> - s_partition_len;
> + if (map->s_partition_type == UDF_VIRTUAL_MAP15) {
> + map->s_type_specific.s_virtual.s_start_offset =
> + udf_ext0_offset(sbi->s_vat_inode);
> + map->s_type_specific.s_virtual.s_num_entries =
> + (sbi->s_vat_inode->i_size - 36) >> 2;
> + } else if (map->s_partition_type == UDF_VIRTUAL_MAP20) {
> + uint32_t pos;
> + struct virtualAllocationTable20 *vat20;
> +
> + pos = udf_block_map(sbi->s_vat_inode, 0);
> + bh = sb_bread(sb, pos);
> + if (!bh)
> + return 1;
> + vat20 = (struct virtualAllocationTable20 *)
> + bh->b_data +
> + udf_ext0_offset(sbi->s_vat_inode);
> + map->s_type_specific.s_virtual.s_start_offset =
> + le16_to_cpu(vat20->lengthHeader) +
> + udf_ext0_offset(sbi->s_vat_inode);
> + map->s_type_specific.s_virtual.s_num_entries =
> + (sbi->s_vat_inode->i_size -
> + map->s_type_specific.s_virtual.
> + s_start_offset) >> 2;
> + brelse(bh);
> }
> + map->s_partition_root = udf_get_pblock(sb, 0, i, 0);
> + map->s_partition_len =
> + sbi->s_partmaps[ino.partitionReferenceNum].
> + s_partition_len;
> }
> return 0;
> }
> @@ -1561,25 +1560,25 @@ static void udf_open_lvid(struct super_block *sb)
> {
> struct udf_sb_info *sbi = UDF_SB(sb);
> struct buffer_head *bh = sbi->s_lvid_bh;
> - if (bh) {
> - struct logicalVolIntegrityDesc *lvid =
> - (struct logicalVolIntegrityDesc *)bh->b_data;
> - struct logicalVolIntegrityDescImpUse *lvidiu =
> - udf_sb_lvidiu(sbi);
> + struct logicalVolIntegrityDesc *lvid;
> + struct logicalVolIntegrityDescImpUse *lvidiu;
> + if (!bh)
> + return;
>
> - lvidiu->impIdent.identSuffix[0] = UDF_OS_CLASS_UNIX;
> - lvidiu->impIdent.identSuffix[1] = UDF_OS_ID_LINUX;
> - udf_time_to_stamp(&lvid->recordingDateAndTime, CURRENT_TIME);
> - lvid->integrityType = LVID_INTEGRITY_TYPE_OPEN;
> + lvid = (struct logicalVolIntegrityDesc *)bh->b_data;
> + lvidiu = udf_sb_lvidiu(sbi);
>
> - lvid->descTag.descCRC = cpu_to_le16(
> - udf_crc((char *)lvid + sizeof(tag),
> - le16_to_cpu(lvid->descTag.descCRCLength),
> - 0));
> + lvidiu->impIdent.identSuffix[0] = UDF_OS_CLASS_UNIX;
> + lvidiu->impIdent.identSuffix[1] = UDF_OS_ID_LINUX;
> + udf_time_to_stamp(&lvid->recordingDateAndTime, CURRENT_TIME);
> + lvid->integrityType = LVID_INTEGRITY_TYPE_OPEN;
>
> - lvid->descTag.tagChecksum = udf_tag_checksum(&lvid->descTag);
> - mark_buffer_dirty(bh);
> - }
> + lvid->descTag.descCRC = cpu_to_le16(
> + udf_crc((char *)lvid + sizeof(tag),
> + le16_to_cpu(lvid->descTag.descCRCLength), 0));
> +
> + lvid->descTag.tagChecksum = udf_tag_checksum(&lvid->descTag);
> + mark_buffer_dirty(bh);
> }
>
> static void udf_close_lvid(struct super_block *sb)
> @@ -1587,35 +1586,35 @@ static void udf_close_lvid(struct super_block *sb)
> struct udf_sb_info *sbi = UDF_SB(sb);
> struct buffer_head *bh = sbi->s_lvid_bh;
> struct logicalVolIntegrityDesc *lvid;
> + struct logicalVolIntegrityDescImpUse *lvidiu;
>
> if (!bh)
> return;
>
> lvid = (struct logicalVolIntegrityDesc *)bh->b_data;
>
> - if (lvid->integrityType == LVID_INTEGRITY_TYPE_OPEN) {
> - struct logicalVolIntegrityDescImpUse *lvidiu =
> - udf_sb_lvidiu(sbi);
> - lvidiu->impIdent.identSuffix[0] = UDF_OS_CLASS_UNIX;
> - lvidiu->impIdent.identSuffix[1] = UDF_OS_ID_LINUX;
> - udf_time_to_stamp(&lvid->recordingDateAndTime, CURRENT_TIME);
> - if (UDF_MAX_WRITE_VERSION > le16_to_cpu(lvidiu->maxUDFWriteRev))
> - lvidiu->maxUDFWriteRev =
> - cpu_to_le16(UDF_MAX_WRITE_VERSION);
> - if (sbi->s_udfrev > le16_to_cpu(lvidiu->minUDFReadRev))
> - lvidiu->minUDFReadRev = cpu_to_le16(sbi->s_udfrev);
> - if (sbi->s_udfrev > le16_to_cpu(lvidiu->minUDFWriteRev))
> - lvidiu->minUDFWriteRev = cpu_to_le16(sbi->s_udfrev);
> - lvid->integrityType = cpu_to_le32(LVID_INTEGRITY_TYPE_CLOSE);
> -
> - lvid->descTag.descCRC = cpu_to_le16(
> - udf_crc((char *)lvid + sizeof(tag),
> - le16_to_cpu(lvid->descTag.descCRCLength),
> - 0));
> -
> - lvid->descTag.tagChecksum = udf_tag_checksum(&lvid->descTag);
> - mark_buffer_dirty(bh);
> - }
> + if (lvid->integrityType != LVID_INTEGRITY_TYPE_OPEN)
> + return;
> +
> + lvidiu = udf_sb_lvidiu(sbi);
> + lvidiu->impIdent.identSuffix[0] = UDF_OS_CLASS_UNIX;
> + lvidiu->impIdent.identSuffix[1] = UDF_OS_ID_LINUX;
> + udf_time_to_stamp(&lvid->recordingDateAndTime, CURRENT_TIME);
> + if (UDF_MAX_WRITE_VERSION > le16_to_cpu(lvidiu->maxUDFWriteRev))
> + lvidiu->maxUDFWriteRev = cpu_to_le16(UDF_MAX_WRITE_VERSION);
> + if (sbi->s_udfrev > le16_to_cpu(lvidiu->minUDFReadRev))
> + lvidiu->minUDFReadRev = cpu_to_le16(sbi->s_udfrev);
> + if (sbi->s_udfrev > le16_to_cpu(lvidiu->minUDFWriteRev))
> + lvidiu->minUDFWriteRev = cpu_to_le16(sbi->s_udfrev);
> + lvid->integrityType = cpu_to_le32(LVID_INTEGRITY_TYPE_CLOSE);
> +
> + lvid->descTag.descCRC = cpu_to_le16(
> + udf_crc((char *)lvid + sizeof(tag),
> + le16_to_cpu(lvid->descTag.descCRCLength),
> + 0));
> +
> + lvid->descTag.tagChecksum = udf_tag_checksum(&lvid->descTag);
> + mark_buffer_dirty(bh);
> }
>
> static void udf_sb_free_bitmap(struct udf_bitmap *bitmap)
> --
> 1.5.3.7
>
Honza
--
Jan Kara <[email protected]>
SUSE Labs, CR

2008-02-05 19:12:56

by Marcin Ślusarz

[permalink] [raw]
Subject: Re: [PATCH 3/6] udf: convert udf_stamp_to_time to return struct timespec

On Tue, Feb 05, 2008 at 04:48:31PM +0100, Jan Kara wrote:
>
> Uh, oh. I guess you somehow mangled the ordering of patches. In this
> patch you revert what you've done in the previous patch. Otherwise I agree
> with the idea of the change...
No, the ordering is ok. Creation of udf_fill_inode_time was an intermediate
state in this cleanup. Every step is obvious and easy. When I tried to create
just one patch it didn't look so obvious, so I decided to send it in 4 parts.

>
> On Sun 03-02-08 19:36:08, [email protected] wrote:
> > Signed-off-by: Marcin Slusarz <[email protected]>
> > Cc: Jan Kara <[email protected]>
> > ---
> > fs/udf/inode.c | 49 ++++++++++++++++++++++++++-----------------------
> > fs/udf/super.c | 9 ++-------
> > fs/udf/udfdecl.h | 4 ++--
> > fs/udf/udftime.c | 17 +++++++----------
> > 4 files changed, 37 insertions(+), 42 deletions(-)
> >
> > diff --git a/fs/udf/inode.c b/fs/udf/inode.c
> > index 2578677..252efe0 100644
> > --- a/fs/udf/inode.c
> > +++ b/fs/udf/inode.c
> > @@ -1151,20 +1151,6 @@ static void __udf_read_inode(struct inode *inode)
> > brelse(bh);
> > }
> >
> > -static void udf_fill_inode_time(struct timespec *tspec,
> > - const timestamp *tstamp,
> > - struct udf_sb_info *sbi)
> > -{
> > - time_t convtime;
> > - long convtime_usec;
> > - if (udf_stamp_to_time(&convtime, &convtime_usec,
> > - lets_to_cpu(*tstamp))) {
> > - tspec->tv_sec = convtime;
> > - tspec->tv_nsec = convtime_usec * 1000;
> > - } else
> > - *tspec = sbi->s_record_time;
> > -}
> > -
>
> > static void udf_fill_inode(struct inode *inode, struct buffer_head *bh)
> > {
> > struct fileEntry *fe;
> > @@ -1256,10 +1242,17 @@ static void udf_fill_inode(struct inode *inode, struct buffer_head *bh)
> > inode->i_blocks = le64_to_cpu(fe->logicalBlocksRecorded) <<
> > (inode->i_sb->s_blocksize_bits - 9);
> >
> > - udf_fill_inode_time(&inode->i_atime, &fe->accessTime, sbi);
> > - udf_fill_inode_time(&inode->i_mtime, &fe->modificationTime,
> > - sbi);
> > - udf_fill_inode_time(&inode->i_ctime, &fe->attrTime, sbi);
> > + if (!udf_stamp_to_time(&inode->i_atime,
> > + lets_to_cpu(fe->accessTime)))
> > + inode->i_atime = sbi->s_record_time;
> > +
> > + if (!udf_stamp_to_time(&inode->i_mtime,
> > + lets_to_cpu(fe->modificationTime)))
> > + inode->i_mtime = sbi->s_record_time;
> > +
> > + if (!udf_stamp_to_time(&inode->i_ctime,
> > + lets_to_cpu(fe->attrTime)))
> > + inode->i_ctime = sbi->s_record_time;
> >
> > iinfo->i_unique = le64_to_cpu(fe->uniqueID);
> > iinfo->i_lenEAttr = le32_to_cpu(fe->lengthExtendedAttr);
> > @@ -1269,11 +1262,21 @@ static void udf_fill_inode(struct inode *inode, struct buffer_head *bh)
> > inode->i_blocks = le64_to_cpu(efe->logicalBlocksRecorded) <<
> > (inode->i_sb->s_blocksize_bits - 9);
> >
> > - udf_fill_inode_time(&inode->i_atime, &efe->accessTime, sbi);
> > - udf_fill_inode_time(&inode->i_mtime, &efe->modificationTime,
> > - sbi);
> > - udf_fill_inode_time(&iinfo->i_crtime, &efe->createTime, sbi);
> > - udf_fill_inode_time(&inode->i_ctime, &efe->attrTime, sbi);
> > + if (!udf_stamp_to_time(&inode->i_atime,
> > + lets_to_cpu(efe->accessTime)))
> > + inode->i_atime = sbi->s_record_time;
> > +
> > + if (!udf_stamp_to_time(&inode->i_mtime,
> > + lets_to_cpu(efe->modificationTime)))
> > + inode->i_mtime = sbi->s_record_time;
> > +
> > + if (!udf_stamp_to_time(&iinfo->i_crtime,
> > + lets_to_cpu(efe->createTime)))
> > + iinfo->i_crtime = sbi->s_record_time;
> > +
> > + if (!udf_stamp_to_time(&inode->i_ctime,
> > + lets_to_cpu(efe->attrTime)))
> > + inode->i_ctime = sbi->s_record_time;
> >
> > iinfo->i_unique = le64_to_cpu(efe->uniqueID);
> > iinfo->i_lenEAttr = le32_to_cpu(efe->lengthExtendedAttr);
> > diff --git a/fs/udf/super.c b/fs/udf/super.c
> > index 0dcee12..9f565a9 100644
> > --- a/fs/udf/super.c
> > +++ b/fs/udf/super.c
> > @@ -909,24 +909,19 @@ static int udf_find_fileset(struct super_block *sb,
> > static void udf_load_pvoldesc(struct super_block *sb, struct buffer_head *bh)
> > {
> > struct primaryVolDesc *pvoldesc;
> > - time_t recording;
> > - long recording_usec;
> > struct ustr instr;
> > struct ustr outstr;
> >
> > pvoldesc = (struct primaryVolDesc *)bh->b_data;
> >
> > - if (udf_stamp_to_time(&recording, &recording_usec,
> > + if (udf_stamp_to_time(&UDF_SB(sb)->s_record_time,
> > lets_to_cpu(pvoldesc->recordingDateAndTime))) {
> > kernel_timestamp ts;
> > ts = lets_to_cpu(pvoldesc->recordingDateAndTime);
> > - udf_debug("recording time %ld/%ld, %04u/%02u/%02u"
> > + udf_debug("recording time %04u/%02u/%02u"
> > " %02u:%02u (%x)\n",
> > - recording, recording_usec,
> > ts.year, ts.month, ts.day, ts.hour,
> > ts.minute, ts.typeAndTimezone);
> > - UDF_SB(sb)->s_record_time.tv_sec = recording;
> > - UDF_SB(sb)->s_record_time.tv_nsec = recording_usec * 1000;
> > }
> >
> > if (!udf_build_ustr(&instr, pvoldesc->volIdent, 32))
> > diff --git a/fs/udf/udfdecl.h b/fs/udf/udfdecl.h
> > index 375be1b..508be85 100644
> > --- a/fs/udf/udfdecl.h
> > +++ b/fs/udf/udfdecl.h
> > @@ -204,7 +204,7 @@ extern short_ad *udf_get_fileshortad(uint8_t *, int, uint32_t *, int);
> > extern uint16_t udf_crc(const uint8_t *, uint32_t, uint16_t);
> >
> > /* udftime.c */
> > -extern time_t *udf_stamp_to_time(time_t *, long *, kernel_timestamp);
> > -extern kernel_timestamp *udf_time_to_stamp(kernel_timestamp *, struct timespec);
> > +extern struct timespec *udf_stamp_to_time(struct timespec *dest, kernel_timestamp src);
> > +extern kernel_timestamp *udf_time_to_stamp(kernel_timestamp *dest, struct timespec src);
> >
> > #endif /* __UDF_DECL_H */
> > diff --git a/fs/udf/udftime.c b/fs/udf/udftime.c
> > index ce59573..12fae6c 100644
> > --- a/fs/udf/udftime.c
> > +++ b/fs/udf/udftime.c
> > @@ -85,7 +85,7 @@ extern struct timezone sys_tz;
> > #define SECS_PER_HOUR (60 * 60)
> > #define SECS_PER_DAY (SECS_PER_HOUR * 24)
> >
> > -time_t *udf_stamp_to_time(time_t *dest, long *dest_usec, kernel_timestamp src)
> > +struct timespec *udf_stamp_to_time(struct timespec *dest, kernel_timestamp src)
> > {
> > int yday;
> > uint8_t type = src.typeAndTimezone >> 12;
> > @@ -97,23 +97,20 @@ time_t *udf_stamp_to_time(time_t *dest, long *dest_usec, kernel_timestamp src)
> > offset = (offset >> 4);
> > if (offset == -2047) /* unspecified offset */
> > offset = 0;
> > - } else {
> > + } else
> > offset = 0;
> > - }
> >
> > if ((src.year < EPOCH_YEAR) ||
> > (src.year >= EPOCH_YEAR + MAX_YEAR_SECONDS)) {
> > - *dest = -1;
> > - *dest_usec = -1;
> > return NULL;
> > }
> > - *dest = year_seconds[src.year - EPOCH_YEAR];
> > - *dest -= offset * 60;
> > + dest->tv_sec = year_seconds[src.year - EPOCH_YEAR];
> > + dest->tv_sec -= offset * 60;
> >
> > yday = ((__mon_yday[__isleap(src.year)][src.month - 1]) + src.day - 1);
> > - *dest += (((yday * 24) + src.hour) * 60 + src.minute) * 60 + src.second;
> > - *dest_usec = src.centiseconds * 10000 +
> > - src.hundredsOfMicroseconds * 100 + src.microseconds;
> > + dest->tv_sec += (((yday * 24) + src.hour) * 60 + src.minute) * 60 + src.second;
> > + dest->tv_nsec = 1000 * (src.centiseconds * 10000 +
> > + src.hundredsOfMicroseconds * 100 + src.microseconds);
> > return dest;
> > }
> >
> > --
> > 1.5.3.7
>
> Honza
> --
> Jan Kara <[email protected]>
> SUSE Labs, CR

2008-02-05 19:29:31

by Marcin Ślusarz

[permalink] [raw]
Subject: Re: [PATCH 4/6] udf: convert udf_stamp_to_time and udf_time_to_stamp to use timestamps

On Tue, Feb 05, 2008 at 04:59:56PM +0100, Jan Kara wrote:
> On Sun 03-02-08 19:36:09, [email protected] wrote:
> > kernel_timestamp type was almost unused - only callers of udf_stamp_to_time
> > and udf_time_to_stamp used it, so let these functions handle endianness
> > internally and don't clutter code with conversions
> OK, but please also rename the functions to something like
> udf_disk_stamp_to_time() and udf_time_to_disk_stamp() so that the name
> suggests that it internally handles endianess...
Ok, should I redo this patch or create separate patch on top of it?

Marcin

2008-02-05 19:35:42

by Marcin Ślusarz

[permalink] [raw]
Subject: Re: [PATCH 6/6] udf: super.c reorganization

On Tue, Feb 05, 2008 at 05:22:19PM +0100, Jan Kara wrote:
> Actually, the loop below would be even more readable it you did:
>
> if (map->s_partition_num == le16_to_cpu(p->partitionNumber))
> break;
> And do the work after we exit from the loop.
>
>
> > for (i = 0; i < sbi->s_partitions; i++) {
> > + struct partitionHeaderDesc *phd;
> > +
> > map = &sbi->s_partmaps[i];
> > udf_debug("Searching map: (%d == %d)\n",
> > map->s_partition_num,
> > le16_to_cpu(p->partitionNumber));
> > - if (map->s_partition_num ==
> > - le16_to_cpu(p->partitionNumber)) {
> > - map->s_partition_len =
> > - le32_to_cpu(p->partitionLength); /* blocks */
> > - map->s_partition_root =
> > - le32_to_cpu(p->partitionStartingLocation);
> > - if (p->accessType ==
> > - cpu_to_le32(PD_ACCESS_TYPE_READ_ONLY))
> > - map->s_partition_flags |=
> > - UDF_PART_FLAG_READ_ONLY;
> > - if (p->accessType ==
> > - cpu_to_le32(PD_ACCESS_TYPE_WRITE_ONCE))
> > - map->s_partition_flags |=
> > - UDF_PART_FLAG_WRITE_ONCE;
> > - if (p->accessType ==
> > - cpu_to_le32(PD_ACCESS_TYPE_REWRITABLE))
> > + if (map->s_partition_num !=
> > + le16_to_cpu(p->partitionNumber))
> > + continue;
> > +
> > + map->s_partition_len =
> > + le32_to_cpu(p->partitionLength); /* blocks */
> > + map->s_partition_root =
> > + le32_to_cpu(p->partitionStartingLocation);
> > + if (p->accessType == cpu_to_le32(PD_ACCESS_TYPE_READ_ONLY))
> > + map->s_partition_flags |= UDF_PART_FLAG_READ_ONLY;
> > + if (p->accessType == cpu_to_le32(PD_ACCESS_TYPE_WRITE_ONCE))
> > + map->s_partition_flags |= UDF_PART_FLAG_WRITE_ONCE;
> > + if (p->accessType == cpu_to_le32(PD_ACCESS_TYPE_REWRITABLE))
> > + map->s_partition_flags |= UDF_PART_FLAG_REWRITABLE;
> > + if (p->accessType == cpu_to_le32(PD_ACCESS_TYPE_OVERWRITABLE))
> > + map->s_partition_flags |= UDF_PART_FLAG_OVERWRITABLE;
> > +
> > + if (strcmp(p->partitionContents.ident,
> > + PD_PARTITION_CONTENTS_NSR02) &&
> > + strcmp(p->partitionContents.ident,
> > + PD_PARTITION_CONTENTS_NSR03))
> > + break;
> > +
> > + phd = (struct partitionHeaderDesc *)
> > + (p->partitionContentsUse);
> > + if (phd->unallocSpaceTable.extLength) {
> > + kernel_lb_addr loc = {
> > + .logicalBlockNum = le32_to_cpu(
> > + phd->unallocSpaceTable.extPosition),
> > + .partitionReferenceNum = i,
> > + };
> > +
> > + map->s_uspace.s_table =
> > + udf_iget(sb, loc);
> > + if (!map->s_uspace.s_table) {
> > + udf_debug("cannot load unallocSpaceTable "
> > + "(part %d)\n", i);
> > + return 1;
> > + }
> > + map->s_partition_flags |=
> > + UDF_PART_FLAG_UNALLOC_TABLE;
> > + udf_debug("unallocSpaceTable (part %d) @ %ld\n",
> > + i, map->s_uspace.s_table->i_ino);
> > + }
> > + if (phd->unallocSpaceBitmap.extLength) {
> > + struct udf_bitmap *bitmap =
> > + udf_sb_alloc_bitmap(sb, i);
> > + map->s_uspace.s_bitmap = bitmap;
> > + if (bitmap != NULL) {
> > + bitmap->s_extLength = le32_to_cpu(
> > + phd->unallocSpaceBitmap.extLength);
> > + bitmap->s_extPosition = le32_to_cpu(
> > + phd->unallocSpaceBitmap.extPosition);
> > map->s_partition_flags |=
> > - UDF_PART_FLAG_REWRITABLE;
> > - if (p->accessType ==
> > - cpu_to_le32(PD_ACCESS_TYPE_OVERWRITABLE))
> > + UDF_PART_FLAG_UNALLOC_BITMAP;
> > + udf_debug("unallocSpaceBitmap (part %d) @ %d\n",
> > + i, bitmap->s_extPosition);
> > + }
> > + }
> > + if (phd->partitionIntegrityTable.extLength)
> > + udf_debug("partitionIntegrityTable (part %d)\n", i);
> > + if (phd->freedSpaceTable.extLength) {
> > + kernel_lb_addr loc = {
> > + .logicalBlockNum = le32_to_cpu(
> > + phd->freedSpaceTable.extPosition),
> > + .partitionReferenceNum = i,
> > + };
> > +
> > + map->s_fspace.s_table =
> > + udf_iget(sb, loc);
> > + if (!map->s_fspace.s_table) {
> > + udf_debug("cannot load freedSpaceTable "
> > + "(part %d)\n", i);
> > + return 1;
> > + }
> > + map->s_partition_flags |=
> > + UDF_PART_FLAG_FREED_TABLE;
> > + udf_debug("freedSpaceTable (part %d) @ %ld\n",
> > + i, map->s_fspace.s_table->i_ino);
> > + }
> > + if (phd->freedSpaceBitmap.extLength) {
> > + struct udf_bitmap *bitmap =
> > + udf_sb_alloc_bitmap(sb, i);
> > + map->s_fspace.s_bitmap = bitmap;
> > + if (bitmap != NULL) {
> > + bitmap->s_extLength = le32_to_cpu(
> > + phd->freedSpaceBitmap.extLength);
> > + bitmap->s_extPosition = le32_to_cpu(
> > + phd->freedSpaceBitmap.extPosition);
> > map->s_partition_flags |=
> > - UDF_PART_FLAG_OVERWRITABLE;
> > -
> > - if (!strcmp(p->partitionContents.ident,
> > - PD_PARTITION_CONTENTS_NSR02) ||
> > - !strcmp(p->partitionContents.ident,
> > - PD_PARTITION_CONTENTS_NSR03)) {
> > - struct partitionHeaderDesc *phd;
> > -
> > - phd = (struct partitionHeaderDesc *)
> > - (p->partitionContentsUse);
> > - if (phd->unallocSpaceTable.extLength) {
> > - kernel_lb_addr loc = {
> > - .logicalBlockNum = le32_to_cpu(phd->unallocSpaceTable.extPosition),
> > - .partitionReferenceNum = i,
> > - };
> > -
> > - map->s_uspace.s_table =
> > - udf_iget(sb, loc);
> > - if (!map->s_uspace.s_table) {
> > - udf_debug("cannot load unallocSpaceTable (part %d)\n", i);
> > - return 1;
> > - }
> > - map->s_partition_flags |=
> > - UDF_PART_FLAG_UNALLOC_TABLE;
> > - udf_debug("unallocSpaceTable (part %d) @ %ld\n",
> > - i, map->s_uspace.s_table->i_ino);
> > - }
> > - if (phd->unallocSpaceBitmap.extLength) {
> > - struct udf_bitmap *bitmap =
> > - udf_sb_alloc_bitmap(sb, i);
> > - map->s_uspace.s_bitmap = bitmap;
> > - if (bitmap != NULL) {
> > - bitmap->s_extLength =
> > - le32_to_cpu(phd->unallocSpaceBitmap.extLength);
> > - bitmap->s_extPosition =
> > - le32_to_cpu(phd->unallocSpaceBitmap.extPosition);
> > - map->s_partition_flags |= UDF_PART_FLAG_UNALLOC_BITMAP;
> > - udf_debug("unallocSpaceBitmap (part %d) @ %d\n",
> > - i, bitmap->s_extPosition);
> > - }
> > - }
> > - if (phd->partitionIntegrityTable.extLength)
> > - udf_debug("partitionIntegrityTable (part %d)\n", i);
> > - if (phd->freedSpaceTable.extLength) {
> > - kernel_lb_addr loc = {
> > - .logicalBlockNum = le32_to_cpu(phd->freedSpaceTable.extPosition),
> > - .partitionReferenceNum = i,
> > - };
> > -
> > - map->s_fspace.s_table =
> > - udf_iget(sb, loc);
> > - if (!map->s_fspace.s_table) {
> > - udf_debug("cannot load freedSpaceTable (part %d)\n", i);
> > - return 1;
> > - }
> > - map->s_partition_flags |=
> > - UDF_PART_FLAG_FREED_TABLE;
> > - udf_debug("freedSpaceTable (part %d) @ %ld\n",
> > - i, map->s_fspace.s_table->i_ino);
> > - }
> > - if (phd->freedSpaceBitmap.extLength) {
> > - struct udf_bitmap *bitmap =
> > - udf_sb_alloc_bitmap(sb, i);
> > - map->s_fspace.s_bitmap = bitmap;
> > - if (bitmap != NULL) {
> > - bitmap->s_extLength =
> > - le32_to_cpu(phd->freedSpaceBitmap.extLength);
> > - bitmap->s_extPosition =
> > - le32_to_cpu(phd->freedSpaceBitmap.extPosition);
> > - map->s_partition_flags |= UDF_PART_FLAG_FREED_BITMAP;
> > - udf_debug("freedSpaceBitmap (part %d) @ %d\n",
> > - i, bitmap->s_extPosition);
> > - }
> > - }
> > + UDF_PART_FLAG_FREED_BITMAP;
> > + udf_debug("freedSpaceBitmap (part %d) @ %d\n",
> > + i, bitmap->s_extPosition);
> > }
> > - break;
> > }
> > + break;
> > }
> > if (i == sbi->s_partitions)
> > udf_debug("Partition (%d) not found in partition map\n",

Ok. I didn't notice that. But it won't be as trivial as the rest. Separate patch?

Marcin

2008-02-06 11:09:47

by Jan Kara

[permalink] [raw]
Subject: Re: [PATCH 6/6] udf: super.c reorganization

On Tue 05-02-08 20:34:49, Marcin Slusarz wrote:
> On Tue, Feb 05, 2008 at 05:22:19PM +0100, Jan Kara wrote:
> > Actually, the loop below would be even more readable it you did:
> >
> > if (map->s_partition_num == le16_to_cpu(p->partitionNumber))
> > break;
> > And do the work after we exit from the loop.
> >
> >
> > > for (i = 0; i < sbi->s_partitions; i++) {
> > > + struct partitionHeaderDesc *phd;
> > > +
> > > map = &sbi->s_partmaps[i];
> > > udf_debug("Searching map: (%d == %d)\n",
> > > map->s_partition_num,
> > > le16_to_cpu(p->partitionNumber));
> > > - if (map->s_partition_num ==
> > > - le16_to_cpu(p->partitionNumber)) {
> > > - map->s_partition_len =
> > > - le32_to_cpu(p->partitionLength); /* blocks */
> > > - map->s_partition_root =
> > > - le32_to_cpu(p->partitionStartingLocation);
> > > - if (p->accessType ==
> > > - cpu_to_le32(PD_ACCESS_TYPE_READ_ONLY))
> > > - map->s_partition_flags |=
> > > - UDF_PART_FLAG_READ_ONLY;
> > > - if (p->accessType ==
> > > - cpu_to_le32(PD_ACCESS_TYPE_WRITE_ONCE))
> > > - map->s_partition_flags |=
> > > - UDF_PART_FLAG_WRITE_ONCE;
> > > - if (p->accessType ==
> > > - cpu_to_le32(PD_ACCESS_TYPE_REWRITABLE))
> > > + if (map->s_partition_num !=
> > > + le16_to_cpu(p->partitionNumber))
> > > + continue;
> > > +
> > > + map->s_partition_len =
> > > + le32_to_cpu(p->partitionLength); /* blocks */
> > > + map->s_partition_root =
> > > + le32_to_cpu(p->partitionStartingLocation);
> > > + if (p->accessType == cpu_to_le32(PD_ACCESS_TYPE_READ_ONLY))
> > > + map->s_partition_flags |= UDF_PART_FLAG_READ_ONLY;
> > > + if (p->accessType == cpu_to_le32(PD_ACCESS_TYPE_WRITE_ONCE))
> > > + map->s_partition_flags |= UDF_PART_FLAG_WRITE_ONCE;
> > > + if (p->accessType == cpu_to_le32(PD_ACCESS_TYPE_REWRITABLE))
> > > + map->s_partition_flags |= UDF_PART_FLAG_REWRITABLE;
> > > + if (p->accessType == cpu_to_le32(PD_ACCESS_TYPE_OVERWRITABLE))
> > > + map->s_partition_flags |= UDF_PART_FLAG_OVERWRITABLE;
> > > +
> > > + if (strcmp(p->partitionContents.ident,
> > > + PD_PARTITION_CONTENTS_NSR02) &&
> > > + strcmp(p->partitionContents.ident,
> > > + PD_PARTITION_CONTENTS_NSR03))
> > > + break;
> > > +
> > > + phd = (struct partitionHeaderDesc *)
> > > + (p->partitionContentsUse);
> > > + if (phd->unallocSpaceTable.extLength) {
> > > + kernel_lb_addr loc = {
> > > + .logicalBlockNum = le32_to_cpu(
> > > + phd->unallocSpaceTable.extPosition),
> > > + .partitionReferenceNum = i,
> > > + };
> > > +
> > > + map->s_uspace.s_table =
> > > + udf_iget(sb, loc);
> > > + if (!map->s_uspace.s_table) {
> > > + udf_debug("cannot load unallocSpaceTable "
> > > + "(part %d)\n", i);
> > > + return 1;
> > > + }
> > > + map->s_partition_flags |=
> > > + UDF_PART_FLAG_UNALLOC_TABLE;
> > > + udf_debug("unallocSpaceTable (part %d) @ %ld\n",
> > > + i, map->s_uspace.s_table->i_ino);
> > > + }
> > > + if (phd->unallocSpaceBitmap.extLength) {
> > > + struct udf_bitmap *bitmap =
> > > + udf_sb_alloc_bitmap(sb, i);
> > > + map->s_uspace.s_bitmap = bitmap;
> > > + if (bitmap != NULL) {
> > > + bitmap->s_extLength = le32_to_cpu(
> > > + phd->unallocSpaceBitmap.extLength);
> > > + bitmap->s_extPosition = le32_to_cpu(
> > > + phd->unallocSpaceBitmap.extPosition);
> > > map->s_partition_flags |=
> > > - UDF_PART_FLAG_REWRITABLE;
> > > - if (p->accessType ==
> > > - cpu_to_le32(PD_ACCESS_TYPE_OVERWRITABLE))
> > > + UDF_PART_FLAG_UNALLOC_BITMAP;
> > > + udf_debug("unallocSpaceBitmap (part %d) @ %d\n",
> > > + i, bitmap->s_extPosition);
> > > + }
> > > + }
> > > + if (phd->partitionIntegrityTable.extLength)
> > > + udf_debug("partitionIntegrityTable (part %d)\n", i);
> > > + if (phd->freedSpaceTable.extLength) {
> > > + kernel_lb_addr loc = {
> > > + .logicalBlockNum = le32_to_cpu(
> > > + phd->freedSpaceTable.extPosition),
> > > + .partitionReferenceNum = i,
> > > + };
> > > +
> > > + map->s_fspace.s_table =
> > > + udf_iget(sb, loc);
> > > + if (!map->s_fspace.s_table) {
> > > + udf_debug("cannot load freedSpaceTable "
> > > + "(part %d)\n", i);
> > > + return 1;
> > > + }
> > > + map->s_partition_flags |=
> > > + UDF_PART_FLAG_FREED_TABLE;
> > > + udf_debug("freedSpaceTable (part %d) @ %ld\n",
> > > + i, map->s_fspace.s_table->i_ino);
> > > + }
> > > + if (phd->freedSpaceBitmap.extLength) {
> > > + struct udf_bitmap *bitmap =
> > > + udf_sb_alloc_bitmap(sb, i);
> > > + map->s_fspace.s_bitmap = bitmap;
> > > + if (bitmap != NULL) {
> > > + bitmap->s_extLength = le32_to_cpu(
> > > + phd->freedSpaceBitmap.extLength);
> > > + bitmap->s_extPosition = le32_to_cpu(
> > > + phd->freedSpaceBitmap.extPosition);
> > > map->s_partition_flags |=
> > > - UDF_PART_FLAG_OVERWRITABLE;
> > > -
> > > - if (!strcmp(p->partitionContents.ident,
> > > - PD_PARTITION_CONTENTS_NSR02) ||
> > > - !strcmp(p->partitionContents.ident,
> > > - PD_PARTITION_CONTENTS_NSR03)) {
> > > - struct partitionHeaderDesc *phd;
> > > -
> > > - phd = (struct partitionHeaderDesc *)
> > > - (p->partitionContentsUse);
> > > - if (phd->unallocSpaceTable.extLength) {
> > > - kernel_lb_addr loc = {
> > > - .logicalBlockNum = le32_to_cpu(phd->unallocSpaceTable.extPosition),
> > > - .partitionReferenceNum = i,
> > > - };
> > > -
> > > - map->s_uspace.s_table =
> > > - udf_iget(sb, loc);
> > > - if (!map->s_uspace.s_table) {
> > > - udf_debug("cannot load unallocSpaceTable (part %d)\n", i);
> > > - return 1;
> > > - }
> > > - map->s_partition_flags |=
> > > - UDF_PART_FLAG_UNALLOC_TABLE;
> > > - udf_debug("unallocSpaceTable (part %d) @ %ld\n",
> > > - i, map->s_uspace.s_table->i_ino);
> > > - }
> > > - if (phd->unallocSpaceBitmap.extLength) {
> > > - struct udf_bitmap *bitmap =
> > > - udf_sb_alloc_bitmap(sb, i);
> > > - map->s_uspace.s_bitmap = bitmap;
> > > - if (bitmap != NULL) {
> > > - bitmap->s_extLength =
> > > - le32_to_cpu(phd->unallocSpaceBitmap.extLength);
> > > - bitmap->s_extPosition =
> > > - le32_to_cpu(phd->unallocSpaceBitmap.extPosition);
> > > - map->s_partition_flags |= UDF_PART_FLAG_UNALLOC_BITMAP;
> > > - udf_debug("unallocSpaceBitmap (part %d) @ %d\n",
> > > - i, bitmap->s_extPosition);
> > > - }
> > > - }
> > > - if (phd->partitionIntegrityTable.extLength)
> > > - udf_debug("partitionIntegrityTable (part %d)\n", i);
> > > - if (phd->freedSpaceTable.extLength) {
> > > - kernel_lb_addr loc = {
> > > - .logicalBlockNum = le32_to_cpu(phd->freedSpaceTable.extPosition),
> > > - .partitionReferenceNum = i,
> > > - };
> > > -
> > > - map->s_fspace.s_table =
> > > - udf_iget(sb, loc);
> > > - if (!map->s_fspace.s_table) {
> > > - udf_debug("cannot load freedSpaceTable (part %d)\n", i);
> > > - return 1;
> > > - }
> > > - map->s_partition_flags |=
> > > - UDF_PART_FLAG_FREED_TABLE;
> > > - udf_debug("freedSpaceTable (part %d) @ %ld\n",
> > > - i, map->s_fspace.s_table->i_ino);
> > > - }
> > > - if (phd->freedSpaceBitmap.extLength) {
> > > - struct udf_bitmap *bitmap =
> > > - udf_sb_alloc_bitmap(sb, i);
> > > - map->s_fspace.s_bitmap = bitmap;
> > > - if (bitmap != NULL) {
> > > - bitmap->s_extLength =
> > > - le32_to_cpu(phd->freedSpaceBitmap.extLength);
> > > - bitmap->s_extPosition =
> > > - le32_to_cpu(phd->freedSpaceBitmap.extPosition);
> > > - map->s_partition_flags |= UDF_PART_FLAG_FREED_BITMAP;
> > > - udf_debug("freedSpaceBitmap (part %d) @ %d\n",
> > > - i, bitmap->s_extPosition);
> > > - }
> > > - }
> > > + UDF_PART_FLAG_FREED_BITMAP;
> > > + udf_debug("freedSpaceBitmap (part %d) @ %d\n",
> > > + i, bitmap->s_extPosition);
> > > }
> > > - break;
> > > }
> > > + break;
> > > }
> > > if (i == sbi->s_partitions)
> > > udf_debug("Partition (%d) not found in partition map\n",
>
> Ok. I didn't notice that. But it won't be as trivial as the rest. Separate patch?
You're reindenting the code anyway, so moving it to another place isn't a
big deal (doesn't make review any harder). So you can just merge it into
the same patch. Thanks.

Honza
--
Jan Kara <[email protected]>
SUSE Labs, CR

2008-02-06 11:10:26

by Jan Kara

[permalink] [raw]
Subject: Re: [PATCH 4/6] udf: convert udf_stamp_to_time and udf_time_to_stamp to use timestamps

On Tue 05-02-08 20:21:58, Marcin Slusarz wrote:
> On Tue, Feb 05, 2008 at 04:59:56PM +0100, Jan Kara wrote:
> > On Sun 03-02-08 19:36:09, [email protected] wrote:
> > > kernel_timestamp type was almost unused - only callers of udf_stamp_to_time
> > > and udf_time_to_stamp used it, so let these functions handle endianness
> > > internally and don't clutter code with conversions
> > OK, but please also rename the functions to something like
> > udf_disk_stamp_to_time() and udf_time_to_disk_stamp() so that the name
> > suggests that it internally handles endianess...
> Ok, should I redo this patch or create separate patch on top of it?
Please, just redo this one. Thanks.

Honza
--
Jan Kara <[email protected]>
SUSE Labs, CR

2008-02-06 13:25:49

by Jan Kara

[permalink] [raw]
Subject: Re: [PATCH 3/6] udf: convert udf_stamp_to_time to return struct timespec

On Tue 05-02-08 20:12:05, Marcin Slusarz wrote:
> On Tue, Feb 05, 2008 at 04:48:31PM +0100, Jan Kara wrote:
> >
> > Uh, oh. I guess you somehow mangled the ordering of patches. In this
> > patch you revert what you've done in the previous patch. Otherwise I agree
> > with the idea of the change...
> No, the ordering is ok. Creation of udf_fill_inode_time was an intermediate
> state in this cleanup. Every step is obvious and easy. When I tried to create
> just one patch it didn't look so obvious, so I decided to send it in 4 parts.
Ah, OK then.

Honza

> > On Sun 03-02-08 19:36:08, [email protected] wrote:
> > > Signed-off-by: Marcin Slusarz <[email protected]>
> > > Cc: Jan Kara <[email protected]>
> > > ---
> > > fs/udf/inode.c | 49 ++++++++++++++++++++++++++-----------------------
> > > fs/udf/super.c | 9 ++-------
> > > fs/udf/udfdecl.h | 4 ++--
> > > fs/udf/udftime.c | 17 +++++++----------
> > > 4 files changed, 37 insertions(+), 42 deletions(-)
> > >
> > > diff --git a/fs/udf/inode.c b/fs/udf/inode.c
> > > index 2578677..252efe0 100644
> > > --- a/fs/udf/inode.c
> > > +++ b/fs/udf/inode.c
> > > @@ -1151,20 +1151,6 @@ static void __udf_read_inode(struct inode *inode)
> > > brelse(bh);
> > > }
> > >
> > > -static void udf_fill_inode_time(struct timespec *tspec,
> > > - const timestamp *tstamp,
> > > - struct udf_sb_info *sbi)
> > > -{
> > > - time_t convtime;
> > > - long convtime_usec;
> > > - if (udf_stamp_to_time(&convtime, &convtime_usec,
> > > - lets_to_cpu(*tstamp))) {
> > > - tspec->tv_sec = convtime;
> > > - tspec->tv_nsec = convtime_usec * 1000;
> > > - } else
> > > - *tspec = sbi->s_record_time;
> > > -}
> > > -
> >
> > > static void udf_fill_inode(struct inode *inode, struct buffer_head *bh)
> > > {
> > > struct fileEntry *fe;
> > > @@ -1256,10 +1242,17 @@ static void udf_fill_inode(struct inode *inode, struct buffer_head *bh)
> > > inode->i_blocks = le64_to_cpu(fe->logicalBlocksRecorded) <<
> > > (inode->i_sb->s_blocksize_bits - 9);
> > >
> > > - udf_fill_inode_time(&inode->i_atime, &fe->accessTime, sbi);
> > > - udf_fill_inode_time(&inode->i_mtime, &fe->modificationTime,
> > > - sbi);
> > > - udf_fill_inode_time(&inode->i_ctime, &fe->attrTime, sbi);
> > > + if (!udf_stamp_to_time(&inode->i_atime,
> > > + lets_to_cpu(fe->accessTime)))
> > > + inode->i_atime = sbi->s_record_time;
> > > +
> > > + if (!udf_stamp_to_time(&inode->i_mtime,
> > > + lets_to_cpu(fe->modificationTime)))
> > > + inode->i_mtime = sbi->s_record_time;
> > > +
> > > + if (!udf_stamp_to_time(&inode->i_ctime,
> > > + lets_to_cpu(fe->attrTime)))
> > > + inode->i_ctime = sbi->s_record_time;
> > >
> > > iinfo->i_unique = le64_to_cpu(fe->uniqueID);
> > > iinfo->i_lenEAttr = le32_to_cpu(fe->lengthExtendedAttr);
> > > @@ -1269,11 +1262,21 @@ static void udf_fill_inode(struct inode *inode, struct buffer_head *bh)
> > > inode->i_blocks = le64_to_cpu(efe->logicalBlocksRecorded) <<
> > > (inode->i_sb->s_blocksize_bits - 9);
> > >
> > > - udf_fill_inode_time(&inode->i_atime, &efe->accessTime, sbi);
> > > - udf_fill_inode_time(&inode->i_mtime, &efe->modificationTime,
> > > - sbi);
> > > - udf_fill_inode_time(&iinfo->i_crtime, &efe->createTime, sbi);
> > > - udf_fill_inode_time(&inode->i_ctime, &efe->attrTime, sbi);
> > > + if (!udf_stamp_to_time(&inode->i_atime,
> > > + lets_to_cpu(efe->accessTime)))
> > > + inode->i_atime = sbi->s_record_time;
> > > +
> > > + if (!udf_stamp_to_time(&inode->i_mtime,
> > > + lets_to_cpu(efe->modificationTime)))
> > > + inode->i_mtime = sbi->s_record_time;
> > > +
> > > + if (!udf_stamp_to_time(&iinfo->i_crtime,
> > > + lets_to_cpu(efe->createTime)))
> > > + iinfo->i_crtime = sbi->s_record_time;
> > > +
> > > + if (!udf_stamp_to_time(&inode->i_ctime,
> > > + lets_to_cpu(efe->attrTime)))
> > > + inode->i_ctime = sbi->s_record_time;
> > >
> > > iinfo->i_unique = le64_to_cpu(efe->uniqueID);
> > > iinfo->i_lenEAttr = le32_to_cpu(efe->lengthExtendedAttr);
> > > diff --git a/fs/udf/super.c b/fs/udf/super.c
> > > index 0dcee12..9f565a9 100644
> > > --- a/fs/udf/super.c
> > > +++ b/fs/udf/super.c
> > > @@ -909,24 +909,19 @@ static int udf_find_fileset(struct super_block *sb,
> > > static void udf_load_pvoldesc(struct super_block *sb, struct buffer_head *bh)
> > > {
> > > struct primaryVolDesc *pvoldesc;
> > > - time_t recording;
> > > - long recording_usec;
> > > struct ustr instr;
> > > struct ustr outstr;
> > >
> > > pvoldesc = (struct primaryVolDesc *)bh->b_data;
> > >
> > > - if (udf_stamp_to_time(&recording, &recording_usec,
> > > + if (udf_stamp_to_time(&UDF_SB(sb)->s_record_time,
> > > lets_to_cpu(pvoldesc->recordingDateAndTime))) {
> > > kernel_timestamp ts;
> > > ts = lets_to_cpu(pvoldesc->recordingDateAndTime);
> > > - udf_debug("recording time %ld/%ld, %04u/%02u/%02u"
> > > + udf_debug("recording time %04u/%02u/%02u"
> > > " %02u:%02u (%x)\n",
> > > - recording, recording_usec,
> > > ts.year, ts.month, ts.day, ts.hour,
> > > ts.minute, ts.typeAndTimezone);
> > > - UDF_SB(sb)->s_record_time.tv_sec = recording;
> > > - UDF_SB(sb)->s_record_time.tv_nsec = recording_usec * 1000;
> > > }
> > >
> > > if (!udf_build_ustr(&instr, pvoldesc->volIdent, 32))
> > > diff --git a/fs/udf/udfdecl.h b/fs/udf/udfdecl.h
> > > index 375be1b..508be85 100644
> > > --- a/fs/udf/udfdecl.h
> > > +++ b/fs/udf/udfdecl.h
> > > @@ -204,7 +204,7 @@ extern short_ad *udf_get_fileshortad(uint8_t *, int, uint32_t *, int);
> > > extern uint16_t udf_crc(const uint8_t *, uint32_t, uint16_t);
> > >
> > > /* udftime.c */
> > > -extern time_t *udf_stamp_to_time(time_t *, long *, kernel_timestamp);
> > > -extern kernel_timestamp *udf_time_to_stamp(kernel_timestamp *, struct timespec);
> > > +extern struct timespec *udf_stamp_to_time(struct timespec *dest, kernel_timestamp src);
> > > +extern kernel_timestamp *udf_time_to_stamp(kernel_timestamp *dest, struct timespec src);
> > >
> > > #endif /* __UDF_DECL_H */
> > > diff --git a/fs/udf/udftime.c b/fs/udf/udftime.c
> > > index ce59573..12fae6c 100644
> > > --- a/fs/udf/udftime.c
> > > +++ b/fs/udf/udftime.c
> > > @@ -85,7 +85,7 @@ extern struct timezone sys_tz;
> > > #define SECS_PER_HOUR (60 * 60)
> > > #define SECS_PER_DAY (SECS_PER_HOUR * 24)
> > >
> > > -time_t *udf_stamp_to_time(time_t *dest, long *dest_usec, kernel_timestamp src)
> > > +struct timespec *udf_stamp_to_time(struct timespec *dest, kernel_timestamp src)
> > > {
> > > int yday;
> > > uint8_t type = src.typeAndTimezone >> 12;
> > > @@ -97,23 +97,20 @@ time_t *udf_stamp_to_time(time_t *dest, long *dest_usec, kernel_timestamp src)
> > > offset = (offset >> 4);
> > > if (offset == -2047) /* unspecified offset */
> > > offset = 0;
> > > - } else {
> > > + } else
> > > offset = 0;
> > > - }
> > >
> > > if ((src.year < EPOCH_YEAR) ||
> > > (src.year >= EPOCH_YEAR + MAX_YEAR_SECONDS)) {
> > > - *dest = -1;
> > > - *dest_usec = -1;
> > > return NULL;
> > > }
> > > - *dest = year_seconds[src.year - EPOCH_YEAR];
> > > - *dest -= offset * 60;
> > > + dest->tv_sec = year_seconds[src.year - EPOCH_YEAR];
> > > + dest->tv_sec -= offset * 60;
> > >
> > > yday = ((__mon_yday[__isleap(src.year)][src.month - 1]) + src.day - 1);
> > > - *dest += (((yday * 24) + src.hour) * 60 + src.minute) * 60 + src.second;
> > > - *dest_usec = src.centiseconds * 10000 +
> > > - src.hundredsOfMicroseconds * 100 + src.microseconds;
> > > + dest->tv_sec += (((yday * 24) + src.hour) * 60 + src.minute) * 60 + src.second;
> > > + dest->tv_nsec = 1000 * (src.centiseconds * 10000 +
> > > + src.hundredsOfMicroseconds * 100 + src.microseconds);
> > > return dest;
> > > }
> > >
> > > --
> > > 1.5.3.7
> >
> > Honza
> > --
> > Jan Kara <[email protected]>
> > SUSE Labs, CR
--
Jan Kara <[email protected]>
SUSE Labs, CR

2008-02-10 10:26:17

by Marcin Ślusarz

[permalink] [raw]
Subject: Re: [PATCH 4/6] udf: convert udf_stamp_to_time and udf_time_to_stamp to use timestamps

On Wed, Feb 06, 2008 at 12:10:08PM +0100, Jan Kara wrote:
> On Tue 05-02-08 20:21:58, Marcin Slusarz wrote:
> > On Tue, Feb 05, 2008 at 04:59:56PM +0100, Jan Kara wrote:
> > > On Sun 03-02-08 19:36:09, [email protected] wrote:
> > > > kernel_timestamp type was almost unused - only callers of udf_stamp_to_time
> > > > and udf_time_to_stamp used it, so let these functions handle endianness
> > > > internally and don't clutter code with conversions
> > > OK, but please also rename the functions to something like
> > > udf_disk_stamp_to_time() and udf_time_to_disk_stamp() so that the name
> > > suggests that it internally handles endianess...
> > Ok, should I redo this patch or create separate patch on top of it?
> Please, just redo this one. Thanks.

---
udf: convert udf_stamp_to_time and udf_time_to_stamp to use timestamps

* kernel_timestamp type was almost unused - only callers of udf_stamp_to_time
and udf_time_to_stamp used it, so let these functions handle endianness
internally and don't clutter code with conversions

* rename udf_stamp_to_time to udf_disk_stamp_to_time
and udf_time_to_stamp to udf_time_to_disk_stamp

Signed-off-by: Marcin Slusarz <[email protected]>
Cc: Jan Kara <[email protected]>
---
fs/udf/inode.c | 45 ++++++++++++++++-----------------------------
fs/udf/super.c | 22 ++++++++++------------
fs/udf/udfdecl.h | 5 +++--
fs/udf/udftime.c | 22 ++++++++++++----------
4 files changed, 41 insertions(+), 53 deletions(-)

diff --git a/fs/udf/inode.c b/fs/udf/inode.c
index e464652..17674ea 100644
--- a/fs/udf/inode.c
+++ b/fs/udf/inode.c
@@ -1242,16 +1242,14 @@ static void udf_fill_inode(struct inode *inode, struct buffer_head *bh)
inode->i_blocks = le64_to_cpu(fe->logicalBlocksRecorded) <<
(inode->i_sb->s_blocksize_bits - 9);

- if (!udf_stamp_to_time(&inode->i_atime,
- lets_to_cpu(fe->accessTime)))
+ if (!udf_disk_stamp_to_time(&inode->i_atime, fe->accessTime))
inode->i_atime = sbi->s_record_time;

- if (!udf_stamp_to_time(&inode->i_mtime,
- lets_to_cpu(fe->modificationTime)))
+ if (!udf_disk_stamp_to_time(&inode->i_mtime,
+ fe->modificationTime))
inode->i_mtime = sbi->s_record_time;

- if (!udf_stamp_to_time(&inode->i_ctime,
- lets_to_cpu(fe->attrTime)))
+ if (!udf_disk_stamp_to_time(&inode->i_ctime, fe->attrTime))
inode->i_ctime = sbi->s_record_time;

iinfo->i_unique = le64_to_cpu(fe->uniqueID);
@@ -1262,20 +1260,17 @@ static void udf_fill_inode(struct inode *inode, struct buffer_head *bh)
inode->i_blocks = le64_to_cpu(efe->logicalBlocksRecorded) <<
(inode->i_sb->s_blocksize_bits - 9);

- if (!udf_stamp_to_time(&inode->i_atime,
- lets_to_cpu(efe->accessTime)))
+ if (!udf_disk_stamp_to_time(&inode->i_atime, efe->accessTime))
inode->i_atime = sbi->s_record_time;

- if (!udf_stamp_to_time(&inode->i_mtime,
- lets_to_cpu(efe->modificationTime)))
+ if (!udf_disk_stamp_to_time(&inode->i_mtime,
+ efe->modificationTime))
inode->i_mtime = sbi->s_record_time;

- if (!udf_stamp_to_time(&iinfo->i_crtime,
- lets_to_cpu(efe->createTime)))
+ if (!udf_disk_stamp_to_time(&iinfo->i_crtime, efe->createTime))
iinfo->i_crtime = sbi->s_record_time;

- if (!udf_stamp_to_time(&inode->i_ctime,
- lets_to_cpu(efe->attrTime)))
+ if (!udf_disk_stamp_to_time(&inode->i_ctime, efe->attrTime))
inode->i_ctime = sbi->s_record_time;

iinfo->i_unique = le64_to_cpu(efe->uniqueID);
@@ -1412,7 +1407,6 @@ static int udf_update_inode(struct inode *inode, int do_sync)
uint32_t udfperms;
uint16_t icbflags;
uint16_t crclen;
- kernel_timestamp cpu_time;
int err = 0;
struct udf_sb_info *sbi = UDF_SB(inode->i_sb);
unsigned char blocksize_bits = inode->i_sb->s_blocksize_bits;
@@ -1515,12 +1509,9 @@ static int udf_update_inode(struct inode *inode, int do_sync)
(inode->i_blocks + (1 << (blocksize_bits - 9)) - 1) >>
(blocksize_bits - 9));

- if (udf_time_to_stamp(&cpu_time, inode->i_atime))
- fe->accessTime = cpu_to_lets(cpu_time);
- if (udf_time_to_stamp(&cpu_time, inode->i_mtime))
- fe->modificationTime = cpu_to_lets(cpu_time);
- if (udf_time_to_stamp(&cpu_time, inode->i_ctime))
- fe->attrTime = cpu_to_lets(cpu_time);
+ udf_time_to_disk_stamp(&fe->accessTime, inode->i_atime);
+ udf_time_to_disk_stamp(&fe->modificationTime, inode->i_mtime);
+ udf_time_to_disk_stamp(&fe->attrTime, inode->i_ctime);
memset(&(fe->impIdent), 0, sizeof(regid));
strcpy(fe->impIdent.ident, UDF_ID_DEVELOPER);
fe->impIdent.identSuffix[0] = UDF_OS_CLASS_UNIX;
@@ -1555,14 +1546,10 @@ static int udf_update_inode(struct inode *inode, int do_sync)
iinfo->i_crtime.tv_nsec > inode->i_ctime.tv_nsec))
iinfo->i_crtime = inode->i_ctime;

- if (udf_time_to_stamp(&cpu_time, inode->i_atime))
- efe->accessTime = cpu_to_lets(cpu_time);
- if (udf_time_to_stamp(&cpu_time, inode->i_mtime))
- efe->modificationTime = cpu_to_lets(cpu_time);
- if (udf_time_to_stamp(&cpu_time, iinfo->i_crtime))
- efe->createTime = cpu_to_lets(cpu_time);
- if (udf_time_to_stamp(&cpu_time, inode->i_ctime))
- efe->attrTime = cpu_to_lets(cpu_time);
+ udf_time_to_disk_stamp(&efe->accessTime, inode->i_atime);
+ udf_time_to_disk_stamp(&efe->modificationTime, inode->i_mtime);
+ udf_time_to_disk_stamp(&efe->createTime, iinfo->i_crtime);
+ udf_time_to_disk_stamp(&efe->attrTime, inode->i_ctime);

memset(&(efe->impIdent), 0, sizeof(regid));
strcpy(efe->impIdent.ident, UDF_ID_DEVELOPER);
diff --git a/fs/udf/super.c b/fs/udf/super.c
index 570fe51..ab63dbb 100644
--- a/fs/udf/super.c
+++ b/fs/udf/super.c
@@ -980,8 +980,8 @@ static void udf_load_pvoldesc(struct super_block *sb, struct buffer_head *bh)

pvoldesc = (struct primaryVolDesc *)bh->b_data;

- if (udf_stamp_to_time(&UDF_SB(sb)->s_record_time,
- lets_to_cpu(pvoldesc->recordingDateAndTime))) {
+ if (udf_disk_stamp_to_time(&UDF_SB(sb)->s_record_time,
+ pvoldesc->recordingDateAndTime)) {
kernel_timestamp ts;
ts = lets_to_cpu(pvoldesc->recordingDateAndTime);
udf_debug("recording time %04u/%02u/%02u"
@@ -1627,7 +1627,6 @@ static void udf_open_lvid(struct super_block *sb)
struct udf_sb_info *sbi = UDF_SB(sb);
struct buffer_head *bh = sbi->s_lvid_bh;
if (bh) {
- kernel_timestamp cpu_time;
struct logicalVolIntegrityDesc *lvid =
(struct logicalVolIntegrityDesc *)bh->b_data;
struct logicalVolIntegrityDescImpUse *lvidiu =
@@ -1635,8 +1634,8 @@ static void udf_open_lvid(struct super_block *sb)

lvidiu->impIdent.identSuffix[0] = UDF_OS_CLASS_UNIX;
lvidiu->impIdent.identSuffix[1] = UDF_OS_ID_LINUX;
- if (udf_time_to_stamp(&cpu_time, CURRENT_TIME))
- lvid->recordingDateAndTime = cpu_to_lets(cpu_time);
+ udf_time_to_disk_stamp(&lvid->recordingDateAndTime,
+ CURRENT_TIME);
lvid->integrityType = LVID_INTEGRITY_TYPE_OPEN;

lvid->descTag.descCRC = cpu_to_le16(
@@ -1651,7 +1650,6 @@ static void udf_open_lvid(struct super_block *sb)

static void udf_close_lvid(struct super_block *sb)
{
- kernel_timestamp cpu_time;
struct udf_sb_info *sbi = UDF_SB(sb);
struct buffer_head *bh = sbi->s_lvid_bh;
struct logicalVolIntegrityDesc *lvid;
@@ -1666,8 +1664,8 @@ static void udf_close_lvid(struct super_block *sb)
udf_sb_lvidiu(sbi);
lvidiu->impIdent.identSuffix[0] = UDF_OS_CLASS_UNIX;
lvidiu->impIdent.identSuffix[1] = UDF_OS_ID_LINUX;
- if (udf_time_to_stamp(&cpu_time, CURRENT_TIME))
- lvid->recordingDateAndTime = cpu_to_lets(cpu_time);
+ udf_time_to_disk_stamp(&lvid->recordingDateAndTime,
+ CURRENT_TIME);
if (UDF_MAX_WRITE_VERSION > le16_to_cpu(lvidiu->maxUDFWriteRev))
lvidiu->maxUDFWriteRev =
cpu_to_le16(UDF_MAX_WRITE_VERSION);
@@ -1852,12 +1850,12 @@ static int udf_fill_super(struct super_block *sb, void *options, int silent)
}

if (!silent) {
- kernel_timestamp ts;
- udf_time_to_stamp(&ts, sbi->s_record_time);
+ timestamp ts;
+ udf_time_to_disk_stamp(&ts, sbi->s_record_time);
udf_info("UDF: Mounting volume '%s', "
"timestamp %04u/%02u/%02u %02u:%02u (%x)\n",
- sbi->s_volume_ident, ts.year, ts.month, ts.day,
- ts.hour, ts.minute, ts.typeAndTimezone);
+ sbi->s_volume_ident, le16_to_cpu(ts.year), ts.month, ts.day,
+ ts.hour, ts.minute, le16_to_cpu(ts.typeAndTimezone));
}
if (!(sb->s_flags & MS_RDONLY))
udf_open_lvid(sb);
diff --git a/fs/udf/udfdecl.h b/fs/udf/udfdecl.h
index 508be85..011feee 100644
--- a/fs/udf/udfdecl.h
+++ b/fs/udf/udfdecl.h
@@ -204,7 +204,8 @@ extern short_ad *udf_get_fileshortad(uint8_t *, int, uint32_t *, int);
extern uint16_t udf_crc(const uint8_t *, uint32_t, uint16_t);

/* udftime.c */
-extern struct timespec *udf_stamp_to_time(struct timespec *dest, kernel_timestamp src);
-extern kernel_timestamp *udf_time_to_stamp(kernel_timestamp *dest, struct timespec src);
+extern struct timespec *udf_disk_stamp_to_time(struct timespec *dest,
+ timestamp src);
+extern timestamp *udf_time_to_disk_stamp(timestamp *dest, struct timespec src);

#endif /* __UDF_DECL_H */
diff --git a/fs/udf/udftime.c b/fs/udf/udftime.c
index 12fae6c..5f81165 100644
--- a/fs/udf/udftime.c
+++ b/fs/udf/udftime.c
@@ -85,14 +85,16 @@ extern struct timezone sys_tz;
#define SECS_PER_HOUR (60 * 60)
#define SECS_PER_DAY (SECS_PER_HOUR * 24)

-struct timespec *udf_stamp_to_time(struct timespec *dest, kernel_timestamp src)
+struct timespec *udf_disk_stamp_to_time(struct timespec *dest, timestamp src)
{
int yday;
- uint8_t type = src.typeAndTimezone >> 12;
+ u16 typeAndTimezone = le16_to_cpu(src.typeAndTimezone);
+ u16 year = le16_to_cpu(src.year);
+ uint8_t type = typeAndTimezone >> 12;
int16_t offset;

if (type == 1) {
- offset = src.typeAndTimezone << 4;
+ offset = typeAndTimezone << 4;
/* sign extent offset */
offset = (offset >> 4);
if (offset == -2047) /* unspecified offset */
@@ -100,21 +102,21 @@ struct timespec *udf_stamp_to_time(struct timespec *dest, kernel_timestamp src)
} else
offset = 0;

- if ((src.year < EPOCH_YEAR) ||
- (src.year >= EPOCH_YEAR + MAX_YEAR_SECONDS)) {
+ if ((year < EPOCH_YEAR) ||
+ (year >= EPOCH_YEAR + MAX_YEAR_SECONDS)) {
return NULL;
}
- dest->tv_sec = year_seconds[src.year - EPOCH_YEAR];
+ dest->tv_sec = year_seconds[year - EPOCH_YEAR];
dest->tv_sec -= offset * 60;

- yday = ((__mon_yday[__isleap(src.year)][src.month - 1]) + src.day - 1);
+ yday = ((__mon_yday[__isleap(year)][src.month - 1]) + src.day - 1);
dest->tv_sec += (((yday * 24) + src.hour) * 60 + src.minute) * 60 + src.second;
dest->tv_nsec = 1000 * (src.centiseconds * 10000 +
src.hundredsOfMicroseconds * 100 + src.microseconds);
return dest;
}

-kernel_timestamp *udf_time_to_stamp(kernel_timestamp *dest, struct timespec ts)
+timestamp *udf_time_to_disk_stamp(timestamp *dest, struct timespec ts)
{
long int days, rem, y;
const unsigned short int *ip;
@@ -125,7 +127,7 @@ kernel_timestamp *udf_time_to_stamp(kernel_timestamp *dest, struct timespec ts)
if (!dest)
return NULL;

- dest->typeAndTimezone = 0x1000 | (offset & 0x0FFF);
+ dest->typeAndTimezone = cpu_to_le16(0x1000 | (offset & 0x0FFF));

ts.tv_sec += offset * 60;
days = ts.tv_sec / SECS_PER_DAY;
@@ -148,7 +150,7 @@ kernel_timestamp *udf_time_to_stamp(kernel_timestamp *dest, struct timespec ts)
- LEAPS_THRU_END_OF(y - 1));
y = yg;
}
- dest->year = y;
+ dest->year = cpu_to_le16(y);
ip = __mon_yday[__isleap(y)];
for (y = 11; days < (long int)ip[y]; --y)
continue;
--
1.5.3.7

2008-02-10 10:29:45

by Marcin Ślusarz

[permalink] [raw]
Subject: Re: [PATCH 5/6] udf: remove unneeded kernel_timestamp type

On Tue, Feb 05, 2008 at 05:01:15PM +0100, Jan Kara wrote:
> On Sun 03-02-08 19:36:10, [email protected] wrote:
> > remove now unneeded kernel_timestamp type with conversion functions
> OK. Acked-by: Jan Kara <[email protected]>
updated version which aplies after changes to patch:
udf: convert udf_stamp_to_time and udf_time_to_stamp to use timestamps

---
udf: remove unneeded kernel_timestamp type

remove now unneeded kernel_timestamp type with conversion functions

Signed-off-by: Marcin Slusarz <[email protected]>
Acked-by: Jan Kara <[email protected]>
---
fs/udf/ecma_167.h | 13 -------------
fs/udf/super.c | 9 +++++----
fs/udf/udfend.h | 22 ----------------------
3 files changed, 5 insertions(+), 39 deletions(-)

diff --git a/fs/udf/ecma_167.h b/fs/udf/ecma_167.h
index 5638771..a0974df 100644
--- a/fs/udf/ecma_167.h
+++ b/fs/udf/ecma_167.h
@@ -70,19 +70,6 @@ typedef struct {
uint8_t microseconds;
} __attribute__ ((packed)) timestamp;

-typedef struct {
- uint16_t typeAndTimezone;
- int16_t year;
- uint8_t month;
- uint8_t day;
- uint8_t hour;
- uint8_t minute;
- uint8_t second;
- uint8_t centiseconds;
- uint8_t hundredsOfMicroseconds;
- uint8_t microseconds;
-} __attribute__ ((packed)) kernel_timestamp;
-
/* Type and Time Zone (ECMA 167r3 1/7.3.1) */
#define TIMESTAMP_TYPE_MASK 0xF000
#define TIMESTAMP_TYPE_CUT 0x0000
diff --git a/fs/udf/super.c b/fs/udf/super.c
index ab63dbb..56d9efb 100644
--- a/fs/udf/super.c
+++ b/fs/udf/super.c
@@ -982,12 +982,13 @@ static void udf_load_pvoldesc(struct super_block *sb, struct buffer_head *bh)

if (udf_disk_stamp_to_time(&UDF_SB(sb)->s_record_time,
pvoldesc->recordingDateAndTime)) {
- kernel_timestamp ts;
- ts = lets_to_cpu(pvoldesc->recordingDateAndTime);
+#ifdef UDFFS_DEBUG
+ timestamp *ts = &pvoldesc->recordingDateAndTime;
udf_debug("recording time %04u/%02u/%02u"
" %02u:%02u (%x)\n",
- ts.year, ts.month, ts.day, ts.hour,
- ts.minute, ts.typeAndTimezone);
+ le16_to_cpu(ts->year), ts->month, ts->day, ts->hour,
+ ts->minute, le16_to_cpu(ts->typeAndTimezone));
+#endif
}

if (!udf_build_ustr(&instr, pvoldesc->volIdent, 32))
diff --git a/fs/udf/udfend.h b/fs/udf/udfend.h
index c4bd120..489f52f 100644
--- a/fs/udf/udfend.h
+++ b/fs/udf/udfend.h
@@ -24,17 +24,6 @@ static inline lb_addr cpu_to_lelb(kernel_lb_addr in)
return out;
}

-static inline kernel_timestamp lets_to_cpu(timestamp in)
-{
- kernel_timestamp out;
-
- memcpy(&out, &in, sizeof(timestamp));
- out.typeAndTimezone = le16_to_cpu(in.typeAndTimezone);
- out.year = le16_to_cpu(in.year);
-
- return out;
-}
-
static inline short_ad lesa_to_cpu(short_ad in)
{
short_ad out;
@@ -85,15 +74,4 @@ static inline kernel_extent_ad leea_to_cpu(extent_ad in)
return out;
}

-static inline timestamp cpu_to_lets(kernel_timestamp in)
-{
- timestamp out;
-
- memcpy(&out, &in, sizeof(timestamp));
- out.typeAndTimezone = cpu_to_le16(in.typeAndTimezone);
- out.year = cpu_to_le16(in.year);
-
- return out;
-}
-
#endif /* __UDF_ENDIAN_H */
--
1.5.3.7

2008-02-10 10:34:01

by Marcin Ślusarz

[permalink] [raw]
Subject: Re: [PATCH 6/6] udf: super.c reorganization

On Wed, Feb 06, 2008 at 12:09:36PM +0100, Jan Kara wrote:
> On Tue 05-02-08 20:34:49, Marcin Slusarz wrote:
> > On Tue, Feb 05, 2008 at 05:22:19PM +0100, Jan Kara wrote:
> > > Actually, the loop below would be even more readable it you did:
> > >
> > > if (map->s_partition_num == le16_to_cpu(p->partitionNumber))
> > > break;
> > > And do the work after we exit from the loop.
> > >
> > >
(...)
> >
> > Ok. I didn't notice that. But it won't be as trivial as the rest. Separate patch?
> You're reindenting the code anyway, so moving it to another place isn't a
> big deal (doesn't make review any harder). So you can just merge it into
> the same patch. Thanks.
As you wish.

---
udf: super.c reorganization

reorganize few code blocks in super.c which
were needlessly indented (and hard to read):

so change from:
rettype fun()
{
init;
if (sth) {
long block of code;
}
}

to:
rettype fun()
{
init;
if (!sth)
return;
long block of code;
}

or

from:
rettype fun2()
{
init;
while (sth) {
init2();
if (sth2) {
long block of code;
}
}
}

to:
rettype fun2()
{
init;
while (sth) {
init2();
if (!sth2)
continue;
long block of code;
}
}

Signed-off-by: Marcin Slusarz <[email protected]>
Cc: Jan Kara <[email protected]>
---
fs/udf/super.c | 552 +++++++++++++++++++++++++++-----------------------------
1 files changed, 270 insertions(+), 282 deletions(-)

diff --git a/fs/udf/super.c b/fs/udf/super.c
index 56d9efb..45d7b62 100644
--- a/fs/udf/super.c
+++ b/fs/udf/super.c
@@ -864,18 +864,18 @@ static void udf_find_anchor(struct super_block *sb)
}

for (i = 0; i < ARRAY_SIZE(sbi->s_anchor); i++) {
- if (sbi->s_anchor[i]) {
- bh = udf_read_tagged(sb, sbi->s_anchor[i],
- sbi->s_anchor[i], &ident);
- if (!bh)
+ if (!sbi->s_anchor[i])
+ continue;
+ bh = udf_read_tagged(sb, sbi->s_anchor[i],
+ sbi->s_anchor[i], &ident);
+ if (!bh)
+ sbi->s_anchor[i] = 0;
+ else {
+ brelse(bh);
+ if ((ident != TAG_IDENT_AVDP) &&
+ (i || (ident != TAG_IDENT_FE &&
+ ident != TAG_IDENT_EFE)))
sbi->s_anchor[i] = 0;
- else {
- brelse(bh);
- if ((ident != TAG_IDENT_AVDP) &&
- (i || (ident != TAG_IDENT_FE &&
- ident != TAG_IDENT_EFE)))
- sbi->s_anchor[i] = 0;
- }
}
}

@@ -1058,128 +1058,118 @@ static struct udf_bitmap *udf_sb_alloc_bitmap(struct super_block *sb, u32 index)

static int udf_load_partdesc(struct super_block *sb, struct buffer_head *bh)
{
- struct partitionDesc *p;
- int i;
+ struct partitionHeaderDesc *phd;
+ struct partitionDesc *p = (struct partitionDesc *)bh->b_data;
struct udf_part_map *map;
- struct udf_sb_info *sbi;
-
- p = (struct partitionDesc *)bh->b_data;
- sbi = UDF_SB(sb);
+ struct udf_sb_info *sbi = UDF_SB(sb);
+ bool found = false;
+ int i;
+ u16 partitionNumber = le16_to_cpu(p->partitionNumber);

for (i = 0; i < sbi->s_partitions; i++) {
map = &sbi->s_partmaps[i];
udf_debug("Searching map: (%d == %d)\n",
- map->s_partition_num,
- le16_to_cpu(p->partitionNumber));
- if (map->s_partition_num ==
- le16_to_cpu(p->partitionNumber)) {
- map->s_partition_len =
- le32_to_cpu(p->partitionLength); /* blocks */
- map->s_partition_root =
- le32_to_cpu(p->partitionStartingLocation);
- if (p->accessType ==
- cpu_to_le32(PD_ACCESS_TYPE_READ_ONLY))
- map->s_partition_flags |=
- UDF_PART_FLAG_READ_ONLY;
- if (p->accessType ==
- cpu_to_le32(PD_ACCESS_TYPE_WRITE_ONCE))
- map->s_partition_flags |=
- UDF_PART_FLAG_WRITE_ONCE;
- if (p->accessType ==
- cpu_to_le32(PD_ACCESS_TYPE_REWRITABLE))
- map->s_partition_flags |=
- UDF_PART_FLAG_REWRITABLE;
- if (p->accessType ==
- cpu_to_le32(PD_ACCESS_TYPE_OVERWRITABLE))
- map->s_partition_flags |=
- UDF_PART_FLAG_OVERWRITABLE;
-
- if (!strcmp(p->partitionContents.ident,
- PD_PARTITION_CONTENTS_NSR02) ||
- !strcmp(p->partitionContents.ident,
- PD_PARTITION_CONTENTS_NSR03)) {
- struct partitionHeaderDesc *phd;
-
- phd = (struct partitionHeaderDesc *)
- (p->partitionContentsUse);
- if (phd->unallocSpaceTable.extLength) {
- kernel_lb_addr loc = {
- .logicalBlockNum = le32_to_cpu(phd->unallocSpaceTable.extPosition),
- .partitionReferenceNum = i,
- };
-
- map->s_uspace.s_table =
- udf_iget(sb, loc);
- if (!map->s_uspace.s_table) {
- udf_debug("cannot load unallocSpaceTable (part %d)\n", i);
- return 1;
- }
- map->s_partition_flags |=
- UDF_PART_FLAG_UNALLOC_TABLE;
- udf_debug("unallocSpaceTable (part %d) @ %ld\n",
- i, map->s_uspace.s_table->i_ino);
- }
- if (phd->unallocSpaceBitmap.extLength) {
- struct udf_bitmap *bitmap =
- udf_sb_alloc_bitmap(sb, i);
- map->s_uspace.s_bitmap = bitmap;
- if (bitmap != NULL) {
- bitmap->s_extLength =
- le32_to_cpu(phd->unallocSpaceBitmap.extLength);
- bitmap->s_extPosition =
- le32_to_cpu(phd->unallocSpaceBitmap.extPosition);
- map->s_partition_flags |= UDF_PART_FLAG_UNALLOC_BITMAP;
- udf_debug("unallocSpaceBitmap (part %d) @ %d\n",
- i, bitmap->s_extPosition);
- }
- }
- if (phd->partitionIntegrityTable.extLength)
- udf_debug("partitionIntegrityTable (part %d)\n", i);
- if (phd->freedSpaceTable.extLength) {
- kernel_lb_addr loc = {
- .logicalBlockNum = le32_to_cpu(phd->freedSpaceTable.extPosition),
- .partitionReferenceNum = i,
- };
-
- map->s_fspace.s_table =
- udf_iget(sb, loc);
- if (!map->s_fspace.s_table) {
- udf_debug("cannot load freedSpaceTable (part %d)\n", i);
- return 1;
- }
- map->s_partition_flags |=
- UDF_PART_FLAG_FREED_TABLE;
- udf_debug("freedSpaceTable (part %d) @ %ld\n",
- i, map->s_fspace.s_table->i_ino);
- }
- if (phd->freedSpaceBitmap.extLength) {
- struct udf_bitmap *bitmap =
- udf_sb_alloc_bitmap(sb, i);
- map->s_fspace.s_bitmap = bitmap;
- if (bitmap != NULL) {
- bitmap->s_extLength =
- le32_to_cpu(phd->freedSpaceBitmap.extLength);
- bitmap->s_extPosition =
- le32_to_cpu(phd->freedSpaceBitmap.extPosition);
- map->s_partition_flags |= UDF_PART_FLAG_FREED_BITMAP;
- udf_debug("freedSpaceBitmap (part %d) @ %d\n",
- i, bitmap->s_extPosition);
- }
- }
- }
+ map->s_partition_num, partitionNumber);
+ found = map->s_partition_num == partitionNumber;
+ if (found)
break;
- }
}
- if (i == sbi->s_partitions)
+
+ if (!found) {
udf_debug("Partition (%d) not found in partition map\n",
- le16_to_cpu(p->partitionNumber));
- else
- udf_debug("Partition (%d:%d type %x) starts at physical %d, "
- "block length %d\n",
- le16_to_cpu(p->partitionNumber), i,
- map->s_partition_type,
- map->s_partition_root,
- map->s_partition_len);
+ partitionNumber);
+ return 0;
+ }
+
+ map->s_partition_len = le32_to_cpu(p->partitionLength); /* blocks */
+ map->s_partition_root = le32_to_cpu(p->partitionStartingLocation);
+
+ if (p->accessType == cpu_to_le32(PD_ACCESS_TYPE_READ_ONLY))
+ map->s_partition_flags |= UDF_PART_FLAG_READ_ONLY;
+ if (p->accessType == cpu_to_le32(PD_ACCESS_TYPE_WRITE_ONCE))
+ map->s_partition_flags |= UDF_PART_FLAG_WRITE_ONCE;
+ if (p->accessType == cpu_to_le32(PD_ACCESS_TYPE_REWRITABLE))
+ map->s_partition_flags |= UDF_PART_FLAG_REWRITABLE;
+ if (p->accessType == cpu_to_le32(PD_ACCESS_TYPE_OVERWRITABLE))
+ map->s_partition_flags |= UDF_PART_FLAG_OVERWRITABLE;
+
+ udf_debug("Partition (%d:%d type %x) starts at physical %d, "
+ "block length %d\n", partitionNumber, i,
+ map->s_partition_type, map->s_partition_root,
+ map->s_partition_len);
+
+ if (strcmp(p->partitionContents.ident, PD_PARTITION_CONTENTS_NSR02) &&
+ strcmp(p->partitionContents.ident, PD_PARTITION_CONTENTS_NSR03))
+ return 0;
+
+ phd = (struct partitionHeaderDesc *)p->partitionContentsUse;
+ if (phd->unallocSpaceTable.extLength) {
+ kernel_lb_addr loc = {
+ .logicalBlockNum = le32_to_cpu(
+ phd->unallocSpaceTable.extPosition),
+ .partitionReferenceNum = i,
+ };
+
+ map->s_uspace.s_table = udf_iget(sb, loc);
+ if (!map->s_uspace.s_table) {
+ udf_debug("cannot load unallocSpaceTable (part %d)\n",
+ i);
+ return 1;
+ }
+ map->s_partition_flags |= UDF_PART_FLAG_UNALLOC_TABLE;
+ udf_debug("unallocSpaceTable (part %d) @ %ld\n",
+ i, map->s_uspace.s_table->i_ino);
+ }
+
+ if (phd->unallocSpaceBitmap.extLength) {
+ struct udf_bitmap *bitmap = udf_sb_alloc_bitmap(sb, i);
+ map->s_uspace.s_bitmap = bitmap;
+ if (bitmap != NULL) {
+ bitmap->s_extLength = le32_to_cpu(
+ phd->unallocSpaceBitmap.extLength);
+ bitmap->s_extPosition = le32_to_cpu(
+ phd->unallocSpaceBitmap.extPosition);
+ map->s_partition_flags |= UDF_PART_FLAG_UNALLOC_BITMAP;
+ udf_debug("unallocSpaceBitmap (part %d) @ %d\n",
+ i, bitmap->s_extPosition);
+ }
+ }
+
+ if (phd->partitionIntegrityTable.extLength)
+ udf_debug("partitionIntegrityTable (part %d)\n", i);
+
+ if (phd->freedSpaceTable.extLength) {
+ kernel_lb_addr loc = {
+ .logicalBlockNum = le32_to_cpu(
+ phd->freedSpaceTable.extPosition),
+ .partitionReferenceNum = i,
+ };
+
+ map->s_fspace.s_table = udf_iget(sb, loc);
+ if (!map->s_fspace.s_table) {
+ udf_debug("cannot load freedSpaceTable (part %d)\n", i);
+ return 1;
+ }
+
+ map->s_partition_flags |= UDF_PART_FLAG_FREED_TABLE;
+ udf_debug("freedSpaceTable (part %d) @ %ld\n",
+ i, map->s_fspace.s_table->i_ino);
+ }
+
+ if (phd->freedSpaceBitmap.extLength) {
+ struct udf_bitmap *bitmap = udf_sb_alloc_bitmap(sb, i);
+ map->s_fspace.s_bitmap = bitmap;
+ if (bitmap != NULL) {
+ bitmap->s_extLength = le32_to_cpu(
+ phd->freedSpaceBitmap.extLength);
+ bitmap->s_extPosition = le32_to_cpu(
+ phd->freedSpaceBitmap.extPosition);
+ map->s_partition_flags |= UDF_PART_FLAG_FREED_BITMAP;
+ udf_debug("freedSpaceBitmap (part %d) @ %d\n",
+ i, bitmap->s_extPosition);
+ }
+ }
+
return 0;
}

@@ -1253,19 +1243,17 @@ static int udf_load_logicalvol(struct super_block *sb, struct buffer_head *bh,
map->s_type_specific.s_sparing.
s_spar_map[j] = bh2;

- if (bh2 != NULL) {
- st = (struct sparingTable *)
- bh2->b_data;
- if (ident != 0 || strncmp(
- st->sparingIdent.ident,
- UDF_ID_SPARING,
- strlen(UDF_ID_SPARING))) {
- brelse(bh2);
- map->s_type_specific.
- s_sparing.
- s_spar_map[j] =
- NULL;
- }
+ if (bh2 == NULL)
+ continue;
+
+ st = (struct sparingTable *)bh2->b_data;
+ if (ident != 0 || strncmp(
+ st->sparingIdent.ident,
+ UDF_ID_SPARING,
+ strlen(UDF_ID_SPARING))) {
+ brelse(bh2);
+ map->s_type_specific.s_sparing.
+ s_spar_map[j] = NULL;
}
}
map->s_partition_func = udf_get_pblock_spar15;
@@ -1430,40 +1418,40 @@ static int udf_process_sequence(struct super_block *sb, long block,
brelse(bh);
}
for (i = 0; i < VDS_POS_LENGTH; i++) {
- if (vds[i].block) {
- bh = udf_read_tagged(sb, vds[i].block, vds[i].block,
- &ident);
-
- if (i == VDS_POS_PRIMARY_VOL_DESC) {
- udf_load_pvoldesc(sb, bh);
- } else if (i == VDS_POS_LOGICAL_VOL_DESC) {
- if (udf_load_logicalvol(sb, bh, fileset)) {
- brelse(bh);
- return 1;
- }
- } else if (i == VDS_POS_PARTITION_DESC) {
- struct buffer_head *bh2 = NULL;
- if (udf_load_partdesc(sb, bh)) {
- brelse(bh);
- return 1;
- }
- for (j = vds[i].block + 1;
- j < vds[VDS_POS_TERMINATING_DESC].block;
- j++) {
- bh2 = udf_read_tagged(sb, j, j, &ident);
- gd = (struct generic_desc *)bh2->b_data;
- if (ident == TAG_IDENT_PD)
- if (udf_load_partdesc(sb,
- bh2)) {
- brelse(bh);
- brelse(bh2);
- return 1;
- }
- brelse(bh2);
- }
+ if (!vds[i].block)
+ continue;
+
+ bh = udf_read_tagged(sb, vds[i].block, vds[i].block,
+ &ident);
+
+ if (i == VDS_POS_PRIMARY_VOL_DESC)
+ udf_load_pvoldesc(sb, bh);
+ else if (i == VDS_POS_LOGICAL_VOL_DESC) {
+ if (udf_load_logicalvol(sb, bh, fileset)) {
+ brelse(bh);
+ return 1;
+ }
+ } else if (i == VDS_POS_PARTITION_DESC) {
+ struct buffer_head *bh2 = NULL;
+ if (udf_load_partdesc(sb, bh)) {
+ brelse(bh);
+ return 1;
+ }
+ for (j = vds[i].block + 1;
+ j < vds[VDS_POS_TERMINATING_DESC].block;
+ j++) {
+ bh2 = udf_read_tagged(sb, j, j, &ident);
+ gd = (struct generic_desc *)bh2->b_data;
+ if (ident == TAG_IDENT_PD)
+ if (udf_load_partdesc(sb, bh2)) {
+ brelse(bh);
+ brelse(bh2);
+ return 1;
+ }
+ brelse(bh2);
}
- brelse(bh);
}
+ brelse(bh);
}

return 0;
@@ -1475,6 +1463,7 @@ static int udf_process_sequence(struct super_block *sb, long block,
static int udf_check_valid(struct super_block *sb, int novrs, int silent)
{
long block;
+ struct udf_sb_info *sbi;

if (novrs) {
udf_debug("Validity check skipped because of novrs option\n");
@@ -1482,18 +1471,16 @@ static int udf_check_valid(struct super_block *sb, int novrs, int silent)
}
/* Check that it is NSR02 compliant */
/* Process any "CD-ROM Volume Descriptor Set" (ECMA 167 2/8.3.1) */
- else {
- block = udf_vrs(sb, silent);
- if (block == -1) {
- struct udf_sb_info *sbi = UDF_SB(sb);
- udf_debug("Failed to read byte 32768. Assuming open "
- "disc. Skipping validity check\n");
- if (!sbi->s_last_block)
- sbi->s_last_block = udf_get_last_block(sb);
- return 0;
- } else
- return !block;
- }
+ block = udf_vrs(sb, silent);
+ if (block != -1)
+ return !block;
+
+ sbi = UDF_SB(sb);
+ udf_debug("Failed to read byte 32768. Assuming open "
+ "disc. Skipping validity check\n");
+ if (!sbi->s_last_block)
+ sbi->s_last_block = udf_get_last_block(sb);
+ return 0;
}

static int udf_load_partition(struct super_block *sb, kernel_lb_addr *fileset)
@@ -1512,6 +1499,7 @@ static int udf_load_partition(struct super_block *sb, kernel_lb_addr *fileset)
for (i = 0; i < ARRAY_SIZE(sbi->s_anchor); i++) {
if (!sbi->s_anchor[i])
continue;
+
bh = udf_read_tagged(sb, sbi->s_anchor[i], sbi->s_anchor[i],
&ident);
if (!bh)
@@ -1553,72 +1541,73 @@ static int udf_load_partition(struct super_block *sb, kernel_lb_addr *fileset)
for (i = 0; i < sbi->s_partitions; i++) {
kernel_lb_addr uninitialized_var(ino);
struct udf_part_map *map = &sbi->s_partmaps[i];
- switch (map->s_partition_type) {
- case UDF_VIRTUAL_MAP15:
- case UDF_VIRTUAL_MAP20:
- if (!sbi->s_last_block) {
- sbi->s_last_block = udf_get_last_block(sb);
- udf_find_anchor(sb);
- }

- if (!sbi->s_last_block) {
- udf_debug("Unable to determine Lastblock (For "
- "Virtual Partition)\n");
- return 1;
- }
+ if (map->s_partition_type != UDF_VIRTUAL_MAP15 &&
+ map->s_partition_type != UDF_VIRTUAL_MAP20)
+ continue;

- for (j = 0; j < sbi->s_partitions; j++) {
- struct udf_part_map *map2 = &sbi->s_partmaps[j];
- if (j != i &&
- map->s_volumeseqnum ==
- map2->s_volumeseqnum &&
- map->s_partition_num ==
- map2->s_partition_num) {
- ino.partitionReferenceNum = j;
- ino.logicalBlockNum =
- sbi->s_last_block -
- map2->s_partition_root;
- break;
- }
+ if (!sbi->s_last_block) {
+ sbi->s_last_block = udf_get_last_block(sb);
+ udf_find_anchor(sb);
+ }
+
+ if (!sbi->s_last_block) {
+ udf_debug("Unable to determine Lastblock (For "
+ "Virtual Partition)\n");
+ return 1;
+ }
+
+ for (j = 0; j < sbi->s_partitions; j++) {
+ struct udf_part_map *map2 = &sbi->s_partmaps[j];
+ if (j != i &&
+ map->s_volumeseqnum ==
+ map2->s_volumeseqnum &&
+ map->s_partition_num ==
+ map2->s_partition_num) {
+ ino.partitionReferenceNum = j;
+ ino.logicalBlockNum =
+ sbi->s_last_block -
+ map2->s_partition_root;
+ break;
}
+ }

- if (j == sbi->s_partitions)
- return 1;
+ if (j == sbi->s_partitions)
+ return 1;

- sbi->s_vat_inode = udf_iget(sb, ino);
- if (!sbi->s_vat_inode)
- return 1;
+ sbi->s_vat_inode = udf_iget(sb, ino);
+ if (!sbi->s_vat_inode)
+ return 1;

- if (map->s_partition_type == UDF_VIRTUAL_MAP15) {
- map->s_type_specific.s_virtual.s_start_offset =
- udf_ext0_offset(sbi->s_vat_inode);
- map->s_type_specific.s_virtual.s_num_entries =
- (sbi->s_vat_inode->i_size - 36) >> 2;
- } else if (map->s_partition_type == UDF_VIRTUAL_MAP20) {
- uint32_t pos;
- struct virtualAllocationTable20 *vat20;
-
- pos = udf_block_map(sbi->s_vat_inode, 0);
- bh = sb_bread(sb, pos);
- if (!bh)
- return 1;
- vat20 = (struct virtualAllocationTable20 *)
- bh->b_data +
- udf_ext0_offset(sbi->s_vat_inode);
- map->s_type_specific.s_virtual.s_start_offset =
- le16_to_cpu(vat20->lengthHeader) +
- udf_ext0_offset(sbi->s_vat_inode);
- map->s_type_specific.s_virtual.s_num_entries =
- (sbi->s_vat_inode->i_size -
- map->s_type_specific.s_virtual.
- s_start_offset) >> 2;
- brelse(bh);
- }
- map->s_partition_root = udf_get_pblock(sb, 0, i, 0);
- map->s_partition_len =
- sbi->s_partmaps[ino.partitionReferenceNum].
- s_partition_len;
+ if (map->s_partition_type == UDF_VIRTUAL_MAP15) {
+ map->s_type_specific.s_virtual.s_start_offset =
+ udf_ext0_offset(sbi->s_vat_inode);
+ map->s_type_specific.s_virtual.s_num_entries =
+ (sbi->s_vat_inode->i_size - 36) >> 2;
+ } else if (map->s_partition_type == UDF_VIRTUAL_MAP20) {
+ uint32_t pos;
+ struct virtualAllocationTable20 *vat20;
+
+ pos = udf_block_map(sbi->s_vat_inode, 0);
+ bh = sb_bread(sb, pos);
+ if (!bh)
+ return 1;
+ vat20 = (struct virtualAllocationTable20 *)
+ bh->b_data +
+ udf_ext0_offset(sbi->s_vat_inode);
+ map->s_type_specific.s_virtual.s_start_offset =
+ le16_to_cpu(vat20->lengthHeader) +
+ udf_ext0_offset(sbi->s_vat_inode);
+ map->s_type_specific.s_virtual.s_num_entries =
+ (sbi->s_vat_inode->i_size -
+ map->s_type_specific.s_virtual.
+ s_start_offset) >> 2;
+ brelse(bh);
}
+ map->s_partition_root = udf_get_pblock(sb, 0, i, 0);
+ map->s_partition_len =
+ sbi->s_partmaps[ino.partitionReferenceNum].
+ s_partition_len;
}
return 0;
}
@@ -1627,26 +1616,26 @@ static void udf_open_lvid(struct super_block *sb)
{
struct udf_sb_info *sbi = UDF_SB(sb);
struct buffer_head *bh = sbi->s_lvid_bh;
- if (bh) {
- struct logicalVolIntegrityDesc *lvid =
- (struct logicalVolIntegrityDesc *)bh->b_data;
- struct logicalVolIntegrityDescImpUse *lvidiu =
- udf_sb_lvidiu(sbi);
+ struct logicalVolIntegrityDesc *lvid;
+ struct logicalVolIntegrityDescImpUse *lvidiu;
+ if (!bh)
+ return;

- lvidiu->impIdent.identSuffix[0] = UDF_OS_CLASS_UNIX;
- lvidiu->impIdent.identSuffix[1] = UDF_OS_ID_LINUX;
- udf_time_to_disk_stamp(&lvid->recordingDateAndTime,
- CURRENT_TIME);
- lvid->integrityType = LVID_INTEGRITY_TYPE_OPEN;
+ lvid = (struct logicalVolIntegrityDesc *)bh->b_data;
+ lvidiu = udf_sb_lvidiu(sbi);

- lvid->descTag.descCRC = cpu_to_le16(
- udf_crc((char *)lvid + sizeof(tag),
- le16_to_cpu(lvid->descTag.descCRCLength),
- 0));
+ lvidiu->impIdent.identSuffix[0] = UDF_OS_CLASS_UNIX;
+ lvidiu->impIdent.identSuffix[1] = UDF_OS_ID_LINUX;
+ udf_time_to_disk_stamp(&lvid->recordingDateAndTime,
+ CURRENT_TIME);
+ lvid->integrityType = LVID_INTEGRITY_TYPE_OPEN;

- lvid->descTag.tagChecksum = udf_tag_checksum(&lvid->descTag);
- mark_buffer_dirty(bh);
- }
+ lvid->descTag.descCRC = cpu_to_le16(
+ udf_crc((char *)lvid + sizeof(tag),
+ le16_to_cpu(lvid->descTag.descCRCLength), 0));
+
+ lvid->descTag.tagChecksum = udf_tag_checksum(&lvid->descTag);
+ mark_buffer_dirty(bh);
}

static void udf_close_lvid(struct super_block *sb)
@@ -1654,36 +1643,35 @@ static void udf_close_lvid(struct super_block *sb)
struct udf_sb_info *sbi = UDF_SB(sb);
struct buffer_head *bh = sbi->s_lvid_bh;
struct logicalVolIntegrityDesc *lvid;
+ struct logicalVolIntegrityDescImpUse *lvidiu;

if (!bh)
return;

lvid = (struct logicalVolIntegrityDesc *)bh->b_data;

- if (lvid->integrityType == LVID_INTEGRITY_TYPE_OPEN) {
- struct logicalVolIntegrityDescImpUse *lvidiu =
- udf_sb_lvidiu(sbi);
- lvidiu->impIdent.identSuffix[0] = UDF_OS_CLASS_UNIX;
- lvidiu->impIdent.identSuffix[1] = UDF_OS_ID_LINUX;
- udf_time_to_disk_stamp(&lvid->recordingDateAndTime,
- CURRENT_TIME);
- if (UDF_MAX_WRITE_VERSION > le16_to_cpu(lvidiu->maxUDFWriteRev))
- lvidiu->maxUDFWriteRev =
- cpu_to_le16(UDF_MAX_WRITE_VERSION);
- if (sbi->s_udfrev > le16_to_cpu(lvidiu->minUDFReadRev))
- lvidiu->minUDFReadRev = cpu_to_le16(sbi->s_udfrev);
- if (sbi->s_udfrev > le16_to_cpu(lvidiu->minUDFWriteRev))
- lvidiu->minUDFWriteRev = cpu_to_le16(sbi->s_udfrev);
- lvid->integrityType = cpu_to_le32(LVID_INTEGRITY_TYPE_CLOSE);
-
- lvid->descTag.descCRC = cpu_to_le16(
- udf_crc((char *)lvid + sizeof(tag),
- le16_to_cpu(lvid->descTag.descCRCLength),
- 0));
-
- lvid->descTag.tagChecksum = udf_tag_checksum(&lvid->descTag);
- mark_buffer_dirty(bh);
- }
+ if (lvid->integrityType != LVID_INTEGRITY_TYPE_OPEN)
+ return;
+
+ lvidiu = udf_sb_lvidiu(sbi);
+ lvidiu->impIdent.identSuffix[0] = UDF_OS_CLASS_UNIX;
+ lvidiu->impIdent.identSuffix[1] = UDF_OS_ID_LINUX;
+ udf_time_to_disk_stamp(&lvid->recordingDateAndTime, CURRENT_TIME);
+ if (UDF_MAX_WRITE_VERSION > le16_to_cpu(lvidiu->maxUDFWriteRev))
+ lvidiu->maxUDFWriteRev = cpu_to_le16(UDF_MAX_WRITE_VERSION);
+ if (sbi->s_udfrev > le16_to_cpu(lvidiu->minUDFReadRev))
+ lvidiu->minUDFReadRev = cpu_to_le16(sbi->s_udfrev);
+ if (sbi->s_udfrev > le16_to_cpu(lvidiu->minUDFWriteRev))
+ lvidiu->minUDFWriteRev = cpu_to_le16(sbi->s_udfrev);
+ lvid->integrityType = cpu_to_le32(LVID_INTEGRITY_TYPE_CLOSE);
+
+ lvid->descTag.descCRC = cpu_to_le16(
+ udf_crc((char *)lvid + sizeof(tag),
+ le16_to_cpu(lvid->descTag.descCRCLength),
+ 0));
+
+ lvid->descTag.tagChecksum = udf_tag_checksum(&lvid->descTag);
+ mark_buffer_dirty(bh);
}

static void udf_sb_free_bitmap(struct udf_bitmap *bitmap)
--
1.5.3.7