Messages in this thread Patch in this message | | | Date | Sat, 19 Dec 1998 13:54:19 +0000 (GMT) | From | Tigran Aivazian <> | Subject | PATCH: bdevname()/cdevname()/kdevname(), do_open() + misc. |
| |
Hello Alan,
The simple patch I promised is below. What it does is this:
a) Adds bdevname() and cdevname() functions which return the strings like fd(2,0) and cua(5,64) respectively. I only changed one call to kdevname() to use bdevname() "VFS: Disk change detected" now prints in fd(2,0) format. Justification - Alan Cox said it might be useful.
b) Removes a couple of unneeded headers from fs/open.c.
c) Corrects a typo in fs/devices.c "." was spelled as "..".
d) removes do_open() function and puts the stuff it used to do back into sys_open(). Because it is not worth calling a real function (not inline!) with lots of arguments to do such a simple thing as do_open(). Someone even put a comment there that it should probably go back to sys_open() ...
e) Adds declarations of kdevname()/bdevname()/cdevname() to <linux/fs.h>. And a comment /* fs/devices.c */ similar to the /* fs/open.c */ that was there already.
h) Changes the buf[32] in kdevname() to buf[2*sizeof(kdev_t) + 4].
Regards, Tigran.
diff -ur linux/fs/devices.c linux-2.1.131.new/fs/devices.c --- linux/fs/devices.c Mon Aug 24 20:33:11 1998 +++ linux-2.1.131.new/fs/devices.c Sat Dec 19 13:00:47 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,26 @@ }; /* - * 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) +char * bdevname(kdev_t dev) +{ + static char buffer[32]; + sprintf(buffer, "%s(%d,%d)", blkdevs[MAJOR(dev)].name, MAJOR(dev), MINOR(dev)); + return buffer; +} + +char * cdevname(kdev_t dev) { static char buffer[32]; + sprintf(buffer, "%s(%d,%d)", chrdevs[MAJOR(dev)].name, MAJOR(dev), MINOR(dev)); + return buffer; +} + +char * kdevname(kdev_t dev) +{ + static char buffer[2*sizeof(kdev_t)+4]; sprintf(buffer, "%02x:%02x", MAJOR(dev), MINOR(dev)); return buffer; } diff -ur linux/fs/open.c linux-2.1.131.new/fs/open.c --- linux/fs/open.c Sat Dec 19 10:21:16 1998 +++ linux-2.1.131.new/fs/open.c Sat Dec 19 12:13:00 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(); @@ -733,13 +719,17 @@ goto out; tmp = getname(filename); - error = PTR_ERR(tmp); - if (IS_ERR(tmp)) + if (IS_ERR(tmp)) { + error = PTR_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.131.new/include/linux/fs.h --- linux/include/linux/fs.h Sat Dec 19 10:20:45 1998 +++ linux-2.1.131.new/include/linux/fs.h Sat Dec 19 12:57:59 1998 @@ -699,11 +699,15 @@ 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/
| |