[Ocfs-tools-commits] jlbec commits r139 - in trunk/ocfs2/libocfs2: . include

svn-commits at oss.oracle.com svn-commits at oss.oracle.com
Sun Jul 4 15:22:05 CDT 2004


Author: jlbec
Date: 2004-07-04 14:22:02 -0500 (Sun, 04 Jul 2004)
New Revision: 139

Added:
   trunk/ocfs2/libocfs2/link.c
   trunk/ocfs2/libocfs2/unlink.c
Modified:
   trunk/ocfs2/libocfs2/Makefile
   trunk/ocfs2/libocfs2/include/filesys.h
   trunk/ocfs2/libocfs2/ocfs2_err.et.in
Log:

o Added link and unlink.



Modified: trunk/ocfs2/libocfs2/Makefile
===================================================================
--- trunk/ocfs2/libocfs2/Makefile	2004-07-03 20:30:33 UTC (rev 138)
+++ trunk/ocfs2/libocfs2/Makefile	2004-07-04 19:22:02 UTC (rev 139)
@@ -14,6 +14,7 @@
 LIBRARIES = libocfs2.a
 
 CFLAGS = $(OPTS) -fno-strict-aliasing $(WARNINGS)
+CPPFLAGS += -DOCFS2_FLAT_INCLUDES
 
 OPTIMIZE = -O2
 
@@ -75,7 +76,9 @@
 	dirblock.c	\
 	dir_iterate.c	\
 	lookup.c	\
-	sysfile.c
+	sysfile.c	\
+	link.c		\
+	unlink.c
 
 HFILES =				\
 	include/jfs_user.h		\

Modified: trunk/ocfs2/libocfs2/include/filesys.h
===================================================================
--- trunk/ocfs2/libocfs2/include/filesys.h	2004-07-03 20:30:33 UTC (rev 138)
+++ trunk/ocfs2/libocfs2/include/filesys.h	2004-07-04 19:22:02 UTC (rev 139)
@@ -27,6 +27,8 @@
 #ifndef _FILESYS_H
 #define _FILESYS_H
 
+#include <stdint.h>
+
 #define OCFS2_LIB_FEATURE_INCOMPAT_SUPP		OCFS2_FEATURE_INCOMPAT_SUPP
 #define OCFS2_LIB_FEATURE_RO_COMPAT_SUPP	OCFS2_FEATURE_RO_COMPAT_SUPP
 
@@ -198,5 +200,11 @@
 
 errcode_t ocfs2_lookup_system_inode(ocfs2_filesys *fs, int type,
 				    int node_num, uint64_t *blkno);
+
+errcode_t ocfs2_link(ocfs2_filesys *fs, uint64_t dir, const char *name,
+		     uint64_t ino, int flags);
+
+errcode_t ocfs2_unlink(ocfs2_filesys *fs, uint64_t dir,
+		       const char *name, uint64_t ino, int flags);
 #endif  /* _FILESYS_H */
 

