Home | History | Annotate | Line # | Download | only in v7fs
v7fs_dirent.c revision 1.1
      1 /*	$NetBSD: v7fs_dirent.c,v 1.1 2011/06/27 11:52:24 uch Exp $	*/
      2 
      3 /*-
      4  * Copyright (c) 2011 The NetBSD Foundation, Inc.
      5  * All rights reserved.
      6  *
      7  * This code is derived from software contributed to The NetBSD Foundation
      8  * by UCHIYAMA Yasushi.
      9  *
     10  * Redistribution and use in source and binary forms, with or without
     11  * modification, are permitted provided that the following conditions
     12  * are met:
     13  * 1. Redistributions of source code must retain the above copyright
     14  *    notice, this list of conditions and the following disclaimer.
     15  * 2. Redistributions in binary form must reproduce the above copyright
     16  *    notice, this list of conditions and the following disclaimer in the
     17  *    documentation and/or other materials provided with the distribution.
     18  *
     19  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     20  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     21  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     22  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     23  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     24  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     25  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     26  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     27  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     28  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     29  * POSSIBILITY OF SUCH DAMAGE.
     30  */
     31 
     32 #include <sys/cdefs.h>
     33 __KERNEL_RCSID(0, "$NetBSD: v7fs_dirent.c,v 1.1 2011/06/27 11:52:24 uch Exp $");
     34 #if defined _KERNEL_OPT
     35 #include "opt_v7fs.h"
     36 #endif
     37 
     38 #ifdef _KERNEL
     39 #include <sys/systm.h>
     40 #include <sys/param.h>
     41 #else
     42 #include <stdio.h>
     43 #include <string.h>
     44 #endif
     45 
     46 #include "v7fs.h"
     47 #include "v7fs_impl.h"
     48 #include "v7fs_endian.h"
     49 #include "v7fs_inode.h"
     50 #include "v7fs_dirent.h"
     51 
     52 #ifdef V7FS_DIRENT_DEBUG
     53 #define	DPRINTF(fmt, args...)	printf("%s: " fmt, __func__, ##args)
     54 #else
     55 #define	DPRINTF(fmt, args...)	((void)0)
     56 #endif
     57 
     58 bool
     59 v7fs_dirent_endian_convert(struct v7fs_self *fs, struct v7fs_dirent *dir, int n)
     60 {
     61 	struct v7fs_superblock *sb = &fs->superblock;
     62 	int i;
     63 	v7fs_ino_t ino;
     64 	bool ok = true;
     65 
     66 	for (i = 0; i < n; i++, dir++) {
     67 		ino = V7FS_VAL16(fs, dir->inode_number);
     68 		if (v7fs_inode_number_sanity(sb, ino)) {
     69 			DPRINTF("Invalid inode# %d %s\n", ino, dir->name);
     70 			ok = false;
     71 		}
     72 		dir->inode_number = ino;
     73 	}
     74 
     75 	return ok;
     76 }
     77 
     78 void
     79 v7fs_dirent_filename(char *dst/* size must be V7FS_NAME_MAX + 1 */,
     80     const char *src)
     81 {
     82 
     83 	strncpy(dst, src, V7FS_NAME_MAX);
     84 	dst[V7FS_NAME_MAX] = '\0';
     85 }
     86