[Libsysio-commit] HEAD: libsysio/drivers/incore fs_incore.c
Brought to you by:
lward
From: Lee W. <lw...@us...> - 2003-10-10 18:52:31
|
Update of /cvsroot/libsysio/libsysio/drivers/incore In directory sc8-pr-cvs1:/tmp/cvs-serv14350/drivers/incore Modified Files: fs_incore.c Log Message: Red Storm branch mega-merge. Please, no more changes to any of the Red Storm branches. We'll keep them for reference for awhile but then, they go away. Finally! Index: fs_incore.c =================================================================== RCS file: /cvsroot/libsysio/libsysio/drivers/incore/fs_incore.c,v retrieving revision 1.6 retrieving revision 1.7 diff -u -w -b -B -p -r1.6 -r1.7 --- fs_incore.c 27 Sep 2003 19:42:01 -0000 1.6 +++ fs_incore.c 10 Oct 2003 18:50:31 -0000 1.7 @@ -56,7 +56,9 @@ #include <sys/types.h> #include <dirent.h> #include <sys/stat.h> +#ifdef _HAVE_STATVFS #include <sys/statvfs.h> +#endif #include <sys/queue.h> #include "sysio.h" @@ -132,7 +134,7 @@ static int _sysio_incore_inop_setattr(st static ssize_t _sysio_incore_dirop_getdirentries(struct inode *ino, char *buf, size_t nbytes, - off64_t *basep); + _SYSIO_OFF_T *basep); static int _sysio_incore_dirop_mkdir(struct pnode *pno, mode_t mode); static int _sysio_incore_dirop_rmdir(struct pnode *pno); static int _sysio_incore_inop_open(struct pnode *pno, int flags, mode_t mode); @@ -153,9 +155,11 @@ static int _sysio_incore_filop_ioctl(str unsigned long int request, va_list ap); static int _sysio_incore_dirop_mknod(struct pnode *pno, mode_t mode, dev_t dev); +#ifdef _HAVE_STATVFS static int _sysio_incore_inop_statvfs(struct pnode *pno, struct inode *ino, struct intnl_statvfs *buf); +#endif static void _sysio_incore_inop_gone(struct inode *ino); static int _sysio_incore_e_isdir(void); static int _sysio_incore_e_inval(void); @@ -205,7 +209,9 @@ static struct inode_ops _sysio_incore_di _sysio_incore_inop_sync, _sysio_incore_dirop_ioctl, _sysio_incore_dirop_mknod, +#ifdef _HAVE_STATVFS _sysio_incore_inop_statvfs, +#endif _sysio_incore_inop_gone }; @@ -218,7 +224,7 @@ static struct inode_ops _sysio_incore_di (ssize_t (*)(struct inode *, \ char *, \ size_t, \ - off64_t *))_sysio_incore_illop + _SYSIO_OFF_T *))_sysio_incore_illop #define _sysio_incore_filop_mkdir \ (int (*)(struct pnode *, mode_t))_sysio_incore_illop #define _sysio_incore_filop_rmdir \ @@ -258,7 +264,9 @@ static struct inode_ops _sysio_incore_fi _sysio_incore_inop_sync, _sysio_incore_filop_ioctl, _sysio_incore_filop_mknod, +#ifdef _HAVE_STATVFS _sysio_incore_inop_statvfs, +#endif _sysio_incore_inop_gone }; @@ -284,7 +292,9 @@ static struct inode_ops _sysio_incore_de _sysio_nodev_inop_sync, _sysio_nodev_inop_ioctl, _sysio_incore_filop_mknod, +#ifdef _HAVE_STATVFS _sysio_incore_inop_statvfs, +#endif _sysio_incore_inop_gone }; @@ -361,13 +371,27 @@ _sysio_incore_init() * Fill in the directory template. */ de = (struct intnl_dirent *)incore_dir_template; - de->d_off = off = de->d_reclen = INCORE_D_RECLEN(1); +#ifdef _DIRENT_HAVE_D_OFF + de->d_off = +#endif + off = de->d_reclen = INCORE_D_RECLEN(1); de->d_type = INCORE_D_TYPEOF(S_IFDIR); de->d_name[0] = '.'; - de->d_name[1] = ' '; - de = (void *)de + de->d_off; +#ifdef _DIRENT_HAVE_D_NAMLEN + de->d_namlen = 1; +#endif + /* + * Move to entry for `..' + */ + de = (void *)de + off; de->d_reclen = INCORE_D_RECLEN(2); - de->d_off = off += de->d_reclen; +#ifdef _DIRENT_HAVE_D_NAMLEN + de->d_namlen = 2; +#endif +#ifdef _DIRENT_HAVE_D_OFF + de->d_off = +#endif + off += de->d_reclen; de->d_type = INCORE_D_TYPEOF(S_IFDIR); de->d_name[0] = de->d_name[1] = '.'; de->d_name[2] = ' '; @@ -407,9 +431,9 @@ incore_i_alloc(struct incore_filesys *ic } static int -incore_trunc(struct incore_inode *icino, off64_t size, int clear) +incore_trunc(struct incore_inode *icino, _SYSIO_OFF_T size, int clear) { - off64_t n; + _SYSIO_OFF_T n; void *p; if (size < 0) @@ -477,7 +501,12 @@ incore_directory_new(struct incore_files sizeof(incore_dir_template)); de = icino->ici_data; de->d_ino = st->st_ino; - (void *)de += de->d_off; + (void *)de += +#ifdef _DIRENT_HAVE_D_OFF + de->d_off; +#else + de->d_reclen; +#endif de->d_ino = parent->ici_st.st_ino; /* @@ -695,7 +724,11 @@ _sysio_incore_fsop_gone(struct filesys * static void * incore_directory_probe(void *data, size_t siz, - off64_t origin, + _SYSIO_OFF_T origin +#ifndef _DIRENT_HAVE_D_OFF + __IS_UNUSED +#endif + , probe_ty entry, probe_ty hole, void *arg) @@ -706,15 +739,21 @@ incore_directory_probe(void *data, de = data; for (;;) { +#ifdef _DIRENT_HAVE_D_OFF assert(de->d_off); +#else + assert(de->d_reclen); +#endif if (entry && (p = (*entry)(de, de->d_reclen, arg))) return p; - n = de->d_off - origin; - if (hole && n > de->d_reclen) { - p = - (*hole)((void *)de + de->d_reclen, - n - de->d_reclen, - arg); + n = +#ifdef _DIRENT_HAVE_D_OFF + de->d_off - origin; +#else + ((void *)de - data) + de->d_reclen; +#endif + if (hole) { + p = (*hole)((void *)de, de->d_reclen, arg); if (p) return p; } @@ -732,7 +771,14 @@ incore_directory_match(struct intnl_dire struct lookup_data *ld) { - if (strlen(de->d_name) == ld->name->len && +#if defined(BSD) || defined(REDSTORM) + if (IFTODT(de->d_type) == DT_WHT) + return NULL; +#endif + if ( +#ifdef _DIRENT_HAVE_D_NAMLEN + ld->name->len == de->d_namlen && +#endif strncmp(de->d_name, ld->name->name, ld->name->len) == 0) return de; ld->de = de; @@ -893,6 +939,13 @@ struct copy_info { size_t nbytes; }; +/* + * Eumeration callback. + * + * Note: + * On those systems supporting white-out entries, they are returned. On + * systems without, they are not. + */ static void * incore_directory_enumerate(struct intnl_dirent *de, size_t reclen, @@ -910,7 +963,7 @@ static ssize_t _sysio_incore_dirop_getdirentries(struct inode *ino, char *buf, size_t nbytes, - off64_t *basep) + _SYSIO_OFF_T *basep) { struct incore_inode *icino = I2IC(ino); off_t off; @@ -974,7 +1027,9 @@ incore_directory_insert(struct incore_in size_t reclen; struct lookup_data lookup_data; struct intnl_dirent *de; + size_t xt; size_t n; + size_t r; reclen = INCORE_D_RECLEN(name->len); INCORE_LD_INIT(&lookup_data, reclen, name); @@ -988,39 +1043,74 @@ incore_directory_insert(struct incore_in if (de) return -EEXIST; de = lookup_data.de; - n = de->d_off; - if (n >= (size_t )parent->ici_st.st_size) { + xt = (void *)lookup_data.de - parent->ici_data; + n = +#ifdef _DIRENT_HAVE_D_OFF + de->d_off; +#else + xt + de->d_reclen; +#endif + r = +#ifdef _DIRENT_HAVE_D_OFF + de->d_reclen; +#else + INCORE_D_RECLEN(de->d_namlen); +#endif + if (!parent->ici_st.st_size || + xt + r + reclen > (size_t )parent->ici_st.st_size) { int err; - size_t xt; - xt = (void *)lookup_data.de - parent->ici_data; - err = - incore_trunc(parent, - ((size_t )((void *)de - parent->ici_data) + - de->d_reclen + - reclen), - 1); + err = incore_trunc(parent, xt + r + reclen, 1); if (err) return err; de = parent->ici_data + xt; n = parent->ici_st.st_size; } +#ifdef _DIRENT_HAVE_D_OFF + de->d_off = xt + r; /* trim */ +#else + de->d_reclen = r; +#endif + (void *)de += r; /* reposition */ + xt += r; + +#ifndef _DIRENT_HAVE_D_OFF /* - * Fix previous entry. + * Will we split this hole or use all of it? */ - de->d_off = (void *)de - parent->ici_data + de->d_reclen; + if (lookup_data.hole.len - reclen && + lookup_data.hole.len - reclen <= INCORE_D_RECLEN(1)) + reclen = lookup_data.hole.len; +#endif /* * Insert new. */ - (void *)de += de->d_reclen; de->d_ino = inum; +#ifdef _DIRENT_HAVE_D_OFF de->d_off = n; +#endif de->d_reclen = reclen; de->d_type = type; (void )memcpy(de->d_name, name->name, name->len); - de->d_name[name->len] = '\0'; +#ifdef _DIRENT_HAVE_D_NAMLEN + de->d_namlen = name->len; +#endif + +#ifndef _DIRENT_HAVE_D_OFF + xt += reclen; + if (n - xt) { + /* + * White-out remaining part of the hole. + */ + (void *)de += reclen; + de->d_ino = 0; + de->d_reclen = n - xt; + de->d_type = DT_WHT; + de->d_namlen = 0; + } +#endif /* * Update attributes to reflect the new entry. @@ -1110,6 +1200,10 @@ incore_unlink_entry(struct incore_inode { struct lookup_data lookup_data; struct intnl_dirent *de; + size_t reclen; +#ifdef _DIRENT_HAVE_D_OFF + size_t off; +#endif if (!S_ISDIR(icino->ici_st.st_mode)) return -ENOTDIR; @@ -1126,8 +1220,25 @@ incore_unlink_entry(struct incore_inode return -ENOENT; assert((size_t )((void *)de - icino->ici_data) >= sizeof(incore_dir_template)); - lookup_data.de->d_off = de->d_off; /* unlink */ - (void )memset(de, 0, de->d_reclen); /* clear */ +#ifndef _DIRENT_HAVE_D_OFF + reclen = de->d_reclen; +#else + off = de->d_off; + reclen = off - ((void *)de - icino->ici_data); +#endif + (void )memset(de, 0, reclen); +#ifndef _DIRENT_HAVE_D_OFF + de->d_type = (__uint8_t )DTTOIF(DT_WHT); + de->d_reclen = reclen; +#else + lookup_data.de->d_off = off; +#endif + + /* + * Adjust link count. + */ + assert(icino->ici_st.st_nlink > 2); + icino->ici_st.st_nlink--; /* * Adjust link count. @@ -1418,11 +1529,11 @@ incore_doio(ssize_t (*f)(struct incore_i static ssize_t incore_read(struct incore_inode *icino, off_t off, char *buf, size_t nbytes) { - off64_t n; + _SYSIO_OFF_T n; if (!nbytes || off > icino->ici_st.st_size) return 0; - n = (off64_t )nbytes; + n = (_SYSIO_OFF_T )nbytes; if (!(n > 0 && (size_t )n == nbytes)) return -EINVAL; if (n > icino->ici_st.st_size - off) @@ -1448,11 +1559,11 @@ incore_write(struct incore_inode *icino, size_t nbytes) { int err; - off64_t n; + _SYSIO_OFF_T n; if (!nbytes) return 0; - n = (off64_t )nbytes; + n = (_SYSIO_OFF_T )nbytes; if (!(n > 0 && (size_t )n == nbytes)) return -EINVAL; if (off + n > icino->ici_st.st_size) { @@ -1544,7 +1655,7 @@ _sysio_incore_dirop_mknod(struct pnode * return -EINVAL; /* - * Must create a new, regular, file. + * Initialize attributes. */ (void )memset(&stat, 0, sizeof(stat)); stat.st_dev = pno->p_parent->p_base->pb_ino->i_fs->fs_dev; @@ -1566,6 +1677,7 @@ _sysio_incore_dirop_mknod(struct pnode * return incore_create(pno, &stat); } +#ifdef _HAVE_STATVFS static int _sysio_incore_inop_statvfs(struct pnode *pno, struct inode *ino, @@ -1599,6 +1711,7 @@ _sysio_incore_inop_statvfs(struct pnode return 0; } +#endif void _sysio_incore_inop_gone(struct inode *ino) |