Added: trunk/ocfs2/libocfs2/link.c
===================================================================
--- trunk/ocfs2/libocfs2/link.c	2004-07-03 20:30:33 UTC (rev 138)
+++ trunk/ocfs2/libocfs2/link.c	2004-07-04 19:22:02 UTC (rev 139)
@@ -0,0 +1,178 @@
+/* -*- mode: c; c-basic-offset: 8; -*-
+ * vim: noexpandtab sw=8 ts=8 sts=0:
+ *
+ * link.c
+ *
+ * Create links in OCFS2 directories.  For the OCFS2 userspace library.
+ *
+ * Copyright (C) 2004 Oracle.  All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public
+ * License, version 2,  as published by the Free Software Foundation.
+ * 
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ * 
+ * You should have received a copy of the GNU General Public
+ * License along with this program; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 021110-1307, USA.
+ *
+ * Authors: Joel Becker
+ *
+ *  This code is a port of e2fsprogs/lib/ext2fs/link.c
+ *  Copyright (C) 1993, 1994 Theodore Ts'o.
+ */
+
+#define _XOPEN_SOURCE 600 /* Triggers magic in features.h */
+#define _LARGEFILE64_SOURCE
+
+#include <stdio.h>
+#include <unistd.h>
+#include <string.h>
+#include <stdlib.h>
+#include <stdint.h>
+#include <sys/stat.h>
+#include <time.h>
+
+#include <linux/types.h>
+
+#include <et/com_err.h>
+#include "ocfs2_err.h"
+
+#include "unix_io.h"
+#include "memory.h"
+#include "byteorder.h"
+
+#include "ocfs2_fs.h"
+
+#include "filesys.h"
+
+
+struct link_struct  {
+	const char	*name;
+	int		namelen;
+	uint64_t	inode;
+	int		flags;
+	int		done;
+	ocfs2_dinode *sb;
+};	
+
+static int link_proc(struct ocfs2_dir_entry *dirent,
+		     int	offset,
+		     int	blocksize,
+		     char	*buf,
+		     void	*priv_data)
+{
+	struct link_struct *ls = (struct link_struct *) priv_data;
+	struct ocfs2_dir_entry *next;
+	int rec_len, min_rec_len;
+	int ret = 0;
+
+	rec_len = OCFS2_DIR_REC_LEN(ls->namelen);
+
+	/*
+	 * See if the following directory entry (if any) is unused;
+	 * if so, absorb it into this one.
+	 */
+	next = (struct ocfs2_dir_entry *) (buf + offset + dirent->rec_len);
+	if ((offset + dirent->rec_len < blocksize - 8) &&
+	    (next->inode == 0) &&
+	    (offset + dirent->rec_len + next->rec_len <= blocksize)) {
+		dirent->rec_len += next->rec_len;
+		ret = OCFS2_DIRENT_CHANGED;
+	}
+
+	/*
+	 * If the directory entry is used, see if we can split the
+	 * directory entry to make room for the new name.  If so,
+	 *e truncate it and return.
+	 */
+	if (dirent->inode) {
+		min_rec_len = OCFS2_DIR_REC_LEN(dirent->name_len & 0xFF);
+		if (dirent->rec_len < (min_rec_len + rec_len))
+			return ret;
+		rec_len = dirent->rec_len - min_rec_len;
+		dirent->rec_len = min_rec_len;
+		next = (struct ocfs2_dir_entry *) (buf + offset +
+                                                   dirent->rec_len);
+		next->inode = 0;
+		next->name_len = 0;
+		next->rec_len = rec_len;
+		return OCFS2_DIRENT_CHANGED;
+	}
+
+	/*
+	 * If we get this far, then the directory entry is not used.
+	 * See if we can fit the request entry in.  If so, do it.
+	 */
+	if (dirent->rec_len < rec_len)
+		return ret;
+	dirent->inode = ls->inode;
+	dirent->name_len = ls->namelen;
+	strncpy(dirent->name, ls->name, ls->namelen);
+        ocfs_set_de_type(dirent, ls->flags);
+
+	ls->done++;
+	return OCFS2_DIRENT_ABORT|OCFS2_DIRENT_CHANGED;
+}
+
+/*
+ * Note: the low 3 bits of the flags field are used as the directory
+ * entry filetype.
+ */
+#ifdef __TURBOC__
+ #pragma argsused
+#endif
+errcode_t ocfs2_link(ocfs2_filesys *fs, uint64_t dir, const char *name, 
+		     uint64_t ino, int flags)
+{
+	errcode_t		retval;
+	struct link_struct	ls;
+#if 0 /* Maybe later */
+        char *buf;
+	struct ocfs2_dinode	inode;
+#endif
+
+	if (!(fs->fs_flags & OCFS2_FLAG_RW))
+		return OCFS2_ET_RO_FILESYS;
+
+	ls.name = name;
+	ls.namelen = name ? strlen(name) : 0;
+	ls.inode = ino;
+	ls.flags = flags;
+	ls.done = 0;
+	ls.sb = fs->fs_super;
+
+	retval = ocfs2_dir_iterate(fs, dir,
+                                   OCFS2_DIRENT_FLAG_INCLUDE_EMPTY,
+                                   0, link_proc, &ls);
+	if (retval)
+		return retval;
+
+	if (!ls.done)
+		return OCFS2_ET_DIR_NO_SPACE;
+
+#if 0 /* Maybe later */
+        retval = ocfs2_malloc_block(fs->fs_io, &buf);
+        if (retval)
+            return retval;
+
+	if ((retval = ocfs2_read_inode(fs, dir, buf)) != 0)
+		return retval;
+
+        di = (ocfs2_dinode *)buf;
+
+	if (inode->i_flags & OCFS2_INDEX_FL) {
+		inode->i_flags &= ~OCFS2_INDEX_FL;
+		if ((retval = ocfs2_write_inode(fs, dir, buf)) != 0)
+			return retval;
+	}
+#endif
+
+	return 0;
+}
+

