Skip to contentSkip to conversation

Use SEEK_{SET,CUR,END} instead of hardcoded values

PATCH In review Josef 'Jeff' Sipek 7 participants 20 messages Sep 17, 2006 – Sep 19, 2006

Subsystems (8)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Use SEEK_{SET,CUR,END} instead of hardcoded values

In July, David Howells added SEEK_{SET,CUR,END} definitions to include/linux/fs.h

The following patches convert offenders which were found by grep'ing the source tree.

Josef 'Jeff' Sipek

11 files changed, 34 insertions(+), 39 deletions(-)
drivers/char/mbcs.c                    |    7 ++++---
drivers/isdn/hardware/eicon/dsp_defs.h |    3 ---
drivers/mtd/mtdchar.c                  |   11 ++++-------
fs/cifs/cifsfs.c                       |    2 +-
fs/locks.c                             |   12 ++++++------
fs/nfs/file.c                          |    2 +-
fs/xfs/xfs_vnodeops.c                  |    6 +++---
sound/core/info.c                      |    6 +++---
sound/drivers/opl4/opl4_proc.c         |    6 +++---
sound/isa/gus/gus_mem_proc.c           |    6 +++---
sound/pci/mixart/mixart.c              |   12 ++++++------
#1 lore raw

PATCH 1/1 MBCS: Use SEEK_{SET, CUR, END} instead of hardcoded values

MBCS: Use SEEK_{SET,CUR,END} instead of hardcoded values

--

drivers/char/mbcs.c +4 -3
diff -r abfba7cd6289 -r 115dd6f4c050 drivers/char/mbcs.c
@@ -22,6 +22,7 @@
 #include <linux/delay.h>
 #include <linux/device.h>
 #include <linux/mm.h>
+#include <linux/fs.h>
 #include <linux/uio.h>
 #include <asm/io.h>
 #include <asm/uaccess.h>
