New version page

Chico CSCI 372 - Peripheral Device

This preview shows page 1-2-3-4-26-27-28-53-54-55-56 out of 56 pages.

View Full Document
View Full Document

End of preview. Want to read all 56 pages?

Upload your study docs or become a GradeBuddy member to access this document.

View Full Document
Unformatted text preview:

Peripheral DeviceDevice System CallsFile TypesPathsFile Library/System CallsImplementation Dependent Callsfind path [operand expression]Path Environment VariableUnix File SystemInode StructureMaximum File SizeUnix File System (cont)DirectoryRetrieving Inode Informationstruct stat *bufHard LinkSymbolic LinkFile DescriptorsFile PointersHandlesFile PointersFile DescriptoropenOpen System CallFile PermissionsFile PermissionsFile Descriptor LayoutFile Descriptor TableSystem File TableFile Pointers and BufferingFile Pointer LayoutDisk BufferingTerminal I/O BufferingOpen my.dat Before ForkOpen my.dat After forkFilterRedirectioncat > my.filedup2Use of dup2File Descriptor Tablepipepipe Examplepipe after forkpipe after dup2pipe after closeReading/WritingBlocking I/0 with PipesNon-Blocking I/OPollingOR SynchronizationNamed pipes – FIFOsFIFO ExampleNamed pipe (Top)Named pipe (Middle)Named pipe (Bottom)Peripheral Device• Controlled with system calls.• Frequently do I/O.• Pseudo-device drivers frequently simulate devices such as terminals• UNIX simplifies system calls to open, close, read, write, and ioctl.• Devices are represented by files called special files located in /dev directory.Device System Calls• open• close• read•write• ioctlFile Types• Regular File – Ordinary file on disk.• Special Files – Device files located in /dev directory– Block Special File – Represents device with characteristics similar to disk.– Character Special File – Represents device with characteristics similar to a keyboard.Paths• Absolute or fully qualified – from root directory (begins with /)• Relative – from current directory• Login Relative – from login directory (begins with ~)File Library/System Callsgetcwd(*buff,size) • buff parameter is pointer to current working directory. • size parameter is size of cwd string (often specified by PATH_MAX.• getcwd returns –1 if cwd is longer than size. Action is unspecified if buff is NULL.Implementation Dependent Calls• sysconf – Returns system-wide limits such as:1. _SC_CLK_TCK2. _SC_CHILD_MAX• pathconf – Report limits associated with a particular file or directory.• fpathconf – Report limits associated with a particular open file or directory.find path [operand expression]• Level 1 (command prompt level) command used to locate accessible files/subdirectories hidden in tree.• operand expression can be very complicated.find . –name “*.c” –size +10 -printPath Environment Variable• /usr/bin:/etc/usr/local/bin:/usr/ccs/bin:/home/robbins/bin:.• /usr/bin – searched first.• /etc/usr/local/bin – searched second.• /usr/ccs/bin – searched third.• /home/robbins/bin – searched fourth.• Current directory – searched last.• No subdirectories searched unless specified.Unix File Systemdevspecial files for devicesetcspecificsfor systemhomeuserdirectoriesoptapplicationpackagesusrsharablefilesvarvarying files,e.g. logs/Inode StructureTriple Indirection PointerDouble Indirection PointerSingle Indirection PointerDirect Block Pointer12…Direct Block Pointer7Direct Block Pointer6Direct Block Pointer5Direct Block Pointer4Direct Block Pointer3Direct Block Pointer2Direct Block Pointer1Access InformationLink and Block CountsRelevant TimesOwner UID and GIDFile Size (in bytes)File TypeInodeFile BlockFile BlockPointer Block……Maximum File SizeAssume block size 8K and 2K pointers per block• 12 direct pointers = 12*8K bytes• Single indirection pointer = 2K*8K bytes• Double indirection pointer = 2K*2K*8K bytes• Triple indirection pointer = 2K*2K*2K*8K bytesMax File Size = (12+2K+2K2+2K3)*8K bytesUnix File System (cont)• home – default directory for user accounts.• /usr/include – where include files are located.Directory• File has a description stored in a structure called inode.• Most user files are ordinary files.• Directories are represented as files too and have an associated inode.• Devices are special files– Character special files– Block special filesRetrieving Inode Information•Use stat to get inode info.•Use fstat to get inode info on open files.•Use lstat to retrieve info on symbolic links. lstat is not included in POSIX.struct stat *bufThe stat/fstat/lstat parameter struct stat *buf contains:mode_t st_mode; /* File mode (see mknod(2)) */ino_t st_ino; /* Inode number */dev_t st_dev; /* ID of device containing directory entry for file */dev_t st_rdev; /* ID of device – this entry is defined only for charspecial or block special files */ nlink_t st_nlink; /* Number of links */uid_t st_uid; /* User ID of the file’s owner */gid_t st_gid; /* Group ID of the file’s group */off_t st_size; /* File size in bytes */time_t st_atime; /* Time of last access */time_t st_mtime; /* Time of last data modification */time_t st_stime; /* Time of last file status change */long st_blksize; /* Preferred I/O block size */long st_blocks; /* Number st_blksize blocks allocated */Hard Linkln /user1/file1 /user2/file2file212345nameinodeentry in /user2directory…23567…links = 2…inode12345file112345nameinodeentry in /user1directory“This is the file text”block 23567Symbolic Link…23567…links = 1…inode12345file112345nameinodeentry in /user1directory“This is the file text”block 23567…15213…links = 1…inode13579file213579nameinodeentry in /user2directory“/user1/file1”block 15213File Descriptors• open• read•write• close – all use file descriptors• ioctlFile Pointers• fopen• fscanf•fprintf• fread – all use file pointers•fwrite• fcloseHandlesHandle is a generic term for both file descriptors and file pointers.File PointersFile pointer handles for standard input, standard output and standard error are:• stdin• stdout – defined in stdio.h•stderrFile pointer is a pointer to a file structure.File DescriptorFile descriptor handles for standard input, standard output and standard error are:•STDIN_FILENO• STDOUT_FILENO•STDERR_FILENOFile descriptor in the case of open is a pointer to a file descriptor tableopen#include <sys/types.h>#include<sys/stat.h>#include <fcntl.h>int open(const char *path, int oflag, …);oflag values: O_RDONLY, O_WRONLY, O_RDWR, O_APPEND, O_EXCL, O_NOCTTY, O_NONBLOCK, O_TRUNCOpen System Callmyfd = open (“/home/ann/my.dat”, O_RDONLY);Open system call sets the file’s status flags


View Full Document
Loading Unlocking...
Login

Join to view Peripheral Device and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Peripheral Device and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?