[PATCH 1 OF 5] Preparation for named pipes

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



In file fs/inode.c, function read_inode() dereferenced a pointer and
later checked that the pointer was not NULL. Now, it first makes the
check.

Remove a very small usage of members i_pipe and i_sock in inode
structures, as well as those members in preparation for the
implementation of named pipes and sockets.

In file fs/minix/namei.c, in many functions, release resources in the
inverse order as they were allocated.

In fs/pipe.c, pipe buffers are now allocated in the pipe_open
function, instead of inode creation function get_pipe_inode().

In init/main.c, after failing to find the init program, opened
/dev/tty0 as console and starts /bin/sh, but in ELKS, the console is
in /dev/tty1, not /dev/tty0. Also, fixed the order of search of the
init program.

Code size was reduced by 32 bytes and bss reduced by 192 bytes.
diff -Nur elks.orig/fs/inode.c elks/fs/inode.c
--- elks.orig/fs/inode.c	2015-03-08 17:08:12.000000000 -0600
+++ elks/fs/inode.c	2015-03-11 17:04:40.000000000 -0600
@@ -175,10 +175,10 @@
 static void read_inode(register struct inode *inode)
 {
     struct super_block *sb = inode->i_sb;
-    register struct super_operations *sop = sb->s_op;
+    register struct super_operations *sop;
 
     lock_inode(inode);
-    if (sb && sop && sop->read_inode)
+    if (sb && (sop = sb->s_op) && sop->read_inode)
 	sop->read_inode(inode);
     unlock_inode(inode);
 }
@@ -325,7 +325,7 @@
 	    return;
 	}
 #ifdef NOT_YET
-	if (inode->i_pipe)
+	if((inode->i_mode & S_IFMT) == S_IFIFO)
 	    wake_up_interruptible(&PIPE_WAIT(*inode));
 #endif
 	goto ini_loop;
@@ -339,7 +339,7 @@
 	    }
 
 	    wake_up(&inode_wait);
-	    if (inode->i_pipe && inode->u.pipe_i.base) {
+	    if (((inode->i_mode & S_IFMT) == S_IFIFO) && inode->u.pipe_i.base) {
 	    /* Free up any memory allocated to the pipe */
 		free_pipe_mem(inode->u.pipe_i.base);
 		inode->u.pipe_i.base = NULL;
@@ -437,16 +437,6 @@
 	inode->i_gid = (__u8) current->egid;
 	inode->i_atime = inode->i_mtime = inode->i_ctime = CURRENT_TIME;
 
-	if (!(PIPE_BASE(*inode) = get_pipe_mem())) {
-	    iput(inode);
-	    return NULL;
-	}
-	inode->i_pipe = 1;
-	PIPE_START(*inode) = PIPE_LEN(*inode) = 0;
-	PIPE_RD_OPENERS(*inode) = PIPE_WR_OPENERS(*inode) = 0;
-	PIPE_READERS(*inode) = PIPE_WRITERS(*inode) = 0;
-	PIPE_LOCK(*inode) = 0;
-
 #if 0
 	inode->i_blksize = PAGE_SIZE;
 #endif
diff -Nur elks.orig/fs/minix/namei.c elks/fs/minix/namei.c
--- elks.orig/fs/minix/namei.c	2015-03-08 17:08:12.000000000 -0600
+++ elks/fs/minix/namei.c	2015-03-11 17:04:40.000000000 -0600
@@ -264,10 +264,10 @@
 	return error;
     }
     de->inode = inode->i_ino;
+    *result = inode;
     mark_buffer_dirty(bh, 1);
     brelse(bh);
     iput(dir);
-    *result = inode;
     return 0;
 }
 
@@ -298,7 +298,6 @@
 	inode->i_rdev = to_kdev_t(rdev);
 
     error = minix_add_entry(dir, name, len, &bh, &de);
-#if 1
     if (error) {
 	inode->i_nlink--;
 	inode->i_dirt = 1;
@@ -309,22 +308,9 @@
     de->inode = inode->i_ino;
     mark_buffer_dirty(bh, 1);
     brelse(bh);
-    iput(dir);
     iput(inode);
-    return 0;
-#else  /* MJN3: If the ordering of the iput()s isn't important, do this. */
-    if (error) {
-	inode->i_nlink--;
-	inode->i_dirt = 1;
-    } else {
-	de->inode = inode->i_ino;
-	mark_buffer_dirty(bh, 1);
-	brelse(bh);
-    }
     iput(dir);
-    iput(inode);
     return error;
-#endif
 }
 
 int minix_mkdir(register struct inode *dir, char *name, size_t len, int mode)
@@ -360,9 +346,9 @@
     debug("m_mkdir: starting minix_bread\n");
     dir_block = minix_bread(inode, 0, 1);
     if (!dir_block) {
-	iput(dir);
 	inode->i_nlink--;
 	iput(inode);
+	iput(dir);
 	return -ENOSPC;
     }
     debug("m_mkdir: read succeeded\n");
