DOC PREVIEW
Chico CSCI 372 - Peripheral Device

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

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 56 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 56 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 56 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 56 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 56 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 56 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 56 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 56 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 56 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 56 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 56 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 56 pages.
Access to all documents
Download any document
Ad free experience

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 PointersHandlesSlide 21File DescriptoropenOpen System CallFile PermissionsSlide 26File 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 dup2 (Ex 3.17)File Descriptor Table (ex 3.17)pipepipe (ex 3.20)pipe (ex 3.20) after forkpipe (ex 3.20) after dup2pipe (ex 3.20) 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 Systemd e vs p e c i a l f i l e s f o r d e v i c e se t cs p e c i f i c sf o r s y s t e mh o m eu s e rd i r e c t o r i e so p ta p p l i c a t i o np a c k a g e su s rs h a r a b l ef i l e sv a rv a r y i n g f i l e s ,e . g . l o g s/Inode StructureInodeFile TypeFile Size (in bytes)Owner UID and GIDRelevant TimesLink and Block CountsAccess InformationDirect Block Pointer1Direct Block Pointer2Direct Block Pointer3Direct Block Pointer4Direct Block Pointer5Direct Block Pointer6Direct Block Pointer7…Direct Block Pointer12Single Indirection PointerDouble Indirection PointerTriple Indirection PointerFile 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 char special 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/file2inode12345…links = 2…23567…directoryentry in /user1inode name12345 file1directoryentry in /user2inode name12345 file2block 23567“This is the file text”Symbolic Linkinode12345…links = 2…23567…directoryentry in /user1inode name12345 file1block 23567“This is the file text”inode13579…links = 2…15213…directoryentry in /user2inode name13579 file2block 15213“/user1/file1”File 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,


View Full Document

Chico CSCI 372 - Peripheral Device

Download Peripheral Device
Our administrator received your request to download this document. We will send you the file to your email shortly.
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 2 2 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?