Messages in this thread Patch in this message | | | Date | Wed, 23 Dec 1998 14:54:09 +0000 (GMT) | From | Tigran Aivazian <> | Subject | [patch]: a small one, corrected and improved. |
| |
Hello,
Here is a modified version (thanks to all guys who commented - I now understand some of my mistakes a bit clearer :) ) of a very simple patch:
0. It is against 2.1.132.
1. Corrects a typo.
2. Gets rid of do_open() because it seems more efficient to do what it does inside sys_open().
3. Introduces two functions bdevname(kdev_t dev) and cdevname(kdev_t dev) that return the symbolic form of device in the form "fd(2,0)" or "cua(5,64)" respectively.
4. Makes check_disk_change() use the new function bdevname() instead of kdevname().
All three k,c,bdevname() are now declared in <linux/fs.h> and a comment line /* fs/devices.c */ is added there.
Regards, Tigran A. Aivazian, http://www.aivazian.demon.co.uk/
PS. Sorry if I mail to you what I should have mailed to Linus. This is only because I already mailed you this thing earlier and sending the same thing (or different versions of the same thing) to two different maintainers I consider unethical.
diff -ur linux/fs/devices.c linux-2.1.132.new/fs/devices.c --- linux/fs/devices.c Mon Aug 24 20:33:11 1998 +++ linux-2.1.132.new/fs/devices.c Wed Dec 23 13:29:18 1998 @@ -210,11 +210,11 @@ return 0; printk(KERN_DEBUG "VFS: Disk change detected on device %s\n", - kdevname(dev)); + bdevname(dev)); sb = get_super(dev); if (sb && invalidate_inodes(sb)) - printk("VFS: busy inodes on changed media..\n"); + printk("VFS: busy inodes on changed media.\n"); invalidate_buffers(dev); @@ -338,13 +338,36 @@ }; /* - * Print device name (in decimal, hexadecimal or symbolic) - - * at present hexadecimal only. + * Print device name (in decimal, hexadecimal or symbolic) * Note: returns pointer to static data! */ char * kdevname(kdev_t dev) { static char buffer[32]; sprintf(buffer, "%02x:%02x", MAJOR(dev), MINOR(dev)); + return buffer; +} + +char * bdevname(kdev_t dev) +{ + static char buffer[32]; + char * name = blkdevs[MAJOR(dev)].name; + + if (name) + sprintf(buffer, "%s(%d,%d)", name, MAJOR(dev), MINOR(dev)); + else + sprintf(buffer, "unknown-block(%d,%d)", MAJOR(dev), MINOR(dev)); + return buffer; +} + +char * cdevname(kdev_t dev) +{ + static char buffer[32]; + char * name = chrdevs[MAJOR(dev)].name; + + if (name) + sprintf(buffer, "%s(%d,%d)", name, MAJOR(dev), MINOR(dev)); + else + sprintf(buffer, "unknown-char(%d,%d)", MAJOR(dev), MINOR(dev)); return buffer; } diff -ur linux/fs/open.c linux-2.1.132.new/fs/open.c --- linux/fs/open.c Tue Dec 1 19:03:25 1998 +++ linux-2.1.132.new/fs/open.c Wed Dec 23 13:13:45 1998 @@ -6,14 +6,11 @@ #include <linux/mm.h> #include <linux/utime.h> -#include <linux/fcntl.h> -#include <linux/stat.h> #include <linux/file.h> #include <linux/smp_lock.h> #include <linux/quotaops.h> #include <asm/uaccess.h> -#include <asm/bitops.h> asmlinkage int sys_statfs(const char * path, struct statfs * buf) { @@ -671,18 +668,6 @@ return ERR_PTR(error); } -/* should probably go into sys_open() */ -static int do_open(const char * filename, int flags, int mode, int fd) -{ - struct file * f; - - f = filp_open(filename, flags, mode); - if (IS_ERR(f)) - return PTR_ERR(f); - fd_install(fd, f); - return 0; -} - /* * Find an empty file descriptor entry, and mark it busy. */ @@ -726,6 +711,7 @@ { char * tmp; int fd, error; + struct file * f; lock_kernel(); fd = get_unused_fd(); @@ -736,10 +722,13 @@ error = PTR_ERR(tmp); if (IS_ERR(tmp)) goto out_fail; - error = do_open(tmp, flags, mode, fd); + f = filp_open(tmp, flags, mode); putname(tmp); - if (error) + if (IS_ERR(f)) { + error = PTR_ERR(f); goto out_fail; + } + fd_install(fd, f); out: unlock_kernel(); return fd; diff -ur linux/include/linux/fs.h linux-2.1.132.new/include/linux/fs.h --- linux/include/linux/fs.h Tue Dec 22 18:44:25 1998 +++ linux-2.1.132.new/include/linux/fs.h Wed Dec 23 13:19:47 1998 @@ -702,11 +702,16 @@ extern struct file_operations def_blk_fops; extern struct inode_operations blkdev_inode_operations; +/* fs/devices.c */ extern int register_chrdev(unsigned int, const char *, struct file_operations *); extern int unregister_chrdev(unsigned int major, const char * name); extern int chrdev_open(struct inode * inode, struct file * filp); extern struct file_operations def_chr_fops; extern struct inode_operations chrdev_inode_operations; +extern char * bdevname(kdev_t dev); +extern char * cdevname(kdev_t dev); +extern char * kdevname(kdev_t dev); + extern void init_fifo(struct inode * inode); extern struct inode_operations fifo_inode_operations;
- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.rutgers.edu Please read the FAQ at http://www.tux.org/lkml/
| |