void fs_read(loff_t pos,int size,void *data) { CHANGE *walk; int got; #if 1 // TMN const size_t readsize_aligned = (size % 512) ? (size + (512 - (size % 512))) : size; // TMN: const loff_t seekpos_aligned = pos - (pos % 512); // TMN: const size_t seek_delta = (size_t)(pos - seekpos_aligned); // TMN: const size_t readsize = (size_t)(pos - seekpos_aligned) + readsize_aligned; // TMN: char* tmpBuf = vfalloc(readsize_aligned); // TMN: if (llseek(fd,seekpos_aligned,0) != seekpos_aligned) pdie("Seek to %I64d",pos); if ((got = read(fd,tmpBuf,readsize_aligned)) < 0) pdie("Read %d bytes at %I64d",size,pos); assert(got >= size); got = size; assert(seek_delta + size <= readsize); memcpy(data, tmpBuf+seek_delta, size); vffree(tmpBuf); #else // TMN: if (llseek(fd,pos,0) != pos) pdie("Seek to %lld",pos); if ((got = read(fd,data,size)) < 0) pdie("Read %d bytes at %lld",size,pos); #endif // TMN: if (got != size) die("Got %d bytes instead of %d at %I64d",got,size,pos); for (walk = changes; walk; walk = walk->next) { if (walk->pos < pos+size && walk->pos+walk->size > pos) { if (walk->pos < pos) memcpy(data,(char *) walk->data+pos-walk->pos,min((size_t)size, (size_t)(walk->size-pos+walk->pos))); else memcpy((char *) data+walk->pos-pos,walk->data,min((size_t)walk->size, (size_t)(size+pos-walk->pos))); } } }
void bwrite(int fd, char *buf, daddr_t blk, long size) { int i, n; char *cp; offset_t offset = ldbtob(blk); offset_t addr; if (fd < 0) return; if (llseek(fd, offset, 0) < 0) rwerror(gettext("SEEK"), blk); else if (write(fd, buf, (int)size) == size) { fsmodified = 1; return; } rwerror(gettext("WRITE"), blk); if (llseek(fd, offset, 0) < 0) rwerror(gettext("SEEK"), blk); pwarn(gettext("THE FOLLOWING SECTORS COULD NOT BE WRITTEN:")); for (cp = buf, i = 0; i < btodb(size); i++, cp += DEV_BSIZE) { n = 0; addr = ldbtob(blk + i); if (llseek(fd, addr, SEEK_CUR) < 0 || (n = write(fd, cp, DEV_BSIZE)) < 0) { (void) printf(" %ld", blk + i); } else if (n > 0) { fsmodified = 1; } } (void) printf("\n"); }
int32_t bread(int fd, char *buf, daddr_t blk, long size) { char *cp; int i, errs; offset_t offset = ldbtob(blk); offset_t addr; if (llseek(fd, offset, 0) < 0) rwerror(gettext("SEEK"), blk); else if (read(fd, buf, (int)size) == size) return (0); rwerror(gettext("READ"), blk); if (llseek(fd, offset, 0) < 0) rwerror(gettext("SEEK"), blk); errs = 0; bzero(buf, (int)size); pwarn(gettext("THE FOLLOWING SECTORS COULD NOT BE READ:")); for (cp = buf, i = 0; i < btodb(size); i++, cp += DEV_BSIZE) { addr = ldbtob(blk + i); if (llseek(fd, addr, SEEK_CUR) < 0 || read(fd, cp, (int)secsize) < 0) { (void) printf(" %ld", blk + i); errs++; } } (void) printf("\n"); return (errs); }
void ADIOI_SFS_Fcntl(ADIO_File fd, int flag, ADIO_Fcntl_t *fcntl_struct, int *error_code) { int i, ntimes, len; ADIO_Offset curr_fsize, alloc_size, size, done; ADIO_Status status; char *buf; #ifndef PRINT_ERR_MSG static char myname[] = "ADIOI_SFS_FCNTL"; #endif switch(flag) { case ADIO_FCNTL_GET_FSIZE: /* On SFS, I find that a write from one process, which changes the file size, does not automatically make the new file size visible to other processes. Therefore, a sync-barrier-sync is needed. (Other processes are able to read the data written though; only file size is returned incorrectly.) */ fsync(fd->fd_sys); MPI_Barrier(fd->comm); fsync(fd->fd_sys); fcntl_struct->fsize = llseek(fd->fd_sys, 0, SEEK_END); if (fd->fp_sys_posn != -1) llseek(fd->fd_sys, fd->fp_sys_posn, SEEK_SET); if (fcntl_struct->fsize == -1) { #ifdef MPICH2 *error_code = MPIR_Err_create_code(MPI_SUCCESS, MPIR_ERR_RECOVERABLE, myname, __LINE__, MPI_ERR_IO, "**io", "**io %s", strerror(errno)); #elif defined(PRINT_ERR_MSG) *error_code = MPI_ERR_UNKNOWN; #else /* MPICH-1 */ *error_code = MPIR_Err_setmsg(MPI_ERR_IO, MPIR_ADIO_ERROR, myname, "I/O Error", "%s", strerror(errno)); ADIOI_Error(fd, *error_code, myname); #endif } else *error_code = MPI_SUCCESS; break; case ADIO_FCNTL_SET_DISKSPACE: ADIOI_GEN_Prealloc(fd, fcntl_struct->diskspace, error_code); break; case ADIO_FCNTL_SET_ATOMICITY: fd->atomicity = (fcntl_struct->atomicity == 0) ? 0 : 1; *error_code = MPI_SUCCESS; break; default: FPRINTF(stderr, "Unknown flag passed to ADIOI_SFS_Fcntl\n"); MPI_Abort(MPI_COMM_WORLD, 1); } }
static void putdiscq(uid_t uid) { struct fsquot *fsqp; for (fsqp = fsqlist; fsqp; fsqp = fsqp->fsq_next) { if (quotactl(Q_SETQLIM, fsqp->fsq_dev, uid, (caddr_t)&fsqp->fsq_dqb) != 0) { int fd; if ((fd = open64(fsqp->fsq_qfile, O_RDWR)) < 0) { (void) fprintf(stderr, "edquota: "); perror(fsqp->fsq_qfile); continue; } (void) llseek(fd, (offset_t)dqoff(uid), L_SET); if (write(fd, (char *)&fsqp->fsq_dqb, sizeof (struct dqblk)) != sizeof (struct dqblk)) { (void) fprintf(stderr, "edquota: "); perror(fsqp->fsq_qfile); } (void) close(fd); } } }
asmlinkage long sys_llseek(unsigned int fd, unsigned long offset_high, unsigned long offset_low, loff_t * result, unsigned int origin) { int retval; struct file * file; struct vms_fd * vms_fd; loff_t offset; retval = -EBADF; vms_fd = fget(fd); file = vms_fd->vfd$l_fd_p; if (!file) goto bad; retval = -EINVAL; if (origin > 2) goto out_putf; offset = llseek(file, ((loff_t) offset_high << 32) | offset_low, origin); retval = (int)offset; if (offset >= 0) { retval = -EFAULT; if (!copy_to_user(result, &offset, sizeof(offset))) retval = 0; } out_putf: fput(file); bad: return retval; }
void bread(diskaddr_t bno, char *buf, int cnt) { int i; int got; offset_t offset; offset = (offset_t)bno * DEV_BSIZE; if (llseek(fi, offset, 0) == (offset_t)-1) { (void) fprintf(stderr, "ff: llseek error %lx %lx\n", ((long *)&offset)[0], ((long *)&offset)[1]); for (i = 0; i < cnt; i++) buf[i] = 0; return; } got = read((int)fi, buf, cnt); if (got != cnt) { perror("read"); (void) fprintf(stderr, "ff: (wanted %d got %d blk %lld)\n", cnt, got, bno); for (i = 0; i < cnt; i++) buf[i] = 0; } }
void bread(diskaddr_t bno, char *buf, int cnt) { int i; int got; if (llseek(fi, (offset_t)bno * DEV_BSIZE, 0) == -1) { (void) fprintf(stderr, "ncheck: lseek error %lld\n", (offset_t)bno * DEV_BSIZE); for (i = 0; i < cnt; i++) { buf[i] = 0; } return; } got = read((int)fi, buf, cnt); if (got != cnt) { (void) fprintf(stderr, "ncheck: read error at block %lld (wanted %d got %d)\n", bno, cnt, got); for (i = 0; i < cnt; i++) buf[i] = 0; } }
void ADIOI_PIOFS_ReadContig(ADIO_File fd, void *buf, int count, MPI_Datatype datatype, int file_ptr_type, ADIO_Offset offset, ADIO_Status *status, int *error_code) { int err=-1, datatype_size, len; #ifndef PRINT_ERR_MSG static char myname[] = "ADIOI_PIOFS_READCONTIG"; #endif MPI_Type_size(datatype, &datatype_size); len = datatype_size * count; if (file_ptr_type == ADIO_EXPLICIT_OFFSET) { if (fd->fp_sys_posn != offset) { llseek(fd->fd_sys, offset, SEEK_SET); } err = read(fd->fd_sys, buf, len); fd->fp_sys_posn = offset + err; /* individual file pointer not updated */ } else { /* read from curr. location of ind. file pointer */ if (fd->fp_sys_posn != fd->fp_ind) { llseek(fd->fd_sys, fd->fp_ind, SEEK_SET); } err = read(fd->fd_sys, buf, len); fd->fp_ind += err; fd->fp_sys_posn = fd->fp_ind; } #ifdef HAVE_STATUS_SET_BYTES if (err != -1) MPIR_Status_set_bytes(status, datatype, err); #endif if (err == -1) { #ifdef MPICH *error_code = MPIR_Err_create_code(MPI_SUCCESS, MPIR_ERR_RECOVERABLE, myname, __LINE__, MPI_ERR_IO, "**io", "**io %s", strerror(errno)); #elif defined(PRINT_ERR_MSG) *error_code = MPI_ERR_UNKNOWN; #else *error_code = MPIR_Err_setmsg(MPI_ERR_IO, MPIR_ADIO_ERROR, myname, "I/O Error", "%s", strerror(errno)); ADIOI_Error(fd, *error_code, myname); #endif } else *error_code = MPI_SUCCESS; }
int fs_test(loff_t pos,int size) { void *scratch; int okay; #if 1 // TMN const size_t readsize_aligned = (size % 512) ? (size + (512 - (size % 512))) : size; // TMN: const loff_t seekpos_aligned = pos - (pos % 512); // TMN: scratch = vfalloc(readsize_aligned); if (llseek(fd,seekpos_aligned,0) != seekpos_aligned) pdie("Seek to %lld",pos); okay = read(fd,scratch,readsize_aligned) == (int)readsize_aligned; vffree(scratch); #else // TMN: if (llseek(fd,pos,0) != pos) pdie("Seek to %lld",pos); scratch = vfalloc(size); okay = read(fd,scratch,size) == size; vffree(scratch); #endif // TMN: return okay; }
void bwrite(diskaddr_t blk, char *buf, int size) { if (llseek(fi, (offset_t)blk * DEV_BSIZE, 0) < 0) { perror("FS SEEK"); exit(31+6); } if (write(fi, buf, size) != size) { perror("FS WRITE"); exit(31+7); } }
/* partition table display */ static void do_table(char *part) { int fd, i; struct partition pt [PART_MAX]; unsigned int second, base; unsigned char boot_sig[2]; if (!strncmp(part, "/dev/", 5)) { if (strncmp(part+5, "md", 2) && isdigit(part[strlen(part)-1]) ) die("Not a device: '%s'", part); fd = open(part, O_RDONLY); } else fd = -1; if (fd<0) die("Unable to open '%s'", part); if (lseek(fd, PART_TABLE_OFFSET, SEEK_SET)<0) die("lseek failed"); if (read(fd, pt, sizeof(pt)) != sizeof(pt)) die("read pt failed"); if ( read(fd, &boot_sig[0], sizeof(boot_sig)) != sizeof(boot_sig) || boot_sig[0] != BOOT_SIGNATURE0 || boot_sig[1] != BOOT_SIGNATURE1 ) die("read boot signature failed"); { if (lseek(fd, MAX_BOOT_SIZE+2, SEEK_SET)<0) die("lseek s/n failed"); if (read(fd, &second, sizeof(second)) != sizeof(second)) die("read s/n failed"); printf(" S/N = %08X\n", second); } printf("%s\n", phead); second=base=0; for (i=0; i<PART_MAX; i++) { print_pt(i+1, pt[i]); if (is_extd_part(pt[i].sys_ind)) { if (!base) base = pt[i].start_sect; else die("invalid partition table: second extended partition found"); } } i=5; while (verbose>0 && base) { if (llseek(fd, SECTORSIZE*(base+second) + PART_TABLE_OFFSET, SEEK_SET) < 0) die("secondary llseek failed"); if (read(fd, pt, sizeof(pt)) != sizeof(pt)) die("secondary read pt failed"); if ( read(fd, &boot_sig[0], sizeof(boot_sig)) != sizeof(boot_sig) || boot_sig[0] != BOOT_SIGNATURE0 || boot_sig[1] != BOOT_SIGNATURE1 ) die("read second boot signature failed"); print_pt(i++, pt[0]); if (is_extd_part(pt[1].sys_ind)) second=pt[1].start_sect; else base = 0; } close(fd); }
/// longseek // A generic 64-bit version of seek long long longseek(int stream,long long offset,int whence) { #if defined(HAVE_LSEEK64) return lseek64(stream,offset,whence); #elif defined(HAVE_LLSEEK) return llseek(stream,offset,whence); #elif defined(HAVE_LSEEK) return lseek(stream,offset,whence); #elif defined(HAVE__LSEEKI64) return _lseeki64(stream,offset,whence); #else // No seeking possible. return -1; #endif }
static arc_handle_t arxive_open(int fd) { arc_handle_t ar; if ((ar = arxive_new()) == 0) return 0; if (llseek(fd, 0, SEEK_SET) < 0) return 0; if (archive_read_open_fd(ar, fd, ARC_BLOCKSIZE) < 0) return 0; return ar; }
void ADIOI_SFS_Open(ADIO_File fd, int *error_code) { int perm, old_mask, amode; #ifndef PRINT_ERR_MSG static char myname[] = "ADIOI_SFS_OPEN"; #endif if (fd->perm == ADIO_PERM_NULL) { old_mask = umask(022); umask(old_mask); perm = old_mask ^ 0666; } else perm = fd->perm; amode = 0; if (fd->access_mode & ADIO_CREATE) amode = amode | O_CREAT; if (fd->access_mode & ADIO_RDONLY) amode = amode | O_RDONLY; if (fd->access_mode & ADIO_WRONLY) amode = amode | O_WRONLY; if (fd->access_mode & ADIO_RDWR) amode = amode | O_RDWR; if (fd->access_mode & ADIO_EXCL) amode = amode | O_EXCL; fd->fd_sys = open(fd->filename, amode, perm); fd->fd_direct = -1; if ((fd->fd_sys != -1) && (fd->access_mode & ADIO_APPEND)) { fd->fp_ind = llseek(fd->fd_sys, 0, SEEK_END); fd->fp_sys_posn = fd->fp_ind; } if (fd->fd_sys == -1) { #ifdef MPICH *error_code = MPIR_Err_create_code(MPI_SUCCESS, MPIR_ERR_RECOVERABLE, myname, __LINE__, MPI_ERR_IO, "**io", "**io %s", strerror(errno)); #elif defined(PRINT_ERR_MSG) *error_code = MPI_ERR_UNKNOWN; #else /* MPICH-1 */ *error_code = MPIR_Err_setmsg(MPI_ERR_IO, MPIR_ADIO_ERROR, myname, "I/O Error", "%s", strerror(errno)); ADIOI_Error(ADIO_FILE_NULL, *error_code, myname); #endif } else *error_code = MPI_SUCCESS; }
int __PHYSFS_platformSeek(void *opaque, PHYSFS_uint64 pos) { int fd = *((int *) opaque); #ifdef PHYSFS_HAVE_LLSEEK unsigned long offset_high = ((pos >> 32) & 0xFFFFFFFF); unsigned long offset_low = (pos & 0xFFFFFFFF); loff_t retoffset; int rc = llseek(fd, offset_high, offset_low, &retoffset, SEEK_SET); BAIL_IF_MACRO(rc == -1, strerror(errno), 0); #else BAIL_IF_MACRO(lseek(fd, (int) pos, SEEK_SET) == -1, strerror(errno), 0); #endif return(1); } /* __PHYSFS_platformSeek */
PHYSFS_sint64 __PHYSFS_platformTell(void *opaque) { int fd = *((int *) opaque); PHYSFS_sint64 retval; #ifdef PHYSFS_HAVE_LLSEEK loff_t retoffset; int rc = llseek(fd, 0, &retoffset, SEEK_CUR); BAIL_IF_MACRO(rc == -1, strerror(errno), -1); retval = (PHYSFS_sint64) retoffset; #else retval = (PHYSFS_sint64) lseek(fd, 0, SEEK_CUR); BAIL_IF_MACRO(retval == -1, strerror(errno), -1); #endif return(retval); } /* __PHYSFS_platformTell */
int bread(diskaddr_t bno, char *buf, int cnt) { int i; if (llseek(fi, (offset_t)bno * DEV_BSIZE, 0) < 0) { fprintf(stderr, "bread: "); perror("llseek"); return (1); } if ((i = read(fi, buf, cnt)) != cnt) { perror("read"); for (i = 0; i < sblock.fs_bsize; i++) buf[i] = 0; return (1); } return (0); }
int mt_lseek(int fd, mt_off_t where, int whence) { #if defined HAVE_LSEEK64 if(lseek64(fd, where, whence) >= 0) return 0; else return -1; #elif defined HAVE_LLSEEK if(llseek(fd, where, whence) >= 0) return 0; else return -1; #else if (lseek(fd, (off_t) where, whence) >= 0) return 0; else return 1; #endif }
static int check_for_login_inactivity( struct passwd pwd, struct spwd shpwd) { int fdl; struct lastlog ll; int retval; long long offset; offset = (long long) pwd.pw_uid * (long long) sizeof (struct lastlog); if ((fdl = open(LASTLOG, O_RDWR|O_CREAT, 0444)) >= 0) { /* * Read the last login (ll) time */ if (llseek(fdl, offset, SEEK_SET) != offset) { /* * XXX uid too large for database */ return (0); } retval = read(fdl, (char *)&ll, sizeof (ll)); /* Check for login inactivity */ if ((shpwd.sp_inact > 0) && (retval == sizeof (ll)) && ll.ll_time) { if (((ll.ll_time / DAY) + shpwd.sp_inact) < DAY_NOW) { /* * Account inactive for too long */ (void) close(fdl); return (1); } } (void) close(fdl); } return (0); }
asmlinkage off_t sys_lseek(unsigned int fd, off_t offset, unsigned int origin) { off_t retval; struct file * file; retval = -EBADF; file = fget(fd); if (!file) goto bad; retval = -EINVAL; if (origin <= 2) { loff_t res = llseek(file, offset, origin); retval = res; if (res != (loff_t)retval) retval = -EOVERFLOW; /* LFS: should only happen on 32 bit platforms */ } fput(file); bad: return retval; }
void read_sectors(int fd, char *buf, int sectornr, int sectorct) { extern long long llseek(int fd, long long offset, int whence); long long offset; int n; offset = sectornr; offset *= 512; if (llseek(fd, offset, SEEK_SET) != offset) { fprintf(stderr, "%s: llseek error\n", progname); exit(1); } n = read(fd, buf, sectorct*512); if (n != sectorct*512) { if (n == -1) perror("read"); fprintf(stderr, "%s: error reading sectors %d-%d\n", progname, sectornr, sectornr+sectorct-1); exit(1); } }
off64_t my_lseek64(int fd,off64_t offset,int whence) { u_long hi,lo; off64_t result; #ifdef SUN hi = 0; #else hi = offset>>32; #endif lo = offset & 0xffffffff; /* use llseek or _llseek??? */ if( llseek(fd,hi,lo,&result,whence) < 0 ){ perror("llseek"); return(-1); } return(result); }
int getdiskquota(struct mnttab *mntp, uid_t uid, struct dqblk *dqp) { int fd; dev_t fsdev; struct stat64 statb; char qfilename[MAXPATHLEN]; if (stat64(mntp->mnt_special, &statb) < 0 || (statb.st_mode & S_IFMT) != S_IFBLK) return (0); fsdev = statb.st_rdev; (void) snprintf(qfilename, sizeof (qfilename), "%s/%s", mntp->mnt_mountp, QFNAME); if (stat64(qfilename, &statb) < 0 || statb.st_dev != fsdev) return (0); (void) __priv_bracket(PRIV_ON); fd = open64(qfilename, O_RDONLY); (void) __priv_bracket(PRIV_OFF); if (fd < 0) return (0); (void) llseek(fd, (offset_t)dqoff(uid), L_SET); switch (read(fd, dqp, sizeof (struct dqblk))) { case 0: /* EOF */ /* * Convert implicit 0 quota (EOF) * into an explicit one (zero'ed dqblk). */ memset((caddr_t)dqp, 0, sizeof (struct dqblk)); break; case sizeof (struct dqblk): /* OK */ break; default: /* ERROR */ close(fd); return (0); } close(fd); return (1); }
/* Get the data of a cluster */ static const unsigned char * get_cluster(long long cluster) { int i,oldest; unsigned ksusage; static unsigned curusage=1; /* Oups. */ if(cluster<-1ll) return NULL; /* Look if the inode is in the cache; * if no, look for the oldest cache entry */ ksusage=clusters[0].lastusage; for(i=oldest=0;i<MAXINODEBUF;i++) { if(clusters[i].cluster==cluster) { clusters[i].cluster=curusage++; return clusters[i].data; } else if(clusters[i].lastusage<ksusage) { ksusage=clusters[i].lastusage; oldest=i; } } /* A sparse file cluster */ if(cluster==-1ll) { memset(clusters[oldest].data,0,clustlen); clusters[oldest].lastusage=curusage++; clusters[oldest].cluster=-1ll; return clusters[oldest].data; } /* Read the cluster */ clusters[i].cluster=-2ll; llseek(dskhandle,cluster*clustlen+part_offset,SEEK_SET); if(read(dskhandle,clusters[oldest].data,clustlen)!=clustlen) return NULL; clusters[oldest].lastusage=curusage++; clusters[oldest].cluster=cluster; return clusters[oldest].data; }
static void getdiscq(uid_t uid) { struct fsquot *fsqp; int fd; for (fsqp = fsqlist; fsqp; fsqp = fsqp->fsq_next) { if (quotactl(Q_GETQUOTA, fsqp->fsq_dev, uid, (caddr_t)&fsqp->fsq_dqb) != 0) { if ((fd = open64(fsqp->fsq_qfile, O_RDONLY)) < 0) { (void) fprintf(stderr, "edquota: "); perror(fsqp->fsq_qfile); continue; } (void) llseek(fd, (offset_t)dqoff(uid), L_SET); switch (read(fd, (char *)&fsqp->fsq_dqb, sizeof (struct dqblk))) { case 0: /* * Convert implicit 0 quota (EOF) * into an explicit one (zero'ed dqblk) */ bzero((caddr_t)&fsqp->fsq_dqb, sizeof (struct dqblk)); break; case sizeof (struct dqblk): /* OK */ break; default: /* ERROR */ (void) fprintf(stderr, "edquota: read error in "); perror(fsqp->fsq_qfile); break; } (void) close(fd); } } }
void ADIOI_PIOFS_Fcntl(ADIO_File fd, int flag, ADIO_Fcntl_t *fcntl_struct, int *error_code) { MPI_Datatype copy_etype, copy_filetype; int i, ntimes, err; ADIO_Offset curr_fsize, alloc_size, size, len, done; ADIO_Status status; char *buf; piofs_change_view_t *piofs_change_view; #ifndef PRINT_ERR_MSG static char myname[] = "ADIOI_PIOFS_FCNTL"; #endif switch(flag) { case ADIO_FCNTL_GET_FSIZE: fcntl_struct->fsize = llseek(fd->fd_sys, 0, SEEK_END); if (fd->fp_sys_posn != -1) llseek(fd->fd_sys, fd->fp_sys_posn, SEEK_SET); if (fcntl_struct->fsize == -1) { #ifdef MPICH *error_code = MPIR_Err_create_code(MPI_SUCCESS, MPIR_ERR_RECOVERABLE, myname, __LINE__, MPI_ERR_IO, "**io", "**io %s", strerror(errno)); #elif defined(PRINT_ERR_MSG) *error_code = MPI_ERR_UNKNOWN; #else /* MPICH-1 */ *error_code = MPIR_Err_setmsg(MPI_ERR_IO, MPIR_ADIO_ERROR, myname, "I/O Error", "%s", strerror(errno)); ADIOI_Error(fd, *error_code, myname); #endif } else *error_code = MPI_SUCCESS; break; case ADIO_FCNTL_SET_DISKSPACE: ADIOI_GEN_Prealloc(fd, fcntl_struct->diskspace, error_code); break; case ADIO_FCNTL_SET_ATOMICITY: piofs_change_view = (piofs_change_view_t *) ADIOI_Malloc(sizeof(piofs_change_view_t)); piofs_change_view->Vbs = piofs_change_view->Vn = piofs_change_view->Hbs = piofs_change_view->Hn = 1; piofs_change_view->subfile = 0; piofs_change_view->flags = (fcntl_struct->atomicity == 0) ? (ACTIVE | NORMAL) : (ACTIVE | CAUTIOUS); err = piofsioctl(fd->fd_sys, PIOFS_CHANGE_VIEW, piofs_change_view); ADIOI_Free(piofs_change_view); fd->atomicity = (fcntl_struct->atomicity == 0) ? 0 : 1; if (err == -1) { #ifdef MPICH *error_code = MPIR_Err_create_code(MPI_SUCCESS, MPIR_ERR_RECOVERABLE, myname, __LINE__, MPI_ERR_IO, "**io", "**io %s", strerror(errno)); #elif defined(PRINT_ERR_MSG) *error_code = MPI_ERR_UNKNOWN; #else /* MPICH-1 */ *error_code = MPIR_Err_setmsg(MPI_ERR_IO, MPIR_ADIO_ERROR, myname, "I/O Error", "%s", strerror(errno)); ADIOI_Error(fd, *error_code, myname); #endif } else *error_code = MPI_SUCCESS; break; default: FPRINTF(stderr, "Unknown flag passed to ADIOI_PIOFS_Fcntl\n"); MPI_Abort(MPI_COMM_WORLD, 1); } }
/*ARGSUSED*/ int pam_sm_open_session(pam_handle_t *pamh, int flags, int argc, const char **argv) { int error; char *ttyn, *rhost, *user; int fdl; struct lastlog newll; struct passwd pwd; char buffer[NSS_BUFLEN_PASSWD]; int i; int debug = 0; offset_t offset; time_t cur_time; for (i = 0; i < argc; i++) { if (strcasecmp(argv[i], "debug") == 0) debug = 1; else syslog(LOG_ERR, "illegal option %s", argv[i]); } if (debug) syslog(LOG_DEBUG, "pam_unix_session: inside pam_sm_open_session()"); if ((error = pam_get_item(pamh, PAM_TTY, (void **)&ttyn)) != PAM_SUCCESS || (error = pam_get_item(pamh, PAM_USER, (void **)&user)) != PAM_SUCCESS || (error = pam_get_item(pamh, PAM_RHOST, (void **)&rhost)) != PAM_SUCCESS) { return (error); } if (user == NULL || *user == '\0') return (PAM_USER_UNKNOWN); /* report error if ttyn not set */ if (ttyn == NULL) return (PAM_SESSION_ERR); if (getpwnam_r(user, &pwd, buffer, sizeof (buffer)) == NULL) { return (PAM_USER_UNKNOWN); } if ((fdl = open(LASTLOG, O_RDWR|O_CREAT|O_DSYNC, 0444)) >= 0) { /* * The value of lastlog is read by the UNIX * account management module */ offset = (offset_t)pwd.pw_uid * (offset_t)sizeof (struct lastlog); if (llseek(fdl, offset, SEEK_SET) != offset) { syslog(LOG_ERR, "pam_unix_session: Can't update lastlog: uid %d " "too large", pwd.pw_uid); (void) close(fdl); return (PAM_SUCCESS); } /* * use time32_t in case of _LP64 * since it's written in lastlog.h */ (void) time(&cur_time); bzero((char *)&newll, sizeof (struct lastlog)); #ifdef _LP64 newll.ll_time = (time32_t)cur_time; #else newll.ll_time = cur_time; #endif if ((strncmp(ttyn, "/dev/", 5) == 0)) { (void) strlcpy(newll.ll_line, (ttyn + sizeof ("/dev/")-1), sizeof (newll.ll_line)); } else { (void) strlcpy(newll.ll_line, ttyn, sizeof (newll.ll_line)); } if (rhost != NULL) { (void) strlcpy(newll.ll_host, rhost, sizeof (newll.ll_host)); } if (debug) { char buf[26]; (void) ctime_r((const time_t *)&cur_time, buf, sizeof (buf)); buf[24] = '\000'; syslog(LOG_DEBUG, "pam_unix_session: " "user = %s, time = %s, tty = %s, host = %s.", user, buf, newll.ll_line, newll.ll_host); } if (write(fdl, (char *)&newll, sizeof (newll)) != sizeof (newll)) syslog(LOG_ERR, "pam_unix_session: Can't write " "lastlog: uid %d: %m", pwd.pw_uid); if (close(fdl) != 0) syslog(LOG_ERR, "pam_unix_session: Can't close " "lastlog: uid %d: %m", pwd.pw_uid); } return (PAM_SUCCESS); }
int _get_partition_type(struct dev_mgr *dm, struct device *d) { int pv_handle = -1; struct device *primary; ssize_t read_ret; ssize_t bytes_read = 0; char *buffer; unsigned short *s_buffer; struct partition *part; loff_t offset = 0; loff_t extended_offset = 0; int part_sought; int part_found = 0; int first_partition = 1; int extended_partition = 0; int p; if (!(primary = dev_primary(dm, d))) { log_error ("Failed to find main device containing partition %s", d->name); return 0; } if (!(buffer = dm_malloc(SECTOR_SIZE))) { log_error("Failed to allocate partition table buffer"); return 0; } /* Get partition table */ if ((pv_handle = open(primary->name, O_RDONLY)) < 0) { log_error("%s: open failed: %s", primary->name, strerror(errno)); return 0; } s_buffer = (unsigned short *) buffer; part = (struct partition *) (buffer + 0x1be); part_sought = MINOR_PART(dm, d); do { bytes_read = 0; if (llseek(pv_handle, offset * SECTOR_SIZE, SEEK_SET) == -1) { log_error("%s: llseek failed: %s", primary->name, strerror(errno)); return 0; } while ((bytes_read < SECTOR_SIZE) && (read_ret = read(pv_handle, buffer + bytes_read, SECTOR_SIZE - bytes_read)) != -1) bytes_read += read_ret; if (read_ret == -1) { log_error("%s: read failed: %s", primary->name, strerror(errno)); return 0; } if (s_buffer[255] == 0xAA55) { if (is_whole_disk(dm, d)) return -1; } else return 0; extended_partition = 0; /* Loop through primary partitions */ for (p = 0; p < 4; p++) { if (part[p].sys_ind == DOS_EXTENDED_PARTITION || part[p].sys_ind == LINUX_EXTENDED_PARTITION || part[p].sys_ind == WIN98_EXTENDED_PARTITION) { extended_partition = 1; offset = extended_offset + part[p].start_sect; if (extended_offset == 0) extended_offset = part[p].start_sect; if (first_partition == 1) part_found++; } else if (first_partition == 1) { if (p == part_sought) { if (part[p].sys_ind == 0) { /* missing primary? */ return 0; } } else part_found++; } else if (!part[p].sys_ind) part_found++; if (part_sought == part_found) return part[p].sys_ind; } first_partition = 0; } while (extended_partition == 1); return 0; }
/* * Try to: * (1) open the device; * (2) fstat the opened device (to verify that it's a device) * (3) seek to the superblock offset; * (4) read the superblock; * (5) check that the SBLK and magic numbers are present; * (6) if it's a char dev, and debug is on, get the dev geometry and VTOC; and * (7) stash all the info. * * If any of this fails (except geom/VTOC calls) we return, saving no info. */ static void CheckDev(char *dev) { int fd; struct stat sbuf; struct sam_sblk sblk; #ifdef sun struct dk_cinfo dkc; struct vtoc vt; struct dk_gpt *efi_vtoc; #endif /* sun */ static struct sam_host_table_blk *htp = NULL; int hosts_table_size; char devrname[MAXPATHLEN]; if (!Dsk2Rdsk(dev, devrname)) { return; } if ((fd = open(devrname, O_RDONLY)) < 0) { if (verbose) { /* Couldn't open '%s' */ error(0, errno, GetCustMsg(13222), dev); } return; } if (fstat(fd, &sbuf) < 0) { if (verbose) { /* fstat of '%s' failed */ error(0, errno, GetCustMsg(13223), dev); } goto ret; } if (!S_ISBLK(sbuf.st_mode) && !S_ISCHR(sbuf.st_mode)) { if (verbose) { /* '%s' is not a block or char special. */ error(0, 0, GetCustMsg(13224), dev); } goto ret; } if (htp == NULL) { htp = malloc(SAM_LARGE_HOSTS_TABLE_SIZE); if (htp == NULL) { error(0, 0, GetCustMsg(13229)); exit(10); } } if (llseek(fd, SUPERBLK*SAM_DEV_BSIZE, SEEK_SET) == (offset_t)-1) { if (verbose) { /* Could not seek on device '%s' */ error(0, errno, GetCustMsg(13225), dev); } goto ret; } if (read(fd, (char *)&sblk, sizeof (sblk)) != sizeof (sblk)) { if (verbose) { /* Could not read from device '%s' */ error(0, errno, GetCustMsg(13226), dev); } goto ret; } if (strncmp((char *)&sblk.info.sb.name[0], "SBLK", 4) != 0) { if (verbose) { /* * Device '%s' doesn't have a QFS superblock * (SBLK).\n */ fprintf(stderr, GetCustMsg(13227), dev); } goto ret; } switch (sblk.info.sb.magic) { case SAM_MAGIC_V1: case SAM_MAGIC_V2: case SAM_MAGIC_V2A: break; case SAM_MAGIC_V1_RE: case SAM_MAGIC_V2_RE: case SAM_MAGIC_V2A_RE: if (byte_swap_sb(&sblk, sizeof (sblk))) { if (verbose) { /* * Device '%s' doesn't have a QFS * superblock (MAGIC).\n */ fprintf(stderr, GetCustMsg(13228), dev); } goto ret; } Devs[NDevs].di_flags |= DI_SBLK_BSWAPPED; break; default: if (verbose) { /* * Device '%s' doesn't have a QFS superblock * (MAGIC).\n */ fprintf(stderr, GetCustMsg(13228), dev); } goto ret; } if (sblk.info.sb.opt_mask & SBLK_OPTV1_LG_HOSTS) { hosts_table_size = SAM_LARGE_HOSTS_TABLE_SIZE; } else { hosts_table_size = SAM_HOSTS_TABLE_SIZE; } if (shared && (sblk.info.sb.magic == SAM_MAGIC_V2 || sblk.info.sb.magic == SAM_MAGIC_V2A) && sblk.info.sb.ord == sblk.info.sb.hosts_ord && sblk.info.sb.hosts != 0) { if (llseek(fd, sblk.info.sb.hosts*SAM_DEV_BSIZE, SEEK_SET) == (offset_t)-1) { if (verbose) { /* Could not seek on device '%s' */ error(0, errno, GetCustMsg(13225), dev); } return; } if (read(fd, (char *)htp, hosts_table_size) != hosts_table_size) { if (verbose) { /* Could not read from device '%s' */ error(0, errno, GetCustMsg(13226), dev); } return; } if (Devs[NDevs].di_flags & DI_SBLK_BSWAPPED) { if (byte_swap_hb(htp)) { /* Invalid hosts file on device '%s'. */ error(0, 0, GetCustMsg(13800), dev); return; } } Devs[NDevs].di_hosts = (struct sam_host_table *)malloc(hosts_table_size); if (!Devs[NDevs].di_hosts) { /* host table malloc failed. */ error(0, 0, GetCustMsg(13229)); exit(10); } bcopy((char *)htp, (char *)Devs[NDevs].di_hosts, hosts_table_size); Devs[NDevs].di_hosts_table_size = hosts_table_size; } else { Devs[NDevs].di_hosts = NULL; } Devs[NDevs].di_did = 0; if (strncmp((char *)dev, "/dev/did/dsk", 12) == 0) { Devs[NDevs].di_did = 1; } #ifdef sun if (debug && S_ISCHR(sbuf.st_mode)) { if (ioctl(fd, DKIOCINFO, &dkc) >= 0) { Devs[NDevs].di_dkip = (struct dk_cinfo *)malloc(sizeof (dkc)); if (!Devs[NDevs].di_dkip) { /* DKIOC malloc failed. */ error(0, 0, GetCustMsg(13230)); exit(10); } bcopy((char *)&dkc, (char *)Devs[NDevs].di_dkip, sizeof (dkc)); } else { if (verbose) { /* Ioctl DKIOCINFO of '%s' failed */ error(0, errno, GetCustMsg(13231)); } Devs[NDevs].di_dkip = NULL; } } else { Devs[NDevs].di_dkip = NULL; } #else /* sun */ Devs[NDevs].di_dkip = NULL; #endif /* sun */ Devs[NDevs].di_vtoc = NULL; #ifdef sun Devs[NDevs].di_efi = NULL; if (debug && S_ISCHR(sbuf.st_mode)) { if (ioctl(fd, DKIOCGVTOC, &vt) >= 0) { Devs[NDevs].di_vtoc = (struct vtoc *)malloc(sizeof (vt)); if (!Devs[NDevs].di_vtoc) { /* VTOC malloc failed. */ error(0, 0, GetCustMsg(13232)); exit(10); } bcopy((char *)&vt, (char *)Devs[NDevs].di_vtoc, sizeof (vt)); } else if (is_efi_present() && ((*call_efi_alloc_and_read)(fd, &efi_vtoc) >= 0)) { Devs[NDevs].di_efi = efi_vtoc; } else { if (verbose) { /* Could not get VTOC of '%s' */ error(0, errno, GetCustMsg(13233), dev); } } } #endif /* sun */ if (verbose) { if (Devs[NDevs].di_flags & DI_SBLK_BSWAPPED) { /* Device '%s' has a (byte-reversed) QFS superblock. */ printf(GetCustMsg(13801), dev); } else { /* Device '%s' has a QFS superblock. */ printf(GetCustMsg(13234), dev); } } Devs[NDevs].di_devname = (char *)malloc(strlen(dev)+1); Devs[NDevs].di_sblk = (struct sam_sblk *)malloc(sizeof (sblk)); if (!Devs[NDevs].di_devname || !Devs[NDevs].di_sblk) { /* Devname or SBLK malloc failed. */ error(0, 0, GetCustMsg(13235)); exit(10); } strcpy(Devs[NDevs].di_devname, dev); bcopy((char *)&sblk, (char *)Devs[NDevs].di_sblk, sizeof (sblk)); ++NDevs; ret: (void) close(fd); }