1 / 62

Agenda

Administrative Issues Link of the Week Review Week Two Information This Week’s Expected Outcomes Next Lab Assignment Break-Out Problems Upcoming Deadlines Lab Assistance, Questions, and Answers. Agenda. https://freedom-to-tinker.com/blog/felten/source-code-and-object-code

leigh
Download Presentation

Agenda

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Administrative Issues Link of the Week Review Week Two Information This Week’s Expected Outcomes Next Lab Assignment Break-Out Problems Upcoming Deadlines Lab Assistance, Questions, and Answers Agenda

  2. https://freedom-to-tinker.com/blog/felten/source-code-and-object-codehttps://freedom-to-tinker.com/blog/felten/source-code-and-object-code • What is object code? • http://www.linfo.org/object_code.html • Object File Format Link of the week

  3. What is object code? An object file is a file containing object code, meaning relocate able format machine code that is usually not directly executable. Object files are produced by an assembler, compiler, or other language translator, and used as input to the linker, which in turn typically generates an executable or library by combining parts of object files. There are various formats for object files, and the same object code can be packaged in different object files. Link of the week

  4. 0000000 7f45 4c46 0102 0100 0000 0000 0000 0000 0000020 0001 0002 0000 0001 0000 0000 0000 0000 0000040 0000 0234 0000 0000 0034 0000 0000 0028 0000060 0008 0001 002e 7368 7374 7274 6162 002e 0000100 7465 7874 002e 726f 6461 7461 002e 7379 0000120 6d74 6162 002e 7374 7274 6162 002e 7265 0000140 6c61 2e74 6578 7400 2e63 6f6d 6d65 6e74 0000160 0000 0000 9de3 bf88 f027 a044 f227 a048 Link of the week

  5. The code produced by a compiler. Programmers write programs in a form called source code. The source code consists of instructions in a particular language, like C, C++, or Java. Computers, however, can only execute instructions written in a low-level language called machine language. Link of the week

  6. What is Object File Format? An object file format is a computer file format used for the storage of object code and related data. There are many different object file formats; originally each type of computer had its own unique format, but with the advent of UNIX software portability, some formats, such as COFF and ELF have been defined and used on different kinds of operating systems. It is possible for the same file format to be used both as linker input and output, and thus as the library and executable file format. Link of the week

  7. Link of the week

  8. Learning Outcomes (Week four) • Write Perl scripts, including variables, control flow, and regular expression syntax Course expected outcome

  9. UNIX file system When we talk about a UNIX file system, we are actually referring to an area of physical memory represented by a single i-list. A UNIX machine may be connected to many different file systems, each with its own i-list. One of those i-lists points to a special storage area, known as the root file system. The root file system contains the files for the operating system itself, and must be available at all times. UNIX Operating System

  10. Other file systems are considered removable. A removable file systems can be attached, or mounted, to the root file system. Typically, an empty directory is created on the root file system as a mount point, and a removable file system is attached to that empty directory. When you issue a cd command to access the files and directories of a mounted removable file system, your file operations will be controlled through the i-list of the removable file system. UNIX Operating System

  11. The purpose of the i-list is to provide the operating system with a map into the memory of some physical storage device (disk drive). The map is continually being updated, as the files are created and removed, and as they grow and shrink in size. Thus, the mechanism of mapping must be very flexible and robust in order to accommodate drastic changes in the number and size of files. The i-list is stored in a known location, on the same memory storage device that it maps. UNIX Operating System

  12. Each entry in an i-list is called an inode. An inode is a data structure that provides the flexibility to track the changing file system. The inodes contain the information necessary to get information from the storage device, which typically communicates in fixed-size disk blocks. UNIX Operating System

  13. An inode contains 10 direct pointers, which point to disk blocks on the storage device. In addition, each inode also contains one indirect pointer, one double indirect pointer, and one triple indirect pointer. The indirect pointer points to a block of direct pointers. The double indirect pointer points to a block of indirect pointers, and the triple indirect pointer points to a block of double indirect pointers. By structuring the pointers in a geometric fashion, a single inode can represent a very large file. UNIX Operating System

  14. It now makes a little more sense to view a UNIX directory as a list of i-numbers, each i-number referencing a specific inode on a specific i-list. The operating system traces its way through a file path by following the inodes until it reaches the direct pointers that contain the actual location of the file on the storage device. UNIX Operating System

  15. UNIX inode attributes The POSIX standard mandates file system behavior that is strongly influenced by traditional UNIX file systems. Regular files must have the following attributes: • The size of the file in bytes. • Device ID (this identifies the device containing the file). • The User ID of the file's owner. • The Group ID of the file. • The file mode which determines the file type and how the file's owner, its group, and others can access the file. UNIX Operating System

  16. Additional system and user flags to further protect the file (limit its use and modification). • Timestamps telling when the inodeitself was last modified (ctime, inode change time), the file content last modified (mtime, modification time), and last accessed (atime, access time). • A link count telling how many hard links point to the inode. • Pointers to the disk blocks that store the file's contents (see inodepointer structure). UNIX Operating System

  17. The UNIX file system relies on data structures about files, beside the file content. The inode content information is considered metadata data that describes data. Each file has a number associated with it, which is called an inode number. UNIX Operating System

  18. UNIX Operating System

  19. UNIX Operating System

  20. UNIX Operating System

  21. UNIX Operating System

  22. UNIX directory • In UNIX, directories are fileswhichcontain information about other files. A UNIX directory is a file whose data is an array or list of (filename, i-node#) pairs. • It has an owner, group owner, size, access permissions, etc. • Many file operations can be used on directories • As a file, a directory has an i-node type structure. • A flag in the structure indicates its type. UNIX Operating System

  23. UNIX directory Unlike other files, the kernel imposes a structure on directory files using the UNIX command mkdir. A directory is a sequence of lines , a sequence of directory entries of variable length where each line contains an inode number and a file name mapping: <filename, inode #> UNIX Operating System

  24. UNIX command mkdirsub_dir The creation of a sub_dir directory file and an inode for it • An inodenumber and name are added to the parent directory file Directory sub_dir UNIX Operating System

  25. UNIX Operating System

  26. Dot and dot-dot files “.” and “..” are stored as ordinary file names with inode numbers pointing to the correct directory files. UNIX Operating System

  27. File system directory structure • The file system directory structure is a link between the inodehash list and the directory files. • The root “/” inodeis always number 2. The root “/” directory file data block is located thru inodenumber 2. • Directory file entries include each entry <filename, inodenumber>. Where file name is the local (unqualified) directoryor regular file name within the directory and inode number is an index into the inodehash array. • The (inode number)inodein the hash list entry has pointer to the data block of the subsequent regular file or directoryfile data block. UNIX Operating System

  28. File system directory structure • If it is a directory file, the directory data blocks are read for the next <filename, inodenumber>, and the process repeats. UNIX Operating System

  29. File system directory structure If a regular file, the data blocks are located and read. This process also explains the difference between hard links and soft links. A hard link directory entry is a direct pointer to a file inode. A soft link is a pointer to another directory entry. In a link, rm clears the directory record. Usually, this means that the inode number is set to 0 but the file may not be affected. The file inode is only deleted when the last link to it is removed; the data block for the file is also deleted (reclaimed). UNIX Operating System

  30. Disk drive UNIX Operating System

  31. File system data structure Disk drive File system UNIX Operating System

  32. Hard link UNIX Operating System

  33. Soft link UNIX Operating System

  34. Link (ln) command The ln command is used to create a hard and soft link. Hard link (physical): ln original_file.txt hard_link.txt Soft link (symbolic): ln –s original_file.txt soft_link.txt UNIX Operating System

  35. UNIX directory • Directory data is stored as binary, and cannot be displayed using the cat command. But some older versions of UNIX allow: od -c dir-name. • Although directories are files, UNIX permissions – rwx- have slightly different meanings: - r, lists directory contents - w, add a file to the directory - x, cd to the directory UNIX Operating System

  36. User process accessing data • Given the file name. To get to the file’s control block (FCB), use the file system catalog (Open, Close, Set_Attribute) • The catalog maps a file name to the file control block • Checks permissions • file_handle=open(file_name): • Search the catalog and bring file control block into the memory • UNIX: in-memory file control block: in-core i-node UNIX Operating System

  37. User process accessing data • Use the file control block to get to the desired offset within the file data: (CREATE, DELETE, SEEK, TRUNCATE) • close(file_handle): release file control block from memory UNIX Operating System

  38. What is a filter? A UNIX filter command performs an operation or manipulation of the input text from a file. Standard in and out are typically used during this operation. UNIX Command Line Filters awk, cat, cut, expand, compress, fold, grep, head, nl, perl, pr, sed, sh, sort, split, strings, tail, tac, tee, tr, uniq, and wc UNIX Operating System

  39. File System Filters cat, cd, chmod, chown, chgrp, cksum, cmp, cp, dd, du, df, fsck, fuser, ln, ls, lsattr, lsof, mkdir, mount, mv, pwd, rm, rmdir, split, touch, umask Processes Filters at, chroot, cron, exit, kill, killall, nice, pgrep, pidof, pkill, ps, pstree, sleep, time, top, and wait UNIX Operating System

  40. Test Command A common way to set up a condition for the if command is with the test command. test condition or [ condition ] The test command evaluates the condition and returns 0 or 1, depending on the results of the test. The brackets work exactly like the test condition. The open bracket is a link to test. UNIX Operating System

  41. Constructing Conditions -s file -r file -w file -S file -x file -f file -d file Examples: if [ ! –f /etc/quotatab ] Does the plain file named /etc/quotatab not exist? If [ -d /etc/rc0.d ] Is the /etc/rc0.d name a directory? UNIX Operating System

  42. Constructing Conditions -S file = True if the file exists and its size is greater than zero. -s file = True if the file exists and is a socket. -w file = True if the file exists and is writable. -x file = True if the file exists and is executable. -f file = True if the file exists and is a regular file -d file = True if the file exists and is a directory. UNIX Operating System

  43. Perl and Shell Similarities Perl scalar@ARGV ~ Shell $# Perl $ARGV[0] ~ Shell $1 Perl $ARGV[1] ~ Shell $2 Perl unless(scalar(@ARGV)==2) ~ Shell if [ $# != 2] All Perl statements are terminated with a “;” Perl exit 0 is returned if execution was successful. Perl exit 1 is returned if execution fails. UNIX Operating System

  44. Perl syntax $? - this variable contains the return value # - precedes a comment statement in Perl \n - new line syntax “ …” $strexp = “This text is considered as a string”; ‘ …’ $charexp = ‘a’; ` …` $cmdexp = `ls –l`; @ARGV – array containing command line arguments $_ - default implied scalar UNIX Operating System

  45. Relational operators There are two types of relational operators. One class operates on numeric values, the other on string values. Relational operators NumericStringMeaning > gtGreater than >= ge Greater than or equal < lt Less than <= leLess than or equal UNIX Operating System

  46. Equality Operators NumericStringMeaning == eq Equal to != ne Not equal to  cmp Comparison, sign results -1 if the left operand is less than right operand 0 If both operands equal to right operand 1 If the left operand is greater right operand UNIX Operating System

  47. Equality Operators if ( $count != 5 ) { print "The counter is NOT equal to 5.\n"; } if ( $response eq 'YES‘ ) { print "You said YES"; } else { print "I don't know what you said, but it wasn't YES"; } UNIX Operating System

  48. Initial Perl design • Perl is designed to - Process text data - Perform pattern matching - Utilize string handling tasks • Perl is available on many platforms - UNIX - Linux - HP-UX UNIX Operating System

  49. Perl utilizes two types of categories Singular variables that represent a single-value. The variable prefix symbol for a scalar is the $. Plural variables are ones that contain multiple-values. Arrays and hashes are two multi-valued variables. The variable prefix symbol for an array and hash are @ and %, respectively. UNIX Operating System

More Related