@@ -381,9 +367,9 @@
     debug("m_mkdir: dir_block update succeeded\n");
     error = minix_add_entry(dir, name, len, &bh, &de);
     if (error) {
-	iput(dir);
 	inode->i_nlink = 0;
 	iput(inode);
+	iput(dir);
 	return error;
     }
     map_buffer(bh);
@@ -391,10 +377,10 @@
     mark_buffer_dirty(bh, 1);
     dir->i_nlink++;
     dir->i_dirt = 1;
-    iput(dir);
-    iput(inode);
     unmap_brelse(bh);
     debug("m_mkdir: done!\n");
+    iput(inode);
+    iput(dir);
     return 0;
 }
 
@@ -592,9 +578,9 @@
     }
     name_block = minix_bread(inode, 0, 1);
     if (!name_block) {
-	iput(dir);
 	inode->i_nlink--;
 	iput(inode);
+	iput(dir);
 	return -ENOSPC;
     }
     map_buffer(name_block);
@@ -624,8 +610,8 @@
     de->inode = inode->i_ino;
     mark_buffer_dirty(bh, 1);
     brelse(bh);
-    iput(dir);
     iput(inode);
+    iput(dir);
     return 0;
 }
 
@@ -660,10 +646,10 @@
     de->inode = oldinode->i_ino;
     mark_buffer_dirty(bh, 1);
     brelse(bh);
-    iput(dir);
     oldinode->i_nlink++;
     oldinode->i_ctime = CURRENT_TIME;
     oldinode->i_dirt = 1;
+    iput(dir);
     iput(oldinode);
     return 0;
 }
diff -Nur elks.orig/fs/pipe.c elks/fs/pipe.c
--- elks.orig/fs/pipe.c	2015-03-08 17:08:12.000000000 -0600
+++ elks/fs/pipe.c	2015-03-11 17:04:40.000000000 -0600
@@ -243,6 +243,17 @@
     if (filp->f_mode & FMODE_WRITE)
 	(inode->u.pipe_i.writers)++;
 
+    if(!PIPE_BASE(*inode)) {
+	if(!(PIPE_BASE(*inode) = get_pipe_mem()))
+	    return -ENOMEM;
+#if 0
+	/* next fields already set to zero by get_empty_inode() */
+	PIPE_START(*inode) = PIPE_LEN(*inode) = 0;
+	PIPE_RD_OPENERS(*inode) = PIPE_WR_OPENERS(*inode) = 0;
+	PIPE_READERS(*inode) = PIPE_WRITERS(*inode) = 0;
+	PIPE_LOCK(*inode) = 0;
+#endif
+    }
     return 0;
 }
 
diff -Nur elks.orig/include/linuxmt/fs.h elks/include/linuxmt/fs.h
--- elks.orig/include/linuxmt/fs.h	2015-03-08 17:08:12.000000000 -0600
+++ elks/include/linuxmt/fs.h	2015-03-11 17:04:40.000000000 -0600
@@ -234,11 +234,6 @@
     unsigned char		i_lock;
     unsigned char		i_dirt;
 
-#ifdef CONFIG_PIPE
-    unsigned char		i_pipe;
-#endif
-
-    unsigned char		i_sock;
     short			i_sem;
 
     union {
diff -Nur elks.orig/init/main.c elks/init/main.c
--- elks.orig/init/main.c	2015-03-08 17:08:12.000000000 -0600
+++ elks/init/main.c	2015-03-11 17:06:59.000000000 -0600
@@ -103,14 +103,14 @@
      * So, I've modified the ELKS kernel to follow this tradition.
      */
 
-    run_init_process("/etc/init", args);
     run_init_process("/sbin/init", args);
+    run_init_process("/etc/init", args);
     run_init_process("/bin/init", args);
 
 #ifdef CONFIG_CONSOLE_SERIAL
-	num = sys_open("/dev/ttyS0", 2, 0);
+    num = sys_open("/dev/ttyS0", 2, 0);
 #else
-	num = sys_open("/dev/tty0", 2, 0);
+    num = sys_open("/dev/tty1", 2, 0);
 #endif
 	if (num < 0)
 	    printk("Unable to open /dev/tty (error %u)\n", -num);
diff -Nur elks.orig/net/socket.c elks/net/socket.c
--- elks.orig/net/socket.c	2015-03-08 17:08:12.000000000 -0600
+++ elks/net/socket.c	2015-03-11 17:04:40.000000000 -0600
@@ -105,7 +105,6 @@
     inode->i_mode = S_IFSOCK;
     inode->i_op = &sock_inode_operations;
     inode->i_gid = (__u8) current->egid;
-    inode->i_sock = 1;
 
     sock = &inode->u.socket_i;
     sock->state = SS_UNCONNECTED;
@@ -145,7 +144,7 @@
 	return NULL;
 
     inode = file->f_inode;
-    if (!inode || !inode->i_sock)
+    if (!inode || ((inode->i_mode & S_IFMT) != S_IFSOCK))
 	return NULL;
 
     if (pfile)

[Index of Archives]     [Kernel]     [Linux ia64]     [DCCP]     [Linux for ARM]     [Yosemite News]     [Linux SCSI]     [Linux Hams]

  Powered by Linux