@@ -447,15 +448,15 @@ loff_t mbcs_sram_llseek(struct file * fi
 	loff_t newpos;
 
 	switch (whence) {
-	case 0:		/* SEEK_SET */
+	case SEEK_SET:
 		newpos = off;
 		break;
 
-	case 1:		/* SEEK_CUR */
+	case SEEK_CUR:
 		newpos = filp->f_pos + off;
 		break;
 
-	case 2:		/* SEEK_END */
+	case SEEK_END:
 		newpos = MBCS_SRAM_SIZE + off;
 		break;
 
#2 lore raw

PATCH 1/1 sound core: Use SEEK_{SET, CUR, END} instead of hardcoded values

In reply to Josef 'Jeff' Sipek

sound core: Use SEEK_{SET,CUR,END} instead of hardcoded values

--

sound/core/info.c +3 -3
diff -r 1622a39ffb54 -r 7e68f25a3e0c sound/core/info.c
@@ -174,15 +174,15 @@ static loff_t snd_info_entry_llseek(stru
 	switch (entry->content) {
 	case SNDRV_INFO_CONTENT_TEXT:
 		switch (orig) {
-		case 0:	/* SEEK_SET */
+		case SEEK_SET:
 			file->f_pos = offset;
 			ret = file->f_pos;
 			goto out;
-		case 1:	/* SEEK_CUR */
+		case SEEK_CUR:
 			file->f_pos += offset;
 			ret = file->f_pos;
 			goto out;
-		case 2:	/* SEEK_END */
+		case SEEK_END:
 		default:
 			ret = -EINVAL;
 			goto out;
#3 lore raw

PATCH 1/1 opl4: Use SEEK_{SET, CUR, END} instead of hardcoded values

In reply to Josef 'Jeff' Sipek

opl4: Use SEEK_{SET,CUR,END} instead of hardcoded values

--

sound/drivers/opl4/opl4_proc.c +3 -3
diff -r 7e68f25a3e0c -r 057a40d60798 sound/drivers/opl4/opl4_proc.c
@@ -105,13 +105,13 @@ static long long snd_opl4_mem_proc_llsee
 					  struct file *file, long long offset, int orig)
 {
 	switch (orig) {
-	case 0: /* SEEK_SET */
+	case SEEK_SET:
 		file->f_pos = offset;
 		break;
-	case 1: /* SEEK_CUR */
+	case SEEK_CUR:
 		file->f_pos += offset;
 		break;
-	case 2: /* SEEK_END, offset is negative */
+	case SEEK_END: /* offset is negative */
 		file->f_pos = entry->size + offset;
 		break;
 	default:
#4 lore raw

PATCH 1/1 EICON ISDN: Removed unused definitions for OS_SEEK_*

In reply to Josef 'Jeff' Sipek

EICON ISDN: Removed unused definitions for OS_SEEK_*

--

drivers/isdn/hardware/eicon/dsp_defs.h +0 -3
diff -r 115dd6f4c050 -r e90cdef08ec3 drivers/isdn/hardware/eicon/dsp_defs.h
@@ -34,9 +34,6 @@
  *
  * I/O functions returns -1 on error, 0 on EOF
  */
-#define OS_SEEK_SET 0
-#define OS_SEEK_CUR 1
-#define OS_SEEK_END 2
 struct _OsFileHandle_;
 typedef long (  * OsFileIo)  (struct _OsFileHandle_    *handle,
                                 void                     *buffer,
#6 lore raw

PATCH 1/1 gus: Use SEEK_{SET, CUR, END} instead of hardcoded values

In reply to Josef 'Jeff' Sipek

gus: Use SEEK_{SET,CUR,END} instead of hardcoded values

--

sound/isa/gus/gus_mem_proc.c +3 -3
diff -r 057a40d60798 -r f255d0d208e7 sound/isa/gus/gus_mem_proc.c
@@ -61,13 +61,13 @@ static long long snd_gf1_mem_proc_llseek
 	struct gus_proc_private *priv = entry->private_data;
 
 	switch (orig) {
-	case 0:	/* SEEK_SET */
+	case SEEK_SET:
 		file->f_pos = offset;
 		break;
-	case 1:	/* SEEK_CUR */
+	case SEEK_CUR:
 		file->f_pos += offset;
 		break;
-	case 2: /* SEEK_END, offset is negative */
+	case SEEK_END: /* offset is negative */
 		file->f_pos = priv->size + offset;
 		break;
 	default:
#7 lore raw

PATCH 1/1 CIFS: Use SEEK_END instead of hardcoded value

In reply to Josef 'Jeff' Sipek

CIFS: Use SEEK_END instead of hardcoded value

--

fs/cifs/cifsfs.c +1 -1
diff -r 7d3e8ba1ace3 -r e2fae9fe7a30 fs/cifs/cifsfs.c
@@ -510,7 +510,7 @@ static loff_t cifs_llseek(struct file *f
 static loff_t cifs_llseek(struct file *file, loff_t offset, int origin)
 {
 	/* origin == SEEK_END => we must revalidate the cached file length */
-	if (origin == 2) {
+	if (origin == SEEK_END) {
 		int retval = cifs_revalidate(file->f_dentry);
 		if (retval < 0)
 			return (loff_t)retval;
#8 lore raw

PATCH 1/1 mixart: Use SEEK_{SET, CUR, END} instead of hardcoded values

In reply to Josef 'Jeff' Sipek

mixart: Use SEEK_{SET,CUR,END} instead of hardcoded values

--

sound/pci/mixart/mixart.c +6 -6
diff -r f255d0d208e7 -r 9ef3df8b70fe sound/pci/mixart/mixart.c
@@ -1109,13 +1109,13 @@ static long long snd_mixart_BA0_llseek(s
 	offset = offset & ~3; /* 4 bytes aligned */
 
 	switch(orig) {
-	case 0:  /* SEEK_SET */
+	case SEEK_SET:
 		file->f_pos = offset;
 		break;
-	case 1:  /* SEEK_CUR */
+	case SEEK_CUR:
 		file->f_pos += offset;
 		break;
-	case 2:  /* SEEK_END, offset is negative */
+	case SEEK_END: /* offset is negative */
 		file->f_pos = MIXART_BA0_SIZE + offset;
 		break;
 	default:
@@ -1135,13 +1135,13 @@ static long long snd_mixart_BA1_llseek(s
 	offset = offset & ~3; /* 4 bytes aligned */
 
 	switch(orig) {
-	case 0:  /* SEEK_SET */
+	case SEEK_SET:
 		file->f_pos = offset;
 		break;
-	case 1:  /* SEEK_CUR */
+	case SEEK_CUR:
 		file->f_pos += offset;
 		break;
-	case 2: /* SEEK_END, offset is negative */
+	case SEEK_END: /* offset is negative */
 		file->f_pos = MIXART_BA1_SIZE + offset;
 		break;
 	default:
#9 lore raw

PATCH 1/1 XFS: Use SEEK_{SET, CUR, END} instead of hardcoded values

In reply to Josef 'Jeff' Sipek

XFS: Use SEEK_{SET,CUR,END} instead of hardcoded values

--

fs/xfs/xfs_vnodeops.c +3 -3
diff -r e2fae9fe7a30 -r 4cdee5980dad fs/xfs/xfs_vnodeops.c
@@ -4510,12 +4510,12 @@ xfs_change_file_space(
 	xfs_iunlock(ip, XFS_ILOCK_SHARED);
 
 	switch (bf->l_whence) {
-	case 0: /*SEEK_SET*/
+	case SEEK_SET:
 		break;
-	case 1: /*SEEK_CUR*/
+	case SEEK_CUR:
 		bf->l_start += offset;
 		break;
-	case 2: /*SEEK_END*/
+	case SEEK_END:
 		bf->l_start += ip->i_d.di_size;
 		break;
 	default:
#13 lore raw

PATCH 1/1 NFS: Use SEEK_END instead of hardcoded value

In reply to Josef 'Jeff' Sipek

NFS: Use SEEK_END instead of hardcoded value

--

fs/nfs/file.c +1 -1
diff -r 4cdee5980dad -r ca33dbd739b3 fs/nfs/file.c
@@ -157,7 +157,7 @@ static loff_t nfs_file_llseek(struct fil
 static loff_t nfs_file_llseek(struct file *filp, loff_t offset, int origin)
 {
 	/* origin == SEEK_END => we must revalidate the cached file length */
-	if (origin == 2) {
+	if (origin == SEEK_END) {
 		struct inode *inode = filp->f_mapping->host;
 		int retval = nfs_revalidate_file_size(inode, filp);
 		if (retval < 0)
#14 lore raw

PATCH 1/1 VFS: Use SEEK_{SET, CUR, END} instead of hardcoded values

In reply to Josef 'Jeff' Sipek

VFS: Use SEEK_{SET,CUR,END} instead of hardcoded values

--

fs/locks.c +6 -6
diff -r ca33dbd739b3 -r 1622a39ffb54 fs/locks.c
@@ -314,13 +314,13 @@ static int flock_to_posix_lock(struct fi
 	off_t start, end;
 
 	switch (l->l_whence) {
-	case 0: /*SEEK_SET*/
+	case SEEK_SET:
 		start = 0;
 		break;
-	case 1: /*SEEK_CUR*/
+	case SEEK_CUR:
 		start = filp->f_pos;
 		break;
-	case 2: /*SEEK_END*/
+	case SEEK_END:
 		start = i_size_read(filp->f_dentry->d_inode);
 		break;
 	default:
@@ -364,13 +364,13 @@ static int flock64_to_posix_lock(struct 
 	loff_t start;
 
 	switch (l->l_whence) {
-	case 0: /*SEEK_SET*/
+	case SEEK_SET:
 		start = 0;
 		break;
-	case 1: /*SEEK_CUR*/
+	case SEEK_CUR:
 		start = filp->f_pos;
 		break;
-	case 2: /*SEEK_END*/
+	case SEEK_END:
 		start = i_size_read(filp->f_dentry->d_inode);
 		break;
 	default:
#15 lore raw

PATCH 1/1 MTD: Use SEEK_{SET, CUR, END} instead of hardcoded values

In reply to Josef 'Jeff' Sipek

MTD: Use SEEK_{SET,CUR,END} instead of hardcoded values

--

drivers/mtd/mtdchar.c +4 -7
diff -r e90cdef08ec3 -r 7d3e8ba1ace3 drivers/mtd/mtdchar.c
@@ -62,15 +62,12 @@ static loff_t mtd_lseek (struct file *fi
 	struct mtd_info *mtd = mfi->mtd;
 
 	switch (orig) {
-	case 0:
-		/* SEEK_SET */
-		break;
-	case 1:
-		/* SEEK_CUR */
+	case SEEK_SET:
+		break;
+	case SEEK_CUR:
 		offset += file->f_pos;
 		break;
-	case 2:
-		/* SEEK_END */
+	case SEEK_END:
 		offset += mtd->size;
 		break;
 	default:
#17 lore raw
In reply to Josef 'Jeff' Sipek
Quoted 4 lines · Josef 'Jeff' Sipek

In July, David Howells added SEEK_{SET,CUR,END} definitions to include/linux/fs.h

The following patches convert offenders which were found by grep'ing the source tree.

Looks like a good change to me.

Nitpick, do you need 11 patches to do it? 1 would be fine, I think?

Signature · 2 lines
SUSE Labs, Novell Inc.
Send instant messages to your online friends http://au.messenger.yahoo.com 
#18 lore raw
Quoted 11 lines · Nick Piggin
Quoted 6 lines · Josef 'Jeff' Sipek

In July, David Howells added SEEK_{SET,CUR,END} definitions to include/linux/fs.h

The following patches convert offenders which were found by grep'ing the source
tree.

Looks like a good change to me.

Nitpick, do you need 11 patches to do it? 1 would be fine, I think?

I don't. I just got carried away with Mercurial's patch queues support.

Josef 'Jeff' Sipek.

Signature · 1 line
A computer without Microsoft is like chocolate cake without mustard.
Acked-by on v1 1/1
#5 lore raw

Re: [PATCH 2 of 11] EICON ISDN: Removed unused definitions for OS_SEEK_*

In reply to Josef 'Jeff' Sipek

Agreed, these defines are not used in the linux kernel. They can be removed.

Armin

Quoted 1 line · Josef 'Jeff' Sipek

EICON ISDN: Removed unused definitions for OS_SEEK_*

--

drivers/isdn/hardware/eicon/dsp_defs.h +0 -3
diff -r 115dd6f4c050 -r e90cdef08ec3 drivers/isdn/hardware/eicon/dsp_defs.h
@@ -34,9 +34,6 @@
  *
  * I/O functions returns -1 on error, 0 on EOF
  */
-#define OS_SEEK_SET 0
-#define OS_SEEK_CUR 1
-#define OS_SEEK_END 2
 struct _OsFileHandle_;
 typedef long (  * OsFileIo)  (struct _OsFileHandle_    *handle,
                                 void                     *buffer,
#10 lore raw

Re: [PATCH 5 of 11] XFS: Use SEEK_{SET, CUR, END} instead of hardcoded values

In reply to Josef 'Jeff' Sipek
Quoted 1 line · Josef 'Jeff' Sipek

XFS: Use SEEK_{SET,CUR,END} instead of hardcoded values

The hard coded values used in xfs_change_file_space() are documented as part of the API to the userspace functions that use this interface in xfsctl(3). That is:

XFS_IOC_FREESP
XFS_IOC_FREESP64
XFS_IOC_ALLOCSP
XFS_IOC_ALLOCSP64

Alter storage space associated with a section of the ordinary file specified. The section is specified by a variable of type xfs_flock64_t, pointed to by the final argument. The data type xfs_flock64_t contains the following
members: l_whence is 0, 1, or 2 to indicate that the relative offset l_start will be measured from the start of the file, the current position, or the end of the file, respectively.

Hence I think that the hard coded values should not be changed to something that is defined outside of XFS's API.

Cheers,

Dave.

Signature · 3 lines
Dave Chinner
Principal Engineer
SGI Australian Software Group
#11 lore raw

Re: [PATCH 5 of 11] XFS: Use SEEK_{SET, CUR, END} instead of hardcoded values

Quoted 2 lines · David Chinner

The hard coded values used in xfs_change_file_space() are documented as part of the API to the userspace functions that use this interface in xfsctl(3).

Hmmm... that's a good point. I think you're right on this account, and so the comments in:

		case 0: /*SEEK_SET*/
			break;
		case 1: /*SEEK_CUR*/
			bf->l_start += offset;
			break;
		case 2: /*SEEK_END*/
			bf->l_start += ip->i_d.di_size;
			break;

should be stripped off as they are not exactly correct.

David

Acked-by on v1 1/1
#19 lore raw
In reply to Josef 'Jeff' Sipek
Quoted 5 lines · Josef 'Jeff' Sipek

In July, David Howells added SEEK_{SET,CUR,END} definitions to include/linux/fs.h

The following patches convert offenders which were found by grep'ing the source tree.

Looks good, though I think you do have to drop the XFS portion of the patch, though you could strip the comments from the case statements there.

So NAK for the XFS patch, but for the rest:

#12 lore raw

Re: [PATCH 5 of 11] XFS: Use SEEK_{SET, CUR, END} instead of hardcoded values

In reply to David Howells
Quoted 17 lines · David Howells
Quoted 2 lines · David Chinner

The hard coded values used in xfs_change_file_space() are documented as part of the API to the userspace functions that use this interface in xfsctl(3).

Hmmm... that's a good point. I think you're right on this account, and so the comments in:

		case 0: /*SEEK_SET*/
			break;
		case 1: /*SEEK_CUR*/
			bf->l_start += offset;
			break;
		case 2: /*SEEK_END*/
			bf->l_start += ip->i_d.di_size;
			break;
Quoted 1 line

should be stripped off as they are not exactly correct.

Sure, they're not _exactly_ the same as seek semantics, but the comment is informative enough to tell you what the magic numbers are supposed to mean as you read the code.

If you really want to strip these out these comments, can you please replace them with a new comment that documents the magic number behaviour?

Cheers,

Dave.

Signature · 3 lines
Dave Chinner
Principal Engineer
SGI Australian Software Group