Modified: trunk/ocfs2/libocfs2/ocfs2_err.et.in
===================================================================
--- trunk/ocfs2/libocfs2/ocfs2_err.et.in	2004-07-03 20:30:33 UTC (rev 138)
+++ trunk/ocfs2/libocfs2/ocfs2_err.et.in	2004-07-04 19:22:02 UTC (rev 139)
@@ -77,4 +77,7 @@
 ec	OCFS2_ET_FILE_NOT_FOUND,
 	"File not found by ocfs2_lookup"
 
+ec	OCFS2_ET_DIR_NO_SPACE,
+	"No free space in the directory"
+
 	end

Added: trunk/ocfs2/libocfs2/unlink.c
===================================================================
--- trunk/ocfs2/libocfs2/unlink.c	2004-07-03 20:30:33 UTC (rev 138)
+++ trunk/ocfs2/libocfs2/unlink.c	2004-07-04 19:22:02 UTC (rev 139)
@@ -0,0 +1,113 @@
+/* -*- mode: c; c-basic-offset: 8; -*-
+ * vim: noexpandtab sw=8 ts=8 sts=0:
+ *
+ * unlink.c
+ *
+ * Remove an entry from an OCFS2 directory.  For the OCFS2 userspace
+ * library.
+ *
+ * Copyright (C) 2004 Oracle.  All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public
+ * License, version 2,  as published by the Free Software Foundation.
+ * 
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ * 
+ * You should have received a copy of the GNU General Public
+ * License along with this program; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 021110-1307, USA.
+ *
+ * Authors: Joel Becker
+ *
+ *  This code is a port of e2fsprogs/lib/ext2fs/unlink.c
+ *  Copyright (C) 1993, 1994, 1997 Theodore Ts'o.
+ */
+
+#define _XOPEN_SOURCE 600 /* Triggers magic in features.h */
+#define _LARGEFILE64_SOURCE
+
+#include <stdio.h>
+#include <unistd.h>
+#include <string.h>
+#include <stdlib.h>
+#include <stdint.h>
+#include <sys/stat.h>
+#include <time.h>
+
+#include <linux/types.h>
+
+#include <et/com_err.h>
+#include "ocfs2_err.h"
+
+#include "unix_io.h"
+#include "memory.h"
+#include "byteorder.h"
+
+#include "ocfs2_fs.h"
+
+#include "filesys.h"
+
+
+struct link_struct  {
+	const char	*name;
+	int		namelen;
+	uint64_t	inode;
+	int		flags;
+	int		done;
+};	
+
+#ifdef __TURBOC__
+ #pragma argsused
+#endif
+static int unlink_proc(struct ocfs2_dir_entry *dirent,
+		     int	offset,
+		     int	blocksize,
+		     char	*buf,
+		     void	*priv_data)
+{
+	struct link_struct *ls = (struct link_struct *) priv_data;
+
+	if (ls->name && ((dirent->name_len & 0xFF) != ls->namelen))
+		return 0;
+	if (ls->name && strncmp(ls->name, dirent->name,
+				dirent->name_len & 0xFF))
+		return 0;
+	if (ls->inode && (dirent->inode != ls->inode))
+		return 0;
+
+	dirent->inode = 0;
+	ls->done++;
+	return OCFS2_DIRENT_ABORT|OCFS2_DIRENT_CHANGED;
+}
+
+#ifdef __TURBOC__
+ #pragma argsused
+#endif
+errcode_t ocfs2_unlink(ocfs2_filesys *fs, uint64_t dir,
+			const char *name, uint64_t ino,
+			int flags)
+{
+	errcode_t	retval;
+	struct link_struct ls;
+
+	if (!(fs->fs_flags & OCFS2_FLAG_RW))
+		return OCFS2_ET_RO_FILESYS;
+
+	ls.name = name;
+	ls.namelen = name ? strlen(name) : 0;
+	ls.inode = ino;
+	ls.flags = 0;
+	ls.done = 0;
+
+	retval = ocfs2_dir_iterate(fs, dir, 0, 0, unlink_proc, &ls);
+	if (retval)
+		return retval;
+
+	return (ls.done) ? 0 : OCFS2_ET_DIR_NO_SPACE;
+}
+



More information about the Ocfs-tools-commits mailing list