1 | /* ␊ |
2 | * Copyright (c) 2001 Apple Computer, Inc. All rights reserved. ␊ |
3 | * ␊ |
4 | * ␊ |
5 | * The contents of this file constitute Original Code as defined in and ␊ |
6 | * are subject to the Apple Public Source License Version 1.1 (the ␊ |
7 | * "License"). You may not use this file except in compliance with the ␊ |
8 | * License. Please obtain a copy of the License at ␊ |
9 | * http://www.apple.com/publicsource and read it before using this file. ␊ |
10 | * ␊ |
11 | * This Original Code and all software distributed under the License are ␊ |
12 | * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER ␊ |
13 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, ␊ |
14 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, ␊ |
15 | * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the ␊ |
16 | * License for the specific language governing rights and limitations ␊ |
17 | * under the License. ␊ |
18 | * ␊ |
19 | * ␊ |
20 | * Shantonu Sen␊ |
21 | * openUp.c - program to set the "first-open-window" field of a volume ␊ |
22 | * ␊ |
23 | * Get the directory ID for the first argument, and set it as word 2 ␊ |
24 | * of the Finder Info fields for the volume it lives on ␊ |
25 | * ␊ |
26 | * cc -o openUp openUp.c ␊ |
27 | * Usage: openUp /Volumes/Foo/OpenMe/ ␊ |
28 | * ␊ |
29 | */ ␊ |
30 | ␊ |
31 | #include <stdio.h>␊ |
32 | #include <unistd.h>␊ |
33 | #include <stdlib.h>␊ |
34 | #include <sys/attr.h>␊ |
35 | #include <sys/stat.h>␊ |
36 | #include <sys/mount.h>␊ |
37 | #include <memory.h>␊ |
38 | ␊ |
39 | struct directoryinfo { ␊ |
40 | ␉long unsigned length; ␊ |
41 | ␉uintptr_t dirid; // changed from: u_int32_t dirid;␊ |
42 | }; ␊ |
43 | ␊ |
44 | struct volumeinfo { ␊ |
45 | ␉long unsigned length; ␊ |
46 | ␉uintptr_t finderinfo[8]; // changed from: u_int32_t finderinfo[8];␊ |
47 | }; ␊ |
48 | ␊ |
49 | ␊ |
50 | int main(int argc, char *argv[]) {␊ |
51 | ␉char *path = NULL;␊ |
52 | ␉struct attrlist alist;␊ |
53 | ␉struct directoryinfo dirinfo;␊ |
54 | ␉struct volumeinfo volinfo;␊ |
55 | ␉struct statfs sfs;␊ |
56 | ␊ |
57 | ␉path = argv[1];␊ |
58 | ␊ |
59 | ␉bzero(&alist, sizeof(alist));␊ |
60 | ␉alist.bitmapcount = 5;␊ |
61 | ␉alist.commonattr = ATTR_CMN_OBJID;␊ |
62 | ␊ |
63 | ␉getattrlist(path, &alist, &dirinfo, sizeof(dirinfo), 0);␊ |
64 | ␊ |
65 | ␉printf("directory id: %lu\n", dirinfo.dirid);␊ |
66 | ␊ |
67 | ␉statfs(path, &sfs);␊ |
68 | ␊ |
69 | ␉printf("mountpoint: %s\n", sfs.f_mntonname);␊ |
70 | ␊ |
71 | ␉alist.commonattr = ATTR_CMN_FNDRINFO;␊ |
72 | ␉alist.volattr = ATTR_VOL_INFO;␊ |
73 | ␊ |
74 | ␉getattrlist(sfs.f_mntonname, &alist, &volinfo, sizeof(volinfo), 0);␊ |
75 | ␉volinfo.finderinfo[2] = dirinfo.dirid;␊ |
76 | ␉setattrlist(sfs.f_mntonname, &alist, volinfo.finderinfo, sizeof(volinfo.finderinfo), 0);␊ |
77 | ␊ |
78 | ␉return EXIT_SUCCESS;␊ |
79 | } ␊ |
80 | |