Module Name: src
Committed By: hannken
Date: Fri Feb 11 10:55:15 UTC 2022
Modified Files:
src/sbin/fsck_v7fs: main.c pathname.c
src/sys/fs/v7fs: v7fs_dirent.c v7fs_dirent.h v7fs_file.c v7fs_file.h
v7fs_file_util.c v7fs_vnops.c
src/usr.sbin/makefs/v7fs: v7fs_populate.c
Log Message:
A component name is a counted string (cn_nameptr, cn_namelen),
not a zero terminated string cn_nameptr.
Change the following operations to work with counted strings:
v7fs_file_lookup_by_name()
v7fs_file_allocate()
v7fs_file_deallocate()
v7fs_directory_add_entry()
v7fs_directory_remove_entry()
v7fs_file_rename()
v7fs_file_link()
v7fs_dirent_filename()
Adapt all vnode operations with component names as argument.
To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/sbin/fsck_v7fs/main.c \
src/sbin/fsck_v7fs/pathname.c
cvs rdiff -u -r1.2 -r1.3 src/sys/fs/v7fs/v7fs_dirent.c \
src/sys/fs/v7fs/v7fs_file.h
cvs rdiff -u -r1.1 -r1.2 src/sys/fs/v7fs/v7fs_dirent.h
cvs rdiff -u -r1.6 -r1.7 src/sys/fs/v7fs/v7fs_file.c
cvs rdiff -u -r1.4 -r1.5 src/sys/fs/v7fs/v7fs_file_util.c
cvs rdiff -u -r1.33 -r1.34 src/sys/fs/v7fs/v7fs_vnops.c
cvs rdiff -u -r1.3 -r1.4 src/usr.sbin/makefs/v7fs/v7fs_populate.c
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/sbin/fsck_v7fs/main.c
diff -u src/sbin/fsck_v7fs/main.c:1.1 src/sbin/fsck_v7fs/main.c:1.2
--- src/sbin/fsck_v7fs/main.c:1.1 Mon Jun 27 11:52:58 2011
+++ src/sbin/fsck_v7fs/main.c Fri Feb 11 10:55:15 2022
@@ -1,4 +1,4 @@
-/* $NetBSD: main.c,v 1.1 2011/06/27 11:52:58 uch Exp $ */
+/* $NetBSD: main.c,v 1.2 2022/02/11 10:55:15 hannken Exp $ */
/*-
* Copyright (c) 2011 The NetBSD Foundation, Inc.
@@ -31,7 +31,7 @@
#include <sys/cdefs.h>
#ifndef lint
-__RCSID("$NetBSD: main.c,v 1.1 2011/06/27 11:52:58 uch Exp $");
+__RCSID("$NetBSD: main.c,v 1.2 2022/02/11 10:55:15 hannken Exp $");
#endif /* not lint */
#include <stdio.h>
@@ -241,8 +241,8 @@ make_lost_and_found(struct v7fs_self *fs
attr.ctime = attr.mtime = attr.atime = (v7fs_time_t)time(NULL);
/* If lost+found already exists, returns EEXIST */
- if (!(error = v7fs_file_allocate
- (fs, &root_inode, "lost+found", &attr, &ino)))
+ if (!(error = v7fs_file_allocate(fs, &root_inode,
+ "lost+found", strlen("lost+found"), &attr, &ino)))
v7fs_superblock_writeback(fs);
if (error == EEXIST)
Index: src/sbin/fsck_v7fs/pathname.c
diff -u src/sbin/fsck_v7fs/pathname.c:1.1 src/sbin/fsck_v7fs/pathname.c:1.2
--- src/sbin/fsck_v7fs/pathname.c:1.1 Mon Jun 27 11:52:58 2011
+++ src/sbin/fsck_v7fs/pathname.c Fri Feb 11 10:55:15 2022
@@ -1,4 +1,4 @@
-/* $NetBSD: pathname.c,v 1.1 2011/06/27 11:52:58 uch Exp $ */
+/* $NetBSD: pathname.c,v 1.2 2022/02/11 10:55:15 hannken Exp $ */
/*-
* Copyright (c) 2011 The NetBSD Foundation, Inc.
@@ -31,7 +31,7 @@
#include <sys/cdefs.h>
#ifndef lint
-__RCSID("$NetBSD: pathname.c,v 1.1 2011/06/27 11:52:58 uch Exp $");
+__RCSID("$NetBSD: pathname.c,v 1.2 2022/02/11 10:55:15 hannken Exp $");
#endif /* not lint */
#include <sys/types.h>
@@ -64,7 +64,7 @@ connect_lost_and_found(struct v7fs_self
return FSCK_EXIT_CHECK_FAILED;
snprintf(name, sizeof(name), "%d", ino);
- v7fs_directory_add_entry(fs, &lost_and_found, ino, name);
+ v7fs_directory_add_entry(fs, &lost_and_found, ino, name, strlen(name));
t = (v7fs_time_t)time(NULL);
lost_and_found.mtime = lost_and_found.atime = t;
v7fs_inode_writeback(fs, &lost_and_found);
@@ -107,7 +107,7 @@ lookup_child_subr(struct v7fs_self *fs,
pwarn("entry #%d not found.", dir->inode_number);
if (reply("REMOVE?"))
v7fs_directory_remove_entry(fs, arg->parent,
- dir->name);
+ dir->name, strlen(dir->name));
} else {
/* Count child dir. */
if (v7fs_inode_isdir(&inode))
Index: src/sys/fs/v7fs/v7fs_dirent.c
diff -u src/sys/fs/v7fs/v7fs_dirent.c:1.2 src/sys/fs/v7fs/v7fs_dirent.c:1.3
--- src/sys/fs/v7fs/v7fs_dirent.c:1.2 Mon Jul 18 21:51:49 2011
+++ src/sys/fs/v7fs/v7fs_dirent.c Fri Feb 11 10:55:15 2022
@@ -1,4 +1,4 @@
-/* $NetBSD: v7fs_dirent.c,v 1.2 2011/07/18 21:51:49 apb Exp $ */
+/* $NetBSD: v7fs_dirent.c,v 1.3 2022/02/11 10:55:15 hannken Exp $ */
/*-
* Copyright (c) 2011 The NetBSD Foundation, Inc.
@@ -34,7 +34,7 @@
#endif
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: v7fs_dirent.c,v 1.2 2011/07/18 21:51:49 apb Exp $");
+__KERNEL_RCSID(0, "$NetBSD: v7fs_dirent.c,v 1.3 2022/02/11 10:55:15 hannken Exp $");
#if defined _KERNEL_OPT
#include "opt_v7fs.h"
#endif
@@ -81,9 +81,12 @@ v7fs_dirent_endian_convert(struct v7fs_s
void
v7fs_dirent_filename(char *dst/* size must be V7FS_NAME_MAX + 1 */,
- const char *src)
+ const char *src, size_t srclen)
{
- strncpy(dst, src, V7FS_NAME_MAX);
- dst[V7FS_NAME_MAX] = '\0';
+ if (srclen > V7FS_NAME_MAX)
+ srclen = V7FS_NAME_MAX;
+
+ memset(dst, 0, V7FS_NAME_MAX + 1);
+ strncpy(dst, src, srclen);
}
Index: src/sys/fs/v7fs/v7fs_file.h
diff -u src/sys/fs/v7fs/v7fs_file.h:1.2 src/sys/fs/v7fs/v7fs_file.h:1.3
--- src/sys/fs/v7fs/v7fs_file.h:1.2 Sat Jul 16 12:35:40 2011
+++ src/sys/fs/v7fs/v7fs_file.h Fri Feb 11 10:55:15 2022
@@ -1,4 +1,4 @@
-/* $NetBSD: v7fs_file.h,v 1.2 2011/07/16 12:35:40 uch Exp $ */
+/* $NetBSD: v7fs_file.h,v 1.3 2022/02/11 10:55:15 hannken Exp $ */
/*-
* Copyright (c) 2011 The NetBSD Foundation, Inc.
@@ -42,22 +42,23 @@ struct v7fs_lookup_arg {
__BEGIN_DECLS
/* core */
int v7fs_file_lookup_by_name(struct v7fs_self *, struct v7fs_inode *,
- const char*, v7fs_ino_t *);
+ const char*, size_t, v7fs_ino_t *);
int v7fs_file_allocate(struct v7fs_self *, struct v7fs_inode *, const char *,
- struct v7fs_fileattr *, v7fs_ino_t *);
-int v7fs_file_deallocate(struct v7fs_self *, struct v7fs_inode *, const char *);
+ size_t, struct v7fs_fileattr *, v7fs_ino_t *);
+int v7fs_file_deallocate(struct v7fs_self *, struct v7fs_inode *, const char *,
+ size_t);
int v7fs_directory_add_entry(struct v7fs_self *,struct v7fs_inode *, v7fs_ino_t,
- const char *);
+ const char *, size_t);
int v7fs_directory_remove_entry(struct v7fs_self *,struct v7fs_inode *,
- const char *);
+ const char *, size_t);
/* util */
int v7fs_file_rename(struct v7fs_self *, struct v7fs_inode *, const char *,
- struct v7fs_inode *, const char *);
+ size_t, struct v7fs_inode *, const char *, size_t);
int v7fs_directory_replace_entry(struct v7fs_self *, struct v7fs_inode *,
const char *, v7fs_ino_t);
int v7fs_file_link(struct v7fs_self *, struct v7fs_inode *, struct v7fs_inode *,
- const char *);
+ const char *, size_t);
bool v7fs_file_lookup_by_number(struct v7fs_self *, struct v7fs_inode *,
v7fs_ino_t, char *);
int v7fs_file_symlink(struct v7fs_self *, struct v7fs_inode *, const char *);
Index: src/sys/fs/v7fs/v7fs_dirent.h
diff -u src/sys/fs/v7fs/v7fs_dirent.h:1.1 src/sys/fs/v7fs/v7fs_dirent.h:1.2
--- src/sys/fs/v7fs/v7fs_dirent.h:1.1 Mon Jun 27 11:52:24 2011
+++ src/sys/fs/v7fs/v7fs_dirent.h Fri Feb 11 10:55:15 2022
@@ -1,4 +1,4 @@
-/* $NetBSD: v7fs_dirent.h,v 1.1 2011/06/27 11:52:24 uch Exp $ */
+/* $NetBSD: v7fs_dirent.h,v 1.2 2022/02/11 10:55:15 hannken Exp $ */
/*-
* Copyright (c) 2011 The NetBSD Foundation, Inc.
@@ -33,6 +33,6 @@
#define _V7FS_DIRENT_H_
__BEGIN_DECLS
bool v7fs_dirent_endian_convert(struct v7fs_self *, struct v7fs_dirent *, int);
-void v7fs_dirent_filename(char *, const char *);
+void v7fs_dirent_filename(char *, const char *, size_t);
__END_DECLS
#endif /*!_V7FS_DIRENT_H_ */
Index: src/sys/fs/v7fs/v7fs_file.c
diff -u src/sys/fs/v7fs/v7fs_file.c:1.6 src/sys/fs/v7fs/v7fs_file.c:1.7
--- src/sys/fs/v7fs/v7fs_file.c:1.6 Mon Dec 29 15:28:58 2014
+++ src/sys/fs/v7fs/v7fs_file.c Fri Feb 11 10:55:15 2022
@@ -1,4 +1,4 @@
-/* $NetBSD: v7fs_file.c,v 1.6 2014/12/29 15:28:58 hannken Exp $ */
+/* $NetBSD: v7fs_file.c,v 1.7 2022/02/11 10:55:15 hannken Exp $ */
/*-
* Copyright (c) 2011 The NetBSD Foundation, Inc.
@@ -34,7 +34,7 @@
#endif
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: v7fs_file.c,v 1.6 2014/12/29 15:28:58 hannken Exp $");
+__KERNEL_RCSID(0, "$NetBSD: v7fs_file.c,v 1.7 2022/02/11 10:55:15 hannken Exp $");
#if defined _KERNEL_OPT
#include "opt_v7fs.h"
#endif
@@ -67,22 +67,14 @@ static int remove_subr(struct v7fs_self
int
v7fs_file_lookup_by_name(struct v7fs_self *fs, struct v7fs_inode *parent_dir,
- const char *name, v7fs_ino_t *ino)
+ const char *name, size_t namelen, v7fs_ino_t *ino)
{
char filename[V7FS_NAME_MAX + 1];
- char *q;
int error;
- size_t len;
- if ((q = strchr(name, '/'))) {
- /* Zap following path. */
- len = MIN(V7FS_NAME_MAX, q - name);
- memcpy(filename, name, len);
- filename[len] = '\0'; /* '/' -> '\0' */
- } else {
- v7fs_dirent_filename(filename, name);
- }
- DPRINTF("%s(%s) dir=%d\n", filename, name, parent_dir->inode_number);
+ v7fs_dirent_filename(filename, name, namelen);
+ DPRINTF("%s(%.*s) dir=%d\n", filename, (int)namelen, name,
+ parent_dir->inode_number);
struct v7fs_lookup_arg lookup_arg = { .name = filename,
.inode_number = 0 };
@@ -135,20 +127,17 @@ lookup_subr(struct v7fs_self *fs, void *
int
v7fs_file_allocate(struct v7fs_self *fs, struct v7fs_inode *parent_dir,
- const char *srcname, struct v7fs_fileattr *attr, v7fs_ino_t *ino)
+ const char *srcname, size_t srclen, struct v7fs_fileattr *attr,
+ v7fs_ino_t *ino)
{
struct v7fs_inode inode;
- char filename[V7FS_NAME_MAX + 1];
struct v7fs_dirent *dir;
int error;
- /* Truncate filename. */
- v7fs_dirent_filename(filename, srcname);
- DPRINTF("%s(%s)\n", filename, srcname);
-
/* Check filename. */
- if (v7fs_file_lookup_by_name(fs, parent_dir, filename, ino) == 0) {
- DPRINTF("%s exists\n", filename);
+ if (v7fs_file_lookup_by_name(fs, parent_dir, srcname, srclen,
+ ino) == 0) {
+ DPRINTF("%.*s exists\n", (int)srclen, srcname);
return EEXIST;
}
@@ -219,7 +208,8 @@ v7fs_file_allocate(struct v7fs_self *fs,
v7fs_inode_writeback(fs, &inode);
/* Link this inode to parent directory. */
- if ((error = v7fs_directory_add_entry(fs, parent_dir, *ino, filename)))
+ if ((error = v7fs_directory_add_entry(fs, parent_dir, *ino, srcname,
+ srclen)))
{
DPRINTF("can't add dirent.\n");
return error;
@@ -230,24 +220,25 @@ v7fs_file_allocate(struct v7fs_self *fs,
int
v7fs_file_deallocate(struct v7fs_self *fs, struct v7fs_inode *parent_dir,
- const char *name)
+ const char *name, size_t namelen)
{
v7fs_ino_t ino;
struct v7fs_inode inode;
int error;
- DPRINTF("%s\n", name);
- if ((error = v7fs_file_lookup_by_name(fs, parent_dir, name, &ino))) {
+ DPRINTF("%.*s\n", (int)namelen, name);
+ if ((error = v7fs_file_lookup_by_name(fs, parent_dir, name, namelen,
+ &ino))) {
DPRINTF("no such a file: %s\n", name);
return error;
}
- DPRINTF("%s->#%d\n", name, ino);
+ DPRINTF("%.*s->#%d\n", (int)namelen, name, ino);
if ((error = v7fs_inode_load(fs, &inode, ino)))
return error;
if (v7fs_inode_isdir(&inode)) {
char filename[V7FS_NAME_MAX + 1];
- v7fs_dirent_filename(filename, name);
+ v7fs_dirent_filename(filename, name, namelen);
/* Check parent */
if (strncmp(filename, "..", V7FS_NAME_MAX) == 0) {
DPRINTF("can not remove '..'\n");
@@ -266,11 +257,12 @@ v7fs_file_deallocate(struct v7fs_self *f
} else {
/* Decrement reference count. */
--inode.nlink; /* regular file. */
- DPRINTF("%s nlink=%d\n", name, inode.nlink);
+ DPRINTF("%.*s nlink=%d\n", (int)namelen, name, inode.nlink);
}
- if ((error = v7fs_directory_remove_entry(fs, parent_dir, name)))
+ if ((error = v7fs_directory_remove_entry(fs, parent_dir, name,
+ namelen)))
return error;
DPRINTF("remove dirent\n");
@@ -281,7 +273,7 @@ v7fs_file_deallocate(struct v7fs_self *f
int
v7fs_directory_add_entry(struct v7fs_self *fs, struct v7fs_inode *parent_dir,
- v7fs_ino_t ino, const char *srcname)
+ v7fs_ino_t ino, const char *srcname, size_t srclen)
{
struct v7fs_inode inode;
struct v7fs_dirent *dir;
@@ -291,8 +283,8 @@ v7fs_directory_add_entry(struct v7fs_sel
char filename[V7FS_NAME_MAX + 1];
/* Truncate filename. */
- v7fs_dirent_filename(filename, srcname);
- DPRINTF("%s(%s) %d\n", filename, srcname, ino);
+ v7fs_dirent_filename(filename, srcname, srclen);
+ DPRINTF("%s(%.*s) %d\n", filename, (int)srclen, srcname, ino);
/* Target inode */
if ((error = v7fs_inode_load(fs, &inode, ino)))
@@ -335,9 +327,10 @@ v7fs_directory_add_entry(struct v7fs_sel
int
v7fs_directory_remove_entry(struct v7fs_self *fs, struct v7fs_inode *parent_dir,
- const char *name)
+ const char *name, size_t namelen)
{
struct v7fs_inode inode;
+ char filename[V7FS_NAME_MAX + 1];
int error;
struct v7fs_dirent lastdirent;
v7fs_daddr_t lastblk;
@@ -345,6 +338,8 @@ v7fs_directory_remove_entry(struct v7fs_
v7fs_off_t pos;
void *buf;
+ v7fs_dirent_filename(filename, name, namelen);
+
/* Setup replaced entry. */
sz = parent_dir->filesize;
lastblk = v7fs_datablock_last(fs, parent_dir,
@@ -360,7 +355,7 @@ v7fs_directory_remove_entry(struct v7fs_
V7FS_VAL16(fs, lastdirent.inode_number), lastdirent.name, pos);
struct v7fs_lookup_arg lookup_arg =
- { .name = name, .replace = &lastdirent/*disk endian */ };
+ { .name = filename, .replace = &lastdirent/*disk endian */ };
/* Search entry that removed. replace it to last dirent. */
if ((error = v7fs_datablock_foreach(fs, parent_dir, remove_subr,
&lookup_arg)) != V7FS_ITERATOR_BREAK)
Index: src/sys/fs/v7fs/v7fs_file_util.c
diff -u src/sys/fs/v7fs/v7fs_file_util.c:1.4 src/sys/fs/v7fs/v7fs_file_util.c:1.5
--- src/sys/fs/v7fs/v7fs_file_util.c:1.4 Sat Jul 30 03:52:04 2011
+++ src/sys/fs/v7fs/v7fs_file_util.c Fri Feb 11 10:55:15 2022
@@ -1,4 +1,4 @@
-/* $NetBSD: v7fs_file_util.c,v 1.4 2011/07/30 03:52:04 uch Exp $ */
+/* $NetBSD: v7fs_file_util.c,v 1.5 2022/02/11 10:55:15 hannken Exp $ */
/*-
* Copyright (c) 2011 The NetBSD Foundation, Inc.
@@ -34,7 +34,7 @@
#endif
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: v7fs_file_util.c,v 1.4 2011/07/30 03:52:04 uch Exp $");
+__KERNEL_RCSID(0, "$NetBSD: v7fs_file_util.c,v 1.5 2022/02/11 10:55:15 hannken Exp $");
#ifdef _KERNEL
#include <sys/systm.h>
#include <sys/param.h>
@@ -67,13 +67,14 @@ static int lookup_parent_from_dir_subr(s
int
v7fs_file_link(struct v7fs_self *fs, struct v7fs_inode *parent_dir,
- struct v7fs_inode *p, const char *name)
+ struct v7fs_inode *p, const char *name, size_t namelen)
{
int error = 0;
- DPRINTF("%d %d %s\n", parent_dir->inode_number, p->inode_number, name);
+ DPRINTF("%d %d %.*s\n", parent_dir->inode_number, p->inode_number,
+ (int)namelen, name);
if ((error = v7fs_directory_add_entry(fs, parent_dir, p->inode_number,
- name))) {
+ name, namelen))) {
DPRINTF("can't add entry");
return error;
}
@@ -118,7 +119,8 @@ v7fs_file_symlink(struct v7fs_self *fs,
int
v7fs_file_rename(struct v7fs_self *fs, struct v7fs_inode *parent_from,
- const char *from, struct v7fs_inode *parent_to, const char *to)
+ const char *from, size_t fromlen, struct v7fs_inode *parent_to,
+ const char *to, size_t tolen)
{
v7fs_ino_t from_ino, to_ino;
struct v7fs_inode inode;
@@ -126,20 +128,21 @@ v7fs_file_rename(struct v7fs_self *fs, s
bool dir_move;
/* Check source file */
- if ((error = v7fs_file_lookup_by_name(fs, parent_from, from,
+ if ((error = v7fs_file_lookup_by_name(fs, parent_from, from, fromlen,
&from_ino))) {
- DPRINTF("%s don't exists\n", from);
+ DPRINTF("%.*s don't exists\n", (int)fromlen, from);
return error;
}
v7fs_inode_load(fs, &inode, from_ino);
dir_move = v7fs_inode_isdir(&inode);
/* Check target file */
- error = v7fs_file_lookup_by_name(fs, parent_to, to, &to_ino);
+ error = v7fs_file_lookup_by_name(fs, parent_to, to, tolen, &to_ino);
if (error == 0) { /* found */
- DPRINTF("%s already exists\n", to);
- if ((error = v7fs_file_deallocate(fs, parent_to, to))) {
- DPRINTF("%s can't remove %d\n", to, error);
+ DPRINTF("%.*s already exists\n", (int)tolen, to);
+ if ((error = v7fs_file_deallocate(fs, parent_to, to, tolen))) {
+ DPRINTF("%.*s can't remove %d\n", (int)tolen,
+ to, error);
return error;
}
} else if (error != ENOENT) {
@@ -149,17 +152,19 @@ v7fs_file_rename(struct v7fs_self *fs, s
/* Check directory hierarchy. t_vnops rename_dir(5) */
if (dir_move && (error = can_dirmove(fs, from_ino,
parent_to->inode_number))) {
- DPRINTF("dst '%s' is child dir of '%s'. error=%d\n", to, from,
- error);
+ DPRINTF("dst '%.*s' is child dir of '%.*s'. error=%d\n",
+ (int)tolen, to, (int)fromlen, from, error);
return error;
}
- if ((error = v7fs_directory_add_entry(fs, parent_to, from_ino, to))) {
+ if ((error = v7fs_directory_add_entry(fs, parent_to, from_ino, to,
+ tolen))) {
DPRINTF("can't add entry");
return error;
}
- if ((error = v7fs_directory_remove_entry(fs, parent_from, from))) {
+ if ((error = v7fs_directory_remove_entry(fs, parent_from, from,
+ fromlen))) {
DPRINTF("can't remove entry");
return error;
}
@@ -260,7 +265,8 @@ lookup_by_number_subr(struct v7fs_self *
for (i = 0; i < n; i++, dir++) {
if (dir->inode_number == p->inode_number) {
if (p->buf)
- v7fs_dirent_filename(p->buf, dir->name);
+ v7fs_dirent_filename(p->buf, dir->name,
+ strlen(dir->name));
ret = V7FS_ITERATOR_BREAK;
break;
}
@@ -330,7 +336,7 @@ lookup_parent_from_dir_subr(struct v7fs_
}
for (i = 0; i < n; i++, dir++) {
- v7fs_dirent_filename(name, dir->name);
+ v7fs_dirent_filename(name, dir->name, strlen(dir->name));
if (strncmp(dir->name, "..", V7FS_NAME_MAX) != 0)
continue;
Index: src/sys/fs/v7fs/v7fs_vnops.c
diff -u src/sys/fs/v7fs/v7fs_vnops.c:1.33 src/sys/fs/v7fs/v7fs_vnops.c:1.34
--- src/sys/fs/v7fs/v7fs_vnops.c:1.33 Tue Feb 1 17:12:24 2022
+++ src/sys/fs/v7fs/v7fs_vnops.c Fri Feb 11 10:55:15 2022
@@ -1,4 +1,4 @@
-/* $NetBSD: v7fs_vnops.c,v 1.33 2022/02/01 17:12:24 jakllsch Exp $ */
+/* $NetBSD: v7fs_vnops.c,v 1.34 2022/02/11 10:55:15 hannken Exp $ */
/*-
* Copyright (c) 2004, 2011 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: v7fs_vnops.c,v 1.33 2022/02/01 17:12:24 jakllsch Exp $");
+__KERNEL_RCSID(0, "$NetBSD: v7fs_vnops.c,v 1.34 2022/02/11 10:55:15 hannken Exp $");
#if defined _KERNEL_OPT
#include "opt_v7fs.h"
#endif
@@ -110,7 +110,7 @@ v7fs_lookup(void *v)
#ifdef V7FS_VNOPS_DEBUG
const char *opname[] = { "LOOKUP", "CREATE", "DELETE", "RENAME" };
#endif
- DPRINTF("'%s' op=%s flags=%d parent=%d %o %dbyte\n", name,
+ DPRINTF("'%.*s' op=%s flags=%d parent=%d %o %dbyte\n", namelen, name,
opname[nameiop], cnp->cn_flags, parent->inode_number, parent->mode,
parent->filesize);
@@ -145,15 +145,18 @@ v7fs_lookup(void *v)
}
/* ".." and regular file. */
- if ((error = v7fs_file_lookup_by_name(fs, parent, name, &ino))) {
+ if ((error = v7fs_file_lookup_by_name(fs, parent, name, namelen,
+ &ino))) {
/* Not found. Tell this entry be able to allocate. */
if (((nameiop == CREATE) || (nameiop == RENAME)) && islastcn) {
/* Check directory permission to allocate. */
if ((error = VOP_ACCESS(dvp, VWRITE, cnp->cn_cred))) {
- DPRINTF("access denied. (%s)\n", name);
+ DPRINTF("access denied. (%.*s)\n",
+ namelen, name);
return error;
}
- DPRINTF("EJUSTRETURN op=%d (%s)\n", nameiop, name);
+ DPRINTF("EJUSTRETURN op=%d (%.*s)\n", nameiop, namelen,
+ name);
return EJUSTRETURN;
}
DPRINTF("lastcn=%d\n", flags & ISLASTCN);
@@ -162,7 +165,7 @@ v7fs_lookup(void *v)
if ((nameiop == DELETE) && islastcn) {
if ((error = VOP_ACCESS(dvp, VWRITE, cnp->cn_cred))) {
- DPRINTF("access denied. (%s)\n", name);
+ DPRINTF("access denied. (%.*s)\n", namelen, name);
return error;
}
}
@@ -186,7 +189,7 @@ v7fs_lookup(void *v)
if (vpp != dvp)
VOP_UNLOCK(vpp);
*a->a_vpp = vpp;
- DPRINTF("done.(%s)\n", name);
+ DPRINTF("done.(%.*s)\n", namelen, name);
return 0;
}
@@ -210,8 +213,8 @@ v7fs_create(void *v)
v7fs_ino_t ino;
int error = 0;
- DPRINTF("%s parent#%d\n", a->a_cnp->cn_nameptr,
- parent_node->inode.inode_number);
+ DPRINTF("%.*s parent#%d\n", (int)a->a_cnp->cn_namelen,
+ a->a_cnp->cn_nameptr, parent_node->inode.inode_number);
KDASSERT((va->va_type == VREG) || (va->va_type == VSOCK));
memset(&attr, 0, sizeof(attr));
@@ -222,7 +225,7 @@ v7fs_create(void *v)
/* Allocate disk entry. and register its entry to parent directory. */
if ((error = v7fs_file_allocate(fs, &parent_node->inode,
- a->a_cnp->cn_nameptr, &attr, &ino))) {
+ a->a_cnp->cn_nameptr, a->a_cnp->cn_namelen, &attr, &ino))) {
DPRINTF("v7fs_file_allocate failed.\n");
return error;
}
@@ -272,8 +275,8 @@ v7fs_mknod(void *v)
v7fs_ino_t ino;
int error = 0;
- DPRINTF("%s %06o %lx %d\n", cnp->cn_nameptr, va->va_mode,
- (long)va->va_rdev, va->va_type);
+ DPRINTF("%.*s %06o %lx %d\n", (int)cnp->cn_namelen, cnp->cn_nameptr,
+ va->va_mode, (long)va->va_rdev, va->va_type);
memset(&attr, 0, sizeof(attr));
attr.uid = kauth_cred_geteuid(cr);
attr.gid = kauth_cred_getegid(cr);
@@ -281,7 +284,7 @@ v7fs_mknod(void *v)
attr.device = va->va_rdev;
if ((error = v7fs_file_allocate(fs, &parent_node->inode,
- cnp->cn_nameptr, &attr, &ino)))
+ cnp->cn_nameptr, cnp->cn_namelen, &attr, &ino)))
return error;
/* Sync dirent size change. */
uvm_vnp_setsize(dvp, v7fs_inode_filesize(&parent_node->inode));
@@ -698,7 +701,8 @@ v7fs_remove(void *v)
struct v7fs_self *fs = v7fsmount->core;
int error = 0;
- DPRINTF("delete %s\n", a->a_cnp->cn_nameptr);
+ DPRINTF("delete %.*s\n", (int)a->a_cnp->cn_namelen,
+ a->a_cnp->cn_nameptr);
if (vp->v_type == VDIR) {
error = EPERM;
@@ -706,7 +710,7 @@ v7fs_remove(void *v)
}
if ((error = v7fs_file_deallocate(fs, &parent_node->inode,
- a->a_cnp->cn_nameptr))) {
+ a->a_cnp->cn_nameptr, a->a_cnp->cn_namelen))) {
DPRINTF("v7fs_file_delete failed.\n");
goto out;
}
@@ -750,7 +754,7 @@ v7fs_link(void *v)
VOP_ABORTOP(dvp, cnp);
goto unlock;
}
- error = v7fs_file_link(fs, parent, p, cnp->cn_nameptr);
+ error = v7fs_file_link(fs, parent, p, cnp->cn_nameptr, cnp->cn_namelen);
/* Sync dirent size change. */
uvm_vnp_setsize(dvp, v7fs_inode_filesize(&parent_node->inode));
@@ -780,9 +784,12 @@ v7fs_rename(void *v)
struct v7fs_self *fs = v7node->v7fsmount->core;
const char *from_name = a->a_fcnp->cn_nameptr;
const char *to_name = a->a_tcnp->cn_nameptr;
+ size_t from_len = a->a_fcnp->cn_namelen;
+ size_t to_len = a->a_tcnp->cn_namelen;
int error;
- DPRINTF("%s->%s %p %p\n", from_name, to_name, fvp, tvp);
+ DPRINTF("%.*s->%.*s %p %p\n", (int)from_len, from_name, (int)to_len,
+ to_name, fvp, tvp);
if ((fvp->v_mount != tdvp->v_mount) ||
(tvp && (fvp->v_mount != tvp->v_mount))) {
@@ -791,8 +798,8 @@ v7fs_rename(void *v)
goto out;
}
// XXXsource file lock?
- error = v7fs_file_rename(fs, &parent_from->inode, from_name,
- &parent_to->inode, to_name);
+ error = v7fs_file_rename(fs, &parent_from->inode, from_name, from_len,
+ &parent_to->inode, to_name, to_len);
/* 'to file' inode may be changed. (hard-linked and it is cached.)
t_vnops rename_reg_nodir */
if (error == 0 && tvp) {
@@ -846,7 +853,7 @@ v7fs_mkdir(void *v)
attr.mode = va->va_mode | vtype_to_v7fs_mode(va->va_type);
if ((error = v7fs_file_allocate(fs, &parent_node->inode,
- cnp->cn_nameptr, &attr, &ino)))
+ cnp->cn_nameptr, cnp->cn_namelen, &attr, &ino)))
return error;
/* Sync dirent size change. */
uvm_vnp_setsize(dvp, v7fs_inode_filesize(&parent_node->inode));
@@ -882,12 +889,13 @@ v7fs_rmdir(void *v)
struct v7fs_self *fs = v7fsmount->core;
int error = 0;
- DPRINTF("delete %s\n", a->a_cnp->cn_nameptr);
+ DPRINTF("delete %.*s\n", (int)a->a_cnp->cn_namelen,
+ a->a_cnp->cn_nameptr);
KDASSERT(vp->v_type == VDIR);
if ((error = v7fs_file_deallocate(fs, &parent_node->inode,
- a->a_cnp->cn_nameptr))) {
+ a->a_cnp->cn_nameptr, a->a_cnp->cn_namelen))) {
DPRINTF("v7fs_directory_deallocate failed.\n");
goto out;
}
@@ -937,7 +945,7 @@ readdir_subr(struct v7fs_self *fs, void
if ((error = v7fs_inode_load(fs, &inode, dir->inode_number)))
break;
- v7fs_dirent_filename(filename, dir->name);
+ v7fs_dirent_filename(filename, dir->name, strlen(dir->name));
DPRINTF("inode=%d name=%s %s\n", dir->inode_number, filename,
v7fs_inode_isdir(&inode) ? "DIR" : "FILE");
@@ -1267,6 +1275,7 @@ v7fs_symlink(void *v)
const char *from = a->a_target;
const char *to = cnp->cn_nameptr;
size_t len = strlen(from) + 1;
+ size_t tolen = cnp->cn_namelen;
int error = 0;
if (len > V7FS_BSIZE) { /* limited to 512byte pathname */
@@ -1280,7 +1289,7 @@ v7fs_symlink(void *v)
attr.mode = va->va_mode | vtype_to_v7fs_mode(va->va_type);
if ((error = v7fs_file_allocate
- (fs, &parent_node->inode, to, &attr, &ino))) {
+ (fs, &parent_node->inode, to, tolen, &attr, &ino))) {
return error;
}
/* Sync dirent size change. */
Index: src/usr.sbin/makefs/v7fs/v7fs_populate.c
diff -u src/usr.sbin/makefs/v7fs/v7fs_populate.c:1.3 src/usr.sbin/makefs/v7fs/v7fs_populate.c:1.4
--- src/usr.sbin/makefs/v7fs/v7fs_populate.c:1.3 Wed Aug 10 11:31:49 2011
+++ src/usr.sbin/makefs/v7fs/v7fs_populate.c Fri Feb 11 10:55:15 2022
@@ -1,4 +1,4 @@
-/* $NetBSD: v7fs_populate.c,v 1.3 2011/08/10 11:31:49 uch Exp $ */
+/* $NetBSD: v7fs_populate.c,v 1.4 2022/02/11 10:55:15 hannken Exp $ */
/*-
* Copyright (c) 2011 The NetBSD Foundation, Inc.
@@ -35,7 +35,7 @@
#include <sys/cdefs.h>
#if defined(__RCSID) && !defined(__lint)
-__RCSID("$NetBSD: v7fs_populate.c,v 1.3 2011/08/10 11:31:49 uch Exp $");
+__RCSID("$NetBSD: v7fs_populate.c,v 1.4 2022/02/11 10:55:15 hannken Exp $");
#endif /* !__lint */
#include <stdio.h>
@@ -89,8 +89,8 @@ allocate(struct v7fs_self *fs, struct v7
attr_setup(node, &attr);
attr.device = dev;
- if ((error = v7fs_file_allocate(fs, parent_inode, node->name, &attr,
- &ino))) {
+ if ((error = v7fs_file_allocate(fs, parent_inode, node->name,
+ strlen(node->name), &attr, &ino))) {
errno = error;
warn("%s", node->name);
return error;
@@ -146,7 +146,7 @@ file_copy(struct v7fs_self *fs, struct v
goto err_exit;
}
if ((error = v7fs_file_link(fs, parent_inode, &inode,
- node->name))) {
+ node->name, strlen(node->name)))) {
errmsg = "hard link";
goto err_exit;
}