Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src A component name is a counted string (cn_nameptr, cn_namelen),
details: https://anonhg.NetBSD.org/src/rev/bc8256bc74ef
branches: trunk
changeset: 361117:bc8256bc74ef
user: hannken <hannken%NetBSD.org@localhost>
date: Fri Feb 11 10:55:15 2022 +0000
description:
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.
diffstat:
sbin/fsck_v7fs/main.c | 8 ++--
sbin/fsck_v7fs/pathname.c | 8 ++--
sys/fs/v7fs/v7fs_dirent.c | 13 ++++--
sys/fs/v7fs/v7fs_dirent.h | 4 +-
sys/fs/v7fs/v7fs_file.c | 65 ++++++++++++++++-------------------
sys/fs/v7fs/v7fs_file.h | 17 ++++----
sys/fs/v7fs/v7fs_file_util.c | 42 +++++++++++++---------
sys/fs/v7fs/v7fs_vnops.c | 59 ++++++++++++++++++-------------
usr.sbin/makefs/v7fs/v7fs_populate.c | 10 ++--
9 files changed, 120 insertions(+), 106 deletions(-)
diffs (truncated from 699 to 300 lines):
diff -r 9626cbd3fb3a -r bc8256bc74ef sbin/fsck_v7fs/main.c
--- a/sbin/fsck_v7fs/main.c Fri Feb 11 04:23:18 2022 +0000
+++ b/sbin/fsck_v7fs/main.c Fri Feb 11 10:55:15 2022 +0000
@@ -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 @@
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)
diff -r 9626cbd3fb3a -r bc8256bc74ef sbin/fsck_v7fs/pathname.c
--- a/sbin/fsck_v7fs/pathname.c Fri Feb 11 04:23:18 2022 +0000
+++ b/sbin/fsck_v7fs/pathname.c Fri Feb 11 10:55:15 2022 +0000
@@ -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 @@
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 @@
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))
diff -r 9626cbd3fb3a -r bc8256bc74ef sys/fs/v7fs/v7fs_dirent.c
--- a/sys/fs/v7fs/v7fs_dirent.c Fri Feb 11 04:23:18 2022 +0000
+++ b/sys/fs/v7fs/v7fs_dirent.c Fri Feb 11 10:55:15 2022 +0000
@@ -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 @@
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);
}
diff -r 9626cbd3fb3a -r bc8256bc74ef sys/fs/v7fs/v7fs_dirent.h
--- a/sys/fs/v7fs/v7fs_dirent.h Fri Feb 11 04:23:18 2022 +0000
+++ b/sys/fs/v7fs/v7fs_dirent.h Fri Feb 11 10:55:15 2022 +0000
@@ -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_ */
diff -r 9626cbd3fb3a -r bc8256bc74ef sys/fs/v7fs/v7fs_file.c
--- a/sys/fs/v7fs/v7fs_file.c Fri Feb 11 04:23:18 2022 +0000
+++ b/sys/fs/v7fs/v7fs_file.c Fri Feb 11 10:55:15 2022 +0000
@@ -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 @@
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 @@
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_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 @@
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 @@
} 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 @@
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 @@
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 @@
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_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_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)
diff -r 9626cbd3fb3a -r bc8256bc74ef sys/fs/v7fs/v7fs_file.h
--- a/sys/fs/v7fs/v7fs_file.h Fri Feb 11 04:23:18 2022 +0000
+++ b/sys/fs/v7fs/v7fs_file.h Fri Feb 11 10:55:15 2022 +0000
@@ -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 $ */
Home |
Main Index |
Thread Index |
Old Index