source: releases/launch/1.0b2/openUp.c@ 258

Last change on this file since 258 was 3, checked in by Nicholas Riley, 22 years ago

Initial import.

File size: 2.8 KB
Line 
1/*
2 * Copyright (c) 2001 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
6 * The contents of this file constitute Original Code as defined in and
7 * are subject to the Apple Public Source License Version 1.1 (the
8 * "License"). You may not use this file except in compliance with the
9 * License. Please obtain a copy of the License at
10 * http://www.apple.com/publicsource and read it before using this file.
11 *
12 * This Original Code and all software distributed under the License are
13 * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
14 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
15 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
17 * License for the specific language governing rights and limitations
18 * under the License.
19 *
20 * @APPLE_LICENSE_HEADER_END@
21 */
22/*
23 * Shantonu Sen <ssen@apple.com>
24 * openUp.c - program to set the "first-open-window" field of a volume
25 *
26 * Get the directory ID for the first argument, and set it as word 2
27 * of the Finder Info fields for the volume it lives on
28 *
29 * cc -o openUp openUp.c
30 * Usage: openUp /Volumes/Foo/OpenMe/
31 *
32 */
33
34#include <stdio.h>
35#include <stdarg.h>
36#include <unistd.h>
37#include <errno.h>
38#include <sys/attr.h>
39#include <sys/stat.h>
40#include <sys/mount.h>
41
42struct directoryinfo {
43 unsigned long length;
44 u_int32_t dirid;
45};
46
47struct volumeinfo {
48 unsigned long length;
49 u_int32_t finderinfo[8];
50};
51
52const char *APP_NAME;
53
54void errnoexit(const char *fmt, ...) {
55 va_list ap;
56 va_start(ap, fmt);
57 fprintf(stderr, "%s: ", APP_NAME);
58 vfprintf(stderr, fmt, ap);
59 fprintf(stderr, " (%s)\n", strerror(errno));
60 exit(1);
61}
62
63int main(int argc, char *argv[]) {
64
65 char *path = NULL;
66 struct attrlist alist;
67 struct directoryinfo dirinfo;
68 struct volumeinfo volinfo;
69 struct statfs sfs;
70 int err;
71
72 APP_NAME = argv[0];
73
74 if (argc != 2) {
75 fprintf(stderr, "usage: %s <path to folder whose window should open when volume is mounted>\n",
76 APP_NAME);
77 exit(1);
78 }
79
80 path = argv[1];
81
82 bzero(&alist, sizeof(alist));
83 alist.bitmapcount = 5;
84 alist.commonattr = ATTR_CMN_OBJID;
85
86 if (getattrlist(path, &alist, &dirinfo, sizeof(dirinfo), 0))
87 errnoexit("getattrlist on path failed");
88
89 printf("directory id: %lu\n", dirinfo.dirid);
90
91 if (statfs(path, &sfs))
92 errnoexit("statfs failed");
93
94 printf("mountpoint: %s\n", sfs.f_mntonname);
95
96 alist.commonattr = ATTR_CMN_FNDRINFO;
97 alist.volattr = ATTR_VOL_INFO;
98
99 if (getattrlist(sfs.f_mntonname, &alist, &volinfo, sizeof(volinfo), 0))
100 errnoexit("getattrlist on mount point failed");
101 volinfo.finderinfo[2] = dirinfo.dirid;
102 if (setattrlist(sfs.f_mntonname, &alist, volinfo.finderinfo,
103 sizeof(volinfo.finderinfo), 0))
104 errnoexit("setattrlist on mount point failed");
105
106 return 0;
107
108}
109
Note: See TracBrowser for help on using the repository browser.